|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\FSi\Bundle\AdminBundle\Admin\CRUD\Context; |
|
4
|
|
|
|
|
5
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\Request\HandlerInterface; |
|
6
|
|
|
use FSi\Bundle\AdminBundle\Doctrine\Admin\BatchElement; |
|
7
|
|
|
use PhpSpec\ObjectBehavior; |
|
8
|
|
|
use Prophecy\Argument; |
|
9
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
10
|
|
|
use Symfony\Component\Form\FormInterface; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
use FSi\Bundle\AdminBundle\Admin\Context\ContextInterface; |
|
15
|
|
|
use FSi\Bundle\AdminBundle\Event\FormEvent; |
|
16
|
|
|
|
|
17
|
|
|
class BatchElementContextSpec extends ObjectBehavior |
|
18
|
|
|
{ |
|
19
|
|
|
function let( |
|
20
|
|
|
BatchElement $element, |
|
21
|
|
|
FormBuilderInterface $formBuilder, |
|
22
|
|
|
FormInterface $batchForm, |
|
23
|
|
|
HandlerInterface $handler |
|
24
|
|
|
) { |
|
25
|
|
|
$this->beConstructedWith([$handler], $formBuilder); |
|
26
|
|
|
$formBuilder->getForm()->willReturn($batchForm); |
|
27
|
|
|
$this->setElement($element); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
function it_is_context() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->shouldBeAnInstanceOf(ContextInterface::class); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
function it_has_array_data() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->getData()->shouldBeArray(); |
|
38
|
|
|
$this->getData()->shouldHaveKeyInArray('form'); |
|
39
|
|
|
$this->getData()->shouldHaveKeyInArray('element'); |
|
40
|
|
|
$this->getData()->shouldHaveKeyInArray('indexes'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
function it_does_not_have_template_name() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->hasTemplateName()->shouldReturn(false); |
|
46
|
|
|
$this->getTemplateName()->shouldReturn(null); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_handles_request_with_request_handlers( |
|
50
|
|
|
HandlerInterface $handler, |
|
51
|
|
|
Request $request, |
|
52
|
|
|
ParameterBag $requestParameterBag |
|
53
|
|
|
) { |
|
54
|
|
|
$handler->handleRequest(Argument::type(FormEvent::class), $request) |
|
55
|
|
|
->willReturn(null); |
|
56
|
|
|
|
|
57
|
|
|
$request->request = $requestParameterBag; |
|
58
|
|
|
$requestParameterBag->get('indexes', [])->willReturn([]); |
|
59
|
|
|
|
|
60
|
|
|
$this->handleRequest($request)->shouldReturn(null); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_return_response_from_handler( |
|
64
|
|
|
HandlerInterface $handler, |
|
65
|
|
|
Request $request, |
|
66
|
|
|
ParameterBag $requestParameterBag, |
|
67
|
|
|
Response $response |
|
68
|
|
|
) { |
|
69
|
|
|
$handler->handleRequest(Argument::type(FormEvent::class), $request) |
|
70
|
|
|
->willReturn($response); |
|
71
|
|
|
|
|
72
|
|
|
$request->request = $requestParameterBag; |
|
73
|
|
|
$requestParameterBag->get('indexes', [])->willReturn([]); |
|
74
|
|
|
|
|
75
|
|
|
$this->handleRequest($request) |
|
76
|
|
|
->shouldReturnAnInstanceOf(Response::class); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getMatchers(): array |
|
80
|
|
|
{ |
|
81
|
|
|
return [ |
|
82
|
|
|
'haveKeyInArray' => function($subject, $key) { |
|
83
|
|
|
if (!is_array($subject)) { |
|
84
|
|
|
return false; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return array_key_exists($key, $subject); |
|
88
|
|
|
}, |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|