You are here

public function PhpStorageFactoryTest::testGetOverride in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php \Drupal\Tests\system\Kernel\PhpStorage\PhpStorageFactoryTest::testGetOverride()

Tests the get() method with overridden settings.

File

core/modules/system/tests/src/Kernel/PhpStorage/PhpStorageFactoryTest.php, line 58
Contains \Drupal\system\Tests\PhpStorage\PhpStorageFactoryTest.

Class

PhpStorageFactoryTest
Tests the PHP storage factory.

Namespace

Drupal\Tests\system\Kernel\PhpStorage

Code

public function testGetOverride() {
  $this
    ->setSettings('test');
  $php = PhpStorageFactory::get('test');

  // The FileReadOnlyStorage should be used from settings.
  $this
    ->assertTrue($php instanceof MockPhpStorage, 'A MockPhpStorage instance was returned from overridden settings.');

  // Test that the name is used for the bin when it is NULL.
  $this
    ->setSettings('test', array(
    'bin' => NULL,
  ));
  $php = PhpStorageFactory::get('test');
  $this
    ->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
  $this
    ->assertIdentical('test', $php
    ->getConfigurationValue('bin'), 'Name value was used for bin.');

  // Test that a default directory is set if it's empty.
  $this
    ->setSettings('test', array(
    'directory' => NULL,
  ));
  $php = PhpStorageFactory::get('test');
  $this
    ->assertTrue($php instanceof MockPhpStorage, 'An MockPhpStorage instance was returned from overridden settings.');
  $this
    ->assertIdentical(PublicStream::basePath() . '/php', $php
    ->getConfigurationValue('directory'), 'Default file directory was used.');

  // Test that a default storage class is set if it's empty.
  $this
    ->setSettings('test', array(
    'class' => NULL,
  ));
  $php = PhpStorageFactory::get('test');
  $this
    ->assertTrue($php instanceof MTimeProtectedFileStorage, 'An MTimeProtectedFileStorage instance was returned from overridden settings with no class.');
}