2014-05-13 00:01:28 +02:00
|
|
|
<?php
|
|
|
|
class EditPostThumbJobTest extends AbstractTest
|
|
|
|
{
|
|
|
|
public function testFile()
|
|
|
|
{
|
|
|
|
$this->grantAccess('editPostThumb');
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-13 00:01:28 +02:00
|
|
|
|
|
|
|
$this->assert->isFalse($post->hasCustomThumb());
|
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostThumbJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_THUMB_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('thumb.jpg'), 'test.jpg'),
|
2014-05-13 00:01:28 +02:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->assert->isTrue($post->hasCustomThumb());
|
2014-05-14 23:44:48 +02:00
|
|
|
$img = imagecreatefromjpeg($post->tryGetWorkingThumbPath());
|
|
|
|
$this->assert->areEqual(150, imagesx($img));
|
|
|
|
$this->assert->areEqual(150, imagesy($img));
|
|
|
|
imagedestroy($img);
|
2014-05-13 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2014-05-14 23:44:48 +02:00
|
|
|
public function testFileDifferentDimensions()
|
2014-05-13 00:01:28 +02:00
|
|
|
{
|
|
|
|
$this->grantAccess('editPostThumb');
|
2014-05-13 21:08:07 +02:00
|
|
|
$post = $this->postMocker->mockSingle();
|
2014-05-13 00:01:28 +02:00
|
|
|
|
|
|
|
$this->assert->isFalse($post->hasCustomThumb());
|
2014-05-14 23:44:48 +02:00
|
|
|
$post = $this->assert->doesNotThrow(function() use ($post)
|
2014-05-13 00:01:28 +02:00
|
|
|
{
|
|
|
|
return Api::run(
|
|
|
|
new EditPostThumbJob(),
|
|
|
|
[
|
|
|
|
JobArgs::ARG_POST_ID => $post->getId(),
|
2014-05-13 21:08:07 +02:00
|
|
|
JobArgs::ARG_NEW_THUMB_CONTENT =>
|
|
|
|
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
|
2014-05-13 00:01:28 +02:00
|
|
|
]);
|
2014-05-14 23:44:48 +02:00
|
|
|
});
|
2014-05-13 00:01:28 +02:00
|
|
|
|
2014-05-14 23:44:48 +02:00
|
|
|
$this->assert->isTrue($post->hasCustomThumb());
|
|
|
|
$img = imagecreatefromjpeg($post->tryGetWorkingThumbPath());
|
|
|
|
$this->assert->areEqual(150, imagesx($img));
|
|
|
|
$this->assert->areEqual(150, imagesy($img));
|
|
|
|
imagedestroy($img);
|
2014-05-13 00:01:28 +02:00
|
|
|
}
|
|
|
|
}
|