From d98f882181a23f8626f60d2b081cc03076e06a8a Mon Sep 17 00:00:00 2001 From: Mark Story Date: Mon, 24 Jun 2024 00:18:23 -0400 Subject: [PATCH] Add test case for #97 --- tests/TestCase/View/TwigViewTest.php | 19 +++++++++++++++++++ tests/test_app/templates/date_format.twig | 2 ++ 2 files changed, 21 insertions(+) create mode 100644 tests/test_app/templates/date_format.twig diff --git a/tests/TestCase/View/TwigViewTest.php b/tests/TestCase/View/TwigViewTest.php index bc60cf1..6275fce 100644 --- a/tests/TestCase/View/TwigViewTest.php +++ b/tests/TestCase/View/TwigViewTest.php @@ -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; @@ -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 = <<assertSame($expected, $output); + } + /** * Tests rendering with markdown. * diff --git a/tests/test_app/templates/date_format.twig b/tests/test_app/templates/date_format.twig new file mode 100644 index 0000000..2781b5f --- /dev/null +++ b/tests/test_app/templates/date_format.twig @@ -0,0 +1,2 @@ +Date: {{ date|date('Y/m/d') }} +Datetime: {{ datetime|date('Y/m/d H:i:s') }} \ No newline at end of file