You are here

public function ConfigStorageTestBase::testInvalidStorage in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php \Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase::testInvalidStorage()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php \Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase::testInvalidStorage()

Tests an invalid storage.

4 methods override ConfigStorageTestBase::testInvalidStorage()
CachedStorageTest::testInvalidStorage in core/tests/Drupal/KernelTests/Core/Config/Storage/CachedStorageTest.php
Tests an invalid storage.
ManagedStorageTest::testInvalidStorage in core/tests/Drupal/KernelTests/Core/Config/Storage/ManagedStorageTest.php
Tests an invalid storage.
MemoryStorageTest::testInvalidStorage in core/tests/Drupal/KernelTests/Core/Config/Storage/MemoryStorageTest.php
Tests an invalid storage.
StorageReplaceDataWrapperTest::testInvalidStorage in core/tests/Drupal/KernelTests/Core/Config/Storage/StorageReplaceDataWrapperTest.php
Tests an invalid storage.

File

core/tests/Drupal/KernelTests/Core/Config/Storage/ConfigStorageTestBase.php, line 119

Class

ConfigStorageTestBase
Base class for testing storage operations.

Namespace

Drupal\KernelTests\Core\Config\Storage

Code

public function testInvalidStorage() {
  $name = 'config_test.storage';

  // Write something to the valid storage to prove that the storages do not
  // pollute one another.
  $data = [
    'foo' => 'bar',
  ];
  $result = $this->storage
    ->write($name, $data);
  $this
    ->assertTrue($result);
  $raw_data = $this
    ->read($name);
  $this
    ->assertSame($data, $raw_data);

  // Reading from a non-existing storage bin returns FALSE.
  $result = $this->invalidStorage
    ->read($name);
  $this
    ->assertFalse($result);

  // Deleting from a non-existing storage bin throws an exception.
  try {
    $this->invalidStorage
      ->delete($name);
    $this
      ->fail('Exception not thrown upon deleting from a non-existing storage bin.');
  } catch (\Exception $e) {

    // An exception occurred as expected; just continue.
  }

  // Listing on a non-existing storage bin returns an empty array.
  $result = $this->invalidStorage
    ->listAll();
  $this
    ->assertSame([], $result);

  // Getting all collections on a non-existing storage bin return an empty
  // array.
  $this
    ->assertSame([], $this->invalidStorage
    ->getAllCollectionNames());

  // Writing to a non-existing storage bin creates the bin.
  $this->invalidStorage
    ->write($name, [
    'foo' => 'bar',
  ]);
  $result = $this->invalidStorage
    ->read($name);
  $this
    ->assertSame([
    'foo' => 'bar',
  ], $result);
}