You are here

public function LanguageSelectionPageConditionTest::testBlackListedPaths in Language Selection Page 8.2

Test the "Blacklisted paths" condition.

File

tests/src/Functional/LanguageSelectionPageConditionTest.php, line 100

Class

LanguageSelectionPageConditionTest
Tests that the condition plugins work.

Namespace

Drupal\Tests\language_selection_page\Functional

Code

public function testBlackListedPaths() {
  $this
    ->drupalGet('admin/config/regional/language/detection/language_selection_page');
  $this
    ->assertSession()
    ->responseContains('/node/add/*');
  $this
    ->assertSession()
    ->responseContains('/node/*/edit');
  $node = $this
    ->drupalCreateNode([
    'langcode' => 'fr',
  ]);
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();

  // Add node to blacklisted paths.
  $blacklisted_paths = '/admin/*' . \PHP_EOL . '/node/' . $node
    ->id();
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => $blacklisted_paths,
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageNotLoaded();

  // Add node to blacklisted paths (in the middle).
  $blacklisted_paths = '/admin/*' . \PHP_EOL . '/node/' . $node
    ->id() . \PHP_EOL . '/bar';
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => $blacklisted_paths,
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());

  // @todo fix this test
  $this
    ->assertLanguageSelectionPageNotLoaded();

  // Add string that contains node, but not node itself.
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => '/admin/*' . \PHP_EOL . '/node/' . $node
      ->id() . '/foobar' . \PHP_EOL . '/bar',
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();

  // Add string that starts with node, but not node itself.
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => '/admin/*' . \PHP_EOL . '/node/' . $node
      ->id() . '/foobar',
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();

  // Test front page.
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => '/admin/*',
  ], 'Save configuration');
  $this
    ->drupalGet('<front>');
  $this
    ->assertLanguageSelectionPageLoaded();
  $this
    ->drupalPostForm('en/admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => '/admin/*' . \PHP_EOL . '<front>',
  ], 'Save configuration');
  $this
    ->drupalGet('<front>');
  $this
    ->assertLanguageSelectionPageNotLoaded();
  $this
    ->resetConfiguration();
}