本文整理汇总了PHP中TYPO3\CMS\Core\Utility\GeneralUtility::addInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP GeneralUtility::addInstance方法的具体用法?PHP GeneralUtility::addInstance怎么用?PHP GeneralUtility::addInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\GeneralUtility
的用法示例。
在下文中一共展示了GeneralUtility::addInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: respectHtmlCanBeDisabled
/**
* @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);
}
示例2: doMailCallsHook
/**
* 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 = 'john@example.com';
$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;
}
示例3: setUp
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);
}
示例4: renderCallsIconFactoryWithGivenOverlayAndReturnsResult
/**
* @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'));
}
示例5: compileThrowsExceptionIfDataProviderDoesNotImplementInterface
/**
* @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([]);
}
示例6: extendAdminPanelHookCallsExtendAdminPanelMethodOfHook
/**
* @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();
}
示例7: isGetPageHookCalled
/**
* 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);
}
示例8: setUp
/**
* 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());
}
示例9: setUp
/**
*
*/
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);
}
示例10: getDriverObjectAcceptsDriverClassName
/**
* @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);
}
示例11: compileThrowsExceptionIfDataProviderDoesNotImplementInterface
/**
* @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([]);
}
示例12: addDataSetsDatabaseData
/**
* @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));
}
示例13: getAuthInfoArrayReturnsEmptyPidListIfNoCheckPidValueIsGiven
/**
* @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']);
}
示例14: logoffCleansFormProtectionIfBackendUserIsLoggedIn
/**
* @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();
}
示例15: addDataAddsTreeConfigurationForExtJs
/**
* @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));
}