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

Unit tests for table formatting.

@group base

Namespace

Unish

Hierarchy

Expanded class hierarchy of tablesUnitTest

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
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.
UnishTestCase::$sites private static property A list of Drupal sites that have been recently installed. They key is the site name and values are details about each site.
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::mkdir public function
UnishTestCase::randomString public function Helper function to generate a random string of arbitrary length.
UnishTestCase::recursive_copy public function
UnishTestCase::setUpDrupal function
UnishTestCase::setUpFreshSandBox public static function Remove any pre-existing sandbox, then create a new one.
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
UnitUnishTestCase::drush_major_version function
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

File

tests/tablesUnitTest.php, line 10

View source
class tablesUnitTest extends UnitUnishTestCase {
  function setUp() {
    // Bootstrap to ensure the auto-loaded is running so that Console_Table is found.
    drush_preflight();
    $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);
  }
}