Completed
Pull Request — 3.1 (#348)
by Piotr
01:23
created

GenericCRUDElementSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\FSi\Bundle\AdminBundle\Admin\CRUD;
11
12
use FSi\Bundle\AdminBundle\Exception\RuntimeException;
13
use FSi\Component\DataGrid\DataGridFactory;
14
use FSi\Component\DataGrid\DataGridInterface;
15
use FSi\Component\DataSource\DataSourceFactoryInterface;
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Symfony\Component\Form\FormFactoryInterface;
19
use FSi\Bundle\AdminBundle\spec\fixtures\MyCRUD;
20
use FSi\Bundle\AdminBundle\Admin\CRUD\GenericCRUDElement;
21
use FSi\Bundle\AdminBundle\Admin\Element;
22
23
class GenericCRUDElementSpec extends ObjectBehavior
24
{
25
    function let()
26
    {
27
        $this->beAnInstanceOf(MyCRUD::class);
28
        $this->beConstructedWith([]);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType(GenericCRUDElement::class);
34
    }
35
36
    function it_is_admin_element()
37
    {
38
        $this->shouldHaveType(Element::class);
39
    }
40
41
    function it_has_default_route()
42
    {
43
        $this->getRoute()->shouldReturn('fsi_admin_list');
44
    }
45
46
    function it_throws_exception_when_init_datagrid_does_not_return_instance_of_datagrid(DataGridFactory $factory)
47
    {
48
        $this->setDataGridFactory($factory);
49
        $factory->createDataGrid(Argument::cetera())->willReturn(null);
50
51
        $this->shouldThrow(\TypeError::class)
52
            ->during('createDataGrid');
53
    }
54
55
    function it_adds_batch_column_to_datagrid_when_element_allow_delete_objects(
56
        DataGridFactory $factory,
57
        DataGridInterface $datagrid
58
    ) {
59
        $factory->createDataGrid('my_datagrid')->shouldBeCalled()->willReturn($datagrid);
60
        $datagrid->hasColumnType('batch')->shouldBeCalled()->willReturn(false);
61
        $datagrid->addColumn('batch', 'batch', [
62
            'actions' => [
63
                'delete' => [
64
                    'route_name' => 'fsi_admin_batch',
65
                    'additional_parameters' => ['element' => $this->getId()],
66
                    'label' => 'crud.list.batch.delete'
67
                ]
68
            ],
69
            'display_order' => -1000
70
        ])->shouldBeCalled();
71
72
        $this->setDataGridFactory($factory);
73
74
        $this->createDataGrid()->shouldReturn($datagrid);
75
    }
76
77
    function it_throws_exception_when_init_datasource_does_not_return_instance_of_datasource(
78
        DataSourceFactoryInterface $factory
79
    ) {
80
        $this->setDataSourceFactory($factory);
81
        $factory->createDataSource(Argument::cetera())->willReturn(null);
82
83
        $this->shouldThrow(\TypeError::class)
84
            ->during('createDataSource');
85
    }
86
87
    function it_throws_exception_when_init_form_does_not_return_instance_of_form(FormFactoryInterface $factory)
88
    {
89
        $this->setFormFactory($factory);
90
        $factory->create(Argument::cetera())->willReturn(null);
91
92
        $this->shouldThrow(\TypeError::class)
93
            ->during('createForm', [null]);
94
    }
95
96
    function it_has_default_options_values()
97
    {
98
        $options = $this->getOptions();
99
        $options->shouldHaveKey('allow_delete');
100
        $options->shouldHaveKey('allow_add');
101
        $options->shouldHaveKey('template_crud_list');
102
        $options->shouldHaveKey('template_crud_create');
103
        $options->shouldHaveKey('template_crud_edit');
104
        $options->shouldHaveKey('template_list');
105
        $options->shouldHaveKey('template_form');
106
        $options['allow_delete']->shouldBe(true);
107
        $options['allow_add']->shouldBe(true);
108
        $options['template_crud_list']->shouldBe(null);
109
        $options['template_crud_create']->shouldBe(null);
110
        $options['template_crud_edit']->shouldBe(null);
111
        $options['template_list']->shouldBe(null);
112
        $options['template_form']->shouldBe(null);
113
    }
114
}
115