You are here

function ContentCrudSingleToMultipleTest::testSingleToMultiple in Content Construction Kit (CCK) 6

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

File

tests/content.crud.test, line 370

Class

ContentCrudSingleToMultipleTest

Code

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,
    ),
  ));
}