public function FivestarTestCase::testExposedWidgetDisplay in Fivestar 8
Same name and namespace in other branches
- 7.2 test/fivestar.field.test \FivestarTestCase::testExposedWidgetDisplay()
Test that we can switch the fivestar widgets around for the exposed widget type.
File
- test/
fivestar.field.test, line 97 - Simpletests for the Fivestar module.
Class
Code
public function testExposedWidgetDisplay() {
// Lets add an exposed widget but display the static widget.
// It's simpler to compare the display type using the static widget.
$this
->createFivestarField([
'widget_type' => 'exposed',
'display' => [
'default' => [
'type' => 'fivestar_formatter_default',
'settings' => [
'style' => 'average',
'text' => 'average',
'expose' => FALSE,
],
],
],
]);
$instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
// Add an test_node_type to test widget against.
$node = $this
->drupalCreateNode([
'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', t('The @name fivestar widget is properly display.', [
'@name' => $name,
]));
}
}