refactored page actions to event subscriber (#2420)

This commit is contained in:
Kevin Papst
2021-03-15 14:18:44 +01:00
committed by GitHub
parent 9a2fd9ba91
commit e1c9af795c
117 changed files with 2403 additions and 815 deletions

View File

@@ -263,9 +263,7 @@ class ActivityControllerTest extends ControllerBaseTest
$team2->tick();
$client->submit($form);
$this->assertIsRedirect($client, $this->createUrl('/admin/activity/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->assertIsRedirect($client, $this->createUrl('/admin/activity/' . $id . '/details'));
/** @var Activity $activity */
$activity = $em->getRepository(Activity::class)->find($id);

View File

@@ -344,9 +344,7 @@ class CustomerControllerTest extends ControllerBaseTest
$team2->tick();
$client->submit($form);
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->assertIsRedirect($client, $this->createUrl('/admin/customer/1/details'));
/** @var Customer $customer */
$customer = $em->getRepository(Customer::class)->find(1);

View File

@@ -410,9 +410,7 @@ class ProjectControllerTest extends ControllerBaseTest
$team2->tick();
$client->submit($form);
$this->assertIsRedirect($client, $this->createUrl('/admin/project/'));
$client->followRedirect();
$this->assertHasDataTable($client);
$this->assertIsRedirect($client, $this->createUrl('/admin/project/1/details'));
/** @var Project $project */
$project = $em->getRepository(Project::class)->find(1);

View File

@@ -23,22 +23,104 @@ class PageActionsEventTest extends TestCase
$user = new User();
$user->setAlias('foo');
$sut = new PageActionsEvent($user, [], 'foo');
$sut = new PageActionsEvent($user, [], 'foo', 'bar');
$this->assertEquals('bar', $sut->getView());
$this->assertEquals('foo', $sut->getActionName());
$this->assertTrue($sut->isView('bar'));
$this->assertFalse($sut->isView('foo'));
$this->assertFalse($sut->isIndexView());
$this->assertSame($user, $sut->getUser());
$this->assertEquals([], $sut->getActions());
$this->assertEquals(['actions' => []], $sut->getPayload());
$this->assertEquals(['actions' => [], 'view' => 'bar'], $sut->getPayload());
$sut = new PageActionsEvent($user, ['hello' => 'world'], 'foo');
$sut = new PageActionsEvent($user, ['hello' => 'world'], 'foo', 'bar');
$this->assertSame($user, $sut->getUser());
$this->assertEquals([], $sut->getActions());
$this->assertEquals(['hello' => 'world', 'actions' => []], $sut->getPayload());
$this->assertEquals(['hello' => 'world', 'actions' => [], 'view' => 'bar'], $sut->getPayload());
}
public function testSetActions()
{
$sut = new PageActionsEvent(new User(), ['hello' => 'world'], 'foo');
$sut->setActions(['foo' => ['url' => 'bar']]);
$sut = new PageActionsEvent(new User(), ['hello' => 'world'], 'foo', 'xxx');
$sut->addAction('foo', ['url' => 'bar']);
$this->assertEquals(['foo' => ['url' => 'bar']], $sut->getActions());
$this->assertEquals(['hello' => 'world', 'actions' => ['foo' => ['url' => 'bar']]], $sut->getPayload());
$this->assertEquals(['hello' => 'world', 'actions' => ['foo' => ['url' => 'bar']], 'view' => 'xxx'], $sut->getPayload());
$this->assertEquals(1, $sut->countActions());
// make sure an action with tzhe same name cannot be added
$sut->addAction('foo', ['url' => 'bar']);
$this->assertEquals(1, $sut->countActions());
$this->assertEquals(0, $sut->countActions('foo'));
$this->assertTrue($sut->hasAction('foo'));
$this->assertFalse($sut->hasAction('sdsd'));
$sut->removeAction('xxx');
$this->assertEquals(1, $sut->countActions());
$sut->removeAction('foo');
$this->assertEquals(0, $sut->countActions());
$sut->addAction('foo', ['url' => 'bar']);
$this->assertEquals(['foo' => ['url' => 'bar']], $sut->getActions());
$sut->replaceAction('foo', ['url' => 'xyz']);
$this->assertEquals(['foo' => ['url' => 'xyz']], $sut->getActions());
}
public function testSubmenu()
{
$sut = new PageActionsEvent(new User(), ['hello' => 'world'], 'foo', 'xxx');
$this->assertFalse($sut->hasSubmenu('test'));
$sut->addActionToSubmenu('test', 'blub', ['url' => 'hello-world']);
$this->assertTrue($sut->hasSubmenu('test'));
$this->assertEquals(['test' => ['children' => ['blub' => ['url' => 'hello-world']]]], $sut->getActions());
$sut->addActionToSubmenu('test', 'blub1', ['url' => 'hello-world']);
$this->assertEquals(2, $sut->countActions('test'));
}
public function testAddHelper()
{
$sut = new PageActionsEvent(new User(), ['hello' => 'world'], 'foo', 'xxx');
$sut->addSearchToggle();
$sut->addDivider();
$sut->addBack('foo1');
$sut->addColumnToggle('foo2');
$sut->addDelete('foo3');
$sut->addHelp('foo4');
$sut->addCreate('foo5', true);
$sut->addCreate('foo6', false);
$sut->addQuickExport('foo7');
$this->assertEquals(8, $sut->countActions());
$expected = [
'search' => ['class' => 'search-toggle visible-xs-inline'],
'divider0' => null,
'back' => ['url' => 'foo1', 'translation_domain' => 'actions'],
'visibility' => ['modal' => '#foo2'],
'help' => ['url' => 'foo4', 'target' => '_blank'],
'create' => ['url' => 'foo5', 'class' => 'modal-ajax-form'],
'download' => ['url' => 'foo7', 'class' => 'toolbar-action'],
'trash' => ['url' => 'foo3', 'class' => 'modal-ajax-form text-red'],
];
$this->assertEquals($expected, $sut->getActions());
}
public function testAddOthers()
{
$sut = new PageActionsEvent(new User(), ['hello' => 'world'], 'foo', 'xxx');
// make sure that modal always start with #, no matter what was given
$sut->addColumnToggle('#fooX');
$this->assertEquals(['visibility' => ['modal' => '#fooX']], $sut->getActions());
// make sure that a second toggle cannot be added
$sut->addColumnToggle('fooY');
$this->assertEquals(['visibility' => ['modal' => '#fooX']], $sut->getActions());
$sut->removeAction('visibility');
$sut->addColumnToggle('fooY');
$this->assertEquals(['visibility' => ['modal' => '#fooY']], $sut->getActions());
}
}

View File

@@ -0,0 +1,29 @@
<?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\EventSubscriber\Actions;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\EventSubscriber\Actions\AbstractActionsSubscriber
*/
abstract class AbstractActionsSubscriberTest extends TestCase
{
protected function assertGetSubscribedEvent(string $className, string $name)
{
$this->assertTrue(method_exists($className, 'getSubscribedEvents'));
$events = $className::getSubscribedEvents();
$actionName = array_keys($events)[0];
$config = $events[$actionName];
$this->assertEquals('actions.' . $name, $actionName);
$this->assertTrue(method_exists($className, $config[0]));
$this->assertEquals(1000, $config[1]);
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ActivitiesSubscriber;
/**
* @covers \App\EventSubscriber\Actions\ActivitiesSubscriber
*/
class ActivitiesSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ActivitiesSubscriber::class, 'activities');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ActivitySubscriber;
/**
* @covers \App\EventSubscriber\Actions\ActivitySubscriber
*/
class ActivitySubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ActivitySubscriber::class, 'activity');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\CalendarSubscriber;
/**
* @covers \App\EventSubscriber\Actions\CalendarSubscriber
*/
class CalendarSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(CalendarSubscriber::class, 'calendar');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\CustomerSubscriber;
/**
* @covers \App\EventSubscriber\Actions\CustomerSubscriber
*/
class CustomerSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(CustomerSubscriber::class, 'customer');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\CustomersSubscriber;
/**
* @covers \App\EventSubscriber\Actions\CustomersSubscriber
*/
class CustomersSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(CustomersSubscriber::class, 'customers');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ExportSubscriber;
/**
* @covers \App\EventSubscriber\Actions\ExportSubscriber
*/
class ExportSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ExportSubscriber::class, 'export');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoiceArchiveSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoiceArchiveSubscriber
*/
class InvoiceArchiveSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoiceArchiveSubscriber::class, 'invoice_details');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoiceTemplateSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoiceTemplateSubscriber
*/
class InvoiceTemplateSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoiceTemplateSubscriber::class, 'invoice_template');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoiceTemplateUploadSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoiceTemplateUploadSubscriber
*/
class InvoiceTemplateUploadSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoiceTemplateUploadSubscriber::class, 'invoice_upload');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoiceTemplatesSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoiceTemplatesSubscriber
*/
class InvoiceTemplatesSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoiceTemplatesSubscriber::class, 'invoice_templates');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\InvoicesSubscriber;
/**
* @covers \App\EventSubscriber\Actions\InvoicesSubscriber
*/
class InvoicesSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(InvoicesSubscriber::class, 'invoices');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\PermissionsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\PermissionsSubscriber
*/
class PermissionsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(PermissionsSubscriber::class, 'user_permissions');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\PluginSubscriber;
/**
* @covers \App\EventSubscriber\Actions\PluginSubscriber
*/
class PluginSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(PluginSubscriber::class, 'plugin');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\PluginsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\PluginsSubscriber
*/
class PluginsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(PluginsSubscriber::class, 'plugins');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ProjectSubscriber;
/**
* @covers \App\EventSubscriber\Actions\ProjectSubscriber
*/
class ProjectSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ProjectSubscriber::class, 'project');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ProjectsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\ProjectsSubscriber
*/
class ProjectsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ProjectsSubscriber::class, 'projects');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\ReportingSubscriber;
/**
* @covers \App\EventSubscriber\Actions\ReportingSubscriber
*/
class ReportingSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(ReportingSubscriber::class, 'reporting');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\SystemConfigurationSubscriber;
/**
* @covers \App\EventSubscriber\Actions\SystemConfigurationSubscriber
*/
class SystemConfigurationSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(SystemConfigurationSubscriber::class, 'system_configuration');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TagSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TagSubscriber
*/
class TagSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TagSubscriber::class, 'tag');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TagsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TagsSubscriber
*/
class TagsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TagsSubscriber::class, 'tags');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TeamSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TeamSubscriber
*/
class TeamSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TeamSubscriber::class, 'team');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TeamsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TeamsSubscriber
*/
class TeamsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TeamsSubscriber::class, 'teams');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetMultiUpdateSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetMultiUpdateSubscriber
*/
class TimesheetMultiUpdateSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetMultiUpdateSubscriber::class, 'timesheets_multi_update');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetSubscriber
*/
class TimesheetSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetSubscriber::class, 'timesheet');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetTeamMultiUpdateSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetTeamMultiUpdateSubscriber
*/
class TimesheetTeamMultiUpdateSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetTeamMultiUpdateSubscriber::class, 'timesheets_team_multi_update');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetTeamSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetTeamSubscriber
*/
class TimesheetTeamSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetTeamSubscriber::class, 'timesheet_team');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetsSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetsSubscriber
*/
class TimesheetsSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetsSubscriber::class, 'timesheets');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\TimesheetsTeamSubscriber;
/**
* @covers \App\EventSubscriber\Actions\TimesheetsTeamSubscriber
*/
class TimesheetsTeamSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(TimesheetsTeamSubscriber::class, 'timesheets_team');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\UserSubscriber;
/**
* @covers \App\EventSubscriber\Actions\UserSubscriber
*/
class UserSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(UserSubscriber::class, 'user');
}
}

View File

@@ -0,0 +1,23 @@
<?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\EventSubscriber\Actions;
use App\EventSubscriber\Actions\UsersSubscriber;
/**
* @covers \App\EventSubscriber\Actions\UsersSubscriber
*/
class UsersSubscriberTest extends AbstractActionsSubscriberTest
{
public function testEventName()
{
$this->assertGetSubscribedEvent(UsersSubscriber::class, 'users');
}
}

View File

@@ -34,10 +34,10 @@ class UserPreferenceSubscriberTest extends TestCase
'theme.collapsed_sidebar',
'theme.update_browser_title',
'calendar.initial_view',
'reporting.initial_view',
'login.initial_view',
'timesheet.daily_stats',
'timesheet.export_decimal',
'reporting.initial_view',
'login.initial_view',
'timesheet.daily_stats',
'timesheet.export_decimal',
];
public function testGetSubscribedEvents()
@@ -67,6 +67,7 @@ class UserPreferenceSubscriberTest extends TestCase
switch ($pref->getName()) {
case UserPreference::HOURLY_RATE:
case UserPreference::INTERNAL_RATE:
case 'reporting.initial_view':
self::assertTrue($pref->isEnabled());
break;
@@ -97,6 +98,7 @@ class UserPreferenceSubscriberTest extends TestCase
switch ($pref->getName()) {
case UserPreference::HOURLY_RATE:
case UserPreference::INTERNAL_RATE:
case 'reporting.initial_view':
self::assertFalse($pref->isEnabled());
break;
@@ -109,7 +111,7 @@ class UserPreferenceSubscriberTest extends TestCase
protected function getSubscriber(bool $seeHourlyRate)
{
$authMock = $this->createMock(AuthorizationCheckerInterface::class);
$authMock->expects($this->once())->method('isGranted')->willReturn($seeHourlyRate);
$authMock->method('isGranted')->willReturn($seeHourlyRate);
$eventMock = $this->createMock(EventDispatcherInterface::class);
$formConfigMock = $this->createMock(SystemConfiguration::class);

View File

@@ -1,33 +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\Twig\Runtime;
use App\Export\ServiceExport;
use App\Twig\Runtime\ExporterExtension;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Twig\Runtime\ExporterExtension
*/
class ExporterExtensionTest extends TestCase
{
protected function getSut(): ExporterExtension
{
$service = new ServiceExport();
return new ExporterExtension($service);
}
public function testGetExporter()
{
$sut = $this->getSut();
self::assertEquals([], $sut->getTimesheetExporter());
}
}

View File

@@ -1,43 +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\Twig\Runtime;
use App\Entity\User;
use App\Reporting\ReportingService;
use App\Twig\Runtime\ReportingExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Twig\Runtime\ReportingExtension
*/
class ReportingExtensionTest extends TestCase
{
protected function getSut(bool $isGranted): ReportingExtension
{
$eventDispatcher = new EventDispatcher();
$authorization = $this->createMock(AuthorizationCheckerInterface::class);
$authorization->expects($this->any())->method('isGranted')->willReturn($isGranted);
$service = new ReportingService($eventDispatcher, $authorization);
return new ReportingExtension($service);
}
public function testRenderWidgetForInvalidValue()
{
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
$this->assertCount(4, $reports);
}
}

View File

@@ -41,11 +41,9 @@ class RuntimeExtensionsTest extends TestCase
'trigger',
'actions',
'javascript_translations',
'timesheet_exporter',
'active_timesheets',
'encore_entry_css_source',
'render_widget',
'available_reports'
];
$i = 0;