-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNewsControllerTest.php
More file actions
66 lines (52 loc) · 2.63 KB
/
Copy pathNewsControllerTest.php
File metadata and controls
66 lines (52 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php declare(strict_types=1);
namespace App\Tests\Functional\Controller;
use App\Tests\Shared\Functional\ControllerWebTestCase;
class NewsControllerTest extends ControllerWebTestCase
{
const NEWS_URL = '/news';
const NEWS_WEEK_601_SLUG = 'week-601';
const NEWS_SYMFONY_LIVE_SLUG = 'symfony-live-usa-2018';
const NEWS_SYMFONY_LIVE_URL = self::NEWS_URL . '/' . self::NEWS_SYMFONY_LIVE_SLUG;
const NEWS_SYMFONY_LIVE_TITLE = 'Join us at SymfonyLive USA 2018!';
const NEWS_COUNT = 2;
const NEWS_TITLE_SELECTOR = 'h1';
const COMMENTS_LIST_SELECTOR = '#comments-list';
const COMMENTS_LIST_FIRST_CHILD_SELECTOR = '#comments-list li:first-child';
const NEW_COMMENT_FORM_SELECTOR = '#new-comment-form';
const NEW_COMMENT_TEXTAREA_NAME = 'new-comment';
const NEW_COMMENT_TITLE = 'Symfony is so cool!';
public function testNews()
{
// Arrange
$client = static::createPantherClient();
// Act
$crawler = $client->request('GET', self::NEWS_URL);
// Assert
$this->assertCount(self::NEWS_COUNT, $crawler->filter(self::NEWS_TITLE_SELECTOR));
$this->assertSame([self::NEWS_WEEK_601_SLUG, self::NEWS_SYMFONY_LIVE_SLUG], $crawler->filter('article')->extract('id'));
$this->takeScreenshot($client, $crawler);
// Arrange
$link = $crawler->selectLink(self::NEWS_SYMFONY_LIVE_TITLE)->link();
// Act
$crawler = $client->click($link);
// Assert
$this->assertSame(self::NEWS_SYMFONY_LIVE_TITLE, $crawler->filter(self::NEWS_TITLE_SELECTOR)->text());
$this->takeScreenshot($client, $crawler);
}
public function testComments()
{
// Arrange
$client = static::createPantherClient();
// Act
$crawler = $client->request('GET', self::NEWS_SYMFONY_LIVE_URL);
$client->waitFor(self::NEW_COMMENT_FORM_SELECTOR, self::SHORT_TIMEOUT_IN_SECOND); // Wait for the form to appear, it may take some time because it's done in JS
$this->takeScreenshot($client, $crawler);
$form = $crawler->filter(self::NEW_COMMENT_FORM_SELECTOR)->form([self::NEW_COMMENT_TEXTAREA_NAME => self::NEW_COMMENT_TITLE]);
$client->submit($form);
$client->waitFor(self::COMMENTS_LIST_SELECTOR, self::SHORT_TIMEOUT_IN_SECOND); // Wait for the comments to appear
// Assert
$this->assertSame(self::$baseUri . self::NEWS_SYMFONY_LIVE_URL, $client->getCurrentURL()); // Assert we're still on the same page
$this->assertSame(self::NEW_COMMENT_TITLE, $crawler->filter(self::COMMENTS_LIST_FIRST_CHILD_SELECTOR)->text());
$this->takeScreenshot($client, $crawler);
}
}