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 89573b4..f706861 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityApiTest.php @@ -37,7 +37,7 @@ public function testCRUD() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testCRUDHelper($entity_type, $user1); + $this->assertCRUD($entity_type, $user1); } } @@ -49,7 +49,7 @@ public function testCRUD() { * @param \Drupal\user\Plugin\Core\Entity\User $user1 * The user to run the tests with. */ - protected function testCRUDHelper($entity_type, \Drupal\user\Plugin\Core\Entity\User $user1) { + protected function assertCRUD($entity_type, \Drupal\user\Plugin\Core\Entity\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/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 4d82753..e3d483b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -61,7 +61,7 @@ protected function createTestEntity($entity_type) { public function testReadWrite() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testReadWriteHelper($entity_type); + $this->assertReadWrite($entity_type); } } @@ -71,7 +71,7 @@ public function testReadWrite() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testReadWriteHelper($entity_type) { + protected function assertReadWrite($entity_type) { $entity = $this->createTestEntity($entity_type); // Access the name field. @@ -270,7 +270,7 @@ protected function testReadWriteHelper($entity_type) { public function testSave() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testSaveHelper($entity_type); + $this->assertSave($entity_type); } } @@ -280,7 +280,7 @@ public function testSave() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testSaveHelper($entity_type) { + protected function assertSave($entity_type) { $entity = $this->createTestEntity($entity_type); $entity->save(); $this->assertTrue((bool) $entity->id(), $entity_type . ': Entity has received an id.'); @@ -304,7 +304,7 @@ protected function testSaveHelper($entity_type) { public function testIntrospection() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testIntrospectionHelper($entity_type); + $this->assertntrospection($entity_type); } } @@ -314,7 +314,7 @@ public function testIntrospection() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testIntrospectionHelper($entity_type) { + protected function assertntrospection($entity_type) { // Test getting metadata upfront, i.e. without having an entity object. $definition = array( 'type' => 'entity', @@ -360,7 +360,7 @@ protected function testIntrospectionHelper($entity_type) { public function testIterator() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testIteratorHelper($entity_type); + $this->assertIterator($entity_type); } } @@ -370,7 +370,7 @@ public function testIterator() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testIteratorHelper($entity_type) { + protected function assertIterator($entity_type) { $entity = $this->createTestEntity($entity_type); foreach ($entity as $name => $field) { @@ -400,7 +400,7 @@ protected function testIteratorHelper($entity_type) { public function testDataStructureInterfaces() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testDataStructureInterfacesHelper($entity_type); + $this->DataStructureInterfaces($entity_type); } } @@ -410,7 +410,7 @@ public function testDataStructureInterfaces() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testDataStructureInterfacesHelper($entity_type) { + protected function DataStructureInterfaces($entity_type) { $entity = $this->createTestEntity($entity_type); $entity->save(); $entity_definition = array( @@ -471,7 +471,7 @@ public function getContainedStrings(TypedDataInterface $wrapper, $depth, array & public function testComputedProperties() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testComputedPropertiesHelper($entity_type); + $this->assertComputedPropertie($entity_type); } } @@ -481,7 +481,7 @@ public function testComputedProperties() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testComputedPropertiesHelper($entity_type) { + protected function assertComputedPropertie($entity_type) { // Make the test text field processed. $instance = field_info_instance($entity_type, 'field_test_text', $entity_type); $instance['settings']['text_processing'] = 1; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php index d9c5886..b95bfed 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php @@ -41,7 +41,7 @@ function setUp() { function testFormCRUD() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testFormCRUDHelper($entity_type); + $this->assertFormCRUD($entity_type); } } @@ -51,9 +51,7 @@ function testFormCRUD() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testFormCRUDHelper($entity_type) { - $entity_type_path = str_replace('_', '-', $entity_type); - + protected function assertFormCRUD($entity_type) { $langcode = LANGUAGE_NOT_SPECIFIED; $name1 = $this->randomName(8); $name2 = $this->randomName(10); @@ -64,19 +62,19 @@ protected function testFormCRUDHelper($entity_type) { "field_test_text[$langcode][0][value]" => $this->randomName(16), ); - $this->drupalPost($entity_type_path . '/add', $edit, t('Save')); + $this->drupalPost($entity_type . '/add', $edit, t('Save')); $entity = $this->loadEntityByName($entity_type, $name1); $this->assertTrue($entity, $entity_type . ': Entity found in the database.'); $edit['name'] = $name2; - $this->drupalPost($entity_type_path . '/manage/' . $entity->id() . '/edit', $edit, t('Save')); + $this->drupalPost($entity_type . '/manage/' . $entity->id() . '/edit', $edit, t('Save')); $entity = $this->loadEntityByName($entity_type, $name1); $this->assertFalse($entity, $entity_type . ': The entity has been modified.'); $entity = $this->loadEntityByName($entity_type, $name2); $this->assertTrue($entity, $entity_type . ': Modified entity found in the database.'); $this->assertNotEqual($entity->name->value, $name1, $entity_type . ': The entity name has been modified.'); - $this->drupalPost($entity_type_path . '/manage/' . $entity->id() . '/edit', array(), t('Delete')); + $this->drupalPost($entity_type . '/manage/' . $entity->id() . '/edit', array(), t('Delete')); $entity = $this->loadEntityByName($entity_type, $name2); $this->assertFalse($entity, $entity_type . ': Entity not found in the database.'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityRevisionsTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityRevisionsTest.php index 98f0529..b8a4bf0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityRevisionsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityRevisionsTest.php @@ -48,8 +48,8 @@ public function setUp() { public function testRevisions() { // All revisionable entity variations have to have the same results. - foreach (_entity_test_revisionable_entity_types() as $entity_type) { - $this->testRevisionsHelper($entity_type); + foreach (_entity_test_entity_types(ENTITY_TEST_TYPES_REVISIONABLE) as $entity_type) { + $this->assertRevisions($entity_type); } } @@ -59,8 +59,7 @@ public function testRevisions() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testRevisionsHelper($entity_type) { - $entity_type_path = str_replace('_', '-', $entity_type); + protected function assertRevisions($entity_type) { // Create initial entity. $entity = entity_create($entity_type, array( @@ -107,7 +106,7 @@ protected function testRevisionsHelper($entity_type) { // Confirm the correct revision text appears in the edit form. $entity = entity_load($entity_type, $entity->id->value); - $this->drupalGet($entity_type_path . '/manage/' . $entity->id->value); + $this->drupalGet($entity_type . '/manage/' . $entity->id->value); $this->assertFieldById('edit-name', $entity->name->value, $entity_type . ': Name matches in UI.'); $this->assertFieldById('edit-field-test-text-und-0-value', $entity->field_test_text->value, $entity_type . ': Text matches in UI.'); } 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 8f2944e..2fdf841 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -79,7 +79,7 @@ function setUp() { public function testEntityLanguageMethods() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testEntityLanguageMethodsHelper($entity_type); + $this->assertEntityLanguageMethods($entity_type); } } @@ -89,7 +89,7 @@ public function testEntityLanguageMethods() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testEntityLanguageMethodsHelper($entity_type) { + protected function assertEntityLanguageMethods($entity_type) { $entity = entity_create($entity_type, array( 'name' => 'test', 'user_id' => $GLOBALS['user']->uid, @@ -192,8 +192,8 @@ protected function testEntityLanguageMethodsHelper($entity_type) { */ public function testMultilingualProperties() { // Test all entity variations with data table support. - foreach (_entity_test_multilingual_entity_types() as $entity_type) { - $this->testMultilingualPropertiesHelper($entity_type); + foreach (_entity_test_entity_types(ENTITY_TEST_TYPES_MULTILINGUAL) as $entity_type) { + $this->assertMultilingualProperties($entity_type); } } @@ -203,7 +203,7 @@ public function testMultilingualProperties() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testMultilingualPropertiesHelper($entity_type) { + protected function assertMultilingualProperties($entity_type) { $name = $this->randomName(); $uid = mt_rand(0, 127); $langcode = $this->langcodes[0]; 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 0af851f..4b2edf6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityUUIDTest.php @@ -36,7 +36,7 @@ public static function getInfo() { function testCRUD() { // All entity variations have to have the same results. foreach (_entity_test_entity_types() as $entity_type) { - $this->testCRUDHelper($entity_type); + $this->assertCRUD($entity_type); } } @@ -46,7 +46,7 @@ function testCRUD() { * @param string $entity_type * The entity type to run the tests with. */ - protected function testCRUDHelper($entity_type) { + protected function assertCRUD($entity_type) { // Verify that no UUID is auto-generated when passing one for creation. $uuid_service = new Uuid(); $uuid = $uuid_service->generate(); 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 3ccf54f..20aed96 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -5,50 +5,42 @@ * Test module for the entity API providing several entity types for testing. */ -use Drupal\entity_test\Plugin\Core\Entity\EntityTest; -use Drupal\entity_test\Plugin\Core\Entity\EntityTestRev; -use Drupal\entity_test\Plugin\Core\Entity\EntityTestMul; -use Drupal\entity_test\Plugin\Core\Entity\EntityTestMulRev; +use Drupal\Core\Entity\EntityInterface; /** - * Returns the a list of entity types to deal with. - * - * @return array - * List with entity_types. + * Filter that limits test entity list to revisionable ones. */ -function _entity_test_entity_types() { - return array( - 'entity_test' => 'entity_test', - 'entity_test_rev' => 'entity_test_rev', - 'entity_test_mul' => 'entity_test_mul', - 'entity_test_mulrev' => 'entity_test_mulrev', - ); -} +const ENTITY_TEST_TYPES_REVISIONABLE = 1; /** - * Returns the a list of entity types that support revisions. - * - * @return array - * List with entity_types. + * Filter that limits test entity list to multilingual ones. */ -function _entity_test_revisionable_entity_types() { - return array( - 'entity_test_rev' => 'entity_test_rev', - 'entity_test_mulrev' => 'entity_test_mulrev', - ); -} +const ENTITY_TEST_TYPES_MULTILINGUAL = 2; /** - * Returns the a list of entity types that have a dedicated data table. + * Returns the a list of entity types to deal with. + * + * @param int $limit + * Either ENTITY_TEST_TYPES_REVISIONABLE to only return revisionable entity + * types or ENTITY_TEST_TYPES_MULTILINGUAL to only return multilingual ones. + * Defaults to NULL, which returns all. * * @return array * List with entity_types. */ -function _entity_test_multilingual_entity_types() { - return array( - 'entity_test_mul' => 'entity_test_mul', - 'entity_test_mulrev' => 'entity_test_mulrev', - ); +function _entity_test_entity_types($filter = NULL) { + $types = array(); + if ($filter == NULL) { + $types[] = 'entity_test'; + } + if ($filter != ENTITY_TEST_TYPES_REVISIONABLE) { + $types[] = 'entity_test_mul'; + } + if ($filter != ENTITY_TEST_TYPES_MULTILINGUAL) { + $types[] = 'entity_test_rev'; + } + $types[] = 'entity_test_mulrev'; + return drupal_map_assoc($types); } /** @@ -93,23 +85,25 @@ function entity_test_menu() { $items = array(); foreach(_entity_test_entity_types() as $entity_type) { - $entity_type_path = str_replace('_', '-', $entity_type); - $items[$entity_type_path . '/add'] = array( - 'title' => 'Add an ' . $entity_type, - 'page callback' => $entity_type . '_add', + $items[$entity_type . '/add'] = array( + 'title' => 'Add an @type', + 'title arguments' => array('%type' => $entity_type), + 'page callback' => 'entity_test_add', + 'page arguments' => array($entity_type), 'access arguments' => array('administer entity_test content'), 'type' => MENU_NORMAL_ITEM, ); - $items[$entity_type_path . '/manage/%' . $entity_type] = array( - 'title' => 'Edit ' . $entity_type, - 'page callback' => $entity_type . '_edit', + $items[$entity_type . '/manage/%' . $entity_type] = array( + 'title' => 'Edit @type', + 'title arguments' => array('%type' => $entity_type), + 'page callback' => 'entity_test_edit', 'page arguments' => array(2), 'access arguments' => array('administer entity_test content'), 'type' => MENU_NORMAL_ITEM, ); - $items[$entity_type_path . '/manage/%' . $entity_type . '/edit'] = array( + $items[$entity_type . '/manage/%' . $entity_type . '/edit'] = array( 'title' => 'Edit', 'type' => MENU_DEFAULT_LOCAL_TASK, ); @@ -129,29 +123,32 @@ function entity_test_form_node_form_alter(&$form, &$form_state, $form_id) { /** * Menu callback: displays the 'Add new entity_test' form. * + * @param string $entity_type + * Name of the entity type for which a create form should be displayed. + * * @return array * The processed form for a new entity_test. * * @see entity_test_menu() */ -function entity_test_add() { - drupal_set_title(t('Create an entity_test')); - $entity = entity_create('entity_test', array()); +function entity_test_add($entity_type) { + drupal_set_title(t('Create an @type', array('@type' => $entity_type))); + $entity = entity_create($entity_type, array()); return entity_get_form($entity); } /** * Menu callback: displays the 'Edit existing entity_test' form. * - * @param EntityTest $entity + * @param \Drupal\Core\Entity\EntityInterface $entity * The entity to be edited. * * @return array - * The processed form for the edited entity_test. + * The processed form for the edited entity. * * @see entity_test_menu() */ -function entity_test_edit(EntityTest $entity) { +function entity_test_edit(EntityInterface $entity) { drupal_set_title($entity->label(), PASS_THROUGH); return entity_get_form($entity); } @@ -164,7 +161,7 @@ function entity_test_edit(EntityTest $entity) { * @param bool $reset * A boolean indicating that the internal cache should be reset. * - * @return Drupal\entity_test\Plugin\Core\Entity\EntityTest + * @return \Drupal\entity_test\Plugin\Core\Entity\EntityTest * The loaded entity object, or FALSE if the entity cannot be loaded. */ function entity_test_load($id, $reset = FALSE) { @@ -172,61 +169,6 @@ function entity_test_load($id, $reset = FALSE) { } /** - * Loads multiple test entities based on certain conditions. - * - * @param array $ids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return array - * An array of test entity objects, indexed by ID. - */ -function entity_test_load_multiple(array $ids = NULL, $reset = FALSE) { - return entity_load_multiple('entity_test', $ids, $reset); -} - -/** - * Deletes multiple test entities. - * - * @param $ids - * An array of test entity IDs. - */ -function entity_test_delete_multiple(array $ids) { - entity_delete_multiple('entity_test', $ids); -} - -/** - * Menu callback: displays the 'Add new entity_test_rev' form. - * - * @return array - * The processed form for a new entity_test_rev. - * - * @see entity_test_menu() - */ -function entity_test_rev_add() { - drupal_set_title(t('Create an entity_test_rev')); - $entity = entity_create('entity_test_rev', array()); - return entity_get_form($entity); -} - -/** - * Menu callback: displays the 'Edit existing entity_test_rev' form. - * - * @param EntityTestRev $entity - * The entity to be edited. - * - * @return array - * The processed form for the edited entity_test_rev. - * - * @see entity_test_menu() - */ -function entity_test_rev_edit(EntityTestRev $entity) { - drupal_set_title($entity->label(), PASS_THROUGH); - return entity_get_form($entity); -} - -/** * Loads a test entity. * * @param int $id @@ -234,7 +176,7 @@ function entity_test_rev_edit(EntityTestRev $entity) { * @param bool $reset * A boolean indicating that the internal cache should be reset. * - * @return Drupal\entity_test\Plugin\Core\Entity\EntityTest + * @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestRev * The loaded entity object, or FALSE if the entity cannot be loaded. */ function entity_test_rev_load($id, $reset = FALSE) { @@ -242,61 +184,6 @@ function entity_test_rev_load($id, $reset = FALSE) { } /** - * Loads multiple test entities based on certain conditions. - * - * @param array $ids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return array - * An array of test entity objects, indexed by ID. - */ -function entity_test_rev_load_multiple(array $ids = NULL, $reset = FALSE) { - return entity_load_multiple('entity_test_rev', $ids, $reset); -} - -/** - * Deletes multiple test entities. - * - * @param $ids - * An array of test entity IDs. - */ -function entity_test_rev_delete_multiple(array $ids) { - entity_delete_multiple('entity_test_rev', $ids); -} - -/** - * Menu callback: displays the 'Add new entity_test_mul' form. - * - * @return array - * The processed form for a new entity_test_mul. - * - * @see entity_test_menu() - */ -function entity_test_mul_add() { - drupal_set_title(t('Create an entity_test_mul')); - $entity = entity_create('entity_test_mul', array()); - return entity_get_form($entity); -} - -/** - * Menu callback: displays the 'Edit existing entity_test_mul' form. - * - * @param EntityTestMul $entity - * The entity to be edited. - * - * @return array - * The processed form for the edited entity_test_mul. - * - * @see entity_test_menu() - */ -function entity_test_mul_edit(EntityTestMul $entity) { - drupal_set_title($entity->label(), PASS_THROUGH); - return entity_get_form($entity); -} - -/** * Loads a test entity. * * @param int $id @@ -304,7 +191,7 @@ function entity_test_mul_edit(EntityTestMul $entity) { * @param bool $reset * A boolean indicating that the internal cache should be reset. * - * @return Drupal\entity_test\Plugin\Core\Entity\EntityTest + * @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestMul * The loaded entity object, or FALSE if the entity cannot be loaded. */ function entity_test_mul_load($id, $reset = FALSE) { @@ -312,61 +199,6 @@ function entity_test_mul_load($id, $reset = FALSE) { } /** - * Loads multiple test entities based on certain conditions. - * - * @param array $ids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return array - * An array of test entity objects, indexed by ID. - */ -function entity_test_mul_load_multiple(array $ids = NULL, $reset = FALSE) { - return entity_load_multiple('entity_test_mul', $ids, $reset); -} - -/** - * Deletes multiple test entities. - * - * @param $ids - * An array of test entity IDs. - */ -function entity_test_mul_delete_multiple(array $ids) { - entity_delete_multiple('entity_test_mul', $ids); -} - -/** - * Menu callback: displays the 'Add new entity_test_mulrev' form. - * - * @return array - * The processed form for a new entity_test_mulrev. - * - * @see entity_test_menu() - */ -function entity_test_mulrev_add() { - drupal_set_title(t('Create an entity_test_mulrev')); - $entity = entity_create('entity_test_mulrev', array()); - return entity_get_form($entity); -} - -/** - * Menu callback: displays the 'Edit existing entity_test_mulrev' form. - * - * @param EntityTestMulRev $entity - * The entity to be edited. - * - * @return array - * The processed form for the edited entity_test_mulrev. - * - * @see entity_test_menu() - */ -function entity_test_mulrev_edit(EntityTestMulRev $entity) { - drupal_set_title($entity->label(), PASS_THROUGH); - return entity_get_form($entity); -} - -/** * Loads a test entity. * * @param int $id @@ -374,34 +206,9 @@ function entity_test_mulrev_edit(EntityTestMulRev $entity) { * @param bool $reset * A boolean indicating that the internal cache should be reset. * - * @return Drupal\entity_test\Plugin\Core\Entity\EntityTest + * @return \Drupal\entity_test\Plugin\Core\Entity\EntityTestMulRev * The loaded entity object, or FALSE if the entity cannot be loaded. */ function entity_test_mulrev_load($id, $reset = FALSE) { return entity_load('entity_test_mulrev', $id, $reset); } - -/** - * Loads multiple test entities based on certain conditions. - * - * @param array $ids - * (optional) An array of entity IDs. If omitted, all entities are loaded. - * @param bool $reset - * A boolean indicating that the internal cache should be reset. - * - * @return array - * An array of test entity objects, indexed by ID. - */ -function entity_test_mulrev_load_multiple(array $ids = NULL, $reset = FALSE) { - return entity_load_multiple('entity_test_mulrev', $ids, $reset); -} - -/** - * Deletes multiple test entities. - * - * @param $ids - * An array of test entity IDs. - */ -function entity_test_mulrev_delete_multiple(array $ids) { - entity_delete_multiple('entity_test_mulrev', $ids); -}