start fixing InternalControllerTest (wip)

This commit is contained in:
binsky 2023-06-20 13:55:57 +02:00
parent d501837b2c
commit 793304f90e
No known key found for this signature in database
GPG key ID: B438F7FA2E3AC98F
3 changed files with 105 additions and 59 deletions

View file

@ -9,6 +9,7 @@ use Test\TestCase;
class PassmanTestCase extends TestCase
{
public const APP_NAME = 'passman';
public string $userId = 'example';
public App $app;
public IAppContainer $appContainer;

View file

@ -48,7 +48,6 @@ class FileControllerTest extends PassmanTestCase
{
private FileController $controller;
private string $userId = 'example';
private EncryptService $encryptService;
private FileService $fileService;
private FileMapper $fileMapper;

View file

@ -23,8 +23,21 @@
namespace OCA\Passman\Controller;
use OCP\AppFramework\Http\JSONResponse;
use Test\TestCase;
use OCA\Passman\Db\CredentialMapper;
use OCA\Passman\Db\CredentialRevisionMapper;
use OCA\Passman\Db\ShareRequestMapper;
use OCA\Passman\Db\SharingACLMapper;
use OCA\Passman\Service\ActivityService;
use OCA\Passman\Service\CredentialRevisionService;
use OCA\Passman\Service\CredentialService;
use OCA\Passman\Service\EncryptService;
use OCA\Passman\Service\SettingsService;
use OCA\Passman\Service\ShareService;
use OCA\Passman\Tests\PassmanTestCase;
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IRequest;
use OCP\Notification\IManager;
/**
* Class InternalControllerTest
@ -32,69 +45,102 @@ use Test\TestCase;
* @package OCA\Passman\Controller
* @coversDefaultClass \OCA\Passman\Controller\InternalController
*/
class InternalControllerTest extends TestCase {
class InternalControllerTest extends PassmanTestCase
{
private $controller;
private $userId = 'john';
private $credentialService;
private InternalController $controller;
private CredentialService $credentialService;
public function setUp(): void
public function setUp(): void
{
$request = $this->getMockBuilder('OCP\IRequest')->getMock();
$config = $this->getMockBuilder('OCP\IConfig')->getMock();
$this->credentialService = $this->getMockBuilder('OCA\Passman\Service\CredentialService')
->disableOriginalConstructor()
->getMock();
$this->controller = new InternalController(
'passman', $request, $this->userId, $this->credentialService, $config
);
}
$config = $this->appContainer->get(IConfig::class);
$request = $this->appContainer->get(IRequest::class);
$notificationManager = $this->appContainer->get(IManager::class);
$appManager = $this->appContainer->get(IAppManager::class);
$settings = new SettingsService($this->userId, $config, self::APP_NAME);
$encryptService = new EncryptService($settings, $config);
/**
* @covers ::remind
*/
public function testRemind() {
$this->controller->remind(null);
$this->assertTrue(true);
}
/**
* @covers ::read
*/
public function testRead() {
$this->controller->read(null);
$this->assertTrue(true);
}
$credentialRevisionMapper = $this->appContainer->get(CredentialRevisionMapper::class);
$credentialRevisionService = new CredentialRevisionService($credentialRevisionMapper, $encryptService, $config);
/**
* @covers ::getAppVersion
*/
public function testGetAppVersion() {
$this->assertTrue(true);
}
$credentialMapper = $this->appContainer->get(CredentialMapper::class);
$sharingACLMapper = $this->appContainer->get(SharingACLMapper::class);
$shareRequestMapper = $this->appContainer->get(ShareRequestMapper::class);
/**
* @covers ::generatePerson
*/
public function testGeneratePerson() {
$this->assertTrue(true);
//$result = $this->controller->generatePerson();
//$this->assertTrue($result instanceof JSONResponse);
}
$shareService = new ShareService(
$sharingACLMapper,
$shareRequestMapper,
$credentialMapper,
$credentialRevisionService,
$encryptService,
$notificationManager
);
$this->credentialService = new CredentialService(
$credentialMapper,
$sharingACLMapper,
new ActivityService(),
$shareService,
$encryptService,
$credentialRevisionService,
$config
);
$this->controller = new InternalController(
self::APP_NAME,
$request,
$this->userId,
$this->credentialService,
$config,
$notificationManager,
$appManager
);
}
/**
* @covers ::getSettings
*/
public function testGetSettings() {
$result = $this->controller->getSettings();
$this->assertTrue($result instanceof JSONResponse);
}
/**
* @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 ::saveSettings
*/
public function testSaveSettings() {
$result = $this->controller->saveSettings('test', 'test');
$this->assertTrue(true);
}
/**
* @covers ::getAppVersion
*/
/*public function testGetAppVersion() {
$this->assertTrue(true);
}*/
/**
* @covers ::generatePerson
*/
/*public function testGeneratePerson() {
$this->assertTrue(true);
//$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);
}*/
}