IntegrationTestTraitTest.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\TestSuite;
  16. use Cake\Core\Configure;
  17. use Cake\Core\Plugin;
  18. use Cake\Event\EventManager;
  19. use Cake\Http\Response;
  20. use Cake\Routing\DispatcherFactory;
  21. use Cake\Routing\Router;
  22. use Cake\Routing\Route\InflectedRoute;
  23. use Cake\TestSuite\IntegrationTestCase;
  24. use Cake\Test\Fixture\AssertIntegrationTestCase;
  25. use Cake\Utility\Security;
  26. use PHPUnit\Framework\AssertionFailedError;
  27. use Zend\Diactoros\UploadedFile;
  28. /**
  29. * Self test of the IntegrationTestCase
  30. */
  31. class IntegrationTestTraitTest extends IntegrationTestCase
  32. {
  33. /**
  34. * Setup method
  35. *
  36. * @return void
  37. */
  38. public function setUp()
  39. {
  40. parent::setUp();
  41. static::setAppNamespace();
  42. Router::reload();
  43. Router::scope('/', function ($routes) {
  44. $routes->setRouteClass(InflectedRoute::class);
  45. $routes->get('/get/:controller/:action', []);
  46. $routes->head('/head/:controller/:action', []);
  47. $routes->options('/options/:controller/:action', []);
  48. $routes->connect('/:controller/:action/*', []);
  49. });
  50. Router::$initialized = true;
  51. $this->useHttpServer(true);
  52. $this->configApplication(Configure::read('App.namespace') . '\Application', null);
  53. DispatcherFactory::clear();
  54. }
  55. /**
  56. * Helper for enabling the legacy stack for backwards compatibility testing.
  57. *
  58. * @return void
  59. */
  60. protected function useLegacyDispatcher()
  61. {
  62. DispatcherFactory::add('Routing');
  63. DispatcherFactory::add('ControllerFactory');
  64. $this->useHttpServer(false);
  65. }
  66. /**
  67. * Tests that all data that used by the request is cast to strings
  68. *
  69. * @return void
  70. */
  71. public function testDataCastToString()
  72. {
  73. $data = [
  74. 'title' => 'Blog Post',
  75. 'status' => 1,
  76. 'published' => true,
  77. 'not_published' => false,
  78. 'comments' => [
  79. [
  80. 'body' => 'Comment',
  81. 'status' => 1,
  82. ]
  83. ],
  84. 'file' => [
  85. 'tmp_name' => __FILE__,
  86. 'size' => 42,
  87. 'error' => 0,
  88. 'type' => 'text/plain',
  89. 'name' => 'Uploaded file'
  90. ],
  91. 'pictures' => [
  92. 'name' => [
  93. ['file' => 'a-file.png'],
  94. ['file' => 'a-moose.png']
  95. ],
  96. 'type' => [
  97. ['file' => 'image/png'],
  98. ['file' => 'image/jpg']
  99. ],
  100. 'tmp_name' => [
  101. ['file' => __FILE__],
  102. ['file' => __FILE__]
  103. ],
  104. 'error' => [
  105. ['file' => 0],
  106. ['file' => 0]
  107. ],
  108. 'size' => [
  109. ['file' => 17188],
  110. ['file' => 2010]
  111. ],
  112. ],
  113. 'upload' => new UploadedFile(__FILE__, 42, 0)
  114. ];
  115. $request = $this->_buildRequest('/posts/add', 'POST', $data);
  116. $this->assertInternalType('string', $request['post']['status']);
  117. $this->assertInternalType('string', $request['post']['published']);
  118. $this->assertSame('0', $request['post']['not_published']);
  119. $this->assertInternalType('string', $request['post']['comments'][0]['status']);
  120. $this->assertInternalType('integer', $request['post']['file']['error']);
  121. $this->assertInternalType('integer', $request['post']['file']['size']);
  122. $this->assertInternalType('integer', $request['post']['pictures']['error'][0]['file']);
  123. $this->assertInternalType('integer', $request['post']['pictures']['error'][1]['file']);
  124. $this->assertInternalType('integer', $request['post']['pictures']['size'][0]['file']);
  125. $this->assertInternalType('integer', $request['post']['pictures']['size'][1]['file']);
  126. $this->assertInstanceOf(UploadedFile::class, $request['post']['upload']);
  127. }
  128. /**
  129. * Test building a request.
  130. *
  131. * @return void
  132. */
  133. public function testRequestBuilding()
  134. {
  135. $this->configRequest([
  136. 'headers' => [
  137. 'X-CSRF-Token' => 'abc123',
  138. 'Content-Type' => 'application/json',
  139. 'Accept' => 'application/json'
  140. ],
  141. 'base' => '',
  142. 'webroot' => '/',
  143. 'environment' => [
  144. 'PHP_AUTH_USER' => 'foo',
  145. 'PHP_AUTH_PW' => 'bar'
  146. ]
  147. ]);
  148. $this->cookie('split_token', 'def345');
  149. $this->session(['User' => ['id' => 1, 'username' => 'mark']]);
  150. $request = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']);
  151. $this->assertEquals('abc123', $request['environment']['HTTP_X_CSRF_TOKEN']);
  152. $this->assertEquals('application/json', $request['environment']['CONTENT_TYPE']);
  153. $this->assertEquals('/tasks/add', $request['url']);
  154. $this->assertArrayHasKey('split_token', $request['cookies']);
  155. $this->assertEquals('def345', $request['cookies']['split_token']);
  156. $this->assertEquals(['id' => '1', 'username' => 'mark'], $request['session']->read('User'));
  157. $this->assertEquals('foo', $request['environment']['PHP_AUTH_USER']);
  158. $this->assertEquals('bar', $request['environment']['PHP_AUTH_PW']);
  159. }
  160. /**
  161. * Test request building adds csrf tokens
  162. *
  163. * @return void
  164. */
  165. public function testRequestBuildingCsrfTokens()
  166. {
  167. $this->enableCsrfToken();
  168. $request = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']);
  169. $this->assertArrayHasKey('csrfToken', $request['cookies']);
  170. $this->assertArrayHasKey('_csrfToken', $request['post']);
  171. $this->assertSame($request['cookies']['csrfToken'], $request['post']['_csrfToken']);
  172. $this->cookie('csrfToken', '');
  173. $request = $this->_buildRequest('/tasks/add', 'POST', [
  174. '_csrfToken' => 'fale',
  175. 'title' => 'First post'
  176. ]);
  177. $this->assertSame('', $request['cookies']['csrfToken']);
  178. $this->assertSame('fale', $request['post']['_csrfToken']);
  179. }
  180. /**
  181. * Test multiple actions using CSRF tokens don't fail
  182. *
  183. * @return void
  184. */
  185. public function testEnableCsrfMultipleRequests()
  186. {
  187. $this->enableCsrfToken();
  188. $first = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']);
  189. $second = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'Second post']);
  190. $this->assertSame(
  191. $first['cookies']['csrfToken'],
  192. $second['post']['_csrfToken'],
  193. 'Csrf token should match cookie'
  194. );
  195. $this->assertSame(
  196. $first['post']['_csrfToken'],
  197. $second['post']['_csrfToken'],
  198. 'Tokens should be consistent per test method'
  199. );
  200. }
  201. /**
  202. * Test pre-determined CSRF tokens.
  203. *
  204. * @return void
  205. */
  206. public function testEnableCsrfPredeterminedCookie()
  207. {
  208. $this->enableCsrfToken();
  209. $value = 'I am a teapot';
  210. $this->cookie('csrfToken', $value);
  211. $request = $this->_buildRequest('/tasks/add', 'POST', ['title' => 'First post']);
  212. $this->assertSame($value, $request['cookies']['csrfToken'], 'Csrf token should match cookie');
  213. $this->assertSame($value, $request['post']['_csrfToken'], 'Tokens should match');
  214. }
  215. /**
  216. * Test building a request, with query parameters
  217. *
  218. * @return void
  219. */
  220. public function testRequestBuildingQueryParameters()
  221. {
  222. $request = $this->_buildRequest('/tasks/view?archived=yes', 'GET', []);
  223. $this->assertSame('/tasks/view', $request['url']);
  224. $this->assertSame('archived=yes', $request['environment']['QUERY_STRING']);
  225. $this->assertSame('/tasks/view', $request['environment']['REQUEST_URI']);
  226. }
  227. /**
  228. * Test cookie encrypted
  229. *
  230. * @see CookieComponentControllerTest
  231. */
  232. public function testCookieEncrypted()
  233. {
  234. Security::setSalt('abcdabcdabcdabcdabcdabcdabcdabcdabcd');
  235. $this->cookieEncrypted('KeyOfCookie', 'Encrypted with aes by default');
  236. $request = $this->_buildRequest('/tasks/view', 'GET', []);
  237. $this->assertStringStartsWith('Q2FrZQ==.', $request['cookies']['KeyOfCookie']);
  238. }
  239. /**
  240. * Test sending get requests.
  241. *
  242. * @group deprecated
  243. * @return void
  244. */
  245. public function testGetLegacy()
  246. {
  247. $this->useLegacyDispatcher();
  248. $this->deprecated(function () {
  249. $this->assertNull($this->_response);
  250. $this->get('/request_action/test_request_action');
  251. $this->assertNotEmpty($this->_response);
  252. $this->assertInstanceOf('Cake\Http\Response', $this->_response);
  253. $this->assertEquals('This is a test', $this->_response->getBody());
  254. $this->_response = null;
  255. $this->get('/get/request_action/test_request_action');
  256. $this->assertEquals('This is a test', $this->_response->getBody());
  257. });
  258. }
  259. /**
  260. * Test sending get request and using default `test_app/config/routes.php`.
  261. *
  262. * @return void
  263. */
  264. public function testGetUsingApplicationWithPluginRoutes()
  265. {
  266. // first clean routes to have Router::$initailized === false
  267. Router::reload();
  268. Plugin::unload();
  269. $this->configApplication(Configure::read('App.namespace') . '\ApplicationWithPluginRoutes', null);
  270. $this->get('/test_plugin');
  271. $this->assertResponseOk();
  272. }
  273. /**
  274. * Test sending get request and using default `test_app/config/routes.php`.
  275. *
  276. * @return void
  277. */
  278. public function testGetUsingApplicationWithDefaultRoutes()
  279. {
  280. // first clean routes to have Router::$initailized === false
  281. Router::reload();
  282. $this->configApplication(Configure::read('App.namespace') . '\ApplicationWithDefaultRoutes', null);
  283. $this->get('/some_alias');
  284. $this->assertResponseOk();
  285. $this->assertEquals('5', $this->_getBodyAsString());
  286. }
  287. public function testExceptionsInMiddlewareJsonView()
  288. {
  289. Router::reload();
  290. Router::connect('/json_response/api_get_data', [
  291. 'controller' => 'JsonResponse',
  292. 'action' => 'apiGetData'
  293. ]);
  294. $this->configApplication(Configure::read('App.namespace') . '\ApplicationWithExceptionsInMiddleware', null);
  295. $this->_request['headers'] = [ "Accept" => "application/json" ];
  296. $this->get('/json_response/api_get_data');
  297. $this->assertResponseCode(403);
  298. $this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
  299. $this->assertResponseContains('"message": "Sample Message"');
  300. $this->assertResponseContains('"code": 403');
  301. }
  302. /**
  303. * Test sending head requests.
  304. *
  305. * @return void
  306. */
  307. public function testHead()
  308. {
  309. $this->assertNull($this->_response);
  310. $this->head('/request_action/test_request_action');
  311. $this->assertNotEmpty($this->_response);
  312. $this->assertInstanceOf('Cake\Http\Response', $this->_response);
  313. $this->assertResponseSuccess();
  314. $this->_response = null;
  315. $this->head('/head/request_action/test_request_action');
  316. $this->assertResponseSuccess();
  317. }
  318. /**
  319. * Test sending options requests.
  320. *
  321. * @return void
  322. */
  323. public function testOptions()
  324. {
  325. $this->assertNull($this->_response);
  326. $this->options('/request_action/test_request_action');
  327. $this->assertNotEmpty($this->_response);
  328. $this->assertInstanceOf('Cake\Http\Response', $this->_response);
  329. $this->assertResponseSuccess();
  330. $this->_response = null;
  331. $this->options('/options/request_action/test_request_action');
  332. $this->assertResponseSuccess();
  333. }
  334. /**
  335. * Test sending get requests sets the request method
  336. *
  337. * @return void
  338. */
  339. public function testGetSpecificRouteLegacy()
  340. {
  341. $this->useLegacyDispatcher();
  342. $this->deprecated(function () {
  343. $this->get('/get/request_action/test_request_action');
  344. $this->assertResponseOk();
  345. $this->assertEquals('This is a test', $this->_response->getBody());
  346. });
  347. }
  348. /**
  349. * Test sending get requests sets the request method
  350. *
  351. * @return void
  352. */
  353. public function testGetSpecificRouteHttpServer()
  354. {
  355. $this->get('/get/request_action/test_request_action');
  356. $this->assertResponseOk();
  357. $this->assertEquals('This is a test', $this->_response->getBody());
  358. }
  359. /**
  360. * Test customizing the app class.
  361. *
  362. * @return void
  363. */
  364. public function testConfigApplication()
  365. {
  366. $this->expectException(\LogicException::class);
  367. $this->expectExceptionMessage('Cannot load "TestApp\MissingApp" for use in integration');
  368. $this->configApplication('TestApp\MissingApp', []);
  369. $this->get('/request_action/test_request_action');
  370. }
  371. /**
  372. * Test sending get requests with Http\Server
  373. *
  374. * @return void
  375. */
  376. public function testGetHttpServer()
  377. {
  378. $this->assertNull($this->_response);
  379. $this->get('/request_action/test_request_action');
  380. $this->assertNotEmpty($this->_response);
  381. $this->assertInstanceOf('Cake\Http\Response', $this->_response);
  382. $this->assertEquals('This is a test', $this->_response->getBody());
  383. $this->assertHeader('X-Middleware', 'true');
  384. }
  385. /**
  386. * Test that the PSR7 requests get query string data
  387. *
  388. * @return void
  389. */
  390. public function testGetQueryStringHttpServer()
  391. {
  392. $this->configRequest(['headers' => ['Content-Type' => 'text/plain']]);
  393. $this->get('/request_action/params_pass?q=query');
  394. $this->assertResponseOk();
  395. $this->assertResponseContains('"q":"query"');
  396. $this->assertResponseContains('"contentType":"text\/plain"');
  397. $this->assertHeader('X-Middleware', 'true');
  398. $request = $this->_controller->request;
  399. $this->assertContains('/request_action/params_pass?q=query', $request->getRequestTarget());
  400. }
  401. /**
  402. * Test that the PSR7 requests get query string data
  403. *
  404. * @group deprecated
  405. * @return void
  406. */
  407. public function testGetQueryStringSetsHere()
  408. {
  409. $this->deprecated(function () {
  410. $this->configRequest(['headers' => ['Content-Type' => 'text/plain']]);
  411. $this->get('/request_action/params_pass?q=query');
  412. $this->assertResponseOk();
  413. $this->assertResponseContains('"q":"query"');
  414. $this->assertResponseContains('"contentType":"text\/plain"');
  415. $this->assertHeader('X-Middleware', 'true');
  416. $request = $this->_controller->request;
  417. $this->assertContains('/request_action/params_pass?q=query', $request->here());
  418. $this->assertContains('/request_action/params_pass?q=query', $request->getRequestTarget());
  419. });
  420. }
  421. /**
  422. * Test that the PSR7 requests get cookies
  423. *
  424. * @return void
  425. */
  426. public function testGetCookiesHttpServer()
  427. {
  428. $this->configRequest(['cookies' => ['split_test' => 'abc']]);
  429. $this->get('/request_action/cookie_pass');
  430. $this->assertResponseOk();
  431. $this->assertResponseContains('"split_test":"abc"');
  432. $this->assertHeader('X-Middleware', 'true');
  433. }
  434. /**
  435. * Test that the PSR7 requests receive post data
  436. *
  437. * @return void
  438. */
  439. public function testPostDataLegacyDispatcher()
  440. {
  441. $this->useLegacyDispatcher();
  442. $this->deprecated(function () {
  443. $this->post('/request_action/post_pass', ['title' => 'value']);
  444. $data = json_decode($this->_response->getBody());
  445. $this->assertEquals('value', $data->title);
  446. });
  447. }
  448. /**
  449. * Test that the PSR7 requests receive post data
  450. *
  451. * @return void
  452. */
  453. public function testPostDataHttpServer()
  454. {
  455. $this->post('/request_action/post_pass', ['title' => 'value']);
  456. $data = json_decode($this->_response->getBody());
  457. $this->assertEquals('value', $data->title);
  458. $this->assertHeader('X-Middleware', 'true');
  459. }
  460. /**
  461. * Test that the PSR7 requests receive encoded data.
  462. *
  463. * @return void
  464. */
  465. public function testInputDataHttpServer()
  466. {
  467. $this->post('/request_action/input_test', '{"hello":"world"}');
  468. if ($this->_response->getBody()->isSeekable()) {
  469. $this->_response->getBody()->rewind();
  470. }
  471. $this->assertSame('world', $this->_response->getBody()->getContents());
  472. $this->assertHeader('X-Middleware', 'true');
  473. }
  474. /**
  475. * Test that the PSR7 requests receive encoded data.
  476. *
  477. * @return void
  478. */
  479. public function testInputDataSecurityToken()
  480. {
  481. $this->enableSecurityToken();
  482. $this->post('/request_action/input_test', '{"hello":"world"}');
  483. $this->assertSame('world', '' . $this->_response->getBody());
  484. $this->assertHeader('X-Middleware', 'true');
  485. }
  486. /**
  487. * Test that the PSR7 requests get cookies
  488. *
  489. * @return void
  490. */
  491. public function testSessionHttpServer()
  492. {
  493. $this->session(['foo' => 'session data']);
  494. $this->get('/request_action/session_test');
  495. $this->assertResponseOk();
  496. $this->assertResponseContains('session data');
  497. $this->assertHeader('X-Middleware', 'true');
  498. }
  499. /**
  500. * Test sending requests stores references to controller/view/layout.
  501. *
  502. * @return void
  503. */
  504. public function testRequestSetsProperties()
  505. {
  506. $this->post('/posts/index');
  507. $this->assertInstanceOf('Cake\Controller\Controller', $this->_controller);
  508. $this->assertNotEmpty($this->_viewName, 'View name not set');
  509. $this->assertContains('Template' . DS . 'Posts' . DS . 'index.ctp', $this->_viewName);
  510. $this->assertNotEmpty($this->_layoutName, 'Layout name not set');
  511. $this->assertContains('Template' . DS . 'Layout' . DS . 'default.ctp', $this->_layoutName);
  512. $this->assertTemplate('index');
  513. $this->assertLayout('default');
  514. $this->assertEquals('value', $this->viewVariable('test'));
  515. }
  516. /**
  517. * Test PSR7 requests store references to controller/view/layout
  518. *
  519. * @return void
  520. */
  521. public function testRequestSetsPropertiesHttpServer()
  522. {
  523. $this->post('/posts/index');
  524. $this->assertInstanceOf('Cake\Controller\Controller', $this->_controller);
  525. $this->assertNotEmpty($this->_viewName, 'View name not set');
  526. $this->assertContains('Template' . DS . 'Posts' . DS . 'index.ctp', $this->_viewName);
  527. $this->assertNotEmpty($this->_layoutName, 'Layout name not set');
  528. $this->assertContains('Template' . DS . 'Layout' . DS . 'default.ctp', $this->_layoutName);
  529. $this->assertTemplate('index');
  530. $this->assertLayout('default');
  531. $this->assertEquals('value', $this->viewVariable('test'));
  532. }
  533. /**
  534. * Assert that the stored template doesn't change when cells are rendered.
  535. *
  536. * @return void
  537. */
  538. public function testAssertTemplateAfterCellRender()
  539. {
  540. $this->get('/posts/get');
  541. $this->assertContains('Template' . DS . 'Posts' . DS . 'get.ctp', $this->_viewName);
  542. $this->assertTemplate('get');
  543. $this->assertResponseContains('cellcontent');
  544. }
  545. /**
  546. * Test array URLs
  547. *
  548. * @return void
  549. */
  550. public function testArrayUrls()
  551. {
  552. $this->post(['controller' => 'Posts', 'action' => 'index']);
  553. $this->assertEquals('value', $this->viewVariable('test'));
  554. }
  555. /**
  556. * Test array URLs with an empty router.
  557. *
  558. * @return void
  559. */
  560. public function testArrayUrlsEmptyRouter()
  561. {
  562. Router::reload();
  563. $this->assertFalse(Router::$initialized);
  564. $this->post(['controller' => 'Posts', 'action' => 'index']);
  565. $this->assertEquals('value', $this->viewVariable('test'));
  566. }
  567. /**
  568. * Test flash and cookie assertions
  569. *
  570. * @return void
  571. */
  572. public function testFlashSessionAndCookieAsserts()
  573. {
  574. $this->post('/posts/index');
  575. $this->assertSession('An error message', 'Flash.flash.0.message');
  576. $this->assertCookie(1, 'remember_me');
  577. $this->assertCookieNotSet('user_id');
  578. }
  579. /**
  580. * Test flash and cookie assertions
  581. *
  582. * @return void
  583. */
  584. public function testFlashSessionAndCookieAssertsHttpServer()
  585. {
  586. $this->post('/posts/index');
  587. $this->assertSession('An error message', 'Flash.flash.0.message');
  588. $this->assertCookieNotSet('user_id');
  589. $this->assertCookie(1, 'remember_me');
  590. }
  591. /**
  592. * Test flash assertions stored with enableRememberFlashMessages() after they
  593. * are rendered
  594. *
  595. * @return void
  596. */
  597. public function testFlashAssertionsAfterRender()
  598. {
  599. $this->enableRetainFlashMessages();
  600. $this->get('/posts/index/with_flash');
  601. $this->assertSession('An error message', 'Flash.flash.0.message');
  602. }
  603. /**
  604. * Test flash assertions stored with enableRememberFlashMessages() even if
  605. * no view is rendered
  606. *
  607. * @return void
  608. */
  609. public function testFlashAssertionsWithNoRender()
  610. {
  611. $this->enableRetainFlashMessages();
  612. $this->get('/posts/flashNoRender');
  613. $this->assertRedirect();
  614. $this->assertSession('An error message', 'Flash.flash.0.message');
  615. }
  616. /**
  617. * Tests the failure message for assertCookieNotSet
  618. *
  619. * @return void
  620. */
  621. public function testCookieNotSetFailure()
  622. {
  623. $this->expectException(AssertionFailedError::class);
  624. $this->expectExceptionMessage('Failed asserting that \'remember_me\' cookie was not set');
  625. $this->post('/posts/index');
  626. $this->assertCookieNotSet('remember_me');
  627. }
  628. /**
  629. * Tests the failure message for assertCookieNotSet when no
  630. * response whas generated
  631. *
  632. * @return void
  633. */
  634. public function testCookieNotSetFailureNoResponse()
  635. {
  636. $this->expectException(AssertionFailedError::class);
  637. $this->expectExceptionMessage('No response set, cannot assert content.');
  638. $this->assertCookieNotSet('remember_me');
  639. }
  640. /**
  641. * Test error handling and error page rendering.
  642. *
  643. * @return void
  644. */
  645. public function testPostAndErrorHandling()
  646. {
  647. $this->post('/request_action/error_method');
  648. $this->assertResponseNotEmpty();
  649. $this->assertResponseContains('Not there or here');
  650. $this->assertResponseContains('<!DOCTYPE html>');
  651. }
  652. /**
  653. * Test posting to a secured form action.
  654. *
  655. * @return void
  656. */
  657. public function testPostSecuredForm()
  658. {
  659. $this->enableSecurityToken();
  660. $data = [
  661. 'title' => 'Some title',
  662. 'body' => 'Some text'
  663. ];
  664. $this->post('/posts/securePost', $data);
  665. $this->assertResponseOk();
  666. $this->assertResponseContains('Request was accepted');
  667. }
  668. /**
  669. * Test posting to a secured form action with nested data.
  670. *
  671. * @return void
  672. */
  673. public function testPostSecuredFormNestedData()
  674. {
  675. $this->enableSecurityToken();
  676. $data = [
  677. 'title' => 'New post',
  678. 'comments' => [
  679. ['comment' => 'A new comment']
  680. ],
  681. 'tags' => ['_ids' => [1, 2, 3, 4]]
  682. ];
  683. $this->post('/posts/securePost', $data);
  684. $this->assertResponseOk();
  685. $this->assertResponseContains('Request was accepted');
  686. }
  687. /**
  688. * Test posting to a secured form action.
  689. *
  690. * @return void
  691. */
  692. public function testPostSecuredFormWithQuery()
  693. {
  694. $this->enableSecurityToken();
  695. $data = [
  696. 'title' => 'Some title',
  697. 'body' => 'Some text'
  698. ];
  699. $this->post('/posts/securePost?foo=bar', $data);
  700. $this->assertResponseOk();
  701. $this->assertResponseContains('Request was accepted');
  702. }
  703. /**
  704. * Test posting to a secured form action with a query that has a part that
  705. * will be encoded by the security component
  706. *
  707. * @return void
  708. */
  709. public function testPostSecuredFormWithUnencodedQuery()
  710. {
  711. $this->enableSecurityToken();
  712. $data = [
  713. 'title' => 'Some title',
  714. 'body' => 'Some text'
  715. ];
  716. $this->post('/posts/securePost?foo=/', $data);
  717. $this->assertResponseOk();
  718. $this->assertResponseContains('Request was accepted');
  719. }
  720. /**
  721. * Test posting to a secured form action action.
  722. *
  723. * @return void
  724. */
  725. public function testPostSecuredFormFailure()
  726. {
  727. $data = [
  728. 'title' => 'Some title',
  729. 'body' => 'Some text'
  730. ];
  731. $this->post('/posts/securePost', $data);
  732. $this->assertResponseError();
  733. }
  734. /**
  735. * Test that exceptions being thrown are handled correctly.
  736. *
  737. * @return void
  738. */
  739. public function testWithExpectedException()
  740. {
  741. $this->get('/tests_apps/throw_exception');
  742. $this->assertResponseCode(500);
  743. }
  744. /**
  745. * Test that exceptions being thrown are handled correctly by the psr7 stack.
  746. *
  747. * @return void
  748. */
  749. public function testWithExpectedExceptionHttpServer()
  750. {
  751. DispatcherFactory::clear();
  752. $this->get('/tests_apps/throw_exception');
  753. $this->assertResponseCode(500);
  754. }
  755. /**
  756. * Test that exceptions being thrown are handled correctly.
  757. *
  758. * @return void
  759. */
  760. public function testWithUnexpectedException()
  761. {
  762. $this->expectException(AssertionFailedError::class);
  763. $this->get('/tests_apps/throw_exception');
  764. $this->assertResponseCode(501);
  765. }
  766. /**
  767. * Test redirecting and integration tests.
  768. *
  769. * @return void
  770. */
  771. public function testRedirect()
  772. {
  773. $this->post('/tests_apps/redirect_to');
  774. $this->assertResponseSuccess();
  775. $this->assertResponseCode(302);
  776. }
  777. /**
  778. * Test redirecting and psr7 stack
  779. *
  780. * @return void
  781. */
  782. public function testRedirectHttpServer()
  783. {
  784. DispatcherFactory::clear();
  785. $this->post('/tests_apps/redirect_to');
  786. $this->assertResponseCode(302);
  787. $this->assertHeader('X-Middleware', 'true');
  788. }
  789. /**
  790. * Test redirecting and integration tests.
  791. *
  792. * @return void
  793. */
  794. public function testRedirectPermanent()
  795. {
  796. $this->post('/tests_apps/redirect_to_permanent');
  797. $this->assertResponseSuccess();
  798. $this->assertResponseCode(301);
  799. }
  800. /**
  801. * Test the responseOk status assertion
  802. *
  803. * @return void
  804. */
  805. public function testAssertResponseStatusCodes()
  806. {
  807. $this->_response = new Response();
  808. $this->_response = $this->_response->withStatus(200);
  809. $this->assertResponseOk();
  810. $this->_response = $this->_response->withStatus(201);
  811. $this->assertResponseOk();
  812. $this->_response = $this->_response->withStatus(204);
  813. $this->assertResponseOk();
  814. $this->_response = $this->_response->withStatus(202);
  815. $this->assertResponseSuccess();
  816. $this->_response = $this->_response->withStatus(302);
  817. $this->assertResponseSuccess();
  818. $this->_response = $this->_response->withStatus(400);
  819. $this->assertResponseError();
  820. $this->_response = $this->_response->withStatus(417);
  821. $this->assertResponseError();
  822. $this->_response = $this->_response->withStatus(500);
  823. $this->assertResponseFailure();
  824. $this->_response = $this->_response->withStatus(505);
  825. $this->assertResponseFailure();
  826. $this->_response = $this->_response->withStatus(301);
  827. $this->assertResponseCode(301);
  828. }
  829. /**
  830. * Test the location header assertion.
  831. *
  832. * @return void
  833. */
  834. public function testAssertRedirect()
  835. {
  836. $this->_response = new Response();
  837. $this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
  838. $this->assertRedirect();
  839. $this->assertRedirect('/tasks/index');
  840. $this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);
  841. $this->assertResponseEmpty();
  842. }
  843. /**
  844. * Test the location header assertion.
  845. *
  846. * @return void
  847. */
  848. public function testAssertNoRedirect()
  849. {
  850. $this->_response = new Response();
  851. $this->assertNoRedirect();
  852. }
  853. /**
  854. * Test the location header assertion.
  855. *
  856. * @return void
  857. */
  858. public function testAssertNoRedirectFail()
  859. {
  860. $test = new AssertIntegrationTestCase('testBadAssertNoRedirect');
  861. $result = $test->run();
  862. $this->assertFalse($result->wasSuccessful());
  863. $this->assertEquals(1, $result->failureCount());
  864. }
  865. /**
  866. * Test the location header assertion string contains
  867. *
  868. * @return void
  869. */
  870. public function testAssertRedirectContains()
  871. {
  872. $this->_response = new Response();
  873. $this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
  874. $this->assertRedirectContains('/tasks/index');
  875. }
  876. /**
  877. * Test the header assertion.
  878. *
  879. * @return void
  880. */
  881. public function testAssertHeader()
  882. {
  883. $this->_response = new Response();
  884. $this->_response = $this->_response->withHeader('Etag', 'abc123');
  885. $this->assertHeader('Etag', 'abc123');
  886. }
  887. /**
  888. * Test the header contains assertion.
  889. *
  890. * @return void
  891. */
  892. public function testAssertHeaderContains()
  893. {
  894. $this->_response = new Response();
  895. $this->_response = $this->_response->withHeader('Etag', 'abc123');
  896. $this->assertHeaderContains('Etag', 'abc');
  897. }
  898. /**
  899. * Test the content type assertion.
  900. *
  901. * @return void
  902. */
  903. public function testAssertContentType()
  904. {
  905. $this->_response = new Response();
  906. $this->_response = $this->_response->withType('json');
  907. $this->assertContentType('json');
  908. $this->assertContentType('application/json');
  909. }
  910. /**
  911. * Test that type() in an action sets the content-type header.
  912. *
  913. * @return void
  914. */
  915. public function testContentTypeInAction()
  916. {
  917. $this->get('/tests_apps/set_type');
  918. $this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
  919. $this->assertContentType('json');
  920. $this->assertContentType('application/json');
  921. }
  922. /**
  923. * Test the content assertion.
  924. *
  925. * @return void
  926. */
  927. public function testAssertResponseEquals()
  928. {
  929. $this->_response = new Response();
  930. $this->_response = $this->_response->withStringBody('Some content');
  931. $this->assertResponseEquals('Some content');
  932. }
  933. /**
  934. * Test the negated content assertion.
  935. *
  936. * @return void
  937. */
  938. public function testAssertResponseNotEquals()
  939. {
  940. $this->_response = new Response();
  941. $this->_response = $this->_response->withStringBody('Some content');
  942. $this->assertResponseNotEquals('Some Content');
  943. }
  944. /**
  945. * Test the content assertion.
  946. *
  947. * @return void
  948. */
  949. public function testAssertResponseContains()
  950. {
  951. $this->_response = new Response();
  952. $this->_response = $this->_response->withStringBody('Some content');
  953. $this->assertResponseContains('content');
  954. }
  955. /**
  956. * Test the content assertion with no case sensitivity.
  957. *
  958. * @return void
  959. */
  960. public function testAssertResponseContainsWithIgnoreCaseFlag()
  961. {
  962. $this->_response = new Response();
  963. $this->_response = $this->_response->withStringBody('Some content');
  964. $this->assertResponseContains('some', 'Failed asserting that the body contains given content', true);
  965. }
  966. /**
  967. * Test the negated content assertion.
  968. *
  969. * @return void
  970. */
  971. public function testAssertResponseNotContains()
  972. {
  973. $this->_response = new Response();
  974. $this->_response = $this->_response->withStringBody('Some content');
  975. $this->assertResponseNotContains('contents');
  976. }
  977. /**
  978. * Test the content regexp assertion.
  979. *
  980. * @return void
  981. */
  982. public function testAssertResponseRegExp()
  983. {
  984. $this->_response = new Response();
  985. $this->_response = $this->_response->withStringBody('Some content');
  986. $this->assertResponseRegExp('/cont/');
  987. }
  988. /**
  989. * Test the content regexp assertion failing
  990. *
  991. * @return void
  992. */
  993. public function testAssertResponseRegExpNoResponse()
  994. {
  995. $this->expectException(AssertionFailedError::class);
  996. $this->expectExceptionMessage('No response set');
  997. $this->assertResponseRegExp('/cont/');
  998. }
  999. /**
  1000. * Test the negated content regexp assertion.
  1001. *
  1002. * @return void
  1003. */
  1004. public function testAssertResponseNotRegExp()
  1005. {
  1006. $this->_response = new Response();
  1007. $this->_response = $this->_response->withStringBody('Some content');
  1008. $this->assertResponseNotRegExp('/cant/');
  1009. }
  1010. /**
  1011. * Test negated content regexp assertion failing
  1012. *
  1013. * @return void
  1014. */
  1015. public function testAssertResponseNotRegExpNoResponse()
  1016. {
  1017. $this->expectException(AssertionFailedError::class);
  1018. $this->expectExceptionMessage('No response set');
  1019. $this->assertResponseNotRegExp('/cont/');
  1020. }
  1021. /**
  1022. * Test that works in tandem with testEventManagerReset2 to
  1023. * test the EventManager reset.
  1024. *
  1025. * The return value is passed to testEventManagerReset2 as
  1026. * an arguments.
  1027. *
  1028. * @return \Cake\Event\EventManager
  1029. */
  1030. public function testEventManagerReset1()
  1031. {
  1032. $eventManager = EventManager::instance();
  1033. $this->assertInstanceOf('Cake\Event\EventManager', $eventManager);
  1034. return $eventManager;
  1035. }
  1036. /**
  1037. * Test if the EventManager is reset between tests.
  1038. *
  1039. * @depends testEventManagerReset1
  1040. * @return void
  1041. */
  1042. public function testEventManagerReset2($prevEventManager)
  1043. {
  1044. $this->assertInstanceOf('Cake\Event\EventManager', $prevEventManager);
  1045. $this->assertNotSame($prevEventManager, EventManager::instance());
  1046. }
  1047. /**
  1048. * Test sending file in requests.
  1049. *
  1050. * @return void
  1051. */
  1052. public function testSendFile()
  1053. {
  1054. $this->get('/posts/file');
  1055. $this->assertFileResponse(TEST_APP . 'TestApp' . DS . 'Controller' . DS . 'PostsController.php');
  1056. }
  1057. /**
  1058. * Test sending file with psr7 stack
  1059. *
  1060. * @return void
  1061. */
  1062. public function testSendFileHttpServer()
  1063. {
  1064. $this->get('/posts/file');
  1065. $this->assertFileResponse(TEST_APP . 'TestApp' . DS . 'Controller' . DS . 'PostsController.php');
  1066. }
  1067. /**
  1068. * Test that assertFile requires a response
  1069. *
  1070. * @return void
  1071. */
  1072. public function testAssertFileNoResponse()
  1073. {
  1074. $this->expectException(AssertionFailedError::class);
  1075. $this->expectExceptionMessage('No response set, cannot assert content');
  1076. $this->assertFileResponse('foo');
  1077. }
  1078. /**
  1079. * Test that assertFile requires a file
  1080. *
  1081. * @return void
  1082. */
  1083. public function testAssertFileNoFile()
  1084. {
  1085. $this->expectException(AssertionFailedError::class);
  1086. $this->expectExceptionMessage('Failed asserting that file was sent.');
  1087. $this->get('/posts/get');
  1088. $this->assertFileResponse('foo');
  1089. }
  1090. /**
  1091. * Test disabling the error handler middleware.
  1092. *
  1093. * @return void
  1094. */
  1095. public function testDisableErrorHandlerMiddleware()
  1096. {
  1097. $this->expectException(\Cake\Routing\Exception\MissingRouteException::class);
  1098. $this->expectExceptionMessage('A route matching "/foo" could not be found.');
  1099. $this->disableErrorHandlerMiddleware();
  1100. $this->get('/foo');
  1101. }
  1102. /**
  1103. * tests getting a secure action while passing a query string
  1104. *
  1105. * @return void
  1106. * @dataProvider methodsProvider
  1107. */
  1108. public function testSecureWithQueryString($method)
  1109. {
  1110. $this->enableSecurityToken();
  1111. $this->{$method}('/posts/securePost/?ids[]=1&ids[]=2');
  1112. $this->assertResponseOk();
  1113. }
  1114. /**
  1115. * Tests flash assertions
  1116. *
  1117. * @return void
  1118. * @throws \PHPUnit\Exception
  1119. */
  1120. public function testAssertFlashMessage()
  1121. {
  1122. $this->get('/posts/stacked_flash');
  1123. $this->assertFlashElement('Flash/error');
  1124. $this->assertFlashElement('Flash/success', 'custom');
  1125. $this->assertFlashMessage('Error 1');
  1126. $this->assertFlashMessageAt(0, 'Error 1');
  1127. $this->assertFlashElementAt(0, 'Flash/error');
  1128. $this->assertFlashMessage('Error 2');
  1129. $this->assertFlashMessageAt(1, 'Error 2');
  1130. $this->assertFlashElementAt(1, 'Flash/error');
  1131. $this->assertFlashMessage('Success 1', 'custom');
  1132. $this->assertFlashMessageAt(0, 'Success 1', 'custom');
  1133. $this->assertFlashElementAt(0, 'Flash/success', 'custom');
  1134. $this->assertFlashMessage('Success 2', 'custom');
  1135. $this->assertFlashMessageAt(1, 'Success 2', 'custom');
  1136. $this->assertFlashElementAt(1, 'Flash/success', 'custom');
  1137. }
  1138. /**
  1139. * Tests asserting flash messages without first sending a request
  1140. *
  1141. * @return void
  1142. */
  1143. public function testAssertFlashMessageWithoutSendingRequest()
  1144. {
  1145. $this->expectException(AssertionFailedError::class);
  1146. $message = 'There is no stored session data. Perhaps you need to run a request?';
  1147. $message .= ' Additionally, ensure `$this->enableRetainFlashMessages()` has been enabled for the test.';
  1148. $this->expectExceptionMessage($message);
  1149. $this->assertFlashMessage('Will not work');
  1150. }
  1151. /**
  1152. * tests failure messages for assertions
  1153. *
  1154. * @param string $assertion Assertion method
  1155. * @param string $message Expected failure message
  1156. * @param string $url URL to test
  1157. * @param mixed ...$rest
  1158. * @dataProvider assertionFailureMessagesProvider
  1159. */
  1160. public function testAssertionFailureMessages($assertion, $message, $url, ...$rest)
  1161. {
  1162. $this->expectException(AssertionFailedError::class);
  1163. $this->expectExceptionMessage($message);
  1164. Security::setSalt('abcdabcdabcdabcdabcdabcdabcdabcdabcd');
  1165. $this->get($url);
  1166. call_user_func_array([$this, $assertion], $rest);
  1167. }
  1168. /**
  1169. * data provider for assertion failure messages
  1170. *
  1171. * @return array
  1172. */
  1173. public function assertionFailureMessagesProvider()
  1174. {
  1175. $templateDir = TEST_APP . 'TestApp' . DS . 'Template' . DS;
  1176. return [
  1177. 'assertContentType' => ['assertContentType', 'Failed asserting that \'test\' was set as the Content-Type.', '/posts/index', 'test'],
  1178. 'assertCookie' => ['assertCookie', 'Failed asserting that \'test\' was in cookie \'remember_me\'.', '/posts/index', 'test', 'remember_me'],
  1179. 'assertCookieEncrypted' => ['assertCookieEncrypted', 'Failed asserting that \'test\' was encrypted in cookie \'NameOfCookie\'.', '/cookie_component_test/set_cookie', 'test', 'NameOfCookie'],
  1180. 'assertCookieNotSet' => ['assertCookieNotSet', 'Failed asserting that \'remember_me\' cookie was not set.', '/posts/index', 'remember_me'],
  1181. 'assertFileResponse' => ['assertFileResponse', 'Failed asserting that \'test\' file was sent.', '/posts/file', 'test'],
  1182. 'assertHeader' => ['assertHeader', 'Failed asserting that \'test\' equals content in header \'X-Cake\'.', '/posts/header', 'X-Cake', 'test'],
  1183. 'assertHeaderContains' => ['assertHeaderContains', 'Failed asserting that \'test\' is in header \'X-Cake\'', '/posts/header', 'X-Cake', 'test'],
  1184. 'assertLayout' => ['assertLayout', 'Failed asserting that \'custom_layout\' equals layout file ' . $templateDir . 'Layout' . DS . 'default.ctp.', '/posts/index', 'custom_layout'],
  1185. 'assertRedirect' => ['assertRedirect', 'Failed asserting that \'http://localhost/\' equals content in header \'Location\'.', '/posts/flashNoRender', '/'],
  1186. 'assertRedirectContains' => ['assertRedirectContains', 'Failed asserting that \'/posts/somewhere-else\' is in header \'Location\'.', '/posts/flashNoRender', '/posts/somewhere-else'],
  1187. 'assertResponseCode' => ['assertResponseCode', 'Failed asserting that 302 matches response status code 200.', '/posts/index', 302],
  1188. 'assertResponseContains' => ['assertResponseContains', 'Failed asserting that \'test\' is in response body.', '/posts/index', 'test'],
  1189. 'assertResponseEmpty' => ['assertResponseEmpty', 'Failed asserting that response body is empty.', '/posts/index'],
  1190. 'assertResponseEquals' => ['assertResponseEquals', 'Failed asserting that \'test\' matches response body.', '/posts/index', 'test'],
  1191. 'assertResponseError' => ['assertResponseError', 'Failed asserting that 200 is between 400 and 429.', '/posts/index'],
  1192. 'assertResponseFailure' => ['assertResponseFailure', 'Failed asserting that 200 is between 500 and 505.', '/posts/index'],
  1193. 'assertResponseNotContains' => ['assertResponseNotContains', 'Failed asserting that \'index\' is not in response body.', '/posts/index', 'index'],
  1194. 'assertResponseNotEmpty' => ['assertResponseNotEmpty', 'Failed asserting that response body is not empty.', '/posts/empty_response'],
  1195. 'assertResponseNotEquals' => ['assertResponseNotEquals', 'Failed asserting that \'posts index\' does not match response body.', '/posts/index/error', 'posts index'],
  1196. 'assertResponseNotRegExp' => ['assertResponseNotRegExp', 'Failed asserting that /index/ PCRE pattern not found in response body.', '/posts/index/error', '/index/'],
  1197. 'assertResponseOk' => ['assertResponseOk', 'Failed asserting that 404 is between 200 and 204.', '/posts/missing', '/index/'],
  1198. 'assertResponseRegExp' => ['assertResponseRegExp', 'Failed asserting that /test/ PCRE pattern found in response body.', '/posts/index/error', '/test/'],
  1199. 'assertResponseSuccess' => ['assertResponseSuccess', 'Failed asserting that 404 is between 200 and 308.', '/posts/missing'],
  1200. 'assertSession' => ['assertSession', 'Failed asserting that \'test\' is in session path \'Missing.path\'.', '/posts/index', 'test', 'Missing.path'],
  1201. 'assertTemplate' => ['assertTemplate', 'Failed asserting that \'custom_template\' equals template file ' . $templateDir . 'Posts' . DS . 'index.ctp.', '/posts/index', 'custom_template'],
  1202. 'assertFlashMessage' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'flash\' message.', '/posts/index', 'missing'],
  1203. 'assertFlashMessageWithKey' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'auth\' message.', '/posts/index', 'missing', 'auth'],
  1204. 'assertFlashMessageAt' => ['assertFlashMessageAt', 'Failed asserting that \'missing\' was in \'flash\' message #0.', '/posts/index', 0, 'missing'],
  1205. 'assertFlashMessageAtWithKey' => ['assertFlashMessageAt', 'Failed asserting that \'missing\' was in \'auth\' message #0.', '/posts/index', 0, 'missing', 'auth'],
  1206. 'assertFlashElement' => ['assertFlashElement', 'Failed asserting that \'missing\' was in \'flash\' element.', '/posts/index', 'missing'],
  1207. 'assertFlashElementWithKey' => ['assertFlashElement', 'Failed asserting that \'missing\' was in \'auth\' element.', '/posts/index', 'missing', 'auth'],
  1208. 'assertFlashElementAt' => ['assertFlashElementAt', 'Failed asserting that \'missing\' was in \'flash\' element #0.', '/posts/index', 0, 'missing'],
  1209. 'assertFlashElementAtWithKey' => ['assertFlashElementAt', 'Failed asserting that \'missing\' was in \'auth\' element #0.', '/posts/index', 0, 'missing', 'auth'],
  1210. ];
  1211. }
  1212. /**
  1213. * data provider for HTTP methods
  1214. *
  1215. * @return array
  1216. */
  1217. public function methodsProvider()
  1218. {
  1219. return [
  1220. 'GET' => ['get'],
  1221. 'POST' => ['post'],
  1222. 'PATCH' => ['patch'],
  1223. 'PUT' => ['put'],
  1224. 'DELETE' => ['delete'],
  1225. ];
  1226. }
  1227. }