| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace Tools\Test\TestCase\View\Helper;
- use App\View\Helper\TimelineHelper;
- use Cake\View\View;
- use DateTime;
- use Tools\TestSuite\TestCase;
- /**
- * Timeline Helper Test Case
- */
- class TimelineHelperTest extends TestCase {
- /**
- * @var \Tools\View\Helper\TimelineHelper|\App\View\Helper\TimelineHelper
- */
- public $Timeline;
- /**
- * @return void
- */
- public function setUp() {
- parent::setUp();
- $this->Timeline = new TimelineHelper(new View(null));
- }
- /**
- * @return void
- */
- public function testAddItem() {
- $data = [
- 'start' => null,
- 'content' => '',
- ];
- $this->Timeline->addItem($data);
- $items = $this->Timeline->items();
- $this->assertSame(1, count($items));
- $data = [
- [
- 'start' => null,
- 'content' => '',
- ],
- [
- 'start' => null,
- 'content' => '',
- ]
- ];
- $this->Timeline->addItems($data);
- $items = $this->Timeline->items();
- $this->assertSame(3, count($items));
- }
- /**
- * @return void
- */
- public function testFinalize() {
- $this->testAddItem();
- $data = [
- 'start' => new DateTime(),
- 'content' => '',
- ];
- $this->Timeline->addItem($data);
- $data = [
- 'start' => new DateTime(date(FORMAT_DB_DATE)),
- 'content' => '',
- ];
- $this->Timeline->addItem($data);
- $this->Timeline->finalize();
- $result = $this->Timeline->getView()->fetch('script');
- $this->assertContains('\'start\': new Date(', $result);
- }
- /**
- * @return void
- */
- public function testFinalizeReturnScript() {
- $this->testAddItem();
- $data = [
- 'start' => new DateTime(),
- 'content' => '',
- ];
- $this->Timeline->addItem($data);
- $data = [
- 'start' => new DateTime(date(FORMAT_DB_DATE)),
- 'content' => '',
- ];
- $this->Timeline->addItem($data);
- $result = $this->Timeline->finalize(true);
- $this->assertContains('\'start\': new Date(', $result);
- }
- /**
- * @return void
- */
- public function tearDown() {
- parent::tearDown();
- unset($this->Timeline);
- }
- }
|