You are here

function SmartqueueDomainAdminTest::testCreateSubqueues in Smartqueue Domain 7

Tests creation and deleted of subqueues.

File

tests/smartqueue_domain.test, line 86
Simpletest for Smartqueue domain module.

Class

SmartqueueDomainAdminTest

Code

function testCreateSubqueues() {

  // Handle user.
  $user = $this
    ->drupalCreateUser(array(
    'administer nodequeue',
  ));
  $this
    ->drupalLogin($user);

  // Create some secondary domains (primary domain is already created).
  $result = $this
    ->domainCreateDomains();

  // ---- 1 ----
  // First, let's test that a subqueue will be automatigically created for
  // each domain when a smartqueue is created.
  // Create a smartqueue.
  $qid = $this
    ->smartqueueDomainCreateSmartqueue();

  // Get ids for all created subqueues.
  $sqids = $this
    ->smartqueueDomainGetSqids($qid);

  // Assert that a subqueue was created for each domain. We need to call
  // domain_domains() to retrieve all domains (including default).
  $domains = domain_domains(TRUE);
  foreach ($domains as $domain) {
    $this
      ->assertTrue(isset($sqids[$domain['domain_id']]), format_string('Subqueue successfully create for domain %domain_id.', array(
      '%domain_id' => $domain['domain_id'],
    )));
  }

  // Double check that the number of subqueues matches the number of domains.
  $this
    ->assertTrue(count($domains) == count($sqids), format_string('%num subqueues successfully created.', array(
    '%num' => count($sqids),
  )));

  // ---- 2 ----
  // Second, test that a new subqueue will be added to our smartqueue when
  // a new domain record is created.
  // Create a new domain.
  $new_result = $this
    ->domainCreateDomains(array(
    'four',
  ));

  // Get new domain id.
  $new_domain_id = $new_result['four']['domain_id'];

  // Get ids for all subqueues.
  $sqids = $this
    ->smartqueueDomainGetSqids($qid);

  // Assert that a new subqueue was created for the new domain.
  $this
    ->assertTrue(isset($sqids[$new_domain_id]), format_string('After new domain record (%domain_id) added, subqueue for domain successfully created.', array(
    '%domain_id' => $new_domain_id,
  )));

  // ---- 3 ----
  // Finally, test that a subqueue intended for a domain will disappear
  // once that domain record is deleted.
  // Get id for the soon-to-be deleted domain.
  $deleted_domain_id = $result['three']['domain_id'];

  // Delete the domain.
  domain_delete($result['three']);

  // Get ids for all subqueues.
  $sqids = $this
    ->smartqueueDomainGetSqids($qid);

  // Assert that a subqueue no longer exists for the deleted domain.
  $this
    ->assertTrue(!isset($sqids[$deleted_domain_id]), format_string('After domain record (%domain_id) deleted, subqueue for domain successfully deleted.', array(
    '%domain_id' => $deleted_domain_id,
  )));
}