Release 2.13 (#4659)

This commit is contained in:
Kevin Papst
2024-03-10 15:35:59 +01:00
committed by GitHub
parent a78e8ed8c4
commit dee90bb15e
79 changed files with 1019 additions and 932 deletions

View File

@@ -168,7 +168,10 @@ class ActivityControllerTest extends APIControllerBaseTest
}
$this->assertAccessIsGranted($client, $url, 'GET', $parameters);
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
@@ -208,7 +211,10 @@ class ActivityControllerTest extends APIControllerBaseTest
$query = ['order' => 'ASC', 'orderBy' => 'project'];
$this->assertAccessIsGranted($client, '/api/activities', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
@@ -219,11 +225,19 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->assertEquals($imports[1]->getId(), $result[2]['project']);
}
public function testGetEntityIsSecure(): void
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/api/activities/1');
}
public function testGetEntity(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/api/activities/1');
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ActivityEntity', $result);
@@ -247,7 +261,10 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->request($client, '/api/activities', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ActivityEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -262,7 +279,10 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->request($client, '/api/activities', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ActivityEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -308,7 +328,10 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->request($client, '/api/activities/1', 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ActivityEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -330,7 +353,10 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->request($client, '/api/activities/' . $imports[2]->getId(), 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ActivityEntity', $result);
$this->assertNotEmpty($result['id']);

View File

@@ -96,7 +96,10 @@ class CustomerControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/customers');
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
@@ -109,7 +112,10 @@ class CustomerControllerTest extends APIControllerBaseTest
$query = ['order' => 'ASC', 'orderBy' => 'name', 'visible' => 3, 'term' => 'test'];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/customers', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
@@ -117,11 +123,19 @@ class CustomerControllerTest extends APIControllerBaseTest
self::assertApiResponseTypeStructure('CustomerCollection', $result[0]);
}
public function testGetEntityIsSecure(): void
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/api/customers/1');
}
public function testGetEntity(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/api/customers/1');
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('CustomerEntity', $result);
@@ -129,7 +143,7 @@ class CustomerControllerTest extends APIControllerBaseTest
public function testGetEntityWithFullResponse(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $this->getEntityManager();
@@ -165,7 +179,10 @@ class CustomerControllerTest extends APIControllerBaseTest
$em->flush();
$this->assertAccessIsGranted($client, '/api/customers/1');
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('CustomerEntity', $result);
@@ -191,7 +208,10 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->request($client, '/api/customers', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('CustomerEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -209,7 +229,10 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->request($client, '/api/customers', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('CustomerEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -262,7 +285,10 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->request($client, '/api/customers/1', 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('CustomerEntity', $result);
$this->assertNotEmpty($result['id']);

View File

@@ -97,7 +97,10 @@ class ProjectControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/projects');
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
@@ -206,7 +209,10 @@ class ProjectControllerTest extends APIControllerBaseTest
}
$this->assertAccessIsGranted($client, $url, 'GET', $parameters);
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertEquals(\count($expected), \count($result), 'Found wrong amount of projects');
@@ -242,9 +248,27 @@ class ProjectControllerTest extends APIControllerBaseTest
yield ['/api/projects', 1, ['customers' => ['2', '2'], 'visible' => VisibilityInterface::SHOW_HIDDEN, 'start' => '2010-12-11', 'end' => '2030-12-11'], []];
}
public function testGetEntityIsSecure(): void
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/api/projects/1');
}
public function testGetEntity(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/api/projects/1');
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
}
public function testGetEntityComplex(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $this->getEntityManager();
$customer = new Customer('first one');
@@ -268,7 +292,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$em->flush();
$this->assertAccessIsGranted($client, '/api/projects/' . $project->getId());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
@@ -318,7 +345,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -344,7 +374,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -367,7 +400,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -390,7 +426,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -410,7 +449,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects', 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);
@@ -461,7 +503,10 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->request($client, '/api/projects/1', 'PATCH', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
self::assertApiResponseTypeStructure('ProjectEntity', $result);
$this->assertNotEmpty($result['id']);

View File

@@ -20,20 +20,14 @@ use App\Entity\User;
*/
trait RateControllerTestTrait
{
/**
* @param string|int $id
* @param string|int|null $rateId
* @return string
*/
abstract protected function getRateUrl($id = '1', $rateId = null): string;
abstract protected function getRateUrl(string|int $id = '1', string|int|null $rateId = null): string;
abstract protected function getRateUrlByRate(RateInterface $rate, bool $isCollection): string;
/**
* @param string|int $id
* @return RateInterface[]
*/
abstract protected function importTestRates($id): array;
abstract protected function importTestRates(string|int $id): array;
public function testAddRateMissingEntityAction(): void
{
@@ -89,7 +83,10 @@ trait RateControllerTestTrait
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertRateStructure($result, null);
$this->assertNotEmpty($result['id']);
@@ -110,7 +107,10 @@ trait RateControllerTestTrait
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertRateStructure($result, 1);
$this->assertNotEmpty($result['id']);
@@ -125,7 +125,10 @@ trait RateControllerTestTrait
$this->request($client, $this->getRateUrl(1));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertEmpty($result);
}
@@ -138,7 +141,10 @@ trait RateControllerTestTrait
$this->request($client, $this->getRateUrl(1));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(\count($expectedRates), \count($result));
@@ -171,7 +177,10 @@ trait RateControllerTestTrait
$this->request($client, $this->getRateUrlByRate($expectedRates[0], true));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$content = $client->getResponse()->getContent();
$this->assertIsString($content);
$result = json_decode($content, true);
$this->assertIsArray($result);
$this->assertEquals(\count($expectedRates) - 1, \count($result));
}

View File

@@ -118,7 +118,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
self::assertApiResponseTypeStructure('TimesheetCollection', $result[0]);
}
public function testGetCollectionForAllUser(): void
public function testGetCollectionForAllUserIsSecure(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importFixtureForUser(User::ROLE_USER);
@@ -136,6 +136,53 @@ class TimesheetControllerTest extends APIControllerBaseTest
self::assertIsString($content);
$result = json_decode($content, true);
self::assertIsArray($result);
self::assertEmpty($result);
self::assertEquals(0, \count($result));
}
public function testGetCollectionForAllUserIsSecureForUser(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$fixture = new TimesheetFixtures($this->getUserByRole(User::ROLE_ADMIN), 7);
$fixture->setFixedRate(true);
$fixture->setHourlyRate(true);
$fixture->setStartDate(new \DateTime('-10 days'));
$this->importFixture($fixture);
$query = ['user' => 'all'];
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$content = $client->getResponse()->getContent();
self::assertIsString($content);
$result = json_decode($content, true);
self::assertIsArray($result);
self::assertNotEmpty($result);
self::assertEquals(10, \count($result));
self::assertApiResponseTypeStructure('TimesheetCollection', $result[0]);
}
public function testGetCollectionForAllUser(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$fixture = new TimesheetFixtures($this->getUserByRole(User::ROLE_SUPER_ADMIN), 7);
$fixture->setFixedRate(true);
$fixture->setHourlyRate(true);
$fixture->setStartDate(new \DateTime('-10 days'));
$this->importFixture($fixture);
$query = ['user' => 'all'];
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$content = $client->getResponse()->getContent();
self::assertIsString($content);
$result = json_decode($content, true);
self::assertIsArray($result);
self::assertNotEmpty($result);
self::assertEquals(17, \count($result));