|
2 | 2 |
|
3 | 3 | namespace Laracasts\Integrated\Extensions; |
4 | 4 |
|
5 | | -use PHPUnit_Framework_ExpectationFailedException as PHPUnitException; |
6 | | -use Laracasts\Integrated\Extensions\Traits\ApiRequests; |
| 5 | +use Laracasts\Integrated\Extensions\Traits\LaravelTestCase; |
7 | 6 | use Illuminate\Foundation\Testing\TestCase; |
8 | | -use Symfony\Component\DomCrawler\Crawler; |
9 | | -use Symfony\Component\DomCrawler\Form; |
10 | 7 | use Laracasts\Integrated\Emulator; |
11 | 8 |
|
12 | 9 | abstract class Laravel extends TestCase implements Emulator |
13 | 10 | { |
14 | | - use IntegrationTrait, ApiRequests; |
15 | | - |
16 | | - /** |
17 | | - * Enable method spoofing for HTML forms with a "_method" attribute. |
18 | | - * |
19 | | - * @setUp |
20 | | - */ |
21 | | - protected function enableMethodSpoofing() |
22 | | - { |
23 | | - $this->app['request']->enableHttpMethodParameterOverride(); |
24 | | - } |
25 | | - |
26 | | - /** |
27 | | - * Get the base url for all requests. |
28 | | - * |
29 | | - * @return string |
30 | | - */ |
31 | | - public function baseUrl() |
32 | | - { |
33 | | - return "http://localhost"; |
34 | | - } |
35 | | - |
36 | | - /** |
37 | | - * Submit a form on the page. |
38 | | - * |
39 | | - * @param string $buttonText |
40 | | - * @param array $formData |
41 | | - * @return static |
42 | | - */ |
43 | | - public function submitForm($buttonText, $formData = []) |
44 | | - { |
45 | | - $this->makeRequestUsingForm( |
46 | | - $this->fillForm($buttonText, $formData) |
47 | | - ); |
48 | | - |
49 | | - return $this; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * Call a URI in the application. |
54 | | - * |
55 | | - * @param string $requestType |
56 | | - * @param string $uri |
57 | | - * @param array $parameters |
58 | | - * @param array $cookies |
59 | | - * @param array $files |
60 | | - * @return static |
61 | | - */ |
62 | | - protected function makeRequest($requestType, $uri, $parameters = [], $cookies = [], $files = []) |
63 | | - { |
64 | | - $this->call($requestType, $uri, $parameters, $cookies, $files); |
65 | | - |
66 | | - $this->clearInputs()->followRedirects()->assertPageLoaded($uri); |
67 | | - |
68 | | - // We'll set the current page again here, since it's possible |
69 | | - // that the user was redirected. |
70 | | - |
71 | | - $this->currentPage = $this->app['request']->fullUrl(); |
72 | | - |
73 | | - $this->crawler = new Crawler($this->response(), $this->currentPage()); |
74 | | - |
75 | | - return $this; |
76 | | - } |
77 | | - |
78 | | - /** |
79 | | - * Follow 302 redirections. |
80 | | - * |
81 | | - * @return void |
82 | | - */ |
83 | | - protected function followRedirects() |
84 | | - { |
85 | | - while ($this->response->isRedirect()) { |
86 | | - $this->makeRequest('GET', $this->response->getTargetUrl()); |
87 | | - } |
88 | | - |
89 | | - return $this; |
90 | | - } |
91 | | - |
92 | | - /** |
93 | | - * Make a request to a URL using form parameters. |
94 | | - * |
95 | | - * @param Form $form |
96 | | - * @return static |
97 | | - */ |
98 | | - protected function makeRequestUsingForm(Form $form) |
99 | | - { |
100 | | - return $this->makeRequest( |
101 | | - $form->getMethod(), $form->getUri(), $form->getValues(), [], $form->getFiles() |
102 | | - ); |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Get the number of rows that match the given condition. |
107 | | - * |
108 | | - * @param string $table |
109 | | - * @param array $data |
110 | | - * @return integer |
111 | | - */ |
112 | | - protected function seeRowsWereReturned($table, $data) |
113 | | - { |
114 | | - return $this->app['db']->table($table)->where($data)->count(); |
115 | | - } |
116 | | - |
117 | | - /** |
118 | | - * Get the content from the reponse. |
119 | | - * |
120 | | - * @return string |
121 | | - */ |
122 | | - protected function response() |
123 | | - { |
124 | | - return $this->response->getContent(); |
125 | | - } |
126 | | - |
127 | | - /** |
128 | | - * Get the status code from the last request. |
129 | | - * |
130 | | - * @return string |
131 | | - */ |
132 | | - protected function statusCode() |
133 | | - { |
134 | | - return $this->response->getStatusCode(); |
135 | | - } |
136 | | - |
137 | | - /** |
138 | | - * Provide additional messaging for 500 errors. |
139 | | - * |
140 | | - * @param string|null $message |
141 | | - * @throws PHPUnitException |
142 | | - * @return void |
143 | | - */ |
144 | | - protected function handleInternalError($message = null) |
145 | | - { |
146 | | - $crawler = new Crawler($this->response(), $this->currentPage()); |
147 | | - |
148 | | - // A little weird, but we need to parse the output HTML to |
149 | | - // figure out the specifics of where the error occurred. |
150 | | - // There might be an easier way to figure this out. |
151 | | - |
152 | | - $crawler = $crawler->filter('.exception_title'); |
153 | | - $exception = $crawler->filter('abbr')->html(); |
154 | | - $location = $crawler->filter('a')->extract('title')[0]; |
155 | | - |
156 | | - $message .= "\n\n{$exception} on {$location}"; |
157 | | - |
158 | | - throw new PHPUnitException($message); |
159 | | - } |
160 | | - |
| 11 | + use LaravelTestCase; |
161 | 12 | } |
0 commit comments