class SettingsTest in Zircon Profile 8
Same name in this branch
- 8 core/modules/views_ui/src/Tests/SettingsTest.php \Drupal\views_ui\Tests\SettingsTest
- 8 core/tests/Drupal/Tests/Core/Site/SettingsTest.php \Drupal\Tests\Core\Site\SettingsTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Site/SettingsTest.php \Drupal\Tests\Core\Site\SettingsTest
@coversDefaultClass \Drupal\Core\Site\Settings @group Site
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Site\SettingsTest
Expanded class hierarchy of SettingsTest
File
- core/
tests/ Drupal/ Tests/ Core/ Site/ SettingsTest.php, line 17 - Contains \Drupal\Tests\Core\Site\SettingsTest.
Namespace
Drupal\Tests\Core\SiteView source
class SettingsTest extends UnitTestCase {
/**
* Simple settings array to test against.
*
* @var array
*/
protected $config = array();
/**
* The class under test.
*
* @var \Drupal\Core\Site\Settings
*/
protected $settings;
/**
* @covers ::__construct
*/
protected function setUp() {
$this->config = array(
'one' => '1',
'two' => '2',
'hash_salt' => $this
->randomMachineName(),
);
$this->settings = new Settings($this->config);
}
/**
* @covers ::get
*/
public function testGet() {
// Test stored settings.
$this
->assertEquals($this->config['one'], Settings::get('one'), 'The correct setting was not returned.');
$this
->assertEquals($this->config['two'], Settings::get('two'), 'The correct setting was not returned.');
// Test setting that isn't stored with default.
$this
->assertEquals('3', Settings::get('three', '3'), 'Default value for a setting not properly returned.');
$this
->assertNull(Settings::get('four'), 'Non-null value returned for a setting that should not exist.');
}
/**
* @covers ::getAll
*/
public function testGetAll() {
$this
->assertEquals($this->config, Settings::getAll());
}
/**
* @covers ::getInstance
*/
public function testGetInstance() {
$singleton = $this->settings
->getInstance();
$this
->assertEquals($singleton, $this->settings);
}
/**
* Tests Settings::getHashSalt();
*
* @covers ::getHashSalt
*/
public function testGetHashSalt() {
$this
->assertSame($this->config['hash_salt'], $this->settings
->getHashSalt());
}
/**
* Tests Settings::getHashSalt() with no hash salt value.
*
* @covers ::getHashSalt
*
* @dataProvider providerTestGetHashSaltEmpty
*
* @expectedException \RuntimeException
*/
public function testGetHashSaltEmpty(array $config) {
// Re-create settings with no 'hash_salt' key.
$settings = new Settings($config);
$settings
->getHashSalt();
}
/**
* Data provider for testGetHashSaltEmpty.
*
* @return array
*/
public function providerTestGetHashSaltEmpty() {
return array(
array(
array(),
),
array(
array(
'hash_salt' => '',
),
),
array(
array(
'hash_salt' => NULL,
),
),
);
}
/**
* Ensures settings cannot be serialized.
*
* @covers ::__sleep
*
* @expectedException \LogicException
*/
public function testSerialize() {
serialize(new Settings([]));
}
/**
* Tests Settings::getApcuPrefix().
*
* @covers ::getApcuPrefix
*/
public function testGetApcuPrefix() {
$settings = new Settings(array(
'hash_salt' => 123,
));
$this
->assertNotEquals($settings::getApcuPrefix('cache_test', '/test/a'), $settings::getApcuPrefix('cache_test', '/test/b'));
$settings = new Settings(array(
'hash_salt' => 123,
'apcu_ensure_unique_prefix' => FALSE,
));
$this
->assertNotEquals($settings::getApcuPrefix('cache_test', '/test/a'), $settings::getApcuPrefix('cache_test', '/test/b'));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SettingsTest:: |
protected | property | Simple settings array to test against. | |
SettingsTest:: |
protected | property | The class under test. | |
SettingsTest:: |
public | function | Data provider for testGetHashSaltEmpty. | |
SettingsTest:: |
protected | function |
@covers ::__construct Overrides UnitTestCase:: |
|
SettingsTest:: |
public | function | @covers ::get | |
SettingsTest:: |
public | function | @covers ::getAll | |
SettingsTest:: |
public | function | Tests Settings::getApcuPrefix(). | |
SettingsTest:: |
public | function | Tests Settings::getHashSalt(); | |
SettingsTest:: |
public | function | Tests Settings::getHashSalt() with no hash salt value. | |
SettingsTest:: |
public | function | @covers ::getInstance | |
SettingsTest:: |
public | function | Ensures settings cannot be serialized. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |