Skip to content

Commit

Permalink
Adding iSite Contact Details support to Programme Options (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Albert authored and felipeparaujo committed Nov 7, 2017
1 parent 496e786 commit 13c4a18
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/Domain/Enumeration/ContactMediumEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace BBC\ProgrammesPagesService\Domain\Enumeration;

class ContactMediumEnum
{
public const EMAIL = 'email';
public const SMS = 'sms';
public const PHONE = 'phone';
public const FAX = 'fax';
public const ADDRESS = 'address';
public const FACEBOOK = 'facebook';
public const TWITTER = 'twitter';
public const GOOGLE_PLUS = 'google-plus';
public const SPOTIFY = 'spotify';
public const PINTEREST = 'pinterest';
public const TUMBLR = 'tumblr';
public const STUMBLEUPON = 'stumbleupon';
public const INSTAGRAM = 'instagram';
public const OTHER = 'other';
}
43 changes: 43 additions & 0 deletions src/Domain/ValueObject/ContactDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace BBC\ProgrammesPagesService\Domain\ValueObject;

use BBC\ProgrammesPagesService\Domain\Enumeration\ContactMediumEnum;

class ContactDetails
{
/**
* @see ContactMediumEnum::VALID_MEDIUM
*
* @var string
*/
private $type;

/** @var string */
private $value;

/** @var string */
private $freetext;

public function __construct(string $mediaType, string $value, string $freetext)
{
$this->type = $mediaType;
$this->value = $value;
$this->freetext = $freetext;
}

public function getType(): string
{
return $this->type;
}

public function getValue(): string
{
return $this->value;
}

public function getFreetext(): string
{
return $this->freetext;
}
}
35 changes: 33 additions & 2 deletions src/Mapper/ProgrammesDbToDomain/OptionsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Options;
use BBC\ProgrammesPagesService\Domain\ValueObject\ContactDetails;

class OptionsMapper extends AbstractMapper
{
Expand Down Expand Up @@ -41,6 +42,9 @@ class OptionsMapper extends AbstractMapper
'bbc_site' => [ 'default' => null, 'cascades' => false ],
'livepromo_block' => [ 'default' => null, 'cascades' => false ],
'prioritytext_block' => [ 'default' => null, 'cascades' => false ],

// contact options
'contact_details' => [ 'default' => [], 'cascades' => false ],
];

private static $defaults = [];
Expand All @@ -62,15 +66,42 @@ public function getDomainModel(array $options, array ...$parentEntities)

// set default values
$defaults = $this->getDefaultValues();
foreach ($defaults as $key => $value) {
foreach ($defaults as $key => $defaultValue) {
if (!isset($options[$key])) {
$options[$key] = $value;
$options[$key] = $defaultValue;
}
}

if (isset($options['contact_details'])) {
$contacts = [];

foreach ($options['contact_details'] as $contactDetails) {
if ($this->isValidContactDetails($contactDetails)) {
$contacts[] = new ContactDetails(
$contactDetails['type'],
$contactDetails['value'],
$contactDetails['freetext']
);
}
}

if ($contacts) {
$options['contact_details'] = $contacts;
}
}

return new Options($options);
}

private function isValidContactDetails(array $contact): bool
{
return (
isset($contact['type']) &&
isset($contact['value']) &&
isset($contact['freetext'])
);
}

private function getDefaultValues()
{
if (!self::$defaults) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Mapper/ProgrammesDbToDomain/CachingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Options;
use BBC\ProgrammesPagesService\Domain\Entity\ContactMediaMap;
use BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\MapperFactory;

class CachingTest extends BaseCoreEntityMapperTestCase
Expand Down Expand Up @@ -63,6 +64,7 @@ public function testCacheAccountsForUnfetchedEntities()
'livepromo_block' => null,
'prioritytext_block' => null,
'navigation_links' => [],
'contact_details' => [],
]
)
);
Expand Down
72 changes: 67 additions & 5 deletions tests/Mapper/ProgrammesDbToDomain/OptionsMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Tests\BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain;

use BBC\ProgrammesPagesService\Domain\Entity\Options;
use BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\OptionsMapper;
use BBC\ProgrammesPagesService\Domain\ValueObject\ContactDetails;
use BBC\ProgrammesPagesService\Mapper\ProgrammesDbToDomain\MapperFactory;

class OptionsMapperTest extends BaseMapperTestCase
{
Expand Down Expand Up @@ -48,11 +49,12 @@ public function testBasicOptionsNoHierarchy()
'livepromo_block' => null,
'prioritytext_block' => null,
'navigation_links' => [],
'contact_details' => [],
];

$this->assertEquals(
new Options($expectedOptions),
$this->getMapper()->getDomainModel($options)
(new MapperFactory())->getOptionsMapper()->getDomainModel($options)
);
}

Expand Down Expand Up @@ -109,16 +111,76 @@ public function testInheritanceOfOptions()
'livepromo_block' => null,
'prioritytext_block' => null,
'navigation_links' => [],
'contact_details' => [],
];

$this->assertEquals(
new Options($expectedOptions),
$this->getMapper()->getDomainModel($childOptions, $parentOptions, $grandparentOptions)
(new MapperFactory())->getOptionsMapper()->getDomainModel($childOptions, $parentOptions, $grandparentOptions)
);
}

private function getMapper(): OptionsMapper
public function testCanAddMappedContact()
{
return new OptionsMapper($this->getMapperFactory());
$options = [
'language' => 'cy',
'second_option' => null,
'contact_details' => [
[
'type' => 'email',
'value' => '[email protected]',
'freetext' => 'Free text',
],
[
'type' => 'email',
'value' => '[email protected]',
'freetext' => 'Free text',
],
],
];

$expectedOptions = [
'projectId' => null,
'language' => 'cy',
'branding_id' => 'br-00002',
'second_option' => null,
'pulse_survey' => null,
'brand_2016_layout' => false,
'brand_2016_layout_use_minimap' => false,
'show_clip_cards' => true,
'show_gallery_cards' => true,
'double_width_first_promo' => false,
'show_tracklist_inadvance' => false,
'show_tracklist_timings' => false,
'show_enhanced_navigation' => false,
'comments_clips_id' => null,
'comments_clips_enabled' => false,
'comments_episodes_id' => null,
'comments_episodes_enabled' => false,
'playlister_popularity_enabled' => false,
'recipes_enabled' => false,
'brand_layout' => 'availability',
'promoted_programmes' => [],
'live_stream_id' => null,
'live_stream_heading' => null,
'pid_override_url' => null,
'pid_override_code' => null,
'ivote_block' => null,
'comingsoon_block' => null,
'comingsoon_textonly' => null,
'bbc_site' => null,
'livepromo_block' => null,
'prioritytext_block' => null,
'navigation_links' => [],
'contact_details' => [
new ContactDetails('email', '[email protected]', 'Free text'),
new ContactDetails('email', '[email protected]', 'Free text'),
],
];

$this->assertEquals(
new Options($expectedOptions),
(new MapperFactory())->getOptionsMapper()->getDomainModel($options)
);
}
}

0 comments on commit 13c4a18

Please sign in to comment.