You are here

public function FivestarTestCase::testExposedWidgetDisplay in Fivestar 7.2

Same name and namespace in other branches
  1. 8 test/fivestar.field.test \FivestarTestCase::testExposedWidgetDisplay()

Tests changing the fivestar widget.

Test that we can switch the fivestar widgets around for the exposed widget type.

File

test/fivestar.field.test, line 153
Simpletests for the Fivestar module.

Class

FivestarTestCase
Makes sure fivestar widgets can be created and used.

Code

public function testExposedWidgetDisplay() {

  // Let's add an exposed widget but display the static widget.
  // It's simpler to compare the display type using the static widget.
  $this
    ->createFivestarField(array(
    'widget_type' => 'exposed',
    'display' => array(
      'default' => array(
        'type' => 'fivestar_formatter_default',
        'settings' => array(
          'style' => 'average',
          'text' => 'average',
          'expose' => FALSE,
        ),
      ),
    ),
  ));
  $instance = field_read_instance('node', 'fivestar_test', 'test_node_type');

  // Add a test_node_type to test widget against.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'test_node_type',
  ));

  // Test the Default Widget.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->assertTrue($this
    ->xpath("//div[contains(@class, 'fivestar-default')]//div[contains(@class,'star-first')]/span"));
  $widgets = module_invoke_all('fivestar_widgets');
  foreach ($widgets as $path => $name) {
    $instance['display']['default']['settings']['widget']['fivestar_widget'] = $path;
    field_update_instance($instance);
    $widget_class = 'fivestar-' . drupal_strtolower($name);
    $this
      ->drupalGet('node/' . $node->nid);
    $result = $this
      ->xpath("//div[contains(@class, '" . $widget_class . "')]//div[contains(@class,'star-first')]/span");
    $this
      ->assertEqual($result[0][0], '0', "The {$name} fivestar widget is properly displayed.");
  }
}