update to Symfony 4.4 (#1275)

This commit is contained in:
Kevin Papst
2020-02-04 15:29:26 +01:00
committed by GitHub
parent 375691365e
commit 75dcae6fbe
53 changed files with 1046 additions and 1019 deletions

View File

@@ -15,6 +15,9 @@ New permissions:
- `comments_create_customer` - NEW: permission that allows to add new comments for customers
- `comments_create_team_customer` - NEW: permission that allows to add new comments for team members of the current customer
- `comments_create_teamlead_customer` - NEW: permission that allows to add new comments for a teamlead of the current customer
- `comments_create_project` - NEW: permission that allows to add new comments for project
- `comments_create_team_project` - NEW: permission that allows to add new comments for team members of the current project
- `comments_create_teamlead_project` - NEW: permission that allows to add new comments for a teamlead of the current project
- `edit_teamlead_project` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)
- `edit_teamlead_customer` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)

View File

@@ -13,7 +13,7 @@ require __DIR__.'/../vendor/autoload.php';
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\Dotenv\Dotenv;
if (!isset($_SERVER['APP_ENV'])) {

View File

@@ -40,7 +40,6 @@
"sensio/framework-extra-bundle": "^5.2",
"symfony/asset": "^4.0",
"symfony/console": "^4.0",
"symfony/debug-pack": "^1.0",
"symfony/dotenv": "^4.0",
"symfony/expression-language": "^4.0",
"symfony/flex": "^1.0",
@@ -62,7 +61,7 @@
"white-october/pagerfanta-bundle": "^1.1"
},
"require-dev": {
"dama/doctrine-test-bundle": "^5.0",
"dama/doctrine-test-bundle": "^6.0",
"doctrine/doctrine-fixtures-bundle": "^3.2",
"friendsofphp/php-cs-fixer": "^2.10",
"fzaninotto/faker": "^1.8",
@@ -73,9 +72,11 @@
"phpunit/phpunit": "^8.0",
"symfony/browser-kit": "^4.0",
"symfony/css-selector": "^4.0",
"symfony/debug-bundle": "^4.0",
"symfony/maker-bundle": "^1.12",
"symfony/phpunit-bridge": "^4.0",
"symfony/profiler-pack": "^1.0"
"symfony/profiler-pack": "^1.0",
"symfony/var-dumper": "^4.0"
},
"repositories": [
{
@@ -136,7 +137,7 @@
],
"kimai:code-lint": [
"bin/console lint:yaml config --parse-tags",
"bin/console lint:twig templates",
"bin/console lint:twig templates --show-deprecations",
"bin/console lint:xliff translations",
"bin/console doctrine:schema:validate --skip-sync -vvv --no-interaction"
],
@@ -157,7 +158,7 @@
"symfony": {
"id": "01C3FWRDJJEX9K6Y3A4XDFXPBR",
"allow-contrib": true,
"require": "4.3.*"
"require": "4.4.*"
}
}
}

1614
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +0,0 @@
services:
EasyCorp\EasyLog\EasyLogHandler:
public: false
arguments: ['%kernel.logs_dir%/%kernel.environment%.log']
#// FIXME: How to add this configuration automatically without messing up with the monolog configuration?
#monolog:
# handlers:
# buffered:
# type: buffer
# handler: easylog
# channels: ['!event']
# level: debug
# easylog:
# type: service
# id: EasyCorp\EasyLog\EasyLogHandler

View File

@@ -4,3 +4,4 @@ twig:
strict_variables: '%kernel.debug%'
form_themes:
- 'form/kimai-theme.html.twig'
exception_controller: null

View File

@@ -1,5 +1,5 @@
controllers:
resource: '../src/Controller/'
resource: '../../src/Controller/'
type: annotation
prefix: /{_locale}
requirements:

View File

@@ -1,5 +1,5 @@
_errors:
resource: '@TwigBundle/Resources/config/routing/errors.xml'
resource: '@FrameworkBundle/Resources/config/routing/errors.xml'
prefix: /{_locale}/_error
requirements:
_locale: '%app_locales%'

View File

@@ -9,6 +9,7 @@
>
<php>
<ini name="error_reporting" value="-1" />
<ini name="max_execution_time" value="-1" />
<ini name="intl.default_locale" value="en_US" />
<env name="KERNEL_CLASS" value="App\Kernel" force="true"/>
<env name="APP_ENV" value="test" force="true"/>
@@ -56,10 +57,16 @@
</whitelist>
</filter>
<!--
begins a database transaction before every testcase and rolls it back after the test finished, so
tests can manipulate the database without affecting other tests
@see https://github.com/dmaicher/doctrine-test-bundle
-->
<extensions>
<extension class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitExtension" />
</extensions>
<listeners>
<!-- it begins a database transaction before every testcase and rolls it back after
the test finished, so tests can manipulate the database without affecting other tests -->
<listener class="DAMA\DoctrineTestBundle\PHPUnit\PHPUnitListener" />
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit>

View File

@@ -1,7 +1,7 @@
<?php
use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

View File

@@ -11,7 +11,6 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\User;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
@@ -19,12 +18,4 @@ abstract class BaseApiController extends AbstractController
{
public const DATE_FORMAT = DateTimeType::HTML5_FORMAT;
public const DATE_FORMAT_PHP = 'Y-m-d\TH:m:s';
/**
* @return User|null
*/
protected function getUser()
{
return parent::getUser();
}
}

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Customer;
use App\Entity\User;
use App\Event\CustomerMetaDefinitionEvent;
use App\Form\API\CustomerApiEditForm;
use App\Repository\CustomerRepository;
@@ -78,8 +79,11 @@ class CustomerController extends BaseApiController
*/
public function cgetAction(ParamFetcherInterface $paramFetcher): Response
{
/** @var User $user */
$user = $this->getUser();
$query = new CustomerQuery();
$query->setCurrentUser($this->getUser());
$query->setCurrentUser($user);
if (null !== ($order = $paramFetcher->get('order'))) {
$query->setOrder($order);

View File

@@ -12,6 +12,7 @@ declare(strict_types=1);
namespace App\API;
use App\Entity\Project;
use App\Entity\User;
use App\Event\ProjectMetaDefinitionEvent;
use App\Form\API\ProjectApiEditForm;
use App\Repository\ProjectRepository;
@@ -89,8 +90,11 @@ class ProjectController extends BaseApiController
*/
public function cgetAction(ParamFetcherInterface $paramFetcher): Response
{
/** @var User $user */
$user = $this->getUser();
$query = new ProjectQuery();
$query->setCurrentUser($this->getUser());
$query->setCurrentUser($user);
if (null !== ($order = $paramFetcher->get('order'))) {
$query->setOrder($order);

View File

@@ -170,8 +170,11 @@ final class TeamController extends BaseApiController
*/
public function postAction(Request $request): Response
{
/** @var User $user */
$user = $this->getUser();
$team = new Team();
$team->setTeamLead($this->getUser());
$team->setTeamLead($user);
$form = $this->createForm(TeamApiEditForm::class, $team);

View File

@@ -302,7 +302,10 @@ class TimesheetController extends BaseApiController
*/
public function postAction(Request $request): Response
{
$timesheet = $this->service->createNewTimesheet($this->getUser(), $request);
/** @var User $user */
$user = $this->getUser();
$timesheet = $this->service->createNewTimesheet($user, $request);
$mode = $this->getTrackingMode();
@@ -520,7 +523,10 @@ class TimesheetController extends BaseApiController
*/
public function activeAction(): Response
{
$data = $this->repository->getActiveEntries($this->getUser());
/** @var User $user */
$user = $this->getUser();
$data = $this->repository->getActiveEntries($user);
$view = new View($data, 200);
$view->getContext()->setGroups(['Default', 'Subresource', 'Timesheet']);
@@ -600,7 +606,10 @@ class TimesheetController extends BaseApiController
throw new AccessDeniedHttpException('You are not allowed to re-start this timesheet');
}
$copyTimesheet = $this->service->createNewTimesheet($this->getUser());
/** @var User $user */
$user = $this->getUser();
$copyTimesheet = $this->service->createNewTimesheet($user);
$copyTimesheet
->setBegin($this->dateTime->createDateTime())

View File

@@ -112,6 +112,7 @@ final class InvoiceController extends AbstractController
}
return $this->render('invoice/index.html.twig', [
'query' => $query,
'model' => $model,
'form' => $form->createView(),
'preview' => $showPreview,

View File

@@ -36,7 +36,9 @@ class Role
* @var string
*
* @ORM\Column(name="name", type="string", length=50, nullable=false)
* @Assert\Length(min=5, max=50)
* @Assert\NotNull()
* @Assert\NotBlank()
* @Assert\Length(allowEmptyString=false, min=5, max=50)
*/
private $name;

View File

@@ -36,7 +36,7 @@ class SearchTermType extends AbstractType
'label' => 'search',
'required' => false,
'constraints' => [
new Length(['min' => 3])
new Length(['min' => 3, 'allowEmptyString' => true])
],
]);
}

View File

@@ -9,6 +9,7 @@
namespace App\Invoice\Calculator;
use App\Invoice\CalculatorInterface;
use App\Invoice\InvoiceItem;
use App\Invoice\InvoiceModel;
@@ -87,11 +88,17 @@ abstract class AbstractCalculator
}
/**
* @deprecated since 1.8 will be removed with 2.0
* @return string
*/
public function getCurrency(): string
{
return $this->model->getCustomer()->getCurrency();
@trigger_error(
sprintf('%s::getCurrency() is deprecated and will be removed with 2.0', CalculatorInterface::class),
E_USER_DEPRECATED
);
return $this->model->getCurrency();
}
/**

View File

@@ -52,6 +52,7 @@ interface CalculatorInterface
/**
* Returns the currency for the invoices amounts.
*
* @deprecated since 1.8 will be removed with 2.0
* @return string
*/
public function getCurrency(): string;

View File

@@ -211,13 +211,23 @@ final class InvoiceModel
return $this->formatter;
}
public function getCurrency(): string
{
if (null === $this->getCustomer()) {
// this should be set from the configuration
return Customer::DEFAULT_CURRENCY;
}
return $this->getCustomer()->getCurrency();
}
public function toArray(): array
{
$model = $this;
$customer = $model->getCustomer();
$project = $model->getQuery()->getProject();
$activity = $model->getQuery()->getActivity();
$currency = $model->getCalculator()->getCurrency();
$currency = $this->getCurrency();
$tax = $model->getCalculator()->getTax();
$total = $model->getCalculator()->getTotal();
$subtotal = $model->getCalculator()->getSubtotal();

View File

@@ -143,7 +143,7 @@ class TimesheetRepository extends EntityRepository
$entityManager = $this->getEntityManager();
$entityManager->persist($entry);
$entityManager->flush($entry);
$entityManager->flush();
return true;
}

View File

@@ -99,15 +99,6 @@
"doctrine/reflection": {
"version": "v1.0.0"
},
"easycorp/easy-log-handler": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "70062abc2cd58794d2a90274502f81b55cd9951b"
}
},
"egulias/email-validator": {
"version": "2.1.3"
},
@@ -468,9 +459,6 @@
"ref": "71d29aaf710fd59cd3abff2b1ade907ed73103c6"
}
},
"symfony/debug-pack": {
"version": "v1.0.4"
},
"symfony/dependency-injection": {
"version": "v4.0.3"
},
@@ -483,6 +471,9 @@
"symfony/dotenv": {
"version": "v4.0.3"
},
"symfony/error-handler": {
"version": "v4.4.3"
},
"symfony/event-dispatcher": {
"version": "v4.0.3"
},

View File

@@ -7,7 +7,6 @@
{% set columns = {
'date': 'alwaysVisible',
'user': 'hidden-xs hidden-sm',
'customer': 'hidden-xs hidden-sm',
'project': 'hidden-xs hidden-sm',
'activity': 'hidden-xs hidden-sm',
'description': 'hidden-xs hidden-sm',
@@ -59,7 +58,7 @@
{% if entries is empty %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns) }}
{{ tables.datatable_header(tableName, columns, query, {}) }}
{% for entry in entries %}
{% set currency = entry.project.customer.currency %}
{% set duration = entry.duration|duration %}
@@ -74,8 +73,11 @@
<tr>
<td class="text-nowrap">{{ entry.begin|date_short }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'user') }}">{{ widgets.label_user(entry.user) }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'customer') }}">{{ widgets.label_customer(entry.project.customer) }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'project') }}">{{ widgets.label_project(entry.project) }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'project') }}">
{{ widgets.label_project(entry.project) }}
<br>
<small>{{ widgets.label_customer(entry.project.customer) }}</small>
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'activity') }}">{{ widgets.label_activity(entry.activity) }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }} timesheet-description">
{{ entry.description|escape|desc2html }}

View File

@@ -62,7 +62,7 @@
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{% set entries = model.calculator.entries %}
{{ tables.data_table_header(tableName, columns) }}
{{ tables.datatable_header(tableName, columns, query, {}) }}
{% for entry in entries %}
{% set amount = entry.amount %}
{% set duration = entry.duration|duration %}

View File

@@ -23,7 +23,7 @@
{% set tableName = 'plugins' %}
{{ tables.data_table_header(tableName, columns) }}
{{ tables.datatable_header(tableName, columns, null, {}) }}
{% for plugin in plugins %}
<tr>
<td>{{ plugin.name }}</td>

View File

@@ -21,14 +21,13 @@ class TagControllerTest extends APIControllerBaseTest
protected function setUp(): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$tagList = ['Test', 'Administration', 'Support', '#2018-001', '#2018-002', '#2018-003', 'Development',
'Marketing', 'First Level Support', 'Bug Fixing'];
$fixture = new TagFixtures();
$fixture->setTagArray($tagList);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()

View File

@@ -13,6 +13,7 @@ use App\Entity\Customer;
use App\Entity\Project;
use App\Entity\User;
use App\Tests\DataFixtures\TeamFixtures;
use Symfony\Bundle\FrameworkBundle\Client;
use Symfony\Component\HttpFoundation\Response;
/**
@@ -20,13 +21,11 @@ use Symfony\Component\HttpFoundation\Response;
*/
class TeamControllerTest extends APIControllerBaseTest
{
protected function setUp(): void
protected function importTeamFixtures(Client $client): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TeamFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()
@@ -39,6 +38,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testGetCollection()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -51,6 +51,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testGetEntity()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams/2');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -110,7 +111,6 @@ class TeamControllerTest extends APIControllerBaseTest
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$data = [
'name' => 'foo',
'teamlead' => 2,
@@ -129,6 +129,7 @@ class TeamControllerTest extends APIControllerBaseTest
public function testDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTeamFixtures($client);
$this->assertAccessIsGranted($client, '/api/teams/2');
$result = json_decode($client->getResponse()->getContent(), true);
@@ -157,7 +158,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['users']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -180,33 +180,28 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/members/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// user not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User not found', $json['message']);
// add user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/5', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
// cannot add existing member
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/5', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User is already member of the team', $json['message']);
// cannot add disabled user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/3', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -226,7 +221,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(4, $result['users']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -249,33 +243,28 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/members/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// user not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User not found', $json['message']);
// remove user
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
// cannot remove non-member
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/2', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('User is not a member of the team', $json['message']);
// cannot remove teamlead
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/members/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -294,7 +283,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(0, $result['customers']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -318,28 +306,24 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/customers/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// customer not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Customer not found', $json['message']);
// add customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['customers']);
// cannot add existing customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -355,7 +339,6 @@ class TeamControllerTest extends APIControllerBaseTest
$em->flush();
// cannot add invisible customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/' . $customer->getId(), 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -376,13 +359,11 @@ class TeamControllerTest extends APIControllerBaseTest
self::assertCount(0, $result['customers']);
// add customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['customers']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -405,21 +386,18 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/customers/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// customer not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Customer not found', $json['message']);
// cannot remove customer
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/customers/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -438,7 +416,6 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(0, $result['projects']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -462,28 +439,24 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/projects/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// project not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/999', 'POST');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Project not found', $json['message']);
// add project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['projects']);
// cannot add existing project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -505,7 +478,6 @@ class TeamControllerTest extends APIControllerBaseTest
$em->flush();
// cannot add invisible project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/' . $project->getId(), 'POST');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
@@ -526,13 +498,11 @@ class TeamControllerTest extends APIControllerBaseTest
self::assertCount(0, $result['projects']);
// add project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'POST');
$this->assertTrue($client->getResponse()->isSuccessful());
$result = json_decode($client->getResponse()->getContent(), true);
self::assertCount(1, $result['projects']);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -555,21 +525,18 @@ class TeamControllerTest extends APIControllerBaseTest
$result = json_decode($client->getResponse()->getContent(), true);
// team not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/999/projects/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Team not found', $json['message']);
// project not found
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/999', 'DELETE');
self::assertEquals(Response::HTTP_NOT_FOUND, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);
self::assertEquals('Project not found', $json['message']);
// cannot remove project
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/api/teams/' . $result['id'] . '/projects/1', 'DELETE');
self::assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
$json = json_decode($client->getResponse()->getContent(), true);

View File

@@ -56,7 +56,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
->setStartDate((new \DateTime('first day of this month'))->setTime(0, 0, 1))
->setAllowEmptyDescriptions(false)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testIsSecure()
@@ -501,7 +501,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->assertApiResponseAccessDenied($client->getResponse(), 'You are not allowed to delete this timesheet');
@@ -516,7 +516,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$timesheet->setExported(true);
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$this->request($client, '/api/timesheets/1', 'DELETE');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -734,7 +734,7 @@ class TimesheetControllerTest extends APIControllerBaseTest
$timesheet->setMetaField((new TimesheetMeta())->setName('xxxxxxx')->setValue('asdasdasd'));
$timesheet->setMetaField((new TimesheetMeta())->setName('1234567890')->setValue('1234567890')->setIsVisible(true));
$em->persist($timesheet);
$em->flush($timesheet);
$em->flush();
$timesheet = $em->getRepository(Timesheet::class)->find(1);
$this->assertEquals('foo', $timesheet->getDescription());

View File

@@ -26,6 +26,6 @@ class AboutControllerTest extends ControllerBaseTest
$result = $client->getCrawler()->filter('div.box-body pre');
$this->assertEquals(1, count($result));
$this->assertStringContainsString('MIT License', $result->text());
$this->assertStringContainsString('MIT License', $result->text(null, true));
}
}

View File

@@ -40,7 +40,7 @@ class ActivityControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ActivityFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Activity $activity) {
@@ -49,7 +49,7 @@ class ActivityControllerTest extends ControllerBaseTest
$activity->setMetaField((new ActivityMeta())->setName('location')->setValue('homeoffice'));
$activity->setMetaField((new ActivityMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/');
@@ -77,7 +77,7 @@ class ActivityControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setActivities($em->getRepository(Activity::class)->findAll());
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/activity/1/budget');
@@ -125,11 +125,9 @@ class ActivityControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/activity/create');
$form = $client->getCrawler()->filter('form[name=activity_edit_form]')->form();
@@ -224,10 +222,11 @@ class ActivityControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -264,13 +263,14 @@ class ActivityControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new ActivityFixtures();
$fixture->setAmount(1)->setIsGlobal(true)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -279,7 +279,7 @@ abstract class ControllerBaseTest extends WebTestCase
protected function assertCalloutWidgetWithMessage(Client $client, string $message)
{
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
self::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
protected function assertHasFlashDeleteSuccess(Client $client)
@@ -301,7 +301,7 @@ abstract class ControllerBaseTest extends WebTestCase
$node = $client->getCrawler()->filter('div.alert.alert-success.alert-dismissible');
self::assertGreaterThan(0, $node->count(), 'Could not find flash success message');
if (null !== $message) {
self::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
}
@@ -314,7 +314,7 @@ abstract class ControllerBaseTest extends WebTestCase
$node = $client->getCrawler()->filter('div.alert.alert-error.alert-dismissible');
self::assertGreaterThan(0, $node->count(), 'Could not find flash error message');
if (null !== $message) {
self::assertStringContainsString($message, $node->text());
self::assertStringContainsString($message, $node->text(null, true));
}
}

View File

@@ -42,7 +42,7 @@ class CustomerControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Customer $customer) {
@@ -51,7 +51,7 @@ class CustomerControllerTest extends ControllerBaseTest
$customer->setMetaField((new CustomerMeta())->setName('location')->setValue('homeoffice'));
$customer->setMetaField((new CustomerMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/');
@@ -161,14 +161,14 @@ class CustomerControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/1/details');
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text());
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text(null, true));
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/admin/customer/1/create_team');
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/1/details'));
$client->followRedirect();
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text());
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text(null, true));
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body table tbody tr');
self::assertEquals(1, $node->count());
}
@@ -183,10 +183,11 @@ class CustomerControllerTest extends ControllerBaseTest
/** @var EntityManager $em */
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$customer = $em->getRepository(Customer::class)->find(1);
$fixture = new ProjectFixtures();
$fixture->setAmount(9); // to trigger a second page (every third activity is hidden)
$fixture->setCustomers([$customer]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/customer/1/projects/1');
@@ -267,7 +268,7 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TeamFixtures();
$fixture->setAmount(2);
$fixture->setAddCustomer(false);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/customer/1/permissions');
$form = $client->getCrawler()->filter('form[name=customer_team_permission_form]')->form();
@@ -292,10 +293,9 @@ class CustomerControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/admin/customer/2/edit');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -322,7 +322,7 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -361,10 +361,10 @@ class CustomerControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new CustomerFixtures();
$fixture->setAmount(1)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -66,7 +66,7 @@ class ExportControllerTest extends ControllerBaseTest
$em->persist($team);
})
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$teamlead = $this->getUserByRole($em, User::ROLE_TEAMLEAD);
@@ -76,7 +76,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(2)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$em->flush();
$this->request($client, '/export/?preview=');
@@ -112,7 +112,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -128,7 +128,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(2)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -194,7 +194,7 @@ class ExportControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/export/');
$this->assertTrue($client->getResponse()->isSuccessful());

View File

@@ -40,9 +40,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/?preview=');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -54,9 +53,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template');
@@ -94,7 +92,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
/** @var InvoiceTemplate $template */
$template = $em->getRepository(InvoiceTemplate::class)->find(1);
@@ -123,7 +121,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$begin = new \DateTime('first day of this month');
$end = new \DateTime('last day of this month');
@@ -133,7 +131,7 @@ class InvoiceControllerTest extends ControllerBaseTest
->setAmount(20)
->setStartDate($begin)
;
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -186,9 +184,8 @@ class InvoiceControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template/1/edit?page=1');
$form = $client->getCrawler()->filter('form[name=invoice_template_form]')->form();
@@ -216,7 +213,7 @@ class InvoiceControllerTest extends ControllerBaseTest
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new InvoiceFixtures();
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/invoice/template/1/delete');
$this->assertIsRedirect($client, '/invoice/template');

View File

@@ -55,7 +55,7 @@ class ProfileControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setStartDate($start);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER);
@@ -338,7 +338,7 @@ class ProfileControllerTest extends ControllerBaseTest
$fixture->setAddCustomer(true);
$fixture->setAddUser(false);
$fixture->addUserToIgnore($user);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER . '/teams');

View File

@@ -43,7 +43,7 @@ class ProjectControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(5);
$fixture->setCallback(function (Project $project) {
@@ -52,7 +52,7 @@ class ProjectControllerTest extends ControllerBaseTest
$project->setMetaField((new ProjectMeta())->setName('location')->setValue('homeoffice'));
$project->setMetaField((new ProjectMeta())->setName('feature')->setValue('timetracking'));
});
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/');
@@ -82,13 +82,13 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture->setAmount(10);
$fixture->setProjects([$project]);
$fixture->setUser($this->getUserByRole($em, User::ROLE_ADMIN));
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$project = $em->getRepository(Project::class)->find(1);
$fixture = new ActivityFixtures();
$fixture->setAmount(6); // to trigger a second page
$fixture->setProjects([$project]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/details');
@@ -180,14 +180,14 @@ class ProjectControllerTest extends ControllerBaseTest
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/details');
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text());
self::assertStringContainsString('Visible to everyone, as no team was assigned yet.', $node->text(null, true));
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->request($client, '/admin/project/1/create_team');
$this->assertIsRedirect($client, $this->createUrl('/admin/project/1/details'));
$client->followRedirect();
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body');
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text());
self::assertStringContainsString('Only visible to the following teams and all admins.', $node->text(null, true));
$node = $client->getCrawler()->filter('div.box#team_listing_box .box-body table tbody tr');
self::assertEquals(1, $node->count());
}
@@ -204,7 +204,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new ActivityFixtures();
$fixture->setAmount(9); // to trigger a second page (every third activity is hidden)
$fixture->setProjects([$project]);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->assertAccessIsGranted($client, '/admin/project/1/activities/1');
@@ -249,10 +249,9 @@ class ProjectControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new CustomerFixtures();
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/project/create');
$form = $client->getCrawler()->filter('form[name=project_edit_form]')->form();
@@ -308,7 +307,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TeamFixtures();
$fixture->setAmount(2);
$fixture->setAddCustomer(false);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->assertAccessIsGranted($client, '/admin/project/1/permissions');
$form = $client->getCrawler()->filter('form[name=project_team_permission_form]')->form();
@@ -333,10 +332,9 @@ class ProjectControllerTest extends ControllerBaseTest
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$fixture = new ProjectFixtures();
$fixture->setAmount(1);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$this->request($client, '/admin/project/2/edit');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -363,7 +361,7 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));
@@ -402,10 +400,10 @@ class ProjectControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($this->getUserByRole($em, User::ROLE_USER));
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$fixture = new ProjectFixtures();
$fixture->setAmount(1)->setIsVisible(true);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -12,23 +12,21 @@ namespace App\Tests\Controller;
use App\Entity\Tag;
use App\Entity\User;
use App\Tests\DataFixtures\TagFixtures;
use Symfony\Bundle\FrameworkBundle\Client;
/**
* @group integration
*/
class TagControllerTest extends ControllerBaseTest
{
protected function setUp(): void
protected function importTags(Client $client): void
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
$tagList = ['Test', 'Administration', 'Support', '#2018-001', '#2018-002', '#2018-003', 'Development',
'Marketing', 'First Level Support', 'Bug Fixing'];
$fixture = new TagFixtures();
$fixture->setTagArray($tagList);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
}
public function testDebugIsSecure()
@@ -39,6 +37,7 @@ class TagControllerTest extends ControllerBaseTest
public function testIndexAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/');
$this->assertHasDataTable($client);
@@ -48,6 +47,7 @@ class TagControllerTest extends ControllerBaseTest
public function testIndexActionWithSearchTermQuery()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->request($client, '/admin/tags/');
$this->assertTrue($client->getResponse()->isSuccessful());
@@ -76,7 +76,7 @@ class TagControllerTest extends ControllerBaseTest
$client->followRedirect();
$this->assertHasDataTable($client);
$this->request($client, '/admin/tags/11/edit');
$this->request($client, '/admin/tags/1/edit');
$editForm = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$this->assertEquals('A tAG Name!', $editForm->get('tag_edit_form[name]')->getValue());
}
@@ -84,6 +84,8 @@ class TagControllerTest extends ControllerBaseTest
public function testEditAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/1/edit');
$form = $client->getCrawler()->filter('form[name=tag_edit_form]')->form();
$client->submit($form, [
@@ -100,6 +102,8 @@ class TagControllerTest extends ControllerBaseTest
public function testMultiDeleteAction()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->importTags($client);
$this->assertAccessIsGranted($client, '/admin/tags/');
$form = $client->getCrawler()->filter('form[name=multi_update_table]')->form();

View File

@@ -147,7 +147,7 @@ class UserControllerTest extends ControllerBaseTest
$fixture = new TimesheetFixtures();
$fixture->setUser($user);
$fixture->setAmount(10);
$this->importFixture($em, $fixture);
$this->importFixture($client, $fixture);
$timesheets = $em->getRepository(Timesheet::class)->findAll();
$this->assertEquals(10, count($timesheets));

View File

@@ -25,11 +25,23 @@ class ThemeEventTest extends TestCase
$sut = new ThemeEvent($user);
$this->assertEquals($user, $sut->getUser());
$this->assertNull($sut->getPayload());
$this->assertEquals('', $sut->getContent());
}
/**
* @group legacy
*/
public function testDeprecation()
{
$user = new User();
$user->setAlias('foo');
$sut = new ThemeEvent($user);
$this->assertEquals($user, $sut->getUser());
}
public function testGetterAndSetter()
{
$user = new User();

View File

@@ -50,7 +50,28 @@ class UserPreferenceEventTest extends TestCase
$sut = new UserPreferenceEvent($user, []);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addPreference($pref);
$sut->addPreference($pref2);
}
/**
* @group legacy
*/
public function testDeprecations()
{
$this->expectException(\InvalidArgumentException::class);
$user = new User();
$user->setAlias('foo');
$pref = new UserPreference();
$pref->setName('foo')->setValue('bar');
$pref2 = new UserPreference();
$pref2->setName('foo')->setValue('hello');
$sut = new UserPreferenceEvent($user, []);
$sut->addUserPreference($pref); // change me, once the deprecated method will be deleted
$sut->addUserPreference($pref2); // change me, once the deprecated method will be deleted
}
}

View File

@@ -32,7 +32,10 @@ class RegistrationSubscriberTest extends TestCase
}
/**
* Legacy test becuase the user bundle won't update to a new release
*
* @dataProvider getTestData
* @group legacy
*/
public function testRoleAssignmentForNewUser(array $existingUsers, $expectedRoles)
{

View File

@@ -25,11 +25,13 @@ abstract class AbstractCalculatorTest extends TestCase
{
protected function assertEmptyModel(CalculatorInterface $sut)
{
$sut->setModel($this->getEmptyModel());
$model = $this->getEmptyModel();
$this->assertEquals('EUR', $model->getCurrency());
$sut->setModel($model);
$this->assertEquals(0, $sut->getTotal());
$this->assertEquals(0, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals(0, $sut->getSubtotal());
$this->assertEquals(0, $sut->getTimeWorked());
$this->assertEquals(0, count($sut->getEntries()));
@@ -89,7 +91,7 @@ abstract class AbstractCalculatorTest extends TestCase
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries([$timesheet]);
$model->addEntries([$timesheet]);
$model->setQuery($query);
$sut->setModel($model);

View File

@@ -136,7 +136,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ActivityInvoiceCalculator();
@@ -145,7 +145,7 @@ class ActivityInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('activity', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -110,7 +110,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new DateInvoiceCalculator();
@@ -119,7 +119,7 @@ class DateInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('date', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -61,7 +61,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery(new InvoiceQuery());
$sut = new DefaultCalculator();
@@ -70,7 +70,7 @@ class DefaultCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('default', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
}

View File

@@ -110,7 +110,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ProjectInvoiceCalculator();
@@ -119,7 +119,7 @@ class ProjectInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('project', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -90,7 +90,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -99,7 +99,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(562.28, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(472.5, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));
@@ -171,7 +171,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -180,7 +180,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5800, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));
@@ -250,7 +250,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new ShortInvoiceCalculator();
@@ -259,7 +259,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('short', $sut->getId());
$this->assertEquals(581.17, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(488.38, $sut->getSubtotal());
$this->assertEquals(5400, $sut->getTimeWorked());
$this->assertEquals(1, count($sut->getEntries()));

View File

@@ -108,7 +108,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$model = new InvoiceModel(new DebugFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$sut = new UserInvoiceCalculator();
@@ -117,7 +117,7 @@ class UserInvoiceCalculatorTest extends AbstractCalculatorTest
$this->assertEquals('user', $sut->getId());
$this->assertEquals(3000.13, $sut->getTotal());
$this->assertEquals(19, $sut->getVat());
$this->assertEquals('EUR', $sut->getCurrency());
$this->assertEquals('EUR', $model->getCurrency());
$this->assertEquals(2521.12, $sut->getSubtotal());
$this->assertEquals(6600, $sut->getTimeWorked());
$this->assertEquals(3, count($sut->getEntries()));

View File

@@ -59,10 +59,6 @@ class InvoiceModelTest extends TestCase
self::assertInstanceOf(InvoiceModel::class, $sut->setCalculator($calculator));
self::assertSame($calculator, $sut->getCalculator());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
self::assertSame($entries, $sut->getEntries());
$generator = new DateNumberGenerator();
self::assertInstanceOf(InvoiceModel::class, $sut->setNumberGenerator($generator));
self::assertSame($generator, $sut->getNumberGenerator());
@@ -73,4 +69,16 @@ class InvoiceModelTest extends TestCase
self::assertSame($template, $sut->getTemplate());
self::assertInstanceOf(\DateTime::class, $sut->getDueDate());
}
/**
* @group legacy
*/
public function testDeprecations()
{
$sut = new InvoiceModel(new DebugFormatter());
$entries = [new Timesheet()];
self::assertInstanceOf(InvoiceModel::class, $sut->setEntries($entries));
self::assertSame($entries, $sut->getEntries());
}
}

View File

@@ -204,7 +204,7 @@ trait RendererTestTrait
$model = new InvoiceModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$model->setUser($user);
@@ -276,7 +276,7 @@ trait RendererTestTrait
$model = new InvoiceModel($this->getFormatter());
$model->setCustomer($customer);
$model->setTemplate($template);
$model->setEntries($entries);
$model->addEntries($entries);
$model->setQuery($query);
$model->setUser($user);

View File

@@ -15,18 +15,23 @@ use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\ORM\EntityManager;
use Symfony\Bundle\FrameworkBundle\Client;
/**
* A trait to be used in all tests that extend the KernelTestCase.
*/
trait KernelTestTrait
{
/**
* @param EntityManager $em
* @param Fixture $fixture
*/
protected function importFixture(EntityManager $em, Fixture $fixture)
protected function importFixture($client, Fixture $fixture)
{
if ($client instanceof Client) {
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
} elseif ($client instanceof EntityManager) {
$em = $client;
} else {
throw new \InvalidArgumentException('Fixtures need an EntityManager to be imported');
}
$loader = new Loader();
$loader->addFixture($fixture);

View File

@@ -14,6 +14,7 @@ use App\Repository\TimesheetRepository;
use App\Repository\WidgetRepository;
use App\Tests\Mocks\Security\CurrentUserFactory;
use App\Widget\Type\CompoundChart;
use App\Widget\Type\Counter;
use App\Widget\WidgetException;
use PHPUnit\Framework\TestCase;
@@ -87,6 +88,7 @@ class WidgetRepositoryTest extends TestCase
'end' => null,
'query' => $query,
'title' => 'Test widget',
'type' => Counter::class,
];
$sut = new WidgetRepository($repoMock, $userMock, ['test' => $widget]);