[TASK] Unit test for FrontendUserGroup model
authorMarkus Günther <mail@markus-guenther.de>
Thu, 16 Aug 2012 10:14:06 +0000 (12:14 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 17 Aug 2012 21:04:55 +0000 (23:04 +0200)
To improve the test coverage we should have unit tests for the
frontend user group model in extbase.

Change-Id: I8e1005e9178161f2ba41b2277a7d993b8448eba9
Resolves: #39848
Release: 6.0
Reviewed-on: http://review.typo3.org/13809
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/extbase/Classes/Domain/Model/FrontendUserGroup.php
typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserGroupTest.php [new file with mode: 0644]

index c33e4a9..1ae6322 100644 (file)
@@ -27,7 +27,7 @@
  *
  * @package Extbase
  * @subpackage Domain\Model
- * @version $Id$
+ *
  * @scope prototype
  * @entity
  * @api
@@ -37,17 +37,17 @@ class Tx_Extbase_Domain_Model_FrontendUserGroup extends Tx_Extbase_DomainObject_
        /**
         * @var string
         */
-       protected $title;
+       protected $title = '';
 
        /**
         * @var string
         */
-       protected $lockToDomain;
+       protected $lockToDomain = '';
 
        /**
         * @var string
         */
-       protected $description;
+       protected $description = '';
 
        /**
         * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup>
@@ -59,7 +59,7 @@ class Tx_Extbase_Domain_Model_FrontendUserGroup extends Tx_Extbase_DomainObject_
         *
         * @param string $title
         */
-       public function __construct($title) {
+       public function __construct($title = '') {
                $this->setTitle($title);
                $this->subgroup = new Tx_Extbase_Persistence_ObjectStorage();
        }
diff --git a/typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserGroupTest.php b/typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserGroupTest.php
new file mode 100644 (file)
index 0000000..6433b93
--- /dev/null
@@ -0,0 +1,179 @@
+ <?php
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Markus Günther <mail@markus-guenther.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for Tx_Extbase_Domain_Model_FrontendUserGroup.
+ *
+ * @author Markus Günther <mail@markus-guenther.de>
+ *
+ * @package Extbase
+ *
+ * @scope prototype
+ * @entity
+ * @api
+ */
+class Tx_Extbase_Tests_Unit_Domain_Model_FrontendUserGroupTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @var Tx_Extbase_Domain_Model_FrontendUserGroup
+        */
+       protected $fixture = NULL;
+
+       public function setUp() {
+               $this->fixture = new Tx_Extbase_Domain_Model_FrontendUserGroup();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function getTitleInitiallyReturnsEmptyString() {
+               $this->fixture = new Tx_Extbase_Domain_Model_FrontendUserGroup();
+
+               $this->assertSame(
+                       '',
+                       $this->fixture->getTitle()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getTitleInitiallyReturnsGivenTitleFromConstruct() {
+               $title = 'foo bar';
+               $this->fixture = new Tx_Extbase_Domain_Model_FrontendUserGroup($title);
+
+               $this->assertSame(
+                       $title,
+                       $this->fixture->getTitle()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setTitleSetsTitle() {
+               $title = 'foo bar';
+               $this->fixture->setTitle($title);
+
+               $this->assertSame(
+                       $title,
+                       $this->fixture->getTitle()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getLockToDomainInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getLockToDomain()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setLockToDomainSetsLockToDomain() {
+               $lockToDomain = 'foo.bar';
+               $this->fixture->setLockToDomain($lockToDomain);
+
+               $this->assertSame(
+                       $lockToDomain,
+                       $this->fixture->getLockToDomain()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getDescriptionInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getDescription()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setDescriptionSetsDescription() {
+               $description = 'foo bar';
+               $this->fixture->setDescription($description);
+
+               $this->assertSame(
+                       $description,
+                       $this->fixture->getDescription()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function addSubgroupAddsSubgroup() {
+               $group1 = new Tx_Extbase_Domain_Model_FrontendUserGroup('foo');
+
+               $this->assertEquals(count($this->fixture->getSubgroup()), 0);
+               $this->fixture->addSubgroup($group1);
+               $this->assertEquals(count($this->fixture->getSubgroup()), 1);
+       }
+
+       /**
+        * @test
+        */
+       public function removeSubgroupRemovesSubgroup() {
+               $group1 = new Tx_Extbase_Domain_Model_FrontendUserGroup('foo');
+               $group2 = new Tx_Extbase_Domain_Model_FrontendUserGroup('bar');
+
+               $this->fixture->addSubgroup($group1);
+               $this->fixture->addSubgroup($group2);
+               $this->assertEquals(count($this->fixture->getSubgroup()), 2);
+               $this->fixture->removeSubgroup($group1);
+               $this->assertEquals(count($this->fixture->getSubgroup()), 1);
+               $this->fixture->removeSubgroup($group2);
+               $this->assertEquals(count($this->fixture->getSubgroup()), 0);
+       }
+
+       /**
+        * @test
+        */
+       public function setSubgroupSetsSubgroups() {
+               $subgroup = new Tx_Extbase_Persistence_ObjectStorage();
+               $group = new Tx_Extbase_Domain_Model_FrontendUserGroup('foo');
+               $subgroup->attach($group);
+               $this->fixture->setSubgroup($subgroup);
+
+               $this->assertSame(
+                       $subgroup,
+                       $this->fixture->getSubgroup()
+               );
+       }
+}
+?>
\ No newline at end of file