Commit 360a22ec authored by WalkingDexter's avatar WalkingDexter Committed by atymchuk

Issue #3037928: Several functional tests

parent 4f28758c
......@@ -207,6 +207,43 @@ display:
entity_type: node
entity_field: title
plugin_id: string
nid:
id: nid
table: node_field_data
field: nid
relationship: none
group_type: group
admin_label: ''
default_action: ignore
exception:
value: all
title_enable: false
title: All
title_enable: false
title: ''
default_argument_type: fixed
default_argument_options:
argument: ''
default_argument_skip_url: false
summary_options:
base_path: ''
count: true
items_per_page: 25
override: false
summary:
sort_order: asc
number_of_records: 0
format: default_summary
specify_validation: false
validate:
type: none
fail: 'not found'
validate_options: { }
break_phrase: false
not: false
entity_type: node
entity_field: nid
plugin_id: node_nid
display_extenders: { }
cache_metadata:
max-age: -1
......@@ -231,7 +268,8 @@ display:
changefreq: ''
arguments:
type: type
max_links: 100
title: title
max_links: 2
path: simple-sitemap-views-test-view
rendering_language: en
cache_metadata:
......
<?php
/**
* @file
* Contains functional tests for Simple XML Sitemap (Views).
*/
namespace Drupal\Tests\simple_sitemap_views\Functional;
/**
......@@ -14,14 +9,6 @@ namespace Drupal\Tests\simple_sitemap_views\Functional;
*/
class SimpleSitemapViewsTest extends SimpleSitemapViewsTestBase {
/**
* Tests Views URL generator availability.
*/
public function testViewsUrlGeneratorAvailability() {
$sitemap_types = $this->generator->getSitemapManager()->getSitemapTypes();
$this->assertContains('views', $sitemap_types['default_hreflang']['urlGenerators']);
}
/**
* Tests status of sitemap support for views.
*/
......@@ -44,19 +31,72 @@ class SimpleSitemapViewsTest extends SimpleSitemapViewsTestBase {
$indexable_views = $this->sitemapViews->getIndexableViews();
$this->assertNotEmpty($indexable_views);
$test_view = NULL;
$test_view_exists = FALSE;
foreach ($indexable_views as &$view) {
if ($view->id() == 'simple_sitemap_views_test_view' && $view->current_display == 'page_1') {
$test_view = $view;
if ($view->id() == $this->testView->id() && $view->current_display == $this->testView->current_display) {
$test_view_exists = TRUE;
break;
}
}
// The test view should be in the list.
$this->assertNotNull($test_view);
$this->assertTrue($test_view_exists);
// Check the indexing status of the argument.
$indexable_arguments = $this->sitemapViews->getIndexableArguments($test_view);
// Check the indexing status of the arguments.
$indexable_arguments = $this->sitemapViews->getIndexableArguments($this->testView);
$this->assertContains('type', $indexable_arguments);
$this->assertContains('title', $indexable_arguments);
$this->assertNotContains('nid', $indexable_arguments);
}
/**
* Tests the process of adding arguments to the index.
*/
public function testAddArgumentsToIndex() {
// Arguments with the wrong value should not be indexed.
$this->sitemapViews->addArgumentsToIndex($this->testView, ['page2']);
$this->assertEquals(0, $this->sitemapViews->getArgumentsFromIndexCount());
// Non-indexable arguments should not be indexed.
$args = ['page', $this->node->getTitle(), $this->node->id()];
$this->sitemapViews->addArgumentsToIndex($this->testView, $args);
$this->assertEquals(0, $this->sitemapViews->getArgumentsFromIndexCount());
// The argument set should not be indexed more than once.
for ($i = 0; $i < 2; $i++) {
$this->sitemapViews->addArgumentsToIndex($this->testView, ['page']);
$this->assertEquals(1, $this->sitemapViews->getArgumentsFromIndexCount());
}
// A new set of arguments must be indexed.
$args = ['page', $this->node->getTitle()];
$this->sitemapViews->addArgumentsToIndex($this->testView, $args);
$this->assertEquals(2, $this->sitemapViews->getArgumentsFromIndexCount());
// The number of argument sets in the index for one view display should not
// exceed the maximum number of link variations.
$args = ['page', $this->node2->getTitle()];
$this->sitemapViews->addArgumentsToIndex($this->testView, $args);
$this->assertEquals(2, $this->sitemapViews->getArgumentsFromIndexCount());
}
/**
* Tests the process of generating view display URLs.
*/
public function testViewsUrlGenerator() {
$sitemap_types = $this->generator->getSitemapManager()->getSitemapTypes();
$this->assertContains('views', $sitemap_types['default_hreflang']['urlGenerators']);
$title = $this->node->getTitle();
$this->sitemapViews->addArgumentsToIndex($this->testView, ['page']);
$this->sitemapViews->addArgumentsToIndex($this->testView, ['page', $title]);
$this->generator->generateSitemap('backend');
// Check that the sitemap contains view display URLs.
$this->drupalGet($this->defaultSitemapUrl);
$test_view_url = $this->testView->getUrl()->toString();
$this->assertSession()->responseContains($test_view_url);
$this->assertSession()->responseContains("$test_view_url/page");
$this->assertSession()->responseContains("$test_view_url/page/$title");
}
}
<?php
/**
* @file
* Contains a base class for Simple XML Sitemap (Views) functional testing.
*/
namespace Drupal\Tests\simple_sitemap_views\Functional;
use Drupal\Tests\simple_sitemap\Functional\SimplesitemapTestBase;
use Drupal\views\Views;
/**
* Defines a base class for Simple XML Sitemap (Views) functional testing.
......@@ -29,6 +25,13 @@ abstract class SimpleSitemapViewsTestBase extends SimplesitemapTestBase {
*/
protected $sitemapViews;
/**
* Test view.
*
* @var \Drupal\views\ViewExecutable
*/
protected $testView;
/**
* {@inheritdoc}
*/
......@@ -36,6 +39,8 @@ abstract class SimpleSitemapViewsTestBase extends SimplesitemapTestBase {
parent::setUp();
$this->sitemapViews = $this->container->get('simple_sitemap.views');
$this->testView = Views::getView('simple_sitemap_views_test_view');
$this->testView->setDisplay('page_1');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment