Create timesheet for User #31 (#47)

* added doctrine listener to calculate duration on each update #31
* added constraints to base objects #31
* new form to create timesheet entries #31
* added unit test for TimesheetVoter #31
This commit is contained in:
Kevin Papst
2018-01-07 19:39:43 +01:00
committed by GitHub
parent 67fd7b970a
commit 4e344dbe6e
17 changed files with 246 additions and 71 deletions

View File

@@ -1,72 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: kevin
* Date: 07.01.18
* Time: 11:12
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace KimaiTest\TimesheetBundle\Repository\Query;
use AppBundle\Repository\Query\BaseQuery;
use \PHPUnit\Framework\TestCase;
use TimesheetBundle\Repository\Query\TimesheetQuery;
/**
* @covers \TimesheetBundle\Repository\Query\TimesheetQuery
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetQueryTest extends TestCase
{
public function testBaseQueryHasOverwrittenFields()
public function testSetOrder()
{
$class = new \ReflectionClass(new BaseQuery());
$this->assertTrue($class->hasProperty('order'));
$this->assertTrue($class->hasProperty('orderBy'));
}
public function testGetUser()
{
$this->markTestIncomplete(__METHOD__);
}
$sut = new TimesheetQuery();
public function testSetUser()
{
$this->markTestIncomplete(__METHOD__);
}
$this->assertEquals(TimesheetQuery::ORDER_DESC, $sut->getOrder());
$this->assertEquals('begin', $sut->getOrderBy());
public function testGetActivity()
{
$this->markTestIncomplete(__METHOD__);
}
$sut->setOrder(TimesheetQuery::ORDER_ASC);
$sut->setOrderBy('id');
public function testSetActivity()
{
$this->markTestIncomplete(__METHOD__);
}
public function testGetProject()
{
$this->markTestIncomplete(__METHOD__);
}
public function testSetProject()
{
$this->markTestIncomplete(__METHOD__);
}
public function testGetCustomer()
{
$this->markTestIncomplete(__METHOD__);
}
public function testSetCustomer()
{
$this->markTestIncomplete(__METHOD__);
}
public function testGetState()
{
$this->markTestIncomplete(__METHOD__);
}
public function testSetState()
{
$this->markTestIncomplete(__METHOD__);
$this->assertEquals(TimesheetQuery::ORDER_ASC, $sut->getOrder());
$this->assertEquals('id', $sut->getOrderBy());
}
}

View File

@@ -0,0 +1,73 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace KimaiTest\TimesheetBundle\Voter;
use AppBundle\Entity\User;
use \PHPUnit\Framework\TestCase;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
use TimesheetBundle\Entity\Customer;
use TimesheetBundle\Entity\Timesheet;
use TimesheetBundle\Voter\TimesheetVoter;
/**
* @covers \TimesheetBundle\Voter\TimesheetVoter
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class TimesheetVoterTest extends TestCase
{
/**
* @dataProvider getTestData
*/
public function testCustomerIsDisallowed($user, $allow, $subject, $attributes, $result)
{
$token = new UsernamePasswordToken($user, 'foo', 'bar', $user->getRoles());
$accessManager = $this->getMockBuilder(AccessDecisionManagerInterface::class)->getMock();
$accessManager->method('decide')->willReturn($allow);
$sut = new TimesheetVoter($accessManager);
$this->assertEquals($result, $sut->vote($token, $subject, $attributes));
}
public function getTestData()
{
$user0 = $this->getUser(0, 'ROLE_CUSTOMER');
$user1 = $this->getUser(1, 'ROLE_USER');
$user2 = $this->getUser(1, 'ROLE_TEAMLEAD');
return [
[$user0, false, new Customer(), ['edit'], VoterInterface::ACCESS_ABSTAIN],
[$user1, false, $this->getTimesheet($user1), ['edit'], VoterInterface::ACCESS_GRANTED],
[$user1, false, $this->getTimesheet($user0), ['edit'], VoterInterface::ACCESS_DENIED],
[$user2, true, $this->getTimesheet($user1), ['edit'], VoterInterface::ACCESS_GRANTED],
];
}
protected function getTimesheet($user)
{
$timesheet = new Timesheet();
$timesheet->setUser($user);
return $timesheet;
}
protected function getUser($id, $role)
{
$user = $this->getMockBuilder(User::class)->getMock();
$user->method('getId')->willReturn($id);
$user->method('getRoles')->willReturn([$role]);
return $user;
}
}