Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert another long test to use a dataprovider.

  • Loading branch information...
commit 1487357ba631bc34d19cabc08d93017294268401 1 parent bc40a55
@markstory markstory authored
Showing with 24 additions and 134 deletions.
  1. +24 −134 lib/Cake/Test/Case/Routing/DispatcherTest.php
View
158 lib/Cake/Test/Case/Routing/DispatcherTest.php
@@ -1346,153 +1346,43 @@ public function testAssetFilterForThemeAndPlugins() {
$this->assertFalse($Dispatcher->asset('js/cjs/debug_kit.js', $response));
}
+
/**
- * testFullPageCachingDispatch method
+ * Data provider for cached actions.
*
- * @return void
+ * - Test simple views
+ * - Test views with nocache tags
+ * - Test requests with named + passed params.
+ * - Test themed views.
+ *
+ * @return array
*/
- public function testFullPageCachingDispatch() {
- Configure::write('Cache.disable', false);
- Configure::write('Cache.check', true);
- Configure::write('debug', 2);
-
-
- Router::reload();
- Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
- Router::connect('/:controller/:action/*');
-
- App::build(array(
- 'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS),
- ), true);
-
- $dispatcher = new TestDispatcher();
- $request = new CakeRequest('/');
- $response = new CakeResponse();
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
-
- $filename = $this->__cachePath($request->here);
- unlink($filename);
-
- $request = new CakeRequest('test_cached_pages/index');
- $_POST = array(
- 'slasher' => "Up in your's grill \ '"
+ public static function cacheActionProvider() {
+ return array(
+ array('/'),
+ array('test_cached_pages/index'),
+ array('TestCachedPages/index'),
+ array('test_cached_pages/test_nocache_tags'),
+ array('TestCachedPages/test_nocache_tags'),
+ array('test_cached_pages/view/param/param'),
+ array('test_cached_pages/view/foo:bar/value:goo'),
+ array('test_cached_pages/themed'),
);
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
- $filename = $this->__cachePath($request->here);
- unlink($filename);
-
- $request = new CakeRequest('TestCachedPages/index');
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
- $filename = $this->__cachePath($request->here);
- unlink($filename);
-
- $request = new CakeRequest('TestCachedPages/test_nocache_tags');
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
- $filename = $this->__cachePath($request->here);
- unlink($filename);
-
- $request = new CakeRequest('test_cached_pages/view/param/param');
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
- $filename = $this->__cachePath($request->here);
- unlink($filename);
-
- $request = new CakeRequest('test_cached_pages/view/foo:bar/value:goo');
-
- ob_start();
- $dispatcher->dispatch($request, $response);
- $out = ob_get_clean();
-
- ob_start();
- $dispatcher->cached($request->here);
- $cached = ob_get_clean();
-
- $result = str_replace(array("\t", "\r\n", "\n"), "", $out);
- $cached = preg_replace('/<!--+[^<>]+-->/', '', $cached);
- $expected = str_replace(array("\t", "\r\n", "\n"), "", $cached);
-
- $this->assertEqual($expected, $result);
- $filename = $this->__cachePath($request->here);
- $this->assertTrue(file_exists($filename));
-
- unlink($filename);
}
-
+
/**
- * Test full page caching with themes.
+ * testFullPageCachingDispatch method
*
+ * @dataProvider cacheActionProvider
* @return void
*/
- public function testFullPageCachingWithThemes() {
+ public function testFullPageCachingDispatch($url) {
Configure::write('Cache.disable', false);
Configure::write('Cache.check', true);
Configure::write('debug', 2);
Router::reload();
+ Router::connect('/', array('controller' => 'test_cached_pages', 'action' => 'index'));
Router::connect('/:controller/:action/*');
App::build(array(
@@ -1500,7 +1390,7 @@ public function testFullPageCachingWithThemes() {
), true);
$dispatcher = new TestDispatcher();
- $request = new CakeRequest('/test_cached_pages/themed');
+ $request = new CakeRequest($url);
$response = new CakeResponse();
ob_start();
Please sign in to comment.
Something went wrong with that request. Please try again.