added begin, end and export filter for API timesheets (#639)
This commit is contained in:
52
tests/API/ConfigurationControllerTest.php
Normal file
52
tests/API/ConfigurationControllerTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\API;
|
||||
|
||||
use App\Configuration\LanguageFormattings;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\Query\VisibilityQuery;
|
||||
use Symfony\Bundle\FrameworkBundle\Client;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\API\ConfigurationController
|
||||
* @group integration
|
||||
*/
|
||||
class ConfigurationControllerTest extends APIControllerBaseTest
|
||||
{
|
||||
public function testI18nIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/api/config/i18n');
|
||||
}
|
||||
|
||||
public function testGetI18n()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/config/i18n', 'GET');
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(7, count($result));
|
||||
$this->assertStructure($result, false);
|
||||
}
|
||||
|
||||
protected function assertStructure(array $result, $full = true)
|
||||
{
|
||||
$expectedKeys = ['date', 'date_time', 'duration', 'form_date', 'form_date_time', 'is24hours', 'time'];
|
||||
$actual = array_keys($result);
|
||||
sort($actual);
|
||||
sort($expectedKeys);
|
||||
|
||||
$this->assertEquals($expectedKeys, $actual, 'Activity structure does not match');
|
||||
}
|
||||
}
|
||||
52
tests/API/Model/I18nTest.php
Normal file
52
tests/API/Model/I18nTest.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\API;
|
||||
|
||||
use App\API\Model\I18n;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\API\Model\I18n
|
||||
*/
|
||||
class I18nTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new I18n();
|
||||
$this->assertTrue($sut->isIs24hours());
|
||||
$this->assertEquals('', $sut->getDuration());
|
||||
$this->assertEquals('', $sut->getDate());
|
||||
$this->assertEquals('', $sut->getDateTime());
|
||||
$this->assertEquals('', $sut->getFormDate());
|
||||
$this->assertEquals('', $sut->getFormDateTime());
|
||||
$this->assertEquals('', $sut->getTime());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new I18n();
|
||||
|
||||
$this->assertInstanceOf(I18n::class, $sut->setIs24hours(false));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDuration('foo'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDate('bar'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setDateTime('hello'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setFormDate('world'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setFormDateTime('testing'));
|
||||
$this->assertInstanceOf(I18n::class, $sut->setTime('fun'));
|
||||
|
||||
$this->assertFalse($sut->isIs24hours());
|
||||
$this->assertEquals('foo', $sut->getDuration());
|
||||
$this->assertEquals('bar', $sut->getDate());
|
||||
$this->assertEquals('hello', $sut->getDateTime());
|
||||
$this->assertEquals('world', $sut->getFormDate());
|
||||
$this->assertEquals('testing', $sut->getFormDateTime());
|
||||
$this->assertEquals('fun', $sut->getTime());
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,23 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
|
||||
public function testGetCollectionWithQuery()
|
||||
{
|
||||
$query = ['customer' => 1, 'project' => 1, 'activity' => 1, 'page' => 2, 'size' => 5, 'order' => 'DESC', 'orderBy' => 'rate'];
|
||||
$begin = new \DateTime('-10 days');
|
||||
$begin->setTime(0, 0, 0);
|
||||
$end = new \DateTime();
|
||||
$end->setTime(23, 59, 59);
|
||||
|
||||
$query = [
|
||||
'customer' => 1,
|
||||
'project' => 1,
|
||||
'activity' => 1,
|
||||
'page' => 2,
|
||||
'size' => 5,
|
||||
'order' => 'DESC',
|
||||
'orderBy' => 'rate',
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 0,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
@@ -130,6 +146,74 @@ class TimesheetControllerTest extends APIControllerBaseTest
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
}
|
||||
|
||||
public function testExportedFilter()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture
|
||||
->setExported(true)
|
||||
->setAmount(7)
|
||||
->setUser($this->getUserByRole($em, User::ROLE_USER))
|
||||
->setStartDate(new \DateTime('-10 days'))
|
||||
->setAllowEmptyDescriptions(false)
|
||||
;
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$begin = new \DateTime('-10 days');
|
||||
$begin->setTime(0, 0, 0);
|
||||
$end = new \DateTime();
|
||||
$end->setTime(23, 59, 59);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 1,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(7, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
'exported' => 0,
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(10, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
|
||||
$query = [
|
||||
'page' => 1,
|
||||
'size' => 50,
|
||||
'begin' => $begin->format('Y-m-d H:i:s'),
|
||||
'end' => $end->format('Y-m-d H:i:s'),
|
||||
];
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
|
||||
$result = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(17, count($result));
|
||||
$this->assertDefaultStructure($result[0], false);
|
||||
}
|
||||
|
||||
public function testGetEntity()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
|
||||
Reference in New Issue
Block a user