updated core to 8.6.3
This commit is contained in:
@@ -7,11 +7,11 @@ use Drupal\comment\Tests\CommentTestTrait;
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\views\Views;
|
||||
use Drupal\comment\Entity\Comment;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Tests the default views provided by views.
|
||||
|
||||
@@ -0,0 +1,379 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional;
|
||||
|
||||
use Drupal\Component\Render\MarkupInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\language\Entity\ConfigurableLanguage;
|
||||
use Drupal\language\Entity\ContentLanguageSettings;
|
||||
use Drupal\node\Entity\Node;
|
||||
use Drupal\node\Entity\NodeType;
|
||||
use Drupal\Tests\field\Functional\Views\FieldTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the Field Views data.
|
||||
*
|
||||
* @group views
|
||||
*/
|
||||
class FieldApiDataTest extends FieldTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $modules = ['language'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $testViews = ['test_field_config_translation_filter'];
|
||||
|
||||
/**
|
||||
* The nodes used by the translation filter tests.
|
||||
*
|
||||
* @var \Drupal\node\NodeInterface[]
|
||||
*/
|
||||
protected $translationNodes;
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$field_names = $this->setUpFieldStorages(4);
|
||||
|
||||
// Attach the field to nodes only.
|
||||
$field = [
|
||||
'field_name' => $field_names[0],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'page',
|
||||
'label' => 'GiraffeA" label',
|
||||
];
|
||||
FieldConfig::create($field)->save();
|
||||
|
||||
// Attach the same field to a different bundle with a different label.
|
||||
$this->drupalCreateContentType(['type' => 'article']);
|
||||
FieldConfig::create([
|
||||
'field_name' => $field_names[0],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'article',
|
||||
'label' => 'GiraffeB" label',
|
||||
])->save();
|
||||
|
||||
// Now create some example nodes/users for the view result.
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$edit = [
|
||||
$field_names[0] => [(['value' => $this->randomMachineName()])],
|
||||
];
|
||||
$nodes[] = $this->drupalCreateNode($edit);
|
||||
}
|
||||
|
||||
$bundles = [];
|
||||
$bundles[] = $bundle = NodeType::create(['type' => 'bundle1']);
|
||||
$bundle->save();
|
||||
$bundles[] = $bundle = NodeType::create(['type' => 'bundle2']);
|
||||
$bundle->save();
|
||||
|
||||
// Make the first field translatable on all bundles.
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[1],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[0]->id(),
|
||||
'translatable' => TRUE,
|
||||
]);
|
||||
$field->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[1],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[1]->id(),
|
||||
'translatable' => TRUE,
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Make the second field not translatable on any bundle.
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[2],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[0]->id(),
|
||||
'translatable' => FALSE,
|
||||
]);
|
||||
$field->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[2],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[1]->id(),
|
||||
'translatable' => FALSE,
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Make the last field translatable on some bundles.
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[3],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[0]->id(),
|
||||
'translatable' => TRUE,
|
||||
]);
|
||||
$field->save();
|
||||
$field = FieldConfig::create([
|
||||
'field_name' => $field_names[3],
|
||||
'entity_type' => 'node',
|
||||
'bundle' => $bundles[1]->id(),
|
||||
'translatable' => FALSE,
|
||||
]);
|
||||
$field->save();
|
||||
|
||||
// Create some example content.
|
||||
ConfigurableLanguage::create([
|
||||
'id' => 'es',
|
||||
])->save();
|
||||
ConfigurableLanguage::create([
|
||||
'id' => 'fr',
|
||||
])->save();
|
||||
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundles[0]->id());
|
||||
$config->setDefaultLangcode('es')
|
||||
->setLanguageAlterable(TRUE)
|
||||
->save();
|
||||
$config = ContentLanguageSettings::loadByEntityTypeBundle('node', $bundles[1]->id());
|
||||
$config->setDefaultLangcode('es')
|
||||
->setLanguageAlterable(TRUE)
|
||||
->save();
|
||||
|
||||
$node = Node::create([
|
||||
'title' => 'Test title ' . $bundles[0]->id(),
|
||||
'type' => $bundles[0]->id(),
|
||||
'langcode' => 'es',
|
||||
$field_names[1] => 'field name 1: es',
|
||||
$field_names[2] => 'field name 2: es',
|
||||
$field_names[3] => 'field name 3: es',
|
||||
]);
|
||||
$node->save();
|
||||
$this->translationNodes[] = $node;
|
||||
$translation = $node->addTranslation('fr');
|
||||
$translation->{$field_names[1]}->value = 'field name 1: fr';
|
||||
$translation->{$field_names[3]}->value = 'field name 3: fr';
|
||||
$translation->title->value = $node->title->value;
|
||||
$translation->save();
|
||||
|
||||
$node = Node::create([
|
||||
'title' => 'Test title ' . $bundles[1]->id(),
|
||||
'type' => $bundles[1]->id(),
|
||||
'langcode' => 'es',
|
||||
$field_names[1] => 'field name 1: es',
|
||||
$field_names[2] => 'field name 2: es',
|
||||
$field_names[3] => 'field name 3: es',
|
||||
]);
|
||||
$node->save();
|
||||
$this->translationNodes[] = $node;
|
||||
$translation = $node->addTranslation('fr');
|
||||
$translation->{$field_names[1]}->value = 'field name 1: fr';
|
||||
$translation->title->value = $node->title->value;
|
||||
$translation->save();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Unit testing the views data structure.
|
||||
*
|
||||
* We check data structure for both node and node revision tables.
|
||||
*/
|
||||
public function testViewsData() {
|
||||
$table_mapping = \Drupal::entityManager()->getStorage('node')->getTableMapping();
|
||||
$field_storage = $this->fieldStorages[0];
|
||||
$current_table = $table_mapping->getDedicatedDataTableName($field_storage);
|
||||
$revision_table = $table_mapping->getDedicatedRevisionTableName($field_storage);
|
||||
$data = $this->getViewsData();
|
||||
|
||||
$this->assertTrue(isset($data[$current_table]));
|
||||
$this->assertTrue(isset($data[$revision_table]));
|
||||
// The node field should join against node_field_data.
|
||||
$this->assertTrue(isset($data[$current_table]['table']['join']['node_field_data']));
|
||||
$this->assertTrue(isset($data[$revision_table]['table']['join']['node_field_revision']));
|
||||
|
||||
$expected_join = [
|
||||
'table' => $current_table,
|
||||
'left_field' => 'nid',
|
||||
'field' => 'entity_id',
|
||||
'extra' => [
|
||||
['field' => 'deleted', 'value' => 0, 'numeric' => TRUE],
|
||||
['left_field' => 'langcode', 'field' => 'langcode'],
|
||||
],
|
||||
];
|
||||
$this->assertEqual($expected_join, $data[$current_table]['table']['join']['node_field_data']);
|
||||
$expected_join = [
|
||||
'table' => $revision_table,
|
||||
'left_field' => 'vid',
|
||||
'field' => 'revision_id',
|
||||
'extra' => [
|
||||
['field' => 'deleted', 'value' => 0, 'numeric' => TRUE],
|
||||
['left_field' => 'langcode', 'field' => 'langcode'],
|
||||
],
|
||||
];
|
||||
$this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_field_revision']);
|
||||
|
||||
// Test click sortable.
|
||||
$this->assertTrue($data[$current_table][$field_storage->getName()]['field']['click sortable'], 'String field is click sortable.');
|
||||
// Click sort should only be on the primary field.
|
||||
$this->assertTrue(empty($data[$revision_table][$field_storage->getName()]['field']['click sortable']), 'Non-primary fields are not click sortable');
|
||||
|
||||
$this->assertTrue($data[$current_table][$field_storage->getName()]['help'] instanceof MarkupInterface);
|
||||
$this->assertEqual($data[$current_table][$field_storage->getName()]['help'], 'Appears in: page, article. Also known as: Content: GiraffeB" label');
|
||||
|
||||
$this->assertTrue($data[$current_table][$field_storage->getName() . '_value']['help'] instanceof MarkupInterface);
|
||||
$this->assertEqual($data[$current_table][$field_storage->getName() . '_value']['help'], 'Appears in: page, article. Also known as: Content: GiraffeA" label (field_name_0)');
|
||||
|
||||
// Since each label is only used once, views_entity_field_label() will
|
||||
// return a label using alphabetical sorting.
|
||||
$this->assertEqual('GiraffeA" label (field_name_0)', $data[$current_table][$field_storage->getName() . '_value']['title']);
|
||||
|
||||
// Attach the same field to a different bundle with a different label.
|
||||
$this->drupalCreateContentType(['type' => 'news']);
|
||||
FieldConfig::create([
|
||||
'field_name' => $this->fieldStorages[0]->getName(),
|
||||
'entity_type' => 'node',
|
||||
'bundle' => 'news',
|
||||
'label' => 'GiraffeB" label',
|
||||
])->save();
|
||||
$this->container->get('views.views_data')->clear();
|
||||
$data = $this->getViewsData();
|
||||
|
||||
// Now the 'GiraffeB" label' is used twice and therefore will be
|
||||
// selected by views_entity_field_label().
|
||||
$this->assertEqual('GiraffeB" label (field_name_0)', $data[$current_table][$field_storage->getName() . '_value']['title']);
|
||||
$this->assertTrue($data[$current_table][$field_storage->getName()]['help'] instanceof MarkupInterface);
|
||||
$this->assertEqual($data[$current_table][$field_storage->getName()]['help'], 'Appears in: page, article, news. Also known as: Content: GiraffeA" label');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the views data for the field created in setUp().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getViewsData() {
|
||||
$views_data = $this->container->get('views.views_data');
|
||||
$data = [];
|
||||
|
||||
// Check the table and the joins of the first field.
|
||||
// Attached to node only.
|
||||
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
|
||||
$table_mapping = \Drupal::entityManager()->getStorage('node')->getTableMapping();
|
||||
$current_table = $table_mapping->getDedicatedDataTableName($this->fieldStorages[0]);
|
||||
$revision_table = $table_mapping->getDedicatedRevisionTableName($this->fieldStorages[0]);
|
||||
$data[$current_table] = $views_data->get($current_table);
|
||||
$data[$revision_table] = $views_data->get($revision_table);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests filtering entries with different translatability.
|
||||
*/
|
||||
public function testEntityFieldFilter() {
|
||||
$map = [
|
||||
'nid' => 'nid',
|
||||
'langcode' => 'langcode',
|
||||
];
|
||||
|
||||
$view = Views::getView('test_field_config_translation_filter');
|
||||
|
||||
// Filter by 'field name 1: es'.
|
||||
$view->setDisplay('embed_1');
|
||||
$this->executeView($view);
|
||||
$expected = [
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by 'field name 1: fr'.
|
||||
$view->setDisplay('embed_2');
|
||||
$this->executeView($view);
|
||||
$expected = [
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by 'field name 2: es'.
|
||||
$view->setDisplay('embed_3');
|
||||
$this->executeView($view);
|
||||
$expected = [
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by 'field name 2: fr', which doesn't exist.
|
||||
$view->setDisplay('embed_4');
|
||||
$this->executeView($view);
|
||||
$expected = [];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by 'field name 3: es'.
|
||||
$view->setDisplay('embed_5');
|
||||
$this->executeView($view);
|
||||
$expected = [
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'es',
|
||||
],
|
||||
// Why is this one returned?
|
||||
[
|
||||
'nid' => $this->translationNodes[1]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
|
||||
// Filter by 'field name 3: fr'.
|
||||
$view->setDisplay('embed_6');
|
||||
$this->executeView($view);
|
||||
$expected = [
|
||||
[
|
||||
'nid' => $this->translationNodes[0]->id(),
|
||||
'langcode' => 'fr',
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertIdenticalResultset($view, $expected, $map);
|
||||
$view->destroy();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -339,7 +339,7 @@ class FieldWebTest extends ViewTestBase {
|
||||
$this->assertSubString($output, UrlHelper::encodePath('Drupal Has A Great Community'));
|
||||
unset($id_field->options['alter']['path_case']);
|
||||
|
||||
// Tests the linkclass setting and see whether it actually exists in the
|
||||
// Tests the link_class setting and see whether it actually exists in the
|
||||
// output.
|
||||
$id_field->options['alter']['link_class'] = $class = $this->randomMachineName();
|
||||
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Drupal\Tests\views\Functional\Plugin;
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
@@ -213,7 +213,7 @@ class DisplayEntityReferenceTest extends ViewTestBase {
|
||||
$this->drupalPostForm('admin/structure/views/nojs/display/test_display_entity_reference/entity_reference_1/style_options', ['style_options[search_fields][uid]' => 'uid'], t('Apply'));
|
||||
$this->drupalPostForm(NULL, [], t('Save'));
|
||||
|
||||
// Test that the search still works with the ralated field.
|
||||
// Test that the search still works with the related field.
|
||||
$view = Views::getView('test_display_entity_reference');
|
||||
$view->setDisplay('entity_reference_1');
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the feed display plugin.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\display\Feed
|
||||
*/
|
||||
class DisplayFeedTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_display_feed', 'test_attached_disabled', 'test_feed_icon'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['block', 'node', 'views'];
|
||||
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(['administer site configuration']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the rendered output.
|
||||
*/
|
||||
public function testFeedOutput() {
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
// Verify a title with HTML entities is properly escaped.
|
||||
$node_title = 'This "cool" & "neat" article\'s title';
|
||||
$node = $this->drupalCreateNode([
|
||||
'title' => $node_title,
|
||||
'body' => [
|
||||
0 => [
|
||||
'value' => 'A paragraph',
|
||||
'format' => filter_default_format(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
// Test the site name setting.
|
||||
$site_name = $this->randomMachineName();
|
||||
$this->config('system.site')->set('name', $site_name)->save();
|
||||
|
||||
$this->drupalGet('test-feed-display.xml');
|
||||
$this->assertEquals($site_name, $this->getSession()->getDriver()->getText('//title'));
|
||||
$this->assertEquals($node_title, $this->getSession()->getDriver()->getText('//item/title'));
|
||||
// Verify HTML is properly escaped in the description field.
|
||||
$this->assertRaw('<p>A paragraph</p>');
|
||||
|
||||
$view = $this->container->get('entity.manager')->getStorage('view')->load('test_display_feed');
|
||||
$display = &$view->getDisplay('feed_1');
|
||||
$display['display_options']['sitename_title'] = 0;
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('test-feed-display.xml');
|
||||
$this->assertEquals('test_display_feed', $this->getSession()->getDriver()->getText('//title'));
|
||||
|
||||
// Add a block display and attach the feed.
|
||||
$view->getExecutable()->newDisplay('block', NULL, 'test');
|
||||
$display = &$view->getDisplay('feed_1');
|
||||
$display['display_options']['displays']['test'] = 'test';
|
||||
$view->save();
|
||||
// Test the feed display adds a feed icon to the block display.
|
||||
$this->drupalPlaceBlock('views_block:test_display_feed-test');
|
||||
$this->drupalGet('<front>');
|
||||
$feed_icon = $this->cssSelect('div.view-id-test_display_feed a.feed-icon');
|
||||
$this->assertTrue(strpos($feed_icon[0]->getAttribute('href'), 'test-feed-display.xml'), 'The feed icon was found.');
|
||||
|
||||
// Test feed display attached to page display with arguments.
|
||||
$this->drupalGet('test-feed-icon/' . $node->id());
|
||||
$page_url = $this->getUrl();
|
||||
$icon_href = $this->cssSelect('a.feed-icon[href *= "test-feed-icon"]')[0]->getAttribute('href');
|
||||
$this->assertEqual($icon_href, $page_url . '/feed', 'The feed icon was found.');
|
||||
$link_href = $this->cssSelect('link[type = "application/rss+xml"][href *= "test-feed-icon"]')[0]->getAttribute('href');
|
||||
$this->assertEqual($link_href, $page_url . '/feed', 'The RSS link was found.');
|
||||
$feed_link = simplexml_load_string($this->drupalGet($icon_href))->channel->link;
|
||||
$this->assertEqual($feed_link, $page_url, 'The channel link was found.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the rendered output for fields display.
|
||||
*/
|
||||
public function testFeedFieldOutput() {
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
// Verify a title with HTML entities is properly escaped.
|
||||
$node_title = 'This "cool" & "neat" article\'s title';
|
||||
$this->drupalCreateNode([
|
||||
'title' => $node_title,
|
||||
'body' => [
|
||||
0 => [
|
||||
'value' => 'A paragraph',
|
||||
'format' => filter_default_format(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->drupalGet('test-feed-display-fields.xml');
|
||||
$this->assertEquals($node_title, $this->getSession()->getDriver()->getText('//title/a'));
|
||||
// Verify HTML is properly escaped in the description field.
|
||||
$this->assertRaw('<p>A paragraph</p>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that nothing is output when the feed display is disabled.
|
||||
*/
|
||||
public function testDisabledFeed() {
|
||||
$this->drupalCreateContentType(['type' => 'page']);
|
||||
$this->drupalCreateNode();
|
||||
|
||||
// Ensure that the feed_1 display is attached to the page_1 display.
|
||||
$view = Views::getView('test_attached_disabled');
|
||||
$view->setDisplay('page_1');
|
||||
$attached_displays = $view->display_handler->getAttachedDisplays();
|
||||
$this->assertTrue(in_array('feed_1', $attached_displays), 'The feed display is attached to the page display.');
|
||||
|
||||
// Check that the rss header is output on the page display.
|
||||
$this->drupalGet('/test-attached-disabled');
|
||||
$feed_header = $this->xpath('//link[@rel="alternate"]');
|
||||
$this->assertEqual($feed_header[0]->getAttribute('type'), 'application/rss+xml', 'The feed link has the type application/rss+xml.');
|
||||
$this->assertTrue(strpos($feed_header[0]->getAttribute('href'), 'test-attached-disabled.xml'), 'Page display contains the correct feed URL.');
|
||||
|
||||
// Disable the feed display.
|
||||
$view->displayHandlers->get('feed_1')->setOption('enabled', FALSE);
|
||||
$view->save();
|
||||
|
||||
// Ensure there is no link rel present on the page.
|
||||
$this->drupalGet('/test-attached-disabled');
|
||||
$result = $this->xpath('//link[@rel="alternate"]');
|
||||
$this->assertTrue(empty($result), 'Page display does not contain a feed header.');
|
||||
|
||||
// Ensure the feed attachment returns 'Not found'.
|
||||
$this->drupalGet('/test-attached-disabled.xml');
|
||||
$this->assertResponse(404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the feed display works when the linked display is disabled.
|
||||
*/
|
||||
public function testDisabledLinkedDisplay() {
|
||||
$view = Views::getView('test_attached_disabled');
|
||||
$view->setDisplay();
|
||||
// Disable the page and link the feed to the page.
|
||||
$view->displayHandlers->get('feed_1')->setOption('link_display', 'page_1');
|
||||
$view->displayHandlers->get('page_1')->setOption('enabled', FALSE);
|
||||
$view->save();
|
||||
|
||||
\Drupal::service('router.builder')->rebuild();
|
||||
|
||||
$this->drupalGet('test-attached-disabled');
|
||||
$this->assertResponse(404);
|
||||
// Ensure the feed can still be reached.
|
||||
$this->drupalGet('test-attached-disabled.xml');
|
||||
$this->assertResponse(200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
use Drupal\views\Views;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\views\Functional\Plugin;
|
||||
|
||||
use Drupal\Tests\views\Functional\ViewTestBase;
|
||||
|
||||
/**
|
||||
* Tests the OPML feed style plugin.
|
||||
*
|
||||
* @group views
|
||||
* @see \Drupal\views\Plugin\views\style\Opml
|
||||
*/
|
||||
class StyleOpmlTest extends ViewTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = ['test_style_opml'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = ['aggregator'];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp($import_test_views = TRUE) {
|
||||
parent::setUp($import_test_views);
|
||||
|
||||
$this->enableViewsTestModule();
|
||||
|
||||
$admin_user = $this->drupalCreateUser(['administer news feeds']);
|
||||
$this->drupalLogin($admin_user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the rendered output.
|
||||
*/
|
||||
public function testOpmlOutput() {
|
||||
// Create a test feed.
|
||||
$values = [
|
||||
'title' => $this->randomMachineName(10),
|
||||
'url' => 'http://example.com/rss.xml',
|
||||
'refresh' => '900',
|
||||
];
|
||||
$feed = $this->container->get('entity.manager')
|
||||
->getStorage('aggregator_feed')
|
||||
->create($values);
|
||||
$feed->save();
|
||||
|
||||
$this->drupalGet('test-feed-opml-style');
|
||||
$outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
|
||||
$this->assertEquals('rss', $outline->getAttribute('type'));
|
||||
$this->assertEquals($feed->label(), $outline->getAttribute('text'));
|
||||
$this->assertEquals($feed->getUrl(), $outline->getAttribute('xmlUrl'));
|
||||
|
||||
$view = $this->container->get('entity.manager')
|
||||
->getStorage('view')
|
||||
->load('test_style_opml');
|
||||
$display = &$view->getDisplay('feed_1');
|
||||
$display['display_options']['row']['options']['type_field'] = 'link';
|
||||
$display['display_options']['row']['options']['url_field'] = 'url';
|
||||
$view->save();
|
||||
|
||||
$this->drupalGet('test-feed-opml-style');
|
||||
$outline = $this->getSession()->getDriver()->find('//outline[1]')[0];
|
||||
$this->assertEquals('link', $outline->getAttribute('type'));
|
||||
$this->assertEquals($feed->label(), $outline->getAttribute('text'));
|
||||
$this->assertEquals($feed->getUrl(), $outline->getAttribute('url'));
|
||||
// xmlUrl should not be present when type is link.
|
||||
$this->assertNull($outline->getAttribute('xmlUrl'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,8 +4,8 @@ namespace Drupal\Tests\views\Functional\Wizard;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Tests the ability of the views wizard to create views filtered by taxonomy.
|
||||
|
||||
@@ -37,9 +37,9 @@ class ModuleTest extends ViewsKernelTestBase {
|
||||
protected $lastErrorMessage;
|
||||
|
||||
/**
|
||||
* Tests the views_get_handler method.
|
||||
* Tests the ViewsHandlerManager::getHandler() method.
|
||||
*
|
||||
* @see views_get_handler()
|
||||
* @see \Drupal\views\Plugin\ViewsHandlerManager::getHandler()
|
||||
*/
|
||||
public function testViewsGetHandler() {
|
||||
$types = ['field', 'area', 'filter'];
|
||||
|
||||
@@ -136,7 +136,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
|
||||
// Test the initStyle() method.
|
||||
$view->initStyle();
|
||||
$this->assertTrue($view->style_plugin instanceof DefaultStyle, 'Make sure a reference to the style plugin is set.');
|
||||
// Test the plugin has been inited and view have references to the view and
|
||||
// Test the plugin has been invited and view have references to the view and
|
||||
// display handler.
|
||||
$this->assertEqual(spl_object_hash($view->style_plugin->view), $view_hash);
|
||||
$this->assertEqual(spl_object_hash($view->style_plugin->displayHandler), $display_hash);
|
||||
|
||||
Reference in New Issue
Block a user