* added toolbar to user screen # 56 * added filter for user role in user admin toolbar # 56 * added unit tests for queries # 56
This commit is contained in:
99
tests/AppBundle/Repository/Query/BaseQueryTest.php
Normal file
99
tests/AppBundle/Repository/Query/BaseQueryTest.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?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\AppBundle\Repository\Query;
|
||||
|
||||
use AppBundle\Entity\User;
|
||||
use AppBundle\Repository\Query\BaseQuery;
|
||||
use \PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \AppBundle\Repository\Query\BaseQuery
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class BaseQueryTest extends TestCase
|
||||
{
|
||||
|
||||
public function testQuery()
|
||||
{
|
||||
$this->assertBaseQuery(new BaseQuery());
|
||||
}
|
||||
|
||||
protected function assertBaseQuery(BaseQuery $sut)
|
||||
{
|
||||
$this->assertResultType($sut);
|
||||
$this->assertHiddenEntity($sut);
|
||||
$this->assertPage($sut);
|
||||
$this->assertPageSize($sut);
|
||||
$this->assertOrderBy($sut);
|
||||
$this->assertOrder($sut);
|
||||
}
|
||||
|
||||
protected function assertResultType(BaseQuery $sut)
|
||||
{
|
||||
$this->assertEquals(BaseQuery::RESULT_TYPE_PAGER, $sut->getResultType());
|
||||
|
||||
$sut->setResultType('foo-bar');
|
||||
$this->assertEquals(BaseQuery::RESULT_TYPE_PAGER, $sut->getResultType());
|
||||
|
||||
$sut->setResultType(BaseQuery::RESULT_TYPE_QUERYBUILDER);
|
||||
$this->assertEquals(BaseQuery::RESULT_TYPE_QUERYBUILDER, $sut->getResultType());
|
||||
}
|
||||
|
||||
protected function assertHiddenEntity(BaseQuery $sut)
|
||||
{
|
||||
$this->assertNull($sut->getHiddenEntity());
|
||||
|
||||
$actual = new User();
|
||||
$actual->setUsername('foo-bar');
|
||||
|
||||
$sut->setHiddenEntity($actual);
|
||||
$this->assertEquals($actual, $sut->getHiddenEntity());
|
||||
}
|
||||
|
||||
protected function assertPage(BaseQuery $sut)
|
||||
{
|
||||
$this->assertEquals(BaseQuery::DEFAULT_PAGE, $sut->getPage());
|
||||
|
||||
$sut->setPage(42);
|
||||
$this->assertEquals(42, $sut->getPage());
|
||||
}
|
||||
|
||||
protected function assertPageSize(BaseQuery $sut)
|
||||
{
|
||||
$this->assertEquals(BaseQuery::DEFAULT_PAGESIZE, $sut->getPageSize());
|
||||
|
||||
$sut->setPageSize(100);
|
||||
$this->assertEquals(100, $sut->getPageSize());
|
||||
}
|
||||
|
||||
protected function assertOrderBy(BaseQuery $sut, $column = 'id')
|
||||
{
|
||||
$this->assertEquals($column, $sut->getOrderBy());
|
||||
|
||||
$sut->setOrderBy('foo');
|
||||
$this->assertEquals('foo', $sut->getOrderBy());
|
||||
}
|
||||
|
||||
protected function assertOrder(BaseQuery $sut, $order = BaseQuery::ORDER_ASC)
|
||||
{
|
||||
$this->assertEquals($order, $sut->getOrder());
|
||||
|
||||
$sut->setOrder('foo');
|
||||
$this->assertEquals($order, $sut->getOrder());
|
||||
|
||||
$sut->setOrder(BaseQuery::ORDER_ASC);
|
||||
$this->assertEquals(BaseQuery::ORDER_ASC, $sut->getOrder());
|
||||
|
||||
$sut->setOrder(BaseQuery::ORDER_DESC);
|
||||
$this->assertEquals(BaseQuery::ORDER_DESC, $sut->getOrder());
|
||||
}
|
||||
}
|
||||
43
tests/AppBundle/Repository/Query/UserQueryTest.php
Normal file
43
tests/AppBundle/Repository/Query/UserQueryTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\AppBundle\Repository\Query;
|
||||
|
||||
use AppBundle\Repository\Query\UserQuery;
|
||||
use AppBundle\Repository\Query\VisibilityInterface;
|
||||
use AppBundle\Repository\Query\VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @covers \AppBundle\Repository\Query\UserQuery
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class UserQueryTest extends BaseQueryTest
|
||||
{
|
||||
public function testQuery()
|
||||
{
|
||||
$sut = new UserQuery();
|
||||
$this->assertBaseQuery($sut);
|
||||
$this->assertInstanceOf(VisibilityInterface::class, $sut);
|
||||
$this->assertArrayHasKey(VisibilityTrait::class, class_uses($sut));
|
||||
$this->assertRole($sut);
|
||||
}
|
||||
|
||||
protected function assertRole(UserQuery $sut)
|
||||
{
|
||||
$this->assertNull($sut->getRole());
|
||||
|
||||
$sut->setRole('foo-bar');
|
||||
$this->assertNull($sut->getRole());
|
||||
|
||||
$sut->setRole('ROLE_USER');
|
||||
$this->assertEquals('ROLE_USER', $sut->getRole());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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\AppBundle\Repository\Query;
|
||||
|
||||
use AppBundle\Repository\Query\VisibilityInterface;
|
||||
use AppBundle\Repository\Query\VisibilityTrait;
|
||||
|
||||
/**
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class VisibilityTraitImplementation implements VisibilityInterface
|
||||
{
|
||||
use VisibilityTrait;
|
||||
}
|
||||
46
tests/AppBundle/Repository/Query/VisibilityTraitTest.php
Normal file
46
tests/AppBundle/Repository/Query/VisibilityTraitTest.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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\AppBundle\Repository\Query;
|
||||
|
||||
use AppBundle\Repository\Query\VisibilityInterface;
|
||||
use AppBundle\Repository\Query\VisibilityTrait;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \AppBundle\Repository\Query\VisibilityTrait
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class VisibilityTraitTest extends TestCase
|
||||
{
|
||||
public function testVisibilityTrait()
|
||||
{
|
||||
$sut = new VisibilityTraitImplementation();
|
||||
|
||||
$this->assertFalse($sut->isExclusiveVisibility());
|
||||
$this->assertEquals(VisibilityTraitImplementation::SHOW_VISIBLE, $sut->getVisibility());
|
||||
|
||||
$sut->setExclusiveVisibility(true);
|
||||
$this->assertTrue($sut->isExclusiveVisibility());
|
||||
|
||||
$sut->setVisibility('foo-bar');
|
||||
$this->assertEquals(VisibilityTraitImplementation::SHOW_VISIBLE, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityTraitImplementation::SHOW_BOTH);
|
||||
$this->assertEquals(VisibilityTraitImplementation::SHOW_BOTH, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityTraitImplementation::SHOW_HIDDEN);
|
||||
$this->assertEquals(VisibilityTraitImplementation::SHOW_HIDDEN, $sut->getVisibility());
|
||||
|
||||
$sut->setVisibility(VisibilityTraitImplementation::SHOW_VISIBLE);
|
||||
$this->assertEquals(VisibilityTraitImplementation::SHOW_VISIBLE, $sut->getVisibility());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user