Completed
Push — master ( 79027c...8f1f38 )
by Oleg
03:47
created

TextTest::toArrayStub()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Malezha\Menu\Tests\ElementTests;
3
4
use Malezha\Menu\Element\Text;
5
use Malezha\Menu\Factory\TextFactory;
6
use Malezha\Menu\Tests\TestCase;
7
8
/**
9
 * Class TextTest
10
 * @package Malezha\Menu\Tests\ElementTests
11
 */
12
class TextTest extends TestCase
13
{
14
    /**
15
     * @return TextFactory
16
     */
17
    protected function factory()
18
    {
19
        return new TextFactory($this->app);
20
    }
21
22
    protected function elementRender()
23
    {
24
        return "<li data-value=\"Element\">Element</li>\n";
25
    }
26
    
27
    protected function serializeStub()
28
    {
29
        return $this->getStub('serialized/text_element.txt');
30
    }
31
    
32
    protected function toArrayStub()
33
    {
34
        return [
35
            'view' => config('menu.elements')[Text::class]['view'],
36
            'text' => 'To array',
37
            'attributes' => [
38
                'class' => 'arrayable',
39
            ],
40
            'displayRule' => true
41
        ];
42
    }
43
    
44
    public function testFactory()
45
    {
46
        $factory = $this->factory();
47
        $factory->text = 'Some text';
48
        $factory->attributes->put('class', 'text-element');
49
        $text = $factory->build();
50
51
        $this->assertAttributeEquals('Some text', 'text', $text);
52
        $this->assertEquals('text-element', $text->attributes->get('class'));
53
    }
54
55
    public function testElement()
56
    {
57
        $factory = $this->factory();
58
        $element = $factory->build();
59
60
        $element->text = 'Element';
61
        $element->attributes->put('data-value', $element->text);
62
        
63
        $this->assertEquals('Element', $element->text);
64
        $this->assertEquals($element->text, $element->attributes->get('data-value'));
65
        $this->assertEquals($this->elementRender(), $element->render());
66
    }
67
    
68
    public function testToArray()
69
    {
70
        $factory = $this->factory();
71
        $factory->text = 'To array';
72
        $factory->attributes->put('class', 'arrayable');
73
        $element = $factory->build();
74
        
75
        $this->assertEquals($this->toArrayStub(), $element->toArray());
76
    }
77
    
78
    public function testView()
79
    {
80
        view()->addLocation(__DIR__ . '/../stub');
81
        $this->app['config']->prepend('menu.paths', __DIR__ . '/../stub');
82
        $view = 'text_element';
83
84
        $element = $this->factory()->build(['text' => 'Block']);
85
        $element->setView($view);
86
        $this->assertAttributeEquals($view, 'view', $element);
87
        $this->assertEquals($view, $element->getView());
88
        $this->assertEquals('<div>Block</div>', $element->render());
89
    }
90
}