diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/units/Auth/LdapTest.php | 230 | ||||
-rw-r--r-- | tests/units/Core/PluginLoaderTest.php | 23 | ||||
-rw-r--r-- | tests/units/Core/TemplateTest.php | 28 | ||||
-rw-r--r-- | tests/units/Model/AclTest.php | 12 | ||||
-rw-r--r-- | tests/units/Model/FileTest.php | 77 | ||||
-rw-r--r-- | tests/units/Model/HourlyRateTest.php | 43 | ||||
-rw-r--r-- | tests/units/Model/ProjectTest.php | 2 | ||||
-rw-r--r-- | tests/units/Model/SubtaskTest.php | 130 | ||||
-rw-r--r-- | tests/units/Model/SubtaskTimeTrackingTest.php | 26 |
9 files changed, 498 insertions, 73 deletions
diff --git a/tests/units/Auth/LdapTest.php b/tests/units/Auth/LdapTest.php index 0f2ad24e..a52b8cf8 100644 --- a/tests/units/Auth/LdapTest.php +++ b/tests/units/Auth/LdapTest.php @@ -37,8 +37,6 @@ class LdapTest extends \Base { parent::setup(); - $this->ldap = $ldap = new Ldap($this->container); - self::$functions = $this ->getMockBuilder('stdClass') ->setMethods(array( @@ -57,36 +55,69 @@ class LdapTest extends \Base self::$functions = null; } + public function testGetAttributes() + { + $ldap = new Ldap($this->container); + $this->assertCount(3, $ldap->getProfileAttributes()); + $this->assertContains(LDAP_ACCOUNT_FULLNAME, $ldap->getProfileAttributes()); + $this->assertContains(LDAP_ACCOUNT_EMAIL, $ldap->getProfileAttributes()); + $this->assertContains(LDAP_ACCOUNT_MEMBEROF, $ldap->getProfileAttributes()); + } + public function testConnectSuccess() { + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapServer')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapServer') + ->will($this->returnValue('my_ldap_server')); + self::$functions ->expects($this->once()) ->method('ldap_connect') ->with( $this->equalTo('my_ldap_server'), - $this->equalTo(389) + $this->equalTo($ldap->getLdapPort()) ) ->will($this->returnValue('my_ldap_resource')); - $this->assertNotFalse($this->ldap->connect('my_ldap_server')); + $this->assertNotFalse($ldap->connect()); } public function testConnectFailure() { + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapServer')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapServer') + ->will($this->returnValue('my_ldap_server')); + self::$functions ->expects($this->once()) ->method('ldap_connect') ->with( $this->equalTo('my_ldap_server'), - $this->equalTo(389) + $this->equalTo($ldap->getLdapPort()) ) ->will($this->returnValue(false)); - $this->assertFalse($this->ldap->connect('my_ldap_server')); + $this->assertFalse($ldap->connect()); } public function testBindAnonymous() { + $ldap = new Ldap($this->container); + self::$functions ->expects($this->once()) ->method('ldap_bind') @@ -97,11 +128,22 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($this->ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'anonymous')); } public function testBindUser() { + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapUserPattern')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapUserPattern') + ->will($this->returnValue('uid=my_user')); + self::$functions ->expects($this->once()) ->method('ldap_bind') @@ -112,11 +154,27 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($this->ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user', 'uid=%s', 'something')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'user')); } public function testBindProxy() { + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapUsername', 'getLdapPassword')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapUsername') + ->will($this->returnValue('someone')); + + $ldap + ->expects($this->once()) + ->method('getLdapPassword') + ->will($this->returnValue('something')); + self::$functions ->expects($this->once()) ->method('ldap_bind') @@ -127,7 +185,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertTrue($this->ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy', 'someone', 'something')); + $this->assertTrue($ldap->bind('my_ldap_connection', 'my_user', 'my_password', 'proxy')); } public function testSearchSuccess() @@ -160,6 +218,22 @@ class LdapTest extends \Base 'is_ldap_user' => 1, ); + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapUserPattern') + ->will($this->returnValue('uid=my_user')); + + $ldap + ->expects($this->once()) + ->method('getLdapBaseDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + self::$functions ->expects($this->at(0)) ->method('ldap_search') @@ -167,7 +241,7 @@ class LdapTest extends \Base $this->equalTo('my_ldap_connection'), $this->equalTo('ou=People,dc=kanboard,dc=local'), $this->equalTo('uid=my_user'), - $this->equalTo($this->ldap->getProfileAttributes()) + $this->equalTo($ldap->getProfileAttributes()) ) ->will($this->returnValue('my_result_identifier')); @@ -190,7 +264,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(true)); - $this->assertEquals($expected, $this->ldap->getProfile('my_ldap_connection', 'my_user', 'my_password', 'ou=People,dc=kanboard,dc=local', 'uid=%s')); + $this->assertEquals($expected, $ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); } public function testSearchWithBadPassword() @@ -214,6 +288,22 @@ class LdapTest extends \Base ) ); + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapUserPattern') + ->will($this->returnValue('uid=my_user')); + + $ldap + ->expects($this->once()) + ->method('getLdapBaseDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + self::$functions ->expects($this->at(0)) ->method('ldap_search') @@ -221,7 +311,7 @@ class LdapTest extends \Base $this->equalTo('my_ldap_connection'), $this->equalTo('ou=People,dc=kanboard,dc=local'), $this->equalTo('uid=my_user'), - $this->equalTo($this->ldap->getProfileAttributes()) + $this->equalTo($ldap->getProfileAttributes()) ) ->will($this->returnValue('my_result_identifier')); @@ -244,11 +334,27 @@ class LdapTest extends \Base ) ->will($this->returnValue(false)); - $this->assertFalse($this->ldap->getProfile('my_ldap_connection', 'my_user', 'my_password', 'ou=People,dc=kanboard,dc=local', 'uid=%s')); + $this->assertFalse($ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); } public function testSearchWithUserNotFound() { + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getLdapUserPattern', 'getLdapBaseDn')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('getLdapUserPattern') + ->will($this->returnValue('uid=my_user')); + + $ldap + ->expects($this->once()) + ->method('getLdapBaseDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + self::$functions ->expects($this->at(0)) ->method('ldap_search') @@ -256,7 +362,7 @@ class LdapTest extends \Base $this->equalTo('my_ldap_connection'), $this->equalTo('ou=People,dc=kanboard,dc=local'), $this->equalTo('uid=my_user'), - $this->equalTo($this->ldap->getProfileAttributes()) + $this->equalTo($ldap->getProfileAttributes()) ) ->will($this->returnValue('my_result_identifier')); @@ -269,7 +375,7 @@ class LdapTest extends \Base ) ->will($this->returnValue(array())); - $this->assertFalse($this->ldap->getProfile('my_ldap_connection', 'my_user', 'my_password', 'ou=People,dc=kanboard,dc=local', 'uid=%s')); + $this->assertFalse($ldap->getProfile('my_ldap_connection', 'my_user', 'my_password')); } public function testSuccessfulAuthentication() @@ -475,4 +581,98 @@ class LdapTest extends \Base $this->assertFalse($ldap->authenticate('user', 'password')); } + + public function testLookup() + { + $entries = array( + 'count' => 1, + 0 => array( + 'count' => 2, + 'dn' => 'uid=my_user,ou=People,dc=kanboard,dc=local', + 'displayname' => array( + 'count' => 1, + 0 => 'My LDAP user', + ), + 'mail' => array( + 'count' => 2, + 0 => 'user1@localhost', + 1 => 'user2@localhost', + ), + 'samaccountname' => array( + 'count' => 1, + 0 => 'my_ldap_user', + ), + 0 => 'displayname', + 1 => 'mail', + 2 => 'samaccountname', + ) + ); + + $expected = array( + 'username' => 'my_ldap_user', + 'name' => 'My LDAP user', + 'email' => 'user1@localhost', + 'is_admin' => 0, + 'is_project_admin' => 0, + 'is_ldap_user' => 1, + ); + + $ldap = $this + ->getMockBuilder('\Auth\Ldap') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('connect', 'getLdapUserPattern', 'getLdapBaseDn', 'getLdapAccountId')) + ->getMock(); + + $ldap + ->expects($this->once()) + ->method('connect') + ->will($this->returnValue('my_ldap_connection')); + + $ldap + ->expects($this->once()) + ->method('getLdapUserPattern') + ->will($this->returnValue('sAMAccountName=my_user')); + + $ldap + ->expects($this->any()) + ->method('getLdapAccountId') + ->will($this->returnValue('samaccountname')); + + $ldap + ->expects($this->once()) + ->method('getLdapBaseDn') + ->will($this->returnValue('ou=People,dc=kanboard,dc=local')); + + self::$functions + ->expects($this->at(0)) + ->method('ldap_bind') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo(null), + $this->equalTo(null) + ) + ->will($this->returnValue(true)); + + self::$functions + ->expects($this->at(1)) + ->method('ldap_search') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('ou=People,dc=kanboard,dc=local'), + $this->equalTo('(&(sAMAccountName=my_user)(mail=user@localhost))'), + $this->equalTo($ldap->getProfileAttributes()) + ) + ->will($this->returnValue('my_result_identifier')); + + self::$functions + ->expects($this->at(2)) + ->method('ldap_get_entries') + ->with( + $this->equalTo('my_ldap_connection'), + $this->equalTo('my_result_identifier') + ) + ->will($this->returnValue($entries)); + + $this->assertEquals($expected, $ldap->lookup('my_user', 'user@localhost')); + } } diff --git a/tests/units/Core/PluginLoaderTest.php b/tests/units/Core/PluginLoaderTest.php new file mode 100644 index 00000000..62327f01 --- /dev/null +++ b/tests/units/Core/PluginLoaderTest.php @@ -0,0 +1,23 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Core\PluginLoader; + +class PluginLoaderTest extends Base +{ + public function testGetSchemaVersion() + { + $p = new PluginLoader($this->container); + $this->assertEquals(0, $p->getSchemaVersion('not_found')); + + $this->assertTrue($p->setSchemaVersion('plugin1', 1)); + $this->assertEquals(1, $p->getSchemaVersion('plugin1')); + + $this->assertTrue($p->setSchemaVersion('plugin2', 33)); + $this->assertEquals(33, $p->getSchemaVersion('plugin2')); + + $this->assertTrue($p->setSchemaVersion('plugin1', 2)); + $this->assertEquals(2, $p->getSchemaVersion('plugin1')); + } +} diff --git a/tests/units/Core/TemplateTest.php b/tests/units/Core/TemplateTest.php new file mode 100644 index 00000000..9833397b --- /dev/null +++ b/tests/units/Core/TemplateTest.php @@ -0,0 +1,28 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Core\Template; + +class TemplateTest extends Base +{ + public function testGetTemplateFile() + { + $t = new Template($this->container); + $this->assertStringEndsWith('app/Core/../Template/a/b.php', $t->getTemplateFile('a/b')); + } + + public function testGetPluginTemplateFile() + { + $t = new Template($this->container); + $this->assertStringEndsWith('app/Core/../../plugins/Myplugin/Template/a/b.php', $t->getTemplateFile('myplugin:a/b')); + } + + public function testGetOverridedTemplateFile() + { + $t = new Template($this->container); + $t->setTemplateOverride('a/b', 'myplugin:c'); + $this->assertStringEndsWith('app/Core/../../plugins/Myplugin/Template/c.php', $t->getTemplateFile('a/b')); + $this->assertStringEndsWith('app/Core/../Template/d.php', $t->getTemplateFile('d')); + } +} diff --git a/tests/units/Model/AclTest.php b/tests/units/Model/AclTest.php index fef03990..3cb28a77 100644 --- a/tests/units/Model/AclTest.php +++ b/tests/units/Model/AclTest.php @@ -290,4 +290,16 @@ class AclTest extends Base $this->assertFalse($acl->isAllowed('task', 'remove', 1)); $this->assertTrue($acl->isAllowed('app', 'index', 1)); } + + public function testExtend() + { + $acl = new Acl($this->container); + + $this->assertFalse($acl->isProjectManagerAction('plop', 'show')); + + $acl->extend('project_manager_acl', array('plop' => '*')); + + $this->assertTrue($acl->isProjectManagerAction('plop', 'show')); + $this->assertTrue($acl->isProjectManagerAction('swimlane', 'index')); + } } diff --git a/tests/units/Model/FileTest.php b/tests/units/Model/FileTest.php index da00917d..e7520c89 100644 --- a/tests/units/Model/FileTest.php +++ b/tests/units/Model/FileTest.php @@ -9,6 +9,17 @@ use Model\Project; class FileTest extends Base { + public function setUp() + { + parent::setUp(); + + $this->container['objectStorage'] = $this + ->getMockBuilder('\Core\ObjectStorage\FileStorage') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('put', 'moveFile', 'remove')) + ->getMock(); + } + public function testCreation() { $p = new Project($this->container); @@ -85,13 +96,32 @@ class FileTest extends Base public function testUploadScreenshot() { $p = new Project($this->container); - $f = new File($this->container); $tc = new TaskCreation($this->container); $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->uploadScreenshot(1, 1, base64_encode('image data'))); + $data = base64_encode('image data'); + + $f = $this + ->getMockBuilder('\Model\File') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('generateThumbnailFromData')) + ->getMock(); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with( + $this->stringContains('1/1/'), + $this->equalTo(base64_decode($data)) + ) + ->will($this->returnValue(true)); + + $f->expects($this->once()) + ->method('generateThumbnailFromData'); + + $this->assertEquals(1, $f->uploadScreenshot(1, 1, $data)); $file = $f->getById(1); $this->assertNotEmpty($file); @@ -113,7 +143,18 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', base64_encode('file data'))); + $data = base64_encode('file data'); + + $this->container['objectStorage'] + ->expects($this->once()) + ->method('put') + ->with( + $this->stringContains('1/1/'), + $this->equalTo(base64_decode($data)) + ) + ->will($this->returnValue(true)); + + $this->assertEquals(1, $f->uploadContent(1, 1, 'my file.pdf', $data)); $file = $f->getById(1); $this->assertNotEmpty($file); @@ -170,9 +211,33 @@ class FileTest extends Base $this->assertEquals(1, $p->create(array('name' => 'test'))); $this->assertEquals(1, $tc->create(array('project_id' => 1, 'title' => 'test'))); - $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo', 10)); - $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo', 10)); - $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo', 10)); + $this->assertEquals(1, $f->create(1, 'B.pdf', '/tmp/foo1', 10)); + $this->assertEquals(2, $f->create(1, 'A.png', '/tmp/foo2', 10)); + $this->assertEquals(3, $f->create(1, 'D.doc', '/tmp/foo3', 10)); + + $this->container['objectStorage'] + ->expects($this->at(0)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo2') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(1)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo1') + ) + ->will($this->returnValue(true)); + + $this->container['objectStorage'] + ->expects($this->at(2)) + ->method('remove') + ->with( + $this->equalTo('/tmp/foo3') + ) + ->will($this->returnValue(true)); $this->assertTrue($f->remove(2)); diff --git a/tests/units/Model/HourlyRateTest.php b/tests/units/Model/HourlyRateTest.php deleted file mode 100644 index ffc0d87e..00000000 --- a/tests/units/Model/HourlyRateTest.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -require_once __DIR__.'/../Base.php'; - -use Model\User; -use Model\HourlyRate; - -class HourlyRateTest extends Base -{ - public function testCreation() - { - $hr = new HourlyRate($this->container); - $this->assertEquals(1, $hr->create(1, 32.4, 'EUR', '2015-01-01')); - $this->assertEquals(2, $hr->create(1, 42, 'CAD', '2015-02-01')); - - $rates = $hr->getAllByUser(0); - $this->assertEmpty($rates); - - $rates = $hr->getAllByUser(1); - $this->assertNotEmpty($rates); - $this->assertCount(2, $rates); - - $this->assertEquals(42, $rates[0]['rate']); - $this->assertEquals('CAD', $rates[0]['currency']); - $this->assertEquals('2015-02-01', date('Y-m-d', $rates[0]['date_effective'])); - - $this->assertEquals(32.4, $rates[1]['rate']); - $this->assertEquals('EUR', $rates[1]['currency']); - $this->assertEquals('2015-01-01', date('Y-m-d', $rates[1]['date_effective'])); - - $this->assertEquals(0, $hr->getCurrentRate(0)); - $this->assertEquals(42, $hr->getCurrentRate(1)); - - $this->assertTrue($hr->remove(2)); - $this->assertEquals(32.4, $hr->getCurrentRate(1)); - - $this->assertTrue($hr->remove(1)); - $this->assertEquals(0, $hr->getCurrentRate(1)); - - $rates = $hr->getAllByUser(1); - $this->assertEmpty($rates); - } -} diff --git a/tests/units/Model/ProjectTest.php b/tests/units/Model/ProjectTest.php index 97357796..9d7b6c0d 100644 --- a/tests/units/Model/ProjectTest.php +++ b/tests/units/Model/ProjectTest.php @@ -26,7 +26,7 @@ class ProjectTest extends Base $this->assertNotFalse($p->create(array('name' => 'UnitTest '.$locale)), 'Unable to create project with '.$locale.':'.$language); } - Translator::load('en_US'); + Translator::unload(); } public function testCreation() diff --git a/tests/units/Model/SubtaskTest.php b/tests/units/Model/SubtaskTest.php index 1ef04c32..5773893c 100644 --- a/tests/units/Model/SubtaskTest.php +++ b/tests/units/Model/SubtaskTest.php @@ -13,6 +13,136 @@ use Model\UserSession; class SubTaskTest extends Base { + public function onSubtaskCreated($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function onSubtaskUpdated($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertArrayHasKey('changes', $data); + $this->assertArrayHasKey('user_id', $data['changes']); + $this->assertArrayHasKey('status', $data['changes']); + + $this->assertEquals(Subtask::STATUS_INPROGRESS, $data['changes']['status']); + $this->assertEquals(1, $data['changes']['user_id']); + } + + public function onSubtaskDeleted($event) + { + $this->assertInstanceOf('Event\SubtaskEvent', $event); + $data = $event->getAll(); + + $this->assertArrayHasKey('id', $data); + $this->assertArrayHasKey('title', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('time_estimated', $data); + $this->assertArrayHasKey('time_spent', $data); + $this->assertArrayHasKey('status', $data); + $this->assertArrayHasKey('task_id', $data); + $this->assertArrayHasKey('user_id', $data); + $this->assertArrayHasKey('position', $data); + $this->assertNotEmpty($data['task_id']); + $this->assertNotEmpty($data['id']); + } + + public function testCreation() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_CREATE, array($this, 'onSubtaskCreated')); + + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(Subtask::STATUS_TODO, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(0, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testModification() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_UPDATE, array($this, 'onSubtaskUpdated')); + + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + $this->assertTrue($s->update(array('id' => 1, 'user_id' => 1, 'status' => Subtask::STATUS_INPROGRESS))); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + $this->assertEquals(1, $subtask['id']); + $this->assertEquals(1, $subtask['task_id']); + $this->assertEquals('subtask #1', $subtask['title']); + $this->assertEquals(Subtask::STATUS_INPROGRESS, $subtask['status']); + $this->assertEquals(0, $subtask['time_estimated']); + $this->assertEquals(0, $subtask['time_spent']); + $this->assertEquals(1, $subtask['user_id']); + $this->assertEquals(1, $subtask['position']); + } + + public function testRemove() + { + $tc = new TaskCreation($this->container); + $s = new Subtask($this->container); + $p = new Project($this->container); + + $this->assertEquals(1, $p->create(array('name' => 'test'))); + $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); + $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1))); + + $this->container['dispatcher']->addListener(Subtask::EVENT_DELETE, array($this, 'onSubtaskDeleted')); + + $subtask = $s->getById(1); + $this->assertNotEmpty($subtask); + + $this->assertTrue($s->remove(1)); + + $subtask = $s->getById(1); + $this->assertEmpty($subtask); + } + public function testToggleStatusWithoutSession() { $tc = new TaskCreation($this->container); diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php index ed286287..f68f283d 100644 --- a/tests/units/Model/SubtaskTimeTrackingTest.php +++ b/tests/units/Model/SubtaskTimeTrackingTest.php @@ -151,8 +151,8 @@ class SubtaskTimeTrackingTest extends Base $time = $st->calculateSubtaskTime(1); $this->assertNotempty($time); $this->assertCount(2, $time); - $this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01); } public function testUpdateSubtaskTimeSpent() @@ -184,13 +184,13 @@ class SubtaskTimeTrackingTest extends Base $time = $st->calculateSubtaskTime(1); $this->assertNotempty($time); - $this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); $time = $st->calculateSubtaskTime(2); $this->assertNotempty($time); - $this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01); - $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01); + $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01); + $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01); } public function testUpdateTaskTimeTracking() @@ -205,7 +205,7 @@ class SubtaskTimeTrackingTest extends Base $this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1))); $this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5))); - $this->assertEquals(3, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2))); + $this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2))); $this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2))); $this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1))); @@ -231,8 +231,18 @@ class SubtaskTimeTrackingTest extends Base $task = $tf->getById(3); $this->assertNotEmpty($task); - $this->assertEquals(4, $task['time_estimated']); + $this->assertEquals(0, $task['time_estimated']); $this->assertEquals(8, $task['time_spent']); + + $this->assertTrue($s->remove(3)); + $this->assertTrue($s->remove(4)); + + $st->updateTaskTimeTracking(2); + + $task = $tf->getById(2); + $this->assertNotEmpty($task); + $this->assertEquals(0, $task['time_estimated']); + $this->assertEquals(0, $task['time_spent']); } public function testGetCalendarEvents() |