public function FivestarTestCase::testViewerRating in Fivestar 8
Same name and namespace in other branches
- 7.2 test/fivestar.field.test \FivestarTestCase::testViewerRating()
Test that users can rate content with exposed widgets.
File
- test/
fivestar.field.test, line 27 - Simpletests for the Fivestar module.
Class
Code
public function testViewerRating() {
$this
->createFivestarField([
'widget_type' => 'exposed',
]);
// Add an test_node_type to rate.
$node = $this
->drupalCreateNode([
'type' => 'test_node_type',
]);
$this
->drupalGet('node/' . $node->nid);
$this
->drupalLogin($this->voter_user);
// Rate the test_node_type.
$edit = [
'vote' => '60',
];
$this
->drupalPost('node/' . $node->nid, $edit, t('Rate'));
$this
->assertNoRaw(t('No votes yet'), 'Visitors can rate content using the exposed widget.');
// Load the instance settings so we can change certain settings.
$instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
// Lets see if visitors is able to re-vote.
// §see http://drupal.org/node/356605
$instance['settings']['allow_revote'] = 1;
field_update_instance($instance);
$this
->drupalGet('node/' . $node->nid);
$result = $this
->xpath("//div[contains(@class, 'field-name-fivestar-test')]//select[contains(@name,'vote')]");
$this
->assertEqual(count($result), TRUE, 'Visitors can re-vote');
// Lets test to make sure the cancel option is not available if disabled.
// @see http://drupal.org/node/1269276
$this
->assertNoRaw(t('Cancel rating'), 'User cannot cancel his vote.');
$instance['settings']['allow_clear'] = 1;
field_update_instance($instance);
$this
->drupalGet('node/' . $node->nid);
$this
->assertRaw(t('Cancel rating'), 'User can cancel his vote.');
// Now lets change the field to have exposed off and make sure the value is still there.
// @see http://drupal.org/node/1242082
$instance['display']['default']['settings']['expose'] = FALSE;
field_update_instance($instance);
$this
->drupalGet('node/' . $node->nid);
$this
->assertFalse($this
->xpath("//form[contains(@class, 'fivestar-widget')]"));
// Make sure the three-star rating still shows on the node view.
$result = $this
->xpath("//div[contains(@class, 'field-name-fivestar-test')]//div[contains(@class,'star-first')]/span");
$this
->assertEqual($result[0][0], '3', 'The static display still shows three stars.');
}