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

Commit e977f7f

Browse files
committed
Merge pull request #160 from symfony-cmf/redirect_migrate
Added test for RedirectMigrate
2 parents 76c2243 + ef3c4e4 commit e977f7f

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 36 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,14 @@ 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+
$this->assertNotNull($autoRoute, 'Autoroute exists for: ' . $newPath);
386+
$this->assertEquals(AutoRouteInterface::TYPE_PRIMARY, $autoRoute->getDefault('type'));
387387
}
388388
}
389389

@@ -409,6 +409,38 @@ public function testLeaveRedirectAndRenameToOriginal()
409409
$this->getDm()->flush();
410410
}
411411

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

0 commit comments

Comments
 (0)