You are here

function SmartIPViewsBridgeTestHelper::setUp in Smart IP 7.2

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 DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

1 call to SmartIPViewsBridgeTestHelper::setUp()
SmartIPViewsBridgeFunctionalTestCase::setUp in modules/smart_ip_views_bridge/tests/smart_ip_views_bridge.test
Sets up a Drupal site for running functional and integration tests.
1 method overrides SmartIPViewsBridgeTestHelper::setUp()
SmartIPViewsBridgeFunctionalTestCase::setUp in modules/smart_ip_views_bridge/tests/smart_ip_views_bridge.test
Sets up a Drupal site for running functional and integration tests.

File

modules/smart_ip_views_bridge/tests/smart_ip_views_bridge.test, line 35
Functionality tests for Smart IP Views Bridge.

Class

SmartIPViewsBridgeTestHelper
Helper test class with some added functions for testing.

Code

function setUp() {

  // Call parent::setUp() allowing test cases to pass further modules.
  $modules = func_get_args();
  $modules = array_merge(array(
    'smart_ip_views_bridge',
    'views',
    'smart_ip',
  ), $modules);
  call_user_func_array(array(
    'parent',
    'setUp',
  ), $modules);

  // Disable Smart IP auto update and use of IPinfodb service
  variable_set('smart_ip_use_ipinfodb_service', FALSE);
  variable_set('smart_ip_auto_update', FALSE);

  // Create and log in our user. The user has the arbitrary privilege
  // which the code uses to grant access.
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer blocks',
    'administer content types',
    'create page content',
    'access administration pages',
    'access content',
    'access content overview',
    'administer nodes',
    'administer site configuration',
    'administer views',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Create CCK fields at Page content type
  $this
    ->drupalGet('admin/structure/types/manage/page/fields');

  // Create singleton CCK text field for City
  $field_label = t('City');
  $edit = array(
    'fields[_add_new_field][label]' => $field_label,
    'fields[_add_new_field][field_name]' => 'city',
    'fields[_add_new_field][type]' => 'text',
    'fields[_add_new_field][widget_type]' => 'text_textfield',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // There are no settings for this, so just press the button.
  $this
    ->drupalPost(NULL, array(), t('Save field settings'));

  // Using all the default settings, so press the button.
  $this
    ->drupalPost(NULL, array(), t('Save settings'));
  $this
    ->assertText(t('Saved @name configuration.', array(
    '@name' => $field_label,
  )));

  // Now we're back on the field-add page.
  $this
    ->drupalGet('admin/structure/types/manage/page/fields');

  // Create singleton CCK text field for Country
  $field_label = t('Country');
  $edit = array(
    'fields[_add_new_field][label]' => $field_label,
    'fields[_add_new_field][field_name]' => 'country',
    'fields[_add_new_field][type]' => 'list_text',
    'fields[_add_new_field][widget_type]' => 'options_select',
  );
  $this
    ->drupalPost(NULL, $edit, t('Save'));

  // There are no settings for this, so just press the button.
  $this
    ->drupalPost(NULL, array(), t('Save field settings'));

  // Add some countries to the list for this settings, then press the button.
  $this
    ->drupalPost(NULL, array(
    'field[settings][allowed_values]' => "PH|Philippines\nUS|United States",
  ), t('Save settings'));
  $this
    ->assertText(t('Saved @name configuration.', array(
    '@name' => $field_label,
  )));

  // Add some contents to be queried at Views
  // Content 1
  $this
    ->drupalGet('node/add/page');
  $content_items = array(
    'title' => 'Content 1',
    'field_city[und][0][value]' => 'Manila',
    'field_country[und]' => 'PH',
  );
  $this
    ->drupalPost(NULL, $content_items, t('Save'));

  // Content 2
  $this
    ->drupalGet('node/add/page');
  $content_items = array(
    'title' => 'Content 2',
    'field_city[und][0][value]' => 'Manila',
    'field_country[und]' => 'PH',
  );
  $this
    ->drupalPost(NULL, $content_items, t('Save'));

  // Content 3
  $this
    ->drupalGet('node/add/page');
  $content_items = array(
    'title' => 'Content 3',
    'field_city[und][0][value]' => 'Texas',
    'field_country[und]' => 'US',
  );
  $this
    ->drupalPost(NULL, $content_items, t('Save'));

  // Check if the 3 contents stored
  $this
    ->drupalGet('admin/content');
  $this
    ->assertText('Content 1');
  $this
    ->assertText('Content 2');
  $this
    ->assertText('Content 3');

  // Define our admin user Smart IP Session variables
  $_SESSION['smart_ip']['location'] = array(
    'country' => 'Philippines',
    'country_code' => 'PH',
    'region' => 'Manila Chartered City',
    'region_code' => 'D9',
    'city' => 'Manila',
    'zip' => '1000',
    'latitude' => '14.5872',
    'longitude' => '120.9667',
  );
  $_SESSION['device_geolocation'] = TRUE;
}