protected function setUp() { $this->testingFramework = new Tx_Oelib_TestingFramework('tx_oelib'); Tx_Oelib_MapperRegistry::getInstance()->activateTestingMode($this->testingFramework); $this->dataMapper = Tx_Oelib_MapperRegistry::get('Tx_Oelib_Tests_Unit_Fixtures_TestingMapper'); $uid = $this->createTestRecord(); $this->subject = $this->dataMapper->find($uid); }
/** * @test */ public function getIsoAlpha2ZoneCodeReturnsIsoAlpha2ZoneCodeOfNorthRhineWestphalia() { /** @var tx_oelib_Mapper_FederalState $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FederalState'); /** @var Tx_Oelib_Model_FederalState $model */ $model = $mapper->find(88); self::assertSame('NW', $model->getIsoAlpha2ZoneCode()); }
/** * Sets the currency of the price to render based on the currency's ISO * alpha 3 code, e.g. "EUR" for Euro, "USD" for US dollars. * * @param string $isoAlpha3Code * the ISO alpha 3 code of the currency to set, must not be empty * * @return void */ public function setCurrencyFromIsoAlpha3Code($isoAlpha3Code) { try { /** @var tx_oelib_Mapper_Currency $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Currency'); $this->currency = $mapper->findByIsoAlpha3Code($isoAlpha3Code); } catch (Exception $exception) { $this->currency = NULL; } }
/** * @test */ public function getUserGroupsGetsRelatedGroupsAsList() { $groupMapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FrontEndUserGroup'); $group1 = $groupMapper->getNewGhost(); $group2 = $groupMapper->getNewGhost(); $groupUids = $group1->getUid() . ',' . $group2->getUid(); $uid = $this->testingFramework->createFrontEndUser($groupUids); /** @var Tx_Oelib_Model_FrontEndUser $user */ $user = $this->subject->find($uid); self::assertSame($groupUids, $user->getUserGroups()->getUids()); }
/** * Cleans up oelib after running a test. * * @return void */ public function cleanUp() { Tx_Oelib_ConfigurationProxy::purgeInstances(); Tx_Oelib_BackEndLoginManager::purgeInstance(); Tx_Oelib_ConfigurationRegistry::purgeInstance(); Tx_Oelib_FrontEndLoginManager::purgeInstance(); tx_oelib_Geocoding_Google::purgeInstance(); tx_oelib_headerProxyFactory::purgeInstance(); Tx_Oelib_MapperRegistry::purgeInstance(); Tx_Oelib_PageFinder::purgeInstance(); Tx_Oelib_Session::purgeInstances(); Tx_Oelib_TemplateHelper::purgeCachedConfigurations(); Tx_Oelib_TranslatorRegistry::purgeInstance(); /** @var Tx_Oelib_MailerFactory $mailerFactory */ $mailerFactory = t3lib_div::makeInstance('Tx_Oelib_MailerFactory'); $mailerFactory->cleanUp(); }
protected function tearDown() { $this->testingFramework->cleanUp(); Tx_Oelib_MapperRegistry::purgeInstance(); }
/** * @test */ public function getDecimalDigitsForKuwaitiDinarReturnsThree() { /** @var Tx_Oelib_Model_Currency $subject */ $subject = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Currency')->find(81); self::assertSame(3, $subject->getDecimalDigits()); }
/** * Sets the data of a place model based on the data given in $formData. * * @param tx_seminars_Model_Place $place the place model to set the data * @param string $prefix the prefix of the form fields in $formData * @param array[] $formData the form data to use for setting the place data * * @return void */ private static function setPlaceData(tx_seminars_Model_Place $place, $prefix, array $formData) { $countryUid = (int) $formData[$prefix . 'country']; if ($countryUid > 0) { try { /** @var tx_oelib_Mapper_Country $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Country'); /** @var Tx_Oelib_Model_Country $country */ $country = $mapper->find($countryUid); } catch (Exception $exception) { $country = NULL; } } else { $country = NULL; } $place->setTitle(trim(strip_tags($formData[$prefix . 'title']))); $place->setAddress(trim(strip_tags($formData[$prefix . 'address']))); $place->setZip(trim(strip_tags($formData[$prefix . 'zip']))); $place->setCity(trim(strip_tags($formData[$prefix . 'city']))); $place->setCountry($country); $place->setHomepage(trim(strip_tags($formData[$prefix . 'homepage']))); $place->setDirections(trim($formData[$prefix . 'directions'])); $place->setNotes(trim(strip_tags($formData[$prefix . 'notes']))); }
/** * @test */ public function hasCountryWithCountryReturnsTrue() { /** @var tx_oelib_Mapper_Country $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Country'); /** @var Tx_Oelib_Model_Country $country */ $country = $mapper->find(54); $this->subject->setCountry($country); self::assertTrue($this->subject->hasCountry()); }
protected function setUp() { $this->testingFramework = new Tx_Oelib_TestingFramework('tx_oelib'); $this->subject = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUserGroup'); }
/** * Deletes all one-to-many related models of this model. * * @param Tx_Oelib_Model $model * the model for which to delete the related models * * @return void */ private function deleteOneToManyRelations(Tx_Oelib_Model $model) { $data = $model->getData(); foreach ($this->relations as $key => $mapperName) { if ($this->isOneToManyRelationConfigured($key)) { $relatedModels = $data[$key]; if (!is_object($relatedModels)) { continue; } $mapper = Tx_Oelib_MapperRegistry::get($mapperName); /** @var Tx_Oelib_Model $relatedModel */ foreach ($relatedModels as $relatedModel) { $mapper->delete($relatedModel); } } } }
/** * @test * * @expectedException BadMethodCallException */ public function setThrowsExceptionIfTheMapperTypeAlreadyIsRegistered() { Tx_Oelib_MapperRegistry::get('Tx_Oelib_Tests_Unit_Fixtures_TestingMapper'); $mapper = new tx_oelib_Tests_Unit_Fixtures_TestingMapper(); Tx_Oelib_MapperRegistry::set('Tx_Oelib_Tests_Unit_Fixtures_TestingMapper', $mapper); }
/** * @test */ public function copyEventRedirectsToRequestUrl() { /** @var tx_seminars_Mapper_Event|PHPUnit_Framework_MockObject_MockObject $mapper */ $mapper = $this->getMock('tx_seminars_Mapper_Event', array('save')); Tx_Oelib_MapperRegistry::set('tx_seminars_Mapper_Event', $mapper); /** @var tx_seminars_Model_Event $event */ $event = $mapper->getLoadedTestingModel(array()); $className = $this->createAccessibleProxyClass(); /** @var tx_seminars_FrontEnd_DefaultController $fixture */ $fixture = new $className(); $fixture->copyEvent($event); $currentUrl = t3lib_div::locationHeaderUrl(t3lib_div::getIndpEnv('REQUEST_URI')); self::assertSame('Location: ' . $currentUrl, $this->headerCollector->getLastAddedHeader()); }
/** * @test */ public function setLoggedInUserForUserGivenAndAlreadyStoredLoggedInUserOverridesTheOldUserWithTheNewOne() { /** @var tx_oelib_Model_BackEndUser $oldBackEndUser */ $oldBackEndUser = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUser')->getNewGhost(); $this->subject->setLoggedInUser($oldBackEndUser); /** @var tx_oelib_Model_BackEndUser $newBackEndUser */ $newBackEndUser = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUser')->getNewGhost(); $this->subject->setLoggedInUser($newBackEndUser); self::assertSame($newBackEndUser, $this->subject->getLoggedInUser()); }
/** * @test */ public function getLoggedInUserWithLoadedModelOfUserNotInDatabaseReturnsThatInstance() { $this->testingFramework->createFakeFrontEnd(); $user = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FrontEndUser')->getNewGhost(); $user->setData(array()); $this->testingFramework->loginFrontEndUser($user->getUid()); self::assertSame($user, $this->subject->getLoggedInUser()); }
/** * @test */ public function loginFrontEndUserMappedAsGhostAndInDatabaseSetsGroupDataOfUser() { $this->subject->createFrontEndPage(); $this->subject->createFakeFrontEnd(); $feUserGroupUid = $this->subject->createFrontEndUserGroup(array('title' => 'foo')); /** @var tx_oelib_Mapper_FrontEndUser $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FrontEndUser'); /** @var tx_oelib_Model_FrontEndUser $user */ $user = $mapper->find($this->subject->createFrontEndUser($feUserGroupUid)); $this->subject->loginFrontEndUser($user->getUid()); self::assertSame(array($feUserGroupUid => 'foo'), $this->getFrontEndController()->fe_user->groupData['title']); }
/** * Gets the currently logged-in back-end user. * * @param string $mapperName * the name of the mapper to use for getting the back-end user model, must not be empty * * @return Tx_Oelib_Model_BackEndUser the logged-in back-end user, will be NULL if no user is logged in */ public function getLoggedInUser($mapperName = 'tx_oelib_Mapper_BackEndUser') { if ($mapperName === '') { throw new InvalidArgumentException('$mapperName must not be empty.', 1331318483); } if (!$this->isLoggedIn()) { return NULL; } if ($this->loggedInUser) { return $this->loggedInUser; } /** @var tx_oelib_Mapper_BackEndUser $mapper */ $mapper = Tx_Oelib_MapperRegistry::get($mapperName); /** @var Tx_Oelib_Model_BackEndUser $user */ $user = $mapper->find($this->getBackEndUserAuthentication()->user['uid']); return $user; }
/** * @test */ public function userGroupRelationIsUserGroupList() { /** @var Tx_Oelib_Model_BackEndUserGroup $group */ $group = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUserGroup')->getNewGhost(); $groupUid = $group->getUid(); $userUid = $this->subject->getLoadedTestingModel(array('usergroup' => $groupUid))->getUid(); /** @var Tx_Oelib_Model_BackEndUser $user */ $user = $this->subject->find($userUid); self::assertInstanceOf('Tx_Oelib_Model_BackEndUserGroup', $user->getGroups()->first()); }
/** * Fakes that a front-end user has logged in. * * If a front-end user currently is logged in, he/she will be logged out * first. * * Note: To set the logged-in users group data properly, the front-end user * and his groups must actually exist in the database. * * @param int $userId UID of the FE user, must not necessarily exist in the database, must be > 0 * * @return void * * @throws InvalidArgumentException * @throws BadMethodCallException if no front end has been created */ public function loginFrontEndUser($userId) { if ((int) $userId <= 0) { throw new InvalidArgumentException('The user ID must be > 0.', 1331490798); } if (!$this->hasFakeFrontEnd()) { throw new BadMethodCallException('Please create a front end before calling loginFrontEndUser.', 1331490812); } if ($this->isLoggedIn()) { $this->logoutFrontEndUser(); } /** @var tx_oelib_Mapper_FrontEndUser $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FrontEndUser'); // loads the model from database if it is a ghost $mapper->existsModel($userId); $dataToSet = $mapper->find($userId)->getData(); $dataToSet['uid'] = $userId; if (isset($dataToSet['usergroup'])) { /** @var Tx_Oelib_List $userGroups */ $userGroups = $dataToSet['usergroup']; $dataToSet['usergroup'] = $userGroups->getUids(); } $this->suppressFrontEndCookies(); // Instead of passing the actual user data to createUserSession, we // pass an empty array to improve performance (e.g. no session record // will be written to the database). $frontEnd = $this->getFrontEndController(); $frontEnd->fe_user->createUserSession(array('uid' => $userId, 'disableIPlock' => TRUE)); $frontEnd->fe_user->user = $dataToSet; $frontEnd->fe_user->fetchGroupData(); $frontEnd->loginUser = TRUE; }
/** * Returns the country of this user as Tx_Oelib_Model_Country. * * Note: This function uses the "country code" field, not the free-text country field. * * @return Tx_Oelib_Model_Country the country of this user, will be NULL if no valid country has been set */ public function getCountry() { $countryCode = $this->getAsString('static_info_country'); if ($countryCode === '') { return NULL; } try { /** @var tx_oelib_Mapper_Country $countryMapper */ $countryMapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Country'); /** @var Tx_Oelib_Model_Country $country */ $country = $countryMapper->findByIsoAlpha3Code($countryCode); } catch (tx_oelib_Exception_NotFound $exception) { $country = NULL; } return $country; }
/** * Returns the event for this registration form. * * @return tx_seminars_Model_Event */ public function getEvent() { /** @var $eventMapper tx_seminars_Mapper_Event */ $eventMapper = Tx_Oelib_MapperRegistry::get('tx_seminars_Mapper_Event'); /** @var tx_seminars_Model_Event $event */ $event = $eventMapper->find($this->getSeminar()->getUid()); return $event; }
/** * @test */ public function getAllGroupsForGroupWithSubgroupCycleReturnsBothGroups() { $group1 = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUserGroup')->getNewGhost(); $group2 = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_BackEndUserGroup')->getNewGhost(); $subgroups1 = new Tx_Oelib_List(); $subgroups1->add($group2); $group1->setData(array('subgroup' => $subgroups1)); $subgroups2 = new Tx_Oelib_List(); $subgroups2->add($group1); $group2->setData(array('subgroup' => $subgroups2)); $groups = new Tx_Oelib_List(); $groups->add($group1); $this->subject->setData(array('usergroup' => $groups)); self::assertSame(2, $this->subject->getAllGroups()->count()); }
/** * Gets the currently logged-in front-end user. * * @param string $mapperName the name of the mapper to use for getting the front-end user model, must not be empty * * @return Tx_Oelib_Model_FrontEndUser the logged-in front-end user, will * be NULL if no user is logged in or * if there is no front end */ public function getLoggedInUser($mapperName = 'tx_oelib_Mapper_FrontEndUser') { if ($mapperName === '') { throw new InvalidArgumentException('$mapperName must not be empty.', 1331488730); } if (!$this->isLoggedIn()) { return NULL; } if ($this->loggedInUser !== NULL) { $user = $this->loggedInUser; } else { /** @var Tx_Oelib_Mapper_FrontEndUser $mapper */ $mapper = Tx_Oelib_MapperRegistry::get($mapperName); /** @var Tx_Oelib_Model_FrontEndUser $user */ $user = $mapper->find($this->getFrontEndController()->fe_user->user['uid']); } return $user; }
/** * Purges the current instance so that getInstance will create a new * instance. * * @return void */ public static function purgeInstance() { self::$instance = NULL; }
/** * @test */ public function findAllByRelationIgnoresIgnoreList() { $model = $this->subject->find($this->testingFramework->createRecord('tx_oelib_test')); $mapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Tests_Unit_Fixtures_TestingChildMapper'); $relatedModel = $mapper->find($this->testingFramework->createRecord('tx_oelib_testchild', array('parent' => $model->getUid()))); $ignoredRelatedModel = $mapper->find($this->testingFramework->createRecord('tx_oelib_testchild', array('parent' => $model->getUid()))); $ignoreList = new Tx_Oelib_List(); $ignoreList->add($ignoredRelatedModel); $result = Tx_Oelib_MapperRegistry::get('tx_oelib_Tests_Unit_Fixtures_TestingChildMapper')->findAllByRelation($model, 'parent', $ignoreList); self::assertSame(1, $result->count()); self::assertSame($relatedModel, $result->first()); }
/** * Creates a hidden copy of $event and saves it. * * @param tx_seminars_Model_Event $event the event copy * * @return void */ protected function copyEvent(tx_seminars_Model_Event $event) { $copy = clone $event; $copy->markAsHidden(); $copy->setRegistrations(new Tx_Oelib_List()); /** @var tx_seminars_Mapper_Event $mapper */ $mapper = Tx_Oelib_MapperRegistry::get('tx_seminars_Mapper_Event'); $mapper->save($copy); $this->redirectToCurrentUrl(); }
/** * @test */ public function getIsoAlpha3CodeReturnsIsoAlpha3CodeOfUnitedKingdomOfGreatBritain() { /** @var Tx_Oelib_Model_Country $subject */ $subject = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_Country')->find(74); self::assertSame('GBR', $subject->getIsoAlpha3Code()); }