TimelineHelperTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. App::uses('TimelineHelper', 'Tools.View/Helper');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. App::uses('HtmlHelper', 'View/Helper');
  5. App::uses('View', 'View');
  6. /**
  7. * Timeline Helper Test Case
  8. */
  9. class TimelineHelperTest extends MyCakeTestCase {
  10. public $Timeline;
  11. /**
  12. * TimelineHelperTest::setUp()
  13. *
  14. * @return void
  15. */
  16. public function setUp() {
  17. parent::setUp();
  18. $this->Timeline = new TimelineTestHelper(new View(null));
  19. $this->Timeline->Html = new HtmlHelper(new View(null));
  20. }
  21. /**
  22. * @return void
  23. */
  24. public function testAddItem() {
  25. $data = array(
  26. 'start' => '',
  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' => '',
  35. 'content' => '',
  36. ),
  37. array(
  38. 'start' => '',
  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' => date(FORMAT_DB_DATETIME),
  58. 'content' => '',
  59. );
  60. $this->Timeline->addItem($data);
  61. $result = $this->Timeline->finalize(true);
  62. $this->debug($result);
  63. $this->assertContains('\'start\': new Date(, -1, 0)', $result);
  64. }
  65. public function tearDown() {
  66. parent::tearDown();
  67. unset($this->Timeline);
  68. }
  69. }
  70. class TimelineTestHelper extends TimelineHelper {
  71. /**
  72. * @return array
  73. */
  74. public function items() {
  75. return $this->_items;
  76. }
  77. }