TimelineHelperTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Tools\View\Helper\TimelineHelper;
  4. use Tools\TestSuite\TestCase;
  5. use Cake\View\View;
  6. use Cake\Core\Configure;
  7. /**
  8. * Timeline Helper Test Case
  9. */
  10. class TimelineHelperTest extends TestCase {
  11. public $Timeline;
  12. /**
  13. * TimelineHelperTest::setUp()
  14. *
  15. * @return void
  16. */
  17. public function setUp() {
  18. parent::setUp();
  19. $this->Timeline = new TimelineTestHelper(new View(null));
  20. }
  21. /**
  22. * @return void
  23. */
  24. public function testAddItem() {
  25. $data = array(
  26. 'start' => null,
  27. 'content' => '',
  28. );
  29. $this->Timeline->addItem($data);
  30. $items = $this->Timeline->items();
  31. $this->assertSame(1, count($items));
  32. $data = array(
  33. array(
  34. 'start' => null,
  35. 'content' => '',
  36. ),
  37. array(
  38. 'start' => null,
  39. 'content' => '',
  40. )
  41. );
  42. $this->Timeline->addItems($data);
  43. $items = $this->Timeline->items();
  44. $this->assertSame(3, count($items));
  45. }
  46. /**
  47. * @return void
  48. */
  49. public function testFinalize() {
  50. $this->testAddItem();
  51. $data = array(
  52. 'start' => new \DateTime(),
  53. 'content' => '',
  54. );
  55. $this->Timeline->addItem($data);
  56. $data = array(
  57. 'start' => new \DateTime(date(FORMAT_DB_DATE)),
  58. 'content' => '',
  59. );
  60. $this->Timeline->addItem($data);
  61. $result = $this->Timeline->finalize(true);
  62. $this->assertContains('\'start\': new Date(', $result);
  63. }
  64. public function tearDown() {
  65. parent::tearDown();
  66. unset($this->Timeline);
  67. }
  68. }
  69. class TimelineTestHelper extends TimelineHelper {
  70. /**
  71. * @return array
  72. */
  73. public function items() {
  74. return $this->_items;
  75. }
  76. }