diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-16 13:58:08 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2019-12-16 13:58:08 +0300 |
commit | a5e10ee0ba0d0ccf11ec372a5e76b53032e9c00b (patch) | |
tree | 41e5ccaf40c09a42f42bbce05d8ff2a045a99c47 /tests | |
parent | 7fc4be9ca17b02746965e926f01700682b6ac006 (diff) |
Fix local caching in external Favicon lib
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/Service/Avatar/FaviconSourceTest.php | 91 | ||||
-rw-r--r-- | tests/Unit/Service/Avatar/FaviconSourceTest.php | 11 |
2 files changed, 96 insertions, 6 deletions
diff --git a/tests/Integration/Service/Avatar/FaviconSourceTest.php b/tests/Integration/Service/Avatar/FaviconSourceTest.php new file mode 100644 index 000000000..f65b7552d --- /dev/null +++ b/tests/Integration/Service/Avatar/FaviconSourceTest.php @@ -0,0 +1,91 @@ +<?php declare(strict_types=1); + +/** + * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +namespace OCA\Mail\Tests\Integration\Service\Avatar; + +use DirectoryIterator; +use Favicon\Favicon; +use OC; +use OCA\Mail\Service\Avatar\AvatarFactory; +use OCA\Mail\Service\Avatar\FaviconSource; +use ChristophWurst\Nextcloud\Testing\TestCase; +use OCP\Files\IMimeTypeDetector; +use OCP\Http\Client\IClient; +use OCP\Http\Client\IClientService; +use OCP\Http\Client\IResponse; +use OCP\IServerContainer; +use PHPUnit\Framework\MockObject\MockObject; +use function iterator_to_array; +use function unlink; + +class FaviconSourceTest extends TestCase { + + /** @var IServerContainer */ + private $serverContainer; + + /** + * @return string[] + */ + private function getCacheFiles(): iterable { + foreach (new DirectoryIterator(__DIR__ . '/../../../../vendor/arthurhoaro/favicon/resources/cache') as $entry) { + if ($entry->isDot() || $entry->getFilename() === '.gitkeep') { + continue; + } + yield $entry->getRealPath(); + } + } + + private function clearFaviconCacheDir(): void { + foreach ($this->getCacheFiles() as $cacheFile) { + unlink($cacheFile); + } + } + + protected function setUp(): void { + parent::setUp(); + + $this->clearFaviconCacheDir(); + + $this->serverContainer = OC::$server; + } + + public function testFetchNoCacheFiles() { + $email = 'noreply@duckduckgo.com'; + $avatarFactory = $this->serverContainer->query(AvatarFactory::class); + /** @var IClientService $clientService */ + $clientService = $this->serverContainer->query(IClientService::class); + /** @var IMimeTypeDetector $clientService */ + $mimeDetector = $this->serverContainer->query(IMimeTypeDetector::class); + $source = new FaviconSource( + $clientService, + new Favicon(), + $mimeDetector + ); + + $avatar = $source->fetch($email, $avatarFactory); + + $this->assertNotNull($avatar); + $this->assertEmpty(iterator_to_array($this->getCacheFiles())); + } + +} diff --git a/tests/Unit/Service/Avatar/FaviconSourceTest.php b/tests/Unit/Service/Avatar/FaviconSourceTest.php index 5213f0211..7bc21c971 100644 --- a/tests/Unit/Service/Avatar/FaviconSourceTest.php +++ b/tests/Unit/Service/Avatar/FaviconSourceTest.php @@ -1,4 +1,4 @@ -<?php +<?php declare(strict_types=1); /** * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> @@ -25,7 +25,6 @@ namespace OCA\Mail\Tests\Unit\Service\Avatar; use Favicon\Favicon; -use Mpclarkson\IconScraper\Icon; use OCA\Mail\Service\Avatar\Avatar; use OCA\Mail\Service\Avatar\AvatarFactory; use OCA\Mail\Service\Avatar\FaviconSource; @@ -34,17 +33,17 @@ use OCP\Files\IMimeTypeDetector; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; -use PHPUnit_Framework_MockObject_MockObject; +use PHPUnit\Framework\MockObject\MockObject; class FaviconSourceTest extends TestCase { - /** @var IClientService|PHPUnit_Framework_MockObject_MockObject */ + /** @var IClientService|MockObject */ private $clientService; - /** @var Favicon|PHPUnit_Framework_MockObject_MockObject */ + /** @var Favicon|MockObject */ private $favicon; - /** @var IMimeTypeDetector|PHPUnit_Framework_MockObject_MockObject */ + /** @var IMimeTypeDetector|MockObject */ private $mimeDetector; /** @var FaviconSource */ |