class tablesUnitTest

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

@file Unit tests for table formatting.

@group base

Hierarchy

Expanded class hierarchy of tablesUnitTest

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
Drush_TestCase::bit_bucket function Borrowed from Drush. Checks operating system and returns supported bit bucket folder.
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::db_driver function
Drush_TestCase::db_url function
Drush_TestCase::directory_cache function
Drush_TestCase::drupalSitewideDirectory function
Drush_TestCase::escapeshellarg public static function
Drush_TestCase::fetchInstallDrupal function
Drush_TestCase::getOutput function Accessor for the last output.
Drush_TestCase::getOutputAsList function Accessor for the last output.
Drush_TestCase::getOutputFromJSON function Accessor for the last output, decoded from json.
Drush_TestCase::get_tar_executable public static function
Drush_TestCase::is_windows public static function
Drush_TestCase::log function Print a log message to the console.
Drush_TestCase::log_level function
Drush_TestCase::randomString public function Helper function to generate a random string of arbitrary length.
Drush_TestCase::setUpDrupal function
Drush_TestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
Drush_TestCase::webroot function
Drush_TestCase::_escapeshellarg_windows public static function
Drush_TestCase::__construct function
Drush_UnitTestCase::drush_major_version function
Drush_UnitTestCase::setUpBeforeClass public static function Minimally bootstrap drush Overrides Drush_TestCase::setUpBeforeClass
Drush_UnitTestCase::tearDownAfterClass public static function Runs after all tests in a class are run. Remove sandbox directory. Overrides Drush_TestCase::tearDownAfterClass
tablesUnitTest::setUp function
tablesUnitTest::tearDown function
tablesUnitTest::testFormatAutoWidths public function Tests drush_format_table() at various table widths with automatic column sizing.
tablesUnitTest::testFormatTableHeader public function Tests drush_format_table() with a header.
tablesUnitTest::testFormatTableWordWrap public function Tests drush_format_table() with word wrapping.
tablesUnitTest::testFormatWidths public function Tests drush_format_table() at various table widths.

File

tests/tablesUnitTest.php, line 9
Unit tests for table formatting.

View source
class tablesUnitTest extends Drush_UnitTestCase {
  function setUp() {
    // Bootstrap to ensure the Console_Table library is present and included.
    drush_bootstrap(DRUSH_BOOTSTRAP_DRUSH);
    $this->original_columns = drush_get_context('DRUSH_COLUMNS');

    // Some table data we reuse between tests.
    $this->numbers = array(
      array('1', '12', '123'),
      array('1234', '12345', '123456'),
      array('1234567', '12345678', '123456789'),
    );
    $this->words = array(
      array('Drush is a command line shell', 'scripting interface', 'for Drupal'),
      array('A veritable', 'Swiss Army knife', 'designed to make life easier for us'),
    );
  }

  function tearDown() {
    drush_set_context('DRUSH_COLUMNS', $this->original_columns);
  }

  /**
   * Tests drush_format_table() at various table widths with automatic column
   * sizing.
   *
   * @see drush_format_table().
   */
  public function testFormatAutoWidths() {
    // print "\n'" . str_replace("\n", "' . PHP_EOL . '", $output) . "'\n";
    drush_set_context('DRUSH_COLUMNS', 16);
    $output = drush_format_table($this->numbers);
    $expected = ' 1    12   123  ' . PHP_EOL . ' 123  123  1234 ' . PHP_EOL . ' 4    45   56   ' . PHP_EOL . ' 123  123  1234 ' . PHP_EOL . ' 456  456  5678 ' . PHP_EOL . ' 7    78   9    ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    drush_set_context('DRUSH_COLUMNS', 22);
    $output = drush_format_table($this->numbers);
    $expected = ' 1      12     123    ' . PHP_EOL . ' 1234   12345  123456 ' . PHP_EOL . ' 12345  12345  123456 ' . PHP_EOL . ' 67     678    789    ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    drush_set_context('DRUSH_COLUMNS', 24);
    $output = drush_format_table($this->numbers);
    $expected = ' 1       12      123    ' . PHP_EOL . ' 1234    12345   123456 ' . PHP_EOL . ' 123456  123456  123456 ' . PHP_EOL . ' 7       78      789    ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    drush_set_context('DRUSH_COLUMNS', 80);
    $output = drush_format_table($this->numbers);
    $expected = ' 1        12        123       ' . PHP_EOL . ' 1234     12345     123456    ' . PHP_EOL . ' 1234567  12345678  123456789 ' . PHP_EOL;
    $this->assertEquals($expected, $output);
  }

  /**
   * Tests drush_format_table() at various table widths.
   *
   * @see drush_format_table().
   */
  public function testFormatWidths() {
    // print "\n'" . str_replace("\n", "' . PHP_EOL . '", $output) . "'\n";
    drush_set_context('DRUSH_COLUMNS', 22);
    $output = drush_format_table($this->numbers, FALSE, array(2));
    $expected = ' 1   12       123     ' . PHP_EOL . ' 12  12345    123456  ' . PHP_EOL . ' 34                   ' . PHP_EOL . ' 12  1234567  1234567 ' . PHP_EOL . ' 34  8        89      ' . PHP_EOL . ' 56                   ' . PHP_EOL . ' 7                    ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    $output = drush_format_table($this->numbers, FALSE, array(10));
    $expected = ' 1           12   123 ' . PHP_EOL . ' 1234        123  123 ' . PHP_EOL . '             45   456 ' . PHP_EOL . ' 1234567     123  123 ' . PHP_EOL . '             456  456 ' . PHP_EOL . '             78   789 ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    $output = drush_format_table($this->numbers, FALSE, array(2, 2));
    $expected = ' 1   12  123       ' . PHP_EOL . ' 12  12  123456    ' . PHP_EOL . ' 34  34            ' . PHP_EOL . '     5             ' . PHP_EOL . ' 12  12  123456789 ' . PHP_EOL . ' 34  34            ' . PHP_EOL . ' 56  56            ' . PHP_EOL . ' 7   78            ' . PHP_EOL;
    $this->assertEquals($expected, $output);

    $output = drush_format_table($this->numbers, FALSE, array(4, 4, 4));
    $expected = ' 1     12    123  ' . PHP_EOL . ' 1234  1234  1234 ' . PHP_EOL . '       5     56   ' . PHP_EOL . ' 1234  1234  1234 ' . PHP_EOL . ' 567   5678  5678 ' . PHP_EOL . '             9    ' . PHP_EOL;
    $this->assertEquals($expected, $output);
  }

  /**
   * Tests drush_format_table() with a header.
   *
   * @see drush_format_table().
   */
  public function testFormatTableHeader() {
    drush_set_context('DRUSH_COLUMNS', 16);
    $rows = $this->numbers;
    array_unshift($rows, array('A', 'B', 'C'));
    $output = drush_format_table($rows, TRUE);
    $expected = ' A    B    C    ' . PHP_EOL . ' 1    12   123  ' . PHP_EOL . ' 123  123  1234 ' . PHP_EOL . ' 4    45   56   ' . PHP_EOL . ' 123  123  1234 ' . PHP_EOL . ' 456  456  5678 ' . PHP_EOL . ' 7    78   9    ' . PHP_EOL;
    $this->assertEquals($expected, $output);
  }

  /**
   * Tests drush_format_table() with word wrapping.
   *
   * @see drush_format_table().
   */
  public function testFormatTableWordWrap() {
    drush_set_context('DRUSH_COLUMNS', 60);
    $output = drush_format_table($this->words);
    $expected = ' Drush is a command  scripting         for Drupal         ' . PHP_EOL . ' line shell          interface                            ' . PHP_EOL . ' A veritable         Swiss Army knife  designed to make   ' . PHP_EOL . '                                       life easier for us ' . PHP_EOL;
    $this->assertEquals($expected, $output);
  }
}