new user-year reporting and data-type chooser (#3155)
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Tests\Controller\ControllerBaseTest;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
abstract class AbstractUserPeriodControllerTest extends ControllerBaseTest
|
||||
{
|
||||
protected function importReportingFixture(string $role)
|
||||
{
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(50);
|
||||
$fixture->setAmountRunning(10);
|
||||
$fixture->setUser($this->getUserByRole($role));
|
||||
$fixture->setStartDate(new \DateTime());
|
||||
$this->importFixture($fixture);
|
||||
}
|
||||
|
||||
abstract protected function getReportUrl(): string;
|
||||
|
||||
abstract protected function getBoxId(): string;
|
||||
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured($this->getReportUrl());
|
||||
}
|
||||
|
||||
public function getTestData(): array
|
||||
{
|
||||
return [
|
||||
[4, 'duration', 'Working hours total'],
|
||||
[4, 'rate', 'Total revenue'],
|
||||
[4, 'internalRate', 'Internal rate'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testUserPeriodReport(int $user, string $dataType, string $title)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, sprintf('%s?user=%s&date=12999119191&sumType=%s', $this->getReportUrl(), $user, $dataType));
|
||||
self::assertStringContainsString(sprintf('<div class="box-body %s', $this->getBoxId()), $client->getResponse()->getContent());
|
||||
$option = $client->getCrawler()->filterXPath("//select[@id='user']/option[@selected]");
|
||||
self::assertEquals($user, $option->attr('value'));
|
||||
$cell = $client->getCrawler()->filterXPath("//th[contains(@class, 'reportDataTypeTitle')]");
|
||||
self::assertEquals($title, $cell->text());
|
||||
}
|
||||
|
||||
public function testUserPeriodReportAsTeamlead()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->importReportingFixture(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, sprintf('%s?date=12999119191', $this->getReportUrl()));
|
||||
self::assertStringContainsString(sprintf('<div class="box-body %s', $this->getBoxId()), $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
$cell = $client->getCrawler()->filterXPath("//th[contains(@class, 'reportDataTypeTitle')]");
|
||||
self::assertEquals('Working hours total', $cell->text());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Tests\Controller\ControllerBaseTest;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
abstract class AbstractUsersPeriodControllerTest extends ControllerBaseTest
|
||||
{
|
||||
protected function importReportingFixture(string $role)
|
||||
{
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(50);
|
||||
$fixture->setAmountRunning(10);
|
||||
$fixture->setUser($this->getUserByRole($role));
|
||||
$fixture->setStartDate(new \DateTime());
|
||||
$this->importFixture($fixture);
|
||||
}
|
||||
|
||||
abstract protected function getReportUrl(): string;
|
||||
|
||||
abstract protected function getReportExportUrl(): string;
|
||||
|
||||
abstract protected function getBoxId(): string;
|
||||
|
||||
public function testIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured($this->getReportUrl());
|
||||
}
|
||||
|
||||
public function getTestData(): array
|
||||
{
|
||||
return [
|
||||
['duration', 'Working hours total'],
|
||||
['rate', 'Total revenue'],
|
||||
['internalRate', 'Internal rate'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testUsersPeriodReport(string $dataType, string $title)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, sprintf('%s?date=12999119191&sumType=%s', $this->getReportUrl(), $dataType));
|
||||
self::assertStringContainsString(sprintf('<div class="box-body %s', $this->getBoxId()), $client->getResponse()->getContent());
|
||||
$cell = $client->getCrawler()->filterXPath("//th[contains(@class, 'reportDataTypeTitle')]");
|
||||
self::assertEquals($title, $cell->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testUsersPeriodReportAsTeamlead(string $dataType, string $title)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->importReportingFixture(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, sprintf('%s?date=12999119191&sumType=%s', $this->getReportUrl(), $dataType));
|
||||
self::assertStringContainsString(sprintf('<div class="box-body %s', $this->getBoxId()), $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
$cell = $client->getCrawler()->filterXPath("//th[contains(@class, 'reportDataTypeTitle')]");
|
||||
self::assertEquals($title, $cell->text());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testUsersPeriodReportExport(string $dataType, string $title)
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
|
||||
$this->request($client, sprintf('%s?date=12999119191&sumType=%s', $this->getReportExportUrl(), $dataType));
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
self::assertInstanceOf(BinaryFileResponse::class, $response);
|
||||
self::assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
self::assertStringContainsString('attachment; filename=kimai-export-users-', $response->headers->get('Content-Disposition'));
|
||||
self::assertStringContainsString('.xlsx', $response->headers->get('Content-Disposition'));
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Tests\Controller\ControllerBaseTest;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ReportByUserControllerTest extends ControllerBaseTest
|
||||
{
|
||||
protected function importReportingFixture(string $role)
|
||||
{
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(50);
|
||||
$fixture->setAmountRunning(10);
|
||||
$fixture->setUser($this->getUserByRole($role));
|
||||
$fixture->setStartDate(new \DateTime());
|
||||
$this->importFixture($fixture);
|
||||
}
|
||||
|
||||
public function testWeekByUserIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/week_by_user');
|
||||
}
|
||||
|
||||
public function testMonthByUserIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/month_by_user');
|
||||
}
|
||||
|
||||
public function testUserWeekReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->importReportingFixture(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/reporting/week_by_user?user=4&date=12999119191');
|
||||
self::assertStringContainsString('<div class="box-body user-week-reporting-box', $client->getResponse()->getContent());
|
||||
$option = $client->getCrawler()->filterXPath("//select[@id='user']/option[@selected]");
|
||||
self::assertEquals(4, $option->attr('value'));
|
||||
}
|
||||
|
||||
public function testUserMonthReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->importReportingFixture(User::ROLE_USER);
|
||||
$this->assertAccessIsGranted($client, '/reporting/month_by_user?user=4&date=12999119191');
|
||||
self::assertStringContainsString('<div class="box-body user-month-reporting-box', $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Tests\Controller\ControllerBaseTest;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ReportUsersListControllerTest extends ControllerBaseTest
|
||||
{
|
||||
protected function importReportingFixture(string $role)
|
||||
{
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture->setAmount(50);
|
||||
$fixture->setAmountRunning(10);
|
||||
$fixture->setUser($this->getUserByRole($role));
|
||||
$fixture->setStartDate(new \DateTime());
|
||||
$this->importFixture($fixture);
|
||||
}
|
||||
|
||||
public function testYearlyListIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/yearly_users_list');
|
||||
}
|
||||
|
||||
public function testWeeklyListIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/weekly_users_list');
|
||||
}
|
||||
|
||||
public function testMonthlyListIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/monthly_users_list');
|
||||
}
|
||||
|
||||
public function testYearlyUsersListIsSecureForUserRole()
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/yearly_users_list');
|
||||
}
|
||||
|
||||
public function testWeeklyUsersListIsSecureForUserRole()
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/weekly_users_list');
|
||||
}
|
||||
|
||||
public function testMonthlyUsersListIsSecureForUserRole()
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/monthly_users_list');
|
||||
}
|
||||
|
||||
public function testYearlyUsersReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->importReportingFixture(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/reporting/yearly_users_list');
|
||||
self::assertStringContainsString('<div class="box-body yearly-user-list-reporting-box', $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
}
|
||||
|
||||
public function testWeeklyUsersReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->importReportingFixture(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/reporting/weekly_users_list');
|
||||
self::assertStringContainsString('<div class="box-body weekly-user-list-reporting-box', $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
}
|
||||
|
||||
public function testMonthlyUsersReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->importReportingFixture(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/reporting/monthly_users_list');
|
||||
self::assertStringContainsString('<div class="box-body monthly-user-list-reporting-box', $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ReportUsersMonthControllerTest extends AbstractUsersPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/users/month';
|
||||
}
|
||||
|
||||
protected function getReportExportUrl(): string
|
||||
{
|
||||
return '/reporting/users/month_export';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'monthly-user-list-reporting-box';
|
||||
}
|
||||
}
|
||||
31
tests/Controller/Reporting/ReportUsersWeekControllerTest.php
Normal file
31
tests/Controller/Reporting/ReportUsersWeekControllerTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ReportUsersWeekControllerTest extends AbstractUsersPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/users/week';
|
||||
}
|
||||
|
||||
protected function getReportExportUrl(): string
|
||||
{
|
||||
return '/reporting/users/week_export';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'weekly-user-list-reporting-box';
|
||||
}
|
||||
}
|
||||
31
tests/Controller/Reporting/ReportUsersYearControllerTest.php
Normal file
31
tests/Controller/Reporting/ReportUsersYearControllerTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class ReportUsersYearControllerTest extends AbstractUsersPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/users/year';
|
||||
}
|
||||
|
||||
protected function getReportExportUrl(): string
|
||||
{
|
||||
return '/reporting/users/year_export';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'yearly-user-list-reporting-box';
|
||||
}
|
||||
}
|
||||
26
tests/Controller/Reporting/UserMonthControllerTest.php
Normal file
26
tests/Controller/Reporting/UserMonthControllerTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class UserMonthControllerTest extends AbstractUserPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/user/month';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'user-month-reporting-box';
|
||||
}
|
||||
}
|
||||
26
tests/Controller/Reporting/UserWeekControllerTest.php
Normal file
26
tests/Controller/Reporting/UserWeekControllerTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class UserWeekControllerTest extends AbstractUserPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/user/week';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'user-week-reporting-box';
|
||||
}
|
||||
}
|
||||
26
tests/Controller/Reporting/UserYearControllerTest.php
Normal file
26
tests/Controller/Reporting/UserYearControllerTest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?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\Controller\Reporting;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
*/
|
||||
class UserYearControllerTest extends AbstractUserPeriodControllerTest
|
||||
{
|
||||
protected function getReportUrl(): string
|
||||
{
|
||||
return '/reporting/user/year';
|
||||
}
|
||||
|
||||
protected function getBoxId(): string
|
||||
{
|
||||
return 'user-year-reporting-box';
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class ReportingControllerTest extends ControllerBaseTest
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
|
||||
$this->request($client, '/reporting/');
|
||||
$this->assertIsRedirect($client, $this->createUrl('/reporting/week_by_user'));
|
||||
$this->assertIsRedirect($client, $this->createUrl('/reporting/user/week'));
|
||||
$client->followRedirect();
|
||||
self::assertStringContainsString('<div class="box-body user-week-reporting-box', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user