You are here

public function FivestarTest::testViewerNonRating in Fivestar 8

Tests that users cannot rate content with exposed widgets.

Tests that users cannot rate content with exposed widgets that has the exposed display setting set to FALSE.

File

tests/src/Functional/FivestarTest.php, line 117

Class

FivestarTest
Test base for the Fivestar module.

Namespace

Drupal\Tests\fivestar\Functional

Code

public function testViewerNonRating() {

  // Add an exposed field, with the 'exposed' display settings set to FALSE.
  $this
    ->createFivestarField([
    'widget_type' => 'exposed',
    'display' => [
      'default' => [
        'type' => 'fivestar_stars',
        'settings' => [
          'style' => 'average',
          'text' => 'average',
          'expose' => FALSE,
        ],
      ],
    ],
  ]);

  // Add the field to the display and form display.
  $this->displayRepository
    ->getViewDisplay('node', 'test_node_type', 'default')
    ->setComponent('fivestar_test')
    ->save();
  $this->displayRepository
    ->getFormDisplay('node', 'test_node_type', 'default')
    ->setComponent('fivestar_test')
    ->save();

  // Create a node with our field to test the static widget.
  $node = $this
    ->createNode([
    'type' => 'test_node_type',
  ]);

  // Rate the test_node_type.
  $this
    ->drupalLogin($this->voterUser);
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertRaw('No votes yet', 'Fivestar field has no votes.');
  $this
    ->assertEmpty($this
    ->xpath("//form[contains(@class, 'fivestar-widget')]"));

  // Check if node with attached fivestar field can be save.
  $edit = [
    'title[0][value]' => $this
      ->randomMachineName(),
  ];
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('node/' . $node
    ->id() . '/edit');
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->pageTextContains('has been updated.');
}