weekly quick-entry form (#2793)
This commit is contained in:
@@ -17,6 +17,7 @@ use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Intl\Util\IntlTestHelper;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\TwigTest;
|
||||
|
||||
/**
|
||||
* @covers \App\Twig\LocaleFormatExtensions
|
||||
@@ -82,6 +83,22 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetTests()
|
||||
{
|
||||
$tests = ['weekend', 'today'];
|
||||
$i = 0;
|
||||
|
||||
$sut = $this->getSut('de', []);
|
||||
$twigTests = $sut->getTests();
|
||||
$this->assertCount(\count($tests), $twigTests);
|
||||
|
||||
/** @var TwigTest $test */
|
||||
foreach ($twigTests as $test) {
|
||||
$this->assertInstanceOf(TwigTest::class, $test);
|
||||
$this->assertEquals($tests[$i++], $test->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $locale
|
||||
* @param \DateTime|string $date
|
||||
@@ -494,6 +511,39 @@ class LocaleFormatExtensionsTest extends TestCase
|
||||
$this->assertEquals('0.00', $sut->durationDecimal(null));
|
||||
}
|
||||
|
||||
private function getTest(string $name): TwigTest
|
||||
{
|
||||
$sut = $this->getSut('en', $this->localeEn);
|
||||
foreach ($sut->getTests() as $test) {
|
||||
if ($test->getName() === $name) {
|
||||
return $test;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \Exception('Unknown twig test: ' . $name);
|
||||
}
|
||||
|
||||
public function testIsToday()
|
||||
{
|
||||
$test = $this->getTest('today');
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime()));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('-1 day')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('+1 day')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), null));
|
||||
}
|
||||
|
||||
public function testIsWeekend()
|
||||
{
|
||||
$test = $this->getTest('weekend');
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first saturday this month')));
|
||||
self::assertTrue(\call_user_func($test->getCallable(), new \DateTime('first sunday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first monday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \DateTime('first friday this month')));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), new \stdClass()));
|
||||
self::assertFalse(\call_user_func($test->getCallable(), null));
|
||||
}
|
||||
|
||||
protected function getTimesheet($seconds)
|
||||
{
|
||||
$begin = new \DateTime();
|
||||
|
||||
Reference in New Issue
Block a user