|
|
|
|
@ -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'); |
|
|
|
|
|
|
|
|
|
|