diff -r 877f952ae2bd -r 6b6c2214f778 web/lib/Zend/Tool/Project/Context/Zf/TestApplicationActionMethod.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/lib/Zend/Tool/Project/Context/Zf/TestApplicationActionMethod.php Thu Mar 21 19:52:38 2013 +0100 @@ -0,0 +1,229 @@ +_forActionName = $this->_resource->getAttribute('forActionName'); + + $this->_resource->setAppendable(false); + $this->_testApplicationControllerResource = $this->_resource->getParentResource(); + if (!$this->_testApplicationControllerResource->getContext() instanceof Zend_Tool_Project_Context_Zf_TestApplicationControllerFile) { + require_once 'Zend/Tool/Project/Context/Exception.php'; + throw new Zend_Tool_Project_Context_Exception('ActionMethod must be a sub resource of a TestApplicationControllerFile'); + } + // make the ControllerFile node appendable so we can tack on the actionMethod. + $this->_resource->getParentResource()->setAppendable(true); + + $this->_testApplicationControllerPath = $this->_testApplicationControllerResource->getContext()->getPath(); + + return $this; + } + + /** + * getPersistentAttributes + * + * @return array + */ + public function getPersistentAttributes() + { + return array( + 'forActionName' => $this->getForActionName() + ); + } + + /** + * getName() + * + * @return string + */ + public function getName() + { + return 'TestApplicationActionMethod'; + } + + /** + * setResource() + * + * @param Zend_Tool_Project_Profile_Resource $resource + * @return Zend_Tool_Project_Context_Zf_ActionMethod + */ + public function setResource(Zend_Tool_Project_Profile_Resource $resource) + { + $this->_resource = $resource; + return $this; + } + + /** + * getActionName() + * + * @return string + */ + public function getForActionName() + { + return $this->_forActionName; + } + + /** + * create() + * + * @return Zend_Tool_Project_Context_Zf_ActionMethod + */ + public function create() + { + $file = $this->_testApplicationControllerPath; + + if (!file_exists($file)) { + require_once 'Zend/Tool/Project/Context/Exception.php'; + throw new Zend_Tool_Project_Context_Exception( + 'Could not create action within test controller ' . $file + . ' with action name ' . $this->_forActionName + ); + } + + $actionParam = $this->getForActionName(); + $controllerParam = $this->_resource->getParentResource()->getForControllerName(); + //$moduleParam = null;// + + /* @var $controllerDirectoryResource Zend_Tool_Project_Profile_Resource */ + $controllerDirectoryResource = $this->_resource->getParentResource()->getParentResource(); + if ($controllerDirectoryResource->getParentResource()->getName() == 'TestApplicationModuleDirectory') { + $moduleParam = $controllerDirectoryResource->getParentResource()->getForModuleName(); + } else { + $moduleParam = 'default'; + } + + + + if ($actionParam == 'index' && $controllerParam == 'Index' && $moduleParam == 'default') { + $assert = '$this->assertQueryContentContains("div#welcome h3", "This is your project\'s main page");'; + } else { + $assert = <<assertQueryContentContains( + 'div#view-content p', + 'View script for controller ' . \$params['controller'] . ' and script/action name ' . \$params['action'] . '' + ); +EOS; + } + + $codeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($file, true, true); + $codeGenFile->getClass()->setMethod(array( + 'name' => 'test' . ucfirst($actionParam) . 'Action', + 'body' => << '$actionParam', 'controller' => '$controllerParam', 'module' => '$moduleParam'); +\$urlParams = \$this->urlizeOptions(\$params); +\$url = \$this->url(\$urlParams); +\$this->dispatch(\$url); + +// assertions +\$this->assertModule(\$urlParams['module']); +\$this->assertController(\$urlParams['controller']); +\$this->assertAction(\$urlParams['action']); +$assert + +EOS + )); + + file_put_contents($file, $codeGenFile->generate()); + + return $this; + } + + /** + * delete() + * + * @return Zend_Tool_Project_Context_Zf_ActionMethod + */ + public function delete() + { + // @todo do this + return $this; + } + + /** + * hasActionMethod() + * + * @param string $controllerPath + * @param string $actionName + * @return bool + */ + /* + public static function hasActionMethod($controllerPath, $actionName) + { + if (!file_exists($controllerPath)) { + return false; + } + + $controllerCodeGenFile = Zend_CodeGenerator_Php_File::fromReflectedFileName($controllerPath, true, true); + return $controllerCodeGenFile->getClass()->hasMethod('test' . $actionName . 'Action'); + } + */ + +} \ No newline at end of file