Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3174996
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Issue forks
drupal-3174996
Commits
09a407f4
Commit
09a407f4
authored
12 years ago
by
Damian Lee
Committed by
Tim Plunkett
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1791554
by damiankloip: Added a view element type.
parent
690c7977
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/Drupal/views/Tests/ViewElementTest.php
+117
-0
117 additions, 0 deletions
lib/Drupal/views/Tests/ViewElementTest.php
tests/views_test_data/views_test_data.module
+31
-0
31 additions, 0 deletions
tests/views_test_data/views_test_data.module
views.module
+28
-0
28 additions, 0 deletions
views.module
with
176 additions
and
0 deletions
lib/Drupal/views/Tests/ViewElementTest.php
0 → 100644
+
117
−
0
View file @
09a407f4
<?php
/**
* @file
* Definition of Drupal\views\Tests\ViewElementTest.
*/
namespace
Drupal\views\Tests
;
/**
* Tests the 'view' element type.
*/
class
ViewElementTest
extends
ViewTestBase
{
/**
* The raw render data array to use in tests.
*
* @var array
*/
protected
$render
;
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'View element'
,
'description'
=>
'Tests the view render element.'
,
'group'
=>
'Views'
);
}
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
enableViewsTestModule
();
// Set up a render array to use. We need to copy this as drupal_render
// passes by reference.
$this
->
render
=
array
(
'view'
=>
array
(
'#type'
=>
'view'
,
'#name'
=>
'test_view'
,
'#display_id'
=>
'default'
,
'#arguments'
=>
array
(
25
),
),
);
}
/**
* Tests the rendered output and form output of a view element.
*/
public
function
testViewElement
()
{
$view
=
$this
->
getBasicView
();
// Set the content as our rendered array.
$render
=
$this
->
render
;
$this
->
drupalSetContent
(
drupal_render
(
$render
));
$xpath
=
$this
->
xpath
(
'//div[@class="views-element-container"]'
);
$this
->
assertTrue
(
$xpath
,
'The view container has been found in the rendered output.'
);
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]'
);
$this
->
assertTrue
(
$xpath
,
'The view content has been found in the rendered output.'
);
// There should be 5 rows in the results.
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
$this
->
assertEqual
(
count
(
$xpath
),
5
);
// Test a form.
$this
->
drupalGet
(
'views_test_data_element_form'
);
$xpath
=
$this
->
xpath
(
'//div[@class="views-element-container form-wrapper"]'
);
$this
->
assertTrue
(
$xpath
,
'The view container has been found on the form.'
);
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]'
);
$this
->
assertTrue
(
$xpath
,
'The view content has been found on the form.'
);
// There should be 5 rows in the results.
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
$this
->
assertEqual
(
count
(
$xpath
),
5
);
// Add an argument and save the view.
$view
->
displayHandlers
[
'default'
]
->
overrideOption
(
'arguments'
,
array
(
'age'
=>
array
(
'default_action'
=>
'ignore'
,
'style_plugin'
=>
'default_summary'
,
'style_options'
=>
array
(),
'wildcard'
=>
'all'
,
'wildcard_substitution'
=>
'All'
,
'title'
=>
''
,
'breadcrumb'
=>
''
,
'default_argument_type'
=>
'fixed'
,
'default_argument'
=>
''
,
'validate'
=>
array
(
'type'
=>
'none'
,
'fail'
=>
'not found'
,
),
'break_phrase'
=>
0
,
'not'
=>
0
,
'id'
=>
'age'
,
'table'
=>
'views_test_data'
,
'field'
=>
'age'
,
'validate_user_argument_type'
=>
'uid'
,
)
));
$view
->
save
();
// Test the render array again.
$render
=
$this
->
render
;
$this
->
drupalSetContent
(
drupal_render
(
$render
));
// There should be 1 row in the results, 'John' arg 25.
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
$this
->
assertEqual
(
count
(
$xpath
),
1
);
// Test that the form has the same expected result.
$this
->
drupalGet
(
'views_test_data_element_form'
);
$xpath
=
$this
->
xpath
(
'//div[@class="view-content"]/div'
);
$this
->
assertEqual
(
count
(
$xpath
),
1
);
}
}
This diff is collapsed.
Click to expand it.
tests/views_test_data/views_test_data.module
+
31
−
0
View file @
09a407f4
...
...
@@ -124,3 +124,34 @@ function template_preprocess_views_view_mapping_test(&$variables) {
function
theme_views_view_mapping_test
(
$variables
)
{
return
drupal_render
(
$variables
[
'element'
]);
}
/**
* Implements hook_menu().
*/
function
views_test_data_menu
()
{
$items
=
array
();
$items
[
'views_test_data_element_form'
]
=
array
(
'title'
=>
'Views test data element form'
,
'description'
=>
'Views test data element form callback'
,
'page callback'
=>
'drupal_get_form'
,
'page arguments'
=>
array
(
'views_test_data_element_form'
),
'access callback'
=>
TRUE
,
);
return
$items
;
}
/**
* Simple form page callback to test the view element.
*/
function
views_test_data_element_form
()
{
$form
[
'view'
]
=
array
(
'#type'
=>
'view'
,
'#name'
=>
'test_view'
,
'#display_id'
=>
'default'
,
'#arguments'
=>
array
(
25
),
);
return
$form
;
}
This diff is collapsed.
Click to expand it.
views.module
+
28
−
0
View file @
09a407f4
...
...
@@ -144,6 +144,34 @@ function views_api_minimum_version() {
return
'2'
;
}
/**
* Implements hook_element_info().
*/
function
views_element_info
()
{
$types
[
'view'
]
=
array
(
'#theme_wrappers'
=>
array
(
'container'
),
'#pre_render'
=>
array
(
'views_pre_render_view_element'
),
'#name'
=>
NULL
,
'#display_id'
=>
'default'
,
'#arguments'
=>
array
(),
);
return
$types
;
}
/**
* View element pre render callback.
*/
function
views_pre_render_view_element
(
$element
)
{
$element
[
'#attributes'
][
'class'
][]
=
'views-element-container'
;
$view
=
views_get_view
(
$element
[
'#name'
]);
if
(
$view
&&
$view
->
access
(
$element
[
'#display_id'
]))
{
$element
[
'view'
][
'#markup'
]
=
$view
->
preview
(
$element
[
'#display_id'
],
$element
[
'#arguments'
]);
}
return
$element
;
}
/**
* Implement hook_theme(). Register views theming functions.
*/
...
...
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