You are here

public function ArrayPluginDefinitionDecoratorTest::testGetId in Plugin 8.2

@covers ::setId @covers ::getId @covers ::offsetExists @covers ::offsetSet @covers ::offsetGet @covers ::offsetUnset

File

tests/src/Unit/PluginDefinition/ArrayPluginDefinitionDecoratorTest.php, line 84

Class

ArrayPluginDefinitionDecoratorTest
@coversDefaultClass \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator

Namespace

Drupal\Tests\plugin\Unit\PluginDefinition

Code

public function testGetId() {

  // Test the injected value.
  $this
    ->assertSame($this->arrayDefinition['id'], $this->sut
    ->getId());
  $this
    ->assertSame($this->arrayDefinition['id'], $this->sut
    ->getArrayDefinition()['id']);
  $this
    ->assertSame($this->arrayDefinition['id'], $this->sut['id']);

  // Test changing the value through the setter.
  $value = $this
    ->randomMachineName();
  $this
    ->assertSame($this->sut, $this->sut
    ->setId($value));
  $this
    ->assertSame($value, $this->sut
    ->getId());
  $this
    ->assertSame($value, $this->sut
    ->getArrayDefinition()['id']);
  $this
    ->assertSame($value, $this->sut['id']);

  // Test changing the value through array access.
  $value = $this
    ->randomMachineName();
  $this->sut['id'] = $value;
  $this
    ->assertSame($value, $this->sut
    ->getId());
  $this
    ->assertSame($value, $this->sut
    ->getArrayDefinition()['id']);
  $this
    ->assertSame($value, $this->sut['id']);

  // Test unsetting the value.
  unset($this->sut['id']);
  $this
    ->assertFalse(isset($this->sut['id']));
  $this
    ->assertNull($this->sut
    ->getId());
  $this
    ->assertFalse(isset($this->sut
    ->getArrayDefinition()['id']));
}