/** * @test */ public function addWithoutParentModelMarksParentModelAsDirty() { $parentModel = new Tx_Oelib_Tests_Unit_Fixtures_TestingModel(); self::assertFalse($parentModel->isDirty()); $this->subject->setParentModel($parentModel); $model = new Tx_Oelib_Tests_Unit_Fixtures_TestingModel(); $this->subject->add($model); self::assertTrue($parentModel->isDirty()); }
/** * @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()); }
/** * @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()); }
/** * @test */ public function filterByDistanceCanReturnTwoElements() { $bonn = new Tx_Oelib_Tests_Unit_Fixtures_TestingGeo(); $bonn->setGeoCoordinates(array('latitude' => 50.72254683, 'longitude' => 7.07519531)); $cologne = new Tx_Oelib_Tests_Unit_Fixtures_TestingGeo(); $cologne->setGeoCoordinates(array('latitude' => 50.94458443, 'longitude' => 6.9543457)); $list = new Tx_Oelib_List(); $list->add($bonn); $list->add($cologne); $filteredList = $this->subject->filterByDistance($list, $cologne, 27.0); self::assertSame(2, $filteredList->count()); }
/** * Clone. * * @throws \BadMethodCallException */ public function __clone() { if ($this->isReadOnly()) { throw new \BadMethodCallException('Read-only models cannot be cloned.', 1436453245); } if ($this->isDead()) { throw new \BadMethodCallException('Deleted models cannot be cloned.', 1436453107); } if ($this->isLoading()) { throw new \BadMethodCallException('Models cannot be cloned while they are loading.', 1436453245); } if ($this->isGhost()) { $this->load(); } $this->resetUid(); /** @var int|string|bool|float|null|Tx_Oelib_List|Tx_Oelib_Model $dataItem */ foreach ($this->data as $key => $dataItem) { if ($dataItem instanceof Tx_Oelib_List) { /** Tx_Oelib_List $dataItem */ if ($dataItem->isRelationOwnedByParent()) { $newDataItem = new Tx_Oelib_List(); $newDataItem->markAsOwnedByParent(); /** @var Tx_Oelib_Model $childModel */ foreach ($dataItem as $childModel) { $newDataItem->add(clone $childModel); } } else { $newDataItem = clone $dataItem; } $newDataItem->setParentModel($this); $this->set($key, $newDataItem); } } $this->markAsDirty(); }
/** * @test */ public function copyRemovesRegistrationsFromEvent() { /** @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('title' => 'TDD for starters')); $registrations = new Tx_Oelib_List(); $registrations->add(new tx_seminars_Model_Registration()); $event->setRegistrations($registrations); $hiddenClone = clone $event; $hiddenClone->markAsHidden(); $hiddenClone->setRegistrations(new Tx_Oelib_List()); $mapper->expects(self::once())->method('save')->with($hiddenClone); $className = $this->createAccessibleProxyClass(); /** @var tx_seminars_FrontEnd_DefaultController $fixture */ $fixture = new $className(); $fixture->copyEvent($event); }
/** * @test */ public function hasGroupMembershipForUserNoneOfTheProvidedGroupsReturnsFalse() { $groupMapper = Tx_Oelib_MapperRegistry::get('tx_oelib_Mapper_FrontEndUserGroup'); $list = new Tx_Oelib_List(); $list->add($groupMapper->getNewGhost()); $list->add($groupMapper->getNewGhost()); $this->subject->setData(array('usergroup' => $list)); self::assertFalse($this->subject->hasGroupMembership($groupMapper->getNewGhost()->getUid() . ',' . $groupMapper->getNewGhost()->getUid())); }