From e493eb632292cb8469a02014ecc976fc1b80545a Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Sun, 11 Dec 2016 23:59:05 +0300 Subject: [PATCH] Updated user page tests. --- .../Tests/Controller/UserControllerTest.php | 79 ++++++++++++++++++- 1 file changed, 77 insertions(+), 2 deletions(-) diff --git a/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/UserControllerTest.php b/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/UserControllerTest.php index 2b0dad8..17dd200 100644 --- a/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/UserControllerTest.php +++ b/src/Skobkin/Bundle/PointToolsBundle/Tests/Controller/UserControllerTest.php @@ -3,14 +3,89 @@ namespace Skobkin\Bundle\PointToolsBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\DomCrawler\Crawler; class UserControllerTest extends WebTestCase { - public function testShow() + public function testTestuserPageHasHeading() { $client = static::createClient(); - $crawler = $client->request('GET', '/user/{login}'); + $crawler = $client->request('GET', '/user/testuser'); + + $userLoginHeading = $crawler->filter('h1.user-login')->first(); + + $this->assertEquals( + 1, + $userLoginHeading->count(), + 'User page has no heading element with user login and avatar' + ); + + return $userLoginHeading; } + /** + * @depends testTestuserPageHasHeading + * + * @param Crawler $heading + */ + public function testTestuserPageHasUserLink(Crawler $heading) + { + $userLink = $heading->children()->filter('a'); + + $this->assertEquals( + 1, + $userLink->count(), + 'User page has no user link in the heading' + ); + + $this->assertEquals( + 'testuser', + $userLink->text(), + 'User link text is not equal user login' + ); + } + + /** + * @depends testTestuserPageHasHeading + * + * @param Crawler $heading + */ + public function testTestuserPageHasUserAvatar(Crawler $heading) + { + $userAvatar = $heading->children()->filter('img')->first(); + + $this->assertEquals( + 1, + $userAvatar->count(), + 'testuser page has no avatar' + ); + + $this->assertEquals( + '//point.im/avatar/testuser/80', + $userAvatar->attr('src'), + 'testuser avatar image source is not correct' + ); + } + + public function testTestuserHasSubscribers() + { + $client = static::createClient(); + + $crawler = $client->request('GET', '/user/testuser'); + + $subscribersList = $crawler->filter('.user-subscribers ul.users')->first(); + + $this->assertEquals( + 1, + $subscribersList->count(), + 'testuser has no subscribers list shown on the page' + ); + + $this->assertGreaterThan( + 0, + $subscribersList->children()->count(), + 'Testuser has zero subscribers in the list' + ); + } }