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

Commit

Permalink
Merge pull request #160 from symfony-cmf/redirect_migrate
Browse files Browse the repository at this point in the history
Added test for RedirectMigrate
  • Loading branch information
wouterj committed Sep 6, 2015
2 parents 76c2243 + ef3c4e4 commit e977f7f
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions Tests/Functional/EventListener/AutoRouteListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function provideLeaveRedirect()
array(
'test/auto-route/seo-articles/en/goodbye-everybody',
'test/auto-route/seo-articles/fr/aurevoir-le-monde',
'test/auto-route/seo-articles/de/aud-weidersehn',
'test/auto-route/seo-articles/de/auf-weidersehn',
'test/auto-route/seo-articles/es/adios-todo-el-mundo',
),
),
Expand Down Expand Up @@ -376,14 +376,14 @@ public function testLeaveRedirect($data, $updatedData, $expectedRedirectRoutePat

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

foreach ($expectedAutoRoutePaths as $newPath) {
$autoRoute = $this->getDm()->find(null, $newPath);
$this->assertNotNull($redirectRoute, 'Autoroute exists for: ' . $originalPath);
$this->assertEquals(AutoRouteInterface::TYPE_REDIRECT, $redirectRoute->getDefault('type'));
$this->assertNotNull($autoRoute, 'Autoroute exists for: ' . $newPath);
$this->assertEquals(AutoRouteInterface::TYPE_PRIMARY, $autoRoute->getDefault('type'));
}
}

Expand All @@ -409,6 +409,38 @@ public function testLeaveRedirectAndRenameToOriginal()
$this->getDm()->flush();
}

/**
* Leave direct should migrate children
*/
public function testLeaveRedirectChildrenMigrations()
{
$article1 = new SeoArticle;
$article1->title = 'Hai';
$article1->path = '/test/article-1';
$this->getDm()->persist($article1);
$this->getDm()->flush();

// add a child to the route
$parentRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/hai');
$childRoute = new AutoRoute();
$childRoute->setName('foo');
$childRoute->setParent($parentRoute);
$this->getDm()->persist($childRoute);
$this->getDm()->flush();

$article1->title = 'Ho';
$this->getDm()->persist($article1);
$this->getDm()->flush();

$originalRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/hai');
$this->assertNotNull($originalRoute);
$this->assertCount(0, $this->getDm()->getChildren($originalRoute));

$newRoute = $this->getDm()->find(null, '/test/auto-route/seo-articles/ho');
$this->assertNotNull($newRoute);
$this->assertCount(1, $this->getDm()->getChildren($newRoute));
}

/**
* Ensure that we can map parent classes: #56
*/
Expand Down

0 comments on commit e977f7f

Please sign in to comment.