class commandCase

  1. 8.0.x tests/commandTest.php commandCase
  2. 6.x tests/commandTest.php commandCase
  3. 7.x tests/commandTest.php commandCase
  4. 4.x tests/commandTest.php commandCase
  5. 5.x tests/commandTest.php commandCase
  6. master tests/commandTest.php commandCase

@group base

Hierarchy

Expanded class hierarchy of commandCase

Members

Contains filters are case sensitive
Namesort ascending Modifiers Type Description
Drush_TestCase::__construct function
Drush_TestCase::_escapeshellarg_windows public static function
Drush_TestCase::webroot function
Drush_TestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory.
Drush_TestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
Drush_TestCase::setUpDrupal function
Drush_TestCase::setUpBeforeClass public static function Assure that each class starts with an empty sandbox directory and a clean environment - http://drupal.org/node/1103568.
Drush_TestCase::randomString public function Helper function to generate a random string of arbitrary length.
Drush_TestCase::log_level function
Drush_TestCase::log function Print a log message to the console.
Drush_TestCase::is_windows public static function
Drush_TestCase::get_tar_executable public static function
Drush_TestCase::getOutputFromJSON function Accessor for the last output, decoded from json.
Drush_TestCase::getOutputAsList function Accessor for the last output.
Drush_TestCase::getOutput function Accessor for the last output.
Drush_TestCase::fetchInstallDrupal function
Drush_TestCase::escapeshellarg public static function
Drush_TestCase::drupalSitewideDirectory function
Drush_TestCase::directory_cache function
Drush_TestCase::db_url function
Drush_TestCase::db_driver function
Drush_TestCase::convert_path function Converts a Windows path (dir1\dir2\dir3) into a Unix path (dir1/dir2/dir3). Also converts a cygwin "drive emulation" path (/cygdrive/c/dir1) into a proper drive path, still with Unix slashes (c:/dir1).
Drush_TestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
Drush_CommandTestCase::EXIT_SUCCESS constant
Drush_CommandTestCase::EXIT_ERROR constant
Drush_CommandTestCase::execute function Actually runs the command. Does not trap the error stream output as this need PHP 4.3+.
Drush_CommandTestCase::drush_major_version function
Drush_CommandTestCase::drush function Invoke drush in via execute().
commandCase::testUnknownOptions public function Assert that unknown options are caught and flagged as errors
commandCase::testRequirementBootstrapPhase public function Assert that minimum bootstrap phase is honored.
commandCase::testMissingDrushDependency public function Assert that commands depending on unknown commandfiles are detected.
commandCase::testMissingCommandCallback public function Assert that errors are thrown for commands with missing callbacks.
commandCase::testInvoke public function
commandCase::testDisabledModule public function Assert that commands in disabled modules are detected.

File

tests/commandTest.php, line 6

View source
class commandCase extends Drush_CommandTestCase {
  public function testInvoke() {
    $expected = array(
      'unit_drush_init',
      'drush_unit_invoke_init',
      'drush_unit_invoke_validate',
      'drush_unit_pre_unit_invoke',
      'drush_unit_invoke_primary',
      
      // Primary callback is not invoked when command specifies a 'callback'.
      // 'drush_unit_invoke',
      'drush_unit_post_unit_invoke',
      'drush_unit_post_unit_invoke_rollback',
      'drush_unit_pre_unit_invoke_rollback',
      'drush_unit_invoke_validate_rollback',
    );

    $options = array(
      'include' => dirname(__FILE__),
    );
    $this->drush('unit-invoke', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $called = $this->getOutputFromJSON();
    $this->assertSame($expected, $called);
  }

  /**
   * Assert that minimum bootstrap phase is honored.
   *
   * Not testing dependency on a module since that requires an installed Drupal.
   * Too slow for little benefit.
   */
  public function testRequirementBootstrapPhase() {
    // Assure that core-cron fails when run outside of a Drupal site.
    $return = $this->drush('core-cron', array(), array('quiet' => NULL), NULL, NULL, self::EXIT_ERROR);
  }

  /**
   * Assert that unknown options are caught and flagged as errors
   */
  public function testUnknownOptions() {
    // Make sure an ordinary 'version' command works
    $return = $this->drush('version', array(), array('pipe' => NULL));
    // Add an unknown option --magic=1234 and insure it fails
    $return = $this->drush('version', array(), array('pipe' => NULL, 'magic' => 1234), NULL, NULL, self::EXIT_ERROR);
    // Finally, add in a hook that uses drush_hook_help_alter to allow the 'magic' option.
    // We need to run 'drush cc drush' to clear the commandfile cache; otherwise, our include will not be found.
    $include_path = dirname(__FILE__) . '/hooks/magic_help_alter';
    $this->drush('version', array(), array('include' => $include_path, 'pipe' => NULL, 'magic' => '1234', 'strict' => NULL));
  }

  /**
   * Assert that errors are thrown for commands with missing callbacks.
   */
  public function testMissingCommandCallback() {
    $options = array(
      'include' => dirname(__FILE__), // Find unit.drush.inc commandfile. //'show-invoke' => TRUE,
    );
    $this->drush('missing-callback', array(), $options, NULL, NULL, self::EXIT_ERROR);
  }

  /**
   * Assert that commands depending on unknown commandfiles are detected.
   */
  public function testMissingDrushDependency() {
    $options = array(
      'include' => dirname(__FILE__), // Find unit.drush.inc commandfile.
      'backend' => NULL, // To obtain and parse the error log.
    );
    $this->drush('unit-drush-dependency', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $parsed = parse_backend_output($this->getOutput());
    $this->assertArrayHasKey("DRUSH_COMMANDFILE_DEPENDENCY_ERROR", $parsed['error_log']);
  }

  /**
   * Assert that commands in disabled modules are detected.
   */
  public function testDisabledModule() {
    $sites = $this->setUpDrupal(1, TRUE);
    $uri = key($sites);
    $root = $this->webroot();
    $options = array(
      'root' => $root,
      'uri' => $uri,
      'cache' => NULL,
    );
    $this->drush('pm-download', array('devel'), $options);
    $options += array(
      'backend' => NULL, // To obtain and parse the error log.
    );
    $this->drush('devel-download', array(), $options, NULL, NULL, self::EXIT_ERROR);
    $parsed = parse_backend_output($this->getOutput());
    $this->assertArrayHasKey("DRUSH_COMMAND_DEPENDENCY_ERROR", $parsed['error_log']);
  }
}