Completed
Push — master ( 08f7b1...ea4e28 )
by Eric
10:49
created

LabelButtonExtensionTest::testDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 16
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\ResourceBundle\Tests\Form\Extension;
13
14
use Lug\Bundle\ResourceBundle\Form\Extension\LabelButtonExtension;
15
use Lug\Bundle\ResourceBundle\Form\Extension\LabelFormExtension;
16
use Symfony\Component\Form\Extension\Core\Type\ButtonType;
17
use Symfony\Component\Form\Extension\Core\Type\FormType;
18
use Symfony\Component\Form\FormFactoryInterface;
19
use Symfony\Component\Form\Forms;
20
21
/**
22
 * @author GeLo <[email protected]>
23
 */
24
class LabelButtonExtensionTest extends \PHPUnit_Framework_TestCase
25
{
26
    /**
27
     * @var FormFactoryInterface
28
     */
29
    private $factory;
30
31
    /**
32
     * @var LabelButtonExtension
33
     */
34
    private $extension;
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    protected function setUp()
40
    {
41
        $this->extension = new LabelButtonExtension();
42
43
        $this->factory = Forms::createFormFactoryBuilder()
44
            ->addTypeExtension(new LabelFormExtension())
45
            ->addTypeExtension($this->extension)
46
            ->getFormFactory();
47
    }
48
49
    public function testInheritance()
50
    {
51
        $this->assertSame(ButtonType::class, $this->extension->getExtendedType());
52
    }
53
54 View Code Duplication
    public function testDefault()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
    {
56
        $form = $this->factory
57
            ->createBuilder(FormType::class)
58
            ->add($buttonName = 'button', ButtonType::class)
59
            ->getForm();
60
61
        $view = $form->createView();
62
        $buttonView = $view->children[$buttonName];
63
64
        $this->assertArrayHasKey('label', $buttonView->vars);
65
        $this->assertNull($buttonView->vars['label']);
66
67
        $this->assertArrayHasKey('label_translation_arguments', $buttonView->vars);
68
        $this->assertEmpty($buttonView->vars['label_translation_arguments']);
69
    }
70
71 View Code Duplication
    public function testLabelPrefix()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        $form = $this->factory
74
            ->createBuilder(FormType::class, null, ['label_prefix' => $labelPrefix = 'prefix'])
75
            ->add($buttonName = 'button', ButtonType::class)
76
            ->getForm();
77
78
        $view = $form->createView();
79
        $buttonView = $view->children[$buttonName];
80
81
        $this->assertArrayHasKey('label', $buttonView->vars);
82
        $this->assertSame($labelPrefix.'.'.$buttonName, $buttonView->vars['label']);
83
    }
84
85
    public function testLabelTranslationArguments()
86
    {
87
        $form = $this->factory->create(ButtonType::class, null, [
88
            'label_translation_arguments' => $arguments = ['foo' => 'bar'],
89
        ]);
90
91
        $view = $form->createView();
92
93
        $this->assertArrayHasKey('label_translation_arguments', $view->vars);
94
        $this->assertSame($arguments, $view->vars['label_translation_arguments']);
95
    }
96
}
97