You are here

protected function StaticDiscoveryTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Plugin/Discovery/StaticDiscoveryTest.php \Drupal\system\Tests\Plugin\Discovery\StaticDiscoveryTest::setUp()

Performs setup tasks before each individual test method is run.

Overrides KernelTestBase::setUp

File

core/modules/system/src/Tests/Plugin/Discovery/StaticDiscoveryTest.php, line 19
Contains \Drupal\system\Tests\Plugin\Discovery\StaticDiscoveryTest.

Class

StaticDiscoveryTest
Tests that plugins using static discovery are correctly discovered.

Namespace

Drupal\system\Tests\Plugin\Discovery

Code

protected function setUp() {
  parent::setUp();
  $this->expectedDefinitions = array(
    'apple' => array(
      'label' => 'Apple',
      'color' => 'green',
    ),
    'cherry' => array(
      'label' => 'Cherry',
      'color' => 'red',
    ),
    'orange' => array(
      'label' => 'Orange',
      'color' => 'orange',
    ),
  );

  // Instead of registering the empty discovery component first and then
  // setting the plugin definitions, we set them first and then delete them
  // again. This implicitly tests StaticDiscovery::deleteDefinition() (in
  // addition to StaticDiscovery::setDefinition() which we need to use
  // anyway).
  $discovery = new StaticDiscovery();
  foreach ($this->expectedDefinitions as $plugin_id => $definition) {
    $discovery
      ->setDefinition($plugin_id, $definition);
  }
  $this->discovery = clone $discovery;
  foreach ($this->expectedDefinitions as $plugin_id => $definition) {
    $discovery
      ->deleteDefinition($plugin_id);
  }
  $this->emptyDiscovery = $discovery;
}