Skip to content

[WIP] add webtests, first try frontend test #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ before_script:
- composer self-update
- echo 'memory_limit = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source
- vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh

script: phpunit --coverage-text

Expand Down
64 changes: 64 additions & 0 deletions Tests/Resources/DataFixtures/Phpcr/LoadFrontendRouteData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/


namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\Resources\DataFixtures\PHPCR;

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use PHPCR\Util\NodeHelper;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute;
use Doctrine\ODM\PHPCR\Document\Generic;

class LoadFrontendRouteData implements FixtureInterface
{
public function load(ObjectManager $manager)
{
NodeHelper::createPath($manager->getPhpcrSession(), '/test');
$root = $manager->find(null, '/test');
$parent = new Generic;
$parent->setParent($root);
$parent->setNodename('routing');
$manager->persist($parent);

//create two prefixes as new candidates
$candidateOne = new Generic;
$candidateOne->setParent($parent);
$candidateOne->setNodename('candidate-1');
$manager->persist($candidateOne);

$candidateTwo = new Generic;
$candidateTwo->setParent($parent);
$candidateTwo->setNodename('candidate-2');
$manager->persist($candidateTwo);

$route = new Route;
$route->setParentDocument($candidateOne);
$route->setName('route-in-candidate-1');
$route->setStaticPrefix('/test/routing/candidate-1');
$manager->persist($route);

$route = new Route;
$route->setParentDocument($candidateTwo);
$route->setStaticPrefix('/test/routing/candidate-2');
$route->setName('route-in-candidate-2');
$manager->persist($route);

$redirectRoute = new RedirectRoute;
$redirectRoute->setParentDocument($candidateOne);
$redirectRoute->setName('redirect-route-1');
$manager->persist($redirectRoute);

$manager->flush();
}
}
17 changes: 17 additions & 0 deletions Tests/Unit/Doctrine/Phpcr/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ public function testGetRouteChildrenNull()
$res = $this->route->getRouteChildren();
$this->assertEquals(array(), $res);
}

public function testRouteGetPathWithPrefix()
{
$route = new Route();
$route->setId('/cms/routes/my-route');
$route->setPrefix('/cms/routes');

$this->assertEquals('/my-route', $route->getPath());
}

public function testRouteGetPath()
{
$route = new Route();
$route->setId('/cms/routes/my-route');

$this->assertEquals('/my-route', $route->getPath());
}
}
31 changes: 31 additions & 0 deletions Tests/WebTest/FrontendWebTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Symfony\Cmf\Bundle\RoutingBundle\Tests\WebTest;


use Symfony\Cmf\Component\Testing\Functional\BaseTestCase;

class FrontendWebTest extends BaseTestCase
{
public function setUp()
{
$this->db('PHPCR')->loadFixtures(array(
'Symfony\Cmf\Bundle\SeoBundle\Tests\Resources\DataFixtures\Phpcr\LoadContentData',
));
$this->client = $this->createClient();
}

public function testCandidateRoutes()
{
$this->client->request('GET', '/route-in-candidate-1');
$res = $this->client->getResponse();

$this->assertEquals(200, $res->getStatusCode());

$this->client->request('GET', '/route-in-candidate-2');
$res = $this->client->getResponse();

$this->assertEquals(200, $res->getStatusCode());
}
}

5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
<testsuite name="orm">
<directory>./Tests/Functional/Doctrine/Orm</directory>
</testsuite>

<testsuite name="WebTest">
<directory>./Tests/WebTest</directory>
</testsuite>

</testsuites>

<filter>
Expand Down