Commit e78ce925 authored by Marco Villegas's avatar Marco Villegas
Browse files

Issue #1985426 follow-up: Use class constants to define test repository counters.

This also updates the counters to reflect the change introduced by the
operation_labels_mapping synchronization option, which by defaults maps
both branches and tags commits relations.
parent 15ae559e
Loading
Loading
Loading
Loading
+12 −8
Changes for tests/VersioncontrolGitDataIntegrityTests.test: 12 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -44,15 +44,17 @@ class VersioncontrolGitDataIntegrityTests extends VersioncontrolGitTestCase {
    $op_label_count = db_query('SELECT COUNT(*) FROM {versioncontrol_operation_labels}')->fetchField();
    $label_count = db_query('SELECT COUNT(*) FROM {versioncontrol_labels}')->fetchField();

    $this->assertEqual($ir_count, 36, t('Correct number of item revisions in {versioncontrol_item_revisions} table after non-bypassing purge.'));
    $this->assertEqual($ir_count, 2 * VersioncontrolGitTestCase::TESTREPO_COUNT_ITEM_REVISIONS, t('Correct number of item revisions in {versioncontrol_item_revisions} table after non-bypassing purge.'));
    // Two fewer b/c v_g_i_r does not record an entry for deleted items, of which we have one.
    $this->assertEqual($git_ir_count + 2, $ir_count, t('Two fewer {versioncontrol_git_item_revisions} records than {versioncontrol_item_revisions} records after non-bypassing purge.'));

    $this->assertEqual($op_count, 32, t('Correct number of operations in {versioncontrol_operations} table after non-bypassing purge.'));
    $this->assertEqual($op_count, 2 * VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATIONS, t('Correct number of operations in {versioncontrol_operations} table after non-bypassing purge.'));
    $this->assertEqual($git_op_count, $op_count, t('Equal number of {versioncontrol_git_operations} and {versioncontrol_operations} records after non-bypassing purge.'));
    $this->assertEqual($op_label_count, 102, t('Correct number of operation/label mappings in {versioncontrol_operation_labels} after non-bypassing purge.'));
    $testrepo_op_label_maps = VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_BRANCH_MAP + VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_TAG_MAP;
    $this->assertEqual($op_label_count, 2 * $testrepo_op_label_maps, t('Correct number of operation/label mappings in {versioncontrol_operation_labels} after non-bypassing purge.'));

    $this->assertEqual($label_count, 14, t('Correct number of labels in {versioncontrol_labels} after non-bypassing purge.'));
    $testrepo_labels = VersioncontrolGitTestCase::TESTREPO_COUNT_BRANCHES + VersioncontrolGitTestCase::TESTREPO_COUNT_TAGS;
    $this->assertEqual($label_count, 2 * $testrepo_labels, t('Correct number of labels in {versioncontrol_labels} after non-bypassing purge.'));
  }

  /**
@@ -76,14 +78,16 @@ class VersioncontrolGitDataIntegrityTests extends VersioncontrolGitTestCase {
    $op_label_count = db_query('SELECT COUNT(*) FROM {versioncontrol_operation_labels}')->fetchField();
    $label_count = db_query('SELECT COUNT(*) FROM {versioncontrol_labels}')->fetchField();

    $this->assertEqual($ir_count, 36, t('Correct number of item revisions in {versioncontrol_item_revisions} table after bypassing purge.'));
    $this->assertEqual($ir_count, 2 * VersioncontrolGitTestCase::TESTREPO_COUNT_ITEM_REVISIONS, t('Correct number of item revisions in {versioncontrol_item_revisions} table after bypassing purge.'));
    // Two fewer b/c v_g_i_r does not record an entry for deleted items, of which we have one.
    $this->assertEqual($git_ir_count + 2, $ir_count, t('Two fewer {versioncontrol_git_item_revisions} records than {versioncontrol_item_revisions} records after bypassing purge.'));

    $this->assertEqual($op_count, 32, t('Correct number of operations in {versioncontrol_operations} table after bypassing purge.'));
    $this->assertEqual($op_count, 2 * VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATIONS, t('Correct number of operations in {versioncontrol_operations} table after bypassing purge.'));
    $this->assertEqual($git_op_count, $op_count, t('Equal number of {versioncontrol_git_operations} and {versioncontrol_operations} records after bypassing purge.'));
    $this->assertEqual($op_label_count, 102, t("Correct number of operation/label mappings in {versioncontrol_operation_labels} after bypassing purge. ($op_label_count)"));
    $testrepo_op_label_maps = VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_BRANCH_MAP + VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_TAG_MAP;
    $this->assertEqual($op_label_count, 2 * $testrepo_op_label_maps, t("Correct number of operation/label mappings in {versioncontrol_operation_labels} after bypassing purge. ($op_label_count)"));

    $this->assertEqual($label_count, 14, t('Correct number of labels in {versioncontrol_labels} after bypassing purge.'));
    $testrepo_labels = VersioncontrolGitTestCase::TESTREPO_COUNT_BRANCHES + VersioncontrolGitTestCase::TESTREPO_COUNT_TAGS;
    $this->assertEqual($label_count, 2 * $testrepo_labels, t('Correct number of labels in {versioncontrol_labels} after bypassing purge.'));
  }
}
+19 −13
Changes for tests/VersioncontrolGitTestCase.test: 19 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -3,6 +3,14 @@
require_once drupal_get_path('module', 'versioncontrol') . '/tests/VersioncontrolTestCase.test';

abstract class VersioncontrolGitTestCase extends VersioncontrolTestCase {
  const TESTREPO_COUNT_BRANCHES = 4;
  const TESTREPO_COUNT_TAGS = 3;
  const TESTREPO_COUNT_OPERATIONS = 16;
  // feature: 7, fixes: 11, enhacements: 11, master: 16
  const TESTREPO_COUNT_OPERATION_BRANCH_MAP = 45;
  // annotated: 2, signed: 2, simple: 2
  const TESTREPO_COUNT_OPERATION_TAG_MAP = 6;
  const TESTREPO_COUNT_ITEM_REVISIONS = 18;

  /**
   * An internal counter used to prevent filesystem collisions when creating
@@ -117,14 +125,8 @@ abstract class VersioncontrolGitTestCase extends VersioncontrolTestCase {
  /**
   * Run history synchronization on an instance of the standard test repository.
   *
   * The test repository has the following characteristics:
   *
   *  - 16 commits
   *  - 18 'items' (files)
   *  - 4 branches - master, enhancements, feature, fixes
   *  - 3 tags - simple, signed, annotated (each having the characteristics
   *    for which they're named)
   *  - 51 commit/label mappings
   * See VersioncontrolGitTestCase::TESTREPO_COUNT_* constants for repository
   * characteristics.
   *
   * @param VersioncontrolGitRepository $repository
   *   The VersioncontrolGitRepository object representing the test repository
@@ -137,11 +139,15 @@ abstract class VersioncontrolGitTestCase extends VersioncontrolTestCase {
      // It's pointless to run these checks more than once.
      $this->testRepoChecked = TRUE;
      $this->assertTrue($synced, t('Sync of test repository completed successfully.'));
      $this->assertEqual(count($repository->loadCommits()), 16, t('Sync of test repository resulted in correct number of commits.'));
      $this->assertEqual(count($repository->loadBranches()), 4, t('Sync of test repository resulted in correct number of branches.'));
      $this->assertEqual(count($repository->loadTags()), 3, t('Sync of test repository resulted in correct number of tags.'));
      $this->assertEqual(count($repository->loadCommits()), VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATIONS, t('Sync of test repository resulted in correct number of commits.'));
      $this->assertEqual(count($repository->loadBranches()), VersioncontrolGitTestCase::TESTREPO_COUNT_BRANCHES, t('Sync of test repository resulted in correct number of branches.'));
      $this->assertEqual(count($repository->loadTags()), VersioncontrolGitTestCase::TESTREPO_COUNT_TAGS, t('Sync of test repository resulted in correct number of tags.'));
      $op_label_count = db_query('SELECT COUNT(*) FROM {versioncontrol_operation_labels} vol INNER JOIN {versioncontrol_labels} vl ON vol.label_id = vl.label_id WHERE vl.repo_id = :repo_id', array('repo_id' => $repository->repo_id))->fetchField();
      $this->assertEqual($op_label_count, 51, t('Sync of test repository resulted in correct number of commit/label mappings.'));
      // By default the reposync plugin use 0x03, which means
      // VersioncontrolGitRepositoryHistorySynchronizerDefault::MAP_COMMIT_BRANCH_RELATIONS |
      // VersioncontrolGitRepositoryHistorySynchronizerDefault::MAP_COMMIT_TAG_RELATIONS
      $test_repository_operation_label_mappings = VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_BRANCH_MAP + VersioncontrolGitTestCase::TESTREPO_COUNT_OPERATION_TAG_MAP;
      $this->assertEqual($op_label_count, $test_repository_operation_label_mappings, t('Sync of test repository resulted in correct number of commit/label mappings.'));
    }
  }

@@ -275,7 +281,7 @@ abstract class VersioncontrolGitTestCase extends VersioncontrolTestCase {
    }

    if ($sync) {
      $repository->sync();
      $this->assertTrue($repository->sync(), t('Repository synchronization was run correctly.'));
    }
  }