1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Tests\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
6
|
|
|
|
7
|
|
|
class BlogControllerTest extends WebTestCase |
8
|
|
|
{ |
9
|
|
|
public function testIndex() |
10
|
|
|
{ |
11
|
|
|
$client = static::createClient(); |
12
|
|
|
|
13
|
|
|
$crawler = $client->request('GET', '/'); |
14
|
|
|
|
15
|
|
|
$date = new \DateTime('now'); |
16
|
|
|
|
17
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
18
|
|
|
$this->assertContains('Test title', $crawler->filter('h2 a')->text()); |
19
|
|
|
$this->assertContains('User name', $crawler->filter('.post-author a')->text()); |
20
|
|
|
$this->assertContains('Test category', $crawler->filter('.post-category a')->text()); |
21
|
|
|
$this->assertContains('Test article', $crawler->filter('.excerpt p')->text()); |
22
|
|
|
$this->assertContains('news', $crawler->filter('.post-tags a')->eq(0)->text()); |
23
|
|
|
$this->assertContains('sport', $crawler->filter('.post-tags a')->eq(1)->text()); |
24
|
|
|
$this->assertContains('1 Comments', $crawler->filter('.post-comment a')->text()); |
25
|
|
|
$this->assertContains('Test category (1)', $crawler->filter('.widget .category-list a')->text()); |
26
|
|
|
$this->assertContains('5 Test title', $crawler->filter('.widget .blogposts.popular a')->text()); |
27
|
|
|
$this->assertContains($date->format('M d, Y').' | by User name', $crawler->filter('.widget .blogposts.popular .text-muted')->text()); |
28
|
|
|
$this->assertContains('Test title', $crawler->filter('.widget .blogposts.latest a')->text()); |
29
|
|
|
$this->assertContains($date->format('M d, Y').' | by User name', $crawler->filter('.widget .blogposts.latest .text-muted')->text()); |
30
|
|
|
$this->assertContains('User name', $crawler->filter('.widget .recent-comments .media-heading a')->eq(0)->text()); |
31
|
|
|
$this->assertContains('Test title', $crawler->filter('.widget .recent-comments .media-heading a')->eq(1)->text()); |
32
|
|
|
$this->assertContains('Text comment', $crawler->filter('.widget .recent-comments .text-muted')->text()); |
33
|
|
|
$this->assertContains('news', $crawler->filter('.widget .tag-list a')->eq(0)->text()); |
34
|
|
|
$this->assertContains('sport', $crawler->filter('.widget .tag-list a')->eq(1)->text()); |
35
|
|
|
$this->assertContains('1', $crawler->filter('.widget .tag-list a .badge')->eq(0)->text()); |
36
|
|
|
$this->assertContains('1', $crawler->filter('.widget .tag-list a .badge')->eq(1)->text()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function testShowArticle() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$client = static::createClient(); |
42
|
|
|
|
43
|
|
|
$crawler = $client->request('GET', '/article/test_title'); |
44
|
|
|
|
45
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
46
|
|
|
$this->assertContains('Test title', $crawler->filter('h2 a')->text()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
public function testSortAuthor() |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$client = static::createClient(); |
52
|
|
|
|
53
|
|
|
$crawler = $client->request('GET', '/author/user_name'); |
54
|
|
|
|
55
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
56
|
|
|
$this->assertContains('Test title', $crawler->filter('h2 a')->text()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function testSortCategory() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$client = static::createClient(); |
62
|
|
|
|
63
|
|
|
$crawler = $client->request('GET', '/category/test_category'); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
66
|
|
|
$this->assertContains('Test title', $crawler->filter('h2 a')->text()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function testSortTags() |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$client = static::createClient(); |
72
|
|
|
|
73
|
|
|
$crawler = $client->request('GET', '/tag/news'); |
74
|
|
|
|
75
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
76
|
|
|
$this->assertContains('Test title', $crawler->filter('h2 a')->text()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testFormComment() |
80
|
|
|
{ |
81
|
|
|
$client = static::createClient(); |
82
|
|
|
|
83
|
|
|
$crawler = $client->request('GET', '/newCommentFor/test_title'); |
84
|
|
|
|
85
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
86
|
|
|
$this->assertContains('Rating', $crawler->filter('label')->eq(0)->text()); |
87
|
|
|
$this->assertContains('Text', $crawler->filter('label')->eq(1)->text()); |
88
|
|
|
$this->assertContains('User', $crawler->filter('label')->eq(2)->text()); |
89
|
|
|
$this->assertContains('Name', $crawler->filter('label')->eq(3)->text()); |
90
|
|
|
$this->assertContains('Email', $crawler->filter('label')->eq(4)->text()); |
91
|
|
|
$this->assertContains('Submit Comment', $crawler->filter('button')->text()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function testCommentsList() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$client = static::createClient(); |
97
|
|
|
|
98
|
|
|
$crawler = $client->request('GET', '/comments/test_title'); |
99
|
|
|
|
100
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
101
|
|
|
$this->assertContains('Comments (1)', $crawler->filter('.section-heading')->text()); |
102
|
|
|
$this->assertContains('Text comment', $crawler->filter('.media-body p')->text()); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function testSuccess() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$client = static::createClient(); |
108
|
|
|
|
109
|
|
|
$crawler = $client->request('GET', '/success'); |
110
|
|
|
|
111
|
|
|
$this->assertEquals(200, $client->getResponse()->getStatusCode()); |
112
|
|
|
$this->assertContains('Your data successfully saved.', $crawler->filter('.alert')->text()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.