diff --git a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php index 89ed6d2..5d1854b 100644 --- a/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php +++ b/core/modules/simpletest/src/Tests/SimpleTestBrowserTest.php @@ -127,7 +127,7 @@ public function testTestingThroughUI() { $tests = array( // A KernelTestBase test. - 'Drupal\system\Tests\DrupalKernel\DrupalKernelTest', + 'Drupal\KernelTests\KernelTestBaseTest', // A PHPUnit unit test. 'Drupal\Tests\action\Unit\Menu\ActionLocalTasksTest', // A PHPUnit functional test. diff --git a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php deleted file mode 100644 index 2ec64e8..0000000 --- a/core/modules/system/src/Tests/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/views/src/Tests/ViewKernelTestBase.php b/core/modules/views/src/Tests/ViewKernelTestBase.php deleted file mode 100644 index 3a5df34..0000000 --- a/core/modules/views/src/Tests/ViewKernelTestBase.php +++ /dev/null @@ -1,148 +0,0 @@ -installSchema('system', array('sequences')); - $this->setUpFixtures(); - - if ($import_test_views) { - ViewTestData::createTestViews(get_class($this), array('views_test_config')); - } - } - - /** - * Sets up the configuration and schema of views and views_test_data modules. - * - * Because the schema of views_test_data.module is dependent on the test - * using it, it cannot be enabled normally. - */ - protected function setUpFixtures() { - // First install the system module. Many Views have Page displays have menu - // links, and for those to work, the system menus must already be present. - $this->installConfig(array('system')); - - // Define the schema and views data variable before enabling the test module. - \Drupal::state()->set('views_test_data_schema', $this->schemaDefinition()); - \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); - - $this->installConfig(array('views', 'views_test_config', 'views_test_data')); - foreach ($this->schemaDefinition() as $table => $schema) { - $this->installSchema('views_test_data', $table); - } - - \Drupal::service('router.builder')->rebuild(); - - // Load the test dataset. - $data_set = $this->dataSet(); - $query = db_insert('views_test_data') - ->fields(array_keys($data_set[0])); - foreach ($data_set as $record) { - $query->values($record); - } - $query->execute(); - } - - /** - * Orders a nested array containing a result set based on a given column. - * - * @param array $result_set - * An array of rows from a result set, with each row as an associative - * array keyed by column name. - * @param string $column - * The column name by which to sort the result set. - * @param bool $reverse - * (optional) Boolean indicating whether to sort the result set in reverse - * order. Defaults to FALSE. - * - * @return array - * The sorted result set. - */ - protected function orderResultSet($result_set, $column, $reverse = FALSE) { - $order = $reverse ? -1 : 1; - usort($result_set, function ($a, $b) use ($column, $order) { - if ($a[$column] == $b[$column]) { - return 0; - } - return $order * (($a[$column] < $b[$column]) ? -1 : 1); - }); - return $result_set; - } - - /** - * Executes a view with debugging. - * - * @param \Drupal\views\ViewExecutable $view - * The view object. - * @param array $args - * (optional) An array of the view arguments to use for the view. - */ - protected function executeView($view, array $args = array()) { - $view->setDisplay(); - $view->preExecute($args); - $view->execute(); - $verbose_message = '
Executed view: ' . ((string) $view->build_info['query']) . '
'; - if ($view->build_info['query'] instanceof SelectInterface) { - $verbose_message .= '
Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '
'; - } - $this->verbose($verbose_message); - } - - /** - * Returns the schema definition. - */ - protected function schemaDefinition() { - return ViewTestData::schemaDefinition(); - } - - /** - * Returns the views data definition. - */ - protected function viewsData() { - return ViewTestData::viewsData(); - } - - /** - * Returns a very simple test dataset. - */ - protected function dataSet() { - return ViewTestData::dataSet(); - } - -} diff --git a/core/modules/views/src/Tests/Plugin/PluginBaseTest.php b/core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php similarity index 96% rename from core/modules/views/src/Tests/Plugin/PluginBaseTest.php rename to core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php index c9ba78f..bfdb848 100644 --- a/core/modules/views/src/Tests/Plugin/PluginBaseTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/PluginBaseTest.php @@ -5,11 +5,11 @@ * Contains \Drupal\views\Tests\Plugin\PluginBaseTest. */ -namespace Drupal\views\Tests\Plugin; +namespace Drupal\Tests\views\Kernel\Plugin; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\Markup; -use Drupal\simpletest\KernelTestBase; +use Drupal\KernelTests\KernelTestBase; use Drupal\views\Plugin\views\PluginBase; /**