You are here

class StateIntegrationTest in Service Container 7.2

Same name and namespace in other branches
  1. 7 lib/Drupal/service_container/Tests/StateIntegrationTest.php \Drupal\service_container\Tests\StateIntegrationTest

Hierarchy

Expanded class hierarchy of StateIntegrationTest

File

lib/Drupal/service_container/Tests/StateIntegrationTest.php, line 10
Contains \Drupal\service_container\Tests\StateIntegrationTest.

Namespace

Drupal\service_container\Tests
View source
class StateIntegrationTest extends ServiceContainerIntegrationTestBase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'State',
      'description' => 'Tests the state system',
      'group' => 'service_container',
    );
  }
  public function testState() {

    /** @var \Drupal\Core\State\StateInterface $state */
    $state = \Drupal::service('state');
    $this
      ->assertEqual(NULL, $state
      ->get('not-existing'));
    $this
      ->assertEqual('default', $state
      ->get('not-existing', 'default'));
    $state
      ->set('key', 'value');
    $this
      ->assertEqual('value', $state
      ->get('key'));
    $state
      ->setMultiple(array(
      'key1' => 'value1',
      'key2' => 'value2',
    ));
    $this
      ->assertEqual(array(
      'key1' => 'value1',
      'key2' => 'value2',
    ), $state
      ->getMultiple(array(
      'key1',
      'key2',
    )));
    $state
      ->delete('key1');
    $this
      ->assertEqual(array(
      'key2' => 'value2',
    ), $state
      ->getMultiple(array(
      'key1',
      'key2',
    )));
    $state
      ->deleteMultiple(array(
      'key2',
    ));
    $this
      ->assertEqual(array(), $state
      ->getMultiple(array(
      'key1',
      'key2',
    )));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ServiceContainerIntegrationTestBase::$container protected property The dependency injection container usable in the test.
ServiceContainerIntegrationTestBase::$profile protected property The profile to install as a basis for testing. 1
ServiceContainerIntegrationTestBase::setUp protected function 5
StateIntegrationTest::getInfo public static function
StateIntegrationTest::testState public function