You are here

class ContentCrudSingleToMultipleTest in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 tests/content.crud.test \ContentCrudSingleToMultipleTest
  2. 6.2 tests/content.crud.test \ContentCrudSingleToMultipleTest

Hierarchy

Expanded class hierarchy of ContentCrudSingleToMultipleTest

File

tests/content.crud.test, line 361

View source
class ContentCrudSingleToMultipleTest extends ContentCrudTestCase {
  function get_info() {
    return array(
      'name' => t('CCK CRUD API - Single to multiple'),
      'desc' => t('Tests the CRUD (create, read, update, delete) API for content types by creating a single value field and chaning it to a multivalue field, sharing it between several content types.'),
      'group' => t('CCK'),
    );
  }
  function testSingleToMultiple() {

    // Acquire the context
    $this
      ->loginWithPermissions();
    $this
      ->acquireContentTypes(3);
    $this
      ->acquireNodes();

    // Create a simple text field
    $this
      ->createFieldText(array(
      'text_processing' => 1,
    ));
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => array(
          'simpletest_f1' => array(
            'value',
            'format',
          ),
        ),
      ),
    ));
    $node0values = $this
      ->assertNodeSaveValues(0, array(
      'simpletest_f1' => array(
        0 => $this
          ->createRandomTextFieldData(),
      ),
    ));

    // Change the text field to allow multiple values
    $this
      ->updateField(array(
      'multiple' => 1,
    ));
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => array(),
      ),
      'per_field' => array(
        'simpletest_f1' => array(
          'delta',
          'simpletest_f1' => array(
            'value',
            'format',
          ),
        ),
      ),
    ));
    $this
      ->assertNodeValues(0, $node0values);

    // Share the text field with other content types
    for ($share_with_content_type = 1; $share_with_content_type <= 2; $share_with_content_type++) {
      $this
        ->shareField($share_with_content_type);
      $this
        ->assertSchemaMatchesTables(array(
        'per_type' => array(
          'simpletest_t' . ($share_with_content_type + 1) => array(),
        ),
      ));

      // The acquired node index will match the content type index as exactly one node is acquired per content type
      $this
        ->assertNodeSaveValues($share_with_content_type, array(
        'simpletest_f1' => array(
          0 => $this
            ->createRandomTextFieldData(),
        ),
      ));
    }

    // Delete the text field from all content types
    for ($delete_from_content_type = 2; $delete_from_content_type >= 0; $delete_from_content_type--) {
      $this
        ->deleteField($delete_from_content_type);

      // The acquired node index will match the content type index as exactly one node is acquired per content type
      $this
        ->assertNodeMissingFields($this->nodes[$delete_from_content_type], array(
        'simpletest_f1',
      ));
    }
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => NULL,
        'simpletest_t2' => NULL,
        'simpletest_t3' => NULL,
      ),
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentCrudSingleToMultipleTest::get_info function
ContentCrudSingleToMultipleTest::testSingleToMultiple function
ContentCrudTestCase::$content_types property
ContentCrudTestCase::$enabled_schema property
ContentCrudTestCase::$last_field property
ContentCrudTestCase::$next_field_n property
ContentCrudTestCase::$nodes property
ContentCrudTestCase::acquireContentTypes function Creates a number of content types with predictable names (simpletest_t1 ... simpletest_tN) These content types can later be accessed via $this->content_types[0 ... N-1]
ContentCrudTestCase::acquireNodes function Creates a number of nodes of each acquired content type. Remember to call acquireContentTypes() before calling this, else the content types won't exist.
ContentCrudTestCase::assertNodeMissingFields function Checks that the output from node_load is missing certain fields
ContentCrudTestCase::assertNodeSaveValues function Checks that after a node is saved using node_save, the values to be saved match up with the output from node_load.
ContentCrudTestCase::assertNodeValues function Checks that the output from node_load matches the expected values.
ContentCrudTestCase::assertSchemaMatchesTables function Checks that the database itself and the reported database schema match the expected columns for the given tables.
ContentCrudTestCase::createField function Creates a field instance with a predictable name. Also makes all future calls to functions which take an optional field use this one as the default.
ContentCrudTestCase::createFieldText function Creates a textfield instance. Identical to createField() except it ensures that the text module is enabled, and adds default settings of type (text) and widget_type (text_textfield) if they are not given in $settings. @sa createField()
ContentCrudTestCase::createRandomTextFieldData function Creates random values for a text field
ContentCrudTestCase::deleteField function Deletes an instance of a field.
ContentCrudTestCase::loginWithPermissions function Creates a user / role with certain permissions and then logs in as that user
ContentCrudTestCase::shareField function Makes a copy of a field instance on a different content type, effectively sharing the field with a new content type. Also makes all future calls to functions which take an optional field use the shared one as the default.
ContentCrudTestCase::updateField function Updates a field instance. Also makes all future calls to functions which take an optional field use the updated one as the default.
ContentCrudTestCase::_assertSchemaMatches function Helper function for assertSchemaMatchesTables Checks that the database and schema for the given table contain only the correct fields
ContentCrudTestCase::_assertTableNotExists function Helper function for assertSchemaMatchesTables Checks that the given database table does NOT exist
ContentCrudTestCase::_compareArrayForChanges function Helper function for assertNodeSaveValues. Recursively checks that all the keys of a table are present in a second and have the same value.