diff options
Diffstat (limited to 'tests/units')
-rw-r--r-- | tests/units/Base.php | 17 | ||||
-rw-r--r-- | tests/units/Core/Plugin/DirectoryTest.php | 44 | ||||
-rw-r--r-- | tests/units/Model/UserNotificationTest.php | 29 |
3 files changed, 72 insertions, 18 deletions
diff --git a/tests/units/Base.php b/tests/units/Base.php index 171f9b2b..16c34573 100644 --- a/tests/units/Base.php +++ b/tests/units/Base.php @@ -33,14 +33,15 @@ abstract class Base extends PHPUnit_Framework_TestCase } $this->container = new Pimple\Container; - $this->container->register(new Kanboard\ServiceProvider\HelperProvider); - $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider); - $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider); - $this->container->register(new Kanboard\ServiceProvider\ClassProvider); - $this->container->register(new Kanboard\ServiceProvider\NotificationProvider); - $this->container->register(new Kanboard\ServiceProvider\RouteProvider); - $this->container->register(new Kanboard\ServiceProvider\AvatarProvider); - $this->container->register(new Kanboard\ServiceProvider\FilterProvider); + $this->container->register(new Kanboard\ServiceProvider\HelperProvider()); + $this->container->register(new Kanboard\ServiceProvider\AuthenticationProvider()); + $this->container->register(new Kanboard\ServiceProvider\DatabaseProvider()); + $this->container->register(new Kanboard\ServiceProvider\ClassProvider()); + $this->container->register(new Kanboard\ServiceProvider\NotificationProvider()); + $this->container->register(new Kanboard\ServiceProvider\RouteProvider()); + $this->container->register(new Kanboard\ServiceProvider\AvatarProvider()); + $this->container->register(new Kanboard\ServiceProvider\FilterProvider()); + $this->container->register(new Kanboard\ServiceProvider\QueueProvider()); $this->container['dispatcher'] = new TraceableEventDispatcher( new EventDispatcher, diff --git a/tests/units/Core/Plugin/DirectoryTest.php b/tests/units/Core/Plugin/DirectoryTest.php new file mode 100644 index 00000000..13aef4b9 --- /dev/null +++ b/tests/units/Core/Plugin/DirectoryTest.php @@ -0,0 +1,44 @@ +<?php + +use Kanboard\Core\Plugin\Directory; + +require_once __DIR__.'/../../Base.php'; + +class DirectoryTest extends Base +{ + public function testIsCompatible() + { + $pluginDirectory = new Directory($this->container); + $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28')); + $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234')); + } + + public function testGetAvailablePlugins() + { + $plugins = array( + array( + 'title' => 'Plugin A', + 'compatible_version' => '1.0.30', + 'remote_install' => true, + ), + array( + 'title' => 'Plugin B', + 'compatible_version' => '1.0.29', + 'remote_install' => false, + ), + ); + + $this->container['httpClient'] + ->expects($this->once()) + ->method('getJson') + ->with('api_url') + ->will($this->returnValue($plugins)); + + $pluginDirectory = new Directory($this->container); + $availablePlugins = $pluginDirectory->getAvailablePlugins('api_url'); + + $this->assertCount(1, $availablePlugins); + $this->assertEquals('Plugin A', $availablePlugins[0]['title']); + } +} diff --git a/tests/units/Model/UserNotificationTest.php b/tests/units/Model/UserNotificationTest.php index 53034e20..42db54b4 100644 --- a/tests/units/Model/UserNotificationTest.php +++ b/tests/units/Model/UserNotificationTest.php @@ -109,7 +109,8 @@ class UserNotificationTest extends Base $this->assertEquals(2, $userModel->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); $this->assertEquals(3, $userModel->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); - $this->assertEquals(4, $userModel->create(array('username' => 'user3'))); + $this->assertEquals(4, $userModel->create(array('username' => 'user3', 'email' => '', 'notifications_enabled' => 1, 'is_active' => 0))); + $this->assertEquals(5, $userModel->create(array('username' => 'user4'))); $this->assertEquals(1, $groupModel->create('G1')); $this->assertEquals(2, $groupModel->create('G2')); @@ -117,6 +118,7 @@ class UserNotificationTest extends Base $this->assertTrue($groupMemberModel->addUser(1, 2)); $this->assertTrue($groupMemberModel->addUser(1, 3)); $this->assertTrue($groupMemberModel->addUser(1, 4)); + $this->assertTrue($groupMemberModel->addUser(1, 5)); $this->assertTrue($groupMemberModel->addUser(2, 2)); $this->assertTrue($groupMemberModel->addUser(2, 3)); @@ -143,26 +145,30 @@ class UserNotificationTest extends Base $this->assertEquals(1, $p->create(array('name' => 'UnitTest1'))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + + // User disabled + $this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0))); // No email + notifications disabled - $this->assertNotFalse($u->create(array('username' => 'user4'))); + $this->assertEquals(6, $u->create(array('username' => 'user5'))); // Nobody is member of any projects $this->assertEmpty($pp->getUsers(1)); $this->assertEmpty($n->getUsersWithNotificationEnabled(1)); // We allow all users to be member of our projects - $this->assertTrue($pp->addUser(1, 1, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 2, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 3, Role::PROJECT_MEMBER)); $this->assertTrue($pp->addUser(1, 4, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 5, Role::PROJECT_MEMBER)); + $this->assertTrue($pp->addUser(1, 6, Role::PROJECT_MEMBER)); $this->assertNotEmpty($pp->getUsers(1)); $users = $n->getUsersWithNotificationEnabled(1); @@ -185,16 +191,19 @@ class UserNotificationTest extends Base $this->assertTrue($pp->isEverybodyAllowed(1)); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); + $this->assertEquals(2, $u->create(array('username' => 'user1', 'email' => 'user1@here', 'notifications_enabled' => 1))); // No email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); + $this->assertEquals(3, $u->create(array('username' => 'user2', 'email' => '', 'notifications_enabled' => 1))); // Email + Notifications enabled - $this->assertNotFalse($u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + $this->assertEquals(4, $u->create(array('username' => 'user3', 'email' => 'user3@here', 'notifications_enabled' => 1))); + + // User disabled + $this->assertEquals(5, $u->create(array('username' => 'user4', 'email' => 'user3@here', 'notifications_enabled' => 1, 'is_active' => 0))); // No email + notifications disabled - $this->assertNotFalse($u->create(array('username' => 'user4'))); + $this->assertEquals(6, $u->create(array('username' => 'user5'))); $users = $n->getUsersWithNotificationEnabled(1); |