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
ddf59196
Commit
ddf59196
authored
15 years ago
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#520740
by marcingy, catch, and Damien Tournoud: Fixed Comment threading (with test).
parent
b2ee71c1
No related branches found
No related tags found
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
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/entity.inc
+10
-10
10 additions, 10 deletions
includes/entity.inc
modules/comment/comment.test
+100
-0
100 additions, 0 deletions
modules/comment/comment.test
with
110 additions
and
10 deletions
includes/entity.inc
+
10
−
10
View file @
ddf59196
...
...
@@ -100,7 +100,6 @@ public function load($ids = array(), $conditions = array()) {
$this
->
revisionId
=
FALSE
;
}
// Create a new variable which is either a prepared version of the $ids
// array for later comparison with the entity cache, or FALSE if no $ids
// were passed. The $ids array is reduced as items are loaded from cache,
...
...
@@ -141,16 +140,17 @@ public function load($ids = array(), $conditions = array()) {
if
(
!
empty
(
$queried_entities
)
&&
!
$this
->
revisionId
)
{
$this
->
cacheSet
(
$queried_entities
);
}
// Ensure that the returned array is ordered the same as the original
// $ids array if this was passed in and remove any invalid ids.
if
(
$passed_ids
)
{
// R
emove any invalid ids
from the array
.
$passed_ids
=
array_intersect_key
(
$passed_ids
,
$entities
);
foreach
(
$entities
as
$entity
)
{
$passed_ids
[
$entity
->
{
$this
->
idKey
}]
=
$entit
y
;
}
$
entities
=
$passed_ids
;
}
// Ensure that the returned array is ordered the same as the original
// $ids array if this was passed in and r
emove any invalid ids.
if
(
$passed_ids
)
{
// Remove any invalid ids from the array.
$passed_ids
=
array_intersect_key
(
$passed_ids
,
$entit
ies
)
;
foreach
(
$entities
as
$entity
)
{
$
passed_ids
[
$entity
->
{
$this
->
idKey
}]
=
$entity
;
}
$entities
=
$passed_ids
;
}
return
$entities
;
...
...
This diff is collapsed.
Click to expand it.
modules/comment/comment.test
+
100
−
0
View file @
ddf59196
...
...
@@ -660,6 +660,106 @@ class CommentPagerTest extends CommentHelperCase {
$this
->
drupalLogout
();
}
/**
* Test comment ordering and threading.
*/
function
testCommentOrderingThreading
()
{
$this
->
drupalLogin
(
$this
->
admin_user
);
// Set comment variables.
$this
->
setCommentForm
(
TRUE
);
$this
->
setCommentSubject
(
TRUE
);
$this
->
setCommentPreview
(
FALSE
);
// Display all the comments on the same page.
$this
->
setCommentsPerPage
(
1000
);
// Create a node and three comments.
$node
=
$this
->
drupalCreateNode
(
array
(
'type'
=>
'article'
,
'promote'
=>
1
));
$comments
=
array
();
$comments
[]
=
$this
->
postComment
(
$node
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
$comments
[]
=
$this
->
postComment
(
$node
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
$comments
[]
=
$this
->
postComment
(
$node
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
// Post a reply to the second comment.
$this
->
drupalGet
(
'comment/reply/'
.
$node
->
nid
.
'/'
.
$comments
[
1
]
->
id
);
$comments
[]
=
$this
->
postComment
(
NULL
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
// Post a reply to the first comment.
$this
->
drupalGet
(
'comment/reply/'
.
$node
->
nid
.
'/'
.
$comments
[
0
]
->
id
);
$comments
[]
=
$this
->
postComment
(
NULL
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
// Post a reply to the last comment.
$this
->
drupalGet
(
'comment/reply/'
.
$node
->
nid
.
'/'
.
$comments
[
2
]
->
id
);
$comments
[]
=
$this
->
postComment
(
NULL
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
// Post a reply to the second comment.
$this
->
drupalGet
(
'comment/reply/'
.
$node
->
nid
.
'/'
.
$comments
[
3
]
->
id
);
$comments
[]
=
$this
->
postComment
(
NULL
,
$this
->
randomName
(),
$this
->
randomName
(),
TRUE
);
// At this point, the comment tree is:
// - 0
// - 4
// - 1
// - 3
// - 6
// - 2
// - 5
$this
->
setCommentSettings
(
'comment_default_mode'
,
COMMENT_MODE_FLAT
,
t
(
'Comment paging changed.'
));
$expected_order
=
array
(
0
,
1
,
2
,
3
,
4
,
5
,
6
,
);
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertCommentOrder
(
$comments
,
$expected_order
);
$this
->
setCommentSettings
(
'comment_default_mode'
,
COMMENT_MODE_THREADED
,
t
(
'Switched to threaded mode.'
));
$expected_order
=
array
(
0
,
4
,
1
,
3
,
6
,
2
,
5
,
);
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertCommentOrder
(
$comments
,
$expected_order
);
}
/**
* Helper function: assert that the comments are displayed in the correct order.
*
* @param $comments
* And array of comments.
* @param $expected_order
* An array of keys from $comments describing the expected order.
*/
function
assertCommentOrder
(
array
$comments
,
array
$expected_order
)
{
$expected_cids
=
array
();
// First, rekey the expected order by cid.
foreach
(
$expected_order
as
$key
)
{
$expected_cids
[]
=
$comments
[
$key
]
->
id
;
}
$comment_anchors
=
$this
->
xpath
(
"//a[starts-with(@id,'comment-')]"
);
$result_order
=
array
();
foreach
(
$comment_anchors
as
$anchor
)
{
$result_order
[]
=
substr
(
$anchor
[
'id'
],
8
);
}
return
$this
->
assertIdentical
(
$expected_cids
,
$result_order
,
t
(
'Comment order: expected @expected, returned @returned.'
,
array
(
'@expected'
=>
implode
(
','
,
$expected_cids
),
'@returned'
=>
implode
(
','
,
$result_order
))));
}
}
class
CommentApprovalTest
extends
CommentHelperCase
{
...
...
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