weekly quick-entry form (#2793)

This commit is contained in:
Kevin Papst
2021-10-18 11:12:46 +02:00
committed by GitHub
parent 64893e0a95
commit 9ab098af86
105 changed files with 3356 additions and 778 deletions

View File

@@ -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();