Commit 551b6e23 authored by Emiliano Balbuena's avatar Emiliano Balbuena

(test): Pro and Pro\Asset spec tests

1 merge request!375Pro logo and background upload
Pipeline #89600159 failed with stages
in 6 minutes and 19 seconds
......@@ -69,10 +69,11 @@ class Manager
/**
* @param UploadedFile $file
* @param Asset|null $asset
* @return bool
* @throws Exception
*/
public function set(UploadedFile $file)
public function set(UploadedFile $file, Asset $asset = null)
{
if (!$this->user) {
throw new Exception('Invalid user');
......@@ -90,7 +91,10 @@ class Manager
// Setup asset
$asset = new Asset();
if (!$asset) {
$asset = new Asset();
}
$asset
->setType($this->type)
->setUserGuid($this->user->guid);
......
<?php
namespace Spec\Minds\Core\Pro\Assets;
use Exception;
use Minds\Core\Pro\Assets\Asset;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class AssetSpec extends ObjectBehavior
{
public function it_is_initializable()
{
$this->shouldHaveType(Asset::class);
}
public function it_should_set_type()
{
$this
->setType(Asset::TYPES[0])
->getType()
->shouldReturn(Asset::TYPES[0]);
}
public function it_should_throw_if_type_is_invalid()
{
$this
->shouldThrow(Exception::class)
->duringSetType('-!__!@_#)!@#_)!@#@!_#)INVALID');
}
}
<?php
namespace Spec\Minds\Core\Pro\Assets;
use ElggFile;
use Minds\Core\Media\Imagick\Manager as ImageManager;
use Minds\Core\Pro\Assets\Asset;
use Minds\Core\Pro\Assets\Manager;
use Minds\Entities\User;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Psr\Http\Message\StreamInterface;
use Zend\Diactoros\UploadedFile;
class ManagerSpec extends ObjectBehavior
{
/** @var ImageManager */
protected $imageManager;
public function let(
ImageManager $imageManager
) {
$this->imageManager = $imageManager;
$this->beConstructedWith($imageManager);
}
public function it_is_initializable()
{
$this->shouldHaveType(Manager::class);
}
public function it_should_set_logo(
User $user,
UploadedFile $file,
StreamInterface $fileStream,
Asset $asset,
ElggFile $assetFile
) {
$file->getStream()
->shouldBeCalled()
->willReturn($fileStream);
$fileStream->getContents()
->shouldBeCalled()
->willReturn('~image file~');
$file->getClientFilename()
->shouldBeCalled()
->willReturn('asset.img');
$this->imageManager->setImageFromBlob('~image file~', 'asset.img')
->shouldBeCalled()
->willReturn();
$asset->setType('logo')
->shouldBeCalled()
->willReturn($asset);
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
$asset->setUserGuid(1000)
->shouldBeCalled()
->willReturn($asset);
$this->imageManager->resize(Argument::cetera())
->shouldBeCalled()
->willReturn($this->imageManager);
$this->imageManager->getPng()
->shouldBeCalled()
->willReturn('~png file~');
$asset->getFile()
->shouldBeCalled()
->willReturn($assetFile);
$assetFile->open('write')
->shouldBeCalled()
->willReturn(true);
$assetFile->write('~png file~')
->shouldBeCalled()
->willReturn(true);
$assetFile->close()
->shouldBeCalled()
->willReturn(true);
$this
->setType('logo')
->setUser($user)
->setActor($user)
->set($file, $asset)
->shouldReturn(true);
}
public function it_should_set_background(
User $user,
UploadedFile $file,
StreamInterface $fileStream,
Asset $asset,
ElggFile $assetFile
) {
$file->getStream()
->shouldBeCalled()
->willReturn($fileStream);
$fileStream->getContents()
->shouldBeCalled()
->willReturn('~image file~');
$file->getClientFilename()
->shouldBeCalled()
->willReturn('asset.img');
$this->imageManager->setImageFromBlob('~image file~', 'asset.img')
->shouldBeCalled()
->willReturn();
$asset->setType('background')
->shouldBeCalled()
->willReturn($asset);
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
$asset->setUserGuid(1000)
->shouldBeCalled()
->willReturn($asset);
$this->imageManager->autorotate()
->shouldBeCalled()
->willReturn($this->imageManager);
$this->imageManager->resize(Argument::cetera())
->shouldBeCalled()
->willReturn($this->imageManager);
$this->imageManager->getJpeg(Argument::type('int'))
->shouldBeCalled()
->willReturn('~jpg file~');
$asset->getFile()
->shouldBeCalled()
->willReturn($assetFile);
$assetFile->open('write')
->shouldBeCalled()
->willReturn(true);
$assetFile->write('~jpg file~')
->shouldBeCalled()
->willReturn(true);
$assetFile->close()
->shouldBeCalled()
->willReturn(true);
$this
->setType('background')
->setUser($user)
->setActor($user)
->set($file, $asset)
->shouldReturn(true);
}
}
......@@ -43,18 +43,105 @@ class HydrateSettingsDelegateSpec extends ObjectBehavior
Activity $activity1,
Activity $activity2
) {
$settings->getLogoGuid()
$this->config->get('cdn_url')
->shouldBeCalled()
->willReturn('http://phpspec.test/');
$settings->hasCustomLogo()
->shouldBeCalled()
->willReturn(true);
$settings->getUserGuid()
->shouldBeCalled()
->willReturn(7500);
->willReturn(1000);
$settings->getTimeUpdated()
->shouldBeCalled()
->willReturn(999999);
$settings->setLogoImage('http://phpspec.test/fs/v1/pro/1000/logo/999999')
->shouldBeCalled()
->willReturn($settings);
$settings->hasCustomBackground()
->shouldBeCalled()
->willReturn(true);
$settings->setBackgroundImage('http://phpspec.test/fs/v1/pro/1000/background/999999')
->shouldBeCalled()
->willReturn($settings);
$user->getPinnedPosts()
->shouldBeCalled()
->willReturn([5000, 5001]);
$this->entitiesBuilder->get(['guids' => ['5000', '5001']])
->shouldBeCalled()
->willReturn([ $activity1, $activity2 ]);
$activity1->get('time_created')
->shouldBeCalled()
->willReturn(10000010);
$activity1->get('entity_guid')
->shouldBeCalled()
->willReturn(7400);
$activity2->get('time_created')
->shouldBeCalled()
->willReturn(10000090);
$activity2->get('guid')
->shouldBeCalled()
->willReturn(5001);
$activity2->get('entity_guid')
->shouldBeCalled()
->willReturn(null);
$settings->setFeaturedContent([5001, 7400])
->shouldBeCalled()
->willReturn($settings);
$user->isProPublished()
->willReturn(false);
$settings->setPublished(false)
->shouldBeCalled();
$this
->shouldNotThrow(Exception::class)
->duringOnGet($user, $settings);
}
public function it_should_hydrate_settings_with_default_assets_on_get(
User $user,
Settings $settings,
Carousel $carousel,
Activity $activity1,
Activity $activity2
) {
$this->config->get('cdn_url')
->shouldBeCalled()
->willReturn('http://phpspec.test/');
$settings->setLogoImage('http://phpspec.test/fs/v1/thumbnail/7500/master')
$settings->hasCustomLogo()
->shouldBeCalled()
->willReturn(false);
$user->getIconURL('large')
->shouldBeCalled()
->willReturn('http://phpspec.test/fs/v1/avatar/1000');
$settings->setLogoImage('http://phpspec.test/fs/v1/avatar/1000')
->shouldBeCalled()
->willReturn($settings);
$settings->hasCustomBackground()
->shouldBeCalled()
->willReturn(false);
$user->get('guid')
->shouldBeCalled()
->willReturn(1000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment