Add tests for activity classes
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
58
tests/unit/Activity/ChangeSetTest.php
Normal file
58
tests/unit/Activity/ChangeSetTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\Deck\Activity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
||||
class ChangeSetTest extends TestCase {
|
||||
|
||||
public function setUp() {
|
||||
}
|
||||
|
||||
public function testChangeSetScalar() {
|
||||
$changeSet = new ChangeSet('A', 'B');
|
||||
$this->assertEquals('A', $changeSet->getBefore());
|
||||
$this->assertEquals('B', $changeSet->getAfter());
|
||||
$this->assertFalse($changeSet->getDiff());
|
||||
$changeSet->enableDiff();
|
||||
$this->assertTrue($changeSet->getDiff());
|
||||
}
|
||||
|
||||
public function testChangeSetObject() {
|
||||
$a = new \stdClass;
|
||||
$a->data = 'A';
|
||||
$b = new \stdClass;
|
||||
$b->data = 'B';
|
||||
$changeSet = new ChangeSet($a, $b);
|
||||
$this->assertEquals('A', $changeSet->getBefore()->data);
|
||||
$this->assertEquals('B', $changeSet->getAfter()->data);
|
||||
$this->assertNotSame($a, $changeSet->getBefore());
|
||||
$this->assertNotSame($b, $changeSet->getAfter());
|
||||
$this->assertFalse($changeSet->getDiff());
|
||||
$changeSet->enableDiff();
|
||||
$this->assertTrue($changeSet->getDiff());
|
||||
}
|
||||
|
||||
}
|
||||
119
tests/unit/Activity/DeckProviderTest.php
Normal file
119
tests/unit/Activity/DeckProviderTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\Deck\Activity;
|
||||
|
||||
use OCP\Activity\IEvent;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||
|
||||
class DeckProviderTest extends TestCase {
|
||||
|
||||
/** @var DeckProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var ActivityManager|MockObject */
|
||||
private $activityManager;
|
||||
|
||||
/** @var string */
|
||||
private $userId = 'admin';
|
||||
|
||||
public function setUp() {
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
$this->provider = new DeckProvider($this->urlGenerator, $this->activityManager, $this->userId);
|
||||
}
|
||||
|
||||
private function mockEvent($objectType, $objectId, $objectName, $subject, $subjectParameters = []) {
|
||||
$data = [];
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->any())->method('getApp')->willReturn('deck');
|
||||
$event->expects($this->any())->method('getSubject')->willReturn($subject);
|
||||
$event->expects($this->any())->method('getSubjectParameters')->willReturn($subjectParameters);
|
||||
$event->expects($this->any())->method('getObjectType')->willReturn($objectType);
|
||||
$event->expects($this->any())->method('getObjectId')->willReturn($objectId);
|
||||
$event->expects($this->any())->method('getObjectName')->willReturn($objectName);
|
||||
$event->expects($this->any())->method('getAuthor')->willReturn('admin');
|
||||
$event->expects($this->any())->method('getMessage')->willReturn('');
|
||||
$event->expects($this->any())->method('setIcon')->will($this->returnCallback(function($icon) use (&$data) {
|
||||
$data['icon'] = $icon;
|
||||
}));
|
||||
$event->expects($this->any())->method('getIcon')->will(
|
||||
$this->returnCallback(function() use (&$data) {
|
||||
return array_key_exists('icon', $data) ? $data['icon'] : 'noicon';
|
||||
})
|
||||
);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testParseFailureApp() {
|
||||
$event = $this->createMock(IEvent::class);
|
||||
$event->expects($this->once())->method('getApp')->willReturn('notdeck');
|
||||
$this->provider->parse('en_US', $event, $event);
|
||||
}
|
||||
|
||||
public function dataEventIcons() {
|
||||
return [
|
||||
[ActivityManager::SUBJECT_CARD_MOVE_STACK, 'deck', 'deck-dark.svg'],
|
||||
[ActivityManager::SUBJECT_CARD_UPDATE, 'files', 'change.svg'],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataEventIcons
|
||||
* @param $subject
|
||||
* @param $icon
|
||||
*/
|
||||
public function testEventIcons($subject, $app, $icon) {
|
||||
$event = $this->mockEvent(
|
||||
ActivityManager::DECK_OBJECT_BOARD, 1, 'Board',
|
||||
$subject);
|
||||
$this->urlGenerator->expects($this->any())
|
||||
->method('imagePath')
|
||||
->will($this->returnCallback(function($a, $i) {
|
||||
return $a . '/' . $i;
|
||||
}));
|
||||
$this->provider->parse('en_US', $event);
|
||||
$this->assertEquals($app . '/' . $icon, $event->getIcon());
|
||||
}
|
||||
|
||||
public function testDeckUrl() {
|
||||
$this->urlGenerator->expects($this->once())
|
||||
->method('linkToRoute')
|
||||
->with('deck.page.index')
|
||||
->willReturn('http://localhost/index.php/apps/deck/');
|
||||
$this->assertEquals(
|
||||
'http://localhost/index.php/apps/deck/#!board/1/card/1',
|
||||
$this->provider->deckUrl('board/1/card/1')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
81
tests/unit/Activity/FilterTest.php
Normal file
81
tests/unit/Activity/FilterTest.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\Deck\Activity;
|
||||
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||
|
||||
class FilterTest extends TestCase {
|
||||
|
||||
/** @var Filter */
|
||||
private $filter;
|
||||
|
||||
/** @var IL10N|MockObject */
|
||||
private $l10n;
|
||||
|
||||
/** @var IURLGenerator|MockObject */
|
||||
private $urlGenerator;
|
||||
|
||||
public function setUp() {
|
||||
$this->l10n = $this->createMock(IL10N::class);
|
||||
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||
$this->filter = new Filter($this->l10n, $this->urlGenerator);
|
||||
}
|
||||
|
||||
public function testGetIdentifier() {
|
||||
$this->assertEquals('deck', $this->filter->getIdentifier());
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->l10n->expects($this->once())
|
||||
->method('t')
|
||||
->with('Deck')
|
||||
->willReturn('Deck');
|
||||
$this->assertEquals('Deck', $this->filter->getName());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertEquals(90, $this->filter->getPriority());
|
||||
}
|
||||
|
||||
public function testGetIcon() {
|
||||
$this->urlGenerator->expects($this->once())
|
||||
->method('imagePath')
|
||||
->with('deck', 'deck-dark.svg')
|
||||
->willReturn('http://localhost/apps/deck/img/deck-dark.svg');
|
||||
$this->assertEquals('http://localhost/apps/deck/img/deck-dark.svg', $this->filter->getIcon());
|
||||
}
|
||||
|
||||
public function testFilterTypes() {
|
||||
$data = ['deck_board', 'deck_card'];
|
||||
$this->assertEquals($data, $this->filter->filterTypes($data));
|
||||
}
|
||||
|
||||
public function testAllowedApps() {
|
||||
$this->assertEquals(['deck'], $this->filter->allowedApps());
|
||||
}
|
||||
|
||||
}
|
||||
65
tests/unit/Activity/SettingTest.php
Normal file
65
tests/unit/Activity/SettingTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @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\Deck\Activity;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SettingTest extends TestCase {
|
||||
|
||||
/** @var Setting */
|
||||
private $setting;
|
||||
|
||||
public function setUp() {
|
||||
$this->setting = new Setting();
|
||||
}
|
||||
|
||||
public function testGetIdentifier() {
|
||||
$this->assertEquals('deck', $this->setting->getIdentifier());
|
||||
}
|
||||
|
||||
public function testGetName() {
|
||||
$this->assertEquals('Deck', $this->setting->getName());
|
||||
}
|
||||
|
||||
public function testGetPriority() {
|
||||
$this->assertEquals(90, $this->setting->getPriority());
|
||||
}
|
||||
|
||||
public function testCanChangeStream() {
|
||||
$this->assertTrue($this->setting->canChangeStream());
|
||||
}
|
||||
|
||||
public function testIsDefaultEnabledStream() {
|
||||
$this->assertTrue($this->setting->isDefaultEnabledStream());
|
||||
}
|
||||
|
||||
public function testCanChangeMail() {
|
||||
$this->assertTrue($this->setting->canChangeMail());
|
||||
}
|
||||
|
||||
public function testIsDefaultEnabledMail() {
|
||||
$this->assertFalse($this->setting->isDefaultEnabledMail());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user