added event for recent activities (#2254)

This commit is contained in:
Kevin Papst
2021-01-11 19:13:14 +01:00
committed by GitHub
parent 1de6b5d385
commit cb6924e6d6
7 changed files with 180 additions and 17 deletions

View File

@@ -26,19 +26,41 @@ class CalendarDragAndDropSourceEventTest extends TestCase
$sut = new CalendarDragAndDropSourceEvent($user);
$hello = new TestDragAndDropSource('hello');
$tmp1 = new TestDragAndDropSource('foo');
$tmp2 = new TestDragAndDropSource('bar');
$tmp3 = new TestDragAndDropSource('hello');
self::assertSame($user, $sut->getUser());
self::assertIsArray($sut->getSources());
self::assertEmpty($sut->getSources());
self::assertInstanceOf(CalendarDragAndDropSourceEvent::class, $sut->addSource(new TestDragAndDropSource()));
self::assertCount(1, $sut->getSources());
self::assertInstanceOf(CalendarDragAndDropSourceEvent::class, $sut->addSource($tmp1));
self::assertInstanceOf(CalendarDragAndDropSourceEvent::class, $sut->addSource($tmp2));
self::assertInstanceOf(CalendarDragAndDropSourceEvent::class, $sut->addSource($hello));
self::assertInstanceOf(CalendarDragAndDropSourceEvent::class, $sut->addSource($tmp3));
self::assertCount(4, $sut->getSources());
self::assertEquals([$tmp1, $tmp2, $hello, $tmp3], $sut->getSources());
self::assertFalse($sut->removeSource(new TestDragAndDropSource('foo')));
self::assertTrue($sut->removeSource($hello));
self::assertFalse($sut->removeSource(new TestDragAndDropSource('world')));
self::assertCount(3, $sut->getSources());
self::assertEquals([$tmp1, $tmp2, $tmp3], $sut->getSources());
}
}
class TestDragAndDropSource implements DragAndDropSource
{
private $title;
public function __construct(string $title)
{
$this->title = $title;
}
public function getTitle(): string
{
return '';
return $this->title;
}
public function getRoute(): string

View 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\Event;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Event\RecentActivityEvent;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Event\RecentActivityEvent
*/
class RecentActivityEventTest extends TestCase
{
public function testGetterAndSetter()
{
$user = new User();
$user->setAlias('foo');
$tmp1 = new Timesheet();
$tmp2 = new Timesheet();
$tmp3 = new Timesheet();
$tmp4 = new Timesheet();
$tmp5 = new Timesheet();
$tmp6 = new Timesheet();
$tmp7 = new Timesheet();
$timesheets = [
$tmp1,
$tmp2,
$tmp3,
$tmp4,
$tmp5,
];
$sut = new RecentActivityEvent($user, $timesheets);
self::assertCount(5, $sut->getRecentActivities());
self::assertEquals($user, $sut->getUser());
self::assertEquals([$tmp1, $tmp2, $tmp3, $tmp4, $tmp5], $sut->getRecentActivities());
self::assertFalse($sut->removeRecentActivity($tmp6));
self::assertTrue($sut->removeRecentActivity($tmp3));
self::assertInstanceOf(RecentActivityEvent::class, $sut->addRecentActivity($tmp6));
self::assertFalse($sut->removeRecentActivity($tmp7));
self::assertEquals([$tmp1, $tmp2, $tmp4, $tmp5, $tmp6], $sut->getRecentActivities());
}
}