From 807b4149ce1be94f349e99c434cec1242b3e63f3 Mon Sep 17 00:00:00 2001 From: brantje Date: Wed, 4 Jan 2017 11:55:32 +0100 Subject: [PATCH] Add some tests --- tests/unit/controller/FileControllerTest.php | 99 ++++++++++++++++ .../controller/InternalControllerTest.php | 32 ++++++ .../controller/SettingsControllerTest.php | 9 +- tests/unit/controller/VaultControllerTest.php | 108 ++++++++++++++++++ 4 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 tests/unit/controller/FileControllerTest.php create mode 100644 tests/unit/controller/VaultControllerTest.php diff --git a/tests/unit/controller/FileControllerTest.php b/tests/unit/controller/FileControllerTest.php new file mode 100644 index 00000000..dc68536d --- /dev/null +++ b/tests/unit/controller/FileControllerTest.php @@ -0,0 +1,99 @@ +. + * + */ + +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); + } +} \ No newline at end of file diff --git a/tests/unit/controller/InternalControllerTest.php b/tests/unit/controller/InternalControllerTest.php index 5326b0db..0c62b6c7 100644 --- a/tests/unit/controller/InternalControllerTest.php +++ b/tests/unit/controller/InternalControllerTest.php @@ -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 */ @@ -65,4 +80,21 @@ class InternalControllerTest extends PHPUnit_Framework_TestCase { $result = $this->controller->generatePerson(); $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); + } + } \ No newline at end of file diff --git a/tests/unit/controller/SettingsControllerTest.php b/tests/unit/controller/SettingsControllerTest.php index 808e7b89..1f16af7c 100644 --- a/tests/unit/controller/SettingsControllerTest.php +++ b/tests/unit/controller/SettingsControllerTest.php @@ -58,13 +58,20 @@ class SettingsControllerTest extends PHPUnit_Framework_TestCase { $result = $this->controller->getForm(); $this->assertTrue($result instanceof TemplateResponse); } + /** + * @covers ::getSection + */ + public function testGetSection() { + $result = $this->controller->getSection(); + $this->assertTrue(is_string($result)); + } /** * @covers ::getPriority */ public function testGetPriority() { $result = $this->controller->getPriority(); - $this->assertTrue($result === 0); + $this->assertTrue(is_numeric($result)); } /** diff --git a/tests/unit/controller/VaultControllerTest.php b/tests/unit/controller/VaultControllerTest.php new file mode 100644 index 00000000..f44b8cb6 --- /dev/null +++ b/tests/unit/controller/VaultControllerTest.php @@ -0,0 +1,108 @@ +. + * + */ + +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); + } +} \ No newline at end of file