Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
225
Merge Requests
225
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
4e748464
Commit
4e748464
authored
Sep 14, 2012
by
damiankloip
Committed by
tim.plunkett
Oct 21, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#1754238
by damiankloip: Add a generic testcase for the display base.
parent
5cc94057
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
218 additions
and
1 deletion
+218
-1
lib/Drupal/views/Tests/Plugin/DisplayTest.php
lib/Drupal/views/Tests/Plugin/DisplayTest.php
+84
-1
tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
...upal/views_test_data/Plugin/views/display/DisplayTest.php
+134
-0
No files found.
lib/Drupal/views/Tests/Plugin/DisplayTest.php
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
();
...
...
tests/views_test_data/lib/Drupal/views_test_data/Plugin/views/display/DisplayTest.php
0 → 100644
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
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment