IntegrationTestTraitTest.php 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  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 string not contains
  845. *
  846. * @return void
  847. */
  848. public function testAssertRedirectNotContains()
  849. {
  850. $this->_response = new Response();
  851. $this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
  852. $this->assertRedirectNotContains('test');
  853. }
  854. /**
  855. * Test the location header assertion.
  856. *
  857. * @return void
  858. */
  859. public function testAssertNoRedirect()
  860. {
  861. $this->_response = new Response();
  862. $this->assertNoRedirect();
  863. }
  864. /**
  865. * Test the location header assertion.
  866. *
  867. * @return void
  868. */
  869. public function testAssertNoRedirectFail()
  870. {
  871. $test = new AssertIntegrationTestCase('testBadAssertNoRedirect');
  872. $result = $test->run();
  873. $this->assertFalse($result->wasSuccessful());
  874. $this->assertEquals(1, $result->failureCount());
  875. }
  876. /**
  877. * Test the location header assertion string contains
  878. *
  879. * @return void
  880. */
  881. public function testAssertRedirectContains()
  882. {
  883. $this->_response = new Response();
  884. $this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
  885. $this->assertRedirectContains('/tasks/index');
  886. }
  887. /**
  888. * Test the header assertion.
  889. *
  890. * @return void
  891. */
  892. public function testAssertHeader()
  893. {
  894. $this->_response = new Response();
  895. $this->_response = $this->_response->withHeader('Etag', 'abc123');
  896. $this->assertHeader('Etag', 'abc123');
  897. }
  898. /**
  899. * Test the header contains assertion.
  900. *
  901. * @return void
  902. */
  903. public function testAssertHeaderContains()
  904. {
  905. $this->_response = new Response();
  906. $this->_response = $this->_response->withHeader('Etag', 'abc123');
  907. $this->assertHeaderContains('Etag', 'abc');
  908. }
  909. /**
  910. * Test the header not contains assertion.
  911. *
  912. * @return void
  913. */
  914. public function testAssertHeaderNotContains()
  915. {
  916. $this->_response = new Response();
  917. $this->_response = $this->_response->withHeader('Etag', 'abc123');
  918. $this->assertHeaderNotContains('Etag', 'xyz');
  919. }
  920. /**
  921. * Test the content type assertion.
  922. *
  923. * @return void
  924. */
  925. public function testAssertContentType()
  926. {
  927. $this->_response = new Response();
  928. $this->_response = $this->_response->withType('json');
  929. $this->assertContentType('json');
  930. $this->assertContentType('application/json');
  931. }
  932. /**
  933. * Test that type() in an action sets the content-type header.
  934. *
  935. * @return void
  936. */
  937. public function testContentTypeInAction()
  938. {
  939. $this->get('/tests_apps/set_type');
  940. $this->assertHeader('Content-Type', 'application/json; charset=UTF-8');
  941. $this->assertContentType('json');
  942. $this->assertContentType('application/json');
  943. }
  944. /**
  945. * Test the content assertion.
  946. *
  947. * @return void
  948. */
  949. public function testAssertResponseEquals()
  950. {
  951. $this->_response = new Response();
  952. $this->_response = $this->_response->withStringBody('Some content');
  953. $this->assertResponseEquals('Some content');
  954. }
  955. /**
  956. * Test the negated content assertion.
  957. *
  958. * @return void
  959. */
  960. public function testAssertResponseNotEquals()
  961. {
  962. $this->_response = new Response();
  963. $this->_response = $this->_response->withStringBody('Some content');
  964. $this->assertResponseNotEquals('Some Content');
  965. }
  966. /**
  967. * Test the content assertion.
  968. *
  969. * @return void
  970. */
  971. public function testAssertResponseContains()
  972. {
  973. $this->_response = new Response();
  974. $this->_response = $this->_response->withStringBody('Some content');
  975. $this->assertResponseContains('content');
  976. }
  977. /**
  978. * Test the content assertion with no case sensitivity.
  979. *
  980. * @return void
  981. */
  982. public function testAssertResponseContainsWithIgnoreCaseFlag()
  983. {
  984. $this->_response = new Response();
  985. $this->_response = $this->_response->withStringBody('Some content');
  986. $this->assertResponseContains('some', 'Failed asserting that the body contains given content', true);
  987. }
  988. /**
  989. * Test the negated content assertion.
  990. *
  991. * @return void
  992. */
  993. public function testAssertResponseNotContains()
  994. {
  995. $this->_response = new Response();
  996. $this->_response = $this->_response->withStringBody('Some content');
  997. $this->assertResponseNotContains('contents');
  998. }
  999. /**
  1000. * Test the content regexp assertion.
  1001. *
  1002. * @return void
  1003. */
  1004. public function testAssertResponseRegExp()
  1005. {
  1006. $this->_response = new Response();
  1007. $this->_response = $this->_response->withStringBody('Some content');
  1008. $this->assertResponseRegExp('/cont/');
  1009. }
  1010. /**
  1011. * Test the content regexp assertion failing
  1012. *
  1013. * @return void
  1014. */
  1015. public function testAssertResponseRegExpNoResponse()
  1016. {
  1017. $this->expectException(AssertionFailedError::class);
  1018. $this->expectExceptionMessage('No response set');
  1019. $this->assertResponseRegExp('/cont/');
  1020. }
  1021. /**
  1022. * Test the negated content regexp assertion.
  1023. *
  1024. * @return void
  1025. */
  1026. public function testAssertResponseNotRegExp()
  1027. {
  1028. $this->_response = new Response();
  1029. $this->_response = $this->_response->withStringBody('Some content');
  1030. $this->assertResponseNotRegExp('/cant/');
  1031. }
  1032. /**
  1033. * Test negated content regexp assertion failing
  1034. *
  1035. * @return void
  1036. */
  1037. public function testAssertResponseNotRegExpNoResponse()
  1038. {
  1039. $this->expectException(AssertionFailedError::class);
  1040. $this->expectExceptionMessage('No response set');
  1041. $this->assertResponseNotRegExp('/cont/');
  1042. }
  1043. /**
  1044. * Test that works in tandem with testEventManagerReset2 to
  1045. * test the EventManager reset.
  1046. *
  1047. * The return value is passed to testEventManagerReset2 as
  1048. * an arguments.
  1049. *
  1050. * @return \Cake\Event\EventManager
  1051. */
  1052. public function testEventManagerReset1()
  1053. {
  1054. $eventManager = EventManager::instance();
  1055. $this->assertInstanceOf('Cake\Event\EventManager', $eventManager);
  1056. return $eventManager;
  1057. }
  1058. /**
  1059. * Test if the EventManager is reset between tests.
  1060. *
  1061. * @depends testEventManagerReset1
  1062. * @return void
  1063. */
  1064. public function testEventManagerReset2($prevEventManager)
  1065. {
  1066. $this->assertInstanceOf('Cake\Event\EventManager', $prevEventManager);
  1067. $this->assertNotSame($prevEventManager, EventManager::instance());
  1068. }
  1069. /**
  1070. * Test sending file in requests.
  1071. *
  1072. * @return void
  1073. */
  1074. public function testSendFile()
  1075. {
  1076. $this->get('/posts/file');
  1077. $this->assertFileResponse(TEST_APP . 'TestApp' . DS . 'Controller' . DS . 'PostsController.php');
  1078. }
  1079. /**
  1080. * Test sending file with psr7 stack
  1081. *
  1082. * @return void
  1083. */
  1084. public function testSendFileHttpServer()
  1085. {
  1086. $this->get('/posts/file');
  1087. $this->assertFileResponse(TEST_APP . 'TestApp' . DS . 'Controller' . DS . 'PostsController.php');
  1088. }
  1089. /**
  1090. * Test that assertFile requires a response
  1091. *
  1092. * @return void
  1093. */
  1094. public function testAssertFileNoResponse()
  1095. {
  1096. $this->expectException(AssertionFailedError::class);
  1097. $this->expectExceptionMessage('No response set, cannot assert content');
  1098. $this->assertFileResponse('foo');
  1099. }
  1100. /**
  1101. * Test that assertFile requires a file
  1102. *
  1103. * @return void
  1104. */
  1105. public function testAssertFileNoFile()
  1106. {
  1107. $this->expectException(AssertionFailedError::class);
  1108. $this->expectExceptionMessage('Failed asserting that file was sent.');
  1109. $this->get('/posts/get');
  1110. $this->assertFileResponse('foo');
  1111. }
  1112. /**
  1113. * Test disabling the error handler middleware.
  1114. *
  1115. * @return void
  1116. */
  1117. public function testDisableErrorHandlerMiddleware()
  1118. {
  1119. $this->expectException(\Cake\Routing\Exception\MissingRouteException::class);
  1120. $this->expectExceptionMessage('A route matching "/foo" could not be found.');
  1121. $this->disableErrorHandlerMiddleware();
  1122. $this->get('/foo');
  1123. }
  1124. /**
  1125. * tests getting a secure action while passing a query string
  1126. *
  1127. * @return void
  1128. * @dataProvider methodsProvider
  1129. */
  1130. public function testSecureWithQueryString($method)
  1131. {
  1132. $this->enableSecurityToken();
  1133. $this->{$method}('/posts/securePost/?ids[]=1&ids[]=2');
  1134. $this->assertResponseOk();
  1135. }
  1136. /**
  1137. * Tests flash assertions
  1138. *
  1139. * @return void
  1140. * @throws \PHPUnit\Exception
  1141. */
  1142. public function testAssertFlashMessage()
  1143. {
  1144. $this->get('/posts/stacked_flash');
  1145. $this->assertFlashElement('Flash/error');
  1146. $this->assertFlashElement('Flash/success', 'custom');
  1147. $this->assertFlashMessage('Error 1');
  1148. $this->assertFlashMessageAt(0, 'Error 1');
  1149. $this->assertFlashElementAt(0, 'Flash/error');
  1150. $this->assertFlashMessage('Error 2');
  1151. $this->assertFlashMessageAt(1, 'Error 2');
  1152. $this->assertFlashElementAt(1, 'Flash/error');
  1153. $this->assertFlashMessage('Success 1', 'custom');
  1154. $this->assertFlashMessageAt(0, 'Success 1', 'custom');
  1155. $this->assertFlashElementAt(0, 'Flash/success', 'custom');
  1156. $this->assertFlashMessage('Success 2', 'custom');
  1157. $this->assertFlashMessageAt(1, 'Success 2', 'custom');
  1158. $this->assertFlashElementAt(1, 'Flash/success', 'custom');
  1159. }
  1160. /**
  1161. * Tests asserting flash messages without first sending a request
  1162. *
  1163. * @return void
  1164. */
  1165. public function testAssertFlashMessageWithoutSendingRequest()
  1166. {
  1167. $this->expectException(AssertionFailedError::class);
  1168. $message = 'There is no stored session data. Perhaps you need to run a request?';
  1169. $message .= ' Additionally, ensure `$this->enableRetainFlashMessages()` has been enabled for the test.';
  1170. $this->expectExceptionMessage($message);
  1171. $this->assertFlashMessage('Will not work');
  1172. }
  1173. /**
  1174. * tests failure messages for assertions
  1175. *
  1176. * @param string $assertion Assertion method
  1177. * @param string $message Expected failure message
  1178. * @param string $url URL to test
  1179. * @param mixed ...$rest
  1180. * @dataProvider assertionFailureMessagesProvider
  1181. */
  1182. public function testAssertionFailureMessages($assertion, $message, $url, ...$rest)
  1183. {
  1184. $this->expectException(AssertionFailedError::class);
  1185. $this->expectExceptionMessage($message);
  1186. Security::setSalt('abcdabcdabcdabcdabcdabcdabcdabcdabcd');
  1187. $this->get($url);
  1188. call_user_func_array([$this, $assertion], $rest);
  1189. }
  1190. /**
  1191. * data provider for assertion failure messages
  1192. *
  1193. * @return array
  1194. */
  1195. public function assertionFailureMessagesProvider()
  1196. {
  1197. $templateDir = TEST_APP . 'TestApp' . DS . 'Template' . DS;
  1198. return [
  1199. 'assertContentType' => ['assertContentType', 'Failed asserting that \'test\' was set as the Content-Type.', '/posts/index', 'test'],
  1200. 'assertCookie' => ['assertCookie', 'Failed asserting that \'test\' was in cookie \'remember_me\'.', '/posts/index', 'test', 'remember_me'],
  1201. 'assertCookieEncrypted' => ['assertCookieEncrypted', 'Failed asserting that \'test\' was encrypted in cookie \'NameOfCookie\'.', '/cookie_component_test/set_cookie', 'test', 'NameOfCookie'],
  1202. 'assertCookieNotSet' => ['assertCookieNotSet', 'Failed asserting that \'remember_me\' cookie was not set.', '/posts/index', 'remember_me'],
  1203. 'assertFileResponse' => ['assertFileResponse', 'Failed asserting that \'test\' file was sent.', '/posts/file', 'test'],
  1204. 'assertHeader' => ['assertHeader', 'Failed asserting that \'test\' equals content in header \'X-Cake\'.', '/posts/header', 'X-Cake', 'test'],
  1205. 'assertHeaderContains' => ['assertHeaderContains', 'Failed asserting that \'test\' is in header \'X-Cake\'', '/posts/header', 'X-Cake', 'test'],
  1206. 'assertLayout' => ['assertLayout', 'Failed asserting that \'custom_layout\' equals layout file ' . $templateDir . 'Layout' . DS . 'default.ctp.', '/posts/index', 'custom_layout'],
  1207. 'assertRedirect' => ['assertRedirect', 'Failed asserting that \'http://localhost/\' equals content in header \'Location\'.', '/posts/flashNoRender', '/'],
  1208. 'assertRedirectContains' => ['assertRedirectContains', 'Failed asserting that \'/posts/somewhere-else\' is in header \'Location\'.', '/posts/flashNoRender', '/posts/somewhere-else'],
  1209. 'assertResponseCode' => ['assertResponseCode', 'Failed asserting that 302 matches response status code 200.', '/posts/index', 302],
  1210. 'assertResponseContains' => ['assertResponseContains', 'Failed asserting that \'test\' is in response body.', '/posts/index', 'test'],
  1211. 'assertResponseEmpty' => ['assertResponseEmpty', 'Failed asserting that response body is empty.', '/posts/index'],
  1212. 'assertResponseEquals' => ['assertResponseEquals', 'Failed asserting that \'test\' matches response body.', '/posts/index', 'test'],
  1213. 'assertResponseError' => ['assertResponseError', 'Failed asserting that 200 is between 400 and 429.', '/posts/index'],
  1214. 'assertResponseFailure' => ['assertResponseFailure', 'Failed asserting that 200 is between 500 and 505.', '/posts/index'],
  1215. 'assertResponseNotContains' => ['assertResponseNotContains', 'Failed asserting that \'index\' is not in response body.', '/posts/index', 'index'],
  1216. 'assertResponseNotEmpty' => ['assertResponseNotEmpty', 'Failed asserting that response body is not empty.', '/posts/empty_response'],
  1217. 'assertResponseNotEquals' => ['assertResponseNotEquals', 'Failed asserting that \'posts index\' does not match response body.', '/posts/index/error', 'posts index'],
  1218. 'assertResponseNotRegExp' => ['assertResponseNotRegExp', 'Failed asserting that /index/ PCRE pattern not found in response body.', '/posts/index/error', '/index/'],
  1219. 'assertResponseOk' => ['assertResponseOk', 'Failed asserting that 404 is between 200 and 204.', '/posts/missing', '/index/'],
  1220. 'assertResponseRegExp' => ['assertResponseRegExp', 'Failed asserting that /test/ PCRE pattern found in response body.', '/posts/index/error', '/test/'],
  1221. 'assertResponseSuccess' => ['assertResponseSuccess', 'Failed asserting that 404 is between 200 and 308.', '/posts/missing'],
  1222. 'assertSession' => ['assertSession', 'Failed asserting that \'test\' is in session path \'Missing.path\'.', '/posts/index', 'test', 'Missing.path'],
  1223. 'assertTemplate' => ['assertTemplate', 'Failed asserting that \'custom_template\' equals template file ' . $templateDir . 'Posts' . DS . 'index.ctp.', '/posts/index', 'custom_template'],
  1224. 'assertFlashMessage' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'flash\' message.', '/posts/index', 'missing'],
  1225. 'assertFlashMessageWithKey' => ['assertFlashMessage', 'Failed asserting that \'missing\' was in \'auth\' message.', '/posts/index', 'missing', 'auth'],
  1226. 'assertFlashMessageAt' => ['assertFlashMessageAt', 'Failed asserting that \'missing\' was in \'flash\' message #0.', '/posts/index', 0, 'missing'],
  1227. 'assertFlashMessageAtWithKey' => ['assertFlashMessageAt', 'Failed asserting that \'missing\' was in \'auth\' message #0.', '/posts/index', 0, 'missing', 'auth'],
  1228. 'assertFlashElement' => ['assertFlashElement', 'Failed asserting that \'missing\' was in \'flash\' element.', '/posts/index', 'missing'],
  1229. 'assertFlashElementWithKey' => ['assertFlashElement', 'Failed asserting that \'missing\' was in \'auth\' element.', '/posts/index', 'missing', 'auth'],
  1230. 'assertFlashElementAt' => ['assertFlashElementAt', 'Failed asserting that \'missing\' was in \'flash\' element #0.', '/posts/index', 0, 'missing'],
  1231. 'assertFlashElementAtWithKey' => ['assertFlashElementAt', 'Failed asserting that \'missing\' was in \'auth\' element #0.', '/posts/index', 0, 'missing', 'auth'],
  1232. ];
  1233. }
  1234. /**
  1235. * data provider for HTTP methods
  1236. *
  1237. * @return array
  1238. */
  1239. public function methodsProvider()
  1240. {
  1241. return [
  1242. 'GET' => ['get'],
  1243. 'POST' => ['post'],
  1244. 'PATCH' => ['patch'],
  1245. 'PUT' => ['put'],
  1246. 'DELETE' => ['delete'],
  1247. ];
  1248. }
  1249. }