setForceOverride() public method

Override the target image
public setForceOverride ( boolean $forceOverride )
$forceOverride boolean True to override the target image
Esempio n. 1
0
 /**
  * Tests the setters and getters.
  */
 public function testSettersAndGetters()
 {
     /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileMock */
     $fileMock = $this->getMockBuilder('Contao\\File')->setMethods(['__get', 'exists'])->setConstructorArgs(['dummy.jpg'])->getMock();
     $fileMock->expects($this->any())->method('exists')->will($this->returnValue(true));
     $fileMock->expects($this->any())->method('__get')->will($this->returnCallback(function ($key) {
         switch ($key) {
             case 'extension':
                 return 'jpg';
             case 'path':
                 return 'dummy.jpg';
             case 'width':
             case 'viewWidth':
                 return 100;
             case 'height':
             case 'viewHeight':
                 return 100;
             default:
                 return null;
         }
     }));
     $imageObj = new Image($fileMock);
     $this->assertFalse($imageObj->getForceOverride());
     $imageObj->setForceOverride(true);
     $this->assertTrue($imageObj->getForceOverride());
     $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 0, 'width' => 100, 'height' => 100]);
     $imageObj->setImportantPart(['x' => 20, 'y' => 40, 'width' => 80, 'height' => 60]);
     $this->assertSame($imageObj->getImportantPart(), ['x' => 20, 'y' => 40, 'width' => 80, 'height' => 60]);
     $imageObj->setImportantPart(['x' => -20, 'y' => 40.1, 'width' => '80', 'height' => 120]);
     $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 40, 'width' => 80, 'height' => 60]);
     $imageObj->setImportantPart(['x' => 200, 'y' => 200, 'width' => 200, 'height' => 200]);
     $this->assertSame($imageObj->getImportantPart(), ['x' => 99, 'y' => 99, 'width' => 1, 'height' => 1]);
     $imageObj->setImportantPart(null);
     $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 0, 'width' => 100, 'height' => 100]);
     $this->assertSame($imageObj->getTargetHeight(), 0);
     $imageObj->setTargetHeight(20);
     $this->assertSame($imageObj->getTargetHeight(), 20);
     $imageObj->setTargetHeight(50.125);
     $this->assertSame($imageObj->getTargetHeight(), 50);
     $this->assertSame($imageObj->getTargetWidth(), 0);
     $imageObj->setTargetWidth(20);
     $this->assertSame($imageObj->getTargetWidth(), 20);
     $imageObj->setTargetWidth(50.125);
     $this->assertSame($imageObj->getTargetWidth(), 50);
     $this->assertSame($imageObj->getTargetPath(), '');
     $imageObj->setTargetPath('foobar');
     $this->assertSame($imageObj->getTargetPath(), 'foobar');
     $this->assertSame($imageObj->getZoomLevel(), 0);
     $imageObj->setZoomLevel(54);
     $this->assertSame($imageObj->getZoomLevel(), 54);
     $this->assertSame($imageObj->getResizeMode(), 'crop');
     $imageObj->setResizeMode('foobar');
     $this->assertSame($imageObj->getResizeMode(), 'foobar');
     $this->assertSame($imageObj->getOriginalPath(), 'dummy.jpg');
     $this->assertSame($imageObj->getResizedPath(), '');
 }