Commit 2fb6246e authored by alexpott's avatar alexpott

Issue #2600804 by Lendude, D4K0, dawehner, droplet: AJAXified glossary view...

Issue #2600804 by Lendude, D4K0, dawehner, droplet: AJAXified glossary view arguments fail when Language URL detection enabled
parent a8579d60
......@@ -53,9 +53,11 @@
Drupal.Views.parseViewArgs = function (href, viewPath) {
var returnObj = {};
var path = Drupal.Views.getPath(href);
// Get viewPath url without baseUrl portion.
var viewHref = Drupal.url(viewPath).substring(drupalSettings.path.baseUrl.length);
// Ensure we have a correct path.
if (viewPath && path.substring(0, viewPath.length + 1) === viewPath + '/') {
returnObj.view_args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
if (viewHref && path.substring(0, viewHref.length + 1) === viewHref + '/') {
returnObj.view_args = decodeURIComponent(path.substring(viewHref.length + 1, path.length));
returnObj.view_path = path;
}
return returnObj;
......
<?php
namespace Drupal\Tests\views\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\simpletest\NodeCreationTrait;
use Drupal\views\Tests\ViewTestData;
/**
* Tests the basic AJAX functionality of the Glossary View.
*
* @group node
*/
class GlossaryViewTest extends JavascriptTestBase {
use ContentTypeCreationTrait;
use NodeCreationTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['language', 'node', 'views', 'views_test_config'];
/**
* @var array
* The test Views to enable.
*/
public static $testViews = ['test_glossary'];
/**
* @var
* The additional language to use.
*/
protected $language;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
ViewTestData::createTestViews(get_class($this), array('views_test_config'));
// Create a Content type and some test nodes with titles that start with
// different letters.
$this->createContentType(['type' => 'page']);
$titles = [
'Page One',
'Page Two',
'Another page',
];
foreach ($titles as $title) {
$this->createNode([
'title' => $title,
'language' => 'en',
]);
$this->createNode([
'title' => $title,
'language' => 'nl',
]);
}
// Create a user privileged enough to use exposed filters and view content.
$user = $this->drupalCreateUser([
'administer site configuration',
'access content',
'access content overview',
]);
$this->drupalLogin($user);
}
/**
* Tests the AJAX callbacks for the glossary view.
*/
public function testGlossaryDefault() {
// Visit the default Glossary page.
$url = Url::fromRoute('view.test_glossary.page_1');
$this->drupalGet($url);
$session = $this->getSession();
$web_assert = $this->assertSession();
$page = $session->getPage();
$rows = $page->findAll('css', '.view-test-glossary tr');
// We expect 2 rows plus the header row.
$this->assertCount(3, $rows);
// Click on the P link, this should show 4 rows plus the header row.
$page->clickLink('P');
$web_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', '.view-test-glossary tr');
$this->assertCount(5, $rows);
}
/**
* Test that the glossary also works on a language prefixed URL.
*/
public function testGlossaryLanguagePrefix() {
$this->language = ConfigurableLanguage::createFromLangcode('nl')->save();
$config = $this->config('language.negotiation');
$config->set('url.prefixes', ['en' => 'en', 'nl' => 'nl'])
->save();
\Drupal::service('kernel')->rebuildContainer();
$url = Url::fromRoute('view.test_glossary.page_1');
$this->drupalGet($url);
$session = $this->getSession();
$web_assert = $this->assertSession();
$page = $session->getPage();
$rows = $page->findAll('css', '.view-test-glossary tr');
// We expect 2 rows plus the header row.
$this->assertCount(3, $rows);
// Click on the P link, this should show 4 rows plus the header row.
$page->clickLink('P');
$web_assert->assertWaitOnAjaxRequest();
$rows = $page->findAll('css', '.view-test-glossary tr');
$this->assertCount(5, $rows);
}
}
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