Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\taxonomy\Tests\Views\TaxonomyFieldAllTerms.
|
||||
*/
|
||||
|
||||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
* Tests the "All terms" taxonomy term field handler.
|
||||
*
|
||||
* @group taxonomy
|
||||
*/
|
||||
class TaxonomyFieldAllTermsTest extends TaxonomyTestBase {
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $testViews = array('taxonomy_all_terms_test');
|
||||
|
||||
function testViewsHandlerAllTermsField() {
|
||||
$view = Views::getView('taxonomy_all_terms_test');
|
||||
$this->executeView($view);
|
||||
$this->drupalGet('taxonomy_all_terms_test');
|
||||
|
||||
$actual = $this->xpath('//a[@href="' . $this->term1->url() . '"]');
|
||||
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term1 links');
|
||||
$this->assertEqual($actual[0]->__toString(), $this->term1->label());
|
||||
$this->assertEqual($actual[1]->__toString(), $this->term1->label());
|
||||
|
||||
$actual = $this->xpath('//a[@href="' . $this->term2->url() . '"]');
|
||||
$this->assertEqual(count($actual), 2, 'Correct number of taxonomy term2 links');
|
||||
$this->assertEqual($actual[0]->__toString(), $this->term2->label());
|
||||
$this->assertEqual($actual[1]->__toString(), $this->term2->label());
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
use Drupal\Core\Render\RenderContext;
|
||||
use Drupal\views\Views;
|
||||
|
||||
/**
|
||||
|
@ -24,10 +25,15 @@ class TaxonomyFieldTidTest extends TaxonomyTestBase {
|
|||
public static $testViews = array('test_taxonomy_tid_field');
|
||||
|
||||
function testViewsHandlerTidField() {
|
||||
/** @var \Drupal\Core\Render\RendererInterface $renderer */
|
||||
$renderer = \Drupal::service('renderer');
|
||||
|
||||
$view = Views::getView('test_taxonomy_tid_field');
|
||||
$this->executeView($view);
|
||||
|
||||
$actual = $view->field['name']->advancedRender($view->result[0]);
|
||||
$actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
|
||||
return $view->field['name']->advancedRender($view->result[0]);
|
||||
});
|
||||
$expected = \Drupal::l($this->term1->label(), $this->term1->urlInfo());
|
||||
|
||||
$this->assertEqual($expected, $actual);
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
namespace Drupal\taxonomy\Tests\Views;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
|
||||
use Drupal\taxonomy\Entity\Term;
|
||||
use Drupal\taxonomy\Entity\Vocabulary;
|
||||
use Drupal\views\Tests\ViewTestData;
|
||||
|
@ -20,6 +22,8 @@ use Drupal\views_ui\Tests\UITestBase;
|
|||
*/
|
||||
class TaxonomyIndexTidUiTest extends UITestBase {
|
||||
|
||||
use EntityReferenceTestTrait;
|
||||
|
||||
/**
|
||||
* Views used by this test.
|
||||
*
|
||||
|
@ -32,7 +36,7 @@ class TaxonomyIndexTidUiTest extends UITestBase {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views');
|
||||
public static $modules = array('node', 'taxonomy', 'taxonomy_test_views', 'entity_reference');
|
||||
|
||||
/**
|
||||
* A nested array of \Drupal\taxonomy\TermInterface objects.
|
||||
|
@ -120,4 +124,72 @@ class TaxonomyIndexTidUiTest extends UITestBase {
|
|||
$this->assertIdentical($expected, $view->calculateDependencies());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests exposed taxonomy filters.
|
||||
*/
|
||||
public function testExposedFilter() {
|
||||
$node_type = $this->drupalCreateContentType(['type' => 'page']);
|
||||
|
||||
// Create the tag field itself.
|
||||
$field_name = 'taxonomy_tags';
|
||||
$this->createEntityReferenceField('node', $node_type->id(), $field_name, NULL, 'taxonomy_term');
|
||||
|
||||
// Create 4 nodes: 1 without a term, 2 with the same term, and 1 with a
|
||||
// different term.
|
||||
$node1 = $this->drupalCreateNode();
|
||||
$node2 = $this->drupalCreateNode([
|
||||
$field_name => [['target_id' => $this->terms[1][0]->id()]],
|
||||
]);
|
||||
$node3 = $this->drupalCreateNode([
|
||||
$field_name => [['target_id' => $this->terms[1][0]->id()]],
|
||||
]);
|
||||
$node4 = $this->drupalCreateNode([
|
||||
$field_name => [['target_id' => $this->terms[2][0]->id()]],
|
||||
]);
|
||||
|
||||
// Only the nodes with the selected term should be shown.
|
||||
$this->drupalGet('test-filter-taxonomy-index-tid');
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a');
|
||||
$this->assertIdentical(2, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
|
||||
// Expose the filter.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', [], 'Expose filter');
|
||||
// Set the operator to 'empty' and remove the default term ID.
|
||||
$this->drupalPostForm(NULL, [
|
||||
'options[operator]' => 'empty',
|
||||
'options[value][]' => [],
|
||||
], 'Apply');
|
||||
// Save the view.
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
|
||||
// After switching to 'empty' operator, the node without a term should be
|
||||
// shown.
|
||||
$this->drupalGet('test-filter-taxonomy-index-tid');
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a');
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node1->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
|
||||
// Set the operator to 'not empty'.
|
||||
$this->drupalPostForm('admin/structure/views/nojs/handler/test_filter_taxonomy_index_tid/default/filter/tid', ['options[operator]' => 'not empty'], 'Apply');
|
||||
// Save the view.
|
||||
$this->drupalPostForm(NULL, [], 'Save');
|
||||
|
||||
// After switching to 'not empty' operator, all nodes with terms should be
|
||||
// shown.
|
||||
$this->drupalGet('test-filter-taxonomy-index-tid');
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a');
|
||||
$this->assertIdentical(3, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node2->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node3->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
$xpath = $this->xpath('//div[@class="view-content"]//a[@href=:href]', [':href' => $node4->url()]);
|
||||
$this->assertIdentical(1, count($xpath));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue