public function testPreRemoveImage()
 {
     $organizationMock = $this->getMockBuilder('\\Organizations\\Entity\\Organization')->getMock();
     $organizationMock->expects($this->once())->method('setImage')->with(null);
     $this->target->setOrganization($organizationMock);
     $this->target->preRemove();
     $this->assertSame($this->target->getOrganization()->getImage(), null);
 }
Exemple #2
0
 /**
  * @covers ::store
  * @covers ::getImagePath
  * @covers ::createDirectoryRecursively
  * @expectedException \RuntimeException
  * @expectedExceptionMessage unable to create directory
  */
 public function testStoreWithInsufficientPermissions()
 {
     $image = new ImageEntity();
     $image->setId('someId');
     $image->setName('filename.ext');
     vfsStreamWrapper::getRoot()->chmod(00);
     $this->manager->store($image);
 }
Exemple #3
0
 /**
  * @param OrganizationImage $image
  * @return string
  */
 protected function getImageSubPath(OrganizationImage $image)
 {
     $id = $image->getId();
     if (!$id) {
         throw new InvalidArgumentException('image must have ID');
     }
     $extension = null;
     $filename = $image->getName();
     if ($filename) {
         // get an extension from the filename
         $extension = pathinfo($filename, PATHINFO_EXTENSION);
     } else {
         // try get an extension from MIME if any
         $extension = str_replace('image/', '', $image->getType());
     }
     if (!$extension) {
         throw new InvalidArgumentException('unable to get an image file extension');
     }
     $firstLevel = substr($id, -1) ?: '0';
     $secondLevel = substr($id, -2, 1) ?: '0';
     return sprintf('%s/%s/%s.%s', $firstLevel, $secondLevel, $id, $extension);
 }