Configure test fixtures and implement conference page functional test
This commit is contained in:
9
Makefile
Normal file
9
Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
SHELL := /bin/bash
|
||||
|
||||
tests:
|
||||
symfony console doctrine:database:drop --force --env=test || true
|
||||
symfony console doctrine:database:create --env=test
|
||||
symfony console doctrine:migrations:migrate -n --env=test
|
||||
symfony console doctrine:fixtures:load -n --env=test
|
||||
symfony php bin/phpunit $(MAKECMDGOALS)
|
||||
.PHONY: tests
|
||||
@@ -2,15 +2,46 @@
|
||||
|
||||
namespace App\DataFixtures;
|
||||
|
||||
use App\Entity\Admin;
|
||||
use App\Entity\Comment;
|
||||
use App\Entity\Conference;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
|
||||
|
||||
class AppFixtures extends Fixture
|
||||
{
|
||||
public function __construct(
|
||||
private PasswordHasherFactoryInterface $passwordHasherFactory,
|
||||
) {
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager): void
|
||||
{
|
||||
// $product = new Product();
|
||||
// $manager->persist($product);
|
||||
$amsterdam = new Conference();
|
||||
$amsterdam->setCity('Amsterdam');
|
||||
$amsterdam->setYear('2019');
|
||||
$amsterdam->setIsInternational(true);
|
||||
$manager->persist($amsterdam);
|
||||
|
||||
$slc = new Conference();
|
||||
$slc->setCity('Salt Lake City');
|
||||
$slc->setYear('2021');
|
||||
$slc->setIsInternational(false);
|
||||
$manager->persist($slc);
|
||||
|
||||
$comment1 = new Comment();
|
||||
$comment1->setConference($amsterdam);
|
||||
$comment1->setAuthor('Jake');
|
||||
$comment1->setEmail('jake@example.com');
|
||||
$comment1->setText('This was a great conference.');
|
||||
$manager->persist($comment1);
|
||||
|
||||
$admin = new Admin();
|
||||
$admin->setRoles(['ROLE_ADMIN']);
|
||||
$admin->setUsername('admin');
|
||||
$admin->setPassword($this->passwordHasherFactory->getPasswordHasher(Admin::class)->hash('admin'));
|
||||
$manager->persist($admin);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
@@ -14,4 +14,34 @@ class ConferenceControllerTest extends WebTestCase
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorTextContains('h2', 'Give your feedback');
|
||||
}
|
||||
|
||||
public function testConferencePage()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$crawler = $client->request('GET', '/');
|
||||
|
||||
$this->assertCount(2, $crawler->filter('h4'));
|
||||
|
||||
$client->clickLink('View');
|
||||
|
||||
$this->assertPageTitleContains('Amsterdam');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorTextContains('h2', 'Amsterdam 2019');
|
||||
$this->assertSelectorExists('div:contains("There are 1 comments")');
|
||||
}
|
||||
|
||||
public function testCommentSubmission()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('GET', 'conference/amsterdam-2019');
|
||||
$client->submitForm('Submit', [
|
||||
'comment[author]' => 'Bob',
|
||||
'comment[text]' => 'Some feedback from an automated functional test',
|
||||
'comment[email]' => 'test@example.com',
|
||||
'comment[photo]' => dirname(__DIR__, 2) . '/public/images/under-construction.gif',
|
||||
]);
|
||||
$this->assertResponseRedirects();
|
||||
$client->followRedirect();
|
||||
$this->assertSelectorExists('div:contains("There are 2 comments")');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user