diff --git a/tests/API/APIControllerBaseTest.php b/tests/API/APIControllerBaseTest.php
index bdccff6c..01e79680 100644
--- a/tests/API/APIControllerBaseTest.php
+++ b/tests/API/APIControllerBaseTest.php
@@ -91,7 +91,7 @@ abstract class APIControllerBaseTest extends ControllerBaseTest
);
$this->assertEquals(
- Response::HTTP_FORBIDDEN, // TODO that should actually be Response::HTTP_UNAUTHORIZED
+ Response::HTTP_FORBIDDEN,
$response->getStatusCode(),
sprintf('The secure URL %s has the wrong status code %s.', $url, $response->getStatusCode())
);
diff --git a/tests/API/ActivityControllerTest.php b/tests/API/ActivityControllerTest.php
index 87d6c927..34a5f6e2 100644
--- a/tests/API/ActivityControllerTest.php
+++ b/tests/API/ActivityControllerTest.php
@@ -77,22 +77,23 @@ class ActivityControllerTest extends APIControllerBaseTest
$hasProject = $expected[$i][0];
$this->assertStructure($activity, false);
if ($hasProject) {
- $this->assertEquals($expected[$i][0], $activity['project']);
+ $this->assertEquals($expected[$i][1], $activity['project']);
}
}
}
public function getCollectionTestData()
{
- yield ['/api/activities', [], [[false], [false], [true, 2], [true, 1], [true, 2]]];
+ yield ['/api/activities', [], [[false], [true, 2], [true, 2], [null], [true, 1]]];
+ //yield ['/api/activities', [], [[false], [false], [true, 2], [true, 1], [true, 2]]];
yield ['/api/activities', ['globals' => 'true'], [[false], [false]]];
yield ['/api/activities', ['globals' => 'true', 'visible' => 3], [[false], [false], [false]]];
yield ['/api/activities', ['globals' => 'true', 'visible' => '2'], [[false]]];
yield ['/api/activities', ['globals' => 'true', 'visible' => 1], [[false], [false]]];
yield ['/api/activities', ['project' => '1'], [[false], [false], [true, 1]]];
- yield ['/api/activities', ['project' => '2', 'visible' => 1], [[false], [false], [true, 2], [true, 2]]];
- yield ['/api/activities', ['project' => '2', 'visible' => '3'], [[false], [false], [false], [true, 2], [true, 2], [true, 2]]];
- yield ['/api/activities', ['project' => '2', 'visible' => 2], [[false], [true, 2]]];
+ yield ['/api/activities', ['project' => '2', 'visible' => 1], [[false], [true, 2], [true, 2], [false]]];
+ yield ['/api/activities', ['project' => '2', 'visible' => '3'], [[false], [true, 2], [true, 2], [true, 2], [false], [false]]];
+ yield ['/api/activities', ['project' => '2', 'visible' => 2], [[true, 2], [false]]];
}
public function testGetCollectionWithQuery()
@@ -100,7 +101,7 @@ class ActivityControllerTest extends APIControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->loadActivityTestData($client);
- $query = ['order' => 'ASC', 'orderBy' => 'project', 'globalsFirst' => 'false'];
+ $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);
@@ -220,7 +221,9 @@ class ActivityControllerTest extends APIControllerBaseTest
protected function assertStructure(array $result, $full = true)
{
- $expectedKeys = ['id', 'name', 'visible', 'project', 'hourlyRate', 'fixedRate', 'color', 'metaFields'];
+ $expectedKeys = [
+ 'id', 'name', 'visible', 'project', 'hourlyRate', 'fixedRate', 'color', 'metaFields', 'parentTitle'
+ ];
if ($full) {
$expectedKeys = array_merge($expectedKeys, [
diff --git a/tests/API/CustomerControllerTest.php b/tests/API/CustomerControllerTest.php
index 56bc319c..bb3d557f 100644
--- a/tests/API/CustomerControllerTest.php
+++ b/tests/API/CustomerControllerTest.php
@@ -163,7 +163,9 @@ class CustomerControllerTest extends APIControllerBaseTest
protected function assertStructure(array $result, $full = true)
{
- $expectedKeys = ['id', 'name', 'visible', 'hourlyRate', 'fixedRate', 'color', 'metaFields'];
+ $expectedKeys = [
+ 'id', 'name', 'visible', 'hourlyRate', 'fixedRate', 'color', 'metaFields'
+ ];
if ($full) {
$expectedKeys = array_merge($expectedKeys, [
diff --git a/tests/API/ProjectControllerTest.php b/tests/API/ProjectControllerTest.php
index 430a6418..95ea49b5 100644
--- a/tests/API/ProjectControllerTest.php
+++ b/tests/API/ProjectControllerTest.php
@@ -100,9 +100,11 @@ class ProjectControllerTest extends APIControllerBaseTest
yield ['/api/projects', ['customer' => '1', 'visible' => VisibilityQuery::SHOW_VISIBLE], [[true, 1], [false, 1]]];
yield ['/api/projects', ['customer' => '1', 'visible' => VisibilityQuery::SHOW_BOTH], [[true, 1], [false, 1], [false, 1]]];
yield ['/api/projects', ['customer' => '1', 'visible' => VisibilityQuery::SHOW_HIDDEN], [[false, 1]]];
+ // customer is invisible, so nothing should be returned
yield ['/api/projects', ['customer' => '2', 'visible' => VisibilityQuery::SHOW_VISIBLE], []];
yield ['/api/projects', ['customer' => '2', 'visible' => VisibilityQuery::SHOW_BOTH], [[false, 2], [false, 2]]];
- yield ['/api/projects', ['customer' => '2', 'visible' => VisibilityQuery::SHOW_HIDDEN], [[false, 2]]];
+ // customer is invisible, so nothing should be returned
+ yield ['/api/projects', ['customer' => '2', 'visible' => VisibilityQuery::SHOW_HIDDEN], []];
}
public function testGetEntity()
@@ -212,7 +214,7 @@ class ProjectControllerTest extends APIControllerBaseTest
protected function assertStructure(array $result, $full = true)
{
$expectedKeys = [
- 'id', 'name', 'visible', 'customer', 'hourlyRate', 'fixedRate', 'color', 'metaFields'
+ 'id', 'name', 'visible', 'customer', 'hourlyRate', 'fixedRate', 'color', 'metaFields', 'parentTitle'
];
if ($full) {
diff --git a/tests/Controller/ExportControllerTest.php b/tests/Controller/ExportControllerTest.php
index e59abb81..39006165 100644
--- a/tests/Controller/ExportControllerTest.php
+++ b/tests/Controller/ExportControllerTest.php
@@ -67,7 +67,7 @@ class ExportControllerTest extends ControllerBaseTest
public function testExportActionWithMissingRenderer()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
- $this->request($client, '/export/data');
+ $this->request($client, '/export/data', 'POST');
$response = $client->getResponse();
$this->assertFalse($response->isSuccessful());
@@ -79,11 +79,14 @@ class ExportControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
- $this->request($client, '/export/');
+ $this->request($client, '/export/', 'GET');
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('#export-form')->form();
- $form->getFormNode()->setAttribute('action', $this->createUrl('/export/data'));
+ $node = $form->getFormNode();
+ $node->setAttribute('action', $this->createUrl('/export/data'));
+ $node->setAttribute('method', 'POST');
+
$client->submit($form, [
'type' => 'default'
]);
@@ -112,7 +115,10 @@ class ExportControllerTest extends ControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$form = $client->getCrawler()->filter('#export-form')->form();
- $form->getFormNode()->setAttribute('action', $this->createUrl('/export/data'));
+ $node = $form->getFormNode();
+ $node->setAttribute('action', $this->createUrl('/export/data'));
+ $node->setAttribute('method', 'POST');
+
// don't add daterange to make sure the current month is the default range
$client->submit($form, [
'type' => 'html'
diff --git a/tests/Controller/InvoiceControllerTest.php b/tests/Controller/InvoiceControllerTest.php
index d91fcb58..a39caa54 100644
--- a/tests/Controller/InvoiceControllerTest.php
+++ b/tests/Controller/InvoiceControllerTest.php
@@ -158,7 +158,9 @@ class InvoiceControllerTest extends ControllerBaseTest
$this->assertDataTableRowCount($client, 'datatable_invoice', 20);
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
- $form->getFormNode()->setAttribute('action', $this->createUrl('/invoice/print'));
+ $node = $form->getFormNode();
+ $node->setAttribute('action', $this->createUrl('/invoice/print'));
+ $node->setAttribute('method', 'POST');
$client->submit($form, [
'template' => 1,
'user' => '',
@@ -177,7 +179,7 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
- $this->request($client, '/invoice/print');
+ $this->request($client, '/invoice/print', 'POST');
$this->assertIsRedirect($client, '/invoice/template/create');
}
@@ -189,7 +191,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
- $this->request($client, '/invoice/print');
+ $this->request($client, '/invoice/print', 'POST');
$this->assertIsRedirect($client, '/invoice/');
}
diff --git a/tests/Mocks/Security/UserDateTimeFactoryFactory.php b/tests/Mocks/Security/UserDateTimeFactoryFactory.php
index 5c8821dd..f191bd13 100644
--- a/tests/Mocks/Security/UserDateTimeFactoryFactory.php
+++ b/tests/Mocks/Security/UserDateTimeFactoryFactory.php
@@ -35,8 +35,8 @@ class UserDateTimeFactoryFactory extends AbstractMockFactory
$pref->setValue($timezone);
$user->addPreference($pref);
}
- $repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getById'])->disableOriginalConstructor()->getMock();
- $repository->expects(TestCase::exactly(1))->method('getById')->willReturn($user);
+ $repository = $this->getMockBuilder(UserRepository::class)->setMethods(['getUserById'])->disableOriginalConstructor()->getMock();
+ $repository->expects(TestCase::exactly(1))->method('getUserById')->willReturn($user);
$token = $this->getMockBuilder(UsernamePasswordToken::class)->setMethods(['getUser'])->disableOriginalConstructor()->getMock();
$token->expects(TestCase::exactly(1))->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
diff --git a/tests/Repository/Query/ActivityQueryTest.php b/tests/Repository/Query/ActivityQueryTest.php
index 11d4216c..d91a6ee0 100644
--- a/tests/Repository/Query/ActivityQueryTest.php
+++ b/tests/Repository/Query/ActivityQueryTest.php
@@ -23,7 +23,7 @@ class ActivityQueryTest extends BaseQueryTest
{
$sut = new ActivityQuery();
- $this->assertBaseQuery($sut);
+ $this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(VisibilityQuery::class, $sut);
$this->assertNull($sut->getCustomer());
diff --git a/tests/Repository/Query/BaseQueryTest.php b/tests/Repository/Query/BaseQueryTest.php
index 9d001f7c..79ed4150 100644
--- a/tests/Repository/Query/BaseQueryTest.php
+++ b/tests/Repository/Query/BaseQueryTest.php
@@ -9,7 +9,6 @@
namespace App\Tests\Repository\Query;
-use App\Entity\User;
use App\Repository\Query\BaseQuery;
use PHPUnit\Framework\TestCase;
@@ -23,13 +22,12 @@ class BaseQueryTest extends TestCase
$this->assertBaseQuery(new BaseQuery());
}
- protected function assertBaseQuery(BaseQuery $sut)
+ protected function assertBaseQuery(BaseQuery $sut, $orderBy = 'id')
{
$this->assertResultType($sut);
- $this->assertHiddenEntity($sut);
$this->assertPage($sut);
$this->assertPageSize($sut);
- $this->assertOrderBy($sut);
+ $this->assertOrderBy($sut, $orderBy);
$this->assertOrder($sut);
}
@@ -51,17 +49,6 @@ class BaseQueryTest extends TestCase
}
}
- protected function assertHiddenEntity(BaseQuery $sut)
- {
- $this->assertNull($sut->getHiddenEntity());
-
- $actual = new User();
- $actual->setUsername('foo-bar');
-
- $sut->setHiddenEntity($actual);
- $this->assertEquals($actual, $sut->getHiddenEntity());
- }
-
protected function assertPage(BaseQuery $sut)
{
$this->assertEquals(BaseQuery::DEFAULT_PAGE, $sut->getPage());
diff --git a/tests/Repository/Query/CustomerQueryTest.php b/tests/Repository/Query/CustomerQueryTest.php
index 4fdd1a2a..065ae9a1 100644
--- a/tests/Repository/Query/CustomerQueryTest.php
+++ b/tests/Repository/Query/CustomerQueryTest.php
@@ -21,7 +21,7 @@ class CustomerQueryTest extends BaseQueryTest
{
$sut = new CustomerQuery();
- $this->assertBaseQuery($sut);
+ $this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(VisibilityQuery::class, $sut);
}
}
diff --git a/tests/Repository/Query/ExportQueryTest.php b/tests/Repository/Query/ExportQueryTest.php
index c8471ef5..20122a1f 100644
--- a/tests/Repository/Query/ExportQueryTest.php
+++ b/tests/Repository/Query/ExportQueryTest.php
@@ -25,7 +25,6 @@ class ExportQueryTest extends BaseQueryTest
$sut = new ExportQuery();
$this->assertResultType($sut);
- $this->assertHiddenEntity($sut);
$this->assertPage($sut);
$this->assertPageSize($sut);
$this->assertOrderBy($sut, 'begin');
diff --git a/tests/Repository/Query/ProjectQueryTest.php b/tests/Repository/Query/ProjectQueryTest.php
index a22eed29..74e89138 100644
--- a/tests/Repository/Query/ProjectQueryTest.php
+++ b/tests/Repository/Query/ProjectQueryTest.php
@@ -22,7 +22,7 @@ class ProjectQueryTest extends BaseQueryTest
{
$sut = new ProjectQuery();
- $this->assertBaseQuery($sut);
+ $this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(VisibilityQuery::class, $sut);
$this->assertNull($sut->getCustomer());
diff --git a/tests/Repository/Query/TimesheetQueryTest.php b/tests/Repository/Query/TimesheetQueryTest.php
index 030ac528..803afa23 100644
--- a/tests/Repository/Query/TimesheetQueryTest.php
+++ b/tests/Repository/Query/TimesheetQueryTest.php
@@ -25,7 +25,6 @@ class TimesheetQueryTest extends BaseQueryTest
$sut = new TimesheetQuery();
$this->assertResultType($sut);
- $this->assertHiddenEntity($sut);
$this->assertPage($sut);
$this->assertPageSize($sut);
$this->assertOrderBy($sut, 'begin');
diff --git a/tests/Repository/Query/VisibilityQueryTest.php b/tests/Repository/Query/VisibilityQueryTest.php
index c092429a..8169dbf5 100644
--- a/tests/Repository/Query/VisibilityQueryTest.php
+++ b/tests/Repository/Query/VisibilityQueryTest.php
@@ -21,12 +21,8 @@ class VisibilityQueryTest extends TestCase
{
$sut = new VisibilityQuery();
- $this->assertFalse($sut->isExclusiveVisibility());
$this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility());
- $sut->setExclusiveVisibility(true);
- $this->assertTrue($sut->isExclusiveVisibility());
-
$sut->setVisibility('foo-bar');
$this->assertEquals(VisibilityQuery::SHOW_VISIBLE, $sut->getVisibility());