diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php index 7de771abf5d47523bda07cb9a91e634598c3004b..621bb63f8459b4a013a68ebc48b4a2fe3c3d9cf9 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php @@ -63,4 +63,16 @@ public function preSave() { } } } + + /** + * {@inheritdoc} + */ + public function isEmpty() { + // We cannot use the parent implementation from StringItem as it does not + // consider the additional 'existing' property that PasswordItem contains. + $value = $this->get('value')->getValue(); + $existing = $this->get('existing')->getValue(); + return $value === NULL && $existing === NULL; + } + } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php index 4772983e2b7477960c743bd448fead1e366a5320..065310c000e555b49f673c75613666158e2e7f0f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php @@ -40,4 +40,12 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel return $properties; } + /** + * {@inheritdoc} + */ + public function isEmpty() { + $value = $this->get('value')->getValue(); + return $value === NULL || $value === ''; + } + } diff --git a/core/modules/aggregator/src/Tests/FeedProcessorPluginTest.php b/core/modules/aggregator/src/Tests/FeedProcessorPluginTest.php index 5142da58d48547d99deea3909bc423c8d215f78c..2584021e5322ac747352a172e78b58fc42045fe4 100644 --- a/core/modules/aggregator/src/Tests/FeedProcessorPluginTest.php +++ b/core/modules/aggregator/src/Tests/FeedProcessorPluginTest.php @@ -47,9 +47,10 @@ public function testProcess() { */ public function testDelete() { $feed = $this->createFeed(); + $description = $feed->description->value ?: ''; $this->updateAndDelete($feed, NULL); // Make sure the feed title is changed. - $entities = entity_load_multiple_by_properties('aggregator_feed', array('description' => $feed->description->value)); + $entities = entity_load_multiple_by_properties('aggregator_feed', array('description' => $description)); $this->assertTrue(empty($entities)); } diff --git a/core/modules/book/src/Tests/BookUninstallTest.php b/core/modules/book/src/Tests/BookUninstallTest.php index c3739d8c4b7b855c333bdff070517386943eb66a..2d2f7dae4c33fce54cd36f16fedcd1894c1b3588 100644 --- a/core/modules/book/src/Tests/BookUninstallTest.php +++ b/core/modules/book/src/Tests/BookUninstallTest.php @@ -57,7 +57,7 @@ public function testBookUninstall() { $allowed_types[] = $content_type->id(); $book_config->set('allowed_types', $allowed_types)->save(); - $node = Node::create(array('type' => $content_type->id())); + $node = Node::create(array('title' => $this->randomString(), 'type' => $content_type->id())); $node->book['bid'] = 'new'; $node->save(); @@ -65,7 +65,7 @@ public function testBookUninstall() { $validation_reasons = \Drupal::service('module_installer')->validateUninstall(['book']); $this->assertEqual(['To uninstall Book, delete all content that is part of a book'], $validation_reasons['book']); - $book_node = Node::create(array('type' => 'book')); + $book_node = Node::create(array('title' => $this->randomString(), 'type' => 'book')); $book_node->book['bid'] = FALSE; $book_node->save(); @@ -84,7 +84,7 @@ public function testBookUninstall() { $module_data = _system_rebuild_module_data(); $this->assertFalse(isset($module_data['book']->info['required']), 'The book module is not required.'); - $node = Node::create(array('type' => $content_type->id())); + $node = Node::create(array('title' => $this->randomString(), 'type' => $content_type->id())); $node->save(); // One node exists but is not part of a book therefore the book module is // not required. diff --git a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php index cd23f6ac2e4503da4abdd8d556364ff39f285bea..fb280743afcf1757d49e81671a2dcebdbbd24617 100644 --- a/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php +++ b/core/modules/comment/src/Tests/Migrate/d6/MigrateCommentTest.php @@ -44,6 +44,7 @@ protected function setUp() { $node = entity_create('node', array( 'type' => 'story', 'nid' => 1, + 'title' => $this->randomString(), )); $node->enforceIsNew(); $node->save(); diff --git a/core/modules/comment/src/Tests/Views/CommentUserNameTest.php b/core/modules/comment/src/Tests/Views/CommentUserNameTest.php index 8b05c84df8229e68f4dc3225f8a36d893bc8db4b..e26d7dc0bd798f3f7457902e406698297c74a604 100644 --- a/core/modules/comment/src/Tests/Views/CommentUserNameTest.php +++ b/core/modules/comment/src/Tests/Views/CommentUserNameTest.php @@ -50,6 +50,7 @@ protected function setUp($import_test_views = TRUE) { $storage ->create(array( 'uid' => 0, + 'name' => '', 'status' => 0, )) ->save(); @@ -75,6 +76,7 @@ protected function setUp($import_test_views = TRUE) { $comment = Comment::create([ 'subject' => 'My comment title', 'uid' => $this->adminUser->id(), + 'name' => $this->adminUser->label(), 'entity_type' => 'entity_test', 'comment_type' => 'entity_test', 'status' => 1, diff --git a/core/modules/content_translation/src/Tests/ContentTranslationMetadataFieldsTest.php b/core/modules/content_translation/src/Tests/ContentTranslationMetadataFieldsTest.php index 437be686da64bd087afde564c9d2f688351615fe..4c18c95e6c3aed34d067a68324dc2736b91334b0 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationMetadataFieldsTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationMetadataFieldsTest.php @@ -61,7 +61,7 @@ public function testSkipUntranslatable() { // Create a new test entity with original values in the default language. $default_langcode = $this->langcodes[0]; - $entity_id = $this->createEntity([], $default_langcode); + $entity_id = $this->createEntity(['title' => $this->randomString()], $default_langcode); $storage = $entity_manager->getStorage($this->entityTypeId); $storage->resetCache(); $entity = $storage->load($entity_id); @@ -118,7 +118,7 @@ public function testSetTranslatable() { // Create a new test entity with original values in the default language. $default_langcode = $this->langcodes[0]; - $entity_id = $this->createEntity(['status' => FALSE], $default_langcode); + $entity_id = $this->createEntity(['title' => $this->randomString(), 'status' => FALSE], $default_langcode); $storage = $entity_manager->getStorage($this->entityTypeId); $storage->resetCache(); $entity = $storage->load($entity_id); diff --git a/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php b/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php index b8ed11c37af176806436035d8306f74282e66070..38955ab63b6a8b21627e77d1efb98fbc34c3ec15 100644 --- a/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php +++ b/core/modules/contextual/src/Tests/ContextualDynamicContextTest.php @@ -134,7 +134,7 @@ function testDifferentPermissions() { $this->assertResponse(403); // Verify that link language is properly handled. - $node3->addTranslation('it')->save(); + $node3->addTranslation('it')->set('title', $this->randomString())->save(); $id = 'node:node=' . $node3->id() . ':changed=' . $node3->getChangedTime() . '&langcode=it'; $this->drupalGet('node', ['language' => ConfigurableLanguage::createFromLangcode('it')]); $this->assertContextualLinkPlaceHolder($id); diff --git a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadBase.php b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadBase.php index 5cff822212efb14a5fbbd9b23655878c6a92b65e..60579195fcf2f15018e9eb52e8c7c9accd388721 100644 --- a/core/modules/file/src/Tests/Migrate/d6/MigrateUploadBase.php +++ b/core/modules/file/src/Tests/Migrate/d6/MigrateUploadBase.php @@ -84,6 +84,7 @@ protected function setUp() { 'type' => 'story', 'nid' => $i, 'vid' => array_shift($vids), + 'title' => $this->randomString(), )); $node->enforceIsNew(); $node->save(); diff --git a/core/modules/hal/src/Tests/EntityTest.php b/core/modules/hal/src/Tests/EntityTest.php index 85d13f77628bcae1a7fff367f378d6a3a3b32292..6301fb05a5c88dce57012a0b9633732eb001def1 100644 --- a/core/modules/hal/src/Tests/EntityTest.php +++ b/core/modules/hal/src/Tests/EntityTest.php @@ -198,7 +198,8 @@ public function testComment() { $original_values = $comment->toArray(); // cid will not exist and hostname will always be denied view access. - unset($original_values['cid'], $original_values['hostname']); + // No value will exist for name as this is only for anonymous users. + unset($original_values['cid'], $original_values['hostname'], $original_values['name']); $normalized = $this->serializer->normalize($comment, $this->format, ['account' => $account]); diff --git a/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php b/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php index 5fd0cbfc33dc0ed7a178a756d07ddeb296ff389f..94971ca77811cb1b9c0c95a3cb94a61e979cb942 100644 --- a/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php +++ b/core/modules/menu_link_content/src/Tests/Migrate/d6/MigrateMenuLinkTest.php @@ -69,7 +69,7 @@ public function testMenuLinks() { $menu_link = entity_load('menu_link_content', 140); $this->assertIdentical('Drupal.org', $menu_link->getTitle()); $this->assertIdentical('secondary-links', $menu_link->getMenuName()); - $this->assertIdentical('', $menu_link->getDescription()); + $this->assertIdentical(NULL, $menu_link->getDescription()); $this->assertIdentical(TRUE, $menu_link->isEnabled()); $this->assertIdentical(FALSE, $menu_link->isExpanded()); $this->assertIdentical(['attributes' => ['title' => '']], $menu_link->link->options); @@ -80,7 +80,7 @@ public function testMenuLinks() { $menu_link = entity_load('menu_link_content', 393); $this->assertIdentical('Test 3', $menu_link->getTitle()); $this->assertIdentical('secondary-links', $menu_link->getMenuName()); - $this->assertIdentical('', $menu_link->getDescription()); + $this->assertIdentical(NULL, $menu_link->getDescription()); $this->assertIdentical(TRUE, $menu_link->isEnabled()); $this->assertIdentical(FALSE, $menu_link->isExpanded()); $this->assertIdentical([], $menu_link->link->options); diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php index 02e54602c24b435fe707b6f1dde07de452d87231..d16b1d3a22e511a38a0e2229f020da918c1e496b 100644 --- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php +++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCckFieldValuesTest.php @@ -33,6 +33,35 @@ protected function setUp() { $this->installEntitySchema('file'); + $node = entity_create('node', array( + 'type' => 'story', + 'nid' => 2, + 'vid' => 12, + 'revision_log' => '', + 'title' => $this->randomString(), + )); + $node->enforceIsNew(); + $node->save(); + + $planet_nodes = [ + 4 => 6, + 5 => 8, + 6 => 9, + 7 => 10, + 8 => 11, + ]; + foreach ($planet_nodes as $nid => $vid) { + $node = entity_create('node', array( + 'type' => 'test_planet', + 'nid' => $nid, + 'vid' => $vid, + 'revision_log' => '', + 'title' => $this->randomString(), + )); + $node->enforceIsNew(); + $node->save(); + } + entity_create('field_storage_config', array( 'entity_type' => 'node', 'field_name' => 'field_test', diff --git a/core/modules/node/src/Entity/Node.php b/core/modules/node/src/Entity/Node.php index 0588ab0974470586030d272193849611ddc5bdaf..84a657b0b0e152341ff459114f4a4cc02cc50d77 100644 --- a/core/modules/node/src/Entity/Node.php +++ b/core/modules/node/src/Entity/Node.php @@ -387,7 +387,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setRequired(TRUE) ->setTranslatable(TRUE) ->setRevisionable(TRUE) - ->setDefaultValue('') ->setSetting('max_length', 255) ->setDisplayOptions('view', array( 'label' => 'hidden', diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php index 2b07bfb047f59829ac781bcbf320cc4ac1780f4a..ab27ac8a03f0f4824de33dcb48701cda4424567e 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTest.php @@ -55,7 +55,7 @@ public function testNode() { $this->assertIdentical('Test title', $node_revision->getTitle()); $this->assertIdentical('1', $node_revision->getRevisionAuthor()->id(), 'Node revision has the correct user'); // This is empty on the first revision. - $this->assertIdentical('', $node_revision->revision_log->value); + $this->assertIdentical(NULL, $node_revision->revision_log->value); // It is pointless to run the second half from MigrateDrupal6Test. if (empty($this->standalone)) { diff --git a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php index a47df1f3aa996b74c1f63af4dff7779f0de4191a..6bae2833b6959a116807f0f538c22d9053b5c9de 100644 --- a/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php +++ b/core/modules/node/src/Tests/Migrate/d6/MigrateNodeTestBase.php @@ -82,6 +82,7 @@ protected function setUp() { 'nid' => 1, 'vid' => 1, 'revision_log' => '', + 'title' => $this->randomString(), )); $node->enforceIsNew(); $node->save(); @@ -91,6 +92,7 @@ protected function setUp() { 'nid' => 3, 'vid' => 4, 'revision_log' => '', + 'title' => $this->randomString(), )); $node->enforceIsNew(); $node->save(); diff --git a/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php b/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php index 62a7b0c6f7443cfd2cc082d7c356a73b1e7933ac..d60cf6ff67732f15507c452677a72036fccb0bad 100644 --- a/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php +++ b/core/modules/node/src/Tests/NodeAccessLanguageAwareCombinationTest.php @@ -111,6 +111,7 @@ protected function setUp() { 'private' => FALSE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 0; $node->save(); @@ -121,6 +122,7 @@ protected function setUp() { 'private' => TRUE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 0; $node->save(); @@ -131,6 +133,7 @@ protected function setUp() { 'private' => FALSE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 0; $node->save(); @@ -141,6 +144,7 @@ protected function setUp() { 'private' => FALSE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 1; $node->save(); @@ -151,6 +155,7 @@ protected function setUp() { 'private' => FALSE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 1; $node->save(); @@ -161,6 +166,7 @@ protected function setUp() { 'private' => TRUE, )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 1; $node->save(); diff --git a/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php b/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php index 135161711ad1fa9e6b1c11d5b8ad378ad86af93c..81ecbd1304f0f3a64e4152174f97102b4070abbe 100644 --- a/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php +++ b/core/modules/node/src/Tests/NodeAccessLanguageAwareTest.php @@ -104,6 +104,7 @@ protected function setUp() { 'field_private' => array(array('value' => 0)), )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 0; $node->save(); @@ -113,6 +114,7 @@ protected function setUp() { 'field_private' => array(array('value' => 0)), )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 1; $node->save(); @@ -122,6 +124,7 @@ protected function setUp() { 'field_private' => array(array('value' => 1)), )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 0; $node->save(); @@ -131,6 +134,7 @@ protected function setUp() { 'field_private' => array(array('value' => 1)), )); $translation = $node->getTranslation('ca'); + $translation->title->value = $this->randomString(); $translation->field_private->value = 1; $node->save(); diff --git a/core/modules/node/src/Tests/NodeValidationTest.php b/core/modules/node/src/Tests/NodeValidationTest.php index b38af1c52521df0dcb143ea0fa9865dec43aa0f0..9f6bccc88204582281c9851fa922a65feeab56c9 100644 --- a/core/modules/node/src/Tests/NodeValidationTest.php +++ b/core/modules/node/src/Tests/NodeValidationTest.php @@ -55,6 +55,11 @@ public function testValidation() { $this->assertEqual($violations[0]->getPropertyPath(), 'title'); $this->assertEqual($violations[0]->getMessage(), 'This value should not be null.'); + $node->set('title', ''); + $violations = $node->validate(); + $this->assertEqual(count($violations), 1, 'Violation found when title is set to an empty string.'); + $this->assertEqual($violations[0]->getPropertyPath(), 'title'); + // Make the title valid again. $node->set('title', $this->randomString()); // Save the node so that it gets an ID and a changed date. diff --git a/core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php b/core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php index 7e1209b5aefd41079e169f958404060e4958e2f4..7f7ecddbef983e8f20dd3e5569169c1351e89155 100644 --- a/core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php +++ b/core/modules/node/src/Tests/Views/NodeRevisionWizardTest.php @@ -26,7 +26,7 @@ public function testViewAdd() { // Create two nodes with two revision. $node_storage = \Drupal::entityManager()->getStorage('node'); /** @var \Drupal\node\NodeInterface $node */ - $node = $node_storage->create(array('type' => 'article', 'created' => REQUEST_TIME + 40)); + $node = $node_storage->create(array('title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 40)); $node->save(); $node = $node->createDuplicate(); @@ -34,7 +34,7 @@ public function testViewAdd() { $node->created->value = REQUEST_TIME + 20; $node->save(); - $node = $node_storage->create(array('type' => 'article', 'created' => REQUEST_TIME + 30)); + $node = $node_storage->create(array('title' => $this->randomString(), 'type' => 'article', 'created' => REQUEST_TIME + 30)); $node->save(); $node = $node->createDuplicate(); diff --git a/core/modules/options/src/Tests/Views/OptionsTestBase.php b/core/modules/options/src/Tests/Views/OptionsTestBase.php index 671216000486376099c13b434955f1381438a262..b204d1bb5056b59798d504f8422d4b9c2e26e09b 100644 --- a/core/modules/options/src/Tests/Views/OptionsTestBase.php +++ b/core/modules/options/src/Tests/Views/OptionsTestBase.php @@ -56,6 +56,7 @@ protected function setUp() { $settings = []; $settings['type'] = 'article'; + $settings['title'] = $this->randomString(); $settings['field_test_list_string'][]['value'] = $this->fieldValues[0]; $settings['field_test_list_integer'][]['value'] = 0; diff --git a/core/modules/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php index 108bbc90056af51c65e47a722ac3688aacd67117..ba6af7802706e0b269bbf9fa8cc59fd614c65d28 100644 --- a/core/modules/shortcut/src/Entity/Shortcut.php +++ b/core/modules/shortcut/src/Entity/Shortcut.php @@ -132,7 +132,6 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The name of the shortcut.')) ->setRequired(TRUE) ->setTranslatable(TRUE) - ->setDefaultValue('') ->setSetting('max_length', 255) ->setDisplayOptions('form', array( 'type' => 'string_textfield', diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php index 308132da4c9f4b2fa16d843b4c9285ef9039610e..541473014520ba796e7e5a746f68d252737afac4 100644 --- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php @@ -677,6 +677,7 @@ public function testEntityConstraintValidation() { $node = entity_create('node', array( 'type' => 'page', 'uid' => $user->id(), + 'title' => $this->randomString(), )); $reference->setValue($node); $violations = $reference->validate(); @@ -699,6 +700,7 @@ public function testEntityConstraintValidation() { $node = entity_create('node', array( 'type' => 'article', 'uid' => $user->id(), + 'title' => $this->randomString(), )); $node->save(); $reference->setValue($node); diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php index fc5c89222e8818aef91743ef2e001d660ea1d17f..4ff9f2204131dd2972c759aa783bbebd87a17bd1 100644 --- a/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/src/Tests/Entity/EntityTranslationFormTest.php @@ -106,6 +106,7 @@ function testEntityFormLanguage() { // Create a body translation and check the form language. $langcode2 = $this->langcodes[1]; + $node->getTranslation($langcode2)->title->value = $this->randomString(); $node->getTranslation($langcode2)->body->value = $this->randomMachineName(16); $node->getTranslation($langcode2)->setOwnerId($web_user->id()); $node->save(); diff --git a/core/modules/system/src/Tests/Module/UninstallTest.php b/core/modules/system/src/Tests/Module/UninstallTest.php index 4f5e1939bc652248d7a029d9087bd4d6c40e06a2..4b8df60cd72a79079c1fd7d29db3af49b00dd273 100644 --- a/core/modules/system/src/Tests/Module/UninstallTest.php +++ b/core/modules/system/src/Tests/Module/UninstallTest.php @@ -51,7 +51,7 @@ function testUninstallPage() { $node_type->setThirdPartySetting('module_test', 'key', 'value'); $node_type->save(); // Add a node to prevent node from being uninstalled. - $node = entity_create('node', array('type' => 'uninstall_blocker')); + $node = entity_create('node', array('type' => 'uninstall_blocker', 'title' => $this->randomString())); $node->save(); $this->drupalGet('admin/modules/uninstall'); diff --git a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTestBase.php b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTestBase.php index 0d51f6456718b0211676258dcc76d7e9fc3bc59b..2a47cea124156453d1029c6175bb7eaeaac34260 100644 --- a/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTestBase.php +++ b/core/modules/taxonomy/src/Tests/Migrate/d6/MigrateTermNodeTestBase.php @@ -71,6 +71,7 @@ protected function setUp() { 'type' => 'story', 'nid' => $i, 'vid' => array_shift($vids), + 'title' => $this->randomString(), )); $node->enforceIsNew(); $node->save(); diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index 53155a0196138fe0179a477976c2d069831f37b5..3716d011ca7cf76f8cd6918fccb0a4cb9230bf09 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -463,13 +463,14 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['name'] = BaseFieldDefinition::create('string') ->setLabel(t('Name')) ->setDescription(t('The name of this user.')) - ->setDefaultValue('') + ->setRequired(TRUE) ->setConstraints(array( // No Length constraint here because the UserName constraint also covers // that. 'UserName' => array(), 'UserNameUnique' => array(), )); + $fields['name']->getItemDefinition()->setClass('\Drupal\user\UserNameItem'); $fields['pass'] = BaseFieldDefinition::create('password') ->setLabel(t('Password')) diff --git a/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php b/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php index 567ae06923c7e815a8bde1efeec6a7316809206f..ef92e112cab63e8a4c8d2d978ad1256ef9532d35 100644 --- a/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php +++ b/core/modules/user/src/Tests/Condition/UserRoleConditionTest.php @@ -88,6 +88,7 @@ protected function setUp() { // Setup an anonymous user for our tests. $this->anonymous = User::create(array( + 'name' => '', 'uid' => 0, )); $this->anonymous->save(); diff --git a/core/modules/user/src/Tests/UserRoleDeleteTest.php b/core/modules/user/src/Tests/UserRoleDeleteTest.php index 99750460d4f96736cea79f7bf843dbdcc24f4fc0..81396ac952a99f64ce372e033ca8dfeeca3750a4 100644 --- a/core/modules/user/src/Tests/UserRoleDeleteTest.php +++ b/core/modules/user/src/Tests/UserRoleDeleteTest.php @@ -42,8 +42,9 @@ public function testRoleDeleteUserRoleReferenceDelete() { // Create user and assign both test roles. $values = array( - 'uid' => 1, - 'roles' => array('test_role_one', 'test_role_two'), + 'uid' => 1, + 'name' => $this->randomString(), + 'roles' => array('test_role_one', 'test_role_two'), ); $user = User::create($values); $user->save(); diff --git a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php index 42f9b429547dfbebb90049318745af9b5bc2dcbc..922501f08073f31defa83349fb8b2a6cd3299757 100644 --- a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php +++ b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php @@ -41,6 +41,8 @@ public function testUserName() { $this->executeView($view); $anon_name = $this->config('user.settings')->get('anonymous'); + $view->result[0]->_entity->setUsername(''); + $view->result[0]->_entity->uid->value = 0; $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) { return $view->field['name']->advancedRender($view->result[0]); }); diff --git a/core/modules/user/src/Tests/Views/UserKernelTestBase.php b/core/modules/user/src/Tests/Views/UserKernelTestBase.php index 6b92ae232072608e882b4c007256a84dbdf9ad3a..fa26cf2b0e98b435dc7931154489c7d87613324c 100644 --- a/core/modules/user/src/Tests/Views/UserKernelTestBase.php +++ b/core/modules/user/src/Tests/Views/UserKernelTestBase.php @@ -74,7 +74,7 @@ protected function setupPermissionTestData() { user_role_grant_permissions('multiple_permissions', array('administer permissions', 'administer users', 'access user profiles')); // Setup a user without an extra role. - $this->users[] = $account = $this->userStorage->create(array()); + $this->users[] = $account = $this->userStorage->create(['name' => $this->randomString()]); $account->save(); // Setup a user with just the first role (so no permission beside the // ones from the authenticated role). diff --git a/core/modules/user/src/UserNameItem.php b/core/modules/user/src/UserNameItem.php new file mode 100644 index 0000000000000000000000000000000000000000..4e2852b6bdc3ac59e957d888f27ddd29b4918a50 --- /dev/null +++ b/core/modules/user/src/UserNameItem.php @@ -0,0 +1,31 @@ +<?php + +/** + * @file + * Contains \Drupal\user\UserNameItem. + */ + +namespace Drupal\user; + +use Drupal\Core\Field\Plugin\Field\FieldType\StringItem; + +/** + * Defines a custom field item class for the 'name' user entity field. + */ +class UserNameItem extends StringItem { + + /** + * {@inheritdoc} + */ + public function isEmpty() { + $value = $this->get('value')->getValue(); + + // Take into account that the name of the anonymous user is an empty string. + if ($this->getEntity()->isAnonymous()) { + return $value === NULL; + } + + return $value === NULL || $value === ''; + } + +} diff --git a/core/modules/user/user.install b/core/modules/user/user.install index dd55b49398c8eb04fe333865dba0f8259c0d3aa2..91a908ed0f0b5fdb3afb51955328b39ba06632c8 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -70,6 +70,7 @@ function user_install() { ->create(array( 'uid' => 0, 'status' => 0, + 'name' => '', )) ->save(); diff --git a/core/modules/views/src/Tests/Entity/FieldEntityTest.php b/core/modules/views/src/Tests/Entity/FieldEntityTest.php index 7790bd57e3a9168e1422e83332629d36986ca0ff..925ed10853babda64d31b7e9a189d18a7906b26c 100644 --- a/core/modules/views/src/Tests/Entity/FieldEntityTest.php +++ b/core/modules/views/src/Tests/Entity/FieldEntityTest.php @@ -57,7 +57,7 @@ public function testGetEntity() { $account = entity_create('user', array('name' => $this->randomMachineName(), 'bundle' => 'user')); $account->save(); - $node = entity_create('node', array('uid' => $account->id(), 'type' => 'page')); + $node = entity_create('node', array('uid' => $account->id(), 'type' => 'page', 'title' => $this->randomString())); $node->save(); $comment = entity_create('comment', array( 'uid' => $account->id(), diff --git a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php index 808c8a44613bc2265cab7d8436d0920c8a24a049..9be30df02779b215b02197866a2e4ebce120a333 100644 --- a/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php +++ b/core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php @@ -60,7 +60,7 @@ protected function setUp() { foreach ($this->entityBundles as $key => $info) { for ($i = 0; $i < 5; $i++) { - $entity = entity_create('node', array('label' => $this->randomMachineName(), 'uid' => 1, 'type' => $key)); + $entity = entity_create('node', array('title' => $this->randomString(), 'uid' => 1, 'type' => $key)); $entity->save(); $this->entities[$key][$entity->id()] = $entity; $this->entities['count']++; diff --git a/core/modules/views/src/Tests/Handler/FieldFieldTest.php b/core/modules/views/src/Tests/Handler/FieldFieldTest.php index 611c16154c5126f8df536c7091c002eff6c2e8ac..dd77cb746fd71014fdad29a80cf82a03f9c493cc 100644 --- a/core/modules/views/src/Tests/Handler/FieldFieldTest.php +++ b/core/modules/views/src/Tests/Handler/FieldFieldTest.php @@ -74,7 +74,7 @@ protected function setUp() { $this->installEntitySchema('entity_test_rev'); // Bypass any field access. - $this->adminUser = User::create(); + $this->adminUser = User::create(['name' => $this->randomString()]); $this->adminUser->save(); $this->container->get('current_user')->setAccount($this->adminUser);