You are here

advancedqueue.test in Advanced Queue 7

File

tests/advancedqueue.test
View source
<?php

/**
 * @file
 *   Advancedqueue Simpletests.
 */
require_once 'advancedqueue_test.inc';

/**
 * Validate that a AdvancedQueue works as a normal queue.
 *
 * Note this class extends core's QueueTestCase, so we use its tests.
 */
class AdvancedQueueTestCase extends QueueTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Advanced queue',
      'description' => 'Validate that a Advanced Queue works as a normal queue.',
      'group' => 'Advanced Queue',
    );
  }
  function setUp() {
    parent::setUp('advancedqueue');
    variable_set('queue_default_class', 'AdvancedQueue');
  }

}

/**
 * Check cron functionality.
 */
class AdvancedQueueCronTestCase extends DrupalWebTestCase {
  protected $admin_user;
  public static function getInfo() {
    return array(
      'name' => 'Cron functionality',
      'description' => 'Workers called by cron, and admin options.',
      'group' => 'Advanced Queue',
    );
  }
  function setUp() {
    parent::setup('advancedqueue_test');
    variable_set('queue_default_class', 'AdvancedQueue');

    // Admin user for admin page check.
    $this->admin_user = $this
      ->drupalCreateUser(array(
      'administer site configuration',
    ));
  }

  /**
   * Test cron calls workers.
   */
  function testCronWorker() {
    $data = advancedqueue_test_populate_two_queues();
    variable_set('advancedqueue_use_cron', TRUE);
    $this
      ->cronRun();
    $count = 0;

    // Check to see that all items were sent to the worker.
    foreach ($data as $item) {
      $count += advancedqueue_test_count_watchdog('advancedqueue_test', 'advancedqueue_test_worker(@item)', array(
        '@item' => print_r($item, TRUE),
      ), WATCHDOG_INFO);
    }
    $this
      ->assertEqual($count, 8, t('All queued items sent to worker.'));
  }

  /**
   * Test admin page options.
   */
  function testAdminOption() {
    $this
      ->drupalLogin($this->admin_user);
    $this
      ->drupalGet('admin/config/system/cron');
    $this
      ->assertField('edit-advancedqueue-use-cron', t('Advancedqueue use cron option.'));
    $this
      ->assertNoFieldChecked('edit-advancedqueue-use-cron', t('Advancedqueue use cron option default unchecked.'));
    $edit = array(
      'advancedqueue_use_cron' => TRUE,
    );
    $this
      ->drupalPost(NULL, $edit, t('Save configuration'));
    $this
      ->assertFieldChecked('edit-advancedqueue-use-cron', t('Advancedqueue cron enabled successfully.'));
    $this
      ->drupalLogout();
  }

}

Classes

Namesort descending Description
AdvancedQueueCronTestCase Check cron functionality.
AdvancedQueueTestCase Validate that a AdvancedQueue works as a normal queue.