added tags for timesheets (#604)
This commit is contained in:
85
tests/Repository/TagRepositoryTest.php
Normal file
85
tests/Repository/TagRepositoryTest.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?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\Repository;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Tests\DataFixtures\TagFixtures;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\TagRepository
|
||||
*/
|
||||
class TagRepositoryTest extends AbstractRepositoryTest
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$em = $this->getEntityManager();
|
||||
$data = new TagFixtures();
|
||||
$data->setTagArray(['Test', 'Travel', '#2018-001', '#2018-002', '#2018-003', '#2018-004', '#2018-005', 'Administration', 'Support', 'PR', '#2018-012']);
|
||||
$this->importFixture($em, $data);
|
||||
}
|
||||
|
||||
public function testFindIds()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$repository = $em->getRepository(Tag::class);
|
||||
|
||||
$result = $repository->findIdsByTagNameList('2018,Test');
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(7, count($result));
|
||||
$this->assertEquals(1, $result[0]);
|
||||
$this->assertEquals(3, $result[1]);
|
||||
$this->assertEquals(4, $result[2]);
|
||||
$this->assertEquals(5, $result[3]);
|
||||
$this->assertEquals(6, $result[4]);
|
||||
$this->assertEquals(7, $result[5]);
|
||||
$this->assertEquals(11, $result[6]);
|
||||
}
|
||||
|
||||
public function testFindNoIds()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$repository = $em->getRepository(Tag::class);
|
||||
|
||||
$result = $repository->findIdsByTagNameList('Simply');
|
||||
$this->assertIsArray($result);
|
||||
$this->assertEmpty($result);
|
||||
$this->assertEquals(0, count($result));
|
||||
}
|
||||
|
||||
public function testFindAllTagNames()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$repository = $em->getRepository(Tag::class);
|
||||
|
||||
$result = $repository->findAllTagNames('2018');
|
||||
$this->assertIsArray($result);
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals(6, count($result));
|
||||
$this->assertEquals('#2018-001', $result[0]);
|
||||
$this->assertEquals('#2018-002', $result[1]);
|
||||
$this->assertEquals('#2018-003', $result[2]);
|
||||
$this->assertEquals('#2018-004', $result[3]);
|
||||
$this->assertEquals('#2018-005', $result[4]);
|
||||
$this->assertEquals('#2018-012', $result[5]);
|
||||
}
|
||||
|
||||
public function testFindNoTagNames()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$repository = $em->getRepository(Tag::class);
|
||||
|
||||
$result = $repository->findAllTagNames('Nothing');
|
||||
$this->assertIsArray($result);
|
||||
$this->assertEmpty($result);
|
||||
$this->assertEquals(0, count($result));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace App\Tests\Repository;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
@@ -119,4 +120,39 @@ class TimesheetRepositoryTest extends AbstractRepositoryTest
|
||||
$repository->save($timesheet);
|
||||
$this->assertEquals(1, $timesheet->getId());
|
||||
}
|
||||
|
||||
public function testSaveWithTags()
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
$activityRepository = $em->getRepository(Activity::class);
|
||||
$activity = $activityRepository->find(1);
|
||||
$projectRepository = $em->getRepository(Project::class);
|
||||
$project = $projectRepository->find(1);
|
||||
|
||||
$user = $this->getUserByRole($em, User::ROLE_USER);
|
||||
$repository = $em->getRepository(Timesheet::class);
|
||||
$tagOne = new Tag();
|
||||
$tagOne->setName('Travel');
|
||||
$tagTwo = new Tag();
|
||||
$tagTwo->setName('Picture');
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
->setDescription('foo')
|
||||
->setUser($user)
|
||||
->setActivity($activity)
|
||||
->setProject($project)
|
||||
->addTag($tagOne)
|
||||
->addTag($tagTwo);
|
||||
|
||||
$this->assertNull($timesheet->getId());
|
||||
$repository->save($timesheet);
|
||||
$this->assertEquals(1, $timesheet->getId());
|
||||
$this->assertEquals(2, $timesheet->getTags()->count());
|
||||
$this->assertEquals('Travel', $timesheet->getTags()->get(0)->getName());
|
||||
$this->assertEquals(1, $timesheet->getTags()->get(0)->getId());
|
||||
$this->assertEquals('Picture', $timesheet->getTags()->get(1)->getName());
|
||||
$this->assertEquals(2, $timesheet->getTags()->get(1)->getId());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user