5 * Contains \Drupal\Tests\Component\Utility\VariableTest.
8 namespace Drupal\Tests\Component\Utility;
10 use Drupal\Component\Utility\Variable;
11 use PHPUnit\Framework\TestCase;
14 * Test variable export functionality in Variable component.
19 * @coversDefaultClass \Drupal\Component\Utility\Variable
21 class VariableTest extends TestCase {
24 * Data provider for testExport().
27 * An array containing:
28 * - The expected export string.
29 * - The variable to export.
31 public function providerTestExport() {
40 "array(\n 1,\n 2,\n 3,\n 4,\n)",
45 "array(\n 'a' => 1,\n)",
82 // Quotes with $ symbols.
83 '"\$settings[\'foo\']"',
93 // A not-stdClass object.
94 "Drupal\Tests\Component\Utility\StubVariableTestClass::__set_state(array(\n))",
95 new StubVariableTestClass(),
101 * Tests exporting variables.
103 * @dataProvider providerTestExport
106 * @param string $expected
107 * The expected exported variable.
108 * @param mixed $variable
109 * The variable to be exported.
111 public function testExport($expected, $variable) {
112 $this->assertEquals($expected, Variable::export($variable));
118 * No-op test class for VariableTest::testExport().
120 * @see Drupal\Tests\Component\Utility\VariableTest::testExport()
121 * @see Drupal\Tests\Component\Utility\VariableTest::providerTestExport()
123 class StubVariableTestClass {