2015-12-01 13:29:08 +00:00
|
|
|
<?php
|
2015-12-01 14:26:22 +00:00
|
|
|
/**
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
|
|
|
* @since 2.8
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
|
|
|
*/
|
2015-12-01 13:29:08 +00:00
|
|
|
App::uses("TableShellHelper", "Console/Helper");
|
|
|
|
App::uses("ConsoleOutputStub", "TestSuite/Stub");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ProgressHelper test.
|
|
|
|
* @property ConsoleOutputStub $consoleOutput
|
|
|
|
* @property TableShellHelper $helper
|
|
|
|
*/
|
2015-12-01 14:26:22 +00:00
|
|
|
class TableShellHelperTest extends CakeTestCase {
|
2015-12-01 13:29:08 +00:00
|
|
|
|
2015-12-01 14:26:22 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2015-12-01 13:29:08 +00:00
|
|
|
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->consoleOutput = new ConsoleOutputStub();
|
|
|
|
$this->helper = new TableShellHelper($this->consoleOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testDefaultOutput() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Header', 'Long Header'),
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value'),
|
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output with multibyte characters
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputUtf8() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Head', 'Long Header'),
|
|
|
|
array('short', 'ÄÄÄÜÜÜ', 'short'),
|
|
|
|
array('Longer thing', 'longerish', 'Longest Value'),
|
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+-----------+---------------+',
|
|
|
|
'| <info>Header 1</info> | <info>Head</info> | <info>Long Header</info> |',
|
|
|
|
'+--------------+-----------+---------------+',
|
|
|
|
'| short | ÄÄÄÜÜÜ | short |',
|
|
|
|
'| Longer thing | longerish | Longest Value |',
|
|
|
|
'+--------------+-----------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output without headers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputWithoutHeaderStyle() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Header', 'Long Header'),
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value'),
|
|
|
|
);
|
|
|
|
$this->helper->config(array('headerStyle' => false));
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| Header 1 | Header | Long Header |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output with different header style
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputWithDifferentHeaderStyle() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Header', 'Long Header'),
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value'),
|
|
|
|
);
|
|
|
|
$this->helper->config(array('headerStyle' => 'error'));
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| <error>Header 1</error> | <error>Header</error> | <error>Long Header</error> |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output without table headers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputWithoutHeaders() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value'),
|
|
|
|
);
|
|
|
|
$this->helper->config(array('headers' => false));
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output with row separator
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputWithRowSeparator() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Header', 'Long Header'),
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value')
|
|
|
|
);
|
|
|
|
$this->helper->config(array('rowSeparator' => true));
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test output with row separator and no headers
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputWithRowSeparatorAndHeaders() {
|
2015-12-01 15:16:54 +00:00
|
|
|
$data = array(
|
|
|
|
array('Header 1', 'Header', 'Long Header'),
|
|
|
|
array('short', 'Longish thing', 'short'),
|
|
|
|
array('Longer thing', 'short', 'Longest Value'),
|
|
|
|
);
|
|
|
|
$this->helper->config(array('rowSeparator' => true));
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->helper->output($data);
|
2015-12-01 15:16:54 +00:00
|
|
|
$expected = array(
|
2015-12-01 14:26:22 +00:00
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| <info>Header 1</info> | <info>Header</info> | <info>Long Header</info> |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| short | Longish thing | short |',
|
|
|
|
'+--------------+---------------+---------------+',
|
|
|
|
'| Longer thing | short | Longest Value |',
|
|
|
|
'+--------------+---------------+---------------+',
|
2015-12-01 15:16:54 +00:00
|
|
|
);
|
2015-12-01 14:26:22 +00:00
|
|
|
$this->assertEquals($expected, $this->consoleOutput->messages());
|
|
|
|
}
|
2015-12-01 13:29:08 +00:00
|
|
|
}
|