Skip to content
Snippets Groups Projects
Commit 764890d6 authored by Alex Bronstein's avatar Alex Bronstein
Browse files

Issue #2349819 by amateescu, swentel, Leksat, larowlan, dawehner, Gábor...

Issue #2349819 by amateescu, swentel, Leksat, larowlan, dawehner, Gábor Hojtsy, mpdonadio, benjy, jmuzz, yched, jibran, marthinal, dmsmidt: String field type doesn't consider empty string as empty value
parent 8dc9763d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Showing
with 86 additions and 14 deletions
......@@ -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;
}
}
......@@ -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 === '';
}
}
......@@ -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));
}
......
......@@ -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.
......
......@@ -44,6 +44,7 @@ protected function setUp() {
$node = entity_create('node', array(
'type' => 'story',
'nid' => 1,
'title' => $this->randomString(),
));
$node->enforceIsNew();
$node->save();
......
......@@ -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,
......
......@@ -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);
......
......@@ -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);
......
......@@ -84,6 +84,7 @@ protected function setUp() {
'type' => 'story',
'nid' => $i,
'vid' => array_shift($vids),
'title' => $this->randomString(),
));
$node->enforceIsNew();
$node->save();
......
......@@ -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]);
......
......@@ -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);
......
......@@ -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',
......
......@@ -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',
......
......@@ -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)) {
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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.
......
......@@ -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();
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment