Skip to content
Browse files

Tests back to 100% and fucktorings.

  • Loading branch information...
1 parent 4c51c55 commit cf151914b0341c7062b8f6bc332f6e3d9495d10c @pekkis pekkis committed
View
50 library/Xi/Filelib/File/Command/UploadFileCommand.php
@@ -48,31 +48,46 @@ public function __construct(FileOperator $fileOperator, $upload, Folder $folder,
}
- public function getResource(FileUpload $upload)
+ public function getResource(File $file, FileUpload $upload)
{
+ $file = clone $file;
+
$hash = sha1_file($upload->getRealPath());
$profileObj = $this->fileOperator->getProfile($this->profile);
- if ($profileObj->isSharedResourceAllowed()) {
- $resources = $this->fileOperator->getBackend()->findResourcesByHash($hash);
- if ($resources) {
- foreach ($resources as $resource) {
- if (!$resource->isExclusive()) {
- return $resource;
- }
+
+ $resources = $this->fileOperator->getBackend()->findResourcesByHash($hash);
+ if ($resources) {
+ foreach ($resources as $resource) {
+ if (!$resource->isExclusive()) {
+ $file->setResource($resource);
+ break;
}
}
+
+ if (!$profileObj->isSharedResourceAllowed($file)) {
+ $file->unsetResource();
+ }
+
}
- $resource = new Resource();
- $resource->setDateCreated(new DateTime());
- $resource->setHash($hash);
- $resource->setSize($upload->getSize());
- $resource->setMimetype($upload->getMimeType());
- $this->fileOperator->getBackend()->createResource($resource);
- return $resource;
- }
+ if (!$file->getResource()) {
+ $resource = new Resource();
+ $resource->setDateCreated(new DateTime());
+ $resource->setHash($hash);
+ $resource->setSize($upload->getSize());
+ $resource->setMimetype($upload->getMimeType());
+ if (!$profileObj->isSharedResourceAllowed($file)) {
+ $resource->setExclusive(true);
+ }
+
+ $this->fileOperator->getBackend()->createResource($resource);
+ $file->setResource($resource);
+ }
+
+ return $file->getResource();
+ }
public function execute()
{
@@ -101,10 +116,9 @@ public function execute()
// @todo: actual statuses
$file->setStatus(File::STATUS_RAW);
- $resource = $this->getResource($upload);
+ $resource = $this->getResource($file, $upload);
$file->setResource($resource);
-
$this->fileOperator->getBackend()->upload($file, $folder);
$this->fileOperator->getStorage()->store($resource, $upload->getRealPath());
View
4 library/Xi/Filelib/File/File.php
@@ -287,6 +287,10 @@ public function getResource()
return $this->resource;
}
+ public function unsetResource()
+ {
+ $this->resource = null;
+ }
/**
* Returns the file as standardized file array
View
8 library/Xi/Filelib/File/FileProfile.php
@@ -326,15 +326,17 @@ private function ensureFileVersionArrayExists($fileType)
}
/**
- * Returns whether profile allows shared resources
+ * Returns whether profile allows shared resources for a file
*
+ * @param File $file
* @return boolean
*/
- public function isSharedResourceAllowed()
+ public function isSharedResourceAllowed(File $file)
{
foreach ($this->getPlugins() as $plugin) {
+
if ($plugin instanceof VersionProvider) {
- if (!$plugin->isSharedResourceAllowed()) {
+ if ($plugin->providesFor($file) && !$plugin->isSharedResourceAllowed()) {
return false;
}
}
View
7 library/Xi/Filelib/Publisher/Filesystem/CopyFilesystemPublisher.php
@@ -52,7 +52,12 @@ public function publishVersion(File $file, $version, VersionProvider $versionPro
mkdir($path, $this->getDirectoryPermission(), true);
}
- $tmp = $this->getFilelib()->getStorage()->retrieveVersion($file->getResource(), $version);
+ if ($versionProvider->areSharedVersionsAllowed()) {
+ $tmp = $this->getFilelib()->getStorage()->retrieveVersion($file->getResource(), $version, null);
+ } else {
+ $tmp = $this->getFilelib()->getStorage()->retrieveVersion($file->getResource(), $version, $file);
+ }
+
copy($tmp, $link);
chmod($link, $this->getFilePermission());
}
View
57 tests/Xi/Tests/Filelib/AbstractOperatorTest.php
@@ -4,6 +4,7 @@
use Xi\Filelib\FileLibrary;
use Xi\Filelib\Command;
+use Xi\Filelib\AbstractOperator;
class AbstractOperatorTest extends TestCase
{
@@ -268,5 +269,61 @@ public function executeOrQueueShouldExecuteWithSynchronousStrategy()
}
+ public function provideCallbackStrategies()
+ {
+ return array(
+ array('asynchronous', Command::STRATEGY_ASYNCHRONOUS),
+ array('synchronous', Command::STRATEGY_SYNCHRONOUS),
+ );
+ }
+
+ /**
+ * @test
+ * @dataProvider provideCallbackStrategies
+ */
+ public function executeOrQueueShouldUtilizeCallbacks($expectedValue, $strategy)
+ {
+ $callbacks = array(
+ Command::STRATEGY_ASYNCHRONOUS => function(AbstractOperator $op, $ret) {
+ return 'asynchronous';
+ },
+ Command::STRATEGY_SYNCHRONOUS => function(AbstractOperator $op, $ret) {
+ return 'synchronous';
+ }
+ );
+
+ $op = $this->getMockBuilder('Xi\Filelib\AbstractOperator')
+ ->disableOriginalConstructor()
+ ->setMethods(array('getCommandStrategy', 'getQueue'))
+ ->getMock();
+
+ $command = $this->getMockBuilder('Xi\Filelib\Command')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $queue = $this->getMock('Xi\Filelib\Queue\Queue');
+
+ $op->expects($this->once())->method('getCommandStrategy')
+ ->with($this->equalTo('tussi'))
+ ->will($this->returnValue($strategy));
+
+ $op->expects($this->any())->method('getQueue')
+ ->will($this->returnValue($queue));
+
+ $command->expects($this->any())->method('execute')
+ ->will($this->returnValue('originalValue'));
+
+ $queue->expects($this->any())->method('enqueue')
+ ->will($this->returnValue('originalValue'));
+
+
+ $ret = $op->executeOrQueue($command, 'tussi', $callbacks);
+
+ $this->assertEquals($expectedValue, $ret);
+
+ }
+
+
+
}
View
24 tests/Xi/Tests/Filelib/File/Command/UploadFileCommandTest.php
@@ -143,7 +143,7 @@ public function commandShouldUploadAndDelegateCorrectly($expectedCallToPublish,
->getMock();
$command->expects($this->once())->method('getResource')
- ->with($this->isInstanceOf('Xi\Filelib\File\Upload\FileUpload'))
+ ->with($this->isInstanceOf('Xi\Filelib\File\File'), $this->isInstanceOf('Xi\Filelib\File\Upload\FileUpload'))
->will($this->returnValue(Resource::create()));
$ret = $command->execute();
@@ -187,6 +187,8 @@ public function commandShouldSerializeAndUnserializeProperly()
*/
public function getResourceShouldGenerateNewResourceIfProfileAllowsButNoResourceIsFound()
{
+ $file = File::create(array());
+
$filelib = $this->getMock('Xi\Filelib\FileLibrary');
$op = $this->getMockBuilder('Xi\Filelib\File\DefaultFileOperator')
@@ -205,6 +207,7 @@ public function getResourceShouldGenerateNewResourceIfProfileAllowsButNoResource
$profile->expects($this->once())
->method('isSharedResourceAllowed')
+ ->with($this->isInstanceOf('Xi\Filelib\File\File'))
->will($this->returnValue(true));
$path = ROOT_TESTS . '/data/self-lussing-manatee.jpg';
@@ -219,8 +222,7 @@ public function getResourceShouldGenerateNewResourceIfProfileAllowsButNoResource
$folder = $this->getMock('Xi\Filelib\Folder\Folder');
$command = new UploadFileCommand($op, $upload, $folder, $profile);
-
- $ret = $command->getResource($upload);
+ $ret = $command->getResource($file, $upload);
$this->assertInstanceOf('Xi\Filelib\File\Resource', $ret);
$this->assertSame($hash, $ret->getHash());
@@ -232,6 +234,8 @@ public function getResourceShouldGenerateNewResourceIfProfileAllowsButNoResource
*/
public function getResourceShouldGenerateNewResourceIfProfileRequires()
{
+ $file = File::create(array());
+
$filelib = $this->getMock('Xi\Filelib\FileLibrary');
$op = $this->getMockBuilder('Xi\Filelib\File\DefaultFileOperator')
@@ -248,7 +252,7 @@ public function getResourceShouldGenerateNewResourceIfProfileRequires()
->with($this->equalTo('lussenhof'))
->will($this->returnValue($profile));
- $profile->expects($this->once())
+ $profile->expects($this->atLeastOnce())
->method('isSharedResourceAllowed')
->will($this->returnValue(false));
@@ -257,13 +261,18 @@ public function getResourceShouldGenerateNewResourceIfProfileRequires()
$upload = new FileUpload($path);
$hash = sha1_file($upload->getRealPath());
- $backend->expects($this->never())->method('findResourcesByHash');
+ $backend->expects($this->once())->method('findResourcesByHash')
+ ->with($this->equalTo($hash))
+ ->will($this->returnValue(array(
+ Resource::create(array('id' => 'first-id')),
+ Resource::create(array('id' => 'second-id')),
+ )));
$folder = $this->getMock('Xi\Filelib\Folder\Folder');
$command = new UploadFileCommand($op, $upload, $folder, $profile);
- $ret = $command->getResource($upload);
+ $ret = $command->getResource($file, $upload);
$this->assertInstanceOf('Xi\Filelib\File\Resource', $ret);
$this->assertSame($hash, $ret->getHash());
@@ -276,6 +285,7 @@ public function getResourceShouldGenerateNewResourceIfProfileRequires()
*/
public function getResourceShouldReuseResourceIfProfileAllowsAndResourcesAreFound()
{
+ $file = File::create(array());
$filelib = $this->getMock('Xi\Filelib\FileLibrary');
$op = $this->getMockBuilder('Xi\Filelib\File\DefaultFileOperator')
@@ -312,7 +322,7 @@ public function getResourceShouldReuseResourceIfProfileAllowsAndResourcesAreFoun
$command = new UploadFileCommand($op, $upload, $folder, $profile);
- $ret = $command->getResource($upload);
+ $ret = $command->getResource($file, $upload);
$this->assertInstanceOf('Xi\Filelib\File\Resource', $ret);
$this->assertSame('first-id', $ret->getId());
View
43 tests/Xi/Tests/Filelib/File/FileProfileTest.php
@@ -340,17 +340,23 @@ private function createProfileWithMockedVersions()
{
$profile = new FileProfile();
- $imageProvider = $this->getMockForAbstractClass('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
+ $imageProvider = $this->getMock('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
$imageProvider->expects($this->any())->method('getIdentifier')->will($this->returnValue('imagenizer'));
$imageProvider->expects($this->any())->method('getVersions')->will($this->returnValue(array('imagenizer')));
+ $imageProvider->expects($this->any())->method('isSharedResourceAllowed')->will($this->returnValue(true));
+ $imageProvider->expects($this->any())->method('providesFor')->will($this->returnCallback(function(File $file) { return $file->getMimetype() == 'image/png'; }));
- $videoProvider = $this->getMockForAbstractClass('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
+ $videoProvider = $this->getMock('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
$videoProvider->expects($this->any())->method('getIdentifier')->will($this->returnValue('videonizer'));
$videoProvider->expects($this->any())->method('getVersions')->will($this->returnValue(array('videonizer')));
+ $videoProvider->expects($this->any())->method('isSharedResourceAllowed')->will($this->returnValue(false));
+ $videoProvider->expects($this->any())->method('providesFor')->will($this->returnCallback(function(File $file) { return $file->getMimetype() == 'video/lus'; }));
- $globalProvider = $this->getMockForAbstractClass('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
+ $globalProvider = $this->getMock('Xi\Filelib\Plugin\VersionProvider\VersionProvider');
$globalProvider->expects($this->any())->method('getIdentifier')->will($this->returnValue('globalizer'));
$globalProvider->expects($this->any())->method('getVersions')->will($this->returnValue(array('globalizer')));
+ $globalProvider->expects($this->any())->method('isSharedResourceAllowed')->will($this->returnValue(true));
+ $globalProvider->expects($this->any())->method('providesFor')->will($this->returnCallback(function(File $file) { return true; }));
$profile->addFileVersion('image', 'imagenizer', $imageProvider);
$profile->addFileVersion('video', 'videonizer', $videoProvider);
@@ -358,9 +364,40 @@ private function createProfileWithMockedVersions()
$profile->addFileVersion('image', 'globalizer', $globalProvider);
$profile->addFileVersion('video', 'globalizer', $globalProvider);
+ $profile->addPlugin($imageProvider);
+ $profile->addPlugin($videoProvider);
+ $profile->addPlugin($globalProvider);
+
return $profile;
}
+ /**
+ * @return array
+ */
+ public function provideDataForisSharedResourceAllowed()
+ {
+ return array(
+ array(true, 'image/png'),
+ array(false, 'video/lus'),
+ array(true, 'lussen/tussen'),
+ );
+ }
+
+ /**
+ * @test
+ * @dataProvider provideDataForisSharedResourceAllowed
+ */
+ public function isSharedResourceAllowedShouldReturnCorrectResult($expected, $mimetype)
+ {
+ $profile = $this->createProfileWithMockedVersions();
+ $profile->setFilelib($this->createMockedFilelib());
+
+ $file = File::create(array('resource' => Resource::create(array('mimetype' => $mimetype))));
+
+ $this->assertEquals($expected, $profile->isSharedResourceAllowed($file));
+ }
+
+
}
View
2 tests/Xi/Tests/Filelib/Plugin/Video/ZencoderPluginTest.php
@@ -217,8 +217,6 @@ public function pluginShouldProvideForVideo()
/**
* @test
- * @plugin
- * @group watussi
*/
public function createVersionsShouldCreateVersions()
{
View
98 tests/Xi/Tests/Filelib/Publisher/Filesystem/CopyFilesystemPublisherTest.php
@@ -19,74 +19,34 @@ public function setUp()
$linker = $this->getMockBuilder('Xi\Filelib\Linker\Linker')->getMock();
+ $linker = $this->getMockBuilder('Xi\Filelib\Linker\Linker')->getMock();
$linker->expects($this->any())->method('getLinkVersion')
- ->will($this->returnCallback(function($file, $version, $extension) {
-
- switch ($file->getId()) {
-
- case 1:
- $prefix = 'lussin/tussin';
- break;
- case 2:
- $prefix = 'lussin/tussin/jussin/pussin';
- break;
- case 3:
- $prefix = 'tohtori/vesalan/suuri/otsa';
- break;
- case 4:
- $prefix = 'lussen/hof';
- break;
- case 5:
- $prefix = '';
- break;
- }
-
-
- return $prefix . '/' . $file->getId() . '-' . $version . '.lus';
-
- }));
+ ->will($this->returnCallback(function($file, $version) {
+ return $this->linkPaths[$file->getId()] . '/' . $file->getId() . '-' . $version . '.lus';
+ }));
$linker->expects($this->any())->method('getLink')
- ->will($this->returnCallback(function($file) {
-
- switch ($file->getId()) {
-
- case 1:
- $prefix = 'lussin/tussin';
- break;
- case 2:
- $prefix = 'lussin/tussin/jussin/pussin';
- break;
- case 3:
- $prefix = 'tohtori/vesalan/suuri/otsa';
- break;
- case 4:
- $prefix = 'lussen/hof';
- break;
- case 5:
- $prefix = '';
- break;
-
-
- }
-
- return $prefix . '/' . $file->getId() . '.lus';
- }));
-
+ ->will($this->returnCallback(function($file) {
+ return $this->linkPaths[$file->getId()] . '/' . $file->getId() . '.lus';
+ }));
$this->plinker = $linker;
}
-
-
public function provideDataForPublishingTests()
{
$files = array();
for ($x = 1; $x <= 5; $x++) {
$file = $this->getMockBuilder('Xi\Filelib\File\File')->getMock();
- $file->expects($this->any())->method('getId')->will($this->returnValue($x));
+
+ $file->expects($this->any())->method('getProfile')
+ ->will($this->returnValue('profile'));
+
$file->expects($this->any())->method('getResource')->will($this->returnValue(Resource::create(array('id' => $x))));
+
+ $file->expects($this->any())->method('getId')->will($this->returnValue($x));
+
$files[$x-1] = $file;
}
@@ -97,6 +57,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussin/tussin/1-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/1/1',
'../../../private/1/1',
+ true,
),
array(
$files[1],
@@ -104,6 +65,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussin/tussin/jussin/pussin/2-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/2/2/2',
'../../../../../private/2/2/2',
+ false,
),
array(
$files[2],
@@ -111,6 +73,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/tohtori/vesalan/suuri/otsa/3-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/3/3/3/3',
'../../../../../private/3/3/3/3',
+ false,
),
array(
$files[3],
@@ -118,16 +81,17 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussen/hof/4-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/666/4',
'../../../private/666/4',
+ true
),
array(
$files[4],
ROOT_TESTS . '/data/publisher/public/5.lus',
ROOT_TESTS . '/data/publisher/public/5-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/1/5',
- '../../../private/1/5',
+ '../private/1/5',
+ true,
),
-
);
return $ret;
@@ -135,13 +99,17 @@ public function provideDataForPublishingTests()
}
-
/**
* @test
* @dataProvider provideDataForPublishingTests
*/
public function publishShouldPublishFile($file, $expectedPath, $expectedVersionPath, $expectedRealPath)
{
+ $this->storage->expects($this->atLeastOnce())->method('retrieve')
+ ->will($this->returnCallback(function(Resource $resource) {
+ return $this->resourcePaths[$resource->getId()];
+ }));
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\CopyFilesystemPublisher')
@@ -173,8 +141,22 @@ public function publishShouldPublishFile($file, $expectedPath, $expectedVersionP
* @test
* @dataProvider provideDataForPublishingTests
*/
- public function publishShouldPublishFileVersion($file, $expectedPath, $expectedVersionPath, $expectedRealPath)
+ public function publishShouldPublishFileVersion($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath, $allowSharedVersions)
{
+ $this->versionProvider->expects($this->atLeastOnce())
+ ->method('areSharedVersionsAllowed')
+ ->will($this->returnValue($allowSharedVersions));
+
+ if ($allowSharedVersions) {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer')
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ } else {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer', $file)
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ }
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\CopyFilesystemPublisher')
View
114 tests/Xi/Tests/Filelib/Publisher/Filesystem/SymlinkFilesystemPublisherTest.php
@@ -19,59 +19,13 @@ public function setUp()
$linker = $this->getMockBuilder('Xi\Filelib\Linker\Linker')->getMock();
$linker->expects($this->any())->method('getLinkVersion')
->will($this->returnCallback(function($file, $version) {
-
- switch ($file->getId()) {
-
- case 1:
- $prefix = 'lussin/tussin';
- break;
- case 2:
- $prefix = 'lussin/tussin/jussin/pussin';
- break;
- case 3:
- $prefix = 'tohtori/vesalan/suuri/otsa';
- break;
- case 4:
- $prefix = 'lussen/hof';
- break;
- case 5:
- $prefix = '';
- break;
-
- }
-
-
- return $prefix . '/' . $file->getId() . '-' . $version . '.lus';
-
+ return $this->linkPaths[$file->getId()] . '/' . $file->getId() . '-' . $version . '.lus';
}));
$linker->expects($this->any())->method('getLink')
->will($this->returnCallback(function($file) {
-
- switch ($file->getId()) {
-
- case 1:
- $prefix = 'lussin/tussin';
- break;
- case 2:
- $prefix = 'lussin/tussin/jussin/pussin';
- break;
- case 3:
- $prefix = 'tohtori/vesalan/suuri/otsa';
- break;
- case 4:
- $prefix = 'lussen/hof';
- break;
- case 5:
- $prefix = '';
- break;
-
- }
-
- return $prefix . '/' . $file->getId() . '.lus';
+ return $this->linkPaths[$file->getId()] . '/' . $file->getId() . '.lus';
}));
-
$this->plinker = $linker;
-
}
@@ -150,14 +104,23 @@ public function provideDataForRelativePathTest()
*/
public function getRelativePathToShouldReturnRelativePathToFile($file, $levelsDown, $expectedRelativePath)
{
- $this->filelib->setStorage($this->storage);
+ $storage = $this->getMock('Xi\Filelib\Storage\FilesystemStorage');
+ $storage->expects($this->any())->method('getRoot')->will($this->returnValue('/tussin/lussu'));
+
+ $storage->expects($this->once())->method('retrieve')
+ ->with($file->getResource())
+ ->will($this->returnValue('/tussin/lussu/lussutustiedosto'));
+
+ $this->filelib->setStorage($storage);
$publisher = new SymlinkFilesystemPublisher();
$publisher->setFilelib($this->filelib);
$publisher->setPublicRoot(ROOT_TESTS . '/data/publisher/public');
$publisher->setRelativePathToRoot('../private');
- $this->assertEquals($expectedRelativePath, $publisher->getRelativePathTo($file, $levelsDown));
+ $expectedPath = str_repeat("../", $levelsDown) . $publisher->getRelativePathToRoot() . '/lussutustiedosto';
+
+ $this->assertEquals($expectedPath, $publisher->getRelativePathTo($file, $levelsDown));
}
@@ -226,6 +189,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussin/tussin/1-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/1/1',
'../../../private/1/1',
+ true,
),
array(
$files[1],
@@ -233,6 +197,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussin/tussin/jussin/pussin/2-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/2/2/2',
'../../../../../private/2/2/2',
+ false,
),
array(
$files[2],
@@ -240,6 +205,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/tohtori/vesalan/suuri/otsa/3-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/3/3/3/3',
'../../../../../private/3/3/3/3',
+ false,
),
array(
$files[3],
@@ -247,6 +213,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/lussen/hof/4-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/666/4',
'../../../private/666/4',
+ true
),
array(
$files[4],
@@ -254,6 +221,7 @@ public function provideDataForPublishingTests()
ROOT_TESTS . '/data/publisher/public/5-xooxer.lus',
ROOT_TESTS . '/data/publisher/private/1/5',
'../private/1/5',
+ true,
),
);
@@ -268,6 +236,11 @@ public function provideDataForPublishingTests()
*/
public function publishShouldPublishFileWithoutRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath)
{
+ $this->storage->expects($this->atLeastOnce())->method('retrieve')
+ ->will($this->returnCallback(function(Resource $resource) {
+ return $this->resourcePaths[$resource->getId()];
+ }));
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\SymlinkFilesystemPublisher')
@@ -299,8 +272,22 @@ public function publishShouldPublishFileWithoutRelativePaths($file, $expectedPat
* @test
* @dataProvider provideDataForPublishingTests
*/
- public function publishShouldPublishFileVersionWithoutRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath)
+ public function publishShouldPublishFileVersionWithoutRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath, $allowSharedVersions)
{
+ $this->versionProvider->expects($this->atLeastOnce())
+ ->method('areSharedVersionsAllowed')
+ ->will($this->returnValue($allowSharedVersions));
+
+ if ($allowSharedVersions) {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer')
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ } else {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer', $file)
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ }
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\SymlinkFilesystemPublisher')
@@ -315,7 +302,7 @@ public function publishShouldPublishFileVersionWithoutRelativePaths($file, $expe
$publisher->setPublicRoot(ROOT_TESTS . '/data/publisher/public');
// $publisher->setRelativePathToRoot('../private');
- $publisher->publishVersion($file, $this->versionProvider->getIdentifier(), $this->versionProvider);
+ $publisher->publishVersion($file, 'xooxer', $this->versionProvider);
$sfi = new \SplFileInfo($expectedVersionPath);
@@ -332,8 +319,13 @@ public function publishShouldPublishFileVersionWithoutRelativePaths($file, $expe
* @test
* @dataProvider provideDataForPublishingTests
*/
- public function publishShouldPublishFileWithRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath)
+ public function publishShouldPublishFileWithRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath, $allowSharedVersions)
{
+ $this->storage->expects($this->atLeastOnce())->method('retrieve')
+ ->will($this->returnCallback(function(Resource $resource) {
+ return $this->resourcePaths[$resource->getId()];
+ }));
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\SymlinkFilesystemPublisher')
@@ -369,8 +361,22 @@ public function publishShouldPublishFileWithRelativePaths($file, $expectedPath,
* @test
* @dataProvider provideDataForPublishingTests
*/
- public function publishShouldPublishFileVersionWithRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath)
+ public function publishShouldPublishFileVersionWithRelativePaths($file, $expectedPath, $expectedVersionPath, $expectedRealPath, $expectedRelativePath, $allowSharedVersions)
{
+ $this->versionProvider->expects($this->atLeastOnce())
+ ->method('areSharedVersionsAllowed')
+ ->will($this->returnValue($allowSharedVersions));
+
+ if ($allowSharedVersions) {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer')
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ } else {
+ $this->storage->expects($this->once())->method('retrieveVersion')
+ ->with($file->getResource(), 'xooxer', $file)
+ ->will($this->returnValue($this->resourcePaths[$file->getResource()->getId()]));
+ }
+
$this->filelib->setStorage($this->storage);
$publisher = $this->getMockBuilder('Xi\Filelib\Publisher\Filesystem\SymlinkFilesystemPublisher')
View
69 tests/Xi/Tests/Filelib/Publisher/Filesystem/TestCase.php
@@ -15,10 +15,30 @@ class TestCase extends \Xi\Tests\Filelib\TestCase
protected $filelib;
protected $version;
+
+ protected $resourcePaths = array();
+ protected $linkPaths = array();
+
public function setUp()
{
parent::setUp();
+ $this->resourcePaths = array(
+ 1 => ROOT_TESTS . '/data/publisher/private/1/1',
+ 2 => ROOT_TESTS . '/data/publisher/private/2/2/2',
+ 3 => ROOT_TESTS . '/data/publisher/private/3/3/3/3',
+ 4 => ROOT_TESTS . '/data/publisher/private/666/4',
+ 5 => ROOT_TESTS . '/data/publisher/private/1/5'
+ );
+
+ $this->linkPaths = array(
+ 1 => 'lussin/tussin',
+ 2 => 'lussin/tussin/jussin/pussin',
+ 3 => 'tohtori/vesalan/suuri/otsa',
+ 4 => 'lussen/hof',
+ 5 => '',
+ );
+
$linker = $this->getMockBuilder('Xi\Filelib\Linker\Linker')->getMock();
$linker->expects($this->any())->method('getLinkVersion')
->will($this->returnCallback(function($file, $version) { return 'tussin/lussun/tussi-' . $version->getIdentifier() . '.jpg'; }));
@@ -62,57 +82,8 @@ public function setUp()
case 5:
return '1';
}
-
-
-
}));
- $storage->expects($this->any())->method('retrieve')
- ->will($this->returnCallback(function($file){
-
- switch ($file->getId()) {
-
- case 1:
- return ROOT_TESTS . '/data/publisher/private/1/1';
-
- case 2:
- return ROOT_TESTS . '/data/publisher/private/2/2/2';
-
- case 3:
- return ROOT_TESTS . '/data/publisher/private/3/3/3/3';
-
- case 4:
- return ROOT_TESTS . '/data/publisher/private/666/4';
- case 5:
- return ROOT_TESTS . '/data/publisher/private/1/5';
- }
-
- }));
-
- $storage->expects($this->any())->method('retrieveVersion')
- ->will($this->returnCallback(function($file, $version){
-
- switch ($file->getId()) {
-
- case 1:
- return ROOT_TESTS . '/data/publisher/private/1/1';
-
- case 2:
- return ROOT_TESTS . '/data/publisher/private/2/2/2';
-
- case 3:
- return ROOT_TESTS . '/data/publisher/private/3/3/3/3';
-
- case 4:
- return ROOT_TESTS . '/data/publisher/private/666/4';
-
- case 5:
- return ROOT_TESTS . '/data/publisher/private/1/5';
- }
-
- }));
-
-
$this->storage = $storage;
$filelib = new FileLibrary();
View
2 tests/bootstrap.php
@@ -1,7 +1,5 @@
<?php
-use Doctrine\Common\ClassLoader;
-
gc_enable();
/**

0 comments on commit cf15191

Please sign in to comment.
Something went wrong with that request. Please try again.