diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php index 44fca073..7a50b373 100644 --- a/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php +++ b/tests/Wallabag/CoreBundle/Helper/ContentProxyTest.php | |||
@@ -8,6 +8,7 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
8 | use Wallabag\CoreBundle\Entity\Tag; | 8 | use Wallabag\CoreBundle\Entity\Tag; |
9 | use Wallabag\UserBundle\Entity\User; | 9 | use Wallabag\UserBundle\Entity\User; |
10 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; | 10 | use Wallabag\CoreBundle\Helper\RuleBasedTagger; |
11 | use Graby\Graby; | ||
11 | 12 | ||
12 | class ContentProxyTest extends \PHPUnit_Framework_TestCase | 13 | class ContentProxyTest extends \PHPUnit_Framework_TestCase |
13 | { | 14 | { |
@@ -253,6 +254,60 @@ class ContentProxyTest extends \PHPUnit_Framework_TestCase | |||
253 | $this->assertCount(0, $entry->getTags()); | 254 | $this->assertCount(0, $entry->getTags()); |
254 | } | 255 | } |
255 | 256 | ||
257 | public function dataForCrazyHtml() | ||
258 | { | ||
259 | return [ | ||
260 | 'script and comment' => [ | ||
261 | '<strong>Script inside:</strong> <!--[if gte IE 4]><script>alert(\'lol\');</script><![endif]--><br />', | ||
262 | 'lol' | ||
263 | ], | ||
264 | 'script' => [ | ||
265 | '<strong>Script inside:</strong><script>alert(\'lol\');</script>', | ||
266 | 'script' | ||
267 | ], | ||
268 | ]; | ||
269 | } | ||
270 | |||
271 | /** | ||
272 | * @dataProvider dataForCrazyHtml | ||
273 | */ | ||
274 | public function testWithCrazyHtmlContent($html, $escapedString) | ||
275 | { | ||
276 | $tagger = $this->getTaggerMock(); | ||
277 | $tagger->expects($this->once()) | ||
278 | ->method('tag'); | ||
279 | |||
280 | $graby = new Graby(); | ||
281 | |||
282 | $proxy = new ContentProxy($graby, $tagger, $this->getTagRepositoryMock(), $this->getLogger(), $this->fetchingErrorMessage); | ||
283 | $entry = $proxy->updateEntry( | ||
284 | new Entry(new User()), | ||
285 | 'http://1.1.1.1', | ||
286 | [ | ||
287 | 'html' => $html, | ||
288 | 'title' => 'this is my title', | ||
289 | 'url' => 'http://1.1.1.1', | ||
290 | 'content_type' => 'text/html', | ||
291 | 'language' => 'fr', | ||
292 | 'status' => '200', | ||
293 | 'open_graph' => [ | ||
294 | 'og_title' => 'my OG title', | ||
295 | 'og_description' => 'OG desc', | ||
296 | 'og_image' => 'http://3.3.3.3/cover.jpg', | ||
297 | ], | ||
298 | ] | ||
299 | ); | ||
300 | |||
301 | $this->assertEquals('http://1.1.1.1', $entry->getUrl()); | ||
302 | $this->assertEquals('this is my title', $entry->getTitle()); | ||
303 | $this->assertNotContains($escapedString, $entry->getContent()); | ||
304 | $this->assertEquals('http://3.3.3.3/cover.jpg', $entry->getPreviewPicture()); | ||
305 | $this->assertEquals('text/html', $entry->getMimetype()); | ||
306 | $this->assertEquals('fr', $entry->getLanguage()); | ||
307 | $this->assertEquals('200', $entry->getHttpStatus()); | ||
308 | $this->assertEquals('1.1.1.1', $entry->getDomainName()); | ||
309 | } | ||
310 | |||
256 | private function getTaggerMock() | 311 | private function getTaggerMock() |
257 | { | 312 | { |
258 | return $this->getMockBuilder(RuleBasedTagger::class) | 313 | return $this->getMockBuilder(RuleBasedTagger::class) |