output = new ezcConsoleOutput( array( 'format' => array( 'red' => array( 'color' => 'red', 'style' => 'bold' ), 'blue' => array( 'color' => 'blue', 'style' => 'bold' ), 'green' => array( 'color' => 'green', 'style' => 'bold' ), 'magenta' => array( 'color' => 'magenta', 'style' => 'bold' ), ), ) ); } /** * tearDown * * @access public */ public function tearDown() { } public function testTable1a() { $this->commonTableTest( __FUNCTION__, $this->tableData1, array( 'cols' => count( $this->tableData1[0] ), 'width' => 80 ), array( 'lineFormatHead' => 'green' ), array( 0 ) ); } public function testTable1b() { $this->commonTableTest( __FUNCTION__, $this->tableData1, array( 'cols' => count( $this->tableData1[0] ), 'width' => 40 ), array( 'lineFormatHead' => 'red', ), array( 0 ) ); } public function testTable2a() { $this->commonTableTest( __FUNCTION__, $this->tableData2, array( 'cols' => count( $this->tableData2[0] ), 'width' => 60 ), array( 'lineFormatHead' => 'magenta', 'colAlign' => ezcConsoleTable::ALIGN_RIGHT, 'widthType' => ezcConsoleTable::WIDTH_FIXED ) ); } public function testTable2b() { $this->commonTableTest( __FUNCTION__, $this->tableData2, array( 'cols' => count( $this->tableData2[0] ), 'width' => 60 ), array( 'lineFormatHead' => 'magenta', 'colAlign' => ezcConsoleTable::ALIGN_RIGHT ) ); } public function testTable3a() { $this->commonTableTest( __FUNCTION__, $this->tableData3, array( 'cols' => count( $this->tableData3[0] ), 'width' => 120 ), array( 'lineFormatHead' => 'blue', 'colAlign' => ezcConsoleTable::ALIGN_CENTER, 'lineVertical' => '#', 'lineHorizontal' => '#', 'corner' => '#' ), array( 0, 3 ) ); } public function testTable3b() { $this->commonTableTest( __FUNCTION__, $this->tableData3, array( 'cols' => count( $this->tableData3[0] ), 'width' => 80 ), array( 'lineFormatHead' => 'magenta', 'lineVertical' => 'v', 'lineHorizontal' => 'h', 'corner' => 'c' ), array( 1, 2 ) ); } public function testTable4a() { $this->commonTableTest( __FUNCTION__, $this->tableData4, array( 'cols' => count( $this->tableData4[0] ), 'width' => 120 ), array( 'lineFormatHead' => 'blue', 'colAlign' => ezcConsoleTable::ALIGN_CENTER, 'colWrap' => ezcConsoleTable::WRAP_CUT ), array( 0 ) ); } public function testTable4b() { $this->commonTableTest( __FUNCTION__, $this->tableData4, array( 'cols' => count( $this->tableData4[0] ), 'width' => 120 ), array( 'lineFormatHead' => 'blue', 'colAlign' => ezcConsoleTable::ALIGN_LEFT, 'colWrap' => ezcConsoleTable::WRAP_AUTO ), array( 0 ) ); } public function testTable4c() { $this->commonTableTest( __FUNCTION__, $this->tableData4, array( 'cols' => count( $this->tableData4[0] ), 'width' => 120 ), array( 'lineFormatHead' => 'blue', 'colAlign' => ezcConsoleTable::ALIGN_CENTER, 'colWrap' => ezcConsoleTable::WRAP_NONE ), array( 0 ) ); } private function commonTableTest( $refFile, $tableData, $settings, $options, $headrows = array() ) { $table = ezcConsoleTable::create( $tableData, $this->output, $settings, $options ); $table->setCellFormat( 'red', 0, 0 ); foreach ( $headrows as $row ) { $table->makeHeadRow( $row ); } $this->assertEquals( file_get_contents( dirname( __FILE__ ) . '/dat/' . $refFile . '.dat' ), implode( "\n", $table->getTable() ), 'Table not correctly generated for ' . $refFile . '.' ); // To prepare test files use this: // file_put_contents( dirname( __FILE__ ) . '/dat/' . $refFile . '.dat', implode( "\n", $table->getTable() ) ); } } ?>