mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-06 11:35:50 +08:00
Add some tests
This commit is contained in:
parent
e98817595f
commit
807b4149ce
4 changed files with 247 additions and 1 deletions
99
tests/unit/controller/FileControllerTest.php
Normal file
99
tests/unit/controller/FileControllerTest.php
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Nextcloud - passman
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
|
||||||
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
||||||
|
* @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\Passman\Controller;
|
||||||
|
|
||||||
|
use OCA\Comments\Activity\Setting;
|
||||||
|
use OCA\Passman\Service\ActivityService;
|
||||||
|
use OCA\Passman\Service\CredentialService;
|
||||||
|
use OCA\Passman\Service\FileService;
|
||||||
|
use OCA\Passman\Service\NotificationService;
|
||||||
|
use OCA\Passman\Service\SettingsService;
|
||||||
|
use OCA\Passman\Service\ShareService;
|
||||||
|
use OCA\Passman\Service\VaultService;
|
||||||
|
use OCP\IGroupManager;
|
||||||
|
use OCP\IUserManager;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InternalControllerTest
|
||||||
|
*
|
||||||
|
* @package OCA\Passman\Controller
|
||||||
|
* @coversDefaultClass \OCA\Passman\Controller\ShareController
|
||||||
|
*/
|
||||||
|
class FileControllerTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $controller;
|
||||||
|
private $userId = 'example';
|
||||||
|
private $credentialService;
|
||||||
|
private $vaultService;
|
||||||
|
private $groupManager;
|
||||||
|
private $userManager;
|
||||||
|
private $activityService;
|
||||||
|
private $shareService;
|
||||||
|
private $notificationService;
|
||||||
|
private $fileService;
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
|
||||||
|
$this->fileService = $this->createMock(FileService::class);
|
||||||
|
$this->controller = new FileController(
|
||||||
|
'passman', $request, $this->userId, $this->fileService
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::uploadFile
|
||||||
|
*/
|
||||||
|
public function testUploadFile() {
|
||||||
|
$result = $this->controller->uploadFile('000', '0.png', 'image/png', 3);
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getFile
|
||||||
|
*/
|
||||||
|
public function testGetFile() {
|
||||||
|
$result = $this->controller->getFile(null);
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::deleteFile
|
||||||
|
*/
|
||||||
|
public function testDeleteFile() {
|
||||||
|
$result = $this->controller->deleteFile(null);
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::updateFile
|
||||||
|
*/
|
||||||
|
public function testUpdateFile() {
|
||||||
|
$this->controller->updateFile('6AD30804-BFFC-4EFC-97F8-20A126FA1709', '0' , '0.jpg');
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -50,6 +50,21 @@ class InternalControllerTest extends PHPUnit_Framework_TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::remind
|
||||||
|
*/
|
||||||
|
public function testRemind() {
|
||||||
|
$this->controller->remind(null);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @covers ::read
|
||||||
|
*/
|
||||||
|
public function testRead() {
|
||||||
|
$this->controller->read(null);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::getAppVersion
|
* @covers ::getAppVersion
|
||||||
*/
|
*/
|
||||||
|
@ -65,4 +80,21 @@ class InternalControllerTest extends PHPUnit_Framework_TestCase {
|
||||||
$result = $this->controller->generatePerson();
|
$result = $this->controller->generatePerson();
|
||||||
$this->assertTrue($result instanceof JSONResponse);
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::getSettings
|
||||||
|
*/
|
||||||
|
public function testGetSettings() {
|
||||||
|
$result = $this->controller->getSettings();
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::saveSettings
|
||||||
|
*/
|
||||||
|
public function testSaveSettings() {
|
||||||
|
$result = $this->controller->saveSettings('test', 'test');
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -58,13 +58,20 @@ class SettingsControllerTest extends PHPUnit_Framework_TestCase {
|
||||||
$result = $this->controller->getForm();
|
$result = $this->controller->getForm();
|
||||||
$this->assertTrue($result instanceof TemplateResponse);
|
$this->assertTrue($result instanceof TemplateResponse);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @covers ::getSection
|
||||||
|
*/
|
||||||
|
public function testGetSection() {
|
||||||
|
$result = $this->controller->getSection();
|
||||||
|
$this->assertTrue(is_string($result));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers ::getPriority
|
* @covers ::getPriority
|
||||||
*/
|
*/
|
||||||
public function testGetPriority() {
|
public function testGetPriority() {
|
||||||
$result = $this->controller->getPriority();
|
$result = $this->controller->getPriority();
|
||||||
$this->assertTrue($result === 0);
|
$this->assertTrue(is_numeric($result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
108
tests/unit/controller/VaultControllerTest.php
Normal file
108
tests/unit/controller/VaultControllerTest.php
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Nextcloud - passman
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com)
|
||||||
|
* @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es)
|
||||||
|
* @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\Passman\Controller;
|
||||||
|
|
||||||
|
use OCA\Passman\Service\CredentialService;
|
||||||
|
use OCA\Passman\Service\VaultService;
|
||||||
|
use PHPUnit_Framework_TestCase;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\JSONResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class InternalControllerTest
|
||||||
|
*
|
||||||
|
* @package OCA\Passman\Controller
|
||||||
|
* @coversDefaultClass \OCA\Passman\Controller\VaultController
|
||||||
|
*/
|
||||||
|
class VaultControllerTest extends PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $controller;
|
||||||
|
private $userId = 'example';
|
||||||
|
private $credentialService;
|
||||||
|
private $vaultService;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
|
||||||
|
$this->vaultService = $this->createMock(VaultService::class);
|
||||||
|
$this->credentialService = $this->createMock(CredentialService::class);
|
||||||
|
|
||||||
|
$this->controller = new VaultController(
|
||||||
|
'passman', $request, $this->userId, $this->vaultService, $this->credentialService
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::listVaults
|
||||||
|
*/
|
||||||
|
public function testListVaults() {
|
||||||
|
$result = $this->controller->listVaults();
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::create
|
||||||
|
*/
|
||||||
|
public function testCreate() {
|
||||||
|
$result = $this->controller->create('My test vault');
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::get
|
||||||
|
*/
|
||||||
|
public function testGet() {
|
||||||
|
$result = $this->controller->get('');
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just test the method
|
||||||
|
* @see http://stackoverflow.com/questions/27511593/how-to-phpunit-test-a-method-with-no-return-value
|
||||||
|
*
|
||||||
|
* @covers ::update
|
||||||
|
*/
|
||||||
|
public function testUpdate() {
|
||||||
|
$this->controller->update('6AD30804-BFFC-4EFC-97F8-20A126FA1709', 'testname' ,null);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just test the method
|
||||||
|
* @see http://stackoverflow.com/questions/27511593/how-to-phpunit-test-a-method-with-no-return-value
|
||||||
|
*
|
||||||
|
* @covers ::updateSharingKeys
|
||||||
|
*/
|
||||||
|
public function testUpdateSharingKeys() {
|
||||||
|
$this->controller->updateSharingKeys('6AD30804-BFFC-4EFC-97F8-20A126FA1709', null ,null);
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::delete
|
||||||
|
*/
|
||||||
|
public function testDelete() {
|
||||||
|
$result = $this->controller->delete('');
|
||||||
|
$this->assertTrue($result instanceof JSONResponse);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue