/** * @test */ public function setUsergroupSetsUsergroup() { $usergroup = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $usergroup->attach(new \TYPO3\CMS\Extbase\Domain\Model\FrontendUserGroup('foo')); $this->fixture->setUsergroup($usergroup); $this->assertSame($usergroup, $this->fixture->getUsergroup()); }
/** * Converts string of tags to an object * @param string $tags * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage */ public function initTags($tags) { /* @var \Mittwald\Typo3Forum\Domain\Model\Forum\Tag */ $objTags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $tagArray = array_unique(explode(',', $tags)); foreach ($tagArray as $tagName) { $tagName = ucfirst(trim($tagName)); if ($tagName == "") { continue; } $searchResult = $this->tagRepository->findTagWithSpecificName($tagName); if ($searchResult[0] != false) { $searchResult[0]->increaseTopicCount(); $objTags->attach($searchResult[0]); } else { /* @var \Mittwald\Typo3Forum\Domain\Model\Forum\Tag $tag */ $tag = $this->objectManager->get('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Tag'); $tag->setName($tagName); $tag->setCrdate(new \DateTime()); $tag->increaseTopicCount(); $objTags->attach($tag); } } return $objTags; }
/** * Converts HTML-array to an object * @param array $attachments * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage */ public function initAttachments(array $attachments) { /* @var \Mittwald\Typo3Forum\Domain\Model\Forum\Attachment */ $objAttachments = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); foreach ($attachments as $attachmentID => $attachment) { if ($attachment['name'] == '') { continue; } $attachmentObj = $this->objectManager->get('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Attachment'); $tmp_name = $_FILES['tx_typo3forum_pi1']['tmp_name']['attachments'][$attachmentID]; $mime_type = mime_content_type($tmp_name); //Save in ObjectStorage and in file system $attachmentObj->setFilename($attachment['name']); $attachmentObj->setRealFilename(sha1($attachment['name'] . time())); $attachmentObj->setMimeType($mime_type); //Create dir if not exists $tca = $attachmentObj->getTCAConfig(); $path = $tca['columns']['real_filename']['config']['uploadfolder']; if (!file_exists($path)) { mkdir($path, '0777', true); } //upload file and put in object storage $res = \TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($tmp_name, $attachmentObj->getAbsoluteFilename()); if ($res === true) { $objAttachments->attach($attachmentObj); } } return $objAttachments; }
/** * Converts an array into an objectStorage * * @param array $array * * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage */ public static function arrayToObjectStorage(array $array = []) { $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); foreach ($array as $element) { $objectStorage->attach($element); } return $objectStorage; }
/** * @test */ public function setPostForObjectStorageContainingPostSetsPost() { $post = new \Dawin\LgLgRbBlog\Domain\Model\Post(); $objectStorageHoldingExactlyOnePost = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOnePost->attach($post); $this->subject->setPost($objectStorageHoldingExactlyOnePost); $this->assertAttributeEquals($objectStorageHoldingExactlyOnePost, 'post', $this->subject); }
/** * @test */ public function setTagsForObjectStorageContainingTagSetsTags() { $tag = new \Dawin\Aces\Domain\Model\Tag(); $objectStorageHoldingExactlyOneTags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneTags->attach($tag); $this->subject->setTags($objectStorageHoldingExactlyOneTags); $this->assertAttributeEquals($objectStorageHoldingExactlyOneTags, 'tags', $this->subject); }
/** * @test */ public function setTeilnehmerMannschaftForObjectStorageContainingTeilnehmerMannschaftSetsTeilnehmerMannschaft() { $teilnehmerMannschaft = new \Ben\Wi4ka3\Domain\Model\TeilnehmerMannschaft(); $objectStorageHoldingExactlyOneTeilnehmerMannschaft = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneTeilnehmerMannschaft->attach($teilnehmerMannschaft); $this->subject->setTeilnehmerMannschaft($objectStorageHoldingExactlyOneTeilnehmerMannschaft); $this->assertAttributeEquals($objectStorageHoldingExactlyOneTeilnehmerMannschaft, 'teilnehmerMannschaft', $this->subject); }
/** * @test */ public function setStagesForObjectStorageContainingStageSetsStages() { $stage = new \Xenio\Seenwanderung\Domain\Model\Stage(); $objectStorageHoldingExactlyOneStages = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneStages->attach($stage); $this->subject->setStages($objectStorageHoldingExactlyOneStages); $this->assertAttributeEquals($objectStorageHoldingExactlyOneStages, 'stages', $this->subject); }
/** * @test */ public function setContentSliderItemsForObjectStorageContainingContentSliderItemSetsContentSliderItems() { $contentSliderItem = new \Winkel\WinkelCslider\Domain\Model\ContentSliderItem(); $objectStorageHoldingExactlyOneContentSliderItems = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneContentSliderItems->attach($contentSliderItem); $this->subject->setContentSliderItems($objectStorageHoldingExactlyOneContentSliderItems); $this->assertAttributeEquals($objectStorageHoldingExactlyOneContentSliderItems, 'contentSliderItems', $this->subject); }
/** * @test */ public function setPlenigoCategoryForObjectStorageContainingPremiumContentCategoriesSetsPlenigoCategory() { $plenigoCategory = new \Plenigo\PlenigoForNews\Domain\Model\PremiumContentCategories(); $objectStorageHoldingExactlyOnePlenigoCategory = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOnePlenigoCategory->attach($plenigoCategory); $this->subject->setPlenigoCategory($objectStorageHoldingExactlyOnePlenigoCategory); $this->assertAttributeEquals($objectStorageHoldingExactlyOnePlenigoCategory, 'plenigoCategory', $this->subject); }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null) { $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); foreach ($convertedChildProperties as $subProperty) { $objectStorage->attach($subProperty); } return $objectStorage; }
/** * Actually convert from $source to $targetType, taking into account the fully * built $convertedChildProperties and $configuration. * * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage * @api */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = NULL) { $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); foreach ($convertedChildProperties as $subPropertyKey => $subProperty) { $objectStorage->attach($subProperty); $this->objectStorageMappingService->mapSplObjectHashToSourceKey(spl_object_hash($subProperty), $subPropertyKey); } return $objectStorage; }
/** * @test */ public function removeFormatFromObjectStorageHoldingFormats() { $format = new \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat(); $localObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $localObjectStorage->attach($format); $localObjectStorage->detach($format); $this->subject->addFormat($format); $this->subject->removeFormat($format); $this->assertEquals($localObjectStorage, $this->subject->getFormats()); }
/** * @test */ public function removeTranslationFromObjectStorageHoldingTranslations() { $translation = new \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation(); $localObjectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $localObjectStorage->attach($translation); $localObjectStorage->detach($translation); $this->fixture->addTranslation($translation); $this->fixture->removeTranslation($translation); $this->assertEquals($localObjectStorage, $this->fixture->getTranslations()); }
/** * @test */ public function setTransactionsSetsTransactions() { $beVariantAttributeOption1 = new \Extcode\Cart\Domain\Model\Product\BeVariantAttributeOption(); $beVariantAttributeOption2 = new \Extcode\Cart\Domain\Model\Product\BeVariantAttributeOption(); $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorage->attach($beVariantAttributeOption1); $objectStorage->attach($beVariantAttributeOption2); $this->beVariantAttribute->setBeVariantAttributeOptions($objectStorage); $this->assertContains($beVariantAttributeOption1, $this->beVariantAttribute->getBeVariantAttributeOptions()); $this->assertContains($beVariantAttributeOption2, $this->beVariantAttribute->getBeVariantAttributeOptions()); }
/** * Test for isValid() * * @param \string $value * @param \bool $expectedResult * @return void * @dataProvider validateIsValidReturnsBoolDataProvider * @test */ public function validateIsValidReturnsBool($value, $expectedResult) { $mail = new \In2code\Powermail\Domain\Model\Mail(); $field = new \In2code\Powermail\Domain\Model\Field(); $field->setType(1); $answer1 = new \In2code\Powermail\Domain\Model\Answer(); $answer1->setValueType(3); $answer1->setValue($value); $answer1->setField($field); $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorage->attach($answer1); $mail->setAnswers($objectStorage); $result = $this->generalValidatorMock->_callRef('isValid', $mail); $this->assertSame($result, $expectedResult); }
/** * findByUidList - find and sort entities defined by list * * @param array $list * @param int $mode Current modes are 0=excludeList, default=includeList * * @return null|\TYPO3\CMS\Extbase\Persistence\ObjectStorage */ public function findByUidList(array $list = [], $mode = 1) { /** In order to keep orderings as set in flexForm, we fetch record by record, storing them into an ObjectStorage */ $return = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); if ($mode === 0) { /** @var \Ecom\EcomToolbox\Domain\Model\Territory $territory */ foreach ($this->findAll() as $territory) { if ($territory instanceof \Ecom\EcomToolbox\Domain\Model\Territory && $territory->isVerified() && !in_array($territory->getUid(), $list)) { $return->attach($territory); } } } else { foreach ($list as $uid) { /** @var \Ecom\EcomToolbox\Domain\Model\Territory $territory */ $territory = $this->findByUid($uid); if ($territory instanceof \Ecom\EcomToolbox\Domain\Model\Territory && $territory->isVerified()) { $return->attach($territory); } } } return $return; }
/** * @test */ public function setChildren4ForObjectStorageContainingChild4SetsChildren4() { $children4 = new \FIXTURE\TestExtension\Domain\Model\Child4(); $objectStorageHoldingExactlyOneChildren4 = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneChildren4->attach($children4); $this->subject->setChildren4($objectStorageHoldingExactlyOneChildren4); self::assertAttributeEquals($objectStorageHoldingExactlyOneChildren4, 'children4', $this->subject); }
/** * @test */ public function setContactForObjectStorageContainingVcardSetsContact() { $contact = new \PHTH\Dracv\Domain\Model\Vcard(); $objectStorageHoldingExactlyOneContact = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneContact->attach($contact); $this->subject->setContact($objectStorageHoldingExactlyOneContact); $this->assertAttributeEquals($objectStorageHoldingExactlyOneContact, 'contact', $this->subject); }
/** * @test */ public function collectionValidatorCallsCollectionElementValidatorWhenValidatingObjectStorages() { $entity = new \TYPO3\CMS\Extbase\Tests\Fixture\Entity('Foo'); $elementType = \TYPO3\CMS\Extbase\Tests\Fixture\Entity::class; $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorage->attach($entity); $aValidator = new \TYPO3\CMS\Extbase\Validation\Validator\GenericObjectValidator(array()); $this->mockValidatorResolver->expects($this->never())->method('createValidator'); $this->mockValidatorResolver->expects($this->once())->method('getBaseValidatorConjunction')->with($elementType)->will($this->returnValue($aValidator)); $this->validator->_set('options', array('elementType' => $elementType)); $this->validator->validate($objectStorage); }
/** * Test if related links can be set * * @test * @return void */ public function relatedLinksCanBeSet() { $link = new Link(); $link->setTitle('fo'); $related = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $related->attach($link); $this->newsDomainModelInstance->setRelatedLinks($related); $this->assertEquals($related, $this->newsDomainModelInstance->getRelatedLinks()); }
/** * @test */ public function setRealtedcourseForObjectStorageContainingCourseSetsRealtedcourse() { $realtedcourse = new \Typo3\Course\Domain\Model\Course(); $objectStorageHoldingExactlyOneRealtedcourse = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneRealtedcourse->attach($realtedcourse); $this->subject->setRealtedcourse($objectStorageHoldingExactlyOneRealtedcourse); $this->assertAttributeEquals($objectStorageHoldingExactlyOneRealtedcourse, 'realtedcourse', $this->subject); }
/** * @test * @return void */ public function getDetailPidFromCategoriesReturnsCorrectValue() { $viewHelper = $this->getAccessibleMock('Tx_MooxNews_ViewHelpers_LinkViewHelper', array('dummy')); $newsItem = new Tx_MooxNews_Domain_Model_News(); $categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $category1 = new Tx_MooxNews_Domain_Model_Category(); $categories->attach($category1); $category2 = new Tx_MooxNews_Domain_Model_Category(); $category2->setSinglePid('123'); $categories->attach($category2); $category3 = new Tx_MooxNews_Domain_Model_Category(); $category3->setSinglePid('456'); $categories->attach($category3); $newsItem->setCategories($categories); $result = $viewHelper->_call('getDetailPidFromCategories', array(), $newsItem); $this->assertEquals(123, $result); }
/** * @test */ public function theRelationsAreDirtyOnReAddingAtOtherPosition() { $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $object1 = new \StdClass(); $object2 = new \StdClass(); $objectStorage->attach($object1); $objectStorage->attach($object2); $clonedStorage = clone $objectStorage; $objectStorage->removeAll($clonedStorage); $objectStorage->attach($object2); $objectStorage->attach($object1); $this->assertTrue($objectStorage->isRelationDirty($object1)); $this->assertTrue($objectStorage->isRelationDirty($object2)); }
/** * generic isValid method * * @param mixed $object * @throws \Exception * * @return bool */ public function isValid($object) { $result = TRUE; $this->validationFields = $this->getValidationFields(); $objectValidators = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); /** @var GenericObjectValidator $objectValidator */ $objectValidator = $this->objectManager->get(GenericObjectValidator::class, array()); $objectValidators->attach($objectValidator); // add the configured object validators if (array_key_exists('objectValidators', $this->validationFields) && is_array($this->validationFields['objectValidators'])) { foreach ($this->validationFields['objectValidators'] as $validationRule) { $parsedAnnotation = $this->validatorResolver->parseValidatorAnnotation($validationRule); foreach ($parsedAnnotation['validators'] as $validatorConfiguration) { $newValidator = $this->validatorResolver->createValidator($validatorConfiguration['validatorName'], $validatorConfiguration['validatorOptions']); if ($newValidator === NULL) { throw new \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException('Invalid typoscript validation rule in ' . $object . '::' . $validationRule . ': Could not resolve class name for validator "' . $validatorConfiguration['validatorName'] . '".', 1241098027); } $objectValidators->attach($newValidator); } } } // add the configured property validators if (array_key_exists('propertyValidators', $this->validationFields) && is_array($this->validationFields['propertyValidators'])) { foreach ($this->validationFields['propertyValidators'] as $validationField => $validationRules) { /** * if the property to validate is a child property then create a new $typoScriptChildValidator * with the validation config of the child */ if (array_key_exists('propertyValidators', $validationRules)) { /** @var TypoScriptChildValidator $typoScriptChildValidator */ $typoScriptChildValidator = $this->objectManager->get(TypoScriptChildValidator::class); $typoScriptChildValidator->setValidationFields($validationRules); $typoScriptChildValidator->setChildPropertyName($validationField); $child = call_user_func_array(array($object, 'get' . $validationField), array()); $typoScriptChildValidator->setChildObject($child); $objectValidators->attach($typoScriptChildValidator); continue; } // only check if it is not a objectValidator (just check propertyValidators) if (!property_exists($object, $validationField) && $validationField != 'objectValidators') { throw new \Exception('The property: "' . $validationField . '" does not exist for class: "' . get_class($object) . '"'); } foreach ($validationRules as $validationRule) { $parsedAnnotation = $this->validatorResolver->parseValidatorAnnotation($validationRule); foreach ($parsedAnnotation['validators'] as $validatorConfiguration) { $newValidator = $this->validatorResolver->createValidator($validatorConfiguration['validatorName'], $validatorConfiguration['validatorOptions']); if ($newValidator === NULL) { throw new \TYPO3\CMS\Extbase\Validation\Exception\NoSuchValidatorException('Invalid typoscript validation rule in ' . $object . '::' . $validationField . ': Could not resolve class name for validator "' . $validatorConfiguration['validatorName'] . '".', 1241098027); } $objectValidator->addPropertyValidator($validationField, $newValidator); } } } } foreach ($objectValidators as $objectValidator) { if ($objectValidator instanceof TypoScriptChildValidator) { $typoScriptChildValidator = $objectValidator; $result = $typoScriptChildValidator->validate($typoScriptChildValidator->getChildObject()); $this->result->forProperty($typoScriptChildValidator->getChildPropertyName())->merge($result); } else { $this->result->merge($objectValidator->validate($object)); } if ($this->result->hasErrors()) { $result = FALSE; } } return $result; }
/** * @test */ public function setAdditionalImageForObjectStorageContainingFilesSetsFiles() { $file = new \TYPO3\CMS\Extbase\Domain\Model\FileReference(); $objectStorageHoldingExactlyOneFile = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneFile->attach($file); $this->subject->setAdditionalImage($objectStorageHoldingExactlyOneFile); $this->assertAttributeEquals($objectStorageHoldingExactlyOneFile, 'additionalImage', $this->subject); }
/** * @test */ public function setRelation4ForObjectStorageContainingAuthorSetsRelation4() { $relation4 = new \Blog\MbhAhBlog\Domain\Model\Author(); $objectStorageHoldingExactlyOneRelation4 = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneRelation4->attach($relation4); $this->subject->setRelation4($objectStorageHoldingExactlyOneRelation4); $this->assertAttributeEquals($objectStorageHoldingExactlyOneRelation4, 'relation4', $this->subject); }
/** * @test */ public function setCategoriesForObjectStorageContainingCategorySetsCategories() { $category = new \DAWIN\BlbBlog\Domain\Model\Category(); $objectStorageHoldingExactlyOneCategories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneCategories->attach($category); $this->subject->setCategories($objectStorageHoldingExactlyOneCategories); $this->assertAttributeEquals($objectStorageHoldingExactlyOneCategories, 'categories', $this->subject); }
/** * @test */ public function setSubGroupsForObjectStorageContainingBackendUserGroupSetsSubGroups() { $subGroup = new \R3H6\BeuserManager\Domain\Model\BackendUserGroup(); $objectStorageHoldingExactlyOneSubGroups = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $objectStorageHoldingExactlyOneSubGroups->attach($subGroup); $this->subject->setSubGroups($objectStorageHoldingExactlyOneSubGroups); $this->assertAttributeEquals($objectStorageHoldingExactlyOneSubGroups, 'subGroups', $this->subject); }
/** * @test */ public function getPropertyPathCanAccessPropertiesOfAnExtbaseObjectStorageObject() { $objectStorage = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage(); $exampleObject = new \stdClass(); $exampleObject->key = 'value'; $exampleObject2 = new \stdClass(); $exampleObject2->key = 'value2'; $objectStorage->attach($exampleObject); $objectStorage->attach($exampleObject2); $array = array('parent' => $objectStorage); $this->assertSame('value', \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array, 'parent.0.key')); $this->assertSame('value2', \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($array, 'parent.1.key')); }