Commit f9c1ff23 authored by alexpott's avatar alexpott

Issue #2314123 by sun: Fixed various tests.

parent 1d1ff757
......@@ -32,6 +32,8 @@ class BlockConfigSchemaTest extends KernelTestBase {
'forum',
'node',
'statistics',
// BlockManager->getModuleName() calls system_get_info().
'system',
'taxonomy',
);
......
......@@ -22,7 +22,7 @@ class CKEditorPluginManagerTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'editor', 'ckeditor');
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor');
/**
* The manager for "CKEditor plugin" plugins.
......@@ -36,7 +36,6 @@ function setUp() {
// Install the Filter module.
$this->installSchema('system', 'url_alias');
$this->enableModules(array('user', 'filter'));
// Create text format, associate CKEditor.
$filtered_html_format = entity_create('filter_format', array(
......
......@@ -23,7 +23,7 @@ class CKEditorTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'editor', 'ckeditor', 'filter_test');
public static $modules = array('system', 'user', 'filter', 'editor', 'ckeditor', 'filter_test');
/**
* An instance of the "CKEditor" text editor plugin.
......@@ -44,7 +44,6 @@ function setUp() {
// Install the Filter module.
$this->installSchema('system', 'url_alias');
$this->enableModules(array('user', 'filter'));
// Create text format, associate CKEditor.
$filtered_html_format = entity_create('filter_format', array(
......
......@@ -24,7 +24,7 @@ class CommentDefaultFormatterCacheTagsTest extends EntityUnitTestBase {
*
* @var array
*/
public static $modules = array('entity_test', 'comment', 'menu_link');
public static $modules = array('entity_test', 'comment');
/**
* {@inheritdoc}
......
......@@ -29,6 +29,8 @@ class CommentStringIdEntitiesTest extends KernelTestBase {
'field_ui',
'entity',
'entity_test',
// EMAIL_MAX_LENGTH constant.
'system',
'text',
);
......
......@@ -71,6 +71,9 @@ public function testStorageMethods() {
// Ensure that the configuration entity can be loaded by UUID.
$entity_loaded_by_uuid = entity_load_by_uuid($entity_type->id(), $entity->uuid());
if (!$entity_loaded_by_uuid) {
$this->fail(sprintf("Failed to load '%s' entity ID '%s' by UUID '%s'.", $entity_type->id(), $entity->id(), $entity->uuid()));
}
// Compare UUIDs as the objects are not identical since
// $entity->enforceIsNew is FALSE and $entity_loaded_by_uuid->enforceIsNew
// is NULL.
......
......@@ -11,6 +11,7 @@
use Drupal\Core\Config\CachedStorage;
use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Tests CachedStorage operations.
......@@ -89,7 +90,7 @@ public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
// Use the regular database cache backend to aid testing.
$container->register('cache_factory', 'Drupal\Core\Cache\DatabaseBackendFactory')
->addArgument(Database::getConnection());
->addArgument(new Reference('database'));
}
}
......@@ -28,6 +28,11 @@ abstract class ConfigStorageTestBase extends DrupalUnitTestBase {
*/
protected $storage;
/**
* @var \Drupal\Core\Config\StorageInterface;
*/
protected $invalidStorage;
/**
* Tests storage CRUD operations.
*
......
......@@ -46,7 +46,7 @@ protected function delete($name) {
/**
* Tests the FileStorage::listAll method with a relative and absolute path.
*/
protected function testlistAll() {
public function testlistAll() {
$expected_files = array(
'core.extension',
'system.performance',
......
......@@ -32,7 +32,7 @@ class ViewsIntegrationTest extends ViewUnitTestBase {
*
* @var array
*/
public static $modules = array('dblog_test_views');
public static $modules = array('dblog', 'dblog_test_views');
/**
* {@inheritdoc}
......@@ -40,7 +40,6 @@ class ViewsIntegrationTest extends ViewUnitTestBase {
protected function setUp() {
parent::setUp();
$this->enableModules(array('system', 'dblog'));
$this->installSchema('dblog', array('watchdog'));
ViewTestData::createTestViews(get_class($this), array('dblog_test_views'));
......
......@@ -22,7 +22,7 @@ class EditorManagerTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'editor');
public static $modules = array('system', 'user', 'filter', 'editor');
/**
* The manager for text editor plugins.
......@@ -36,7 +36,6 @@ public function setUp() {
// Install the Filter module.
$this->installSchema('system', 'url_alias');
$this->enableModules(array('user', 'filter'));
// Add text formats.
$filtered_html_format = entity_create('filter_format', array(
......
......@@ -24,6 +24,11 @@
*/
class QuickEditIntegrationTest extends QuickEditTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('editor', 'editor_test');
/**
* The manager for editor plug-ins.
*
......@@ -65,9 +70,6 @@ public function setUp() {
// Install the Filter module.
$this->installSchema('system', 'url_alias');
// Enable the Text Editor and Text Editor Test module.
$this->enableModules(array('editor', 'editor_test'));
// Create a field.
$this->field_name = 'field_textarea';
$this->createFieldWithInstance(
......
......@@ -16,7 +16,7 @@
*/
class EntityDisplayTest extends DrupalUnitTestBase {
public static $modules = array('entity', 'field', 'entity_test', 'user', 'text', 'entity_test');
public static $modules = array('entity', 'field', 'entity_test', 'user', 'text', 'field_test', 'node', 'system');
protected function setUp() {
parent::setUp();
......@@ -137,8 +137,6 @@ public function testExtraFieldComponent() {
* Tests the behavior of a field component within an entity display object.
*/
public function testFieldComponent() {
$this->enableModules(array('field_test'));
$field_name = 'test_field';
// Create a field storage and an instance.
$field_storage = entity_create('field_storage_config', array(
......@@ -264,7 +262,6 @@ public function testBaseFieldComponent() {
* Tests renaming and deleting a bundle.
*/
public function testRenameDeleteBundle() {
$this->enableModules(array('field_test', 'node', 'system', 'text'));
$this->installEntitySchema('node');
// Create a node bundle, display and form display object.
......@@ -314,8 +311,6 @@ public function testRenameDeleteBundle() {
* Tests deleting field instance.
*/
public function testDeleteFieldInstance() {
$this->enableModules(array('field_test'));
$field_name = 'test_field';
// Create a field storage and an instance.
$field_storage = entity_create('field_storage_config', array(
......
......@@ -16,7 +16,7 @@
*/
class EntityFormDisplayTest extends DrupalUnitTestBase {
public static $modules = array('entity', 'field', 'entity_test', 'user', 'text');
public static $modules = array('entity', 'field', 'entity_test', 'field_test', 'user', 'text');
protected function setUp() {
parent::setUp();
......@@ -47,8 +47,6 @@ public function testEntityGetFromDisplay() {
* Tests the behavior of a field component within an EntityFormDisplay object.
*/
public function testFieldComponent() {
$this->enableModules(array('field_test'));
// Create a field storage and an instance.
$field_name = 'test_field';
$field_storage = entity_create('field_storage_config', array(
......@@ -177,8 +175,6 @@ public function testBaseFieldComponent() {
* Tests deleting field instance.
*/
public function testDeleteFieldInstance() {
$this->enableModules(array('field_sql_storage', 'field_test'));
$field_name = 'test_field';
// Create a field storage and an instance.
$field_storage = entity_create('field_storage_config', array(
......
......@@ -18,13 +18,6 @@
*/
class EmailItemTest extends FieldUnitTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('email');
public function setUp() {
parent::setUp();
......
......@@ -22,7 +22,7 @@ class FieldImportDeleteUninstallTest extends FieldUnitTestBase {
*
* @var array
*/
public static $modules = array('telephone', 'menu_link');
public static $modules = array('telephone');
public function setUp() {
parent::setUp();
......
......@@ -13,6 +13,17 @@
* @group file
*/
class ValidatorTest extends FileManagedUnitTestBase {
/**
* @var \Drupal\file\Entity\File
*/
protected $image;
/**
* @var \Drupal\file\Entity\File
*/
protected $non_image;
function setUp() {
parent::setUp();
......
......@@ -33,7 +33,7 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('entity', 'entity_test', 'entity_reference', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter', 'menu_link');
public static $modules = array('entity', 'entity_test', 'entity_reference', 'field', 'hal', 'language', 'rest', 'serialization', 'system', 'text', 'user', 'filter');
/**
* The mock serializer.
......
......@@ -21,7 +21,7 @@ class NodeLastChangedTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('entity', 'user', 'node', 'field', 'text', 'filter');
public static $modules = array('entity', 'user', 'node', 'field', 'system', 'text', 'filter');
public function setUp() {
parent::setUp();
......
......@@ -20,6 +20,11 @@
*/
class MetadataGeneratorTest extends QuickEditTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('quickedit_test');
/**
* The manager for editor plugins.
*
......@@ -124,8 +129,6 @@ public function testSimpleEntityType() {
public function testEditorWithCustomMetadata() {
$this->installSchema('system', 'url_alias');
// Enable edit_test module so that the WYSIWYG editor becomes available.
$this->enableModules(array('quickedit_test'));
$this->editorManager = $this->container->get('plugin.manager.quickedit.editor');
$this->editorSelector = new EditorSelector($this->editorManager, $this->container->get('plugin.manager.field.formatter'));
$this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
......
......@@ -23,6 +23,21 @@ class CrudTest extends DrupalUnitTestBase {
*/
public static $modules = array('entity_test', 'rdf', 'system');
/**
* @var string
*/
protected $prefix;
/**
* @var string
*/
protected $entity_type;
/**
* @var string
*/
protected $bundle;
public function setUp() {
parent::setUp();
$this->prefix = 'rdf.mapping';
......
......@@ -23,7 +23,7 @@ class EmailFieldRdfaTest extends FieldRdfaTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('email', 'text');
public static $modules = array('text');
public function setUp() {
parent::setUp();
......
......@@ -38,9 +38,9 @@ public function setUp() {
))->save();
// Set up test values.
$this->test_value = $this->randomMachineName();
$this->testValue = $this->randomMachineName();
$this->entity = entity_create('entity_test');
$this->entity->{$this->fieldName}->value = $this->test_value;
$this->entity->{$this->fieldName}->value = $this->testValue;
$this->entity->save();
$this->uri = $this->getAbsoluteUri($this->entity);
......@@ -51,7 +51,7 @@ public function setUp() {
*/
public function testDefaultFormatter() {
// Expected value is the output of the datatype callback, not the raw value.
$this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->test_value));
$this->assertFormatterRdfa(array('type'=>'text_default'), 'http://schema.org/interactionCount', array('value' => 'foo' . $this->testValue));
}
}
......
......@@ -50,7 +50,12 @@ abstract class FieldRdfaTestBase extends FieldUnitTestBase {
*
* @var array
*/
public static $modules = array('rdf', 'menu_link');
public static $modules = array('rdf');
/**
* @var string
*/
protected $testValue;
/**
* {@inheritdoc}
......
......@@ -24,7 +24,7 @@ class SystemMenuBlockTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'menu_link', 'block');
public static $modules = array('system', 'block');
/**
* Tests calculation of a system menu block's configuration dependencies.
......
......@@ -13,6 +13,7 @@
* Tests the APCu cache backend.
*
* @group Cache
* @requires extension apc
*/
class ApcuBackendUnitTest extends GenericCacheBackendUnitTestBase {
......@@ -33,14 +34,14 @@ protected function checkRequirements() {
}
protected function createCacheBackend($bin) {
$this->backend = new ApcuBackend($bin, $this->databasePrefix);
return $this->backend;
return new ApcuBackend($bin, $this->databasePrefix);
}
public function tearDown() {
$this->backend->removeBin();
foreach ($this->cachebackends as $bin => $cachebackend) {
$this->cachebackends[$bin]->removeBin();
}
parent::tearDown();
$this->backend = NULL;
}
}
......@@ -94,7 +94,7 @@ public function tearDownCacheBackend() {
* @return \Drupal\Core\Cache\CacheBackendInterface
* Cache backend to test.
*/
final function getCacheBackend($bin = null) {
protected function getCacheBackend($bin = null) {
if (!isset($bin)) {
$bin = $this->getTestBin();
}
......
......@@ -21,7 +21,7 @@ class SelectComplexTest extends DatabaseTestBase {
*
* @var array
*/
public static $modules = array('node_access_test', 'field');
public static $modules = array('system', 'user', 'node_access_test', 'field');
/**
* Tests simple JOIN statements.
......@@ -322,9 +322,7 @@ function testJoinTwice() {
* Tests that we can join on a query.
*/
function testJoinSubquery() {
$this->enableModules(array('system'), FALSE);
$this->installSchema('system', 'sequences');
$this->enableModules(array('field', 'user'));
$account = entity_create('user', array(
'name' => $this->randomMachineName(),
......
......@@ -39,7 +39,7 @@ class: Drupal\Core\Cache\MemoryBackendFactory
file_put_contents($this->siteDirectory . '/services.yml', $doc);
// Rebuild the container.
$this->kernel->rebuildContainer();
$this->container->get('kernel')->rebuildContainer();
$this->assertTrue($this->container->has('site.service.yml'));
$this->assertIdentical(get_class($this->container->get('cache.backend.database')), 'Drupal\Core\Cache\MemoryBackendFactory');
......
......@@ -22,7 +22,7 @@ class ConfigEntityQueryTest extends DrupalUnitTestBase {
*
* @var array
*/
static $modules = array('config_test');
static $modules = array('entity', 'config_test');
/**
* Stores the search results for alter comparison.
......@@ -49,7 +49,6 @@ protected function setUp() {
parent::setUp();
$this->entities = array();
$this->enableModules(array('entity'), TRUE);
$this->factory = $this->container->get('entity.query');
// These two are here to make sure that matchArray needs to go over several
......@@ -346,7 +345,7 @@ public function testConfigEntityQuery() {
/**
* Tests count query.
*/
protected function testCount() {
public function testCount() {
// Test count on no conditions.
$count = $this->factory->get('config_query_test')
->count()
......@@ -372,7 +371,7 @@ protected function testCount() {
/**
* Tests sorting and range on config entity queries.
*/
protected function testSortRange() {
public function testSortRange() {
// Sort by simple ascending/descending.
$this->queryResults = $this->factory->get('config_query_test')
->sort('number', 'DESC')
......@@ -428,7 +427,7 @@ protected function testSortRange() {
/**
* Tests dotted path matching.
*/
protected function testDotted() {
public function testDotted() {
$this->queryResults = $this->factory->get('config_query_test')
->condition('array.level1.*', 1)
->execute();
......
......@@ -119,7 +119,7 @@ function testEntityTranslationAccess() {
/**
* Tests hook invocations.
*/
protected function testHooks() {
public function testHooks() {
$state = $this->container->get('state');
$entity = entity_create('entity_test', array(
'name' => 'test',
......
......@@ -28,13 +28,6 @@ class EntityBundleFieldTest extends EntityUnitTestBase {
*/
protected $database;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('menu_link');
/**
* {@inheritdoc}
*/
......
......@@ -135,7 +135,6 @@ public function testBlockHooks() {
*/
public function testCommentHooks() {
$account = $this->createUser();
$this->enableModules(array('entity', 'filter'));
entity_create('node_type', array(
'type' => 'article',
'name' => 'Article',
......
......@@ -34,6 +34,21 @@ class EntityFieldTest extends EntityUnitTestBase {
*/
public static $modules = array('filter', 'text', 'node', 'user');
/**
* @var string
*/
protected $entity_name;
/**
* @var \Drupal\user\Entity\User
*/
protected $entity_user;
/**
* @var string
*/
protected $entity_field_text;
public function setUp() {
parent::setUp();
......@@ -230,9 +245,9 @@ protected function assertReadWrite($entity_type) {
// Tests adding a value to a field item list.
$entity->name[] = 'Another name';
$this->assertEqual($entity->name[1]->value == 'Another name', format_string('%entity_type: List item added via [].', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->name[1]->value, 'Another name', format_string('%entity_type: List item added via [].', array('%entity_type' => $entity_type)));
$entity->name[2]->value = 'Third name';
$this->assertEqual($entity->name[2]->value == 'Third name', format_string('%entity_type: List item added by a accessing not yet created item.', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->name[2]->value, 'Third name', format_string('%entity_type: List item added by a accessing not yet created item.', array('%entity_type' => $entity_type)));
// Test removing and empty-ing list items.
$this->assertEqual(count($entity->name), 3, format_string('%entity_type: List has 3 items.', array('%entity_type' => $entity_type)));
......
......@@ -36,6 +36,13 @@ abstract class EntityLanguageTestBase extends EntityUnitTestBase {
*/
protected $field_name;
/**
* Test field instances, keyed by entity type.
*
* @var array
*/
protected $instance;
/**
* The untranslatable test field name.
*
......
......@@ -373,7 +373,7 @@ function testSort() {
/**
* Test tablesort().
*/
protected function testTableSort() {
public function testTableSort() {
// While ordering on bundles do not give us a definite order, we can still
// assert that all entities from one bundle are after the other as the
// order dictates.
......@@ -422,7 +422,7 @@ protected function testTableSort() {
/**
* Test that count queries are separated across entity types.
*/
protected function testCount() {
public function testCount() {
// Create a field with the same name in a different entity type.
$field_name = $this->figures;
$field_storage = entity_create('field_storage_config', array(
......
......@@ -21,6 +21,21 @@ class EntityValidationTest extends EntityUnitTestBase {
*/
public static $modules = array('filter', 'text');
/**
* @var string
*/
protected $entity_name;
/**
* @var \Drupal\user\Entity\User
*/
protected $entity_user;
/**
* @var string
*/
protected $entity_field_text;
/**
* {@inheritdoc}
*/
......
......@@ -36,6 +36,11 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
*/
protected $field_name;
/**
* @var int
*/
protected $field_cardinality;
/**
* A field storage to use in this class.
*
......@@ -50,6 +55,11 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
*/
protected $instance;
/**
* @var string
*/
protected $table;
/**
* Name of the revision table of the field.
*
......
......@@ -18,6 +18,11 @@
*/
class ModuleHandlerTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = array('system');
/**
* {@inheritdoc}
*/
......
......@@ -23,7 +23,7 @@ class ThemeHandlerTest extends DrupalUnitTestBase {
*
* @var array
*/
public static $modules = array('system', 'menu_link');
public static $modules = array('system');
public function containerBuild(ContainerBuilder $container) {
parent::containerBuild($container);
......
......@@ -13,6 +13,22 @@
* @group File
*/
class NameMungingTest extends FileTestBase {
/**
* @var string
*/
protected $bad_extension;
/**
* @var string
*/
protected $name;
/**
* @var string
*/
protected $name_with_uc_ext;
function setUp() {
parent::setUp();
$this->bad_extension = 'php';
......
......@@ -21,6 +21,11 @@ class ScanDirectoryTest extends FileTestBase {