Skip to content

Commit

Permalink
Add test case for #97
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 24, 2024
1 parent 8b543dd commit d98f882
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/TestCase/View/TwigViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
namespace Cake\TwigView\Test\TestCase\View;

use Cake\Core\Configure;
use Cake\I18n\Date;
use Cake\I18n\DateTime;
use Cake\TestSuite\TestCase;
use TestApp\View\AppView;
use Twig\Error\RuntimeError;
Expand Down Expand Up @@ -136,6 +138,23 @@ public function testCellsShareTwig()
$this->assertSame($this->view->getTwig(), $cell->createView(AppView::class)->getTwig());
}


/**
* Test that Cake date/time objects are formatted correctly
*/
public function testTwigDateFormat()
{
$this->view->set('date', new Date('2024-06-24'));
$this->view->set('datetime', new DateTime('2024-06-24 12:13:14'));

$output = $this->view->render('date_format', false);
$expected = <<<TEXT
Date: 2024/06/24
Datetime: 2024/06/24 12:13:14
TEXT;
$this->assertSame($expected, $output);
}

/**
* Tests rendering with markdown.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/test_app/templates/date_format.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date: {{ date|date('Y/m/d') }}
Datetime: {{ datetime|date('Y/m/d H:i:s') }}

0 comments on commit d98f882

Please sign in to comment.