/** * @test */ public function setControllerObjectNameAndSetControllerCommandNameUnsetTheBuiltCommandObject() { $this->request->setControllerObjectName('Tx_Extbase_Command_CacheCommandController'); $this->request->setControllerCommandName('flush'); $this->request->getCommand(); $this->request->setControllerObjectName('Tx_SomeExtension_Command_BeerCommandController'); $this->request->setControllerCommandName('drink'); $this->mockObjectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, 'Tx_SomeExtension_Command_BeerCommandController', 'drink'); $this->request->getCommand(); }
/** * @test */ public function is_datetime_created_with_invalid_text() { $import = $this->getMock(Import::class); $strategy = $this->getMock(Strategy::class); $path = './import.csv'; $import->expects($this->once())->method('setStarttime')->with($this->isInstanceOf(\DateTime::class)); $this->objectManager->expects($this->once())->method('get')->with(Import::class)->will($this->returnCallback(function () use($import) { return $import; })); $this->fixture->addToQueue($path, $strategy, ['start' => 'Lorem ipsum']); }
/** * @return void */ protected function injectDependencies() { $this->mockConfigurationManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($this->configuration)); $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager); $this->mockObjectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Request::class)->will($this->returnValue($this->mockRequest)); $this->requestBuilder->_set('objectManager', $this->mockObjectManager); $pluginNamespace = 'tx_' . strtolower($this->configuration['extensionName'] . '_' . $this->configuration['pluginName']); $this->mockExtensionService->expects($this->any())->method('getPluginNamespace')->will($this->returnValue($pluginNamespace)); $this->requestBuilder->_set('extensionService', $this->mockExtensionService); $this->mockEnvironmentService->expects($this->any())->method('getServerRequestMethod')->will($this->returnValue('GET')); $this->requestBuilder->_set('environmentService', $this->mockEnvironmentService); }
protected function setUp() { $this->widgetRequestBuilder = $this->getAccessibleMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequestBuilder::class, array('setArgumentsFromRawRequestData')); $this->mockWidgetRequest = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class); $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); $this->mockObjectManager->expects($this->once())->method('get')->with(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)->will($this->returnValue($this->mockWidgetRequest)); $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager); $this->mockWidgetContext = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetContext::class); $this->mockAjaxWidgetContextHolder = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AjaxWidgetContextHolder::class, array(), array(), '', false); $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder); $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext)); }
public function setUp() { $this->widgetRequestBuilder = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequestBuilder', array('setArgumentsFromRawRequestData')); $this->mockWidgetRequest = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest'); $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface'); $this->mockObjectManager->expects($this->once())->method('get')->with('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetRequest')->will($this->returnValue($this->mockWidgetRequest)); $this->widgetRequestBuilder->_set('objectManager', $this->mockObjectManager); $this->mockWidgetContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext'); $this->mockAjaxWidgetContextHolder = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Widget\\AjaxWidgetContextHolder', array(), array(), '', FALSE); $this->widgetRequestBuilder->injectAjaxWidgetContextHolder($this->mockAjaxWidgetContextHolder); $this->mockAjaxWidgetContextHolder->expects($this->once())->method('get')->will($this->returnValue($this->mockWidgetContext)); }
/** * @test * @author Bastian Waidelich <*****@*****.**> */ public function getAvailableCommandsReturnsAllAvailableCommands() { /** @var \TYPO3\CMS\Core\Tests\AccessibleObjectInterface $commandManager */ $commandManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager::class, array('dummy')); $commandManager->_set('objectManager', $this->mockObjectManager); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'] = array(\TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockBCommandController::class); $mockCommand1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, array(), array(), '', FALSE); $mockCommand2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, array(), array(), '', FALSE); $mockCommand3 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, array(), array(), '', FALSE); $this->mockObjectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class, 'foo')->will($this->returnValue($mockCommand1)); $this->mockObjectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockACommandController::class, 'bar')->will($this->returnValue($mockCommand2)); $this->mockObjectManager->expects($this->at(2))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, \TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockBCommandController::class, 'baz')->will($this->returnValue($mockCommand3)); $commands = $commandManager->getAvailableCommands(); $this->assertEquals(3, count($commands)); $this->assertSame($mockCommand1, $commands[0]); $this->assertSame($mockCommand2, $commands[1]); $this->assertSame($mockCommand3, $commands[2]); }
/** * Sets up this test case * * @author Robert Lemke <*****@*****.**> */ protected function setUp() { $this->request = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class, array('dummy')); $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface::class); $this->mockObjectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\Request::class)->will($this->returnValue($this->request)); $this->mockCommand = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\Command::class, array(), array(), '', FALSE); $this->mockCommand->expects($this->any())->method('getControllerClassName')->will($this->returnValue('Tx_SomeExtensionName_Command_DefaultCommandController')); $this->mockCommand->expects($this->any())->method('getControllerCommandName')->will($this->returnValue('list')); $this->mockCommandManager = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandManager::class); $this->mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('some_extension_name:default:list')->will($this->returnValue($this->mockCommand)); $this->mockReflectionService = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class); $this->mockConfigurationManager = $this->getMock(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::class); $this->requestBuilder = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Cli\RequestBuilder::class, array('dummy')); $this->requestBuilder->_set('objectManager', $this->mockObjectManager); $this->requestBuilder->_set('reflectionService', $this->mockReflectionService); $this->requestBuilder->_set('commandManager', $this->mockCommandManager); $this->requestBuilder->_set('configurationManager', $this->mockConfigurationManager); }
/** * @test * @expectedException \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException */ public function convertFromShouldThrowExceptionIfPropertyOnTargetObjectCouldNotBeSet() { $source = array('propertyX' => 'bar'); $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters(); $convertedChildProperties = array('propertyNotExisting' => 'bar'); $this->mockObjectManager->expects($this->any())->method('get')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters::class)->will($this->returnValue($object)); $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters::class, '__construct')->will($this->returnValue(array())); $configuration = $this->buildConfiguration(array(PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true)); $result = $this->converter->convertFrom($source, \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSetters::class, $convertedChildProperties, $configuration); $this->assertSame($object, $result); }
/** * @test * @return void */ public function mergeWithExistingConfigurationOverwritesDefaultKeysWithCurrent() { $localConfiguration = serialize(array('FE.' => array('enabled' => '1', 'saltedPWHashingMethod' => \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface_sha1::class), 'CLI.' => array('enabled' => '0'))); $configurationManagerMock = $this->getMock(\TYPO3\CMS\Core\Configuration\ConfigurationManager::class); $configurationManagerMock->expects($this->once())->method('getConfigurationValueByPath')->with('EXT/extConf/testextensionkey')->will($this->returnValue($localConfiguration)); $this->injectedObjectManagerMock->expects($this->any())->method('get')->will($this->returnValue($configurationManagerMock)); $defaultConfiguration = array('FE.enabled' => array('value' => '0'), 'FE.saltedPWHashingMethod' => array('value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class), 'BE.enabled' => array('value' => '1'), 'BE.saltedPWHashingMethod' => array('value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class)); $expectedResult = array('FE.enabled' => array('value' => '1'), 'FE.saltedPWHashingMethod' => array('value' => \TYPO3\CMS\Saltedpasswords\Salt\SaltInterface_sha1::class), 'BE.enabled' => array('value' => '1'), 'BE.saltedPWHashingMethod' => array('value' => \TYPO3\CMS\Saltedpasswords\Salt\Md5Salt::class), 'CLI.enabled' => array('value' => '0')); $actualResult = $this->configurationItemRepository->_call('mergeWithExistingConfiguration', $defaultConfiguration, 'testextensionkey'); $this->assertEquals($expectedResult, $actualResult); }
/** * @test * @expectedException \TYPO3\CMS\Extbase\Property\Exception\InvalidTargetException */ public function convertFromShouldThrowExceptionIfRequiredConstructorParameterWasNotFound() { $source = array('propertyX' => 'bar'); $object = new \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor('param1'); $convertedChildProperties = array('property2' => 'bar'); $this->mockReflectionService->expects($this->any())->method('getMethodParameters')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(array('property1' => array('optional' => false)))); $this->mockReflectionService->expects($this->any())->method('hasMethod')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, '__construct')->will($this->returnValue(true)); $this->mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->with(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class)->will($this->returnValue(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class)); $this->mockContainer->expects($this->any())->method('getImplementationClassName')->will($this->returnValue(\TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class)); $configuration = $this->buildConfiguration(array(PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true)); $result = $this->converter->convertFrom($source, \TYPO3\CMS\Extbase\Tests\Fixture\ClassWithSettersAndConstructor::class, $convertedChildProperties, $configuration); $this->assertSame($object, $result); }
/** * @test * @author Bastian Waidelich <*****@*****.**> */ public function getArgumentDefinitionsReturnsArrayOfArgumentDefinitionIfCommandExpectsArguments() { $mockParameterReflection = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ParameterReflection::class, array(), array(), '', FALSE); $mockReflectionService = $this->getMock(\TYPO3\CMS\Extbase\Reflection\ReflectionService::class); $mockMethodParameters = array('argument1' => array('optional' => FALSE), 'argument2' => array('optional' => TRUE)); $mockReflectionService->expects($this->atLeastOnce())->method('getMethodParameters')->will($this->returnValue($mockMethodParameters)); $this->command->_set('reflectionService', $mockReflectionService); $this->mockMethodReflection->expects($this->atLeastOnce())->method('getParameters')->will($this->returnValue(array($mockParameterReflection))); $this->mockMethodReflection->expects($this->atLeastOnce())->method('getTagsValues')->will($this->returnValue(array('param' => array('@param $argument1 argument1 description', '@param $argument2 argument2 description')))); $mockCommandArgumentDefinition1 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, array(), array(), '', FALSE); $mockCommandArgumentDefinition2 = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, array(), array(), '', FALSE); $this->mockObjectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, 'argument1', TRUE, 'argument1 description')->will($this->returnValue($mockCommandArgumentDefinition1)); $this->mockObjectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition::class, 'argument2', FALSE, 'argument2 description')->will($this->returnValue($mockCommandArgumentDefinition2)); $expectedResult = array($mockCommandArgumentDefinition1, $mockCommandArgumentDefinition2); $actualResult = $this->command->getArgumentDefinitions(); $this->assertSame($expectedResult, $actualResult); }
/** * @test */ public function getSecurityStatusOfExtensionsReturnsErrorForExistingExtensionIfOutdatedExtensionExists() { /** @var $mockTerObject \TYPO3\CMS\Extensionmanager\Domain\Model\Extension|\PHPUnit_Framework_MockObject_MockObject */ $mockTerObject = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension'); $mockTerObject->expects($this->any())->method('getVersion')->will($this->returnValue('1.0.6')); $mockTerObject->expects($this->atLeastOnce())->method('getReviewState')->will($this->returnValue(-2)); $mockExtensionList = array('enetcache' => array('terObject' => $mockTerObject)); /** @var $mockListUtility \TYPO3\CMS\Extensionmanager\Utility\ListUtility|\PHPUnit_Framework_MockObject_MockObject */ $mockListUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility'); $mockListUtility->expects($this->once())->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')->will($this->returnValue($mockExtensionList)); /** @var $mockReport \TYPO3\CMS\Extensionmanager\Report\ExtensionStatus|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface */ $mockReport = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Report\\ExtensionStatus', array('dummy'), array(), '', FALSE); $mockReport->_set('objectManager', $this->mockObjectManager); $statusMock = $this->getMock('TYPO3\\CMS\\Reports\\Status', array(), array(), '', FALSE); $this->mockObjectManager->expects($this->at(3))->method('get')->with($this->anything(), $this->anything(), $this->anything(), $this->anything(), \TYPO3\CMS\Reports\Status::WARNING)->will($this->returnValue($statusMock)); $mockReport->_set('listUtility', $mockListUtility); $mockReport->_set('languageService', $this->mockLanguageService); $result = $mockReport->_call('getSecurityStatusOfExtensions'); /** @var $loadedResult \TYPO3\CMS\Reports\Status */ $loadedResult = $result->existingoutdated; $this->assertSame($statusMock, $loadedResult); }
/** * @test */ public function initiateSubRequestBuildsRequestProperly() { $controller = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController::class, array(), array(), '', FALSE); $this->viewHelper->_set('controller', $controller); // Initial Setup $widgetRequest = $this->getMock(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class); $response = $this->getMock(\TYPO3\CMS\Extbase\Mvc\Web\Response::class); $this->objectManager->expects($this->at(0))->method('get')->with(\TYPO3\CMS\Fluid\Core\Widget\WidgetRequest::class)->will($this->returnValue($widgetRequest)); $this->objectManager->expects($this->at(1))->method('get')->with(\TYPO3\CMS\Extbase\Mvc\Web\Response::class)->will($this->returnValue($response)); // Widget Context is set $widgetRequest->expects($this->once())->method('setWidgetContext')->with($this->widgetContext); // The namespaced arguments are passed to the sub-request // and the action name is exctracted from the namespace. $this->controllerContext->expects($this->once())->method('getRequest')->will($this->returnValue($this->request)); $this->widgetContext->expects($this->once())->method('getWidgetIdentifier')->will($this->returnValue('widget-1')); $this->request->expects($this->once())->method('getArguments')->will($this->returnValue(array('k1' => 'k2', 'widget-1' => array('arg1' => 'val1', 'arg2' => 'val2', 'action' => 'myAction')))); $widgetRequest->expects($this->once())->method('setArguments')->with(array('arg1' => 'val1', 'arg2' => 'val2')); $widgetRequest->expects($this->once())->method('setControllerActionName')->with('myAction'); // Controller is called $controller->expects($this->once())->method('processRequest')->with($widgetRequest, $response); $output = $this->viewHelper->_call('initiateSubRequest'); // SubResponse is returned $this->assertSame($response, $output); }
/** * ResolverUsesObjectManagerToRetrieveConcreteImplementation * * @return void */ public function testResolverUsesObjectManagerToRetrieveConcreteImplementation() { $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('DreadLabs\\VantomasWebsite\\Disqus\\Resource\\Foo\\Bar')); $this->patternProviderMock->expects($this->once())->method('getPattern')->willReturn('DreadLabs\\VantomasWebsite\\Disqus\\Resource\\%s\\%s'); $this->sut->resolve('Foo', 'Bar'); }