You are here

class ContentCrudMultipleToSingleTest in Content Construction Kit (CCK) 6

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

Hierarchy

Expanded class hierarchy of ContentCrudMultipleToSingleTest

File

tests/content.crud.test, line 433

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

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

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

    // Change to a simple text field
    $this
      ->updateField(array(
      'multiple' => 0,
    ));
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => array(
          'simpletest_f1' => array(
            'value',
            'format',
          ),
        ),
      ),
      'per_field' => array(
        'simpletest_f1' => NULL,
      ),
    ));
    $node0values = $this
      ->assertNodeSaveValues(0, array(
      'simpletest_f1' => array(
        0 => $this
          ->createRandomTextFieldData(),
      ),
    ));

    // Share the text field with other content type
    $this
      ->shareField(1);
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => array(),
        'simpletest_t2' => array(),
      ),
      'per_field' => array(
        'simpletest_f1' => array(
          'simpletest_f1' => array(
            'value',
            'format',
          ),
        ),
      ),
    ));
    $node1values = $this
      ->assertNodeSaveValues(1, array(
      'simpletest_f1' => array(
        0 => $this
          ->createRandomTextFieldData(),
      ),
    ));
    $this
      ->assertNodeValues(0, $node0values);

    // Share the text field with a 3rd type
    $this
      ->shareField(2);
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t3' => array(),
      ),
    ));
    $this
      ->assertNodeSaveValues(2, array(
      'simpletest_f1' => array(
        0 => $this
          ->createRandomTextFieldData(),
      ),
    ));
    $this
      ->assertNodeValues(1, $node1values);
    $this
      ->assertNodeValues(0, $node0values);

    // Remove text field from 3rd type
    $this
      ->deleteField(2);
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t3' => NULL,
      ),
    ));
    $this
      ->assertNodeMissingFields($this->nodes[2], array(
      'simpletest_f1',
    ));

    // Remove text field from other type
    $this
      ->deleteField(1);
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => array(
          'simpletest_f1' => array(
            'value',
            'format',
          ),
        ),
        'simpletest_t2' => NULL,
      ),
      'per_field' => array(
        'simpletest_f1' => NULL,
      ),
    ));
    $this
      ->assertNodeMissingFields(1, array(
      'simpletest_f1',
    ));
    $this
      ->assertNodeValues(0, $node0values);

    // Remove text field from original type
    $this
      ->deleteField(0);
    $this
      ->assertSchemaMatchesTables(array(
      'per_type' => array(
        'simpletest_t1' => NULL,
      ),
    ));
    $this
      ->assertNodeMissingFields(0, array(
      'simpletest_f1',
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentCrudMultipleToSingleTest::get_info function
ContentCrudMultipleToSingleTest::testMultipleToSingle 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.