class outputFormatCase

  1. 8.0.x tests/outputFormatTest.php outputFormatCase
  2. 6.x tests/outputFormatTest.php outputFormatCase
  3. 7.x tests/outputFormatTest.php outputFormatCase

@todo, Consider removing these tests now that we have outputFormatUnitCase.

@group slow @group base

Namespace

Unish

Hierarchy

Expanded class hierarchy of outputFormatCase

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
CommandUnishTestCase::$coverage_data protected property Code coverage data collected during a single test.
CommandUnishTestCase::$defaultIdleTimeout private property Default idle timeout for commands.
CommandUnishTestCase::$defaultTimeout private property Default timeout for commands.
CommandUnishTestCase::$idleTimeout protected property Idle timeouts for commands.
CommandUnishTestCase::$process private property Process of last executed command.
CommandUnishTestCase::$timeout protected property Timeout for command.
CommandUnishTestCase::drush function Invoke drush in via execute().
CommandUnishTestCase::drush_major_version function
CommandUnishTestCase::execute function Actually runs the command.
CommandUnishTestCase::EXIT_ERROR constant
CommandUnishTestCase::EXIT_SUCCESS constant
CommandUnishTestCase::getErrorOutput function Accessor for the last stderr output, trimmed.
CommandUnishTestCase::getErrorOutputAsList function Accessor for the last stderr output, rtrimmed and split on newlines.
CommandUnishTestCase::getErrorOutputRaw function Accessor for the last stderr output, non-trimmed.
CommandUnishTestCase::getOutput function Accessor for the last output, trimmed.
CommandUnishTestCase::getOutputAsList function Accessor for the last output, rtrimmed and split on newlines.
CommandUnishTestCase::getOutputFromJSON function Accessor for the last output, decoded from json.
CommandUnishTestCase::getOutputRaw function Accessor for the last output, non-trimmed.
CommandUnishTestCase::parse_backend_output function A slightly less functional copy of drush_backend_parse_output().
CommandUnishTestCase::run public function Override the run method, so we can add in our code coverage data after the test has run.
CommandUnishTestCase::UNISH_EXITCODE_USER_ABORT constant
outputFormatCase::getDataForDrupal public function
outputFormatCase::testOutputFormatWithDrupal public function Test output formats using various Drush commands on a Drupal site.
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed.
UnishTestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
UnishTestCase::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).
UnishTestCase::db_driver function
UnishTestCase::db_url function
UnishTestCase::directory_cache function
UnishTestCase::drupalSitewideDirectory function
UnishTestCase::escapeshellarg public static function
UnishTestCase::fetchInstallDrupal function
UnishTestCase::getSites function
UnishTestCase::get_tar_executable public static function
UnishTestCase::is_windows public static function
UnishTestCase::log function Print a log message to the console.
UnishTestCase::log_level function
UnishTestCase::randomString public function Helper function to generate a random string of arbitrary length.
UnishTestCase::setUpBeforeClass public static function Assure that each class starts with an empty sandbox directory and a clean environment - http://drupal.org/node/1103568.
UnishTestCase::setUpDrupal function
UnishTestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
UnishTestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory.
UnishTestCase::tick function Print out a tick mark.
UnishTestCase::unish_file_aliases function Prepare the contents of an aliases file.
UnishTestCase::webroot function
UnishTestCase::writeSiteAlias function
UnishTestCase::_escapeshellarg_windows public static function
UnishTestCase::__construct function

File

tests/outputFormatTest.php, line 15

View source
class outputFormatCase extends CommandUnishTestCase {

  /**
   * Test output formats using various Drush commands on a Drupal site.
   *
   * Cannot use dataProvider since we want to share one setUpDrupal(),
   **/
  public function testOutputFormatWithDrupal() {
    $data = $this->getDataForDrupal();
    $sites = $this->setUpDrupal(1, TRUE);
    $site_options = array(
      'root' => $this->webroot(),
      'uri' => key($sites),
    );
    $this->drush('pm-download', array('devel'), $site_options + array('cache' => NULL, 'skip' => TRUE));

    foreach ($data as $row) {
      extract($row);
      $name = $name . ": ";
      // We need to specify a fixed column width so that word wrapping does
      // not change our output contrary to our expectations when run in
      // a narrow terminal window.
      $env = array(
        'COLUMNS' => '800',
      );
      $this->drush($command, $args, $site_options + $options + array('format' => $format), NULL, NULL, self::EXIT_SUCCESS, NULL, $env);
      $output = implode("\n", $this->getOutputAsList()); // note: we consider trailing eols insignificant
      // If the Drupal command we are running might produce variable output,
      // we can use one or more output filters to simplify the output down
      // to an invariant form.
      foreach ($output_filter as $regex => $replacement) {
        $output = preg_replace($regex, $replacement, $output);
      }
      $this->assertEquals($name . $expected, $name . $output);
    }
  }

  public function getDataForDrupal() {
    $unish_tmp = UNISH_TMP; // Need local variable.
    return array(
      array(
        'name' => 'Status test - drush version / list',
        'command' => 'core-status',
        'args' => array('drush version'),
        'options' => array(),
        'format' => 'list',
        'output_filter' => array('/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev',),
        'expected' => '0.0-dev',
      ),
      
      //      array(
      //        'name' => 'Status test - drush / ini',
      //        'command' => 'core-status',
      //        'args' => array('drush'),
      //        'format' => 'ini',
      //        'output_filter' => array('/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev', '#/.*/etc/drush#' => '/etc/drush'),
      //        'expected' => 'drush-version=0.0-dev
      //drush-conf=
      //drush-alias-files=/etc/drush/dev.alias.drushrc.php',
      //      ),
      array(
        'name' => 'Status test - drush / export',
        'command' => 'core-status',
        'args' => array('drush'),
        'options' => array(),
        'format' => 'var_export',
        'output_filter' => array(
          '/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev',
          '#/.*/etc/drush#' => '/etc/drush',
          "/'drush-script' => '.*drush.php'/" => "'drush-script' => 'drush.php'",
        ),
        'expected' => "array(
  'drush-script' => 'drush.php',
  'drush-version' => '0.0-dev',
  'drush-temp' => '$unish_tmp',
  'drush-conf' => array(),
  'drush-alias-files' => array(
    '/etc/drush/dev.alias.drushrc.php',
  ),
)",
      ),
      array(
        'name' => 'Status test - drush / key-value',
        'command' => 'core-status',
        'args' => array('drush'),
        'options' => array(),
        'format' => 'key-value',
        'output_filter' => array(
          '/[0-9]+\.[0-9]+[a-zA-Z0-9-]*/' => '0.0-dev',
          '#/.*/etc/drush#' => '/etc/drush',
          "/(Drush script *:  ).*drush.php/" => "Drush script:  drush.php",
        ),
        'expected' => "Drush script:  drush.php
 Drush version          :  0.0-dev
 Drush temp directory   :  $unish_tmp
 Drush configuration    :
 Drush alias files      :  /etc/drush/dev.alias.drushrc.php",
      ),
      
      /*
        core-requirements is a little hard to test, because the
        output can be quite variable

      array(
        'name' => 'Requirements test - table',
        'command' => 'core-requirements',
        'args' => array(),
        'format' => 'table',
        'output_filter' => array(),
        'expected' => "",
      ),
      */
      //      array(
      //        'name' => 'pm-updatestatus - table',
      //        'command' => 'pm-updatestatus',
      //        'args' => array(),
      //        'options' => array(),
      //        'format' => 'table',
      //        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
      //        'expected' => "Name    Installed Version  Proposed version  Message
      // Drupal  0.0               0.0              Up to date",
      //      ),
      /*
        pm-updatestatus --format=csv does not work.

        should filter out the items that do not need updating, and print just
        the name of the projects that need updates

      array(
        'name' => 'pm-updatestatus - csv',
        'command' => 'pm-updatestatus',
        'args' => array(),
        'format' => 'csv',
        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
        'expected' => "",
      ),
      */
      // updatestatus now omits projects that are up tp date. this test now needs work.
      //      array(
      //        'name' => 'pm-updatestatus - csv',
      //        'command' => 'pm-updatestatus',
      //        'args' => array(),
      //        'options' => array(),
      //        'format' => 'csv',
      //        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
      //        'expected' => "drupal,0.0,0.0,Up to date",
      //      ),
      /*
        pm-updatestatus --format=ini does not work

      array(
        'name' => 'pm-updatestatus - ini',
        'command' => 'pm-updatestatus',
        'args' => array(),
        'format' => 'ini',
        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
        'expected' => "",
      ),
      */
      //      array(
      //        'name' => 'pm-updatestatus - ini-sections',
      //        'command' => 'pm-updatestatus',
      //        'args' => array(),
      //        'format' => 'ini-sections',
      //        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
      //        'expected' => "[drupal]
      //short_name=drupal
      //installed_version=0.0
      //proposed_version=0.0
      //message=Up to date",
      //      ),
      /*
        pm-updatestatus --format=key-value does not work

      array(
        'name' => 'pm-updatestatus - key-value',
        'command' => 'pm-updatestatus',
        'args' => array(),
        'options' => array(),
        'format' => 'key-value',
        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0'),
        'expected' => "",
      ),
      */
      //      array(
      //        'name' => 'pm-updatestatus - key-value-list',
      //        'command' => 'pm-updatestatus',
      //        'args' => array(),
      //        'options' => array(),
      //        'format' => 'key-value-list',
      //        'output_filter' => array('/[0-9]+\.[0-9]+/' => '0.0', '/Update available/' => 'Up to date'),
      //        'expected' => "Name                :  Drupal
      // Installed Version   :  0.0
      // Proposed version    :  0.0
      // Message             :  Up to date",
      //      ),
      array(
        'name' => 'pm-info - key-value-list',
        'command' => 'pm-info',
        'args' => array('devel'),
        'options' => array('fields' => 'project,type,devel,description'),
        'format' => 'key-value-list',
        'output_filter' => array(),
        'expected' => "Project       :  devel
 Type          :  module
 Description   :  Various blocks, pages, and functions for developers.",
      ),
      array(
        'name' => 'pm-info - csv',
        'command' => 'pm-info',
        'args' => array('devel'),
        'options' => array('fields' => 'project,type,devel,description'),
        'format' => 'csv',
        'expected' => "devel,module,\"Various blocks, pages, and functions for developers.\"",
      ),
      
      /*
         pm-info --format=ini does not work.

         The output data could not be processed by the selected format 'string'.
         Multiple rows provided where only one is allowed.

      array(
        'name' => 'pm-info - ini',
        'command' => 'pm-info',
        'args' => array('devel'),
        'options' => array('fields' => 'project,type,devel,description'),
        'format' => 'ini',
        'expected' => "",
      ),
      */
      //      array(
      //        'name' => 'pm-info - ini-sections',
      //        'command' => 'pm-info',
      //        'args' => array('devel'),
      //        'options' => array('fields' => 'project,type,devel,description'),
      //        'format' => 'ini-sections',
      //        'expected' => "[devel]
      //project=devel
      //type=module
      //description=Various blocks, pages, and functions for developers.",
      //      ),
      /*
        pm-info --format=key-value does not respect --fields

      array(
        'name' => 'pm-info - key-value',
        'command' => 'pm-info',
        'args' => array('devel'),
        'options' => array('fields' => 'project,type,devel,description'),
        'format' => 'key-value',
        'expected' => "",
      ),
      */ array(
        'name' => 'pm-info - table',
        'command' => 'pm-info',
        'args' => array('devel'),
        'options' => array('fields' => 'project,type,description'),
        'format' => 'table',
        'output_filter' => array(),
        'expected' => "Project  Type    Description
 devel    module  Various blocks, pages, and functions for developers.",
      ),
      // More commands that also support output formats: // pm-list // queue-list // cache-get // config-get and config-list (D8 only) // field-info // php-eval // role-list // search-status // site-alias // user-information // variable-get // version // watchdog-list // watchdog-show
    );
  }
}