Split FileService to NetworkingService and FileDao
This commit is contained in:
parent
608eb2e917
commit
3744f0429a
30 changed files with 290 additions and 212 deletions
1
TODO
1
TODO
|
@ -59,7 +59,6 @@ everything related to tags:
|
||||||
- target tags (allow multiple)
|
- target tags (allow multiple)
|
||||||
|
|
||||||
refactors:
|
refactors:
|
||||||
- split FileService into FileService and FileDao
|
|
||||||
- add enum validation in IValidatables (needs refactors of enums and
|
- add enum validation in IValidatables (needs refactors of enums and
|
||||||
possible disposal of EnumHelper in favor of something more subtle)
|
possible disposal of EnumHelper in favor of something more subtle)
|
||||||
- change content spinner to nprogress:
|
- change content spinner to nprogress:
|
||||||
|
|
|
@ -15,7 +15,7 @@ use Szurubooru\Services\CommentService;
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
use Szurubooru\Services\PrivilegeService;
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
class CommentController extends AbstractController
|
final class CommentController extends AbstractController
|
||||||
{
|
{
|
||||||
private $privilegeService;
|
private $privilegeService;
|
||||||
private $authService;
|
private $authService;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use Szurubooru\Services\FavoritesService;
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
use Szurubooru\Services\PrivilegeService;
|
use Szurubooru\Services\PrivilegeService;
|
||||||
|
|
||||||
class FavoritesController extends AbstractController
|
final class FavoritesController extends AbstractController
|
||||||
{
|
{
|
||||||
private $privilegeService;
|
private $privilegeService;
|
||||||
private $authService;
|
private $authService;
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Controllers;
|
namespace Szurubooru\Controllers;
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Router;
|
use Szurubooru\Router;
|
||||||
use Szurubooru\Services\FileService;
|
use Szurubooru\Services\NetworkingService;
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
|
|
||||||
final class PostContentController extends AbstractController
|
final class PostContentController extends AbstractController
|
||||||
{
|
{
|
||||||
|
private $fileDao;
|
||||||
private $postService;
|
private $postService;
|
||||||
private $fileService;
|
private $networkingService;
|
||||||
private $httpHelper;
|
|
||||||
private $thumbnailService;
|
private $thumbnailService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
PublicFileDao $fileDao,
|
||||||
PostService $postService,
|
PostService $postService,
|
||||||
FileService $fileService,
|
NetworkingService $networkingService,
|
||||||
HttpHelper $httpHelper,
|
|
||||||
ThumbnailService $thumbnailService)
|
ThumbnailService $thumbnailService)
|
||||||
{
|
{
|
||||||
|
$this->fileDao = $fileDao;
|
||||||
$this->postService = $postService;
|
$this->postService = $postService;
|
||||||
$this->fileService = $fileService;
|
$this->networkingService = $networkingService;
|
||||||
$this->httpHelper = $httpHelper;
|
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->thumbnailService = $thumbnailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ final class PostContentController extends AbstractController
|
||||||
public function getPostContent($postName)
|
public function getPostContent($postName)
|
||||||
{
|
{
|
||||||
$post = $this->postService->getByName($postName);
|
$post = $this->postService->getByName($postName);
|
||||||
$this->fileService->serve($post->getContentPath());
|
$this->networkingService->serve($this->fileDao->getFullPath($post->getContentPath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPostThumbnail($postName, $size)
|
public function getPostThumbnail($postName, $size)
|
||||||
|
@ -42,11 +42,11 @@ final class PostContentController extends AbstractController
|
||||||
$post = $this->postService->getByName($postName);
|
$post = $this->postService->getByName($postName);
|
||||||
|
|
||||||
$sourceName = $post->getThumbnailSourceContentPath();
|
$sourceName = $post->getThumbnailSourceContentPath();
|
||||||
if (!$this->fileService->exists($sourceName))
|
if (!$this->fileDao->exists($sourceName))
|
||||||
$sourceName = $post->getContentPath();
|
$sourceName = $post->getContentPath();
|
||||||
|
|
||||||
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
||||||
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
||||||
$this->fileService->serve($thumbnailName);
|
$this->networkingService->serve($this->fileDao->getFullPath($thumbnailName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,31 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Controllers;
|
namespace Szurubooru\Controllers;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
use Szurubooru\Helpers\HttpHelper;
|
||||||
use Szurubooru\Router;
|
use Szurubooru\Router;
|
||||||
use Szurubooru\Services\FileService;
|
use Szurubooru\Services\NetworkingService;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Services\UserService;
|
use Szurubooru\Services\UserService;
|
||||||
|
|
||||||
final class UserAvatarController extends AbstractController
|
final class UserAvatarController extends AbstractController
|
||||||
{
|
{
|
||||||
|
private $fileDao;
|
||||||
private $userService;
|
private $userService;
|
||||||
private $fileService;
|
private $networkingService;
|
||||||
private $httpHelper;
|
private $httpHelper;
|
||||||
private $thumbnailService;
|
private $thumbnailService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
PublicFileDao $fileDao,
|
||||||
UserService $userService,
|
UserService $userService,
|
||||||
FileService $fileService,
|
NetworkingService $networkingService,
|
||||||
HttpHelper $httpHelper,
|
HttpHelper $httpHelper,
|
||||||
ThumbnailService $thumbnailService)
|
ThumbnailService $thumbnailService)
|
||||||
{
|
{
|
||||||
|
$this->fileDao = $fileDao;
|
||||||
$this->userService = $userService;
|
$this->userService = $userService;
|
||||||
$this->fileService = $fileService;
|
$this->networkingService = $networkingService;
|
||||||
$this->httpHelper = $httpHelper;
|
$this->httpHelper = $httpHelper;
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->thumbnailService = $thumbnailService;
|
||||||
}
|
}
|
||||||
|
@ -73,12 +77,12 @@ final class UserAvatarController extends AbstractController
|
||||||
{
|
{
|
||||||
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
$this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
||||||
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
$thumbnailName = $this->thumbnailService->getThumbnailName($sourceName, $size, $size);
|
||||||
$this->fileService->serve($thumbnailName);
|
$this->networkingService->serve($this->fileDao->getFullPath($thumbnailName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function serveBlankFile($size)
|
private function serveBlankFile($size)
|
||||||
{
|
{
|
||||||
$this->serveFromFile($this->getBlankAvatarSourceContentPath(), $size);
|
$this->serveFromFile($this->fileDao->getFullPath($this->getBlankAvatarSourceContentPath()), $size);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBlankAvatarSourceContentPath()
|
private function getBlankAvatarSourceContentPath()
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Szurubooru\SearchServices\Requirements\RequirementRangedValue;
|
||||||
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
||||||
use Szurubooru\SearchServices\Result;
|
use Szurubooru\SearchServices\Result;
|
||||||
|
|
||||||
abstract class AbstractDao implements ICrudDao
|
abstract class AbstractDao implements ICrudDao, IBatchDao
|
||||||
{
|
{
|
||||||
protected $pdo;
|
protected $pdo;
|
||||||
protected $fpdo;
|
protected $fpdo;
|
||||||
|
|
53
src/Dao/FileDao.php
Normal file
53
src/Dao/FileDao.php
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Dao;
|
||||||
|
use Szurubooru\Dao\IFileDao;
|
||||||
|
|
||||||
|
class FileDao implements IFileDao
|
||||||
|
{
|
||||||
|
private $directory;
|
||||||
|
|
||||||
|
public function __construct($directory)
|
||||||
|
{
|
||||||
|
$this->directory = $directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load($fileName)
|
||||||
|
{
|
||||||
|
$fullPath = $this->getFullPath($fileName);
|
||||||
|
return file_exists($fullPath)
|
||||||
|
? file_get_contents($fullPath)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($fileName, $data)
|
||||||
|
{
|
||||||
|
$fullPath = $this->getFullPath($fileName);
|
||||||
|
$this->createFolders($fileName);
|
||||||
|
file_put_contents($fullPath, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($fileName)
|
||||||
|
{
|
||||||
|
$fullPath = $this->getFullPath($fileName);
|
||||||
|
if (file_exists($fullPath))
|
||||||
|
unlink($fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exists($fileName)
|
||||||
|
{
|
||||||
|
$fullPath = $this->getFullPath($fileName);
|
||||||
|
return file_exists($fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFullPath($fileName)
|
||||||
|
{
|
||||||
|
return $this->directory . DIRECTORY_SEPARATOR . $fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createFolders($fileName)
|
||||||
|
{
|
||||||
|
$fullPath = $this->getFullPath(dirname($fileName));
|
||||||
|
if (!file_exists($fullPath))
|
||||||
|
mkdir($fullPath, 0777, true);
|
||||||
|
}
|
||||||
|
}
|
11
src/Dao/IBatchDao.php
Normal file
11
src/Dao/IBatchDao.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Dao;
|
||||||
|
|
||||||
|
interface IBatchDao
|
||||||
|
{
|
||||||
|
public function findAll();
|
||||||
|
|
||||||
|
public function deleteAll();
|
||||||
|
|
||||||
|
public function batchSave(array $objects);
|
||||||
|
}
|
|
@ -3,15 +3,9 @@ namespace Szurubooru\Dao;
|
||||||
|
|
||||||
interface ICrudDao
|
interface ICrudDao
|
||||||
{
|
{
|
||||||
public function findAll();
|
|
||||||
|
|
||||||
public function findById($objectId);
|
public function findById($objectId);
|
||||||
|
|
||||||
public function save(&$object);
|
public function save(&$object);
|
||||||
|
|
||||||
public function batchSave(array $object);
|
|
||||||
|
|
||||||
public function deleteById($objectId);
|
public function deleteById($objectId);
|
||||||
|
|
||||||
public function deleteAll();
|
|
||||||
}
|
}
|
||||||
|
|
13
src/Dao/IFileDao.php
Normal file
13
src/Dao/IFileDao.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Dao;
|
||||||
|
|
||||||
|
interface IFileDao
|
||||||
|
{
|
||||||
|
public function load($fileName);
|
||||||
|
|
||||||
|
public function save($fileName, $contents);
|
||||||
|
|
||||||
|
public function delete($fileName);
|
||||||
|
|
||||||
|
public function exists($fileName);
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Dao;
|
namespace Szurubooru\Dao;
|
||||||
use Szurubooru\Dao\EntityConverters\PostEntityConverter;
|
use Szurubooru\Dao\EntityConverters\PostEntityConverter;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Dao\TagDao;
|
use Szurubooru\Dao\TagDao;
|
||||||
use Szurubooru\Dao\UserDao;
|
use Szurubooru\Dao\UserDao;
|
||||||
use Szurubooru\DatabaseConnection;
|
use Szurubooru\DatabaseConnection;
|
||||||
|
@ -8,21 +9,20 @@ use Szurubooru\Entities\Entity;
|
||||||
use Szurubooru\Entities\Post;
|
use Szurubooru\Entities\Post;
|
||||||
use Szurubooru\SearchServices\Filters\PostFilter;
|
use Szurubooru\SearchServices\Filters\PostFilter;
|
||||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
|
|
||||||
class PostDao extends AbstractDao implements ICrudDao
|
class PostDao extends AbstractDao implements ICrudDao
|
||||||
{
|
{
|
||||||
private $tagDao;
|
private $tagDao;
|
||||||
private $userDao;
|
private $userDao;
|
||||||
private $fileService;
|
private $fileDao;
|
||||||
private $thumbnailService;
|
private $thumbnailService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DatabaseConnection $databaseConnection,
|
DatabaseConnection $databaseConnection,
|
||||||
TagDao $tagDao,
|
TagDao $tagDao,
|
||||||
UserDao $userDao,
|
UserDao $userDao,
|
||||||
FileService $fileService,
|
PublicFileDao $fileDao,
|
||||||
ThumbnailService $thumbnailService)
|
ThumbnailService $thumbnailService)
|
||||||
{
|
{
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
|
@ -32,7 +32,7 @@ class PostDao extends AbstractDao implements ICrudDao
|
||||||
|
|
||||||
$this->tagDao = $tagDao;
|
$this->tagDao = $tagDao;
|
||||||
$this->userDao = $userDao;
|
$this->userDao = $userDao;
|
||||||
$this->fileService = $fileService;
|
$this->fileDao = $fileDao;
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->thumbnailService = $thumbnailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,14 +63,14 @@ class PostDao extends AbstractDao implements ICrudDao
|
||||||
Post::LAZY_LOADER_CONTENT,
|
Post::LAZY_LOADER_CONTENT,
|
||||||
function (Post $post)
|
function (Post $post)
|
||||||
{
|
{
|
||||||
return $this->fileService->load($post->getContentPath());
|
return $this->fileDao->load($post->getContentPath());
|
||||||
});
|
});
|
||||||
|
|
||||||
$post->setLazyLoader(
|
$post->setLazyLoader(
|
||||||
Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT,
|
Post::LAZY_LOADER_THUMBNAIL_SOURCE_CONTENT,
|
||||||
function (Post $post)
|
function (Post $post)
|
||||||
{
|
{
|
||||||
return $this->fileService->load($post->getThumbnailSourceContentPath());
|
return $this->fileDao->load($post->getThumbnailSourceContentPath());
|
||||||
});
|
});
|
||||||
|
|
||||||
$post->setLazyLoader(
|
$post->setLazyLoader(
|
||||||
|
@ -194,9 +194,9 @@ class PostDao extends AbstractDao implements ICrudDao
|
||||||
$targetPath = $post->getContentPath();
|
$targetPath = $post->getContentPath();
|
||||||
$content = $post->getContent();
|
$content = $post->getContent();
|
||||||
if ($content)
|
if ($content)
|
||||||
$this->fileService->save($targetPath, $content);
|
$this->fileDao->save($targetPath, $content);
|
||||||
else
|
else
|
||||||
$this->fileService->delete($targetPath, $content);
|
$this->fileDao->delete($targetPath, $content);
|
||||||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,9 +205,9 @@ class PostDao extends AbstractDao implements ICrudDao
|
||||||
$targetPath = $post->getThumbnailSourceContentPath();
|
$targetPath = $post->getThumbnailSourceContentPath();
|
||||||
$content = $post->getThumbnailSourceContent();
|
$content = $post->getThumbnailSourceContent();
|
||||||
if ($content)
|
if ($content)
|
||||||
$this->fileService->save($targetPath, $content);
|
$this->fileDao->save($targetPath, $content);
|
||||||
else
|
else
|
||||||
$this->fileService->delete($targetPath);
|
$this->fileDao->delete($targetPath);
|
||||||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
src/Dao/PublicFileDao.php
Normal file
13
src/Dao/PublicFileDao.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Dao;
|
||||||
|
use Szurubooru\Config;
|
||||||
|
use Szurubooru\Dao\FileDao;
|
||||||
|
use Szurubooru\Dao\IFileDao;
|
||||||
|
|
||||||
|
class PublicFileDao extends FileDao implements IFileDao
|
||||||
|
{
|
||||||
|
public function __construct(Config $config)
|
||||||
|
{
|
||||||
|
parent::__construct($config->getPublicDataDirectory());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Dao;
|
namespace Szurubooru\Dao;
|
||||||
use Szurubooru\Dao\EntityConverters\UserEntityConverter;
|
use Szurubooru\Dao\EntityConverters\UserEntityConverter;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\DatabaseConnection;
|
use Szurubooru\DatabaseConnection;
|
||||||
use Szurubooru\Entities\Entity;
|
use Szurubooru\Entities\Entity;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
|
|
||||||
class UserDao extends AbstractDao implements ICrudDao
|
class UserDao extends AbstractDao implements ICrudDao
|
||||||
|
@ -12,12 +12,12 @@ class UserDao extends AbstractDao implements ICrudDao
|
||||||
const ORDER_NAME = 'name';
|
const ORDER_NAME = 'name';
|
||||||
const ORDER_REGISTRATION_TIME = 'registrationTime';
|
const ORDER_REGISTRATION_TIME = 'registrationTime';
|
||||||
|
|
||||||
private $fileService;
|
private $fileDao;
|
||||||
private $thumbnailService;
|
private $thumbnailService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DatabaseConnection $databaseConnection,
|
DatabaseConnection $databaseConnection,
|
||||||
FileService $fileService,
|
PublicFileDao $fileDao,
|
||||||
ThumbnailService $thumbnailService)
|
ThumbnailService $thumbnailService)
|
||||||
{
|
{
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
|
@ -25,7 +25,7 @@ class UserDao extends AbstractDao implements ICrudDao
|
||||||
'users',
|
'users',
|
||||||
new UserEntityConverter());
|
new UserEntityConverter());
|
||||||
|
|
||||||
$this->fileService = $fileService;
|
$this->fileDao = $fileDao;
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->thumbnailService = $thumbnailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ class UserDao extends AbstractDao implements ICrudDao
|
||||||
function(User $user)
|
function(User $user)
|
||||||
{
|
{
|
||||||
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
||||||
return $this->fileService->load($avatarSource);
|
return $this->fileDao->load($avatarSource);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,16 +71,16 @@ class UserDao extends AbstractDao implements ICrudDao
|
||||||
$targetPath = $user->getCustomAvatarSourceContentPath();
|
$targetPath = $user->getCustomAvatarSourceContentPath();
|
||||||
$content = $user->getCustomAvatarSourceContent();
|
$content = $user->getCustomAvatarSourceContent();
|
||||||
if ($content)
|
if ($content)
|
||||||
$this->fileService->save($targetPath, $content);
|
$this->fileDao->save($targetPath, $content);
|
||||||
else
|
else
|
||||||
$this->fileService->delete($targetPath);
|
$this->fileDao->delete($targetPath);
|
||||||
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
$this->thumbnailService->deleteUsedThumbnails($targetPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function afterDelete(Entity $user)
|
protected function afterDelete(Entity $user)
|
||||||
{
|
{
|
||||||
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
$avatarSource = $user->getCustomAvatarSourceContentPath();
|
||||||
$this->fileService->delete($avatarSource);
|
$this->fileDao->delete($avatarSource);
|
||||||
$this->thumbnailService->deleteUsedThumbnails($avatarSource);
|
$this->thumbnailService->deleteUsedThumbnails($avatarSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,18 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Services;
|
namespace Szurubooru\Services;
|
||||||
use Szurubooru\Config;
|
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
use Szurubooru\Helpers\HttpHelper;
|
||||||
|
|
||||||
class FileService
|
class NetworkingService
|
||||||
{
|
{
|
||||||
private $dataDirectory;
|
|
||||||
private $httpHelper;
|
private $httpHelper;
|
||||||
|
|
||||||
public function __construct(Config $config, HttpHelper $httpHelper)
|
public function __construct(HttpHelper $httpHelper)
|
||||||
{
|
{
|
||||||
$this->dataDirectory = $config->getPublicDataDirectory();
|
|
||||||
$this->httpHelper = $httpHelper;
|
$this->httpHelper = $httpHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serve($target, $options = [])
|
public function serve($fullPath, $options = [])
|
||||||
{
|
{
|
||||||
$fullPath = $this->getFullPath($target);
|
|
||||||
|
|
||||||
$daysToLive = isset($options->daysToLive)
|
$daysToLive = isset($options->daysToLive)
|
||||||
? $options->daysToLive
|
? $options->daysToLive
|
||||||
: 7;
|
: 7;
|
||||||
|
@ -61,46 +56,6 @@ class FileService
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createFolders($target)
|
|
||||||
{
|
|
||||||
$fullPath = $this->getFullPath(dirname($target));
|
|
||||||
if (!file_exists($fullPath))
|
|
||||||
mkdir($fullPath, 0777, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function exists($target)
|
|
||||||
{
|
|
||||||
$fullPath = $this->getFullPath($target);
|
|
||||||
return $target and file_exists($fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete($target)
|
|
||||||
{
|
|
||||||
$fullPath = $this->getFullPath($target);
|
|
||||||
if (file_exists($fullPath))
|
|
||||||
unlink($fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load($source)
|
|
||||||
{
|
|
||||||
if (!$this->exists($source))
|
|
||||||
return null;
|
|
||||||
$fullPath = $this->getFullPath($source);
|
|
||||||
return file_get_contents($fullPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save($destination, $data)
|
|
||||||
{
|
|
||||||
$this->createFolders($destination);
|
|
||||||
$finalDestination = $this->getFullPath($destination);
|
|
||||||
file_put_contents($finalDestination, $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFullPath($destination)
|
|
||||||
{
|
|
||||||
return $this->dataDirectory . DIRECTORY_SEPARATOR . $destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function download($url, $maxBytes = null)
|
public function download($url, $maxBytes = null)
|
||||||
{
|
{
|
||||||
set_time_limit(60);
|
set_time_limit(60);
|
|
@ -15,9 +15,9 @@ use Szurubooru\SearchServices\Filters\SnapshotFilter;
|
||||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||||
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
||||||
use Szurubooru\Services\AuthService;
|
use Szurubooru\Services\AuthService;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\HistoryService;
|
use Szurubooru\Services\HistoryService;
|
||||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||||
|
use Szurubooru\Services\NetworkingService;
|
||||||
use Szurubooru\Services\TagService;
|
use Szurubooru\Services\TagService;
|
||||||
use Szurubooru\Services\TimeService;
|
use Szurubooru\Services\TimeService;
|
||||||
use Szurubooru\Validator;
|
use Szurubooru\Validator;
|
||||||
|
@ -31,7 +31,7 @@ class PostService
|
||||||
private $globalParamDao;
|
private $globalParamDao;
|
||||||
private $timeService;
|
private $timeService;
|
||||||
private $authService;
|
private $authService;
|
||||||
private $fileService;
|
private $networkingService;
|
||||||
private $tagService;
|
private $tagService;
|
||||||
private $historyService;
|
private $historyService;
|
||||||
private $imageManipulator;
|
private $imageManipulator;
|
||||||
|
@ -44,7 +44,7 @@ class PostService
|
||||||
GlobalParamDao $globalParamDao,
|
GlobalParamDao $globalParamDao,
|
||||||
AuthService $authService,
|
AuthService $authService,
|
||||||
TimeService $timeService,
|
TimeService $timeService,
|
||||||
FileService $fileService,
|
NetworkingService $networkingService,
|
||||||
TagService $tagService,
|
TagService $tagService,
|
||||||
HistoryService $historyService,
|
HistoryService $historyService,
|
||||||
ImageManipulator $imageManipulator)
|
ImageManipulator $imageManipulator)
|
||||||
|
@ -56,7 +56,7 @@ class PostService
|
||||||
$this->globalParamDao = $globalParamDao;
|
$this->globalParamDao = $globalParamDao;
|
||||||
$this->timeService = $timeService;
|
$this->timeService = $timeService;
|
||||||
$this->authService = $authService;
|
$this->authService = $authService;
|
||||||
$this->fileService = $fileService;
|
$this->networkingService = $networkingService;
|
||||||
$this->tagService = $tagService;
|
$this->tagService = $tagService;
|
||||||
$this->historyService = $historyService;
|
$this->historyService = $historyService;
|
||||||
$this->imageManipulator = $imageManipulator;
|
$this->imageManipulator = $imageManipulator;
|
||||||
|
@ -270,12 +270,12 @@ class PostService
|
||||||
|
|
||||||
$this->assertNoPostWithThisContentChecksum($post);
|
$this->assertNoPostWithThisContentChecksum($post);
|
||||||
$youtubeThumbnailUrl = 'http://img.youtube.com/vi/' . $youtubeId . '/mqdefault.jpg';
|
$youtubeThumbnailUrl = 'http://img.youtube.com/vi/' . $youtubeId . '/mqdefault.jpg';
|
||||||
$youtubeThumbnail = $this->fileService->download($youtubeThumbnailUrl);
|
$youtubeThumbnail = $this->networkingService->download($youtubeThumbnailUrl);
|
||||||
$post->setThumbnailSourceContent($youtubeThumbnail);
|
$post->setThumbnailSourceContent($youtubeThumbnail);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$contents = $this->fileService->download($url);
|
$contents = $this->networkingService->download($url);
|
||||||
$this->updatePostContentFromString($post, $contents);
|
$this->updatePostContentFromString($post, $contents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,29 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Services;
|
namespace Szurubooru\Services;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Dao\TagDao;
|
use Szurubooru\Dao\TagDao;
|
||||||
use Szurubooru\Dao\TransactionManager;
|
use Szurubooru\Dao\TransactionManager;
|
||||||
use Szurubooru\Entities\Tag;
|
use Szurubooru\Entities\Tag;
|
||||||
use Szurubooru\SearchServices\Filters\TagFilter;
|
use Szurubooru\SearchServices\Filters\TagFilter;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\TimeService;
|
use Szurubooru\Services\TimeService;
|
||||||
|
|
||||||
class TagService
|
class TagService
|
||||||
{
|
{
|
||||||
private $transactionManager;
|
private $transactionManager;
|
||||||
private $tagDao;
|
private $tagDao;
|
||||||
private $fileService;
|
private $fileDao;
|
||||||
private $timeService;
|
private $timeService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
TransactionManager $transactionManager,
|
TransactionManager $transactionManager,
|
||||||
TagDao $tagDao,
|
TagDao $tagDao,
|
||||||
TimeService $timeService,
|
PublicFileDao $fileDao,
|
||||||
FileService $fileService)
|
TimeService $timeService)
|
||||||
{
|
{
|
||||||
$this->transactionManager = $transactionManager;
|
$this->transactionManager = $transactionManager;
|
||||||
$this->tagDao = $tagDao;
|
$this->tagDao = $tagDao;
|
||||||
|
$this->fileDao = $fileDao;
|
||||||
$this->timeService = $timeService;
|
$this->timeService = $timeService;
|
||||||
$this->fileService = $fileService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFiltered(TagFilter $filter)
|
public function getFiltered(TagFilter $filter)
|
||||||
|
@ -43,7 +43,7 @@ class TagService
|
||||||
$tags[$tag->getName()] = $tag->getUsages();
|
$tags[$tag->getName()] = $tag->getUsages();
|
||||||
}
|
}
|
||||||
$json = json_encode($tags);
|
$json = json_encode($tags);
|
||||||
$this->fileService->save('tags.json', $json);
|
$this->fileDao->save('tags.json', $json);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteUnusedTags()
|
public function deleteUnusedTags()
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Services;
|
namespace Szurubooru\Services;
|
||||||
use Szurubooru\Config;
|
use Szurubooru\Config;
|
||||||
use Szurubooru\Services\FileService;
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||||
|
|
||||||
class ThumbnailService
|
class ThumbnailService
|
||||||
{
|
{
|
||||||
private $config;
|
private $config;
|
||||||
private $fileService;
|
private $fileDao;
|
||||||
private $thumbnailGenerator;
|
private $thumbnailGenerator;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Config $config,
|
Config $config,
|
||||||
FileService $fileService,
|
PublicFileDao $fileDao,
|
||||||
SmartThumbnailGenerator $thumbnailGenerator)
|
SmartThumbnailGenerator $thumbnailGenerator)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->fileService = $fileService;
|
$this->fileDao = $fileDao;
|
||||||
$this->thumbnailGenerator = $thumbnailGenerator;
|
$this->thumbnailGenerator = $thumbnailGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class ThumbnailService
|
||||||
{
|
{
|
||||||
list ($width, $height) = $size;
|
list ($width, $height) = $size;
|
||||||
$target = $this->getThumbnailName($sourceName, $width, $height);
|
$target = $this->getThumbnailName($sourceName, $width, $height);
|
||||||
$this->fileService->delete($target);
|
$this->fileDao->delete($target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class ThumbnailService
|
||||||
{
|
{
|
||||||
$thumbnailName = $this->getThumbnailName($sourceName, $width, $height);
|
$thumbnailName = $this->getThumbnailName($sourceName, $width, $height);
|
||||||
|
|
||||||
if (!$this->fileService->exists($thumbnailName))
|
if (!$this->fileDao->exists($thumbnailName))
|
||||||
$this->generate($sourceName, $width, $height);
|
$this->generate($sourceName, $width, $height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,24 +57,24 @@ class ThumbnailService
|
||||||
|
|
||||||
$thumbnailName = $this->getThumbnailName($sourceName, $width, $height);
|
$thumbnailName = $this->getThumbnailName($sourceName, $width, $height);
|
||||||
|
|
||||||
$source = $this->fileService->load($sourceName);
|
$source = $this->fileDao->load($sourceName);
|
||||||
$result = null;
|
$result = null;
|
||||||
|
|
||||||
if (!$source)
|
if (!$source)
|
||||||
$source = $this->fileService->load($this->getBlankThumbnailName());
|
$source = $this->fileDao->load($this->getBlankThumbnailName());
|
||||||
|
|
||||||
if ($source)
|
if ($source)
|
||||||
$result = $this->thumbnailGenerator->generate($source, $width, $height, $cropStyle);
|
$result = $this->thumbnailGenerator->generate($source, $width, $height, $cropStyle);
|
||||||
|
|
||||||
if (!$result)
|
if (!$result)
|
||||||
$result = $this->fileService->load($this->getBlankThumbnailName());
|
$result = $this->fileDao->load($this->getBlankThumbnailName());
|
||||||
|
|
||||||
$this->fileService->save($thumbnailName, $result);
|
$this->fileDao->save($thumbnailName, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUsedThumbnailSizes()
|
public function getUsedThumbnailSizes()
|
||||||
{
|
{
|
||||||
foreach (glob($this->fileService->getFullPath('thumbnails') . DIRECTORY_SEPARATOR . '*x*') as $fn)
|
foreach (glob($this->fileDao->getFullPath('thumbnails') . DIRECTORY_SEPARATOR . '*x*') as $fn)
|
||||||
{
|
{
|
||||||
if (!is_dir($fn))
|
if (!is_dir($fn))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Szurubooru\FormData\UserEditFormData;
|
||||||
use Szurubooru\Helpers\MimeHelper;
|
use Szurubooru\Helpers\MimeHelper;
|
||||||
use Szurubooru\SearchServices\Filters\UserFilter;
|
use Szurubooru\SearchServices\Filters\UserFilter;
|
||||||
use Szurubooru\Services\EmailService;
|
use Szurubooru\Services\EmailService;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\PasswordService;
|
use Szurubooru\Services\PasswordService;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Services\TimeService;
|
use Szurubooru\Services\TimeService;
|
||||||
|
@ -25,7 +24,6 @@ class UserService
|
||||||
private $userDao;
|
private $userDao;
|
||||||
private $passwordService;
|
private $passwordService;
|
||||||
private $emailService;
|
private $emailService;
|
||||||
private $fileService;
|
|
||||||
private $thumbnailService;
|
private $thumbnailService;
|
||||||
private $timeService;
|
private $timeService;
|
||||||
private $tokenService;
|
private $tokenService;
|
||||||
|
@ -37,7 +35,6 @@ class UserService
|
||||||
UserDao $userDao,
|
UserDao $userDao,
|
||||||
PasswordService $passwordService,
|
PasswordService $passwordService,
|
||||||
EmailService $emailService,
|
EmailService $emailService,
|
||||||
FileService $fileService,
|
|
||||||
ThumbnailService $thumbnailService,
|
ThumbnailService $thumbnailService,
|
||||||
TimeService $timeService,
|
TimeService $timeService,
|
||||||
TokenService $tokenService)
|
TokenService $tokenService)
|
||||||
|
@ -48,7 +45,6 @@ class UserService
|
||||||
$this->userDao = $userDao;
|
$this->userDao = $userDao;
|
||||||
$this->passwordService = $passwordService;
|
$this->passwordService = $passwordService;
|
||||||
$this->emailService = $emailService;
|
$this->emailService = $emailService;
|
||||||
$this->fileService = $fileService;
|
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->thumbnailService = $thumbnailService;
|
||||||
$this->timeService = $timeService;
|
$this->timeService = $timeService;
|
||||||
$this->tokenService = $tokenService;
|
$this->tokenService = $tokenService;
|
||||||
|
|
|
@ -1,26 +1,26 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Upgrades;
|
namespace Szurubooru\Upgrades;
|
||||||
use Szurubooru\Dao\PostDao;
|
use Szurubooru\Dao\PostDao;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\DatabaseConnection;
|
use Szurubooru\DatabaseConnection;
|
||||||
use Szurubooru\Entities\Post;
|
use Szurubooru\Entities\Post;
|
||||||
use Szurubooru\Helpers\MimeHelper;
|
use Szurubooru\Helpers\MimeHelper;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
|
|
||||||
class Upgrade04 implements IUpgrade
|
class Upgrade04 implements IUpgrade
|
||||||
{
|
{
|
||||||
private $postDao;
|
private $postDao;
|
||||||
private $postService;
|
private $postService;
|
||||||
private $fileService;
|
private $fileDao;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PostDao $postDao,
|
PostDao $postDao,
|
||||||
PostService $postService,
|
PostService $postService,
|
||||||
FileService $fileService)
|
PublicFileDao $fileDao)
|
||||||
{
|
{
|
||||||
$this->postDao = $postDao;
|
$this->postDao = $postDao;
|
||||||
$this->postService = $postService;
|
$this->postService = $postService;
|
||||||
$this->fileService = $fileService;
|
$this->fileDao = $fileDao;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function run(DatabaseConnection $databaseConnection)
|
public function run(DatabaseConnection $databaseConnection)
|
||||||
|
@ -32,7 +32,7 @@ class Upgrade04 implements IUpgrade
|
||||||
{
|
{
|
||||||
if ($post->getContentType() !== Post::POST_TYPE_YOUTUBE)
|
if ($post->getContentType() !== Post::POST_TYPE_YOUTUBE)
|
||||||
{
|
{
|
||||||
$fullPath = $this->fileService->getFullPath($post->getContentPath());
|
$fullPath = $this->fileDao->getFullPath($post->getContentPath());
|
||||||
$mime = MimeHelper::getMimeTypeFromFile($fullPath);
|
$mime = MimeHelper::getMimeTypeFromFile($fullPath);
|
||||||
$post->setContentMimeType($mime);
|
$post->setContentMimeType($mime);
|
||||||
$this->postDao->save($post);
|
$this->postDao->save($post);
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests;
|
namespace Szurubooru\Tests;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\DatabaseConnection;
|
use Szurubooru\DatabaseConnection;
|
||||||
use Szurubooru\Entities\Post;
|
use Szurubooru\Entities\Post;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
use Szurubooru\Helpers\HttpHelper;
|
||||||
use Szurubooru\Injector;
|
use Szurubooru\Injector;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\UpgradeService;
|
use Szurubooru\Services\UpgradeService;
|
||||||
use Szurubooru\Tests\AbstractTestCase;
|
use Szurubooru\Tests\AbstractTestCase;
|
||||||
use Szurubooru\Upgrades\UpgradeRepository;
|
use Szurubooru\Upgrades\UpgradeRepository;
|
||||||
|
@ -22,24 +22,15 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
||||||
$config->set('database/user', '');
|
$config->set('database/user', '');
|
||||||
$config->set('database/password', '');
|
$config->set('database/password', '');
|
||||||
|
|
||||||
$fileService = $this->prepareFileService();
|
|
||||||
$this->databaseConnection = new DatabaseConnection($config);
|
$this->databaseConnection = new DatabaseConnection($config);
|
||||||
Injector::set(DatabaseConnection::class, $this->databaseConnection);
|
Injector::set(DatabaseConnection::class, $this->databaseConnection);
|
||||||
Injector::set(FileService::class, $fileService);
|
Injector::set(PublicFileDao::class, $this->preparePublicFileDao());
|
||||||
|
|
||||||
$upgradeRepository = Injector::get(UpgradeRepository::class);
|
$upgradeRepository = Injector::get(UpgradeRepository::class);
|
||||||
$upgradeService = new UpgradeService($config, $this->databaseConnection, $upgradeRepository);
|
$upgradeService = new UpgradeService($config, $this->databaseConnection, $upgradeRepository);
|
||||||
$upgradeService->runUpgradesQuiet();
|
$upgradeService->runUpgradesQuiet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareFileService()
|
|
||||||
{
|
|
||||||
$testDirectory = $this->createTestDirectory();
|
|
||||||
$configMock = $this->mockConfig(null, $testDirectory);
|
|
||||||
$httpHelper = Injector::get(HttpHelper::class);
|
|
||||||
return new FileService($configMock, $httpHelper);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
|
@ -68,4 +59,11 @@ abstract class AbstractDatabaseTestCase extends AbstractTestCase
|
||||||
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
|
$user->setAccessRank(User::ACCESS_RANK_REGULAR_USER);
|
||||||
return $user;
|
return $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function preparePublicFileDao()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$configMock = $this->mockConfig(null, $testDirectory);
|
||||||
|
return new PublicFileDao($configMock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
61
tests/Dao/FileDaoTest.php
Normal file
61
tests/Dao/FileDaoTest.php
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Tests\Services;
|
||||||
|
use Szurubooru\Dao\FileDao;
|
||||||
|
use Szurubooru\Tests\AbstractTestCase;
|
||||||
|
|
||||||
|
final class FileDaoTest extends AbstractTestCase
|
||||||
|
{
|
||||||
|
public function testSaving()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$fileDao->save('dog.txt', 'awesome dog');
|
||||||
|
$expected = 'awesome dog';
|
||||||
|
$actual = file_get_contents($testDirectory . DIRECTORY_SEPARATOR . 'dog.txt');
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSavingSubfolders()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$fileDao->save('friends/dog.txt', 'hot dog');
|
||||||
|
$expected = 'hot dog';
|
||||||
|
$actual = file_get_contents($testDirectory . DIRECTORY_SEPARATOR . 'friends/dog.txt');
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoading()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$fileDao->save('dog.txt', 'awesome dog');
|
||||||
|
$this->assertEquals('awesome dog', $fileDao->load('dog.txt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExists()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$fileDao->save('dog.txt', 'awesome dog');
|
||||||
|
$this->assertTrue($fileDao->exists('dog.txt'));
|
||||||
|
$this->assertFalse($fileDao->exists('fish.txt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLoadingUnexisting()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$this->assertNull($fileDao->load('dog.txt'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDeleting()
|
||||||
|
{
|
||||||
|
$testDirectory = $this->createTestDirectory();
|
||||||
|
$fileDao = new FileDao($testDirectory);
|
||||||
|
$fileDao->save('dog.txt', 'awesome dog');
|
||||||
|
$this->assertTrue(file_exists($testDirectory . DIRECTORY_SEPARATOR . 'dog.txt'));
|
||||||
|
$fileDao->delete('dog.txt');
|
||||||
|
$this->assertFalse(file_exists($testDirectory . DIRECTORY_SEPARATOR . 'dog.txt'));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,17 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests\Dao;
|
namespace Szurubooru\Tests\Dao;
|
||||||
use Szurubooru\Dao\PostDao;
|
use Szurubooru\Dao\PostDao;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Dao\TagDao;
|
use Szurubooru\Dao\TagDao;
|
||||||
use Szurubooru\Dao\UserDao;
|
use Szurubooru\Dao\UserDao;
|
||||||
use Szurubooru\Entities\Tag;
|
use Szurubooru\Entities\Tag;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||||
|
|
||||||
final class PostDaoTest extends AbstractDatabaseTestCase
|
final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
private $fileServiceMock;
|
private $fileDaoMock;
|
||||||
private $thumbnailServiceMock;
|
private $thumbnailServiceMock;
|
||||||
private $tagDao;
|
private $tagDao;
|
||||||
private $userDao;
|
private $userDao;
|
||||||
|
@ -19,16 +19,14 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||||
|
|
||||||
$this->tagDao = new TagDao(
|
$this->tagDao = new TagDao($this->databaseConnection);
|
||||||
$this->databaseConnection,
|
|
||||||
$this->fileServiceMock);
|
|
||||||
|
|
||||||
$this->userDao = new UserDao(
|
$this->userDao = new UserDao(
|
||||||
$this->databaseConnection,
|
$this->databaseConnection,
|
||||||
$this->fileServiceMock,
|
$this->fileDaoMock,
|
||||||
$this->thumbnailServiceMock);
|
$this->thumbnailServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +234,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
|
|
||||||
$post = $postDao->findById($post->getId());
|
$post = $postDao->findById($post->getId());
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('load')
|
->method('load')
|
||||||
->with($post->getContentPath())
|
->with($post->getContentPath())
|
||||||
|
@ -258,7 +256,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
[$post->getContentPath()],
|
[$post->getContentPath()],
|
||||||
[$post->getThumbnailSourceContentPath()]);
|
[$post->getThumbnailSourceContentPath()]);
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->exactly(1))
|
->expects($this->exactly(1))
|
||||||
->method('save')
|
->method('save')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
@ -281,7 +279,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
[$post->getContentPath()],
|
[$post->getContentPath()],
|
||||||
[$post->getThumbnailSourceContentPath()]);
|
[$post->getThumbnailSourceContentPath()]);
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
->method('save')
|
->method('save')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
@ -298,7 +296,7 @@ final class PostDaoTest extends AbstractDatabaseTestCase
|
||||||
$this->databaseConnection,
|
$this->databaseConnection,
|
||||||
$this->tagDao,
|
$this->tagDao,
|
||||||
$this->userDao,
|
$this->userDao,
|
||||||
$this->fileServiceMock,
|
$this->fileDaoMock,
|
||||||
$this->thumbnailServiceMock);
|
$this->thumbnailServiceMock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests\Dao;
|
namespace Szurubooru\Tests\Dao;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Dao\UserDao;
|
use Szurubooru\Dao\UserDao;
|
||||||
use Szurubooru\SearchServices\Filters\UserFilter;
|
use Szurubooru\SearchServices\Filters\UserFilter;
|
||||||
use Szurubooru\SearchServices\Result;
|
use Szurubooru\SearchServices\Result;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||||
|
|
||||||
final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
private $fileServiceMock;
|
private $fileDaoMock;
|
||||||
private $thumbnailServiceMock;
|
private $thumbnailServiceMock;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ final class UserDaoFilterTest extends AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
return new UserDao(
|
return new UserDao(
|
||||||
$this->databaseConnection,
|
$this->databaseConnection,
|
||||||
$this->fileServiceMock,
|
$this->fileDaoMock,
|
||||||
$this->thumbnailServiceMock);
|
$this->thumbnailServiceMock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests\Dao;
|
namespace Szurubooru\Tests\Dao;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Dao\UserDao;
|
use Szurubooru\Dao\UserDao;
|
||||||
use Szurubooru\Entities\User;
|
use Szurubooru\Entities\User;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||||
|
|
||||||
final class UserDaoTest extends AbstractDatabaseTestCase
|
final class UserDaoTest extends AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
private $fileServiceMock;
|
private $fileDaoMock;
|
||||||
private $thumbnailServiceMock;
|
private $thumbnailServiceMock;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ final class UserDaoTest extends AbstractDatabaseTestCase
|
||||||
|
|
||||||
$user = $userDao->findById($user->getId());
|
$user = $userDao->findById($user->getId());
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('load')
|
->method('load')
|
||||||
->with($user->getCustomAvatarSourceContentPath())->willReturn('whatever');
|
->with($user->getCustomAvatarSourceContentPath())->willReturn('whatever');
|
||||||
|
@ -93,7 +93,7 @@ final class UserDaoTest extends AbstractDatabaseTestCase
|
||||||
return $subject == $user->getCustomAvatarSourceContentPath();
|
return $subject == $user->getCustomAvatarSourceContentPath();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('save')
|
->method('save')
|
||||||
->with($this->callback(
|
->with($this->callback(
|
||||||
|
@ -110,7 +110,7 @@ final class UserDaoTest extends AbstractDatabaseTestCase
|
||||||
{
|
{
|
||||||
return new UserDao(
|
return new UserDao(
|
||||||
$this->databaseConnection,
|
$this->databaseConnection,
|
||||||
$this->fileServiceMock,
|
$this->fileDaoMock,
|
||||||
$this->thumbnailServiceMock);
|
$this->thumbnailServiceMock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
<?php
|
|
||||||
namespace Szurubooru\Tests\Services;
|
|
||||||
use Szurubooru\Helpers\HttpHelper;
|
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Tests\AbstractTestCase;
|
|
||||||
|
|
||||||
final class FileServiceTest extends AbstractTestCase
|
|
||||||
{
|
|
||||||
public function testSaving()
|
|
||||||
{
|
|
||||||
$testDirectory = $this->createTestDirectory();
|
|
||||||
$configMock = $this->mockConfig(null, $testDirectory);
|
|
||||||
$httpHelper = $this->mock(HttpHelper::class);
|
|
||||||
$fileService = new FileService($configMock, $httpHelper);
|
|
||||||
$fileService->save('dog.txt', 'awesome dog');
|
|
||||||
$expected = 'awesome dog';
|
|
||||||
$actual = file_get_contents($testDirectory . DIRECTORY_SEPARATOR . 'dog.txt');
|
|
||||||
$this->assertEquals($expected, $actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testDownload()
|
|
||||||
{
|
|
||||||
$configMock = $this->mockConfig();
|
|
||||||
$httpHelper = $this->mock(HttpHelper::class);
|
|
||||||
$fileService = new FileService($configMock, $httpHelper);
|
|
||||||
$content = $fileService->download('http://modernseoul.files.wordpress.com/2012/04/korean-alphabet-chart-modern-seoul.jpg');
|
|
||||||
$this->assertGreaterThan(0, strlen($content));
|
|
||||||
}
|
|
||||||
}
|
|
16
tests/Services/NetworkingServiceTest.php
Normal file
16
tests/Services/NetworkingServiceTest.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Tests\Services;
|
||||||
|
use Szurubooru\Helpers\HttpHelper;
|
||||||
|
use Szurubooru\Services\NetworkingService;
|
||||||
|
use Szurubooru\Tests\AbstractTestCase;
|
||||||
|
|
||||||
|
final class NetworkingServiceTest extends AbstractTestCase
|
||||||
|
{
|
||||||
|
public function testDownload()
|
||||||
|
{
|
||||||
|
$httpHelper = $this->mock(HttpHelper::class);
|
||||||
|
$networkingService = new NetworkingService($httpHelper);
|
||||||
|
$content = $networkingService->download('http://modernseoul.files.wordpress.com/2012/04/korean-alphabet-chart-modern-seoul.jpg');
|
||||||
|
$this->assertGreaterThan(0, strlen($content));
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,9 +8,9 @@ use Szurubooru\Entities\User;
|
||||||
use Szurubooru\FormData\UploadFormData;
|
use Szurubooru\FormData\UploadFormData;
|
||||||
use Szurubooru\Injector;
|
use Szurubooru\Injector;
|
||||||
use Szurubooru\Services\AuthService;
|
use Szurubooru\Services\AuthService;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\HistoryService;
|
use Szurubooru\Services\HistoryService;
|
||||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||||
|
use Szurubooru\Services\NetworkingService;
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
use Szurubooru\Services\TagService;
|
use Szurubooru\Services\TagService;
|
||||||
use Szurubooru\Services\TimeService;
|
use Szurubooru\Services\TimeService;
|
||||||
|
@ -26,7 +26,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
||||||
private $globalParamDaoMock;
|
private $globalParamDaoMock;
|
||||||
private $authServiceMock;
|
private $authServiceMock;
|
||||||
private $timeServiceMock;
|
private $timeServiceMock;
|
||||||
private $fileServiceMock;
|
private $networkingServiceMock;
|
||||||
private $tagService;
|
private $tagService;
|
||||||
private $historyServiceMock;
|
private $historyServiceMock;
|
||||||
private $imageManipulatorMock;
|
private $imageManipulatorMock;
|
||||||
|
@ -41,7 +41,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
||||||
$this->globalParamDaoMock = $this->mock(GlobalParamDao::class);
|
$this->globalParamDaoMock = $this->mock(GlobalParamDao::class);
|
||||||
$this->authServiceMock = $this->mock(AuthService::class);
|
$this->authServiceMock = $this->mock(AuthService::class);
|
||||||
$this->timeServiceMock = $this->mock(TimeService::class);
|
$this->timeServiceMock = $this->mock(TimeService::class);
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
$this->networkingServiceMock = $this->mock(NetworkingService::class);
|
||||||
$this->tagService = Injector::get(TagService::class);
|
$this->tagService = Injector::get(TagService::class);
|
||||||
$this->historyServiceMock = $this->mock(HistoryService::class);
|
$this->historyServiceMock = $this->mock(HistoryService::class);
|
||||||
$this->configMock->set('database/maxPostSize', 1000000);
|
$this->configMock->set('database/maxPostSize', 1000000);
|
||||||
|
@ -207,7 +207,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
||||||
$this->globalParamDaoMock,
|
$this->globalParamDaoMock,
|
||||||
$this->authServiceMock,
|
$this->authServiceMock,
|
||||||
$this->timeServiceMock,
|
$this->timeServiceMock,
|
||||||
$this->fileServiceMock,
|
$this->networkingServiceMock,
|
||||||
$this->tagService,
|
$this->tagService,
|
||||||
$this->historyServiceMock,
|
$this->historyServiceMock,
|
||||||
$this->imageManipulatorMock);
|
$this->imageManipulatorMock);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests\Services;
|
namespace Szurubooru\Tests\Services;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Entities\Tag;
|
use Szurubooru\Entities\Tag;
|
||||||
use Szurubooru\Injector;
|
use Szurubooru\Injector;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\TagService;
|
use Szurubooru\Services\TagService;
|
||||||
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
use Szurubooru\Tests\AbstractDatabaseTestCase;
|
||||||
|
|
||||||
|
@ -74,11 +74,11 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
||||||
$tag1 = new Tag();
|
$tag1 = new Tag();
|
||||||
$tag1->setName('test');
|
$tag1->setName('test');
|
||||||
$tag1->setCreationTime(date('c'));
|
$tag1->setCreationTime(date('c'));
|
||||||
$fileService = $this->getFileService();
|
$fileDao = $this->getPublicFileDao();
|
||||||
$tagService = $this->getTagService();
|
$tagService = $this->getTagService();
|
||||||
$tagService->createTags([$tag1]);
|
$tagService->createTags([$tag1]);
|
||||||
$tagService->exportJson();
|
$tagService->exportJson();
|
||||||
$this->assertEquals('{"test":0}', $fileService->load('tags.json'));
|
$this->assertEquals('{"test":0}', $fileDao->load('tags.json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testExportMultiple()
|
public function testExportMultiple()
|
||||||
|
@ -89,16 +89,16 @@ final class TagServiceTest extends AbstractDatabaseTestCase
|
||||||
$tag2 = new Tag();
|
$tag2 = new Tag();
|
||||||
$tag2->setName('test2');
|
$tag2->setName('test2');
|
||||||
$tag2->setCreationTime(date('c'));
|
$tag2->setCreationTime(date('c'));
|
||||||
$fileService = $this->getFileService();
|
$fileDao = $this->getPublicFileDao();
|
||||||
$tagService = $this->getTagService();
|
$tagService = $this->getTagService();
|
||||||
$tagService->createTags([$tag1, $tag2]);
|
$tagService->createTags([$tag1, $tag2]);
|
||||||
$tagService->exportJson();
|
$tagService->exportJson();
|
||||||
$this->assertEquals('{"test1":0,"test2":0}', $fileService->load('tags.json'));
|
$this->assertEquals('{"test1":0,"test2":0}', $fileDao->load('tags.json'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getFileService()
|
private function getPublicFileDao()
|
||||||
{
|
{
|
||||||
return Injector::get(FileService::class);
|
return Injector::get(PublicFileDao::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getTagService()
|
private function getTagService()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Szurubooru\Tests\Services;
|
namespace Szurubooru\Tests\Services;
|
||||||
use Szurubooru\Services\FileService;
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
|
@ -9,7 +9,7 @@ use Szurubooru\Tests\AbstractTestCase;
|
||||||
final class ThumbnailServiceTest extends AbstractTestCase
|
final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
private $configMock;
|
private $configMock;
|
||||||
private $fileServiceMock;
|
private $fileDaoMock;
|
||||||
private $thumbnailGeneratorMock;
|
private $thumbnailGeneratorMock;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
|
@ -17,7 +17,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->configMock = $this->mockConfig();
|
$this->configMock = $this->mockConfig();
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||||
$this->thumbnailGeneratorMock = $this->mock(SmartThumbnailGenerator::class);
|
$this->thumbnailGeneratorMock = $this->mock(SmartThumbnailGenerator::class);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
mkdir($tempDirectory . DIRECTORY_SEPARATOR . 'something unexpected');
|
mkdir($tempDirectory . DIRECTORY_SEPARATOR . 'something unexpected');
|
||||||
touch($tempDirectory . DIRECTORY_SEPARATOR . '15x15');
|
touch($tempDirectory . DIRECTORY_SEPARATOR . '15x15');
|
||||||
|
|
||||||
$this->fileServiceMock->expects($this->once())->method('getFullPath')->with('thumbnails')->willReturn($tempDirectory);
|
$this->fileDaoMock->expects($this->once())->method('getFullPath')->with('thumbnails')->willReturn($tempDirectory);
|
||||||
$thumbnailService = $this->getThumbnailService();
|
$thumbnailService = $this->getThumbnailService();
|
||||||
|
|
||||||
$expected = [[5, 5], [10, 10]];
|
$expected = [[5, 5], [10, 10]];
|
||||||
|
@ -50,8 +50,8 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
touch($tempDirectory . DIRECTORY_SEPARATOR . '5x5' . DIRECTORY_SEPARATOR . 'keep');
|
touch($tempDirectory . DIRECTORY_SEPARATOR . '5x5' . DIRECTORY_SEPARATOR . 'keep');
|
||||||
touch($tempDirectory . DIRECTORY_SEPARATOR . '10x10' . DIRECTORY_SEPARATOR . 'remove');
|
touch($tempDirectory . DIRECTORY_SEPARATOR . '10x10' . DIRECTORY_SEPARATOR . 'remove');
|
||||||
|
|
||||||
$this->fileServiceMock->expects($this->once())->method('getFullPath')->with('thumbnails')->willReturn($tempDirectory);
|
$this->fileDaoMock->expects($this->once())->method('getFullPath')->with('thumbnails')->willReturn($tempDirectory);
|
||||||
$this->fileServiceMock->expects($this->exactly(2))->method('delete')->withConsecutive(
|
$this->fileDaoMock->expects($this->exactly(2))->method('delete')->withConsecutive(
|
||||||
['thumbnails' . DIRECTORY_SEPARATOR . '10x10' . DIRECTORY_SEPARATOR . 'remove'],
|
['thumbnails' . DIRECTORY_SEPARATOR . '10x10' . DIRECTORY_SEPARATOR . 'remove'],
|
||||||
['thumbnails' . DIRECTORY_SEPARATOR . '5x5' . DIRECTORY_SEPARATOR . 'remove']);
|
['thumbnails' . DIRECTORY_SEPARATOR . '5x5' . DIRECTORY_SEPARATOR . 'remove']);
|
||||||
$thumbnailService = $this->getThumbnailService();
|
$thumbnailService = $this->getThumbnailService();
|
||||||
|
@ -63,7 +63,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
$this->configMock->set('misc/thumbnailCropStyle', 'outside');
|
$this->configMock->set('misc/thumbnailCropStyle', 'outside');
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->exactly(2))
|
->expects($this->exactly(2))
|
||||||
->method('load')
|
->method('load')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
@ -84,7 +84,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
IThumbnailGenerator::CROP_OUTSIDE)
|
IThumbnailGenerator::CROP_OUTSIDE)
|
||||||
->willReturn('generated thumbnail');
|
->willReturn('generated thumbnail');
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('save')
|
->method('save')
|
||||||
->with('thumbnails' . DIRECTORY_SEPARATOR . '100x100' . DIRECTORY_SEPARATOR . 'nope', 'generated thumbnail');
|
->with('thumbnails' . DIRECTORY_SEPARATOR . '100x100' . DIRECTORY_SEPARATOR . 'nope', 'generated thumbnail');
|
||||||
|
@ -97,7 +97,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
$this->configMock->set('misc/thumbnailCropStyle', 'outside');
|
$this->configMock->set('misc/thumbnailCropStyle', 'outside');
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->exactly(3))
|
->expects($this->exactly(3))
|
||||||
->method('load')
|
->method('load')
|
||||||
->withConsecutive(
|
->withConsecutive(
|
||||||
|
@ -120,7 +120,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
IThumbnailGenerator::CROP_OUTSIDE)
|
IThumbnailGenerator::CROP_OUTSIDE)
|
||||||
->willReturn(null);
|
->willReturn(null);
|
||||||
|
|
||||||
$this->fileServiceMock
|
$this->fileDaoMock
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('save')
|
->method('save')
|
||||||
->with('thumbnails' . DIRECTORY_SEPARATOR . '100x100' . DIRECTORY_SEPARATOR . 'nope', 'content of blank thumbnail (2)');
|
->with('thumbnails' . DIRECTORY_SEPARATOR . '100x100' . DIRECTORY_SEPARATOR . 'nope', 'content of blank thumbnail (2)');
|
||||||
|
@ -134,7 +134,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
||||||
{
|
{
|
||||||
return new ThumbnailService(
|
return new ThumbnailService(
|
||||||
$this->configMock,
|
$this->configMock,
|
||||||
$this->fileServiceMock,
|
$this->fileDaoMock,
|
||||||
$this->thumbnailGeneratorMock);
|
$this->thumbnailGeneratorMock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ use Szurubooru\Entities\User;
|
||||||
use Szurubooru\FormData\RegistrationFormData;
|
use Szurubooru\FormData\RegistrationFormData;
|
||||||
use Szurubooru\FormData\UserEditFormData;
|
use Szurubooru\FormData\UserEditFormData;
|
||||||
use Szurubooru\Services\EmailService;
|
use Szurubooru\Services\EmailService;
|
||||||
use Szurubooru\Services\FileService;
|
|
||||||
use Szurubooru\Services\PasswordService;
|
use Szurubooru\Services\PasswordService;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\ThumbnailService;
|
||||||
use Szurubooru\Services\TimeService;
|
use Szurubooru\Services\TimeService;
|
||||||
|
@ -23,7 +22,6 @@ final class UserServiceTest extends AbstractTestCase
|
||||||
private $userDaoMock;
|
private $userDaoMock;
|
||||||
private $passwordServiceMock;
|
private $passwordServiceMock;
|
||||||
private $emailServiceMock;
|
private $emailServiceMock;
|
||||||
private $fileServiceMock;
|
|
||||||
private $thumbnailServiceMock;
|
private $thumbnailServiceMock;
|
||||||
private $timeServiceMock;
|
private $timeServiceMock;
|
||||||
private $tokenServiceMock;
|
private $tokenServiceMock;
|
||||||
|
@ -37,7 +35,6 @@ final class UserServiceTest extends AbstractTestCase
|
||||||
$this->userDaoMock = $this->mock(UserDao::class);
|
$this->userDaoMock = $this->mock(UserDao::class);
|
||||||
$this->passwordServiceMock = $this->mock(PasswordService::class);
|
$this->passwordServiceMock = $this->mock(PasswordService::class);
|
||||||
$this->emailServiceMock = $this->mock(EmailService::class);
|
$this->emailServiceMock = $this->mock(EmailService::class);
|
||||||
$this->fileServiceMock = $this->mock(FileService::class);
|
|
||||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||||
$this->timeServiceMock = $this->mock(TimeService::class);
|
$this->timeServiceMock = $this->mock(TimeService::class);
|
||||||
$this->tokenServiceMock = $this->mock(TokenService::class);
|
$this->tokenServiceMock = $this->mock(TokenService::class);
|
||||||
|
@ -290,7 +287,6 @@ final class UserServiceTest extends AbstractTestCase
|
||||||
$this->userDaoMock,
|
$this->userDaoMock,
|
||||||
$this->passwordServiceMock,
|
$this->passwordServiceMock,
|
||||||
$this->emailServiceMock,
|
$this->emailServiceMock,
|
||||||
$this->fileServiceMock,
|
|
||||||
$this->thumbnailServiceMock,
|
$this->thumbnailServiceMock,
|
||||||
$this->timeServiceMock,
|
$this->timeServiceMock,
|
||||||
$this->tokenServiceMock);
|
$this->tokenServiceMock);
|
||||||
|
|
Loading…
Reference in a new issue