Skip to content

Commit

Permalink
Update code to newer version of phpUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
pdragun committed May 3, 2024
1 parent 6ccd037 commit e2dc2b7
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 48 deletions.
27 changes: 15 additions & 12 deletions tests/Controller/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function testShowBlogPostInEachCategory(): void
$this->assertSelectorTextContains('html h1', 'História turistiky');

$client->request('GET', '/blog/viacdnove-akcie/2011/nizke-tatry');

$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertSelectorTextContains('html h1', 'Nízke Tatry');

$client->request('GET', '/blog/receptury-na-tury/2011/cergovske-susienky');

$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertSelectorTextContains('html h1', 'Čergovské sušienky');
}
Expand All @@ -72,7 +72,8 @@ public function test404(string $url): void
$this->assertTrue($client->getResponse()->isNotFound());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/blo'];
yield ['/bloga'];
Expand Down Expand Up @@ -105,7 +106,8 @@ public function testRequiredLogin(string $url): void
$this->assertSelectorTextContains('html h1', 'Prosím, prihlás sa:');
}

public function provide302Urls(): iterable
/** @return iterable<string[]> */
public static function provide302Urls(): iterable
{
yield ['/blog/2000/pridat-novy/add'];
yield ['/blog/blog-slug/pridat-novy/add'];
Expand All @@ -123,15 +125,16 @@ public function testAdmin404(string $url): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser);
$client->request('GET', $url);

$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provideAdmin404Urls(): iterable
/** @return iterable<string[]> */
public static function provideAdmin404Urls(): iterable
{
yield ['/blog/viacdnove-akcie1/pridat-novy/add'];
yield ['/blog/z-klubovej-kuchyne1/pridat-novy/add'];
Expand All @@ -155,13 +158,13 @@ public function testEditBlog(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

$crawler = $client->request('GET', '/blog/z-klubovej-kuchyne/2011/historia-turistiky');
$this->assertResponseIsSuccessful();

// test existing blog entry
$this->assertSelectorTextContains('html h1', 'História turistiky');
$this->assertSelectorTextContains('html h2', 'Začiatky turistiky v Európe a svete');
Expand All @@ -171,7 +174,7 @@ public function testEditBlog(): void

$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('html h1', 'História turistiky'); // edit page


$buttonCrawlerNode = $crawler->selectButton('Uložiť článok');
$form = $buttonCrawlerNode->form();
Expand Down Expand Up @@ -215,7 +218,7 @@ public function testCreateDeleteBlog(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

Expand Down Expand Up @@ -284,7 +287,7 @@ public function testCreateDeleteBlog(): void

$this->assertEquals(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();

// new blog entry
$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertSelectorTextContains('html h1', 'Grlík');
Expand All @@ -300,7 +303,7 @@ public function testCreateDeleteBlog(): void

$link = $crawler->selectLink('Chcem zmazať')->link(); // click on delete button
$crawler = $client->click($link);

$this->assertEquals(302, $client->getResponse()->getStatusCode());
$client->followRedirect();

Expand Down
3 changes: 2 additions & 1 deletion tests/Controller/ContactControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/kontak'];
yield ['/kontakta'];
Expand Down
33 changes: 18 additions & 15 deletions tests/Controller/EventChronicleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/kronik'];
yield ['/kronikaa'];
Expand Down Expand Up @@ -85,7 +86,8 @@ public function testRequiredLogin(string $url): void
$this->assertSelectorTextContains('html h1', 'Prosím, prihlás sa:');
}

public function provide302Urls(): iterable
/** @return iterable<string[]> */
public static function provide302Urls(): iterable
{
yield ['/kronika/2000/pridat-novu/add'];
yield ['/kronika/2000/pridat-novu/2020-10-25/add'];
Expand All @@ -102,15 +104,16 @@ public function testAdmin404(string $url): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser);
$client->request('GET', $url);

$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provideAdmin404Urls(): array
/** @return iterable<string[]> */
public static function provideAdmin404Urls(): array
{
return [
['/kronika/2011/jaskyne-uhradu/edit'],
Expand All @@ -126,7 +129,7 @@ public function testEdit(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

Expand Down Expand Up @@ -169,7 +172,7 @@ public function testEdit(): void
$values[$formName]['routes'][1]['length'] = 10; // add new Route #2

$crawler = $client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles()); // save


$this->assertEquals('/kronika/2010/Jaskyne-Uhradu1', $client->getResponse()->headers->get('location'));
$this->assertEquals(302, $client->getResponse()->getStatusCode());
Expand All @@ -182,7 +185,7 @@ public function testEdit(): void
$this->assertEquals('Podhradie – Opálená skala – Džimova spása – Podhradie (dĺžka 10 km)', $crawler->filterXPath('//*[@id="routes"]/ul/li[2]')->text());

$link = $crawler->selectLink('Upraviť túto')->link();
$crawler = $client->click($link); // clik on button Edit
$crawler = $client->click($link); // click on button Edit

$this->assertResponseIsSuccessful(); // new page loaded
$this->assertSelectorTextContains('html h1', 'Upraviť túto kroniku');
Expand All @@ -207,7 +210,7 @@ public function testEdit(): void
$values[$formName]['routes'][0]['length'] = 15;
$values[$formName]['routes'][0]['elevation'] = 11;
unset($values[$formName]['routes'][1]); // delete second route (both title and length)

$crawler = $client->request($form->getMethod(), $form->getUri(), $values, $form->getPhpFiles());

$this->assertEquals('/kronika/2010/Jaskyne-Uhradu', $client->getResponse()->headers->get('location'));
Expand All @@ -221,21 +224,21 @@ public function testCreateDelete(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

$crawler = $client->request('GET', '/kronika/2010');


$this->assertResponseIsSuccessful();

$link = $crawler->selectLink('Pridať novú kroniku')->link();
$crawler = $client->click($link);

$this->assertResponseIsSuccessful();
$this->assertSelectorTextContains('html h1', 'Pridanie novej kroniky');

$buttonCrawlerNode = $crawler->selectButton('Vytvor kroniku');

$formStartDate = $buttonCrawlerNode->form();
Expand All @@ -249,7 +252,7 @@ public function testCreateDelete(): void

$this->assertEquals(302, $client->getResponse()->getStatusCode());
$crawler = $client->followRedirect();

$this->assertEquals(200, $client->getResponse()->getStatusCode());
$this->assertSelectorTextContains('html h1', 'Vytvoriť novú kroniku');

Expand All @@ -258,7 +261,7 @@ public function testCreateDelete(): void
$form = $crawler->selectButton('Uložiť kroniku')->form();

$formName = $form->getName();

// $form[$formName . '[sportType][0]']->tick();
// $form[$formName . '[sportType][3]']->tick();

Expand Down Expand Up @@ -293,7 +296,7 @@ public function testCreateDelete(): void

$link = $crawler->selectLink('Chcem zmazať')->link();
$crawler = $client->click($link);

$this->assertEquals(302, $client->getResponse()->getStatusCode());
$client->followRedirect();

Expand Down
19 changes: 11 additions & 8 deletions tests/Controller/EventInvitationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/pozvank'];
yield ['/pozvankya'];
Expand Down Expand Up @@ -61,7 +62,7 @@ public function testShowListInvitationPostInYear(): void
}

/** Test existing invitation */
public function testShowInvitation()
public function testShowInvitation(): void
{
$client = static::createClient();
$crawler = $client->request('GET', '/pozvanky/2011/gulasove-opojenie-v-tesaroch');
Expand All @@ -75,7 +76,7 @@ public function testShowInvitation()
}

/** Test upcoming invitations */
public function testShowLatestInvitation()
public function testShowLatestInvitation(): void
{
$client = static::createClient();
$crawler = $client->request('GET', '/pozvanky/aktualne');
Expand Down Expand Up @@ -116,7 +117,8 @@ public function testRequiredLogin(string $url): void
$this->assertSelectorTextContains('html h1', 'Prosím, prihlás sa:');
}

public function provide302Urls(): iterable
/** @return iterable<string[]> */
public static function provide302Urls(): iterable
{
yield ['/pozvanky/2000/pridat-novu/add'];
yield ['/pozvanky/2000/pridat-novu/2020-10-25/add'];
Expand All @@ -133,15 +135,16 @@ public function testAdmin404(string $url): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

$client->request('GET', $url);
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provideAdmin404Urls(): iterable
/** @return iterable<string[]> */
public static function provideAdmin404Urls(): iterable
{
yield ['/pozvanky/2010/gulasove-opojenie-v-tesaroch/edit'];
yield ['/pozvanky/2011/gulasove-opojenie-v-tesaroch1/edit'];
Expand All @@ -155,7 +158,7 @@ public function testEdit(): void
{
$client = static::createClient();
$userRepository = static::getContainer()->get(UserRepository::class);

$testUser = $userRepository->findOneByEmail('[email protected]');
$client->loginUser($testUser); // login admin

Expand Down Expand Up @@ -195,7 +198,7 @@ public function testEdit(): void
$this->assertEquals(10, $values[$formName]['routes'][0]['elevation']);
$this->assertEquals('Podhradie – Opálená skala – Džimova spása – Úhrad – Podhradie', $values[$formName]['routes'][1]['title']);
$this->assertEquals(15, $values[$formName]['routes'][1]['length']);

// edit values
$values[$formName]['title'] = 'Gulášové opojenie v Tesároch1';
$values[$formName]['summary'] = 'Turisticko-športový deň 10. 9. v Tesároch';
Expand Down
19 changes: 9 additions & 10 deletions tests/Controller/EventPlanControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testShowListInvitationPostInYear(): void
$this->assertEquals('23. 1.', $crawler->filterXPath('//*[@id="event-plan"]/tr[4]/td[1]')->text());
$this->assertEquals('Výjazd za snehom', $crawler->filterXPath('//*[@id="event-plan"]/tr[4]/td[2]')->text());
$this->assertEquals('Z, V', $crawler->filterXPath('//*[@id="event-plan"]/tr[4]/td[3]')->text());

}

/** @dataProvider provide404Urls */
Expand All @@ -49,15 +49,14 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): array
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
return [
['/pla'],
['/plana'],
['/plan/2000'],
['/plan/3000'],
['/plan/asdf'],
['/plan/asdf/asdf'],
];
yield ['/pla'];
yield ['/plana'];
yield ['/plan/2000'];
yield ['/plan/3000'];
yield ['/plan/asdf'];
yield ['/plan/asdf/asdf'];
}
}
3 changes: 2 additions & 1 deletion tests/Controller/GpxControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/gpp'];
yield ['/gpxx'];
Expand Down
3 changes: 2 additions & 1 deletion tests/Controller/SecurityControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function test404(string $url): void
$this->assertEquals(404, $client->getResponse()->getStatusCode());
}

public function provide404Urls(): iterable
/** @return iterable<string[]> */
public static function provide404Urls(): iterable
{
yield ['/logi'];
yield ['/logina'];
Expand Down
23 changes: 23 additions & 0 deletions tests/Feature/ContactControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
uses(WebTestCase::class);

test('contact page', function () {

$response = $this->get('GET', '/kontakt');

expect($response->getStatusCode())->toEqual(200);
$this->assertSelectorTextContains('html h1', 'Kontakt');
});

test('404', function (string $url) {
$response = $this->get('GET', $url);

expect($response->getStatusCode())->toEqual(404);
})->with([
'/kontak',
'/kontakta',
]);

0 comments on commit e2dc2b7

Please sign in to comment.