2016-12-12 16:58:29 +00:00
|
|
|
<?php
|
|
|
|
|
2017-01-09 19:08:01 +00:00
|
|
|
namespace Tests\Skobkin\PointToolsBundle\Controller;
|
2016-12-12 16:58:29 +00:00
|
|
|
|
2023-03-11 16:27:07 +00:00
|
|
|
use src\PointToolsBundle\DataFixtures\ORM\LoadPostData;
|
2019-04-03 15:55:29 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\{Client, Test\WebTestCase};
|
2016-12-12 16:58:29 +00:00
|
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
|
|
|
|
class PostControllerTest extends WebTestCase
|
|
|
|
{
|
|
|
|
public function testNonExistingPostPage()
|
|
|
|
{
|
2019-04-03 15:55:29 +00:00
|
|
|
$client = $this->createClientForPostId('nonexistingpost');
|
2016-12-12 16:58:29 +00:00
|
|
|
|
|
|
|
$this->assertTrue($client->getResponse()->isNotFound(), '404 response code for non-existing post');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Crawler
|
|
|
|
*/
|
|
|
|
public function testShortPostPageIsOk()
|
|
|
|
{
|
2019-04-03 15:55:29 +00:00
|
|
|
$client = $this->createClientForPostId(LoadPostData::POST_ID_SHORT);
|
2016-12-12 16:58:29 +00:00
|
|
|
|
|
|
|
$this->assertTrue($client->getResponse()->isOk(), '200 response code for existing post');
|
|
|
|
|
2019-04-03 15:55:29 +00:00
|
|
|
return $client->getCrawler();
|
2016-12-12 16:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testShortPostPageIsOk
|
|
|
|
*
|
|
|
|
* @param Crawler $crawler
|
|
|
|
*
|
|
|
|
* @return Crawler
|
|
|
|
*/
|
|
|
|
public function testShortPostPageHasPostBlock(Crawler $crawler)
|
|
|
|
{
|
|
|
|
$postBlock = $crawler->filter('div.post-block');
|
|
|
|
|
|
|
|
$this->assertEquals(1, $postBlock->count(), 'Post page has zero or more than one div.post-block');
|
|
|
|
|
|
|
|
return $postBlock->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testShortPostPageHasPostBlock
|
|
|
|
*
|
|
|
|
* @param Crawler $postBlock
|
|
|
|
*/
|
|
|
|
public function testShortPostPostBlockHasCorrectPostText(Crawler $postBlock)
|
|
|
|
{
|
|
|
|
$postText = $postBlock->filter('div.post-text > div')->first();
|
|
|
|
|
|
|
|
$this->assertEquals(1, $postText->count(), 'Postblock has no .post-text block');
|
|
|
|
$p = $postText->filter('p');
|
|
|
|
$this->assertEquals(1, $p->count(), '.post-text has zero or more than one paragraphs');
|
|
|
|
$this->assertEquals('Test short post', $p->text(), '.post-text has no correct post text');
|
|
|
|
}
|
2019-04-03 15:55:29 +00:00
|
|
|
|
|
|
|
public function testPrivateUserPostForbidden()
|
|
|
|
{
|
|
|
|
$client = $this->createClientForPostId(LoadPostData::POST_ID_PR_USER);
|
|
|
|
|
2019-04-03 17:34:16 +00:00
|
|
|
$this->assertTrue($client->getResponse()->isNotFound(), '404 response code for private user\'s post');
|
2019-04-03 15:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testWhitelistOnlyUserPostForbidden()
|
|
|
|
{
|
|
|
|
$client = $this->createClientForPostId(LoadPostData::POST_ID_WL_USER);
|
|
|
|
|
2019-04-03 17:34:16 +00:00
|
|
|
$this->assertTrue($client->getResponse()->isNotFound(), '404 response code for whitelist-only user\'s post');
|
2019-04-03 15:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrivateWhitelistOnlyUserPostForbidden()
|
|
|
|
{
|
|
|
|
$client = $this->createClientForPostId(LoadPostData::POST_ID_PR_WL_USER);
|
|
|
|
|
2019-04-03 17:34:16 +00:00
|
|
|
$this->assertTrue($client->getResponse()->isNotFound(), '404 response code for private whitelist-only user\'s post');
|
2019-04-03 15:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function createClientForPostId(string $id): Client
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$client->request('GET', '/'.$id);
|
|
|
|
|
|
|
|
return $client;
|
|
|
|
}
|
2016-12-12 16:58:29 +00:00
|
|
|
}
|