TimelineHelperTest.php 1.9 KB

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