Skip to content

Commit 7fd1ac8

Browse files
committed
chore: add unit tests for form modifier
1 parent 8638c1e commit 7fd1ac8

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\tao\test\unit\models\classes\form\Modifier;
24+
25+
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
26+
use oat\tao\model\form\Modifier\UniqueIdFormModifier;
27+
use oat\tao\model\TaoOntology;
28+
use PHPUnit\Framework\MockObject\MockObject;
29+
use PHPUnit\Framework\TestCase;
30+
use tao_helpers_form_Form;
31+
use tao_helpers_Uri;
32+
33+
class UniqueIdFormModifierTest extends TestCase
34+
{
35+
/** @var FeatureFlagCheckerInterface|MockObject */
36+
private $featureFlagChecker;
37+
38+
private UniqueIdFormModifier $sut;
39+
40+
protected function setUp(): void
41+
{
42+
$this->featureFlagChecker = $this->createMock(FeatureFlagCheckerInterface::class);
43+
$this->sut = new UniqueIdFormModifier($this->featureFlagChecker);
44+
}
45+
46+
public function testFeatureEnabled(): void
47+
{
48+
$this->featureFlagChecker
49+
->expects($this->once())
50+
->method('isEnabled')
51+
->willReturn(true);
52+
53+
$form = $this->createMock(tao_helpers_form_Form::class);
54+
55+
$form
56+
->expects($this->never())
57+
->method('removeElement');
58+
59+
$this->sut->modify($form);
60+
}
61+
62+
public function testFeatureDisabled(): void
63+
{
64+
$this->featureFlagChecker
65+
->expects($this->once())
66+
->method('isEnabled')
67+
->willReturn(false);
68+
69+
$form = $this->createMock(tao_helpers_form_Form::class);
70+
71+
$form
72+
->expects($this->once())
73+
->method('removeElement')
74+
->with(tao_helpers_Uri::encode(TaoOntology::PROPERTY_UNIQUE_IDENTIFIER));
75+
76+
$this->sut->modify($form);
77+
}
78+
}

0 commit comments

Comments
 (0)