Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • omadrid/engine
  • javanick/engine
  • minds/engine
  • joe59/engine
  • eiennohi/engine
  • edgebal/engine
  • msantang78/engine
  • maruthi-adithya/engine
  • duyquoc/engine
  • benhayward.ben/engine
  • rlperez/engine
  • priestd09/engine
  • dknunn/engine
  • ascenderking/engine
  • catastrop/engine
  • jim-toth/engine
  • project_connection/engine
  • manishoo/engine
  • murbo98/engine
  • namesty/engine
  • Moikapy/engine
  • bedriguler/engine
  • CodingNagger/engine
  • jun784/engine
  • alexgleason/engine
  • gigasim97/engine
  • auxchar/engine
  • pestixaba/engine
  • m994/engine
  • webprodev/minds_engine
  • fabiolalombardim/engine
  • zackwy/engine
  • linleyj7/engine
  • fiatjaf/minds-engine
  • ppitestsblishaokai/engine
  • VARUN-KUSH/engine
  • brainr386/engine
37 results
Show changes
Commits on Source (2)
<?php
/**
* CampaignUrnDelegate
* @author edgebal
*/
namespace Minds\Core\Boost\Campaigns\Delegates;
......@@ -20,9 +16,8 @@ class CampaignUrnDelegate
* CampaignUrnDelegate constructor.
* @param GuidBuilder $guid
*/
public function __construct(
$guid = null
) {
public function __construct(?GuidBuilder $guid = null)
{
$this->guid = $guid ?: Di::_()->get('Guid');
}
......@@ -31,18 +26,13 @@ class CampaignUrnDelegate
* @return Campaign
* @throws CampaignException
*/
public function onCreate(Campaign $campaign)
public function onCreate(Campaign $campaign): Campaign
{
if ($campaign->getUrn()) {
throw new CampaignException('Campaign already has an URN');
}
$guid = $this->guid->build();
$urn = "urn:campaign:{$guid}";
$campaign
->setUrn($urn);
return $campaign;
return $campaign->setUrn("urn:campaign:{$guid}");
}
}
<?php
/**
* NormalizeHashtagsDelegate
* @author edgebal
*/
namespace Minds\Core\Boost\Campaigns\Delegates;
......@@ -16,7 +12,7 @@ class NormalizeHashtagsDelegate
* @return Campaign
* @throws CampaignException
*/
public function onCreate(Campaign $campaign)
public function onCreate(Campaign $campaign): Campaign
{
$hashtags = $campaign->getHashtags();
......@@ -29,13 +25,10 @@ class NormalizeHashtagsDelegate
}, $hashtags))));
if (count($hashtags) > 5) {
throw new CampaignException('Campaigns should have 5 hashtags or less');
throw new CampaignException('Campaigns have a maximum of 5 hashtags');
}
$campaign
->setHashtags($hashtags);
return $campaign;
return $campaign->setHashtags($hashtags);
}
/**
......@@ -44,11 +37,9 @@ class NormalizeHashtagsDelegate
* @return Campaign
* @throws CampaignException
*/
public function onUpdate(Campaign $campaign, Campaign $campaignRef)
public function onUpdate(Campaign $campaign, Campaign $campaignRef): Campaign
{
$campaign
->setHashtags($campaignRef->getHashtags());
$campaign->setHashtags($campaignRef->getHashtags());
return $this->onCreate($campaign);
}
}
......@@ -2,14 +2,40 @@
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Campaign;
use Minds\Core\Boost\Campaigns\CampaignException;
use Minds\Core\Boost\Campaigns\Delegates\CampaignUrnDelegate;
use Minds\Core\GuidBuilder;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class CampaignUrnDelegateSpec extends ObjectBehavior
{
/** @var GuidBuilder */
protected $guidBuilder;
public function let(GuidBuilder $guidBuilder)
{
$this->beConstructedWith($guidBuilder);
$this->guidBuilder = $guidBuilder;
}
public function it_is_initializable()
{
$this->shouldHaveType(CampaignUrnDelegate::class);
}
public function it_should_throw_an_exception_if_urn_already_set(Campaign $campaign)
{
$campaign->getUrn()->shouldBeCalled()->willReturn('urn:campaign:1234');
$this->shouldThrow(CampaignException::class)->during('onCreate', [$campaign]);
}
public function it_should_create_and_set_a_urn(Campaign $campaign)
{
$campaign->getUrn()->shouldBeCalled()->willReturn(null);
$this->guidBuilder->build()->shouldBeCalled()->willReturn(12345);
$campaign->setUrn('urn:campaign:12345')->shouldBeCalled()->willReturn($campaign);
$this->onCreate($campaign);
}
}
......@@ -2,6 +2,8 @@
namespace Spec\Minds\Core\Boost\Campaigns\Delegates;
use Minds\Core\Boost\Campaigns\Campaign;
use Minds\Core\Boost\Campaigns\CampaignException;
use Minds\Core\Boost\Campaigns\Delegates\NormalizeHashtagsDelegate;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
......@@ -12,4 +14,84 @@ class NormalizeHashtagsDelegateSpec extends ObjectBehavior
{
$this->shouldHaveType(NormalizeHashtagsDelegate::class);
}
public function it_should_throw_exception_if_more_than_5_hashtags_on_create(Campaign $campaign)
{
$hashtags = [
'one',
'two',
'three',
'four',
'five',
'six'
];
$campaign->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$this->shouldThrow(CampaignException::class)->during('onCreate', [$campaign]);
}
public function it_should_throw_exception_if_more_than_5_hashtags_on_update(Campaign $campaign, Campaign $campaignRef)
{
$hashtags = [
'one',
'two',
'three',
'four',
'five',
'six'
];
$campaignRef->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$campaign->setHashtags($hashtags)->shouldBeCalled()->willReturn($campaign);
$campaign->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$this->shouldThrow(CampaignException::class)->during('onUpdate', [$campaign, $campaignRef]);
}
public function it_should_normalise_hashtags_on_create(Campaign $campaign)
{
$hashtags = [
'on e',
'two',
'th*ree',
'four',
'five'
];
$hashtagsNormal = [
'one',
'two',
'three',
'four',
'five'
];
$campaign->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$campaign->setHashtags($hashtagsNormal)->shouldBeCalled()->willReturn($campaign);
$this->onCreate($campaign);
}
public function it_should_normalise_hashtags_on_update(Campaign $campaign, Campaign $campaignRef)
{
$hashtags = [
'on e',
'two',
'th*ree',
'four',
'five'
];
$hashtagsNormal = [
'one',
'two',
'three',
'four',
'five'
];
$campaignRef->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$campaign->setHashtags($hashtags)->shouldbeCalled()->willReturn($campaign);
$campaign->getHashtags()->shouldBeCalled()->willReturn($hashtags);
$campaign->setHashtags($hashtagsNormal)->shouldBeCalled()->willReturn($campaign);
$this->onUpdate($campaign, $campaignRef);
}
}