You are here

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

Tests content type config deletion with OnlyOne::deleteContentTypeConfig().

@covers ::deleteContentTypeConfig @dataProvider providerDeleteContentTypeConfig

Parameters

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

string $content_type: Content type machine name to delete through OnlyOne::eleteContentTypeConfig().

string $content_types: Content types configured to have onlyone node.

File

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

Class

OnlyOneTest
Tests the OnlyOne class methods.

Namespace

Drupal\Tests\onlyone\Unit

Code

public function testDeleteContentTypeConfig($expected, $content_type, $content_types) {

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

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

  // Config::set mock.
  $config
    ->expects($this
    ->any())
    ->method('set')
    ->with('onlyone_node_types', $this
    ->anything())
    ->willReturnSelf();

  // Config::save mock.
  $config
    ->expects($this
    ->any())
    ->method('save');

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

  // Testing the function.
  $this
    ->assertEquals($expected, $this->onlyOne
    ->deleteContentTypeConfig($content_type));
}