function ComponentNegotiatorTest::testNegotiateCachesNullResults

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/KernelTests/Components/ComponentNegotiatorTest.php \Drupal\KernelTests\Components\ComponentNegotiatorTest::testNegotiateCachesNullResults()

Tests that negotiate() caches null results.

File

core/tests/Drupal/KernelTests/Components/ComponentNegotiatorTest.php, line 66

Class

ComponentNegotiatorTest
Tests the component negotiator.

Namespace

Drupal\KernelTests\Components

Code

public function testNegotiateCachesNullResults() : void {
  $definitions = $this->manager
    ->getDefinitions();
  // sdc_test:my-banner has no replacement: negotiate() returns null.
  $this->assertNull($this->negotiator
    ->negotiate('sdc_test:my-banner', $definitions));
  // Add a fake replacement and call again. The null result must be served
  // from cache. Definitions are immutable within a request, so this fake
  // entry only serves to detect if doNegotiate() re-ran unexpectedly.
  $definitions['fake:replacement'] = [
    'id' => 'fake:replacement',
    'replaces' => 'sdc_test:my-banner',
    'extension_type' => ExtensionType::Module,
    'provider' => 'sdc_test',
  ];
  $this->assertNull($this->negotiator
    ->negotiate('sdc_test:my-banner', $definitions));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.