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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
ccd6fb62
Commit
ccd6fb62
authored
Sep 9, 2010
by
Angie Byron
Browse files
Options
Downloads
Patches
Plain Diff
#903110
by bojanz: Fixed Multiple pager support is partially broken. (with tests)
parent
eaee909a
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
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
includes/pager.inc
+15
-5
15 additions, 5 deletions
includes/pager.inc
modules/simpletest/tests/database_test.test
+37
-0
37 additions, 0 deletions
modules/simpletest/tests/database_test.test
with
52 additions
and
5 deletions
includes/pager.inc
+
15
−
5
View file @
ccd6fb62
...
...
@@ -82,17 +82,17 @@ public function execute() {
/**
* Ensure that there is an element associated with this query.
* If an element was not specified previously, then the value of the
* $maxElement counter is taken, after which the counter is incremented.
*
* After running this
query
, access $this->element to get the element for this
* After running this
method
, access $this->element to get the element for this
* query.
*/
protected
function
ensureElement
()
{
if
(
!
empty
(
$this
->
element
))
{
return
;
}
if
(
!
isset
(
$this
->
element
))
{
$this
->
element
=
self
::
$maxElement
++
;
}
}
/**
* Specify the count query object to use for this pager.
...
...
@@ -149,10 +149,20 @@ public function limit($limit = 10) {
* whatever reason you want to explicitly define an element for a given query,
* you may do so here.
*
* Setting the element here also increments the static $maxElement counter,
* which is used for determining the $element when there's none specified.
*
* Note that no collision detection is done when setting an element ID
* explicitly, so it is possible for two pagers to end up using the same ID
* if both are set explicitly.
*
* @param $element
*/
public
function
element
(
$element
)
{
$this
->
element
=
$element
;
if
(
$element
>=
self
::
$maxElement
)
{
self
::
$maxElement
=
$element
+
1
;
}
return
$this
;
}
}
...
...
This diff is collapsed.
Click to expand it.
modules/simpletest/tests/database_test.test
+
37
−
0
View file @
ccd6fb62
...
...
@@ -2216,6 +2216,43 @@ class DatabaseSelectPagerDefaultTestCase extends DatabaseTestCase {
->
fetchCol
();
$this
->
assertEqual
(
$ages
,
array
(
'George'
,
'Ringo'
),
t
(
'Pager query with having expression returned the correct ages.'
));
}
/**
* Confirm that every pager gets a valid non-overlaping element ID.
*/
function
testElementNumbers
()
{
$_GET
[
'page'
]
=
'3, 2, 1, 0'
;
$name
=
db_select
(
'test'
,
't'
)
->
extend
(
'PagerDefault'
)
->
element
(
2
)
->
fields
(
't'
,
array
(
'name'
))
->
orderBy
(
'age'
)
->
limit
(
1
)
->
execute
()
->
fetchField
();
$this
->
assertEqual
(
$name
,
'Paul'
,
t
(
'Pager query #1 with a specified element ID returned the correct results.'
));
// Setting an element smaller than the previous one
// should not overwrite the pager $maxElement with a smaller value.
$name
=
db_select
(
'test'
,
't'
)
->
extend
(
'PagerDefault'
)
->
element
(
1
)
->
fields
(
't'
,
array
(
'name'
))
->
orderBy
(
'age'
)
->
limit
(
1
)
->
execute
()
->
fetchField
();
$this
->
assertEqual
(
$name
,
'George'
,
t
(
'Pager query #2 with a specified element ID returned the correct results.'
));
$name
=
db_select
(
'test'
,
't'
)
->
extend
(
'PagerDefault'
)
->
fields
(
't'
,
array
(
'name'
))
->
orderBy
(
'age'
)
->
limit
(
1
)
->
execute
()
->
fetchField
();
$this
->
assertEqual
(
$name
,
'John'
,
t
(
'Pager query #3 with a generated element ID returned the correct results.'
));
unset
(
$_GET
[
'page'
]);
}
}
...
...
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