You are here

class LanguageTest in Drupal 8

Same name in this branch
  1. 8 core/modules/ckeditor/tests/src/Unit/Plugin/CKEditorPlugin/LanguageTest.php \Drupal\Tests\ckeditor\Unit\Plugin\CKEditorPlugin\LanguageTest
  2. 8 core/modules/language/tests/src/Kernel/Plugin/migrate/source/LanguageTest.php \Drupal\Tests\language\Kernel\Plugin\migrate\source\LanguageTest
Same name and namespace in other branches
  1. 9 core/modules/ckeditor/tests/src/Unit/Plugin/CKEditorPlugin/LanguageTest.php \Drupal\Tests\ckeditor\Unit\Plugin\CKEditorPlugin\LanguageTest
  2. 10 core/modules/ckeditor/tests/src/Unit/Plugin/CKEditorPlugin/LanguageTest.php \Drupal\Tests\ckeditor\Unit\Plugin\CKEditorPlugin\LanguageTest

@coversDefaultClass \Drupal\ckeditor\Plugin\CKEditorPlugin\Language

@group ckeditor

Hierarchy

Expanded class hierarchy of LanguageTest

File

core/modules/ckeditor/tests/src/Unit/Plugin/CKEditorPlugin/LanguageTest.php, line 14

Namespace

Drupal\Tests\ckeditor\Unit\Plugin\CKEditorPlugin
View source
class LanguageTest extends UnitTestCase {

  /**
   * The plugin under test.
   *
   * @var \Drupal\ckeditor\Plugin\CKEditorPlugin\Language
   */
  protected $plugin;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $this->plugin = new Language([], $this
      ->randomMachineName(), []);
  }

  /**
   * Provides a list of configs to test.
   */
  public function providerGetConfig() {
    return [
      [
        'un',
        count(LanguageManager::getUnitedNationsLanguageList()),
      ],
      [
        'all',
        count(LanguageManager::getStandardLanguageList()),
      ],
    ];
  }

  /**
   * @covers ::getConfig
   *
   * @dataProvider providerGetConfig
   */
  public function testGetConfig($language_list, $expected_number) {
    $editor = $this
      ->getMockBuilder('Drupal\\editor\\Entity\\Editor')
      ->disableOriginalConstructor()
      ->getMock();
    $editor
      ->expects($this
      ->once())
      ->method('getSettings')
      ->willReturn([
      'plugins' => [
        'language' => [
          'language_list' => $language_list,
        ],
      ],
    ]);
    $config = $this->plugin
      ->getConfig($editor);
    $this
      ->assertIsArray($config);
    $this
      ->assertContains('ar:Arabic:rtl', $config['language_list']);
    $this
      ->assertContains('zh-hans:Chinese, Simplified', $config['language_list']);
    $this
      ->assertContains('en:English', $config['language_list']);
    $this
      ->assertContains('fr:French', $config['language_list']);
    $this
      ->assertContains('ru:Russian', $config['language_list']);
    $this
      ->assertContains('ar:Arabic:rtl', $config['language_list']);
    $this
      ->assertEquals($expected_number, count($config['language_list']));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageTest::$plugin protected property The plugin under test.
LanguageTest::providerGetConfig public function Provides a list of configs to test.
LanguageTest::setUp public function Overrides UnitTestCase::setUp
LanguageTest::testGetConfig public function @covers ::getConfig
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.