You are here

public function PdbBlockDeriverTest::testGetDerivativeDefinitions in Decoupled Blocks 8

Tests the getDerivativeDefinitions() method.

File

tests/src/Unit/Plugin/Derivative/PdbBlockDeriverTest.php, line 75

Class

PdbBlockDeriverTest
@coversDefaultClass \Drupal\pdb\Plugin\Derivative\PdbBlockDeriver @group pdb

Namespace

Drupal\Tests\pdb\Unit\Plugin\Derivative

Code

public function testGetDerivativeDefinitions() {
  $base_plugin_definition = [
    'provider' => 'pdb',
  ];

  // example_1 should not appear due to debug mode being off.
  $expected = [
    'block_1' => [
      'info' => [
        'name' => 'Block 1',
        'machine_name' => 'block_1',
        'presentation' => 'pdb',
        'contexts' => [
          'entity' => 'node',
        ],
      ],
      'provider' => 'pdb',
      'admin_label' => 'Block 1',
      'cache' => [
        'max-age' => 0,
      ],
    ],
  ];
  $return = $this->deriver
    ->getDerivativeDefinitions($base_plugin_definition);
  $this
    ->assertInstanceOf('Drupal\\Core\\Plugin\\Context\\EntityContextDefinition', $return['block_1']['context_definitions']['entity']);

  // Remove the context to compare the arrays.
  unset($return['block_1']['context_definitions']);
  $this
    ->assertEquals($expected, $return);
}