public function testExtract() { $favicon = new Favicon(); $html = '<!DOCTYPE html><html><head> <link rel="icon" href="http://example.com/myicon.ico" /> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/myicon.ico'), $favicon->extract($html)); // multiple values in rel attribute $html = '<!DOCTYPE html><html><head> <link rel="shortcut icon" href="http://example.com/myicon.ico" /> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/myicon.ico'), $favicon->extract($html)); // icon part of another string $html = '<!DOCTYPE html><html><head> <link rel="fluid-icon" href="http://example.com/myicon.ico" /> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/myicon.ico'), $favicon->extract($html)); // with other attributes present $html = '<!DOCTYPE html><html><head> <link rel="icon" type="image/vnd.microsoft.icon" href="http://example.com/image.ico" /> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/image.ico'), $favicon->extract($html)); // ignore icon in other attribute $html = '<!DOCTYPE html><html><head> <link type="icon" href="http://example.com/image.ico" /> </head><body><p>boo</p></body></html>'; // ignores apple icon $html = '<!DOCTYPE html><html><head> <link rel="apple-touch-icon" href="assets/img/touch-icon-iphone.png"> <link rel="icon" type="image/png" href="http://example.com/image.png" /> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/image.png'), $favicon->extract($html)); // allows multiple icons $html = '<!DOCTYPE html><html><head> <link rel="icon" type="image/png" href="http://example.com/image.png" /> <link rel="icon" type="image/x-icon" href="http://example.com/image.ico"/> </head><body><p>boo</p></body></html>'; $this->assertEquals(array('http://example.com/image.png', 'http://example.com/image.ico'), $favicon->extract($html)); // empty array with broken html $html = '!DOCTYPE html html head link rel="icon" type="image/png" href="http://example.com/image.png" / link rel="icon" type="image/x-icon" href="http://example.com/image.ico"/ /head body /p boo /p body /html'; $this->assertEquals(array(), $favicon->extract($html)); // empty array on no input $this->assertEquals(array(), $favicon->extract('')); // empty array on no icon found $html = '<!DOCTYPE html><html><head> </head><body><p>boo</p></body></html>'; $this->assertEquals(array(), $favicon->extract($html)); }