TableHelperTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * CakePHP : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  11. * @link http://cakephp.org CakePHP Project
  12. * @since 3.1.0
  13. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Shell\Helper;
  16. use Cake\Console\ConsoleIo;
  17. use Cake\Shell\Helper\TableHelper;
  18. use Cake\TestSuite\Stub\ConsoleOutput;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * TableHelper test.
  22. */
  23. class TableHelperTest extends TestCase
  24. {
  25. /**
  26. * setUp method
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. parent::setUp();
  33. $this->stub = new ConsoleOutput();
  34. $this->io = new ConsoleIo($this->stub);
  35. $this->helper = new TableHelper($this->io);
  36. }
  37. /**
  38. * Test output
  39. *
  40. * @return voi
  41. */
  42. public function testOutput()
  43. {
  44. $data = [
  45. ['Header 1', 'Header', 'Long Header'],
  46. ['short', 'Longish thing', 'short'],
  47. ['Longer thing', 'short', 'Longest Value'],
  48. ];
  49. $this->helper->output($data);
  50. $expected = [
  51. '+--------------+---------------+---------------+',
  52. '| Header 1 | Header | Long Header |',
  53. '+--------------+---------------+---------------+',
  54. '| short | Longish thing | short |',
  55. '| Longer thing | short | Longest Value |',
  56. '+--------------+---------------+---------------+',
  57. ];
  58. $this->assertEquals($expected, $this->stub->messages());
  59. }
  60. /**
  61. * Test output array shifting
  62. *
  63. * @return voi
  64. */
  65. public function testOutputShifting()
  66. {
  67. $data = [
  68. ['Header 1', 'Header', 'Long Header'],
  69. ['short', 'Longish thing', 'short'],
  70. ];
  71. $this->helper->output([$data]);
  72. $expected = [
  73. '+----------+---------------+-------------+',
  74. '| Header 1 | Header | Long Header |',
  75. '+----------+---------------+-------------+',
  76. '| short | Longish thing | short |',
  77. '+----------+---------------+-------------+',
  78. ];
  79. $this->assertEquals($expected, $this->stub->messages());
  80. }
  81. /**
  82. * Test output with multibyte characters
  83. *
  84. * @return voi
  85. */
  86. public function testOutputUtf8()
  87. {
  88. $data = [
  89. ['Header 1', 'Head', 'Long Header'],
  90. ['short', 'ÄÄÄÜÜÜ', 'short'],
  91. ['Longer thing', 'longerish', 'Longest Value'],
  92. ];
  93. $this->helper->output($data);
  94. $expected = [
  95. '+--------------+-----------+---------------+',
  96. '| Header 1 | Head | Long Header |',
  97. '+--------------+-----------+---------------+',
  98. '| short | ÄÄÄÜÜÜ | short |',
  99. '| Longer thing | longerish | Longest Value |',
  100. '+--------------+-----------+---------------+',
  101. ];
  102. $this->assertEquals($expected, $this->stub->messages());
  103. }
  104. }