added installation command (#838)
This commit is contained in:
@@ -50,7 +50,8 @@ class CreateUserCommandTest extends KernelTestCase
|
||||
|
||||
$container = self::$kernel->getContainer();
|
||||
$user = $container->get('doctrine')->getRepository(User::class)->loadUserByUsername('MyTestUser');
|
||||
$this->assertNotNull($user);
|
||||
self::assertInstanceOf(User::class, $user);
|
||||
self::assertNotNull($user);
|
||||
}
|
||||
|
||||
protected function createUser($username, $email, $role, $password)
|
||||
|
||||
93
tests/Command/InstallCommandTest.php
Normal file
93
tests/Command/InstallCommandTest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?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\InstallCommand;
|
||||
use App\Utils\File;
|
||||
use Symfony\Bundle\FrameworkBundle\Console\Application;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
|
||||
/**
|
||||
* @covers \App\Command\InstallCommand
|
||||
* @group integration
|
||||
*/
|
||||
class InstallCommandTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
protected $application;
|
||||
|
||||
protected function getCommand($permission = 0777): InstallCommand
|
||||
{
|
||||
$fileMock = $this->getMockBuilder(File::class)->setMethods(['getPermissions'])->getMock();
|
||||
$fileMock->expects($this->exactly(5))->method('getPermissions')->willReturn($permission);
|
||||
|
||||
$kernel = self::bootKernel();
|
||||
$this->application = new Application($kernel);
|
||||
$container = self::$kernel->getContainer();
|
||||
|
||||
$this->application->add(new InstallCommand(
|
||||
$container->getParameter('kernel.project_dir'),
|
||||
$container->get('doctrine')->getConnection(),
|
||||
$fileMock
|
||||
));
|
||||
|
||||
return $this->application->find('kimai:install');
|
||||
}
|
||||
|
||||
public function testMissingPermissionsAborted()
|
||||
{
|
||||
$command = $this->getCommand(0210);
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->setInputs(['no']);
|
||||
$commandTester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
|
||||
$result = $commandTester->getDisplay();
|
||||
|
||||
self::assertContains('var/cache/', $result);
|
||||
self::assertContains('var/data/', $result);
|
||||
self::assertContains('var/log/', $result);
|
||||
self::assertContains('var/plugins/', $result);
|
||||
self::assertContains('var/sessions/', $result);
|
||||
self::assertEquals(5, substr_count($result, 'missing: read owner,read group,write group'));
|
||||
self::assertContains('[WARNING] Aborting installation to review the permissions for above mentioned', $result);
|
||||
self::assertEquals(InstallCommand::ERROR_PERMISSIONS, $commandTester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testFullRunWithEverythingPreInstalled()
|
||||
{
|
||||
$command = $this->getCommand(0770);
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->setInputs(['no']);
|
||||
$commandTester->execute([
|
||||
'command' => $command->getName(),
|
||||
]);
|
||||
|
||||
$result = $commandTester->getDisplay();
|
||||
|
||||
// create database is skipped
|
||||
self::assertContains('[NOTE] Database is existing and connection could be established', $result);
|
||||
|
||||
// create schema is skipped
|
||||
self::assertContains('[NOTE] It seems as if you already have the required tables in your database,', $result);
|
||||
self::assertContains('skipping schema creation', $result);
|
||||
|
||||
self::assertContains('[NOTE] Found ', $result);
|
||||
self::assertContains(' migrations in your database, skipping import', $result);
|
||||
|
||||
self::assertContains('[OK] Congratulations! Kimai 2 (0.9 stable) was successful installed!', $result);
|
||||
|
||||
self::assertEquals(0, $commandTester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ class UserControllerTest extends ControllerBaseTest
|
||||
$this->assertAccessIsGranted($client, '/admin/user/create');
|
||||
$form = $client->getCrawler()->filter('form[name=user_create]')->form();
|
||||
$this->assertTrue($form->has('user_create[create_more]'));
|
||||
$this->assertFalse($form->get('user_create[create_more]')->hasValue());
|
||||
$this->assertNull($form->get('user_create[create_more]')->getValue());
|
||||
$client->submit($form, [
|
||||
'user_create' => [
|
||||
|
||||
36
tests/Doctrine/TimesheetSubscriberTest.php
Normal file
36
tests/Doctrine/TimesheetSubscriberTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Doctrine;
|
||||
|
||||
use App\Doctrine\TimesheetSubscriber;
|
||||
use Doctrine\ORM\Events;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Doctrine\TimesheetSubscriber
|
||||
*/
|
||||
class TimesheetSubscriberTest extends TestCase
|
||||
{
|
||||
public function testGetSubscribedEvents()
|
||||
{
|
||||
$sut = new TimesheetSubscriber([]);
|
||||
$events = $sut->getSubscribedEvents();
|
||||
$this->assertTrue(in_array(Events::onFlush, $events));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Invalid TimesheetCalculator implementation given. Expected CalculatorInterface but received stdClass
|
||||
*/
|
||||
public function testConstructThrowsExceptionOnInvalidParam()
|
||||
{
|
||||
new TimesheetSubscriber([new \stdClass()]);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ namespace App\Tests\Doctrine;
|
||||
|
||||
use App\Doctrine\UTCDateTimeType;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\SqlitePlatform;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
@@ -19,24 +21,6 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
*/
|
||||
class UTCDateTimeTypeTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @var AbstractPlatform
|
||||
*/
|
||||
private $platform;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
|
||||
$registry = $kernel->getContainer()->get('doctrine');
|
||||
/** @var \Doctrine\DBAL\Connection $connection */
|
||||
$connection = $registry->getConnection();
|
||||
$this->platform = $connection->getDatabasePlatform();
|
||||
}
|
||||
|
||||
public function testGetUtc()
|
||||
{
|
||||
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
|
||||
@@ -49,13 +33,16 @@ class UTCDateTimeTypeTest extends KernelTestCase
|
||||
$this->assertEquals('UTC', $type::getUtc()->getName());
|
||||
}
|
||||
|
||||
public function testConvertToDatabaseValue()
|
||||
/**
|
||||
* @dataProvider getPlatforms
|
||||
*/
|
||||
public function testConvertToDatabaseValue(AbstractPlatform $platform)
|
||||
{
|
||||
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
|
||||
/** @var UTCDateTimeType $type */
|
||||
$type = Type::getType(Type::DATETIME);
|
||||
|
||||
$result = $type->convertToDatabaseValue(null, $this->platform);
|
||||
$result = $type->convertToDatabaseValue(null, $platform);
|
||||
$this->assertNull($result);
|
||||
|
||||
$berlinTz = new \DateTimeZone('Europe/Berlin');
|
||||
@@ -66,40 +53,63 @@ class UTCDateTimeTypeTest extends KernelTestCase
|
||||
|
||||
$expected = clone $date;
|
||||
$expected->setTimezone($type::getUtc());
|
||||
$bla = $expected->format($this->platform->getDateTimeFormatString());
|
||||
$bla = $expected->format($platform->getDateTimeFormatString());
|
||||
|
||||
/** @var \DateTime $result */
|
||||
$result = $type->convertToDatabaseValue($date, $this->platform);
|
||||
$result = $type->convertToDatabaseValue($date, $platform);
|
||||
|
||||
$this->assertEquals($bla, $result);
|
||||
}
|
||||
|
||||
public function testConvertToPHPValue()
|
||||
/**
|
||||
* @dataProvider getPlatforms
|
||||
*/
|
||||
public function testConvertToPHPValue(AbstractPlatform $platform)
|
||||
{
|
||||
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
|
||||
/** @var UTCDateTimeType $type */
|
||||
$type = Type::getType(Type::DATETIME);
|
||||
|
||||
$result = $type->convertToPHPValue(null, $this->platform);
|
||||
$result = $type->convertToPHPValue(null, $platform);
|
||||
$this->assertNull($result);
|
||||
|
||||
$result = $type->convertToPHPValue('2019-01-17 13:30:00', $this->platform);
|
||||
$result = $type->convertToPHPValue('2019-01-17 13:30:00', $platform);
|
||||
$this->assertInstanceOf(\DateTime::class, $result);
|
||||
$this->assertEquals('UTC', $result->getTimezone()->getName());
|
||||
|
||||
$result = $result->format($this->platform->getDateTimeFormatString());
|
||||
$result = $result->format($platform->getDateTimeFormatString());
|
||||
$this->assertEquals('2019-01-17 13:30:00', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPlatforms
|
||||
* @expectedException \Doctrine\DBAL\Types\ConversionException
|
||||
*/
|
||||
public function testConvertToPHPValueWithInvalidValue()
|
||||
public function testConvertToPHPValueWithInvalidValue(AbstractPlatform $platform)
|
||||
{
|
||||
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
|
||||
/** @var UTCDateTimeType $type */
|
||||
$type = Type::getType(Type::DATETIME);
|
||||
|
||||
$type->convertToPHPValue('201xx01-17 13:30:00', $this->platform);
|
||||
$type->convertToPHPValue('201xx01-17 13:30:00', $platform);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPlatforms
|
||||
*/
|
||||
public function testRequiresSQLCommentHint(AbstractPlatform $platform)
|
||||
{
|
||||
Type::overrideType(Type::DATETIME, UTCDateTimeType::class);
|
||||
/** @var UTCDateTimeType $type */
|
||||
$type = Type::getType(Type::DATETIME);
|
||||
self::assertTrue($type->requiresSQLCommentHint($platform));
|
||||
}
|
||||
|
||||
public function getPlatforms()
|
||||
{
|
||||
return [
|
||||
[new MySqlPlatform()],
|
||||
[new SqlitePlatform()],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
36
tests/Utils/FileTest.php
Normal file
36
tests/Utils/FileTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Utils;
|
||||
|
||||
use App\Utils\File;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Utils\File
|
||||
*/
|
||||
class FileTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Filesystem\Exception\FileNotFoundException
|
||||
* @expectedExceptionMessage Unknown file "/kjhgkjhg/jkhgkjhg"
|
||||
*/
|
||||
public function testGetPermissionsOnNonExistingFile()
|
||||
{
|
||||
$sut = new File();
|
||||
$sut->getPermissions('/kjhgkjhg/jkhgkjhg');
|
||||
}
|
||||
|
||||
public function testGetPermissionsOnDisallowedDirectory()
|
||||
{
|
||||
$sut = new File();
|
||||
$perms = $sut->getPermissions(__FILE__);
|
||||
$this->assertEquals($perms, fileperms(__FILE__));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user