client = new Parse(); $this->client->http = new p3k\HTTPTest(dirname(__FILE__).'/data/'); } private function parse($params) { $request = new Request($params); $response = new Response(); return $this->client->parse($request, $response); } public function testAllowsWhitelistedTags() { $url = 'http://sanitize.example/entry-with-valid-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $this->assertEquals('entry', $data['data']['type']); $this->assertContains('This content has only valid tags.', $html); $this->assertContains('links,', $html, ' missing'); $this->assertContains('abbreviations,', $html, ' missing'); $this->assertContains('bold,', $html, ' missing'); $this->assertContains('inline code,', $html, ' missing'); $this->assertContains('delete,', $html, ' missing'); $this->assertContains('emphasis,', $html, ' missing'); $this->assertContains('italics,', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('inline quote,', $html, ' missing'); $this->assertContains('strikethrough,', $html, ' missing'); $this->assertContains('strong text,', $html, ' missing'); $this->assertContains('time elements', $html, ' missing'); $this->assertContains('Blockquote tags are okay', $html); $this->assertContains('preformatted text is okay too', $html, ' missing'); $this->assertContains('for code examples and such', $html, ' missing'); $this->assertContains('Paragraph tags are allowed', $html, ' missing'); $this->assertContains('One', $html, ' missing'); $this->assertContains('Two', $html, ' missing'); $this->assertContains('Three', $html, ' missing'); $this->assertContains('Four', $html, ' missing'); $this->assertContains('Five', $html, ' missing'); $this->assertContains('Six', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('One', $html, ' missing'); } public function testRemovesUnsafeTags() { $url = 'http://sanitize.example/entry-with-unsafe-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $text = $data['data']['content']['text']; $this->assertEquals('entry', $data['data']['type']); $this->assertNotContains('
inline code
missing'); $this->assertContains('delete,', $html, ' missing'); $this->assertContains('emphasis,', $html, ' missing'); $this->assertContains('italics,', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('inline quote,', $html, ' missing'); $this->assertContains('strikethrough,', $html, ' missing'); $this->assertContains('strong text,', $html, ' missing'); $this->assertContains('time elements', $html, ' missing'); $this->assertContains('Blockquote tags are okay', $html); $this->assertContains('preformatted text is okay too', $html, ' missing'); $this->assertContains('for code examples and such', $html, ' missing'); $this->assertContains('Paragraph tags are allowed', $html, ' missing'); $this->assertContains('One', $html, ' missing'); $this->assertContains('Two', $html, ' missing'); $this->assertContains('Three', $html, ' missing'); $this->assertContains('Four', $html, ' missing'); $this->assertContains('Five', $html, ' missing'); $this->assertContains('Six', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('One', $html, ' missing'); } public function testRemovesUnsafeTags() { $url = 'http://sanitize.example/entry-with-unsafe-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $text = $data['data']['content']['text']; $this->assertEquals('entry', $data['data']['type']); $this->assertNotContains('
inline quote
missing'); $this->assertContains('strikethrough,', $html, ' missing'); $this->assertContains('strong text,', $html, ' missing'); $this->assertContains('time elements', $html, ' missing'); $this->assertContains('Blockquote tags are okay', $html); $this->assertContains('preformatted text is okay too', $html, ' missing'); $this->assertContains('for code examples and such', $html, ' missing'); $this->assertContains('Paragraph tags are allowed', $html, ' missing'); $this->assertContains('One', $html, ' missing'); $this->assertContains('Two', $html, ' missing'); $this->assertContains('Three', $html, ' missing'); $this->assertContains('Four', $html, ' missing'); $this->assertContains('Five', $html, ' missing'); $this->assertContains('Six', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('One', $html, ' missing'); } public function testRemovesUnsafeTags() { $url = 'http://sanitize.example/entry-with-unsafe-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $text = $data['data']['content']['text']; $this->assertEquals('entry', $data['data']['type']); $this->assertNotContains('
Blockquote tags are okay
preformatted text is okay too', $html, ' missing'); $this->assertContains('for code examples and such', $html, ' missing'); $this->assertContains('Paragraph tags are allowed', $html, ' missing'); $this->assertContains('One', $html, ' missing'); $this->assertContains('Two', $html, ' missing'); $this->assertContains('Three', $html, ' missing'); $this->assertContains('Four', $html, ' missing'); $this->assertContains('Five', $html, ' missing'); $this->assertContains('Six', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('One', $html, ' missing'); } public function testRemovesUnsafeTags() { $url = 'http://sanitize.example/entry-with-unsafe-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $text = $data['data']['content']['text']; $this->assertEquals('entry', $data['data']['type']); $this->assertNotContains('
missing'); $this->assertContains('for code examples and such
missing'); $this->assertContains('Paragraph tags are allowed', $html, ' missing'); $this->assertContains('One', $html, ' missing'); $this->assertContains('Two', $html, ' missing'); $this->assertContains('Three', $html, ' missing'); $this->assertContains('Four', $html, ' missing'); $this->assertContains('Five', $html, ' missing'); $this->assertContains('Six', $html, ' missing'); $this->assertContains('', $html, ' missing'); $this->assertContains('One', $html, ' missing'); } public function testRemovesUnsafeTags() { $url = 'http://sanitize.example/entry-with-unsafe-tags'; $response = $this->parse(['url' => $url]); $body = $response->getContent(); $this->assertEquals(200, $response->getStatusCode()); $data = json_decode($body, true); $html = $data['data']['content']['html']; $text = $data['data']['content']['text']; $this->assertEquals('entry', $data['data']['type']); $this->assertNotContains('
Paragraph tags are allowed
missing'); $this->assertContains('