Skip to content

Commit

Permalink
get theme path implementation and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
takeit committed Oct 31, 2014
1 parent 4672237 commit 7c3183f
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
46 changes: 45 additions & 1 deletion newscoop/library/Newscoop/Services/ThemesService.php
Expand Up @@ -9,24 +9,68 @@
namespace Newscoop\Services;

use Newscoop\ThemesServiceInterface;
use Newscoop\IssueServiceInterface;

/**
* Themes service
*/
class ThemesService implements ThemesServiceInterface
{
/**
* Issue service
*
* @var IssueServiceInterface
*/
protected $issueService;

/**
* Cache service
*
* @var CacheService
*/
protected $cacheService;

/**
* Publication service
*
* @var PublicationService
*/
protected $publicationService;

/**
* Construct
*/
public function __construct()
public function __construct(IssueServiceInterface $issueService, CacheService $cacheService, PublicationService $publicationService)
{
$this->issueService = $issueService;
$this->cacheService = $cacheService;
$this->publicationService = $publicationService;
}

/**
* {@inheritDoc}
*/
public function getThemePath()
{
$issue = $this->issueService->getIssue();
$language = $issue->getLanguageId();
$publication = $this->publicationService->getPublication();
$cacheKeyThemePath = $this->cacheService->getCacheKey(array('getThemePath', $language, $publication->getId(), $issue->getNumber()), 'issue');

if ($this->cacheService->contains($cacheKeyThemePath)) {
$themePath = $this->cacheService->fetch($cacheKeyThemePath);
} else {
$cacheKey = $this->cacheService->getCacheKey(array('issue', $publication->getId(), $language, $issue->getNumber()), 'issue');
if ($this->cacheService->contains($cacheKey)) {
$issue = $this->cacheService->fetch($cacheKey);
} else {
$this->cacheService->save($cacheKey, $issue);
}

//$resourceId = new ResourceId('template_engine/classes/CampSystem');
//$outputService = $resourceId->getService(IOutputService::NAME);
}

return '';
}
}
Expand Up @@ -133,6 +133,10 @@ services:
class: Newscoop\Services\IssueService
arguments: ["@em", "@newscoop_newscoop.publication_service"]

newscoop_newscoop.themes_service:
class: Newscoop\Services\ThemesService
arguments: ["@newscoop_newscoop.issue_service", "@newscoop.cache"]

newscoop_newscoop.listener.publication:
class: Newscoop\NewscoopBundle\EventListener\PublicationListener
arguments: ["@newscoop_newscoop.publication_service"]
Expand Down
31 changes: 29 additions & 2 deletions spec/Newscoop/Services/ThemesServiceSpec.php
Expand Up @@ -3,12 +3,39 @@
namespace spec\Newscoop\Services;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Newscoop\IssueServiceInterface;
use Newscoop\Services\CacheService;
use Newscoop\Services\PublicationService;
use Newscoop\Entity\Issue;
use Newscoop\Entity\Publication;

class ThemesServiceSpec extends ObjectBehavior
{
function it_is_initializable()
public function it_is_initializable()
{
$this->shouldHaveType('Newscoop\Services\ThemesService');
$this->shouldImplement('Newscoop\ThemesServiceInterface');
}

public function let(
IssueServiceInterface $issueService,
Issue $issue,
CacheService $cacheService,
PublicationService $publicationService,
Publication $publication)
{
$issueService->getIssue()->willReturn($issue);
$publicationService->getPublication()->willReturn($publication);
$this->beConstructedWith($issueService, $cacheService, $publicationService);
}

public function it_gets_theme_path(Issue $issue)
{
$issue->getId()->willReturn(1);
$issue->getNumber()->willReturn(10);
$issue->getName()->willReturn("May 2014");
$issue->getShortName()->willReturn("may2014");
$issue->getLanguageId()->willReturn(1);
$this->getThemePath()->shouldBeString();
}
}

0 comments on commit 7c3183f

Please sign in to comment.