added internal rates (#1591)

This commit is contained in:
Kevin Papst
2020-04-08 14:50:15 +02:00
committed by GitHub
parent 82c713031e
commit 68d703d1e3
128 changed files with 4044 additions and 1571 deletions

View File

@@ -149,6 +149,22 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
);
}
protected function assertNotFoundForDelete(HttpKernelBrowser $client, string $url)
{
return $this->assertExceptionForMethod($client, $url, 'DELETE', [], [
'code' => 404,
'message' => 'Not found'
]);
}
protected function assertEntityNotFoundForDelete(string $role, string $url)
{
return $this->assertExceptionForDeleteAction($role, $url, [], [
'code' => 404,
'message' => 'Not found'
]);
}
protected function assertEntityNotFoundForPatch(string $role, string $url, array $data)
{
return $this->assertExceptionForPatchAction($role, $url, $data, [
@@ -157,11 +173,32 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
]);
}
protected function assertEntityNotFoundForPost(string $role, string $url, array $data, ?string $message = null)
{
return $this->assertExceptionForPostAction($role, $url, $data, [
'code' => 404,
'message' => $message ?? 'Not found'
]);
}
protected function assertExceptionForDeleteAction(string $role, string $url, array $data, array $expectedErrors)
{
$this->assertExceptionForRole($role, $url, 'DELETE', $data, $expectedErrors);
}
protected function assertExceptionForPatchAction(string $role, string $url, array $data, array $expectedErrors)
{
$client = $this->getClientForAuthenticatedUser($role);
$this->assertExceptionForRole($role, $url, 'PATCH', $data, $expectedErrors);
}
$this->request($client, $url, 'PATCH', [], json_encode($data));
protected function assertExceptionForPostAction(string $role, string $url, array $data, array $expectedErrors)
{
$this->assertExceptionForRole($role, $url, 'POST', $data, $expectedErrors);
}
protected function assertExceptionForMethod(HttpKernelBrowser $client, string $url, string $method, array $data, array $expectedErrors)
{
$this->request($client, $url, $method, [], json_encode($data));
$response = $client->getResponse();
self::assertFalse($response->isSuccessful());
@@ -173,25 +210,10 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
);
}
protected function assertEntityNotFoundForDelete(string $role, string $url, array $data)
protected function assertExceptionForRole(string $role, string $url, string $method, array $data, array $expectedErrors)
{
$client = $this->getClientForAuthenticatedUser($role);
$this->request($client, $url, 'DELETE', [], json_encode($data));
$response = $client->getResponse();
self::assertFalse($response->isSuccessful());
$expected = [
'code' => 404,
'message' => 'Not found'
];
self::assertEquals(404, $client->getResponse()->getStatusCode());
self::assertEquals(
$expected,
json_decode($client->getResponse()->getContent(), true)
);
$this->assertExceptionForMethod($client, $url, $method, $data, $expectedErrors);
}
protected function assertApiException(Response $response, string $message)

View File

@@ -9,10 +9,14 @@
namespace App\Tests\API;
use App\DataFixtures\UserFixtures;
use App\Entity\Activity;
use App\Entity\ActivityRate;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\User;
use App\Repository\ActivityRateRepository;
use App\Repository\ActivityRepository;
use App\Tests\Mocks\ActivityTestMetaFieldSubscriberMock;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
@@ -22,6 +26,51 @@ use Symfony\Component\HttpKernel\HttpKernelBrowser;
*/
class ActivityControllerTest extends APIControllerBaseTest
{
use RateControllerTestTrait;
protected function getRateUrl(string $id = '1', ?string $rateId = null): string
{
if (null !== $rateId) {
return sprintf('/api/activities/%s/rates/%s', $id, $rateId);
}
return sprintf('/api/activities/%s/rates', $id);
}
protected function importTestRates(string $id): array
{
/** @var ActivityRateRepository $rateRepository */
$rateRepository = $this->getEntityManager()->getRepository(ActivityRate::class);
/** @var ActivityRepository $repository */
$repository = $this->getEntityManager()->getRepository(Activity::class);
/** @var Activity|null $activity */
$activity = $repository->find($id);
if (null === $activity) {
$activity = new Activity();
$activity->setName('foooo');
$repository->saveActivity($activity);
}
$rate1 = new ActivityRate();
$rate1->setActivity($activity);
$rate1->setRate(17.45);
$rate1->setIsFixed(false);
$rateRepository->saveRate($rate1);
$rate2 = new ActivityRate();
$rate2->setActivity($activity);
$rate2->setRate(99);
$rate2->setInternalRate(9);
$rate2->setIsFixed(true);
$rate2->setUser($this->getUserByName(UserFixtures::USERNAME_USER));
$rateRepository->saveRate($rate2);
return [$rate1, $rate2];
}
public function testIsSecure()
{
$this->assertUrlIsSecured('/api/activities');
@@ -29,9 +78,11 @@ class ActivityControllerTest extends APIControllerBaseTest
protected function loadActivityTestData(HttpKernelBrowser $client)
{
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Project $project */
$project = $em->getRepository(Project::class)->find(1);
/** @var Customer $customer */
$customer = $em->getRepository(Customer::class)->find(1);
$project2 = new Project();
@@ -104,7 +155,6 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->loadActivityTestData($client);
$query = ['order' => 'ASC', 'orderBy' => 'project'];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/activities', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -277,7 +327,7 @@ class ActivityControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Activity $activity */
$activity = $em->getRepository(Activity::class)->find(1);
$this->assertEquals('another,testing,bar', $activity->getMetaField('metatestmock')->getValue());

View File

@@ -9,8 +9,12 @@
namespace App\Tests\API;
use App\DataFixtures\UserFixtures;
use App\Entity\Customer;
use App\Entity\CustomerRate;
use App\Entity\User;
use App\Repository\CustomerRateRepository;
use App\Repository\CustomerRepository;
use App\Tests\Mocks\CustomerTestMetaFieldSubscriberMock;
use Symfony\Component\HttpFoundation\Response;
@@ -19,6 +23,53 @@ use Symfony\Component\HttpFoundation\Response;
*/
class CustomerControllerTest extends APIControllerBaseTest
{
use RateControllerTestTrait;
protected function getRateUrl(string $id = '1', ?string $rateId = null): string
{
if (null !== $rateId) {
return sprintf('/api/customers/%s/rates/%s', $id, $rateId);
}
return sprintf('/api/customers/%s/rates', $id);
}
protected function importTestRates(string $id): array
{
/** @var CustomerRateRepository $rateRepository */
$rateRepository = $this->getEntityManager()->getRepository(CustomerRate::class);
/** @var CustomerRepository $repository */
$repository = $this->getEntityManager()->getRepository(Customer::class);
/** @var Customer|null $customer */
$customer = $repository->find($id);
if (null === $customer) {
$customer = new Customer();
$customer->setCountry('DE');
$customer->setTimezone('Europre/Paris');
$customer->setName('foooo');
$repository->saveCustomer($customer);
}
$rate1 = new CustomerRate();
$rate1->setCustomer($customer);
$rate1->setRate(17.45);
$rate1->setIsFixed(false);
$rateRepository->saveRate($rate1);
$rate2 = new CustomerRate();
$rate2->setCustomer($customer);
$rate2->setRate(99);
$rate2->setInternalRate(9);
$rate2->setIsFixed(true);
$rate2->setUser($this->getUserByName(UserFixtures::USERNAME_USER));
$rateRepository->saveRate($rate2);
return [$rate1, $rate2];
}
public function testIsSecure()
{
$this->assertUrlIsSecured('/api/customers');
@@ -221,7 +272,7 @@ class CustomerControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Customer $customer */
$customer = $em->getRepository(Customer::class)->find(1);
$this->assertEquals('another,testing,bar', $customer->getMetaField('metatestmock')->getValue());

View File

@@ -9,9 +9,13 @@
namespace App\Tests\API;
use App\DataFixtures\UserFixtures;
use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\ProjectRate;
use App\Entity\User;
use App\Repository\ProjectRateRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\VisibilityInterface;
use App\Tests\Mocks\ProjectTestMetaFieldSubscriberMock;
use Symfony\Component\HttpFoundation\Response;
@@ -22,6 +26,52 @@ use Symfony\Component\HttpKernel\HttpKernelBrowser;
*/
class ProjectControllerTest extends APIControllerBaseTest
{
use RateControllerTestTrait;
protected function getRateUrl(string $id = '1', ?string $rateId = null): string
{
if (null !== $rateId) {
return sprintf('/api/projects/%s/rates/%s', $id, $rateId);
}
return sprintf('/api/projects/%s/rates', $id);
}
protected function importTestRates(string $id): array
{
/** @var ProjectRateRepository $rateRepository */
$rateRepository = $this->getEntityManager()->getRepository(ProjectRate::class);
/** @var ProjectRepository $repository */
$repository = $this->getEntityManager()->getRepository(Project::class);
/** @var Project|null $project */
$project = $repository->find($id);
if (null === $project) {
$project = new Project();
$project->setName('foooo');
$project->setCustomer($this->getEntityManager()->getRepository(Customer::class)->find(1));
$repository->saveProject($project);
}
$rate1 = new ProjectRate();
$rate1->setProject($project);
$rate1->setRate(17.45);
$rate1->setIsFixed(false);
$rateRepository->saveRate($rate1);
$rate2 = new ProjectRate();
$rate2->setProject($project);
$rate2->setRate(99);
$rate2->setInternalRate(9);
$rate2->setIsFixed(true);
$rate2->setUser($this->getUserByName(UserFixtures::USERNAME_USER));
$rateRepository->saveRate($rate2);
return [$rate1, $rate2];
}
public function testIsSecure()
{
$this->assertUrlIsSecured('/api/projects');
@@ -41,7 +91,7 @@ class ProjectControllerTest extends APIControllerBaseTest
protected function loadProjectTestData(HttpKernelBrowser $client)
{
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$customer = $em->getRepository(Customer::class)->find(1);
@@ -278,7 +328,7 @@ class ProjectControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Project $project */
$project = $em->getRepository(Project::class)->find(1);
$this->assertEquals('another,testing,bar', $project->getMetaField('metatestmock')->getValue());

View File

@@ -0,0 +1,205 @@
<?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\Entity\User;
use Symfony\Component\HttpFoundation\Response;
/**
* @group integration
*/
trait RateControllerTestTrait
{
abstract protected function getRateUrl(string $id = '1', ?string $rateId = null): string;
abstract protected function importTestRates(string $id): array;
public function testAddRateMissingEntityAction()
{
$data = [
'user' => 1,
'rate' => 12.34,
'internal_rate' => 6.66,
'is_fixed' => false
];
$this->assertEntityNotFoundForPost(User::ROLE_ADMIN, $this->getRateUrl(99), $data, 'Not found');
}
public function testAddRateMissingUserAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'user' => 33,
'rate' => 12.34,
'internal_rate' => 6.66,
'is_fixed' => false
];
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$response = $client->getResponse();
$this->assertEquals(400, $response->getStatusCode());
$this->assertApiCallValidationError($response, ['user']);
}
public function testAddRateActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$data = [
'user' => null,
'rate' => 12.34,
'internal_rate' => 6.66,
'is_fixed' => false
];
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
$this->assertEquals(Response::HTTP_FORBIDDEN, $response->getStatusCode());
$json = json_decode($response->getContent(), true);
$this->assertEquals('Access denied.', $json['message']);
}
public function testAddRateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'user' => null,
'rate' => 12.34,
'internal_rate' => 6.66,
'is_fixed' => false
];
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertRateStructure($result, null);
$this->assertNotEmpty($result['id']);
$this->assertEquals(12.34, $result['rate']);
$this->assertEquals(6.66, $result['internalRate']);
$this->assertFalse($result['isFixed']);
}
public function testAddFixedRateAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'user' => 1,
'rate' => 12.34,
'internal_rate' => 6.66,
'is_fixed' => true
];
$this->request($client, $this->getRateUrl(), 'POST', [], json_encode($data));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertRateStructure($result, 1);
$this->assertNotEmpty($result['id']);
$this->assertEquals(12.34, $result['rate']);
$this->assertEquals(6.66, $result['internalRate']);
$this->assertTrue($result['isFixed']);
}
public function testGetRatesEmptyResult()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, $this->getRateUrl(1));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertEmpty($result);
}
public function testGetRates()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$expectedRates = $this->importTestRates(1);
$this->request($client, $this->getRateUrl(1));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertNotEmpty($result);
$this->assertEquals(count($expectedRates), count($result));
foreach ($result as $rate) {
$this->assertRateStructure($rate, ($rate['user'] === null ? null : $rate['user']['id']));
}
}
public function testGetRatesEntityNotFound()
{
$this->assertEntityNotFound(User::ROLE_ADMIN, $this->getRateUrl(99));
}
public function testGetRatesIsSecured()
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, $this->getRateUrl(1));
}
public function testDeleteRate()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$expectedRates = $this->importTestRates(1);
$this->request($client, $this->getRateUrl(1, 1), 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertEmpty($client->getResponse()->getContent());
// fetch rates to validate that one was removed
$this->request($client, $this->getRateUrl(1));
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$this->assertIsArray($result);
$this->assertEquals(count($expectedRates) - 1, count($result));
}
public function testDeleteRateEntityNotFound()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, $this->getRateUrl(99, 1));
}
public function testDeleteRateRateNotFound()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, $this->getRateUrl(1, 99));
}
public function testDeleteRateWithInvalidAssignment()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTestRates(1);
$this->importTestRates(2);
$this->assertNotFoundForDelete($client, $this->getRateUrl(2, 1));
}
protected function assertRateStructure(array $result, $user = null)
{
$expectedKeys = [
'id', 'rate', 'internalRate', 'isFixed', 'user'
];
$actual = array_keys($result);
sort($actual);
sort($expectedKeys);
$this->assertEquals($expectedKeys, $actual, 'Rate structure does not match');
if (null !== $user) {
self::assertIsArray($result['user'], 'Rate user is not an array');
self::assertEquals($user, $result['user']['id'], 'Rate user does not match');
} else {
self::assertNull($result['user']);
}
}
}

View File

@@ -17,9 +17,13 @@ use App\Entity\User;
*/
class StatusControllerTest extends APIControllerBaseTest
{
public function testIsSecure()
public function testIsSecurePing()
{
$this->assertUrlIsSecured('/api/ping');
}
public function testIsSecureVersion()
{
$this->assertUrlIsSecured('/api/version');
}

View File

@@ -12,16 +12,15 @@ namespace App\Tests\API;
use App\Entity\User;
use App\Tests\DataFixtures\TagFixtures;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
/**
* @group integration
*/
class TagControllerTest extends APIControllerBaseTest
{
protected function setUp(): void
protected function importTagFixtures(HttpKernelBrowser $client): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$tagList = ['Test', 'Administration', 'Support', '#2018-001', '#2018-002', '#2018-003', 'Development',
'Marketing', 'First Level Support', 'Bug Fixing'];
@@ -38,6 +37,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testGetCollection()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importTagFixtures($client);
$this->assertAccessIsGranted($client, '/api/tags');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -50,6 +50,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testEmptyCollection()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importTagFixtures($client);
$query = ['name' => 'nothing'];
$this->assertAccessIsGranted($client, '/api/tags', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -62,6 +63,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testPostAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTagFixtures($client);
$data = [
'name' => 'foo',
];
@@ -77,6 +79,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testPostActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importTagFixtures($client);
$data = [
'name' => 'foo',
];
@@ -91,6 +94,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testPartOfEntries()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importTagFixtures($client);
$query = ['name' => 'in'];
$this->assertAccessIsGranted($client, '/api/tags', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -107,6 +111,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTagFixtures($client);
$this->request($client, '/api/tags/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -121,7 +126,7 @@ class TagControllerTest extends APIControllerBaseTest
public function testDeleteActionWithUnknownTimesheet()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/tags/255', []);
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/tags/255');
}
protected function assertStructure(array $result, $full = true)

View File

@@ -31,8 +31,22 @@ class TeamControllerTest extends APIControllerBaseTest
public function testIsSecure()
{
$this->assertUrlIsSecured('/api/teams');
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/api/teams');
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/api/teams');
}
public function getRoleTestData()
{
return [
[User::ROLE_USER],
[User::ROLE_TEAMLEAD],
];
}
/**
* @dataProvider getRoleTestData
*/
public function testIsSecureForRole(string $role)
{
$this->assertUrlIsSecuredForRole($role, '/api/teams');
}
public function testGetCollection()
@@ -66,7 +80,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testDeleteActionWithUnknownTeam()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/teams/255', []);
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/teams/255');
}
public function testPostAction()
@@ -142,8 +156,6 @@ class TeamControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
self::assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
$this->assertEmpty($client->getResponse()->getContent());
$this->assertEntityNotFound(User::ROLE_ADMIN, '/api/teams/' . $id);
}
public function testPostMemberAction()
@@ -334,7 +346,7 @@ class TeamControllerTest extends APIControllerBaseTest
$customer->setVisible(false);
$customer->setCountry('DE');
$customer->setTimezone('Europe/Berlin');
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$em->persist($customer);
$em->flush();
@@ -472,7 +484,7 @@ class TeamControllerTest extends APIControllerBaseTest
$project->setName('foooo');
$project->setVisible(false);
$project->setCustomer($customer);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$em->persist($customer);
$em->persist($project);
$em->flush();

View File

@@ -19,7 +19,6 @@ use App\Entity\User;
use App\Tests\DataFixtures\TimesheetFixtures;
use App\Tests\Mocks\Security\UserDateTimeFactoryFactory;
use App\Tests\Mocks\TimesheetTestMetaFieldSubscriberMock;
use App\Timesheet\UserDateTimeFactory;
use Symfony\Component\HttpFoundation\Response;
/**
@@ -31,21 +30,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
public const DATE_FORMAT_HTML5 = 'Y-m-d\TH:i:s';
public const TEST_TIMEZONE = 'Europe/London';
/**
* @var UserDateTimeFactory
*/
protected $dateTime;
protected function setUp(): void
{
$this->importFixtureForUser(User::ROLE_USER);
$this->dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE);
}
protected function importFixtureForUser(string $role)
{
$client = $this->getClientForAuthenticatedUser($role);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -56,7 +43,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate((new \DateTime('first day of this month'))->setTime(0, 0, 1))
->setAllowEmptyDescriptions(false)
;
$this->importFixture($client, $fixture);
$this->importFixture($this, $fixture);
}
public function testIsSecure()
@@ -67,6 +54,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollection()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -79,6 +67,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollectionFull()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', ['full' => 'true']);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -92,7 +81,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollectionForOtherUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -117,7 +107,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollectionForAllUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -172,6 +163,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -181,7 +173,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertDefaultStructure($result[0], false);
}
public function testGetCollectionWithDeprecatedQuery()
public function testGetCollectionWithSingleParamsQuery()
{
$begin = new \DateTime('first day of this month');
$begin->setTime(0, 0, 0);
@@ -203,6 +195,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -215,7 +208,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testExportedFilter()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -240,7 +234,6 @@ class TimesheetControllerTest extends APIControllerBaseTest
'exported' => 1,
];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -257,7 +250,6 @@ class TimesheetControllerTest extends APIControllerBaseTest
'exported' => 0,
];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -272,7 +264,6 @@ class TimesheetControllerTest extends APIControllerBaseTest
'begin' => $begin->format(self::DATE_FORMAT_HTML5),
'end' => $end->format(self::DATE_FORMAT_HTML5),
];
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets', 'GET', $query);
$result = json_decode($client->getResponse()->getContent(), true);
@@ -285,6 +276,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetEntity()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -294,15 +286,17 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetEntityAccessDenied()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_ADMIN);
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertApiAccessDenied($client, '/api/timesheets/15', 'You are not allowed to view this timesheet');
}
public function testGetEntityAccessAllowedForAdmin()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -317,12 +311,13 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testPostAction()
{
$dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'activity' => 1,
'project' => 1,
'begin' => ($this->dateTime->createDateTime('- 16 hours'))->format('Y-m-d H:m:0'),
'end' => ($this->dateTime->createDateTime())->format('Y-m-d H:m:0'),
'begin' => ($dateTime->createDateTime('- 16 hours'))->format('Y-m-d H:m:0'),
'end' => ($dateTime->createDateTime())->format('Y-m-d H:m:0'),
'description' => 'foo',
'fixedRate' => 2016,
'hourlyRate' => 127
@@ -344,7 +339,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$customer = (new Customer())->setName('foo-bar-1')->setVisible(false)->setCountry('DE')->setTimezone('Europe/Berlin');
$em->persist($customer);
$project = (new Project())->setName('foo-bar-2')->setVisible(true)->setCustomer($customer);
@@ -372,7 +367,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$customer = (new Customer())->setName('foo-bar-1')->setVisible(true)->setCountry('DE')->setTimezone('Europe/Berlin');
$em->persist($customer);
$project = (new Project())->setName('foo-bar-2')->setVisible(true)->setCustomer($customer);
@@ -396,12 +391,14 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testPatchAction()
{
$dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE);
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importFixtureForUser(User::ROLE_USER);
$data = [
'activity' => 1,
'project' => 1,
'begin' => ($this->dateTime->createDateTime('- 7 hours'))->format('Y-m-d\TH:m:0'),
'end' => ($this->dateTime->createDateTime())->format('Y-m-d\TH:m:0'),
'begin' => ($dateTime->createDateTime('- 7 hours'))->format('Y-m-d\TH:m:0'),
'end' => ($dateTime->createDateTime())->format('Y-m-d\TH:m:0'),
'description' => 'foo',
'exported' => true,
];
@@ -419,7 +416,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testPatchActionWithInvalidUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -456,6 +454,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testInvalidPatchAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$data = [
'activity' => 10,
'project' => 1,
@@ -475,6 +475,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/api/timesheets/1');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -487,32 +488,31 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
$this->assertEmpty($client->getResponse()->getContent());
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/' . $id);
}
public function testDeleteActionWithUnknownTimesheet()
{
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/timesheets/255', []);
$this->assertEntityNotFoundForDelete(User::ROLE_ADMIN, '/api/timesheets/255');
}
public function testDeleteActionForDifferentUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$id = 1;
$this->request($client, '/api/timesheets/' . $id, 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertEquals(Response::HTTP_NO_CONTENT, $client->getResponse()->getStatusCode());
$this->assertEmpty($client->getResponse()->getContent());
$this->assertEntityNotFound(User::ROLE_USER, '/api/timesheets/' . $id);
}
public function testDeleteActionWithoutAuthorization()
{
$this->importFixtureForUser(User::ROLE_ADMIN);
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_ADMIN);
$this->request($client, '/api/timesheets/15', 'DELETE');
@@ -526,8 +526,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDeleteActionForExportedRecordIsNotAllowed()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
@@ -541,8 +542,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDeleteActionForExportedRecordIsAllowedForAdmin()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
@@ -556,7 +558,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetRecentCollectionWithSubresources()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$start = new \DateTime('-10 days');
@@ -589,7 +591,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testActiveAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$start = new \DateTime('-10 days');
@@ -617,7 +619,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testStopAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$start = new \DateTime('-10 days');
@@ -635,7 +638,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->request($client, '/api/timesheets/11/stop', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertInstanceOf(\DateTime::class, $timesheet->getEnd());
@@ -644,6 +647,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testStopActionFailsOnStoppedEntry()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->request($client, '/api/timesheets/1/stop', 'PATCH');
$this->assertApiException($client->getResponse(), 'Timesheet entry already stopped');
@@ -657,7 +661,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testStopNotAllowedForUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$start = new \DateTime('-10 days');
@@ -679,7 +684,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testGetCollectionWithTags()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$this->importFixtureForUser(User::ROLE_USER);
$em = $this->getEntityManager();
$fixture = new TimesheetFixtures();
$fixture
@@ -724,6 +730,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$data = [
'description' => 'foo',
@@ -739,7 +746,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertEmpty($result['description']);
$this->assertEmpty($result['tags']);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find($result['id']);
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
@@ -753,8 +760,9 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartActionWithCopyData()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setDescription('foo');
@@ -779,7 +787,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertEquals([['name' => 'sdfsdf', 'value' => 'nnnnn'], ['name' => '1234567890', 'value' => '1234567890']], $result['metaFields']);
$this->assertEquals(['another', 'testing', 'bar'], $result['tags']);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find($result['id']);
$this->assertInstanceOf(\DateTime::class, $timesheet->getBegin());
@@ -793,7 +801,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testRestartNotAllowedForUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
$start = new \DateTime('-10 days');
@@ -808,7 +817,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
;
$this->importFixture($em, $fixture);
$this->request($client, '/api/timesheets/12/restart', 'PATCH');
$this->request($client, '/api/timesheets/2/restart', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to re-start this timesheet');
}
@@ -819,12 +828,13 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testDuplicateAction()
{
$dateTime = (new UserDateTimeFactoryFactory($this))->create(self::TEST_TIMEZONE);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'activity' => 1,
'project' => 1,
'begin' => ($this->dateTime->createDateTime('- 16 hours'))->format('Y-m-d H:m:0'),
'end' => ($this->dateTime->createDateTime())->format('Y-m-d H:m:0'),
'begin' => ($dateTime->createDateTime('- 16 hours'))->format('Y-m-d H:m:0'),
'end' => ($dateTime->createDateTime())->format('Y-m-d H:m:0'),
'description' => 'foo',
'fixedRate' => 2016,
'hourlyRate' => 127
@@ -858,32 +868,34 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testExportAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importFixtureForUser(User::ROLE_USER);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals(false, $timesheet->isExported());
$this->assertFalse($timesheet->isExported());
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertDefaultStructure(json_decode($client->getResponse()->getContent(), true), true);
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em->clear();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals(true, $timesheet->isExported());
$this->assertTrue($timesheet->isExported());
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em->clear();
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals(false, $timesheet->isExported());
$this->assertFalse($timesheet->isExported());
}
public function testExportNotAllowedForUser()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
$this->request($client, '/api/timesheets/1/export', 'PATCH');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to lock this timesheet');
@@ -901,7 +913,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaActionThrowsExceptionOnMissingName()
{
return $this->assertExceptionForPatchAction(User::ROLE_ADMIN, '/api/timesheets/1/meta', ['value' => 'X'], [
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['value' => 'X'], [
'code' => 400,
'message' => 'Parameter "name" of value "NULL" violated a constraint "This value should not be null."'
]);
@@ -909,7 +924,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaActionThrowsExceptionOnMissingValue()
{
return $this->assertExceptionForPatchAction(User::ROLE_ADMIN, '/api/timesheets/1/meta', ['name' => 'X'], [
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['name' => 'X'], [
'code' => 400,
'message' => 'Parameter "value" of value "NULL" violated a constraint "This value should not be null."'
]);
@@ -917,7 +935,10 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaActionThrowsExceptionOnMissingMetafield()
{
return $this->assertExceptionForPatchAction(User::ROLE_ADMIN, '/api/timesheets/1/meta', ['name' => 'X', 'value' => 'Y'], [
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->importFixtureForUser(User::ROLE_USER);
return $this->assertExceptionForMethod($client, '/api/timesheets/1/meta', 'PATCH', ['name' => 'X', 'value' => 'Y'], [
'code' => 500,
'message' => 'Unknown meta-field requested'
]);
@@ -926,7 +947,8 @@ class TimesheetControllerTest extends APIControllerBaseTest
public function testMetaAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
static::$kernel->getContainer()->get('event_dispatcher')->addSubscriber(new TimesheetTestMetaFieldSubscriberMock());
$this->importFixtureForUser(User::ROLE_USER);
static::$container->get('event_dispatcher')->addSubscriber(new TimesheetTestMetaFieldSubscriberMock());
$data = [
'name' => 'metatestmock',
@@ -936,7 +958,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$em = static::$kernel->getContainer()->get('doctrine.orm.entity_manager');
$em = $this->getEntityManager();
/** @var Timesheet $timesheet */
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals('another,testing,bar', $timesheet->getMetaField('metatestmock')->getValue());
@@ -945,7 +967,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
protected function assertDefaultStructure(array $result, $full = true)
{
$expectedKeys = [
'id', 'begin', 'end', 'duration', 'description', 'rate', 'activity', 'project', 'tags', 'user', 'metaFields'
'id', 'begin', 'end', 'duration', 'description', 'rate', 'activity', 'project', 'tags', 'user', 'metaFields', 'internalRate'
];
if ($full) {

View File

@@ -20,9 +20,23 @@ class UserControllerTest extends APIControllerBaseTest
public function testIsSecure()
{
$this->assertUrlIsSecured('/api/users');
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/api/users');
$this->assertUrlIsSecuredForRole(User::ROLE_TEAMLEAD, '/api/users');
$this->assertUrlIsSecuredForRole(User::ROLE_ADMIN, '/api/users');
}
public function getRoleTestData()
{
return [
[User::ROLE_USER],
[User::ROLE_TEAMLEAD],
[User::ROLE_ADMIN],
];
}
/**
* @dataProvider getRoleTestData
*/
public function testIsSecureForRole(string $role)
{
$this->assertUrlIsSecuredForRole($role, '/api/users');
}
public function testGetCollection()
@@ -187,7 +201,6 @@ class UserControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
$data = [
'avatar' => 'test321',
'title' => 'qwertzui',