This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
FieldViewHelperServiceTest.php
81 lines (65 loc) 路 2.25 KB
/
FieldViewHelperServiceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
namespace Romm\Formz\Tests\Unit\Service\ViewHelper\Field;
use Romm\Formz\Configuration\Form\Field\Field;
use Romm\Formz\Configuration\View\Layouts\Layout;
use Romm\Formz\Service\ViewHelper\Field\FieldViewHelperService;
use Romm\Formz\Tests\Unit\AbstractUnitTest;
class FieldViewHelperServiceTest extends AbstractUnitTest
{
/**
* @test
*/
public function setCurrentFieldSetsCurrentField()
{
$fieldService = new FieldViewHelperService;
$field = new Field;
$this->assertFalse($fieldService->fieldContextExists());
$fieldService->setCurrentField($field);
$this->assertTrue($fieldService->fieldContextExists());
$this->assertSame($field, $fieldService->getCurrentField());
}
/**
* @test
*/
public function resetStateResetsState()
{
$fieldService = new FieldViewHelperService;
$field = new Field;
$this->assertFalse($fieldService->fieldContextExists());
$fieldService->setCurrentField($field);
$this->assertTrue($fieldService->fieldContextExists());
$fieldService->removeCurrentField();
$this->assertFalse($fieldService->fieldContextExists());
}
/**
* @test
*/
public function nestingFieldsWorks()
{
$fieldService = new FieldViewHelperService;
$field1 = new Field;
$field2 = new Field;
$fieldService->setCurrentField($field1);
$this->assertSame($field1, $fieldService->getCurrentField());
$fieldService->setCurrentField($field2);
$this->assertSame($field2, $fieldService->getCurrentField());
$fieldService->removeCurrentField();
$this->assertSame($field1, $fieldService->getCurrentField());
}
/**
* @test
*/
public function viewIsInstantiatedOncePerLayout()
{
$fieldService = new FieldViewHelperService;
$layout1 = new Layout;
$layout1->setTemplateFile('foo/bar');
$layout2 = new Layout;
$layout2->setTemplateFile('bar/baz');
$view1 = $fieldService->getView($layout1);
$view2 = $fieldService->getView($layout1);
$this->assertSame($view1, $view2);
$view3 = $fieldService->getView($layout2);
$this->assertNotSame($view1, $view3);
}
}