Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit a91da87

Browse files
committed
Introduced web test case for redirect
1 parent 4d88a0f commit a91da87

File tree

9 files changed

+70
-31
lines changed

9 files changed

+70
-31
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
- SYMFONY_VERSION=dev-master
1212

1313
before_script:
14-
- composer self-update
1514
- composer require symfony/framework-bundle:${SYMFONY_VERSION} --prefer-source
1615
- vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh
1716

Adapter/PhpcrOdmAdapter.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,6 @@ public function migrateAutoRouteChildren(AutoRouteInterface $srcAutoRoute, AutoR
9999
}
100100
}
101101

102-
/**
103-
* {@inheritDoc}
104-
*/
105-
public function removeDefunctRoute(AutoRouteInterface $autoRoute, $newRoute)
106-
{
107-
$session = $this->dm->getPhpcrSession();
108-
try {
109-
$node = $this->dm->getNodeForDocument($autoRoute);
110-
$newNode = $this->dm->getNodeForDocument($newRoute);
111-
} catch (InvalidItemStateException $e) {
112-
// nothing ..
113-
}
114-
115-
$session->save();
116-
}
117-
118102
/**
119103
* {@inheritDoc}
120104
*/
@@ -165,7 +149,6 @@ public function createRedirectRoute(AutoRouteInterface $referringAutoRoute, Auto
165149
{
166150
$referringAutoRoute->setRedirectTarget($newRoute);
167151
$referringAutoRoute->setType(AutoRouteInterface::TYPE_REDIRECT);
168-
$this->dm->persist($referringAutoRoute);
169152
}
170153

171154
/**

Model/AutoRoute.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AutoRoute extends Route implements AutoRouteInterface
2727
/**
2828
* @var AutoRouteInterface
2929
*/
30-
protected $redirectTarget;
30+
protected $redirectRoute;
3131

3232
/**
3333
* {@inheritDoc}
@@ -50,8 +50,13 @@ public function setType($type)
5050
$this->setDefault('type', $type);
5151
}
5252

53-
public function setRedirectTarget(AutoRouteInterface $redirectTarget)
53+
public function setRedirectTarget(AutoRouteInterface $redirectRoute)
5454
{
55-
$this->redirectTarget = $redirectTarget;
55+
$this->redirectRoute = $redirectRoute;
56+
}
57+
58+
public function getRedirectTarget()
59+
{
60+
return $this->redirectRoute;
5661
}
5762
}

Resources/config/doctrine-model/AutoRoute.phpcr.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
33

44
<document name="Symfony\Cmf\Bundle\RoutingAutoBundle\Model\AutoRoute">
5-
<reference-one name="redirectTarget"/>
5+
<reference-one name="redirectRoute"/>
66
</document>
77

88
</doctrine-mapping>

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,19 +386,16 @@ public function testLeaveRedirect($data, $updatedData, $expectedRedirectRoutePat
386386
}
387387

388388
/**
389-
* depends testLeaveRedirect
389+
* @depends testLeaveRedirect
390390
*
391391
* See https://github.com/symfony-cmf/RoutingAutoBundle/issues/111
392392
*/
393-
public function testLLeaveRedirectAndRenameToOriginal()
393+
public function testLeaveRedirectAndRenameToOriginal()
394394
{
395395
$article = new SeoArticle;
396396
$article->title = 'Hai';
397397
$article->path = '/test/article-1';
398398
$this->getDm()->persist($article);
399-
400-
$this->getDm()->persist($article);
401-
402399
$this->getDm()->flush();
403400

404401
$article->title = 'Ho';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Controller;
4+
5+
use Symfony\Cmf\Component\RoutingAuto\Model\AutoRouteInterface;
6+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7+
8+
class TestController extends Controller
9+
{
10+
public function redirectAction(AutoRouteInterface $routeDocument)
11+
{
12+
$routeTarget = $routeDocument->getRedirectTarget();
13+
return $this->redirect($this->get('router')->generate($routeTarget));
14+
}
15+
}

Tests/Resources/app/config/app_config.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@ cmf_routing:
66
dynamic:
77
enabled: true
88
controllers_by_type:
9-
demo_alias: test.controller:aliasAction
10-
controllers_by_class:
11-
Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\RedirectRoute: cmf_routing.redirect_controller:redirectAction
9+
cmf_routing_auto.redirect: Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Controller\TestController::redirectAction
1210
persistence:
1311
phpcr:
1412
enabled: true
15-
route_basepath: /test/routing
13+
route_basepath: /test/auto-route
1614

1715
cmf_routing_auto:
1816
auto_mapping: false
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Symfony\Component\Routing\RouteCollection;
4+
5+
$collection = new RouteCollection();
6+
7+
return $collection;

Tests/WebTest/RedirectTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\WebTest;
4+
5+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\SeoArticle;
6+
use Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Functional\BaseTestCase;
7+
8+
class RedirectTest extends BaseTestCase
9+
{
10+
public function setUp(array $options = array(), $routebase = null)
11+
{
12+
parent::setUp($options, $routebase);
13+
$this->client = $this->createClient();
14+
15+
$article = new SeoArticle();
16+
$article->title = 'SEO Article';
17+
$article->path = '/test/article-1';
18+
19+
$this->getDm()->persist($article);
20+
$this->getDm()->flush();
21+
}
22+
23+
public function testRedirect()
24+
{
25+
$article = $this->getDm()->find(null, '/test/article-1');
26+
$this->assertNotNull($article);
27+
$article->title = 'Renamed Article';
28+
$this->getDm()->flush();
29+
30+
$this->client->request('GET', '/seo-articles/seo-article');
31+
$resp = $this->client->getResponse();
32+
$this->assertEquals(302, $resp->getStatusCode());
33+
$this->assertContains('Redirecting to <a href="/seo-articles/renamed-article">/seo-articles/renamed-article</a>', $resp->getContent());
34+
}
35+
}

0 commit comments

Comments
 (0)