Release 2.27 (#5212)
This commit is contained in:
32
tests/Ldap/LdapBadgeTest.php
Normal file
32
tests/Ldap/LdapBadgeTest.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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\Ldap;
|
||||
|
||||
use App\Ldap\LdapBadge;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Ldap\LdapBadge
|
||||
*/
|
||||
class LdapBadgeTest extends TestCase
|
||||
{
|
||||
public function testMarkResolvedSetsResolvedToTrue(): void
|
||||
{
|
||||
$badge = new LdapBadge();
|
||||
$badge->markResolved();
|
||||
self::assertTrue($badge->isResolved());
|
||||
}
|
||||
|
||||
public function testIsResolvedReturnsFalseInitially(): void
|
||||
{
|
||||
$badge = new LdapBadge();
|
||||
self::assertFalse($badge->isResolved());
|
||||
}
|
||||
}
|
||||
@@ -22,16 +22,19 @@ use Symfony\Component\Mime\Email;
|
||||
*/
|
||||
class KimaiMailerTest extends TestCase
|
||||
{
|
||||
public function getSut(): KimaiMailer
|
||||
public function getSut(?MailerInterface $mailer = null): KimaiMailer
|
||||
{
|
||||
$config = new MailConfiguration('zippel@example.com');
|
||||
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
if ($mailer === null) {
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$mailer->expects(self::once())->method('send');
|
||||
}
|
||||
|
||||
return new KimaiMailer($config, $mailer);
|
||||
}
|
||||
|
||||
public function testSendSetsFrom(): void
|
||||
public function testSendSetsFromHeaderFromFallback(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('Testing');
|
||||
@@ -47,4 +50,83 @@ class KimaiMailerTest extends TestCase
|
||||
|
||||
self::assertEquals([new Address('zippel@example.com', 'Kimai')], $message->getFrom());
|
||||
}
|
||||
|
||||
public function testSendToUserSetsFromHeaderFromFallback(): void
|
||||
{
|
||||
$user = new User();
|
||||
$user->setUserIdentifier('Testing');
|
||||
$user->setEmail('foo@example.com');
|
||||
$user->setAlias('Super User');
|
||||
$user->setEnabled(true);
|
||||
|
||||
$mailer = $this->getSut();
|
||||
$message = new Email();
|
||||
|
||||
$mailer->sendToUser($user, $message);
|
||||
|
||||
self::assertEquals([new Address('zippel@example.com', 'Kimai')], $message->getFrom());
|
||||
}
|
||||
|
||||
public function testSendToUserSendsEmailWhenUserIsEnabledAndHasEmail(): void
|
||||
{
|
||||
$user = $this->createMock(User::class);
|
||||
$user->method('isEnabled')->willReturn(true);
|
||||
$user->method('getEmail')->willReturn('foo-bar@example.com');
|
||||
|
||||
$email = new Email();
|
||||
self::assertEquals([], $email->getTo());
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$mailer->expects(self::once())->method('send')->with($email);
|
||||
|
||||
$sut = $this->getSut($mailer);
|
||||
|
||||
$sut->sendToUser($user, $email);
|
||||
self::assertEquals([new Address('zippel@example.com', 'Kimai')], $email->getFrom());
|
||||
self::assertEquals([new Address('foo-bar@example.com')], $email->getTo());
|
||||
}
|
||||
|
||||
public function testSendToUserDoesNotSendEmailWhenUserIsDisabled(): void
|
||||
{
|
||||
$user = $this->createMock(User::class);
|
||||
$user->method('isEnabled')->willReturn(false);
|
||||
$user->method('getEmail')->willReturn('user@example.com');
|
||||
|
||||
$email = new Email();
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$mailer->expects(self::never())->method('send');
|
||||
$sut = $this->getSut($mailer);
|
||||
|
||||
$sut->sendToUser($user, $email);
|
||||
}
|
||||
|
||||
public function testSendToUserDoesNotSendEmailWhenUserHasNoEmail(): void
|
||||
{
|
||||
$user = $this->createMock(User::class);
|
||||
$user->method('isEnabled')->willReturn(true);
|
||||
$user->method('getEmail')->willReturn(null);
|
||||
|
||||
$email = new Email();
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$mailer->expects(self::never())->method('send');
|
||||
$sut = $this->getSut($mailer);
|
||||
|
||||
$sut->sendToUser($user, $email);
|
||||
}
|
||||
|
||||
public function testSThrowsOnEmptyFromAddress(): void
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('Missing email "from" address');
|
||||
|
||||
$user = $this->createMock(User::class);
|
||||
$user->method('isEnabled')->willReturn(true);
|
||||
$user->method('getEmail')->willReturn('test@example.com');
|
||||
|
||||
$email = new Email();
|
||||
$config = new MailConfiguration('');
|
||||
$mailer = $this->createMock(MailerInterface::class);
|
||||
$sut = new KimaiMailer($config, $mailer);
|
||||
|
||||
$sut->sendToUser($user, $email);
|
||||
}
|
||||
}
|
||||
|
||||
38
tests/Plugin/PackageTest.php
Normal file
38
tests/Plugin/PackageTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
|
||||
use App\Plugin\Package;
|
||||
use App\Plugin\PluginMetadata;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Plugin\Package
|
||||
*/
|
||||
class PackageTest extends TestCase
|
||||
{
|
||||
public function testGetPackageFileReturnsCorrectFile(): void
|
||||
{
|
||||
$fileInfo = new \SplFileInfo('path/to/package.zip');
|
||||
$metadata = $this->createMock(PluginMetadata::class);
|
||||
$package = new Package($fileInfo, $metadata);
|
||||
|
||||
self::assertSame($fileInfo, $package->getPackageFile());
|
||||
}
|
||||
|
||||
public function testGetMetadataReturnsCorrectMetadata(): void
|
||||
{
|
||||
$fileInfo = new \SplFileInfo('path/to/package.zip');
|
||||
$metadata = $this->createMock(PluginMetadata::class);
|
||||
$package = new Package($fileInfo, $metadata);
|
||||
|
||||
self::assertSame($metadata, $package->getMetadata());
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,7 @@ class PaginationExtensionTest extends TestCase
|
||||
|
||||
$values = array_fill(0, 151, 'blub');
|
||||
$pagerfanta = new Pagination(new ArrayAdapter($values));
|
||||
$pagerfanta->setMaxPerPage(10);
|
||||
$result = $sut->renderPagination($pagerfanta, [
|
||||
'css_container_class' => 'pagination pagination-sm inline',
|
||||
'routeName' => 'project_activities',
|
||||
@@ -98,6 +99,7 @@ class PaginationExtensionTest extends TestCase
|
||||
|
||||
$values = array_fill(0, 151, 'blub');
|
||||
$pagerfanta = new Pagination(new ArrayAdapter($values));
|
||||
$pagerfanta->setMaxPerPage(10);
|
||||
$result = $sut->renderPagination($pagerfanta, [
|
||||
'css_container_class' => 'pagination pagination-sm inline',
|
||||
'routeName' => 'project_activities',
|
||||
@@ -106,6 +108,26 @@ class PaginationExtensionTest extends TestCase
|
||||
$this->assertPaginationHtml($result);
|
||||
}
|
||||
|
||||
public function testRenderPaginationWithoutPageSize(): void
|
||||
{
|
||||
$sut = $this->getSut();
|
||||
|
||||
$values = array_fill(0, 151, 'blub');
|
||||
$pagerfanta = new Pagination(new ArrayAdapter($values));
|
||||
$result = $sut->renderPagination($pagerfanta, [
|
||||
'css_container_class' => 'pagination pagination-sm inline',
|
||||
'routeName' => 'project_activities',
|
||||
'routeParams' => ['id' => 137]
|
||||
]);
|
||||
|
||||
$expected =
|
||||
'<ul class="pagination pagination-sm inline"><li class="page-item disabled"><span class="page-link pagination-link"><i class="fas fa-chevron-left"></i></span></li>' .
|
||||
'<li class="page-item active"><a class="page-link pagination-link" href="project_activities?id=137&page=1">1</a></li>' .
|
||||
'<li class="page-item disabled"><span class="page-link pagination-link"><i class="fas fa-chevron-right"></i></span></li></ul>';
|
||||
|
||||
self::assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testRenderPaginationWithoutRouteName(): void
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
Reference in New Issue
Block a user