This commit is contained in:
parent
cb1ab0ed18
commit
2d3100b5c9
1 changed files with 17 additions and 12 deletions
|
@ -8,10 +8,13 @@ use App\Entity\MenuItem;
|
|||
use App\Entity\OrderItem;
|
||||
use App\Tests\DbWebTest;
|
||||
use Override;
|
||||
use Symfony\Component\BrowserKit\Cookie;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
use function assert;
|
||||
use function range;
|
||||
use function sprintf;
|
||||
use function str_ends_with;
|
||||
|
||||
final class FoodOrderControllerTest extends DbWebTest
|
||||
{
|
||||
|
@ -155,26 +158,26 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
'nobody'
|
||||
);
|
||||
if ($prevPage > 0) {
|
||||
if ($prevPage === 1) {
|
||||
$prevPage = '';
|
||||
} else {
|
||||
$prevPage = "/{$prevPage}";
|
||||
}
|
||||
|
||||
$node = $crawler->filter('a')->reduce(fn(Crawler $node, $i): bool => $node->text() === 'previous page')->first();
|
||||
$prevPage = $prevPage === 1 ? '' : "/{$prevPage}";
|
||||
$node = $crawler->filter('a')
|
||||
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'previous page')
|
||||
->first();
|
||||
$target = $node->attr('href');
|
||||
$this->assertTrue(str_ends_with($target, $prevPage));
|
||||
$this->assertTrue(str_ends_with((string) $target, $prevPage));
|
||||
}
|
||||
if ($prevPage > 3) {
|
||||
$node = $crawler->filter('a')->reduce(fn(Crawler $node, $i): bool => $node->text() === 'next page')->first();
|
||||
$node = $crawler->filter('a')
|
||||
->reduce(static fn(Crawler $node, $i): bool => $node->text() === 'next page')
|
||||
->first();
|
||||
$target = $node->attr('href');
|
||||
$this->assertTrue(str_ends_with($target, "/{$nextPage}"));
|
||||
$this->assertTrue(str_ends_with((string) $target, "/{$nextPage}"));
|
||||
}
|
||||
}
|
||||
|
||||
public function testNew(): void
|
||||
{
|
||||
$this->client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie('username', 'Testing-1'));
|
||||
$this->client->getCookieJar()
|
||||
->set(new Cookie('username', 'Testing-1'));
|
||||
$this->client->request('GET', sprintf('%snew', $this->path));
|
||||
|
||||
self::assertResponseStatusCodeSame(200);
|
||||
|
@ -185,7 +188,9 @@ final class FoodOrderControllerTest extends DbWebTest
|
|||
|
||||
self::assertResponseRedirects("{$this->path}list");
|
||||
self::assertSame(1, $this->repository->count([]));
|
||||
$order = $this->repository->findOneBy(['createdBy' => 'Testing-1']);
|
||||
$order = $this->repository->findOneBy([
|
||||
'createdBy' => 'Testing-1',
|
||||
]);
|
||||
assert($order instanceof FoodOrder);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue