function StateTest::testDelete

Tests both delete() & deleteMultiple() method.

Those value we are getting from testSetMultiple() function.

@covers ::delete @covers ::deleteMultiple

@depends testSetMultiple

Parameters

\Drupal\Core\State\State $state: The tested state.

File

core/tests/Drupal/Tests/Core/State/StateTest.php, line 303

Class

StateTest
@coversDefaultClass \Drupal\Core\State\State @group State

Namespace

Drupal\Tests\Core\State

Code

public function testDelete(State $state) : void {
    $state->delete('key1');
    $this->assertEquals(NULL, $state->get('key1'));
    $this->assertEquals([
        'key1' => NULL,
    ], $state->getMultiple([
        'key1',
    ]));
    $this->assertEquals('value2', $state->get('key2'));
    $this->assertEquals([
        'key2' => 'value2',
        'key3' => 'value3',
    ], $state->getMultiple([
        'key2',
        'key3',
    ]));
    $state->deleteMultiple([
        'key2',
        'key3',
    ]);
    $this->assertEquals(NULL, $state->get('key2'));
    $this->assertEquals(NULL, $state->get('key3'));
    $this->assertEquals([
        'key2' => NULL,
        'key3' => NULL,
    ], $state->getMultiple([
        'key2',
        'key3',
    ]));
}

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