浏览代码

added tests

chris 11 年之前
父节点
当前提交
f7c6658d3a
共有 2 个文件被更改,包括 25 次插入2 次删除
  1. 5 2
      Controller/Component/AjaxComponent.php
  2. 20 0
      Test/Case/Controller/Component/AjaxComponentTest.php

+ 5 - 2
Controller/Component/AjaxComponent.php

@@ -112,8 +112,11 @@ class AjaxComponent extends Component {
 
 
 		$this->Controller->autoRender = true;
 		$this->Controller->autoRender = true;
 		$this->Controller->set('_redirect', compact('url', 'status', 'exit'));
 		$this->Controller->set('_redirect', compact('url', 'status', 'exit'));
-		$content = $this->Controller->viewVars;
-		$this->Controller->set('_serialize', array('_redirect', 'content'));
+		$content = array();
+		if (!empty($this->Controller->viewVars['_serialize'])) {
+			$content = $this->Controller->viewVars['_serialize'];
+		}
+		$this->Controller->set('_serialize', array_merge(array('_redirect'), $content));
 
 
 		return false;
 		return false;
 	}
 	}

+ 20 - 0
Test/Case/Controller/Component/AjaxComponentTest.php

@@ -130,6 +130,26 @@ class AjaxComponentTest extends CakeTestCase {
 		$this->assertNull($session);
 		$this->assertNull($session);
 	}
 	}
 
 
+	/**
+	 * AjaxComponentTest::testSetVars()
+	 *
+	 * @return void
+	 */
+	public function testSetVars() {
+		$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
+
+		$this->Controller->Components->unload('Ajax');
+
+		$content = array('id' => 1, 'title' => 'title');
+		$this->Controller->set(compact('content'));
+		$this->Controller->set('_serialize', array('content'));
+
+		$this->Controller->Components->load('Tools.Ajax');
+		$this->assertNotEmpty($this->Controller->viewVars);
+		$this->assertNotEmpty($this->Controller->viewVars['_serialize']);
+		$this->assertEquals('content', $this->Controller->viewVars['_serialize'][0]);
+	}
+
 }
 }
 
 
 // Use Controller instead of AppController to avoid conflicts
 // Use Controller instead of AppController to avoid conflicts