/** * @test */ public function renderReturnsResultOfContentObjectRenderer() { $this->subject->expects($this->any())->method('renderChildren')->will($this->returnValue('innerContent')); $contentObjectRendererMock = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array(), array(), '', FALSE); $contentObjectRendererMock->expects($this->once())->method('stdWrap')->will($this->returnValue('foo')); GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $contentObjectRendererMock); $this->assertEquals('foo', $this->subject->render('42')); }
/** * @test */ public function respectHtmlCanBeDisabled() { $this->mockContentObject->expects($this->once())->method('crop')->with('Some Content', '123|...|1')->will($this->returnValue('Cropped Content')); GeneralUtility::addInstance(ContentObjectRenderer::class, $this->mockContentObject); $actualResult = $this->viewHelper->render(123, '...', true, false); $this->assertEquals('Cropped Content', $actualResult); }
/** * Method called from tests mailCallsHook() and mailCallsHookWithDefaultMailFrom(). */ protected function doMailCallsHook($fromAddress = '', $fromName = '') { // Backup configuration $mailConfigurationBackup = $GLOBALS['TYPO3_CONF_VARS']['MAIL']; $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromAddress'] = $fromAddress; $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'] = $fromName; $to = '*****@*****.**'; $subject = 'Good news everybody!'; $messageBody = 'The hooks works!'; $additionalHeaders = 'Reply-to: jane@example.com'; $additionalParameters = '-f postmaster@example.com'; $fakeThis = FALSE; $additionalHeadersExpected = $additionalHeaders; if ($fromAddress !== '' && $fromName !== '') { $additionalHeadersExpected .= LF . sprintf('From: "%s" <%s>', $fromName, $fromAddress); } $mockMailer = $this->getMock('TYPO3\\CMS\\Core\\Mail\\MailerAdapterInterface', array('mail')); $mockClassName = get_class($mockMailer); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($mockClassName, $mockMailer); $mockMailer->expects($this->once())->method('mail')->with($to, $subject, $messageBody, $additionalHeadersExpected, $additionalParameters, $fakeThis)->will($this->returnValue(TRUE)); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/utility/class.t3lib_utility_mail.php']['substituteMailDelivery'] = array($mockClassName); \TYPO3\CMS\Core\Utility\MailUtility::mail($to, $subject, $messageBody, $additionalHeaders, $additionalParameters); // Restore configuration $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = $mailConfigurationBackup; }
public function setUp() { // $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', get_class_methods('TYPO3\\CMS\\Core\\Database\\DatabaseConnection'), array(), '', false); $classInfoCacheMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\Container\\ClassInfoCache', array(), array(), '', false); GeneralUtility::addInstance('TYPO3\\CMS\\Extbase\\Object\\Container\\ClassInfoCache', $classInfoCacheMock); $configuration = array('transport' => 'R3H6\\MailSpool\\Mail\\SpoolTransport', 'spool' => 'R3H6\\MailSpool\\Tests\\Unit\\Mail\\Fixtures\\TestSpool', 'transport_real' => 'R3H6\\MailSpool\\Tests\\Unit\\Mail\\Fixtures\\TestTransport'); $this->subject = new \R3H6\MailSpool\Mail\SpoolTransport($configuration); }
/** * @test */ public function renderCallsIconFactoryWithGivenOverlayAndReturnsResult() { $iconFactoryProphecy = $this->prophesize(IconFactory::class); GeneralUtility::addInstance(IconFactory::class, $iconFactoryProphecy->reveal()); $iconProphecy = $this->prophesize(Icon::class); $iconFactoryProphecy->getIcon('myIdentifier', Argument::any(), 'overlayString', IconState::cast(IconState::STATE_DEFAULT))->shouldBeCalled()->willReturn($iconProphecy->reveal()); $iconProphecy->render(NULL)->shouldBeCalled()->willReturn('htmlFoo'); $this->assertSame('htmlFoo', $this->viewHelper->render('myIdentifier', Icon::SIZE_LARGE, 'overlayString')); }
/** * @test */ public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface() { /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */ $formDataProviderProphecy = $this->prophesize(\stdClass::class); GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal()); $providerList = [\stdClass::class]; $this->subject->setProviderList($providerList); $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1441108719); $this->subject->compile([]); }
/** * @test */ public function extendAdminPanelHookCallsExtendAdminPanelMethodOfHook() { $hookClass = $this->getUniqueId('tx_coretest'); $hookMock = $this->getMock(\TYPO3\CMS\Frontend\View\AdminPanelViewHookInterface::class, array(), array(), $hookClass); GeneralUtility::addInstance($hookClass, $hookMock); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_adminpanel.php']['extendAdminPanel'][] = $hookClass; /** @var $adminPanelMock \PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Frontend\View\AdminPanelView */ $adminPanelMock = $this->getMock(\TYPO3\CMS\Frontend\View\AdminPanelView::class, array('extGetLL'), array(), '', false); $hookMock->expects($this->once())->method('extendAdminPanel')->with($this->isType('string'), $this->isInstanceOf(\TYPO3\CMS\Frontend\View\AdminPanelView::class)); $adminPanelMock->display(); }
/** * Tests whether the getPage Hook is called correctly. * * @test */ public function isGetPageHookCalled() { // Create a hook mock object $className = $this->getUniqueId('tx_coretest'); $getPageHookMock = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepositoryGetPageHookInterface::class, array('getPage_preProcess'), array(), $className); // Register hook mock object GeneralUtility::addInstance($className, $getPageHookMock); $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_page.php']['getPage'][] = $className; // Test if hook is called and register a callback method to check given arguments $getPageHookMock->expects($this->once())->method('getPage_preProcess')->will($this->returnCallback(array($this, 'isGetPagePreProcessCalledCallback'))); $this->pageSelectObject->getPage(42, false); }
/** * Set up */ protected function setUp() { $this->singletonInstances = GeneralUtility::getSingletonInstances(); $this->formProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Domain\\Model\\Form'); $this->typoScriptFactoryProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory'); $this->typoScriptFactoryProphecy->getLayoutFromTypoScript(Argument::any())->willReturn(array()); GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactory', $this->typoScriptFactoryProphecy->reveal()); $this->typoScriptLayoutProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Layout'); $templateServiceProphecy = $this->prophesize('TYPO3\\CMS\\Core\\TypoScript\\TemplateService'); $templateServiceProphecy->sortedKeyList(Argument::any())->willReturn(array(10, 20)); GeneralUtility::addInstance('TYPO3\\CMS\\Core\\TypoScript\\TemplateService', $templateServiceProphecy->reveal()); }
/** * */ public function setUp() { $contentObjectRendererProphecy = $this->prophesize('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', $contentObjectRendererProphecy->reveal()); $localisationProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Localization'); GeneralUtility::addInstance('TYPO3\\CMS\\Form\\Localization', $localisationProphecy->reveal()); $requestProphecy = $this->prophesize('TYPO3\\CMS\\Form\\Request'); $this->singletonInstances = GeneralUtility::getSingletonInstances(); GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Form\\Request', $requestProphecy->reveal()); $this->elementId = uniqid('elementId_', TRUE); $this->subject = new AttributesAttribute($this->elementId); }
/** * @test */ public function getDriverObjectAcceptsDriverClassName() { $mockedDriver = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Resource\Driver\AbstractDriver::class); $driverFixtureClass = get_class($mockedDriver); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($driverFixtureClass, $mockedDriver); $mockedMount = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false); $mockedRegistry = $this->getMock(\TYPO3\CMS\Core\Resource\Driver\DriverRegistry::class); $mockedRegistry->expects($this->once())->method('getDriverClass')->with($this->equalTo($driverFixtureClass))->will($this->returnValue($driverFixtureClass)); \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Resource\Driver\DriverRegistry::class, $mockedRegistry); $obj = $this->subject->getDriverObject($driverFixtureClass, array()); $this->assertInstanceOf(\TYPO3\CMS\Core\Resource\Driver\AbstractDriver::class, $obj); }
/** * @test */ public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface() { /** @var DependencyOrderingService|ObjectProphecy $orderingServiceProphecy */ $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class); GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal()); $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0); /** @var FormDataProviderInterface|ObjectProphecy $formDataProviderProphecy */ $formDataProviderProphecy = $this->prophesize(\stdClass::class); $GLOBALS['TYPO3_CONF_VARS']['SYS']['formEngine']['formDataGroup']['tcaInputPlaceholderRecord'] = array(\stdClass::class => array()); GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal()); $this->setExpectedException(\UnexpectedValueException::class, $this->anything(), 1443986127); $this->subject->compile([]); }
/** * @test */ public function addDataSetsDatabaseData() { $aFieldConfig = ['type' => 'group', 'internal_type' => 'db', 'MM' => 'mmTableName', 'allowed' => 'aForeignTable']; $input = ['tableName' => 'aTable', 'databaseRow' => ['uid' => 42, 'aField' => '1,2'], 'processedTca' => ['columns' => ['aField' => ['config' => $aFieldConfig]]]]; /** @var RelationHandler|ObjectProphecy $relationHandlerProphecy */ $relationHandlerProphecy = $this->prophesize(RelationHandler::class); GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal()); $relationHandlerProphecy->start('1,2', 'aForeignTable', 'mmTableName', 42, 'aTable', $aFieldConfig)->shouldBeCalled(); $relationHandlerProphecy->getFromDB()->shouldBeCalled(); $relationHandlerProphecy->readyForInterface()->shouldBeCalled()->willReturn('1|aLabel,2|anotherLabel'); $expected = $input; $expected['databaseRow']['aField'] = '1|aLabel,2|anotherLabel'; $this->assertSame($expected, $this->subject->addData($input)); }
/** * @test */ public function getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven() { /** @var Connection|ObjectProphecy $connection */ $connection = $this->prophesize(Connection::class); $connection->getDatabasePlatform()->willReturn(new MockPlatform()); $connection->getExpressionBuilder()->willReturn(new ExpressionBuilder($connection->reveal())); $queryBuilder = GeneralUtility::makeInstance(QueryBuilder::class, $connection->reveal(), null, $this->prophesize(\Doctrine\DBAL\Query\QueryBuilder::class)->reveal()); /** @var ConnectionPool|ObjectProphecy $connection */ $connectionPool = $this->prophesize(ConnectionPool::class); $connectionPool->getQueryBuilderForTable(Argument::cetera())->willReturn($queryBuilder); GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal()); /** @var $mock \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication */ $mock = $this->getMock(\TYPO3\CMS\Core\Authentication\AbstractUserAuthentication::class, array('dummy')); $mock->checkPid = true; $mock->checkPid_value = null; $mock->user_table = 'be_users'; $result = $mock->getAuthInfoArray(); $this->assertEquals('', $result['db_user']['checkPidList']); }
/** * @test */ public function logoffCleansFormProtectionIfBackendUserIsLoggedIn() { /** @var ObjectProphecy|Connection $connection */ $connection = $this->prophesize(Connection::class); $connection->delete('be_sessions', Argument::cetera())->willReturn(1); /** @var ObjectProphecy|ConnectionPool $connectionPool */ $connectionPool = $this->prophesize(ConnectionPool::class); $connectionPool->getConnectionForTable(Argument::cetera())->willReturn($connection->reveal()); GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal()); /** @var ObjectProphecy|\TYPO3\CMS\Core\FormProtection\AbstractFormProtection $formProtection */ $formProtection = $this->prophesize(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class); $formProtection->clean()->shouldBeCalled(); \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set('default', $formProtection->reveal()); // logoff() call the static factory that has a dependency to a valid BE_USER object. Mock this away $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication::class, array(), array(), '', false); $GLOBALS['BE_USER']->user = array('uid' => $this->getUniqueId()); $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, array(), array(), '', false); $subject = $this->getAccessibleMock(BackendUserAuthentication::class, array('dummy'), array(), '', false); $subject->_set('db', $GLOBALS['TYPO3_DB']); $subject->logoff(); }
/** * @test */ public function addDataAddsTreeConfigurationForExtJs() { $GLOBALS['TCA']['foreignTable'] = []; /** @var DatabaseConnection|ObjectProphecy $database */ $database = $this->prophesize(DatabaseConnection::class); $GLOBALS['TYPO3_DB'] = $database->reveal(); /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */ $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class); $GLOBALS['BE_USER'] = $backendUserProphecy->reveal(); /** @var DatabaseTreeDataProvider|ObjectProphecy $treeDataProviderProphecy */ $treeDataProviderProphecy = $this->prophesize(DatabaseTreeDataProvider::class); GeneralUtility::addInstance(DatabaseTreeDataProvider::class, $treeDataProviderProphecy->reveal()); /** @var TableConfigurationTree|ObjectProphecy $treeDataProviderProphecy */ $tableConfigurationTreeProphecy = $this->prophesize(TableConfigurationTree::class); GeneralUtility::addInstance(TableConfigurationTree::class, $tableConfigurationTreeProphecy->reveal()); $tableConfigurationTreeProphecy->setDataProvider(Argument::cetera())->shouldBeCalled(); $tableConfigurationTreeProphecy->setNodeRenderer(Argument::cetera())->shouldBeCalled(); $tableConfigurationTreeProphecy->render()->shouldBeCalled()->willReturn(['fake', 'tree', 'data']); $input = ['tableName' => 'aTable', 'databaseRow' => ['aField' => '1'], 'processedTca' => ['columns' => ['aField' => ['config' => ['type' => 'select', 'renderType' => 'selectTree', 'treeConfig' => ['childrenField' => 'childrenField'], 'foreign_table' => 'foreignTable', 'items' => [], 'maxitems' => 1]]]]]; $expected = $input; $expected['databaseRow']['aField'] = ['1']; $expected['processedTca']['columns']['aField']['config']['treeData'] = ['items' => [['fake', 'tree', 'data']], 'selectedNodes' => []]; $this->assertEquals($expected, $this->subject->addData($input)); }
/** * Sets up this test case * * @return void */ public function setUp() { $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances(); $this->view = $this->getAccessibleMock('TYPO3\\CMS\\Fluid\\View\\StandaloneView', array('dummy'), array(), '', FALSE); $this->mockTemplateParser = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\TemplateParser'); $this->mockParsedTemplate = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Parser\\ParsedTemplateInterface'); $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate)); $this->mockConfigurationManager = $this->getMock('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManagerInterface'); $this->mockObjectManager = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager'); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $this->mockRequest = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request'); $this->mockUriBuilder = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder'); $this->mockContentObject = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $this->mockControllerContext = $this->getMock('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext'); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockViewHelperVariableContainer = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer'); $this->mockRenderingContext = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext'); $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer)); $this->view->_set('templateParser', $this->mockTemplateParser); $this->view->_set('objectManager', $this->mockObjectManager); $this->view->setRenderingContext($this->mockRenderingContext); $this->mockTemplateCompiler = $this->getMock('TYPO3\\CMS\\Fluid\\Core\\Compiler\\TemplateCompiler'); $this->view->_set('templateCompiler', $this->mockTemplateCompiler); \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', $this->mockObjectManager); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', $this->mockContentObject); $mockCacheManager = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array(), array(), '', FALSE); $mockCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\PhpFrontend', array(), array(), '', FALSE); $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Cache\\CacheManager', $mockCacheManager); }
/** * Sets up this test case * * @return void */ protected function setUp() { $this->singletonInstances = GeneralUtility::getSingletonInstances(); $this->view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, array('testFileExistence', 'buildParserConfiguration', 'getOrParseAndStoreTemplate'), array(), '', false); $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class); $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $this->mockRequest = $this->getMock(Request::class); $this->mockUriBuilder = $this->getMock(UriBuilder::class); $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); $this->mockControllerContext = $this->getMock(ControllerContext::class); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockTemplatePaths = $this->getMock(TemplatePaths::class); $this->mockViewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class); $this->mockRenderingContext = $this->getMock(\TYPO3\CMS\Fluid\Tests\Unit\Core\Rendering\RenderingContextFixture::class); $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer)); $this->mockRenderingContext->expects($this->any())->method('getVariableProvider')->willReturn($this->mockVariableProvider); $this->mockRenderingContext->expects($this->any())->method('getTemplatePaths')->willReturn($this->mockTemplatePaths); $this->view->_set('objectManager', $this->mockObjectManager); $this->view->_set('baseRenderingContext', $this->mockRenderingContext); $this->view->_set('controllerContext', $this->mockControllerContext); $this->view->expects($this->any())->method('getOrParseAndStoreTemplate')->willReturn($this->mockParsedTemplate); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $this->mockObjectManager); GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $this->mockContentObject); $this->mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager::class, array(), array(), '', false); $mockCache = $this->getMock(\TYPO3Fluid\Fluid\Core\Cache\FluidCacheInterface::class, array(), array(), '', false); $this->mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $this->mockCacheManager); }
/** * @test * @dataProvider correctValuesForMmRelationWithSingleValueAllowedDataProvider */ public function correctValuesForMmRelationWithSingleValueAllowed($input, $relationHandlerUids) { $GLOBALS['TCA']['foreignTable'] = []; /** @var BackendUserAuthentication|ObjectProphecy $backendUserProphecy */ $backendUserProphecy = $this->prophesize(BackendUserAuthentication::class); $GLOBALS['BE_USER'] = $backendUserProphecy->reveal(); /** @var DatabaseConnection|ObjectProphecy $database */ $database = $this->prophesize(DatabaseConnection::class); $GLOBALS['TYPO3_DB'] = $database->reveal(); $fieldConfig = $input['processedTca']['columns']['aField']['config']; /** @var RelationHandler|ObjectProphecy $relationHandlerProphecy */ $relationHandlerProphecy = $this->prophesize(RelationHandler::class); GeneralUtility::addInstance(RelationHandler::class, $relationHandlerProphecy->reveal()); $field = $input['databaseRow']['aField']; $foreignTable = $input['processedTca']['columns']['aField']['config']['foreign_table']; $mmTable = $input['processedTca']['columns']['aField']['config']['MM']; $uid = $input['databaseRow']['uid']; $tableName = $input['tableName']; $fieldConfig = $input['processedTca']['columns']['aField']['config']; $relationHandlerProphecy->start($field, $foreignTable, $mmTable, $uid, $tableName, $fieldConfig)->shouldBeCalled(); $relationHandlerProphecy->getValueArray()->shouldBeCalled()->willReturn($relationHandlerUids); $expected = $input; $expected['databaseRow']['aField'] = $relationHandlerUids; $this->assertEquals($expected, $this->subject->addData($input)); }
/** * @test */ public function processDatamapWhenEditingRecordInWorkspaceCreatesNewRecordInWorkspace() { // Unset possible hooks on method under test // @TODO: Can be removed if unit test boostrap is fixed to not load LocalConfiguration anymore $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'] = array(); $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection'); $GLOBALS['TCA'] = array('pages' => array('columns' => array())); /** @var $subject \TYPO3\CMS\Core\DataHandling\DataHandler|\TYPO3\CMS\Core\Tests\UnitTestCase */ $subject = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('newlog', 'checkModifyAccessList', 'tableReadOnly', 'checkRecordUpdateAccess')); $subject->bypassWorkspaceRestrictions = FALSE; $subject->datamap = array('pages' => array('1' => array('header' => 'demo'))); $subject->expects($this->once())->method('checkModifyAccessList')->with('pages')->will($this->returnValue(TRUE)); $subject->expects($this->once())->method('tableReadOnly')->with('pages')->will($this->returnValue(FALSE)); $subject->expects($this->once())->method('checkRecordUpdateAccess')->will($this->returnValue(TRUE)); $backEndUser = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication'); $backEndUser->workspace = 1; $backEndUser->workspaceRec = array('freeze' => FALSE); $backEndUser->expects($this->once())->method('workspaceAllowAutoCreation')->will($this->returnValue(TRUE)); $backEndUser->expects($this->once())->method('workspaceCannotEditRecord')->will($this->returnValue(TRUE)); $backEndUser->expects($this->once())->method('recordEditAccessInternals')->with('pages', 1)->will($this->returnValue(TRUE)); $subject->BE_USER = $backEndUser; $createdTceMain = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array()); $createdTceMain->expects($this->once())->method('start')->with(array(), array('pages' => array(1 => array('version' => array('action' => 'new', 'treeLevels' => -1, 'label' => 'Auto-created for WS #1'))))); $createdTceMain->expects($this->never())->method('process_datamap'); $createdTceMain->expects($this->once())->method('process_cmdmap'); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', $createdTceMain); $subject->process_datamap(); }
/** * Sets up this test case * * @return void */ protected function setUp() { $this->singletonInstances = GeneralUtility::getSingletonInstances(); $this->view = $this->getAccessibleMock(\TYPO3\CMS\Fluid\View\StandaloneView::class, array('testFileExistence', 'buildParserConfiguration'), array(), '', FALSE); $this->mockTemplateParser = $this->getMock(TemplateParser::class); $this->mockParsedTemplate = $this->getMock(\TYPO3\CMS\Fluid\Core\Parser\ParsedTemplateInterface::class); $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate)); $this->mockConfigurationManager = $this->getMock(ConfigurationManagerInterface::class); $this->mockObjectManager = $this->getMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $this->mockRequest = $this->getMock(Request::class); $this->mockUriBuilder = $this->getMock(UriBuilder::class); $this->mockContentObject = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class); $this->mockControllerContext = $this->getMock(ControllerContext::class); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockViewHelperVariableContainer = $this->getMock(\TYPO3\CMS\Fluid\Core\ViewHelper\ViewHelperVariableContainer::class); $this->mockRenderingContext = $this->getMock(RenderingContext::class); $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer)); $this->view->_set('templateParser', $this->mockTemplateParser); $this->view->_set('objectManager', $this->mockObjectManager); $this->view->setRenderingContext($this->mockRenderingContext); $this->mockTemplateCompiler = $this->getMock(TemplateCompiler::class); $this->view->_set('templateCompiler', $this->mockTemplateCompiler); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $this->mockObjectManager); GeneralUtility::addInstance(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, $this->mockContentObject); $mockCacheManager = $this->getMock(\TYPO3\CMS\Core\Cache\CacheManager::class, array(), array(), '', FALSE); $mockCache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\PhpFrontend::class, array(), array(), '', FALSE); $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager); }
/** * @test * @dataProvider getContentObjectValidContentObjectsDataProvider * @param string $name TypoScript name of content object * @param string $fullClassName Expected class name */ public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $fullClassName) { $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', false); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance); $this->assertSame($contentObjectInstance, $this->subject->getContentObject($name)); }
/** * @test */ public function addDataAddFlashMessageWithMissingIsoCode() { $dbRows = [['uid' => 3, 'title' => 'french', 'language_isocode' => '', 'static_lang_isocode' => '', 'flag' => 'fr']]; $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->shouldBeCalled()->willReturn($dbRows); // Needed for backendUtility::getRecord() $GLOBALS['TCA']['static_languages'] = ['foo']; $expected = ['systemLanguageRows' => [-1 => ['uid' => -1, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages', 'iso' => 'DEF', 'flagIconIdentifier' => 'flags-multiple'], 0 => ['uid' => 0, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage', 'iso' => 'DEF', 'flagIconIdentifier' => 'empty-empty'], 3 => ['uid' => 3, 'title' => 'french', 'flagIconIdentifier' => 'flags-fr', 'iso' => '']]]; /** @var FlashMessage|ObjectProphecy $flashMessage */ $flashMessage = $this->prophesize(FlashMessage::class); GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal()); /** @var FlashMessageService|ObjectProphecy $flashMessageService */ $flashMessageService = $this->prophesize(FlashMessageService::class); GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal()); /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */ $flashMessageQueue = $this->prophesize(FlashMessageQueue::class); $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal()); $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled(); $this->assertSame($expected, $this->subject->addData([])); }
/** * @test */ public function addDataCallsFlexFormSegmentGroupForDummyContainerAndAddsFlexParentDatabaseRow() { $input = ['tableName' => 'aTable', 'databaseRow' => ['aField' => ['data' => []], 'pointerField' => 'aFlex'], 'processedTca' => ['columns' => ['aField' => ['config' => ['type' => 'flex', 'ds_pointerField' => 'pointerField', 'ds' => ['sheets' => ['sDEF' => ['ROOT' => ['type' => 'array', 'el' => ['aFlexField' => ['label' => 'aFlexFieldLabel', 'config' => ['type' => 'input']]]]]]]]]]], 'pageTsConfig' => []]; /** @var FlexFormSegment|ObjectProphecy $dummyGroupExisting */ $dummyGroupExisting = $this->prophesize(FlexFormSegment::class); GeneralUtility::addInstance(FlexFormSegment::class, $dummyGroupExisting->reveal()); // Check array given to flex group contains databaseRow as flexParentDatabaseRow and check compile is called $dummyGroupExisting->compile(Argument::that(function ($result) use($input) { if ($result['flexParentDatabaseRow'] === $input['databaseRow']) { return true; } return false; }))->shouldBeCalled()->willReturnArgument(0); $this->subject->addData($input); }
/** * @test */ public function addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows() { $input = ['tableName' => 'tt_content', 'databaseRow' => ['uid' => 42, 'text' => 'localized text', 'sys_language_uid' => 2, 'l10n_parent' => 23], 'processedTca' => ['ctrl' => ['languageField' => 'sys_language_uid', 'transOrigPointerField' => 'l10n_parent']], 'userTsConfig' => ['options.' => ['additionalPreviewLanguages' => '2,3']], 'systemLanguageRows' => [0 => ['uid' => 0, 'title' => 'Default Language', 'iso' => 'DEV'], 2 => ['uid' => 2, 'title' => 'dansk', 'iso' => 'dk,'], 3 => ['uid' => 3, 'title' => 'french', 'iso' => 'fr']], 'defaultLanguageRow' => null, 'additionalLanguageRows' => []]; $translationResult = ['translations' => [3 => ['uid' => 43]]]; // For BackendUtility::getRecord() $GLOBALS['TCA']['tt_content'] = array('foo'); $recordWsolResult = ['uid' => 43, 'text' => 'localized text in french']; $defaultLanguageRow = ['uid' => 23, 'text' => 'default language text', 'sys_language_uid' => 0]; // Needed for BackendUtility::getRecord $GLOBALS['TCA']['tt_content'] = array('foo'); $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow); /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */ $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class); GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal()); $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult); $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled(); // This is the real check: The "additional overlay" should be fetched $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult); $expected = $input; $expected['defaultLanguageRow'] = $defaultLanguageRow; $expected['additionalLanguageRows'] = [3 => ['uid' => 43, 'text' => 'localized text in french']]; $this->assertEquals($expected, $this->subject->addData($input)); }
/** * @test * @dataProvider getContentObjectValidContentObjectsDataProvider * @param string $name TypoScript name of content object * @param string $className Expected class name */ public function getContentObjectCallsMakeInstanceForNewContentObjectInstance($name, $className) { $fullClassName = 'TYPO3\\CMS\\Frontend\\ContentObject\\' . $className . 'ContentObject'; $contentObjectInstance = $this->getMock($fullClassName, array(), array(), '', FALSE); \TYPO3\CMS\Core\Utility\GeneralUtility::addInstance($fullClassName, $contentObjectInstance); $this->assertSame($contentObjectInstance, $this->cObj->getContentObject($name)); }
/** * @test */ public function addDataItemsProcFuncEnqueuesFlashMessageOnException() { $input = ['tableName' => 'aTable', 'databaseRow' => ['aField' => 'aValue'], 'pageTsConfig' => ['TCEFORM.' => ['aTable.' => ['aField.' => ['itemsProcFunc.' => ['itemParamKey' => 'itemParamValue']]]]], 'processedTca' => ['columns' => ['aField' => ['config' => ['type' => 'check', 'aKey' => 'aValue', 'items' => [0 => ['foo', 'bar']], 'itemsProcFunc' => function (array $parameters, $pObj) { throw new \UnexpectedValueException('anException', 1438604329); }]]]]]; $languageService = $this->prophesize(LanguageService::class); $GLOBALS['LANG'] = $languageService->reveal(); /** @var FlashMessage|ObjectProphecy $flashMessage */ $flashMessage = $this->prophesize(FlashMessage::class); GeneralUtility::addInstance(FlashMessage::class, $flashMessage->reveal()); /** @var FlashMessageService|ObjectProphecy $flashMessageService */ $flashMessageService = $this->prophesize(FlashMessageService::class); GeneralUtility::setSingletonInstance(FlashMessageService::class, $flashMessageService->reveal()); /** @var FlashMessageQueue|ObjectProphecy $flashMessageQueue */ $flashMessageQueue = $this->prophesize(FlashMessageQueue::class); $flashMessageService->getMessageQueueByIdentifier(Argument::cetera())->willReturn($flashMessageQueue->reveal()); $flashMessageQueue->enqueue($flashMessage)->shouldBeCalled(); $this->subject->addData($input); }
/** * @test */ public function getLayoutPathAndFilenameRespectsCasingOfLayoutName() { $singletonInstances = GeneralUtility::getSingletonInstances(); $mockParsedTemplate = $this->getMock(ParsedTemplateInterface::class); $mockTemplateParser = $this->getMock(TemplateParser::class); $mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($mockParsedTemplate)); /** @var ObjectManager|\PHPUnit_Framework_MockObject_MockObject $mockObjectManager */ $mockObjectManager = $this->getMock(ObjectManager::class); $mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $mockRequest = $this->getMock(WebRequest::class); $mockControllerContext = $this->getMock(ControllerContext::class); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); $mockViewHelperVariableContainer = $this->getMock(ViewHelperVariableContainer::class); /** @var RenderingContext|\PHPUnit_Framework_MockObject_MockObject $mockRenderingContext */ $mockRenderingContext = $this->getMock(RenderingContext::class); $mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($mockControllerContext)); $mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($mockViewHelperVariableContainer)); /** @var TemplateView|\PHPUnit_Framework_MockObject_MockObject|AccessibleObjectInterface $view */ $view = $this->getAccessibleMock(TemplateView::class, array('testFileExistence', 'buildParserConfiguration'), array(), '', FALSE); $view->_set('templateParser', $mockTemplateParser); $view->_set('objectManager', $mockObjectManager); $view->setRenderingContext($mockRenderingContext); $mockTemplateCompiler = $this->getMock(TemplateCompiler::class); $view->_set('templateCompiler', $mockTemplateCompiler); GeneralUtility::setSingletonInstance(ObjectManager::class, $mockObjectManager); $mockContentObject = $this->getMock(ContentObjectRenderer::class); GeneralUtility::addInstance(ContentObjectRenderer::class, $mockContentObject); /** @var CacheManager|\PHPUnit_Framework_MockObject_MockObject $mockCacheManager */ $mockCacheManager = $this->getMock(CacheManager::class, array(), array(), '', FALSE); $mockCache = $this->getMock(PhpFrontend::class, array(), array(), '', FALSE); $mockCacheManager->expects($this->any())->method('getCache')->will($this->returnValue($mockCache)); GeneralUtility::setSingletonInstance(CacheManager::class, $mockCacheManager); $mockRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html')); $view->setLayoutRootPaths(array('some/Default/Directory')); $view->setTemplateRootPaths(array('some/Default/Directory')); $view->setPartialRootPaths(array('some/Default/Directory')); $view->expects($this->at(0))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/LayoutName.html')->willReturn(FALSE); $view->expects($this->at(1))->method('testFileExistence')->with(PATH_site . 'some/Default/Directory/layoutName.html')->willReturn(TRUE); $this->assertSame(PATH_site . 'some/Default/Directory/layoutName.html', $view->_call('getLayoutPathAndFilename', 'layoutName')); GeneralUtility::purgeInstances(); GeneralUtility::resetSingletonInstances($singletonInstances); }
/** * @test */ public function purgeInstancesDropsAddedInstance() { $instance = $this->getMock('foo'); $className = get_class($instance); Utility\GeneralUtility::addInstance($className, $instance); Utility\GeneralUtility::purgeInstances(); $this->assertNotSame($instance, Utility\GeneralUtility::makeInstance($className)); }
/** * @test */ public function isServerRunningReturnsFalseForStoppedServer() { $registryMock = $this->prophet->prophesize('TYPO3\\CMS\\Core\\Registry'); $registryMock->get('tx_tika', 'server.pid')->willReturn(''); GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Registry', $registryMock->reveal()); $processMock = $this->prophet->prophesize('ApacheSolrForTypo3\\Tika\\Process'); $processMock->findPid()->willReturn(''); GeneralUtility::addInstance('ApacheSolrForTypo3\\Tika\\Process', $processMock->reveal()); $service = new ServerService($this->getConfiguration()); $this->assertFalse($service->isServerRunning()); }