Commit b2ca0f41 authored by catch's avatar catch
Browse files

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

parent 1943fb61
......@@ -68,13 +68,16 @@ public function getValue() {
* An array of values of the field items.
*/
public function setValue($values) {
if (!empty($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);
}
// 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.");
}
if (!empty($values)) {
if (!is_array($values)) {
throw new InvalidArgumentException("An entity field requires a numerically indexed array of items as value.");
}
......
......@@ -41,7 +41,7 @@ function setUp() {
function testFormCRUD() {
$langcode = LANGUAGE_NOT_SPECIFIED;
$name1 = $this->randomName(8);
$name2 = $this->randomName(8);
$name2 = $this->randomName(10);
$edit = array(
'name' => $name1,
......
......@@ -171,6 +171,15 @@ 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