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
a07965a6
Unverified
Commit
a07965a6
authored
5 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3041801
by claudiu.cristea, Lendude: Convert StyleTest to a kernel test
parent
758cb9df
No related branches found
Branches containing commit
No related tags found
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/src/Kernel/Plugin/StyleTest.php
+35
-44
35 additions, 44 deletions
core/modules/views/tests/src/Kernel/Plugin/StyleTest.php
with
35 additions
and
44 deletions
core/modules/views/tests/src/
Functiona
l/Plugin/StyleTest.php
→
core/modules/views/tests/src/
Kerne
l/Plugin/StyleTest.php
+
35
−
44
View file @
a07965a6
<?php
namespace
Drupal\Tests\views\
Functiona
l\Plugin
;
namespace
Drupal\Tests\views\
Kerne
l\Plugin
;
use
Drupal\Tests\views\
Functional\View
TestBase
;
use
Drupal\Tests\views\
Kernel\ViewsKernel
TestBase
;
use
Drupal\views\Views
;
use
Drupal\views_test_data
\Plugin\views\row\RowTest
;
use
Drupal\views\Plugin\views\row\Fields
;
...
...
@@ -13,35 +13,20 @@
* Tests general style functionality.
*
* @group views
*
* @see \Drupal\views_test_data\Plugin\views\style\StyleTest.
*/
class
StyleTest
extends
ViewTestBase
{
class
StyleTest
extends
View
sKernel
TestBase
{
/**
* Views used by this test.
*
* @var array
* {@inheritdoc}
*/
public
static
$testViews
=
[
'test_view'
];
/**
* Stores the SimpleXML representation of the output.
*
* @var \SimpleXMLElement
*/
protected
$elements
;
protected
function
setUp
(
$import_test_views
=
TRUE
)
{
parent
::
setUp
(
$import_test_views
);
$this
->
enableViewsTestModule
();
}
/**
* Tests the general rendering of styles.
*/
public
function
testStyle
()
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer
=
$this
->
container
->
get
(
'renderer'
);
// This run use the test row plugin and render with it.
...
...
@@ -57,14 +42,14 @@ public function testStyle() {
$view
->
initStyle
();
// Reinitialize the style as it supports row plugins now.
$view
->
style_plugin
->
init
(
$view
,
$view
->
display_handler
);
$this
->
assert
True
(
$view
->
rowPlugin
i
nstance
of
Row
T
est
,
'Make sure the right
row
p
lugin
class is loaded.'
);
$this
->
assert
I
nstance
Of
(
Row
t
est
::
class
,
$view
->
row
P
lugin
);
$random_text
=
$this
->
randomMachineName
();
$view
->
rowPlugin
->
setOutput
(
$random_text
);
$output
=
$view
->
preview
();
$output
=
$renderer
->
renderRoot
(
$output
);
$this
->
assert
True
(
strpos
(
$output
,
$random_text
)
!==
FALSE
,
'Make sure that the rendering of the row plugin appears in the output of the view.'
);
$this
->
assert
Contains
(
$random_text
,
(
string
)
$output
);
// Test without row plugin support.
$view
=
Views
::
getView
(
'test_view'
);
...
...
@@ -75,8 +60,8 @@ public function testStyle() {
$view
->
initDisplay
();
$view
->
initStyle
();
$view
->
style_plugin
->
setUsesRowPlugin
(
FALSE
);
$this
->
assert
True
(
$view
->
style_plugin
i
nstance
of
StyleTestPlugin
,
'Make sure the right
style
plugin
class is loaded.'
);
$this
->
assert
True
(
$view
->
rowPlugin
i
nstance
of
Fields
,
'Make sure that rowPlugin is now a fields instance.'
);
$this
->
assert
I
nstance
Of
(
StyleTestPlugin
::
class
,
$view
->
style
_
plugin
);
$this
->
assert
I
nstance
Of
(
Fields
::
class
,
$view
->
rowPlugin
);
$random_text
=
$this
->
randomMachineName
();
// Set some custom text to the output and make sure that this value is
...
...
@@ -84,18 +69,21 @@ public function testStyle() {
$view
->
style_plugin
->
setOutput
(
$random_text
);
$output
=
$view
->
preview
();
$output
=
$renderer
->
renderRoot
(
$output
);
$this
->
assert
True
(
strpos
(
$output
,
$random_text
)
!==
FALSE
,
'Make sure that the rendering of the style plugin appears in the output of the view.'
);
$this
->
assert
Contains
(
$random_text
,
(
string
)
$output
);
}
/**
* Tests the grouping features of styles.
*/
public
function
testGrouping
()
{
$this
->
_t
estGrouping
(
FALSE
);
$this
->
_t
estGrouping
(
TRUE
);
$this
->
doT
estGrouping
(
FALSE
);
$this
->
doT
estGrouping
(
TRUE
);
}
/**
*
Tests the grouping features of styles
.
*
Provides reusable code for ::testGrouping()
.
*/
p
ublic
function
_t
estGrouping
(
$stripped
=
FALSE
)
{
p
rotected
function
doT
estGrouping
(
$stripped
=
FALSE
)
{
$view
=
Views
::
getView
(
'test_view'
);
$view
->
setDisplay
();
// Setup grouping by the job and the age field.
...
...
@@ -175,7 +163,6 @@ public function _testGrouping($stripped = FALSE) {
// Alter the results to support the stripped case.
if
(
$stripped
)
{
// Add some html to the result and expected value.
$rand1
=
'<a data="'
.
$this
->
randomMachineName
()
.
'" />'
;
$view
->
result
[
0
]
->
views_test_data_job
.
=
$rand1
;
...
...
@@ -196,7 +183,7 @@ public function _testGrouping($stripped = FALSE) {
// The newer api passes the value of the grouping as well.
$sets_new_rendered
=
$view
->
style_plugin
->
renderGrouping
(
$view
->
result
,
$view
->
style_plugin
->
options
[
'grouping'
],
TRUE
);
$this
->
assertEqual
(
$sets_new_rendered
,
$expected
,
'The style plugins should properly group the results with grouping by the rendered output.'
);
$this
->
assertEqual
s
(
$expected
,
$sets_new_rendered
);
// Don't test stripped case, because the actual value is not stripped.
if
(
!
$stripped
)
{
...
...
@@ -215,7 +202,7 @@ public function _testGrouping($stripped = FALSE) {
unset
(
$new_expected
[
'Job: Drummer'
]);
unset
(
$new_expected
[
'Drummer'
][
'rows'
][
'Age: 28'
]);
$this
->
assertEqual
(
$
sets_new_value
,
$new_expected
,
'The style plugins should proper group the results with grouping by the
value
.'
);
$this
->
assertEqual
s
(
$
new_expected
,
$sets_new_
value
);
}
// Test that grouping works on fields having no label.
...
...
@@ -248,11 +235,11 @@ public function _testGrouping($stripped = FALSE) {
$data
[
'group'
]
=
$job
;
$expected
[
$job
]
=
$data
;
}
$this
->
assertEqual
(
$expected
,
$sets_new_rendered
);
$this
->
assertEqual
s
(
$expected
,
$sets_new_rendered
);
}
/**
* Tests custom
css
classes.
* Tests custom
CSS row
classes.
*/
public
function
testCustomRowClasses
()
{
$view
=
Views
::
getView
(
'test_view'
);
...
...
@@ -264,34 +251,38 @@ public function testCustomRowClasses() {
$view
->
style_plugin
->
options
[
'row_class'
]
=
$random_name
.
" test-token-{{ name }}"
;
$output
=
$view
->
preview
();
$
this
->
storeViewPreview
(
\Drupal
::
service
(
'renderer'
)
->
renderRoot
(
$output
));
$
html_dom
=
$this
->
getHtmlDom
(
$this
->
container
->
get
(
'renderer'
)
->
renderRoot
(
$output
));
$rows
=
$
this
->
elements
->
body
->
div
->
div
->
div
;
$rows
=
$
html_dom
->
body
->
div
->
div
;
$count
=
0
;
foreach
(
$rows
as
$row
)
{
$attributes
=
$row
->
attributes
();
$class
=
(
string
)
$attributes
[
'class'
][
0
];
$this
->
assert
True
(
strpos
(
$class
,
$random_name
)
!==
FALSE
,
'Make sure that a custom css class is added to the output.'
);
$this
->
assert
Contains
(
$random_name
,
$class
);
// Check token replacement.
$name
=
$view
->
field
[
'name'
]
->
getValue
(
$view
->
result
[
$count
]);
$this
->
assert
True
(
strpos
(
$class
,
"test-token-
$name
"
)
!==
FALSE
,
'Make sure that a token in custom css class is replaced.'
);
$this
->
assert
Contains
(
"test-token-
$name
"
,
$class
);
$count
++
;
}
}
/**
* Stores a view output in the elements.
* Returns a view output as SimpleXMLElement.
*
* @return \SimpleXMLElement|null
* The HTML DOM.
*/
protected
function
storeViewPreview
(
$output
)
{
$html
D
om
=
new
\DOMDocument
();
@
$html
D
om
->
loadHTML
(
$output
);
if
(
$html
D
om
)
{
protected
function
getHtmlDom
(
$output
)
{
$html
_d
om
=
new
\DOMDocument
();
@
$html
_d
om
->
loadHTML
(
$output
);
if
(
$html
_d
om
)
{
// It's much easier to work with simplexml than DOM, luckily enough
// we can just simply import our DOM tree.
$this
->
elements
=
simplexml_import_dom
(
$html
D
om
);
return
simplexml_import_dom
(
$html
_d
om
);
}
return
NULL
;
}
}
This diff is collapsed.
Click to expand it.
Alex Pott
@alexpott
mentioned in commit
3759538d
·
5 years ago
mentioned in commit
3759538d
mentioned in commit 3759538d4391cc60cef76b87d6e8a60743eb00df
Toggle commit list
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