#29: add more tests
This commit is contained in:
parent
c4cd275c83
commit
9afa7fe431
8 changed files with 331 additions and 184 deletions
|
@ -8,6 +8,7 @@ use App\Tests\DbWebTest;
|
|||
use Override;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
use function range;
|
||||
use function sprintf;
|
||||
|
||||
final class FoodOrderControllerTest extends DbWebTest
|
||||
|
@ -51,6 +52,58 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
);
|
||||
}
|
||||
|
||||
public function testPaginatedIndex(): void
|
||||
{
|
||||
$this->generatePaginatedOrders();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list");
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
1,
|
||||
'older orders'
|
||||
);
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
0,
|
||||
'next page'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @testWith [1, 0, 1]
|
||||
* [2, 1, 1]
|
||||
* [3, 1, 1]
|
||||
* [4, 1, 0, 5]
|
||||
*/
|
||||
public function testPaginatedFirstPage(int $page, int $prevPage, int $nextPage, int $items = 10): void
|
||||
{
|
||||
$this->generatePaginatedOrders();
|
||||
$crawler = $this->client->request('GET', "{$this->path}list/archive/{$page}");
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
self::assertPageTitleContains('FoodOrder index');
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'td',
|
||||
$items,
|
||||
'nobody'
|
||||
);
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'a',
|
||||
$nextPage,
|
||||
'next page'
|
||||
);
|
||||
$this->assertElementContainsCount(
|
||||
$crawler,
|
||||
'a',
|
||||
$prevPage,
|
||||
'previous page'
|
||||
);
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
@ -64,4 +117,16 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
self::assertResponseRedirects("{$this->path}list");
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
}
|
||||
|
||||
private function generatePaginatedOrders(): void
|
||||
{
|
||||
foreach (range(1, 35) as $i) {
|
||||
$order = new FoodOrder($this->generateOldUlid());
|
||||
$order->setFoodVendor($this->vendor);
|
||||
$order->close();
|
||||
$this->manager->persist($order);
|
||||
|
||||
}
|
||||
$this->manager->flush();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue