work on tests

This commit is contained in:
2023-12-11 17:32:21 +01:00
parent a97a22d464
commit 2402050f5f
6 changed files with 268 additions and 103 deletions

View File

@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Controller;
use Chill\MainBundle\Entity\NewsItem;
use Chill\MainBundle\Test\PrepareClientTrait;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* Tests the admin pages for news items
*
*/
class NewsItemControllerTest extends WebTestCase
{
use PrepareClientTrait;
protected function tearDown(): void
{
self::ensureKernelShutdown();
}
public function generateNewsItemIds(): iterable
{
self::bootKernel();
$em = self::$container->get(EntityManagerInterface::class);
$qb = $em->createQueryBuilder();
$newsItems = $qb->select('n')->from(NewsItem::class, 'n')
->setMaxResults(2)
->getQuery()
->getResult();
foreach ($newsItems as $n) {
yield [$n->getId()];
}
self::ensureKernelShutdown();
}
public function testList()
{
$client = $this->getClientAuthenticated();
$client->request('GET', "/fr/admin/news_item");
self::assertResponseIsSuccessful('Test that news item admin page shows');
}
/**
* @dataProvider generateNewsItemIds
*/
public function testShowSingleItem(int $newsItemId)
{
$client = $this->getClientAuthenticated();
$client->request('GET', "/fr/amdin/news_item/{$newsItemId}/view");
$this->assertResponseIsSuccessful('test that single news item admin page loads successfully');
}
}