diff --git a/browsertest-convert.php b/browsertest-convert.php index cc20c34..57cfb2a 100644 --- a/browsertest-convert.php +++ b/browsertest-convert.php @@ -292,6 +292,7 @@ // The conversion script has some issues with 'CommentTestBase' 'comment', + 'CommentAttributesTest', // https://www.drupal.org/node/2795601 'FormatDateTest', @@ -324,6 +325,8 @@ 'views_ui', // Exclude big_pipe, because its doing curl magic 'big_pipe', + // No web tests in serialization module. + 'serialization', // All other kind of issues 'BlockLanguageCacheTest', @@ -466,7 +469,35 @@ // https://www.drupal.org/node/2795611 'RouterTest', - + + // Skip tests using the Views base class, not converted yet. + '/src/Tests/Views/', + // Do not copy traits, reuse them. + 'Trait.php', + + // Fixtures staying with Simpletest for now. + 'TestDataConverter.php'. + 'ErrorContainer.php', + 'ExceptionContainer.php', + 'StubForm.php', + 'FieldDefaultValueCallbackProvider.php', + 'FakeRecord.php', + 'UrlAliasFixtures.php', + 'MockRouteProvider.php', + 'MockAliasManager.php', + + // Unused base classes. + 'ShortcutTestBase', + 'AjaxTestBase', + 'EntityUnitTestBase', + 'EntityWithUriCacheTagsTestBase', + 'ConfigAfterInstallerTestBase', + 'NormalizerTestBase', + 'GenericCacheBackendUnitTestBase', + + // Installer tests + 'ConfigInstallProfileUnmetDependenciesTest', + '/Installer/', ]; function isTestExcluded($test_name, array $excluded_tests) { @@ -515,12 +546,47 @@ function glob_recursive($pattern, $flags = 0) { $file_name = str_replace('core/modules/' . $module_name . '/src/Tests/', '', $simpletest_file_path); $file_content = file_get_contents($simpletest_file_path); + // Views tests are not converted yet. + if (strpos($file_content, ' extends ViewTestBase {') !== FALSE) { + continue; + } + // Installer tests are not converted yet. + if (strpos($file_content, ' extends InstallerTestBase {') !== FALSE) { + continue; + } + // REST tests are not converted yet. + if (strpos($file_content, ' extends RestTestBase {') !== FALSE) { + continue; + } + // Module tests should be refactored into kernel and browser tests. + if (strpos($file_content, ' extends ModuleTestBase {') !== FALSE) { + continue; + } + // We surely don't want to move kernel tests around. + if (strpos($file_content, ' extends KernelTestBase {') !== FALSE) { + continue; + } + + // Add @deprecated to old test base files. + if (strpos($simpletest_file_path, 'TestBase.php') !== FALSE) { + $class_name = str_replace('/', "\\", substr($file_name, 0, -4)); + $simpletest_file_content = str_replace("*/\nabstract class ", "*\n * @deprecated Scheduled for removal in Drupal 9.0.0.\n * Use \\Drupal\\Tests\\$module_name\\Functional\\$class_name instead.\n */\nabstract class ", $file_content); + file_put_contents($simpletest_file_path, $simpletest_file_content); + } + $file_content = str_replace("namespace Drupal\\$module_name\\Tests", "namespace Drupal\\Tests\\$module_name\\Functional", $file_content); $file_content = str_replace("use Drupal\\simpletest\\WebTestBase;", "use Drupal\\Tests\\BrowserTestBase;", $file_content); $file_content = str_replace(" extends WebTestBase {", " extends BrowserTestBase {", $file_content); - // Traits - $file_content = str_replace("use Drupal\\config\\Tests\\SchemaCheckTestTrait;", "use Drupal\\Tests\\config\\Functional\\SchemaCheckTestTrait;", $file_content); + // Fix use statements for traits. + if (strpos($file_content, 'use EntityReferenceTestTrait;') !== FALSE + && strpos($file_content, "use Drupal\\field\\Tests\\EntityReference\\EntityReferenceTestTrait;") === FALSE + ) { + $file_content = str_replace("use Drupal\\Tests\\BrowserTestBase;", "use Drupal\\Tests\\BrowserTestBase;\nuse Drupal\\field\\Tests\\EntityReference\\EntityReferenceTestTrait;", $file_content); + } + + // Fix use statements for base classes. + str_replace("use Drupal\\system\\Tests\\Cache\\PageCacheTagsTestBase;", "use Drupal\\Tests\\system\\Functional\\Cache\\PageCacheTagsTestBase;", $file_content); $test_dir = dirname("$browsertest_dir/$file_name"); if (!file_exists($test_dir)) { @@ -530,20 +596,8 @@ function glob_recursive($pattern, $flags = 0) { file_put_contents("$browsertest_dir/$file_name", $file_content); - // Keep existing traits and base classes. - if ( - strpos($simpletest_file_path, 'Trait.php') === FALSE - && strpos($simpletest_file_path, 'Base.php') === FALSE - && strpos($simpletest_file_path, 'MockRouteProvider.php') === FALSE - && strpos($simpletest_file_path, 'MockAliasManager.php') === FALSE - && strpos($simpletest_file_path, 'UrlAliasFixtures.php') === FALSE - && strpos($simpletest_file_path, 'FieldDefaultValueCallbackProvider.php') === FALSE - && strpos($simpletest_file_path, 'FakeRecord.php') === FALSE - && strpos($simpletest_file_path, 'StubForm.php') === FALSE - && strpos($simpletest_file_path, 'TestDataConverter.php') === FALSE - && strpos($simpletest_file_path, 'ErrorContainer.php') === FALSE - && strpos($simpletest_file_path, 'ExceptionContainer.php') === FALSE - ) { + // Keep existing base classes. + if (strpos($simpletest_file_path, 'Base.php') === FALSE) { unlink($simpletest_file_path); } } diff --git a/core/modules/aggregator/src/Tests/AggregatorTestBase.php b/core/modules/aggregator/src/Tests/AggregatorTestBase.php index 15be144..30184d2 100644 --- a/core/modules/aggregator/src/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/src/Tests/AggregatorTestBase.php @@ -9,6 +9,9 @@ /** * Defines a base class for testing the Aggregator module. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\aggregator\Functional\AggregatorTestBase instead. */ abstract class AggregatorTestBase extends WebTestBase { diff --git a/core/modules/block_content/src/Tests/BlockContentTestBase.php b/core/modules/block_content/src/Tests/BlockContentTestBase.php index 16df855..28c6e22 100644 --- a/core/modules/block_content/src/Tests/BlockContentTestBase.php +++ b/core/modules/block_content/src/Tests/BlockContentTestBase.php @@ -8,6 +8,9 @@ /** * Sets up block content types. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\block_content\Functional\BlockContentTestBase instead. */ abstract class BlockContentTestBase extends WebTestBase { diff --git a/core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php similarity index 98% rename from core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php rename to core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php index c69f2a7..5a46ddd 100644 --- a/core/modules/block_content/tests/src/Functional/Views/BlockContentFieldFilterTest.php +++ b/core/modules/block_content/src/Tests/Views/BlockContentFieldFilterTest.php @@ -1,6 +1,6 @@ createBlockContentType(array('id' => 'basic')); - - $this->adminUser = $this->drupalCreateUser($this->permissions); - - if ($import_test_views) { - ViewTestData::createTestViews(get_class($this), array('block_content_test_views')); - } - } - - /** - * Creates a custom block. - * - * @param array $settings - * (optional) An associative array of settings for the block_content, as - * used in entity_create(). - * - * @return \Drupal\block_content\Entity\BlockContent - * Created custom block. - */ - protected function createBlockContent(array $settings = array()) { - $status = 0; - $settings += array( - 'info' => $this->randomMachineName(), - 'type' => 'basic', - 'langcode' => 'en', - ); - if ($block_content = BlockContent::create($settings)) { - $status = $block_content->save(); - } - $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content %info.', array('%info' => $block_content->label()))); - return $block_content; - } - - /** - * Creates a custom block type (bundle). - * - * @param array $values - * An array of settings to change from the defaults. - * - * @return \Drupal\block_content\Entity\BlockContentType - * Created custom block type. - */ - protected function createBlockContentType(array $values = array()) { - // Find a non-existent random type name. - if (!isset($values['id'])) { - do { - $id = strtolower($this->randomMachineName(8)); - } while (BlockContentType::load($id)); - } - else { - $id = $values['id']; - } - $values += array( - 'id' => $id, - 'label' => $id, - 'revision' => FALSE - ); - $bundle = BlockContentType::create($values); - $status = $bundle->save(); - block_content_add_body_field($bundle->id()); - - $this->assertEqual($status, SAVED_NEW, SafeMarkup::format('Created block content type %bundle.', array('%bundle' => $bundle->id()))); - return $bundle; - } - -} diff --git a/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php b/core/modules/book/src/Tests/Views/BookRelationshipTest.php similarity index 98% rename from core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php rename to core/modules/book/src/Tests/Views/BookRelationshipTest.php index 75feaea..2302e8b 100644 --- a/core/modules/book/tests/src/Functional/Views/BookRelationshipTest.php +++ b/core/modules/book/src/Tests/Views/BookRelationshipTest.php @@ -1,6 +1,6 @@ uuid(); - $entity_type_id = $entity->getEntityTypeId(); - $original_data = $entity->toArray(); - // Copy everything to sync. - $this->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync')); - // Delete the configuration from active. Don't worry about side effects of - // deleting config like fields cleaning up field storages. The coming import - // should recreate everything as necessary. - $entity->delete(); - $this->configImporter()->reset()->import(); - $imported_entity = \Drupal::entityManager()->loadEntityByUuid($entity_type_id, $entity_uuid); - $this->assertIdentical($original_data, $imported_entity->toArray()); - } - -} diff --git a/core/modules/config/tests/src/Functional/SchemaCheckTestTrait.php b/core/modules/config/tests/src/Functional/SchemaCheckTestTrait.php deleted file mode 100644 index 684ab9d..0000000 --- a/core/modules/config/tests/src/Functional/SchemaCheckTestTrait.php +++ /dev/null @@ -1,59 +0,0 @@ -checkConfigSchema($typed_config, $config_name, $config_data); - if ($errors === FALSE) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(SafeMarkup::format('No schema for @config_name', array('@config_name' => $config_name))); - return; - } - elseif ($errors === TRUE) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->pass(SafeMarkup::format('Schema found for @config_name and values comply with schema.', array('@config_name' => $config_name))); - } - else { - foreach ($errors as $key => $error) { - // @todo Since the use of this trait is under TestBase, it works. - // Can be fixed as part of https://www.drupal.org/node/2260053. - $this->fail(SafeMarkup::format('Schema key @key failed with: @error', array('@key' => $key, '@error' => $error))); - } - } - } - - /** - * Asserts configuration, specified by name, has a valid schema. - * - * @param string $config_name - * The configuration name. - */ - public function assertConfigSchemaByName($config_name) { - $config = $this->config($config_name); - $this->assertConfigSchema(\Drupal::service('config.typed'), $config->getName(), $config->get()); - } - -} diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationInstallTest.php b/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php similarity index 97% rename from core/modules/config_translation/tests/src/Functional/ConfigTranslationInstallTest.php rename to core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php index 6d0546f..7daa305 100644 --- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationInstallTest.php +++ b/core/modules/config_translation/src/Tests/ConfigTranslationInstallTest.php @@ -1,6 +1,6 @@ 'page', - 'name' => 'page' - ]); - $node_type->save(); - $fieldStorage = FieldStorageConfig::create([ - 'field_name' => static::$field_name, - 'entity_type' => 'node', - 'type' => 'datetime', - 'settings' => ['datetime_type' => DateTimeItem::DATETIME_TYPE_DATETIME], - ]); - $fieldStorage->save(); - $field = FieldConfig::create([ - 'field_storage' => $fieldStorage, - 'bundle' => 'page', - 'required' => TRUE, - ]); - $field->save(); - - // Views needs to be aware of the new field. - $this->container->get('views.views_data')->clear(); - - // Set column map. - $this->map = [ - 'nid' => 'nid', - ]; - - // Load test views. - ViewTestData::createTestViews(get_class($this), ['datetime_test']); - } - -} diff --git a/core/modules/field/src/Tests/FieldTestBase.php b/core/modules/field/src/Tests/FieldTestBase.php index 4fe944f..30c80df 100644 --- a/core/modules/field/src/Tests/FieldTestBase.php +++ b/core/modules/field/src/Tests/FieldTestBase.php @@ -8,6 +8,9 @@ /** * Parent class for Field API tests. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\field\Functional\FieldTestBase instead. */ abstract class FieldTestBase extends WebTestBase { diff --git a/core/modules/field/tests/src/Functional/Views/FieldUITest.php b/core/modules/field/src/Tests/Views/FieldUITest.php similarity index 99% rename from core/modules/field/tests/src/Functional/Views/FieldUITest.php rename to core/modules/field/src/Tests/Views/FieldUITest.php index 6e50a5c..c47bf19 100644 --- a/core/modules/field/tests/src/Functional/Views/FieldUITest.php +++ b/core/modules/field/src/Tests/Views/FieldUITest.php @@ -1,6 +1,6 @@ $field_name, - 'type' => 'entity_reference', - 'entity_type' => $entity_type, - 'cardinality' => $cardinality, - 'settings' => array( - 'target_type' => $target_entity_type, - ), - ))->save(); - } - if (!FieldConfig::loadByName($entity_type, $bundle, $field_name)) { - FieldConfig::create(array( - 'field_name' => $field_name, - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'label' => $field_label, - 'settings' => array( - 'handler' => $selection_handler, - 'handler_settings' => $selection_handler_settings, - ), - ))->save(); - } - } - -} diff --git a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceXSSTest.php b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceXSSTest.php index ae32450..46986ec 100644 --- a/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceXSSTest.php +++ b/core/modules/field/tests/src/Functional/EntityReference/EntityReferenceXSSTest.php @@ -5,6 +5,7 @@ use Drupal\Core\Entity\Entity\EntityFormDisplay; use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\Tests\BrowserTestBase; +use Drupal\field\Tests\EntityReference\EntityReferenceTestTrait; /** * Tests possible XSS security issues in entity references. diff --git a/core/modules/field/tests/src/Functional/FieldDefaultValueCallbackProvider.php b/core/modules/field/tests/src/Functional/FieldDefaultValueCallbackProvider.php deleted file mode 100644 index c02a752..0000000 --- a/core/modules/field/tests/src/Functional/FieldDefaultValueCallbackProvider.php +++ /dev/null @@ -1,17 +0,0 @@ - 'Calculated default value']]; - } - -} diff --git a/core/modules/field/tests/src/Functional/Views/FieldTestBase.php b/core/modules/field/tests/src/Functional/Views/FieldTestBase.php deleted file mode 100644 index d8633b5..0000000 --- a/core/modules/field/tests/src/Functional/Views/FieldTestBase.php +++ /dev/null @@ -1,82 +0,0 @@ - 'page', - 'name' => 'page', - ])->save(); - - ViewTestData::createTestViews(get_class($this), array('field_test_views')); - } - - function setUpFieldStorages($amount = 3, $type = 'string') { - // Create three fields. - $field_names = array(); - for ($i = 0; $i < $amount; $i++) { - $field_names[$i] = 'field_name_' . $i; - $this->fieldStorages[$i] = FieldStorageConfig::create(array( - 'field_name' => $field_names[$i], - 'entity_type' => 'node', - 'type' => $type, - )); - $this->fieldStorages[$i]->save(); - } - return $field_names; - } - - function setUpFields($bundle = 'page') { - foreach ($this->fieldStorages as $key => $field_storage) { - $this->fields[$key] = FieldConfig::create([ - 'field_storage' => $field_storage, - 'bundle' => $bundle, - ]); - $this->fields[$key]->save(); - } - } - -} diff --git a/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php b/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php deleted file mode 100644 index 2cded02..0000000 --- a/core/modules/field_ui/tests/src/Functional/FieldUiTestTrait.php +++ /dev/null @@ -1,127 +0,0 @@ -randomString(); - $initial_edit = array( - 'new_storage_type' => $field_type, - 'label' => $label, - 'field_name' => $field_name, - ); - - // Allow the caller to set a NULL path in case they navigated to the right - // page before calling this method. - if ($bundle_path !== NULL) { - $bundle_path = "$bundle_path/fields/add-field"; - } - - // First step: 'Add field' page. - $this->drupalPostForm($bundle_path, $initial_edit, t('Save and continue')); - $this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Storage settings page was displayed.'); - // Test Breadcrumbs. - $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the storage settings page.'); - - // Second step: 'Storage settings' form. - $this->drupalPostForm(NULL, $storage_edit, t('Save field settings')); - $this->assertRaw(t('Updated field %label field settings.', array('%label' => $label)), 'Redirected to field settings page.'); - - // Third step: 'Field settings' form. - $this->drupalPostForm(NULL, $field_edit, t('Save settings')); - $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.'); - - // Check that the field appears in the overview form. - $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.'); - } - - /** - * Adds an existing field through the Field UI. - * - * @param string $bundle_path - * Admin path of the bundle that the field is to be attached to. - * @param string $existing_storage_name - * The name of the existing field storage for which we want to add a new - * field. - * @param string $label - * (optional) The label of the new field. Defaults to a random string. - * @param array $field_edit - * (optional) $edit parameter for drupalPostForm() on the second step - * ('Field settings' form). - */ - public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = array()) { - $label = $label ?: $this->randomString(); - $initial_edit = array( - 'existing_storage_name' => $existing_storage_name, - 'existing_storage_label' => $label, - ); - - // First step: 'Re-use existing field' on the 'Add field' page. - $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue')); - // Set the main content to only the content region because the label can - // contain HTML which will be auto-escaped by Twig. - $main_content = $this->cssSelect('.region-content'); - $this->setRawContent(reset($main_content)->asXml()); - $this->assertRaw('field-config-edit-form', 'The field config edit form is present.'); - $this->assertNoRaw('&lt;', 'The page does not have double escaped HTML tags.'); - - // Second step: 'Field settings' form. - $this->drupalPostForm(NULL, $field_edit, t('Save settings')); - $this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.'); - - // Check that the field appears in the overview form. - $this->assertFieldByXPath('//table[@id="field-overview"]//tr/td[1]', $label, 'Field was created and appears in the overview page.'); - } - - /** - * Deletes a field through the Field UI. - * - * @param string $bundle_path - * Admin path of the bundle that the field is to be deleted from. - * @param string $field_name - * The name of the field. - * @param string $label - * The label of the field. - * @param string $bundle_label - * The label of the bundle. - */ - public function fieldUIDeleteField($bundle_path, $field_name, $label, $bundle_label) { - // Display confirmation form. - $this->drupalGet("$bundle_path/fields/$field_name/delete"); - $this->assertRaw(t('Are you sure you want to delete the field %label', array('%label' => $label)), 'Delete confirmation was found.'); - - // Test Breadcrumbs. - $this->assertLink($label, 0, 'Field label is correct in the breadcrumb of the field delete page.'); - - // Submit confirmation form. - $this->drupalPostForm(NULL, array(), t('Delete')); - $this->assertRaw(t('The field %label has been deleted from the %type content type.', array('%label' => $label, '%type' => $bundle_label)), 'Delete message was found.'); - - // Check that the field does not appear in the overview form. - $this->assertNoFieldByXPath('//table[@id="field-overview"]//span[@class="label-field"]', $label, 'Field does not appear in the overview page.'); - } - -} diff --git a/core/modules/file/src/Tests/FileFieldTestBase.php b/core/modules/file/src/Tests/FileFieldTestBase.php index 307eb4d..9ec9c75 100644 --- a/core/modules/file/src/Tests/FileFieldTestBase.php +++ b/core/modules/file/src/Tests/FileFieldTestBase.php @@ -10,6 +10,9 @@ /** * Provides methods specifically for testing File module's field handling. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\file\Functional\FileFieldTestBase instead. */ abstract class FileFieldTestBase extends WebTestBase { diff --git a/core/modules/file/src/Tests/FileManagedTestBase.php b/core/modules/file/src/Tests/FileManagedTestBase.php index a6e94fa..711d8a4 100644 --- a/core/modules/file/src/Tests/FileManagedTestBase.php +++ b/core/modules/file/src/Tests/FileManagedTestBase.php @@ -9,6 +9,9 @@ /** * Base class for file tests that use the file_test module to test uploads and * hooks. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\file\Functional\FileManagedTestBase instead. */ abstract class FileManagedTestBase extends WebTestBase { diff --git a/core/modules/file/tests/src/Functional/Views/RelationshipUserFileDataTest.php b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php similarity index 98% rename from core/modules/file/tests/src/Functional/Views/RelationshipUserFileDataTest.php rename to core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php index 674cbdc..db49ae1 100644 --- a/core/modules/file/tests/src/Functional/Views/RelationshipUserFileDataTest.php +++ b/core/modules/file/src/Tests/Views/RelationshipUserFileDataTest.php @@ -1,6 +1,6 @@ createStub($entity_type_id); - $this->assertTrue($entity_id, 'Stub successfully created'); - if ($entity_id) { - $violations = $this->validateStub($entity_type_id, $entity_id); - if (!$this->assertIdentical(count($violations), 0, 'Stub is a valid entity')) { - foreach ($violations as $violation) { - $this->fail((string) $violation->getMessage()); - } - } - } - } - - /** - * Create a stub of the given entity type. - * - * @param string $entity_type_id - * The entity type we are stubbing. - * - * @return int - * ID of the created entity. - */ - protected function createStub($entity_type_id) { - // Create a dummy migration to pass to the destination plugin. - $definition = [ - 'migration_tags' => ['Stub test'], - 'source' => ['plugin' => 'empty'], - 'process' => [], - 'destination' => ['plugin' => 'entity:' . $entity_type_id], - ]; - $migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition); - $destination_plugin = $migration->getDestinationPlugin(TRUE); - $stub_row = new Row([], [], TRUE); - $destination_ids = $destination_plugin->import($stub_row); - return reset($destination_ids); - } - - /** - * Perform validation on a stub entity. - * - * @param string $entity_type_id - * The entity type we are stubbing. - * @param string $entity_id - * ID of the stubbed entity to validate. - * - * @return \Drupal\Core\Entity\EntityConstraintViolationListInterface - * List of constraint violations identified. - */ - protected function validateStub($entity_type_id, $entity_id) { - $controller = \Drupal::entityManager()->getStorage($entity_type_id); - /** @var \Drupal\Core\Entity\ContentEntityInterface $stub_entity */ - $stub_entity = $controller->load($entity_id); - return $stub_entity->validate(); - } - -} diff --git a/core/modules/node/src/Tests/NodeTestBase.php b/core/modules/node/src/Tests/NodeTestBase.php index d4799d4..a5da2b4 100644 --- a/core/modules/node/src/Tests/NodeTestBase.php +++ b/core/modules/node/src/Tests/NodeTestBase.php @@ -8,6 +8,9 @@ /** * Sets up page and article content types. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\node\Functional\NodeTestBase instead. */ abstract class NodeTestBase extends WebTestBase { diff --git a/core/modules/node/tests/src/Functional/Views/BulkFormAccessTest.php b/core/modules/node/src/Tests/Views/BulkFormAccessTest.php similarity index 99% rename from core/modules/node/tests/src/Functional/Views/BulkFormAccessTest.php rename to core/modules/node/src/Tests/Views/BulkFormAccessTest.php index 7da0efa..6dada72 100644 --- a/core/modules/node/tests/src/Functional/Views/BulkFormAccessTest.php +++ b/core/modules/node/src/Tests/Views/BulkFormAccessTest.php @@ -1,6 +1,6 @@ xpath('//input[@type="submit"][@value="Save"]'); - - // Verify that the number of buttons passed as parameters is - // available in the dropbutton widget. - if ($dropbutton) { - $i = 0; - $count = count($buttons); - - // Assert there is no save button. - $this->assertTrue(empty($save_button)); - - // Dropbutton elements. - $elements = $this->xpath('//div[@class="dropbutton-wrapper"]//input[@type="submit"]'); - $this->assertEqual($count, count($elements)); - foreach ($elements as $element) { - $value = isset($element['value']) ? (string) $element['value'] : ''; - $this->assertEqual($buttons[$i], $value); - $i++; - } - } - else { - // Assert there is a save button. - $this->assertTrue(!empty($save_button)); - $this->assertNoRaw('dropbutton-wrapper'); - } - } - -} diff --git a/core/modules/node/tests/src/Functional/Views/NodeTestBase.php b/core/modules/node/tests/src/Functional/Views/NodeTestBase.php deleted file mode 100644 index 5dcb2f0..0000000 --- a/core/modules/node/tests/src/Functional/Views/NodeTestBase.php +++ /dev/null @@ -1,28 +0,0 @@ -installEntitySchema('entity_test_mulrev'); - $this->installEntitySchema('user'); - $this->installConfig(array('field')); - \Drupal::service('router.builder')->rebuild(); - \Drupal::moduleHandler()->invoke('rest', 'install'); - - // Auto-create a field for testing. - FieldStorageConfig::create(array( - 'entity_type' => 'entity_test_mulrev', - 'field_name' => 'field_test_text', - 'type' => 'text', - 'cardinality' => 1, - 'translatable' => FALSE, - ))->save(); - FieldConfig::create(array( - 'entity_type' => 'entity_test_mulrev', - 'field_name' => 'field_test_text', - 'bundle' => 'entity_test_mulrev', - 'label' => 'Test text-field', - 'widget' => array( - 'type' => 'text_textfield', - 'weight' => 0, - ), - ))->save(); - } - -} diff --git a/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php b/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php deleted file mode 100644 index 1cb063a..0000000 --- a/core/modules/shortcut/tests/src/Functional/ShortcutTestBase.php +++ /dev/null @@ -1,133 +0,0 @@ -profile != 'standard') { - // Create Basic page and Article node types. - $this->drupalCreateContentType(array('type' => 'page', 'name' => 'Basic page')); - $this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article')); - - // Populate the default shortcut set. - $shortcut = Shortcut::create(array( - 'shortcut_set' => 'default', - 'title' => t('Add content'), - 'weight' => -20, - 'link' => array( - 'uri' => 'internal:/node/add', - ), - )); - $shortcut->save(); - - $shortcut = Shortcut::create(array( - 'shortcut_set' => 'default', - 'title' => t('All content'), - 'weight' => -19, - 'link' => array( - 'uri' => 'internal:/admin/content', - ), - )); - $shortcut->save(); - } - - // Create users. - $this->adminUser = $this->drupalCreateUser(array('access toolbar', 'administer shortcuts', 'view the administration theme', 'create article content', 'create page content', 'access content overview', 'administer users', 'link to any page', 'edit any article content')); - $this->shortcutUser = $this->drupalCreateUser(array('customize shortcut links', 'switch shortcut sets', 'access shortcuts', 'access content')); - - // Create a node. - $this->node = $this->drupalCreateNode(array('type' => 'article')); - - // Log in as admin and grab the default shortcut set. - $this->drupalLogin($this->adminUser); - $this->set = ShortcutSet::load('default'); - \Drupal::entityManager()->getStorage('shortcut_set')->assignUser($this->set, $this->adminUser); - } - - /** - * Creates a generic shortcut set. - */ - function generateShortcutSet($label = '', $id = NULL) { - $set = ShortcutSet::create(array( - 'id' => isset($id) ? $id : strtolower($this->randomMachineName()), - 'label' => empty($label) ? $this->randomString() : $label, - )); - $set->save(); - return $set; - } - - /** - * Extracts information from shortcut set links. - * - * @param \Drupal\shortcut\ShortcutSetInterface $set - * The shortcut set object to extract information from. - * @param string $key - * The array key indicating what information to extract from each link: - * - 'title': Extract shortcut titles. - * - 'link': Extract shortcut paths. - * - 'id': Extract the shortcut ID. - * - * @return array - * Array of the requested information from each link. - */ - function getShortcutInformation(ShortcutSetInterface $set, $key) { - $info = array(); - \Drupal::entityManager()->getStorage('shortcut')->resetCache(); - foreach ($set->getShortcuts() as $shortcut) { - if ($key == 'link') { - $info[] = $shortcut->link->uri; - } - else { - $info[] = $shortcut->{$key}->value; - } - } - return $info; - } - -} diff --git a/core/modules/simpletest/tests/src/Functional/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php similarity index 99% rename from core/modules/simpletest/tests/src/Functional/KernelTestBaseTest.php rename to core/modules/simpletest/src/Tests/KernelTestBaseTest.php index b0265ec..15ecf1f 100644 --- a/core/modules/simpletest/tests/src/Functional/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -1,6 +1,6 @@ 'Bad html ']; - } - } diff --git a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml index cbcf6d8..a2d5ed5 100644 --- a/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml +++ b/core/modules/system/tests/modules/test_page_test/test_page_test.routing.yml @@ -58,11 +58,3 @@ test_page_test.error: code: 200 requirements: _access: 'TRUE' - -test_page_test.encoded: - path: '/test-encoded' - defaults: - _title: 'Page with encoded HTML' - _controller: '\Drupal\test_page_test\Controller\Test::renderEncodedMarkup' - requirements: - _access: 'TRUE' diff --git a/core/modules/system/tests/src/Functional/Ajax/AjaxTestBase.php b/core/modules/system/tests/src/Functional/Ajax/AjaxTestBase.php deleted file mode 100644 index b315811..0000000 --- a/core/modules/system/tests/src/Functional/Ajax/AjaxTestBase.php +++ /dev/null @@ -1,63 +0,0 @@ -assertTrue($found, $message); - } - -} diff --git a/core/modules/system/tests/src/Functional/Bootstrap/ExceptionContainer.php b/core/modules/system/tests/src/Functional/Bootstrap/ExceptionContainer.php deleted file mode 100644 index 55e744f..0000000 --- a/core/modules/system/tests/src/Functional/Bootstrap/ExceptionContainer.php +++ /dev/null @@ -1,24 +0,0 @@ -config('system.performance'); - $config->set('cache.page.max_age', 300); - $config->save(); - } - - /** - * Gets a specific header value as array. - * - * @param string $header_name - * The header name. - * - * @return string[] - * The header value, potentially exploded by spaces. - */ - protected function getCacheHeaderValues($header_name) { - $header_value = $this->drupalGetHeader($header_name); - if (empty($header_value)) { - return []; - } - else { - return explode(' ', $header_value); - } - } - - /** - * Asserts whether an expected cache context was present in the last response. - * - * @param string $expected_cache_context - * The expected cache context. - */ - protected function assertCacheContext($expected_cache_context) { - $cache_contexts = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Contexts')); - $this->assertTrue(in_array($expected_cache_context, $cache_contexts), "'" . $expected_cache_context . "' is present in the X-Drupal-Cache-Contexts header."); - } - - /** - * Asserts that a cache context was not present in the last response. - * - * @param string $not_expected_cache_context - * The expected cache context. - */ - protected function assertNoCacheContext($not_expected_cache_context) { - $cache_contexts = explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Contexts')); - $this->assertFalse(in_array($not_expected_cache_context, $cache_contexts), "'" . $not_expected_cache_context . "' is not present in the X-Drupal-Cache-Contexts header."); - } - - /** - * Asserts page cache miss, then hit for the given URL; checks cache headers. - * - * @param \Drupal\Core\Url $url - * The URL to test. - * @param string[] $expected_contexts - * The expected cache contexts for the given URL. - * @param string[] $expected_tags - * The expected cache tags for the given URL. - */ - protected function assertPageCacheContextsAndTags(Url $url, array $expected_contexts, array $expected_tags) { - $absolute_url = $url->setAbsolute()->toString(); - sort($expected_contexts); - sort($expected_tags); - - // Assert cache miss + expected cache contexts + tags. - $this->drupalGet($absolute_url); - $this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS'); - $this->assertCacheTags($expected_tags); - $this->assertCacheContexts($expected_contexts); - - // Assert cache hit + expected cache contexts + tags. - $this->drupalGet($absolute_url); - $this->assertCacheTags($expected_tags); - $this->assertCacheContexts($expected_contexts); - - // Assert page cache item + expected cache tags. - $cid_parts = array($url->setAbsolute()->toString(), 'html'); - $cid = implode(':', $cid_parts); - $cache_entry = \Drupal::cache('render')->get($cid); - sort($cache_entry->tags); - $this->assertEqual($cache_entry->tags, $expected_tags); - $this->debugCacheTags($cache_entry->tags, $expected_tags); - } - - /** - * Provides debug information for cache tags. - * - * @param string[] $actual_tags - * The actual cache tags. - * @param string[] $expected_tags - * The expected cache tags. - */ - protected function debugCacheTags(array $actual_tags, array $expected_tags) { - if ($actual_tags !== $expected_tags) { - debug('Unwanted cache tags in response: ' . implode(',', array_diff($actual_tags, $expected_tags))); - debug('Missing cache tags in response: ' . implode(',', array_diff($expected_tags, $actual_tags))); - } - } - - /** - * Ensures that some cache tags are present in the current response. - * - * @param string[] $expected_tags - * The expected tags. - * @param bool $include_default_tags - * (optional) Whether the default cache tags should be included. - */ - protected function assertCacheTags(array $expected_tags, $include_default_tags = TRUE) { - // The anonymous role cache tag is only added if the user is anonymous. - if ($include_default_tags && \Drupal::currentUser()->isAnonymous()) { - $expected_tags = Cache::mergeTags($expected_tags, ['config:user.role.anonymous']); - } - $actual_tags = $this->getCacheHeaderValues('X-Drupal-Cache-Tags'); - sort($expected_tags); - sort($actual_tags); - $this->assertIdentical($actual_tags, $expected_tags); - $this->debugCacheTags($actual_tags, $expected_tags); - } - - /** - * Ensures that some cache contexts are present in the current response. - * - * @param string[] $expected_contexts - * The expected cache contexts. - * @param string $message - * (optional) A verbose message to output. - * @param bool $include_default_contexts - * (optional) Whether the default contexts should automatically be included. - * - * @return - * TRUE if the assertion succeeded, FALSE otherwise. - */ - protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) { - if ($include_default_contexts) { - $default_contexts = ['languages:language_interface', 'theme']; - // Add the user.permission context to the list of default contexts except - // when user is already there. - if (!in_array('user', $expected_contexts)) { - $default_contexts[] = 'user.permissions'; - } - $expected_contexts = Cache::mergeContexts($expected_contexts, $default_contexts); - } - - $actual_contexts = $this->getCacheHeaderValues('X-Drupal-Cache-Contexts'); - sort($expected_contexts); - sort($actual_contexts); - $return = $this->assertIdentical($actual_contexts, $expected_contexts, $message); - if (!$return) { - debug('Unwanted cache contexts in response: ' . implode(',', array_diff($actual_contexts, $expected_contexts))); - debug('Missing cache contexts in response: ' . implode(',', array_diff($expected_contexts, $actual_contexts))); - } - return $return; - } - - /** - * Asserts the max age header. - * - * @param int $max_age - */ - protected function assertCacheMaxAge($max_age) { - $cache_control_header = $this->drupalGetHeader('Cache-Control'); - if (strpos($cache_control_header, 'max-age:' . $max_age) === FALSE) { - debug('Expected max-age:' . $max_age . '; Response max-age:' . $cache_control_header); - } - $this->assertTrue(strpos($cache_control_header, 'max-age:' . $max_age)); - } - -} diff --git a/core/modules/system/tests/src/Functional/Cache/GenericCacheBackendUnitTestBase.php b/core/modules/system/tests/src/Functional/Cache/GenericCacheBackendUnitTestBase.php deleted file mode 100644 index 6996a4d..0000000 --- a/core/modules/system/tests/src/Functional/Cache/GenericCacheBackendUnitTestBase.php +++ /dev/null @@ -1,623 +0,0 @@ -testBin)) { - $this->testBin = 'page'; - } - return $this->testBin; - } - - /** - * Creates a cache backend to test. - * - * Override this method to test a CacheBackend. - * - * @param string $bin - * Bin name to use for this backend instance. - * - * @return \Drupal\Core\Cache\CacheBackendInterface - * Cache backend to test. - */ - protected abstract function createCacheBackend($bin); - - /** - * Allows specific implementation to change the environment before a test run. - */ - public function setUpCacheBackend() { - } - - /** - * Allows alteration of environment after a test run but before tear down. - * - * Used before the real tear down because the tear down will change things - * such as the database prefix. - */ - public function tearDownCacheBackend() { - } - - /** - * Gets a backend to test; this will get a shared instance set in the object. - * - * @return \Drupal\Core\Cache\CacheBackendInterface - * Cache backend to test. - */ - protected function getCacheBackend($bin = NULL) { - if (!isset($bin)) { - $bin = $this->getTestBin(); - } - if (!isset($this->cachebackends[$bin])) { - $this->cachebackends[$bin] = $this->createCacheBackend($bin); - // Ensure the backend is empty. - $this->cachebackends[$bin]->deleteAll(); - } - return $this->cachebackends[$bin]; - } - - protected function setUp() { - $this->cachebackends = array(); - $this->defaultValue = $this->randomMachineName(10); - - parent::setUp(); - - $this->setUpCacheBackend(); - } - - protected function tearDown() { - // Destruct the registered backend, each test will get a fresh instance, - // properly emptying it here ensure that on persistent data backends they - // will come up empty the next test. - foreach ($this->cachebackends as $bin => $cachebackend) { - $this->cachebackends[$bin]->deleteAll(); - } - unset($this->cachebackends); - - $this->tearDownCacheBackend(); - - parent::tearDown(); - } - - /** - * Tests the get and set methods of Drupal\Core\Cache\CacheBackendInterface. - */ - public function testSetGet() { - $backend = $this->getCacheBackend(); - - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); - $with_backslash = array('foo' => '\Drupal\foo\Bar'); - $backend->set('test1', $with_backslash); - $cached = $backend->get('test1'); - $this->assert(is_object($cached), "Backend returned an object for cache id test1."); - $this->assertIdentical($with_backslash, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - // We need to round because microtime may be rounded up in the backend. - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); - $backend->set('test2', array('value' => 3), REQUEST_TIME + 3); - $cached = $backend->get('test2'); - $this->assert(is_object($cached), "Backend returned an object for cache id test2."); - $this->assertIdentical(array('value' => 3), $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, REQUEST_TIME + 3, 'Expire time is correct.'); - - $backend->set('test3', 'foobar', REQUEST_TIME - 3); - $this->assertFalse($backend->get('test3'), 'Invalid item not returned.'); - $cached = $backend->get('test3', TRUE); - $this->assert(is_object($cached), 'Backend returned an object for cache id test3.'); - $this->assertFalse($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, REQUEST_TIME - 3, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test4'), "Backend does not contain data for cache id test4."); - $with_eof = array('foo' => "\nEOF\ndata"); - $backend->set('test4', $with_eof); - $cached = $backend->get('test4'); - $this->assert(is_object($cached), "Backend returned an object for cache id test4."); - $this->assertIdentical($with_eof, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $this->assertIdentical(FALSE, $backend->get('test5'), "Backend does not contain data for cache id test5."); - $with_eof_and_semicolon = array('foo' => "\nEOF;\ndata"); - $backend->set('test5', $with_eof_and_semicolon); - $cached = $backend->get('test5'); - $this->assert(is_object($cached), "Backend returned an object for cache id test5."); - $this->assertIdentical($with_eof_and_semicolon, $cached->data); - $this->assertTrue($cached->valid, 'Item is marked as valid.'); - $this->assertTrue($cached->created >= REQUEST_TIME && $cached->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached->expire, Cache::PERMANENT, 'Expire time is correct.'); - - $with_variable = array('foo' => '$bar'); - $backend->set('test6', $with_variable); - $cached = $backend->get('test6'); - $this->assert(is_object($cached), "Backend returned an object for cache id test6."); - $this->assertIdentical($with_variable, $cached->data); - - // Make sure that a cached object is not affected by changing the original. - $data = new \stdClass(); - $data->value = 1; - $data->obj = new \stdClass(); - $data->obj->value = 2; - $backend->set('test7', $data); - $expected_data = clone $data; - // Add a property to the original. It should not appear in the cached data. - $data->this_should_not_be_in_the_cache = TRUE; - $cached = $backend->get('test7'); - $this->assert(is_object($cached), "Backend returned an object for cache id test7."); - $this->assertEqual($expected_data, $cached->data); - $this->assertFalse(isset($cached->data->this_should_not_be_in_the_cache)); - // Add a property to the cache data. It should not appear when we fetch - // the data from cache again. - $cached->data->this_should_not_be_in_the_cache = TRUE; - $fresh_cached = $backend->get('test7'); - $this->assertFalse(isset($fresh_cached->data->this_should_not_be_in_the_cache)); - - // Check with a long key. - $cid = str_repeat('a', 300); - $backend->set($cid, 'test'); - $this->assertEqual('test', $backend->get($cid)->data); - - // Check that the cache key is case sensitive. - $backend->set('TEST8', 'value'); - $this->assertEqual('value', $backend->get('TEST8')->data); - $this->assertFalse($backend->get('test8')); - - // Calling ::set() with invalid cache tags. This should fail an assertion. - try { - $backend->set('assertion_test', 'value', Cache::PERMANENT, ['node' => [3, 5, 7]]); - $this->fail('::set() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::set() was called with invalid cache tags, runtime assertion failed.'); - } - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::delete(). - */ - public function testDelete() { - $backend = $this->getCacheBackend(); - - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1."); - $backend->set('test1', 7); - $this->assert(is_object($backend->get('test1')), "Backend returned an object for cache id test1."); - - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2."); - $backend->set('test2', 3); - $this->assert(is_object($backend->get('test2')), "Backend returned an object for cache id %cid."); - - $backend->delete('test1'); - $this->assertIdentical(FALSE, $backend->get('test1'), "Backend does not contain data for cache id test1 after deletion."); - - $this->assert(is_object($backend->get('test2')), "Backend still has an object for cache id test2."); - - $backend->delete('test2'); - $this->assertIdentical(FALSE, $backend->get('test2'), "Backend does not contain data for cache id test2 after deletion."); - - $long_cid = str_repeat('a', 300); - $backend->set($long_cid, 'test'); - $backend->delete($long_cid); - $this->assertIdentical(FALSE, $backend->get($long_cid), "Backend does not contain data for long cache id after deletion."); - } - - /** - * Tests data type preservation. - */ - public function testValueTypeIsKept() { - $backend = $this->getCacheBackend(); - - $variables = array( - 'test1' => 1, - 'test2' => '0', - 'test3' => '', - 'test4' => 12.64, - 'test5' => FALSE, - 'test6' => array(1, 2, 3), - ); - - // Create cache entries. - foreach ($variables as $cid => $data) { - $backend->set($cid, $data); - } - - // Retrieve and test cache objects. - foreach ($variables as $cid => $value) { - $object = $backend->get($cid); - $this->assert(is_object($object), sprintf("Backend returned an object for cache id %s.", $cid)); - $this->assertIdentical($value, $object->data, sprintf("Data of cached id %s kept is identical in type and value", $cid)); - } - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::getMultiple(). - */ - public function testGetMultiple() { - $backend = $this->getCacheBackend(); - - // Set numerous testing keys. - $long_cid = str_repeat('a', 300); - $backend->set('test1', 1); - $backend->set('test2', 3); - $backend->set('test3', 5); - $backend->set('test4', 7); - $backend->set('test5', 11); - $backend->set('test6', 13); - $backend->set('test7', 17); - $backend->set($long_cid, 300); - - // Mismatch order for harder testing. - $reference = array( - 'test3', - 'test7', - 'test21', // Cid does not exist. - 'test6', - 'test19', // Cid does not exist until added before second getMultiple(). - 'test2', - ); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - // Test return - ensure it contains existing cache ids. - $this->assert(isset($ret['test2']), "Existing cache id test2 is set."); - $this->assert(isset($ret['test3']), "Existing cache id test3 is set."); - $this->assert(isset($ret['test6']), "Existing cache id test6 is set."); - $this->assert(isset($ret['test7']), "Existing cache id test7 is set."); - // Test return - ensure that objects has expected properties. - $this->assertTrue($ret['test2']->valid, 'Item is marked as valid.'); - $this->assertTrue($ret['test2']->created >= REQUEST_TIME && $ret['test2']->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($ret['test2']->expire, Cache::PERMANENT, 'Expire time is correct.'); - // Test return - ensure it does not contain nonexistent cache ids. - $this->assertFalse(isset($ret['test19']), "Nonexistent cache id test19 is not set."); - $this->assertFalse(isset($ret['test21']), "Nonexistent cache id test21 is not set."); - // Test values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test3']->data, 5, "Existing cache id test3 has the correct value."); - $this->assertIdentical($ret['test6']->data, 13, "Existing cache id test6 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - // Test $cids array - ensure it contains cache id's that do not exist. - $this->assert(in_array('test19', $cids), "Nonexistent cache id test19 is in cids array."); - $this->assert(in_array('test21', $cids), "Nonexistent cache id test21 is in cids array."); - // Test $cids array - ensure it does not contain cache id's that exist. - $this->assertFalse(in_array('test2', $cids), "Existing cache id test2 is not in cids array."); - $this->assertFalse(in_array('test3', $cids), "Existing cache id test3 is not in cids array."); - $this->assertFalse(in_array('test6', $cids), "Existing cache id test6 is not in cids array."); - $this->assertFalse(in_array('test7', $cids), "Existing cache id test7 is not in cids array."); - - // Test a second time after deleting and setting new keys which ensures that - // if the backend uses statics it does not cause unexpected results. - $backend->delete('test3'); - $backend->delete('test6'); - $backend->set('test19', 57); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - // Test return - ensure it contains existing cache ids. - $this->assert(isset($ret['test2']), "Existing cache id test2 is set"); - $this->assert(isset($ret['test7']), "Existing cache id test7 is set"); - $this->assert(isset($ret['test19']), "Added cache id test19 is set"); - // Test return - ensure it does not contain nonexistent cache ids. - $this->assertFalse(isset($ret['test3']), "Deleted cache id test3 is not set"); - $this->assertFalse(isset($ret['test6']), "Deleted cache id test6 is not set"); - $this->assertFalse(isset($ret['test21']), "Nonexistent cache id test21 is not set"); - // Test values. - $this->assertIdentical($ret['test2']->data, 3, "Existing cache id test2 has the correct value."); - $this->assertIdentical($ret['test7']->data, 17, "Existing cache id test7 has the correct value."); - $this->assertIdentical($ret['test19']->data, 57, "Added cache id test19 has the correct value."); - // Test $cids array - ensure it contains cache id's that do not exist. - $this->assert(in_array('test3', $cids), "Deleted cache id test3 is in cids array."); - $this->assert(in_array('test6', $cids), "Deleted cache id test6 is in cids array."); - $this->assert(in_array('test21', $cids), "Nonexistent cache id test21 is in cids array."); - // Test $cids array - ensure it does not contain cache id's that exist. - $this->assertFalse(in_array('test2', $cids), "Existing cache id test2 is not in cids array."); - $this->assertFalse(in_array('test7', $cids), "Existing cache id test7 is not in cids array."); - $this->assertFalse(in_array('test19', $cids), "Added cache id test19 is not in cids array."); - - // Test with a long $cid and non-numeric array key. - $cids = array('key:key' => $long_cid); - $return = $backend->getMultiple($cids); - $this->assertEqual(300, $return[$long_cid]->data); - $this->assertTrue(empty($cids)); - } - - /** - * Tests \Drupal\Core\Cache\CacheBackendInterface::setMultiple(). - */ - public function testSetMultiple() { - $backend = $this->getCacheBackend(); - - $future_expiration = REQUEST_TIME + 100; - - // Set multiple testing keys. - $backend->set('cid_1', 'Some other value'); - $items = array( - 'cid_1' => array('data' => 1), - 'cid_2' => array('data' => 2), - 'cid_3' => array('data' => array(1, 2)), - 'cid_4' => array('data' => 1, 'expire' => $future_expiration), - 'cid_5' => array('data' => 1, 'tags' => array('test:a', 'test:b')), - ); - $backend->setMultiple($items); - $cids = array_keys($items); - $cached = $backend->getMultiple($cids); - - $this->assertEqual($cached['cid_1']->data, $items['cid_1']['data'], 'Over-written cache item set correctly.'); - $this->assertTrue($cached['cid_1']->valid, 'Item is marked as valid.'); - $this->assertTrue($cached['cid_1']->created >= REQUEST_TIME && $cached['cid_1']->created <= round(microtime(TRUE), 3), 'Created time is correct.'); - $this->assertEqual($cached['cid_1']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_2']->data, $items['cid_2']['data'], 'New cache item set correctly.'); - $this->assertEqual($cached['cid_2']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_3']->data, $items['cid_3']['data'], 'New cache item with serialized data set correctly.'); - $this->assertEqual($cached['cid_3']->expire, CacheBackendInterface::CACHE_PERMANENT, 'Cache expiration defaults to permanent.'); - - $this->assertEqual($cached['cid_4']->data, $items['cid_4']['data'], 'New cache item set correctly.'); - $this->assertEqual($cached['cid_4']->expire, $future_expiration, 'Cache expiration has been correctly set.'); - - $this->assertEqual($cached['cid_5']->data, $items['cid_5']['data'], 'New cache item set correctly.'); - - // Calling ::setMultiple() with invalid cache tags. This should fail an - // assertion. - try { - $items = [ - 'exception_test_1' => array('data' => 1, 'tags' => []), - 'exception_test_2' => array('data' => 2, 'tags' => ['valid']), - 'exception_test_3' => array('data' => 3, 'tags' => ['node' => [3, 5, 7]]), - ]; - $backend->setMultiple($items); - $this->fail('::setMultiple() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::setMultiple() was called with invalid cache tags, runtime assertion failed.'); - } - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::delete() and - * Drupal\Core\Cache\CacheBackendInterface::deleteMultiple(). - */ - public function testDeleteMultiple() { - $backend = $this->getCacheBackend(); - - // Set numerous testing keys. - $backend->set('test1', 1); - $backend->set('test2', 3); - $backend->set('test3', 5); - $backend->set('test4', 7); - $backend->set('test5', 11); - $backend->set('test6', 13); - $backend->set('test7', 17); - - $backend->delete('test1'); - $backend->delete('test23'); // Nonexistent key should not cause an error. - $backend->deleteMultiple(array( - 'test3', - 'test5', - 'test7', - 'test19', // Nonexistent key should not cause an error. - 'test21', // Nonexistent key should not cause an error. - )); - - // Test if expected keys have been deleted. - $this->assertIdentical(FALSE, $backend->get('test1'), "Cache id test1 deleted."); - $this->assertIdentical(FALSE, $backend->get('test3'), "Cache id test3 deleted."); - $this->assertIdentical(FALSE, $backend->get('test5'), "Cache id test5 deleted."); - $this->assertIdentical(FALSE, $backend->get('test7'), "Cache id test7 deleted."); - - // Test if expected keys exist. - $this->assertNotIdentical(FALSE, $backend->get('test2'), "Cache id test2 exists."); - $this->assertNotIdentical(FALSE, $backend->get('test4'), "Cache id test4 exists."); - $this->assertNotIdentical(FALSE, $backend->get('test6'), "Cache id test6 exists."); - - // Test if that expected keys do not exist. - $this->assertIdentical(FALSE, $backend->get('test19'), "Cache id test19 does not exist."); - $this->assertIdentical(FALSE, $backend->get('test21'), "Cache id test21 does not exist."); - - // Calling deleteMultiple() with an empty array should not cause an error. - $this->assertFalse($backend->deleteMultiple(array())); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::deleteAll(). - */ - public function testDeleteAll() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->deleteAll(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been deleted.'); - $this->assertFalse($backend_a->get('test2'), 'Second key has been deleted.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::invalidate() and - * Drupal\Core\Cache\CacheBackendInterface::invalidateMultiple(). - */ - function testInvalidate() { - $backend = $this->getCacheBackend(); - $backend->set('test1', 1); - $backend->set('test2', 2); - $backend->set('test3', 2); - $backend->set('test4', 2); - - $reference = array('test1', 'test2', 'test3', 'test4'); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - $this->assertEqual(count($ret), 4, 'Four items returned.'); - - $backend->invalidate('test1'); - $backend->invalidateMultiple(array('test2', 'test3')); - - $cids = $reference; - $ret = $backend->getMultiple($cids); - $this->assertEqual(count($ret), 1, 'Only one item element returned.'); - - $cids = $reference; - $ret = $backend->getMultiple($cids, TRUE); - $this->assertEqual(count($ret), 4, 'Four items returned.'); - - // Calling invalidateMultiple() with an empty array should not cause an - // error. - $this->assertFalse($backend->invalidateMultiple(array())); - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::invalidateTags(). - */ - function testInvalidateTags() { - $backend = $this->getCacheBackend(); - - // Create two cache entries with the same tag and tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - Cache::invalidateTags(array('test_tag:2')); - $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two cache items invalidated after invalidating a cache tag.'); - $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); - - // Create two cache entries with the same tag and an array tag value. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Two cache items were created.'); - - // Invalidate test_tag of value 1. This should invalidate both entries. - Cache::invalidateTags(array('test_tag:1')); - $this->assertFalse($backend->get('test_cid_invalidate1') || $backend->get('test_cid_invalidate2'), 'Two caches removed after invalidating a cache tag.'); - $this->assertTrue($backend->get('test_cid_invalidate1', TRUE) && $backend->get('test_cid_invalidate2', TRUE), 'Cache items not deleted after invalidating a cache tag.'); - - // Create three cache entries with a mix of tags and tag values. - $backend->set('test_cid_invalidate1', $this->defaultValue, Cache::PERMANENT, array('test_tag:1')); - $backend->set('test_cid_invalidate2', $this->defaultValue, Cache::PERMANENT, array('test_tag:2')); - $backend->set('test_cid_invalidate3', $this->defaultValue, Cache::PERMANENT, array('test_tag_foo:3')); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2') && $backend->get('test_cid_invalidate3'), 'Three cached items were created.'); - Cache::invalidateTags(array('test_tag_foo:3')); - $this->assertTrue($backend->get('test_cid_invalidate1') && $backend->get('test_cid_invalidate2'), 'Cache items not matching the tag were not invalidated.'); - $this->assertFalse($backend->get('test_cid_invalidated3'), 'Cached item matching the tag was removed.'); - - // Create cache entry in multiple bins. Two cache entries - // (test_cid_invalidate1 and test_cid_invalidate2) still exist from previous - // tests. - $tags = array('test_tag:1', 'test_tag:2', 'test_tag:3'); - $bins = array('path', 'bootstrap', 'page'); - foreach ($bins as $bin) { - $this->getCacheBackend($bin)->set('test', $this->defaultValue, Cache::PERMANENT, $tags); - $this->assertTrue($this->getCacheBackend($bin)->get('test'), 'Cache item was set in bin.'); - } - - Cache::invalidateTags(array('test_tag:2')); - - // Test that the cache entry has been invalidated in multiple bins. - foreach ($bins as $bin) { - $this->assertFalse($this->getCacheBackend($bin)->get('test'), 'Tag invalidation affected item in bin.'); - } - // Test that the cache entry with a matching tag has been invalidated. - $this->assertFalse($this->getCacheBackend($bin)->get('test_cid_invalidate2'), 'Cache items matching tag were invalidated.'); - // Test that the cache entry with without a matching tag still exists. - $this->assertTrue($this->getCacheBackend($bin)->get('test_cid_invalidate1'), 'Cache items not matching tag were not invalidated.'); - } - - /** - * Test Drupal\Core\Cache\CacheBackendInterface::invalidateAll(). - */ - public function testInvalidateAll() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->invalidateAll(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been invalidated.'); - $this->assertFalse($backend_a->get('test2'), 'Second key has been invalidated.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - $this->assertTrue($backend_a->get('test1', TRUE), 'First key has not been deleted.'); - $this->assertTrue($backend_a->get('test2', TRUE), 'Second key has not been deleted.'); - } - - /** - * Tests Drupal\Core\Cache\CacheBackendInterface::removeBin(). - */ - public function testRemoveBin() { - $backend_a = $this->getCacheBackend(); - $backend_b = $this->getCacheBackend('bootstrap'); - - // Set both expiring and permanent keys. - $backend_a->set('test1', 1, Cache::PERMANENT); - $backend_a->set('test2', 3, time() + 1000); - $backend_b->set('test3', 4, Cache::PERMANENT); - - $backend_a->removeBin(); - - $this->assertFalse($backend_a->get('test1'), 'First key has been deleted.'); - $this->assertFalse($backend_a->get('test2', TRUE), 'Second key has been deleted.'); - $this->assertTrue($backend_b->get('test3'), 'Item in other bin is preserved.'); - } - -} diff --git a/core/modules/system/tests/src/Functional/Database/FakeRecord.php b/core/modules/system/tests/src/Functional/Database/FakeRecord.php deleted file mode 100644 index d51dbd0..0000000 --- a/core/modules/system/tests/src/Functional/Database/FakeRecord.php +++ /dev/null @@ -1,12 +0,0 @@ -state->set('entity_test_new', TRUE); - $this->entityManager->clearCachedDefinitions(); - $this->entityDefinitionUpdateManager->applyUpdates(); - } - - /** - * Resets the entity type definition. - */ - protected function resetEntityType() { - $this->state->set('entity_test_update.entity_type', NULL); - $this->entityManager->clearCachedDefinitions(); - $this->entityDefinitionUpdateManager->applyUpdates(); - } - - /** - * Updates the 'entity_test_update' entity type to revisionable. - */ - protected function updateEntityTypeToRevisionable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $keys = $entity_type->getKeys(); - $keys['revision'] = 'revision_id'; - $entity_type->set('entity_keys', $keys); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Updates the 'entity_test_update' entity type not revisionable. - */ - protected function updateEntityTypeToNotRevisionable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $keys = $entity_type->getKeys(); - unset($keys['revision']); - $entity_type->set('entity_keys', $keys); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Updates the 'entity_test_update' entity type to translatable. - */ - protected function updateEntityTypeToTranslatable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('translatable', TRUE); - $entity_type->set('data_table', 'entity_test_update_data'); - - if ($entity_type->isRevisionable()) { - $entity_type->set('revision_data_table', 'entity_test_update_revision_data'); - } - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Updates the 'entity_test_update' entity type to not translatable. - */ - protected function updateEntityTypeToNotTranslatable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('translatable', FALSE); - $entity_type->set('data_table', NULL); - - if ($entity_type->isRevisionable()) { - $entity_type->set('revision_data_table', NULL); - } - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Adds a new base field to the 'entity_test_update' entity type. - * - * @param string $type - * (optional) The field type for the new field. Defaults to 'string'. - */ - protected function addBaseField($type = 'string') { - $definitions['new_base_field'] = BaseFieldDefinition::create($type) - ->setName('new_base_field') - ->setLabel(t('A new base field')); - $this->state->set('entity_test_update.additional_base_field_definitions', $definitions); - } - - /** - * Adds a long-named base field to the 'entity_test_update' entity type. - */ - protected function addLongNameBaseField() { - $key = 'entity_test_update.additional_base_field_definitions'; - $definitions = $this->state->get($key, []); - $definitions['new_long_named_entity_reference_base_field'] = BaseFieldDefinition::create('entity_reference') - ->setName('new_long_named_entity_reference_base_field') - ->setLabel(t('A new long-named base field')) - ->setSetting('target_type', 'user') - ->setSetting('handler', 'default'); - $this->state->set($key, $definitions); - } - - /** - * Adds a new revisionable base field to the 'entity_test_update' entity type. - * - * @param string $type - * (optional) The field type for the new field. Defaults to 'string'. - */ - protected function addRevisionableBaseField($type = 'string') { - $definitions['new_base_field'] = BaseFieldDefinition::create($type) - ->setName('new_base_field') - ->setLabel(t('A new revisionable base field')) - ->setRevisionable(TRUE); - $this->state->set('entity_test_update.additional_base_field_definitions', $definitions); - } - - /** - * Modifies the new base field from 'string' to 'text'. - */ - protected function modifyBaseField() { - $this->addBaseField('text'); - } - - /** - * Promotes a field to an entity key. - */ - protected function makeBaseFieldEntityKey() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - $entity_keys = $entity_type->getKeys(); - $entity_keys['new_base_field'] = 'new_base_field'; - $entity_type->set('entity_keys', $entity_keys); - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Removes the new base field from the 'entity_test_update' entity type. - */ - protected function removeBaseField() { - $this->state->delete('entity_test_update.additional_base_field_definitions'); - } - - /** - * Adds a single-field index to the base field. - */ - protected function addBaseFieldIndex() { - $this->state->set('entity_test_update.additional_field_index.entity_test_update.new_base_field', TRUE); - } - - /** - * Removes the index added in addBaseFieldIndex(). - */ - protected function removeBaseFieldIndex() { - $this->state->delete('entity_test_update.additional_field_index.entity_test_update.new_base_field'); - } - - /** - * Adds a new bundle field to the 'entity_test_update' entity type. - * - * @param string $type - * (optional) The field type for the new field. Defaults to 'string'. - */ - protected function addBundleField($type = 'string') { - $definitions['new_bundle_field'] = FieldStorageDefinition::create($type) - ->setName('new_bundle_field') - ->setLabel(t('A new bundle field')) - ->setTargetEntityTypeId('entity_test_update'); - $this->state->set('entity_test_update.additional_field_storage_definitions', $definitions); - $this->state->set('entity_test_update.additional_bundle_field_definitions.test_bundle', $definitions); - } - - /** - * Modifies the new bundle field from 'string' to 'text'. - */ - protected function modifyBundleField() { - $this->addBundleField('text'); - } - - /** - * Removes the new bundle field from the 'entity_test_update' entity type. - */ - protected function removeBundleField() { - $this->state->delete('entity_test_update.additional_field_storage_definitions'); - $this->state->delete('entity_test_update.additional_bundle_field_definitions.test_bundle'); - } - - /** - * Adds an index to the 'entity_test_update' entity type's base table. - * - * @see \Drupal\entity_test\EntityTestStorageSchema::getEntitySchema() - */ - protected function addEntityIndex() { - $indexes = array( - 'entity_test_update__new_index' => array('name', 'user_id'), - ); - $this->state->set('entity_test_update.additional_entity_indexes', $indexes); - } - - /** - * Removes the index added in addEntityIndex(). - */ - protected function removeEntityIndex() { - $this->state->delete('entity_test_update.additional_entity_indexes'); - } - - /** - * Renames the base table to 'entity_test_update_new'. - */ - protected function renameBaseTable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('base_table', 'entity_test_update_new'); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Renames the data table to 'entity_test_update_data_new'. - */ - protected function renameDataTable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('data_table', 'entity_test_update_data_new'); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Renames the revision table to 'entity_test_update_revision_new'. - */ - protected function renameRevisionBaseTable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('revision_table', 'entity_test_update_revision_new'); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Renames the revision data table to 'entity_test_update_revision_data_new'. - */ - protected function renameRevisionDataTable() { - $entity_type = clone $this->entityManager->getDefinition('entity_test_update'); - - $entity_type->set('revision_data_table', 'entity_test_update_revision_data_new'); - - $this->state->set('entity_test_update.entity_type', $entity_type); - } - - /** - * Removes the entity type. - */ - protected function deleteEntityType() { - $this->state->set('entity_test_update.entity_type', 'null'); - } - -} diff --git a/core/modules/system/tests/src/Functional/Entity/EntityUnitTestBase.php b/core/modules/system/tests/src/Functional/Entity/EntityUnitTestBase.php deleted file mode 100644 index 5407cd7..0000000 --- a/core/modules/system/tests/src/Functional/Entity/EntityUnitTestBase.php +++ /dev/null @@ -1,200 +0,0 @@ -entityManager = $this->container->get('entity.manager'); - $this->state = $this->container->get('state'); - - $this->installSchema('system', 'sequences'); - - $this->installEntitySchema('user'); - $this->installEntitySchema('entity_test'); - - // If the concrete test sub-class installs the Node or Comment modules, - // ensure that the node and comment entity schema are created before the - // field configurations are installed. This is because the entity tables - // need to be created before the body field storage tables. This prevents - // trying to create the body field tables twice. - $class = get_class($this); - while ($class) { - if (property_exists($class, 'modules')) { - // Only check the modules, if the $modules property was not inherited. - $rp = new \ReflectionProperty($class, 'modules'); - if ($rp->class == $class) { - foreach (array_intersect(array('node', 'comment'), $class::$modules) as $module) { - $this->installEntitySchema($module); - } - if (in_array('forum', $class::$modules, TRUE)) { - // Forum module is particular about the order that dependencies are - // enabled in. The comment, node and taxonomy config and the - // taxonomy_term schema need to be installed before the forum config - // which in turn needs to be installed before field config. - $this->installConfig(['comment', 'node', 'taxonomy']); - $this->installEntitySchema('taxonomy_term'); - $this->installConfig(['forum']); - } - } - } - $class = get_parent_class($class); - } - - $this->installConfig(array('field')); - } - - /** - * Creates a user. - * - * @param array $values - * (optional) The values used to create the entity. - * @param array $permissions - * (optional) Array of permission names to assign to user. - * - * @return \Drupal\user\Entity\User - * The created user entity. - */ - protected function createUser($values = array(), $permissions = array()) { - if ($permissions) { - // Create a new role and apply permissions to it. - $role = Role::create(array( - 'id' => strtolower($this->randomMachineName(8)), - 'label' => $this->randomMachineName(8), - )); - $role->save(); - user_role_grant_permissions($role->id(), $permissions); - $values['roles'][] = $role->id(); - } - - $account = User::create($values + [ - 'name' => $this->randomMachineName(), - 'status' => 1, - ]); - $account->enforceIsNew(); - $account->save(); - return $account; - } - - /** - * Reloads the given entity from the storage and returns it. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity to be reloaded. - * - * @return \Drupal\Core\Entity\EntityInterface - * The reloaded entity. - */ - protected function reloadEntity(EntityInterface $entity) { - $controller = $this->entityManager->getStorage($entity->getEntityTypeId()); - $controller->resetCache(array($entity->id())); - return $controller->load($entity->id()); - } - - /** - * Returns the entity_test hook invocation info. - * - * @return array - * An associative array of arbitrary hook data keyed by hook name. - */ - protected function getHooksInfo() { - $key = 'entity_test.hooks'; - $hooks = $this->state->get($key); - $this->state->set($key, array()); - return $hooks; - } - - /** - * Installs a module and refreshes services. - * - * @param string $module - * The module to install. - */ - protected function installModule($module) { - $this->enableModules(array($module)); - $this->refreshServices(); - } - - /** - * Uninstalls a module and refreshes services. - * - * @param string $module - * The module to uninstall. - */ - protected function uninstallModule($module) { - $this->disableModules(array($module)); - $this->refreshServices(); - } - - /** - * Refresh services. - */ - protected function refreshServices() { - $this->container = \Drupal::getContainer(); - $this->entityManager = $this->container->get('entity.manager'); - $this->state = $this->container->get('state'); - } - - /** - * Generates a random ID avoiding collisions. - * - * @param bool $string - * (optional) Whether the id should have string type. Defaults to FALSE. - * - * @return int|string - * The entity identifier. - */ - protected function generateRandomEntityId($string = FALSE) { - srand(time()); - do { - // 0x7FFFFFFF is the maximum allowed value for integers that works for all - // Drupal supported databases and is known to work for other databases - // like SQL Server 2014 and Oracle 10 too. - $id = $string ? $this->randomMachineName() : mt_rand(1, 0x7FFFFFFF); - } while (isset($this->generatedIds[$id])); - $this->generatedIds[$id] = $id; - return $id; - } - -} diff --git a/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php b/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php deleted file mode 100644 index 34a1d54..0000000 --- a/core/modules/system/tests/src/Functional/Entity/EntityWithUriCacheTagsTestBase.php +++ /dev/null @@ -1,156 +0,0 @@ -_view" - * - ":" - */ - public function testEntityUri() { - $entity_url = $this->entity->urlInfo(); - $entity_type = $this->entity->getEntityTypeId(); - - // Selects the view mode that will be used. - $view_mode = $this->selectViewMode($entity_type); - - // The default cache contexts for rendered entities. - $entity_cache_contexts = $this->getDefaultCacheContexts(); - - // Generate the standardized entity cache tags. - $cache_tag = $this->entity->getCacheTags(); - $view_cache_tag = \Drupal::entityManager()->getViewBuilder($entity_type)->getCacheTags(); - $render_cache_tag = 'rendered'; - - - $this->pass("Test entity.", 'Debug'); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit, but also the presence of the correct cache tags. - $this->verifyPageCache($entity_url, 'HIT'); - - // Also verify the existence of an entity render cache entry, if this entity - // type supports render caching. - if (\Drupal::entityManager()->getDefinition($entity_type)->isRenderCacheable()) { - $cache_keys = ['entity_view', $entity_type, $this->entity->id(), $view_mode]; - $cid = $this->createCacheId($cache_keys, $entity_cache_contexts); - $redirected_cid = NULL; - $additional_cache_contexts = $this->getAdditionalCacheContextsForEntity($this->entity); - if (count($additional_cache_contexts)) { - $redirected_cid = $this->createCacheId($cache_keys, Cache::mergeContexts($entity_cache_contexts, $additional_cache_contexts)); - } - $expected_cache_tags = Cache::mergeTags($cache_tag, $view_cache_tag); - $expected_cache_tags = Cache::mergeTags($expected_cache_tags, $this->getAdditionalCacheTagsForEntity($this->entity)); - $expected_cache_tags = Cache::mergeTags($expected_cache_tags, array($render_cache_tag)); - $this->verifyRenderCache($cid, $expected_cache_tags, $redirected_cid); - } - - // Verify that after modifying the entity, there is a cache miss. - $this->pass("Test modification of entity.", 'Debug'); - $this->entity->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - - // Verify that after modifying the entity's display, there is a cache miss. - $this->pass("Test modification of entity's '$view_mode' display.", 'Debug'); - $entity_display = entity_get_display($entity_type, $this->entity->bundle(), $view_mode); - $entity_display->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - - if ($bundle_entity_type_id = $this->entity->getEntityType()->getBundleEntityType()) { - // Verify that after modifying the corresponding bundle entity, there is a - // cache miss. - $this->pass("Test modification of entity's bundle entity.", 'Debug'); - $bundle_entity = $this->container->get('entity_type.manager') - ->getStorage($bundle_entity_type_id) - ->load($this->entity->bundle()); - $bundle_entity->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - } - - - if ($this->entity->getEntityType()->get('field_ui_base_route')) { - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of entity's configurable field.", 'Debug'); - $field_storage_name = $this->entity->getEntityTypeId() . '.configurable_field'; - $field_storage = FieldStorageConfig::load($field_storage_name); - $field_storage->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - // Verify that after modifying a configurable field on the entity, there - // is a cache miss. - $this->pass("Test modification of entity's configurable field.", 'Debug'); - $field_name = $this->entity->getEntityTypeId() . '.' . $this->entity->bundle() . '.configurable_field'; - $field = FieldConfig::load($field_name); - $field->save(); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - } - - - // Verify that after invalidating the entity's cache tag directly, there is - // a cache miss. - $this->pass("Test invalidation of entity's cache tag.", 'Debug'); - Cache::invalidateTags($this->entity->getCacheTagsToInvalidate()); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - - // Verify that after invalidating the generic entity type's view cache tag - // directly, there is a cache miss. - $this->pass("Test invalidation of entity's 'view' cache tag.", 'Debug'); - Cache::invalidateTags($view_cache_tag); - $this->verifyPageCache($entity_url, 'MISS'); - - // Verify a cache hit. - $this->verifyPageCache($entity_url, 'HIT'); - - - // Verify that after deleting the entity, there is a cache miss. - $this->pass('Test deletion of entity.', 'Debug'); - $this->entity->delete(); - $this->verifyPageCache($entity_url, 'MISS'); - $this->assertResponse(404); - } - - /** - * Gets the default cache contexts for rendered entities. - * - * @return array - * The default cache contexts for rendered entities. - */ - protected function getDefaultCacheContexts() { - return ['languages:' . LanguageInterface::TYPE_INTERFACE, 'theme', 'user.permissions']; - } - -} diff --git a/core/modules/system/tests/src/Functional/Form/StubForm.php b/core/modules/system/tests/src/Functional/Form/StubForm.php deleted file mode 100644 index 4cf91c0..0000000 --- a/core/modules/system/tests/src/Functional/Form/StubForm.php +++ /dev/null @@ -1,60 +0,0 @@ -formId = $form_id; - $this->form = $form; - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - $this->formId; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - return $this->form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - } - -} diff --git a/core/modules/system/tests/src/Functional/Installer/ConfigAfterInstallerTestBase.php b/core/modules/system/tests/src/Functional/Installer/ConfigAfterInstallerTestBase.php deleted file mode 100644 index c18712c..0000000 --- a/core/modules/system/tests/src/Functional/Installer/ConfigAfterInstallerTestBase.php +++ /dev/null @@ -1,44 +0,0 @@ -container->get('config.storage'); - /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ - $config_manager = $this->container->get('config.manager'); - - $default_install_path = 'core/profiles/' . $this->profile . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; - $profile_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); - - foreach ($profile_config_storage->listAll() as $config_name) { - $result = $config_manager->diff($profile_config_storage, $active_config_storage, $config_name); - try { - $this->assertConfigDiff($result, $config_name, $skipped_config); - } - catch (\Exception $e) { - $this->fail($e->getMessage()); - } - } - } - -} diff --git a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php deleted file mode 100644 index f124df7..0000000 --- a/core/modules/system/tests/src/Functional/Menu/AssertBreadcrumbTrait.php +++ /dev/null @@ -1,111 +0,0 @@ -drupalGet($goto); - } - $this->assertBreadcrumbParts($trail); - - // Additionally assert page title, if given. - if (isset($page_title)) { - $this->assertTitle(strtr('@title | Drupal', array('@title' => $page_title))); - } - - // Additionally assert active trail in a menu tree output, if given. - if ($tree) { - $this->assertMenuActiveTrail($tree, $last_active); - } - } - - /** - * Assert that a trail exists in the internal browser. - * - * @param array $trail - * An associative array whose keys are expected breadcrumb link paths and - * whose values are expected breadcrumb link texts (not sanitized). - */ - protected function assertBreadcrumbParts($trail) { - // Compare paths with actual breadcrumb. - $parts = $this->getBreadcrumbParts(); - $pass = TRUE; - // There may be more than one breadcrumb on the page. If $trail is empty - // this test would go into an infinite loop, so we need to check that too. - while ($trail && !empty($parts)) { - foreach ($trail as $path => $title) { - // If the path is empty, generate the path from the route. If - // the path does not start with a leading slash, then run it through - // Url::fromUri('base:')->toString() to get the correct base - // prepended. - if ($path == '') { - $url = Url::fromRoute('')->toString(); - } - elseif ($path[0] != '/') { - $url = Url::fromUri('base:' . $path)->toString(); - } - else { - $url = $path; - } - $part = array_shift($parts); - $pass = ($pass && $part['href'] === $url && $part['text'] === Html::escape($title)); - } - } - // No parts must be left, or an expected "Home" will always pass. - $pass = ($pass && empty($parts)); - - $this->assertTrue($pass, format_string('Breadcrumb %parts found on @path.', array( - '%parts' => implode(' » ', $trail), - '@path' => $this->getUrl(), - ))); - } - - /** - * Returns the breadcrumb contents of the current page in the internal browser. - */ - protected function getBreadcrumbParts() { - $parts = array(); - $elements = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a'); - if (!empty($elements)) { - foreach ($elements as $element) { - $parts[] = array( - 'text' => (string) $element, - 'href' => (string) $element['href'], - 'title' => (string) $element['title'], - ); - } - } - return $parts; - } - -} diff --git a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php b/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php deleted file mode 100644 index aa96e27..0000000 --- a/core/modules/system/tests/src/Functional/Menu/AssertMenuActiveTrailTrait.php +++ /dev/null @@ -1,65 +0,0 @@ - $link_title) { - $part_xpath = (!$i ? '//' : '/following-sibling::ul/descendant::'); - $part_xpath .= 'li[contains(@class, :class)]/a[contains(@href, :href) and contains(text(), :title)]'; - $part_args = array( - ':class' => 'menu-item--active-trail', - ':href' => Url::fromUri('base:' . $link_path)->toString(), - ':title' => $link_title, - ); - $xpath .= $this->buildXPathQuery($part_xpath, $part_args); - $i++; - } - $elements = $this->xpath($xpath); - $this->assertTrue(!empty($elements), 'Active trail to current page was found in menu tree.'); - - // Append prefix for active link asserted below. - $xpath .= '/following-sibling::ul/descendant::'; - } - else { - $xpath .= '//'; - } - $xpath_last_active = ($last_active ? 'and contains(@class, :class-active)' : ''); - $xpath .= 'li[contains(@class, :class-trail)]/a[contains(@href, :href) ' . $xpath_last_active . 'and contains(text(), :title)]'; - $args = array( - ':class-trail' => 'menu-item--active-trail', - ':class-active' => 'is-active', - ':href' => Url::fromUri('base:' . $active_link_path)->toString(), - ':title' => $active_link_title, - ); - $elements = $this->xpath($xpath, $args); - $this->assertTrue(!empty($elements), format_string('Active link %title was found in menu tree, including active trail links %tree.', array( - '%title' => $active_link_title, - '%tree' => implode(' » ', $tree), - ))); - } - -} diff --git a/core/modules/system/tests/src/Functional/Path/UrlAliasFixtures.php b/core/modules/system/tests/src/Functional/Path/UrlAliasFixtures.php deleted file mode 100644 index d663eb2..0000000 --- a/core/modules/system/tests/src/Functional/Path/UrlAliasFixtures.php +++ /dev/null @@ -1,97 +0,0 @@ -tableDefinition(); - $schema = $connection->schema(); - - foreach ($tables as $name => $table) { - $schema->dropTable($name); - $schema->createTable($name, $table); - } - } - - /** - * Drop the tables used for the sample data. - * - * @param \Drupal\Core\Database\Connection $connection - * The connection to use to drop the tables. - */ - public function dropTables(Connection $connection) { - $tables = $this->tableDefinition(); - $schema = $connection->schema(); - - foreach ($tables as $name => $table) { - $schema->dropTable($name); - } - } - - /** - * Returns an array of URL aliases for testing. - * - * @return array of URL alias definitions. - */ - public function sampleUrlAliases() { - return array( - array( - 'source' => '/node/1', - 'alias' => '/alias_for_node_1_en', - 'langcode' => 'en' - ), - array( - 'source' => '/node/2', - 'alias' => '/alias_for_node_2_en', - 'langcode' => 'en' - ), - array( - 'source' => '/node/1', - 'alias' => '/alias_for_node_1_fr', - 'langcode' => 'fr' - ), - array( - 'source' => '/node/1', - 'alias' => '/alias_for_node_1_und', - 'langcode' => 'und' - ) - ); - } - - - /** - * Returns the table definition for the URL alias fixtures. - * - * @return array - * Table definitions. - */ - public function tableDefinition() { - $tables = array(); - - // Prime the drupal_get_filename() cache with the location of the system - // module as its location is known and shouldn't change. - // @todo Remove as part of https://www.drupal.org/node/2186491 - drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml'); - module_load_install('system'); - $schema = system_schema(); - - $tables['url_alias'] = AliasStorage::schemaDefinition(); - $tables['key_value'] = $schema['key_value']; - - return $tables; - } - -} diff --git a/core/modules/system/tests/src/Functional/Routing/MockAliasManager.php b/core/modules/system/tests/src/Functional/Routing/MockAliasManager.php deleted file mode 100644 index 6f55748..0000000 --- a/core/modules/system/tests/src/Functional/Routing/MockAliasManager.php +++ /dev/null @@ -1,95 +0,0 @@ -defaultLanguage; - - if ($path[0] !== '/') { - throw new \InvalidArgumentException('The path needs to start with a slash.'); - } - if ($alias[0] !== '/') { - throw new \InvalidArgumentException('The alias needs to start with a slash.'); - } - - $this->aliases[$path][$language] = $alias; - $this->systemPaths[$alias][$language] = $path; - } - - /** - * {@inheritdoc} - */ - public function getPathByAlias($alias, $langcode = NULL) { - $langcode = $langcode ?: $this->defaultLanguage; - return $this->systemPaths[$alias][$langcode]; - } - - /** - * {@inheritdoc} - * @param $path - * @param null $langcode - * @return - */ - public function getAliasByPath($path, $langcode = NULL) { - if ($path[0] !== '/') { - throw new \InvalidArgumentException(sprintf('Source path %s has to start with a slash.', $path)); - } - - $langcode = $langcode ?: $this->defaultLanguage; - $this->lookedUp[$path] = 1; - return $this->aliases[$path][$langcode]; - } - - /** - * {@inheritdoc} - */ - public function cacheClear($source = NULL) { - // Not needed. - } - -} diff --git a/core/modules/system/tests/src/Functional/Routing/MockRouteProvider.php b/core/modules/system/tests/src/Functional/Routing/MockRouteProvider.php deleted file mode 100644 index b15215c..0000000 --- a/core/modules/system/tests/src/Functional/Routing/MockRouteProvider.php +++ /dev/null @@ -1,94 +0,0 @@ -routes = $routes; - } - - /** - * Implements \Symfony\Cmf\Component\Routing\RouteProviderInterface::getRouteCollectionForRequest(). - * - * Simply return all routes to prevent - * \Symfony\Component\Routing\Exception\ResourceNotFoundException. - */ - public function getRouteCollectionForRequest(Request $request) { - return $this->routes; - } - - /** - * {@inheritdoc} - */ - public function getRouteByName($name) { - $routes = $this->getRoutesByNames(array($name)); - if (empty($routes)) { - throw new RouteNotFoundException(sprintf('Route "%s" does not exist.', $name)); - } - - return reset($routes); - } - - /** - * {@inheritdoc} - */ - public function preLoadRoutes($names) { - // Nothing to do. - } - - /** - * {@inheritdoc} - */ - public function getRoutesByNames($names) { - $routes = array(); - foreach ($names as $name) { - $routes[] = $this->routes->get($name); - } - - return $routes; - } - - /** - * {@inheritdoc} - */ - public function getRoutesByPattern($pattern) { - return new RouteCollection(); - } - - /** - * {@inheritdoc} - */ - public function getAllRoutes() { - return $this->routes->all(); - } - - /** - * {@inheritdoc} - */ - public function reset() { - $this->routes = array(); - } - -} diff --git a/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php index aa91237..12c30c7 100644 --- a/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/src/Tests/TaxonomyTestBase.php @@ -7,6 +7,9 @@ /** * Provides common helper methods for Taxonomy module tests. + * + * @deprecated Scheduled for removal in Drupal 9.0.0. + * Use \Drupal\Tests\taxonomy\Functional\TaxonomyTestBase instead. */ abstract class TaxonomyTestBase extends WebTestBase { diff --git a/core/modules/taxonomy/tests/src/Functional/Views/RelationshipNodeTermDataTest.php b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php similarity index 97% rename from core/modules/taxonomy/tests/src/Functional/Views/RelationshipNodeTermDataTest.php rename to core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php index 6467a8f..c38c45c 100644 --- a/core/modules/taxonomy/tests/src/Functional/Views/RelationshipNodeTermDataTest.php +++ b/core/modules/taxonomy/src/Tests/Views/RelationshipNodeTermDataTest.php @@ -1,6 +1,6 @@ $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. - */ - function createTerm(Vocabulary $vocabulary, $values = array()) { - $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; - } - -} diff --git a/core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php b/core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php deleted file mode 100644 index 0a40f79..0000000 --- a/core/modules/taxonomy/tests/src/Functional/TaxonomyTranslationTestTrait.php +++ /dev/null @@ -1,105 +0,0 @@ -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 = array( - 'target_bundles' => array( - $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, array( - 'type' => 'entity_reference_autocomplete_tags', - )) - ->save(); - entity_get_display('node', 'article', 'default') - ->setComponent($this->termFieldName, array( - 'type' => 'entity_reference_label', - )) - ->save(); - } - -} diff --git a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php b/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php deleted file mode 100644 index 378d09f..0000000 --- a/core/modules/taxonomy/tests/src/Functional/Views/TaxonomyTestBase.php +++ /dev/null @@ -1,155 +0,0 @@ -mockStandardInstall(); - - if ($import_test_views) { - ViewTestData::createTestViews(get_class($this), array('taxonomy_test_views')); - } - - $this->term1 = $this->createTerm(); - $this->term2 = $this->createTerm(); - - $node = array(); - $node['type'] = 'article'; - $node['field_views_testing_tags'][]['target_id'] = $this->term1->id(); - $node['field_views_testing_tags'][]['target_id'] = $this->term2->id(); - $this->nodes[] = $this->drupalCreateNode($node); - $this->nodes[] = $this->drupalCreateNode($node); - } - - /** - * Provides a workaround for the inability to use the standard profile. - * - * @see https://www.drupal.org/node/1708692 - */ - protected function mockStandardInstall() { - $this->drupalCreateContentType(array( - 'type' => 'article', - )); - // Create the vocabulary for the tag field. - $this->vocabulary = Vocabulary::create([ - 'name' => 'Views testing tags', - 'vid' => 'views_testing_tags', - ]); - $this->vocabulary->save(); - $field_name = 'field_' . $this->vocabulary->id(); - - $handler_settings = array( - 'target_bundles' => array( - $this->vocabulary->id() => $this->vocabulary->id(), - ), - 'auto_create' => TRUE, - ); - $this->createEntityReferenceField('node', 'article', $field_name, 'Tags', 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); - - entity_get_form_display('node', 'article', 'default') - ->setComponent($field_name, array( - 'type' => 'entity_reference_autocomplete_tags', - 'weight' => -4, - )) - ->save(); - - entity_get_display('node', 'article', 'default') - ->setComponent($field_name, array( - 'type' => 'entity_reference_label', - 'weight' => 10, - )) - ->save(); - entity_get_display('node', 'article', 'teaser') - ->setComponent($field_name, array( - 'type' => 'entity_reference_label', - 'weight' => 10, - )) - ->save(); - } - - /** - * Creates and returns a taxonomy term. - * - * @param array $settings - * (optional) An array of values to override the following default - * properties of the term: - * - name: A random string. - * - description: A random string. - * - format: First available text format. - * - vid: Vocabulary ID of self::$vocabulary object. - * - langcode: LANGCODE_NOT_SPECIFIED. - * Defaults to an empty array. - * - * @return \Drupal\taxonomy\Entity\Term - * The created taxonomy term. - */ - protected function createTerm(array $settings = []) { - $filter_formats = filter_formats(); - $format = array_pop($filter_formats); - $settings += [ - 'name' => $this->randomMachineName(), - 'description' => $this->randomMachineName(), - // Use the first available text format. - 'format' => $format->id(), - 'vid' => $this->vocabulary->id(), - 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - ]; - $term = Term::create($settings); - $term->save(); - return $term; - } - -} diff --git a/core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php b/core/modules/user/src/Tests/Views/AccessPermissionTest.php similarity index 97% rename from core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php rename to core/modules/user/src/Tests/Views/AccessPermissionTest.php index acb33d5..b8ef5a9 100644 --- a/core/modules/user/tests/src/Functional/Views/AccessPermissionTest.php +++ b/core/modules/user/src/Tests/Views/AccessPermissionTest.php @@ -1,6 +1,6 @@ drupalPlaceBlock('system_breadcrumb_block'); - - $this->enableViewsTestModule(); - - $this->webUser = $this->drupalCreateUser(); - $roles = $this->webUser->getRoles(); - $this->webRole = $roles[0]; - - $this->normalRole = $this->drupalCreateRole(array()); - $this->normalUser = $this->drupalCreateUser(array('views_test_data test permission')); - $this->normalUser->addRole($this->normalRole); - $this->normalUser->save(); - // @todo when all the plugin information is cached make a reset function and - // call it here. - } - -} diff --git a/core/modules/user/tests/src/Functional/Views/UserTestBase.php b/core/modules/user/tests/src/Functional/Views/UserTestBase.php deleted file mode 100644 index a2a7769..0000000 --- a/core/modules/user/tests/src/Functional/Views/UserTestBase.php +++ /dev/null @@ -1,46 +0,0 @@ -users[] = $this->drupalCreateUser(); - $this->users[] = User::load(1); - $this->nodes[] = $this->drupalCreateNode(array('uid' => $this->users[0]->id())); - $this->nodes[] = $this->drupalCreateNode(array('uid' => 1)); - } - -}