-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09921b3
commit 74a1c1e
Showing
7 changed files
with
1,785 additions
and
749 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{% extends 'layout.html.twig' %} | ||
|
||
{% block body %} | ||
<h1>{{ title }}</h1> | ||
|
||
<label for="exampleCheckbox">Example Checkbox</label> | ||
<input type="checkbox" id="exampleCheckbox" name="exampleCheckbox" {% if checked %}checked{% endif %}> | ||
|
||
<label for="exampleInput">Example Input</label> | ||
<input type="text" id="exampleInput" name="exampleInput" value="{{ inputValue }}"> | ||
|
||
<p class="info">This is a test paragraph with some text.</p> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Cookie; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class BrowserController extends AbstractController | ||
{ | ||
public function requestWithAttribute(Request $request): Response | ||
{ | ||
$request->attributes->set('page', 'register'); | ||
|
||
return $this->render('blog/home.html.twig'); | ||
} | ||
|
||
public function responseWithCookie(): Response | ||
{ | ||
$response = new Response('TESTCOOKIE has been set.'); | ||
$response->headers->setCookie(new Cookie('TESTCOOKIE', 'codecept')); | ||
|
||
return $response; | ||
} | ||
|
||
public function responseJsonFormat(): Response | ||
{ | ||
return $this->json([ | ||
'status' => 'success', | ||
'message' => "Expected format: 'json'.", | ||
]); | ||
} | ||
|
||
public function unprocessableEntity(): Response | ||
{ | ||
return $this->json([ | ||
'status' => 'error', | ||
'message' => 'The request was well-formed but could not be processed.', | ||
], Response::HTTP_UNPROCESSABLE_ENTITY); | ||
} | ||
|
||
public function redirectToHome(): RedirectResponse | ||
{ | ||
return $this->redirectToRoute('index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class DomCrawlerController extends AbstractController | ||
{ | ||
public function __invoke(): Response | ||
{ | ||
return $this->render('dom_crawler/test_page.html.twig', [ | ||
'page_title' => 'Test Page', | ||
'title' => 'Test Page', | ||
'checked' => true, | ||
'inputValue' => 'Expected Value', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,115 @@ | |
|
||
final class BrowserCest | ||
{ | ||
public function assertBrowserCookieValueSame(FunctionalTester $I) | ||
{ | ||
$I->setCookie('TESTCOOKIE', 'codecept'); | ||
$I->assertBrowserCookieValueSame('TESTCOOKIE', 'codecept'); | ||
} | ||
|
||
public function assertBrowserHasCookie(FunctionalTester $I) | ||
{ | ||
$I->setCookie('TESTCOOKIE', 'codecept'); | ||
$I->assertBrowserHasCookie('TESTCOOKIE'); | ||
} | ||
|
||
public function assertBrowserNotHasCookie(FunctionalTester $I) | ||
{ | ||
$I->setCookie('TESTCOOKIE', 'codecept'); | ||
$I->resetCookie('TESTCOOKIE'); | ||
$I->assertBrowserNotHasCookie('TESTCOOKIE'); | ||
} | ||
|
||
public function assertRequestAttributeValueSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/request_attr'); | ||
$I->assertRequestAttributeValueSame('page', 'register'); | ||
} | ||
|
||
public function assertResponseCookieValueSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_cookie'); | ||
$I->assertResponseCookieValueSame('TESTCOOKIE', 'codecept'); | ||
} | ||
|
||
public function assertResponseFormatSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_json'); | ||
$I->assertResponseFormatSame('json'); | ||
} | ||
|
||
public function assertResponseHasCookie(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_cookie'); | ||
$I->assertResponseHasCookie('TESTCOOKIE'); | ||
} | ||
|
||
public function assertResponseHasHeader(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_json'); | ||
$I->assertResponseHasHeader('content-type'); | ||
} | ||
|
||
public function assertResponseHeaderNotSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_json'); | ||
$I->assertResponseHeaderNotSame('content-type', 'application/octet-stream'); | ||
} | ||
|
||
public function assertResponseHeaderSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/response_json'); | ||
$I->assertResponseHeaderSame('content-type', 'application/json'); | ||
} | ||
|
||
public function assertResponseIsSuccessful(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/'); | ||
$I->assertResponseIsSuccessful(); | ||
} | ||
|
||
public function assertResponseIsUnprocessable(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/unprocessable_entity'); | ||
$I->assertResponseIsUnprocessable(); | ||
} | ||
|
||
public function assertResponseNotHasCookie(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/'); | ||
$I->assertResponseNotHasCookie('TESTCOOKIE'); | ||
} | ||
|
||
public function assertResponseNotHasHeader(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/'); | ||
$I->assertResponseNotHasHeader('accept-charset'); | ||
} | ||
|
||
public function assertResponseRedirects(FunctionalTester $I) | ||
{ | ||
$I->stopFollowingRedirects(); | ||
$I->amOnPage('/redirect_home'); | ||
$I->assertResponseRedirects(); | ||
$I->assertResponseRedirects('/'); | ||
} | ||
|
||
public function assertResponseStatusCodeSame(FunctionalTester $I) | ||
{ | ||
$I->stopFollowingRedirects(); | ||
$I->amOnPage('/redirect_home'); | ||
$I->assertResponseStatusCodeSame(302); | ||
} | ||
|
||
public function assertRouteSame(FunctionalTester $I) | ||
{ | ||
$I->amOnPage('/'); | ||
$I->assertRouteSame('index'); | ||
|
||
$I->amOnPage('/login'); | ||
$I->assertRouteSame('app_login'); | ||
} | ||
|
||
public function seePageIsAvailable(FunctionalTester $I) | ||
{ | ||
// With url parameter | ||
|
@@ -30,10 +139,10 @@ public function submitSymfonyForm(FunctionalTester $I) | |
$I->submitSymfonyForm('registration_form', [ | ||
'[email]' => '[email protected]', | ||
'[password]' => '123456', | ||
'[agreeTerms]' => true | ||
'[agreeTerms]' => true, | ||
]); | ||
$I->seeInRepository(User::class, [ | ||
'email' => '[email protected]' | ||
'email' => '[email protected]', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Functional; | ||
|
||
use App\Tests\Support\FunctionalTester; | ||
|
||
final class DomCrawlerCest | ||
{ | ||
public function _before(FunctionalTester $I): void | ||
{ | ||
$I->amOnPage('/test_page'); | ||
} | ||
|
||
public function assertCheckboxChecked(FunctionalTester $I): void | ||
{ | ||
$I->assertCheckboxChecked('exampleCheckbox', 'The checkbox should be checked.'); | ||
} | ||
|
||
public function assertCheckboxNotChecked(FunctionalTester $I): void | ||
{ | ||
$I->assertCheckboxNotChecked('nonExistentCheckbox', 'This checkbox should not be checked.'); | ||
} | ||
|
||
public function assertInputValueSame(FunctionalTester $I): void | ||
{ | ||
$I->assertInputValueSame('exampleInput', 'Expected Value', 'The input value should be "Expected Value".'); | ||
} | ||
|
||
public function assertPageTitleContains(FunctionalTester $I): void | ||
{ | ||
$I->assertPageTitleContains('Test', 'The page title should contain "Test".'); | ||
} | ||
|
||
public function assertPageTitleSame(FunctionalTester $I): void | ||
{ | ||
$I->assertPageTitleSame('Test Page', 'The page title should be "Test Page".'); | ||
} | ||
|
||
public function assertSelectorExists(FunctionalTester $I): void | ||
{ | ||
$I->assertSelectorExists('h1', 'The <h1> element should be present.'); | ||
} | ||
|
||
public function assertSelectorNotExists(FunctionalTester $I): void | ||
{ | ||
$I->assertSelectorNotExists('.non-existent-class', 'This selector should not exist.'); | ||
} | ||
|
||
public function assertSelectorTextSame(FunctionalTester $I): void | ||
{ | ||
$I->assertSelectorTextSame('h1', 'Test Page', 'The text in the <h1> tag should be exactly "Test Page".'); | ||
} | ||
} |