Commit 4a4cb910 authored by Anja Leichsenring's avatar Anja Leichsenring Committed by Andreas Fernandez
Browse files

[TASK] Add unit test for fatal error on null object method call

With #45685 a bugfix was merged. Now the corresponding
unit test is added as well.

Change-Id: Id62c4c7a29d2e28847381c18e963cb834e35fa01
Resolves: #69405
Relates: #45685
Releases: master, 6.2
Reviewed-on: http://review.typo3.org/42918

Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
parent 36b9b288
<?php
namespace typo3\sysext\form\Tests\Unit\Domain;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Model\Attribute\AbstractAttribute;
use TYPO3\CMS\Form\Domain\Model\Attribute\AttributesAttribute;
use TYPO3\CMS\Form\Localization;
use TYPO3\CMS\Form\Request;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* Test case for class \TYPO3\CMS\Form\Domain\Model\Attribute\AttributesAttribute
*/
class AttributesAttributeTest extends UnitTestCase {
/**
* @var AttributesAttribute
*/
protected $subject = NULL;
/**
* @var array A backup of registered singleton instances
*/
protected $singletonInstances = array();
/**
* @var string
*/
protected $elementId;
/**
*
*/
public function setUp(){
$contentObjectRendererProphecy = $this->prophesize(ContentObjectRenderer::class);
GeneralUtility::addInstance(ContentObjectRenderer::class, $contentObjectRendererProphecy->reveal());
$localisationProphecy = $this->prophesize(Localization::class);
GeneralUtility::addInstance(Localization::class, $localisationProphecy->reveal());
$requestProphecy = $this->prophesize(Request::class);
$this->singletonInstances = GeneralUtility::getSingletonInstances();
GeneralUtility::setSingletonInstance(Request::class, $requestProphecy->reveal());
$this->elementId = uniqid('elementId_', TRUE);
$this->subject = new AttributesAttribute($this->elementId);
}
/**
* Tear down the tests
*/
protected function tearDown() {
GeneralUtility::resetSingletonInstances($this->singletonInstances);
parent::tearDown();
}
/**
* @test
*/
public function hasAttributeReturnsFalseForMissingAttribute() {
$this->assertFalse($this->subject->hasAttribute('anAttribute'));
}
/**
* @test
*/
public function getValueReturnsEmptyIfAttributeIsNotSet() {
$this->assertEmpty($this->subject->getValue('anAttribute'));
}
/**
* @test
*/
public function getValueReturnsValueIfAttributeIsSet() {
$attributeProphecy = $this->prophesize(AbstractAttribute::class);
$attributeProphecy->getValue()->shouldBeCalled()->willReturn('aValue');
$this->subject->setAttribute('anAttribute', $attributeProphecy->reveal());
$this->assertSame('aValue', $this->subject->getValue('anAttribute'));
}
}
Supports Markdown
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