You are here

function CertificateUpdateTestCase::testUpdate in Certificate 7.3

Same name and namespace in other branches
  1. 8.3 tests/CertificateUpdateTestCase.test \CertificateUpdateTestCase::testUpdate()

Test an upgrade to Certificate 7.x-3.x from 7.x-2.x

File

tests/CertificateUpdateTestCase.test, line 24

Class

CertificateUpdateTestCase

Code

function testUpdate() {
  $this
    ->assertTrue($this
    ->performUpgrade(), 'The upgrade was completed successfully.');
  drupal_get_schema(NULL, TRUE);

  // Check that the updated schema matches our hook_schema().
  $schema = drupal_get_schema_unprocessed('certificate');
  foreach ($schema as $table => $info) {
    $this
      ->assertTrue(db_table_exists($table), "{$table} exists");
    foreach ($info['fields'] as $field_name => $field_info) {
      $this
        ->assertTrue(db_field_exists($table, $field_name), "{$table} has {$field_name}");
    }
    if (isset($info['indexes'])) {
      foreach ($info['indexes'] as $index_name => $columns) {
        $this
          ->assertTrue(db_index_exists($table, $index_name), "{$table} has index {$index_name}");
      }
    }
    if (isset($info['unique keys'])) {
      foreach ($info['unique keys'] as $index_name => $columns) {
        $this
          ->assertTrue(db_index_exists($table, $index_name), "{$table} has unique key {$index_name}");
      }
    }
  }

  // Manually load this file for some reason.
  module_load_include('inc', 'entity', 'includes/entity.controller');
  module_load_include('inc', 'entity', 'includes/entity.ui');
  module_load_include('inc', 'certificate', 'certificate.classes');

  // Check certificate migrations.
  $this
    ->drupalGet('admin/structure/certificates');
  $this
    ->assertText('Template A Portrait');
  $this
    ->assertText('Machine name: 1)');
  $this
    ->assertText('Template B Landscape');
  $this
    ->assertText('Machine name: 2)');
  $this
    ->drupalGet('admin/structure/certificates/manage/1');
  $this
    ->assertText('This is the body for Template A Portrait. It is filtered HTML.');
  $this
    ->assertFieldChecked('edit-orientation-portrait');
  $this
    ->assertOptionSelected('edit-certificate-body-und-0-format--2', 'filtered_html');
  $this
    ->drupalGet('admin/structure/certificates/manage/2');
  $this
    ->assertText('This is the body for Template B Landscape. It is full html.');
  $this
    ->assertFieldChecked('edit-orientation-landscape');
  $this
    ->assertOptionSelected('edit-certificate-body-und-0-format--2', 'full_html');

  // Check global mappings.
  $this
    ->drupalGet('admin/structure/certificates/mapping');
  $this
    ->assertOptionSelected('edit-certificate-map-manual-manual', '1');
  $this
    ->assertOptionSelected('edit-certificate-map-firstletter-a', '1');
  $this
    ->assertOptionSelected('edit-certificate-map-firstletter-b', '2');

  // Check existing mapping (reversed from global).
  $this
    ->drupalGet('node/3/edit');
  $this
    ->assertOptionSelected('edit-certificate-map-manual-manual', '2');
  $this
    ->assertOptionSelected('edit-certificate-map-firstletter-a', '2');
  $this
    ->assertOptionSelected('edit-certificate-map-firstletter-b', '1');
}