diff --git a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php b/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php deleted file mode 100644 index 85b3d394f3d78b75bfec969fc6dd10466bfe3a2f..0000000000000000000000000000000000000000 --- a/core/modules/field/lib/Drupal/field/Tests/EntityPropertiesTest.php +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -/** - * @file - * Definition of Drupal\field\Tests\EntityPropertiesTest. - */ - -namespace Drupal\field\Tests; - -/** - * Tests entity properties. - */ -class EntityPropertiesTest extends FieldTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('field_test'); - - public static function getInfo() { - return array( - 'name' => 'Entity properties', - 'description' => 'Tests entity properties.', - 'group' => 'Entity API', - ); - } - - /** - * Tests label key and label callback of an entity. - */ - function testEntityLabel() { - $entity_types = array( - 'test_entity_no_label', - 'test_entity_label', - 'test_entity_label_callback', - ); - - // @todo Remove once test_entity entity has been merged with entity_test. - $values = array( - 'ftlabel' => $this->randomName(), - ); - - foreach ($entity_types as $entity_type) { - $entity = entity_create($entity_type, $values); - $label = $entity->label(); - - switch ($entity_type) { - case 'test_entity_no_label': - $this->assertFalse($label, 'Entity with no label property or callback returned FALSE.'); - break; - - case 'test_entity_label': - $this->assertEqual($label, $entity->ftlabel, 'Entity with label key returned correct label.'); - break; - - case 'test_entity_label_callback': - $this->assertEqual($label, 'label callback ' . $entity->ftlabel, 'Entity with label callback returned correct label.'); - break; - } - } - } -} diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module index 03094dd532f15a19d179756712607aab13fe4fc0..4ecd1a95c68d7753f86f79bb2f92926269cbe799 100644 --- a/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -186,23 +186,6 @@ function field_test_field_create_field($field) { field_test_memorize(__FUNCTION__, $args); } -/** - * Entity label callback. - * - * @param $entity_type - * The entity type. - * @param $entity - * The entity object. - * @param $langcocde - * (optional) The langcode. - * - * @return - * The label of the entity prefixed with "label callback". - */ -function field_test_entity_label_callback($entity_type, $entity, $langcode = NULL) { - return 'label callback ' . $entity->ftlabel; -} - /** * Implements hook_field_attach_view_alter(). */ diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelCallbackTestEntity.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelCallbackTestEntity.php deleted file mode 100644 index cddde9e5998db41081ad19e58d928cdbf7ea5312..0000000000000000000000000000000000000000 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelCallbackTestEntity.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\field_test\Plugin\Core\Entity\LabelCallbackTestEntity. - */ - -namespace Drupal\field_test\Plugin\Core\Entity; - -use Drupal\Core\Annotation\Plugin; -use Drupal\Core\Annotation\Translation; - -/** - * Test entity class. - * - * @Plugin( - * id = "test_entity_label_callback", - * label = @Translation("Test entity label callback"), - * module = "field_test", - * controller_class = "Drupal\field_test\TestEntityController", - * field_cache = FALSE, - * base_table = "test_entity", - * revision_table = "test_entity_revision", - * label_callback = "field_test_entity_label_callback", - * fieldable = TRUE, - * entity_keys = { - * "id" = "ftid", - * "revision" = "ftvid", - * "bundle" = "fttype" - * } - * ) - */ -class LabelCallbackTestEntity extends TestEntity { - -} diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelTestEntity.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelTestEntity.php deleted file mode 100644 index 7e2bdb25b047e72488d9214960ff63802b7c284e..0000000000000000000000000000000000000000 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/LabelTestEntity.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\field_test\Plugin\Core\Entity\LabelTestEntity. - */ - -namespace Drupal\field_test\Plugin\Core\Entity; - -use Drupal\Core\Annotation\Plugin; -use Drupal\Core\Annotation\Translation; - -/** - * Test entity class. - * - * @Plugin( - * id = "test_entity_label", - * label = @Translation("Test Entity label"), - * module = "field_test", - * controller_class = "Drupal\field_test\TestEntityController", - * form_controller_class = { - * "default" = "Drupal\field_test\TestEntityFormController" - * }, - * field_cache = FALSE, - * base_table = "test_entity", - * revision_table = "test_entity_revision", - * fieldable = TRUE, - * entity_keys = { - * "id" = "ftid", - * "revision" = "ftvid", - * "bundle" = "fttype", - * "label" = "ftlabel" - * } - * ) - */ -class LabelTestEntity extends TestEntity { - -} diff --git a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/NoLabelTestEntity.php b/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/NoLabelTestEntity.php deleted file mode 100644 index 4802e5e0090842f97ad810e78b061a40c9a5619d..0000000000000000000000000000000000000000 --- a/core/modules/field/tests/modules/field_test/lib/Drupal/field_test/Plugin/Core/Entity/NoLabelTestEntity.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/** - * @file - * Contains Drupal\field_test\Plugin\Core\Entity\NoLabelTestEntity. - */ - -namespace Drupal\field_test\Plugin\Core\Entity; - -use Drupal\Core\Annotation\Plugin; -use Drupal\Core\Annotation\Translation; - -/** - * Test entity class. - * - * @Plugin( - * id = "test_entity_no_label", - * label = @Translation("Test Entity without label"), - * module = "field_test", - * controller_class = "Drupal\field_test\TestEntityController", - * form_controller_class = { - * "default" = "Drupal\field_test\TestEntityFormController" - * }, - * field_cache = FALSE, - * base_table = "test_entity", - * revision_table = "test_entity_revision", - * fieldable = TRUE, - * entity_keys = { - * "id" = "ftid", - * "revision" = "ftvid", - * "bundle" = "fttype" - * } - * ) - */ -class NoLabelTestEntity extends TestEntity { - -} diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php index 74bae2fad87188d16f583ca73dacecf3ce1ceffa..6b0379fc15fb911881640cb036ca9bbf489a86b6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityAccessTest.php @@ -9,14 +9,15 @@ use Drupal\Core\Language\Language; use Drupal\Core\TypedData\AccessibleInterface; -use Drupal\simpletest\WebTestBase; use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; /** * Tests the entity access controller. */ -class EntityAccessTest extends WebTestBase { +class EntityAccessTest extends EntityUnitBaseTest { + + public static $modules = array('language', 'locale'); public static function getInfo() { return array( @@ -26,12 +27,20 @@ public static function getInfo() { ); } - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test'); + function setUp() { + parent::setUp(); + $this->installSchema('user', array('role_permission', 'users_roles')); + $this->installSchema('system', array('variable', 'url_alias')); + $this->installSchema('language', 'language'); + + // Create the default languages. + $default_language = language_save(language_default()); + $languages = language_default_locked_languages($default_language->weight); + foreach ($languages as $language) { + language_save($language); + } + + } /** * Asserts entity access correctly grants or denies access. @@ -39,7 +48,7 @@ public static function getInfo() { function assertEntityAccess($ops, AccessibleInterface $object, User $account = NULL) { foreach ($ops as $op => $result) { $message = format_string("Entity access returns @result with operation '@op'.", array( - '@result' => isset($result) ? 'null' : ($result ? 'true' : 'false'), + '@result' => !isset($result) ? 'null' : ($result ? 'true' : 'false'), '@op' => $op, )); @@ -52,24 +61,22 @@ function assertEntityAccess($ops, AccessibleInterface $object, User $account = N */ function testEntityAccess() { // Set up a non-admin user that is allowed to view test entities. - $user = $this->drupalCreateUser(array('view test entity')); - $this->drupalLogin($user); - + global $user; + $user = $this->createUser(array('uid' => 2), array('view test entity')); $entity = entity_create('entity_test', array( 'name' => 'test', )); - $entity->save(); - // The current user is allowed to view, create, update and delete entities. + // The current user is allowed to view entities. $this->assertEntityAccess(array( - 'create' => TRUE, - 'update' => TRUE, - 'delete' => TRUE, + 'create' => FALSE, + 'update' => FALSE, + 'delete' => FALSE, 'view' => TRUE, ), $entity); // The custom user is not allowed to perform any operation on test entities. - $custom_user = $this->drupalCreateUser(); + $custom_user = $this->createUser(); $this->assertEntityAccess(array( 'create' => FALSE, 'update' => FALSE, @@ -100,13 +107,10 @@ function testEntityAccessDefaultController() { * Ensures entity access for entity translations is properly working. */ function testEntityTranslationAccess() { - // Enable translations for the test entity type. - variable_set('entity_test_translation', TRUE); - module_enable(array('locale')); // Set up a non-admin user that is allowed to view test entity translations. - $user = $this->drupalCreateUser(array('view test entity translations')); - $this->drupalLogin($user); + global $user; + $user = $this->createUser(array('uid' => 2), array('view test entity translations')); // Create two test languages. foreach (array('foo', 'bar') as $langcode) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php index 4c428cca27273d2eab0518aaa42816d472683d62..30c502551145d62e0da7222dccbaf35e31dc5f99 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php @@ -7,19 +7,12 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\WebTestBase; +use Drupal\user\Plugin\Core\Entity\User; /** * Tests the basic Entity API. */ -class EntityApiTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test'); +class EntityApiTest extends EntityUnitBaseTest { public static function getInfo() { return array( @@ -29,15 +22,26 @@ public static function getInfo() { ); } + public function setUp() { + parent::setUp(); + $this->installSchema('entity_test', array( + 'entity_test_mul', + 'entity_test_mul_property_data', + 'entity_test_rev', + 'entity_test_rev_revision', + 'entity_test_mulrev', + 'entity_test_mulrev_property_data', + 'entity_test_mulrev_property_revision' + )); + } + /** * Tests basic CRUD functionality of the Entity API. */ public function testCRUD() { - $user1 = $this->drupalCreateUser(); - // All entity variations have to have the same results. foreach (entity_test_entity_types() as $entity_type) { - $this->assertCRUD($entity_type, $user1); + $this->assertCRUD($entity_type, $this->createUser()); } } @@ -49,7 +53,7 @@ public function testCRUD() { * @param \Drupal\user\Plugin\Core\Entity\User $user1 * The user to run the tests with. */ - protected function assertCRUD($entity_type, \Drupal\user\Plugin\Core\Entity\User $user1) { + protected function assertCRUD($entity_type, User $user1) { // Create some test entities. $entity = entity_create($entity_type, array('name' => 'test', 'user_id' => $user1->uid)); $entity->save(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 7668112d40d1ad7498d4898306cee0d06233ae1b..a1f2dc9071dd2f5510798aa7ee1adde3c37b65d2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -7,7 +7,6 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\WebTestBase; use Drupal\Core\Database\Database; /** @@ -22,14 +21,14 @@ * As well as all type-specific hooks, like hook_node_insert(), * hook_comment_update(), etc. */ -class EntityCrudHookTest extends WebTestBase { +class EntityCrudHookTest extends EntityUnitBaseTest { /** * Modules to enable. * * @var array */ - public static $modules = array('entity_crud_hook_test', 'taxonomy', 'block_test', 'block', 'comment', 'file', 'entity_test'); + public static $modules = array('block', 'block_test', 'entity_crud_hook_test', 'file', 'taxonomy', 'node', 'comment'); protected $ids = array(); @@ -41,6 +40,13 @@ public static function getInfo() { ); } + public function setUp() { + parent::setUp(); + $this->installSchema('user', array('users_roles', 'users_data')); + $this->installSchema('node', array('node', 'node_revision', 'node_type', 'node_access')); + $this->installSchema('comment', array('comment', 'node_comment_statistics')); + } + /** * Checks the order of CRUD hook execution messages. * @@ -124,8 +130,10 @@ public function testBlockHooks() { * Tests hook invocations for CRUD operations on comments. */ public function testCommentHooks() { + $account = $this->createUser(); + $node = entity_create('node', array( - 'uid' => 1, + 'uid' => $account->uid, 'type' => 'article', 'title' => 'Test node', 'status' => 1, @@ -145,7 +153,7 @@ public function testCommentHooks() { 'cid' => NULL, 'pid' => 0, 'nid' => $nid, - 'uid' => 1, + 'uid' => $account->uid, 'subject' => 'Test comment', 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, @@ -202,6 +210,7 @@ public function testCommentHooks() { * Tests hook invocations for CRUD operations on files. */ public function testFileHooks() { + $this->installSchema('file', array('file_managed', 'file_usage')); $url = 'public://entity_crud_hook_test.file'; file_put_contents($url, 'Test test test'); $file = entity_create('file', array( @@ -264,8 +273,10 @@ public function testFileHooks() { * Tests hook invocations for CRUD operations on nodes. */ public function testNodeHooks() { + $account = $this->createUser(); + $node = entity_create('node', array( - 'uid' => 1, + 'uid' => $account->id(), 'type' => 'article', 'title' => 'Test node', 'status' => 1, @@ -326,6 +337,8 @@ public function testNodeHooks() { * Tests hook invocations for CRUD operations on taxonomy terms. */ public function testTaxonomyTermHooks() { + $this->installSchema('taxonomy', array('taxonomy_term_data', 'taxonomy_term_hierarchy')); + $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Test vocabulary', 'vid' => 'test', @@ -393,6 +406,8 @@ public function testTaxonomyTermHooks() { * Tests hook invocations for CRUD operations on taxonomy vocabularies. */ public function testTaxonomyVocabularyHooks() { + $this->installSchema('taxonomy', array('taxonomy_term_data', 'taxonomy_term_hierarchy')); + $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Test vocabulary', 'vid' => 'test', diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index e3ad6fe746e5abd868531e6e8281a762a74c0618..1fad7983b48efbfb443e58bba17b82251584d947 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -11,19 +11,18 @@ use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Entity\Field\FieldItemInterface; use Drupal\Core\TypedData\TypedDataInterface; -use Drupal\simpletest\WebTestBase; /** * Tests Entity API base functionality. */ -class EntityFieldTest extends WebTestBase { +class EntityFieldTest extends EntityUnitBaseTest { /** * Modules to enable. * * @var array */ - public static $modules = array('entity_test'); + public static $modules = array('filter', 'text', 'node'); public static function getInfo() { return array( @@ -33,6 +32,27 @@ public static function getInfo() { ); } + public function setUp() { + parent::setUp(); + $this->installSchema('user', array('users_roles', 'users_data')); + $this->installSchema('node', array('node', 'node_revision', 'node_type', 'node_access')); + $this->installSchema('entity_test', array( + 'entity_test_mul', + 'entity_test_mul_property_data', + 'entity_test_rev', + 'entity_test_rev_revision', + 'entity_test_mulrev', + 'entity_test_mulrev_property_data', + 'entity_test_mulrev_property_revision' + )); + + // Create the test field. + entity_test_install(); + + // Install required default configuration for filter module. + $this->installConfig(array('system', 'filter')); + } + /** * Creates a test entity. * @@ -40,7 +60,7 @@ public static function getInfo() { */ protected function createTestEntity($entity_type) { $this->entity_name = $this->randomName(); - $this->entity_user = $this->drupalCreateUser(); + $this->entity_user = $this->createUser(); $this->entity_field_text = $this->randomName(); // Pass in the value of the name field when creating. With the user @@ -100,13 +120,13 @@ protected function assertReadWrite($entity_type) { $this->assertEqual($this->entity_user->name, $entity->user_id->entity->name, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type))); // Change the assigned user by entity. - $new_user = $this->drupalCreateUser(); + $new_user = $this->createUser(); $entity->user_id->entity = $new_user; $this->assertEqual($new_user->uid, $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type))); $this->assertEqual($new_user->name, $entity->user_id->entity->name, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type))); // Change the assigned user by id. - $new_user = $this->drupalCreateUser(); + $new_user = $this->createUser(); $entity->user_id->target_id = $new_user->uid; $this->assertEqual($new_user->uid, $entity->user_id->target_id, format_string('%entity_type: Updated user id can be read.', array('%entity_type' => $entity_type))); $this->assertEqual($new_user->name, $entity->user_id->entity->name, format_string('%entity_type: Updated user name value can be read.', array('%entity_type' => $entity_type))); @@ -185,7 +205,7 @@ protected function assertReadWrite($entity_type) { // Test creating the entity by passing in plain values. $this->entity_name = $this->randomName(); $name_item[0]['value'] = $this->entity_name; - $this->entity_user = $this->drupalCreateUser(); + $this->entity_user = $this->createUser(); $user_item[0]['target_id'] = $this->entity_user->uid; $this->entity_field_text = $this->randomName(); $text_item[0]['value'] = $this->entity_field_text; @@ -523,7 +543,14 @@ public function testEntityConstraintValidation() { $this->assertEqual($violations->count(), 0); // Test validating an entity of the wrong type. - $node = $this->drupalCreateNode(array('type' => 'page')); + $user = $this->createUser(); + $user->save(); + $node = entity_create('node', array( + 'type' => 'page', + 'uid' => $user->id(), + )); + // @todo: EntityWrapper can only handle entities with an id. + $node->save(); $wrapped_entity->setValue($node); $violations = $wrapped_entity->validate(); $this->assertEqual($violations->count(), 1); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e2a93b071992fe055ddb22b9ca5cf2e26d5ae265 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityLabelTest.php @@ -0,0 +1,55 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Entity\EntityLabelTest. + */ + +namespace Drupal\system\Tests\Entity; + +/** + * Tests entity properties. + */ +class EntityLabelTest extends EntityUnitBaseTest { + + public static function getInfo() { + return array( + 'name' => 'Entity label', + 'description' => 'Tests entity labels.', + 'group' => 'Entity API', + ); + } + + /** + * Tests label key and label callback of an entity. + */ + function testEntityLabel() { + $entity_types = array( + 'entity_test_no_label', + 'entity_test_label', + 'entity_test_label_callback', + ); + + $values = array( + 'name' => $this->randomName(), + ); + foreach ($entity_types as $entity_type) { + $entity = entity_create($entity_type, $values); + $label = $entity->label(); + + switch ($entity_type) { + case 'entity_test_no_label': + $this->assertFalse($label, 'Entity with no label property or callback returned FALSE.'); + break; + + case 'entity_test_label': + $this->assertEqual($label, $entity->name->value, 'Entity with label key returned correct label.'); + break; + + case 'entity_test_label_callback': + $this->assertEqual($label, 'label callback ' . $entity->name->value, 'Entity with label callback returned correct label.'); + break; + } + } + } +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php index 8d5fa811ecc8d6eaa89986005e88cfe50a43be52..d5a9b988cef48196488104dda33737cdcac12f23 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryRelationshipTest.php @@ -7,19 +7,17 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\WebTestBase; - /** * Tests Entity Query API relationship functionality. */ -class EntityQueryRelationshipTest extends WebTestBase { +class EntityQueryRelationshipTest extends EntityUnitBaseTest { /** * Modules to enable. * * @var array */ - public static $modules = array('entity_test', 'taxonomy'); + public static $modules = array('taxonomy', 'options'); /** * @var \Drupal\field_sql_storage\Entity\QueryFactory @@ -69,8 +67,11 @@ public static function getInfo() { ); } - protected function setUp() { + public function setUp() { parent::setUp(); + + $this->installSchema('taxonomy', array('taxonomy_term_data', 'taxonomy_term_hierarchy')); + // We want a taxonomy term reference field. It needs a vocabulary, terms, // a field and an instance. First, create the vocabulary. $vocabulary = entity_create('taxonomy_vocabulary', array( @@ -100,7 +101,7 @@ protected function setUp() { )); $term->save(); $this->terms[] = $term; - $this->accounts[] = $this->drupalCreateUser(); + $this->accounts[] = $this->createUser(); } // Create three entity_test entities, the 0th entity will point to the // 0th account and 0th term, the 1st and 2nd entity will point to the diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index 1882e6f8cea02729d9bb6fefc9e6464cbf4f0e65..a2ece4a8e78f2a6f35b8a984dc87519827c2e425 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -7,19 +7,17 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\WebTestBase; - /** * Tests the basic Entity API. */ -class EntityQueryTest extends WebTestBase { +class EntityQueryTest extends EntityUnitBaseTest { /** * Modules to enable. * * @var array */ - public static $modules = array('field', 'field_sql_storage', 'field_test', 'text'); + public static $modules = array('field_test'); /** * @var array @@ -55,6 +53,7 @@ public static function getInfo() { function setUp() { parent::setUp(); + $this->installSchema('field_test', array('test_entity', 'test_entity_revision', 'test_entity_bundle')); $figures = drupal_strtolower($this->randomName()); $greetings = drupal_strtolower($this->randomName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index 63098bde855b7d91177f517bcfe2e00568df5f54..40fbd15fd61e8470df65c8fa25efcf958091e449 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -10,22 +10,16 @@ use InvalidArgumentException; use Drupal\Core\Language\Language; -use Drupal\simpletest\WebTestBase; /** * Tests entity translation. */ -class EntityTranslationTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test', 'locale'); +class EntityTranslationTest extends EntityUnitBaseTest { protected $langcodes; + public static $modules = array('language', 'locale'); + public static function getInfo() { return array( 'name' => 'Entity Translation', @@ -36,6 +30,21 @@ public static function getInfo() { function setUp() { parent::setUp(); + $this->installSchema('system', 'variable'); + $this->installSchema('language', 'language'); + $this->installSchema('entity_test', array( + 'entity_test_mul', + 'entity_test_mul_property_data', + 'entity_test_rev', + 'entity_test_rev_revision', + 'entity_test_mulrev', + 'entity_test_mulrev_property_data', + 'entity_test_mulrev_property_revision', + )); + + // Create the test field. + entity_test_install(); + // Enable translations for the test entity type. state()->set('entity_test.translation', TRUE); @@ -61,6 +70,13 @@ function setUp() { $this->instance[$entity_type] = field_read_instance($entity_type, $this->field_name, $entity_type); } + // Create the default languages. + $default_language = language_save(language_default()); + $languages = language_default_locked_languages($default_language->weight); + foreach ($languages as $language) { + language_save($language); + } + // Create test languages. $this->langcodes = array(); for ($i = 0; $i < 3; ++$i) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php index a4e2d4e8edbca832f449f76b0c4d162baf315cb9..5110134549ebd6e244bb382aa788acd1ba2759d6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php @@ -8,19 +8,11 @@ namespace Drupal\system\Tests\Entity; use Drupal\Component\Uuid\Uuid; -use Drupal\simpletest\WebTestBase; /** * Tests creation, saving, and loading of entity UUIDs. */ -class EntityUUIDTest extends WebTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = array('entity_test'); +class EntityUUIDTest extends EntityUnitBaseTest { public static function getInfo() { return array( @@ -30,6 +22,20 @@ public static function getInfo() { ); } + public function setUp() { + parent::setUp(); + + $this->installSchema('entity_test', array( + 'entity_test_mul', + 'entity_test_mul_property_data', + 'entity_test_rev', + 'entity_test_rev_revision', + 'entity_test_mulrev', + 'entity_test_mulrev_property_data', + 'entity_test_mulrev_property_revision', + )); + } + /** * Tests UUID generation in entity CRUD operations. */ diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitBaseTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitBaseTest.php new file mode 100644 index 0000000000000000000000000000000000000000..274724cc4fc1f715511518aab973085991ff6c92 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUnitBaseTest.php @@ -0,0 +1,66 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Entity\EntityApiTest. + */ + +namespace Drupal\system\Tests\Entity; + +use Drupal\simpletest\DrupalUnitTestBase; + +/** + * Defines an abstract test base for entity unit tests. + */ +abstract class EntityUnitBaseTest extends DrupalUnitTestBase { + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('user', 'system', 'field', 'text', 'field_sql_storage', 'entity_test'); + + public function setUp() { + parent::setUp(); + $this->installSchema('user', 'users'); + $this->installSchema('system', 'sequences'); + $this->installSchema('field', array('field_config', 'field_config_instance')); + $this->installSchema('entity_test', 'entity_test'); + } + + /** + * 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. The + * role_permission and users_roles tables must be installed before this can + * be used. + * + * @return \Drupal\user\Plugin\Core\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 = entity_create('user_role', array( + 'id' => strtolower($this->randomName(8)), + 'label' => $this->randomName(8), + )); + $role->save(); + user_role_grant_permissions($role->id(), $permissions); + $values['roles'][$role->id()] = $role->id(); + } + + $account = entity_create('user', $values + array( + 'name' => $this->randomName(), + 'status' => 1, + )); + $account->enforceIsNew(); + $account->save(); + return $account; + } + +} diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php index 487fc43d11ef96113b7fa8ed0cfbbbb29a84e1f5..43ab362ba06d151bb9f8fc375d95f901084b59ba 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUriTest.php @@ -7,19 +7,10 @@ namespace Drupal\system\Tests\Entity; -use Drupal\simpletest\DrupalUnitTestBase; - /** * Tests the basic Entity API. */ -class EntityUriTest extends DrupalUnitTestBase { - - /** - * Modules to load. - * - * @var array - */ - public static $modules = array('field', 'field_sql_storage', 'system', 'text', 'entity_test'); +class EntityUriTest extends EntityUnitBaseTest { public static function getInfo() { return array( @@ -29,12 +20,9 @@ public static function getInfo() { ); } - protected function setUp() { + public function setUp() { parent::setUp(); - $this->installSchema('system', array('variable', 'url_alias')); - $this->installSchema('field', array('field_config', 'field_config_instance')); - $this->installSchema('entity_test', array('entity_test')); } /** diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 2752729cc58114ba87538d2d04c28e0b62a38d18..e36e47b081225fbc0e7bcda7dc2ad4a8bb69e644 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -251,3 +251,20 @@ function entity_test_entity_test_insert($entity) { throw new Exception("Test exception rollback."); } } + +/** + * Entity label callback. + * + * @param $entity_type + * The entity type. + * @param $entity + * The entity object. + * @param $langcocde + * (optional) The langcode. + * + * @return + * The label of the entity prefixed with "label callback". + */ +function entity_test_label_callback($entity_type, $entity, $langcode = NULL) { + return 'label callback ' . $entity->name->value; +} diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php index 1c8979ee5b91b3ac0547139059093acd83e39323..6396ec3831a4e80dc914823aefb5aec6cda7dacb 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php @@ -79,6 +79,12 @@ protected function init() { * Overrides Drupal\entity\Entity::label(). */ public function label($langcode = LANGUAGE_DEFAULT) { - return $this->getTranslation($langcode)->name->value; + $info = $this->entityInfo(); + if (isset($info['entity_keys']['label']) && $info['entity_keys']['label'] == 'name') { + return $this->getTranslation($langcode)->name->value; + } + else { + return parent::label($langcode); + } } } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabel.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabel.php new file mode 100644 index 0000000000000000000000000000000000000000..6f2bb6dba0bdbe138983de0345e22262cbf7b405 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabel.php @@ -0,0 +1,30 @@ +<?php + +/** + * @file + * Contains \Drupal\entity_test\Plugin\Core\Entity\EntityTestLabel. + */ + +namespace Drupal\entity_test\Plugin\Core\Entity; + +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; + +/** + * Test entity class. + * + * @Plugin( + * id = "entity_test_label", + * label = @Translation("Entity Test label"), + * module = "entity_test", + * controller_class = "Drupal\entity_test\EntityTestStorageController", + * base_table = "entity_test", + * entity_keys = { + * "id" = "id", + * "label" = "name" + * } + * ) + */ +class EntityTestLabel extends EntityTest { + +} diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabelCallback.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabelCallback.php new file mode 100644 index 0000000000000000000000000000000000000000..a98bb34942efba2257d764968a33d569b1f3bf74 --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestLabelCallback.php @@ -0,0 +1,33 @@ +<?php + +/** + * @file + * Contains \Drupal\entity_test\Plugin\Core\Entity\EntityTestLabelCallback. + */ + +namespace Drupal\entity_test\Plugin\Core\Entity; + +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; + +/** + * Test entity class. + * + * @Plugin( + * id = "entity_test_label_callback", + * label = @Translation("Entity test label callback"), + * module = "entity_test", + * controller_class = "Drupal\entity_test\EntityTestStorageController", + * field_cache = FALSE, + * base_table = "entity_test", + * revision_table = "entity_test_revision", + * label_callback = "entity_test_label_callback", + * fieldable = TRUE, + * entity_keys = { + * "id" = "id" + * } + * ) + */ +class EntityTestLabelCallback extends EntityTest { + +} diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestNoLabel.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestNoLabel.php new file mode 100644 index 0000000000000000000000000000000000000000..9c41220f63131ac9bef3d81d433ad0591db335ff --- /dev/null +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestNoLabel.php @@ -0,0 +1,30 @@ +<?php + +/** + * @file + * Contains \Drupal\entity_test\Plugin\Core\Entity\EntityTestNoLabel. + */ + +namespace Drupal\entity_test\Plugin\Core\Entity; + +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Annotation\Translation; + +/** + * Test entity class. + * + * @Plugin( + * id = "entity_test_no_label", + * label = @Translation("Entity Test without label"), + * module = "entity_test", + * controller_class = "Drupal\entity_test\EntityTestStorageController", + * field_cache = FALSE, + * base_table = "entity_test", + * entity_keys = { + * "id" = "ftid", + * } + * ) + */ +class EntityTestNoLabel extends EntityTest { + +}