Browse Source

fixed test breaks.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
35373b14ae
  1. 11
      extensions/yii/imagine/BaseImage.php
  2. 4
      tests/unit/VendorTestCase.php
  3. 26
      tests/unit/extensions/imagine/AbstractImageTest.php

11
extensions/yii/imagine/BaseImage.php

@ -190,7 +190,8 @@ class BaseImage
$img = static::getImagine()->open(Yii::getAlias($filename)); $img = static::getImagine()->open(Yii::getAlias($filename));
$watermark = static::getImagine()->open(Yii::getAlias($watermarkFilename)); $watermark = static::getImagine()->open(Yii::getAlias($watermarkFilename));
return $img->paste($watermark, new Point($start[0], $start[1])); $img->paste($watermark, new Point($start[0], $start[1]));
return $img;
} }
/** /**
@ -221,7 +222,9 @@ class BaseImage
$img = static::getImagine()->open(Yii::getAlias($filename)); $img = static::getImagine()->open(Yii::getAlias($filename));
$font = static::getImagine()->font(Yii::getAlias($fontFile), $fontSize, new Color($fontColor)); $font = static::getImagine()->font(Yii::getAlias($fontFile), $fontSize, new Color($fontColor));
return $img->draw()->text($text, $font, new Point($start[0], $start[1]), $fontAngle); $img->draw()->text($text, $font, new Point($start[0], $start[1]), $fontAngle);
return $img;
} }
/** /**
@ -245,6 +248,8 @@ class BaseImage
$image = static::getImagine()->create($box, $padColor); $image = static::getImagine()->create($box, $padColor);
return $image->paste($img, $pasteTo); $image->paste($img, $pasteTo);
return $image;
} }
} }

4
tests/unit/VendorTestCase.php

@ -19,6 +19,10 @@ class VendorTestCase extends TestCase
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
$vendorDir = __DIR__ . '/../../vendor'; $vendorDir = __DIR__ . '/../../vendor';
if (!is_dir($vendorDir)) {
// this is used by `yii2-dev`
$vendorDir = __DIR__ . '/../../../../../vendor';
}
Yii::setAlias('@vendor', $vendorDir); Yii::setAlias('@vendor', $vendorDir);
$vendorAutoload = $vendorDir . '/autoload.php'; $vendorAutoload = $vendorDir . '/autoload.php';
if (file_exists($vendorAutoload)) { if (file_exists($vendorAutoload)) {

26
tests/unit/extensions/imagine/AbstractImageTest.php

@ -38,8 +38,7 @@ abstract class AbstractImageTest extends VendorTestCase
$fontFile = Yii::getAlias('@yiiunit/data/imagine/GothamRnd-Light') . '.otf'; $fontFile = Yii::getAlias('@yiiunit/data/imagine/GothamRnd-Light') . '.otf';
$img = Image::text($this->imageFile, 'Yii-2 Image', [ $img = Image::text($this->imageFile, 'Yii-2 Image', $fontFile, [0, 0], [
'font' => $fontFile,
'size' => 12, 'size' => 12,
'color' => '000' 'color' => '000'
]); ]);
@ -57,11 +56,6 @@ abstract class AbstractImageTest extends VendorTestCase
$this->assertEquals(100, $img->getSize()->getWidth()); $this->assertEquals(100, $img->getSize()->getWidth());
$this->assertEquals(100, $img->getSize()->getHeight()); $this->assertEquals(100, $img->getSize()->getHeight());
$point = new Point(20, 20);
$img = Image::crop($this->imageFile, 100, 100, $point);
$this->assertEquals(100, $img->getSize()->getWidth());
$this->assertEquals(100, $img->getSize()->getHeight());
} }
public function testWatermark() public function testWatermark()
@ -97,24 +91,8 @@ abstract class AbstractImageTest extends VendorTestCase
{ {
Image::setImagine(null); Image::setImagine(null);
Image::$driver = 'fake-driver'; Image::$driver = 'fake-driver';
Image::getImagine();
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testShouldThrowExceptionOnCropInvalidArgument()
{
Image::crop($this->imageFile, 100, 100, new \stdClass());
}
/**
* @expectedException \InvalidArgumentException
*/
public function testShouldThrowExceptionOnWatermarkInvalidArgument()
{
Image::watermark($this->imageFile, $this->watermarkFile, new \stdClass());
}
abstract protected function isFontTestSupported(); abstract protected function isFontTestSupported();
} }

Loading…
Cancel
Save