public function LanguageConditionTest::testConditions

Test the language condition.

File

drupal/core/modules/language/lib/Drupal/language/Tests/Condition/LanguageConditionTest.php, line 73
Contains \Drupal\language\Tests\Condition\LanguageConditionTest.

Class

LanguageConditionTest
Tests the language condition.

Namespace

Drupal\language\Tests\Condition

Code

public function testConditions() {

  // Grab the language condition and configure it to check the content
  // language.
  $language = language_load('en');
  $condition = $this->manager
    ->createInstance('language')
    ->setConfig('langcodes', array(
    'en' => 'en',
    'it' => 'it',
  ))
    ->setContextValue('language', $language);
  $this
    ->assertTrue($condition
    ->execute(), 'Language condition passes as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is English, Italian.');

  // Change to Italian only.
  $condition
    ->setConfig('langcodes', array(
    'it' => 'it',
  ));
  $this
    ->assertFalse($condition
    ->execute(), 'Language condition fails as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is Italian.');

  // Negate the condition
  $condition
    ->setConfig('negate', TRUE);
  $this
    ->assertTrue($condition
    ->execute(), 'Language condition passes as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is not Italian.');

  // Change the default language to Italian.
  $language = language_load('it');
  $condition = $this->manager
    ->createInstance('language')
    ->setConfig('langcodes', array(
    'en' => 'en',
    'it' => 'it',
  ))
    ->setContextValue('language', $language);
  $this
    ->assertTrue($condition
    ->execute(), 'Language condition passes as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is English, Italian.');

  // Change to Italian only.
  $condition
    ->setConfig('langcodes', array(
    'it' => 'it',
  ));
  $this
    ->assertTrue($condition
    ->execute(), 'Language condition passes as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is Italian.');

  // Negate the condition
  $condition
    ->setConfig('negate', TRUE);
  $this
    ->assertFalse($condition
    ->execute(), 'Language condition fails as expected.');

  // Check for the proper summary.
  $this
    ->assertEqual($condition
    ->summary(), 'The language is not Italian.');
}