RateNodeWidgetTestBase.php in Rate 8
File
tests/src/Functional/RateNodeWidgetTestBase.php
View source
<?php
namespace Drupal\Tests\rate\Functional;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\rate\Traits\AssertRateWidgetTrait;
abstract class RateNodeWidgetTestBase extends BrowserTestBase {
use AssertRateWidgetTrait;
protected $defaultTheme = 'stable';
public static $modules = [
'node',
'rate',
];
protected $widget;
protected $labels;
protected $users;
protected function setUp() {
parent::setUp();
NodeType::create([
'type' => 'article',
'name' => 'Article',
])
->save();
$this
->config('rate.settings')
->set('enabled_types_widgets.node', [
'article' => [
'widget_type' => $this->widget,
],
])
->set('use_ajax', FALSE)
->save();
$this
->drupalCreateNode([
'type' => 'article',
'nid' => 1,
])
->save();
$this
->drupalCreateNode([
'type' => 'article',
'nid' => 2,
])
->save();
$permissions = [
'access content',
'cast rate vote on node of article',
];
$this->users[0] = $this
->createUser($permissions);
$this->users[1] = $this
->createUser($permissions);
$this->users[2] = $this
->createUser($permissions);
}
public function testPermissions() {
$this
->drupalLogin($this->users[0]);
$this
->drupalGet('node/1');
foreach ($this->labels as $label) {
$this
->assertSession()
->linkExists($label);
}
$user = $this
->createUser([
'access content',
]);
$this
->drupalLogin($user);
$this
->drupalGet('node/1');
foreach (array_merge($this->labels, [
'Undo',
]) as $label) {
$this
->assertSession()
->linkNotExists($label);
}
}
}