class outputFormatUnitCase

  1. 8.0.x tests/outputFormatUnitTest.php outputFormatUnitCase
  2. 6.x tests/outputFormatUnitTest.php outputFormatUnitCase
  3. 7.x tests/outputFormatUnitTest.php outputFormatUnitCase
  4. master tests/outputFormatUnitTest.php outputFormatUnitCase

Namespace

Unish

Hierarchy

Expanded class hierarchy of outputFormatUnitCase

Members

Contains filters are case sensitive
Name Modifierssort descending Type Description
UnitUnishTestCase::drush_major_version function
UnishTestCase::__construct function
UnishTestCase::log function Print a log message to the console.
UnishTestCase::log_level function
UnishTestCase::tick function Print out a tick mark.
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::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
UnishTestCase::webroot function
UnishTestCase::getSites function
UnishTestCase::directory_cache function
UnishTestCase::db_url function
UnishTestCase::db_driver function
UnishTestCase::setUpDrupal function
UnishTestCase::fetchInstallDrupal function
UnishTestCase::writeSiteAlias function
UnishTestCase::unish_file_aliases function Prepare the contents of an aliases file.
UnishTestCase::drupalSitewideDirectory function
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed.
outputFormatUnitCase::testOutputFormat public function Test various output formats using php-eval with no Drupal site.
outputFormatUnitCase::provider public function
UnishTestCase::randomString public function Helper function to generate a random string of arbitrary length.
UnitUnishTestCase::setUpBeforeClass public static function Minimally bootstrap drush Overrides UnishTestCase::setUpBeforeClass
UnitUnishTestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory. Overrides UnishTestCase::tearDownAfterClass
UnishTestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
UnishTestCase::is_windows public static function
UnishTestCase::get_tar_executable public static function
UnishTestCase::escapeshellarg public static function
UnishTestCase::_escapeshellarg_windows public static function

File

tests/outputFormatUnitTest.php, line 10
Tests for outputformat.drush.inc

View source
class outputFormatUnitCase extends UnitUnishTestCase {

  /**
   * Test various output formats using php-eval with no Drupal site.
   *
   * @dataProvider provider
   **/
  public function testOutputFormat($name, $format, $data, $expected) {
    drush_preflight();
    $this->assertEquals($expected, trim(drush_format($data, array(), $format)), $name . ': ' . $format);
  }

  public function provider() {
    $json = '{"a":{"b":2,"c":3},"d":{"e":5,"f":6}}';
    if (version_compare(phpversion(), '5.4.0', '>=')) {
      $json = json_encode(json_decode($json), JSON_PRETTY_PRINT);
    }

    return array(
      array(
        'name' => 'String test',
        'format' => 'string',
        'data' => array('drush version' => '6.0-dev'),
        'expected' => '6.0-dev',
      ),
      array(
        'name' => 'List test',
        'format' => 'list',
        'data' => array('drush version' => '6.0-dev'),
        'expected' => '6.0-dev',
      ),
      array(
        'name' => 'Key-value test',
        'format' => 'key-value',
        'data' => array('drush version' => '6.0-dev'),
        'expected' => 'drush version   :  6.0-dev',
      ),
      
      //      array(
      //        'name' => 'Table test',
      //        'format' => 'table',
      //        'data' => array(
      //          'a' => array('b' => 2, 'c' => 3),
      //          'd' => array('b' => 5, 'c' => 6),
      //        ),
      //        'expected' => "b  c
      // 2  3
      // 5  6",
      //        ),
      array(
        'name' => 'print-r test',
        'format' => 'print-r',
        'data' => array(
          'a' => array(
            'b' => 2,
            'c' => 3,
          ),
          'd' => array(
            'b' => 5,
            'c' => 6,
          ),
        ),
        'expected' => "Array
(
    [a] => Array
        (
            [b] => 2
            [c] => 3
        )

    [d] => Array
        (
            [b] => 5
            [c] => 6
        )

)",
      ),
      array(
        'name' => 'json test',
        'format' => 'json',
        'data' => array(
          'a' => array(
            'b' => 2,
            'c' => 3,
          ),
          'd' => array(
            'e' => 5,
            'f' => 6,
          ),
        ),
        'expected' => $json,
      ),
      
      //      array(
      //        'name' => 'key-value test 1d array',
      //        'format' => 'key-value',
      //        'data' => array(
      //          'b' => 'Two B or ! Two B, that is the comparison',
      //          'c' => 'I see that C has gone to Sea',
      //        ),
      //        'expected' => "b   :  Two B or ! Two B, that is the comparison
      // c   :  I see that C has gone to Sea",
      //      ),
      //      array(
      //        'name' => 'key-value test 2d array',
      //        'format' => 'key-value',
      //        'data' => array(
      //          'a' => array(
      //            'b' => 'Two B or ! Two B, that is the comparison',
      //            'c' => 'I see that C has gone to Sea',
      //          ),
      //          'd' => array(
      //            'e' => 'Elephants and electron microscopes',
      //            'f' => 'My margin is too small',
      //          )
      //        ),
      //        'expected' => "a   :  Two B or ! Two B, that is the comparison
      //        I see that C has gone to Sea
      // d   :  Elephants and electron microscopes
      //        My margin is too small",
      //      ),
      array(
        'name' => 'export test',
        'format' => 'var_export',
        'data' => array(
          'a' => array(
            'b' => 2,
            'c' => 3,
          ),
          'd' => array(
            'e' => 5,
            'f' => 6,
          ),
        ),
        'expected' => "array(
  'a' => array(
    'b' => 2,
    'c' => 3,
  ),
  'd' => array(
    'e' => 5,
    'f' => 6,
  ),
)",
      ),
      
      //      array(
      //        'name' => 'config test',
      //        'format' => 'config',
      //        'data' => array(
      //          'a' => array('b' => 2, 'c' => 3),
      //          'd' => array('e' => 5, 'f' => 6),
      //        ),
      //        'expected' => "\$config[\"a\"] = array (
      //  'b' => 2,
      //  'c' => 3,
      //);
      //\$config[\"d\"] = array (
      //  'e' => 5,
      //  'f' => 6,
      //);",
      //      ),
      array(
        'name' => 'variables test',
        'format' => 'variables',
        'data' => array(
          'a' => array(
            'b' => 2,
            'c' => 3,
          ),
          'd' => array(
            'e' => 5,
            'f' => 6,
          ),
        ),
        'expected' => "\$a[\"b\"] = 2;
\$a[\"c\"] = 3;
\$d[\"e\"] = 5;
\$d[\"f\"] = 6;",
      ),
    );
  }
}