Skip to content

Commit e65c755

Browse files
committed
test: Add tests for date_format
1 parent 52495a9 commit e65c755

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

tests/OptionsTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,23 @@ public function testDateFormatDifferentYear(): void
181181
$formatted = formatDate("2000-04-12", "M j[, Y]");
182182
$this->assertEquals("Apr 12, 2000", $formatted);
183183
}
184+
185+
/**
186+
* Test date formatter no brackets different year
187+
*/
188+
public function testDateFormatNoBracketsDiffYear(): void
189+
{
190+
$formatted = formatDate("2000-04-12", "Y/m/d");
191+
$this->assertEquals("2000/04/12", $formatted);
192+
}
193+
194+
/**
195+
* Test date formatter no brackets same year
196+
*/
197+
public function testDateFormatNoBracketsSameYear(): void
198+
{
199+
$year = date("Y");
200+
$formatted = formatDate("$year-04-12", "Y/m/d");
201+
$this->assertEquals("$year/04/12", $formatted);
202+
}
184203
}

tests/RenderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,20 @@ public function testErrorCardRender(): void
5656
$this->assertEquals($expected, $render);
5757
}
5858

59+
/**
60+
* Test date_format parameter in render
61+
*/
62+
public function testDateFormatRender(): void
63+
{
64+
$year = date("Y");
65+
$this->testStats["currentStreak"]["end"] = "$year-04-12";
66+
$this->testParams["date_format"] = "[Y-]m-d";
67+
// Check that the card is rendered as expected
68+
$render = generateCard($this->testStats, $this->testParams);
69+
$expected = file_get_contents("tests/expected/test_date_card.svg");
70+
$this->assertEquals($expected, $render);
71+
}
72+
5973
/**
6074
* Test JSON render
6175
*/

tests/expected/test_date_card.svg

Lines changed: 121 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)