/** * @covers \eZ\Publish\Core\IO\Handler::getFileContents */ public function testGetFileContents() { $repositoryPath = 'images/testGetFileContents.gif'; $struct = $this->getCreateStructFromLocalFile($this->imageInputPath, $repositoryPath); $this->IOHandler->create($struct); self::assertEquals(file_get_contents($this->imageInputPath), $this->IOHandler->getFileContents($repositoryPath)); }
/** * @depends testCreate * @param BinaryFile $binaryFile */ public function testGetMimeType(BinaryFile $binaryFile) { $repositoryPath = 'images/testGetFileContents.gif'; $struct = $this->getCreateStructFromLocalFile($this->imageInputPath, $repositoryPath); $binaryFile = $this->IOHandler->create($struct); $mimeType = $this->IOHandler->getMimeType($binaryFile->id); self::assertEquals($struct->mimeType, $mimeType); }
/** * Creates a binary file in the repository * * @param \eZ\Publish\Core\IO\Values\BinaryFileCreateStruct $binaryFileCreateStruct * * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue * * @return \eZ\Publish\Core\IO\Values\BinaryFile The created BinaryFile object */ public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct) { if (empty($binaryFileCreateStruct->id) || !is_string($binaryFileCreateStruct->id)) { throw new InvalidArgumentValue("id", $binaryFileCreateStruct->id, "BinaryFileCreateStruct"); } if (!is_int($binaryFileCreateStruct->size) || $binaryFileCreateStruct->size < 0) { throw new InvalidArgumentValue("size", $binaryFileCreateStruct->size, "BinaryFileCreateStruct"); } if (!is_resource($binaryFileCreateStruct->inputStream)) { throw new InvalidArgumentValue("inputStream", "property is not a file resource", "BinaryFileCreateStruct"); } if (!isset($binaryFileCreateStruct->mimeType)) { $buffer = fread($binaryFileCreateStruct->inputStream, $binaryFileCreateStruct->size); $binaryFileCreateStruct->mimeType = $this->mimeTypeDetector->getFromBuffer($buffer); unset($buffer); } $spiBinaryCreateStruct = $this->buildSPIBinaryFileCreateStructObject($binaryFileCreateStruct); $spiBinaryFile = $this->ioHandler->create($spiBinaryCreateStruct); return $this->buildDomainBinaryFileObject($spiBinaryFile); }