class VariableTest in Zircon Profile 8
Same name in this branch
- 8 core/tests/Drupal/Tests/Component/Utility/VariableTest.php \Drupal\Tests\Component\Utility\VariableTest
- 8 core/modules/migrate_drupal/tests/src/Unit/source/VariableTest.php \Drupal\Tests\migrate_drupal\Unit\source\VariableTest
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Utility/VariableTest.php \Drupal\Tests\Component\Utility\VariableTest
Test variable export functionality in Variable component.
@group Variable @group Utility
@coversDefaultClass \Drupal\Component\Utility\Variable
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\Utility\VariableTest
Expanded class hierarchy of VariableTest
File
- core/
tests/ Drupal/ Tests/ Component/ Utility/ VariableTest.php, line 21 - Contains \Drupal\Tests\Component\Utility\VariableTest.
Namespace
Drupal\Tests\Component\UtilityView source
class VariableTest extends UnitTestCase {
/**
* Data provider for testExport().
*
* @return array
* An array containing:
* - The expected export string.
* - The variable to export.
*/
public function providerTestExport() {
return array(
// Array.
array(
'array()',
array(),
),
array(
// non-associative.
"array(\n 1,\n 2,\n 3,\n 4,\n)",
array(
1,
2,
3,
4,
),
),
array(
// associative.
"array(\n 'a' => 1,\n)",
array(
'a' => 1,
),
),
// Bool.
array(
'TRUE',
TRUE,
),
array(
'FALSE',
FALSE,
),
// Strings.
array(
"'string'",
'string',
),
array(
'"\\n\\r\\t"',
"\n\r\t",
),
array(
// 2 backslashes. \\
"'\\'",
'\\',
),
array(
// Double-quote "
"'\"'",
"\"",
),
array(
// Single-quote '
'"\'"',
"'",
),
array(
// Quotes with $ symbols.
'"\\$settings[\'foo\']"',
'$settings[\'foo\']',
),
// Object.
array(
// A stdClass object.
'(object) array()',
new \stdClass(),
),
array(
// A not-stdClass object.
"Drupal\\Tests\\Component\\Utility\\StubVariableTestClass::__set_state(array(\n))",
new StubVariableTestClass(),
),
);
}
/**
* Tests exporting variables.
*
* @dataProvider providerTestExport
* @covers ::export
*
* @param string $expected
* The expected exported variable.
* @param mixed $variable
* The variable to be exported.
*/
public function testExport($expected, $variable) {
$this
->assertEquals($expected, Variable::export($variable));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
UnitTestCase:: |
protected | function | 259 | |
VariableTest:: |
public | function | Data provider for testExport(). | |
VariableTest:: |
public | function | Tests exporting variables. |