Пример #1
0
 /**
  * Create a FileSystemFile object from an existing
  * file on the file system.
  *
  * @param string $path The canonical path to the file.
  * @param string $mimeType The mime-type of the file (if you want to force it).
  * @param string $filename The file name of the file (if you want to force it).
  * @throws \qtism\common\datatypes\files\FileManagerException
  * @return \qtism\common\datatypes\files\FileSystemFile
  */
 public function createFromFile($path, $mimeType, $filename = '')
 {
     $destination = $this->buildDestination();
     try {
         return FileSystemFile::createFromExistingFile($path, $destination, $mimeType, $filename);
     } catch (RuntimeException $e) {
         $msg = "An error occured while creating a QTI FileSystemFile object.";
         throw new FileManagerException($msg, 0, $e);
     }
 }
 /**
  * @dataProvider createFromExistingFileProvider
  * 
  * @param string $source
  * @param string $destination
  * @param string $mimeType
  * @param boolean|string $withFilename
  */
 public function testCreateFromExistingFile($source, $mimeType, $withFilename = true)
 {
     $destination = tempnam('/tmp', 'qtism');
     $pFile = FileSystemFile::createFromExistingFile($source, $destination, $mimeType, $withFilename);
     $expectedContent = file_get_contents($source);
     if ($withFilename === true) {
         // Check if the name is the original one.
         $pathinfo = pathinfo($source);
         $this->assertEquals($pathinfo['basename'], $pFile->getFilename());
     } else {
         $this->assertEquals($withFilename, $pFile->getFilename());
     }
     $this->assertEquals($expectedContent, $pFile->getData());
     $this->assertEquals($mimeType, $pFile->getMimeType());
     unlink($destination);
 }