From 9396580789ae2e5275f5e7d7e120069f8583ef6a Mon Sep 17 00:00:00 2001 From: Vladimir Kalskov Date: Tue, 16 Jul 2019 13:47:38 +0300 Subject: [PATCH] TAO-8697 - Registering service GroupService --- config/default/Groups.conf.php | 6 + manifest.php | 2 +- models/GroupsService.php | 2 + models/update/Updater.php | 9 +- test/integration/GroupsTest.php | 193 +++++++++++++++++--------------- 5 files changed, 119 insertions(+), 93 deletions(-) create mode 100644 config/default/Groups.conf.php diff --git a/config/default/Groups.conf.php b/config/default/Groups.conf.php new file mode 100644 index 0000000..d18fc55 --- /dev/null +++ b/config/default/Groups.conf.php @@ -0,0 +1,6 @@ + 'Groups core extension', 'description' => 'TAO Groups extension', 'license' => 'GPL-2.0', - 'version' => '6.1.0', + 'version' => '6.1.2', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array( 'taoTestTaker' => '>=4.0.0', diff --git a/models/GroupsService.php b/models/GroupsService.php index 0f486c9..811a2d6 100644 --- a/models/GroupsService.php +++ b/models/GroupsService.php @@ -40,6 +40,8 @@ class GroupsService extends tao_models_classes_ClassService { + const SERVICE_ID = 'taoGroups/Groups'; + const CLASS_URI = 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Group'; const PROPERTY_MEMBERS_URI = 'http://www.tao.lu/Ontologies/TAOGroup.rdf#member'; diff --git a/models/update/Updater.php b/models/update/Updater.php index a9bbe83..d0b3197 100644 --- a/models/update/Updater.php +++ b/models/update/Updater.php @@ -28,6 +28,7 @@ use oat\tao\model\accessControl\func\AccessRule; use oat\tao\model\user\TaoRoles; use oat\taoGroups\controller\Api; + /** * Service methods to manage the Groups business models using the RDF API. * @@ -77,6 +78,12 @@ public function update($initialVersion) $this->setVersion('3.0.1'); } - $this->skip('3.0.1','6.1.0'); + $this->skip('3.0.1','6.1.1'); + + if ($this->isVersion('6.1.1')) { + $groupsService = new GroupsService(); + $this->getServiceManager()->register(GroupsService::SERVICE_ID, $groupsService); + $this->setVersion('6.1.2'); + } } } diff --git a/test/integration/GroupsTest.php b/test/integration/GroupsTest.php index fd63728..d6df75c 100644 --- a/test/integration/GroupsTest.php +++ b/test/integration/GroupsTest.php @@ -30,6 +30,7 @@ use \core_kernel_classes_Class; use \core_kernel_classes_Property; use oat\tao\test\TaoPhpUnitTestRunner; +use oat\oatbox\service\ServiceManager; @@ -41,40 +42,43 @@ */ class GroupsTest extends TaoPhpUnitTestRunner { - - /** - * @var GroupsService - */ - protected $groupsService = null; - - protected $subjectsService = null; - /** - * tests initialization - */ - public function setUp(){ + /** + * @var GroupsService + */ + protected $groupsService = null; + + protected $subjectsService = null; + + /** + * tests initialization + */ + public function setUp() + { TaoPhpUnitTestRunner::initTest(); - $this->subjectsService = TestTakerService::singleton(); - $this->groupsService = GroupsService::singleton(); - } - - /** - * Test the user service implementation - * @see tao_models_classes_ServiceFactory::get - * @see oat\taoGroups\models\GroupsService::__construct - */ - public function testService(){ - $this->assertIsA($this->subjectsService, '\tao_models_classes_Service'); - $this->assertIsA($this->groupsService, 'oat\taoGroups\models\GroupsService'); - } + $this->subjectsService = $this->getServiceLocator()->get('TestTakerService'); + $this->groupsService = $this->getServiceLocator()->get(GroupsService::SERVICE_ID); + } + + /** + * Test the user service implementation + * @see tao_models_classes_ServiceFactory::get + * @see oat\taoGroups\models\GroupsService::__construct + */ + public function testService() + { + $this->assertIsA($this->subjectsService, '\tao_models_classes_Service'); + $this->assertIsA($this->groupsService, 'oat\taoGroups\models\GroupsService'); + } /** * @return \core_kernel_classes_Class|null */ - public function testGroup() { - $groupClass = $this->groupsService->getRootClass(); - $this->assertIsA($groupClass, 'core_kernel_classes_Class'); - $this->assertEquals(GroupsService::CLASS_URI, $groupClass->getUri()); + public function testGroup() + { + $groupClass = $this->groupsService->getRootClass(); + $this->assertIsA($groupClass, 'core_kernel_classes_Class'); + $this->assertEquals(GroupsService::CLASS_URI, $groupClass->getUri()); return $groupClass; } @@ -84,11 +88,12 @@ public function testGroup() { * @param $group * @return \core_kernel_classes_Class */ - public function testSubGroup($groupClass) { - $subGroupLabel = 'subGroup class'; - $subGroup = $this->groupsService->createSubClass($groupClass, $subGroupLabel); - $this->assertIsA($subGroup, 'core_kernel_classes_Class'); - $this->assertEquals($subGroupLabel, $subGroup->getLabel()); + public function testSubGroup($groupClass) + { + $subGroupLabel = 'subGroup class'; + $subGroup = $this->groupsService->createSubClass($groupClass, $subGroupLabel); + $this->assertIsA($subGroup, 'core_kernel_classes_Class'); + $this->assertEquals($subGroupLabel, $subGroup->getLabel()); $this->assertTrue($this->groupsService->isGroupClass($subGroup)); @@ -101,11 +106,12 @@ public function testSubGroup($groupClass) { * @param $group * @return \core_kernel_classes_Resource */ - public function testGroupInstance($groupClass) { - $groupInstanceLabel = 'group instance'; - $groupInstance = $this->groupsService->createInstance($groupClass, $groupInstanceLabel); - $this->assertIsA($groupInstance, 'core_kernel_classes_Resource'); - $this->assertEquals($groupInstanceLabel, $groupInstance->getLabel()); + public function testGroupInstance($groupClass) + { + $groupInstanceLabel = 'group instance'; + $groupInstance = $this->groupsService->createInstance($groupClass, $groupInstanceLabel); + $this->assertIsA($groupInstance, 'core_kernel_classes_Resource'); + $this->assertEquals($groupInstanceLabel, $groupInstance->getLabel()); return $groupInstance; } @@ -115,18 +121,19 @@ public function testGroupInstance($groupClass) { * @param $subGroup * @return \core_kernel_classes_Class */ - public function testSubGroupInstance($subGroupClass) { - $subGroupInstanceLabel = 'subGroup instance'; - $subGroupInstance = $this->groupsService->createInstance($subGroupClass); - - $subGroupInstance->removePropertyValues(new core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL)); - $subGroupInstance->setLabel($subGroupInstanceLabel); - $this->assertIsA($subGroupInstance, 'core_kernel_classes_Resource'); - $this->assertEquals($subGroupInstanceLabel, $subGroupInstance->getLabel()); - - $subGroupInstanceLabel2 = 'my sub group instance'; - $subGroupInstance->setLabel($subGroupInstanceLabel2); - $this->assertEquals($subGroupInstanceLabel2, $subGroupInstance->getLabel()); + public function testSubGroupInstance($subGroupClass) + { + $subGroupInstanceLabel = 'subGroup instance'; + $subGroupInstance = $this->groupsService->createInstance($subGroupClass); + + $subGroupInstance->removePropertyValues(new core_kernel_classes_Property(OntologyRdfs::RDFS_LABEL)); + $subGroupInstance->setLabel($subGroupInstanceLabel); + $this->assertIsA($subGroupInstance, 'core_kernel_classes_Resource'); + $this->assertEquals($subGroupInstanceLabel, $subGroupInstance->getLabel()); + + $subGroupInstanceLabel2 = 'my sub group instance'; + $subGroupInstance->setLabel($subGroupInstanceLabel2); + $this->assertEquals($subGroupInstanceLabel2, $subGroupInstance->getLabel()); return $subGroupInstance; } @@ -135,63 +142,67 @@ public function testSubGroupInstance($subGroupClass) { * @depends testGroupInstance * @param $groupInstance */ - public function testDeleteGroupInstance($groupInstance) { - $this->assertTrue($groupInstance->delete()); + public function testDeleteGroupInstance($groupInstance) + { + $this->assertTrue($groupInstance->delete()); } /** * @depends testSubGroupInstance * @param $subGroupInstance */ - public function testDeleteSubGroupInstance($subGroupInstance) { - $this->assertTrue($subGroupInstance->delete()); + public function testDeleteSubGroupInstance($subGroupInstance) + { + $this->assertTrue($subGroupInstance->delete()); } /** * @depends testSubGroup * @param $subGroup */ - public function testDeleteSubGroupClass($subGroup) { - $this->assertTrue($subGroup->delete()); + public function testDeleteSubGroupClass($subGroup) + { + $this->assertTrue($subGroup->delete()); } /** * * @author Lionel Lecaque, lionel@taotesting.com */ - public function testGetGroups(){ - $groupClass = GroupsService::singleton()->getRootClass(); - $this->assertTrue($this->groupsService->isGroupClass($groupClass)); - - $subject = $this->subjectsService->createInstance($this->subjectsService->getRootClass(),'testSubject'); - $oneGroup = $groupClass->createInstance('testGroupInstance'); - - $this->groupsService->addUser($subject->getUri(), $oneGroup); - $oneGroup2 = $groupClass->createInstance('testGroupInstance2'); - - $subclass = $groupClass->createSubClass('testGroupSubclass'); - $oneGroup3 = $subclass->createInstance('testSubGroupInstance'); - $this->groupsService->addUser($subject->getUri(), $oneGroup3); - - $generisUser = new \core_kernel_users_GenerisUser($subject); - $groups = $this->groupsService->getGroups($generisUser); - - $this->assertTrue(is_array($groups)); - $this->assertTrue(count($groups) == 2); - array_walk($groups, function (&$group) { - $group = $group->getUri(); - }); - $this->assertContains($oneGroup->getUri(), $groups); - $this->assertNotContains($oneGroup2->getUri(), $groups); - $this->assertContains($oneGroup3->getUri(), $groups); - - $this->assertTrue($this->groupsService->deleteGroup($oneGroup)); - $this->assertTrue($this->groupsService->deleteGroup($oneGroup2)); - $this->assertTrue($this->groupsService->deleteGroup($oneGroup3)); - - $this->assertTrue($this->groupsService->deleteClass($subclass)); - - $subject->delete(); - } + public function testGetGroups() + { + $groupClass = $this->groupsService->getRootClass(); + $this->assertTrue($this->groupsService->isGroupClass($groupClass)); + + $subject = $this->subjectsService->createInstance($this->subjectsService->getRootClass(),'testSubject'); + $oneGroup = $groupClass->createInstance('testGroupInstance'); + + $this->groupsService->addUser($subject->getUri(), $oneGroup); + $oneGroup2 = $groupClass->createInstance('testGroupInstance2'); + + $subclass = $groupClass->createSubClass('testGroupSubclass'); + $oneGroup3 = $subclass->createInstance('testSubGroupInstance'); + $this->groupsService->addUser($subject->getUri(), $oneGroup3); + + $generisUser = new \core_kernel_users_GenerisUser($subject); + $groups = $this->groupsService->getGroups($generisUser); + + $this->assertTrue(is_array($groups)); + $this->assertTrue(count($groups) == 2); + array_walk($groups, function (&$group) { + $group = $group->getUri(); + }); + $this->assertContains($oneGroup->getUri(), $groups); + $this->assertNotContains($oneGroup2->getUri(), $groups); + $this->assertContains($oneGroup3->getUri(), $groups); + + $this->assertTrue($this->groupsService->deleteGroup($oneGroup)); + $this->assertTrue($this->groupsService->deleteGroup($oneGroup2)); + $this->assertTrue($this->groupsService->deleteGroup($oneGroup3)); + + $this->assertTrue($this->groupsService->deleteClass($subclass)); + + $subject->delete(); + } -} \ No newline at end of file +}