Commit 4ce3ff3d authored by webchick's avatar webchick
Browse files

#371363 by yched: Fix field form tests from randomly breaking. Hooray.

parent b6ad2af7
...@@ -53,7 +53,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -53,7 +53,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
$values[$evid] = array(); $values[$evid] = array();
// Note: we insert one extra value ('<=' instead of '<'). // Note: we insert one extra value ('<=' instead of '<').
for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) {
$value = mt_rand(0, 127); $value = mt_rand(1, 127);
$values[$evid][] = $value; $values[$evid][] = $value;
$query->values(array($etid, $eid, $evid, $delta, $value)); $query->values(array($etid, $eid, $evid, $delta, $value));
} }
...@@ -112,7 +112,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -112,7 +112,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
// Note: we try to insert one extra value ('<=' instead of '<'). // Note: we try to insert one extra value ('<=' instead of '<').
// TODO : test empty values filtering and "compression" (store consecutive deltas). // TODO : test empty values filtering and "compression" (store consecutive deltas).
for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $rev_values[0] = $values; $entity->{$this->field_name} = $rev_values[0] = $values;
field_attach_insert($entity_type, $entity); field_attach_insert($entity_type, $entity);
...@@ -132,7 +132,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -132,7 +132,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
$values = array(); $values = array();
// Note: we try to update one extra value ('<=' instead of '<'). // Note: we try to update one extra value ('<=' instead of '<').
for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) { for ($delta = 0; $delta <= $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $rev_values[1] = $values; $entity->{$this->field_name} = $rev_values[1] = $values;
field_attach_update($entity_type, $entity); field_attach_update($entity_type, $entity);
...@@ -223,7 +223,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -223,7 +223,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
// Populate values to be displayed. // Populate values to be displayed.
$values = array(); $values = array();
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $values; $entity->{$this->field_name} = $values;
...@@ -321,7 +321,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -321,7 +321,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
// Create revision 0 // Create revision 0
$values = array(); $values = array();
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$rev[0]->{$this->field_name} = $values; $rev[0]->{$this->field_name} = $values;
field_attach_insert($entity_type, $rev[0]); field_attach_insert($entity_type, $rev[0]);
...@@ -382,7 +382,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -382,7 +382,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$values = array(); $values = array();
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $values; $entity->{$this->field_name} = $values;
$entity_type = 'test_entity'; $entity_type = 'test_entity';
...@@ -441,7 +441,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -441,7 +441,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$values = array(); $values = array();
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $values; $entity->{$this->field_name} = $values;
$entity->{$field_name} = array(0 => array('value' => 99)); $entity->{$field_name} = array(0 => array('value' => 99));
...@@ -474,7 +474,7 @@ class FieldAttachTestCase extends DrupalWebTestCase { ...@@ -474,7 +474,7 @@ class FieldAttachTestCase extends DrupalWebTestCase {
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']); $entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
$values = array(); $values = array();
for ($delta = 0; $delta < $this->field['cardinality']; $delta++) { for ($delta = 0; $delta < $this->field['cardinality']; $delta++) {
$values[$delta]['value'] = mt_rand(0, 127); $values[$delta]['value'] = mt_rand(1, 127);
} }
$entity->{$this->field_name} = $values; $entity->{$this->field_name} = $values;
...@@ -767,7 +767,7 @@ class FieldFormTestCase extends DrupalWebTestCase { ...@@ -767,7 +767,7 @@ class FieldFormTestCase extends DrupalWebTestCase {
// TODO : check that the correct field is flagged for error. // TODO : check that the correct field is flagged for error.
// Create an entity // Create an entity
$value = mt_rand(0, 127); $value = mt_rand(1, 127);
$edit = array($this->field_name . '[0][value]' => $value); $edit = array($this->field_name . '[0][value]' => $value);
$this->drupalPost(NULL, $edit, t('Save')); $this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/(\d+)/edit|', $this->url, $match); preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
...@@ -782,7 +782,7 @@ class FieldFormTestCase extends DrupalWebTestCase { ...@@ -782,7 +782,7 @@ class FieldFormTestCase extends DrupalWebTestCase {
$this->assertNoField($this->field_name . '[1][value]', 'No extraneous widget is displayed'); $this->assertNoField($this->field_name . '[1][value]', 'No extraneous widget is displayed');
// Update the entity. // Update the entity.
$value = mt_rand(0, 127); $value = mt_rand(1, 127);
$edit = array($this->field_name . '[0][value]' => $value); $edit = array($this->field_name . '[0][value]' => $value);
$this->drupalPost(NULL, $edit, t('Save')); $this->drupalPost(NULL, $edit, t('Save'));
$this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), 'Entity was updated'); $this->assertRaw(t('test_entity @id has been updated.', array('@id' => $id)), 'Entity was updated');
...@@ -813,7 +813,7 @@ class FieldFormTestCase extends DrupalWebTestCase { ...@@ -813,7 +813,7 @@ class FieldFormTestCase extends DrupalWebTestCase {
$this->assertRaw(t('!name field is required.', array('!name' => $this->instance['label'])), 'Required field with no value fails validation'); $this->assertRaw(t('!name field is required.', array('!name' => $this->instance['label'])), 'Required field with no value fails validation');
// Create an entity // Create an entity
$value = mt_rand(0, 127); $value = mt_rand(1, 127);
$edit = array($this->field_name . '[0][value]' => $value); $edit = array($this->field_name . '[0][value]' => $value);
$this->drupalPost(NULL, $edit, t('Save')); $this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/(\d+)/edit|', $this->url, $match); preg_match('|test-entity/(\d+)/edit|', $this->url, $match);
...@@ -869,7 +869,7 @@ class FieldFormTestCase extends DrupalWebTestCase { ...@@ -869,7 +869,7 @@ class FieldFormTestCase extends DrupalWebTestCase {
$weight = mt_rand(-$delta_range, $delta_range); $weight = mt_rand(-$delta_range, $delta_range);
} while (in_array($weight, $weights)); } while (in_array($weight, $weights));
$weights[] = $weight; $weights[] = $weight;
$value = mt_rand(0, 127); $value = mt_rand(1, 127);
$edit["$this->field_name[$delta][value]"] = $value; $edit["$this->field_name[$delta][value]"] = $value;
$edit["$this->field_name[$delta][_weight]"] = $weight; $edit["$this->field_name[$delta][_weight]"] = $weight;
// We'll need three slightly different formats to check the values. // We'll need three slightly different formats to check the values.
......
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