Update to Drupal 8.1.1. For more information, see https://www.drupal.org/node/2718713

This commit is contained in:
Pantheon Automation 2016-05-04 14:35:41 -07:00 committed by Greg Anderson
parent c0a0d5a94c
commit 9eae24d844
669 changed files with 3873 additions and 1553 deletions

View file

@ -49,7 +49,7 @@ class TermSelection extends DefaultSelection {
*/
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
if ($match || $limit) {
return parent::getReferenceableEntities($match , $match_operator, $limit);
return parent::getReferenceableEntities($match, $match_operator, $limit);
}
$options = array();

View file

@ -68,7 +68,7 @@ class Vocabulary extends DrupalSqlBase {
->execute()
->fetchCol();
$row->setSourceProperty('node_types', $node_types);
$row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1);
$row->setSourceProperty('cardinality', ($row->getSourceProperty('tags') == 1 || $row->getSourceProperty('multiple') == 1) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 1);
return parent::prepareRow($row);
}

View file

@ -391,8 +391,7 @@ class TaxonomyIndexTid extends ManyToOne {
$vocabulary = $this->vocabularyStorage->load($this->options['vid']);
$dependencies[$vocabulary->getConfigDependencyKey()][] = $vocabulary->getConfigDependencyName();
foreach ($this->options['value'] as $tid) {
$term = $this->termStorage->load($tid);
foreach ($this->termStorage->loadMultiple($this->options['value']) as $term) {
$dependencies[$term->getConfigDependencyKey()][] = $term->getConfigDependencyName();
}

View file

@ -86,7 +86,7 @@ class TermStorageSchema extends SqlContentEntityStorageSchema {
'description' => 'The Unix timestamp when the node was created.',
'type' => 'int',
'not null' => TRUE,
'default'=> 0,
'default' => 0,
),
),
'primary key' => array('nid', 'tid'),

View file

@ -58,7 +58,7 @@ class TermViewsData extends EntityViewsData {
'relationship field' => 'tid',
'outer field' => 'taxonomy_term_field_data.tid',
'argument table' => 'taxonomy_term_field_data',
'argument field' => 'tid',
'argument field' => 'tid',
'base' => 'node_field_data',
'field' => 'nid',
'relationship' => 'node_field_data:term_node_tid'

View file

@ -1,150 +0,0 @@
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\taxonomy\Entity\Term;
use Drupal\simpletest\KernelTestBase;
/**
* Kernel tests for taxonomy term functions.
*
* @group taxonomy
*/
class TermKernelTest extends KernelTestBase {
use TaxonomyTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = array( 'filter', 'taxonomy', 'text', 'user' );
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('filter'));
$this->installEntitySchema('taxonomy_term');
}
/**
* Deleting terms should also remove related vocabulary.
* Deleting an invalid term should silently fail.
*/
public function testTermDelete() {
$vocabulary = $this->createVocabulary();
$valid_term = $this->createTerm($vocabulary);
// Delete a valid term.
$valid_term->delete();
$terms = entity_load_multiple_by_properties('taxonomy_term', array('vid' => $vocabulary->id()));
$this->assertTrue(empty($terms), 'Vocabulary is empty after deletion');
// Delete an invalid term. Should not throw any notices.
entity_delete_multiple('taxonomy_term', array(42));
}
/**
* Deleting a parent of a term with multiple parents does not delete the term.
*/
public function testMultipleParentDelete() {
$vocabulary = $this->createVocabulary();
$parent_term1 = $this->createTerm($vocabulary);
$parent_term2 = $this->createTerm($vocabulary);
$child_term = $this->createTerm($vocabulary);
$child_term->parent = array($parent_term1->id(), $parent_term2->id());
$child_term->save();
$child_term_id = $child_term->id();
$parent_term1->delete();
$term_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
$term_storage->resetCache(array($child_term_id));
$child_term = Term::load($child_term_id);
$this->assertTrue(!empty($child_term), 'Child term is not deleted if only one of its parents is removed.');
$parent_term2->delete();
$term_storage->resetCache(array($child_term_id));
$child_term = Term::load($child_term_id);
$this->assertTrue(empty($child_term), 'Child term is deleted if all of its parents are removed.');
}
/**
* Test a taxonomy with terms that have multiple parents of different depths.
*/
public function testTaxonomyVocabularyTree() {
// Create a new vocabulary with 6 terms.
$vocabulary = $this->createVocabulary();
$term = array();
for ($i = 0; $i < 6; $i++) {
$term[$i] = $this->createTerm($vocabulary);
}
// Get the taxonomy storage.
$taxonomy_storage = $this->container->get('entity.manager')->getStorage('taxonomy_term');
// Set the weight on $term[1] so it appears before $term[5] when fetching
// the parents for $term[2], in order to test for a regression on
// \Drupal\taxonomy\TermStorageInterface::loadAllParents().
$term[1]->weight = -1;
$term[1]->save();
// $term[2] is a child of 1 and 5.
$term[2]->parent = array($term[1]->id(), $term[5]->id());
$term[2]->save();
// $term[3] is a child of 2.
$term[3]->parent = array($term[2]->id());
$term[3]->save();
// $term[5] is a child of 4.
$term[5]->parent = array($term[4]->id());
$term[5]->save();
/**
* Expected tree:
* term[0] | depth: 0
* term[1] | depth: 0
* -- term[2] | depth: 1
* ---- term[3] | depth: 2
* term[4] | depth: 0
* -- term[5] | depth: 1
* ---- term[2] | depth: 2
* ------ term[3] | depth: 3
*/
// Count $term[1] parents with $max_depth = 1.
$tree = $taxonomy_storage->loadTree($vocabulary->id(), $term[1]->id(), 1);
$this->assertEqual(1, count($tree), 'We have one parent with depth 1.');
// Count all vocabulary tree elements.
$tree = $taxonomy_storage->loadTree($vocabulary->id());
$this->assertEqual(8, count($tree), 'We have all vocabulary tree elements.');
// Count elements in every tree depth.
foreach ($tree as $element) {
if (!isset($depth_count[$element->depth])) {
$depth_count[$element->depth] = 0;
}
$depth_count[$element->depth]++;
}
$this->assertEqual(3, $depth_count[0], 'Three elements in taxonomy tree depth 0.');
$this->assertEqual(2, $depth_count[1], 'Two elements in taxonomy tree depth 1.');
$this->assertEqual(2, $depth_count[2], 'Two elements in taxonomy tree depth 2.');
$this->assertEqual(1, $depth_count[3], 'One element in taxonomy tree depth 3.');
/** @var \Drupal\taxonomy\TermStorageInterface $storage */
$storage = \Drupal::entityManager()->getStorage('taxonomy_term');
// Count parents of $term[2].
$parents = $storage->loadParents($term[2]->id());
$this->assertEqual(2, count($parents), 'The term has two parents.');
// Count parents of $term[3].
$parents = $storage->loadParents($term[3]->id());
$this->assertEqual(1, count($parents), 'The term has one parent.');
// Identify all ancestors of $term[2].
$ancestors = $storage->loadAllParents($term[2]->id());
$this->assertEqual(4, count($ancestors), 'The term has four ancestors including the term itself.');
// Identify all ancestors of $term[3].
$ancestors = $storage->loadAllParents($term[3]->id());
$this->assertEqual(5, count($ancestors), 'The term has five ancestors including the term itself.');
}
}

View file

@ -161,7 +161,7 @@ class TermTest extends TaxonomyTestBase {
for ($x = 1; $x <= 17; $x++) {
$this->assertNoText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' not found on Page 3');
}
for ($x =18; $x <= 25; $x++) {
for ($x = 18; $x <= 25; $x++) {
$this->assertText($terms_array[$x]->getName(), $terms_array[$x]->getName() . ' found on Page 3');
}
}

View file

@ -1,67 +0,0 @@
<?php
namespace Drupal\taxonomy\Tests;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
/**
* Tests term validation constraints.
*
* @group taxonomy
*/
class TermValidationTest extends EntityUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('taxonomy_term');
}
/**
* Tests the term validation constraints.
*/
public function testValidation() {
$this->entityManager->getStorage('taxonomy_vocabulary')->create(array(
'vid' => 'tags',
'name' => 'Tags',
))->save();
$term = $this->entityManager->getStorage('taxonomy_term')->create(array(
'name' => 'test',
'vid' => 'tags',
));
$violations = $term->validate();
$this->assertEqual(count($violations), 0, 'No violations when validating a default term.');
$term->set('name', $this->randomString(256));
$violations = $term->validate();
$this->assertEqual(count($violations), 1, 'Violation found when name is too long.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name.0.value');
$field_label = $term->get('name')->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => $field_label, '@max' => 255)));
$term->set('name', NULL);
$violations = $term->validate();
$this->assertEqual(count($violations), 1, 'Violation found when name is NULL.');
$this->assertEqual($violations[0]->getPropertyPath(), 'name');
$this->assertEqual($violations[0]->getMessage(), t('This value should not be null.'));
$term->set('name', 'test');
$term->set('parent', 9999);
$violations = $term->validate();
$this->assertEqual(count($violations), 1, 'Violation found when term parent is invalid.');
$this->assertEqual($violations[0]->getMessage(), format_string('The referenced entity (%type: %id) does not exist.', array('%type' => 'taxonomy_term', '%id' => 9999)));
$term->set('parent', 0);
$violations = $term->validate();
$this->assertEqual(count($violations), 0, 'No violations for parent id 0.');
}
}

View file

@ -144,4 +144,3 @@ class TokenReplaceTest extends TaxonomyTestBase {
}
}
}

View file

@ -0,0 +1,156 @@
<?php
namespace Drupal\taxonomy\Tests\Views;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\views\Entity\View;
use Drupal\views\Tests\ViewTestData;
/**
* Test the taxonomy term index filter.
*
* @see \Drupal\taxonomy\Plugin\views\filter\TaxonomyIndexTid
*
* @group taxonomy
*/
class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['taxonomy', 'taxonomy_test_views', 'views', 'node'];
/**
* {@inheritdoc}
*/
public static $testViews = ['test_filter_taxonomy_index_tid__non_existing_dependency'];
/**
* @var \Drupal\taxonomy\TermInterface[]
*/
protected $terms = [];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp(FALSE);
// Setup vocabulary and terms so the initial import is valid.
Vocabulary::create([
'vid' => 'tags',
'name' => 'Tags',
])->save();
// This will get a term ID of 3.
$term = Term::create([
'vid' => 'tags',
'name' => 'muh',
]);
$term->save();
// This will get a term ID of 4.
$this->terms[$term->id()] = $term;
$term = Term::create([
'vid' => 'tags',
'name' => 'muh',
]);
$term->save();
$this->terms[$term->id()] = $term;
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
}
/**
* Tests dependencies are not added for terms that do not exist.
*/
public function testConfigDependency() {
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
// Dependencies are sorted.
$content_dependencies = [
$this->terms[3]->getConfigDependencyName(),
$this->terms[4]->getConfigDependencyName(),
];
sort($content_dependencies);
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => $content_dependencies,
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
$this->terms[3]->delete();
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => [
$this->terms[4]->getConfigDependencyName(),
],
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
}
/**
* Tests post update function fixes dependencies.
*
* @see views_post_update_taxonomy_index_tid()
*/
public function testPostUpdateFunction() {
/** @var \Drupal\views\Entity\View $view */
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
// Dependencies are sorted.
$content_dependencies = [
$this->terms[3]->getConfigDependencyName(),
$this->terms[4]->getConfigDependencyName(),
];
sort($content_dependencies);
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => $content_dependencies,
'module' => [
'node',
'taxonomy',
'user',
],
], $view->calculateDependencies()->getDependencies());
$this->terms[3]->delete();
\Drupal::moduleHandler()->loadInclude('views', 'post_update.php');
views_post_update_taxonomy_index_tid();
$view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');
$this->assertEqual([
'config' => [
'taxonomy.vocabulary.tags',
],
'content' => [
$this->terms[4]->getConfigDependencyName(),
],
'module' => [
'node',
'taxonomy',
'user',
],
], $view->getDependencies());
}
}

View file

@ -55,11 +55,13 @@ abstract class TaxonomyTestBase extends ViewTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->mockStandardInstall();
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
if ($import_test_views) {
ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views'));
}
$this->term1 = $this->createTerm();
$this->term2 = $this->createTerm();