Пример #1
0
 /**
  * @test
  */
 public function supportsChainingInAllSettersWithFakeNullArgument()
 {
     $asset = Asset::getInstance();
     $settableProperties = ObjectAccess::getSettablePropertyNames($asset);
     foreach ($settableProperties as $propertyName) {
         $setter = 'set' . ucfirst($propertyName);
         $asset = $asset->{$setter}(NULL);
         $this->assertInstanceOf('FluidTYPO3\\Vhs\\Asset', $asset, 'The ' . $setter . ' method does not support chaining');
     }
 }
Пример #2
0
 /**
  * @test
  */
 public function getSettablePropertyNamesReturnsPropertyNamesOfStdClass()
 {
     $stdClassObject = new \stdClass();
     $stdClassObject->property = 'string1';
     $stdClassObject->property2 = NULL;
     $settablePropertyNames = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getSettablePropertyNames($stdClassObject);
     $expectedPropertyNames = array('property', 'property2');
     $this->assertEquals($expectedPropertyNames, $settablePropertyNames, 'getSettablePropertyNames returns not all settable properties.');
 }
 /**
  * action clone news
  *
  * @param \int $uid	 
  * @return void
  */
 public function cloneNewsAction($uid = 0)
 {
     if ($uid > 0) {
         $defaultStorageFields = array("categories", "contentElements", "relatedFiles", "relatedLinks", "media", "falMedia", "falRelatedFiles");
         $testedStorageFields = array("categories");
         $storageClasses = array("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\LazyObjectStorage");
         $original = $this->newsRepository->findByUid($uid, FALSE);
         $clone = $this->objectManager->create('Tx_MooxNews_Domain_Model_News');
         // $product = source object
         $properties = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getSettablePropertyNames($original);
         foreach ($properties as $name) {
             $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($original, $name);
             if (!in_array($name, $defaultStorageFields) && (!is_object($value) || is_object($value) && !in_array(get_class($value), $storageClasses))) {
                 \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($clone, $name, $value);
             }
         }
         foreach ($properties as $name) {
             $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getProperty($original, $name);
             if (in_array($name, $defaultStorageFields) && in_array($name, $testedStorageFields) || !in_array($name, $defaultStorageFields) && is_object($value) && in_array(get_class($value), $storageClasses)) {
                 $getCall = "get" . ucfirst($name);
                 $setCall = "get" . ucfirst($name);
                 if (method_exists($original, $getCall)) {
                     $objects = $original->{$getCall}();
                     if (method_exists($clone->{$getCall}(), "attach")) {
                         if (count($objects)) {
                             foreach ($objects as $object) {
                                 if (\TYPO3\CMS\Extbase\Reflection\ObjectAccess::isPropertySettable($object, "uid")) {
                                     //$object->setUid(NULL);
                                 }
                                 $clone->{$getCall}()->attach($object);
                             }
                         }
                     } elseif (method_exists($clone, $setCall)) {
                         $clone->{$setCall}($objects);
                     }
                 }
             }
         }
         $clone->setTitle($original->getTitle() . " [Kopie]");
         $clone->setHidden(1);
         $this->newsRepository->add($clone);
         $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\PersistenceManagerInterface')->persistAll();
         $this->flashMessageContainer->add('', 'Eintrag wurde dupliziert', \TYPO3\CMS\Core\Messaging\FlashMessage::OK);
     }
     $this->redirect("index");
 }