TYPO3 testing framework that provides base classes and configuration for PHPUnit tests
There are no plans to support nimut/testing-framework for versions above TYPO3 v11. You are advised to switch to the
typo3/testing-framework for TYPO3 v12 and above. The typo3/testing-framework has improved support for testing more
than one version of the core. Further information and an introduction can be found in the official TYPO3 documentation:
bash
composer require --dev nimut/testing-framework
\Nimut\TestingFramework\TestCase\UnitTestCase
.bash
vendor/bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/UnitTests.xml \
typo3conf/ext/example_extension/Tests/Unit
\Nimut\TestingFramework\TestCase\ViewHelperBaseTestcase
.php
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $viewHelper;
protected function setUp()
{
parent::setUp();
$this->viewHelper = $this->getMockBuilder(RenderChildrenViewHelper::class)->setMethods(['renderChildren'])->getMock();
$this->injectDependenciesIntoViewHelper($this->viewHelper);
$this->viewHelper->initializeArguments();
}
\Nimut\TestingFramework\TestCase\FunctionalTestCase
.bash
vendor/bin/phpunit -c vendor/nimut/testing-framework/res/Configuration/FunctionalTests.xml \
typo3conf/ext/example_extension/Tests/Functional
composer.json
file to symlink your extension to the proper root-dir/web-dir.json
"scripts": {
"post-autoload-dump": [
"@prepare-extension-test-structure"
],
"prepare-extension-test-structure": [
"Nimut\\TestingFramework\\Composer\\ExtensionTestEnvironment::prepare"
]
}
$this->getDatabaseConnection()
to get an instance of\Nimut\TestingFramework\Database\DatabaseInterface
.$this->getDatabaseConnection()->getDatabaseInstance()
. You have to check weather this instance is a\TYPO3\CMS\Core\Database\Query\QueryBuilder
(TYPO3 CMS 8 and above) or an instance of\TYPO3\CMS\Core\Database\DatabaseConnection
(TYPO3 CMS 7).php
$this->importDataSet('ntf://Database/pages.xml');
php
// First import some page records
$this->importDataSet('ntf://Database/pages.xml');
// Import tt_content record that should be shown on your home page
$this->importDataSet('ntf://Database/tt_content.xml');
// Setup the page with uid 1 and include the TypoScript as sys_template record
$this->setUpFrontendRootPage(1, array('ntf://TypoScript/JsonRenderer.ts'));
// Fetch the frontend response
$response = $this->getFrontendResponse(1);
// Assert no error has occured
$this->assertSame('success', $response->getStatus());
// Get the first section from the response
$sections = $response->getResponseSections();
$defaultSection = array_shift($sections);
// Get the section structure
$structure = $defaultSection->getStructure();
// Make assertions for the structure
$this->assertTrue(is_array($structure['pages:1']['__contents']['tt_content:1']));
php
[
// Page for your request
'pages:1' => [
'uid' => '1',
'pid' => '0',
'sorting' => '0',
'title' => 'Root',
// Array with subpages
'__pages' => [
'pages:2' => [
'uid' => '2',
'pid' => '1',
'sorting' => '0',
'title' => 'Dummy 1-2',
],
'pages:5' => [
'uid' => '5',
'pid' => '1',
'sorting' => '0',
'title' => 'Dummy 1-5',
],
],
// Array with content elements
'__contents' => [
'tt_content:1' => [
'uid' => '1',
'pid' => '1',
'sorting' => '0',
'header' => 'Test content',
'sys_language_uid' => '0',
'categories' => '0',
],
],
],
]
php
// Setup the page with uid 1 and include ntf and own TypoScript
$this->setUpFrontendRootPage(
1,
array(
'ntf://TypoScript/JsonRenderer.ts',
'EXT:example_extension/Tests/Functional/Fixtures/TypoScript/Config.ts'
)
);
config.watcher.tableFields.tt_content = uid,_ORIG_uid,_LOCALIZED_UID,pid,sorting,sys_language_uid,header,categories,CType,subheader,bodytext