diff options
Diffstat (limited to 'modules/field')
-rw-r--r-- | modules/field/field.test | 15 | ||||
-rw-r--r-- | modules/field/modules/text/text.test | 26 |
2 files changed, 31 insertions, 10 deletions
diff --git a/modules/field/field.test b/modules/field/field.test index f54ad5842..af9eb4b72 100644 --- a/modules/field/field.test +++ b/modules/field/field.test @@ -1,8 +1,6 @@ <?php // $Id$ -// TODO : use drupalCreateField() / drupalCreateFieldInstance() all over ? - class FieldAttachTestCase extends DrupalWebTestCase { public static function getInfo() { return array( @@ -1013,8 +1011,10 @@ class FieldTestCase extends DrupalWebTestCase { // TODO: Also test deletion of the data stored in the field ? // Create two fields (so we can test that only one is deleted). - $this->field = $this->drupalCreateField('test_field', 'test_field_name'); - $this->another_field = $this->drupalCreateField('test_field', 'another_test_field_name'); + $this->field = array('field_name' => 'test_field_name', 'type' => 'test_field'); + field_create_field($this->field); + $this->another_field = array('field_name' => 'another_test_field_name', 'type' => 'test_field'); + field_create_field($this->another_field); // Create instances for each. $this->instance_definition = array( @@ -1073,8 +1073,11 @@ class FieldInstanceTestCase extends DrupalWebTestCase { function setUp() { parent::setUp('field_sql_storage', 'field', 'field_test'); - - $this->field = $this->drupalCreateField('test_field'); + $this->field = array( + 'field_name' => drupal_strtolower($this->randomName()), + 'type' => 'test_field', + ); + field_create_field($this->field); $this->instance_definition = array( 'field_name' => $this->field['field_name'], 'bundle' => FIELD_TEST_BUNDLE, diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test index e86ac89cb..8f7459370 100644 --- a/modules/field/modules/text/text.test +++ b/modules/field/modules/text/text.test @@ -27,13 +27,31 @@ class TextFieldTestCase extends DrupalWebTestCase { function testTextFieldValidation() { // Create a field with settings to validate. $max_length = 3; - $field = $this->drupalCreateField('text', NULL, array('settings' => array('max_length' => $max_length))); - $this->instance = $this->drupalCreateFieldInstance($field['field_name'], 'text_textfield', 'text_default', FIELD_TEST_BUNDLE); - + $this->field = array( + 'field_name' => drupal_strtolower($this->randomName()), + 'type' => 'text', + 'settings' => array( + 'max_length' => $max_length, + ) + ); + field_create_field($this->field); + $this->instance = array( + 'field_name' => $this->field['field_name'], + 'bundle' => FIELD_TEST_BUNDLE, + 'widget' => array( + 'type' => 'text_textfield', + ), + 'display' => array( + 'full' => array( + 'type' => 'text_default', + ), + ), + ); + field_create_instance($this->instance); // Test valid and invalid values with field_attach_validate(). $entity = field_test_create_stub_entity(0, 0, FIELD_TEST_BUNDLE); for ($i = 0; $i <= $max_length + 2; $i++) { - $entity->{$field['field_name']}[0]['value'] = str_repeat('x', $i); + $entity->{$this->field['field_name']}[0]['value'] = str_repeat('x', $i); try { field_attach_validate('test_entity', $entity); $this->assertTrue($i <= $max_length, "Length $i does not cause validation error when max_length is $max_length"); |