Completed
Push — master ( 14b415...20d98b )
by amaury
02:50
created

ContentTypeSubscriberTest::testFormFieldTransformationException()   B

↳ Parent: ContentTypeSubscriberTest

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 25
Code Lines 21

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 1
eloc 21
nc 1
nop 0
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\BackofficeBundle\EventSubscriber;
4
5
use OpenOrchestra\FunctionalTests\Utils\AbstractAuthenticatedTest;
6
use OpenOrchestra\ModelBundle\Document\Content;
7
use OpenOrchestra\ModelBundle\Document\ContentAttribute;
8
use OpenOrchestra\ModelBundle\Document\Status;
9
use Symfony\Component\Form\FormFactoryInterface;
10
11
/**
12
 * Class ContentTypeSubscriberTest
13
 *
14
 * @group backofficeTest
15
 */
16
class ContentTypeSubscriberTest extends AbstractAuthenticatedTest
17
{
18
    /**
19
     * @var FormFactoryInterface
20
     */
21
    protected $formFactory;
22
23
    /**
24
     * Set up the test
25
     */
26
    public function setUp()
27
    {
28
        parent::setUp();
29
        $this->formFactory = static::$kernel->getContainer()->get('form.factory');
30
    }
31
32
    /**
33
     * Test post set data form content
34
     *
35
     * @param mixed $attributeValue
36
     * @param mixed $fieldValue
37
     * @param int   $countError
38
     *
39
     * @dataProvider provideFormAttributeValue
40
     */
41
    public function testFormFieldTransformation($attributeValue, $fieldValue, $countError)
42
    {
43
        $status = new Status();
44
        $content = new Content();
45
        $content->setContentType("customer");
46
        $content->setStatus($status);
47
48
        $attribute = new ContentAttribute();
49
        $attribute->setName("identifier");
50
        $attribute->setValue($attributeValue);
51
        $attribute->setType('integer');
52
        $content->addAttribute($attribute);
53
54
        $form = $this->formFactory->create('oo_content', $content, array('csrf_protection' => false));
55
        $this->assertSame($countError, count($form->get('identifier')->getErrors()));
56
        $this->assertSame($fieldValue, $form->get('identifier')->getData());
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function provideFormAttributeValue()
63
    {
64
        return array(
65
            array(1, 1, 0),
66
            array(null, null, 0),
67
            array("not integer", null, 1),
68
            array(array("not integer"), null, 1),
69
        );
70
    }
71
72
    /**
73
     * Test submit form with transformation on one field
74
     */
75
    public function testFormFieldTransformationException()
76
    {
77
        $status = new Status();
78
        $content = new Content();
79
        $content->setContentType('news');
80
        $content->setSiteId('2');
81
        $content->setLanguage('fr');
82
        $content->setStatus($status);
83
84
        $form = $this->formFactory->create('oo_content', $content, array('csrf_protection' => false));
85
        $form->submit(array(
86
            'name' => 'foo',
87
            'keywords' => null,
88
            'title' => 'foo',
89
            'publish_start' => 'foo',
90
            'publish_end' => '2015-12-17',
91
            'image' => null,
92
            'intro' => 'foo',
93
            'text' => null
94
        ));
95
        $this->assertSame('foo', $form->get('name')->getData());
96
        $this->assertCount(1, $form->get('publish_start')->getErrors());
97
        $this->assertNull($form->get('publish_start')->getData());
98
        $this->assertCount(1, $form->getErrors(true));
99
    }
100
}
101