Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,187 @@
langcode: en
status: true
dependencies:
module:
- node
- user
id: sa_contrib_2013_035
label: SA_CONTRIB_2013_035
module: views
description: ''
tag: '<script>alert("foo");</script>, <marquee>test</marquee>'
base_table: node_field_data
base_field: nid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: perm
options:
perm: 'access content'
cache:
type: tag
options: { }
query:
type: views_query
options:
disable_sql_rewrite: false
distinct: false
replica: false
query_comment: ''
query_tags: { }
exposed_form:
type: basic
options:
submit_button: Apply
reset_button: false
reset_button_label: Reset
exposed_sorts_label: 'Sort by'
expose_sort_order: true
sort_asc_label: Asc
sort_desc_label: Desc
pager:
type: none
options:
offset: 0
style:
type: default
options:
grouping: { }
row_class: ''
default_row_class: true
uses_fields: false
row:
type: fields
options:
inline: { }
separator: ''
hide_empty: false
default_field_elements: true
fields:
title:
id: title
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: '<marquee>test</marquee>'
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: false
ellipsis: false
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: field
entity_type: node
entity_field: title
title_1:
id: title_1
table: node_field_data
field: title
relationship: none
group_type: group
admin_label: '<script>alert("XSS")</script>'
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: false
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: field
entity_type: node
entity_field: title
filters: { }
sorts: { }
header:
area:
id: area
table: views
field: area
plugin_id: text
footer: { }
empty: { }
relationships: { }
arguments: { }
title: '<marquee>VIEWS TITLE</marquee>'
page_1:
display_plugin: page
id: page_1
display_title: Page
position: 2
display_options:
path: foobar

View file

@ -0,0 +1,4 @@
/**
* @file
* Just a placeholder file for the test.
*/

View file

@ -0,0 +1,8 @@
name: 'Views UI Test'
type: module
description: 'Test module for Views UI.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- views_ui

View file

@ -0,0 +1,4 @@
views_ui_test.test:
css:
component:
css/views_ui_test.test.css: {}

View file

@ -0,0 +1,17 @@
<?php
/**
* @file
* Helper module for Views UI tests.
*/
/**
* Implements hook_views_preview_info_alter().
*
* Add a row count row to the live preview area.
*/
function views_ui_test_views_preview_info_alter(&$rows, $view) {
$data = ['#markup' => t('Test row count')];
$data['#attached']['library'][] = 'views_ui_test/views_ui_test.test';
$rows['query'][] = [['data' => $data], count($view->result)];
}

View file

@ -0,0 +1,76 @@
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests the View UI filter criteria group dialog.
*
* @group views_ui
*/
class FilterCriteriaTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'views', 'views_ui'];
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer views',
'administer nodes',
'access content overview',
]);
// Disable automatic live preview to make the sequence of calls clearer.
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
$this->drupalLogin($admin_user);
}
/**
* Tests dialog for filter criteria.
*/
public function testFilterCriteriaDialog() {
$this->drupalGet('admin/structure/views/view/content_recent');
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
// Use the 'And/Or Rearrange' link for fields to open a dialog.
$dropbutton = $page->find('css', '.views-ui-display-tab-bucket.filter .dropbutton-toggle button');
$dropbutton->click();
$add_link = $page->findById('views-rearrange-filter');
$this->assertTrue($add_link->isVisible(), 'And/Or Rearrange button found.');
$add_link->click();
$assert_session->assertWaitOnAjaxRequest();
// Add a new filter group.
$create_new_filter_group = $page->findById('views-add-group-link');
$this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.');
$create_new_filter_group->click();
$assert_session->assertWaitOnAjaxRequest();
// Assert the existence of the new filter group by checking the remove group
// link.
$remove_link = $page->findLink('Remove group');
$this->assertTrue($remove_link->isVisible(), 'New group found.');
// Remove the group again and assert the group is not present anymore.
$remove_link->click();
$assert_session->assertWaitOnAjaxRequest();
$remove_link = $page->findLink('Remove group');
$this->assertEmpty($remove_link, 'Remove button not available');
// Checks that the admin summary is not double escaped.
$this->drupalGet('admin/structure/views/view/who_s_online');
$page = $this->getSession()->getPage();
$this->assertNotNull($page->findLink('User: Last access (>= -15 minutes)'));
}
}

View file

@ -0,0 +1,69 @@
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests the JavaScript library caching on consecutive requests.
*
* @group views_ui
*/
class LibraryCachingTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'views', 'views_ui'];
/**
* Tests if the Views UI dialogs open on consecutive requests.
*/
public function testConsecutiveDialogRequests() {
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer views',
'administer nodes',
'access content overview',
]);
// Disable automatic live preview to make the sequence of calls clearer.
\Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
$this->drupalLogin($admin_user);
$this->drupalGet('admin/structure/views/view/content');
$page = $this->getSession()->getPage();
// Use the 'Add' link for fields to open a dialog. This will load the proper
// dialog libraries.
$add_link = $page->findById('views-add-field');
$this->assertTrue($add_link->isVisible(), 'Add fields button found.');
$add_link->click();
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
// Close the dialog and open it again. No no libraries will be loaded, but a
// cache entry will be made for not loading any libraries.
$page->pressButton('Close');
$add_link->click();
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
$page->pressButton('Close');
// Reload the page.
$this->drupalGet('admin/structure/views/view/content');
$page = $this->getSession()->getPage();
// Now use the 'Update preview' button to load libraries.
$preview = $page->findById('preview-submit');
// The first click will load all the libraries.
$preview->click();
$this->assertJsCondition("jQuery('.ajax-progress').length === 0");
// The second click will not load any new libraries.
$preview->click();
$this->assertJsCondition("jQuery('.ajax-progress').length === 0");
// Check to see if the dialogs still open.
$add_link = $page->findById('views-add-field');
$add_link->click();
$this->assertJsCondition("jQuery('.ui-dialog-titlebar').length > 0");
$page->pressButton('Close');
}
}

View file

@ -0,0 +1,123 @@
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests the JavaScript filtering on the Views listing page.
*
* @see core/modules/views_ui/js/views_ui.listing.js
* @group views_ui
*/
class ViewsListingTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'views', 'views_ui'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer views',
]);
$this->drupalLogin($admin_user);
}
/**
* Tests the filtering on the Views listing page.
*/
public function testFilterViewsListing() {
$this->drupalGet('admin/structure/views');
$session = $this->assertSession();
$page = $this->getSession()->getPage();
// Test that we search in both the enabled and disabled rows.
$enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this->filterVisibleElements($enabled_rows);
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this->filterVisibleElements($disabled_rows);
// Test that we see some rows of views in both tables.
$this->assertCount(6, $enabled_rows);
$this->assertCount(2, $disabled_rows);
// Filter on the string 'people'. This should only show the people view.
$search_input = $page->find('css', '.views-filter-text.form-search');
$search_input->setValue('people');
$enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this->filterVisibleElements($enabled_rows);
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this->filterVisibleElements($disabled_rows);
$this->assertCount(1, $enabled_rows);
$this->assertCount(0, $disabled_rows);
// Filter on a string that also appears in the description.
$search_input->setValue('content');
$enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this->filterVisibleElements($enabled_rows);
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this->filterVisibleElements($disabled_rows);
$this->assertCount(3, $enabled_rows);
$this->assertCount(2, $disabled_rows);
// Reset the search string and check that we are back to the initial stage.
$search_input->setValue('');
// Add a backspace to trigger the keyUp event.
$search_input->keyUp(8);
$enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this->filterVisibleElements($enabled_rows);
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this->filterVisibleElements($disabled_rows);
$this->assertCount(6, $enabled_rows);
$this->assertCount(2, $disabled_rows);
// Disable a View and see if it moves to the disabled listing.
$enabled_view = $page->find('css', 'tr.views-ui-list-enabled');
// Open the dropdown with additional actions.
$enabled_view->find('css', 'li.dropbutton-toggle button')->click();
$disable_button = $enabled_view->find('css', 'li.disable.dropbutton-action a');
// Check that the disable button is visible now.
$this->assertTrue($disable_button->isVisible());
$disable_button->click();
$session->assertWaitOnAjaxRequest();
$enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
$enabled_rows = $this->filterVisibleElements($enabled_rows);
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
$disabled_rows = $this->filterVisibleElements($disabled_rows);
// Test that one enabled View has been moved to the disabled list.
$this->assertCount(5, $enabled_rows);
$this->assertCount(3, $disabled_rows);
}
/**
* Removes any non-visible elements from the passed array.
*
* @param array $elements
* @return array
*/
protected function filterVisibleElements($elements) {
$elements = array_filter($elements, function($element) {
return $element->isVisible();
});
return $elements;
}
}

View file

@ -0,0 +1,82 @@
<?php
namespace Drupal\Tests\views_ui\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
/**
* Tests views creation wizard.
*
* @see core/modules/views_ui/js/views-admin.js
* @group views_ui
*/
class ViewsWizardTest extends JavascriptTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['node', 'views', 'views_ui', 'block', 'user'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser([
'administer site configuration',
'administer views',
]);
$this->drupalLogin($admin_user);
}
/**
* Tests creating a View using the wizard.
*/
public function testCreateViewWizard() {
$this->drupalGet('admin/structure/views/add');
$page = $this->getSession()->getPage();
// Set a view name, this should be used to prepopulate a number of other
// fields when creating displays.
$label_value = 'test view';
$search_input = $page->findField('label');
$search_input->setValue($label_value);
$page->findField('page[create]')->click();
// Test if the title and path have been populated.
$this->assertEquals($label_value, $page->findField('page[title]')->getValue());
$this->assertEquals(str_replace(' ', '-', $label_value), $page->findField('page[path]')->getValue());
// Create a menu item.
$page->findField('page[link]')->click();
$this->assertEquals($label_value, $page->findField('page[link_properties][title]')->getValue());
// Add a block display.
$page->findField('block[create]')->click();
$this->assertEquals($label_value, $page->findField('block[title]')->getValue());
// Select the entity type to display and test that the type selector is
// shown when expected.
$page->selectFieldOption('show[wizard_key]', 'node');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for nodes when there are no node types.');
$this->assertEquals('teasers', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format shows the expected default value.');
$this->assertEquals('titles_linked', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format shows the expected default value.');
$page->selectFieldOption('show[wizard_key]', 'users');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNull($page->findField('show[type]'), 'The "of type" filter is not added for users.');
$this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was updated to a valid value.');
$this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was updated to a valid value.');
$this->drupalCreateContentType(['type' => 'page']);
$page->selectFieldOption('show[wizard_key]', 'node');
$this->assertSession()->assertWaitOnAjaxRequest();
$this->assertNotNull($page->findField('show[type]'), 'The "of type" filter is added for nodes when there is at least one node type.');
$this->assertEquals('fields', $page->findField('page[style][row_plugin]')->getValue(), 'The page display format was not changed from a valid value.');
$this->assertEquals('fields', $page->findField('block[style][row_plugin]')->getValue(), 'The block display format was not changed from a valid value.');
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Drupal\Tests\views_ui\Kernel;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views_ui\Controller\ViewsUIController;
use Drupal\Component\Utility\Html;
use Drupal\views\Entity\View;
/**
* Tests the views ui tagging functionality.
*
* @group views_ui
*/
class TagTest extends ViewsKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('views', 'views_ui', 'user');
/**
* Tests the views_ui_autocomplete_tag function.
*/
public function testViewsUiAutocompleteTag() {
\Drupal::moduleHandler()->loadInclude('views_ui', 'inc', 'admin');
// Save 15 views with a tag.
$tags = array();
for ($i = 0; $i < 16; $i++) {
$suffix = $i % 2 ? 'odd' : 'even';
$tag = 'autocomplete_tag_test_' . $suffix . $this->randomMachineName();
$tags[] = $tag;
View::create(array('tag' => $tag, 'id' => $this->randomMachineName()))->save();
}
// Make sure just ten results are returns.
$controller = ViewsUIController::create($this->container);
$request = $this->container->get('request_stack')->getCurrentRequest();
$request->query->set('q', 'autocomplete_tag_test');
$result = $controller->autocompleteTag($request);
$matches = (array) json_decode($result->getContent(), TRUE);
$this->assertEqual(count($matches), 10, 'Make sure the maximum amount of tag results is 10.');
// Make sure the returned array has the proper format.
$suggestions = array_map(function ($tag) {
return array('value' => $tag, 'label' => Html::escape($tag));
}, $tags);
foreach ($matches as $match) {
$this->assertTrue(in_array($match, $suggestions), 'Make sure the returned array has the proper format.');
}
// Make sure that matching by a certain prefix works.
$request->query->set('q', 'autocomplete_tag_test_even');
$result = $controller->autocompleteTag($request);
$matches = (array) json_decode($result->getContent(), TRUE);
$this->assertEqual(count($matches), 8, 'Make sure that only a subset is returned.');
foreach ($matches as $tag) {
$this->assertTrue(array_search($tag['value'], $tags) !== FALSE, format_string('Make sure the returned tag @tag actually exists.', array('@tag' => $tag['value'])));
}
// Make sure an invalid result doesn't return anything.
$request->query->set('q', $this->randomMachineName());
$result = $controller->autocompleteTag($request);
$matches = (array) json_decode($result->getContent());
$this->assertEqual(count($matches), 0, "Make sure an invalid tag doesn't return anything.");
}
}

View file

@ -0,0 +1,25 @@
<?php
namespace Drupal\Tests\views_ui\Unit\Form\Ajax;
use Drupal\Tests\UnitTestCase;
use Drupal\views_ui\Form\Ajax\RearrangeFilter;
/**
* Unit tests for Views UI module functions.
*
* @group views_ui
*/
class RearrangeFilterTest extends UnitTestCase {
/**
* Tests static methods.
*/
public function testStaticMethods() {
// Test the RearrangeFilter::arrayKeyPlus method.
$original = array(0 => 'one', 1 => 'two', 2 => 'three');
$expected = array(1 => 'one', 2 => 'two', 3 => 'three');
$this->assertSame(RearrangeFilter::arrayKeyPlus($original), $expected);
}
}

View file

@ -0,0 +1,180 @@
<?php
/**
* @file
* Contains \Drupal\Tests\views_ui\Unit\ViewListBuilderTest.
*/
namespace Drupal\Tests\views_ui\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views\ViewExecutableFactory;
use Drupal\views_ui\ViewListBuilder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* @coversDefaultClass \Drupal\views_ui\ViewListBuilder
* @group views_ui
*/
class ViewListBuilderTest extends UnitTestCase {
/**
* Tests the listing of displays on a views list builder.
*
* @see \Drupal\views_ui\ViewListBuilder::getDisplaysList()
* @covers ::buildRow
*/
public function testBuildRowEntityList() {
$storage = $this->getMockBuilder('Drupal\Core\Config\Entity\ConfigEntityStorage')
->disableOriginalConstructor()
->getMock();
$display_manager = $this->getMockBuilder('\Drupal\views\Plugin\ViewsPluginManager')
->disableOriginalConstructor()
->getMock();
$display_manager->expects($this->any())
->method('getDefinition')
->will($this->returnValueMap(array(
array(
'default',
TRUE,
array(
'id' => 'default',
'title' => 'Master',
'theme' => 'views_view',
'no_ui' => TRUE,
'admin' => '',
)
),
array(
'page',
TRUE,
array(
'id' => 'page',
'title' => 'Page',
'uses_menu_links' => TRUE,
'uses_route' => TRUE,
'contextual_links_locations' => array('page'),
'theme' => 'views_view',
'admin' => 'Page admin label',
)
),
array(
'embed',
TRUE,
array(
'id' => 'embed',
'title' => 'embed',
'theme' => 'views_view',
'admin' => 'Embed admin label',
)
),
)));
$default_display = $this->getMock('Drupal\views\Plugin\views\display\DefaultDisplay',
array('initDisplay'),
array(array(), 'default', $display_manager->getDefinition('default'))
);
$route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
$state = $this->getMock('\Drupal\Core\State\StateInterface');
$menu_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
$page_display = $this->getMock('Drupal\views\Plugin\views\display\Page',
array('initDisplay', 'getPath'),
array(array(), 'default', $display_manager->getDefinition('page'), $route_provider, $state, $menu_storage)
);
$page_display->expects($this->any())
->method('getPath')
->will($this->onConsecutiveCalls(
$this->returnValue('test_page'),
$this->returnValue('<object>malformed_path</object>'),
$this->returnValue('<script>alert("placeholder_page/%")</script>')));
$embed_display = $this->getMock('Drupal\views\Plugin\views\display\Embed', array('initDisplay'),
array(array(), 'default', $display_manager->getDefinition('embed'))
);
$values = array();
$values['status'] = FALSE;
$values['display']['default']['id'] = 'default';
$values['display']['default']['display_title'] = 'Display';
$values['display']['default']['display_plugin'] = 'default';
$values['display']['page_1']['id'] = 'page_1';
$values['display']['page_1']['display_title'] = 'Page 1';
$values['display']['page_1']['display_plugin'] = 'page';
$values['display']['page_1']['display_options']['path'] = 'test_page';
$values['display']['page_2']['id'] = 'page_2';
$values['display']['page_2']['display_title'] = 'Page 2';
$values['display']['page_2']['display_plugin'] = 'page';
$values['display']['page_2']['display_options']['path'] = '<object>malformed_path</object>';
$values['display']['page_3']['id'] = 'page_3';
$values['display']['page_3']['display_title'] = 'Page 3';
$values['display']['page_3']['display_plugin'] = 'page';
$values['display']['page_3']['display_options']['path'] = '<script>alert("placeholder_page/%")</script>';
$values['display']['embed']['id'] = 'embed';
$values['display']['embed']['display_title'] = 'Embedded';
$values['display']['embed']['display_plugin'] = 'embed';
$display_manager->expects($this->any())
->method('createInstance')
->will($this->returnValueMap(array(
array('default', $values['display']['default'], $default_display),
array('page', $values['display']['page_1'], $page_display),
array('page', $values['display']['page_2'], $page_display),
array('page', $values['display']['page_3'], $page_display),
array('embed', $values['display']['embed'], $embed_display),
)));
$container = new ContainerBuilder();
$user = $this->getMock('Drupal\Core\Session\AccountInterface');
$request_stack = new RequestStack();
$request_stack->push(new Request());
$views_data = $this->getMockBuilder('Drupal\views\ViewsData')
->disableOriginalConstructor()
->getMock();
$route_provider = $this->getMock('Drupal\Core\Routing\RouteProviderInterface');
$executable_factory = new ViewExecutableFactory($user, $request_stack, $views_data, $route_provider);
$container->set('views.executable', $executable_factory);
$container->set('plugin.manager.views.display', $display_manager);
\Drupal::setContainer($container);
// Setup a view list builder with a mocked buildOperations method,
// because t() is called on there.
$entity_type = $this->getMock('Drupal\Core\Entity\EntityTypeInterface');
$view_list_builder = new TestViewListBuilder($entity_type, $storage, $display_manager);
$view_list_builder->setStringTranslation($this->getStringTranslationStub());
$view = new View($values, 'view');
$row = $view_list_builder->buildRow($view);
$expected_displays = array(
'Embed admin label',
'Page admin label',
'Page admin label',
'Page admin label',
);
$this->assertEquals($expected_displays, $row['data']['view_name']['data']['#displays']);
$display_paths = $row['data']['path']['data']['#items'];
// These values will be escaped by Twig when rendered.
$this->assertEquals('/test_page, /<object>malformed_path</object>, /<script>alert("placeholder_page/%")</script>', implode(', ', $display_paths));
}
}
class TestViewListBuilder extends ViewListBuilder {
public function buildOperations(EntityInterface $entity) {
return array();
}
}

View file

@ -0,0 +1,141 @@
<?php
namespace Drupal\Tests\views_ui\Unit;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Entity\View;
use Drupal\views_ui\ViewUI;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\views_ui\ViewUI
* @group views_ui
*/
class ViewUIObjectTest extends UnitTestCase {
/**
* Tests entity method decoration.
*/
public function testEntityDecoration() {
$method_args = array();
$method_args['setOriginalId'] = array(12);
$method_args['setStatus'] = array(TRUE);
$method_args['enforceIsNew'] = array(FALSE);
$method_args['label'] = array(LanguageInterface::LANGCODE_NOT_SPECIFIED);
$reflection = new \ReflectionClass('Drupal\Core\Config\Entity\ConfigEntityInterface');
$interface_methods = array();
foreach ($reflection->getMethods() as $reflection_method) {
$interface_methods[] = $reflection_method->getName();
// EntityInterface::isNew() is missing from the list of methods, because it
// calls id(), which breaks the ->expect($this->once()) call. Call it later.
// EntityInterface::isSyncing() is only called during syncing process.
// EntityInterface::isUninstalling() is only called during uninstallation
// process. EntityInterface::getConfigDependencyName() and
// ConfigEntityInterface::calculateDependencies() are only used for
// dependency management.
if (!in_array($reflection_method->getName(), ['isNew', 'isSyncing', 'isUninstalling', 'getConfigDependencyKey', 'getConfigDependencyName', 'calculateDependencies'])) {
if (count($reflection_method->getParameters()) == 0) {
$method_args[$reflection_method->getName()] = array();
}
}
}
$storage = $this->getMock('Drupal\views\Entity\View', $interface_methods, array(array(), 'view'));
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs(array($storage))
->getMock();
$storage->set('executable', $executable);
$view_ui = new ViewUI($storage);
foreach ($method_args as $method => $args) {
$method_mock = $storage->expects($this->once())
->method($method);
foreach ($args as $arg) {
$method_mock->with($this->equalTo($arg));
}
call_user_func_array(array($view_ui, $method), $args);
}
$storage->expects($this->once())
->method('isNew');
$view_ui->isNew();
}
/**
* Tests the isLocked method.
*/
public function testIsLocked() {
$storage = $this->getMock('Drupal\views\Entity\View', array(), array(array(), 'view'));
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs(array($storage))
->getMock();
$storage->set('executable', $executable);
$account = $this->getMock('Drupal\Core\Session\AccountInterface');
$account->expects($this->exactly(2))
->method('id')
->will($this->returnValue(1));
$container = new ContainerBuilder();
$container->set('current_user', $account);
\Drupal::setContainer($container);
$view_ui = new ViewUI($storage);
// A view_ui without a lock object is not locked.
$this->assertFalse($view_ui->isLocked());
// Set the lock object with a different owner than the mocked account above.
$lock = (object) array(
'owner' => 2,
'data' => array(),
'updated' => (int) $_SERVER['REQUEST_TIME'],
);
$view_ui->lock = $lock;
$this->assertTrue($view_ui->isLocked());
// Set a different lock object with the same object as the mocked account.
$lock = (object) array(
'owner' => 1,
'data' => array(),
'updated' => (int) $_SERVER['REQUEST_TIME'],
);
$view_ui->lock = $lock;
$this->assertFalse($view_ui->isLocked());
}
/**
* Tests serialization of the ViewUI object.
*/
public function testSerialization() {
// Set a container so the DependencySerializationTrait has it.
$container = new ContainerBuilder();
\Drupal::setContainer($container);
$storage = new View([], 'view');
$executable = $this->getMockBuilder('Drupal\views\ViewExecutable')
->disableOriginalConstructor()
->setConstructorArgs([$storage])
->getMock();
$storage->set('executable', $executable);
$view_ui = new ViewUI($storage);
// Make sure the executable is returned before serializing.
$this->assertInstanceOf('Drupal\views\ViewExecutable', $view_ui->getExecutable());
$serialized = serialize($view_ui);
// Make sure the ViewExecutable class is not found in the serialized string.
$this->assertSame(strpos($serialized, '"Drupal\views\ViewExecutable"'), FALSE);
$unserialized = unserialize($serialized);
$this->assertInstanceOf('Drupal\views_ui\ViewUI', $unserialized);
}
}