Exemplo n.º 1
0
 /**
  * @param int   $targetDirId - destination folder id
  * @param array $filesIds    - list of files ids to move
  * @param array $foldersIds  - list of folders ids to move
  *
  * @return bool
  * @throws CopyMoveSelectionException
  */
 public function move($targetDirId, array $filesIds, array $foldersIds = array())
 {
     if (empty($filesIds) && empty($foldersIds)) {
         return false;
     }
     $targetDir = $this->getDirectoryById($targetDirId);
     foreach ($filesIds as $fileId) {
         $file = $this->getFileById($fileId);
         $file->setDirectory($targetDir);
     }
     if (!empty($foldersIds)) {
         $targetDirParents = $this->directoryProvider->getDirectoryParentsList($targetDir, false);
         foreach ($foldersIds as $dirId) {
             $dir = $this->getDirectoryById($dirId);
             if ($dir === $targetDir) {
                 throw new CopyMoveSelectionException('Try to move dir to it self: ' . $dir->getName());
             } else {
                 if (in_array($dir, $targetDirParents)) {
                     throw new CopyMoveSelectionException('Try to move parent dir to child dir: ' . $dir->getName());
                 }
             }
             $dir->setParent($targetDir);
         }
     }
     return true;
 }
 /**
  * @covers RI\FileManagerBundle\DataProvider\DirectoryDataProvider::getDirectoryParentsList
  */
 public function testGetDirectoryParentList_ShouldReturnNotConvertedArray()
 {
     $rootDirMock = $this->createMock('RI\\FileManagerBundle\\Entity\\Directory');
     $rootDirMock->expects($this->once())->method('getParent')->will($this->returnValue(null));
     $levelOneDirMock = $this->createMock('RI\\FileManagerBundle\\Entity\\Directory');
     $levelOneDirMock->expects($this->once())->method('getParent')->will($this->returnValue($rootDirMock));
     $directoryMock = $this->createMock('RI\\FileManagerBundle\\Entity\\Directory');
     $directoryMock->expects($this->once())->method('getParent')->will($this->returnValue($levelOneDirMock));
     $expectedData = array($rootDirMock, $levelOneDirMock);
     $this->assertEquals($expectedData, $this->directoryDataProvider->getDirectoryParentsList($directoryMock, false));
 }
 /**
  * @covers RI\FileManagerBundle\Model\Selection\MoveSelectionModel::__construct
  * @covers RI\FileManagerBundle\Model\Selection\MoveSelectionModel::move
  * @covers RI\FileManagerBundle\Model\Selection\MoveSelectionModel::getDirectoryById
  * @covers RI\FileManagerBundle\Model\Selection\MoveSelectionModel::getFileById
  */
 public function testMove_ShouldReturnTrue()
 {
     $this->setMocks();
     $this->directoryRepositoryMock->expects($this->at(0))->method('find')->with(self::DIR_ID_1)->will($this->returnValue($this->directories[self::DIR_ID_1]));
     $this->directoryRepositoryMock->expects($this->at(1))->method('find')->with(self::DIR_ID_2)->will($this->returnValue($this->directories[self::DIR_ID_2]));
     $this->fileRepositoryMock->expects($this->at(0))->method('find')->with(self::FILE_ID_1)->will($this->returnValue($this->files[self::FILE_ID_1]));
     $this->fileRepositoryMock->expects($this->at(1))->method('find')->with(self::FILE_ID_2)->will($this->returnValue($this->files[self::FILE_ID_2]));
     $this->directoryDataProviderMock->expects($this->once())->method('getDirectoryParentsList')->with($this->directories[self::DIR_ID_1])->will($this->returnValue(array()));
     $result = $this->moveSelectionModel->move(self::DIR_ID_1, array(self::FILE_ID_1, self::FILE_ID_2), array(self::DIR_ID_2));
     $this->assertTrue($result);
     $this->assertEquals($this->directories[self::DIR_ID_1], $this->files[self::FILE_ID_1]->getDirectory());
     $this->assertEquals($this->directories[self::DIR_ID_1], $this->files[self::FILE_ID_2]->getDirectory());
     $this->assertEquals($this->directories[self::DIR_ID_1], $this->directories[self::DIR_ID_2]->getParent());
 }
 /**
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copy
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copyFolders
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::getDirectoryById
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::getFileById
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copyFiles
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copyFile
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copyFileOnDisk
  * @covers RI\FileManagerBundle\Model\Selection\CopySelectionModel::copyFolderRecursive
  */
 public function testCopy_ShouldReturnTrue()
 {
     $this->setMocks();
     $this->directoryDataProviderMock->expects($this->once())->method('getDirectoryParentsList')->with($this->directories[self::DIR_ID_1])->will($this->returnValue(array()));
     $this->directoryRepositoryMock->expects($this->at(0))->method('find')->with(self::DIR_ID_1)->will($this->returnValue($this->directories[self::DIR_ID_1]));
     $this->directoryRepositoryMock->expects($this->at(1))->method('find')->with(self::DIR_ID_2)->will($this->returnValue($this->directories[self::DIR_ID_2]));
     $this->fileRepositoryMock->expects($this->at(0))->method('fetchFromDir')->with($this->directories[self::DIR_ID_2])->will($this->returnValue($this->files[self::FILE_ID_2]));
     $this->fileRepositoryMock->expects($this->at(1))->method('find')->with(self::FILE_ID_1)->will($this->returnValue($this->files[self::FILE_ID_1]));
     $this->fileRepositoryMock->expects($this->at(2))->method('find')->with(self::FILE_ID_2)->will($this->returnValue($this->files[self::FILE_ID_2]));
     $this->entityManagerMock->expects($this->any())->method('persist');
     $this->uploadDirectoryManagerMock->expects($this->at(0))->method('getNewPath')->with('abc.jpg')->will($this->returnValue('/../../web/abc_1.jpg'));
     $this->uploadDirectoryManagerMock->expects($this->at(1))->method('getAbsoluteUploadDir')->will($this->returnValue(__DIR__));
     $this->uploadDirectoryManagerMock->expects($this->at(2))->method('getNewPath')->with('xyz.jpg')->will($this->returnValue('/../../web/xyz_1.jpg'));
     $this->uploadDirectoryManagerMock->expects($this->at(3))->method('getAbsoluteUploadDir')->will($this->returnValue(__DIR__));
     $result = $this->CopySelectionModel->copy(self::DIR_ID_1, array(self::FILE_ID_1, self::FILE_ID_2), array(self::DIR_ID_2));
     $this->assertTrue($result);
 }
Exemplo n.º 5
0
 /**
  * @param Directory $targetDir
  * @param array     $foldersIds
  *
  * @throws CopyMoveSelectionException
  */
 private function copyFolders(Directory $targetDir = null, array $foldersIds = array())
 {
     if (!empty($foldersIds)) {
         $targetDirParents = $this->directoryProvider->getDirectoryParentsList($targetDir, false);
         foreach ($foldersIds as $dirId) {
             $dir = $this->getDirectoryById($dirId);
             if ($dir === $targetDir) {
                 throw new CopyMoveSelectionException('Try to move dir to it self: ' . $dir->getName());
             } else {
                 if (in_array($dir, $targetDirParents)) {
                     throw new CopyMoveSelectionException('Try to move parent dir to child dir: ' . $dir->getName());
                 }
             }
             $this->copyFolderRecursive($targetDir, $dir);
         }
     }
 }