ソースを参照

Add asserts for template/layout.

mark_story 11 年 前
コミット
e35b8085f2

+ 28 - 0
src/TestSuite/IntegrationTestCase.php

@@ -438,4 +438,32 @@ class IntegrationTestCase extends TestCase {
 		$this->assertContains($content, $this->_response->body(), $message);
 	}
 
+/**
+ * Assert that the search string was in the template name.
+ *
+ * @param string $file The content to check for.
+ * @param string $message The failure message that will be appended to the generated message.
+ * @return void
+ */
+	public function assertTemplate($content, $message = '') {
+		if (!$this->_viewName) {
+			$this->fail('No view name stored. ' . $message);
+		}
+		$this->assertContains($content, $this->_viewName, $message);
+	}
+
+/**
+ * Assert that the search string was in the layout name.
+ *
+ * @param string $file The content to check for.
+ * @param string $message The failure message that will be appended to the generated message.
+ * @return void
+ */
+	public function assertLayout($content, $message = '') {
+		if (!$this->_layoutName) {
+			$this->fail('No layout name stored. ' . $message);
+		}
+		$this->assertContains($content, $this->_layoutName, $message);
+	}
+
 }

+ 5 - 0
tests/TestCase/TestSuite/IntegrationTestCaseTest.php

@@ -85,10 +85,15 @@ class IntegrationTestCaseTest extends IntegrationTestCase {
 		$this->assertInstanceOf('Cake\Controller\Controller', $this->_controller);
 		$this->assertContains('Template' . DS . 'Posts' . DS . 'index.ctp', $this->_viewName);
 		$this->assertContains('Template' . DS . 'Layout' . DS . 'default.ctp', $this->_layoutName);
+
+		$this->assertTemplate('index');
+		$this->assertLayout('default');
 	}
 
 /**
+ * Test error handling and error page rendering.
  *
+ * @return void
  */
 	public function testPostAndErrorHandling() {
 		$this->post('/request_action/error_method');