public function testDeleteMockResourceExistsSizes()
 {
     $resourceDO = $this->getResourceDOMock();
     $this->filesystem->put($resourceDO->getFilePath(), '');
     $resourceDOSize10x11 = $this->getResourceDOMock();
     $resourceDOSize10x11->setWidth(10);
     $resourceDOSize10x11->setHeight(11);
     $this->filesystem->put($resourceDOSize10x11->getFilePath(), '');
     $resourceDOSize20x21 = $this->getResourceDOMock();
     $resourceDOSize20x21->setWidth(20);
     $resourceDOSize20x21->setHeight(21);
     $this->filesystem->put($resourceDOSize20x21->getFilePath(), '');
     $yetAnotherWrongDO = clone $resourceDO;
     $yetAnotherWrongDO->setWidth(998);
     $yetAnotherWrongDO->setHeight(999);
     $this->wrongFiles->create($resourceDO, 'Wrong1');
     $this->wrongFiles->create($resourceDOSize10x11, 'Wrong2');
     $this->wrongFiles->create($resourceDOSize20x21, 'Wrong3');
     $this->wrongFiles->create($yetAnotherWrongDO, 'Wrong4');
     $modelFiles = $this->filesystem->listContents('/', true);
     // Make the expected model looks like filesystem after the command execution
     // With this model we will be sure that other files have not been deleted
     unset($modelFiles[56], $modelFiles[57]);
     $modelFiles[55] = ['type' => 'dir', 'path' => 'testBase/png/def/def/0/c9f/20x21', 'dirname' => 'testBase/png/def/def/0/c9f', 'basename' => '20x21', 'filename' => '20x21'];
     $command = $this->getCommand($resourceDO);
     $result = $command();
     $this->assertTrue($result);
     $this->assertFalse($this->filesystem->has($resourceDOSize10x11->getFilePath()));
     $this->assertFalse($this->filesystem->has($resourceDOSize20x21->getFilePath()));
     $result = $this->filesystem->listContents('/', true);
     $this->assertEquals($modelFiles, $result);
 }
 public function testDestroyResourceAllVariantsAndVersionsButLeaveOthers()
 {
     $resourceDO = $this->getResourceDOMock();
     $this->wrongFiles->create($resourceDO);
     $this->testDestroyResourceAllVariantsAndVersions();
     $this->wrongFiles->assertExist($resourceDO);
 }
 public function testDeleteResourceButLeaveOther()
 {
     $resourceDO = $this->getResourceDOMock();
     $this->filesystem->put($resourceDO->getFilePath(), '');
     $this->wrongFiles->create($resourceDO);
     $model = $this->filesystem->listContents('/', true);
     $model[30] = ['type' => 'dir', 'path' => 'testBase/testType/def/def/1', 'dirname' => 'testBase/testType/def/def', 'basename' => '1', 'filename' => '1'];
     $model[31] = ['type' => 'dir', 'path' => 'testBase/testType/def/def/1/c9f', 'dirname' => 'testBase/testType/def/def/1', 'basename' => 'c9f', 'filename' => 'c9f'];
     $model[32] = ['type' => 'file', 'visibility' => 'public', 'size' => 0, 'path' => 'testBase/testType/def/def/1/c9f/c9f7e81bafc626421e04b573022e6203.testType', 'dirname' => 'testBase/testType/def/def/1/c9f', 'basename' => 'c9f7e81bafc626421e04b573022e6203.testType', 'extension' => 'testType', 'filename' => 'c9f7e81bafc626421e04b573022e6203'];
     $command = $this->getCommand($resourceDO);
     $result = $command();
     $this->assertEquals($resourceDO, $result);
     $this->assertFalse($this->filesystem->has($resourceDO->getFilePath()));
     $result = $this->filesystem->listContents('/', true);
     unset($result[32]['timestamp']);
     $this->assertEquals($model, $result);
 }
 /**
  * @dataProvider testFindResourceDataProvider
  */
 public function testFindResourceMock($namespace, $type, $variant, $version, $name, $nameAlternative, $author)
 {
     $content = 'just a test';
     $resourceDO = $this->prepareResource($namespace, $type, $variant, $version, $name, $nameAlternative, $author);
     $uuid = $resourceDO->getUuid();
     // SAVE CURRENT
     $filePath = $resourceDO->getFilePath();
     $this->filesystem->put($filePath, $content);
     $this->assertTrue($this->filesystem->has($filePath));
     // SAVE ANOTHER VERSION
     $resourceDOVersion = clone $resourceDO;
     $version2 = (string) ($version + 1);
     $resourceDOVersion->setVersion($version2);
     $filePath = $resourceDOVersion->getFilePath();
     $this->filesystem->put($filePath, $content);
     $this->assertTrue($this->filesystem->has($filePath));
     // SAVE ANOTHER VARIANT
     $resourceDOVariant = clone $resourceDO;
     $variant2 = $variant . '_second';
     $resourceDOVariant->setVariant($variant2);
     $filePath = $resourceDOVariant->getFilePath();
     $this->filesystem->put($filePath, $content);
     $this->assertTrue($this->filesystem->has($filePath));
     // SAVE WRONG FILES
     $this->wrongFiles->create($resourceDO, $content);
     $modelBaseDir = substr(self::BASE_DIR, 1, 100);
     $shardVariant = substr($variant, 0, ResourceDOAbstract::SHARD_SLICE_LENGTH);
     $shardFilename = substr($uuid, 0, ResourceDOAbstract::SHARD_SLICE_LENGTH);
     $namespacePath = $namespace ? $namespace . '/' : '';
     $model = [[ResourceDOAbstract::TOKEN_TYPE => $type, 'visibility' => 'public', 'path' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant . '/' . $version . '/' . $shardFilename . '/' . $uuid . '.' . $type, 'dirname' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant . '/' . $version . '/' . $shardFilename, 'basename' => $uuid . '.' . $type, 'extension' => $type, 'filename' => $uuid, 'directory_relative' => $type . '/' . $shardVariant . '/' . $variant . '/' . $version . '/' . $shardFilename, ResourceDOAbstract::TOKEN_SHARD_VARIANT => $shardVariant, ResourceDOAbstract::TOKEN_VARIANT => $variant, ResourceDOAbstract::TOKEN_VERSION => $version, ResourceDOAbstract::TOKEN_SHARD_FILENAME => $shardFilename], [ResourceDOAbstract::TOKEN_TYPE => $type, 'visibility' => 'public', 'path' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant . '/' . $version2 . '/' . $shardFilename . '/' . $uuid . '.' . $type, 'dirname' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant . '/' . $version2 . '/' . $shardFilename, 'basename' => $uuid . '.' . $type, 'extension' => $type, 'filename' => $uuid, 'directory_relative' => $type . '/' . $shardVariant . '/' . $variant . '/' . $version2 . '/' . $shardFilename, ResourceDOAbstract::TOKEN_SHARD_VARIANT => $shardVariant, ResourceDOAbstract::TOKEN_VARIANT => $variant, ResourceDOAbstract::TOKEN_VERSION => $version2, ResourceDOAbstract::TOKEN_SHARD_FILENAME => $shardFilename], [ResourceDOAbstract::TOKEN_TYPE => $type, 'visibility' => 'public', 'path' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant2 . '/' . $version . '/' . $shardFilename . '/' . $uuid . '.' . $type, 'dirname' => $modelBaseDir . '/' . $namespacePath . $type . '/' . $shardVariant . '/' . $variant2 . '/' . $version . '/' . $shardFilename, 'basename' => $uuid . '.' . $type, 'extension' => $type, 'filename' => $uuid, 'directory_relative' => $type . '/' . $shardVariant . '/' . $variant2 . '/' . $version . '/' . $shardFilename, ResourceDOAbstract::TOKEN_SHARD_VARIANT => $shardVariant, ResourceDOAbstract::TOKEN_VARIANT => $variant2, ResourceDOAbstract::TOKEN_VERSION => $version, ResourceDOAbstract::TOKEN_SHARD_FILENAME => $shardFilename]];
     $command = $this->getCommand($resourceDO);
     $result = $command();
     foreach ($result as &$item) {
         $this->assertArrayHasKey('size', $item);
         $this->assertArrayHasKey('timestamp', $item);
         unset($item['size'], $item['timestamp']);
     }
     $this->assertEquals($model, $result);
 }