diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php index dd7712e..9a7892c 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DatetimeFieldTest.php @@ -21,7 +21,7 @@ class DatetimeFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'field_test', 'datetime', 'field_ui'); + public static $modules = array('node', 'entity_test', 'datetime', 'field_ui'); /** * A field to use in this test class. @@ -42,8 +42,8 @@ function setUp() { parent::setUp(); $web_user = $this->drupalCreateUser(array( - 'access field_test content', - 'administer field_test content', + 'view test entity', + 'administer entity_test content', 'administer content types', )); $this->drupalLogin($web_user); @@ -56,8 +56,8 @@ function setUp() { )); $this->instance = field_create_instance(array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'settings' => array( 'default_value' => 'blank', ), @@ -85,7 +85,7 @@ function setUp() { function testDateField() { // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element not found.'); @@ -98,12 +98,14 @@ function testDateField() { $time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type); $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format), ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertRaw($date->format($date_format)); $this->assertNoRaw($date->format($time_format)); @@ -154,7 +156,7 @@ function testDatetimeField() { field_update_field($this->field); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.'); @@ -167,13 +169,15 @@ function testDatetimeField() { $time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type); $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format), "{$this->field['field_name']}[$langcode][0][value][time]" => $date->format($time_format), ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertRaw($date->format($date_format)); $this->assertRaw($date->format($time_format)); @@ -234,7 +238,7 @@ function testDatelistWidget() { field_cache_clear(); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $field_name = $this->field['field_name']; $langcode = Language::LANGCODE_NOT_SPECIFIED; @@ -256,7 +260,10 @@ function testDatelistWidget() { $date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15); $date = new DrupalDateTime($date_value); - $edit = array(); + $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), + ); // Add the ampm indicator since we are testing 12 hour time. $date_value['ampm'] = 'am'; foreach ($date_value as $part => $value) { @@ -264,9 +271,9 @@ function testDatelistWidget() { } $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertOptionSelected("edit-$field_name-$langcode-0-value-year", '2012', 'Correct year selected.'); $this->assertOptionSelected("edit-$field_name-$langcode-0-value-month", '12', 'Correct month selected.'); @@ -293,7 +300,7 @@ function testDefaultValue() { // Display creation form. $date = new DrupalDateTime(); $date_format = 'Y-m-d'; - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; // See if current date is set. We cannot test for the precise time because @@ -310,7 +317,7 @@ function testDefaultValue() { // Display creation form. $date = new DrupalDateTime(); - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); // See that no date is set. $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); @@ -327,7 +334,7 @@ function testInvalidField() { field_update_field($this->field); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.'); @@ -403,23 +410,23 @@ function testInvalidField() { } /** - * Renders a test_entity and sets the output in the internal browser. + * Renders a entity_test and sets the output in the internal browser. * * @param int $id - * The test_entity ID to render. + * The entity_test ID to render. * @param string $view_mode * (optional) The view mode to use for rendering. Defaults to 'full'. * @param bool $reset - * (optional) Whether to reset the test_entity controller cache. Defaults to + * (optional) Whether to reset the entity_test controller cache. Defaults to * TRUE to simplify testing. */ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { if ($reset) { - entity_get_controller('test_entity')->resetCache(array($id)); + entity_get_controller('entity_test')->resetCache(array($id)); } - $entity = field_test_entity_test_load($id); - $display = entity_get_display('test_entity', $entity->bundle(), 'full'); - field_attach_prepare_view('test_entity', array($entity->id() => $entity), array($entity->bundle() => $display), $view_mode); + $entity = entity_load('entity_test', $id); + $display = entity_get_display('entity_test', $entity->bundle(), 'full'); + field_attach_prepare_view('entity_test', array($entity->id() => $entity), array($entity->bundle() => $display), $view_mode); $entity->content = field_attach_view($entity, $display, $view_mode); $output = drupal_render($entity->content); diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index 50badce..6999441 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -20,7 +20,7 @@ class EmailFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'field_test', 'email', 'field_ui'); + public static $modules = array('node', 'entity_test', 'email', 'field_ui'); public static function getInfo() { return array( @@ -34,8 +34,8 @@ function setUp() { parent::setUp(); $this->web_user = $this->drupalCreateUser(array( - 'access field_test content', - 'administer field_test content', + 'view test entity', + 'administer entity_test content', 'administer content types', )); $this->drupalLogin($this->web_user); @@ -53,13 +53,13 @@ function testEmailField() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); field_create_instance($this->instance); // Create a form display for the default form mode. - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'email_default', 'settings' => array( @@ -68,14 +68,14 @@ function testEmailField() { )) ->save(); // Create a display for the full view mode. - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], array( 'type' => 'email_mailto', )) ->save(); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget found.'); $this->assertRaw('placeholder="example@example.com"'); @@ -83,16 +83,18 @@ function testEmailField() { // Submit a valid e-mail address and ensure it is accepted. $value = 'test@example.com'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertRaw($value); // Verify that a mailto link is displayed. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $entity->content = field_attach_view($entity, $display); $this->drupalSetContent(drupal_render($entity->content)); diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index 1ec4ec4..461e04f 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -20,7 +20,7 @@ class LinkFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('field_test', 'link'); + public static $modules = array('entity_test', 'link'); public static function getInfo() { return array( @@ -34,8 +34,8 @@ function setUp() { parent::setUp(); $this->web_user = $this->drupalCreateUser(array( - 'access field_test content', - 'administer field_test content', + 'view test entity', + 'administer entity_test content', )); $this->drupalLogin($this->web_user); } @@ -52,14 +52,14 @@ function testURLValidation() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'settings' => array( 'title' => DRUPAL_DISABLED, ), ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'link_default', 'settings' => array( @@ -67,7 +67,7 @@ function testURLValidation() { ), )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], array( 'type' => 'link', )) @@ -76,19 +76,21 @@ function testURLValidation() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'Link URL field is displayed'); $this->assertRaw('placeholder="http://example.com"'); // Verify that a valid URL can be submitted. $value = 'http://www.example.com/'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][url]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->assertRaw($value); // Verify that invalid URLs cannot be submitted. @@ -100,9 +102,11 @@ function testURLValidation() { // Missing host name 'http://', ); - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); foreach ($wrong_entries as $invalid_value) { $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][url]" => $invalid_value, ); $this->drupalPost(NULL, $edit, t('Save')); @@ -122,15 +126,15 @@ function testLinkTitle() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'label' => 'Read more about this entity', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'link_default', 'settings' => array( @@ -139,7 +143,7 @@ function testLinkTitle() { ), )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], array( 'type' => 'link', 'label' => 'hidden', @@ -155,7 +159,7 @@ function testLinkTitle() { field_update_instance($this->instance); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); // Assert label is shown. $this->assertText('Read more about this entity'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][url]", '', 'URL field found.'); @@ -185,7 +189,7 @@ function testLinkTitle() { $this->assertNoText(t('!name field is required.', array('!name' => t('Title')))); // Verify that a URL and title meets requirements. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $edit = array( "{$this->field['field_name']}[$langcode][0][url]" => 'http://www.example.com', "{$this->field['field_name']}[$langcode][0][title]" => 'Example', @@ -199,13 +203,15 @@ function testLinkTitle() { // Verify that a link without title is rendered using the URL as link text. $value = 'http://www.example.com/'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][url]" => $value, "{$this->field['field_name']}[$langcode][0][title]" => '', ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); $this->renderTestEntity($id); $expected_link = l($value, $value); @@ -214,10 +220,12 @@ function testLinkTitle() { // Verify that a link with title is rendered using the title as link text. $title = $this->randomName(); $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][title]" => $title, ); - $this->drupalPost("test-entity/manage/$id/edit", $edit, t('Save')); - $this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id))); + $this->drupalPost("entity_test/manage/$id/edit", $edit, t('Save')); + $this->assertText(t('entity_test @id has been updated.', array('@id' => $id))); $this->renderTestEntity($id); $expected_link = l($title, $value); @@ -237,9 +245,9 @@ function testLinkFormatter() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', + 'entity_type' => 'entity_test', 'label' => 'Read more about this entity', - 'bundle' => 'test_bundle', + 'bundle' => 'entity_test', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), @@ -249,12 +257,12 @@ function testLinkFormatter() { 'label' => 'hidden', ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'link_default', )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], $display_options) ->save(); @@ -265,13 +273,15 @@ function testLinkFormatter() { // - The second field item uses a URL and title. // For consistency in assertion code below, the URL is assigned to the title // variable for the first field. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $url1 = 'http://www.example.com/content/articles/archive?author=John&year=2012#com'; $url2 = 'http://www.example.org/content/articles/archive?author=John&year=2012#org'; $title1 = $url1; // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][url]" => $url1, // Note that $title1 is not submitted. "{$this->field['field_name']}[$langcode][0][title]" => '', @@ -281,9 +291,9 @@ function testLinkFormatter() { // Assert label is shown. $this->assertText('Read more about this entity'); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); // Verify that the link is output according to the formatter settings. // Not using generatePermutations(), since that leads to 32 cases, which @@ -310,7 +320,7 @@ function testLinkFormatter() { else { $display_options['settings'] = $new_value; } - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], $display_options) ->save(); @@ -378,8 +388,8 @@ function testLinkSeparateFormatter() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'settings' => array( 'title' => DRUPAL_OPTIONAL, ), @@ -389,12 +399,12 @@ function testLinkSeparateFormatter() { 'label' => 'hidden', ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'link_default', )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], $display_options) ->save(); @@ -405,20 +415,22 @@ function testLinkSeparateFormatter() { // - The second field item uses a URL and title. // For consistency in assertion code below, the URL is assigned to the title // variable for the first field. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $url1 = 'http://www.example.com/content/articles/archive?author=John&year=2012#com'; $url2 = 'http://www.example.org/content/articles/archive?author=John&year=2012#org'; // Intentionally contains an ampersand that needs sanitization on output. $title2 = 'A very long & strange example title that could break the nice layout of the site'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][url]" => $url1, "{$this->field['field_name']}[$langcode][1][url]" => $url2, "{$this->field['field_name']}[$langcode][1][title]" => $title2, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id))); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); // Verify that the link is output according to the formatter settings. $options = array( @@ -430,7 +442,7 @@ function testLinkSeparateFormatter() { foreach ($values as $new_value) { // Update the field formatter settings. $display_options['settings'] = array($setting => $new_value); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field['field_name'], $display_options) ->save(); @@ -483,11 +495,11 @@ function testLinkSeparateFormatter() { */ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) { if ($reset) { - $this->container->get('plugin.manager.entity')->getStorageController('test_entity')->resetCache(array($id)); + $this->container->get('plugin.manager.entity')->getStorageController('entity_test')->resetCache(array($id)); } - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), $view_mode); - field_attach_prepare_view('test_entity', array($entity->id() => $entity), array($entity->bundle() => $display)); + field_attach_prepare_view('entity_test', array($entity->id() => $entity), array($entity->bundle() => $display)); $entity->content = field_attach_view($entity, $display); $output = drupal_render($entity->content); diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 7cb310a..f9a817f 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -20,7 +20,7 @@ class NumberFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('node', 'field_test', 'number', 'field_ui'); + public static $modules = array('node', 'entity_test', 'number', 'field_ui'); protected $field; protected $instance; @@ -37,7 +37,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer content types', 'administer node fields','administer node display')); + $this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content', 'administer content types', 'administer node fields','administer node display')); $this->drupalLogin($this->web_user); } @@ -56,12 +56,12 @@ function testNumberDecimalField() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'number', 'settings' => array( @@ -69,14 +69,14 @@ function testNumberDecimalField() { ), )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'default') + entity_get_display('entity_test', 'entity_test', 'default') ->setComponent($this->field['field_name'], array( 'type' => 'number_decimal', )) ->save(); // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertRaw('placeholder="0.00"'); @@ -84,12 +84,14 @@ function testNumberDecimalField() { // Submit a signed decimal value within the allowed precision and scale. $value = '-1234.5678'; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field['field_name']}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); $this->assertRaw(round($value, 2), 'Value is displayed.'); // Try to create entries with more than one decimal separator; assert fail. @@ -102,7 +104,7 @@ function testNumberDecimalField() { ); foreach ($wrong_entries as $wrong_entry) { - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $edit = array( "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, ); @@ -120,7 +122,7 @@ function testNumberDecimalField() { ); foreach ($wrong_entries as $wrong_entry) { - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $edit = array( "{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry, ); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php index 4e97dbe..df3ac66 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesTest.php @@ -19,7 +19,14 @@ class OptionsDynamicValuesTest extends FieldTestBase { * * @var array */ - public static $modules = array('options', 'field_test', 'options_test'); + public static $modules = array('options', 'entity_test', 'options_test'); + + /** + * The created entity. + * + * @var \Drupal\Core\Entity\Entity + */ + protected $entity; function setUp() { parent::setUp(); @@ -37,25 +44,31 @@ function setUp() { $this->instance = array( 'field_name' => $this->field_name, - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test_rev', + 'bundle' => 'entity_test_rev', 'required' => TRUE, ); $this->instance = field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default') ->setComponent($this->field_name, array( 'type' => 'options_select', )) ->save(); + // Create an entity and prepare test data that will be used by + // options_test_dynamic_values_callback(). + $values = array( + 'user_id' => mt_rand(1, 10), + 'name' => $this->randomName(), + ); + $this->entity = entity_create('entity_test_rev', $values); + $this->entity->save(); + $uri = $this->entity->uri(); $this->test = array( - 'id' => mt_rand(1, 10), - // Make sure this does not equal the ID so that - // options_test_dynamic_values_callback() always returns 4 values. - 'vid' => mt_rand(20, 30), - 'bundle' => 'test_bundle', - 'label' => $this->randomName(), + 'label' => $this->entity->label(), + 'uuid' => $this->entity->uuid(), + 'bundle' => $this->entity->bundle(), + 'uri' => $uri['path'], ); - $this->entity = call_user_func_array('field_test_create_entity', $this->test); } } diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php index 5ede47b..6651a17 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php @@ -28,7 +28,7 @@ public static function getInfo() { function testDynamicAllowedValues() { // Verify that the test passes against every value we had. foreach ($this->test as $key => $value) { - $this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $value; + $this->entity->test_options->value = $value; try { field_attach_validate($this->entity); $this->pass("$key should pass"); @@ -40,7 +40,7 @@ function testDynamicAllowedValues() { } // Now verify that the test does not pass against anything else. foreach ($this->test as $key => $value) { - $this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = is_numeric($value) ? (100 - $value) : ('X' . $value); + $this->entity->test_options->value = is_numeric($value) ? (100 - $value) : ('X' . $value); $pass = FALSE; try { field_attach_validate($this->entity); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsSelectDynamicValuesTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsSelectDynamicValuesTest.php index 4344d21..0237546 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsSelectDynamicValuesTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsSelectDynamicValuesTest.php @@ -27,11 +27,11 @@ function testSelectListDynamic() { $this->entity->save(); // Create a web user. - $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content')); + $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); $this->drupalLogin($web_user); // Display form. - $this->drupalGet('test-entity/manage/' . $this->entity->ftid . '/edit'); + $this->drupalGet('entity_test_rev/manage/' . $this->entity->id() . '/edit'); $options = $this->xpath('//select[@id="edit-test-options-und"]/option'); $this->assertEqual(count($options), count($this->test) + 1); foreach ($options as $option) { diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 91f7498..f206d0e 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -20,7 +20,7 @@ class OptionsWidgetsTest extends FieldTestBase { * * @var array */ - public static $modules = array('options', 'field_test', 'options_test', 'taxonomy', 'field_ui'); + public static $modules = array('options', 'entity_test', 'options_test', 'taxonomy', 'field_ui'); public static function getInfo() { return array( @@ -69,7 +69,7 @@ function setUp() { $this->bool = field_create_field($this->bool); // Create a web user. - $this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content')); + $this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); $this->drupalLogin($this->web_user); } @@ -80,11 +80,11 @@ function testRadioButtons() { // Create an instance of the 'single value' field. $instance = array( 'field_name' => $this->card_1['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); $instance = field_create_instance($instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->card_1['field_name'], array( 'type' => 'options_buttons', )) @@ -93,13 +93,15 @@ function testRadioButtons() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_entity(); - $entity = clone $entity_init; - $entity->is_new = TRUE; - field_test_entity_save($entity); + $entity = entity_create('entity_test', array( + 'user_id' => 1, + 'name' => $this->randomName(), + )); + $entity->save(); + $entity_init = clone $entity; // With no field data, no buttons are checked. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoFieldChecked("edit-card-1-$langcode-0"); $this->assertNoFieldChecked("edit-card-1-$langcode-1"); $this->assertNoFieldChecked("edit-card-1-$langcode-2"); @@ -111,7 +113,7 @@ function testRadioButtons() { $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0)); // Check that the selected button is checked. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-1-$langcode-0"); $this->assertNoFieldChecked("edit-card-1-$langcode-1"); $this->assertNoFieldChecked("edit-card-1-$langcode-2"); @@ -126,7 +128,7 @@ function testRadioButtons() { field_update_field($this->card_1); $instance['required'] = TRUE; field_update_instance($instance); - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-1-$langcode-99"); } @@ -137,11 +139,11 @@ function testCheckBoxes() { // Create an instance of the 'multiple values' field. $instance = array( 'field_name' => $this->card_2['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); $instance = field_create_instance($instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->card_2['field_name'], array( 'type' => 'options_buttons', )) @@ -150,13 +152,15 @@ function testCheckBoxes() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_entity(); - $entity = clone $entity_init; - $entity->is_new = TRUE; - field_test_entity_save($entity); + $entity = entity_create('entity_test', array( + 'user_id' => 1, + 'name' => $this->randomName(), + )); + $entity->save(); + $entity_init = clone $entity; // Display form: with no field data, nothing is checked. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoFieldChecked("edit-card-2-$langcode-0"); $this->assertNoFieldChecked("edit-card-2-$langcode-1"); $this->assertNoFieldChecked("edit-card-2-$langcode-2"); @@ -172,7 +176,7 @@ function testCheckBoxes() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0, 2)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-2-$langcode-0"); $this->assertNoFieldChecked("edit-card-2-$langcode-1"); $this->assertFieldChecked("edit-card-2-$langcode-2"); @@ -187,7 +191,7 @@ function testCheckBoxes() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-2-$langcode-0"); $this->assertNoFieldChecked("edit-card-2-$langcode-1"); $this->assertNoFieldChecked("edit-card-2-$langcode-2"); @@ -216,7 +220,7 @@ function testCheckBoxes() { field_update_field($this->card_2); $instance['required'] = TRUE; field_update_instance($instance); - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-card-2-$langcode-99"); } @@ -227,12 +231,12 @@ function testSelectListSingle() { // Create an instance of the 'single value' field. $instance = array( 'field_name' => $this->card_1['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'required' => TRUE, ); $instance = field_create_instance($instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->card_1['field_name'], array( 'type' => 'options_select', )) @@ -241,13 +245,15 @@ function testSelectListSingle() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_entity(); - $entity = clone $entity_init; - $entity->is_new = TRUE; - field_test_entity_save($entity); + $entity = entity_create('entity_test', array( + 'user_id' => 1, + 'name' => $this->randomName(), + )); + $entity->save(); + $entity_init = clone $entity; // Display form. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A required field without any value has a "none" option. $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1-' . $langcode, ':label' => t('- Select a value -'))), 'A required select list has a "Select a value" choice.'); @@ -269,7 +275,7 @@ function testSelectListSingle() { $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A required field with a value has no 'none' option. $this->assertFalse($this->xpath('//select[@id=:id]//option[@value="_none"]', array(':id' => 'edit-card-1-' . $langcode)), 'A required select list with an actual value has no "none" choice.'); $this->assertOptionSelected("edit-card-1-$langcode", 0); @@ -281,12 +287,12 @@ function testSelectListSingle() { field_update_instance($instance); // Display form. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); // A non-required field has a 'none' option. $this->assertTrue($this->xpath('//select[@id=:id]//option[@value="_none" and text()=:label]', array(':id' => 'edit-card-1-' . $langcode, ':label' => t('- None -'))), 'A non-required select list has a "None" choice.'); // Submit form: Unselect the option. $edit = array("card_1[$langcode]" => '_none'); - $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save')); + $this->drupalPost('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); $this->assertFieldValues($entity_init, 'card_1', $langcode, array()); // Test optgroups. @@ -296,7 +302,7 @@ function testSelectListSingle() { field_update_field($this->card_1); // Display form: with no field data, nothing is selected - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoOptionSelected("edit-card-1-$langcode", 0); $this->assertNoOptionSelected("edit-card-1-$langcode", 1); $this->assertNoOptionSelected("edit-card-1-$langcode", 2); @@ -309,14 +315,14 @@ function testSelectListSingle() { $this->assertFieldValues($entity_init, 'card_1', $langcode, array(0)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertOptionSelected("edit-card-1-$langcode", 0); $this->assertNoOptionSelected("edit-card-1-$langcode", 1); $this->assertNoOptionSelected("edit-card-1-$langcode", 2); // Submit form: Unselect the option. $edit = array("card_1[$langcode]" => '_none'); - $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save')); + $this->drupalPost('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); $this->assertFieldValues($entity_init, 'card_1', $langcode, array()); } @@ -327,11 +333,11 @@ function testSelectListMultiple() { // Create an instance of the 'multiple values' field. $instance = array( 'field_name' => $this->card_2['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); $instance = field_create_instance($instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->card_2['field_name'], array( 'type' => 'options_select', )) @@ -340,13 +346,15 @@ function testSelectListMultiple() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_entity(); - $entity = clone $entity_init; - $entity->is_new = TRUE; - field_test_entity_save($entity); + $entity = entity_create('entity_test', array( + 'user_id' => 1, + 'name' => $this->randomName(), + )); + $entity->save(); + $entity_init = clone $entity; // Display form: with no field data, nothing is selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertNoOptionSelected("edit-card-2-$langcode", 2); @@ -358,7 +366,7 @@ function testSelectListMultiple() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0, 2)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertOptionSelected("edit-card-2-$langcode", 2); @@ -369,7 +377,7 @@ function testSelectListMultiple() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertNoOptionSelected("edit-card-2-$langcode", 2); @@ -389,18 +397,18 @@ function testSelectListMultiple() { // Check that the 'none' option has no efect if actual options are selected // as well. $edit = array("card_2[$langcode][]" => array('_none' => '_none', 0 => 0)); - $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save')); + $this->drupalPost('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0)); // Check that selecting the 'none' option empties the field. $edit = array("card_2[$langcode][]" => array('_none' => '_none')); - $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save')); + $this->drupalPost('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); $this->assertFieldValues($entity_init, 'card_2', $langcode, array()); // A required select list does not have an empty key. $instance['required'] = TRUE; field_update_instance($instance); - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFalse($this->xpath('//select[@id=:id]//option[@value=""]', array(':id' => 'edit-card-2-' . $langcode)), 'A required select list does not have an empty key.'); // We do not have to test that a required select list with one option is @@ -416,7 +424,7 @@ function testSelectListMultiple() { field_update_instance($instance); // Display form: with no field data, nothing is selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertNoOptionSelected("edit-card-2-$langcode", 2); @@ -429,14 +437,14 @@ function testSelectListMultiple() { $this->assertFieldValues($entity_init, 'card_2', $langcode, array(0)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertOptionSelected("edit-card-2-$langcode", 0); $this->assertNoOptionSelected("edit-card-2-$langcode", 1); $this->assertNoOptionSelected("edit-card-2-$langcode", 2); // Submit form: Unselect the option. $edit = array("card_2[$langcode][]" => array('_none' => '_none')); - $this->drupalPost('test-entity/manage/' . $entity->ftid . '/edit', $edit, t('Save')); + $this->drupalPost('entity_test/manage/' . $entity->id() . '/edit', $edit, t('Save')); $this->assertFieldValues($entity_init, 'card_2', $langcode, array()); } @@ -447,11 +455,11 @@ function testOnOffCheckbox() { // Create an instance of the 'boolean' field. $instance = array( 'field_name' => $this->bool['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); $instance = field_create_instance($instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->bool['field_name'], array( 'type' => 'options_onoff', )) @@ -460,13 +468,15 @@ function testOnOffCheckbox() { $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. - $entity_init = field_test_create_entity(); - $entity = clone $entity_init; - $entity->is_new = TRUE; - field_test_entity_save($entity); + $entity = entity_create('entity_test', array( + 'user_id' => 1, + 'name' => $this->randomName(), + )); + $entity->save(); + $entity_init = clone $entity; // Display form: with no field data, option is unchecked. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoFieldChecked("edit-bool-$langcode"); $this->assertRaw('Some dangerous & unescaped markup', 'Option text was properly filtered.'); @@ -476,7 +486,7 @@ function testOnOffCheckbox() { $this->assertFieldValues($entity_init, 'bool', $langcode, array(1)); // Display form: check that the right options are selected. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertFieldChecked("edit-bool-$langcode"); // Submit form: uncheck the option. @@ -485,7 +495,7 @@ function testOnOffCheckbox() { $this->assertFieldValues($entity_init, 'bool', $langcode, array(0)); // Display form: with 'off' value, option is unchecked. - $this->drupalGet('test-entity/manage/' . $entity->ftid . '/edit'); + $this->drupalGet('entity_test/manage/' . $entity->id() . '/edit'); $this->assertNoFieldChecked("edit-bool-$langcode"); // Create Basic page node type. diff --git a/core/modules/options/tests/options_test.module b/core/modules/options/tests/options_test.module index 90f6bf1..4ece85c 100644 --- a/core/modules/options/tests/options_test.module +++ b/core/modules/options/tests/options_test.module @@ -30,10 +30,11 @@ function options_test_allowed_values_callback($field, $instance, $entity) { function options_test_dynamic_values_callback($field, $instance, EntityInterface $entity, &$cacheable) { $cacheable = FALSE; // We need the values of the entity as keys. + $uri = $entity->uri(); return drupal_map_assoc(array( - $entity->ftlabel, - $entity->id(), - $entity->getRevisionId(), + $entity->label(), + $uri['path'], + $entity->uuid(), $entity->bundle(), )); } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php index 3383f94..0b5c29a 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/CrudTest.php @@ -34,7 +34,7 @@ public static function getInfo() { */ function testCRUD() { // Verify loading of a default mapping. - $mapping = _rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = _rdf_mapping_load('entity_test', 'entity_test'); $this->assertTrue(count($mapping), 'Default mapping was found.'); // Verify saving a mapping. diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/MappingHookTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/MappingHookTest.php index eb1340e..b05f4af 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/MappingHookTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/MappingHookTest.php @@ -19,7 +19,7 @@ class MappingHookTest extends WebTestBase { * * @var array */ - public static $modules = array('rdf', 'rdf_test', 'field_test'); + public static $modules = array('rdf', 'rdf_test', 'entity_test'); public static function getInfo() { return array( @@ -34,7 +34,7 @@ public static function getInfo() { */ function testMapping() { // Test that the mapping is returned correctly by the hook. - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $this->assertIdentical($mapping['rdftype'], array('sioc:Post'), 'Mapping for rdftype is sioc:Post.'); $this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), 'Mapping for title is dc:title.'); $this->assertIdentical($mapping['created'], array( @@ -44,7 +44,7 @@ function testMapping() { ), 'Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.'); $this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), 'Mapping for uid is sioc:has_creator and dc:creator, and type is rel.'); - $mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping'); + $mapping = rdf_mapping_load('entity_test', 'test_bundle_no_mapping'); $this->assertEqual($mapping, array(), 'Empty array returned when an entity type, bundle pair has no mapping.'); } } diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php index bf47b46..2f517e1 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php @@ -20,7 +20,7 @@ class RdfaMarkupTest extends WebTestBase { * * @var array */ - public static $modules = array('rdf', 'field_test', 'rdf_test'); + public static $modules = array('rdf', 'entity_test', 'rdf_test'); protected $profile = 'standard'; @@ -40,7 +40,7 @@ function testDrupalRdfaAttributes() { $expected_attributes = array( 'property' => array('dc:title'), ); - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $attributes = rdf_rdfa_attributes($mapping['title']); ksort($expected_attributes); ksort($attributes); @@ -54,7 +54,7 @@ function testDrupalRdfaAttributes() { 'property' => array('dc:created'), 'content' => $isoDate, ); - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $attributes = rdf_rdfa_attributes($mapping['created'], $date); ksort($expected_attributes); ksort($attributes); @@ -65,7 +65,7 @@ function testDrupalRdfaAttributes() { 'datatype' => 'foo:bar1type', 'property' => array('foo:bar1'), ); - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $attributes = rdf_rdfa_attributes($mapping['foobar1']); ksort($expected_attributes); ksort($attributes); @@ -75,7 +75,7 @@ function testDrupalRdfaAttributes() { $expected_attributes = array( 'rel' => array('sioc:has_creator', 'dc:creator'), ); - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']); ksort($expected_attributes); ksort($attributes); @@ -85,7 +85,7 @@ function testDrupalRdfaAttributes() { $expected_attributes = array( 'rev' => array('sioc:reply_of'), ); - $mapping = rdf_mapping_load('test_entity', 'test_bundle'); + $mapping = rdf_mapping_load('entity_test', 'entity_test'); $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']); ksort($expected_attributes); ksort($attributes); diff --git a/core/modules/rdf/tests/rdf_test.module b/core/modules/rdf/tests/rdf_test.module index 4d90472..ea45e43 100644 --- a/core/modules/rdf/tests/rdf_test.module +++ b/core/modules/rdf/tests/rdf_test.module @@ -11,8 +11,8 @@ function rdf_test_rdf_mapping() { return array( array( - 'type' => 'test_entity', - 'bundle' => 'test_bundle', + 'type' => 'entity_test', + 'bundle' => 'entity_test', 'mapping' => array( 'rdftype' => array('sioc:Post'), 'title' => array( 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 f42ea78..8b5b19b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -19,7 +19,7 @@ class EntityQueryTest extends EntityUnitTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = array('field_test', 'language'); /** * @var array @@ -55,7 +55,9 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installSchema('field_test', array('test_entity', 'test_entity_revision', 'test_entity_bundle')); + $this->installSchema('entity_test', array('entity_test_mulrev', 'entity_test_mulrev_property_data', 'entity_test_mulrev_property_revision')); + $this->installSchema('language', array('language')); + $this->installSchema('system', array('variable')); $figures = drupal_strtolower($this->randomName()); $greetings = drupal_strtolower($this->randomName()); foreach (array($figures => 'shape', $greetings => 'text') as $field_name => $field_type) { @@ -63,6 +65,7 @@ function setUp() { 'field_name' => $field_name, 'type' => $field_type, 'cardinality' => 2, + 'translatable' => TRUE, ); $fields[] = field_create_field($field); } @@ -73,11 +76,11 @@ function setUp() { do { $bundle = $this->randomName(); } while ($bundles && strtolower($bundles[0]) >= strtolower($bundle)); - field_test_create_bundle($bundle); + entity_test_create_bundle($bundle); foreach ($fields as $field) { $instance = array( 'field_name' => $field['field_name'], - 'entity_type' => 'test_entity', + 'entity_type' => 'entity_test_mulrev', 'bundle' => $bundle, ); field_create_instance($instance); @@ -85,11 +88,11 @@ function setUp() { $bundles[] = $bundle; } // Each unit is a list of field name, langcode and a column-value array. - $units[] = array($figures, Language::LANGCODE_NOT_SPECIFIED, array( + $units[] = array($figures, 'en', array( 'color' => 'red', 'shape' => 'triangle', )); - $units[] = array($figures, Language::LANGCODE_NOT_SPECIFIED, array( + $units[] = array($figures, 'en', array( 'color' => 'blue', 'shape' => 'circle', )); @@ -104,24 +107,41 @@ function setUp() { 'format' => 'format-pl' )); // Make these languages available to the greetings field. + $langcode = new Language(array( + 'langcode' => 'en', + 'name' => $this->randomString(), + )); + language_save($langcode); + $langcode = new Language(array( + 'langcode' => 'tr', + 'name' => $this->randomString(), + )); + language_save($langcode); + $langcode = new Language(array( + 'langcode' => 'pl', + 'name' => $this->randomString(), + )); + language_save($langcode); $field_langcodes = &drupal_static('field_available_languages'); - $field_langcodes['test_entity'][$greetings] = array('tr', 'pl'); + $field_langcodes['entity_test_mulrev'][$greetings] = array('tr', 'pl'); // Calculate the cartesian product of the unit array by looking at the // bits of $i and add the unit at the bits that are 1. For example, // decimal 13 is binary 1101 so unit 3,2 and 0 will be added to the // entity. for ($i = 1; $i <= 15; $i++) { - $entity = entity_create('test_entity', array( - 'ftid' => $i, - 'ftvid' => $i, - 'fttype' => $bundles[$i & 1], + $entity = entity_create('entity_test_mulrev', array( + 'type' => $bundles[$i & 1], + 'name' => $this->randomName(), + 'langcode' => 'en', )); - $entity->enforceIsNew(); - $entity->setNewRevision(); + // Make sure the name is set for every language that we might create. + foreach (array('tr', 'pl') as $langcode) { + $entity->getTranslation($langcode)->name = $this->randomName(); + } foreach (array_reverse(str_split(decbin($i))) as $key => $bit) { if ($bit) { - $unit = $units[$key]; - $entity->{$unit[0]}[$unit[1]][] = $unit[2]; + list($field_name, $langcode, $values) = $units[$key]; + $entity->getTranslation($langcode)->{$field_name}[] = $values; } } $entity->save(); @@ -137,19 +157,19 @@ function setUp() { function testEntityQuery() { $greetings = $this->greetings; $figures = $this->figures; - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->exists($greetings, 'tr') ->condition("$figures.color", 'red') - ->sort('ftid') + ->sort('id') ->execute(); // As unit 0 was the red triangle and unit 2 was the turkish greeting, // bit 0 and bit 2 needs to be set. $this->assertResult(5, 7, 13, 15); - $query = $this->factory->get('test_entity', 'OR') + $query = $this->factory->get('entity_test_mulrev', 'OR') ->exists($greetings, 'tr') ->condition("$figures.color", 'red') - ->sort('ftid'); + ->sort('id'); $count_query = clone $query; $this->assertEqual(12, $count_query->count()->execute()); $this->queryResults = $query->execute(); @@ -158,9 +178,9 @@ function testEntityQuery() { $this->assertResult(1, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15); // Test cloning of query conditions. - $query = $this->factory->get('test_entity') + $query = $this->factory->get('entity_test_mulrev') ->condition("$figures.color", 'red') - ->sort('ftid'); + ->sort('id'); $cloned_query = clone $query; $cloned_query ->condition("$figures.shape", 'circle'); @@ -171,95 +191,95 @@ function testEntityQuery() { $this->queryResults = $cloned_query->execute(); $this->assertResult(); - $query = $this->factory->get('test_entity'); + $query = $this->factory->get('entity_test_mulrev'); $group = $query->orConditionGroup() ->exists($greetings, 'tr') ->condition("$figures.color", 'red'); $this->queryResults = $query ->condition($group) ->condition("$greetings.value", 'sie', 'STARTS_WITH') - ->sort('ftvid') + ->sort('revision_id') ->execute(); // Bit 3 and (bit 0 or 2) -- the above 8 part of the above. $this->assertResult(9, 11, 12, 13, 14, 15); // No figure has both the colors blue and red at the same time. - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->condition("$figures.color", 'blue') ->condition("$figures.color", 'red') - ->sort('ftid') + ->sort('id') ->execute(); $this->assertResult(); // But an entity might have a red and a blue figure both. - $query = $this->factory->get('test_entity'); + $query = $this->factory->get('entity_test_mulrev'); $group_blue = $query->andConditionGroup()->condition("$figures.color", 'blue'); $group_red = $query->andConditionGroup()->condition("$figures.color", 'red'); $this->queryResults = $query ->condition($group_blue) ->condition($group_red) - ->sort('ftvid') + ->sort('revision_id') ->execute(); // Unit 0 and unit 1, so bits 0 1. $this->assertResult(3, 7, 11, 15); - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->exists("$figures.color") ->notExists("$greetings.value") - ->sort('ftid') + ->sort('id') ->execute(); // Bit 0 or 1 is on but 2 and 3 are not. $this->assertResult(1, 2, 3); // Now update the 'merhaba' string to xsiemax which is not a meaningful // word but allows us to test revisions and string operations. - $ids = $this->factory->get('test_entity') + $ids = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'merhaba') ->execute(); - $entities = entity_load_multiple('test_entity', $ids); + $entities = entity_load_multiple('entity_test_mulrev', $ids); foreach ($entities as $entity) { $entity->setNewRevision(); - $entity->{$greetings}['tr'][0]['value'] = 'xsiemax'; + $entity->getTranslation('tr')->$greetings->value = 'xsiemax'; $entity->save(); } // When querying current revisions, this string is no longer found. - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'merhaba') ->execute(); $this->assertResult(); - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'merhaba') ->age(FIELD_LOAD_REVISION) - ->sort('ftvid') + ->sort('revision_id') ->execute(); // Bit 2 needs to be set. // The keys must be 16-23 because the first batch stopped at 15 so the // second started at 16 and eight entities were saved. $assert = $this->assertRevisionResult(range(16, 23), array(4, 5, 6, 7, 12, 13, 14, 15)); - $results = $this->factory->get('test_entity') + $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'siema', 'CONTAINS') - ->sort('ftid') + ->sort('id') ->execute(); // This is the same as the previous one because xsiemax replaced merhaba // but also it contains the entities that siema originally but not // merhaba. $assert = array_slice($assert, 0, 4, TRUE) + array(8 => '8', 9 => '9', 10 => '10', 11 => '11') + array_slice($assert, 4, 4, TRUE); $this->assertIdentical($results, $assert); - $results = $this->factory->get('test_entity') + $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'siema', 'STARTS_WITH') ->execute(); // Now we only get the ones that originally were siema, entity id 8 and // above. $this->assertIdentical($results, array_slice($assert, 4, 8, TRUE)); - $results = $this->factory->get('test_entity') + $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'a', 'ENDS_WITH') ->execute(); // It is very important that we do not get the ones which only have // xsiemax despite originally they were merhaba, ie. ended with a. $this->assertIdentical($results, array_slice($assert, 4, 8, TRUE)); - $results = $this->factory->get('test_entity') + $results = $this->factory->get('entity_test_mulrev') ->condition("$greetings.value", 'a', 'ENDS_WITH') ->age(FIELD_LOAD_REVISION) - ->sort('ftid') + ->sort('id') ->execute(); // Now we get everything. $this->assertIdentical($results, $assert); @@ -274,18 +294,18 @@ function testSort() { $greetings = $this->greetings; $figures = $this->figures; // Order up and down on a number. - $this->queryResults = $this->factory->get('test_entity') - ->sort('ftid') + $this->queryResults = $this->factory->get('entity_test_mulrev') + ->sort('id') ->execute(); $this->assertResult(range(1, 15)); - $this->queryResults = $this->factory->get('test_entity') - ->sort('ftid', 'DESC') + $this->queryResults = $this->factory->get('entity_test_mulrev') + ->sort('id', 'DESC') ->execute(); $this->assertResult(range(15, 1)); - $query = $this->factory->get('test_entity') + $query = $this->factory->get('entity_test_mulrev') ->sort("$figures.color") ->sort("$greetings.format") - ->sort('ftid'); + ->sort('id'); // As we do not have any conditions, here are the possible colors and // language codes, already in order, with the first occurence of the // entity id marked with *: @@ -328,19 +348,19 @@ function testSort() { // Test the pager by setting element #1 to page 2 with a page size of 4. // Results will be #8-12 from above. $_GET['page'] = '0,2'; - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->sort("$figures.color") ->sort("$greetings.format") - ->sort('ftid') + ->sort('id') ->pager(4, 1) ->execute(); $this->assertResult(15, 6, 7, 1); // Now test the reversed order. - $query = $this->factory->get('test_entity') + $query = $this->factory->get('entity_test_mulrev') ->sort("$figures.color", 'DESC') ->sort("$greetings.format", 'DESC') - ->sort('ftid', 'DESC'); + ->sort('id', 'DESC'); $count_query = clone $query; $this->assertEqual(15, $count_query->count()->execute()); $this->queryResults = $query->execute(); @@ -357,26 +377,26 @@ protected function testTableSort() { $_GET['sort'] = 'asc'; $_GET['order'] = 'Type'; $header = array( - 'id' => array('data' => 'Id', 'specifier' => 'ftid'), - 'type' => array('data' => 'Type', 'specifier' => 'fttype'), + 'id' => array('data' => 'Id', 'specifier' => 'id'), + 'type' => array('data' => 'Type', 'specifier' => 'type'), ); - $this->queryResults = array_values($this->factory->get('test_entity') + $this->queryResults = array_values($this->factory->get('entity_test_mulrev') ->tableSort($header) ->execute()); $this->assertBundleOrder('asc'); $_GET['sort'] = 'desc'; $header = array( - 'id' => array('data' => 'Id', 'specifier' => 'ftid'), - 'type' => array('data' => 'Type', 'specifier' => 'fttype'), + 'id' => array('data' => 'Id', 'specifier' => 'id'), + 'type' => array('data' => 'Type', 'specifier' => 'type'), ); - $this->queryResults = array_values($this->factory->get('test_entity') + $this->queryResults = array_values($this->factory->get('entity_test_mulrev') ->tableSort($header) ->execute()); $this->assertBundleOrder('desc'); // Ordering on ID is definite, however. $_GET['order'] = 'Id'; - $this->queryResults = $this->factory->get('test_entity') + $this->queryResults = $this->factory->get('entity_test_mulrev') ->tableSort($header) ->execute(); $this->assertResult(range(15, 1)); @@ -392,21 +412,21 @@ protected function testCount() { $bundle = $this->randomName(); $instance = array( 'field_name' => $field_name, - 'entity_type' => 'test_entity_bundle', + 'entity_type' => 'entity_test', 'bundle' => $bundle, ); field_create_instance($instance); - $entity = entity_create('test_entity_bundle', array( - 'ftid' => 1, - 'fttype' => $bundle, + $entity = entity_create('entity_test', array( + 'id' => 1, + 'type' => $bundle, )); $entity->enforceIsNew(); $entity->setNewRevision(); $entity->save(); // As the single entity of this type we just saved does not have a value // in the color field, the result should be 0. - $count = $this->factory->get('test_entity_bundle') + $count = $this->factory->get('entity_test') ->exists("$field_name.color") ->count() ->execute(); @@ -461,7 +481,7 @@ protected function assertBundleOrder($order) { * The tags and metadata should propogate to the SQL query object. */ function testMetaData() { - $query = \Drupal::entityQuery('test_entity'); + $query = \Drupal::entityQuery('entity_test_mulrev'); $query ->addTag('efq_metadata_test') ->addMetaData('foo', 'bar') 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 e8c1d9b..745e032 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -134,6 +134,27 @@ function entity_test_entity_bundle_info_alter(&$bundles) { } /** + * Implements hook_entity_view_mode_info_alter(). + */ +function entity_test_entity_view_mode_info_alter(&$view_modes) { + $entity_info = entity_get_info(); + foreach ($entity_info as $entity_type => $info) { + if ($entity_info[$entity_type]['module'] == 'entity_test') { + $view_modes[$entity_type] = array( + 'full' => array( + 'label' => t('Full object'), + 'status' => TRUE, + ), + 'teaser' => array( + 'label' => t('Teaser'), + 'status' => TRUE, + ), + ); + } + } +} + +/** * Implements hook_field_extra_fields(). */ function entity_test_field_extra_fields() { diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php index 185fdab..0ad1da0 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php @@ -51,10 +51,35 @@ public function form(array $form, array &$form_state) { '#languages' => Language::STATE_ALL, ); + // @todo: Is there a better way to check if an entity type is revisionable? + $entity_info = $entity->entityInfo(); + if (!empty($entity_info['entity_keys']['revision']) && !$entity->isNew()) { + $form['revision'] = array( + '#type' => 'checkbox', + '#title' => t('Create new revision'), + '#default_value' => $entity->isNewRevision(), + ); + } + return $form; } /** + * Overrides \Drupal\Core\Entity\EntityFormController::submit(). + */ + public function submit(array $form, array &$form_state) { + // Build the entity object from the submitted values. + $entity = parent::submit($form, $form_state); + + // Save as a new revision if requested to do so. + if (!empty($form_state['values']['revision'])) { + $entity->setNewRevision(); + } + + return $entity; + } + + /** * Overrides Drupal\Core\Entity\EntityFormController::save(). */ public function save(array $form, array &$form_state) { 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 25167c7..1dca5f7 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 @@ -29,6 +29,7 @@ * }, * base_table = "entity_test", * fieldable = TRUE, + * field_cache = FALSE, * entity_keys = { * "id" = "id", * "uuid" = "uuid", 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/EntityTestCache.php similarity index 89% copy from core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php copy to core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTestCache.php index 25167c7..a495998 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/EntityTestCache.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\entity_test\Plugin\Core\Entity\EntityTest. + * Definition of Drupal\entity_test\Plugin\Core\Entity\EntityTestCache. */ namespace Drupal\entity_test\Plugin\Core\Entity; @@ -10,14 +10,13 @@ use Drupal\Core\Entity\EntityNG; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; -use Drupal\Core\Language\Language; /** * Defines the test entity class. * * @EntityType( - * id = "entity_test", - * label = @Translation("Test entity"), + * id = "entity_test_cache", + * label = @Translation("Test entity with field cache"), * module = "entity_test", * controllers = { * "storage" = "Drupal\entity_test\EntityTestStorageController", @@ -29,15 +28,16 @@ * }, * base_table = "entity_test", * fieldable = TRUE, + * field_cache = TRUE, * entity_keys = { * "id" = "id", * "uuid" = "uuid", - * "bundle" = "type" + * "bundle" = "type", * }, * menu_base_path = "entity-test/manage/%entity_test" * ) */ -class EntityTest extends EntityNG { +class EntityTestCache extends EntityNG { /** * The entity ID. @@ -90,7 +90,7 @@ protected function init() { /** * Overrides Drupal\entity\Entity::label(). */ - public function label($langcode = Language::LANGCODE_DEFAULT) { + public function label($langcode = LANGUAGE_DEFAULT) { $info = $this->entityInfo(); if (isset($info['entity_keys']['label']) && $info['entity_keys']['label'] == 'name') { return $this->getTranslation($langcode)->name->value; 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 index e7d4169..0af450b 100644 --- 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 @@ -23,7 +23,7 @@ * field_cache = FALSE, * base_table = "entity_test", * entity_keys = { - * "id" = "ftid", + * "id" = "id", * "bundle" = "type" * } * ) diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 8284e39..f82bce2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -19,7 +19,7 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = array('entity_test'); protected $instance; protected $vocabulary1; @@ -36,7 +36,7 @@ public static function getInfo() { function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy')); + $web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content', 'administer taxonomy')); $this->drupalLogin($web_user); $this->vocabulary1 = $this->createVocabulary(); $this->vocabulary2 = $this->createVocabulary(); @@ -63,16 +63,16 @@ function setUp() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field_name, array( 'type' => 'options_select', )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field_name, array( 'type' => 'taxonomy_term_reference_link', )) @@ -89,21 +89,23 @@ function testTaxonomyTermFieldMultipleVocabularies() { // Submit an entity with both terms. $langcode = Language::LANGCODE_NOT_SPECIFIED; - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is displayed'); $edit = array( + 'user_id' => mt_rand(0, 10), + 'name' => $this->randomName(), "{$this->field_name}[$langcode][]" => array($term1->id(), $term2->id()), ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created.'); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created.'); // Render the entity. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $entities = array($id => $entity); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - field_attach_prepare_view('test_entity', $entities, array($entity->bundle() => $display)); + field_attach_prepare_view('entity_test', $entities, array($entity->bundle() => $display)); $entity->content = field_attach_view($entity, $display); $this->content = drupal_render($entity->content); $this->assertText($term1->label(), 'Term 1 name is displayed.'); @@ -113,10 +115,10 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->vocabulary2->delete(); // Re-render the content. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $entities = array($id => $entity); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - field_attach_prepare_view('test_entity', $entities, array($entity->bundle() => $display)); + field_attach_prepare_view('entity_test', $entities, array($entity->bundle() => $display)); $entity->content = field_attach_view($entity, $display); $this->plainTextContent = FALSE; $this->content = drupal_render($entity->content); @@ -130,11 +132,13 @@ function testTaxonomyTermFieldMultipleVocabularies() { $this->assertEqual(count($field_info['settings']['allowed_values']), 1, 'Only one vocabulary is allowed for the field.'); // The widget should still be displayed. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is still displayed'); // Term 1 should still pass validation. $edit = array( + 'user_id' => mt_rand(0, 10), + 'name' => $this->randomName(), "{$this->field_name}[$langcode][]" => array($term1->id()), ); $this->drupalPost(NULL, $edit, t('Save')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index 541d7be..53a53b1 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -20,7 +20,7 @@ class TermFieldTest extends TaxonomyTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = array('entity_test'); protected $instance; protected $vocabulary; @@ -36,7 +36,11 @@ public static function getInfo() { function setUp() { parent::setUp(); - $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy')); + $web_user = $this->drupalCreateUser(array( + 'view test entity', + 'administer entity_test content', + 'administer taxonomy', + )); $this->drupalLogin($web_user); $this->vocabulary = $this->createVocabulary(); @@ -57,16 +61,16 @@ function setUp() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field_name, array( 'type' => 'options_select', )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field_name, array( 'type' => 'taxonomy_term_reference_link', )) @@ -79,9 +83,9 @@ function setUp() { function testTaxonomyTermFieldValidation() { // Test valid and invalid values with field_attach_validate(). $langcode = Language::LANGCODE_NOT_SPECIFIED; - $entity = field_test_create_entity(); + $entity = entity_create('entity_test', array()); $term = $this->createTerm($this->vocabulary); - $entity->{$this->field_name}[$langcode][0]['tid'] = $term->id(); + $entity->{$this->field_name}->tid = $term->id(); try { field_attach_validate($entity); $this->pass('Correct term does not cause validation error.'); @@ -90,9 +94,9 @@ function testTaxonomyTermFieldValidation() { $this->fail('Correct term does not cause validation error.'); } - $entity = field_test_create_entity(); + $entity = entity_create('entity_test', array()); $bad_term = $this->createTerm($this->createVocabulary()); - $entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->id(); + $entity->{$this->field_name}->tid = $bad_term->id(); try { field_attach_validate($entity); $this->fail('Wrong term causes validation error.'); @@ -111,30 +115,32 @@ function testTaxonomyTermFieldWidgets() { // Display creation form. $langcode = Language::LANGCODE_NOT_SPECIFIED; - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field_name}[$langcode]", '', 'Widget is displayed.'); // Submit with some value. $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field_name}[$langcode]" => array($term->id()), ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created.'); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id))); // Display the object. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $entities = array($id => $entity); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); - field_attach_prepare_view('test_entity', $entities, array($entity->bundle() => $display)); + field_attach_prepare_view('entity_test', $entities, array($entity->bundle() => $display)); $entity->content = field_attach_view($entity, $display); $this->content = drupal_render($entity->content); $this->assertText($term->label(), 'Term label is displayed.'); // Delete the vocabulary and verify that the widget is gone. $this->vocabulary->delete(); - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertNoFieldByName("{$this->field_name}[$langcode]", '', 'Widget is not displayed'); } diff --git a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php index dbc8524..0ecec7b 100644 --- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php @@ -26,7 +26,7 @@ class TextPlainUnitTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('system', 'entity', 'field', 'field_sql_storage', 'text', 'field_test'); + public static $modules = array('entity', 'field', 'field_sql_storage', 'text', 'entity_test', 'system'); /** * Contains rendered content. @@ -48,10 +48,11 @@ function setUp() { // Configure the theme system. $this->installConfig(array('system', 'field')); + $this->installSchema('entity_test', 'entity_test'); // @todo Add helper methods for all of the following. - $this->entity_type = 'test_entity'; + $this->entity_type = 'entity_test'; if (!isset($this->bundle)) { $this->bundle = $this->entity_type; } @@ -126,41 +127,6 @@ protected function renderEntityFields(EntityInterface $entity, EntityDisplay $di } /** - * Sets the item of a field on an entity. - * - * @param \Drupal\Core\Entity\EntityInterface $entity - * The entity object. - * @param string $field_name - * The name of the field. - * @param array $item - * The new field item to set. - * @param int $delta - * (optional) A specific delta to set. If omitted, all field items are - * replaced and $item will be delta 0. - * @param string $langcode - * (optional) A specific langcode for which to the set the field. If - * omitted, $this->langcode is used. - */ - protected function setFieldItem(EntityInterface $entity, $field_name, $item, $delta = NULL, $langcode = NULL) { - if (!isset($langcode)) { - $langcode = $this->langcode; - } - if (!isset($delta)) { - $entity->set($field_name, array( - $langcode => array( - 0 => $item, - ), - )); - } - else { - $property = $entity->get($field_name); - $property[$langcode][$delta] = $item; - ksort($property[$langcode]); - $entity->set($field_name, $property); - } - } - - /** * Formats an assertion message string. * * Unlike format_string(), @@ -332,9 +298,7 @@ function testPlainText() { $value .= "\n\n" . $this->randomString(); $entity = $this->createEntity(array()); - $this->setFieldItem($entity, $this->field_name, array( - 'value' => $value, - )); + $entity->{$this->field_name}->value = $value; // Verify that all HTML is escaped and newlines are retained. $this->renderEntityFields($entity, $this->display); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index 9aed6ee..50cbd45 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -21,7 +21,7 @@ class TextFieldTest extends WebTestBase { * * @var array */ - public static $modules = array('field_test'); + public static $modules = array('entity_test'); protected $instance; protected $admin_user; @@ -39,7 +39,7 @@ function setUp() { parent::setUp(); $this->admin_user = $this->drupalCreateUser(array('administer filters')); - $this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content')); + $this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content')); $this->drupalLogin($this->web_user); } @@ -61,16 +61,16 @@ function testTextFieldValidation() { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field['field_name'], - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', ); field_create_instance($this->instance); // Test valid and invalid values with field_attach_validate(). - $entity = field_test_create_entity(); + $entity = entity_create('entity_test', array()); $langcode = Language::LANGCODE_NOT_SPECIFIED; for ($i = 0; $i <= $max_length + 2; $i++) { - $entity->{$this->field['field_name']}[$langcode][0]['value'] = str_repeat('x', $i); + $entity->{$this->field['field_name']}->value = str_repeat('x', $i); try { field_attach_validate($entity); $this->assertTrue($i <= $max_length, "Length $i does not cause validation error when max_length is $max_length"); @@ -94,21 +94,21 @@ function testTextfieldWidgets() { */ function _testTextfieldWidgets($field_type, $widget_type) { // Setup a field and instance - $entity_type = 'test_entity'; + $entity_type = 'entity_test'; $this->field_name = drupal_strtolower($this->randomName()); $this->field = array('field_name' => $this->field_name, 'type' => $field_type); field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'label' => $this->randomName() . '_label', 'settings' => array( 'text_processing' => TRUE, ), ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field_name, array( 'type' => $widget_type, 'settings' => array( @@ -116,14 +116,14 @@ function _testTextfieldWidgets($field_type, $widget_type) { ), )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field_name) ->save(); $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertNoFieldByName("{$this->field_name}[$langcode][0][format]", '1', 'Format selector is not displayed'); $this->assertRaw(format_string('placeholder="A placeholder on !widget_type"', array('!widget_type' => $widget_type))); @@ -131,18 +131,20 @@ function _testTextfieldWidgets($field_type, $widget_type) { // Submit with some value. $value = $this->randomName(); $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field_name}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); // Display the entity. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $entity->content = field_attach_view($entity, $display); - $this->content = drupal_render($entity->content); + $this->drupalSetContent(drupal_render($entity->content)); $this->assertText($value, 'Filtered tags are not displayed'); } @@ -159,26 +161,25 @@ function testTextfieldWidgetsFormatted() { */ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Setup a field and instance - $entity_type = 'test_entity'; $this->field_name = drupal_strtolower($this->randomName()); $this->field = array('field_name' => $this->field_name, 'type' => $field_type); field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, - 'entity_type' => 'test_entity', - 'bundle' => 'test_bundle', + 'entity_type' => 'entity_test', + 'bundle' => 'entity_test', 'label' => $this->randomName() . '_label', 'settings' => array( 'text_processing' => TRUE, ), ); field_create_instance($this->instance); - entity_get_form_display('test_entity', 'test_bundle', 'default') + entity_get_form_display('entity_test', 'entity_test', 'default') ->setComponent($this->field_name, array( 'type' => $widget_type, )) ->save(); - entity_get_display('test_entity', 'test_bundle', 'full') + entity_get_display('entity_test', 'entity_test', 'full') ->setComponent($this->field_name) ->save(); @@ -195,22 +196,24 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Display the creation form. Since the user only has access to one format, // no format selector will be displayed. - $this->drupalGet('test-entity/add/test_bundle'); + $this->drupalGet('entity_test/add'); $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertNoFieldByName("{$this->field_name}[$langcode][0][format]", '', 'Format selector is not displayed'); // Submit with data that should be filtered. $value = '' . $this->randomName() . ''; $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field_name}[$langcode][0][value]" => $value, ); $this->drupalPost(NULL, $edit, t('Save')); - preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match); + preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match); $id = $match[1]; - $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created'); + $this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created'); // Display the entity. - $entity = field_test_entity_test_load($id); + $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $entity->content = field_attach_view($entity, $display); $this->content = drupal_render($entity->content); @@ -238,20 +241,22 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { // Display edition form. // We should now have a 'text format' selector. - $this->drupalGet('test-entity/manage/' . $id . '/edit'); + $this->drupalGet('entity_test/manage/' . $id . '/edit'); $this->assertFieldByName("{$this->field_name}[$langcode][0][value]", NULL, 'Widget is displayed'); $this->assertFieldByName("{$this->field_name}[$langcode][0][format]", NULL, 'Format selector is displayed'); // Edit and change the text format to the new one that was created. $edit = array( + 'user_id' => 1, + 'name' => $this->randomName(), "{$this->field_name}[$langcode][0][format]" => $format_id, ); $this->drupalPost(NULL, $edit, t('Save')); - $this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), 'Entity was updated'); + $this->assertText(t('entity_test @id has been updated.', array('@id' => $id)), 'Entity was updated'); // Display the entity. - $this->container->get('plugin.manager.entity')->getStorageController('test_entity')->resetCache(array($id)); - $entity = field_test_entity_test_load($id); + $this->container->get('plugin.manager.entity')->getStorageController('entity_test')->resetCache(array($id)); + $entity = entity_load('entity_test', $id); $display = entity_get_display($entity->entityType(), $entity->bundle(), 'full'); $entity->content = field_attach_view($entity, $display); $this->content = drupal_render($entity->content);