You are here

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

Tests the available and not available content types methods.

The test is for the methods OnlyOne::getAvailableContentTypes() and OnlyOne::getNotAvailableContentTypes().

@covers ::getAvailableContentTypes @covers ::getNotAvailableContentTypes @dataProvider providerGetAvailableContentTypes

Parameters

array $expected: The expected result from calling the function.

bool $multilingual: Whether the site is multilingual or not.

File

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

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function testGetAvailableContentTypes(array $expected, $multilingual) {

  // Mocking isMultilingual.
  $this->languageManager
    ->expects($this
    ->any())
    ->method('isMultilingual')
    ->willReturn($multilingual);

  // StatementInterface mock.
  $statement = $this
    ->createMock('Drupal\\Core\\Database\\StatementInterface');

  // StatementInterface::fetchCol mock.
  $statement
    ->expects($this
    ->any())
    ->method('fetchCol')
    ->willReturn($expected);

  // Mocking query.
  $this->connection
    ->expects($this
    ->any())
    ->method('query')
    ->willReturn($statement);

  // Testing the functions.
  $this
    ->assertEquals($expected, $this->onlyOne
    ->getAvailableContentTypes());
  $this
    ->assertEquals($expected, $this->onlyOne
    ->getNotAvailableContentTypes());
}