class VariableTest

Same name in this branch
  1. 8.9.x core/modules/migrate_drupal/tests/src/Unit/source/VariableTest.php \Drupal\Tests\migrate_drupal\Unit\source\VariableTest
  2. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\VariableTest
Same name and namespace in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\VariableTest
  2. 9 core/tests/Drupal/Tests/Component/Utility/VariableTest.php \Drupal\Tests\Component\Utility\VariableTest
  3. 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\VariableTest
  4. 10 core/tests/Drupal/Tests/Component/Utility/VariableTest.php \Drupal\Tests\Component\Utility\VariableTest
  5. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/VariableTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\VariableTest
  6. 11.x 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\Component\Utility\VariableTest extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of VariableTest

File

core/tests/Drupal/Tests/Component/Utility/VariableTest.php, line 21

Namespace

Drupal\Tests\Component\Utility
View source
class VariableTest extends TestCase {
    
    /**
     * Data provider for testExport().
     *
     * @return array
     *   An array containing:
     *     - The expected export string.
     *     - The variable to export.
     */
    public function providerTestExport() {
        return [
            // Array.
[
                'array()',
                [],
            ],
            [
                // non-associative.
"array(\n  1,\n  2,\n  3,\n  4,\n)",
                [
                    1,
                    2,
                    3,
                    4,
                ],
            ],
            [
                // associative.
"array(\n  'a' => 1,\n)",
                [
                    'a' => 1,
                ],
            ],
            // Bool.
[
                'TRUE',
                TRUE,
            ],
            [
                'FALSE',
                FALSE,
            ],
            // Strings.
[
                "'string'",
                'string',
            ],
            [
                '"\\n\\r\\t"',
                "\n\r\t",
            ],
            [
                // 2 backslashes. \\
"'\\'",
                '\\',
            ],
            [
                // Double-quote "
"'\"'",
                "\"",
            ],
            [
                // Single-quote '
'"\'"',
                "'",
            ],
            [
                // Quotes with $ symbols.
'"\\$settings[\'foo\']"',
                '$settings[\'foo\']',
            ],
            // Object.
[
                // A stdClass object.
'(object) array()',
                new \stdClass(),
            ],
            [
                // 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

Title Sort descending Modifiers Object type Summary
VariableTest::providerTestExport public function Data provider for testExport().
VariableTest::testExport public function Tests exporting variables.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.