Skip to content
Snippets Groups Projects
Commit fea7b36d authored by Sebastian Michaelsen's avatar Sebastian Michaelsen Committed by Alexander Opitz
Browse files

[TASK] Avoid using $GLOBALS['TYPO3_DB'] in DataHandler

Instead of $GLOBALS['TYPO3_DB'] a type hinted property
$this->databaseConnection is used to gain autocompletion and better IDE
inspection in this class.

Resolves: #63326
Releases: master
Change-Id: I97a7158fd7a19ecb9687e66906392678d53b58f6
Reviewed-on: http://review.typo3.org/34614


Reviewed-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Tested-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Reviewed-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
Tested-by: default avatarAlexander Opitz <opitz.alexander@googlemail.com>
parent 9389273c
Branches
Tags
No related merge requests found
This diff is collapsed.
......@@ -14,6 +14,11 @@ namespace TYPO3\CMS\Core\Tests\Unit\DataHandler;
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Dbal\Database\DatabaseConnection;
/**
* Test case
*
......@@ -28,7 +33,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
protected $singletonInstances = array();
/**
* @var \TYPO3\CMS\Core\DataHandling\DataHandler
* @var DataHandler
*/
protected $subject;
......@@ -39,14 +44,15 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
public function setUp() {
$GLOBALS['TCA'] = array();
$this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
$this->singletonInstances = GeneralUtility::getSingletonInstances();
$this->backEndUser = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
$this->subject = new \TYPO3\CMS\Core\DataHandling\DataHandler();
$GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array(), array(), '', FALSE);
$this->subject = new DataHandler();
$this->subject->start(array(), '', $this->backEndUser);
}
public function tearDown() {
\TYPO3\CMS\Core\Utility\GeneralUtility::resetSingletonInstances($this->singletonInstances);
GeneralUtility::resetSingletonInstances($this->singletonInstances);
parent::tearDown();
}
......@@ -57,7 +63,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
* @test
*/
public function fixtureCanBeCreated() {
$this->assertTrue($this->subject instanceof \TYPO3\CMS\Core\DataHandling\DataHandler);
$this->assertTrue($this->subject instanceof DataHandler);
}
//////////////////////////////////////////
......@@ -166,7 +172,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
* @dataProvider inputValuesStringsDataProvider
*/
public function inputValueCheckRecognizesStringValuesAsIntegerValuesCorrectly($value, $expectedReturnValue) {
$GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
$tcaFieldConf = array(
'input' => array(),
'eval' => 'int',
......@@ -187,7 +192,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
* Tests whether a wrong interface on the 'checkModifyAccessList' hook throws an exception.
*
* @test
* @expectedException UnexpectedValueException
* @expectedException \UnexpectedValueException
*/
public function doesCheckModifyAccessListThrowExceptionOnWrongHookInterface() {
$hookClass = uniqid('tx_coretest');
......@@ -233,11 +238,12 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
* @test
*/
public function processDatamapForFrozenNonZeroWorkspaceReturnsFalse() {
$fixture = $this->getMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('newlog'));
/** @var DataHandler $subject */
$subject = $this->getMock(DataHandler::class, array('newlog'));
$this->backEndUser->workspace = 1;
$this->backEndUser->workspaceRec = array('freeze' => TRUE);
$fixture->BE_USER = $this->backEndUser;
$this->assertFalse($fixture->process_datamap());
$subject->BE_USER = $this->backEndUser;
$this->assertFalse($subject->process_datamap());
}
/**
......@@ -248,19 +254,18 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
// @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 */
/** @var $subject DataHandler|\PHPUnit_Framework_MockObject_MockObject */
$subject = $this->getMock(
'TYPO3\\CMS\\Core\\DataHandling\\DataHandler',
DataHandler::class,
array('newlog', 'checkModifyAccessList', 'tableReadOnly', 'checkRecordUpdateAccess')
);
$subject->bypassWorkspaceRestrictions = FALSE;
$subject->datamap = array(
'pages' => array(
......@@ -272,6 +277,8 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
$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));
/** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $backEndUser */
$backEndUser = $this->getMock('TYPO3\\CMS\\Core\\Authentication\\BackendUserAuthentication');
$backEndUser->workspace = 1;
$backEndUser->workspaceRec = array('freeze' => FALSE);
......@@ -279,7 +286,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
$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 = $this->getMock(DataHandler::class, array());
$createdTceMain->expects($this->once())->method('start')->with(array(), array(
'pages' => array(
1 => array(
......@@ -293,7 +300,7 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
));
$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);
GeneralUtility::addInstance(DataHandler::class, $createdTceMain);
$subject->process_datamap();
}
......@@ -301,7 +308,6 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
* @test
*/
public function doesCheckFlexFormValueHookGetsCalled() {
$GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
$hookClass = uniqid('tx_coretest');
$hookMock = $this->getMock($hookClass, array('checkFlexFormValue_beforeMerge'));
$hookMock->expects($this->once())->method('checkFlexFormValue_beforeMerge');
......@@ -570,8 +576,9 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
public function getPlaceholderTitleForTableLabelReturnsLabelThatsMatchesLabelFieldConditions($expected, $eval) {
$table = 'phpunit_dummy';
/** @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $subject */
$subject = $this->getAccessibleMock(
'TYPO3\\CMS\\Core\\DataHandling\\DataHandler',
DataHandler::class,
array('dummy')
);
......@@ -635,8 +642,8 @@ class DataHandlerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
'1' => array('table' => uniqid('bar_'), 'id' => 67)
);
/** @var \TYPO3\CMS\Core\DataHandling\DataHandler $mockDataHandler */
$mockDataHandler = $this->getAccessibleMock('TYPO3\\CMS\\Core\\DataHandling\\DataHandler', array('getInlineFieldType', 'deleteAction', 'createRelationHandlerInstance'), array(), '', FALSE);
/** @var DataHandler|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $mockDataHandler */
$mockDataHandler = $this->getAccessibleMock(DataHandler::class, array('getInlineFieldType', 'deleteAction', 'createRelationHandlerInstance'), array(), '', FALSE);
$mockDataHandler->expects($this->once())->method('getInlineFieldType')->will($this->returnValue('field'));
$mockDataHandler->expects($this->once())->method('createRelationHandlerInstance')->will($this->returnValue($mockRelationHandler));
$mockDataHandler->expects($this->never())->method('deleteAction');
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment