Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -0,0 +1,48 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyConfigsTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to taxonomy.settings.yml.
*
* @group taxonomy
*/
class MigrateTaxonomyConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Variable.php']);
$this->executeMigration('d6_taxonomy_settings');
}
/**
* Tests migration of taxonomy variables to taxonomy.settings.yml.
*/
public function testTaxonomySettings() {
$config = $this->config('taxonomy.settings');
$this->assertIdentical(100, $config->get('terms_per_page_admin'));
$this->assertIdentical(FALSE, $config->get('override_selector'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'taxonomy.settings', $config->get());
}
}

View file

@ -0,0 +1,108 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyTermTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\taxonomy\Entity\Term;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Upgrade taxonomy terms.
*
* @group taxonomy
*/
class MigrateTaxonomyTermTest extends MigrateDrupal6TestBase {
static $modules = array('taxonomy', 'text');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
$this->prepareMigrations(array(
'd6_taxonomy_vocabulary' => array(
array(array(1), array('vocabulary_1_i_0_')),
array(array(2), array('vocabulary_2_i_1_')),
array(array(3), array('vocabulary_3_i_2_')),
)));
$this->loadDumps([
'TermData.php',
'TermHierarchy.php',
'Vocabulary.php',
'VocabularyNodeTypes.php',
]);
$this->executeMigration('d6_taxonomy_term');
}
/**
* Tests the Drupal 6 taxonomy term to Drupal 8 migration.
*/
public function testTaxonomyTerms() {
$expected_results = array(
'1' => array(
'source_vid' => 1,
'vid' => 'vocabulary_1_i_0_',
'weight' => 0,
'parent' => array(0),
),
'2' => array(
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 3,
'parent' => array(0),
),
'3' => array(
'source_vid' => 2,
'vid' => 'vocabulary_2_i_1_',
'weight' => 4,
'parent' => array(2),
),
'4' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 6,
'parent' => array(0),
),
'5' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 7,
'parent' => array(4),
),
'6' => array(
'source_vid' => 3,
'vid' => 'vocabulary_3_i_2_',
'weight' => 8,
'parent' => array(4, 5),
),
);
$terms = Term::loadMultiple(array_keys($expected_results));
foreach ($expected_results as $tid => $values) {
/** @var Term $term */
$term = $terms[$tid];
$this->assertIdentical("term {$tid} of vocabulary {$values['source_vid']}", $term->name->value);
$this->assertIdentical("description of term {$tid} of vocabulary {$values['source_vid']}", $term->description->value);
$this->assertIdentical($values['vid'], $term->vid->target_id);
$this->assertIdentical((string) $values['weight'], $term->weight->value);
if ($values['parent'] === array(0)) {
$this->assertNull($term->parent->target_id);
}
else {
$parents = array();
foreach (\Drupal::entityManager()->getStorage('taxonomy_term')->loadParents($tid) as $parent) {
$parents[] = (int) $parent->id();
}
$this->assertIdentical($parents, $values['parent']);
}
}
}
}

View file

@ -0,0 +1,56 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTaxonomyVocabularyTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Migrate taxonomy vocabularies to taxonomy.vocabulary.*.yml.
*
* @group taxonomy
*/
class MigrateTaxonomyVocabularyTest extends MigrateDrupal6TestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_taxonomy_vocabulary');
}
/**
* Tests the Drupal 6 taxonomy vocabularies to Drupal 8 migration.
*/
public function testTaxonomyVocabulary() {
for ($i = 0; $i < 3; $i++) {
$j = $i + 1;
$vocabulary = Vocabulary::load("vocabulary_{$j}_i_{$i}_");
$this->assertIdentical(entity_load('migration', 'd6_taxonomy_vocabulary')->getIdMap()->lookupDestinationID(array($j)), array($vocabulary->id()));
$this->assertIdentical("vocabulary $j (i=$i)", $vocabulary->label());
$this->assertIdentical("description of vocabulary $j (i=$i)", $vocabulary->getDescription());
$this->assertIdentical($i, $vocabulary->getHierarchy());
$this->assertIdentical(4 + $i, $vocabulary->get('weight'));
}
$vocabulary = Vocabulary::load('vocabulary_name_much_longer_than');
$this->assertIdentical('vocabulary name much longer than thirty two characters', $vocabulary->label());
$this->assertIdentical('description of vocabulary name much longer than thirty two characters', $vocabulary->getDescription());
$this->assertIdentical(3, $vocabulary->getHierarchy());
$this->assertIdentical(7, $vocabulary->get('weight'));
}
}

View file

@ -0,0 +1,51 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeRevisionTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\MigrateExecutable;
/**
* Upgrade taxonomy term node associations.
*
* @group taxonomy
*/
class MigrateTermNodeRevisionTest extends MigrateTermNodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$id_mappings = array(
'd6_term_node' => array(
array(array(2), array(1)),
),
'd6_node_revision' => array(
array(array(2), array(2)),
),
);
$this->prepareMigrations($id_mappings);
/** @var \Drupal\migrate\entity\Migration $migration */
$migrations = entity_load_multiple('migration', array('d6_term_node_revision:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Tests the Drupal 6 term-node revision association to Drupal 8 migration.
*/
public function testTermRevisionNode() {
$node = \Drupal::entityManager()->getStorage('node')->loadRevision(2);
$this->assertIdentical(2, count($node->vocabulary_3_i_2_));
$this->assertIdentical('4', $node->vocabulary_3_i_2_[0]->target_id);
$this->assertIdentical('5', $node->vocabulary_3_i_2_[1]->target_id);
}
}

View file

@ -0,0 +1,49 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate\MigrateExecutable;
use Drupal\node\Entity\Node;
/**
* Upgrade taxonomy term node associations.
*
* @group taxonomy
*/
class MigrateTermNodeTest extends MigrateTermNodeTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
/** @var \Drupal\migrate\entity\Migration $migration */
$migrations = entity_load_multiple('migration', array('d6_term_node:*'));
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this);
$executable->import();
}
}
/**
* Tests the Drupal 6 term-node association to Drupal 8 migration.
*/
public function testTermNode() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$node_storage->resetCache(array(1, 2));
$nodes = Node::loadMultiple(array(1, 2));
$node = $nodes[1];
$this->assertIdentical(1, count($node->vocabulary_1_i_0_));
$this->assertIdentical('1', $node->vocabulary_1_i_0_[0]->target_id);
$node = $nodes[2];
$this->assertIdentical(2, count($node->vocabulary_2_i_1_));
$this->assertIdentical('2', $node->vocabulary_2_i_1_[0]->target_id);
$this->assertIdentical('3', $node->vocabulary_2_i_1_[1]->target_id);
}
}

View file

@ -0,0 +1,98 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateTermNodeTestBase.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference\Tests\EntityReferenceTestTrait;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Base class for Taxonomy/Node migration tests.
*/
abstract class MigrateTermNodeTestBase extends MigrateDrupal6TestBase {
use EntityReferenceTestTrait;
/**
* {@inheritdoc}
*/
static $modules = array('node', 'taxonomy', 'text', 'filter', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('taxonomy_term');
$this->installSchema('node', array('node_access'));
$vocabulary = entity_create('taxonomy_vocabulary', array(
'vid' => 'test',
));
$vocabulary->save();
$node_type = entity_create('node_type', array('type' => 'story'));
$node_type->save();
foreach (array('vocabulary_1_i_0_', 'vocabulary_2_i_1_', 'vocabulary_3_i_2_') as $name) {
$handler_settings = array(
'target_bundles' => array(
$vocabulary->id() => $vocabulary->id(),
),
'auto_create' => TRUE,
);
$this->createEntityReferenceField('node', 'story', $name, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
}
$id_mappings = array(
'd6_vocabulary_field_instance' => array(
array(array(1, 'page'), array('node', 'page', 'test')),
),
'd6_vocabulary_entity_display' => array(
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
),
'd6_vocabulary_entity_form_display' => array(
array(array(1, 'page'), array('node', 'page', 'default', 'test')),
),
'd6_node' => array(
array(array(1), array(1)),
array(array(2), array(2)),
),
);
$this->prepareMigrations($id_mappings);
$vids = array(1, 2, 3);
for ($i = 1; $i <= 2; $i++) {
$node = entity_create('node', array(
'type' => 'story',
'nid' => $i,
'vid' => array_shift($vids),
));
$node->enforceIsNew();
$node->save();
if ($i == 1) {
$node->vid->value = array_shift($vids);
$node->enforceIsNew(FALSE);
$node->setNewRevision();
$node->isDefaultRevision(FALSE);
$node->save();
}
}
$this->loadDumps([
'Node.php',
'NodeRevisions.php',
'ContentTypeStory.php',
'ContentTypeTestPlanet.php',
'TermNode.php',
'TermHierarchy.php',
'TermData.php',
'Vocabulary.php',
'VocabularyNodeTypes.php',
]);
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyEntityDisplayTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary entity display migration.
*
* @group taxonomy
*/
class MigrateVocabularyEntityDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('field', 'node', 'taxonomy', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
foreach (array('page', 'article', 'story') as $type) {
entity_create('node_type', array('type' => $type))->save();
entity_create('field_config', array(
'label' => 'Tags',
'description' => '',
'field_name' => 'tags',
'entity_type' => 'node',
'bundle' => $type,
'required' => 1,
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
'tags' => 'tags',
),
'auto_create' => TRUE,
),
),
))->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field_instance' => array(
array(array(4, 'page'), array('node', 'page', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_entity_display');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyEntityDisplay() {
// Test that the field exists.
$component = entity_get_display('node', 'page', 'default')->getComponent('tags');
$this->assertIdentical('entity_reference_label', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,89 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyEntityFormDisplayTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary entity form display migration.
*
* @group taxonomy
*/
class MigrateVocabularyEntityFormDisplayTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
foreach (array('page', 'article', 'story') as $type) {
entity_create('node_type', array('type' => $type))->save();
entity_create('field_config', array(
'label' => 'Tags',
'description' => '',
'field_name' => 'tags',
'entity_type' => 'node',
'bundle' => $type,
'required' => 1,
'settings' => array(
'handler' => 'default',
'handler_settings' => array(
'target_bundles' => array(
'tags' => 'tags',
),
'auto_create' => TRUE,
),
),
))->save();
}
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field_instance' => array(
array(array(4, 'page'), array('node', 'page', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_entity_form_display');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyEntityFormDisplay() {
// Test that the field exists.
$component = entity_get_form_display('node', 'page', 'default')->getComponent('tags');
$this->assertIdentical('options_select', $component['type']);
$this->assertIdentical(20, $component['weight']);
// Test the Id map.
$this->assertIdentical(array('node', 'article', 'default', 'tags'), entity_load('migration', 'd6_vocabulary_entity_form_display')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,97 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyFieldInstanceTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary field instance migration.
*
* @group taxonomy
*/
class MigrateVocabularyFieldInstanceTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'field', 'taxonomy', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
entity_create('node_type', array('type' => 'page'))->save();
entity_create('node_type', array('type' => 'article'))->save();
entity_create('node_type', array('type' => 'story'))->save();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_node_type' => array(
array(array('article'), array('article')),
array(array('page'), array('page')),
array(array('story'), array('story')),
),
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
'd6_vocabulary_field' => array(
array(array(4), array('node', 'tags')),
)
);
$this->prepareMigrations($id_mappings);
// Create the vocab.
entity_create('taxonomy_vocabulary', array(
'field_name' => 'Test Vocabulary',
'description' => 'Test Vocabulary',
'vid' => 'tags',
))->save();
// Create the field storage.
entity_create('field_storage_config', array(
'entity_type' => 'node',
'field_name' => 'tags',
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'settings' => array(
'target_type' => 'taxonomy_term',
),
))->save();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_field_instance');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyFieldInstance() {
// Test that the field exists.
$field_id = 'node.article.tags';
$field = FieldConfig::load($field_id);
$this->assertIdentical($field_id, $field->id(), 'Field instance exists on article bundle.');
// Test the page bundle as well.
$field_id = 'node.page.tags';
$field = FieldConfig::load($field_id);
$this->assertIdentical($field_id, $field->id(), 'Field instance exists on page bundle.');
$settings = $field->getSettings();
$this->assertIdentical('default:taxonomy_term', $settings['handler'], 'The handler plugin ID is correct.');
$this->assertIdentical(['tags'], $settings['handler_settings']['target_bundles'], 'The target_bundle handler setting is correct.');
$this->assertIdentical(TRUE, $settings['handler_settings']['auto_create'], 'The "auto_create" setting is correct.');
$this->assertIdentical(array('node', 'article', 'tags'), entity_load('migration', 'd6_vocabulary_field_instance')->getIdMap()->lookupDestinationID(array(4, 'article')));
}
}

View file

@ -0,0 +1,66 @@
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\Migrate\d6\MigrateVocabularyFieldTest.
*/
namespace Drupal\taxonomy\Tests\Migrate\d6;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
/**
* Vocabulary field migration.
*
* @group taxonomy
*/
class MigrateVocabularyFieldTest extends MigrateDrupal6TestBase {
/**
* The modules to be enabled during the test.
*
* @var array
*/
static $modules = array('node', 'taxonomy', 'field', 'text', 'entity_reference');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Add some id mappings for the dependant migrations.
$id_mappings = array(
'd6_taxonomy_vocabulary' => array(
array(array(4), array('tags')),
),
);
$this->prepareMigrations($id_mappings);
entity_create('taxonomy_vocabulary', array(
'name' => 'Test Vocabulary',
'description' => 'Test Vocabulary',
'vid' => 'test_vocab',
))->save();
$this->loadDumps(['Vocabulary.php', 'VocabularyNodeTypes.php']);
$this->executeMigration('d6_vocabulary_field');
}
/**
* Tests the Drupal 6 vocabulary-node type association to Drupal 8 migration.
*/
public function testVocabularyField() {
// Test that the field exists.
$field_storage_id = 'node.tags';
$field_storage = FieldStorageConfig::load($field_storage_id);
$this->assertIdentical($field_storage_id, $field_storage->id());
$settings = $field_storage->getSettings();
$this->assertIdentical('taxonomy_term', $settings['target_type'], "Target type is correct.");
$this->assertIdentical(array('node', 'tags'), entity_load('migration', 'd6_vocabulary_field')->getIdMap()->lookupDestinationID(array(4)), "Test IdMap");
}
}

View file

@ -8,6 +8,7 @@
namespace Drupal\taxonomy\Tests;
use Drupal\user\RoleInterface;
use Drupal\file\Entity\File;
/**
* Tests access checks of private image fields.
@ -86,7 +87,7 @@ class TaxonomyImageTest extends TaxonomyTestBase {
// Create a user that should have access to the file and one that doesn't.
$access_user = $this->drupalCreateUser(array('access content'));
$no_access_user = $this->drupalCreateUser();
$image = file_load($term->field_test->target_id);
$image = File::load($term->field_test->target_id);
$this->drupalLogin($access_user);
$this->drupalGet(file_create_url($image->getFileUri()));
$this->assertResponse(200, 'Private image on term is accessible with right permission');

View file

@ -78,8 +78,12 @@ trait TaxonomyTranslationTestTrait {
/**
* Adds term reference field for the article content type.
*
* @param bool $translatable
* (optional) If TRUE, create a translatable term reference field. Defaults
* to FALSE.
*/
protected function setUpTermReferenceField() {
protected function setUpTermReferenceField($translatable = FALSE) {
$handler_settings = array(
'target_bundles' => array(
$this->vocabulary->id() => $this->vocabulary->id(),
@ -88,7 +92,7 @@ trait TaxonomyTranslationTestTrait {
);
$this->createEntityReferenceField('node', 'article', $this->termFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_storage = FieldStorageConfig::loadByName('node', $this->termFieldName);
$field_storage->setTranslatable(FALSE);
$field_storage->setTranslatable($translatable);
$field_storage->save();
entity_get_form_display('node', 'article', 'default')

View file

@ -50,7 +50,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
$this->vocabulary = $this->createVocabulary();
$this->enableTranslation();
$this->setUpTerm();
$this->setUpTermReferenceField();
$this->setUpTermReferenceField(TRUE);
$this->setUpNode();
}
@ -85,7 +85,7 @@ class TermTranslationFieldViewTest extends TaxonomyTestBase {
'langcode' => $this->baseLangcode,
));
$node->save();
$node->addTranslation($this->translateToLangcode, array());
$node->addTranslation($this->translateToLangcode, $node->toArray());
$node->save();
$this->node = $node;
}

View file

@ -10,6 +10,7 @@ namespace Drupal\taxonomy\Tests;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Render\BubbleableMetadata;
/**
* Generates text using placeholders for dummy content to check taxonomy token
@ -91,10 +92,26 @@ class TokenReplaceTest extends TaxonomyTestBase {
$tests['[term:node-count]'] = 0;
$tests['[term:parent:name]'] = '[term:parent:name]';
$tests['[term:vocabulary:name]'] = SafeMarkup::checkPlain($this->vocabulary->label());
$tests['[term:vocabulary]'] = SafeMarkup::checkPlain($this->vocabulary->label());
$base_bubbleable_metadata = BubbleableMetadata::createFromObject($term1);
$metadata_tests = array();
$metadata_tests['[term:tid]'] = $base_bubbleable_metadata;
$metadata_tests['[term:name]'] = $base_bubbleable_metadata;
$metadata_tests['[term:description]'] = $base_bubbleable_metadata;
$metadata_tests['[term:url]'] = $base_bubbleable_metadata;
$metadata_tests['[term:node-count]'] = $base_bubbleable_metadata;
$metadata_tests['[term:parent:name]'] = $base_bubbleable_metadata;
$bubbleable_metadata = clone $base_bubbleable_metadata;
$metadata_tests['[term:vocabulary:name]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
$metadata_tests['[term:vocabulary]'] = $bubbleable_metadata->addCacheTags($this->vocabulary->getCacheTags());
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()));
$bubbleable_metadata = new BubbleableMetadata();
$output = $token_service->replace($input, array('term' => $term1), array('langcode' => $language_interface->getId()), $bubbleable_metadata);
$this->assertEqual($output, $expected, format_string('Sanitized taxonomy term token %token replaced.', array('%token' => $input)));
$this->assertEqual($bubbleable_metadata, $metadata_tests[$input]);
}
// Generate and test sanitized tokens for term2.

View file

@ -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());
}
}

View file

@ -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);

View file

@ -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));
}
}