diff --git a/core/modules/comment/tests/src/Functional/CommentEntityTest.php b/core/modules/comment/tests/src/Functional/CommentEntityTest.php index 62d57f0371..219f7ffe96 100644 --- a/core/modules/comment/tests/src/Functional/CommentEntityTest.php +++ b/core/modules/comment/tests/src/Functional/CommentEntityTest.php @@ -6,7 +6,7 @@ use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\comment\CommentInterface; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; use Drupal\comment\Entity\Comment; /** diff --git a/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php b/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php index 5edaf42afe..3877b49ef9 100644 --- a/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php +++ b/core/modules/system/tests/src/Functional/Module/PrepareUninstallTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\system\Functional\Module; use Drupal\Tests\BrowserTestBase; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests that modules which provide entity types can be uninstalled. diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php index eb9e5e983b..7a980bd148 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php @@ -6,7 +6,7 @@ use Drupal\simpletest\WebTestBase; use Drupal\Tests\field\Traits\EntityReferenceTestTrait; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Provides common helper methods for Taxonomy module tests. diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php b/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php index a1b4a55214..5477d8afd4 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyTestTrait.php @@ -12,7 +12,7 @@ * Provides common helper methods for Taxonomy module tests. * * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. - * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait + * Use \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait */ trait TaxonomyTestTrait { diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php index 0958df3e5d..0e2c5aa399 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyQueryAlterTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Database\Database; use Drupal\Tests\BrowserTestBase; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests that appropriate query tags are added. diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestBase.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestBase.php index b75295ad0d..7c210839b7 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestBase.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestBase.php @@ -4,6 +4,7 @@ use Drupal\Tests\BrowserTestBase; use Drupal\Tests\field\Traits\EntityReferenceTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Provides common helper methods for Taxonomy module tests. diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php index 8dcdf17007..ed99228762 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php +++ b/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php @@ -2,58 +2,20 @@ namespace Drupal\Tests\taxonomy\Functional; -use Drupal\Core\Language\LanguageInterface; -use Drupal\taxonomy\Entity\Vocabulary; -use Drupal\taxonomy\Entity\Term; +@trigger_error('The ' . __NAMESPACE__ . '\TaxonomyTestTrait is deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait. See https://www.drupal.org/node/3041703.', E_USER_DEPRECATED); + +use \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait as ActualTaxonomyTestTrait; /** * Provides common helper methods for Taxonomy module tests. + * + * @deprecated in Drupal 8.8.0 and will be removed before Drupal 9.0.0. Instead, + * use \Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait. + * + * @see https://www.drupal.org/node/3041703 */ trait TaxonomyTestTrait { - /** - * Returns a new vocabulary with random properties. - */ - public function createVocabulary() { - // Create a vocabulary. - $vocabulary = Vocabulary::create([ - 'name' => $this->randomMachineName(), - 'description' => $this->randomMachineName(), - 'vid' => mb_strtolower($this->randomMachineName()), - 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - 'weight' => mt_rand(0, 10), - ]); - $vocabulary->save(); - return $vocabulary; - } - - /** - * Returns a new term with random properties in vocabulary $vid. - * - * @param \Drupal\taxonomy\Entity\Vocabulary $vocabulary - * The vocabulary object. - * @param array $values - * (optional) An array of values to set, keyed by property name. If the - * entity type has bundles, the bundle key has to be specified. - * - * @return \Drupal\taxonomy\Entity\Term - * The new taxonomy term object. - */ - public function createTerm(Vocabulary $vocabulary, $values = []) { - $filter_formats = filter_formats(); - $format = array_pop($filter_formats); - $term = Term::create($values + [ - 'name' => $this->randomMachineName(), - 'description' => [ - 'value' => $this->randomMachineName(), - // Use the first available text format. - 'format' => $format->id(), - ], - 'vid' => $vocabulary->id(), - 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - ]); - $term->save(); - return $term; - } + use ActualTaxonomyTestTrait; } diff --git a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php index 429e6fdafd..7c13169be1 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php @@ -5,7 +5,7 @@ use Drupal\KernelTests\KernelTestBase; use Drupal\taxonomy\TermInterface; use Drupal\taxonomy\VocabularyInterface; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests legacy user functionality. diff --git a/core/modules/taxonomy/tests/src/Functional/EfqTest.php b/core/modules/taxonomy/tests/src/Kernel/TaxonomyTermEfqTest.php similarity index 55% rename from core/modules/taxonomy/tests/src/Functional/EfqTest.php rename to core/modules/taxonomy/tests/src/Kernel/TaxonomyTermEfqTest.php index e78d9ec9b1..0b57ada60c 100644 --- a/core/modules/taxonomy/tests/src/Functional/EfqTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TaxonomyTermEfqTest.php @@ -1,47 +1,53 @@ drupalLogin($this->drupalCreateUser(['administer taxonomy'])); - $this->vocabulary = $this->createVocabulary(); - } + protected static $modules = [ + 'field', + 'filter', + 'taxonomy', + 'text', + 'user', + ]; /** * Tests that a basic taxonomy entity query works. */ public function testTaxonomyEfq() { + $this->installEntitySchema('taxonomy_term'); + $vocabulary = $this->createVocabulary(); + $terms = []; for ($i = 0; $i < 5; $i++) { - $term = $this->createTerm($this->vocabulary); + $term = $this->createTerm($vocabulary); $terms[$term->id()] = $term; } $result = \Drupal::entityQuery('taxonomy_term')->execute(); sort($result); - $this->assertEqual(array_keys($terms), $result, 'Taxonomy terms were retrieved by entity query.'); + $this->assertEquals(array_keys($terms), $result); $tid = reset($result); $ids = (object) [ 'entity_type' => 'taxonomy_term', 'entity_id' => $tid, - 'bundle' => $this->vocabulary->id(), + 'bundle' => $vocabulary->id(), ]; $term = _field_create_entity_from_ids($ids); - $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.'); + $this->assertEquals($tid, $term->id()); // Create a second vocabulary and five more terms. $vocabulary2 = $this->createVocabulary(); @@ -55,7 +61,7 @@ public function testTaxonomyEfq() { ->condition('vid', $vocabulary2->id()) ->execute(); sort($result); - $this->assertEqual(array_keys($terms2), $result, format_string('Taxonomy terms from the %name vocabulary were retrieved by entity query.', ['%name' => $vocabulary2->label()])); + $this->assertEqual(array_keys($terms2), $result); $tid = reset($result); $ids = (object) [ 'entity_type' => 'taxonomy_term', @@ -63,7 +69,7 @@ public function testTaxonomyEfq() { 'bundle' => $vocabulary2->id(), ]; $term = _field_create_entity_from_ids($ids); - $this->assertEqual($term->id(), $tid, 'Taxonomy term can be created based on the IDs.'); + $this->assertEquals($tid, $term->id()); } } diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php index 3d8bff80a3..cb1930b4bd 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php @@ -4,7 +4,7 @@ use Drupal\taxonomy\Entity\Term; use Drupal\KernelTests\KernelTestBase; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Kernel tests for taxonomy term functions. diff --git a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php index 2fde283e32..4cdcc40cb7 100644 --- a/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/Views/TaxonomyFieldVidTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\taxonomy\Kernel\Views; use Drupal\Core\Render\RenderContext; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; use Drupal\Tests\views\Kernel\ViewsKernelTestBase; use Drupal\user\Entity\User; use Drupal\views\Tests\ViewTestData; diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php b/core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php similarity index 69% copy from core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php copy to core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php index 8dcdf17007..21814a1159 100644 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTestTrait.php +++ b/core/modules/taxonomy/tests/src/Traits/TaxonomyTestTrait.php @@ -1,10 +1,11 @@ $this->randomMachineName(), 'description' => [ 'value' => $this->randomMachineName(), - // Use the first available text format. - 'format' => $format->id(), + // Use the fallback text format. + 'format' => filter_fallback_format(), ], 'vid' => $vocabulary->id(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, diff --git a/core/modules/views/tests/src/Functional/TaxonomyGlossaryTest.php b/core/modules/views/tests/src/Functional/TaxonomyGlossaryTest.php index fbf5f41458..6e9d477677 100644 --- a/core/modules/views/tests/src/Functional/TaxonomyGlossaryTest.php +++ b/core/modules/views/tests/src/Functional/TaxonomyGlossaryTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\views\Functional; -use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait; +use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait; /** * Tests glossary functionality of taxonomy views.