[TASK] Unit test for FrontendUser model
authorMarkus Günther <mail@markus-guenther.de>
Fri, 17 Aug 2012 08:20:36 +0000 (10:20 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Fri, 17 Aug 2012 20:59:26 +0000 (22:59 +0200)
To improve the test coverage we should have unit tests for the
frontend user model in extbase.

Change-Id: I975db656f7e7a3dcc2704923f4878acb0505fa49
Resolves: #39849
Release: 6.0
Reviewed-on: http://review.typo3.org/13846
Reviewed-by: Nicole Cordes
Tested-by: Nicole Cordes
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/extbase/Classes/Domain/Model/FrontendUser.php
typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserTest.php [new file with mode: 0644]

index f263abe..20fdb6f 100644 (file)
@@ -37,12 +37,12 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        /**
         * @var string
         */
-       protected $username;
+       protected $username = '';
 
        /**
         * @var string
         */
-       protected $password;
+       protected $password = '';
 
        /**
         * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Extbase_Domain_Model_FrontendUserGroup>
@@ -52,22 +52,22 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        /**
         * @var string
         */
-       protected $name;
+       protected $name = '';
 
        /**
         * @var string
         */
-       protected $firstName;
+       protected $firstName = '';
 
        /**
         * @var string
         */
-       protected $middleName;
+       protected $middleName = '';
 
        /**
         * @var string
         */
-       protected $lastName;
+       protected $lastName = '';
 
        /**
         * @var string
@@ -130,14 +130,14 @@ class Tx_Extbase_Domain_Model_FrontendUser extends Tx_Extbase_DomainObject_Abstr
        protected $image = '';
 
        /**
-        * @var DateTime
+        * @var DateTime|NULL
         */
-       protected $lastlogin = '';
+       protected $lastlogin = NULL;
 
        /**
-        * @var DateTime
+        * @var DateTime|NULL
         */
-       protected $isOnline = '';
+       protected $isOnline = NULL;
 
        /**
         * Constructs a new Front-End User
diff --git a/typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserTest.php b/typo3/sysext/extbase/Tests/Unit/Domain/Model/FrontendUserTest.php
new file mode 100644 (file)
index 0000000..a2f3d40
--- /dev/null
@@ -0,0 +1,548 @@
+<?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_FrontendUser.
+ *
+ * @author Markus Günther <mail@markus-guenther.de>
+ *
+ * @package Extbase
+ *
+ * @scope prototype
+ * @entity
+ * @api
+ */
+class Tx_Extbase_Tests_Unit_Domain_Model_FrontendUserTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
+
+       /**
+        * @var Tx_Extbase_Domain_Model_FrontendUser
+        */
+       protected $fixture = NULL;
+
+       public function setUp() {
+               $this->fixture = new Tx_Extbase_Domain_Model_FrontendUser();
+       }
+
+       public function tearDown() {
+               unset($this->fixture);
+       }
+
+       /**
+        * @test
+        */
+       public function getUsernameInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getUsername()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setUsernameSetsUsername() {
+               $username = 'don.juan';
+               $this->fixture->setUsername($username);
+
+               $this->assertSame(
+                       $username,
+                       $this->fixture->getUsername()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getPasswordInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getPassword()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setPasswordSetsPassword() {
+               $password = 'f00Bar';
+               $this->fixture->setPassword($password);
+
+               $this->assertSame(
+                       $password,
+                       $this->fixture->getPassword()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setUsergroupSetsUsergroup() {
+               $usergroup = new Tx_Extbase_Persistence_ObjectStorage();
+               $usergroup->attach(new Tx_Extbase_Domain_Model_FrontendUserGroup('foo'));
+               $this->fixture->setUsergroup($usergroup);
+
+               $this->assertSame(
+                       $usergroup,
+                       $this->fixture->getUsergroup()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function addUsergroupAddsUserGroup() {
+               $usergroup = new Tx_Extbase_Domain_Model_FrontendUserGroup('foo');
+
+               $this->assertEquals(count($this->fixture->getUsergroup()), 0);
+               $this->fixture->addUsergroup($usergroup);
+               $this->assertEquals(count($this->fixture->getUsergroup()), 1);
+       }
+
+       /**
+        * @test
+        */
+       public function removeUsergroupRemovesUsergroup() {
+               $usergroup = new Tx_Extbase_Domain_Model_FrontendUserGroup('foo');
+
+               $this->fixture->addUsergroup($usergroup);
+               $this->assertEquals(count($this->fixture->getUsergroup()), 1);
+               $this->fixture->removeUsergroup($usergroup);
+               $this->assertEquals(count($this->fixture->getUsergroup()), 0);
+       }
+
+       /**
+        * @test
+        */
+       public function getNameInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setNameSetsName() {
+               $name = 'don juan';
+               $this->fixture->setName($name);
+
+               $this->assertSame(
+                       $name,
+                       $this->fixture->getName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getFirstNameInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getFirstName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setFirstNameSetsFirstName() {
+               $firstName = 'don';
+               $this->fixture->setFirstName($firstName);
+
+               $this->assertSame(
+                       $firstName,
+                       $this->fixture->getFirstName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getMiddleNameInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getMiddleName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setMiddleNameSetsMiddleName() {
+               $middleName = 'miguel';
+               $this->fixture->setMiddleName($middleName);
+
+               $this->assertSame(
+                       $middleName,
+                       $this->fixture->getMiddleName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getLastNameInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getLastName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setLastNameSetsLastName() {
+               $lastName = 'juan';
+               $this->fixture->setLastName($lastName);
+
+               $this->assertSame(
+                       $lastName,
+                       $this->fixture->getLastName()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getAddressInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getAddress()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setAddressSetsAddress() {
+               $address = 'foobar 42, foo';
+               $this->fixture->setAddress($address);
+
+               $this->assertSame(
+                       $address,
+                       $this->fixture->getAddress()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getTelephoneInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getTelephone()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setTelephoneSetsTelephone() {
+               $telephone = '42';
+               $this->fixture->setTelephone($telephone);
+
+               $this->assertSame(
+                       $telephone,
+                       $this->fixture->getTelephone()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getFaxInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getFax()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setFaxSetsFax() {
+               $fax = '42';
+               $this->fixture->setFax($fax);
+
+               $this->assertSame(
+                       $fax,
+                       $this->fixture->getFax()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getEmailInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getEmail()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setEmailSetsEmail() {
+               $email = 'don.juan@example.com';
+               $this->fixture->setEmail($email);
+
+               $this->assertSame(
+                       $email,
+                       $this->fixture->getEmail()
+               );
+       }
+
+       /**
+        * @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 getTitleInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getTitle()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setTitleSetsTitle() {
+               $title = 'foobar';
+               $this->fixture->setTitle($title);
+
+               $this->assertSame(
+                       $title,
+                       $this->fixture->getTitle()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getZipInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getZip()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setZipSetsZip() {
+               $zip = '42';
+               $this->fixture->setZip($zip);
+
+               $this->assertSame(
+                       $zip,
+                       $this->fixture->getZip()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getCityInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getCity()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setCitySetsCity() {
+               $city = 'foo';
+               $this->fixture->setCity($city);
+
+               $this->assertSame(
+                       $city,
+                       $this->fixture->getCity()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getCountryInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getCountry()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setCountrySetsCountry() {
+               $country = 'foo';
+               $this->fixture->setCountry($country);
+
+               $this->assertSame(
+                       $country,
+                       $this->fixture->getCountry()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getWwwInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getWww()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setWwwSetsWww() {
+               $www = 'foo.bar';
+               $this->fixture->setWww($www);
+
+               $this->assertSame(
+                       $www,
+                       $this->fixture->getWww()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getCompanyInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getCompany()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setCompanySetsCompany() {
+               $company = 'foo bar';
+               $this->fixture->setCompany($company);
+
+               $this->assertSame(
+                       $company,
+                       $this->fixture->getCompany()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getImageInitiallyReturnsEmptyString() {
+               $this->assertSame(
+                       '',
+                       $this->fixture->getImage()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setImageSetsImage() {
+               $image = 'foobar.gif';
+               $this->fixture->setImage($image);
+
+               $this->assertSame(
+                       $image,
+                       $this->fixture->getImage()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getLastloginInitiallyReturnsNull() {
+               $this->assertNull(
+                       $this->fixture->getLastlogin()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setLastloginSetsLastlogin() {
+               $date = new \DateTime();
+               $this->fixture->setLastlogin($date);
+
+               $this->assertSame(
+                       $date,
+                       $this->fixture->getLastlogin()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function getIsOnlineInitiallyReturnsNull() {
+               $this->assertNull(
+                       $this->fixture->getIsOnline()
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function setIsOnlineSetsIsOnline() {
+               $isOnline = new \DateTime();
+               $this->fixture->setIsOnline($isOnline);
+
+               $this->assertSame(
+                       $isOnline,
+                       $this->fixture->getIsOnline()
+               );
+       }
+}
+?>
\ No newline at end of file