Skip to content

Commit

Permalink
Added webspace to node when saving page-tree content-type (#208)
Browse files Browse the repository at this point in the history
* added webspace to node when saving page-tree content-type

* fixed travis config
  • Loading branch information
wachterjohannes authored and trickreich committed Jun 26, 2017
1 parent 682caf1 commit 47dec00
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
sudo: true

language: php

env:
Expand Down Expand Up @@ -33,14 +31,16 @@ matrix:
- COMPOSER_FLAGS="--prefer-dist --no-interaction"
# - SULU_VERSION="~1.6.0"
- SYMFONY__PHPCR__TRANSPORT=jackrabbit

addons:
apt:
packages:
- oracle-java8-installer

before_install:
# Container based PHP image ues PHP 5.6.5, once it will be upgraded sudo will be not necessary
- sudo apt-get install -y oracle-java8-set-default
- sudo update-java-alternatives -s java-8-oracle
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
- java -version
- |
if [[ $SYMFONY__PHPCR__TRANSPORT = jackrabbit ]]; then
if [ ! -f downloads/jackrabbit-standalone-$JACKRABBIT_VERSION.jar ]; then
Expand Down
24 changes: 23 additions & 1 deletion Content/PageTreeRouteContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use PHPCR\ItemNotFoundException;
use PHPCR\NodeInterface;
use PHPCR\PropertyType;
use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
use Sulu\Bundle\RouteBundle\Generator\ChainRouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\ConflictResolverInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\Content\SimpleContentType;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
use Sulu\Component\DocumentManager\DocumentRegistry;

/**
Expand All @@ -32,6 +34,16 @@ class PageTreeRouteContentType extends SimpleContentType
*/
private $template;

/**
* @var DocumentManagerInterface
*/
private $documentManager;

/**
* @var DocumentInspector
*/
private $documentInspector;

/**
* @var DocumentRegistry
*/
Expand All @@ -49,19 +61,25 @@ class PageTreeRouteContentType extends SimpleContentType

/**
* @param string $template
* @param DocumentManagerInterface $documentManager
* @param DocumentInspector $documentInspector
* @param DocumentRegistry $documentRegistry
* @param ChainRouteGeneratorInterface $chainRouteGenerator
* @param ConflictResolverInterface $conflictResolver
*/
public function __construct(
$template,
DocumentManagerInterface $documentManager,
DocumentInspector $documentInspector,
DocumentRegistry $documentRegistry,
ChainRouteGeneratorInterface $chainRouteGenerator,
ConflictResolverInterface $conflictResolver
) {
parent::__construct('PageTreeRoute');

$this->template = $template;
$this->documentManager = $documentManager;
$this->documentInspector = $documentInspector;
$this->documentRegistry = $documentRegistry;
$this->chainRouteGenerator = $chainRouteGenerator;
$this->conflictResolver = $conflictResolver;
Expand Down Expand Up @@ -101,7 +119,7 @@ public function write(
}

$path = $this->getAttribute('path', $value, '');
$page = $this->getAttribute('page', $value, ['uuid' => null, 'path' => '/']);
$page = $this->getAttribute('page', $value, ['uuid' => null, 'path' => '/', 'webspace' => $webspaceKey]);

$suffix = $this->getAttribute('suffix', $value);
if (!$suffix) {
Expand All @@ -121,8 +139,11 @@ public function write(
if ($node->hasProperty($pagePropertyName)) {
$node->getProperty($pagePropertyName)->remove();
}

$document = $this->documentManager->find($page['uuid'], $languageCode);
$node->setProperty($pagePropertyName, $page['uuid'], PropertyType::WEAKREFERENCE);
$node->setProperty($pagePropertyName . '-path', $page['path']);
$node->setProperty($pagePropertyName . '-webspace', $this->documentInspector->getWebspace($document));
}

/**
Expand Down Expand Up @@ -175,6 +196,7 @@ private function readPage($propertyName, NodeInterface $node)
return [
'uuid' => $pageUuid,
'path' => $node->getPropertyValueWithDefault($pagePropertyName . '-path', ''),
'webspace' => $node->getPropertyValueWithDefault($pagePropertyName . '-webspace', null),
];
}

Expand Down
2 changes: 2 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@
<service id="sulu_article.content_types.page_tree_route"
class="Sulu\Bundle\ArticleBundle\Content\PageTreeRouteContentType">
<argument>%sulu_article.content-type.page_tree_route.template%</argument>
<argument type="service" id="sulu_document_manager.document_manager"/>
<argument type="service" id="sulu_document_manager.document_inspector"/>
<argument type="service" id="sulu_document_manager.document_registry"/>
<argument type="service" id="sulu_route.chain_generator"/>
<argument type="service" id="sulu_route.manager.conflict_resolver.auto_increment"/>
Expand Down
60 changes: 52 additions & 8 deletions Tests/Functional/Content/PageTreeRouteContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@
use PHPCR\PropertyType;
use Sulu\Bundle\ArticleBundle\Content\PageTreeRouteContentType;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Bundle\ContentBundle\Document\BasePageDocument;
use Sulu\Bundle\DocumentManagerBundle\Bridge\DocumentInspector;
use Sulu\Bundle\RouteBundle\Generator\ChainRouteGeneratorInterface;
use Sulu\Bundle\RouteBundle\Manager\ConflictResolverInterface;
use Sulu\Bundle\RouteBundle\Model\RouteInterface;
use Sulu\Component\Content\Compat\PropertyInterface;
use Sulu\Component\DocumentManager\DocumentManagerInterface;
use Sulu\Component\DocumentManager\DocumentRegistry;

class PageTreeRouteContentTypeTest extends \PHPUnit_Framework_TestCase
{
/**
* @var DocumentManagerInterface
*/
private $documentManager;

/**
* @var DocumentInspector
*/
private $documentInspector;

/**
* @var DocumentRegistry
*/
Expand Down Expand Up @@ -53,6 +66,11 @@ class PageTreeRouteContentTypeTest extends \PHPUnit_Framework_TestCase
*/
private $property;

/**
* @var BasePageDocument
*/
private $document;

/**
* @var string
*/
Expand All @@ -73,8 +91,15 @@ class PageTreeRouteContentTypeTest extends \PHPUnit_Framework_TestCase
*/
private $template = 'test.html.twig';

/**
* @var string
*/
private $uuid = '123-123-123';

public function setUp()
{
$this->documentManager = $this->prophesize(DocumentManagerInterface::class);
$this->documentInspector = $this->prophesize(DocumentInspector::class);
$this->documentRegistry = $this->prophesize(DocumentRegistry::class);
$this->chainRouteGenerator = $this->prophesize(ChainRouteGeneratorInterface::class);
$this->conflictResolver = $this->prophesize(ConflictResolverInterface::class);
Expand All @@ -85,8 +110,16 @@ public function setUp()

$this->contentType = new PageTreeRouteContentType(
$this->template,
$this->documentRegistry->reveal(), $this->chainRouteGenerator->reveal(), $this->conflictResolver->reveal()
$this->documentManager->reveal(),
$this->documentInspector->reveal(),
$this->documentRegistry->reveal(),
$this->chainRouteGenerator->reveal(),
$this->conflictResolver->reveal()
);

$this->document = $this->prophesize(BasePageDocument::class);
$this->documentManager->find($this->uuid, $this->locale)->willReturn($this->document->reveal());
$this->documentInspector->getWebspace($this->document->reveal())->willReturn($this->webspaceKey);
}

public function testRead()
Expand All @@ -95,8 +128,9 @@ public function testRead()
'path' => '/test-page/test-article',
'suffix' => 'test-article',
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
'webspace' => $this->webspaceKey,
],
];

Expand All @@ -107,6 +141,8 @@ public function testRead()
->willReturn($value['page']['uuid']);
$this->node->getPropertyValueWithDefault($this->propertyName . '-page-path', '')
->willReturn($value['page']['path']);
$this->node->getPropertyValueWithDefault($this->propertyName . '-page-webspace', null)
->willReturn($value['page']['webspace']);

$this->property->setValue($value)->shouldBeCalled();

Expand Down Expand Up @@ -152,8 +188,9 @@ public function testWrite()
'path' => '/test-page/test-article',
'suffix' => 'test-article',
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
'webspace' => $this->webspaceKey,
],
];

Expand All @@ -164,6 +201,7 @@ public function testWrite()
$this->node->setProperty($this->propertyName . '-page', $value['page']['uuid'], PropertyType::WEAKREFERENCE)
->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-path', $value['page']['path'])->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-webspace', $value['page']['webspace'])->shouldBeCalled();

$this->node->hasProperty($this->propertyName . '-page')->willReturn(false);

Expand All @@ -183,8 +221,9 @@ public function testWriteExistingPageRelation()
'path' => '/test-page/test-article',
'suffix' => 'test-article',
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
'webspace' => $this->webspaceKey,
],
];

Expand All @@ -195,6 +234,7 @@ public function testWriteExistingPageRelation()
$this->node->setProperty($this->propertyName . '-page', $value['page']['uuid'], PropertyType::WEAKREFERENCE)
->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-path', $value['page']['path'])->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-webspace', $value['page']['webspace'])->shouldBeCalled();

$pageProperty = $this->prophesize(\PHPCR\PropertyInterface::class);
$pageProperty->remove()->shouldBeCalled();
Expand Down Expand Up @@ -231,8 +271,9 @@ function () use ($route) {

$value = [
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
'webspace' => $this->webspaceKey,
],
];

Expand All @@ -243,6 +284,7 @@ function () use ($route) {
$this->node->setProperty($this->propertyName . '-page', $value['page']['uuid'], PropertyType::WEAKREFERENCE)
->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-path', $value['page']['path'])->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-webspace', $value['page']['webspace'])->shouldBeCalled();

$pageProperty = $this->prophesize(\PHPCR\PropertyInterface::class);
$pageProperty->remove()->shouldBeCalled();
Expand Down Expand Up @@ -279,8 +321,9 @@ function () use ($route) {

$value = [
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/',
'webspace' => $this->webspaceKey,
],
];

Expand All @@ -291,6 +334,7 @@ function () use ($route) {
$this->node->setProperty($this->propertyName . '-page', $value['page']['uuid'], PropertyType::WEAKREFERENCE)
->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-path', $value['page']['path'])->shouldBeCalled();
$this->node->setProperty($this->propertyName . '-page-webspace', $value['page']['webspace'])->shouldBeCalled();

$pageProperty = $this->prophesize(\PHPCR\PropertyInterface::class);
$pageProperty->remove()->shouldBeCalled();
Expand All @@ -316,7 +360,7 @@ public function testGetContentData()
{
$value = [
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
],
'path' => '/test-page/test-article',
Expand All @@ -332,7 +376,7 @@ public function testGetViewData()
{
$value = [
'page' => [
'uuid' => '123-123-123',
'uuid' => $this->uuid,
'path' => '/test-page',
],
'path' => '/test-page/test-article',
Expand Down
5 changes: 5 additions & 0 deletions Tests/Functional/Controller/ArticleControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ public function testPostPageTreeRoute()
'page' => [
'uuid' => $page->getUuid(),
'path' => $page->getResourceSegment(),
'webspace' => 'sulu_io',
],
'suffix' => 'test-article',
'path' => '/test-page/test-article',
Expand All @@ -931,6 +932,7 @@ public function testPostPageTreeRouteGenerate()
'page' => [
'uuid' => $page->getUuid(),
'path' => $page->getResourceSegment(),
'webspace' => 'sulu_io',
],
'suffix' => 'articles/test-article',
'path' => '/test-page/articles/test-article',
Expand Down Expand Up @@ -978,6 +980,7 @@ public function testPostPageTreeRouteGeneratePublishPage()
'page' => [
'uuid' => $page->getUuid(),
'path' => $page->getResourceSegment(),
'webspace' => 'sulu_io',
],
'suffix' => 'articles/test-article',
'path' => '/test-page-2/articles/test-article',
Expand Down Expand Up @@ -1021,6 +1024,7 @@ public function testPostPageTreeRouteGenerateMovePage()
'page' => [
'uuid' => $page1->getUuid(),
'path' => $page1->getResourceSegment(),
'webspace' => 'sulu_io',
],
'suffix' => 'articles/test-article',
'path' => '/page-2/page-1/articles/test-article',
Expand All @@ -1037,6 +1041,7 @@ public function testPostPageTreeRouteGenerateRemovePage()
'page' => [
'uuid' => $page->getUuid(),
'path' => $page->getResourceSegment(),
'webspace' => 'sulu_io',
],
'suffix' => 'articles/test-article',
'path' => '/test-page/articles/test-article',
Expand Down

0 comments on commit 47dec00

Please sign in to comment.