You are here

public function UcAddressesTestModuleTestCase::testTestModule in Ubercart Addresses 6.2

Test if test module is installed without problems.

File

tests/uc_addresses.test.test, line 43
Test cases for test module.

Class

UcAddressesTestModuleTestCase
Test cases for the test module.

Code

public function testTestModule() {

  // Ensure the expected address fields from the test module are present.
  $fields = uc_addresses_get_address_fields();
  $this
    ->assertTrue(isset($fields['billing_extra1']), t('The field %field is available.', array(
    '%field' => t('Billing Extra Field'),
  )));
  $this
    ->assertTrue(isset($fields['shipping_extra2']), t('The field %field is available.', array(
    '%field' => t('Delivery Extra Field'),
  )));

  // Test if the database columns are added.
  $this
    ->assertTrue(db_column_exists('uc_addresses', 'billing_extra1'), t('The database column %column is available in the table %table.', array(
    '%column' => 'billing_extra1',
    '%table' => 'uc_addresses',
  )));
  $this
    ->assertTrue(db_column_exists('uc_addresses', 'shipping_extra2'), t('The database column %column is available in the table %table.', array(
    '%column' => 'shipping_extra2',
    '%table' => 'uc_addresses',
  )));
  $this
    ->assertTrue(db_column_exists('uc_orders', 'billing_billing_extra1'), t('The database column %column is available in the table %table.', array(
    '%column' => 'billing_billing_extra1',
    '%table' => 'uc_orders',
  )));
  $this
    ->assertTrue(db_column_exists('uc_orders', 'delivery_shipping_extra2'), t('The database column %column is available in the table %table.', array(
    '%column' => 'delivery_shipping_extra2',
    '%table' => 'uc_orders',
  )));
  $this
    ->assertFalse(db_column_exists('uc_orders', 'delivery_billing_extra1'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'delivery_billing_extra1',
    '%table' => 'uc_orders',
  )));
  $this
    ->assertFalse(db_column_exists('uc_orders', 'billing_shipping_extra2'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'billing_shipping_extra2',
    '%table' => 'uc_orders',
  )));

  // Test if the fields are displayed on an address form.
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet($this
    ->constructAddressUrl($this->adminUser) . 'add');
  $this
    ->assertFieldByName('address[billing_extra1]');
  $this
    ->assertFieldByName('address[shipping_extra2]');

  // Test if the module can be uninstalled too and flush schema cache.
  drupal_uninstall_module('uc_addresses_test');
  drupal_get_schema(NULL, TRUE);

  // Now ensure that the fields added by the test module are no longer there in the database.
  $this
    ->assertFalse(db_column_exists('uc_addresses', 'billing_extra1'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'billing_extra1',
    '%table' => 'uc_addresses',
  )));
  $this
    ->assertFalse(db_column_exists('uc_addresses', 'shipping_extra2'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'shipping_extra2',
    '%table' => 'uc_addresses',
  )));
  $this
    ->assertFalse(db_column_exists('uc_orders', 'billing_billing_extra1'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'billing_billing_extra1',
    '%table' => 'uc_orders',
  )));
  $this
    ->assertFalse(db_column_exists('uc_orders', 'delivery_shipping_extra2'), t('The database column %column is not available in the table %table.', array(
    '%column' => 'delivery_shipping_extra2',
    '%table' => 'uc_orders',
  )));
}