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

Commit 8871811

Browse files
committed
Added passing test for updating blog with posts
1 parent 2b5c5ea commit 8871811

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Tests/Functional/EventListener/AutoRouteListenerTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,31 @@ public function testPersistBlog()
4444
$this->assertEquals('unit-testing-blog', $routes[0]->getName());
4545
}
4646

47-
public function testUpdateBlog()
47+
public function provideTestUpdateBlog()
4848
{
49-
$this->createBlog();
49+
return array(
50+
array(false),
51+
array(true),
52+
);
53+
}
54+
55+
/**
56+
* @dataProvider provideTestUpdateBlog
57+
*/
58+
public function testUpdateBlog($withPosts = false)
59+
{
60+
$this->createBlog($withPosts);
5061

5162
$blog = $this->getDm()->find(null, '/test/test-blog');
5263
// test update
5364
$blog->title = 'Foobar';
5465
$this->getDm()->persist($blog);
5566
$this->getDm()->flush();
5667

68+
// note: The NAME stays the same, its the ID not the title
5769
$blog = $this->getDm()->find(null, '/test/test-blog');
70+
$this->assertNotNull($blog);
71+
5872
$routes = $blog->routes;
5973

6074
$this->assertCount(1, $routes);
@@ -64,6 +78,16 @@ public function testUpdateBlog()
6478

6579
$this->assertEquals('foobar', $routes[0]->getName());
6680
$this->assertEquals('/test/auto-route/blog/foobar', $routes[0]->getId());
81+
82+
if ($withPosts) {
83+
$post = $this->getDm()->find(null, '/test/test-blog/This is a post title');
84+
$this->assertNotNull($post);
85+
86+
$routes = $post->routes;
87+
$this->getDm()->refresh($routes[0]);
88+
89+
$this->assertEquals('/test/auto-route/blog/foobar/2013/03/21/this-is-a-post-title', $routes[0]->getId());
90+
}
6791
}
6892

6993
public function testRemoveBlog()

0 commit comments

Comments
 (0)