Issue #1825568 by alexpott: Fixed Random test failure in Drupal\system\Tests\Entity\EntityFormTest.

8.0.x
catch 2012-10-29 11:57:49 +00:00
parent 1943fb6167
commit b2ca0f4148
3 changed files with 19 additions and 7 deletions

View File

@ -68,13 +68,16 @@ class Field extends TypedData implements IteratorAggregate, FieldInterface {
* 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 (!empty($values)) {
// 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 (!is_array($values)) {
throw new InvalidArgumentException("An entity field requires a numerically indexed array of items as value.");
}

View File

@ -41,7 +41,7 @@ class EntityFormTest extends WebTestBase {
function testFormCRUD() {
$langcode = LANGUAGE_NOT_SPECIFIED;
$name1 = $this->randomName(8);
$name2 = $this->randomName(8);
$name2 = $this->randomName(10);
$edit = array(
'name' => $name1,

View File

@ -171,6 +171,15 @@ class EntityTranslationTest extends WebTestBase {
$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);
}
/**