home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (poormanscron.test)

This example Drupal source code file (poormanscron.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

200, array, configuration, cron_last, cron_safe_threshold, function, is, not, null, php, poormanscron, the, time, when

The poormanscron.test Drupal example source code

<?php
// $Id: poormanscron.test,v 1.1.2.2 2010/01/17 16:53:37 davereid Exp $

/**
 * @file
 * Unit tests for the poormanscron module.
 */

class PoormanscronUnitTest extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Poormanscron functionality',
      'description' => 'Tests the poormanscron module.',
      'group' => 'Poormanscron',
    );
  }

  function setUp() {
    parent::setUp('poormanscron');
    $this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
  }

  /**
   * Ensure that the cron image callback to run it automatically is working.
   */
  function testCronThreshold() {
    // Ensure cron does not run when the cron threshold is enabled and was
    // not passed.
    $cron_last = time();
    $cron_safe_threshold = 100;
    variable_set('cron_last', $cron_last);
    variable_set('cron_safe_threshold', $cron_safe_threshold);
    $this->drupalGet('');
    $this->assertRaw('"runNext": ' . ($cron_last + $cron_safe_threshold));
    $this->drupalGet('poormanscron/run-cron-check');
    $this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is not passed.'));

    // Test if cron runs when the cron threshold was passed.
    $cron_last = time() - 200;
    variable_set('cron_last', $cron_last);
    $this->drupalGet('');
    $this->assertRaw('"runNext": ' . ($cron_last + $cron_safe_threshold));
    $this->drupalGet('poormanscron/run-cron-check');
    $this->assertTrue($cron_last < variable_get('cron_last', NULL), t('Cron runs when the cron threshold is passed.'));

    // Disable the cron threshold through the interface.
    $this->drupalLogin($this->admin_user);
    $this->drupalPost('admin/settings/site-information', array('cron_safe_threshold' => 0), t('Save configuration'));
    $this->assertText(t('The configuration options have been saved.'));

    // Test if cron does not run when the cron threshold is disabled.
    $cron_last = time() - 200;
    variable_set('cron_last', $cron_last);
    $this->drupalGet('');
    $this->assertNoRaw('runNext');
    $this->drupalGet('poormanscron/run-cron-check');
    $this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is disabled.'));
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal poormanscron.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.