Source of file WebsiteParserTest.php
Size: 1,459 Bytes - Last Modified: 2021-12-23T10:07:40+00:00
/var/www/docs.ssmods.com/process/src/tests/functional/WebsiteParserTest.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | <?php /** * Test website parser. * @author Christian Blank <c.blank@notthatbad.net> */ class WebsiteParserTest extends SapphireTest { public function setUpOnce() { Injector::nest(); Injector::inst()->registerService(new TestFetcher(), 'Fetcher'); parent::setUpOnce(); } public function tearDownOnce() { Injector::unnest(); parent::tearDownOnce(); } public function testNotFound() { $result = WebsiteParser::parse("http://not.a-site"); $this->assertTrue($result->isError()); } public function testNormalSite() { $result = WebsiteParser::parse("http://normal.site"); $this->assertFalse($result->isError()); $this->assertFalse($result->hasImage()); $this->assertEquals("Normal Site", $result->Title); $this->assertEquals("The description", $result->Description); } } class TestFetcher implements IFetcher, TestOnly { const HTML_DOC = <<<'EOT' <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Normal Site</title> <meta name="description" content="The description"> </head> <body> </body> </html> EOT; private static $data = [ "http://normal.site" => TestFetcher::HTML_DOC, ]; public function fetch($url) { if(array_key_exists($url, self::$data)) { return self::$data[$url]; } throw new Exception("Website not found"); } } |