You are here

public function DerivativeDiscoveryDecoratorTest::testExistingDerivative in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest::testExistingDerivative()

Tests derivative definitions when a definition already exists.

File

core/tests/Drupal/Tests/Core/Plugin/Discovery/DerivativeDiscoveryDecoratorTest.php, line 139
Contains \Drupal\Tests\Core\Plugin\Discovery\DerivativeDiscoveryDecoratorTest.

Class

DerivativeDiscoveryDecoratorTest
Unit tests for the derivative discovery decorator.

Namespace

Drupal\Tests\Core\Plugin\Discovery

Code

public function testExistingDerivative() {
  $definitions = array();
  $definitions['non_container_aware_discovery'] = array(
    'id' => 'non_container_aware_discovery',
    'deriver' => '\\Drupal\\Tests\\Core\\Plugin\\Discovery\\TestDerivativeDiscovery',
    'string' => 'string',
    'empty_string' => 'not_empty',
    'array' => array(
      'one',
      'two',
    ),
    'empty_array' => array(
      'three',
    ),
    'null_value' => TRUE,
  );

  // This will clash with a derivative id.
  // @see \Drupal\Tests\Core\Plugin\Discovery\TestDerivativeDiscovery
  $definitions['non_container_aware_discovery:test_discovery_1'] = array(
    'id' => 'non_container_aware_discovery:test_discovery_1',
    'string' => 'string',
    'empty_string' => '',
    'array' => array(
      'one',
      'two',
    ),
    'empty_array' => array(),
    'null_value' => NULL,
  );
  $this->discoveryMain
    ->expects($this
    ->any())
    ->method('getDefinitions')
    ->will($this
    ->returnValue($definitions));
  $discovery = new DerivativeDiscoveryDecorator($this->discoveryMain);
  $returned_definitions = $discovery
    ->getDefinitions();

  // If the definition was merged, there should only be two.
  $this
    ->assertCount(2, $returned_definitions);
  $expected = $definitions['non_container_aware_discovery'];
  $expected['id'] = 'non_container_aware_discovery:test_discovery_1';
  $this
    ->assertArrayEquals($expected, $returned_definitions['non_container_aware_discovery:test_discovery_1']);
}