use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\UserBundle\Entity\User;
use Wallabag\CoreBundle\Helper\RuleBasedTagger;
+use Graby\Graby;
class ContentProxyTest extends \PHPUnit_Framework_TestCase
{
$tagger->expects($this->once())
->method('tag');
- $graby = $this->getMockBuilder('Graby\Graby')->getMock();
-
- $proxy = new ContentProxy($graby, $tagger, $this->getLogger(), $this->fetchingErrorMessage);
- $entry = $proxy->updateEntry(new Entry(new User()), 'http://0.0.0.0', [
- 'html' => str_repeat('this is my content', 325),
- 'title' => 'this is my title',
- 'url' => 'http://1.1.1.1',
- 'content_type' => 'text/html',
- 'language' => 'fr',
- ]);
+ $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
+ $entry = $proxy->updateEntry(
+ new Entry(new User()),
+ 'http://0.0.0.0',
+ [
+ 'html' => str_repeat('this is my content', 325),
+ 'title' => 'this is my title',
+ 'url' => 'http://1.1.1.1',
+ 'content_type' => 'text/html',
+ 'language' => 'fr',
+ ]
+ );
$this->assertEquals('http://1.1.1.1', $entry->getUrl());
$this->assertEquals('this is my title', $entry->getTitle());
$this->assertCount(0, $entry->getTags());
}
+ public function dataForCrazyHtml()
+ {
+ return [
+ 'script and comment' => [
+ '<strong>Script inside:</strong> <!--[if gte IE 4]><script>alert(\'lol\');</script><![endif]--><br />',
+ 'lol'
+ ],
+ 'script' => [
+ '<strong>Script inside:</strong><script>alert(\'lol\');</script>',
+ 'script'
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider dataForCrazyHtml
+ */
+ public function testWithCrazyHtmlContent($html, $escapedString)
+ {
+ $tagger = $this->getTaggerMock();
+ $tagger->expects($this->once())
+ ->method('tag');
+
+ $proxy = new ContentProxy((new Graby()), $tagger, $this->getLogger(), $this->fetchingErrorMessage);
+ $entry = $proxy->updateEntry(
+ new Entry(new User()),
+ 'http://1.1.1.1',
+ [
+ 'html' => $html,
+ 'title' => 'this is my title',
+ 'url' => 'http://1.1.1.1',
+ 'content_type' => 'text/html',
+ 'language' => 'fr',
+ 'status' => '200',
+ 'open_graph' => [
+ 'og_title' => 'my OG title',
+ 'og_description' => 'OG desc',
+ 'og_image' => 'http://3.3.3.3/cover.jpg',
+ ],
+ ]
+ );
+
+ $this->assertEquals('http://1.1.1.1', $entry->getUrl());
+ $this->assertEquals('this is my title', $entry->getTitle());
+ $this->assertNotContains($escapedString, $entry->getContent());
+ $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture());
+ $this->assertEquals('text/html', $entry->getMimetype());
+ $this->assertEquals('fr', $entry->getLanguage());
+ $this->assertEquals('200', $entry->getHttpStatus());
+ $this->assertEquals('1.1.1.1', $entry->getDomainName());
+ }
+
private function getTaggerMock()
{
return $this->getMockBuilder(RuleBasedTagger::class)