mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-03 14:37:44 +00:00
correct newsItemControllerTest
This commit is contained in:
parent
8f2409fc06
commit
85b91250fb
@ -27,45 +27,78 @@ class NewsItemControllerTest extends WebTestCase
|
|||||||
{
|
{
|
||||||
use PrepareClientTrait;
|
use PrepareClientTrait;
|
||||||
|
|
||||||
protected function tearDown(): void
|
private static array $entitiesToDelete = [];
|
||||||
|
|
||||||
|
private EntityManagerInterface $em;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
self::ensureKernelShutdown();
|
self::bootKernel();
|
||||||
|
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generateNewsItemIds(): iterable
|
public static function tearDownAfterClass(): void
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
$em = self::$container->get(EntityManagerInterface::class);
|
$em = self::$container->get(EntityManagerInterface::class);
|
||||||
|
|
||||||
$qb = $em->createQueryBuilder();
|
foreach (self::$entitiesToDelete as [$class, $id]) {
|
||||||
|
$entity = $em->find($class, $id);
|
||||||
|
|
||||||
|
if (null !== $entity) {
|
||||||
|
$em->remove($entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateNewsItemIds(): iterable
|
||||||
|
{
|
||||||
|
/* $qb = $em->createQueryBuilder();
|
||||||
$newsItems = $qb->select('n')->from(NewsItem::class, 'n')
|
$newsItems = $qb->select('n')->from(NewsItem::class, 'n')
|
||||||
->setMaxResults(2)
|
->setMaxResults(2)
|
||||||
->getQuery()
|
->getQuery()
|
||||||
->getResult();
|
->getResult();*/
|
||||||
|
|
||||||
foreach ($newsItems as $n) {
|
$this->setUp();
|
||||||
yield [$n->getId()];
|
|
||||||
}
|
|
||||||
|
|
||||||
self::ensureKernelShutdown();
|
$newsItem = new NewsItem();
|
||||||
|
$newsItem->setTitle('Lorem Ipsum');
|
||||||
|
$newsItem->setContent('some text');
|
||||||
|
$newsItem->setStartDate(new \DateTimeImmutable('now'));
|
||||||
|
|
||||||
|
$this->em->persist($newsItem);
|
||||||
|
|
||||||
|
self::$entitiesToDelete[] = [NewsItem::class, $newsItem];
|
||||||
|
|
||||||
|
yield [$newsItem];
|
||||||
|
|
||||||
|
$this->em->flush();
|
||||||
|
$this->em->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testList()
|
public function testList()
|
||||||
{
|
{
|
||||||
$client = $this->getClientAuthenticated();
|
$client = $this->getClientAuthenticated('admin', 'password');
|
||||||
$client->request('GET', '/fr/admin/news_item');
|
$client->request('GET', '/fr/admin/news_item');
|
||||||
|
|
||||||
self::assertResponseIsSuccessful('Test that news item admin page shows');
|
self::assertResponseIsSuccessful('News item admin page shows');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider generateNewsItemIds
|
* @dataProvider generateNewsItemIds
|
||||||
|
*
|
||||||
|
* test gets skipped... why?
|
||||||
*/
|
*/
|
||||||
public function testShowSingleItem(int $newsItemId)
|
public function testShowSingleItem(NewsItem $newsItem)
|
||||||
{
|
{
|
||||||
$client = $this->getClientAuthenticated();
|
$client = $this->getClientAuthenticated('admin', 'password');
|
||||||
$client->request('GET', "/fr/amdin/news_item/{$newsItemId}/view");
|
$client->request('GET', "/fr/admin/news_item/{$newsItem->getId()}/view");
|
||||||
|
|
||||||
$this->assertResponseIsSuccessful('test that single news item admin page loads successfully');
|
self::assertResponseIsSuccessful('Single news item admin page loads successfully');
|
||||||
|
|
||||||
|
self::$entitiesToDelete[] = [NewsItem::class, $newsItem];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user