szurubooru/tests/Tests/JobTests/EditPostThumbnailJobTest.php

52 lines
1.5 KiB
PHP
Raw Normal View History

2014-05-13 00:01:28 +02:00
<?php
class EditPostThumbnailJobTest extends AbstractTest
2014-05-13 00:01:28 +02:00
{
public function testFile()
{
$this->grantAccess('editPostThumbnail');
$post = $this->postMocker->mockSingle();
2014-05-13 00:01:28 +02:00
$this->assert->isFalse($post->hasCustomThumbnail());
2014-05-13 00:01:28 +02:00
$post = $this->assert->doesNotThrow(function() use ($post)
{
return Api::run(
new EditPostThumbnailJob(),
2014-05-13 00:01:28 +02:00
[
JobArgs::ARG_POST_ID => $post->getId(),
JobArgs::ARG_NEW_THUMBNAIL_CONTENT =>
new ApiFileInput($this->testSupport->getPath('thumb.jpg'), 'test.jpg'),
2014-05-13 00:01:28 +02:00
]);
});
$this->assert->isTrue($post->hasCustomThumbnail());
$img = imagecreatefromjpeg($post->getThumbnailPath());
$this->assert->areEqual(150, imagesx($img));
$this->assert->areEqual(150, imagesy($img));
imagedestroy($img);
2014-05-13 00:01:28 +02:00
}
public function testFileDifferentDimensions()
2014-05-13 00:01:28 +02:00
{
$this->grantAccess('editPostThumbnail');
$post = $this->postMocker->mockSingle();
2014-05-13 00:01:28 +02:00
$this->assert->isFalse($post->hasCustomThumbnail());
$post = $this->assert->doesNotThrow(function() use ($post)
2014-05-13 00:01:28 +02:00
{
return Api::run(
new EditPostThumbnailJob(),
2014-05-13 00:01:28 +02:00
[
JobArgs::ARG_POST_ID => $post->getId(),
JobArgs::ARG_NEW_THUMBNAIL_CONTENT =>
new ApiFileInput($this->testSupport->getPath('image.jpg'), 'test.jpg'),
2014-05-13 00:01:28 +02:00
]);
});
2014-05-13 00:01:28 +02:00
$this->assert->isTrue($post->hasCustomThumbnail());
$img = imagecreatefromjpeg($post->getThumbnailPath());
$this->assert->areEqual(150, imagesx($img));
$this->assert->areEqual(150, imagesy($img));
imagedestroy($img);
2014-05-13 00:01:28 +02:00
}
}