added tags for timesheets (#604)
This commit is contained in:
51
tests/Entity/TagTest.php
Normal file
51
tests/Entity/TagTest.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\Entity;
|
||||
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Tag
|
||||
*/
|
||||
class TagTest extends AbstractEntityTest
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Tag();
|
||||
$this->assertNull($sut->getId());
|
||||
$this->assertNull($sut->getName());
|
||||
}
|
||||
|
||||
public function testSetterAndGetter()
|
||||
{
|
||||
$sut = new Tag();
|
||||
|
||||
$this->assertInstanceOf(Tag::class, $sut->setName('foo'));
|
||||
$this->assertEquals('foo', $sut->getName());
|
||||
$this->assertEquals('foo', (string) $sut);
|
||||
}
|
||||
|
||||
public function testWithTimesheet()
|
||||
{
|
||||
$sut = new Tag();
|
||||
$timesheet = new Timesheet();
|
||||
|
||||
$this->assertEmpty($timesheet->getTags());
|
||||
|
||||
$sut->setName('bar');
|
||||
$sut->addTimesheet($timesheet);
|
||||
|
||||
$this->assertSame($sut, $timesheet->getTags()[0]);
|
||||
|
||||
$sut->removeTimesheet($timesheet);
|
||||
$this->assertEmpty($timesheet->getTags());
|
||||
}
|
||||
}
|
||||
@@ -12,8 +12,10 @@ namespace App\Tests\Entity;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
* @covers \App\Entity\Timesheet
|
||||
@@ -34,6 +36,8 @@ class TimesheetTest extends AbstractEntityTest
|
||||
$this->assertSame(0.00, $sut->getRate());
|
||||
$this->assertNull($sut->getFixedRate());
|
||||
$this->assertNull($sut->getHourlyRate());
|
||||
$this->assertEquals(new ArrayCollection(), $sut->getTags());
|
||||
$this->assertEquals([], $sut->getTagsAsArray());
|
||||
|
||||
$this->assertInstanceOf(Timesheet::class, $sut->setFixedRate(13.47));
|
||||
$this->assertEquals(13.47, $sut->getFixedRate());
|
||||
@@ -251,4 +255,27 @@ class TimesheetTest extends AbstractEntityTest
|
||||
|
||||
$this->assertHasViolationForField($entity, []);
|
||||
}
|
||||
|
||||
public function testTags()
|
||||
{
|
||||
$sut = new Timesheet();
|
||||
$tag = new Tag();
|
||||
$tag->setName('bar');
|
||||
$tag1 = new Tag();
|
||||
$tag1->setName('foo');
|
||||
|
||||
$this->assertEmpty($sut->getTags());
|
||||
|
||||
$sut->addTag($tag);
|
||||
$sut->addTag($tag1);
|
||||
|
||||
$this->assertEquals([0 => 'bar', 1 => 'foo'], $sut->getTagsAsArray());
|
||||
$this->assertEquals(new ArrayCollection([$tag, $tag1]), $sut->getTags());
|
||||
|
||||
$sut->removeTag($tag);
|
||||
$this->assertEquals([1 => 'foo'], $sut->getTagsAsArray());
|
||||
|
||||
$sut->removeTag($tag1);
|
||||
$this->assertEmpty($sut->getTags());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user