Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
55240a04
Commit
55240a04
authored
Jul 13, 2014
by
Alex Pott
Browse files
Issue
#2163245
by Mile23: Unit testing for \Drupal\Component\Utility\Variable.
parent
3c305393
Changes
1
Hide whitespace changes
Inline
Side-by-side
core/tests/Drupal/Tests/Component/Utility/VariableTest.php
0 → 100644
View file @
55240a04
<?php
/**
* @file
* Contains \Drupal\Tests\Component\Utility\VariableTest.
*/
namespace
Drupal\Tests\Component\Utility
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\Component\Utility\Variable
;
/**
* Test variable export functionality in Variable component.
*
* @group Variable
* @group Utility
*
* @coversDefaultClass \Drupal\Component\Utility\Variable
*/
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 '
'"\'"'
,
"'"
,
),
// 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
));
}
}
/**
* No-op test class for VariableTest::testExport().
*
* @see Drupal\Tests\Component\Utility\VariableTest::testExport()
* @see Drupal\Tests\Component\Utility\VariableTest::providerTestExport()
*/
class
StubVariableTestClass
{
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment