/**
  * @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);
 }
Exemple #2
0
 /**
  * Test if category can be set
  *
  * @test
  * @return void
  */
 public function categoryCanBeSet()
 {
     $category = new Tx_MooxNews_Domain_Model_Category();
     $category->setTitle('fo');
     $categories = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     $categories->attach($category);
     $this->newsDomainModelInstance->setCategories($categories);
     $this->assertEquals($categories, $this->newsDomainModelInstance->getCategories());
 }
 /**
  * Add category image when not already present
  *
  * @param Tx_MooxNews_Domain_Model_Category $category
  * @param $image
  */
 protected function setFileRelationFromImage($category, $image)
 {
     // get fileObject by given identifier (file UID, combined identifier or path/filename)
     try {
         $newImage = $this->getResourceFactory()->retrieveFileOrFolderObject($image);
     } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $exception) {
         $newImage = FALSE;
     }
     // only proceed if image is found
     if (!$newImage instanceof \TYPO3\CMS\Core\Resource\File) {
         return;
     }
     // new image found check if this isn't already
     $existingImages = $category->getImages();
     if (!is_null($existingImages) && $existingImages->count() !== 0) {
         /** @var $item Tx_MooxNews_Domain_Model_FileReference */
         foreach ($existingImages as $item) {
             // only check already persisted items
             if ($item->getFileUid() === (int) $newImage->getUid() || $item->getUid() && $item->getOriginalResource()->getName() === $newImage->getName() && $item->getOriginalResource()->getSize() === (int) $newImage->getSize()) {
                 $newImage = FALSE;
                 break;
             }
         }
     }
     if ($newImage) {
         // file not inside a storage then search for existing file or copy the one form storage 0 to the import folder
         if ($newImage->getStorage()->getUid() === 0) {
             // search DB for same file based on hash (to prevent duplicates)
             $existingFile = $this->findFileByHash($newImage->getSha1());
             // no exciting file then copy file to import folder
             if ($existingFile === NULL) {
                 $newImage = $this->getResourceStorage()->copyFile($newImage, $this->getImportFolder());
             } else {
                 $newImage = $existingFile;
             }
         }
         /** @var Tx_MooxNews_Domain_Model_FileReference $fileReference */
         $fileReference = $this->objectManager->get('Tx_MooxNews_Domain_Model_FileReference');
         $fileReference->setFileUid($newImage->getUid());
         $fileReference->setPid($category->getPid());
         $category->addImage($fileReference);
     }
 }
Exemple #4
0
 /**
  * Test if importSource can be set
  *
  * @test
  * @return void
  */
 public function importSourceCanBeSet()
 {
     $value = 'something';
     $this->instance->setImportSource($value);
     $this->assertEquals($value, $this->instance->getImportSource());
 }