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
e14fbaa3
Commit
e14fbaa3
authored
12 years ago
by
Salvador Molina
Committed by
Tim Plunkett
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1758486
by slv_, dawehner, aspilicious: Write tests for the recent comments view.
parent
6efde1f2
No related branches found
Branches containing commit
Tags
11-80253
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
lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php
+158
-0
158 additions, 0 deletions
lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php
with
158 additions
and
0 deletions
lib/Drupal/views/Tests/Comment/DefaultViewRecentComments.php
0 → 100644
+
158
−
0
View file @
e14fbaa3
<?php
/**
* @file
* Definition of Drupal\views\Tests\Comment\DefaultViewRecentComments.
*/
namespace
Drupal\views\Tests\Comment
;
use
Drupal\entity\DatabaseStorageController
;
use
Drupal\views\Tests\ViewTestBase
;
class
DefaultViewRecentComments
extends
ViewTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
array
(
'comment'
,
'block'
);
/**
* Number of results for the Master display.
*
* @var int
*/
protected
$masterDisplayResults
=
5
;
/**
* Number of results for the Block display.
*
* @var int
*/
protected
$blockDisplayResults
=
5
;
/**
* Number of results for the Page display.
*
* @var int
*/
protected
$pageDisplayResults
=
5
;
/**
* Will hold the comments created for testing.
*
* @var array
*/
protected
$commentsCreated
=
array
();
/**
* Contains the node object used for comments of this test.
*
* @var Drupal\node\Node
*/
public
$node
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Default View - Recent Comments'
,
'description'
=>
'Test results for the Recent Comments view shipped with the module'
,
'group'
=>
'Views Config'
,
);
}
public
function
setUp
()
{
parent
::
setUp
();
// Create a new content type
$content_type
=
$this
->
drupalCreateContentType
();
// Add a node of the new content type.
$node_data
=
array
(
'type'
=>
$content_type
->
type
,
);
$this
->
node
=
$this
->
drupalCreateNode
(
$node_data
);
// Create some comments and attach them to the created node.
for
(
$i
=
0
;
$i
<
$this
->
masterDisplayResults
;
$i
++
)
{
$comment
=
entity_create
(
'comment'
,
array
());
$comment
->
uid
=
0
;
$comment
->
nid
=
$this
->
node
->
nid
;
$comment
->
subject
=
'Test comment '
.
$i
;
$comment
->
node_type
=
'comment_node_'
.
$this
->
node
->
type
;
$comment
->
comment_body
[
LANGUAGE_NOT_SPECIFIED
][
0
][
'value'
]
=
'Test body '
.
$i
;
$comment
->
comment_body
[
LANGUAGE_NOT_SPECIFIED
][
0
][
'format'
]
=
'full_html'
;
comment_save
(
$comment
);
}
// Store all the nodes just created to access their properties on the tests.
$this
->
commentsCreated
=
entity_load_multiple
(
'comment'
);
}
/**
* Tests the block defined by the comments_recent view.
*/
public
function
testBlockDisplay
()
{
$view
=
views_get_view
(
'comments_recent'
);
$view
->
setDisplay
(
'block'
);
$this
->
executeView
(
$view
);
$map
=
array
(
'comment_nid'
=>
'nid'
,
'comment_subject'
=>
'subject'
,
'cid'
=>
'cid'
,
'comment_changed'
=>
'changed'
);
$expected_result
=
array
();
foreach
(
array_values
(
$this
->
commentsCreated
)
as
$key
=>
$comment
)
{
$expected_result
[
$key
][
'nid'
]
=
$comment
->
nid
;
$expected_result
[
$key
][
'subject'
]
=
$comment
->
subject
;
$expected_result
[
$key
][
'cid'
]
=
$comment
->
cid
;
$expected_result
[
$key
][
'changed'
]
=
$comment
->
changed
;
}
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$map
);
// Check the number of results given by the display is the expected.
$this
->
assertEqual
(
sizeof
(
$view
->
result
),
$this
->
blockDisplayResults
,
format_string
(
'There are exactly @results comments. Expected @expected'
,
array
(
'@results'
=>
count
(
$view
->
result
),
'@expected'
=>
$this
->
blockDisplayResults
)
)
);
}
/**
* Tests the page defined by the comments_recent view.
*/
public
function
testPageDisplay
()
{
$view
=
views_get_view
(
'comments_recent'
);
$view
->
setDisplay
(
'page'
);
$this
->
executeView
(
$view
);
$map
=
array
(
'comment_nid'
=>
'nid'
,
'comment_subject'
=>
'subject'
,
'comment_changed'
=>
'changed'
,
'comment_changed'
=>
'created'
,
'cid'
=>
'cid'
);
$expected_result
=
array
();
foreach
(
array_values
(
$this
->
commentsCreated
)
as
$key
=>
$comment
)
{
$expected_result
[
$key
][
'nid'
]
=
$comment
->
nid
;
$expected_result
[
$key
][
'subject'
]
=
$comment
->
subject
;
$expected_result
[
$key
][
'changed'
]
=
$comment
->
changed
;
$expected_result
[
$key
][
'created'
]
=
$comment
->
created
;
$expected_result
[
$key
][
'cid'
]
=
$comment
->
cid
;
}
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$map
);
// Check the number of results given by the display is the expected.
$this
->
assertEqual
(
count
(
$view
->
result
),
$this
->
pageDisplayResults
,
format_string
(
'There are exactly @results comments. Expected @expected'
,
array
(
'@results'
=>
count
(
$view
->
result
),
'@expected'
=>
$this
->
pageDisplayResults
)
)
);
}
}
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