Skip to content

Commit 282002e

Browse files
committed
Added admin tests
1 parent b9f5306 commit 282002e

File tree

13 files changed

+153
-39
lines changed

13 files changed

+153
-39
lines changed

Admin/PageAdmin.php

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class PageAdmin extends Admin
1616
{
1717
protected $translationDomain = 'CmfSimpleCmsBundle';
1818

19+
protected $baseRouteName = 'cmf_simplecms_page';
20+
protected $baseRoutePattern = '/cmf/simplecms/page';
21+
1922
private $sortOrder = false;
2023

2124
public function setSortOrder($sortOrder)
@@ -51,41 +54,10 @@ protected function configureFormFields(FormMapper $formMapper)
5154
->add('label', null, array('required' => false))
5255
->add('title')
5356
->add('createDate')
54-
->add('publishStartDate', null, array('required' => false))
55-
->add('publishEndDate', null, array('required' => false))
5657
->add('body', 'textarea')
5758
;
5859
}
5960

60-
protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
61-
{
62-
if (!in_array($action, array('edit', 'create'))) {
63-
return;
64-
}
65-
66-
$menu->addChild(
67-
$this->trans('sidemenu.publish_start_end_date')
68-
);
69-
70-
$menu->addChild(
71-
$this->trans('sidemenu.end_date_disable')
72-
);
73-
74-
if ('edit' == $action) {
75-
$page = $this->getSubject();
76-
$uri = $this->routeGenerator->generate($page);
77-
if ($page instanceof MultilangPage) {
78-
$uri.= '#'.$page->getTitle();
79-
}
80-
81-
$menu->addChild(
82-
$this->trans('sidemenu.review'),
83-
array('uri' => $uri)
84-
);
85-
}
86-
87-
}
88-
8961
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
9062
{
9163
$datagridMapper

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Changelog
22
=========
33

4+
* **2013-08-04**: Changed name of Sonata route names / patterns - now /admin/cmf/simplecms/foo instead of /admin/bundle/simplecms/foo
5+
46
1.0.0-beta3
57
-----------
68

DependencyInjection/CmfSimpleCmsExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public function load(array $configs, ContainerBuilder $container)
3737
$container->setParameter($this->getAlias() . '.menu_basepath', PathHelper::getParentPath($config['basepath']));
3838
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['routing']['uri_filter_regexp']);
3939

40-
$loader->load('services/routing.xml');
41-
$loader->load('services/migrator.xml');
40+
$loader->load('routing.xml');
41+
$loader->load('migrator.xml');
4242

4343
$dynamic = $container->getDefinition($this->getAlias().'.dynamic_router');
4444

@@ -113,7 +113,7 @@ protected function loadMenu($config, XmlFileLoader $loader, ContainerBuilder $co
113113
return;
114114
}
115115

116-
$loader->load('services/menu.xml');
116+
$loader->load('menu.xml');
117117
}
118118

119119
protected function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilder $container)
@@ -129,7 +129,7 @@ protected function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuil
129129
: false
130130
);
131131

132-
$loader->load('services/admin.xml');
132+
$loader->load('admin.xml');
133133
}
134134

135135
/**

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function getConfigTreeBuilder()
3838
->fixXmlConfig('controller_by_alias', 'controllers_by_alias')
3939
->fixXmlConfig('controller_by_class', 'controllers_by_class')
4040
->fixXmlConfig('template_by_class', 'templates_by_class')
41+
->addDefaultsIfNotSet()
4142
->children()
4243
->scalarNode('content_repository_id')->defaultValue('cmf_routing.content_repository')->end()
4344
->scalarNode('uri_filter_regexp')->defaultValue('')->end()

Migrator/Page.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
use Doctrine\Bundle\PHPCRBundle\Migrator\MigratorInterface;
1414
use Doctrine\ODM\PHPCR\DocumentManager;
1515

16-
// dan: What does this do ??
16+
/**
17+
* Doctrine migrator for pages
18+
*
19+
* Provides a way of creating and maintaining pages from YAML files.
20+
*/
1721
class Page implements MigratorInterface
1822
{
1923
/**

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Symfony CMF SimpleCmsBundle Bundle
1+
# Symfony CMF SimpleCms Bundle
22

33
[![Build Status](https://secure.travis-ci.org/symfony-cmf/SimpleCmsBundle.png)](http://travis-ci.org/symfony-cmf/SimpleCmsBundle)
44
[![Latest Stable Version](https://poser.pugx.org/symfony-cmf/simple-cms-bundle/version.png)](https://packagist.org/packages/symfony-cmf/simple-cms-bundle)
@@ -29,7 +29,7 @@ See also:
2929
## Contributing
3030

3131
Pull requests are welcome. Please see our
32-
[CONTRIBUTING](https://github.com/symfony-cmf/symfony-cmf/blob/master/CONTRIBUTING.md)
32+
[CONTRIBUTING](https://github.com/symfony-cmf/SimpleCmsBundle/blob/master/CONTRIBUTING.md)
3333
guide.
3434

3535
Unit and/or functional tests exist for this bundle. See the
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\Resources\DataFixtures\Phpcr;
4+
5+
use Doctrine\Common\DataFixtures\FixtureInterface;
6+
use Doctrine\Common\Persistence\ObjectManager;
7+
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
8+
use Doctrine\ODM\PHPCR\Document\Generic;
9+
use Symfony\Cmf\Bundle\SimpleCmsBundle\Document\Page;
10+
11+
class LoadPageData implements FixtureInterface, DependentFixtureInterface
12+
{
13+
public function getDependencies()
14+
{
15+
return array(
16+
'Symfony\Cmf\Component\Testing\DataFixtures\PHPCR\LoadBaseData',
17+
);
18+
}
19+
20+
public function load(ObjectManager $manager)
21+
{
22+
$root = $manager->find(null, '/test');
23+
$base = new Generic;
24+
$base->setNodename('page');
25+
$base->setParent($root);
26+
$manager->persist($base);
27+
28+
$page = new Page;
29+
$page->setName('homepage');
30+
$page->setTitle('Homepage');
31+
$page->setLabel('homepage');
32+
$page->setPublishable(true);
33+
$page->setParent($base);
34+
35+
$manager->persist($page);
36+
37+
$manager->flush();
38+
}
39+
}

Tests/Resources/app/AppKernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function configure()
1616
$this->addBundles(array(
1717
new \Symfony\Cmf\Bundle\SimpleCmsBundle\CmfSimpleCmsBundle(),
1818
new \Symfony\Cmf\Bundle\MenuBundle\CmfMenuBundle(),
19-
new \Symfony\Cmf\Bundle\MenuBundle\CmfRoutingBundle(),
19+
new \Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle(),
20+
new \Symfony\Cmf\Bundle\CoreBundle\CmfCoreBundle(),
2021
));
2122
}
2223

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services">
3+
4+
<config xmlns="http://cmf.symfony.com/schema/dic/simplecms"
5+
basepath="/test/page"
6+
>
7+
</config>
8+
9+
</container>
10+

Tests/Resources/app/config/config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
$loader->import(CMF_TEST_CONFIG_DIR.'/default.php');
4+
$loader->import(CMF_TEST_CONFIG_DIR.'/phpcr_odm.php');
5+
$loader->import(CMF_TEST_CONFIG_DIR.'/sonata_admin.php');
6+
$loader->import(__DIR__.'/cmf_simple_cms.xml');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Symfony\Component\Routing\RouteCollection;
4+
5+
$collection = new RouteCollection();
6+
$collection->addCollection(
7+
$loader->import(CMF_TEST_CONFIG_DIR.'/routing/sonata_routing.yml')
8+
);
9+
//$collection->addCollection(
10+
// $loader->import(__DIR__.'/routing/my_test_routing.yml')
11+
//);
12+
13+
return $collection;

Tests/WebTest/Admin/PageAdminTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\WebTest\Admin;
4+
5+
use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;
6+
7+
class PageAdminTest extends BaseTestCase
8+
{
9+
public function setUp()
10+
{
11+
$this->db('PHPCR')->loadFixtures(array(
12+
'Symfony\Cmf\Bundle\SimpleCmsBundle\Tests\Resources\DataFixtures\Phpcr\LoadPageData',
13+
));
14+
$this->client = $this->createClient();
15+
}
16+
17+
public function testPageList()
18+
{
19+
$crawler = $this->client->request('GET', '/admin/cmf/simplecms/page/list');
20+
$res = $this->client->getResponse();
21+
$this->assertEquals(200, $res->getStatusCode());
22+
$this->assertCount(1, $crawler->filter('html:contains("homepage")'));
23+
}
24+
25+
public function testPageEdit()
26+
{
27+
$crawler = $this->client->request('GET', '/admin/cmf/simplecms/page/test/pages/homepage/edit');
28+
$res = $this->client->getResponse();
29+
$this->assertEquals(200, $res->getStatusCode());
30+
$this->assertCount(1, $crawler->filter('input[value="homepage"]'));
31+
}
32+
33+
public function testPageShow()
34+
{
35+
return;
36+
$crawler = $this->client->request('GET', '/admin/cmf/simplecms/page/test/pages/homepage/show');
37+
$res = $this->client->getResponse();
38+
$this->assertEquals(200, $res->getStatusCode());
39+
$this->assertCount(2, $crawler->filter('td:contains("test-page")'));
40+
}
41+
42+
public function testPageCreate()
43+
{
44+
$crawler = $this->client->request('GET', '/admin/cmf/simplecms/page/create');
45+
$res = $this->client->getResponse();
46+
$this->assertEquals(200, $res->getStatusCode());
47+
48+
$button = $crawler->selectButton('Create');
49+
$form = $button->form();
50+
$node = $form->getFormNode();
51+
$actionUrl = $node->getAttribute('action');
52+
$uniqId = substr(strchr($actionUrl, '='), 1);
53+
54+
$form[$uniqId.'[parent]'] = '/test/pages';
55+
$form[$uniqId.'[title]'] = 'foo-page';
56+
$form[$uniqId.'[label]'] = 'Foo Page';
57+
58+
$this->client->submit($form);
59+
$res = $this->client->getResponse();
60+
61+
// If we have a 302 redirect, then all is well
62+
$this->assertEquals(302, $res->getStatusCode());
63+
}
64+
}

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"symfony/framework-bundle": "~2.2",
1818
"symfony-cmf/core-bundle": "~1.0.0-RC1",
1919
"symfony-cmf/routing-bundle": "~1.1.0-RC1",
20+
"symfony-cmf/menu-bundle": "~1.0.0-RC1",
2021
"symfony-cmf/content-bundle": "~1.0.0-RC1",
22+
"symfony-cmf/core-bundle": "~1.0.0-RC1",
2123
"doctrine/phpcr-bundle": "1.0.*",
2224
"doctrine/phpcr-odm": "1.0.*"
2325
},

0 commit comments

Comments
 (0)