示例#1
0
 public function testValidateFileNoImage()
 {
     $image = CM_File::createTmp();
     $formField = new CM_FormField_FileImage();
     $exception = $this->catchException(function () use($formField, $image) {
         $formField->validateFile($image);
     });
     $this->assertInstanceOf(CM_Exception_FormFieldValidation::class, $exception);
     $this->assertSame('FormField Validation failed', $exception->getMessage());
     /** @var CM_Exception $exception */
     $this->assertSame('Invalid image', $exception->getMessagePublic(new CM_Frontend_Render()));
 }
示例#2
0
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  */
 public function testForkAndWaitForChildren()
 {
     $file = CM_File::createTmp();
     $process = CM_Process::getInstance();
     $parentOutput = [];
     for ($i = 1; $i <= 4; $i++) {
         $parentOutput[] = "Child {$i} forked.";
         $process->fork(function () use($i, $file) {
             $ms = 100 * $i;
             usleep($ms * 1000);
             $file->appendLine("Child {$i} terminated after {$ms} ms.");
         });
     }
     $parentOutput[] = 'Parent waiting for 250 ms...';
     usleep(250000);
     $parentOutput[] = 'Parent listening to children...';
     $process->waitForChildren();
     $parentOutput[] = 'Parent terminated.';
     $childrenOutput = explode(PHP_EOL, $file->read());
     $this->assertSame(['Child 1 forked.', 'Child 2 forked.', 'Child 3 forked.', 'Child 4 forked.', 'Parent waiting for 250 ms...', 'Parent listening to children...', 'Parent terminated.'], $parentOutput);
     $this->assertContainsAll(['Child 2 terminated after 200 ms.', 'Child 1 terminated after 100 ms.', 'Child 3 terminated after 300 ms.', 'Child 4 terminated after 400 ms.'], $childrenOutput);
 }
示例#3
0
 /**
  * @expectedException CM_Exception_FormFieldValidation
  */
 public function testValidateFileNoImage()
 {
     $image = CM_File::createTmp();
     $formField = new CM_FormField_FileImage();
     $formField->validateFile($image);
 }
示例#4
0
 public function testResizeSpecificKeepExif()
 {
     $imageFileOriginal = new CM_File(DIR_TEST_DATA . 'img/test-rotated.jpg');
     $image = new CM_Image_Image($imageFileOriginal->read());
     $image->resize($image->getWidth(), $image->getHeight());
     $imageFile = CM_File::createTmp(null, $image->getBlob());
     $newImage = new CM_Image_Image($imageFile->read());
     $this->assertSame(6, $this->_getImagickObject($newImage)->getImageOrientation());
 }
示例#5
0
 public function testResize()
 {
     $image = $this->mockClass('CM_File_Image')->newInstanceWithoutConstructor();
     $image->mockMethod('getWidth')->set(250);
     $image->mockMethod('getHeight')->set(150);
     $targetFile = CM_File::createTmp();
     $format = 'jpg';
     $resizeSpecificMethod = $image->mockMethod('resizeSpecific')->set(function ($width, $height, $offsetX, $offsetY, $formatNew, $fileNew) use($format, $targetFile) {
         $this->assertSame(250, $width);
         $this->assertSame(150, $height);
         $this->assertSame(0, $offsetX);
         $this->assertSame(0, $offsetY);
         $this->assertSame($format, $formatNew);
         $this->assertSame($targetFile, $fileNew);
     });
     /** @var CM_File_Image $image */
     $image->resize(500, 400, false, $format, $targetFile);
     $this->assertSame(1, $resizeSpecificMethod->getCallCount());
 }