Commit 1750dba6 authored by Dries's avatar Dries

- Patch #1024840 by Jody Lynn: whitespace fixes for field module.

parent 2dbeb605
......@@ -1271,7 +1271,7 @@ function hook_field_attach_delete_revision($entity_type, $entity) {
*/
function hook_field_attach_purge($entity_type, $entity, $field, $instance) {
// find the corresponding data in mymodule and purge it
if($entity_type == 'node' && $field->field_name == 'my_field_name') {
if ($entity_type == 'node' && $field->field_name == 'my_field_name') {
mymodule_remove_mydata($entity->nid);
}
}
......
......@@ -135,7 +135,7 @@ function field_default_insert($entity_type, $entity, $field, $instance, $langcod
* - the name of a view mode
* - or an array of display settings to use for display, as found in the
* 'display' entry of $instance definitions.
*/
*/
function field_default_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items, $display) {
// Group entities, instances and items by formatter module.
$modules = array();
......
......@@ -98,8 +98,8 @@ class ListFieldTestCase extends FieldTestCase {
}
/**
* List module UI tests.
*/
* List module UI tests.
*/
class ListFieldUITestCase extends FieldTestCase {
public static function getInfo() {
return array(
......
......@@ -1568,109 +1568,109 @@ class FieldFormTestCase extends FieldTestCase {
* Tests Field API form integration within a subform.
*/
function testNestedFieldForm() {
// Add two instances on the 'test_bundle'
field_create_field($this->field_single);
field_create_field($this->field_unlimited);
$this->instance['field_name'] = 'field_single';
$this->instance['label'] = 'Single field';
field_create_instance($this->instance);
$this->instance['field_name'] = 'field_unlimited';
$this->instance['label'] = 'Unlimited field';
field_create_instance($this->instance);
// Create two entities.
$entity_1 = field_test_create_stub_entity(1, 1);
$entity_1->is_new = TRUE;
$entity_1->field_single[LANGUAGE_NONE][] = array('value' => 0);
$entity_1->field_unlimited[LANGUAGE_NONE][] = array('value' => 1);
field_test_entity_save($entity_1);
$entity_2 = field_test_create_stub_entity(2, 2);
$entity_2->is_new = TRUE;
$entity_2->field_single[LANGUAGE_NONE][] = array('value' => 10);
$entity_2->field_unlimited[LANGUAGE_NONE][] = array('value' => 11);
field_test_entity_save($entity_2);
// Display the 'combined form'.
$this->drupalGet('test-entity/nested/1/2');
$this->assertFieldByName('field_single[und][0][value]', 0, t('Entity 1: field_single value appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][0][value]', 1, t('Entity 1: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_single][und][0][value]', 10, t('Entity 2: field_single value appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][0][value]', 11, t('Entity 2: field_unlimited value 0 appears correctly is the form.'));
// Submit the form and check that the entities are updated accordingly.
$edit = array(
'field_single[und][0][value]' => 1,
'field_unlimited[und][0][value]' => 2,
'field_unlimited[und][1][value]' => 3,
'entity_2[field_single][und][0][value]' => 11,
'entity_2[field_unlimited][und][0][value]' => 12,
'entity_2[field_unlimited][und][1][value]' => 13,
);
$this->drupalPost(NULL, $edit, t('Save'));
field_cache_clear();
$entity_1 = field_test_create_stub_entity(1);
$entity_2 = field_test_create_stub_entity(2);
$this->assertFieldValues($entity_1, 'field_single', LANGUAGE_NONE, array(1));
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(2, 3));
$this->assertFieldValues($entity_2, 'field_single', LANGUAGE_NONE, array(11));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(12, 13));
// Submit invalid values and check that errors are reported on the
// correct widgets.
$edit = array(
'field_unlimited[und][1][value]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), t('Entity 1: the field validation error was reported.'));
$error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-field-unlimited-und-1-value'));
$this->assertTrue($error_field, t('Entity 1: the error was flagged on the correct element.'));
$edit = array(
'entity_2[field_unlimited][und][1][value]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), t('Entity 2: the field validation error was reported.'));
$error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-entity-2-field-unlimited-und-1-value'));
$this->assertTrue($error_field, t('Entity 2: the error was flagged on the correct element.'));
// Test that reordering works on both entities.
$edit = array(
'field_unlimited[und][0][_weight]' => 0,
'field_unlimited[und][1][_weight]' => -1,
'entity_2[field_unlimited][und][0][_weight]' => 0,
'entity_2[field_unlimited][und][1][_weight]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
field_cache_clear();
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(3, 2));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(13, 12));
// Test the 'add more' buttons. Only AJAX submission is tested, because
// the two 'add more' buttons present in the form have the same #value,
// which confuses drupalPost().
// 'Add more' button in the first entity:
$this->drupalGet('test-entity/nested/1/2');
$this->drupalPostAJAX(NULL, array(), 'field_unlimited_add_more');
$this->assertFieldByName('field_unlimited[und][0][value]', 3, t('Entity 1: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][1][value]', 2, t('Entity 1: field_unlimited value 1 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][2][value]', '', t('Entity 1: field_unlimited value 2 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][3][value]', '', t('Entity 1: an empty widget was added for field_unlimited value 3.'));
// 'Add more' button in the first entity (changing field values):
$edit = array(
'entity_2[field_unlimited][und][0][value]' => 13,
'entity_2[field_unlimited][und][1][value]' => 14,
'entity_2[field_unlimited][und][2][value]' => 15,
);
$this->drupalPostAJAX(NULL, $edit, 'entity_2_field_unlimited_add_more');
$this->assertFieldByName('entity_2[field_unlimited][und][0][value]', 13, t('Entity 2: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][1][value]', 14, t('Entity 2: field_unlimited value 1 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][2][value]', 15, t('Entity 2: field_unlimited value 2 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][3][value]', '', t('Entity 2: an empty widget was added for field_unlimited value 3.'));
// Save the form and check values are saved correclty.
$this->drupalPost(NULL, array(), t('Save'));
field_cache_clear();
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(3, 2));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(13, 14, 15));
// Add two instances on the 'test_bundle'
field_create_field($this->field_single);
field_create_field($this->field_unlimited);
$this->instance['field_name'] = 'field_single';
$this->instance['label'] = 'Single field';
field_create_instance($this->instance);
$this->instance['field_name'] = 'field_unlimited';
$this->instance['label'] = 'Unlimited field';
field_create_instance($this->instance);
// Create two entities.
$entity_1 = field_test_create_stub_entity(1, 1);
$entity_1->is_new = TRUE;
$entity_1->field_single[LANGUAGE_NONE][] = array('value' => 0);
$entity_1->field_unlimited[LANGUAGE_NONE][] = array('value' => 1);
field_test_entity_save($entity_1);
$entity_2 = field_test_create_stub_entity(2, 2);
$entity_2->is_new = TRUE;
$entity_2->field_single[LANGUAGE_NONE][] = array('value' => 10);
$entity_2->field_unlimited[LANGUAGE_NONE][] = array('value' => 11);
field_test_entity_save($entity_2);
// Display the 'combined form'.
$this->drupalGet('test-entity/nested/1/2');
$this->assertFieldByName('field_single[und][0][value]', 0, t('Entity 1: field_single value appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][0][value]', 1, t('Entity 1: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_single][und][0][value]', 10, t('Entity 2: field_single value appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][0][value]', 11, t('Entity 2: field_unlimited value 0 appears correctly is the form.'));
// Submit the form and check that the entities are updated accordingly.
$edit = array(
'field_single[und][0][value]' => 1,
'field_unlimited[und][0][value]' => 2,
'field_unlimited[und][1][value]' => 3,
'entity_2[field_single][und][0][value]' => 11,
'entity_2[field_unlimited][und][0][value]' => 12,
'entity_2[field_unlimited][und][1][value]' => 13,
);
$this->drupalPost(NULL, $edit, t('Save'));
field_cache_clear();
$entity_1 = field_test_create_stub_entity(1);
$entity_2 = field_test_create_stub_entity(2);
$this->assertFieldValues($entity_1, 'field_single', LANGUAGE_NONE, array(1));
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(2, 3));
$this->assertFieldValues($entity_2, 'field_single', LANGUAGE_NONE, array(11));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(12, 13));
// Submit invalid values and check that errors are reported on the
// correct widgets.
$edit = array(
'field_unlimited[und][1][value]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), t('Entity 1: the field validation error was reported.'));
$error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-field-unlimited-und-1-value'));
$this->assertTrue($error_field, t('Entity 1: the error was flagged on the correct element.'));
$edit = array(
'entity_2[field_unlimited][und][1][value]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
$this->assertRaw(t('%label does not accept the value -1', array('%label' => 'Unlimited field')), t('Entity 2: the field validation error was reported.'));
$error_field = $this->xpath('//input[@id=:id and contains(@class, "error")]', array(':id' => 'edit-entity-2-field-unlimited-und-1-value'));
$this->assertTrue($error_field, t('Entity 2: the error was flagged on the correct element.'));
// Test that reordering works on both entities.
$edit = array(
'field_unlimited[und][0][_weight]' => 0,
'field_unlimited[und][1][_weight]' => -1,
'entity_2[field_unlimited][und][0][_weight]' => 0,
'entity_2[field_unlimited][und][1][_weight]' => -1,
);
$this->drupalPost('test-entity/nested/1/2', $edit, t('Save'));
field_cache_clear();
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(3, 2));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(13, 12));
// Test the 'add more' buttons. Only AJAX submission is tested, because
// the two 'add more' buttons present in the form have the same #value,
// which confuses drupalPost().
// 'Add more' button in the first entity:
$this->drupalGet('test-entity/nested/1/2');
$this->drupalPostAJAX(NULL, array(), 'field_unlimited_add_more');
$this->assertFieldByName('field_unlimited[und][0][value]', 3, t('Entity 1: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][1][value]', 2, t('Entity 1: field_unlimited value 1 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][2][value]', '', t('Entity 1: field_unlimited value 2 appears correctly is the form.'));
$this->assertFieldByName('field_unlimited[und][3][value]', '', t('Entity 1: an empty widget was added for field_unlimited value 3.'));
// 'Add more' button in the first entity (changing field values):
$edit = array(
'entity_2[field_unlimited][und][0][value]' => 13,
'entity_2[field_unlimited][und][1][value]' => 14,
'entity_2[field_unlimited][und][2][value]' => 15,
);
$this->drupalPostAJAX(NULL, $edit, 'entity_2_field_unlimited_add_more');
$this->assertFieldByName('entity_2[field_unlimited][und][0][value]', 13, t('Entity 2: field_unlimited value 0 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][1][value]', 14, t('Entity 2: field_unlimited value 1 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][2][value]', 15, t('Entity 2: field_unlimited value 2 appears correctly is the form.'));
$this->assertFieldByName('entity_2[field_unlimited][und][3][value]', '', t('Entity 2: an empty widget was added for field_unlimited value 3.'));
// Save the form and check values are saved correclty.
$this->drupalPost(NULL, array(), t('Save'));
field_cache_clear();
$this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NONE, array(3, 2));
$this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NONE, array(13, 14, 15));
}
}
......@@ -1827,7 +1827,7 @@ class FieldDisplayAPITestCase extends FieldTestCase {
$item = $this->entity->{$this->field_name}[LANGUAGE_NONE][$delta];
$output = field_view_value('test_entity', $this->entity, $this->field_name, $item, $display);
$this->drupalSetContent(drupal_render($output));
$this->assertText($setting . '|0:' . $value['value'], t('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
$this->assertText($setting . '|0:' . $value['value'], t('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
}
// Check that prepare_view steps are invoked.
......@@ -1843,7 +1843,7 @@ class FieldDisplayAPITestCase extends FieldTestCase {
$item = $this->entity->{$this->field_name}[LANGUAGE_NONE][$delta];
$output = field_view_value('test_entity', $this->entity, $this->field_name, $item, $display);
$this->drupalSetContent(drupal_render($output));
$this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), t('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
$this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), t('Value @delta was displayed with expected setting.', array('@delta' => $delta)));
}
// View mode: check that display settings specified in the instance are
......@@ -2880,7 +2880,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
public static function getInfo() {
return array(
'name' => 'Field bulk delete tests',
'description'=> 'Bulk delete fields and instances, and clean up afterwards.',
'description' => 'Bulk delete fields and instances, and clean up afterwards.',
'group' => 'Field API',
);
}
......@@ -3127,7 +3127,7 @@ class EntityPropertiesTestCase extends FieldTestCase {
public static function getInfo() {
return array(
'name' => 'Entity properties',
'description'=> 'Tests entity properties.',
'description' => 'Tests entity properties.',
'group' => 'Entity API',
);
}
......
......@@ -288,7 +288,7 @@ function field_test_field_storage_query($field_id, $conditions, $count, &$cursor
case '<=':
case '>':
case '>=':
eval('$match = $match && '. $row->{$column} . ' ' . $operator . ' '. $value);
eval('$match = $match && ' . $row->{$column} . ' ' . $operator . ' '. $value);
break;
case 'IN':
$match = $match && in_array($row->{$column}, $value);
......
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