You are here

private function OnlyOneTest::getOnlyOneMock in Allow a content type only once (Only One) 8

Mock some OnlyOne class functions.

Parameters

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

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

Return value

\Drupal\onlyone\OnlyOne|\PHPUnit\Framework\MockObject\MockObject The mocked class.

2 calls to OnlyOneTest::getOnlyOneMock()
OnlyOneTest::testAddAditionalInfoToContentTypesIsolated in tests/src/Unit/OnlyOneTest.php
Tests the OnlyOne::addAditionalInfoToContentTypes() method in isolation.
OnlyOneTest::testGetAvailableContentTypesSummarized in tests/src/Unit/OnlyOneTest.php
Tests the available and not available summarized content types methods.

File

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

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

private function getOnlyOneMock(array $configured, $multilingual) {

  // Mock OnlyOne.

  /** @var \Drupal\onlyone\OnlyOne|\PHPUnit\Framework\MockObject\MockObject $controller */
  $controller = $this
    ->getMockBuilder('Drupal\\onlyone\\OnlyOne')
    ->setConstructorArgs([
    $this->entityTypeManager,
    $this->connection,
    $this->languageManager,
    $this->configFactory,
    $this
      ->getStringTranslationStub(),
  ])
    ->setMethods([
    'getContentTypesList',
    'getLanguageLabel',
  ])
    ->getMock();

  // Mock getContentTypesList().
  $controller
    ->expects($this
    ->any())
    ->method('getContentTypesList')
    ->willReturn($this
    ->getContentTypesList());

  // Mock getLanguageLabel().
  $controller
    ->expects($this
    ->any())
    ->method('getLanguageLabel')
    ->will($this
    ->returnValueMap($this
    ->getLanguageMap()));

  // ImmutableConfig mock.
  $config = $this
    ->createMock('Drupal\\Core\\Config\\ImmutableConfig');

  // ImmutableConfig::get mock.
  $config
    ->expects($this
    ->any())
    ->method('get')
    ->with('onlyone_node_types')
    ->willReturn($configured);

  // Mocking getEditable method.
  $this->configFactory
    ->expects($this
    ->any())
    ->method('get')
    ->with('onlyone.settings')
    ->willReturn($config);

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