Loading Core/Pro/Delegates/SetupRoutingDelegate.php +3 −2 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,7 @@ class SetupRoutingDelegate $userGuid = $settings->getUserGuid(); $userGuid = $settings->getUserGuid(); if (!$settings->getDomain()) { if (!$settings->getDomain()) { $settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_prefix'] ?? 'minds.com')); $settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_suffix'] ?? 'minds.com')); } } $success = $this->edgeRouter $success = $this->edgeRouter Loading @@ -46,7 +46,8 @@ class SetupRoutingDelegate ->putEndpoint($settings); ->putEndpoint($settings); if (!$success) { if (!$success) { // TODO: Issue a warning based on $success error_log("[MindsPro] Cannot setup endpoint."); // TODO: Implement user-facing warning } } } } } } Core/Pro/Domain.php +2 −3 Original line number Original line Diff line number Diff line Loading @@ -44,15 +44,14 @@ class Domain return null; return null; } } $settings = $this->repository->getList([ return $this->repository->getList([ 'domain' => $domain, 'domain' => $domain, ])->first(); ])->first(); return $settings; } } /** /** * @param Settings $settings * @param Settings $settings * @param User|null $owner * @return string * @return string * @throws Exception * @throws Exception */ */ Loading Spec/Core/Pro/Channel/ManagerSpec.php 0 → 100644 +127 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Channel; use Minds\Common\Repository\Response; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Feeds\Top\Manager as TopManager; use Minds\Core\Pro\Channel\Manager; use Minds\Core\Pro\Repository; use Minds\Core\Pro\Settings; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class ManagerSpec extends ObjectBehavior { /** @var Repository */ protected $repository; /** @var TopManager */ protected $top; /** @var abstractCacher */ protected $cache; public function let( Repository $repository, TopManager $top, abstractCacher $cache ) { $this->repository = $repository; $this->top = $top; $this->cache = $cache; $this->beConstructedWith($repository, $top, $cache); } public function it_is_initializable() { $this->shouldHaveType(Manager::class); } public function it_should_get_all_categories_content( User $user, Response $getListResponse, Response $topGetListResponse1, Response $topGetListResponse2Top, Response $topGetListResponse2Latest, Settings $settings ) { $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $this->repository->getList([ 'user_guid' => 1000 ]) ->shouldBeCalled() ->willReturn($getListResponse); $getListResponse->first() ->shouldBeCalled() ->willReturn($settings); $this->cache->get(Argument::containingString('::1000')) ->shouldBeCalled() ->willReturn(null); $settings->getTagList() ->shouldBeCalled() ->willReturn([ ['tag' => 'test1', 'label' => 'Test 1'], ['tag' => 'test2', 'label' => 'Test 2'], ]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test1']; })) ->shouldBeCalled() ->willReturn($topGetListResponse1); $topGetListResponse1->toArray() ->shouldBeCalled() ->willReturn([5000, 5001, 5002]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test2']; })) ->shouldBeCalled() ->willReturn($topGetListResponse2Top); $topGetListResponse2Top->toArray() ->shouldBeCalled() ->willReturn([]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'latest' && $opts['hashtags'] === ['test2']; })) ->shouldBeCalled() ->willReturn($topGetListResponse2Latest); $topGetListResponse2Latest->toArray() ->shouldBeCalled() ->willReturn([5100, 5101, 5102]); $output = [ [ 'tag' => ['tag' => 'test1', 'label' => 'Test 1'], 'content' => [5000, 5001, 5002], ], [ 'tag' => ['tag' => 'test2', 'label' => 'Test 2'], 'content' => [5100, 5101, 5102], ], ]; $this->cache->set(Argument::containingString('::1000'), $output, Argument::type('int')) ->shouldBeCalled() ->willReturn(true); $this ->setUser($user) ->getAllCategoriesContent() ->shouldReturn($output); } } Spec/Core/Pro/Delegates/HydrateSettingsDelegateSpec.php 0 → 100644 +117 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Delegates; use Exception; use Minds\Core\Config; use Minds\Core\EntitiesBuilder; use Minds\Core\Pro\Delegates\HydrateSettingsDelegate; use Minds\Core\Pro\Settings; use Minds\Entities\Activity; use Minds\Entities\Object\Carousel; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class HydrateSettingsDelegateSpec extends ObjectBehavior { /** @var EntitiesBuilder */ protected $entitiesBuilder; /** @var Config */ protected $config; public function let( EntitiesBuilder $entitiesBuilder, Config $config ) { $this->entitiesBuilder = $entitiesBuilder; $this->config = $config; $this->beConstructedWith($entitiesBuilder, $config); } public function it_is_initializable() { $this->shouldHaveType(HydrateSettingsDelegate::class); } public function it_should_hydrate_settings_on_get( User $user, Settings $settings, Carousel $carousel, Activity $activity1, Activity $activity2 ) { $settings->getLogoGuid() ->shouldBeCalled() ->willReturn(7500); $this->config->get('cdn_url') ->shouldBeCalled() ->willReturn('http://phpspec.test/'); $settings->setLogoImage('http://phpspec.test/fs/v1/thumbnail/7500/master') ->shouldBeCalled() ->willReturn($settings); $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $this->entitiesBuilder->get([ 'subtype' => 'carousel', 'owner_guid' => '1000' ]) ->shouldBeCalled() ->willReturn([ $carousel ]); $carousel->get('guid') ->shouldBeCalled() ->willReturn(9500); $carousel->get('last_updated') ->shouldBeCalled() ->willReturn(9999999); $settings->setBackgroundImage('http://phpspec.test/fs/v1/banners/9500/fat/9999999') ->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); $this ->shouldNotThrow(Exception::class) ->duringOnGet($user, $settings); } } Spec/Core/Pro/Delegates/InitializeSettingsDelegateSpec.php 0 → 100644 +81 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Delegates; use Exception; use Minds\Common\Repository\Response; use Minds\Core\Pro\Delegates\InitializeSettingsDelegate; use Minds\Core\Pro\Delegates\SetupRoutingDelegate; use Minds\Core\Pro\Repository; use Minds\Core\Pro\Settings; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class InitializeSettingsDelegateSpec extends ObjectBehavior { /** @var Repository */ protected $repository; /** @var SetupRoutingDelegate */ protected $setupRoutingDelegate; public function let( Repository $repository, SetupRoutingDelegate $setupRoutingDelegate ) { $this->repository = $repository; $this->setupRoutingDelegate = $setupRoutingDelegate; $this->beConstructedWith($repository, $setupRoutingDelegate); } public function it_is_initializable() { $this->shouldHaveType(InitializeSettingsDelegate::class); } public function it_should_initialize_settings_on_enable( User $user, Response $getListResponse, Settings $settings ) { $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $user->get('name') ->shouldBeCalled() ->willReturn('PHPSpec'); $this->repository->getList([ 'user_guid' => 1000 ]) ->shouldBeCalled() ->willReturn($getListResponse); $getListResponse->first() ->shouldBeCalled() ->willReturn($settings); $settings->getTitle() ->shouldBeCalled() ->willReturn(''); $settings->setTitle('PHPSpec') ->shouldBeCalled() ->willReturn($settings); $this->setupRoutingDelegate->onUpdate($settings) ->shouldBeCalled() ->willReturn(null); $this->repository->add($settings) ->shouldBeCalled() ->willReturn(true); $this ->shouldNotThrow(Exception::class) ->duringOnEnable($user); } } Loading
Core/Pro/Delegates/SetupRoutingDelegate.php +3 −2 Original line number Original line Diff line number Diff line Loading @@ -38,7 +38,7 @@ class SetupRoutingDelegate $userGuid = $settings->getUserGuid(); $userGuid = $settings->getUserGuid(); if (!$settings->getDomain()) { if (!$settings->getDomain()) { $settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_prefix'] ?? 'minds.com')); $settings->setDomain(sprintf("pro-%s.%s", $userGuid, $this->config->get('pro')['subdomain_suffix'] ?? 'minds.com')); } } $success = $this->edgeRouter $success = $this->edgeRouter Loading @@ -46,7 +46,8 @@ class SetupRoutingDelegate ->putEndpoint($settings); ->putEndpoint($settings); if (!$success) { if (!$success) { // TODO: Issue a warning based on $success error_log("[MindsPro] Cannot setup endpoint."); // TODO: Implement user-facing warning } } } } } }
Core/Pro/Domain.php +2 −3 Original line number Original line Diff line number Diff line Loading @@ -44,15 +44,14 @@ class Domain return null; return null; } } $settings = $this->repository->getList([ return $this->repository->getList([ 'domain' => $domain, 'domain' => $domain, ])->first(); ])->first(); return $settings; } } /** /** * @param Settings $settings * @param Settings $settings * @param User|null $owner * @return string * @return string * @throws Exception * @throws Exception */ */ Loading
Spec/Core/Pro/Channel/ManagerSpec.php 0 → 100644 +127 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Channel; use Minds\Common\Repository\Response; use Minds\Core\Data\cache\abstractCacher; use Minds\Core\Feeds\Top\Manager as TopManager; use Minds\Core\Pro\Channel\Manager; use Minds\Core\Pro\Repository; use Minds\Core\Pro\Settings; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class ManagerSpec extends ObjectBehavior { /** @var Repository */ protected $repository; /** @var TopManager */ protected $top; /** @var abstractCacher */ protected $cache; public function let( Repository $repository, TopManager $top, abstractCacher $cache ) { $this->repository = $repository; $this->top = $top; $this->cache = $cache; $this->beConstructedWith($repository, $top, $cache); } public function it_is_initializable() { $this->shouldHaveType(Manager::class); } public function it_should_get_all_categories_content( User $user, Response $getListResponse, Response $topGetListResponse1, Response $topGetListResponse2Top, Response $topGetListResponse2Latest, Settings $settings ) { $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $this->repository->getList([ 'user_guid' => 1000 ]) ->shouldBeCalled() ->willReturn($getListResponse); $getListResponse->first() ->shouldBeCalled() ->willReturn($settings); $this->cache->get(Argument::containingString('::1000')) ->shouldBeCalled() ->willReturn(null); $settings->getTagList() ->shouldBeCalled() ->willReturn([ ['tag' => 'test1', 'label' => 'Test 1'], ['tag' => 'test2', 'label' => 'Test 2'], ]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test1']; })) ->shouldBeCalled() ->willReturn($topGetListResponse1); $topGetListResponse1->toArray() ->shouldBeCalled() ->willReturn([5000, 5001, 5002]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'top' && $opts['hashtags'] === ['test2']; })) ->shouldBeCalled() ->willReturn($topGetListResponse2Top); $topGetListResponse2Top->toArray() ->shouldBeCalled() ->willReturn([]); $this->top->getList(Argument::that(function (array $opts) { return $opts['algorithm'] === 'latest' && $opts['hashtags'] === ['test2']; })) ->shouldBeCalled() ->willReturn($topGetListResponse2Latest); $topGetListResponse2Latest->toArray() ->shouldBeCalled() ->willReturn([5100, 5101, 5102]); $output = [ [ 'tag' => ['tag' => 'test1', 'label' => 'Test 1'], 'content' => [5000, 5001, 5002], ], [ 'tag' => ['tag' => 'test2', 'label' => 'Test 2'], 'content' => [5100, 5101, 5102], ], ]; $this->cache->set(Argument::containingString('::1000'), $output, Argument::type('int')) ->shouldBeCalled() ->willReturn(true); $this ->setUser($user) ->getAllCategoriesContent() ->shouldReturn($output); } }
Spec/Core/Pro/Delegates/HydrateSettingsDelegateSpec.php 0 → 100644 +117 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Delegates; use Exception; use Minds\Core\Config; use Minds\Core\EntitiesBuilder; use Minds\Core\Pro\Delegates\HydrateSettingsDelegate; use Minds\Core\Pro\Settings; use Minds\Entities\Activity; use Minds\Entities\Object\Carousel; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class HydrateSettingsDelegateSpec extends ObjectBehavior { /** @var EntitiesBuilder */ protected $entitiesBuilder; /** @var Config */ protected $config; public function let( EntitiesBuilder $entitiesBuilder, Config $config ) { $this->entitiesBuilder = $entitiesBuilder; $this->config = $config; $this->beConstructedWith($entitiesBuilder, $config); } public function it_is_initializable() { $this->shouldHaveType(HydrateSettingsDelegate::class); } public function it_should_hydrate_settings_on_get( User $user, Settings $settings, Carousel $carousel, Activity $activity1, Activity $activity2 ) { $settings->getLogoGuid() ->shouldBeCalled() ->willReturn(7500); $this->config->get('cdn_url') ->shouldBeCalled() ->willReturn('http://phpspec.test/'); $settings->setLogoImage('http://phpspec.test/fs/v1/thumbnail/7500/master') ->shouldBeCalled() ->willReturn($settings); $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $this->entitiesBuilder->get([ 'subtype' => 'carousel', 'owner_guid' => '1000' ]) ->shouldBeCalled() ->willReturn([ $carousel ]); $carousel->get('guid') ->shouldBeCalled() ->willReturn(9500); $carousel->get('last_updated') ->shouldBeCalled() ->willReturn(9999999); $settings->setBackgroundImage('http://phpspec.test/fs/v1/banners/9500/fat/9999999') ->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); $this ->shouldNotThrow(Exception::class) ->duringOnGet($user, $settings); } }
Spec/Core/Pro/Delegates/InitializeSettingsDelegateSpec.php 0 → 100644 +81 −0 Original line number Original line Diff line number Diff line <?php namespace Spec\Minds\Core\Pro\Delegates; use Exception; use Minds\Common\Repository\Response; use Minds\Core\Pro\Delegates\InitializeSettingsDelegate; use Minds\Core\Pro\Delegates\SetupRoutingDelegate; use Minds\Core\Pro\Repository; use Minds\Core\Pro\Settings; use Minds\Entities\User; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class InitializeSettingsDelegateSpec extends ObjectBehavior { /** @var Repository */ protected $repository; /** @var SetupRoutingDelegate */ protected $setupRoutingDelegate; public function let( Repository $repository, SetupRoutingDelegate $setupRoutingDelegate ) { $this->repository = $repository; $this->setupRoutingDelegate = $setupRoutingDelegate; $this->beConstructedWith($repository, $setupRoutingDelegate); } public function it_is_initializable() { $this->shouldHaveType(InitializeSettingsDelegate::class); } public function it_should_initialize_settings_on_enable( User $user, Response $getListResponse, Settings $settings ) { $user->get('guid') ->shouldBeCalled() ->willReturn(1000); $user->get('name') ->shouldBeCalled() ->willReturn('PHPSpec'); $this->repository->getList([ 'user_guid' => 1000 ]) ->shouldBeCalled() ->willReturn($getListResponse); $getListResponse->first() ->shouldBeCalled() ->willReturn($settings); $settings->getTitle() ->shouldBeCalled() ->willReturn(''); $settings->setTitle('PHPSpec') ->shouldBeCalled() ->willReturn($settings); $this->setupRoutingDelegate->onUpdate($settings) ->shouldBeCalled() ->willReturn(null); $this->repository->add($settings) ->shouldBeCalled() ->willReturn(true); $this ->shouldNotThrow(Exception::class) ->duringOnEnable($user); } }