You are here

protected function DeployWebTestCase::runScenario in Deploy - Content Staging 7.2

Same name and namespace in other branches
  1. 7.3 deploy.test \DeployWebTestCase::runScenario()

This method runs a deployment scenario where we have one production site (the endpoint) and a staging site (the origin).

Both sites are "out of sync" content wise (as production/stage always are) but deployments of new and updated content are still possible.

@todo Conditionally test references modules too, since they are very likely too be used on most sites.

@todo Test with translations too.

5 calls to DeployWebTestCase::runScenario()
DeployAdhocPlanTestCase::testDeployment in modules/deploy_adhoc_plan/deploy_adhoc_plan.test
DeployAutoPlanNoDependencyPluginTestCase::testDeployment in modules/deploy_auto_plan/deploy_auto_plan.test
DeployAutoPlanTestCase::testDeployment in modules/deploy_auto_plan/deploy_auto_plan.test
DeployQueuedDeploymentTestCase::testDeployment in ./deploy.test
DeploySimpleDeploymentTestCase::testDeployment in ./deploy.test
Simple deployment scenario.

File

./deploy.test, line 266
Deployment tests.

Class

DeployWebTestCase
Helper class.

Code

protected function runScenario($plan_name) {

  // Switch to our production site.
  $this
    ->switchSite('deploy_origin', 'deploy_endpoint');

  // Intentionally force the sites out of sync by creating some content that
  // only exists in production.
  $user = $this
    ->drupalCreateUser();
  $term = $this
    ->createTerm();
  $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'uid' => $user->uid,
    'field_tags' => array(
      LANGUAGE_NONE => array(
        array(
          'tid' => $term->tid,
        ),
      ),
    ),
  ));

  // Switch to our staging site and push some new content.
  $this
    ->switchSite('deploy_endpoint', 'deploy_origin');
  $user_stage = $this
    ->drupalCreateUser();
  $term_stage = $this
    ->createTerm();
  $node_title_orig = $this
    ->randomString();
  $node_stage = $this
    ->drupalCreateNode(array(
    'type' => 'article',
    'title' => $node_title_orig,
    'uid' => $user_stage->uid,
    'field_tags' => array(
      LANGUAGE_NONE => array(
        array(
          'tid' => $term_stage->tid,
        ),
      ),
    ),
  ));
  list($nid_stage, $vid_stage) = entity_extract_ids('node', $node_stage);

  // If this base class should manage adding to the plan is configurable to
  // allow for modules like deploy_auto_plan.module to use other ways and
  // still be able to extend this class.
  if ($this->manage_add_to_plan) {

    // Now add the node to the plan.
    deploy_manager_add_to_plan($plan_name, 'node', $node_stage);
  }

  // Test that the node was added to the plan with the right identifiers.
  $count = db_query('SELECT COUNT(revision_id) FROM {deploy_manager_entities} WHERE plan_name = :plan_name AND entity_id = :nid AND revision_id = :vid', array(
    ':plan_name' => $plan_name,
    ':nid' => $nid_stage,
    ':vid' => $vid_stage,
  ))
    ->fetchField();
  $this
    ->assertEqual($count, 1, 'The entity was added to the deployment plan');

  // This will deploy the node only. But with dependencies (like the author
  // and the term).
  $this
    ->deployPlan($plan_name);

  // Switch to our production site and make sure the content was pushed.
  $this
    ->switchSite('deploy_origin', 'deploy_endpoint');

  // Load the deployed entities to test. Since we don't know their primary IDs
  // here on the production site we look them up using their UUIDs.
  $users = entity_uuid_load('user', array(
    $user_stage->uuid,
  ), array(), TRUE);
  $terms = entity_uuid_load('taxonomy_term', array(
    $term_stage->uuid,
  ), array(), TRUE);
  $nodes = entity_uuid_load('node', array(
    $node_stage->uuid,
  ), array(), TRUE);
  $user_prod = reset($users);
  $term_prod = reset($terms);
  $node_prod = reset($nodes);

  // Test to see if all entities are locally different, but universally the
  // same. They should be, since we forced the sites out of sync earlier.
  //
  // Test the node author.
  $test = $user_stage->uuid == $user_prod->uuid && $user_stage->uid != $user_prod->uid;
  $this
    ->assertTrue($test, 'New node author was deployed successfully.');

  // Test the term.
  $test = $term_stage->uuid == $term_prod->uuid && $term_stage->tid != $term_prod->tid;
  $this
    ->assertTrue($test, 'New term was deployed successfully.');

  // Test the node itself.
  $test = $node_stage->uuid == $node_prod->uuid && $node_stage->nid != $node_prod->nid;
  $this
    ->assertTrue($test, 'New node was deployed successfully.');

  // Test if the dependencies got attached to the node.
  $this
    ->assertEqual($node_prod->uid, $user_stage->uuid, 'Node author was successfully attached to node.');
  $this
    ->assertEqual($node_prod->field_tags[LANGUAGE_NONE][0]['tid'], $term_stage->uuid, 'Term was successfully attached to node.');

  // Now switch back to staging site and make updates to all entities to see
  // if updates is comming through, when a new deployment is done.
  $this
    ->switchSite('deploy_endpoint', 'deploy_origin');

  // Update the node.
  $node_stage->title = $this
    ->randomString();
  node_save($node_stage);

  // TODO: Update more entities in the dependency chain of the node.
  // Since we have a new revision ID we have to add the node again.
  if ($this->manage_add_to_plan) {
    deploy_manager_add_to_plan($plan_name, 'node', $node_stage);
  }

  // Now deploy the node again.
  $this
    ->deployPlan($plan_name);

  // Switch back to production to assert the changes.
  $this
    ->switchSite('deploy_origin', 'deploy_endpoint');
  $nodes = entity_uuid_load('node', array(
    $node_stage->uuid,
  ), array(), TRUE);
  $node_prod = reset($nodes);
  $test = $node_prod->title == $node_stage->title && $node_prod->title != $node_title_orig;
  $this
    ->assertTrue($test, 'Node was successfully updated after new deployment.');
}