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
4e748464
Commit
4e748464
authored
12 years ago
by
Damian Lee
Committed by
Tim Plunkett
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1754238
by damiankloip: Add a generic testcase for the display base.
parent
5cc94057
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/Plugin/DisplayTest.php
+84
-1
84 additions, 1 deletion
lib/Drupal/views/Tests/Plugin/DisplayTest.php
tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
+134
-0
134 additions, 0 deletions
...upal/views_test_data/Plugin/views/display/DisplayTest.php
with
218 additions
and
1 deletion
lib/Drupal/views/Tests/Plugin/DisplayTest.php
+
84
−
1
View file @
4e748464
...
...
@@ -7,11 +7,21 @@
namespace
Drupal\views\Tests\Plugin
;
use
Drupal\views\ViewDisplay
;
use
Drupal\views_test_data
\Plugin\views\display\DisplayTest
as
DisplayTestPlugin
;
/**
* Tests the basic display plugin.
*/
class
DisplayTest
extends
PluginTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
array
(
'views_ui'
);
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Display'
,
...
...
@@ -20,10 +30,83 @@ public static function getInfo() {
);
}
public
function
setUp
()
{
parent
::
setUp
();
$this
->
enableViewsTestModule
();
$this
->
adminUser
=
$this
->
drupalCreateUser
(
array
(
'administer views'
));
$this
->
drupalLogin
(
$this
->
adminUser
);
// Create 10 nodes.
$this
->
nodes
=
array
();
for
(
$i
=
0
;
$i
<
11
;
$i
++
)
{
$this
->
drupalCreateNode
(
array
(
'promote'
=>
TRUE
));
}
}
/**
* Tests the display test plugin.
*
* @see Drupal\views_test_data\Plugin\views\display\DisplayTest
*/
function
testDisplayPlugin
()
{
$view
=
views_get_view
(
'frontpage'
);
// Add a new 'display_test' display and test it's there.
$view
->
addDisplay
(
'display_test'
);
$this
->
assertTrue
(
isset
(
$view
->
display
[
'display_test_1'
]),
'Added display has been assigned to "display_test_1"'
);
// Create an expected ViewDisplay and check that it's equal.
$options
=
array
(
'display_options'
=>
array
(),
'display_plugin'
=>
'display_test'
,
'id'
=>
'display_test_1'
,
'display_title'
=>
'Display test'
,
'position'
=>
NULL
,
);
$expected_display
=
new
ViewDisplay
(
$options
);
$this
->
assertEqual
(
$view
->
display
[
'display_test_1'
],
$expected_display
);
$view
->
setDisplay
(
'display_test_1'
);
$this
->
assertTrue
(
$view
->
display_handler
instanceof
DisplayTestPlugin
,
'The correct display handler instance is on the view object.'
);
// Check the test option.
$this
->
assertIdentical
(
$view
->
display_handler
->
getOption
(
'test_option'
),
''
);
$output
=
$view
->
preview
();
$this
->
assertTrue
(
strpos
(
$output
,
'<h1></h1>'
)
!==
FALSE
,
'An empty value for test_option found in output.'
);
// Change this option and check the title of out output.
$view
->
display_handler
->
overrideOption
(
'test_option'
,
'Test option title'
);
$view
->
save
();
$output
=
$view
->
preview
();
// Test we have our custom <h1> tag in the output of the view.
$this
->
assertTrue
(
strpos
(
$output
,
'<h1>Test option title</h1>'
)
!==
FALSE
,
'The test_option value found in display output title.'
);
// Test that the display category/summary is in the UI.
$this
->
drupalGet
(
'admin/structure/views/view/frontpage/edit/display_test_1'
);
$this
->
assertText
(
'Display test settings'
);
$this
->
clickLink
(
'Test option title'
);
$this
->
randomString
=
$this
->
randomString
();
$this
->
drupalPost
(
NULL
,
array
(
'test_option'
=>
$this
->
randomString
),
t
(
'Apply'
));
// Check the new value has been saved by checking the UI summary text.
$this
->
drupalGet
(
'admin/structure/views/view/frontpage/edit/display_test_1'
);
$this
->
assertText
(
$this
->
randomString
);
}
/**
* Tests the overriding of filter_groups.
*/
function
testFilterGroupsOverriding
()
{
public
function
testFilterGroupsOverriding
()
{
$view
=
$this
->
createViewFromConfig
(
'test_filter_groups'
);
$view
->
initDisplay
();
...
...
This diff is collapsed.
Click to expand it.
tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
0 → 100644
+
134
−
0
View file @
4e748464
<?php
/**
* @file
* Definition of Drupal\views_test_data\Plugin\views\display\DisplayTest.
*/
namespace
Drupal\views_test_data\Plugin\views\display
;
use
Drupal\views\Plugin\views\display\DisplayPluginBase
;
use
Drupal\Core\Annotation\Plugin
;
use
Drupal\Core\Annotation\Translation
;
/**
* Defines a Display test plugin.
*
* @Plugin(
* id = "display_test",
* title = @Translation("Display test"),
* theme = "views_view",
* contextual_links_locations = {"view"}
* )
*/
class
DisplayTest
extends
DisplayPluginBase
{
/**
* Whether the display allows attachments.
*
* @var bool
*/
protected
$usesAttachments
=
TRUE
;
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::defineOptions().
*/
protected
function
defineOptions
()
{
$options
=
parent
::
defineOptions
();
$options
[
'test_option'
]
=
array
(
'default'
=>
''
);
return
$options
;
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::optionsSummaryv().
*/
public
function
optionsSummary
(
&
$categories
,
&
$options
)
{
parent
::
optionsSummary
(
$categories
,
$options
);
$categories
[
'display_test'
]
=
array
(
'title'
=>
t
(
'Display test settings'
),
'column'
=>
'second'
,
'build'
=>
array
(
'#weight'
=>
-
100
,
),
);
$test_option
=
$this
->
getOption
(
'test_option'
)
?:
t
(
'Empty'
);
$options
[
'test_option'
]
=
array
(
'category'
=>
'display_test'
,
'title'
=>
t
(
'Test option'
),
'value'
=>
views_ui_truncate
(
$test_option
,
24
),
);
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::buildOptionsForm().
*/
public
function
buildOptionsForm
(
&
$form
,
&
$form_state
)
{
parent
::
buildOptionsForm
(
$form
,
$form_state
);
switch
(
$form_state
[
'section'
])
{
case
'test_option'
:
$form
[
'#title'
]
.
=
t
(
'Test option'
);
$form
[
'test_option'
]
=
array
(
'#type'
=>
'textfield'
,
'#description'
=>
t
(
'This is a textfield for test_option.'
),
'#default_value'
=>
$this
->
getOption
(
'test_option'
),
);
break
;
}
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::validateOptionsForm().
*/
public
function
validateOptionsForm
(
&
$form
,
&
$form_state
)
{
parent
::
validateOptionsForm
(
$form
,
$form_state
);
watchdog
(
'views'
,
$form_state
[
'values'
][
'test_option'
]);
switch
(
$form_state
[
'section'
])
{
case
'test_option'
:
if
(
!
trim
(
$form_state
[
'values'
][
'test_option'
]))
{
form_error
(
$form
[
'test_option'
],
t
(
'You cannot have an empty option.'
));
}
break
;
}
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::submitOptionsForm().
*/
public
function
submitOptionsForm
(
&
$form
,
&
$form_state
)
{
parent
::
submitOptionsForm
(
$form
,
$form_state
);
switch
(
$form_state
[
'section'
])
{
case
'test_option'
:
$this
->
setOption
(
'test_option'
,
$form_state
[
'values'
][
'test_option'
]);
break
;
}
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::execute().
*/
public
function
execute
()
{
$this
->
view
->
build
();
// Render the test option as the title before the view output.
$render
=
'<h1>'
.
filter_xss_admin
(
$this
->
options
[
'test_option'
])
.
'</h1>'
;
// And now render the view.
$render
.
=
$this
->
view
->
render
();
return
$render
;
}
/**
* Overrides Drupal\views\Plugin\views\display\DisplayPluginBase::preview().
*
* Override so preview and execute are the same output.
*/
public
function
preview
()
{
return
$this
->
execute
();
}
}
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