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
fbbc7ee5
Commit
fbbc7ee5
authored
12 years ago
by
Daniel Wehner
Committed by
Tim Plunkett
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1754258
by dawehner: Add a generic testcase for the relationship base.
parent
ba438a69
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
lib/Drupal/views/Tests/Handler/RelationshipTest.php
+185
-0
185 additions, 0 deletions
lib/Drupal/views/Tests/Handler/RelationshipTest.php
lib/Drupal/views/Tests/Node/RevisionRelationships.php
+69
-0
69 additions, 0 deletions
lib/Drupal/views/Tests/Node/RevisionRelationships.php
with
254 additions
and
0 deletions
lib/Drupal/views/Tests/Handler/RelationshipTest.php
0 → 100644
+
185
−
0
View file @
fbbc7ee5
<?php
/**
* @file
* Definition of Drupal\views\Tests\Handler\RelationshipTest.
*/
namespace
Drupal\views\Tests\Handler
;
/**
* Tests the base relationship handler.
*
* @see Drupal\views\Plugin\views\relationship\RelationshipPluginBase
*/
class
RelationshipTest
extends
HandlerTestBase
{
/**
* Maps between the key in the expected result and the query result.
*
* @var array
*/
protected
$columnMap
=
array
(
'views_test_data_name'
=>
'name'
,
'users_views_test_data_uid'
=>
'uid'
,
);
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Relationship: Standard'
,
'description'
=>
'Tests the base relationship handler.'
,
'group'
=>
'Views Handlers'
,
);
}
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
enableViewsTestModule
();
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::schemaDefinition().
*
* Adds a uid column to test the relationships.
*
* @return array
*/
protected
function
schemaDefinition
()
{
$schema
=
parent
::
schemaDefinition
();
$schema
[
'views_test_data'
][
'fields'
][
'uid'
]
=
array
(
'description'
=>
"The
{
users
}
.uid of the author of the beatle entry."
,
'type'
=>
'int'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
'default'
=>
0
);
return
$schema
;
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::viewsData().
*
* Adds a relationship for the uid column.
*
* @return array
*/
protected
function
viewsData
()
{
$data
=
parent
::
viewsData
();
$data
[
'views_test_data'
][
'uid'
]
=
array
(
'title'
=>
t
(
'UID'
),
'help'
=>
t
(
'The test data UID'
),
'relationship'
=>
array
(
'id'
=>
'standard'
,
'base'
=>
'users'
,
'base field'
=>
'uid'
)
);
return
$data
;
}
/**
* Tests the query result of a view with a relationship.
*/
public
function
testRelationshipQuery
()
{
// Set the first entry to have the admin as author.
db_query
(
"UPDATE
{
views_test_data
}
SET uid = 1 WHERE id = 1"
);
db_query
(
"UPDATE
{
views_test_data
}
SET uid = 2 WHERE id <> 1"
);
$view
=
$this
->
getBasicView
();
$view
->
display
[
'default'
]
->
handler
->
overrideOption
(
'relationships'
,
array
(
'uid'
=>
array
(
'id'
=>
'uid'
,
'table'
=>
'views_test_data'
,
'field'
=>
'uid'
,
),
));
$view
->
display
[
'default'
]
->
handler
->
overrideOption
(
'filters'
,
array
(
'uid'
=>
array
(
'id'
=>
'uid'
,
'table'
=>
'users'
,
'field'
=>
'uid'
,
'relationship'
=>
'uid'
,
),
));
$fields
=
$view
->
display
[
'default'
]
->
handler
->
getOption
(
'fields'
);
$view
->
display
[
'default'
]
->
handler
->
overrideOption
(
'fields'
,
$fields
+
array
(
'uid'
=>
array
(
'id'
=>
'uid'
,
'table'
=>
'users'
,
'field'
=>
'uid'
,
'relationship'
=>
'uid'
,
),
));
$view
->
initDisplay
();
$view
->
initHandlers
();
// Check for all beatles created by admin.
$view
->
filter
[
'uid'
]
->
value
=
array
(
1
);
$this
->
executeView
(
$view
);
$expected_result
=
array
(
array
(
'name'
=>
'John'
,
'uid'
=>
1
)
);
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$this
->
columnMap
);
$view
->
destroy
();
// Check for all beatles created by another user, which so doesn't exist.
$view
->
initDisplay
();
$view
->
initHandlers
();
$view
->
filter
[
'uid'
]
->
value
=
array
(
3
);
$this
->
executeView
(
$view
);
$expected_result
=
array
();
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$this
->
columnMap
);
$view
->
destroy
();
// Set the relationship to required, so only results authored by the admin
// should return.
$view
->
initDisplay
();
$view
->
initHandlers
();
$view
->
relationship
[
'uid'
]
->
options
[
'required'
]
=
TRUE
;
$this
->
executeView
(
$view
);
$expected_result
=
array
(
array
(
'name'
=>
'John'
,
'uid'
=>
1
)
);
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$this
->
columnMap
);
$view
->
destroy
();
// Set the relationship to optional should cause to return all beatles.
$view
->
initDisplay
();
$view
->
initHandlers
();
$view
->
relationship
[
'uid'
]
->
options
[
'required'
]
=
FALSE
;
$this
->
executeView
(
$view
);
$expected_result
=
$this
->
dataSet
();
// Alter the expected result to contain the right uids.
foreach
(
$expected_result
as
$key
=>
&
$row
)
{
// Only John has an existing author.
if
(
$row
[
'name'
]
==
'John'
)
{
$row
[
'uid'
]
=
1
;
}
else
{
// The LEFT join should set an empty {users}.uid field.
$row
[
'uid'
]
=
NULL
;
}
}
$this
->
assertIdenticalResultset
(
$view
,
$expected_result
,
$this
->
columnMap
);
}
}
This diff is collapsed.
Click to expand it.
lib/Drupal/views/Tests/Node/RevisionRelationships.php
0 → 100644
+
69
−
0
View file @
fbbc7ee5
<?php
/**
* @file
* Definition of Drupal\views\Tests\Node\RevisionRelationships.
*/
namespace
Drupal\views\Tests\Node
;
use
Drupal\views\Tests\ViewTestBase
;
/**
* Tests basic node_revision table integration into views.
*/
class
RevisionRelationships
extends
ViewTestBase
{
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Node: Revision integration'
,
'description'
=>
'Tests the integration of node_revision table of node module'
,
'group'
=>
'Views Modules'
,
);
}
/**
* Create a node with revision and rest result count for both views.
*/
public
function
testNodeRevisionRelationship
()
{
$node
=
$this
->
drupalCreateNode
();
// Create revision of the node.
$node_revision
=
clone
$node
;
$node_revision
->
revision
=
1
;
$node
->
save
();
$column_map
=
array
(
'vid'
=>
'vid'
,
'node_revision_nid'
=>
'node_revision_nid'
,
'node_node_revision_nid'
=>
'node_node_revision_nid'
,
);
// Here should be two rows.
$view_nid
=
$this
->
createViewFromConfig
(
'test_node_revision_nid'
);
$this
->
executeView
(
$view_nid
,
array
(
$node
->
nid
));
$resultset_nid
=
array
(
array
(
'vid'
=>
'1'
,
'node_revision_nid'
=>
'1'
,
'node_node_revision_nid'
=>
'1'
,
),
array
(
'vid'
=>
'2'
,
'node_revision_nid'
=>
'1'
,
'node_node_revision_nid'
=>
'1'
,
),
);
$this
->
assertIdenticalResultset
(
$view_nid
,
$resultset_nid
,
$column_map
);
// There should be only one row with active revision 2.
$view_vid
=
$this
->
createViewFromConfig
(
'test_node_revision_vid'
);
$this
->
executeView
(
$view_vid
,
array
(
$node
->
nid
));
$resultset_vid
=
array
(
array
(
'vid'
=>
'2'
,
'node_revision_nid'
=>
'1'
,
'node_node_revision_nid'
=>
'1'
,
),
);
$this
->
assertIdenticalResultset
(
$view_vid
,
$resultset_vid
,
$column_map
);
}
}
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