Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Testing;
4
 
5
use Illuminate\Testing\Assert as PHPUnit;
6
use Illuminate\Testing\Constraints\SeeInOrder;
7
 
8
class TestComponent
9
{
10
    /**
11
     * The original component.
12
     *
13
     * @var \Illuminate\View\Component
14
     */
15
    public $component;
16
 
17
    /**
18
     * The rendered component contents.
19
     *
20
     * @var string
21
     */
22
    protected $rendered;
23
 
24
    /**
25
     * Create a new test component instance.
26
     *
27
     * @param  \Illuminate\View\Component  $component
28
     * @param  \Illuminate\View\View  $view
29
     * @return void
30
     */
31
    public function __construct($component, $view)
32
    {
33
        $this->component = $component;
34
 
35
        $this->rendered = $view->render();
36
    }
37
 
38
    /**
39
     * Assert that the given string is contained within the rendered component.
40
     *
41
     * @param  string  $value
42
     * @param  bool  $escape
43
     * @return $this
44
     */
45
    public function assertSee($value, $escape = true)
46
    {
47
        $value = $escape ? e($value) : $value;
48
 
49
        PHPUnit::assertStringContainsString((string) $value, $this->rendered);
50
 
51
        return $this;
52
    }
53
 
54
    /**
55
     * Assert that the given strings are contained in order within the rendered component.
56
     *
57
     * @param  array  $values
58
     * @param  bool  $escape
59
     * @return $this
60
     */
61
    public function assertSeeInOrder(array $values, $escape = true)
62
    {
63
        $values = $escape ? array_map('e', $values) : $values;
64
 
65
        PHPUnit::assertThat($values, new SeeInOrder($this->rendered));
66
 
67
        return $this;
68
    }
69
 
70
    /**
71
     * Assert that the given string is contained within the rendered component text.
72
     *
73
     * @param  string  $value
74
     * @param  bool  $escape
75
     * @return $this
76
     */
77
    public function assertSeeText($value, $escape = true)
78
    {
79
        $value = $escape ? e($value) : $value;
80
 
81
        PHPUnit::assertStringContainsString((string) $value, strip_tags($this->rendered));
82
 
83
        return $this;
84
    }
85
 
86
    /**
87
     * Assert that the given strings are contained in order within the rendered component text.
88
     *
89
     * @param  array  $values
90
     * @param  bool  $escape
91
     * @return $this
92
     */
93
    public function assertSeeTextInOrder(array $values, $escape = true)
94
    {
95
        $values = $escape ? array_map('e', $values) : $values;
96
 
97
        PHPUnit::assertThat($values, new SeeInOrder(strip_tags($this->rendered)));
98
 
99
        return $this;
100
    }
101
 
102
    /**
103
     * Assert that the given string is not contained within the rendered component.
104
     *
105
     * @param  string  $value
106
     * @param  bool  $escape
107
     * @return $this
108
     */
109
    public function assertDontSee($value, $escape = true)
110
    {
111
        $value = $escape ? e($value) : $value;
112
 
113
        PHPUnit::assertStringNotContainsString((string) $value, $this->rendered);
114
 
115
        return $this;
116
    }
117
 
118
    /**
119
     * Assert that the given string is not contained within the rendered component text.
120
     *
121
     * @param  string  $value
122
     * @param  bool  $escape
123
     * @return $this
124
     */
125
    public function assertDontSeeText($value, $escape = true)
126
    {
127
        $value = $escape ? e($value) : $value;
128
 
129
        PHPUnit::assertStringNotContainsString((string) $value, strip_tags($this->rendered));
130
 
131
        return $this;
132
    }
133
 
134
    /**
135
     * Get the string contents of the rendered component.
136
     *
137
     * @return string
138
     */
139
    public function __toString()
140
    {
141
        return $this->rendered;
142
    }
143
 
144
    /**
145
     * Dynamically access properties on the underlying component.
146
     *
147
     * @param  string  $attribute
148
     * @return mixed
149
     */
150
    public function __get($attribute)
151
    {
152
        return $this->component->{$attribute};
153
    }
154
 
155
    /**
156
     * Dynamically call methods on the underlying component.
157
     *
158
     * @param  string  $method
159
     * @param  array  $parameters
160
     * @return mixed
161
     */
162
    public function __call($method, $parameters)
163
    {
164
        return $this->component->{$method}(...$parameters);
165
    }
166
}