View source
<?php
namespace Drupal\Tests\language_cookie\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
class LanguageCookieConditionTest extends LanguageCookieTestBase {
public function testBlackListedPaths() {
$node = $this
->drupalCreateNode();
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('node/' . $node
->id());
$last = $this->container
->get('state')
->get('language_cookie_test.language_negotiation_last');
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this
->assertEquals('en', $last_interface_language);
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('fr/node/' . $node
->id());
$this
->assertSession()
->cookieEquals('language', 'fr');
$this
->drupalGet('node/' . $node
->id());
$last = $this->container
->get('state')
->get('language_cookie_test.language_negotiation_last');
$last_interface_language = $last[LanguageInterface::TYPE_INTERFACE];
$this
->assertEquals('fr', $last_interface_language);
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*' . PHP_EOL . '/node/' . $node
->id(),
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en/node/' . $node
->id());
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*' . PHP_EOL . '/node/' . $node
->id() . PHP_EOL . '/bar',
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en/node/' . $node
->id());
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*' . PHP_EOL . '/node/' . $node
->id() . '/foobar' . PHP_EOL . '/bar',
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en/node/' . $node
->id());
$this
->assertSession()
->cookieEquals('language', 'en');
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*' . PHP_EOL . '/node/' . $node
->id() . '/foobar',
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en/node/' . $node
->id());
$this
->assertSession()
->cookieEquals('language', 'en');
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*',
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en');
$this
->assertSession()
->cookieEquals('language', 'en');
$this
->drupalGet('en/admin/config/regional/language/detection/language_cookie');
$this
->submitForm([
'blacklisted_paths' => '/admin/*' . PHP_EOL . '<front>',
], 'Save configuration');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en');
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
$this
->drupalGet('admin/config/search/path/add');
$this
->submitForm([
'langcode[0][value]' => 'und',
'path[0][value]' => '/node/' . $node
->id(),
'alias[0][value]' => '/httprl_async_function_callback',
], 'Save');
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('fr/httprl_async_function_callback');
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
}
public function testAjax() {
$node = $this
->drupalCreateNode();
$headers = [];
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('fr/node/' . $node
->id(), [], $headers);
$this
->assertSession()
->cookieEquals('language', 'fr');
$headers['X-Requested-With'] = 'XMLHttpRequest';
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('fr/node/' . $node
->id(), [], $headers);
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
}
public function testOneLanguage() {
$language = ConfigurableLanguage::load('fr');
$language
->delete();
$node = $this
->drupalCreateNode();
$this
->getSession()
->setCookie('language', NULL);
$this
->drupalGet('en/node/' . $node
->id());
$this
->assertEmpty($this
->getSession()
->getCookie('language'));
$this
->drupalGet('admin/config/development/performance');
$this
->submitForm([], 'Clear all caches');
}
}