RateWidgetTest.php in Rate 8
File
tests/src/Functional/RateWidgetTest.php
View source
<?php
namespace Drupal\Tests\rate\Functional;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\Tests\BrowserTestBase;
class RateWidgetTest extends BrowserTestBase {
protected $defaultTheme = 'stable';
public static $modules = [
'entity_test',
'rate',
];
protected $webUsers;
protected $testEntity;
protected function setUp() {
parent::setUp();
$this
->createUser();
$this
->config('rate.settings')
->set('enabled_types_widgets.entity_test', [
'entity_test' => [
'widget_type' => 'number_up_down',
'use_ajax' => FALSE,
],
])
->set('use_ajax', FALSE)
->save();
$display = \Drupal::service('entity_display.repository')
->getViewDisplay('entity_test', 'entity_test', 'default');
$display
->setComponent('rate_vote_widget', [
'weight' => 3,
]);
$display
->save();
$role = $this
->createRole([
'access content',
'cast rate vote on entity_test of entity_test',
'view test entity',
]);
foreach (range(1, 2) as $i) {
$this->webUsers[$i] = $this
->createUser();
$this->webUsers[$i]
->addRole($role);
$this->webUsers[$i]
->save();
}
$this->testEntity = EntityTest::create([
'name' => $this
->randomString(),
]);
$this->testEntity
->save();
}
public function testWidgetCaching() {
$this
->drupalLogin($this->webUsers[1]);
$this
->drupalGet($this->testEntity
->toUrl());
$this
->clickLink('Up');
$this
->drupalGet($this->testEntity
->toUrl());
$this
->assertSession()
->pageTextContains('+1');
$this
->assertSession()
->linkExists('Undo');
$this
->drupalLogin($this->webUsers[2]);
$this
->drupalGet($this->testEntity
->toUrl());
$this
->assertSession()
->pageTextContains('+1');
$this
->assertSession()
->linkNotExists('Undo');
}
}