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

Commit 2955d3f

Browse files
committed
Added test for RedirectMigrate
1 parent 76c2243 commit 2955d3f

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public function provideLeaveRedirect()
341341
array(
342342
'test/auto-route/seo-articles/en/goodbye-everybody',
343343
'test/auto-route/seo-articles/fr/aurevoir-le-monde',
344-
'test/auto-route/seo-articles/de/aud-weidersehn',
344+
'test/auto-route/seo-articles/de/auf-weidersehn',
345345
'test/auto-route/seo-articles/es/adios-todo-el-mundo',
346346
),
347347
),
@@ -376,14 +376,17 @@ public function testLeaveRedirect($data, $updatedData, $expectedRedirectRoutePat
376376

377377
foreach ($expectedRedirectRoutePaths as $originalPath) {
378378
$redirectRoute = $this->getDm()->find(null, $originalPath);
379-
$this->assertNotNull($redirectRoute, 'Autoroute exists for: ' . $originalPath);
379+
$this->assertNotNull($redirectRoute, 'Redirect exists for: ' . $originalPath);
380380
$this->assertEquals(AutoRouteInterface::TYPE_REDIRECT, $redirectRoute->getDefault('type'));
381381
}
382382

383383
foreach ($expectedAutoRoutePaths as $newPath) {
384384
$autoRoute = $this->getDm()->find(null, $newPath);
385-
$this->assertNotNull($redirectRoute, 'Autoroute exists for: ' . $originalPath);
386-
$this->assertEquals(AutoRouteInterface::TYPE_REDIRECT, $redirectRoute->getDefault('type'));
385+
if (null === $autoRoute) {
386+
var_dump($newPath);die();;
387+
}
388+
$this->assertNotNull($autoRoute, 'Autoroute exists for: ' . $newPath);
389+
$this->assertEquals(AutoRouteInterface::TYPE_PRIMARY, $autoRoute->getDefault('type'));
387390
}
388391
}
389392

@@ -409,6 +412,38 @@ public function testLeaveRedirectAndRenameToOriginal()
409412
$this->getDm()->flush();
410413
}
411414

415+
/**
416+
* Leave direct should migrate children
417+
*/
418+
public function testLeaveRedirectChildrenMigrations()
419+
{
420+
$article1 = new SeoArticle;
421+
$article1->title = 'Hai';
422+
$article1->path = '/test/article-1';
423+
$this->getDm()->persist($article1);
424+
$this->getDm()->flush();
425+
426+
// add a child to the route
427+
$parentRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/hai');
428+
$childRoute = new AutoRoute();
429+
$childRoute->setName('foo');
430+
$childRoute->setParent($parentRoute);
431+
$this->getDm()->persist($childRoute);
432+
$this->getDm()->flush();
433+
434+
$article1->title = 'Ho';
435+
$this->getDm()->persist($article1);
436+
$this->getDm()->flush();
437+
438+
$originalRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/hai');
439+
$this->assertNotNull($originalRoute);
440+
$this->assertCount(0, $this->getDm()->getChildren($originalRoute));
441+
442+
$newRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/ho');
443+
$this->assertNotNull($newRoute);
444+
$this->assertCount(1, $this->getDm()->getChildren($newRoute));
445+
}
446+
412447
/**
413448
* Ensure that we can map parent classes: #56
414449
*/

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"prefer-stable": true,
1414
"require": {
1515
"php": ">=5.3.9",
16-
"symfony-cmf/routing-auto": "~1.1",
16+
"symfony-cmf/routing-auto": "dev-redirect_migrate",
1717
"symfony-cmf/routing-bundle": "~1.2,>=1.2.0",
1818
"symfony-cmf/core-bundle": "~1.2",
1919
"aferrandini/urlizer": "1.0.*",

0 commit comments

Comments
 (0)