Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/undo-ransomware/ransomware_detection.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Held <ilovemilk@wusa.io>2018-09-14 00:30:16 +0300
committerMatthias Held <ilovemilk@wusa.io>2018-09-14 00:30:16 +0300
commitd13f6eb2292046408b7f60f8b94d483a3be1733e (patch)
tree70d5df455915fcad4cd6bbb59549eee878819a6b
parente3c5bbfb1cf4ea5d19a3fa8ad017e58110cac800 (diff)
Add tests
Signed-off-by: Matthias Held <matthias.held@uni-konstanz.de>
-rw-r--r--lib/Settings/Personal.php14
-rw-r--r--tests/Unit/Settings/AdminSectionTest.php75
-rw-r--r--tests/Unit/Settings/AdminTest.php24
-rw-r--r--tests/Unit/Settings/PersonalSectionTest.php75
-rw-r--r--tests/Unit/Settings/PersonalTest.php78
5 files changed, 249 insertions, 17 deletions
diff --git a/lib/Settings/Personal.php b/lib/Settings/Personal.php
index 2d06957..7db2c73 100644
--- a/lib/Settings/Personal.php
+++ b/lib/Settings/Personal.php
@@ -24,39 +24,25 @@ namespace OCA\RansomwareDetection\Settings;
use OCP\Settings\ISettings;
use OCA\RansomwareDetection\AppInfo\Application;
use OCP\AppFramework\Http\TemplateResponse;
-use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IConfig;
-use OCP\IL10N;
class Personal implements ISettings
{
/** @var IConfig */
protected $config;
- /** @var ITimeFactory */
- protected $time;
-
- /** @var IL10N */
- protected $l10n;
-
/** @var string */
protected $userId;
/**
* @param IConfig $config
- * @param ITimeFactory $time
- * @param IL10N $l10n
* @param string $userId
*/
public function __construct(
IConfig $config,
- ITimeFactory $time,
- IL10N $l10n,
$userId
) {
$this->config = $config;
- $this->time = $time;
- $this->l10n = $l10n;
$this->userId = $userId;
}
diff --git a/tests/Unit/Settings/AdminSectionTest.php b/tests/Unit/Settings/AdminSectionTest.php
new file mode 100644
index 0000000..d2b32a4
--- /dev/null
+++ b/tests/Unit/Settings/AdminSectionTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @copyright Copyright (c) 2018 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\tests\Unit\Settings;
+
+use OCA\RansomwareDetection\AppInfo\Application;
+use OCA\RansomwareDetection\Settings\AdminSection;
+use OCP\IURLGenerator;
+use OCP\IL10N;
+use Test\TestCase;
+
+class AdminSectionTest extends TestCase {
+
+ /** @var AdminSection */
+ private $adminSection;
+
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
+
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ protected $l;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->urlGenerator = $this->getMockForAbstractClass( IURLGenerator::class, array(), '', FALSE, TRUE, TRUE, array( 'imagePath' ) );
+ $this->l = $this->getMockForAbstractClass( IL10N::class, array(), '', FALSE, TRUE, TRUE, array( 't' ) );
+
+ $this->adminSection = new AdminSection($this->urlGenerator, $this->l);
+ }
+
+ public function testGetIcon() {
+ $this->urlGenerator->expects($this->once())
+ ->method('imagePath')
+ ->with('ransomware_detection', 'app-dark.svg')
+ ->willReturn('app-dark.svg');
+
+ $this->assertSame('app-dark.svg', $this->adminSection->getIcon());
+ }
+
+ public function testGetID() {
+ $this->assertSame(Application::APP_ID, $this->adminSection->getID());
+ }
+
+ public function testGetName() {
+ $this->l->expects($this->once())
+ ->method('t')
+ ->with('Ransomware detection')
+ ->willReturn('Ransomware detection');
+
+ $this->assertSame('Ransomware detection', $this->adminSection->getName());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(15, $this->adminSection->getPriority());
+ }
+}
diff --git a/tests/Unit/Settings/AdminTest.php b/tests/Unit/Settings/AdminTest.php
index 4dc7940..440445a 100644
--- a/tests/Unit/Settings/AdminTest.php
+++ b/tests/Unit/Settings/AdminTest.php
@@ -43,15 +43,33 @@ class AdminTest extends TestCase {
$this->admin = new Admin($this->config);
}
- public function testGetForm() {
+ public function dataGetForm()
+ {
+ return [
+ ['suspicionLevel' => 2, 'minimumSequenceLength' => 5, 'expireDays' => 7, 'activeSuspicionLevel' => ['code' => 2, 'name' => 'Suspicious'], 'suspicionLevels' => [['code' => 1, 'name' => 'Maybe suspicious']]],
+ ['suspicionLevel' => 1, 'minimumSequenceLength' => 5, 'expireDays' => 7, 'activeSuspicionLevel' => ['code' => 1, 'name' => 'Maybe suspicious'], 'suspicionLevels' => [['code' => 2, 'name' => 'Suspicious']]],
+ ['suspicionLevel' => 3, 'minimumSequenceLength' => 5, 'expireDays' => 7, 'activeSuspicionLevel' => [], 'suspicionLevels' => [['code' => 1, 'name' => 'Maybe suspicious'], ['code' => 2, 'name' => 'Suspicious']]],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetForm
+ *
+ * @param int $suspicionLevel
+ * @param int $minimumSequenceLength
+ * @param int $expireDays
+ * @param array $activeSuspicionLevel
+ * @param array $suspicionLevels
+ */
+ public function testGetForm($suspicionLevel, $minimumSequenceLength, $expireDays, $activeSuspicionLevel, $suspicionLevels) {
$this->config->expects($this->any())
->method('getAppValue')
->withConsecutive([Application::APP_ID, 'suspicion_level', $this->anything()], [Application::APP_ID, 'minimum_sequence_length', $this->anything()], [Application::APP_ID, 'expire_days', $this->anything()])
- ->willReturnOnConsecutiveCalls(2, 5, 7);
+ ->willReturnOnConsecutiveCalls($suspicionLevel, $minimumSequenceLength, $expireDays);
$expected = new TemplateResponse(Application::APP_ID, 'admin',
- ['minimum_sequence_length' => 5, 'active_suspicion_level' => ['code' => 2, 'name' => 'Suspicious'], 'suspicion_levels' => [['code' => 1, 'name' => 'Maybe suspicious']], 'expire_days' => 7], '');
+ ['minimum_sequence_length' => $minimumSequenceLength, 'active_suspicion_level' => $activeSuspicionLevel, 'suspicion_levels' => $suspicionLevels, 'expire_days' => $expireDays], '');
$this->assertEquals($expected, $this->admin->getForm());
}
diff --git a/tests/Unit/Settings/PersonalSectionTest.php b/tests/Unit/Settings/PersonalSectionTest.php
new file mode 100644
index 0000000..3e04a18
--- /dev/null
+++ b/tests/Unit/Settings/PersonalSectionTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @copyright Copyright (c) 2018 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\tests\Unit\Settings;
+
+use OCA\RansomwareDetection\AppInfo\Application;
+use OCA\RansomwareDetection\Settings\PersonalSection;
+use OCP\IURLGenerator;
+use OCP\IL10N;
+use Test\TestCase;
+
+class PersonalSectionTest extends TestCase {
+
+ /** @var PersonalSection */
+ private $personalSection;
+
+ /** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
+ protected $urlGenerator;
+
+ /** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
+ protected $l;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->urlGenerator = $this->getMockForAbstractClass( IURLGenerator::class, array(), '', FALSE, TRUE, TRUE, array( 'imagePath' ) );
+ $this->l = $this->getMockForAbstractClass( IL10N::class, array(), '', FALSE, TRUE, TRUE, array( 't' ) );
+
+ $this->personalSection = new PersonalSection($this->urlGenerator, $this->l);
+ }
+
+ public function testGetIcon() {
+ $this->urlGenerator->expects($this->once())
+ ->method('imagePath')
+ ->with('ransomware_detection', 'app-dark.svg')
+ ->willReturn('app-dark.svg');
+
+ $this->assertSame('app-dark.svg', $this->personalSection->getIcon());
+ }
+
+ public function testGetID() {
+ $this->assertSame(Application::APP_ID, $this->personalSection->getID());
+ }
+
+ public function testGetName() {
+ $this->l->expects($this->once())
+ ->method('t')
+ ->with('Ransomware detection')
+ ->willReturn('Ransomware detection');
+
+ $this->assertSame('Ransomware detection', $this->personalSection->getName());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(15, $this->personalSection->getPriority());
+ }
+}
diff --git a/tests/Unit/Settings/PersonalTest.php b/tests/Unit/Settings/PersonalTest.php
new file mode 100644
index 0000000..e05d47b
--- /dev/null
+++ b/tests/Unit/Settings/PersonalTest.php
@@ -0,0 +1,78 @@
+<?php
+
+/**
+ * @copyright Copyright (c) 2018 Matthias Held <matthias.held@uni-konstanz.de>
+ * @author Matthias Held <matthias.held@uni-konstanz.de>
+ * @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 <https://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\RansomwareDetection\tests\Unit\Settings;
+
+use OCA\RansomwareDetection\AppInfo\Application;
+use OCA\RansomwareDetection\Settings\Personal;
+use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IConfig;
+use Test\TestCase;
+
+class PersonalTest extends TestCase {
+
+ /** @var Personal */
+ private $personal;
+
+ /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
+ protected $config;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->config = $this->getMockForAbstractClass( IConfig::class, array(), '', FALSE, TRUE, TRUE, array( 'getUserValue' ) );
+
+ $this->personal = new Personal($this->config, 'john');
+ }
+
+ public function dataGetForm() {
+ return [
+ ['colorMode' => 0, 'colorActive' => ['code' => 0, 'name' => 'Normal'], 'color' => ['code' => 1, 'name' => 'Color blind']],
+ ['colorMode' => 1, 'colorActive' => ['code' => 1, 'name' => 'Color blind'], 'color' => ['code' => 0, 'name' => 'Normal']],
+ ];
+ }
+
+ /**
+ * @dataProvider dataGetForm
+ *
+ * @param int $colorMode
+ * @param array $colorActive
+ * @param array $color
+ */
+ public function testGetForm($colorMode, $colorActive, $color) {
+ $this->config->expects($this->once())
+ ->method('getUserValue')
+ ->willReturn($colorMode);
+
+ $expected = new TemplateResponse(Application::APP_ID, 'personal',
+ ['color_active' => $colorActive, 'color' => $color,], '');
+
+ $this->assertEquals($expected, $this->personal->getForm());
+ }
+
+ public function testGetSection() {
+ $this->assertSame(Application::APP_ID, $this->personal->getSection());
+ }
+
+ public function testGetPriority() {
+ $this->assertSame(40, $this->personal->getPriority());
+ }
+}