View source
<?php
namespace Drupal\Tests\views\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\views\Tests\ViewTestData;
class GlossaryViewTest extends WebDriverTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
public static $modules = [
'language',
'node',
'views',
'views_test_config',
];
protected $defaultTheme = 'classy';
public static $testViews = [
'test_glossary',
];
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), [
'views_test_config',
]);
$this
->createContentType([
'type' => 'page',
]);
$titles = [
'Page One',
'Page Two',
'Another page',
];
foreach ($titles as $title) {
$this
->createNode([
'title' => $title,
'language' => 'en',
]);
$this
->createNode([
'title' => $title,
'language' => 'nl',
]);
}
$user = $this
->drupalCreateUser([
'administer site configuration',
'access content',
'access content overview',
]);
$this
->drupalLogin($user);
}
public function testGlossaryDefault() {
$url = Url::fromRoute('view.test_glossary.page_1');
$this
->drupalGet($url);
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$page = $session
->getPage();
$rows = $page
->findAll('css', '.view-test-glossary tr');
$this
->assertCount(3, $rows);
$page
->clickLink('P');
$web_assert
->assertWaitOnAjaxRequest();
$rows = $page
->findAll('css', '.view-test-glossary tr');
$this
->assertCount(5, $rows);
}
public function testGlossaryLanguagePrefix() {
ConfigurableLanguage::createFromLangcode('nl')
->save();
$config = $this
->config('language.negotiation');
$config
->set('url.prefixes', [
'en' => 'en',
'nl' => 'nl',
])
->save();
\Drupal::service('kernel')
->rebuildContainer();
$url = Url::fromRoute('view.test_glossary.page_1');
$this
->drupalGet($url);
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$page = $session
->getPage();
$rows = $page
->findAll('css', '.view-test-glossary tr');
$this
->assertCount(3, $rows);
$page
->clickLink('P');
$web_assert
->assertWaitOnAjaxRequest();
$rows = $page
->findAll('css', '.view-test-glossary tr');
$this
->assertCount(5, $rows);
}
}