Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
893ae862
Commit
893ae862
authored
11 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2023095
by damiankloip: Convert Drupal\views\Tests\PluginBaseTest to PHPUnit.
parent
088b191c
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/views/tests/Drupal/views/Tests/PluginBaseTest.php
+79
-37
79 additions, 37 deletions
...modules/views/tests/Drupal/views/Tests/PluginBaseTest.php
with
79 additions
and
37 deletions
core/modules/views/
lib
/Drupal/views/Tests/PluginBase
Unit
Test.php
→
core/modules/views/
tests
/Drupal/views/Tests/PluginBaseTest.php
+
79
−
37
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\Drupal
UnitTest
B
ase
;
use
Drupal\
Component\Plugin\Discovery\StaticDiscovery
;
use
Drupal\
Tests\
UnitTest
C
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
test
s
'
,
'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 s
etOptionDefault
method
.
*
Data provider for testS
etOptionDefault
()
.
*
* @
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
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment