You are here

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

Tests the available and not available summarized content types methods.

The test is for the methods OnlyOne::getAvailableContentTypesSummarized() and OnlyOne::getNotAvailableContentTypesSummarized().

@covers ::getAvailableContentTypesSummarized @covers ::getNotAvailableContentTypesSummarized @dataProvider providerGetAvailableContentTypesSummarized

Parameters

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

array $configured: The configured content types to have onlyone node.

array $content_types: The returned content types from the the database query.

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

File

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

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function testGetAvailableContentTypesSummarized(array $expected, array $configured, array $content_types, $multilingual) {

  // Mock OnlyOne.
  $controller = $this
    ->getOnlyOneMock($configured, $multilingual);

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

  // StatementInterface::fetchCol mock.
  $statement
    ->expects($this
    ->any())
    ->method('fetchAll')
    ->with(\PDO::FETCH_GROUP)
    ->willReturn($content_types);

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

  // Testing the functions.
  $this
    ->assertEquals($expected, $controller
    ->getAvailableContentTypesSummarized());
  $this
    ->assertEquals($expected, $controller
    ->getNotAvailableContentTypesSummarized());
}