summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/filerepo
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/filerepo')
-rw-r--r--tests/phpunit/includes/filerepo/FileRepoTest.php55
-rw-r--r--tests/phpunit/includes/filerepo/RepoGroupTest.php59
-rw-r--r--tests/phpunit/includes/filerepo/StoreBatchTest.php146
-rw-r--r--tests/phpunit/includes/filerepo/file/FileTest.php386
4 files changed, 646 insertions, 0 deletions
diff --git a/tests/phpunit/includes/filerepo/FileRepoTest.php b/tests/phpunit/includes/filerepo/FileRepoTest.php
new file mode 100644
index 00000000..a196dca8
--- /dev/null
+++ b/tests/phpunit/includes/filerepo/FileRepoTest.php
@@ -0,0 +1,55 @@
+<?php
+
+class FileRepoTest extends MediaWikiTestCase {
+
+ /**
+ * @expectedException MWException
+ * @covers FileRepo::__construct
+ */
+ public function testFileRepoConstructionOptionCanNotBeNull() {
+ new FileRepo();
+ }
+
+ /**
+ * @expectedException MWException
+ * @covers FileRepo::__construct
+ */
+ public function testFileRepoConstructionOptionCanNotBeAnEmptyArray() {
+ new FileRepo( array() );
+ }
+
+ /**
+ * @expectedException MWException
+ * @covers FileRepo::__construct
+ */
+ public function testFileRepoConstructionOptionNeedNameKey() {
+ new FileRepo( array(
+ 'backend' => 'foobar'
+ ) );
+ }
+
+ /**
+ * @expectedException MWException
+ * @covers FileRepo::__construct
+ */
+ public function testFileRepoConstructionOptionNeedBackendKey() {
+ new FileRepo( array(
+ 'name' => 'foobar'
+ ) );
+ }
+
+ /**
+ * @covers FileRepo::__construct
+ */
+ public function testFileRepoConstructionWithRequiredOptions() {
+ $f = new FileRepo( array(
+ 'name' => 'FileRepoTestRepository',
+ 'backend' => new FSFileBackend( array(
+ 'name' => 'local-testing',
+ 'wikiId' => 'test_wiki',
+ 'containerPaths' => array()
+ ) )
+ ) );
+ $this->assertInstanceOf( 'FileRepo', $f );
+ }
+}
diff --git a/tests/phpunit/includes/filerepo/RepoGroupTest.php b/tests/phpunit/includes/filerepo/RepoGroupTest.php
new file mode 100644
index 00000000..5bdb7e7f
--- /dev/null
+++ b/tests/phpunit/includes/filerepo/RepoGroupTest.php
@@ -0,0 +1,59 @@
+<?php
+class RepoGroupTest extends MediaWikiTestCase {
+
+ function testHasForeignRepoNegative() {
+ $this->setMwGlobals( 'wgForeignFileRepos', array() );
+ RepoGroup::destroySingleton();
+ FileBackendGroup::destroySingleton();
+ $this->assertFalse( RepoGroup::singleton()->hasForeignRepos() );
+ }
+
+ function testHasForeignRepoPositive() {
+ $this->setUpForeignRepo();
+ $this->assertTrue( RepoGroup::singleton()->hasForeignRepos() );
+ }
+
+ function testForEachForeignRepo() {
+ $this->setUpForeignRepo();
+ $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
+ $fakeCallback->expects( $this->once() )->method( 'callback' );
+ RepoGroup::singleton()->forEachForeignRepo(
+ array( $fakeCallback, 'callback' ), array( array() ) );
+ }
+
+ function testForEachForeignRepoNone() {
+ $this->setMwGlobals( 'wgForeignFileRepos', array() );
+ RepoGroup::destroySingleton();
+ FileBackendGroup::destroySingleton();
+ $fakeCallback = $this->getMock( 'RepoGroupTestHelper' );
+ $fakeCallback->expects( $this->never() )->method( 'callback' );
+ RepoGroup::singleton()->forEachForeignRepo(
+ array( $fakeCallback, 'callback' ), array( array() ) );
+ }
+
+ private function setUpForeignRepo() {
+ global $wgUploadDirectory;
+ $this->setMwGlobals( 'wgForeignFileRepos', array( array(
+ 'class' => 'ForeignAPIRepo',
+ 'name' => 'wikimediacommons',
+ 'backend' => 'wikimediacommons-backend',
+ 'apibase' => 'https://commons.wikimedia.org/w/api.php',
+ 'hashLevels' => 2,
+ 'fetchDescription' => true,
+ 'descriptionCacheExpiry' => 43200,
+ 'apiThumbCacheExpiry' => 86400,
+ 'directory' => $wgUploadDirectory
+ ) ) );
+ RepoGroup::destroySingleton();
+ FileBackendGroup::destroySingleton();
+ }
+}
+
+/**
+ * Quick helper class to use as a mock callback for RepoGroup::singleton()->forEachForeignRepo.
+ */
+class RepoGroupTestHelper {
+ function callback( FileRepo $repo, array $foo ) {
+ return true;
+ }
+}
diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php
new file mode 100644
index 00000000..9cc2efbf
--- /dev/null
+++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php
@@ -0,0 +1,146 @@
+<?php
+
+/**
+ * @group FileRepo
+ * @group medium
+ */
+class StoreBatchTest extends MediaWikiTestCase {
+
+ protected $createdFiles;
+ protected $date;
+ /** @var FileRepo */
+ protected $repo;
+
+ protected function setUp() {
+ global $wgFileBackends;
+ parent::setUp();
+
+ # Forge a FSRepo object to not have to rely on local wiki settings
+ $tmpPrefix = wfTempDir() . '/storebatch-test-' . time() . '-' . mt_rand();
+ if ( $this->getCliArg( 'use-filebackend' ) ) {
+ $name = $this->getCliArg( 'use-filebackend' );
+ $useConfig = array();
+ foreach ( $wgFileBackends as $conf ) {
+ if ( $conf['name'] == $name ) {
+ $useConfig = $conf;
+ }
+ }
+ $useConfig['lockManager'] = LockManagerGroup::singleton()->get( $useConfig['lockManager'] );
+ unset( $useConfig['fileJournal'] );
+ $useConfig['name'] = 'local-testing'; // swap name
+ $class = $useConfig['class'];
+ $backend = new $class( $useConfig );
+ } else {
+ $backend = new FSFileBackend( array(
+ 'name' => 'local-testing',
+ 'wikiId' => wfWikiID(),
+ 'containerPaths' => array(
+ 'unittests-public' => "{$tmpPrefix}-public",
+ 'unittests-thumb' => "{$tmpPrefix}-thumb",
+ 'unittests-temp' => "{$tmpPrefix}-temp",
+ 'unittests-deleted' => "{$tmpPrefix}-deleted",
+ )
+ ) );
+ }
+ $this->repo = new FileRepo( array(
+ 'name' => 'unittests',
+ 'backend' => $backend
+ ) );
+
+ $this->date = gmdate( "YmdHis" );
+ $this->createdFiles = array();
+ }
+
+ protected function tearDown() {
+ $this->repo->cleanupBatch( $this->createdFiles ); // delete files
+ foreach ( $this->createdFiles as $tmp ) { // delete dirs
+ $tmp = $this->repo->resolveVirtualUrl( $tmp );
+ while ( $tmp = FileBackend::parentStoragePath( $tmp ) ) {
+ $this->repo->getBackend()->clean( array( 'dir' => $tmp ) );
+ }
+ }
+ parent::tearDown();
+ }
+
+ /**
+ * Store a file or virtual URL source into a media file name.
+ *
+ * @param string $originalName The title of the image
+ * @param string $srcPath The filepath or virtual URL
+ * @param int $flags Flags to pass into repo::store().
+ * @return FileRepoStatus
+ */
+ private function storeit( $originalName, $srcPath, $flags ) {
+ $hashPath = $this->repo->getHashPath( $originalName );
+ $dstRel = "$hashPath{$this->date}!$originalName";
+ $dstUrlRel = $hashPath . $this->date . '!' . rawurlencode( $originalName );
+
+ $result = $this->repo->store( $srcPath, 'temp', $dstRel, $flags );
+ $result->value = $this->repo->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
+ $this->createdFiles[] = $result->value;
+
+ return $result;
+ }
+
+ /**
+ * Test storing a file using different flags.
+ *
+ * @param string $fn The title of the image
+ * @param string $infn The name of the file (in the filesystem)
+ * @param string $otherfn The name of the different file (in the filesystem)
+ * @param bool $fromrepo 'true' if we want to copy from a virtual URL out of the Repo.
+ */
+ private function storecohort( $fn, $infn, $otherfn, $fromrepo ) {
+ $f = $this->storeit( $fn, $infn, 0 );
+ $this->assertTrue( $f->isOK(), 'failed to store a new file' );
+ $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
+ $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
+ if ( $fromrepo ) {
+ $f = $this->storeit( "Other-$fn", $infn, FileRepo::OVERWRITE );
+ $infn = $f->value;
+ }
+ // This should work because we're allowed to overwrite
+ $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE );
+ $this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' );
+ $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
+ $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
+ // This should fail because we're overwriting.
+ $f = $this->storeit( $fn, $infn, 0 );
+ $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' );
+ $this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
+ $this->assertEquals( $f->successCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
+ // This should succeed because we're overwriting the same content.
+ $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE_SAME );
+ $this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' );
+ $this->assertEquals( $f->failCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
+ $this->assertEquals( $f->successCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
+ // This should fail because we're overwriting different content.
+ if ( $fromrepo ) {
+ $f = $this->storeit( "Other-$fn", $otherfn, FileRepo::OVERWRITE );
+ $otherfn = $f->value;
+ }
+ $f = $this->storeit( $fn, $otherfn, FileRepo::OVERWRITE_SAME );
+ $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' );
+ $this->assertEquals( $f->failCount, 1, "counts wrong {$f->successCount} {$f->failCount}" );
+ $this->assertEquals( $f->successCount, 0, "counts wrong {$f->successCount} {$f->failCount}" );
+ }
+
+ /**
+ * @covers FileRepo::store
+ */
+ public function teststore() {
+ global $IP;
+ $this->storecohort(
+ "Test1.png",
+ "$IP/tests/phpunit/data/filerepo/wiki.png",
+ "$IP/tests/phpunit/data/filerepo/video.png",
+ false
+ );
+ $this->storecohort(
+ "Test2.png",
+ "$IP/tests/phpunit/data/filerepo/wiki.png",
+ "$IP/tests/phpunit/data/filerepo/video.png",
+ true
+ );
+ }
+}
diff --git a/tests/phpunit/includes/filerepo/file/FileTest.php b/tests/phpunit/includes/filerepo/file/FileTest.php
new file mode 100644
index 00000000..8e8b8a9e
--- /dev/null
+++ b/tests/phpunit/includes/filerepo/file/FileTest.php
@@ -0,0 +1,386 @@
+<?php
+
+class FileTest extends MediaWikiMediaTestCase {
+
+ /**
+ * @param string $filename
+ * @param bool $expected
+ * @dataProvider providerCanAnimate
+ */
+ function testCanAnimateThumbIfAppropriate( $filename, $expected ) {
+ $this->setMwGlobals( 'wgMaxAnimatedGifArea', 9000 );
+ $file = $this->dataFile( $filename );
+ $this->assertEquals( $file->canAnimateThumbIfAppropriate(), $expected );
+ }
+
+ function providerCanAnimate() {
+ return array(
+ array( 'nonanimated.gif', true ),
+ array( 'jpeg-comment-utf.jpg', true ),
+ array( 'test.tiff', true ),
+ array( 'Animated_PNG_example_bouncing_beach_ball.png', false ),
+ array( 'greyscale-png.png', true ),
+ array( 'Toll_Texas_1.svg', true ),
+ array( 'LoremIpsum.djvu', true ),
+ array( '80x60-2layers.xcf', true ),
+ array( 'Soccer_ball_animated.svg', false ),
+ array( 'Bishzilla_blink.gif', false ),
+ array( 'animated.gif', true ),
+ );
+ }
+
+ /**
+ * @dataProvider getThumbnailBucketProvider
+ * @covers File::getThumbnailBucket
+ */
+ public function testGetThumbnailBucket( $data ) {
+ $this->setMwGlobals( 'wgThumbnailBuckets', $data['buckets'] );
+ $this->setMwGlobals( 'wgThumbnailMinimumBucketDistance', $data['minimumBucketDistance'] );
+
+ $fileMock = $this->getMockBuilder( 'File' )
+ ->setConstructorArgs( array( 'fileMock', false ) )
+ ->setMethods( array( 'getWidth' ) )
+ ->getMockForAbstractClass();
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getWidth' )
+ ->will( $this->returnValue( $data['width'] ) );
+
+ $this->assertEquals(
+ $data['expectedBucket'],
+ $fileMock->getThumbnailBucket( $data['requestedWidth'] ),
+ $data['message'] );
+ }
+
+ public function getThumbnailBucketProvider() {
+ $defaultBuckets = array( 256, 512, 1024, 2048, 4096 );
+
+ return array(
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 120,
+ 'expectedBucket' => 256,
+ 'message' => 'Picking bucket bigger than requested size'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 300,
+ 'expectedBucket' => 512,
+ 'message' => 'Picking bucket bigger than requested size'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 1024,
+ 'expectedBucket' => 2048,
+ 'message' => 'Picking bucket bigger than requested size'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 2048,
+ 'expectedBucket' => false,
+ 'message' => 'Picking no bucket because none is bigger than the requested size'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 3500,
+ 'expectedBucket' => false,
+ 'message' => 'Picking no bucket because requested size is bigger than original'
+ ) ),
+ array( array(
+ 'buckets' => array( 1024 ),
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 1024,
+ 'expectedBucket' => false,
+ 'message' => 'Picking no bucket because requested size equals biggest bucket'
+ ) ),
+ array( array(
+ 'buckets' => null,
+ 'minimumBucketDistance' => 0,
+ 'width' => 3000,
+ 'requestedWidth' => 1024,
+ 'expectedBucket' => false,
+ 'message' => 'Picking no bucket because no buckets have been specified'
+ ) ),
+ array( array(
+ 'buckets' => array( 256, 512 ),
+ 'minimumBucketDistance' => 10,
+ 'width' => 3000,
+ 'requestedWidth' => 245,
+ 'expectedBucket' => 256,
+ 'message' => 'Requested width is distant enough from next bucket for it to be picked'
+ ) ),
+ array( array(
+ 'buckets' => array( 256, 512 ),
+ 'minimumBucketDistance' => 10,
+ 'width' => 3000,
+ 'requestedWidth' => 246,
+ 'expectedBucket' => 512,
+ 'message' => 'Requested width is too close to next bucket, picking next one'
+ ) ),
+ );
+ }
+
+ /**
+ * @dataProvider getThumbnailSourceProvider
+ * @covers File::getThumbnailSource
+ */
+ public function testGetThumbnailSource( $data ) {
+ $backendMock = $this->getMockBuilder( 'FSFileBackend' )
+ ->setConstructorArgs( array( array( 'name' => 'backendMock', 'wikiId' => wfWikiId() ) ) )
+ ->getMock();
+
+ $repoMock = $this->getMockBuilder( 'FileRepo' )
+ ->setConstructorArgs( array( array( 'name' => 'repoMock', 'backend' => $backendMock ) ) )
+ ->setMethods( array( 'fileExists', 'getLocalReference' ) )
+ ->getMock();
+
+ $fsFile = new FSFile( 'fsFilePath' );
+
+ $repoMock->expects( $this->any() )
+ ->method( 'fileExists' )
+ ->will( $this->returnValue( true ) );
+
+ $repoMock->expects( $this->any() )
+ ->method( 'getLocalReference' )
+ ->will( $this->returnValue( $fsFile ) );
+
+ $handlerMock = $this->getMock( 'BitmapHandler', array( 'supportsBucketing' ) );
+ $handlerMock->expects( $this->any() )
+ ->method( 'supportsBucketing' )
+ ->will( $this->returnValue( $data['supportsBucketing'] ) );
+
+ $fileMock = $this->getMockBuilder( 'File' )
+ ->setConstructorArgs( array( 'fileMock', $repoMock ) )
+ ->setMethods( array( 'getThumbnailBucket', 'getLocalRefPath', 'getHandler' ) )
+ ->getMockForAbstractClass();
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getThumbnailBucket' )
+ ->will( $this->returnValue( $data['thumbnailBucket'] ) );
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getLocalRefPath' )
+ ->will( $this->returnValue( 'localRefPath' ) );
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getHandler' )
+ ->will( $this->returnValue( $handlerMock ) );
+
+ $reflection = new ReflectionClass( $fileMock );
+ $reflection_property = $reflection->getProperty( 'handler' );
+ $reflection_property->setAccessible( true );
+ $reflection_property->setValue( $fileMock, $handlerMock );
+
+ if ( !is_null( $data['tmpBucketedThumbCache'] ) ) {
+ $reflection_property = $reflection->getProperty( 'tmpBucketedThumbCache' );
+ $reflection_property->setAccessible( true );
+ $reflection_property->setValue( $fileMock, $data['tmpBucketedThumbCache'] );
+ }
+
+ $result = $fileMock->getThumbnailSource(
+ array( 'physicalWidth' => $data['physicalWidth'] ) );
+
+ $this->assertEquals( $data['expectedPath'], $result['path'], $data['message'] );
+ }
+
+ public function getThumbnailSourceProvider() {
+ return array(
+ array( array(
+ 'supportsBucketing' => true,
+ 'tmpBucketedThumbCache' => null,
+ 'thumbnailBucket' => 1024,
+ 'physicalWidth' => 2048,
+ 'expectedPath' => 'fsFilePath',
+ 'message' => 'Path downloaded from storage'
+ ) ),
+ array( array(
+ 'supportsBucketing' => true,
+ 'tmpBucketedThumbCache' => array( 1024 => '/tmp/shouldnotexist' + rand() ),
+ 'thumbnailBucket' => 1024,
+ 'physicalWidth' => 2048,
+ 'expectedPath' => 'fsFilePath',
+ 'message' => 'Path downloaded from storage because temp file is missing'
+ ) ),
+ array( array(
+ 'supportsBucketing' => true,
+ 'tmpBucketedThumbCache' => array( 1024 => '/tmp' ),
+ 'thumbnailBucket' => 1024,
+ 'physicalWidth' => 2048,
+ 'expectedPath' => '/tmp',
+ 'message' => 'Temporary path because temp file was found'
+ ) ),
+ array( array(
+ 'supportsBucketing' => false,
+ 'tmpBucketedThumbCache' => null,
+ 'thumbnailBucket' => 1024,
+ 'physicalWidth' => 2048,
+ 'expectedPath' => 'localRefPath',
+ 'message' => 'Original file path because bucketing is unsupported by handler'
+ ) ),
+ array( array(
+ 'supportsBucketing' => true,
+ 'tmpBucketedThumbCache' => null,
+ 'thumbnailBucket' => false,
+ 'physicalWidth' => 2048,
+ 'expectedPath' => 'localRefPath',
+ 'message' => 'Original file path because no width provided'
+ ) ),
+ );
+ }
+
+ /**
+ * @dataProvider generateBucketsIfNeededProvider
+ * @covers File::generateBucketsIfNeeded
+ */
+ public function testGenerateBucketsIfNeeded( $data ) {
+ $this->setMwGlobals( 'wgThumbnailBuckets', $data['buckets'] );
+
+ $backendMock = $this->getMockBuilder( 'FSFileBackend' )
+ ->setConstructorArgs( array( array( 'name' => 'backendMock', 'wikiId' => wfWikiId() ) ) )
+ ->getMock();
+
+ $repoMock = $this->getMockBuilder( 'FileRepo' )
+ ->setConstructorArgs( array( array( 'name' => 'repoMock', 'backend' => $backendMock ) ) )
+ ->setMethods( array( 'fileExists', 'getLocalReference' ) )
+ ->getMock();
+
+ $fileMock = $this->getMockBuilder( 'File' )
+ ->setConstructorArgs( array( 'fileMock', $repoMock ) )
+ ->setMethods( array( 'getWidth', 'getBucketThumbPath', 'makeTransformTmpFile',
+ 'generateAndSaveThumb', 'getHandler' ) )
+ ->getMockForAbstractClass();
+
+ $handlerMock = $this->getMock( 'JpegHandler', array( 'supportsBucketing' ) );
+ $handlerMock->expects( $this->any() )
+ ->method( 'supportsBucketing' )
+ ->will( $this->returnValue( true ) );
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getHandler' )
+ ->will( $this->returnValue( $handlerMock ) );
+
+ $reflectionMethod = new ReflectionMethod( 'File', 'generateBucketsIfNeeded' );
+ $reflectionMethod->setAccessible( true );
+
+ $fileMock->expects( $this->any() )
+ ->method( 'getWidth' )
+ ->will( $this->returnValue( $data['width'] ) );
+
+ $fileMock->expects( $data['expectedGetBucketThumbPathCalls'] )
+ ->method( 'getBucketThumbPath' );
+
+ $repoMock->expects( $data['expectedFileExistsCalls'] )
+ ->method( 'fileExists' )
+ ->will( $this->returnValue( $data['fileExistsReturn'] ) );
+
+ $fileMock->expects( $data['expectedMakeTransformTmpFile'] )
+ ->method( 'makeTransformTmpFile' )
+ ->will( $this->returnValue( $data['makeTransformTmpFileReturn'] ) );
+
+ $fileMock->expects( $data['expectedGenerateAndSaveThumb'] )
+ ->method( 'generateAndSaveThumb' )
+ ->will( $this->returnValue( $data['generateAndSaveThumbReturn'] ) );
+
+ $this->assertEquals( $data['expectedResult'],
+ $reflectionMethod->invoke(
+ $fileMock,
+ array(
+ 'physicalWidth' => $data['physicalWidth'],
+ 'physicalHeight' => $data['physicalHeight'] )
+ ),
+ $data['message'] );
+ }
+
+ public function generateBucketsIfNeededProvider() {
+ $defaultBuckets = array( 256, 512, 1024, 2048, 4096 );
+
+ return array(
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'width' => 256,
+ 'physicalWidth' => 256,
+ 'physicalHeight' => 100,
+ 'expectedGetBucketThumbPathCalls' => $this->never(),
+ 'expectedFileExistsCalls' => $this->never(),
+ 'fileExistsReturn' => null,
+ 'expectedMakeTransformTmpFile' => $this->never(),
+ 'makeTransformTmpFileReturn' => false,
+ 'expectedGenerateAndSaveThumb' => $this->never(),
+ 'generateAndSaveThumbReturn' => false,
+ 'expectedResult' => false,
+ 'message' => 'No bucket found, nothing to generate'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'width' => 5000,
+ 'physicalWidth' => 300,
+ 'physicalHeight' => 200,
+ 'expectedGetBucketThumbPathCalls' => $this->once(),
+ 'expectedFileExistsCalls' => $this->once(),
+ 'fileExistsReturn' => true,
+ 'expectedMakeTransformTmpFile' => $this->never(),
+ 'makeTransformTmpFileReturn' => false,
+ 'expectedGenerateAndSaveThumb' => $this->never(),
+ 'generateAndSaveThumbReturn' => false,
+ 'expectedResult' => false,
+ 'message' => 'File already exists, no reason to generate buckets'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'width' => 5000,
+ 'physicalWidth' => 300,
+ 'physicalHeight' => 200,
+ 'expectedGetBucketThumbPathCalls' => $this->once(),
+ 'expectedFileExistsCalls' => $this->once(),
+ 'fileExistsReturn' => false,
+ 'expectedMakeTransformTmpFile' => $this->once(),
+ 'makeTransformTmpFileReturn' => false,
+ 'expectedGenerateAndSaveThumb' => $this->never(),
+ 'generateAndSaveThumbReturn' => false,
+ 'expectedResult' => false,
+ 'message' => 'Cannot generate temp file for bucket'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'width' => 5000,
+ 'physicalWidth' => 300,
+ 'physicalHeight' => 200,
+ 'expectedGetBucketThumbPathCalls' => $this->once(),
+ 'expectedFileExistsCalls' => $this->once(),
+ 'fileExistsReturn' => false,
+ 'expectedMakeTransformTmpFile' => $this->once(),
+ 'makeTransformTmpFileReturn' => new TempFSFile( '/tmp/foo' ),
+ 'expectedGenerateAndSaveThumb' => $this->once(),
+ 'generateAndSaveThumbReturn' => false,
+ 'expectedResult' => false,
+ 'message' => 'Bucket image could not be generated'
+ ) ),
+ array( array(
+ 'buckets' => $defaultBuckets,
+ 'width' => 5000,
+ 'physicalWidth' => 300,
+ 'physicalHeight' => 200,
+ 'expectedGetBucketThumbPathCalls' => $this->once(),
+ 'expectedFileExistsCalls' => $this->once(),
+ 'fileExistsReturn' => false,
+ 'expectedMakeTransformTmpFile' => $this->once(),
+ 'makeTransformTmpFileReturn' => new TempFSFile( '/tmp/foo' ),
+ 'expectedGenerateAndSaveThumb' => $this->once(),
+ 'generateAndSaveThumbReturn' => new ThumbnailImage( false, 'bar', false, false ),
+ 'expectedResult' => true,
+ 'message' => 'Bucket image could not be generated'
+ ) ),
+ );
+ }
+}