You are here

function ContentCrudBasicTest::testBasic in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6.2 tests/content.crud.test \ContentCrudBasicTest::testBasic()

File

tests/content.crud.test, line 391

Class

ContentCrudBasicTest

Code

function testBasic() {

  // Create a field with both field and instance settings.
  $field = $this
    ->createFieldText(array(
    'widget_type' => 'text_textarea',
    'text_processing' => 1,
    'rows' => 5,
  ), 0);

  // Check that collapse and expand are inverse.
  $fields = content_field_instance_read(array(
    'field_name' => $field['field_name'],
    'type_name' => $this->content_types[0]->type,
  ));
  $field1 = array_pop($fields);
  $field2 = content_field_instance_collapse($field1);
  $field3 = content_field_instance_expand($field2);
  $field4 = content_field_instance_collapse($field3);
  $this
    ->assertIdentical($field1, $field3, 'collapse then expand is identity');
  $this
    ->assertIdentical($field2, $field4, 'expand then collapse is identity');

  // Check that collapse and expand are both final
  // (e.g. do not further alter the data when called multiple times).
  $fields = content_field_instance_read(array(
    'field_name' => $field['field_name'],
    'type_name' => $this->content_types[0]->type,
  ));
  $field1 = array_pop($fields);
  $field2 = content_field_instance_collapse($field1);
  $field3 = content_field_instance_collapse($field2);
  $this
    ->assertIdentical($field2, $field3, 'collapse is final');
  $field2 = content_field_instance_expand($field1);
  $field3 = content_field_instance_expand($field2);
  $this
    ->assertIdentical($field2, $field3, 'expand is final');

  // Check that updating a field as is leaves it unchanged.
  $fields = content_field_instance_read(array(
    'field_name' => $field['field_name'],
    'type_name' => $this->content_types[0]->type,
  ));
  $field1 = array_pop($fields);
  $field2 = content_field_instance_update($field1);
  $fields = content_field_instance_read(array(
    'field_name' => $field['field_name'],
    'type_name' => $this->content_types[0]->type,
  ));
  $field3 = array_pop($fields);
  $this
    ->assertIdentical($field1, $field3, 'read, update, read is identity');
}