Fix tests

This commit is contained in:
Roeland Jago Douma 2016-08-29 15:17:59 +02:00
parent 14136295b7
commit 6a85882f61
No known key found for this signature in database
GPG key ID: 1E152838F164D13B
2 changed files with 35 additions and 14 deletions

View file

@ -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

View file

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