[TYPO3-mvc] Unit test controller+view
Fernando Arconada
falcifer2001 at yahoo.es
Fri Dec 10 12:36:16 CET 2010
Hello
I'm trying to code a unit test to validate the output of my plugin, just
the output of my plugin and not the whole page.
I could not get the output of my view (dont want to use selenium), any
idea? i ve tried with this code
<?php
class Tx_F2contentce_Controller_ContentceControllerTest extends
Tx_Extbase_BaseTestCase {
/**
* @test
*
*/
public function vimeoActionWorks() {
$view = $this->getViewObject();
$view->setTemplatePathAndFilename(dirname(__FILE__) .
'/../../Resources/Private/Templates/Contentce/Vimeo.html');
$controller = $this->getControllerObject();
$controller->_set('view', $view);
$controller->_set('actionMethodName', 'vimeoAction');
$controller->initializeAction();
$controller->_call('callActionMethod');
}
public function getViewObject() {
$templateView = $this->getAccessibleMock
('Tx_Fluid_View_TemplateView', array('resolveTemplatePathAndFilename',
'buildParserConfiguration'), array(), '', FALSE);
$parsedTemplate = $this->getMock
('Tx_Fluid_Core_Parser_ParsedTemplateInterface');
$objectManager = $this->getMock
('Tx_Fluid_Compatibility_ObjectManager');
$controllerContext = $this->getMock
('Tx_Extbase_MVC_Controller_ControllerContext', array(), array(), '',
FALSE);
$variableContainer = $this->getMock
('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer');
$renderingContext = $this->getMock
('Tx_Fluid_Core_Rendering_RenderingContext', array(), array(), '', FALSE);
$viewHelperVariableContainer = $this->getMock
('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer');
$objectManager->expects($this->exactly(3))->method
('create')->will($this->onConsecutiveCalls($variableContainer,
$renderingContext, $viewHelperVariableContainer));
$templateView->_set('objectManager', $objectManager);
//$templateView->injectTemplateParser($this->getMock
('Tx_Fluid_Core_Parser_TemplateParser'));
$templateView->injectTemplateParser(new
Tx_Fluid_Core_Parser_TemplateParser);
$templateView->setControllerContext($controllerContext);
$templateView->expects($this->once())->method('render');
$templateView->expects($this->once())->method
('parseTemplate')->will($this->returnValue($parsedTemplate));
return $templateView;
}
public function getControllerObject() {
$mockRequest = $this->getMock('Tx_Extbase_MVC_Request');
$response = new Tx_Extbase_MVC_Response;
$mockArguments = new ArrayObject;
$mockArgumentMappingResults = $this->getMock
('Tx_Extbase_Property_MappingResults', array(), array(), '', FALSE);
$mockController = $this->getMock($this-
>buildAccessibleProxy('Tx_F2contentce_Controller_ContentceController'),
array('getRequest'), array(), '', FALSE);
$mockController->_set('request', $mockRequest);
$mockController->_set('response', $response);
$mockController->_set('arguments', $mockArguments);
$mockController->_set('argumentsMappingResults',
$mockArgumentMappingResults);
return $mockController;
}
}
?>
More information about the TYPO3-project-typo3v4mvc
mailing list