Commit 3b4548f9 authored by webchick's avatar webchick
Browse files

Issue #1825568 by alexpott, fago, Berdir: Fixed Random test failure in...

Issue #1825568 by alexpott, fago, Berdir: Fixed Random test failure in Drupal\system\Tests\Entity\EntityFormTest.
parent 933b67c4
......@@ -68,16 +68,12 @@ public function getValue() {
* An array of values of the field items.
*/
public function setValue($values) {
// Support passing in only the value of the first item.
if (!is_array($values) || (!empty($values) && !is_numeric(current(array_keys($values))))) {
$values = array(0 => $values);
}
if (!is_array($values)) {
throw new InvalidArgumentException("An entity field requires a numerically indexed array of items as value.");
}
if (isset($values) && $values !== array()) {
// Support passing in only the value of the first item.
if (!is_array($values) || !is_numeric(current(array_keys($values)))) {
$values = array(0 => $values);
}
if (!empty($values)) {
if (!is_array($values)) {
throw new InvalidArgumentException("An entity field requires a numerically indexed array of items as value.");
}
......
......@@ -210,6 +210,16 @@ public function testReadWrite() {
$this->assertEqual(count(iterator_to_array($entity->name->getIterator())), count($entity->name), 'Count matches iterator count.');
$this->assertTrue($entity->name->getValue() === array(0 => NULL), 'Name field value contains a NULL value.');
// Test removing all list items by assigning an empty array.
$entity->name = array();
$this->assertIdentical(count($entity->name), 0, 'Name field contains no items.');
$this->assertIdentical($entity->name->getValue(), array(), 'Name field value is an empty array.');
// Test removing all list items by setting it to NULL.
$entity->name = NULL;
$this->assertIdentical(count($entity->name), 0, 'Name field contains no items.');
$this->assertIdentical($entity->name->getValue(), array(), 'Name field value is an empty array.');
// Test get and set field values.
$entity->name = 'foo';
$this->assertEqual($entity->name[0]->getPropertyValues(), array('value' => 'foo'), 'Field value has been retrieved via getPropertyValue()');
......@@ -230,6 +240,15 @@ public function testReadWrite() {
));
$this->assertNotNull($entity->user_id->value, 'User id is not NULL');
$this->assertIdentical($entity->user_id->value, 0, 'User id has been set to 0');
// Test setting the ID with the value only.
$entity = entity_create('entity_test', array(
'name' => $name_item,
'user_id' => 0,
'field_test_text' => $text_item,
));
$this->assertNotNull($entity->user_id->value, 'User id is not NULL');
$this->assertIdentical($entity->user_id->value, 0, 'User id has been set to 0');
}
/**
......
......@@ -171,15 +171,6 @@ function testEntityLanguageMethods() {
$entity->getTranslation($this->langcodes[1], FALSE)->set($field_name, array(0 => array('value' => 'default value2')));
// Get the value.
$this->assertEqual($entity->get($field_name)->value, 'default value2', 'Untranslated value set into a translation in non-strict mode.');
// Test setting the user_id to 0 using setValue method.
$entity = entity_create('entity_test', array(
'name' => 'test',
'user_id' => $GLOBALS['user']->uid,
));
$translation = $entity->getTranslation($this->langcodes[1], FALSE);
$translation->user_id->setValue(0);
$this->assertIdentical($entity->get('user_id')->value, 0);
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment