Store sessions in database (#1736)
This commit is contained in:
39
tests/Command/CreateReleaseCommandTest.php
Normal file
39
tests/Command/CreateReleaseCommandTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\CreateReleaseCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\CreateReleaseCommand
|
||||
* @group integration
|
||||
*/
|
||||
class CreateReleaseCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
$this->application->add(new CreateReleaseCommand(realpath(__DIR__ . '/../../')));
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:create-release');
|
||||
self::assertInstanceOf(CreateReleaseCommand::class, $command);
|
||||
}
|
||||
}
|
||||
51
tests/Command/ImportCustomerCommandTest.php
Normal file
51
tests/Command/ImportCustomerCommandTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\ImportCustomerCommand;
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TeamRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\ImportCustomerCommand
|
||||
* @group integration
|
||||
*/
|
||||
class ImportCustomerCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
|
||||
$customers = $this->createMock(CustomerRepository::class);
|
||||
$projects = $this->createMock(ProjectRepository::class);
|
||||
$teams = $this->createMock(TeamRepository::class);
|
||||
$users = $this->createMock(UserRepository::class);
|
||||
$configuration = $this->createMock(FormConfiguration::class);
|
||||
|
||||
$this->application->add(new ImportCustomerCommand($customers, $projects, $teams, $users, $configuration));
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:import:customer');
|
||||
self::assertInstanceOf(ImportCustomerCommand::class, $command);
|
||||
}
|
||||
}
|
||||
53
tests/Command/ImportTimesheetCommandTest.php
Normal file
53
tests/Command/ImportTimesheetCommandTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\ImportTimesheetCommand;
|
||||
use App\Configuration\FormConfiguration;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\CustomerRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\ImportTimesheetCommand
|
||||
* @group integration
|
||||
*/
|
||||
class ImportTimesheetCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
|
||||
$customers = $this->createMock(CustomerRepository::class);
|
||||
$projects = $this->createMock(ProjectRepository::class);
|
||||
$activities = $this->createMock(ActivityRepository::class);
|
||||
$users = $this->createMock(UserRepository::class);
|
||||
$timesheets = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(FormConfiguration::class);
|
||||
|
||||
$this->application->add(new ImportTimesheetCommand($customers, $projects, $activities, $users, $timesheets, $configuration));
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:import:timesheet');
|
||||
self::assertInstanceOf(ImportTimesheetCommand::class, $command);
|
||||
}
|
||||
}
|
||||
47
tests/Command/KimaiImporterCommandTest.php
Normal file
47
tests/Command/KimaiImporterCommandTest.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\KimaiImporterCommand;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\KimaiImporterCommand
|
||||
* @group integration
|
||||
*/
|
||||
class KimaiImporterCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
|
||||
$encoder = $this->createMock(UserPasswordEncoderInterface::class);
|
||||
$registry = $this->createMock(ManagerRegistry::class);
|
||||
$validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$this->application->add(new KimaiImporterCommand($encoder, $registry, $validator));
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:import-v1');
|
||||
self::assertInstanceOf(KimaiImporterCommand::class, $command);
|
||||
}
|
||||
}
|
||||
39
tests/Command/ReloadCommandTest.php
Normal file
39
tests/Command/ReloadCommandTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\ReloadCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\ReloadCommand
|
||||
* @group integration
|
||||
*/
|
||||
class ReloadCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
$this->application->add(new ReloadCommand());
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:reload');
|
||||
self::assertInstanceOf(ReloadCommand::class, $command);
|
||||
}
|
||||
}
|
||||
39
tests/Command/ResetCommandTest.php
Normal file
39
tests/Command/ResetCommandTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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\Command;
|
||||
|
||||
use App\Command\ResetCommand;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\ResetCommand
|
||||
* @group integration
|
||||
*/
|
||||
class ResetCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
$this->application->add(new ResetCommand());
|
||||
}
|
||||
|
||||
public function testCommandName()
|
||||
{
|
||||
$command = $this->application->find('kimai:reset-dev');
|
||||
self::assertInstanceOf(ResetCommand::class, $command);
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Plugin\PluginManager;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin\TestPlugin;
|
||||
|
||||
/**
|
||||
* @group integration
|
||||
|
||||
49
tests/EventSubscriber/RedirectToLocaleSubscriberTest.php
Normal file
49
tests/EventSubscriber/RedirectToLocaleSubscriberTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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;
|
||||
|
||||
use App\EventSubscriber\RedirectToLocaleSubscriber;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Event\RequestEvent;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
/**
|
||||
* @covers \App\EventSubscriber\RedirectToLocaleSubscriber
|
||||
*/
|
||||
class RedirectToLocaleSubscriberTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||
$sut = new RedirectToLocaleSubscriber($urlGenerator, 'de|en', 'en');
|
||||
|
||||
self::assertEquals([KernelEvents::REQUEST => ['onKernelRequest']], RedirectToLocaleSubscriber::getSubscribedEvents());
|
||||
|
||||
$request = $this->createMock(Request::class);
|
||||
$request->expects($this->once())->method('getPathInfo')->willReturn('/de');
|
||||
|
||||
$event = $this->createMock(RequestEvent::class);
|
||||
$event->expects($this->once())->method('getRequest')->willReturn($request);
|
||||
$event->expects($this->never())->method('setResponse');
|
||||
|
||||
$sut->onKernelRequest($event);
|
||||
}
|
||||
|
||||
public function testConstructWithUnknownDefaultLocale()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$this->expectExceptionMessage('The default locale ("en") must be one of "de|it".');
|
||||
|
||||
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
|
||||
$sut = new RedirectToLocaleSubscriber($urlGenerator, 'de|it', 'en');
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Plugin\Fixtures;
|
||||
namespace App\Tests\Plugin\Fixtures\TestPlugin;
|
||||
|
||||
use App\Plugin\PluginInterface;
|
||||
|
||||
31
tests/Plugin/Fixtures/TestPlugin2/TestPlugin2.php
Normal file
31
tests/Plugin/Fixtures/TestPlugin2/TestPlugin2.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\Plugin\Fixtures\TestPlugin2;
|
||||
|
||||
use App\Plugin\PluginInterface;
|
||||
|
||||
class TestPlugin2 implements PluginInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'TestPlugin';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return __DIR__;
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ use App\Plugin\Plugin;
|
||||
use App\Plugin\PluginInterface;
|
||||
use App\Plugin\PluginManager;
|
||||
use App\Plugin\PluginMetadata;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin\TestPlugin;
|
||||
use App\Tests\Plugin\Fixtures\TestPlugin2\TestPlugin2;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -38,15 +39,13 @@ class PluginManagerTest extends TestCase
|
||||
{
|
||||
$sut = new PluginManager([]);
|
||||
|
||||
$plugin = $this->getMockBuilder(PluginInterface::class)
|
||||
->onlyMethods(['getName', 'getPath'])
|
||||
->getMock();
|
||||
|
||||
$plugin->method('getName')->willReturn('foo');
|
||||
$plugin->method('getPath')->willReturn('bar');
|
||||
$plugin = $this->createMock(PluginInterface::class);
|
||||
$plugin->expects($this->any())->method('getName')->willReturn('foo');
|
||||
$plugin->expects($this->any())->method('getPath')->willReturn('bar');
|
||||
|
||||
$sut->addPlugin(new TestPlugin());
|
||||
$sut->addPlugin($plugin);
|
||||
$sut->addPlugin(new TestPlugin2());
|
||||
$sut->addPlugin(new TestPlugin());
|
||||
|
||||
// make sure a plugin with the same name is not added twice, the first one wins!
|
||||
|
||||
45
tests/Security/AclDecisionManagerTest.php
Normal file
45
tests/Security/AclDecisionManagerTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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\Security;
|
||||
|
||||
use App\Security\AclDecisionManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
|
||||
|
||||
/**
|
||||
* @covers \App\Security\AclDecisionManager
|
||||
*/
|
||||
class AclDecisionManagerTest extends TestCase
|
||||
{
|
||||
public function testFullyAuthenticated()
|
||||
{
|
||||
$manager = $this->createMock(AccessDecisionManagerInterface::class);
|
||||
$manager->expects($this->once())->method('decide')->willReturn(true);
|
||||
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
|
||||
$sut = new AclDecisionManager($manager);
|
||||
$result = $sut->isFullyAuthenticated($token);
|
||||
self::assertTrue($result);
|
||||
}
|
||||
|
||||
public function testIsNotFullyAuthenticated()
|
||||
{
|
||||
$manager = $this->createMock(AccessDecisionManagerInterface::class);
|
||||
$manager->expects($this->once())->method('decide')->willReturn(false);
|
||||
|
||||
$token = $this->createMock(TokenInterface::class);
|
||||
|
||||
$sut = new AclDecisionManager($manager);
|
||||
$result = $sut->isFullyAuthenticated($token);
|
||||
self::assertFalse($result);
|
||||
}
|
||||
}
|
||||
26
tests/Security/SessionHandlerTest.php
Normal file
26
tests/Security/SessionHandlerTest.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\Security;
|
||||
|
||||
use App\Security\SessionHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Security\SessionHandler
|
||||
*/
|
||||
class SessionHandlerTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$sut = new SessionHandler(null);
|
||||
|
||||
self::assertFalse($sut->isSessionExpired());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user