* 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:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
73
tests/TimesheetBundle/Voter/TimesheetVoterTest.php
Normal file
73
tests/TimesheetBundle/Voter/TimesheetVoterTest.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user