Unverified Commit c4b5c0dc authored by larowlan's avatar larowlan

Issue #2870459 by naveenvalecha, Lendude, zahord, Jo Fitzgerald, dawehner,...

Issue #2870459 by naveenvalecha, Lendude, zahord, Jo Fitzgerald, dawehner, larowlan, claudiu.cristea: Convert web tests to browser tests for taxonomy module
parent 9539eafc
......@@ -3,7 +3,7 @@
namespace Drupal\Tests\rdf\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
/**
* Tests RDFa markup generation for taxonomy term fields.
......
......@@ -2,7 +2,7 @@
namespace Drupal\Tests\rdf\Functional;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
/**
* Tests the RDFa markup of Taxonomy terms.
......
......@@ -2,8 +2,11 @@
namespace Drupal\taxonomy\Tests;
@trigger_error(__NAMESPACE__ . '\TaxonomyTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTestBase', E_USER_DEPRECATED);
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
* Provides common helper methods for Taxonomy module tests.
......
......@@ -2,6 +2,8 @@
namespace Drupal\taxonomy\Tests;
@trigger_error(__NAMESPACE__ . '\TaxonomyTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait', E_USER_DEPRECATED);
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -9,6 +11,9 @@
/**
* 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
*/
trait TaxonomyTestTrait {
......
......@@ -2,6 +2,8 @@
namespace Drupal\taxonomy\Tests;
@trigger_error(__NAMESPACE__ . '\TaxonomyTranslationTestTrait is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait', E_USER_DEPRECATED);
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -9,6 +11,9 @@
/**
* Provides common testing base for translated taxonomy terms.
*
* @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0.
* Use \Drupal\Tests\taxonomy\Functional\TaxonomyTranslationTestTrait
*/
trait TaxonomyTranslationTestTrait {
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\TestFileCreationTrait;
use Drupal\user\RoleInterface;
use Drupal\file\Entity\File;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -14,6 +15,11 @@
*/
class TaxonomyImageTest extends TaxonomyTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
compareFiles as drupalCompareFiles;
}
/**
* Used taxonomy vocabulary.
*
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests that appropriate query tags are added.
*
* @group taxonomy
*/
class TaxonomyQueryAlterTest extends WebTestBase {
class TaxonomyQueryAlterTest extends BrowserTestBase {
use TaxonomyTestTrait;
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
/**
* Ensures that the term pager works properly.
......
......@@ -4,7 +4,6 @@
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
/**
* Provides common helper methods for Taxonomy module tests.
......
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
/**
* Provides common helper methods for Taxonomy module tests.
*/
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' => Unicode::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;
}
}
<?php
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Provides common testing base for translated taxonomy terms.
*/
trait TaxonomyTranslationTestTrait {
use EntityReferenceTestTrait;
/**
* The vocabulary.
*
* @var \Drupal\taxonomy\Entity\Vocabulary;
*/
protected $vocabulary;
/**
* The field name for our taxonomy term field.
*
* @var string
*/
protected $termFieldName = 'field_tag';
/**
* The langcode of the source language.
*
* @var string
*/
protected $baseLangcode = 'en';
/**
* Target langcode for translation.
*
* @var string
*/
protected $translateToLangcode = 'hu';
/**
* The node to check the translated value on.
*
* @var \Drupal\node\Entity\Node
*/
protected $node;
/**
* Adds additional languages.
*/
protected function setupLanguages() {
ConfigurableLanguage::createFromLangcode($this->translateToLangcode)->save();
$this->rebuildContainer();
}
/**
* Enables translations where it needed.
*/
protected function enableTranslation() {
// Enable translation for the current entity type and ensure the change is
// picked up.
\Drupal::service('content_translation.manager')->setEnabled('node', 'article', TRUE);
\Drupal::service('content_translation.manager')->setEnabled('taxonomy_term', $this->vocabulary->id(), TRUE);
drupal_static_reset();
\Drupal::entityManager()->clearCachedDefinitions();
\Drupal::service('router.builder')->rebuild();
\Drupal::service('entity.definition_update_manager')->applyUpdates();
}
/**
* 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() {
$handler_settings = [
'target_bundles' => [
$this->vocabulary->id() => $this->vocabulary->id(),
],
'auto_create' => TRUE,
];
$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->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->termFieldName, [
'type' => 'entity_reference_autocomplete_tags',
])
->save();
entity_get_display('node', 'article', 'default')
->setComponent($this->termFieldName, [
'type' => 'entity_reference_label',
])
->save();
}
}
......@@ -3,7 +3,6 @@
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Tests\TaxonomyTranslationTestTrait;
/**
* Tests the translation of taxonomy terms field on nodes.
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
use Drupal\Core\Language\LanguageInterface;
use Drupal\taxonomy\Entity\Vocabulary;
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
/**
* Verifies that various taxonomy pages use the expected theme.
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
......@@ -47,8 +47,8 @@ class ArgumentValidatorTermTest extends TaxonomyTestBase {
*/
public static $testViews = ['test_argument_validator_term'];
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add three terms to the 'tags' vocabulary.
for ($i = 0; $i < 3; $i++) {
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\field\Entity\FieldConfig;
use Drupal\views\Views;
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -30,14 +30,14 @@ public function testViewsHandlerAllTermsField() {
$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());
$this->assertEqual($actual[0]->getText(), $this->term1->label());
$this->assertEqual($actual[1]->getText(), $this->term1->label());
$this->assertEscaped($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());
$this->assertEqual($actual[0]->getText(), $this->term2->label());
$this->assertEqual($actual[1]->getText(), $this->term2->label());
}
/**
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -45,8 +45,8 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
*/
public $termNames = [];
public function setUp() {
parent::setUp();
public function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add two new languages.
ConfigurableLanguage::createFromLangcode('fr')->save();
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\taxonomy\Entity\Term;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -34,7 +34,7 @@ class TaxonomyIndexTidFilterTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
protected function setUp($import_test_views = TRUE) {
parent::setUp(FALSE);
// Setup vocabulary and terms so the initial import is valid.
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\node\NodeInterface;
use Drupal\taxonomy\TermInterface;
......@@ -30,8 +30,8 @@ class TaxonomyRelationshipTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Make term2 parent of term1.
$this->term1->set('parent', $this->term2->id());
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
/**
* Tests the taxonomy term with depth argument.
......@@ -32,8 +32,8 @@ class TaxonomyTermArgumentDepthTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create a term with markup in the label.
$first = $this->createTerm(['name' => '<em>First</em>']);
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
......@@ -34,8 +34,8 @@ class TaxonomyTermFilterDepthTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create a hierarchy 3 deep. Note the parent setup function creates two
// top-level terms w/o children.
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
......@@ -40,8 +40,8 @@ class TaxonomyTermViewTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Create an administrative user.
$this->adminUser = $this->drupalCreateUser(['administer taxonomy', 'bypass node access']);
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait;
use Drupal\views\Tests\ViewTestBase;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\taxonomy\Entity\Term;
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\taxonomy\Entity\Vocabulary;
......@@ -36,8 +36,8 @@ class TaxonomyVocabularyArgumentTest extends TaxonomyTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add default vocabulary to list of vocabularies.
$this->vocabularies[] = $this->vocabulary;
......
<?php
namespace Drupal\taxonomy\Tests\Views;
namespace Drupal\Tests\taxonomy\Functional\Views;
use Drupal\views\Views;
......
<?php
namespace Drupal\taxonomy\Tests;
namespace Drupal\Tests\taxonomy\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Url;
......@@ -78,7 +78,6 @@ public function testVocabularyInterface() {
$site_name = $this->config('system.site')->get('name');
$this->assertTitle(t('Don\'t Panic | @site-name', ['@site-name' => $site_name]), 'The page title contains the escaped character.');
$this->assertNoTitle(t('Don&#039;t Panic | @site-name', ['@site-name' => $site_name]), 'The page title does not contain an encoded character.');
}
/**
......
......@@ -4,7 +4,7 @@
use Drupal\taxonomy\Entity\Term;
use Drupal\KernelTests\KernelTestBase;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
* Kernel tests for taxonomy term functions.
......
......@@ -2,7 +2,7 @@
namespace Drupal\Tests\views\Functional;
use Drupal\taxonomy\Tests\TaxonomyTestTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
/**
* Tests glossary functionality of taxonomy views.
......
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