added table-column ordering (#1086)

This commit is contained in:
Kevin Papst
2019-09-09 23:47:42 +02:00
committed by GitHub
parent d041a3f4f9
commit a651e55dc9
82 changed files with 932 additions and 516 deletions

View File

@@ -47,5 +47,7 @@ class ActivityQueryTest extends BaseQueryTest
$sut->setCustomer(99);
$this->assertEquals(99, $sut->getCustomer());
$this->assertResetByFormError(new ActivityQuery(), 'name');
}
}

View File

@@ -13,6 +13,11 @@ use App\Entity\Team;
use App\Repository\Query\BaseQuery;
use App\Utils\SearchTerm;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormFactoryInterface;
/**
* @covers \App\Repository\Query\BaseQuery
@@ -22,6 +27,24 @@ class BaseQueryTest extends TestCase
public function testQuery()
{
$this->assertBaseQuery(new BaseQuery());
$this->assertResetByFormError(new BaseQuery());
}
protected function assertResetByFormError(BaseQuery $sut, $orderBy = 'id', $order = 'ASC')
{
$sut->setOrder('ASK');
$sut->setOrderBy('foo');
$sut->setPage(99);
$sut->setPageSize(99);
$sut->setSearchTerm(new SearchTerm('sdf'));
$this->resetByFormError($sut, ['order', 'orderBy', 'page', 'pageSize', 'searchTerm']);
self::assertEquals(1, $sut->getPage());
self::assertEquals(50, $sut->getPageSize());
self::assertEquals($order, $sut->getOrder());
self::assertEquals($orderBy, $sut->getOrderBy());
self::assertNull($sut->getSearchTerm());
}
protected function assertBaseQuery(BaseQuery $sut, $orderBy = 'id')
@@ -34,6 +57,34 @@ class BaseQueryTest extends TestCase
$this->assertTeams($sut);
}
private function getFormBuilder(string $name)
{
return new FormBuilder($name, null, new EventDispatcher(), $this->getMockBuilder(FormFactoryInterface::class)->getMock(), []);
}
protected function resetByFormError(BaseQuery $sut, array $invalidFields)
{
$formBuilder = $this->getFormBuilder('form');
$formBuilder->setCompound(true);
$formBuilder->setDataMapper($this->getMockBuilder(DataMapperInterface::class)->getMock());
$form = $formBuilder->getForm();
foreach ($invalidFields as $fieldName) {
$form->add($this->getFormBuilder($fieldName)->getForm());
}
$form->submit([]);
foreach ($invalidFields as $fieldName) {
$form->get($fieldName)->addError(new FormError('Failed'));
}
$formErrors = $form->getErrors(true);
$sut->resetByFormError($formErrors);
}
protected function assertResultType(BaseQuery $sut)
{
self::assertEquals(BaseQuery::RESULT_TYPE_PAGER, $sut->getResultType());

View File

@@ -23,5 +23,7 @@ class CustomerQueryTest extends BaseQueryTest
$this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(VisibilityQuery::class, $sut);
$this->assertResetByFormError(new CustomerQuery(), 'name');
}
}

View File

@@ -36,5 +36,7 @@ class ProjectQueryTest extends BaseQueryTest
// make sure int is allowed as well
$sut->setCustomer(99);
$this->assertEquals(99, $sut->getCustomer());
$this->assertResetByFormError(new ProjectQuery(), 'name');
}
}

View File

@@ -0,0 +1,28 @@
<?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\Query;
use App\Repository\Query\TagQuery;
/**
* @covers \App\Repository\Query\TagQuery
*/
class TagQueryTest extends BaseQueryTest
{
public function testQuery()
{
$sut = new TagQuery();
$this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(TagQuery::class, $sut);
$this->assertResetByFormError(new TagQuery(), 'name');
}
}

View File

@@ -0,0 +1,28 @@
<?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\Query;
use App\Repository\Query\TeamQuery;
/**
* @covers \App\Repository\Query\TeamQuery
*/
class TeamQueryTest extends BaseQueryTest
{
public function testQuery()
{
$sut = new TeamQuery();
$this->assertBaseQuery($sut, 'name');
$this->assertInstanceOf(TeamQuery::class, $sut);
$this->assertResetByFormError(new TeamQuery(), 'name');
}
}

View File

@@ -39,6 +39,8 @@ class TimesheetQueryTest extends BaseQueryTest
$this->assertState($sut);
$this->assertExported($sut);
$this->assertSearchTerm($sut);
$this->assertResetByFormError(new TimesheetQuery(), 'begin', 'DESC');
}
protected function assertUser(TimesheetQuery $sut)

View File

@@ -20,9 +20,11 @@ class UserQueryTest extends BaseQueryTest
public function testQuery()
{
$sut = new UserQuery();
$this->assertBaseQuery($sut);
$this->assertBaseQuery($sut, 'username');
$this->assertInstanceOf(VisibilityQuery::class, $sut);
$this->assertRole($sut);
$this->assertResetByFormError(new UserQuery(), 'username');
}
protected function assertRole(UserQuery $sut)