Example #1
0
 /**
  * @covers Favicon::get
  * @uses Favicon
  */
 public function testGetValidFavNoCacheSetup()
 {
     $url = 'http://domain.tld';
     $fav = new Favicon(array('url' => $url));
     $dataAccess = $this->getMock('Favicon\\DataAccess', array('retrieveHeader', 'retrieveUrl'));
     $fav->setDataAccess($dataAccess);
     // MOCK
     $dataAccess->expects($this->any())->method('retrieveHeader')->will($this->returnValue(array(0 => 'HTTP/1.1 200 OK')));
     $dataAccess->expects($this->any())->method('retrieveUrl')->will($this->returnValue(file_get_contents($this->RESOURCE_FAV_ICO)));
     $this->assertEquals(self::slash($url) . $this->DEFAULT_FAV_CHECK, $fav->get());
 }
Example #2
0
 /**
  * Get feed favicon
  */
 protected function getFavicon(&$feed)
 {
     $favicon = FAVICON_DIRECTORY . $feed->id . '.ico';
     if ((!file_exists($favicon) || time() - filemtime($favicon) > FAVICON_CACHE_DURATION) && $feed->link != null) {
         $favService = new Favicon();
         $this->verbose('Downloading favicon for link #' . $feed->id . ': ' . $feed->link);
         if ($favUrl = $favService->get($feed->link)) {
             $favRequest = $this->makeRequest($favUrl);
             if ($favRequest['info']['http_code'] == 200 && !empty($favRequest['html'])) {
                 file_put_contents($favicon, $favRequest['html']);
             }
         }
         if (!file_exists($favicon) || !filesize($favicon)) {
             copy(FAVICON_DIRECTORY . FAVICON_DEFAULT, $favicon);
         }
     }
 }