RateMultilingualTest.php in Rate 8
File
tests/src/Functional/RateMultilingualTest.php
View source
<?php
namespace Drupal\Tests\rate\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\rate\Traits\AssertRateWidgetTrait;
use Drupal\Tests\rate\Traits\NodeVoteTrait;
class RateMultilingualTest extends BrowserTestBase {
use NodeVoteTrait;
use AssertRateWidgetTrait;
protected $defaultTheme = 'stable';
protected static $modules = [
'language',
'node',
'rate',
];
protected $node;
protected function setUp() {
parent::setUp();
ConfigurableLanguage::createFromLangcode('pl')
->save();
NodeType::create([
'type' => 'article',
'name' => 'Article',
])
->save();
$this
->config('rate.settings')
->set('enabled_types_widgets.node', [
'article' => [
'widget_type' => 'fivestar',
],
])
->set('use_ajax', FALSE)
->save();
$this->node = Node::create([
'title' => 'English article',
'type' => 'article',
]);
$this->node
->addTranslation('pl', [
'title' => 'Polish article',
]);
$this->node
->save();
$user = $this
->createUser([
'access content',
'cast rate vote on node of article',
]);
$this
->drupalLogin($user);
}
public function testMultilingualNode() {
$session = $this
->assertSession();
$this
->drupalGet('pl/node/' . $this->node
->id());
$this
->assertFivestar(0);
$session
->linkExists('Star');
$session
->linkNotExists('Undo');
$this
->voteFivestar(5);
$this
->assertFivestar(5);
$session
->linkNotExists('Star');
$session
->linkExists('Undo');
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertFivestar(5);
$session
->linkNotExists('Star');
$session
->linkExists('Undo');
}
}