Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
310
Merge Requests
310
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
893ae862
Commit
893ae862
authored
Jun 22, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2023095
by damiankloip: Convert Drupal\views\Tests\PluginBaseTest to PHPUnit.
parent
088b191c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
37 deletions
+79
-37
core/modules/views/tests/Drupal/views/Tests/PluginBaseTest.php
...modules/views/tests/Drupal/views/Tests/PluginBaseTest.php
+79
-37
No files found.
core/modules/views/
lib/Drupal/views/Tests/PluginBaseUnit
Test.php
→
core/modules/views/
tests/Drupal/views/Tests/PluginBase
Test.php
View file @
893ae862
...
...
@@ -2,37 +2,93 @@
/**
* @file
* Contains \Drupal\views\Tests\PluginBase
Unit
Test.
* Contains \Drupal\views\Tests\PluginBaseTest.
*/
namespace
Drupal\views\Tests
;
use
Drupal\
simpletest\DrupalUnitTestB
ase
;
use
Drupal\
Component\Plugin\Discovery\StaticDiscovery
;
use
Drupal\
Tests\UnitTestC
ase
;
use
Drupal\
views\Tests\TestHelperPlugin
;
/**
* Tests code of the views plugin base class.
*
* @see \Drupal\views\Plugin\views\PluginBase.
*/
class
PluginBaseUnitTest
extends
DrupalUnitTestBase
{
class
PluginBaseTest
extends
UnitTestCase
{
/**
* The test helper plugin to use for the tests.
*
* @var \Drupal\views\Tests\TestHelperPlugin
*/
protected
$testHelperPlugin
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Plugin base
unit tests
'
,
'name'
=>
'Plugin base
test
'
,
'description'
=>
'Tests code of the views plugin base class.'
,
'group'
=>
'Views Plugins'
,
);
}
/**
* {@inheritdoc}
*/
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
testHelperPlugin
=
new
TestHelperPlugin
(
array
(),
'default'
,
array
());
}
/**
* Tests the unpackOptions method.
*
* @param array $storage
* The storage array to unpack option into.
* @param array $options
* The array of options to unpack.
* @param array $definition
* The definition array, defining default options.
* @param array $expected
* The expected array after unpacking
* @param bool $all
* Whether to unpack all options.
*
* @see \Drupal\views\Plugin\views\PluginBase::unpackOptions.
*
* @dataProvider providerTestUnpackOptions
*/
public
function
testUnpackOptions
(
$storage
,
$options
,
$definition
,
$expected
,
$all
=
FALSE
)
{
$this
->
testHelperPlugin
->
unpackOptions
(
$storage
,
$options
,
$definition
,
$all
);
$this
->
assertEquals
(
$storage
,
$expected
);
}
/**
* Tests the setOptionDefault method.
*
* @param array $storage
* The storage array to unpack option into.
* @param array $definition
* The definition array, defining default options.
* @param array $expected
* The expected array after unpacking
*
* @see \Drupal\views\Plugin\views\PluginBase::setOptionDefaults.
*
* @dataProvider providerTestSetOptionDefault
*/
public
function
testUnpackOptions
()
{
$plugin
=
$this
->
getTestPlugin
();
public
function
testSetOptionDefault
(
$storage
,
$definition
,
$expected
)
{
$this
->
testHelperPlugin
->
testSetOptionDefaults
(
$storage
,
$definition
);
$this
->
assertEquals
(
$storage
,
$expected
);
}
/**
* Data provider for testUnpackOptions().
*
* @return array
*/
public
function
providerTestUnpackOptions
()
{
$test_parameters
=
array
();
// Set a storage but no value, so the storage value should be kept.
$test_parameters
[]
=
array
(
...
...
@@ -66,6 +122,7 @@ public function testUnpackOptions() {
);
// Set no storage but an options value, so the options value should be kept.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key'
=>
'value'
,
),
...
...
@@ -79,6 +136,7 @@ public function testUnpackOptions() {
// Set additional options, which aren't part of the definition, so they
// should be ignored if all is set.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key'
=>
'value'
,
'key2'
=>
'value2'
,
...
...
@@ -91,6 +149,7 @@ public function testUnpackOptions() {
),
);
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key'
=>
'value'
,
'key2'
=>
'value2'
,
...
...
@@ -106,6 +165,7 @@ public function testUnpackOptions() {
);
// Provide multiple options with their corresponding definition.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key'
=>
'value'
,
'key2'
=>
'value2'
,
...
...
@@ -121,6 +181,7 @@ public function testUnpackOptions() {
);
// Set a complex definition structure with a zero and a one level structure.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key0'
=>
'value'
,
'key1'
=>
array
(
'key1:1'
=>
'value1'
,
'key1:2'
=>
'value2'
),
...
...
@@ -138,6 +199,7 @@ public function testUnpackOptions() {
);
// Setup a two level structure.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'options'
=>
array
(
'key2'
=>
array
(
'key2:1'
=>
array
(
...
...
@@ -170,31 +232,25 @@ public function testUnpackOptions() {
),
);
foreach
(
$test_parameters
as
$parameter
)
{
$parameter
+=
array
(
'storage'
=>
array
(),
);
$plugin
->
unpackOptions
(
$parameter
[
'storage'
],
$parameter
[
'options'
],
$parameter
[
'definition'
],
!
empty
(
$parameter
[
'all'
]));
$this
->
assertEqual
(
$parameter
[
'storage'
],
$parameter
[
'expected'
]);
}
return
$test_parameters
;
}
/**
*
Tests the setOptionDefault method
.
*
Data provider for testSetOptionDefault()
.
*
* @
see \Drupal\views\Plugin\views\PluginBase::setOptionDefaults.
* @
return array
*/
public
function
testSetOptionDefault
()
{
$plugin
=
$this
->
getTestPlugin
();
public
function
providerTestSetOptionDefault
()
{
$test_parameters
=
array
();
// No definition
mustn't
change anything on the storage.
// No definition
should
change anything on the storage.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'definition'
=>
array
(),
'expected'
=>
array
(),
);
// Set a single definition, which should be picked up.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'definition'
=>
array
(
'key'
=>
array
(
'default'
=>
'value'
),
),
...
...
@@ -204,6 +260,7 @@ public function testSetOptionDefault() {
);
// Set multiple keys, all should be picked up.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'definition'
=>
array
(
'key'
=>
array
(
'default'
=>
'value'
),
'key2'
=>
array
(
'default'
=>
'value2'
),
...
...
@@ -217,6 +274,7 @@ public function testSetOptionDefault() {
);
// Setup a definition with multiple levels.
$test_parameters
[]
=
array
(
'storage'
=>
array
(),
'definition'
=>
array
(
'key'
=>
array
(
'default'
=>
'value'
),
'key2'
=>
array
(
'contains'
=>
array
(
...
...
@@ -233,23 +291,7 @@ public function testSetOptionDefault() {
),
);
foreach
(
$test_parameters
as
$parameter
)
{
$parameter
+=
array
(
'storage'
=>
array
(),
);
$plugin
->
testSetOptionDefaults
(
$parameter
[
'storage'
],
$parameter
[
'definition'
]);
$this
->
assertEqual
(
$parameter
[
'storage'
],
$parameter
[
'expected'
]);
}
}
/**
* Sets up and returns a basic instance of a plugin.
*
* @return \Drupal\views\Tests\TestHelperPlugin
* A test plugin instance.
*/
protected
function
getTestPlugin
()
{
return
new
TestHelperPlugin
(
array
(),
'default'
,
array
());
return
$test_parameters
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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