Commit 20a08028 authored by catch's avatar catch

Issue #2687897 by dawehner, jhedstrom, catch, jibran, Berdir, klausi: Convert...

Issue #2687897 by dawehner, jhedstrom, catch, jibran, Berdir, klausi: Convert system module's kernel tests to NG
parent 4012b7ed
......@@ -4,3 +4,5 @@ description: 'Provides the HTTP Basic authentication provider'
package: Web services
version: VERSION
core: 8.x
dependencies:
- user
......@@ -15,6 +15,9 @@
*
* @see DatabaseBackendUnitTestCase
* For a full working implementation.
*
* @deprecated as of Drupal 8.2.x, will be removed before Drupal 9.0.0. Use
* \Drupal\KernelTests\Core\Cache\GenericCacheBackendUnitTestBase instead.
*/
abstract class GenericCacheBackendUnitTestBase extends KernelTestBase {
......
......@@ -2,7 +2,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Test page rendering hooks.
......
......@@ -3,7 +3,7 @@
namespace Drupal\system\Tests\Common;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests scanning system directories in drupal_system_listing().
......
<?php
namespace Drupal\system\Tests\Action;
namespace Drupal\Tests\system\Kernel\Action;
use Drupal\simpletest\KernelTestBase;
use Drupal\Core\Action\ActionInterface;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Action;
use Drupal\user\RoleInterface;
......@@ -12,7 +12,7 @@
*
* @group Action
*/
class ActionUnitTest extends KernelTestBase {
class ActionTest extends KernelTestBase {
/**
* {@inheritdoc}
......
<?php
namespace Drupal\system\Tests\Block;
namespace Drupal\Tests\system\Kernel\Block;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Menu;
use Drupal\block\Entity\Block;
use Drupal\Core\Render\Element;
use Drupal\simpletest\KernelTestBase;
use Drupal\system\Tests\Routing\MockRouteProvider;
use Drupal\Tests\Core\Menu\MenuLinkMock;
use Drupal\user\Entity\User;
......
<?php
namespace Drupal\system\Tests\System;
namespace Drupal\Tests\system\Kernel\System;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the effectiveness of hook_system_info_alter().
......
# Themes are not supposed to provide/install this kind of config normally.
# This exists for testing purposes only.
# @see \Drupal\system\Tests\Extension\ThemeInstallerTest
# @see \Drupal\KernelTests\Core\Theme\ThemeInstallerTest
id: fancy
label: 'Fancy date'
status: true
......
<?php
namespace Drupal\system\Tests\Common;
namespace Drupal\KernelTests\Core\Asset;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Asset\AttachedAssets;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests #attached assets: attached asset libraries and JavaScript settings.
......@@ -195,13 +195,16 @@ function testSettings() {
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
$rendered_js = $this->renderer->renderPlain($js_render_array);
// Cast to string since this returns a \Drupal\Core\Render\Markup object.
$rendered_js = (string) $this->renderer->renderPlain($js_render_array);
// Parse the generated drupalSettings <script> back to a PHP representation.
$startToken = '{';
$endToken = '}';
$start = strpos($rendered_js, $startToken);
$end = strrpos($rendered_js, $endToken);
// Convert to a string, as $renderer_js is a \Drupal\Core\Render\Markup
// object.
$json = Unicode::substr($rendered_js, $start, $end - $start + 1);
$parsed_settings = Json::decode($json);
......
<?php
namespace Drupal\system\Tests\Asset;
namespace Drupal\KernelTests\Core\Asset;
use Drupal\Core\Asset\Exception\InvalidLibrariesExtendSpecificationException;
use Drupal\Core\Asset\Exception\InvalidLibrariesOverrideSpecificationException;
......
<?php
namespace Drupal\system\Tests\Asset;
namespace Drupal\KernelTests\Core\Asset;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests that the asset files for all core libraries exist.
......@@ -83,17 +83,17 @@ class ResolvedLibraryDefinitionsFilesMatchTest extends KernelTestBase {
*/
protected $pathsChecked;
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->themeHandler = $this->container->get('theme_handler');
$this->themeInitialization = $this->container->get('theme.initialization');
$this->themeManager = $this->container->get('theme.manager');
$this->libraryDiscovery = $this->container->get('library.discovery');
// Install all core themes.
sort($this->allThemes);
$this->container->get('theme_installer')->install($this->allThemes);
......@@ -109,8 +109,14 @@ protected function setUp() {
return TRUE;
});
$this->allModules = array_keys($all_modules);
$this->allModules[] = 'system';
sort($this->allModules);
$this->enableModules($this->allModules);
$this->container->get('module_installer')->install($this->allModules);
$this->themeHandler = $this->container->get('theme_handler');
$this->themeInitialization = $this->container->get('theme.initialization');
$this->themeManager = $this->container->get('theme.manager');
$this->libraryDiscovery = $this->container->get('library.discovery');
}
/**
......
<?php
namespace Drupal\system\Tests\Bootstrap;
namespace Drupal\KernelTests\Core\Bootstrap;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests that drupal_get_filename() works correctly.
*
* @group Bootstrap
*/
class GetFilenameUnitTest extends KernelTestBase {
class GetFilenameTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
/**
* Tests that drupal_get_filename() works when the file is not in database.
......
<?php
namespace Drupal\system\Tests\Bootstrap;
namespace Drupal\KernelTests\Core\Bootstrap;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests that drupal_static() and drupal_static_reset() work.
*
* @group Bootstrap
*/
class ResettableStaticUnitTest extends KernelTestBase {
class ResettableStaticTest extends KernelTestBase {
/**
* Tests drupal_static() function.
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\Apcu4Backend;
use Drupal\Core\Cache\ApcuBackend;
......@@ -11,7 +11,7 @@
* @group Cache
* @requires extension apc
*/
class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
class ApcuBackendTest extends GenericCacheBackendUnitTestBase {
/**
* Get a list of failed requirements.
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\BackendChain;
use Drupal\Core\Cache\MemoryBackend;
......@@ -10,7 +10,7 @@
*
* @group Cache
*/
class BackendChainUnitTest extends GenericCacheBackendUnitTestBase {
class BackendChainTest extends GenericCacheBackendUnitTestBase {
protected function createCacheBackend($bin) {
$chain = new BackendChain($bin);
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\simpletest\UserCreationTrait;
use Drupal\user\Entity\Role;
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\ChainedFastBackend;
use Drupal\Core\Cache\DatabaseBackend;
......@@ -11,7 +11,7 @@
*
* @group Cache
*/
class ChainedFastBackendUnitTest extends GenericCacheBackendUnitTestBase {
class ChainedFastBackendTest extends GenericCacheBackendUnitTestBase {
/**
* Creates a new instance of ChainedFastBackend.
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\Cache;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\DependencyInjection\Reference;
/**
......@@ -24,8 +24,8 @@ class DatabaseBackendTagTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
public function register(ContainerBuilder $container) {
parent::register($container);
// Change container to database cache backends.
$container
->register('cache_factory', 'Drupal\Core\Cache\CacheFactory')
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\DatabaseBackend;
......@@ -9,7 +9,7 @@
*
* @group Cache
*/
class DatabaseBackendUnitTest extends GenericCacheBackendUnitTestBase {
class DatabaseBackendTest extends GenericCacheBackendUnitTestBase {
/**
* Modules to enable.
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\MemoryBackend;
......@@ -9,7 +9,7 @@
*
* @group Cache
*/
class MemoryBackendUnitTest extends GenericCacheBackendUnitTestBase {
class MemoryBackendTest extends GenericCacheBackendUnitTestBase {
/**
* Creates a new instance of MemoryBackend.
......
<?php
namespace Drupal\system\Tests\Cache;
namespace Drupal\KernelTests\Core\Cache;
use Drupal\Core\Cache\PhpBackend;
......@@ -9,7 +9,7 @@
*
* @group Cache
*/
class PhpBackendUnitTest extends GenericCacheBackendUnitTestBase {
class PhpBackendTest extends GenericCacheBackendUnitTestBase {
/**
* Creates a new instance of MemoryBackend.
......
<?php
namespace Drupal\system\Tests\Update;
namespace Drupal\KernelTests\Core\Command;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Command\DbDumpApplication;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\User;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Reference;
......@@ -66,8 +66,8 @@ class DbDumpTest extends KernelTestBase {
*
* Register a database cache backend rather than memory-based.
*/
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
public function register(ContainerBuilder $container) {
parent::register($container);
$container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
->addArgument(new Reference('database'))
->addArgument(new Reference('cache_tags.invalidator.checksum'));
......@@ -121,6 +121,7 @@ protected function setUp() {
'cachetags',
'config',
'cache_bootstrap',
'cache_config',
'cache_data',
'cache_default',
'cache_discovery',
......
<?php
namespace Drupal\system\Tests\Common;
namespace Drupal\KernelTests\Core\Common;
use Drupal\Component\Utility\Bytes;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Parse a predefined amount of bytes and compare the output with the expected
......@@ -11,7 +11,7 @@
*
* @group Common
*/
class SizeUnitTest extends KernelTestBase {
class SizeTest extends KernelTestBase {
protected $exactTestCases;
protected $roundedTestCases;
......
<?php
namespace Drupal\system\Tests\Common;
namespace Drupal\KernelTests\Core\Common;
use Drupal\Component\Utility\UrlHelper;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Confirm that \Drupal\Component\Utility\Xss::filter() and check_url() work
......
<?php
namespace Drupal\system\Tests\DrupalKernel;
namespace Drupal\KernelTests\Core\DrupalKernel;
use Drupal\Core\Site\Settings;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests site-specific service overrides.
......@@ -18,7 +18,7 @@ class DrupalKernelSiteTest extends KernelTestBase {
public function testServicesYml() {
$container_yamls = Settings::get('container_yamls');
$container_yamls[] = $this->siteDirectory . '/services.yml';
$this->settingsSet('container_yamls', $container_yamls);
$this->setSetting('container_yamls', $container_yamls);
$this->assertFalse($this->container->has('site.service.yml'));
// A service provider class always has precedence over services.yml files.
// KernelTestBase::buildContainer() swaps out many services with in-memory
......
<?php
namespace Drupal\system\Tests\DrupalKernel;
namespace Drupal\KernelTests\Core\DrupalKernel;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Response;
/**
......
<?php
namespace Drupal\system\Tests\Element;
namespace Drupal\KernelTests\Core\Element;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element\PathElement;
use Drupal\Core\Url;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
......
<?php
namespace Drupal\system\Tests\System;
namespace Drupal\KernelTests\Core\EventSubscriber;
use Drupal\Core\Database\Database;
use Drupal\Core\EventSubscriber\ReplicaDatabaseIgnoreSubscriber;
use Drupal\Core\DrupalKernel;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
......
<?php
namespace Drupal\system\Tests\Module;
namespace Drupal\KernelTests\Core\Extension;
use Drupal\simpletest\KernelTestBase;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests hook_module_implements_alter().
......@@ -11,6 +11,11 @@
*/
class ModuleImplementsAlterTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['system'];
/**
* Tests hook_module_implements_alter() adding an implementation.
*
......
<?php
namespace Drupal\system\Tests\File;
namespace Drupal\KernelTests\Core\File;
use Drupal\Component\PhpStorage\FileStorage;
......@@ -10,6 +10,7 @@
* @group File
*/
class DirectoryTest extends FileTestBase {
/**
* Test local directory handling functions.
*/
......@@ -77,7 +78,7 @@ function testFileCheckDirectoryHandling() {
$this->assertFalse(file_prepare_directory($directory, 0), 'Error reported for a non-writeable directory.', 'File');
// Test directory permission modification.
$this->settingsSet('file_chmod_directory', 0777);
$this->setSetting('file_chmod_directory', 0777);
$this->assertTrue(file_prepare_directory($directory, FILE_MODIFY_PERMISSIONS), 'No error reported when making directory writeable.', 'File');
}
......
<?php
namespace Drupal\system\Tests\File;
namespace Drupal\KernelTests\Core\File;
use Drupal\simpletest\KernelTestBase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\KernelTests\KernelTestBase;
/**
* Base class for file tests that adds some additional file specific
......@@ -31,16 +32,49 @@ abstract class FileTestBase extends KernelTestBase {
*/
protected $classname;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(array('system'));
$this->registerStreamWrapper('private', 'Drupal\Core\StreamWrapper\PrivateStream');
\Drupal::configFactory()->getEditable('system.file')->set('default_scheme', 'public')->save();
}
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container) {
parent::register($container);
$container->register('stream_wrapper.private', 'Drupal\Core\StreamWrapper\PrivateStream')
->addTag('stream_wrapper', ['scheme' => 'private']);
if (isset($this->scheme)) {
$this->registerStreamWrapper($this->scheme, $this->classname);
$container->register('stream_wrapper.' . $this->scheme, $this->classname)
->addTag('stream_wrapper', ['scheme' => $this->scheme]);
}
}
/**
* {@inheritdoc}
*/
protected function setUpFilesystem() {
$public_file_directory = $this->siteDirectory . '/files';
require_once 'core/includes/file.inc';
mkdir($this->siteDirectory, 0775);
mkdir($this->siteDirectory . '/files', 0775);
mkdir($this->siteDirectory . '/files/config/' . CONFIG_SYNC_DIRECTORY, 0775, TRUE);
$this->setSetting('file_public_path', $public_file_directory);
$GLOBALS['config_directories'] = array(
CONFIG_SYNC_DIRECTORY => $this->siteDirectory . '/files/config/sync',
);
}
/**
* Helper function to test the permissions of a file.
*
......
<?php
namespace Drupal\system\Tests\File;
namespace Drupal\KernelTests\Core\File;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\simpletest\KernelTestBase;
use Drupal\Core\Site\Settings;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests .htaccess file saving.
*
* @group File
*/
class HtaccessUnitTest extends KernelTestBase {
class HtaccessTest extends KernelTestBase {
/**
* Tests file_save_htaccess().
*/
function testHtaccessSave() {
// Prepare test directories.
$public = $this->publicFilesDirectory . '/test/public';
$private = $this->publicFilesDirectory . '/test/private';
$public = Settings::get('file_public_path') . '/test/public';
$private = Settings::get('file_public_path') . '/test/private';
$stream = 'public://test/stream';
// Verify that file_save_htaccess() returns FALSE if .htaccess cannot be
......
<?php
namespace Drupal\system\Tests\File;
namespace Drupal\KernelTests\Core\File;
/**
* Tests filename mimetype detection.
......
<?php
namespace Drupal\system\Tests\File;
namespace Drupal\KernelTests\Core\File;
/**
* Tests filename munging and unmunging.
......