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
1cb3315f
Unverified
Commit
1cb3315f
authored
5 years ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3041786
by claudiu.cristea, Lendude: Convert LatestRevisionFilterTest to a kernel test
parent
d88a43d4
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/Entity/LatestRevisionFilterTest.php
+31
-54
31 additions, 54 deletions
...iews/tests/src/Kernel/Entity/LatestRevisionFilterTest.php
with
31 additions
and
54 deletions
core/modules/views/tests/src/
Functiona
l/Entity/LatestRevisionFilterTest.php
→
core/modules/views/tests/src/
Kerne
l/Entity/LatestRevisionFilterTest.php
+
31
−
54
View file @
1cb3315f
<?php
namespace
Drupal\Tests\views\
Functiona
l\Entity
;
namespace
Drupal\Tests\views\
Kerne
l\Entity
;
use
Drupal\node\Entity\Node
;
use
Drupal\Tests\views\Functional\ViewTestBase
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\Tests\views\Kernel\ViewsKernelTestBase
;
use
Drupal\views\ViewExecutable
;
use
Drupal\views\Views
;
...
...
@@ -12,43 +13,26 @@
*
* @group views
*/
class
LatestRevisionFilterTest
extends
ViewTestBase
{
class
LatestRevisionFilterTest
extends
View
sKernel
TestBase
{
/**
* An array of node revisions.
*
* @var \Drupal\node\NodeInterface[]
*/
protected
$allRevisions
=
[];
/**
* An array of node revisions.
*
* @var \Drupal\node\NodeInterface[]
*/
protected
$latestRevisions
=
[];
/**
* Views used by this test.
*
* @var array
* {@inheritdoc}
*/
public
static
$testViews
=
[
'test_latest_revision_filter'
];
/**
* Modules to enable.
*
* @var array
* {@inheritdoc}
*/
public
static
$modules
=
[
'node'
];
/**
*
{@inheritdoc}
*
Tests the 'Latest revision' filter.
*/
protected
function
setUp
(
$import_test_views
=
TRUE
)
{
parent
::
setUp
();
$this
->
drupalCreateContentType
([
'type'
=>
'article'
]);
public
function
testLatestRevisionFilter
()
{
$this
->
installEntitySchema
(
'user'
);
$this
->
installEntitySchema
(
'node'
);
$this
->
installSchema
(
'node'
,
[
'node_access'
]);
NodeType
::
create
([
'type'
=>
'article'
])
->
save
();
// Create a node that goes through various default/pending revision stages.
$node
=
Node
::
create
([
...
...
@@ -56,26 +40,26 @@ protected function setUp($import_test_views = TRUE) {
'type'
=>
'article'
,
]);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$node
->
setTitle
(
'First node - v2 - pending'
);
$node
->
setNewRevision
(
TRUE
);
$node
->
isDefaultRevision
(
FALSE
);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$node
->
setTitle
(
'First node - v3 - default'
);
$node
->
setNewRevision
(
TRUE
);
$node
->
isDefaultRevision
(
TRUE
);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$node
->
setTitle
(
'First node - v4 - pending'
);
$node
->
setNewRevision
(
TRUE
);
$node
->
isDefaultRevision
(
TRUE
);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$
this
->
latest
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$latest
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
// Create a node that has a default and a pending revision.
$node
=
Node
::
create
([
...
...
@@ -83,14 +67,14 @@ protected function setUp($import_test_views = TRUE) {
'type'
=>
'article'
,
]);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$node
->
setTitle
(
'Second node - v2 - pending'
);
$node
->
setNewRevision
(
TRUE
);
$node
->
isDefaultRevision
(
FALSE
);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$
this
->
latest
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$latest
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
// Create a node that only has a default revision.
$node
=
Node
::
create
([
...
...
@@ -98,8 +82,8 @@ protected function setUp($import_test_views = TRUE) {
'type'
=>
'article'
,
]);
$node
->
save
();
$
this
->
all
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$
this
->
latest
R
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$all
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
$latest
_r
evisions
[
$node
->
getRevisionId
()]
=
$node
;
// Create a node that only has a pending revision.
$node
=
Node
::
create
([
...
...
@@ -108,24 +92,19 @@ protected function setUp($import_test_views = TRUE) {
]);
$node
->
isDefaultRevision
(
FALSE
);
$node
->
save
();
$this
->
allRevisions
[
$node
->
getRevisionId
()]
=
$node
;
$this
->
latestRevisions
[
$node
->
getRevisionId
()]
=
$node
;
}
$all_revisions
[
$node
->
getRevisionId
()]
=
$node
;
$latest_revisions
[
$node
->
getRevisionId
()]
=
$node
;
/**
* Tests the 'Latest revision' filter.
*/
public
function
testLatestRevisionFilter
()
{
$view
=
Views
::
getView
(
'test_latest_revision_filter'
);
$this
->
executeView
(
$view
);
// Check that we have all the results.
$this
->
assertCount
(
count
(
$
this
->
latest
R
evisions
),
$view
->
result
);
$this
->
assertCount
(
count
(
$latest
_r
evisions
),
$view
->
result
);
$expected
=
$not_expected
=
[];
foreach
(
$
this
->
all
R
evisions
as
$revision_id
=>
$revision
)
{
if
(
isset
(
$
this
->
latest
R
evisions
[
$revision_id
]))
{
foreach
(
$all
_r
evisions
as
$revision_id
=>
$revision
)
{
if
(
isset
(
$latest
_r
evisions
[
$revision_id
]))
{
$expected
[]
=
[
'vid'
=>
$revision_id
,
'title'
=>
$revision
->
label
(),
...
...
@@ -136,25 +115,23 @@ public function testLatestRevisionFilter() {
}
}
$this
->
assertIdenticalResultset
(
$view
,
$expected
,
[
'vid'
=>
'vid'
,
'title'
=>
'title'
],
'The test view only shows the latest revisions.'
);
$this
->
assertNotInResultSet
(
$view
,
$not_expected
,
'Non-latest revisions are not shown by the view.'
);
$this
->
assertNotInResultSet
(
$view
,
$not_expected
);
$view
->
destroy
();
}
/**
*
Verifie
s that a list of revision IDs are not in the result.
*
Assert
s that a list of revision IDs are not in the result.
*
* @param \Drupal\views\ViewExecutable $view
* An executed View.
* @param array $not_expected_revision_ids
* An array of revision IDs which should not be part of the result set.
* @param string $message
* (optional) A custom message to display with the assertion.
*/
protected
function
assertNotInResultSet
(
ViewExecutable
$view
,
array
$not_expected_revision_ids
,
$message
=
''
)
{
protected
function
assertNotInResultSet
(
ViewExecutable
$view
,
array
$not_expected_revision_ids
)
{
$found_revision_ids
=
array_filter
(
$view
->
result
,
function
(
$row
)
use
(
$not_expected_revision_ids
)
{
return
in_array
(
$row
->
vid
,
$not_expected_revision_ids
);
});
$this
->
assertFalse
(
$found_revision_ids
,
$message
);
$this
->
assertFalse
(
$found_revision_ids
);
}
}
This diff is collapsed.
Click to expand it.
Alex Pott
@alexpott
mentioned in commit
33bbfa4f
·
5 years ago
mentioned in commit
33bbfa4f
mentioned in commit 33bbfa4f32c3afa80578093981006b811c63e65c
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