[FEATURE] Add userGroups to backendUser model
authorMarkus Günther <mail@markus-guenther.de>
Fri, 17 Aug 2012 23:07:05 +0000 (01:07 +0200)
committerTymoteusz Motylewski <t.motylewski@gmail.com>
Tue, 8 Jan 2013 22:10:30 +0000 (23:10 +0100)
This patch adds the new BackendUserGroup model as property to the new
BackendUser model. The patch adds the usual methods for a
SplObjectStorage and the corresponding unit tests

Change-Id: I047361810eeb48c53483c99ed0a79966d0dd0e00
Resolves: #39329
Releases: 6.1
Reviewed-on: https://review.typo3.org/13879
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Tymoteusz Motylewski
Tested-by: Tymoteusz Motylewski
typo3/sysext/extbase/Classes/Domain/Model/BackendUser.php
typo3/sysext/extbase/Tests/Unit/Domain/Model/BackendUserTest.php
typo3/sysext/extbase/ext_typoscript_setup.txt

index c21ca5f..5254eb7 100644 (file)
@@ -46,6 +46,11 @@ class BackendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
        protected $isAdministrator = FALSE;
 
        /**
+        * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
+        */
+       protected $backendUserGroups = NULL;
+
+       /**
         * @var boolean
         */
        protected $isDisabled = FALSE;
@@ -89,7 +94,7 @@ class BackendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
         * Constructs this backend user
         */
        public function __construct() {
-               $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->initializeObject();
        }
 
        /**
@@ -99,6 +104,7 @@ class BackendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
         */
        public function initializeObject() {
                $this->fileMounts = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $this->backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
        }
 
        /**
@@ -140,6 +146,54 @@ class BackendUser extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {
        }
 
        /**
+        * Getter for the backend user groups
+        *
+        * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup>
+        */
+       public function getBackendUserGroups() {
+               return $this->backendUserGroups;
+       }
+
+       /**
+        * Setter for the backend user groups
+        *
+        * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $backendUserGroups
+        * @return void
+        */
+       public function setBackendUserGroups(\TYPO3\CMS\Extbase\Persistence\ObjectStorage $backendUserGroups) {
+               $this->backendUserGroups = $backendUserGroups;
+       }
+
+       /**
+        * Adds a backend user group to this backend user
+        *
+        * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup
+        * @return void
+        */
+       public function addBackendUserGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup) {
+               $this->backendUserGroups->attach($backendUserGroup);
+       }
+
+       /**
+        * Removes backend user group from this backend user
+        *
+        * @param \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup
+        * @return void
+        */
+       public function removeBackendUserGroup(\TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup $backendUserGroup) {
+               $this->backendUserGroups->detach($backendUserGroup);
+       }
+
+       /**
+        * Remove all backend user groups from this backend user
+        *
+        * @return void
+        */
+       public function removeAllBackendUserGroups() {
+               $this->backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+       }
+
+       /**
         * Checks whether this user is disabled.
         *
         * @return boolean whether this user is disabled
index 5655f73..92fe665 100644 (file)
@@ -81,6 +81,64 @@ class BackendUserTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
        /**
         * @test
         */
+       public function getBackendUserGroupsInitiallyReturnsEmptyStorage() {
+               $this->assertEquals(new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(), $this->fixture->getBackendUserGroups());
+       }
+
+       /**
+        * @test
+        */
+       public function setBackendUserGroupsSetsBackendUserGroups() {
+               $backendUserGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+               $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
+               $backendUserGroups->attach($group1);
+
+               $this->fixture->setBackendUserGroups($backendUserGroups);
+               $this->assertSame(
+                       $backendUserGroups,
+                       $this->fixture->getBackendUserGroups()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function addBackendUserGroupAddsBackendUserGroup() {
+               $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
+
+               $this->fixture->addBackendUserGroup($group1);
+               $this->assertTrue($this->fixture->getBackendUserGroups()->contains($group1));
+       }
+
+       /**
+        * @test
+        */
+       public function removeBackendUserGroupRemovesBackendUserGroup() {
+               $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
+
+               $this->fixture->addBackendUserGroup($group1);
+               $this->fixture->removeBackendUserGroup($group1);
+               $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group1));
+       }
+
+       /**
+        * @test
+        */
+       public function removeAllBackendUserGroupsRemovesAllBackendUserGroups() {
+               $group1 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
+               $group2 = new \TYPO3\CMS\Extbase\Domain\Model\BackendUserGroup();
+
+               $this->fixture->addBackendUserGroup($group1);
+               $this->fixture->addBackendUserGroup($group2);
+               $this->fixture->removeAllBackendUserGroups();
+
+               $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group1));
+               $this->assertFalse($this->fixture->getBackendUserGroups()->contains($group2));
+       }
+
+       /**
+        * @test
+        */
        public function getIsDisabledInitiallyReturnsFalse() {
                $this->assertFalse($this->fixture->getIsDisabled());
        }
index 993e38d..501d113 100644 (file)
@@ -44,6 +44,7 @@ config.tx_extbase {
                                        columns {
                                                username.mapOnProperty = userName
                                                admin.mapOnProperty = isAdministrator
+                                               usergroup.mapOnProperty = backendUserGroups
                                                disable.mapOnProperty = isDisabled
                                                realName.mapOnProperty = realName
                                                starttime.mapOnProperty = startDateAndTime