diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-09-05 15:08:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-05 15:08:43 +0200 |
commit | 06fa48670699a4dc752c2cd44284ef6dc5da9e9f (patch) | |
tree | c30a8037c2d0de9d7d41a7ba2177e782eed292d5 /tests | |
parent | 12736a359221cf9d6d4dc4c3aba83a545554b02e (diff) | |
parent | 6a85882f610ed34c971a1510f5876f0564fd7612 (diff) | |
download | nextcloud-server-06fa48670699a4dc752c2cd44284ef6dc5da9e9f.tar.gz nextcloud-server-06fa48670699a4dc752c2cd44284ef6dc5da9e9f.zip |
Merge pull request #1158 from nextcloud/cache_avatars
Cache avatars
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Core/Controller/AvatarControllerTest.php | 7 | ||||
-rw-r--r-- | tests/lib/AvatarTest.php | 42 |
2 files changed, 35 insertions, 14 deletions
diff --git a/tests/Core/Controller/AvatarControllerTest.php b/tests/Core/Controller/AvatarControllerTest.php index fe1a44b28ab..af75c4bb751 100644 --- a/tests/Core/Controller/AvatarControllerTest.php +++ b/tests/Core/Controller/AvatarControllerTest.php @@ -31,6 +31,7 @@ function is_uploaded_file($filename) { namespace Tests\Core\Controller; +use OC\AppFramework\Utility\TimeFactory; use OC\Core\Controller\AvatarController; use OCP\AppFramework\Http; use OCP\Files\Cache\ICache; @@ -74,6 +75,8 @@ class AvatarControllerTest extends \Test\TestCase { private $logger; /** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */ private $request; + /** @var TimeFactory|\PHPUnit_Framework_MockObject_MockObject */ + private $timeFactory; protected function setUp() { parent::setUp(); @@ -87,6 +90,7 @@ class AvatarControllerTest extends \Test\TestCase { $this->request = $this->getMockBuilder('OCP\IRequest')->getMock(); $this->rootFolder = $this->getMockBuilder('OCP\Files\IRootFolder')->getMock(); $this->logger = $this->getMockBuilder('OCP\ILogger')->getMock(); + $this->timeFactory = $this->getMockBuilder('OC\AppFramework\Utility\TimeFactory')->getMock(); $this->avatarMock = $this->getMockBuilder('OCP\IAvatar')->getMock(); $this->userMock = $this->getMockBuilder('OCP\IUser')->getMock(); @@ -100,7 +104,8 @@ class AvatarControllerTest extends \Test\TestCase { $this->userManager, $this->rootFolder, $this->logger, - 'userid' + 'userid', + $this->timeFactory ); // Configure userMock diff --git a/tests/lib/AvatarTest.php b/tests/lib/AvatarTest.php index 0a00f5d5614..f515f0d013f 100644 --- a/tests/lib/AvatarTest.php +++ b/tests/lib/AvatarTest.php @@ -20,15 +20,26 @@ class AvatarTest extends \Test\TestCase { /** @var \OC\User\User | \PHPUnit_Framework_MockObject_MockObject $user */ private $user; + /** @var \OCP\IConfig|\PHPUnit_Framework_MockObject_MockObject */ + private $config; + public function setUp() { parent::setUp(); - $this->folder = $this->getMock('\OCP\Files\Folder'); + $this->folder = $this->getMockBuilder('OCP\Files\Folder')->getMock(); /** @var \OCP\IL10N | \PHPUnit_Framework_MockObject_MockObject $l */ - $l = $this->getMock('\OCP\IL10N'); + $l = $this->getMockBuilder('OCP\IL10N')->getMock(); $l->method('t')->will($this->returnArgument(0)); - $this->user = $this->getMockBuilder('\OC\User\User')->disableOriginalConstructor()->getMock(); - $this->avatar = new \OC\Avatar($this->folder, $l, $this->user, $this->getMock('\OCP\ILogger')); + $this->user = $this->getMockBuilder('OC\User\User')->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder('OCP\IConfig')->getMock(); + + $this->avatar = new \OC\Avatar( + $this->folder, + $l, + $this->user, + $this->getMockBuilder('\OCP\ILogger')->getMock(), + $this->config + ); } public function testGetNoAvatar() { @@ -44,7 +55,7 @@ class AvatarTest extends \Test\TestCase { $expected = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get')->with('avatar.128.jpg')->willReturn($file); @@ -59,7 +70,7 @@ class AvatarTest extends \Test\TestCase { $expected = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get')->with('avatar.jpg')->willReturn($file); @@ -77,7 +88,7 @@ class AvatarTest extends \Test\TestCase { $expected2 = new \OC_Image(\OC::$SERVERROOT . '/tests/data/testavatar.png'); $expected2->resize(32); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->getMockBuilder('OCP\Files\File')->getMock(); $file->method('getContent')->willReturn($expected->data()); $this->folder->method('get') @@ -91,7 +102,7 @@ class AvatarTest extends \Test\TestCase { } )); - $newFile = $this->getMock('\OCP\Files\File'); + $newFile = $this->getMockBuilder('OCP\Files\File')->getMock(); $newFile->expects($this->once()) ->method('putContent') ->with($expected2->data()); @@ -129,22 +140,22 @@ class AvatarTest extends \Test\TestCase { } public function testSetAvatar() { - $avatarFileJPG = $this->getMock('\OCP\Files\File'); + $avatarFileJPG = $this->getMockBuilder('OCP\Files\File')->getMock(); $avatarFileJPG->method('getName') ->willReturn('avatar.jpg'); $avatarFileJPG->expects($this->once())->method('delete'); - $avatarFilePNG = $this->getMock('\OCP\Files\File'); + $avatarFilePNG = $this->getMockBuilder('OCP\Files\File')->getMock(); $avatarFilePNG->method('getName') ->willReturn('avatar.png'); $avatarFilePNG->expects($this->once())->method('delete'); - $resizedAvatarFile = $this->getMock('\OCP\Files\File'); + $resizedAvatarFile = $this->getMockBuilder('OCP\Files\File')->getMock(); $resizedAvatarFile->method('getName') ->willReturn('avatar.32.jpg'); $resizedAvatarFile->expects($this->once())->method('delete'); - $nonAvatarFile = $this->getMock('\OCP\Files\File'); + $nonAvatarFile = $this->getMockBuilder('OCP\Files\File')->getMock(); $nonAvatarFile->method('getName') ->willReturn('avatarX'); $nonAvatarFile->expects($this->never())->method('delete'); @@ -152,7 +163,7 @@ class AvatarTest extends \Test\TestCase { $this->folder->method('getDirectoryListing') ->willReturn([$avatarFileJPG, $avatarFilePNG, $resizedAvatarFile, $nonAvatarFile]); - $newFile = $this->getMock('\OCP\Files\File'); + $newFile = $this->getMockBuilder('OCP\Files\File')->getMock(); $this->folder->expects($this->once()) ->method('newFile') ->with('avatar.png') @@ -163,6 +174,11 @@ class AvatarTest extends \Test\TestCase { ->method('putContent') ->with($image->data()); + $this->config->expects($this->once()) + ->method('setUserValue'); + $this->config->expects($this->once()) + ->method('getUserValue'); + // One on remove and once on setting the new avatar $this->user->expects($this->exactly(2))->method('triggerChange'); |