From 6c640221a98e0129be3d5192a64f043b4699b447 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 14 Feb 2014 09:56:51 +0100 Subject: [PATCH 1/6] WIP refactor common features into RoutingBundle --- CmfSimpleCmsBundle.php | 1 - DependencyInjection/CmfSimpleCmsExtension.php | 107 +-- DependencyInjection/Configuration.php | 4 +- Doctrine/Phpcr/MultilangRedirectRoute.php | 37 - Doctrine/Phpcr/MultilangRoute.php | 37 - Doctrine/Phpcr/Page.php | 635 ++++++++++++++++- Doctrine/Phpcr/PageRouteProvider.php | 91 --- Model/Page.php | 670 ------------------ .../config/doctrine-model/Page.phpcr.xml | 32 - .../MultilangRedirectRoute.phpcr.xml | 10 - .../doctrine-phpcr/MultilangRoute.phpcr.xml | 10 - .../config/doctrine-phpcr/Page.phpcr.xml | 16 + Resources/config/routing-bc.xml | 39 + Resources/config/routing-phpcr.xml | 41 -- Resources/config/routing.xml | 31 - 15 files changed, 719 insertions(+), 1042 deletions(-) delete mode 100644 Doctrine/Phpcr/MultilangRedirectRoute.php delete mode 100644 Doctrine/Phpcr/MultilangRoute.php delete mode 100644 Doctrine/Phpcr/PageRouteProvider.php delete mode 100644 Model/Page.php delete mode 100644 Resources/config/doctrine-model/Page.phpcr.xml delete mode 100644 Resources/config/doctrine-phpcr/MultilangRedirectRoute.phpcr.xml delete mode 100644 Resources/config/doctrine-phpcr/MultilangRoute.phpcr.xml create mode 100644 Resources/config/routing-bc.xml delete mode 100644 Resources/config/routing-phpcr.xml delete mode 100644 Resources/config/routing.xml diff --git a/CmfSimpleCmsBundle.php b/CmfSimpleCmsBundle.php index c64515b..0844af9 100644 --- a/CmfSimpleCmsBundle.php +++ b/CmfSimpleCmsBundle.php @@ -30,7 +30,6 @@ public function build(ContainerBuilder $container) $container->addCompilerPass( DoctrinePhpcrMappingsPass::createXmlMappingDriver( array( - realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Model', realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr', ), array('cmf_simple_cms.persistence.phpcr.manager_name') diff --git a/DependencyInjection/CmfSimpleCmsExtension.php b/DependencyInjection/CmfSimpleCmsExtension.php index 5f4e7ae..81fc151 100644 --- a/DependencyInjection/CmfSimpleCmsExtension.php +++ b/DependencyInjection/CmfSimpleCmsExtension.php @@ -43,12 +43,12 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration(new Configuration(), $configs); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $this->loadRouting($config['routing'], $loader, $container); + if ($config['routing']) { + $this->loadRouting($config['routing'], $loader, $container); + } if ($config['persistence']['phpcr']) { $this->loadPhpcr($config['persistence']['phpcr'], $loader, $container); - $locales = isset($config['multilang']['locales']) ? $config['multilang']['locales'] : false; - $this->loadPhpcrRouting($config, $loader, $container, $locales); if ($config['use_menu']) { $this->loadPhpcrMenu($config, $loader, $container); @@ -58,46 +58,34 @@ public function load(array $configs, ContainerBuilder $container) protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder $container) { - $container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']); - - $loader->load('routing.xml'); + if (!empty($config['uri_filter_regexp'])) { + throw new InvalidConfigurationException('cmf_simple.routing.uri_filter_regexp must be configured on cmf_routing.'); + } - $dynamic = $container->getDefinition($this->getAlias().'.dynamic_router'); + $loader->load('routing-bc.xml'); if (!empty($config['generic_controller'])) { - $definition = new DefinitionDecorator('cmf_routing.enhancer.explicit_template'); - $definition->replaceArgument(2, $config['generic_controller']); - $container->setDefinition( - $this->getAlias() . '.enhancer.explicit_template', - $definition - ); - $dynamic->addMethodCall('addRouteEnhancer', array( - new Reference($this->getAlias() . '.enhancer.explicit_template') - )); + $container->setParameter($this->getAlias() . '.generic_controller', $config['generic_controller']); + $definition = $container->getDefinition($this->getAlias() . '.enhancer.explicit_template'); + $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); + } else { + $container->removeDefinition($this->getAlias() . '.enhancer.explicit_template'); } if (!empty($config['controllers_by_type'])) { - $definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_type'); - $definition->replaceArgument(2, $config['controllers_by_type']); - $container->setDefinition( - $this->getAlias() . '.enhancer.controllers_by_type', - $definition - ); - $dynamic->addMethodCall('addRouteEnhancer', array( - new Reference($this->getAlias() . '.enhancer.controllers_by_type') - )); + $container->setParameter($this->getAlias() . '.controllers_by_type', $config['controllers_by_type']); + $definition = $container->getDefinition($this->getAlias() . '.enhancer.controllers_by_type'); + $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); + } else { + $container->removeDefinition($this->getAlias() . '.enhancer.controllers_by_type'); } if (!empty($config['controllers_by_class'])) { - $definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_class'); - $definition->replaceArgument(2, $config['controllers_by_class']); - $container->setDefinition( - $this->getAlias() . '.enhancer.controllers_by_class', - $definition - ); - $dynamic->addMethodCall('addRouteEnhancer', array( - new Reference($this->getAlias() . '.enhancer.controllers_by_class') - )); + $container->setParameter($this->getAlias() . '.controllers_by_class', $config['controllers_by_class']); + $definition = $container->getDefinition($this->getAlias() . '.enhancer.controllers_by_class'); + $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); + } else { + $container->removeDefinition($this->getAlias() . '.enhancer.controllers_by_class'); } if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) { @@ -105,39 +93,24 @@ protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder foreach ($config['templates_by_class'] as $key => $value) { $controllerForTemplates[$key] = $config['generic_controller']; } - - $definition = new DefinitionDecorator('cmf_routing.enhancer.controller_for_templates_by_class'); + $definition = $container->getDefinition($this->getAlias() . '.enhancer.controller_for_templates_by_class'); $definition->replaceArgument(2, $controllerForTemplates); - - $container->setDefinition( - $this->getAlias() . '.enhancer.controller_for_templates_by_class', - $definition - ); - - $definition = new DefinitionDecorator('cmf_routing.enhancer.templates_by_class'); - $definition->replaceArgument(2, $config['templates_by_class']); - - $container->setDefinition( - $this->getAlias() . '.enhancer.templates_by_class', - $definition - ); - - $dynamic->addMethodCall('addRouteEnhancer', array( - new Reference($this->getAlias() . '.enhancer.controller_for_templates_by_class') - )); - $dynamic->addMethodCall('addRouteEnhancer', array( - new Reference($this->getAlias() . '.enhancer.templates_by_class') - )); + $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); + + $container->setParameter($this->getAlias() . '.templates_by_class', $config['templates_by_class']); + $definition = $container->getDefinition($this->getAlias() . '.enhancer.templates_by_class'); + $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); + } else { + $container->removeDefinition($this->getAlias() . '.enhancer.controller_for_templates_by_class'); + $container->removeDefinition($this->getAlias() . '.enhancer.templates_by_class'); } } protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container) { $loader->load('services-phpcr.xml'); - // migrator is only for PHPCR $loader->load('migrator-phpcr.xml'); - // save some characters $prefix = $this->getAlias() . '.persistence.phpcr'; $container->setParameter($prefix . '.basepath', $config['basepath']); @@ -155,24 +128,6 @@ protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $c $container->setParameter($prefix . '.document.class', $config['document_class']); } - protected function loadPhpcrRouting($config, XmlFileLoader $loader, ContainerBuilder $container, $locales) - { - $loader->load('routing-phpcr.xml'); - $prefix = $this->getAlias() . '.persistence.phpcr'; - - $routeProvider = $container->getDefinition($prefix.'.route_provider'); - $routeProvider->replaceArgument(0, new Reference($config['persistence']['phpcr']['manager_registry'])); - if (!empty($locales)) { - $routeProvider->addMethodCall('setLocales', array($locales)); - } - $container->setAlias($this->getAlias() . '.route_provider', $prefix.'.route_provider'); - - $generator = $container->getDefinition($this->getAlias().'.generator'); - $generator->addMethodCall('setContentRepository', array( - new Reference($config['routing']['content_repository_id']) - )); - } - protected function loadPhpcrMenu($config, XmlFileLoader $loader, ContainerBuilder $container) { $bundles = $container->getParameter('kernel.bundles'); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b029707..d22d871 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -58,6 +58,7 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('routing') + ->info('deprecated, configure routing in cmf_routing bundle configuration') ->fixXmlConfig('controller_by_type', 'controllers_by_type') ->fixXmlConfig('controller_by_class', 'controllers_by_class') ->fixXmlConfig('template_by_class', 'templates_by_class') @@ -65,7 +66,7 @@ public function getConfigTreeBuilder() ->children() ->scalarNode('generic_controller')->defaultValue('cmf_content.controller:indexAction')->end() ->scalarNode('content_repository_id')->defaultValue('cmf_routing.content_repository')->end() - ->scalarNode('uri_filter_regexp')->defaultValue('')->end() + ->scalarNode('uri_filter_regexp')->end() ->arrayNode('controllers_by_type') ->useAttributeAsKey('type') ->prototype('scalar')->end() @@ -82,6 +83,7 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('multilang') + ->info('unused, deprecated') ->fixXmlConfig('locale') ->children() ->arrayNode('locales') diff --git a/Doctrine/Phpcr/MultilangRedirectRoute.php b/Doctrine/Phpcr/MultilangRedirectRoute.php deleted file mode 100644 index c8a5065..0000000 --- a/Doctrine/Phpcr/MultilangRedirectRoute.php +++ /dev/null @@ -1,37 +0,0 @@ -getPrefix(); - $path = substr($this->getId(), strlen($prefix)); - $path = $prefix.'/{_locale}'.$path; - - return $this->generateStaticPrefix($path, $this->idPrefix); - } -} diff --git a/Doctrine/Phpcr/MultilangRoute.php b/Doctrine/Phpcr/MultilangRoute.php deleted file mode 100644 index e75a392..0000000 --- a/Doctrine/Phpcr/MultilangRoute.php +++ /dev/null @@ -1,37 +0,0 @@ -getPrefix(); - $path = substr($this->getId(), strlen($prefix)); - $path = $prefix.'/{_locale}'.$path; - - return $this->generateStaticPrefix($path, $this->idPrefix); - } -} diff --git a/Doctrine/Phpcr/Page.php b/Doctrine/Phpcr/Page.php index 0879f79..fb3d286 100644 --- a/Doctrine/Phpcr/Page.php +++ b/Doctrine/Phpcr/Page.php @@ -9,15 +9,640 @@ * file that was distributed with this source code. */ - namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr; -use Symfony\Cmf\Bundle\SimpleCmsBundle\Model\Page as ModelPage; +use Doctrine\Common\Collections\Collection; +use LogicException; +use Knp\Menu\NodeInterface; +use Doctrine\Common\Collections\ArrayCollection; +use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishTimePeriodInterface; +use Symfony\Cmf\Bundle\CoreBundle\PublishWorkflow\PublishableInterface; +use Symfony\Cmf\Bundle\CoreBundle\Translatable\TranslatableInterface; +use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; +use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface; + +use Symfony\Component\Validator\Constraints as Assert; /** - * {@inheritDoc} + * This is the standard Simple CMS Page document. + * + * It supports: + * + * - Multilang + * - Publish Workflow + * + * Additionally you can store "extra" string values in it for application + * specific purposes. */ -class Page extends ModelPage +class Page extends Route implements + NodeInterface, + RouteReferrersReadInterface, // this must not be the write interface, it would make no sense + PublishTimePeriodInterface, + PublishableInterface, + TranslatableInterface { - public $node; + /** + * @var NodeInterface + */ + protected $node; + + /** + * @Assert\NotBlank + */ + protected $title; + + /** + * Menu label. + * + * @var string + */ + protected $label = ''; + + /** + * HTML attributes to add to the individual menu element. + * + * e.g. array('class' => 'foobar', 'style' => 'bar: foo') + * + * @var array + */ + protected $attributes = array(); + + /** + * HTML attributes to add to the children list element. + * + * e.g. array('class' => 'foobar', 'style' => 'bar: foo') + * + * @var array + */ + protected $childrenAttributes = array(); + + /** + * HTML attributes to add to items link. + * + * e.g. array('class' => 'foobar', 'style' => 'bar: foo') + * + * @var array + */ + protected $linkAttributes = array(); + + /** + * HTML attributes to add to the items label. + * + * e.g. array('class' => 'foobar', 'style' => 'bar: foo') + * + * @var array + */ + protected $labelAttributes = array(); + + /** + * Set to false to not render a menu item for this. + * + * @var boolean + */ + protected $display = true; + + /** + * Set to false to not render the child menu items of this page. + * + * @var boolean + */ + protected $displayChildren = true; + + /** + * @var string + */ + protected $body; + + /** + * @var \DateTime + */ + protected $createDate; + + /** + * @var \DateTime + */ + protected $publishStartDate; + + /** + * @var \DateTime + */ + protected $publishEndDate; + + /** + * @var boolean + */ + protected $publishable = true; + + /** + * @var string + */ + protected $locale; + + /** + * Extra values an application can store along with a page + * @var array + */ + protected $extras = array(); + + /** + * Additional supported options are: + * + * * add_format_pattern: When set, ".{_format}" is appended to the route pattern. + * Also implicitly sets a default/require on "_format" to "html". + * * add_locale_pattern: When set, "/{_locale}" is prepended to the route pattern. + */ + public function __construct(array $options = array()) + { + parent::__construct($options); + + $this->createDate = new \DateTime(); + $this->children = new ArrayCollection(); + } + + /** + * @return NodeInterface + */ + public function getNode() + { + return $this->node; + } + + /** + * {@inheritDoc} + */ + public function getLocale() + { + return $this->locale; + } + + /** + * {@inheritDoc} + */ + public function setLocale($locale) + { + $this->locale = $locale; + } + + /** + * Get the "date" of this page, which is the publishStartDate if set, + * otherwise the createDate. + */ + public function getDate() + { + return $this->publishStartDate ? $this->publishStartDate : $this->createDate; + } + + /** + * {@inheritDoc} + */ + public function getPublishStartDate() + { + return $this->publishStartDate; + } + + /** + * {@inheritDoc} + */ + public function setPublishStartDate(\DateTime $publishStartDate = null) + { + $this->publishStartDate = $publishStartDate; + } + + /** + * {@inheritDoc} + */ + public function getPublishEndDate() + { + return $this->publishEndDate; + } + + /** + * {@inheritDoc} + */ + public function setPublishEndDate(\DateTime $publishEndDate = null) + { + $this->publishEndDate = $publishEndDate; + } + + /** + * {@inheritDoc} + */ + public function isPublishable() + { + return $this->publishable; + } + + /** + * {@inheritDoc} + */ + public function setPublishable($publishable) + { + $this->publishable = $publishable; + } + + /** + * Get extras - a flat key-value hashmap + * + * @return array with only string values + */ + public function getExtras() + { + return $this->extras; + } + + /** + * Set extras - applications can store additional information on a page + * without needing to extend the document class. + * + * @param array $extras a flat key-value hashmap. The values are cast to + * string as PHPCR stores multivalue data with only one data type for + * all values. + */ + public function setExtras($extras) + { + foreach ($extras as $key => $value) { + $extras[$key] = (string) $value; + } + + $this->extras = $extras; + } + + /** + * Add a single key - value pair to extras + * + * @param string $key + * @param string $value - if this is not a string it is cast to one + */ + public function addExtra($key, $value) + { + $this->extras[$key] = (string) $value; + } + + /** + * Remove a single key - value pair from extras, if it was set. + * + * @param string $key + */ + public function removeExtra($key) + { + if (array_key_exists($key, $this->extras)) { + unset($this->extras[$key]); + } + } + + /** + * Return a single extras value for the provided key or the $default if + * the key is not defined. + * + * @param string $key + * @param string|null $default + * + * @return string|null The value at $key or if not existing $default + */ + public function getExtra($key, $default = null) + { + return array_key_exists($key, $this->extras) ? $this->extras[$key] : $default; + } + + /** + * Content method: Get the routes that point to this content + * + * {@inheritDoc} + */ + public function getRoutes() + { + return array($this); + } + + /** + * Menu method: Get child menu nodes. + * + * @return ArrayCollection the child nodes + */ + public function getChildren() + { + return $this->children; + } + + /** + * Menu method: List of child menu nodes + * + * @param object[] $children + */ + public function setChildren($children) + { + $this->children = $children; + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return $this->name; + } + + /** + * Route method: The content of this route is the object itself. + * + * {@inheritDoc} + */ + public function getContent() + { + return $this; + } + + /** + * Never call this, it makes no sense. The SimpleCms Page is its own + * content. + * + * @param $document + * + * @throws LogicException + */ + public function setContent($document) + { + throw new LogicException('Do not set a content object for the SimpleCMS page. It is its own content.'); + } + + /** + * Menu method: set the menu label + * + * @param string $label + */ + public function setLabel($label) + { + $this->label = $label; + } + + /** + * Menu method: get the label for the menu + * + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * Content method: set the page title + * + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * Content method: get the page title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Content method: set the page body + * + * @param string $body + */ + public function setBody($body) + { + $this->body = $body; + } + + /** + * Content method: get the page body + * + * @return string + */ + public function getBody() + { + return $this->body; + } + + /** + * Get the creation date + * + * @return \DateTime + */ + public function getCreateDate() + { + return $this->createDate; + } + + /** + * Overwrite the creation date manually + * + * On creation of a Page, the createDate is automatically set to the + * current time. + * + * @param \DateTime $createDate + */ + public function setCreateDate(\DateTime $createDate = null) + { + $this->createDate = $createDate; + } + + /** + * Return the attributes associated with this menu node + * + * @return array + */ + public function getAttributes() + { + return $this->attributes; + } + + /** + * Set the attributes associated with this menu node + * + * @param $attributes array + * + * @return Page The current Page instance + */ + public function setAttributes(array $attributes) + { + $this->attributes = $attributes; + + return $this; + } + + /** + * Return the given attribute, optionally specifying a default value + * + * @param string $name The name of the attribute to return + * @param string $default The value to return if the attribute doesn't exist + * + * @return string + */ + public function getAttribute($name, $default = null) + { + if (isset($this->attributes[$name])) { + return $this->attributes[$name]; + } + + return $default; + } + + /** + * Set the named attribute + * + * @param string $name attribute name + * @param string $value attribute value + * + * @return Page The current Page instance + */ + public function setAttribute($name, $value) + { + $this->attributes[$name] = $value; + + return $this; + } + + /** + * Return the children attributes + * + * @return array + */ + public function getChildrenAttributes() + { + return $this->childrenAttributes; + } + + /** + * Set the children attributes + * + * @param array $attributes + * + * @return Page The current Page instance + */ + public function setChildrenAttributes(array $attributes) + { + $this->childrenAttributes = $attributes; + + return $this; + } + + /** + * Get the link HTML attributes. + * + * @return array + */ + public function getLinkAttributes() + { + return $this->linkAttributes; + } + + /** + * Set the link HTML attributes as associative array. + * + * @param array $linkAttributes + * + * @return Page The current Page instance + */ + public function setLinkAttributes($linkAttributes) + { + $this->linkAttributes = $linkAttributes; + + return $this; + } + + /** + * Get the label HTML attributes. + * + * @return array + */ + public function getLabelAttributes() + { + return $this->labelAttributes; + } + + /** + * Set the label HTML attributes as associative array. + * + * @param array $labelAttributes + * + * @return Page The current Page instance + */ + public function setLabelAttributes($labelAttributes) + { + $this->labelAttributes = $labelAttributes; + + return $this; + } + + /** + * Whether to display the menu item for this. + * + * @return boolean + */ + public function getDisplay() + { + return $this->display; + } + + /** + * Set whether to display the menu item for this. + * + * @param boolean $display + * + * @return Page The current Page instance + */ + public function setDisplay($display) + { + $this->display = $display; + + return $this; + } + + /** + * Whether to display the child menu items of this page. + * + * @return boolean + */ + public function getDisplayChildren() + { + return $this->displayChildren; + } + + /** + * Set whether to display the child menu items of this page. + * + * @param boolean $displayChildren + * + * @return Page The current Page instance + */ + public function setDisplayChildren($displayChildren) + { + $this->displayChildren = $displayChildren; + + return $this; + } + + /** + * Route method and Menu method - provides menu options merged with the + * route options + * + * {@inheritDoc} + */ + public function getOptions() + { + return parent::getOptions() + array( + 'label' => $this->getLabel(), + 'attributes' => $this->getAttributes(), + 'childrenAttributes' => $this->getChildrenAttributes(), + 'display' => $this->display, + 'displayChildren' => $this->displayChildren, + 'routeParameters' => array(), + 'routeAbsolute' => false, + 'linkAttributes' => $this->linkAttributes, + 'labelAttributes' => $this->labelAttributes, + 'content' => $this, + ); + } } diff --git a/Doctrine/Phpcr/PageRouteProvider.php b/Doctrine/Phpcr/PageRouteProvider.php deleted file mode 100644 index a8ea8e6..0000000 --- a/Doctrine/Phpcr/PageRouteProvider.php +++ /dev/null @@ -1,91 +0,0 @@ -locales = $locales; - } - - protected function getCandidates($url) - { - $dirs = explode('/', ltrim($url, '/')); - if (isset($dirs[0]) && in_array($dirs[0], $this->locales)) { - $this->locale = $dirs[0]; - array_shift($dirs); - $url = '/'.implode('/', $dirs); - - // the normal listener "waits" until the routing completes - // as the locale could be defined inside the route - $this->getObjectManager()->getLocaleChooserStrategy()->setLocale($this->locale); - } - - return parent::getCandidates($url); - } - - protected function configureLocale($route) - { - if ($this->getObjectManager()->isDocumentTranslatable($route)) { - // add locale requirement - if (!$route->getRequirement('_locale')) { - $locales = $this->getObjectManager()->getLocalesFor($route, true); - $route->setRequirement('_locale', implode('|', $locales)); - } - } - } - - public function getRouteCollectionForRequest(Request $request) - { - $collection = parent::getRouteCollectionForRequest($request); - foreach ($collection as $route) { - $this->configureLocale($route); - } - - return $collection; - } - - /** - * {@inheritDoc} - */ - public function getRouteByName($name, $parameters = array()) - { - $route = parent::getRouteByName($name, $parameters); - $this->configureLocale($route); - - return $route; - } -} diff --git a/Model/Page.php b/Model/Page.php deleted file mode 100644 index e5583c0..0000000 --- a/Model/Page.php +++ /dev/null @@ -1,670 +0,0 @@ - 'foobar', 'style' => 'bar: foo') - * - * @var array - */ - protected $attributes = array(); - - /** - * HTML attributes to add to the children list element. - * - * e.g. array('class' => 'foobar', 'style' => 'bar: foo') - * - * @var array - */ - protected $childrenAttributes = array(); - - /** - * HTML attributes to add to items link. - * - * e.g. array('class' => 'foobar', 'style' => 'bar: foo') - * - * @var array - */ - protected $linkAttributes = array(); - - /** - * HTML attributes to add to the items label. - * - * e.g. array('class' => 'foobar', 'style' => 'bar: foo') - * - * @var array - */ - protected $labelAttributes = array(); - - /** - * Set to false to not render a menu item for this. - * - * @var boolean - */ - protected $display = true; - - /** - * Set to false to not render the child menu items of this page. - * - * @var boolean - */ - protected $displayChildren = true; - - /** - * @var string - */ - protected $body; - - /** - * @var \DateTime - */ - protected $createDate; - - /** - * @var \DateTime - */ - protected $publishStartDate; - - /** - * @var \DateTime - */ - protected $publishEndDate; - - /** - * @var boolean - */ - protected $publishable = true; - - /** - * @var boolean - */ - protected $addLocalePattern; - - /** - * @var string - */ - protected $locale; - - /** - * Extra values an application can store along with a page - * @var array - */ - protected $extras = array(); - - /** - * Overwrite to be able to create route without pattern - * - * @param Boolean $addFormatPattern whether to add ".{_format}" to the route pattern - * also implicitly sets a default/require on "_format" to "html" - * @param Boolean $addTrailingSlash whether to add a trailing slash to the route, defaults to not add one - * @param Boolean $addLocalePattern whether to add "/{_locale}" to the route pattern - */ - public function __construct($addFormatPattern = false, $addTrailingSlash = false, $addLocalePattern = false) - { - parent::__construct($addFormatPattern, $addTrailingSlash); - $this->addLocalePattern = $addLocalePattern; - $this->createDate = new \DateTime(); - } - - public function getAddLocalePattern() - { - return $this->addLocalePattern; - } - - public function setAddLocalePattern($addLocalePattern) - { - $this->addLocalePattern = $addLocalePattern; - } - - /** - * {@inheritDoc} - */ - public function getLocale() - { - return $this->locale; - } - - /** - * {@inheritDoc} - */ - public function setLocale($locale) - { - $this->locale = $locale; - } - - /** - * {@inheritDoc} - * - * automatically prepend the _locale to the pattern - * - * @see PageRouteProvider::getCandidates() - */ - public function getStaticPrefix() - { - if (!$this->addLocalePattern) { - return parent::getStaticPrefix(); - } - - $prefix = $this->getPrefix(); - $path = substr(parent::getId(), strlen($prefix)); - $path = $prefix.'/{_locale}'.$path; - - return $this->generateStaticPrefix($path, $this->idPrefix); - } - - /** - * Get the "date" of this page, which is the publishStartDate if set, - * otherwise the createDate. - */ - public function getDate() - { - return $this->publishStartDate ? $this->publishStartDate : $this->createDate; - } - - /** - * {@inheritDoc} - */ - public function getPublishStartDate() - { - return $this->publishStartDate; - } - - /** - * {@inheritDoc} - */ - public function setPublishStartDate(\DateTime $publishStartDate = null) - { - $this->publishStartDate = $publishStartDate; - } - - /** - * {@inheritDoc} - */ - public function getPublishEndDate() - { - return $this->publishEndDate; - } - - /** - * {@inheritDoc} - */ - public function setPublishEndDate(\DateTime $publishEndDate = null) - { - $this->publishEndDate = $publishEndDate; - } - - /** - * {@inheritDoc} - */ - public function isPublishable() - { - return $this->publishable; - } - - /** - * {@inheritDoc} - */ - public function setPublishable($publishable) - { - $this->publishable = $publishable; - } - - /** - * Get extras - a flat key-value hashmap - * - * @return array with only string values - */ - public function getExtras() - { - return $this->extras; - } - - /** - * Set extras - applications can store additional information on a page - * without needing to extend the document class. - * - * @param array $extras a flat key-value hashmap. The values are cast to - * string as PHPCR stores multivalue data with only one data type for - * all values. - */ - public function setExtras($extras) - { - foreach ($extras as $key => $value) { - $extras[$key] = (string) $value; - } - - $this->extras = $extras; - } - - /** - * Add a single key - value pair to extras - * - * @param string $key - * @param string $value - if this is not a string it is cast to one - */ - public function addExtra($key, $value) - { - $this->extras[$key] = (string) $value; - } - - /** - * Remove a single key - value pair from extras, if it was set. - * - * @param string $key - */ - public function removeExtra($key) - { - if (array_key_exists($key, $this->extras)) { - unset($this->extras[$key]); - } - } - - /** - * Return a single extras value for the provided key or the $default if - * the key is not defined. - * - * @param string $key - * @param string|null $default - * - * @return string|null The value at $key or if not existing $default - */ - public function getExtra($key, $default = null) - { - return array_key_exists($key, $this->extras) ? $this->extras[$key] : $default; - } - - /** - * Content method: Get the routes that point to this content - * - * {@inheritDoc} - */ - public function getRoutes() - { - return array($this); - } - - /** - * Menu method: Get child menu nodes. - * - * @return ArrayCollection the child nodes - */ - public function getChildren() - { - return $this->children; - } - - /** - * Menu method: List of child menu nodes - * - * @param object[] $children - */ - public function setChildren($children) - { - $this->children = $children; - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return $this->name; - } - - /** - * Route method: The content of this route is the object itself. - * - * {@inheritDoc} - */ - public function getContent() - { - return $this; - } - - /** - * Never call this, it makes no sense. The SimpleCms Page is its own - * content. - * - * @param $document - * - * @throws LogicException - */ - public function setContent($document) - { - throw new LogicException('Do not set a content for the redirect route. It is its own content.'); - } - - /** - * Menu method: set the menu label - * - * @param string $label - */ - public function setLabel($label) - { - $this->label = $label; - } - - /** - * Menu method: get the label for the menu - * - * @return string - */ - public function getLabel() - { - return $this->label; - } - - /** - * Content method: set the page title - * - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * Content method: get the page title - * - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * Content method: set the page body - * - * @param string $body - */ - public function setBody($body) - { - $this->body = $body; - } - - /** - * Content method: get the page body - * - * @return string - */ - public function getBody() - { - return $this->body; - } - - /** - * Get the creation date - * - * @return \DateTime - */ - public function getCreateDate() - { - return $this->createDate; - } - - /** - * Overwrite the creation date manually - * - * On creation of a Page, the createDate is automatically set to the - * current time. - * - * @param \DateTime $createDate - */ - public function setCreateDate(\DateTime $createDate = null) - { - $this->createDate = $createDate; - } - - /** - * Return the attributes associated with this menu node - * - * @return array - */ - public function getAttributes() - { - return $this->attributes; - } - - /** - * Set the attributes associated with this menu node - * - * @param $attributes array - * - * @return Page The current Page instance - */ - public function setAttributes(array $attributes) - { - $this->attributes = $attributes; - - return $this; - } - - /** - * Return the given attribute, optionally specifying a default value - * - * @param string $name The name of the attribute to return - * @param string $default The value to return if the attribute doesn't exist - * - * @return string - */ - public function getAttribute($name, $default = null) - { - if (isset($this->attributes[$name])) { - return $this->attributes[$name]; - } - - return $default; - } - - /** - * Set the named attribute - * - * @param string $name attribute name - * @param string $value attribute value - * - * @return Page The current Page instance - */ - public function setAttribute($name, $value) - { - $this->attributes[$name] = $value; - - return $this; - } - - /** - * Return the children attributes - * - * @return array - */ - public function getChildrenAttributes() - { - return $this->childrenAttributes; - } - - /** - * Set the children attributes - * - * @param array $attributes - * - * @return Page The current Page instance - */ - public function setChildrenAttributes(array $attributes) - { - $this->childrenAttributes = $attributes; - - return $this; - } - - /** - * Get the link HTML attributes. - * - * @return array - */ - public function getLinkAttributes() - { - return $this->linkAttributes; - } - - /** - * Set the link HTML attributes as associative array. - * - * @param array $linkAttributes - * - * @return Page The current Page instance - */ - public function setLinkAttributes($linkAttributes) - { - $this->linkAttributes = $linkAttributes; - - return $this; - } - - /** - * Get the label HTML attributes. - * - * @return array - */ - public function getLabelAttributes() - { - return $this->labelAttributes; - } - - /** - * Set the label HTML attributes as associative array. - * - * @param array $labelAttributes - * - * @return Page The current Page instance - */ - public function setLabelAttributes($labelAttributes) - { - $this->labelAttributes = $labelAttributes; - - return $this; - } - - /** - * Whether to display the menu item for this. - * - * @return boolean - */ - public function getDisplay() - { - return $this->display; - } - - /** - * Set whether to display the menu item for this. - * - * @param boolean $display - * - * @return Page The current Page instance - */ - public function setDisplay($display) - { - $this->display = $display; - - return $this; - } - - /** - * Whether to display the child menu items of this page. - * - * @return boolean - */ - public function getDisplayChildren() - { - return $this->displayChildren; - } - - /** - * Set whether to display the child menu items of this page. - * - * @param boolean $displayChildren - * - * @return Page The current Page instance - */ - public function setDisplayChildren($displayChildren) - { - $this->displayChildren = $displayChildren; - - return $this; - } - - /** - * Route method and Menu method - provides menu options merged with the - * route options - * - * {@inheritDoc} - */ - public function getOptions() - { - return parent::getOptions() + array( - 'label' => $this->getLabel(), - 'attributes' => $this->getAttributes(), - 'childrenAttributes' => $this->getChildrenAttributes(), - 'display' => $this->display, - 'displayChildren' => $this->displayChildren, - 'routeParameters' => array(), - 'routeAbsolute' => false, - 'linkAttributes' => $this->linkAttributes, - 'labelAttributes' => $this->labelAttributes, - 'content' => $this, - ); - } -} diff --git a/Resources/config/doctrine-model/Page.phpcr.xml b/Resources/config/doctrine-model/Page.phpcr.xml deleted file mode 100644 index 443d990..0000000 --- a/Resources/config/doctrine-model/Page.phpcr.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Resources/config/doctrine-phpcr/MultilangRedirectRoute.phpcr.xml b/Resources/config/doctrine-phpcr/MultilangRedirectRoute.phpcr.xml deleted file mode 100644 index 1836995..0000000 --- a/Resources/config/doctrine-phpcr/MultilangRedirectRoute.phpcr.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/Resources/config/doctrine-phpcr/MultilangRoute.phpcr.xml b/Resources/config/doctrine-phpcr/MultilangRoute.phpcr.xml deleted file mode 100644 index db4d8b4..0000000 --- a/Resources/config/doctrine-phpcr/MultilangRoute.phpcr.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/Resources/config/doctrine-phpcr/Page.phpcr.xml b/Resources/config/doctrine-phpcr/Page.phpcr.xml index db8f209..fb36ef9 100644 --- a/Resources/config/doctrine-phpcr/Page.phpcr.xml +++ b/Resources/config/doctrine-phpcr/Page.phpcr.xml @@ -7,8 +7,24 @@ + + + + + + + + + + + + + + + diff --git a/Resources/config/routing-bc.xml b/Resources/config/routing-bc.xml new file mode 100644 index 0000000..aa16c04 --- /dev/null +++ b/Resources/config/routing-bc.xml @@ -0,0 +1,39 @@ + + + + + + + _template + _controller + %cmf_simple_cms.generic_controller% + + + + type + _controller + %cmf_simple_cms.controllers_by_type% + + + + _content + _controller + %cmf_simple_cms.controllers_by_class% + + + + _content + _controller + + + + + _content + _template + %cmf_simple_cms.templates_by_class% + + + + diff --git a/Resources/config/routing-phpcr.xml b/Resources/config/routing-phpcr.xml deleted file mode 100644 index b3dd976..0000000 --- a/Resources/config/routing-phpcr.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\PageRouteProvider - Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\IdPrefixListener - - - - - - - - - - - - null - %cmf_simple_cms.persistence.phpcr.manager_name% - %cmf_simple_cms.persistence.phpcr.basepath% - - - - %cmf_simple_cms.persistence.phpcr.basepath% - - - - - - diff --git a/Resources/config/routing.xml b/Resources/config/routing.xml deleted file mode 100644 index d0db559..0000000 --- a/Resources/config/routing.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter - Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher - Symfony\Cmf\Bundle\RoutingBundle\Routing\ContentAwareGenerator - - - - - - - - - %cmf_simple_cms.uri_filter_regexp% - - - - - - - - - - - - - From 3d4dcdd0be41d4d851e85ba90ab85b25984ba6e1 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Tue, 1 Apr 2014 22:37:34 +0200 Subject: [PATCH 2/6] adjust admin and configuration, and cleanup tests --- Admin/PageAdmin.php | 55 +++++++++------- CHANGELOG.md | 12 ++++ DependencyInjection/CmfSimpleCmsExtension.php | 54 ---------------- DependencyInjection/Configuration.php | 38 +++-------- Doctrine/Phpcr/Page.php | 34 +++++++--- Migrator/Phpcr/Page.php | 8 +-- Resources/config/admin-phpcr.xml | 5 +- Resources/config/routing-bc.xml | 39 ------------ Resources/config/schema/simplecms-1.1.xsd | 56 +++++++++++++++++ .../translations/CmfSimpleCmsBundle.de.xliff | 24 ------- .../translations/CmfSimpleCmsBundle.en.xliff | 26 +------- .../translations/CmfSimpleCmsBundle.fr.xliff | 24 ------- Tests/Functional/Doctrine/Phpcr/PageTest.php | 13 +++- Tests/Resources/Fixtures/config/config.php | 18 ++++++ Tests/Resources/Fixtures/config/config.xml | 20 ++++++ Tests/Resources/Fixtures/config/config.yml | 12 ++++ Tests/Resources/Fixtures/config/config1.xml | 2 + Tests/Resources/app/config/cmf_core.yml | 13 ++++ Tests/Resources/app/config/cmf_simple_cms.xml | 4 -- .../CmfSimpleCmsExtensionTest.php | 63 +++++++++++++++++++ .../DependencyInjection/ConfigurationTest.php | 62 ++++++++++++++++++ .../DependencyInjection/XmlSchemaTest.php | 41 ++++++++++++ Tests/Unit/Doctrine/Phpcr/PageTest.php | 3 + Tests/WebTest/Admin/PageAdminTest.php | 8 ++- Tests/WebTest/TestApp/HttpStatusCodeTest.php | 8 ++- composer.json | 2 + 26 files changed, 403 insertions(+), 241 deletions(-) delete mode 100644 Resources/config/routing-bc.xml create mode 100644 Resources/config/schema/simplecms-1.1.xsd create mode 100644 Tests/Resources/Fixtures/config/config.php create mode 100644 Tests/Resources/Fixtures/config/config.xml create mode 100644 Tests/Resources/Fixtures/config/config.yml create mode 100644 Tests/Resources/Fixtures/config/config1.xml create mode 100644 Tests/Unit/DependencyInjection/CmfSimpleCmsExtensionTest.php create mode 100644 Tests/Unit/DependencyInjection/ConfigurationTest.php create mode 100644 Tests/Unit/DependencyInjection/XmlSchemaTest.php diff --git a/Admin/PageAdmin.php b/Admin/PageAdmin.php index 11dd287..1c9bb20 100644 --- a/Admin/PageAdmin.php +++ b/Admin/PageAdmin.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ - namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Admin; -use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; +use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; +use Symfony\Cmf\Bundle\RoutingBundle\Admin\RouteAdmin; use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page; -use Symfony\Cmf\Bundle\SimpleCmsBundle\Model\Page as ModelPage; +use Symfony\Component\Form\FormBuilder; -class PageAdmin extends Admin +class PageAdmin extends RouteAdmin { protected $translationDomain = 'CmfSimpleCmsBundle'; @@ -37,32 +37,41 @@ protected function configureListFields(ListMapper $listMapper) { $listMapper ->addIdentifier('path', 'text') - ->add('title', 'text') + ->addIdentifier('title', 'text') ->add('label', 'text') ->add('name', 'text') ->add('createDate', 'date') - ->add('publishStartDate', 'date') - ->add('publishEndDate', 'date') ; } protected function configureFormFields(FormMapper $formMapper) { + parent::configureFormFields($formMapper); + + $formMapper->remove('content'); + + // remap to routeOptions + $formMapper->remove('options'); + $formMapper - ->with('form.group_general') - ->add( - 'parent', - 'doctrine_phpcr_odm_tree', - array('choice_list' => array(), 'select_root_node' => true, 'root_node' => $this->getRootPath()) - ) - ->add('name', 'text') - ->add('label', null, array('required' => false)) - ->add('title') - ->add('createDate') - ->add('addFormatPattern', null, array('required' => false, 'help' => 'form.help_add_format_pattern')) - ->add('addTrailingSlash', null, array('required' => false, 'help' => 'form.help_add_trailing_slash')) - ->add('addLocalePattern', null, array('required' => false, 'help' => 'form.help_add_locale_pattern')) - ->add('body', 'textarea') + ->with('form.group_general', array( + 'translation_domain' => 'CmfSimpleCmsBundle', + )) + ->add('label', null, array('required' => false)) + ->add('title') + ->add('body', 'textarea') + ->add('createDate') + ->end() + ->with('form.group_advanced', array( + 'translation_domain' => 'CmfRoutingBundle', + )) + ->add( + 'routeOptions', + 'sonata_type_immutable_array', + array('keys' => $this->configureFieldsForOptions($this->getSubject()->getRouteOptions()), 'label' => 'form.label_options'), + array('help' => 'form.help_options') + ) + ->end() ; } @@ -98,7 +107,7 @@ public function preUpdate($object) */ protected function ensureOrderByDate($page) { - $items = $page->getParent()->getChildren(); + $items = $page->getParentDocument()->getChildren(); $itemsByDate = array(); /** @var $item Page */ @@ -135,7 +144,7 @@ protected function ensureOrderByDate($page) public function toString($object) { - return $object instanceof ModelPage && $object->getTitle() + return $object instanceof Page && $object->getTitle() ? $object->getTitle() : $this->trans('link_add', array(), 'SonataAdminBundle') ; diff --git a/CHANGELOG.md b/CHANGELOG.md index d71cb53..3736b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ Changelog ========= +* **2014-04-01**: Refactored the RoutingBundle to provide all routing + features needed by SimpleCmsBundle. + * The configuration for document to route/template now all happens under + cmf_routing.dynamic and the route enhancers also apply to simplecms Pages. + You can configure additional base paths where to look for routes in the + cmf_routing.persistence.phpcr.base_routepaths field. + * The configuration for locales is not needed anymore. Configuring it on the + cmf_routing is enough. + * The options for the format pattern, trailing slash and locale pattern are + now moved into the route "options" and the Page Document now takes an + array of options in the constructor instead of boolean flags. + * **2013-11-14**: The Page now supports the menu options that make sense for a page: display, displayChildren, attributes, children|link|labelAttributes. Note that those only affect the menu rendering, not anything else. diff --git a/DependencyInjection/CmfSimpleCmsExtension.php b/DependencyInjection/CmfSimpleCmsExtension.php index 81fc151..47ccec5 100644 --- a/DependencyInjection/CmfSimpleCmsExtension.php +++ b/DependencyInjection/CmfSimpleCmsExtension.php @@ -43,10 +43,6 @@ public function load(array $configs, ContainerBuilder $container) $config = $this->processConfiguration(new Configuration(), $configs); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - if ($config['routing']) { - $this->loadRouting($config['routing'], $loader, $container); - } - if ($config['persistence']['phpcr']) { $this->loadPhpcr($config['persistence']['phpcr'], $loader, $container); @@ -56,56 +52,6 @@ public function load(array $configs, ContainerBuilder $container) } } - protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder $container) - { - if (!empty($config['uri_filter_regexp'])) { - throw new InvalidConfigurationException('cmf_simple.routing.uri_filter_regexp must be configured on cmf_routing.'); - } - - $loader->load('routing-bc.xml'); - - if (!empty($config['generic_controller'])) { - $container->setParameter($this->getAlias() . '.generic_controller', $config['generic_controller']); - $definition = $container->getDefinition($this->getAlias() . '.enhancer.explicit_template'); - $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); - } else { - $container->removeDefinition($this->getAlias() . '.enhancer.explicit_template'); - } - - if (!empty($config['controllers_by_type'])) { - $container->setParameter($this->getAlias() . '.controllers_by_type', $config['controllers_by_type']); - $definition = $container->getDefinition($this->getAlias() . '.enhancer.controllers_by_type'); - $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); - } else { - $container->removeDefinition($this->getAlias() . '.enhancer.controllers_by_type'); - } - - if (!empty($config['controllers_by_class'])) { - $container->setParameter($this->getAlias() . '.controllers_by_class', $config['controllers_by_class']); - $definition = $container->getDefinition($this->getAlias() . '.enhancer.controllers_by_class'); - $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); - } else { - $container->removeDefinition($this->getAlias() . '.enhancer.controllers_by_class'); - } - - if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) { - $controllerForTemplates = array(); - foreach ($config['templates_by_class'] as $key => $value) { - $controllerForTemplates[$key] = $config['generic_controller']; - } - $definition = $container->getDefinition($this->getAlias() . '.enhancer.controller_for_templates_by_class'); - $definition->replaceArgument(2, $controllerForTemplates); - $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); - - $container->setParameter($this->getAlias() . '.templates_by_class', $config['templates_by_class']); - $definition = $container->getDefinition($this->getAlias() . '.enhancer.templates_by_class'); - $definition->addTag('dynamic_router_route_enhancer', array('priority' => -1000)); - } else { - $container->removeDefinition($this->getAlias() . '.enhancer.controller_for_templates_by_class'); - $container->removeDefinition($this->getAlias() . '.enhancer.templates_by_class'); - } - } - protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container) { $loader->load('services-phpcr.xml'); diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index d22d871..5dd9b2e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -58,39 +58,17 @@ public function getConfigTreeBuilder() ->end() ->arrayNode('routing') - ->info('deprecated, configure routing in cmf_routing bundle configuration') - ->fixXmlConfig('controller_by_type', 'controllers_by_type') - ->fixXmlConfig('controller_by_class', 'controllers_by_class') - ->fixXmlConfig('template_by_class', 'templates_by_class') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('generic_controller')->defaultValue('cmf_content.controller:indexAction')->end() - ->scalarNode('content_repository_id')->defaultValue('cmf_routing.content_repository')->end() - ->scalarNode('uri_filter_regexp')->end() - ->arrayNode('controllers_by_type') - ->useAttributeAsKey('type') - ->prototype('scalar')->end() - ->end() - ->arrayNode('controllers_by_class') - ->useAttributeAsKey('alias') - ->prototype('scalar')->end() - ->end() - ->arrayNode('templates_by_class') - ->useAttributeAsKey('alias') - ->prototype('scalar')->end() - ->end() + ->info('removed') + ->beforeNormalization() + ->ifArray() + ->thenInvalid('The routing configuration has moved to cmf_routing.dynamic') ->end() ->end() - ->arrayNode('multilang') - ->info('unused, deprecated') - ->fixXmlConfig('locale') - ->children() - ->arrayNode('locales') - ->isRequired() - ->requiresAtLeastOneElement() - ->prototype('scalar')->end() - ->end() + ->info('removed') + ->beforeNormalization() + ->ifArray() + ->thenInvalid('The locale configuration is not needed anymore') ->end() ->end() ->end() diff --git a/Doctrine/Phpcr/Page.php b/Doctrine/Phpcr/Page.php index fb3d286..792391f 100644 --- a/Doctrine/Phpcr/Page.php +++ b/Doctrine/Phpcr/Page.php @@ -144,19 +144,27 @@ class Page extends Route implements */ protected $extras = array(); - /** - * Additional supported options are: - * - * * add_format_pattern: When set, ".{_format}" is appended to the route pattern. - * Also implicitly sets a default/require on "_format" to "html". - * * add_locale_pattern: When set, "/{_locale}" is prepended to the route pattern. - */ public function __construct(array $options = array()) { parent::__construct($options); $this->createDate = new \DateTime(); - $this->children = new ArrayCollection(); + } + + /** + * @deprecated use getOption('add_locale_pattern') instead + */ + public function getAddLocalePattern() + { + return $this->getOption('add_locale_pattern'); + } + + /** + * @deprecated use setOption('add_locale_pattern', $bool) instead + */ + public function setAddLocalePattern($addLocalePattern) + { + $this->setOption('add_locale_pattern', $addLocalePattern); } /** @@ -645,4 +653,14 @@ public function getOptions() 'content' => $this, ); } + + public function getRouteOptions() + { + return parent::getOptions(); + } + + public function setRouteOptions(array $options) + { + parent::setOptions($options); + } } diff --git a/Migrator/Phpcr/Page.php b/Migrator/Phpcr/Page.php index 27efb55..6acd45d 100644 --- a/Migrator/Phpcr/Page.php +++ b/Migrator/Phpcr/Page.php @@ -31,17 +31,17 @@ class Page implements MigratorInterface { /** - * @var PHPCR\SessionInterface + * @var SessionInterface */ protected $session; /* - * @var Symfony\Component\Console\Output\OutputInterface + * @var OutputInterface */ protected $output; /** - * @var \Doctrine\ODM\PHPCR\DocumentManager + * @var DocumentManager */ protected $dm; @@ -65,7 +65,7 @@ public function init(SessionInterface $session, OutputInterface $output) protected function createPageInstance($className) { - return new $className(true); + return new $className(array('add_format_pattern' => true)); } public function migrate($path = '/', $depth = -1) diff --git a/Resources/config/admin-phpcr.xml b/Resources/config/admin-phpcr.xml index 2cd6a85..352c590 100644 --- a/Resources/config/admin-phpcr.xml +++ b/Resources/config/admin-phpcr.xml @@ -27,12 +27,15 @@ - + %cmf_simple_cms.persistence.phpcr.basepath% %cmf_simple_cms.persistence.phpcr.admin.sort% + + + diff --git a/Resources/config/routing-bc.xml b/Resources/config/routing-bc.xml deleted file mode 100644 index aa16c04..0000000 --- a/Resources/config/routing-bc.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - _template - _controller - %cmf_simple_cms.generic_controller% - - - - type - _controller - %cmf_simple_cms.controllers_by_type% - - - - _content - _controller - %cmf_simple_cms.controllers_by_class% - - - - _content - _controller - - - - - _content - _template - %cmf_simple_cms.templates_by_class% - - - - diff --git a/Resources/config/schema/simplecms-1.1.xsd b/Resources/config/schema/simplecms-1.1.xsd new file mode 100644 index 0000000..558830b --- /dev/null +++ b/Resources/config/schema/simplecms-1.1.xsd @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/translations/CmfSimpleCmsBundle.de.xliff b/Resources/translations/CmfSimpleCmsBundle.de.xliff index ca637cd..e90bba5 100644 --- a/Resources/translations/CmfSimpleCmsBundle.de.xliff +++ b/Resources/translations/CmfSimpleCmsBundle.de.xliff @@ -82,18 +82,6 @@ form.label_create_date Erstellungsdatum - - form.label_add_format_pattern - Formatmuster hinzufügen - - - form.label_add_trailing_slash - Abschließenden Schrägstrich hinzufügen - - - form.label_add_locale_pattern - Sprache hinzufügen - form.label_locale Sprache @@ -102,18 +90,6 @@ form.label_body Inhalt - - form.help_add_format_pattern - Format zu URL hinzufügen: /eine/url.{format}. Wenn nichts angegeben wird ist das Format html. - - - form.help_add_trailing_slash - Die URL hört in diesem Fall mit einem Schrägstrich auf, zum Beispiel /eine/url/. - - - form.help_add_locale_pattern - Die URL enthält in diesem Fall die Sprache: /{locale}/eine/url - diff --git a/Resources/translations/CmfSimpleCmsBundle.en.xliff b/Resources/translations/CmfSimpleCmsBundle.en.xliff index d2441a2..a7e2b85 100644 --- a/Resources/translations/CmfSimpleCmsBundle.en.xliff +++ b/Resources/translations/CmfSimpleCmsBundle.en.xliff @@ -72,7 +72,7 @@ form.label_label - Label + Menu Label form.label_title @@ -82,18 +82,6 @@ form.label_create_date Create date - - form.label_add_format_pattern - Add format pattern - - - form.label_add_trailing_slash - Add trailing slash - - - form.label_add_locale_pattern - Add locale pattern - form.label_locale Locale @@ -102,18 +90,6 @@ form.label_body Content - - form.help_add_format_pattern - Append format to route like /your/route.{format}. Default format is html. - - - form.help_add_trailing_slash - Append a trailing slash to route like /your/route/. - - - form.help_add_locale_pattern - Prepend locale to route like /{locale}/your/route - diff --git a/Resources/translations/CmfSimpleCmsBundle.fr.xliff b/Resources/translations/CmfSimpleCmsBundle.fr.xliff index 12a0dff..31ebb8b 100644 --- a/Resources/translations/CmfSimpleCmsBundle.fr.xliff +++ b/Resources/translations/CmfSimpleCmsBundle.fr.xliff @@ -82,18 +82,6 @@ form.label_create_date Date création - - form.label_add_format_pattern - Ajouter le format - - - form.label_add_trailing_slash - Ajouter le slash final - - - form.label_add_locale_pattern - Ajouter le langage - form.label_locale Langage @@ -101,18 +89,6 @@ form.label_body Contenu - - - form.help_add_format_pattern - Ajoute le format à la route tel que /your/route.{format}. Le format par défaut est html. - - - form.help_add_trailing_slash - Ajoute un slash à la fin de la route tel que /your/route/. - - - form.help_add_locale_pattern - Prefix la route avec le langage tel que /{locale}/your/route diff --git a/Tests/Functional/Doctrine/Phpcr/PageTest.php b/Tests/Functional/Doctrine/Phpcr/PageTest.php index fecaa31..02c085e 100644 --- a/Tests/Functional/Doctrine/Phpcr/PageTest.php +++ b/Tests/Functional/Doctrine/Phpcr/PageTest.php @@ -12,16 +12,23 @@ namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\Functional\Migrator\Phpcr; +use Doctrine\ODM\PHPCR\DocumentManager; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; use Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page; class PageTest extends BaseTestCase { + /** + * @var DocumentManager + */ + private $dm; + private $baseDocument; + public function setUp() { $this->db('PHPCR')->createTestNode(); $this->dm = $this->db('PHPCR')->getOm(); - $this->baseNode = $this->dm->find(null, '/test'); + $this->baseDocument = $this->dm->find(null, '/test'); } public function testPage() @@ -35,7 +42,6 @@ public function testPage() 'publishable' => false, 'publishStartDate' => new \DateTime('2013-06-18'), 'publishEndDate' => new \DateTime('2013-06-18'), - 'addLocalePattern' => true, 'extras' => array( 'extra_1' => 'foobar', 'extra_2' => 'barfoo', @@ -45,7 +51,7 @@ public function testPage() $page = new Page; $refl = new \ReflectionClass($page); - $page->setParent($this->baseNode); + $page->setParentDocument($this->baseDocument); foreach ($data as $key => $value) { $refl = new \ReflectionClass($page); @@ -53,6 +59,7 @@ public function testPage() $prop->setAccessible(true); $prop->setValue($page, $value); } + $page->setOption('add_locale_pattern', true); $this->dm->persist($page); $this->dm->flush(); diff --git a/Tests/Resources/Fixtures/config/config.php b/Tests/Resources/Fixtures/config/config.php new file mode 100644 index 0000000..ce9df56 --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.php @@ -0,0 +1,18 @@ +loadFromExtension('cmf_simple_cms', array( + 'persistence' => array( + 'phpcr' => array( + 'enabled' => true, + 'basepath' => '/cms/simple', + 'manager_registry' => 'doctrine_phpcr', + 'manager_name' => null, + 'document_class' => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page', + 'use_sonata_admin' => true, + 'sonata_admin' => array( + 'sort' => 'asc', + ) + ), + ), + 'use_menu' => false, +)); diff --git a/Tests/Resources/Fixtures/config/config.xml b/Tests/Resources/Fixtures/config/config.xml new file mode 100644 index 0000000..7b5deba --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml new file mode 100644 index 0000000..9afece9 --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.yml @@ -0,0 +1,12 @@ +cmf_simple_cms: + persistence: + phpcr: + enabled: true + basepath: /cms/simple + manager_registry: doctrine_phpcr + manager_name: ~ + document_class: Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page + use_sonata_admin: true + sonata_admin: + sort: asc + use_menu: false diff --git a/Tests/Resources/Fixtures/config/config1.xml b/Tests/Resources/Fixtures/config/config1.xml new file mode 100644 index 0000000..fd9b40a --- /dev/null +++ b/Tests/Resources/Fixtures/config/config1.xml @@ -0,0 +1,2 @@ + + diff --git a/Tests/Resources/app/config/cmf_core.yml b/Tests/Resources/app/config/cmf_core.yml index d97764b..960c1a3 100644 --- a/Tests/Resources/app/config/cmf_core.yml +++ b/Tests/Resources/app/config/cmf_core.yml @@ -1,7 +1,20 @@ cmf_core: multilang: locales: [ en, fr ] + persistence: + phpcr: + enabled: true cmf_routing: + chain: + routers_by_id: + router.default: 200 + cmf_routing.dynamic_router: 100 dynamic: enabled: true + templates_by_class: + Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page: ::layout.html.twig + persistence: + phpcr: + route_basepaths: + - "/test/page" diff --git a/Tests/Resources/app/config/cmf_simple_cms.xml b/Tests/Resources/app/config/cmf_simple_cms.xml index 027564e..90e4a5f 100644 --- a/Tests/Resources/app/config/cmf_simple_cms.xml +++ b/Tests/Resources/app/config/cmf_simple_cms.xml @@ -7,10 +7,6 @@ basepath="/test/page" /> - - - ::layout.html.twig - diff --git a/Tests/Unit/DependencyInjection/CmfSimpleCmsExtensionTest.php b/Tests/Unit/DependencyInjection/CmfSimpleCmsExtensionTest.php new file mode 100644 index 0000000..a3c83df --- /dev/null +++ b/Tests/Unit/DependencyInjection/CmfSimpleCmsExtensionTest.php @@ -0,0 +1,63 @@ +container->setParameter('kernel.bundles', array('CmfRoutingBundle' => true, 'SonataDoctrinePHPCRAdminBundle' => true, 'CmfMenuBundle' => true)); + + $this->load(array( + 'persistence' => array( + 'phpcr' => array( + 'enabled' => true, + ), + ), + )); + + $this->assertContainerBuilderHasService('cmf_simple_cms.initializer', '%cmf_simple_cms.initializer.class%'); + $this->assertContainerBuilderHasService('cmf_simple_cms.persistence.phpcr.migrator.page', '%cmf_simple_cms.persistence.phpcr.migrator_page.class%'); + $this->assertContainerBuilderHasServiceDefinitionWithMethodCall('cmf_simple_cms.persistence.phpcr.menu_provider', 'setManagerName', array( + '%cmf_simple_cms.persistence.phpcr.manager_name%', + )); + $this->assertContainerBuilderHasService('cmf_simple_cms.persistence.phpcr.admin.page', '%cmf_simple_cms.persistence.phpcr.admin.page.class%'); + } + + public function testLoadMinimal() + { + $this->load(array( + 'persistence' => array( + 'phpcr' => array( + 'enabled' => true, + 'use_sonata_admin' => false, + ), + ), + 'use_menu' => false, + )); + + $this->assertFalse($this->container->has('cmf_simple_cms.persistence.phpcr.admin.page')); + $this->assertFalse($this->container->has('cmf_simple_cms.persistence.phpcr.menu_provider')); + } +} diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php new file mode 100644 index 0000000..8559895 --- /dev/null +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -0,0 +1,62 @@ + array( + 'phpcr' => array( + 'enabled' => true, + 'basepath' => '/cms/simple', + 'manager_registry' => 'doctrine_phpcr', + 'manager_name' => null, + 'document_class' => 'Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page', + 'use_sonata_admin' => true, + 'sonata_admin' => array( + 'sort' => 'asc', + ) + ), + ), + 'use_menu' => false, + ); + + $formats = array_map(function ($path) { + return __DIR__.'/../../Resources/Fixtures/'.$path; + }, array( + 'config/config.yml', + 'config/config.xml', + 'config/config.php', + )); + + foreach ($formats as $format) { + $this->assertProcessedConfigurationEquals($expectedConfiguration, array($format)); + } + } +} diff --git a/Tests/Unit/DependencyInjection/XmlSchemaTest.php b/Tests/Unit/DependencyInjection/XmlSchemaTest.php new file mode 100644 index 0000000..531f5ad --- /dev/null +++ b/Tests/Unit/DependencyInjection/XmlSchemaTest.php @@ -0,0 +1,41 @@ +fixturesPath = __DIR__.'/../../Resources/Fixtures/config/'; + $this->schemaPath = __DIR__.'/../../../Resources/config/schema/simplecms-1.1.xsd'; + } + + public function testSchema() + { + $fixturesPath = $this->fixturesPath; + $xmlFiles = array_map(function ($file) use ($fixturesPath) { + return $fixturesPath.$file; + }, array( + 'config.xml', + 'config1.xml', + )); + + $this->assertSchemaAcceptsXml($xmlFiles, $this->schemaPath); + } +} + diff --git a/Tests/Unit/Doctrine/Phpcr/PageTest.php b/Tests/Unit/Doctrine/Phpcr/PageTest.php index be1f64f..b777e7b 100644 --- a/Tests/Unit/Doctrine/Phpcr/PageTest.php +++ b/Tests/Unit/Doctrine/Phpcr/PageTest.php @@ -16,6 +16,9 @@ class PageTest extends \PHPUnit_Framework_TestCase { + /** + * Testing BC + */ public function testGetSet() { $page = new Page; diff --git a/Tests/WebTest/Admin/PageAdminTest.php b/Tests/WebTest/Admin/PageAdminTest.php index 665329e..2e9824b 100644 --- a/Tests/WebTest/Admin/PageAdminTest.php +++ b/Tests/WebTest/Admin/PageAdminTest.php @@ -12,10 +12,16 @@ namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\WebTest\Admin; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; class PageAdminTest extends BaseTestCase { + /** + * @var Client + */ + private $client; + public function setUp() { $this->db('PHPCR')->loadFixtures(array( @@ -69,6 +75,6 @@ public function testPageCreate() $res = $this->client->getResponse(); // If we have a 302 redirect, then all is well - $this->assertEquals(302, $res->getStatusCode()); + $this->assertEquals(302, $res->getStatusCode(), $res); } } diff --git a/Tests/WebTest/TestApp/HttpStatusCodeTest.php b/Tests/WebTest/TestApp/HttpStatusCodeTest.php index f739555..2718891 100644 --- a/Tests/WebTest/TestApp/HttpStatusCodeTest.php +++ b/Tests/WebTest/TestApp/HttpStatusCodeTest.php @@ -12,10 +12,16 @@ namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\WebTest\TestApp; +use Symfony\Bundle\FrameworkBundle\Client; use Symfony\Cmf\Component\Testing\Functional\BaseTestCase; class HttpStatusCodeTest extends BaseTestCase { + /** + * @var Client + */ + private $client; + public function setUp() { $this->db('PHPCR')->loadFixtures(array( @@ -39,7 +45,7 @@ public function provideStatusCodeTest() */ public function testStatusCode($url, $expectedStatusCode = 200) { - $crawler = $this->client->request('GET', $url); + $this->client->request('GET', $url); $res = $this->client->getResponse(); $this->assertEquals($expectedStatusCode, $res->getStatusCode()); } diff --git a/composer.json b/composer.json index 33e9f88..a8a071c 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,8 @@ }, "require-dev": { "symfony-cmf/testing": ">=1.0.0,<1.2-dev", + "matthiasnoback/symfony-dependency-injection-test": "0.*", + "matthiasnoback/symfony-config-test": "0.*", "sonata-project/doctrine-phpcr-admin-bundle": ">=1.0.0,<1.2-dev", "symfony/monolog-bundle": "~2.2" }, From 0ae210f32c1b354ba095c1efa5e21c9de8b4ab06 Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Wed, 2 Apr 2014 10:20:29 +0200 Subject: [PATCH 3/6] improve the error messages --- DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5dd9b2e..6df5d05 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -61,14 +61,14 @@ public function getConfigTreeBuilder() ->info('removed') ->beforeNormalization() ->ifArray() - ->thenInvalid('The routing configuration has moved to cmf_routing.dynamic') + ->thenInvalid('The SimpleCmsBundle routing configuration has moved to cmf_routing.dynamic') ->end() ->end() ->arrayNode('multilang') ->info('removed') ->beforeNormalization() ->ifArray() - ->thenInvalid('The locale configuration is not needed anymore') + ->thenInvalid('The SimpleCmsBundle locale configuration is not needed anymore') ->end() ->end() ->end() From 702576106d83273c7022d62251929d1c2b579e9a Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Wed, 2 Apr 2014 11:55:46 +0200 Subject: [PATCH 4/6] adjust prepend configuration for routing --- CHANGELOG.md | 2 ++ DependencyInjection/CmfSimpleCmsExtension.php | 29 +++++++++++++++++-- Tests/Resources/app/config/cmf_core.yml | 8 ----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3736b47..c047699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ Changelog * **2014-04-01**: Refactored the RoutingBundle to provide all routing features needed by SimpleCmsBundle. + * If you where only using the SimpleCmsBundle you now need to activate + the dynamic router. SimpleCmsBundle automatically does this for you. * The configuration for document to route/template now all happens under cmf_routing.dynamic and the route enhancers also apply to simplecms Pages. You can configure additional base paths where to look for routes in the diff --git a/DependencyInjection/CmfSimpleCmsExtension.php b/DependencyInjection/CmfSimpleCmsExtension.php index 47ccec5..7957a2d 100644 --- a/DependencyInjection/CmfSimpleCmsExtension.php +++ b/DependencyInjection/CmfSimpleCmsExtension.php @@ -32,9 +32,32 @@ class CmfSimpleCmsExtension extends Extension implements PrependExtensionInterfa */ public function prepend(ContainerBuilder $container) { - $prependConfig = array('persistence' => array('phpcr' => (array('enabled' => true)))); - $container->prependExtensionConfig('cmf_menu', $prependConfig); - $prependConfig = array('dynamic' => $prependConfig); + // process the configuration of CmfCoreExtension + $configs = $container->getExtensionConfig($this->getAlias()); + $parameterBag = $container->getParameterBag(); + $configs = $parameterBag->resolveValue($configs); + $config = $this->processConfiguration(new Configuration(), $configs); + + if (empty($config['persistence']['phpcr']['enabled'])) { + return; + } + + $prependConfig = array( + 'chain' => array( + 'routers_by_id' => array( + 'router.default' => 0, + 'cmf_routing.dynamic_router' => -100, + ) + ), + 'dynamic' => array( + 'enabled' => true, + ) + ); + if (isset($config['persistence']['phpcr']['basepath']) + && '/cms/simple' != $config['persistence']['phpcr']['basepath'] + ) { + $prependConfig['dynamic']['persistence']['phpcr']['route_basepaths'] = array($config['persistence']['phpcr']['basepath']); + } $container->prependExtensionConfig('cmf_routing', $prependConfig); } diff --git a/Tests/Resources/app/config/cmf_core.yml b/Tests/Resources/app/config/cmf_core.yml index 960c1a3..78a89bc 100644 --- a/Tests/Resources/app/config/cmf_core.yml +++ b/Tests/Resources/app/config/cmf_core.yml @@ -6,15 +6,7 @@ cmf_core: enabled: true cmf_routing: - chain: - routers_by_id: - router.default: 200 - cmf_routing.dynamic_router: 100 dynamic: enabled: true templates_by_class: Symfony\Cmf\Bundle\SimpleCmsBundle\Doctrine\Phpcr\Page: ::layout.html.twig - persistence: - phpcr: - route_basepaths: - - "/test/page" From b631cd4b340c0a43e4c7f44a5de2de6d5169a61e Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 3 Apr 2014 10:50:25 +0200 Subject: [PATCH 5/6] cleanup test --- Tests/Functional/Doctrine/Phpcr/PageTest.php | 65 ++++++++------------ 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/Tests/Functional/Doctrine/Phpcr/PageTest.php b/Tests/Functional/Doctrine/Phpcr/PageTest.php index 02c085e..16b4298 100644 --- a/Tests/Functional/Doctrine/Phpcr/PageTest.php +++ b/Tests/Functional/Doctrine/Phpcr/PageTest.php @@ -33,33 +33,20 @@ public function setUp() public function testPage() { - $data = array( - 'name' => 'page-name', - 'title' => 'Page Title', - 'label' => 'Page Label', - 'body' => 'This is body', - 'createDate' => new \DateTime('2013-07-05'), - 'publishable' => false, - 'publishStartDate' => new \DateTime('2013-06-18'), - 'publishEndDate' => new \DateTime('2013-06-18'), - 'extras' => array( - 'extra_1' => 'foobar', - 'extra_2' => 'barfoo', - ), - ); - - $page = new Page; - $refl = new \ReflectionClass($page); - + $page = new Page(array('add_locale_pattern' => true)); $page->setParentDocument($this->baseDocument); - - foreach ($data as $key => $value) { - $refl = new \ReflectionClass($page); - $prop = $refl->getProperty($key); - $prop->setAccessible(true); - $prop->setValue($page, $value); - } - $page->setOption('add_locale_pattern', true); + $page->setName('page-name'); + $page->setTitle('Page Title'); + $page->setLabel('Page Label'); + $page->setBody('This is body'); + $page->setCreateDate(new \DateTime('2013-07-05')); + $page->setPublishable(false); + $page->setPublishStartDate(new \DateTime('2013-06-18')); + $page->setPublishEndDate(new \DateTime('2013-06-18')); + $page->setExtras(array( + 'extra_1' => 'foobar', + 'extra_2' => 'barfoo', + )); $this->dm->persist($page); $this->dm->flush(); @@ -68,16 +55,14 @@ public function testPage() $page = $this->dm->find(null, '/test/page-name'); $this->assertNotNull($page); - - foreach ($data as $key => $value) { - $prop = $refl->getProperty($key); - $prop->setAccessible(true); - $v = $prop->getValue($page); - - if (!is_object($value)) { - $this->assertEquals($value, $v); - } - } + $this->assertTrue($page->getOption('add_locale_pattern')); + $this->assertEquals('Page Title', $page->getTitle()); + $this->assertEquals('Page Label', $page->getLabel()); + $this->assertEquals('This is body', $page->getBody()); + $this->assertEquals(array( + 'extra_1' => 'foobar', + 'extra_2' => 'barfoo', + ), $page->getExtras()); // test publish start and end $publishStartDate = $page->getPublishStartDate(); @@ -85,20 +70,22 @@ public function testPage() $this->assertInstanceOf('\DateTime', $publishStartDate); $this->assertInstanceOf('\DateTime', $publishEndDate); - $this->assertEquals($data['publishStartDate']->format('Y-m-d'), $publishStartDate->format('Y-m-d')); - $this->assertEquals($data['publishEndDate']->format('Y-m-d'), $publishEndDate->format('Y-m-d')); + $this->assertEquals('2013-06-18', $publishStartDate->format('Y-m-d')); + $this->assertEquals('2013-06-18', $publishEndDate->format('Y-m-d')); // test multi-lang $page->setLocale('fr'); + $page->setTitle('french'); $this->dm->persist($page); $this->dm->flush(); $this->dm->clear(); $page = $this->dm->findTranslation(null, '/test/page-name', 'fr'); $this->assertEquals('fr', $page->getLocale()); + $this->assertEquals('french', $page->getTitle()); // test node - $node = $page->node; + $node = $page->getNode(); $this->assertInstanceOf('PHPCR\NodeInterface', $node); } } From 9ae1897de42e909d594c39555164789fc9957a96 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Thu, 3 Apr 2014 11:31:00 +0200 Subject: [PATCH 6/6] bumping core-bundle minimal version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a8a071c..5346b60 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "require": { "php": ">=5.3.3", "symfony/framework-bundle": "~2.2", - "symfony-cmf/core-bundle": ">=1.0.0,<1.2-dev", + "symfony-cmf/core-bundle": ">=1.1.0,<1.2-dev", "symfony-cmf/routing-bundle": "1.2.*", "symfony-cmf/menu-bundle": ">=1.0.0,<1.2-dev", "symfony-cmf/content-bundle": ">=1.0.0,<1.2-dev",