You are here

public function ScannerWithFieldCollectionTestCase::setUp in Search and Replace Scanner 7

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides ScannerBasicsTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/ScannerWithFieldCollectionTestCase.test, line 31
Test integration with Field Collection.

Class

ScannerWithFieldCollectionTestCase
Test integration with Field Collection.

Code

public function setUp(array $modules = array()) {

  // Enable the FC module.
  $modules[] = 'field_collection';

  // Some helper logic.
  $modules[] = 'scanner_with_fc_tests';

  // Buid the site.
  parent::setUp($modules);

  // Delete the same content created above.
  module_load_include('inc', 'devel_generate');
  devel_generate_content_kill(array(
    'node_types' => array(
      'article',
    ),
  ));

  // Add a FC field to the Article content type.
  $this
    ->drupalGet('admin/structure/types/manage/article/fields');
  $this
    ->assertResponse(200);
  $edit = array(
    'fields[_add_new_field][label]' => 'Stuff',
    'fields[_add_new_field][field_name]' => 'stuff',
    'fields[_add_new_field][type]' => 'field_collection',
    'fields[_add_new_field][widget_type]' => 'field_collection_embed',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $edit = array();
  $this
    ->drupalPost(NULL, $edit, t('Save field settings'));
  $this
    ->assertResponse(200);
  $edit = array(
    'field[cardinality]' => -1,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  $this
    ->assertResponse(200);
  $this
    ->assertText('Saved Stuff configuration.');

  // Add a text field to the FC type.
  $this
    ->drupalGet('admin/structure/field-collections/field-stuff/fields');
  $this
    ->assertResponse(200);
  $edit = array(
    'fields[_add_new_field][label]' => 'Text',
    'fields[_add_new_field][field_name]' => 'text',
    'fields[_add_new_field][type]' => 'text',
    'fields[_add_new_field][widget_type]' => 'text_textfield',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));
  $this
    ->assertResponse(200);
  $edit = array();
  $this
    ->drupalPost(NULL, $edit, t('Save field settings'));
  $this
    ->assertResponse(200);
  $edit = array();
  $this
    ->drupalPost(NULL, $edit, t('Save settings'));
  $this
    ->assertResponse(200);
  $this
    ->assertText('Saved Text configuration.');

  // Generate some sample content.
  $this
    ->generateSampleContent();
}