From 6dc2e80a3d03688b5216d92fa7a640fc5690617c Mon Sep 17 00:00:00 2001 From: Martijn Swinkels Date: Wed, 5 Dec 2018 15:37:53 +0100 Subject: [PATCH] PSR-2 standards auto fix --- controller/Api.php | 5 +- controller/Groups.php | 102 ++++++------- controller/Main.php | 20 +-- controller/SaSGroups.php | 16 +- helpers/TestTakerForm.php | 31 ++-- includes/constants.php | 16 +- includes/raw_start.php | 19 ++- manifest.php | 52 +++---- models/CrudGroupsService.php | 49 +++--- models/GroupsService.php | 47 +++--- models/update/Updater.php | 11 +- test/integration/GroupsTest.php | 221 ++++++++++++++-------------- test/integration/RestGroupsTest.php | 3 +- 13 files changed, 303 insertions(+), 289 deletions(-) diff --git a/controller/Api.php b/controller/Api.php index 42cb777..b34baf5 100644 --- a/controller/Api.php +++ b/controller/Api.php @@ -13,7 +13,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * + * * Copyright (c) 2013-2014 (original work) Open Assessment Technologies SA * */ @@ -58,11 +58,10 @@ protected function getParametersRequirements() * is set it will become mandatory for the method/operation in $key * Default Parameters Requirents are applied * type by default is not required and the root class type is applied - * + * * @example :"post"=> array("login", "password") */ ; } } -?> \ No newline at end of file diff --git a/controller/Groups.php b/controller/Groups.php index fbf694f..983b3e5 100644 --- a/controller/Groups.php +++ b/controller/Groups.php @@ -43,67 +43,67 @@ * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php */ -class Groups extends tao_actions_SaSModule { +class Groups extends tao_actions_SaSModule +{ - /** - * Initialize the service and the default data - */ - public function __construct() - { - - parent::__construct(); + /** + * Initialize the service and the default data + */ + public function __construct() + { - //the service is initialized by default - $this->service = GroupsService::singleton(); - $this->defaultData(); - } + parent::__construct(); - /** - * (non-PHPdoc) - * @see tao_actions_SaSModule::getClassService() - */ - protected function getClassService() - { - return GroupsService::singleton(); - } + //the service is initialized by default + $this->service = GroupsService::singleton(); + $this->defaultData(); + } - /** - * Edit a group instance - * @return void - */ - public function editGroup() - { - $clazz = $this->getCurrentClass(); - $group = $this->getCurrentInstance(); + /** + * (non-PHPdoc) + * @see tao_actions_SaSModule::getClassService() + */ + protected function getClassService() + { + return GroupsService::singleton(); + } - $formContainer = new \tao_actions_form_Instance($clazz, $group); - $myForm = $formContainer->getForm(); - if($myForm->isSubmited()){ - if($myForm->isValid()){ + /** + * Edit a group instance + * @return void + */ + public function editGroup() + { + $clazz = $this->getCurrentClass(); + $group = $this->getCurrentInstance(); - $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($group); - $group = $binder->bind($myForm->getValues()); + $formContainer = new \tao_actions_form_Instance($clazz, $group); + $myForm = $formContainer->getForm(); + if ($myForm->isSubmited()) { + if ($myForm->isValid()) { + $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($group); + $group = $binder->bind($myForm->getValues()); - $this->setData("selectNode", tao_helpers_Uri::encode($group->getUri())); - $this->setData('message', __('Group saved')); - $this->setData('reload', true); - } - } + $this->setData("selectNode", tao_helpers_Uri::encode($group->getUri())); + $this->setData('message', __('Group saved')); + $this->setData('reload', true); + } + } - $memberProperty = new core_kernel_classes_Property(GroupsService::PROPERTY_MEMBERS_URI); - $memberForm = tao_helpers_form_GenerisTreeForm::buildReverseTree($group, $memberProperty); - $memberForm->setData('title', __('Select group test takers')); - $this->setData('memberForm', $memberForm->render()); + $memberProperty = new core_kernel_classes_Property(GroupsService::PROPERTY_MEMBERS_URI); + $memberForm = tao_helpers_form_GenerisTreeForm::buildReverseTree($group, $memberProperty); + $memberForm->setData('title', __('Select group test takers')); + $this->setData('memberForm', $memberForm->render()); - if (common_ext_ExtensionsManager::singleton()->isEnabled('taoDeliveryRdf')) { - $this->setData('deliveryForm', DeliveryWidget::renderDeliveryTree($group)); - } + if (common_ext_ExtensionsManager::singleton()->isEnabled('taoDeliveryRdf')) { + $this->setData('deliveryForm', DeliveryWidget::renderDeliveryTree($group)); + } $updatedAt = $this->getServiceManager()->get(ResourceWatcher::SERVICE_ID)->getUpdatedAt($group); - $this->setData('updatedAt', $updatedAt); - $this->setData('formTitle', __('Edit group')); - $this->setData('myForm', $myForm->render()); - $this->setView('form_group.tpl'); - } + $this->setData('updatedAt', $updatedAt); + $this->setData('formTitle', __('Edit group')); + $this->setData('myForm', $myForm->render()); + $this->setView('form_group.tpl'); + } /** * overwrite the parent moveAllInstances to add the requiresRight only in Items diff --git a/controller/Main.php b/controller/Main.php index b21b308..e764f66 100644 --- a/controller/Main.php +++ b/controller/Main.php @@ -1,19 +1,19 @@ \ No newline at end of file diff --git a/controller/SaSGroups.php b/controller/SaSGroups.php index 67dbc8d..b0ff555 100644 --- a/controller/SaSGroups.php +++ b/controller/SaSGroups.php @@ -1,19 +1,19 @@ * @package taoGroups - * + * * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php */ class SaSGroups extends Groups @@ -44,7 +44,7 @@ protected function getClassService() /** * overrided to prevent exception: * if no class is selected, the root class is returned - * + * * @see TaoModule::getCurrentClass() * @return core_kernel_class_Class */ @@ -58,7 +58,7 @@ protected function getCurrentClass() /** * Render the tree to select the group related subjects - * + * */ public function selectSubjects() { @@ -68,4 +68,4 @@ public function selectSubjects() $this->setData('tree', $memberForm->render()); $this->setView('sas' . DIRECTORY_SEPARATOR . 'generisTreeSelect.tpl', 'tao'); } -} \ No newline at end of file +} diff --git a/helpers/TestTakerForm.php b/helpers/TestTakerForm.php index 17002ba..08d0974 100644 --- a/helpers/TestTakerForm.php +++ b/helpers/TestTakerForm.php @@ -1,22 +1,22 @@ * @package taoGroups - + */ class TestTakerForm { /** - * Returns a form to modify the groups a user is part of - * + * Returns a form to modify the groups a user is part of + * * @param core_kernel_classes_Resource $subject * @return string */ - public static function renderGroupTreeForm(core_kernel_classes_Resource $subject) { - + public static function renderGroupTreeForm(core_kernel_classes_Resource $subject) + { + // Ensure groups constants are loaded common_ext_ExtensionsManager::singleton()->getExtensionById('taoGroups'); $memberProperty = new core_kernel_classes_Property(GroupsService::PROPERTY_MEMBERS_URI); - $groupForm = tao_helpers_form_GenerisTreeForm::buildTree($subject, $memberProperty); - $groupForm->setData('title', __('Add to group')); - return $groupForm->render(); + $groupForm = tao_helpers_form_GenerisTreeForm::buildTree($subject, $memberProperty); + $groupForm->setData('title', __('Add to group')); + return $groupForm->render(); } -} \ No newline at end of file +} diff --git a/includes/constants.php b/includes/constants.php index 0f1c010..335123c 100755 --- a/includes/constants.php +++ b/includes/constants.php @@ -1,31 +1,31 @@ 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Members' -); \ No newline at end of file + 'TAO_GROUP_MEMBERS_PROP'=> 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Members' +); diff --git a/includes/raw_start.php b/includes/raw_start.php index b5df1f8..6c8be25 100644 --- a/includes/raw_start.php +++ b/includes/raw_start.php @@ -1,38 +1,37 @@ start(); -?> \ No newline at end of file diff --git a/manifest.php b/manifest.php index 1575018..5f6de80 100755 --- a/manifest.php +++ b/manifest.php @@ -42,44 +42,44 @@ 'generis' => '>=5.11.0', 'tao' => '>=21.0.0' ), - 'models' => array( - 'http://www.tao.lu/Ontologies/TAOGroup.rdf' - ), - 'install' => array( - 'rdf' => array( - dirname(__FILE__). '/models/ontology/taogroup.rdf' - ) - ), + 'models' => array( + 'http://www.tao.lu/Ontologies/TAOGroup.rdf' + ), + 'install' => array( + 'rdf' => array( + dirname(__FILE__). '/models/ontology/taogroup.rdf' + ) + ), 'update' => 'oat\\taoGroups\\models\\update\\Updater', - 'managementRole' => 'http://www.tao.lu/Ontologies/TAOGroup.rdf#GroupsManagerRole', + 'managementRole' => 'http://www.tao.lu/Ontologies/TAOGroup.rdf#GroupsManagerRole', 'acl' => array( array('grant', 'http://www.tao.lu/Ontologies/TAOGroup.rdf#GroupsManagerRole', array('ext'=>'taoGroups')) ), 'routes' => array( '/taoGroups' => 'oat\\taoGroups\\controller' ), - 'optimizableClasses' => array( - 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Group' - ), - 'constants' => array( - # actions directory - "DIR_ACTIONS" => $extpath."controller".DIRECTORY_SEPARATOR, + 'optimizableClasses' => array( + 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Group' + ), + 'constants' => array( + # actions directory + "DIR_ACTIONS" => $extpath."controller".DIRECTORY_SEPARATOR, - # views directory - "DIR_VIEWS" => $extpath."views".DIRECTORY_SEPARATOR, + # views directory + "DIR_VIEWS" => $extpath."views".DIRECTORY_SEPARATOR, - # default module name - 'DEFAULT_MODULE_NAME' => 'Groups', + # default module name + 'DEFAULT_MODULE_NAME' => 'Groups', - #default action name - 'DEFAULT_ACTION_NAME' => 'index', + #default action name + 'DEFAULT_ACTION_NAME' => 'index', - #BASE PATH: the root path in the file system (usually the document root) - 'BASE_PATH' => $extpath, + #BASE PATH: the root path in the file system (usually the document root) + 'BASE_PATH' => $extpath, - #BASE URL (usually the domain root) - 'BASE_URL' => ROOT_URL .'taoGroups/', - ), + #BASE URL (usually the domain root) + 'BASE_URL' => ROOT_URL .'taoGroups/', + ), 'extra' => array( 'structures' => dirname(__FILE__).DIRECTORY_SEPARATOR.'controller'.DIRECTORY_SEPARATOR.'structures.xml', ) diff --git a/models/CrudGroupsService.php b/models/CrudGroupsService.php index ce443a7..189f49e 100644 --- a/models/CrudGroupsService.php +++ b/models/CrudGroupsService.php @@ -1,21 +1,21 @@ getClassService()->deleteGroup(new core_kernel_classes_Resource($resource)); //parent::delete($resource) return true; } /** - * + * * @author Patrick Plichart, patrick@taotesting.com * @param array $propertiesValues * @return core_kernel_classes_Resource */ - public function createFromArray(array $propertiesValues){ - if (!isset($propertiesValues[OntologyRdfs::RDFS_LABEL])) { - $propertiesValues[OntologyRdfs::RDFS_LABEL] = ""; - } - $type = isset($propertiesValues[OntologyRdf::RDF_TYPE]) ? $propertiesValues[OntologyRdf::RDF_TYPE] : $this->getRootClass(); - $label = $propertiesValues[OntologyRdfs::RDFS_LABEL]; - //hmmm - unset($propertiesValues[OntologyRdfs::RDFS_LABEL]); - unset($propertiesValues[OntologyRdf::RDF_TYPE]); - $resource = parent::create($label, $type, $propertiesValues); - return $resource; + public function createFromArray(array $propertiesValues) + { + if (!isset($propertiesValues[OntologyRdfs::RDFS_LABEL])) { + $propertiesValues[OntologyRdfs::RDFS_LABEL] = ""; + } + $type = isset($propertiesValues[OntologyRdf::RDF_TYPE]) ? $propertiesValues[OntologyRdf::RDF_TYPE] : $this->getRootClass(); + $label = $propertiesValues[OntologyRdfs::RDFS_LABEL]; + //hmmm + unset($propertiesValues[OntologyRdfs::RDFS_LABEL]); + unset($propertiesValues[OntologyRdf::RDF_TYPE]); + $resource = parent::create($label, $type, $propertiesValues); + return $resource; } -} \ No newline at end of file +} diff --git a/models/GroupsService.php b/models/GroupsService.php index 783bcfc..171bc83 100644 --- a/models/GroupsService.php +++ b/models/GroupsService.php @@ -1,19 +1,19 @@ * @package taoGroups - + */ -class GroupsService - extends tao_models_classes_ClassService +class GroupsService extends tao_models_classes_ClassService { const CLASS_URI = 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Group'; @@ -64,14 +63,14 @@ public function getRootClass() * @param Resource group * @return boolean */ - public function deleteGroup( core_kernel_classes_Resource $group) + public function deleteGroup(core_kernel_classes_Resource $group) { $returnValue = (bool) false; - - if(!is_null($group)){ - $returnValue = $group->delete(); - } - return (bool) $returnValue; + + if (!is_null($group)) { + $returnValue = $group->delete(); + } + return (bool) $returnValue; } /** @@ -82,7 +81,7 @@ public function deleteGroup( core_kernel_classes_Resource $group) * @param Class clazz * @return boolean */ - public function isGroupClass( core_kernel_classes_Class $clazz) + public function isGroupClass(core_kernel_classes_Class $clazz) { return $clazz->equals($this->getRootClass()) || $clazz->isSubClassOf($this->getRootClass()); } @@ -98,13 +97,15 @@ public function isGroupClass( core_kernel_classes_Class $clazz) public function getGroups(User $user) { $groups = $user->getPropertyValues(self::PROPERTY_MEMBERS_URI); - array_walk($groups, function(&$group) { $group = new core_kernel_classes_Resource($group);}); + array_walk($groups, function (&$group) { + $group = new core_kernel_classes_Resource($group); + }); return $groups; } /** * gets the users of a group - * + * * @param string $groupUri * @return array resources of users */ @@ -112,33 +113,35 @@ public function getUsers($groupUri) { $subjectClass = TestTakerService::singleton()->getRootClass(); $users = $subjectClass->searchInstances(array( - self::PROPERTY_MEMBERS_URI => $groupUri + self::PROPERTY_MEMBERS_URI => $groupUri ), array( - 'recursive' => true, 'like' => false + 'recursive' => true, 'like' => false )); return $users; } /** * Add a User to a Group - * + * * @param string $userUri * @param core_kernel_classes_Resource $group * @return boolean */ - public function addUser($userUri, core_kernel_classes_Resource $group) { + public function addUser($userUri, core_kernel_classes_Resource $group) + { $user = new \core_kernel_classes_Resource($userUri); return $user->setPropertyValue(new core_kernel_classes_Property(self::PROPERTY_MEMBERS_URI), $group); } /** * Remove a User from a Group - * + * * @param string $userUri * @param core_kernel_classes_Resource $group * @return boolean */ - public function removeUser($userUri, core_kernel_classes_Resource $group) { + public function removeUser($userUri, core_kernel_classes_Resource $group) + { $user = new \core_kernel_classes_Resource($userUri); return $user->removePropertyValue(new core_kernel_classes_Property(self::PROPERTY_MEMBERS_URI), $group); } diff --git a/models/update/Updater.php b/models/update/Updater.php index ff876e2..5f23b3d 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. * @@ -46,7 +47,7 @@ class Updater extends \common_ext_ExtensionUpdater */ public function update($initialVersion) { - if ($this->isVersion('2.6')) { + if ($this->isVersion('2.6')) { OntologyUpdater::syncModels(); $iterator = new \core_kernel_classes_ResourceIterator(array(GroupsService::singleton()->getRootClass())); @@ -58,10 +59,10 @@ public function update($initialVersion) } } } - $this->setVersion('2.6.1'); + $this->setVersion('2.6.1'); } - if ($this->isBetween('2.6.1','2.7')){ + if ($this->isBetween('2.6.1', '2.7')) { $this->setVersion('2.7'); } @@ -70,13 +71,13 @@ public function update($initialVersion) $this->setVersion('2.7.1'); } - $this->skip('2.7.1','3.0.0'); + $this->skip('2.7.1', '3.0.0'); // fix anonymous access if ($this->isVersion('3.0.0')) { AclProxy::revokeRule(new AccessRule(AccessRule::GRANT, TaoRoles::ANONYMOUS, Api::class)); $this->setVersion('3.0.1'); } - $this->skip('3.0.1','4.1.0'); + $this->skip('3.0.1', '4.1.0'); } } diff --git a/test/integration/GroupsTest.php b/test/integration/GroupsTest.php index fd63728..ff80386 100644 --- a/test/integration/GroupsTest.php +++ b/test/integration/GroupsTest.php @@ -1,28 +1,27 @@ * @package taoGroups - + */ -class GroupsTest extends TaoPhpUnitTestRunner { - - /** - * @var GroupsService - */ - protected $groupsService = null; - - protected $subjectsService = null; - - /** - * tests initialization - */ - public function setUp(){ +class GroupsTest extends TaoPhpUnitTestRunner +{ + + /** + * @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 = TestTakerService::singleton(); + $this->groupsService = GroupsService::singleton(); + } /** - * @return \core_kernel_classes_Class|null + * Test the user service implementation + * @see tao_models_classes_ServiceFactory::get + * @see oat\taoGroups\models\GroupsService::__construct */ - public function testGroup() { - $groupClass = $this->groupsService->getRootClass(); - $this->assertIsA($groupClass, 'core_kernel_classes_Class'); - $this->assertEquals(GroupsService::CLASS_URI, $groupClass->getUri()); + 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()); return $groupClass; } @@ -84,11 +85,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 +103,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 +118,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 +139,66 @@ 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(); - } - -} \ No newline at end of file + 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(); + } +} diff --git a/test/integration/RestGroupsTest.php b/test/integration/RestGroupsTest.php index e5b7ce0..fe28264 100644 --- a/test/integration/RestGroupsTest.php +++ b/test/integration/RestGroupsTest.php @@ -31,7 +31,8 @@ */ class RestGroupsTest extends RestTestCase { - public function serviceProvider(){ + public function serviceProvider() + { return array( array('taoGroups/Api',GroupsService::CLASS_URI) );