You are here

public function FivestarTestCase::testAuthorRating in Fivestar 7.2

Test that authors can rate their own content.

File

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

Class

FivestarTestCase
Makes sure fivestar widgets can be created and used.

Code

public function testAuthorRating() {
  $this
    ->drupalLogin($this->adminUser);

  // Add an author-rated fivestar field to the test_node_type content type.
  $this
    ->createFivestarField(array(
    'widget_type' => 'stars',
  ));

  // Load the instance settings so we can set allow_ownvote.
  $instance = field_read_instance('node', 'fivestar_test', 'test_node_type');
  $instance['settings']['allow_ownvote'] = 1;
  field_update_instance($instance);

  // Save a test_node_type node with a two-star rating.
  $edit = array(
    'title' => $this
      ->randomString(),
    // Equals a rating of 2 stars.
    'fivestar_test[und][0][rating]' => '40',
  );
  $this
    ->drupalPost('node/add/test_node_type', $edit, 'Save');

  // Make sure the two-star rating 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], '2', 'Content authors can rate their own content using the stars widget.');
}