You are here

public function OnlyOneTest::testGetLanguageLabelForEmptyLanguage in Allow a content type only once (Only One) 8

Tests language label for empty language with OnlyOne::getLanguageLabel().

The empty string as language_code is a special situation, you can read more at: https://stackoverflow.com/q/49466415/3653989 .

@covers ::getLanguageLabel

File

tests/src/Unit/OnlyOneTest.php, line 451

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function testGetLanguageLabelForEmptyLanguage() {

  // LanguageInterface mock.
  $language = $this
    ->createMock('Drupal\\Core\\Language\\LanguageInterface');

  // Mocking getName method.
  $language
    ->expects($this
    ->any())
    ->method('getName')
    ->willReturn('Not specified');

  // Mocking getLanguage method.
  $this->languageManager
    ->expects($this
    ->any())
    ->method('getLanguage')
    ->with(LanguageInterface::LANGCODE_NOT_SPECIFIED)
    ->willReturn($language);

  // Testing the function.
  $this
    ->assertEquals('Not specified', $this->onlyOne
    ->getLanguageLabel(''));
}