CakeRequestTest.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  1. <?php
  2. /**
  3. * CakeRequest Test case file.
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. *
  10. * Licensed under The MIT License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package Cake.Test.Case.Network
  16. * @since CakePHP(tm) v 2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. App::uses('Dispatcher', 'Routing');
  20. App::uses('Xml', 'Utility');
  21. App::uses('CakeRequest', 'Network');
  22. class TestCakeRequest extends CakeRequest {
  23. public function reConstruct($url = 'some/path', $parseEnvironment = true) {
  24. $this->_base();
  25. if (empty($url)) {
  26. $url = $this->_url();
  27. }
  28. if ($url[0] == '/') {
  29. $url = substr($url, 1);
  30. }
  31. $this->url = $url;
  32. if ($parseEnvironment) {
  33. $this->_processPost();
  34. $this->_processGet();
  35. $this->_processFiles();
  36. }
  37. $this->here = $this->base . '/' . $this->url;
  38. }
  39. }
  40. class CakeRequestTest extends CakeTestCase {
  41. /**
  42. * setup callback
  43. *
  44. * @return void
  45. */
  46. public function setUp() {
  47. parent::setUp();
  48. $this->_app = Configure::read('App');
  49. $this->_case = null;
  50. if (isset($_GET['case'])) {
  51. $this->_case = $_GET['case'];
  52. unset($_GET['case']);
  53. }
  54. Configure::write('App.baseUrl', false);
  55. }
  56. /**
  57. * tearDown
  58. *
  59. * @return void
  60. */
  61. public function tearDown() {
  62. parent::tearDown();
  63. if (!empty($this->_case)) {
  64. $_GET['case'] = $this->_case;
  65. }
  66. Configure::write('App', $this->_app);
  67. }
  68. /**
  69. * test that the autoparse = false constructor works.
  70. *
  71. * @return void
  72. */
  73. public function testNoAutoParseConstruction() {
  74. $_GET = array(
  75. 'one' => 'param'
  76. );
  77. $request = new CakeRequest(null, false);
  78. $this->assertFalse(isset($request->query['one']));
  79. }
  80. /**
  81. * test construction
  82. *
  83. * @return void
  84. */
  85. public function testConstructionGetParsing() {
  86. $_GET = array(
  87. 'one' => 'param',
  88. 'two' => 'banana'
  89. );
  90. $request = new CakeRequest('some/path');
  91. $this->assertEquals($request->query, $_GET);
  92. $_GET = array(
  93. 'one' => 'param',
  94. 'two' => 'banana',
  95. );
  96. $request = new CakeRequest('some/path');
  97. $this->assertEquals($request->query, $_GET);
  98. $this->assertEquals('some/path', $request->url);
  99. }
  100. /**
  101. * Test that querystring args provided in the url string are parsed.
  102. *
  103. * @return void
  104. */
  105. public function testQueryStringParsingFromInputUrl() {
  106. $_GET = array();
  107. $request = new CakeRequest('some/path?one=something&two=else');
  108. $expected = array('one' => 'something', 'two' => 'else');
  109. $this->assertEquals($expected, $request->query);
  110. $this->assertEquals('some/path?one=something&two=else', $request->url);
  111. }
  112. /**
  113. * Test that named arguments + querystrings are handled correctly.
  114. *
  115. * @return void
  116. */
  117. public function testQueryStringAndNamedParams() {
  118. $_SERVER['REQUEST_URI'] = '/tasks/index/page:1?ts=123456';
  119. $request = new CakeRequest();
  120. $this->assertEquals('tasks/index/page:1', $request->url);
  121. $_SERVER['REQUEST_URI'] = '/tasks/index/page:1/?ts=123456';
  122. $request = new CakeRequest();
  123. $this->assertEquals('tasks/index/page:1/', $request->url);
  124. }
  125. /**
  126. * test addParams() method
  127. *
  128. * @return void
  129. */
  130. public function testAddParams() {
  131. $request = new CakeRequest('some/path');
  132. $request->params = array('controller' => 'posts', 'action' => 'view');
  133. $result = $request->addParams(array('plugin' => null, 'action' => 'index'));
  134. $this->assertSame($result, $request, 'Method did not return itself. %s');
  135. $this->assertEquals('posts', $request->controller);
  136. $this->assertEquals('index', $request->action);
  137. $this->assertEquals(null, $request->plugin);
  138. }
  139. /**
  140. * test splicing in paths.
  141. *
  142. * @return void
  143. */
  144. public function testAddPaths() {
  145. $request = new CakeRequest('some/path');
  146. $request->webroot = '/some/path/going/here/';
  147. $result = $request->addPaths(array(
  148. 'random' => '/something', 'webroot' => '/', 'here' => '/', 'base' => '/base_dir'
  149. ));
  150. $this->assertSame($result, $request, 'Method did not return itself. %s');
  151. $this->assertEquals('/', $request->webroot);
  152. $this->assertEquals('/base_dir', $request->base);
  153. $this->assertEquals('/', $request->here);
  154. $this->assertFalse(isset($request->random));
  155. }
  156. /**
  157. * test parsing POST data into the object.
  158. *
  159. * @return void
  160. */
  161. public function testPostParsing() {
  162. $_POST = array('data' => array(
  163. 'Article' => array('title')
  164. ));
  165. $request = new CakeRequest('some/path');
  166. $this->assertEquals($_POST['data'], $request->data);
  167. $_POST = array('one' => 1, 'two' => 'three');
  168. $request = new CakeRequest('some/path');
  169. $this->assertEquals($_POST, $request->data);
  170. $_POST = array(
  171. 'data' => array(
  172. 'Article' => array('title' => 'Testing'),
  173. ),
  174. 'action' => 'update'
  175. );
  176. $request = new CakeRequest('some/path');
  177. $expected = array(
  178. 'Article' => array('title' => 'Testing'),
  179. 'action' => 'update'
  180. );
  181. $this->assertEquals($expected, $request->data);
  182. $_POST = array('data' => array(
  183. 'Article' => array('title'),
  184. 'Tag' => array('Tag' => array(1, 2))
  185. ));
  186. $request = new CakeRequest('some/path');
  187. $this->assertEquals($_POST['data'], $request->data);
  188. $_POST = array('data' => array(
  189. 'Article' => array('title' => 'some title'),
  190. 'Tag' => array('Tag' => array(1, 2))
  191. ));
  192. $request = new CakeRequest('some/path');
  193. $this->assertEquals($_POST['data'], $request->data);
  194. $_POST = array(
  195. 'a' => array(1, 2),
  196. 'b' => array(1, 2)
  197. );
  198. $request = new CakeRequest('some/path');
  199. $this->assertEquals($_POST, $request->data);
  200. }
  201. /**
  202. * test parsing PUT data into the object.
  203. *
  204. * @return void
  205. */
  206. public function testPutParsing() {
  207. $_SERVER['REQUEST_METHOD'] = 'PUT';
  208. $_SERVER['CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
  209. $data = array('data' => array(
  210. 'Article' => array('title')
  211. ));
  212. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  213. $request->expects($this->at(0))->method('_readInput')
  214. ->will($this->returnValue('data[Article][]=title'));
  215. $request->reConstruct();
  216. $this->assertEquals($data['data'], $request->data);
  217. $data = array('one' => 1, 'two' => 'three');
  218. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  219. $request->expects($this->at(0))->method('_readInput')
  220. ->will($this->returnValue('one=1&two=three'));
  221. $request->reConstruct();
  222. $this->assertEquals($data, $request->data);
  223. $data = array(
  224. 'data' => array(
  225. 'Article' => array('title' => 'Testing'),
  226. ),
  227. 'action' => 'update'
  228. );
  229. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  230. $request->expects($this->at(0))->method('_readInput')
  231. ->will($this->returnValue('data[Article][title]=Testing&action=update'));
  232. $request->reConstruct();
  233. $expected = array(
  234. 'Article' => array('title' => 'Testing'),
  235. 'action' => 'update'
  236. );
  237. $this->assertEquals($expected, $request->data);
  238. $_SERVER['REQUEST_METHOD'] = 'DELETE';
  239. $data = array('data' => array(
  240. 'Article' => array('title'),
  241. 'Tag' => array('Tag' => array(1, 2))
  242. ));
  243. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  244. $request->expects($this->at(0))->method('_readInput')
  245. ->will($this->returnValue('data[Article][]=title&Tag[Tag][]=1&Tag[Tag][]=2'));
  246. $request->reConstruct();
  247. $this->assertEquals($data['data'], $request->data);
  248. $data = array('data' => array(
  249. 'Article' => array('title' => 'some title'),
  250. 'Tag' => array('Tag' => array(1, 2))
  251. ));
  252. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  253. $request->expects($this->at(0))->method('_readInput')
  254. ->will($this->returnValue('data[Article][title]=some%20title&Tag[Tag][]=1&Tag[Tag][]=2'));
  255. $request->reConstruct();
  256. $this->assertEquals($data['data'], $request->data);
  257. $data = array(
  258. 'a' => array(1, 2),
  259. 'b' => array(1, 2)
  260. );
  261. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  262. $request->expects($this->at(0))->method('_readInput')
  263. ->will($this->returnValue('a[]=1&a[]=2&b[]=1&b[]=2'));
  264. $request->reConstruct();
  265. $this->assertEquals($data, $request->data);
  266. }
  267. /**
  268. * test parsing json PUT data into the object.
  269. *
  270. * @return void
  271. */
  272. public function testPutParsingJSON() {
  273. $_SERVER['REQUEST_METHOD'] = 'PUT';
  274. $_SERVER['CONTENT_TYPE'] = 'application/json';
  275. $request = $this->getMock('TestCakeRequest', array('_readInput'));
  276. $request->expects($this->at(0))->method('_readInput')
  277. ->will($this->returnValue('{Article":["title"]}'));
  278. $request->reConstruct();
  279. $this->assertEquals('{Article":["title"]}', $request->data);
  280. }
  281. /**
  282. * test parsing of FILES array
  283. *
  284. * @return void
  285. */
  286. public function testFilesParsing() {
  287. $_FILES = array(
  288. 'data' => array(
  289. 'name' => array(
  290. 'File' => array(
  291. array('data' => 'cake_sqlserver_patch.patch'),
  292. array('data' => 'controller.diff'),
  293. array('data' => ''),
  294. array('data' => ''),
  295. ),
  296. 'Post' => array('attachment' => 'jquery-1.2.1.js'),
  297. ),
  298. 'type' => array(
  299. 'File' => array(
  300. array('data' => ''),
  301. array('data' => ''),
  302. array('data' => ''),
  303. array('data' => ''),
  304. ),
  305. 'Post' => array('attachment' => 'application/x-javascript'),
  306. ),
  307. 'tmp_name' => array(
  308. 'File' => array(
  309. array('data' => '/private/var/tmp/phpy05Ywj'),
  310. array('data' => '/private/var/tmp/php7MBztY'),
  311. array('data' => ''),
  312. array('data' => ''),
  313. ),
  314. 'Post' => array('attachment' => '/private/var/tmp/phpEwlrIo'),
  315. ),
  316. 'error' => array(
  317. 'File' => array(
  318. array('data' => 0),
  319. array('data' => 0),
  320. array('data' => 4),
  321. array('data' => 4)
  322. ),
  323. 'Post' => array('attachment' => 0)
  324. ),
  325. 'size' => array(
  326. 'File' => array(
  327. array('data' => 6271),
  328. array('data' => 350),
  329. array('data' => 0),
  330. array('data' => 0),
  331. ),
  332. 'Post' => array('attachment' => 80469)
  333. ),
  334. )
  335. );
  336. $request = new CakeRequest('some/path');
  337. $expected = array(
  338. 'File' => array(
  339. array(
  340. 'data' => array(
  341. 'name' => 'cake_sqlserver_patch.patch',
  342. 'type' => '',
  343. 'tmp_name' => '/private/var/tmp/phpy05Ywj',
  344. 'error' => 0,
  345. 'size' => 6271,
  346. )
  347. ),
  348. array(
  349. 'data' => array(
  350. 'name' => 'controller.diff',
  351. 'type' => '',
  352. 'tmp_name' => '/private/var/tmp/php7MBztY',
  353. 'error' => 0,
  354. 'size' => 350,
  355. )
  356. ),
  357. array(
  358. 'data' => array(
  359. 'name' => '',
  360. 'type' => '',
  361. 'tmp_name' => '',
  362. 'error' => 4,
  363. 'size' => 0,
  364. )
  365. ),
  366. array(
  367. 'data' => array(
  368. 'name' => '',
  369. 'type' => '',
  370. 'tmp_name' => '',
  371. 'error' => 4,
  372. 'size' => 0,
  373. )
  374. ),
  375. ),
  376. 'Post' => array(
  377. 'attachment' => array(
  378. 'name' => 'jquery-1.2.1.js',
  379. 'type' => 'application/x-javascript',
  380. 'tmp_name' => '/private/var/tmp/phpEwlrIo',
  381. 'error' => 0,
  382. 'size' => 80469,
  383. )
  384. )
  385. );
  386. $this->assertEquals($expected, $request->data);
  387. $_FILES = array(
  388. 'data' => array(
  389. 'name' => array(
  390. 'Document' => array(
  391. 1 => array(
  392. 'birth_cert' => 'born on.txt',
  393. 'passport' => 'passport.txt',
  394. 'drivers_license' => 'ugly pic.jpg'
  395. ),
  396. 2 => array(
  397. 'birth_cert' => 'aunt betty.txt',
  398. 'passport' => 'betty-passport.txt',
  399. 'drivers_license' => 'betty-photo.jpg'
  400. ),
  401. ),
  402. ),
  403. 'type' => array(
  404. 'Document' => array(
  405. 1 => array(
  406. 'birth_cert' => 'application/octet-stream',
  407. 'passport' => 'application/octet-stream',
  408. 'drivers_license' => 'application/octet-stream',
  409. ),
  410. 2 => array(
  411. 'birth_cert' => 'application/octet-stream',
  412. 'passport' => 'application/octet-stream',
  413. 'drivers_license' => 'application/octet-stream',
  414. )
  415. )
  416. ),
  417. 'tmp_name' => array(
  418. 'Document' => array(
  419. 1 => array(
  420. 'birth_cert' => '/private/var/tmp/phpbsUWfH',
  421. 'passport' => '/private/var/tmp/php7f5zLt',
  422. 'drivers_license' => '/private/var/tmp/phpMXpZgT',
  423. ),
  424. 2 => array(
  425. 'birth_cert' => '/private/var/tmp/php5kHZt0',
  426. 'passport' => '/private/var/tmp/phpnYkOuM',
  427. 'drivers_license' => '/private/var/tmp/php9Rq0P3',
  428. )
  429. )
  430. ),
  431. 'error' => array(
  432. 'Document' => array(
  433. 1 => array(
  434. 'birth_cert' => 0,
  435. 'passport' => 0,
  436. 'drivers_license' => 0,
  437. ),
  438. 2 => array(
  439. 'birth_cert' => 0,
  440. 'passport' => 0,
  441. 'drivers_license' => 0,
  442. )
  443. )
  444. ),
  445. 'size' => array(
  446. 'Document' => array(
  447. 1 => array(
  448. 'birth_cert' => 123,
  449. 'passport' => 458,
  450. 'drivers_license' => 875,
  451. ),
  452. 2 => array(
  453. 'birth_cert' => 876,
  454. 'passport' => 976,
  455. 'drivers_license' => 9783,
  456. )
  457. )
  458. )
  459. )
  460. );
  461. $request = new CakeRequest('some/path');
  462. $expected = array(
  463. 'Document' => array(
  464. 1 => array(
  465. 'birth_cert' => array(
  466. 'name' => 'born on.txt',
  467. 'tmp_name' => '/private/var/tmp/phpbsUWfH',
  468. 'error' => 0,
  469. 'size' => 123,
  470. 'type' => 'application/octet-stream',
  471. ),
  472. 'passport' => array(
  473. 'name' => 'passport.txt',
  474. 'tmp_name' => '/private/var/tmp/php7f5zLt',
  475. 'error' => 0,
  476. 'size' => 458,
  477. 'type' => 'application/octet-stream',
  478. ),
  479. 'drivers_license' => array(
  480. 'name' => 'ugly pic.jpg',
  481. 'tmp_name' => '/private/var/tmp/phpMXpZgT',
  482. 'error' => 0,
  483. 'size' => 875,
  484. 'type' => 'application/octet-stream',
  485. ),
  486. ),
  487. 2 => array(
  488. 'birth_cert' => array(
  489. 'name' => 'aunt betty.txt',
  490. 'tmp_name' => '/private/var/tmp/php5kHZt0',
  491. 'error' => 0,
  492. 'size' => 876,
  493. 'type' => 'application/octet-stream',
  494. ),
  495. 'passport' => array(
  496. 'name' => 'betty-passport.txt',
  497. 'tmp_name' => '/private/var/tmp/phpnYkOuM',
  498. 'error' => 0,
  499. 'size' => 976,
  500. 'type' => 'application/octet-stream',
  501. ),
  502. 'drivers_license' => array(
  503. 'name' => 'betty-photo.jpg',
  504. 'tmp_name' => '/private/var/tmp/php9Rq0P3',
  505. 'error' => 0,
  506. 'size' => 9783,
  507. 'type' => 'application/octet-stream',
  508. ),
  509. ),
  510. )
  511. );
  512. $this->assertEquals($expected, $request->data);
  513. $_FILES = array(
  514. 'data' => array(
  515. 'name' => array('birth_cert' => 'born on.txt'),
  516. 'type' => array('birth_cert' => 'application/octet-stream'),
  517. 'tmp_name' => array('birth_cert' => '/private/var/tmp/phpbsUWfH'),
  518. 'error' => array('birth_cert' => 0),
  519. 'size' => array('birth_cert' => 123)
  520. )
  521. );
  522. $request = new CakeRequest('some/path');
  523. $expected = array(
  524. 'birth_cert' => array(
  525. 'name' => 'born on.txt',
  526. 'type' => 'application/octet-stream',
  527. 'tmp_name' => '/private/var/tmp/phpbsUWfH',
  528. 'error' => 0,
  529. 'size' => 123
  530. )
  531. );
  532. $this->assertEquals($expected, $request->data);
  533. $_FILES = array(
  534. 'something' => array(
  535. 'name' => 'something.txt',
  536. 'type' => 'text/plain',
  537. 'tmp_name' => '/some/file',
  538. 'error' => 0,
  539. 'size' => 123
  540. )
  541. );
  542. $request = new CakeRequest('some/path');
  543. $this->assertEquals($request->params['form'], $_FILES);
  544. }
  545. /**
  546. * test method overrides coming in from POST data.
  547. *
  548. * @return void
  549. */
  550. public function testMethodOverrides() {
  551. $_POST = array('_method' => 'POST');
  552. $request = new CakeRequest('some/path');
  553. $this->assertEquals(env('REQUEST_METHOD'), 'POST');
  554. $_POST = array('_method' => 'DELETE');
  555. $request = new CakeRequest('some/path');
  556. $this->assertEquals(env('REQUEST_METHOD'), 'DELETE');
  557. $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
  558. $request = new CakeRequest('some/path');
  559. $this->assertEquals(env('REQUEST_METHOD'), 'PUT');
  560. }
  561. /**
  562. * test the clientIp method.
  563. *
  564. * @return void
  565. */
  566. public function testclientIp() {
  567. $_SERVER['HTTP_X_FORWARDED_FOR'] = '192.168.1.5, 10.0.1.1, proxy.com';
  568. $_SERVER['HTTP_CLIENT_IP'] = '192.168.1.2';
  569. $_SERVER['REMOTE_ADDR'] = '192.168.1.3';
  570. $request = new CakeRequest('some/path');
  571. $this->assertEquals('192.168.1.5', $request->clientIp(false));
  572. $this->assertEquals('192.168.1.2', $request->clientIp());
  573. unset($_SERVER['HTTP_X_FORWARDED_FOR']);
  574. $this->assertEquals('192.168.1.2', $request->clientIp());
  575. unset($_SERVER['HTTP_CLIENT_IP']);
  576. $this->assertEquals('192.168.1.3', $request->clientIp());
  577. $_SERVER['HTTP_CLIENTADDRESS'] = '10.0.1.2, 10.0.1.1';
  578. $this->assertEquals('10.0.1.2', $request->clientIp());
  579. }
  580. /**
  581. * test the referer function.
  582. *
  583. * @return void
  584. */
  585. public function testReferer() {
  586. $request = new CakeRequest('some/path');
  587. $request->webroot = '/';
  588. $_SERVER['HTTP_REFERER'] = 'http://cakephp.org';
  589. $result = $request->referer();
  590. $this->assertSame($result, 'http://cakephp.org');
  591. $_SERVER['HTTP_REFERER'] = '';
  592. $result = $request->referer();
  593. $this->assertSame($result, '/');
  594. $_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
  595. $result = $request->referer(true);
  596. $this->assertSame($result, '/some/path');
  597. $_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
  598. $result = $request->referer(false);
  599. $this->assertSame($result, FULL_BASE_URL . '/some/path');
  600. $_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/some/path';
  601. $result = $request->referer(true);
  602. $this->assertSame($result, '/some/path');
  603. $_SERVER['HTTP_REFERER'] = FULL_BASE_URL . '/recipes/add';
  604. $result = $request->referer(true);
  605. $this->assertSame($result, '/recipes/add');
  606. $_SERVER['HTTP_X_FORWARDED_HOST'] = 'cakephp.org';
  607. $result = $request->referer();
  608. $this->assertSame($result, 'cakephp.org');
  609. }
  610. /**
  611. * test the simple uses of is()
  612. *
  613. * @return void
  614. */
  615. public function testIsHttpMethods() {
  616. $request = new CakeRequest('some/path');
  617. $this->assertFalse($request->is('undefined-behavior'));
  618. $_SERVER['REQUEST_METHOD'] = 'GET';
  619. $this->assertTrue($request->is('get'));
  620. $_SERVER['REQUEST_METHOD'] = 'POST';
  621. $this->assertTrue($request->is('POST'));
  622. $_SERVER['REQUEST_METHOD'] = 'PUT';
  623. $this->assertTrue($request->is('put'));
  624. $this->assertFalse($request->is('get'));
  625. $_SERVER['REQUEST_METHOD'] = 'DELETE';
  626. $this->assertTrue($request->is('delete'));
  627. $this->assertTrue($request->isDelete());
  628. $_SERVER['REQUEST_METHOD'] = 'delete';
  629. $this->assertFalse($request->is('delete'));
  630. }
  631. /**
  632. * test the method() method.
  633. *
  634. * @return void
  635. */
  636. public function testMethod() {
  637. $_SERVER['REQUEST_METHOD'] = 'delete';
  638. $request = new CakeRequest('some/path');
  639. $this->assertEquals('delete', $request->method());
  640. }
  641. /**
  642. * test host retrieval.
  643. *
  644. * @return void
  645. */
  646. public function testHost() {
  647. $_SERVER['HTTP_HOST'] = 'localhost';
  648. $request = new CakeRequest('some/path');
  649. $this->assertEquals('localhost', $request->host());
  650. }
  651. /**
  652. * test domain retrieval.
  653. *
  654. * @return void
  655. */
  656. public function testDomain() {
  657. $_SERVER['HTTP_HOST'] = 'something.example.com';
  658. $request = new CakeRequest('some/path');
  659. $this->assertEquals('example.com', $request->domain());
  660. $_SERVER['HTTP_HOST'] = 'something.example.co.uk';
  661. $this->assertEquals('example.co.uk', $request->domain(2));
  662. }
  663. /**
  664. * test getting subdomains for a host.
  665. *
  666. * @return void
  667. */
  668. public function testSubdomain() {
  669. $_SERVER['HTTP_HOST'] = 'something.example.com';
  670. $request = new CakeRequest('some/path');
  671. $this->assertEquals(array('something'), $request->subdomains());
  672. $_SERVER['HTTP_HOST'] = 'www.something.example.com';
  673. $this->assertEquals(array('www', 'something'), $request->subdomains());
  674. $_SERVER['HTTP_HOST'] = 'www.something.example.co.uk';
  675. $this->assertEquals(array('www', 'something'), $request->subdomains(2));
  676. $_SERVER['HTTP_HOST'] = 'example.co.uk';
  677. $this->assertEquals(array(), $request->subdomains(2));
  678. }
  679. /**
  680. * test ajax, flash and friends
  681. *
  682. * @return void
  683. */
  684. public function testisAjaxFlashAndFriends() {
  685. $request = new CakeRequest('some/path');
  686. $_SERVER['HTTP_USER_AGENT'] = 'Shockwave Flash';
  687. $this->assertTrue($request->is('flash'));
  688. $_SERVER['HTTP_USER_AGENT'] = 'Adobe Flash';
  689. $this->assertTrue($request->is('flash'));
  690. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
  691. $this->assertTrue($request->is('ajax'));
  692. $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHTTPREQUEST';
  693. $this->assertFalse($request->is('ajax'));
  694. $this->assertFalse($request->isAjax());
  695. $_SERVER['HTTP_USER_AGENT'] = 'Android 2.0';
  696. $this->assertTrue($request->is('mobile'));
  697. $this->assertTrue($request->isMobile());
  698. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 5.1; rv:2.0b6pre) Gecko/20100902 Firefox/4.0b6pre Fennec/2.0b1pre';
  699. $this->assertTrue($request->is('mobile'));
  700. $this->assertTrue($request->isMobile());
  701. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; OMNIA7)';
  702. $this->assertTrue($request->is('mobile'));
  703. $this->assertTrue($request->isMobile());
  704. }
  705. /**
  706. * test __call expcetions
  707. *
  708. * @expectedException CakeException
  709. * @return void
  710. */
  711. public function testMagicCallExceptionOnUnknownMethod() {
  712. $request = new CakeRequest('some/path');
  713. $request->IamABanana();
  714. }
  715. /**
  716. * test is(ssl)
  717. *
  718. * @return void
  719. */
  720. public function testIsSsl() {
  721. $request = new CakeRequest('some/path');
  722. $_SERVER['HTTPS'] = 1;
  723. $this->assertTrue($request->is('ssl'));
  724. $_SERVER['HTTPS'] = 'on';
  725. $this->assertTrue($request->is('ssl'));
  726. $_SERVER['HTTPS'] = '1';
  727. $this->assertTrue($request->is('ssl'));
  728. $_SERVER['HTTPS'] = 'I am not empty';
  729. $this->assertTrue($request->is('ssl'));
  730. $_SERVER['HTTPS'] = 1;
  731. $this->assertTrue($request->is('ssl'));
  732. $_SERVER['HTTPS'] = 'off';
  733. $this->assertFalse($request->is('ssl'));
  734. $_SERVER['HTTPS'] = false;
  735. $this->assertFalse($request->is('ssl'));
  736. $_SERVER['HTTPS'] = '';
  737. $this->assertFalse($request->is('ssl'));
  738. }
  739. /**
  740. * test getting request params with object properties.
  741. *
  742. * @return void
  743. */
  744. public function testMagicget() {
  745. $request = new CakeRequest('some/path');
  746. $request->params = array('controller' => 'posts', 'action' => 'view', 'plugin' => 'blogs');
  747. $this->assertEquals('posts', $request->controller);
  748. $this->assertEquals('view', $request->action);
  749. $this->assertEquals('blogs', $request->plugin);
  750. $this->assertSame($request->banana, null);
  751. }
  752. /**
  753. * Test isset()/empty() with overloaded properties.
  754. *
  755. * @return void
  756. */
  757. public function testMagicisset() {
  758. $request = new CakeRequest('some/path');
  759. $request->params = array(
  760. 'controller' => 'posts',
  761. 'action' => 'view',
  762. 'plugin' => 'blogs',
  763. 'named' => array()
  764. );
  765. $this->assertTrue(isset($request->controller));
  766. $this->assertFalse(isset($request->notthere));
  767. $this->assertFalse(empty($request->controller));
  768. $this->assertTrue(empty($request->named));
  769. }
  770. /**
  771. * test the array access implementation
  772. *
  773. * @return void
  774. */
  775. public function testArrayAccess() {
  776. $request = new CakeRequest('some/path');
  777. $request->params = array('controller' => 'posts', 'action' => 'view', 'plugin' => 'blogs');
  778. $this->assertEquals('posts', $request['controller']);
  779. $request['slug'] = 'speedy-slug';
  780. $this->assertEquals('speedy-slug', $request->slug);
  781. $this->assertEquals('speedy-slug', $request['slug']);
  782. $this->assertTrue(isset($request['action']));
  783. $this->assertFalse(isset($request['wrong-param']));
  784. $this->assertTrue(isset($request['plugin']));
  785. unset($request['plugin']);
  786. $this->assertFalse(isset($request['plugin']));
  787. $this->assertNull($request['plugin']);
  788. $this->assertNull($request->plugin);
  789. $request = new CakeRequest('some/path?one=something&two=else');
  790. $this->assertTrue(isset($request['url']['one']));
  791. $request->data = array('Post' => array('title' => 'something'));
  792. $this->assertEquals('something', $request['data']['Post']['title']);
  793. }
  794. /**
  795. * test adding detectors and having them work.
  796. *
  797. * @return void
  798. */
  799. public function testAddDetector() {
  800. $request = new CakeRequest('some/path');
  801. $request->addDetector('compare', array('env' => 'TEST_VAR', 'value' => 'something'));
  802. $_SERVER['TEST_VAR'] = 'something';
  803. $this->assertTrue($request->is('compare'), 'Value match failed.');
  804. $_SERVER['TEST_VAR'] = 'wrong';
  805. $this->assertFalse($request->is('compare'), 'Value mis-match failed.');
  806. $request->addDetector('compareCamelCase', array('env' => 'TEST_VAR', 'value' => 'foo'));
  807. $_SERVER['TEST_VAR'] = 'foo';
  808. $this->assertTrue($request->is('compareCamelCase'), 'Value match failed.');
  809. $request->addDetector('banana', array('env' => 'TEST_VAR', 'pattern' => '/^ban.*$/'));
  810. $_SERVER['TEST_VAR'] = 'banana';
  811. $this->assertTrue($request->isBanana());
  812. $_SERVER['TEST_VAR'] = 'wrong value';
  813. $this->assertFalse($request->isBanana());
  814. $request->addDetector('mobile', array('options' => array('Imagination')));
  815. $_SERVER['HTTP_USER_AGENT'] = 'Imagination land';
  816. $this->assertTrue($request->isMobile());
  817. $_SERVER['HTTP_USER_AGENT'] = 'iPhone 3.0';
  818. $this->assertTrue($request->isMobile());
  819. $request->addDetector('callme', array('env' => 'TEST_VAR', 'callback' => array($this, 'detectCallback')));
  820. $request->addDetector('index', array('param' => 'action', 'value' => 'index'));
  821. $request->params['action'] = 'index';
  822. $this->assertTrue($request->isIndex());
  823. $request->params['action'] = 'add';
  824. $this->assertFalse($request->isIndex());
  825. $request->return = true;
  826. $this->assertTrue($request->isCallMe());
  827. $request->return = false;
  828. $this->assertFalse($request->isCallMe());
  829. }
  830. /**
  831. * helper function for testing callbacks.
  832. *
  833. * @return void
  834. */
  835. public function detectCallback($request) {
  836. return $request->return == true;
  837. }
  838. /**
  839. * test getting headers
  840. *
  841. * @return void
  842. */
  843. public function testHeader() {
  844. $_SERVER['HTTP_HOST'] = 'localhost';
  845. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-ca) AppleWebKit/534.8+ (KHTML, like Gecko) Version/5.0 Safari/533.16';
  846. $request = new CakeRequest('/', false);
  847. $this->assertEquals($_SERVER['HTTP_HOST'], $request->header('host'));
  848. $this->assertEquals($_SERVER['HTTP_USER_AGENT'], $request->header('User-Agent'));
  849. }
  850. /**
  851. * test accepts() with and without parameters
  852. *
  853. * @return void
  854. */
  855. public function testAccepts() {
  856. $_SERVER['HTTP_ACCEPT'] = 'text/xml,application/xml;q=0.9,application/xhtml+xml,text/html,text/plain,image/png';
  857. $request = new CakeRequest('/', false);
  858. $result = $request->accepts();
  859. $expected = array(
  860. 'text/xml', 'application/xhtml+xml', 'text/html', 'text/plain', 'image/png', 'application/xml'
  861. );
  862. $this->assertEquals($expected, $result, 'Content types differ.');
  863. $result = $request->accepts('text/html');
  864. $this->assertTrue($result);
  865. $result = $request->accepts('image/gif');
  866. $this->assertFalse($result);
  867. }
  868. /**
  869. * Test that accept header types are trimmed for comparisons.
  870. *
  871. * @return void
  872. */
  873. public function testAcceptWithWhitespace() {
  874. $_SERVER['HTTP_ACCEPT'] = 'text/xml , text/html , text/plain,image/png';
  875. $request = new CakeRequest('/', false);
  876. $result = $request->accepts();
  877. $expected = array(
  878. 'text/xml', 'text/html', 'text/plain', 'image/png'
  879. );
  880. $this->assertEquals($expected, $result, 'Content types differ.');
  881. $this->assertTrue($request->accepts('text/html'));
  882. }
  883. /**
  884. * Content types from accepts() should respect the client's q preference values.
  885. *
  886. * @return void
  887. */
  888. public function testAcceptWithQvalueSorting() {
  889. $_SERVER['HTTP_ACCEPT'] = 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0';
  890. $request = new CakeRequest('/', false);
  891. $result = $request->accepts();
  892. $expected = array('application/xml', 'text/html', 'application/json');
  893. $this->assertEquals($expected, $result);
  894. }
  895. /**
  896. * Test the raw parsing of accept headers into the q value formatting.
  897. *
  898. * @return void
  899. */
  900. public function testParseAcceptWithQValue() {
  901. $_SERVER['HTTP_ACCEPT'] = 'text/html;q=0.8,application/json;q=0.7,application/xml;q=1.0,image/png';
  902. $request = new CakeRequest('/', false);
  903. $result = $request->parseAccept();
  904. $expected = array(
  905. '1.0' => array('application/xml', 'image/png'),
  906. '0.8' => array('text/html'),
  907. '0.7' => array('application/json'),
  908. );
  909. $this->assertEquals($expected, $result);
  910. }
  911. /**
  912. * Test parsing accept with a confusing accept value.
  913. *
  914. * @return void
  915. */
  916. public function testParseAcceptNoQValues() {
  917. $_SERVER['HTTP_ACCEPT'] = 'application/json, text/plain, */*';
  918. $request = new CakeRequest('/', false);
  919. $result = $request->parseAccept();
  920. $expected = array(
  921. '1.0' => array('application/json', 'text/plain', '*/*'),
  922. );
  923. $this->assertEquals($expected, $result);
  924. }
  925. /**
  926. * testBaseUrlAndWebrootWithModRewrite method
  927. *
  928. * @return void
  929. */
  930. public function testBaseUrlAndWebrootWithModRewrite() {
  931. Configure::write('App.baseUrl', false);
  932. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  933. $_SERVER['PHP_SELF'] = '/1.2.x.x/app/webroot/index.php';
  934. $_SERVER['PATH_INFO'] = '/posts/view/1';
  935. $request = new CakeRequest();
  936. $this->assertEquals('/1.2.x.x', $request->base);
  937. $this->assertEquals('/1.2.x.x/', $request->webroot);
  938. $this->assertEquals('posts/view/1', $request->url);
  939. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/app/webroot';
  940. $_SERVER['PHP_SELF'] = '/index.php';
  941. $_SERVER['PATH_INFO'] = '/posts/add';
  942. $request = new CakeRequest();
  943. $this->assertEquals('', $request->base);
  944. $this->assertEquals('/', $request->webroot);
  945. $this->assertEquals('posts/add', $request->url);
  946. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches/1.2.x.x/test/';
  947. $_SERVER['PHP_SELF'] = '/webroot/index.php';
  948. $request = new CakeRequest();
  949. $this->assertEquals('', $request->base);
  950. $this->assertEquals('/', $request->webroot);
  951. $_SERVER['DOCUMENT_ROOT'] = '/some/apps/where';
  952. $_SERVER['PHP_SELF'] = '/app/webroot/index.php';
  953. $request = new CakeRequest();
  954. $this->assertEquals('', $request->base);
  955. $this->assertEquals('/', $request->webroot);
  956. Configure::write('App.dir', 'auth');
  957. $_SERVER['DOCUMENT_ROOT'] = '/cake/repo/branches';
  958. $_SERVER['PHP_SELF'] = '/demos/auth/webroot/index.php';
  959. $request = new CakeRequest();
  960. $this->assertEquals('/demos/auth', $request->base);
  961. $this->assertEquals('/demos/auth/', $request->webroot);
  962. Configure::write('App.dir', 'code');
  963. $_SERVER['DOCUMENT_ROOT'] = '/Library/WebServer/Documents';
  964. $_SERVER['PHP_SELF'] = '/clients/PewterReport/code/webroot/index.php';
  965. $request = new CakeRequest();
  966. $this->assertEquals('/clients/PewterReport/code', $request->base);
  967. $this->assertEquals('/clients/PewterReport/code/', $request->webroot);
  968. }
  969. /**
  970. * testBaseUrlwithModRewriteAlias method
  971. *
  972. * @return void
  973. */
  974. public function testBaseUrlwithModRewriteAlias() {
  975. $_SERVER['DOCUMENT_ROOT'] = '/home/aplusnur/public_html';
  976. $_SERVER['PHP_SELF'] = '/control/index.php';
  977. Configure::write('App.base', '/control');
  978. $request = new CakeRequest();
  979. $this->assertEquals('/control', $request->base);
  980. $this->assertEquals('/control/', $request->webroot);
  981. Configure::write('App.base', false);
  982. Configure::write('App.dir', 'affiliate');
  983. Configure::write('App.webroot', 'newaffiliate');
  984. $_SERVER['DOCUMENT_ROOT'] = '/var/www/abtravaff/html';
  985. $_SERVER['PHP_SELF'] = '/newaffiliate/index.php';
  986. $request = new CakeRequest();
  987. $this->assertEquals('/newaffiliate', $request->base);
  988. $this->assertEquals('/newaffiliate/', $request->webroot);
  989. }
  990. /**
  991. * test base, webroot, and url parsing when there is no url rewriting
  992. *
  993. * @return void
  994. */
  995. public function testBaseUrlWithNoModRewrite() {
  996. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites';
  997. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake/index.php';
  998. $_SERVER['PHP_SELF'] = '/cake/index.php/posts/index';
  999. $_SERVER['REQUEST_URI'] = '/cake/index.php/posts/index';
  1000. Configure::write('App', array(
  1001. 'dir' => APP_DIR,
  1002. 'webroot' => WEBROOT_DIR,
  1003. 'base' => false,
  1004. 'baseUrl' => '/cake/index.php'
  1005. ));
  1006. $request = new CakeRequest();
  1007. $this->assertEquals('/cake/index.php', $request->base);
  1008. $this->assertEquals('/cake/app/webroot/', $request->webroot);
  1009. $this->assertEquals('posts/index', $request->url);
  1010. }
  1011. /**
  1012. * testBaseUrlAndWebrootWithBaseUrl method
  1013. *
  1014. * @return void
  1015. */
  1016. public function testBaseUrlAndWebrootWithBaseUrl() {
  1017. Configure::write('App.dir', 'app');
  1018. Configure::write('App.baseUrl', '/app/webroot/index.php');
  1019. $request = new CakeRequest();
  1020. $this->assertEquals('/app/webroot/index.php', $request->base);
  1021. $this->assertEquals('/app/webroot/', $request->webroot);
  1022. Configure::write('App.baseUrl', '/app/webroot/test.php');
  1023. $request = new CakeRequest();
  1024. $this->assertEquals('/app/webroot/test.php', $request->base);
  1025. $this->assertEquals('/app/webroot/', $request->webroot);
  1026. Configure::write('App.baseUrl', '/app/index.php');
  1027. $request = new CakeRequest();
  1028. $this->assertEquals('/app/index.php', $request->base);
  1029. $this->assertEquals('/app/webroot/', $request->webroot);
  1030. Configure::write('App.baseUrl', '/CakeBB/app/webroot/index.php');
  1031. $request = new CakeRequest();
  1032. $this->assertEquals('/CakeBB/app/webroot/index.php', $request->base);
  1033. $this->assertEquals('/CakeBB/app/webroot/', $request->webroot);
  1034. Configure::write('App.baseUrl', '/CakeBB/app/index.php');
  1035. $request = new CakeRequest();
  1036. $this->assertEquals('/CakeBB/app/index.php', $request->base);
  1037. $this->assertEquals('/CakeBB/app/webroot/', $request->webroot);
  1038. Configure::write('App.baseUrl', '/CakeBB/index.php');
  1039. $request = new CakeRequest();
  1040. $this->assertEquals('/CakeBB/index.php', $request->base);
  1041. $this->assertEquals('/CakeBB/app/webroot/', $request->webroot);
  1042. Configure::write('App.baseUrl', '/dbhauser/index.php');
  1043. $_SERVER['DOCUMENT_ROOT'] = '/kunden/homepages/4/d181710652/htdocs/joomla';
  1044. $_SERVER['SCRIPT_FILENAME'] = '/kunden/homepages/4/d181710652/htdocs/joomla/dbhauser/index.php';
  1045. $request = new CakeRequest();
  1046. $this->assertEquals('/dbhauser/index.php', $request->base);
  1047. $this->assertEquals('/dbhauser/app/webroot/', $request->webroot);
  1048. }
  1049. /**
  1050. * test baseUrl with no rewrite and using the top level index.php.
  1051. *
  1052. * @return void
  1053. */
  1054. public function testBaseUrlNoRewriteTopLevelIndex() {
  1055. Configure::write('App.baseUrl', '/index.php');
  1056. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev';
  1057. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/index.php';
  1058. $request = new CakeRequest();
  1059. $this->assertEquals('/index.php', $request->base);
  1060. $this->assertEquals('/app/webroot/', $request->webroot);
  1061. }
  1062. /**
  1063. * Check that a sub-directory containing app|webroot doesn't get mishandled when re-writing is off.
  1064. *
  1065. * @return void
  1066. */
  1067. public function testBaseUrlWithAppAndWebrootInDirname() {
  1068. Configure::write('App.baseUrl', '/approval/index.php');
  1069. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1070. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/approval/index.php';
  1071. $request = new CakeRequest();
  1072. $this->assertEquals('/approval/index.php', $request->base);
  1073. $this->assertEquals('/approval/app/webroot/', $request->webroot);
  1074. Configure::write('App.baseUrl', '/webrootable/index.php');
  1075. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/';
  1076. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/webrootable/index.php';
  1077. $request = new CakeRequest();
  1078. $this->assertEquals('/webrootable/index.php', $request->base);
  1079. $this->assertEquals('/webrootable/app/webroot/', $request->webroot);
  1080. }
  1081. /**
  1082. * test baseUrl with no rewrite, and using the app/webroot/index.php file as is normal with virtual hosts.
  1083. *
  1084. * @return void
  1085. */
  1086. public function testBaseUrlNoRewriteWebrootIndex() {
  1087. Configure::write('App.baseUrl', '/index.php');
  1088. $_SERVER['DOCUMENT_ROOT'] = '/Users/markstory/Sites/cake_dev/app/webroot';
  1089. $_SERVER['SCRIPT_FILENAME'] = '/Users/markstory/Sites/cake_dev/app/webroot/index.php';
  1090. $request = new CakeRequest();
  1091. $this->assertEquals('/index.php', $request->base);
  1092. $this->assertEquals('/', $request->webroot);
  1093. }
  1094. /**
  1095. * Test that a request with a . in the main GET parameter is filtered out.
  1096. * PHP changes GET parameter keys containing dots to _.
  1097. *
  1098. * @return void
  1099. */
  1100. public function testGetParamsWithDot() {
  1101. $_GET = array();
  1102. $_GET['/posts/index/add_add'] = '';
  1103. $_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php';
  1104. $_SERVER['REQUEST_URI'] = '/cake_dev/posts/index/add.add';
  1105. $request = new CakeRequest();
  1106. $this->assertEquals(array(), $request->query);
  1107. }
  1108. /**
  1109. * Test that a request with urlencoded bits in the main GET parameter are filtered out.
  1110. *
  1111. * @return void
  1112. */
  1113. public function testGetParamWithUrlencodedElement() {
  1114. $_GET = array();
  1115. $_GET['/posts/add/∂∂'] = '';
  1116. $_SERVER['PHP_SELF'] = '/cake_dev/app/webroot/index.php';
  1117. $_SERVER['REQUEST_URI'] = '/cake_dev/posts/add/%E2%88%82%E2%88%82';
  1118. $request = new CakeRequest();
  1119. $this->assertEquals(array(), $request->query);
  1120. }
  1121. /**
  1122. * generator for environment configurations
  1123. *
  1124. * @return void
  1125. */
  1126. public static function environmentGenerator() {
  1127. return array(
  1128. array(
  1129. 'IIS - No rewrite base path',
  1130. array(
  1131. 'App' => array(
  1132. 'base' => false,
  1133. 'baseUrl' => '/index.php',
  1134. 'dir' => 'app',
  1135. 'webroot' => 'webroot'
  1136. ),
  1137. 'SERVER' => array(
  1138. 'SCRIPT_NAME' => '/index.php',
  1139. 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot',
  1140. 'QUERY_STRING' => '',
  1141. 'REQUEST_URI' => '/index.php',
  1142. 'URL' => '/index.php',
  1143. 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\index.php',
  1144. 'ORIG_PATH_INFO' => '/index.php',
  1145. 'PATH_INFO' => '',
  1146. 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\index.php',
  1147. 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot',
  1148. 'PHP_SELF' => '/index.php',
  1149. ),
  1150. ),
  1151. array(
  1152. 'base' => '/index.php',
  1153. 'webroot' => '/app/webroot/',
  1154. 'url' => ''
  1155. ),
  1156. ),
  1157. array(
  1158. 'IIS - No rewrite with path, no PHP_SELF',
  1159. array(
  1160. 'App' => array(
  1161. 'base' => false,
  1162. 'baseUrl' => '/index.php?',
  1163. 'dir' => 'app',
  1164. 'webroot' => 'webroot'
  1165. ),
  1166. 'SERVER' => array(
  1167. 'QUERY_STRING' => '/posts/add',
  1168. 'REQUEST_URI' => '/index.php?/posts/add',
  1169. 'PHP_SELF' => '',
  1170. 'URL' => '/index.php?/posts/add',
  1171. 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot',
  1172. 'argv' => array('/posts/add'),
  1173. 'argc' => 1
  1174. ),
  1175. ),
  1176. array(
  1177. 'url' => 'posts/add',
  1178. 'base' => '/index.php?',
  1179. 'webroot' => '/app/webroot/'
  1180. )
  1181. ),
  1182. array(
  1183. 'IIS - No rewrite sub dir 2',
  1184. array(
  1185. 'App' => array(
  1186. 'base' => false,
  1187. 'baseUrl' => '/site/index.php',
  1188. 'dir' => 'app',
  1189. 'webroot' => 'webroot',
  1190. ),
  1191. 'SERVER' => array(
  1192. 'SCRIPT_NAME' => '/site/index.php',
  1193. 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot',
  1194. 'QUERY_STRING' => '',
  1195. 'REQUEST_URI' => '/site/index.php',
  1196. 'URL' => '/site/index.php',
  1197. 'SCRIPT_FILENAME' => 'C:\\Inetpub\\wwwroot\\site\\index.php',
  1198. 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot',
  1199. 'PHP_SELF' => '/site/index.php',
  1200. 'argv' => array(),
  1201. 'argc' => 0
  1202. ),
  1203. ),
  1204. array(
  1205. 'url' => '',
  1206. 'base' => '/site/index.php',
  1207. 'webroot' => '/site/app/webroot/'
  1208. ),
  1209. ),
  1210. array(
  1211. 'IIS - No rewrite sub dir 2 with path',
  1212. array(
  1213. 'App' => array(
  1214. 'base' => false,
  1215. 'baseUrl' => '/site/index.php',
  1216. 'dir' => 'app',
  1217. 'webroot' => 'webroot'
  1218. ),
  1219. 'GET' => array('/posts/add' => ''),
  1220. 'SERVER' => array(
  1221. 'SCRIPT_NAME' => '/site/index.php',
  1222. 'PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot',
  1223. 'QUERY_STRING' => '/posts/add',
  1224. 'REQUEST_URI' => '/site/index.php/posts/add',
  1225. 'URL' => '/site/index.php/posts/add',
  1226. 'ORIG_PATH_TRANSLATED' => 'C:\\Inetpub\\wwwroot\\site\\index.php',
  1227. 'DOCUMENT_ROOT' => 'C:\\Inetpub\\wwwroot',
  1228. 'PHP_SELF' => '/site/index.php/posts/add',
  1229. 'argv' => array('/posts/add'),
  1230. 'argc' => 1
  1231. ),
  1232. ),
  1233. array(
  1234. 'url' => 'posts/add',
  1235. 'base' => '/site/index.php',
  1236. 'webroot' => '/site/app/webroot/'
  1237. )
  1238. ),
  1239. array(
  1240. 'Apache - No rewrite, document root set to webroot, requesting path',
  1241. array(
  1242. 'App' => array(
  1243. 'base' => false,
  1244. 'baseUrl' => '/index.php',
  1245. 'dir' => 'app',
  1246. 'webroot' => 'webroot'
  1247. ),
  1248. 'SERVER' => array(
  1249. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
  1250. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  1251. 'QUERY_STRING' => '',
  1252. 'REQUEST_URI' => '/index.php/posts/index',
  1253. 'SCRIPT_NAME' => '/index.php',
  1254. 'PATH_INFO' => '/posts/index',
  1255. 'PHP_SELF' => '/index.php/posts/index',
  1256. ),
  1257. ),
  1258. array(
  1259. 'url' => 'posts/index',
  1260. 'base' => '/index.php',
  1261. 'webroot' => '/'
  1262. ),
  1263. ),
  1264. array(
  1265. 'Apache - No rewrite, document root set to webroot, requesting root',
  1266. array(
  1267. 'App' => array(
  1268. 'base' => false,
  1269. 'baseUrl' => '/index.php',
  1270. 'dir' => 'app',
  1271. 'webroot' => 'webroot'
  1272. ),
  1273. 'SERVER' => array(
  1274. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
  1275. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  1276. 'QUERY_STRING' => '',
  1277. 'REQUEST_URI' => '/index.php',
  1278. 'SCRIPT_NAME' => '/index.php',
  1279. 'PATH_INFO' => '',
  1280. 'PHP_SELF' => '/index.php',
  1281. ),
  1282. ),
  1283. array(
  1284. 'url' => '',
  1285. 'base' => '/index.php',
  1286. 'webroot' => '/'
  1287. ),
  1288. ),
  1289. array(
  1290. 'Apache - No rewrite, document root set above top level cake dir, requesting path',
  1291. array(
  1292. 'App' => array(
  1293. 'base' => false,
  1294. 'baseUrl' => '/site/index.php',
  1295. 'dir' => 'app',
  1296. 'webroot' => 'webroot'
  1297. ),
  1298. 'SERVER' => array(
  1299. 'SERVER_NAME' => 'localhost',
  1300. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1301. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1302. 'REQUEST_URI' => '/site/index.php/posts/index',
  1303. 'SCRIPT_NAME' => '/site/index.php',
  1304. 'PATH_INFO' => '/posts/index',
  1305. 'PHP_SELF' => '/site/index.php/posts/index',
  1306. ),
  1307. ),
  1308. array(
  1309. 'url' => 'posts/index',
  1310. 'base' => '/site/index.php',
  1311. 'webroot' => '/site/app/webroot/',
  1312. ),
  1313. ),
  1314. array(
  1315. 'Apache - No rewrite, document root set above top level cake dir, request root, no PATH_INFO',
  1316. array(
  1317. 'App' => array(
  1318. 'base' => false,
  1319. 'baseUrl' => '/site/index.php',
  1320. 'dir' => 'app',
  1321. 'webroot' => 'webroot'
  1322. ),
  1323. 'SERVER' => array(
  1324. 'SERVER_NAME' => 'localhost',
  1325. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1326. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1327. 'REQUEST_URI' => '/site/index.php/',
  1328. 'SCRIPT_NAME' => '/site/index.php',
  1329. 'PHP_SELF' => '/site/index.php/',
  1330. ),
  1331. ),
  1332. array(
  1333. 'url' => '',
  1334. 'base' => '/site/index.php',
  1335. 'webroot' => '/site/app/webroot/',
  1336. ),
  1337. ),
  1338. array(
  1339. 'Apache - No rewrite, document root set above top level cake dir, request path, with GET',
  1340. array(
  1341. 'App' => array(
  1342. 'base' => false,
  1343. 'baseUrl' => '/site/index.php',
  1344. 'dir' => 'app',
  1345. 'webroot' => 'webroot'
  1346. ),
  1347. 'GET' => array('a' => 'b', 'c' => 'd'),
  1348. 'SERVER' => array(
  1349. 'SERVER_NAME' => 'localhost',
  1350. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1351. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1352. 'REQUEST_URI' => '/site/index.php/posts/index?a=b&c=d',
  1353. 'SCRIPT_NAME' => '/site/index.php',
  1354. 'PATH_INFO' => '/posts/index',
  1355. 'PHP_SELF' => '/site/index.php/posts/index',
  1356. 'QUERY_STRING' => 'a=b&c=d'
  1357. ),
  1358. ),
  1359. array(
  1360. 'urlParams' => array('a' => 'b', 'c' => 'd'),
  1361. 'url' => 'posts/index',
  1362. 'base' => '/site/index.php',
  1363. 'webroot' => '/site/app/webroot/',
  1364. ),
  1365. ),
  1366. array(
  1367. 'Apache - w/rewrite, document root set above top level cake dir, request root, no PATH_INFO',
  1368. array(
  1369. 'App' => array(
  1370. 'base' => false,
  1371. 'baseUrl' => false,
  1372. 'dir' => 'app',
  1373. 'webroot' => 'webroot'
  1374. ),
  1375. 'SERVER' => array(
  1376. 'SERVER_NAME' => 'localhost',
  1377. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1378. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1379. 'REQUEST_URI' => '/site/',
  1380. 'SCRIPT_NAME' => '/site/app/webroot/index.php',
  1381. 'PHP_SELF' => '/site/app/webroot/index.php',
  1382. ),
  1383. ),
  1384. array(
  1385. 'url' => '',
  1386. 'base' => '/site',
  1387. 'webroot' => '/site/',
  1388. ),
  1389. ),
  1390. array(
  1391. 'Apache - w/rewrite, document root above top level cake dir, request root, no PATH_INFO/REQUEST_URI',
  1392. array(
  1393. 'App' => array(
  1394. 'base' => false,
  1395. 'baseUrl' => false,
  1396. 'dir' => 'app',
  1397. 'webroot' => 'webroot'
  1398. ),
  1399. 'SERVER' => array(
  1400. 'SERVER_NAME' => 'localhost',
  1401. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents',
  1402. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/index.php',
  1403. 'SCRIPT_NAME' => '/site/app/webroot/index.php',
  1404. 'PHP_SELF' => '/site/app/webroot/index.php',
  1405. 'PATH_INFO' => null,
  1406. 'REQUEST_URI' => null,
  1407. ),
  1408. ),
  1409. array(
  1410. 'url' => '',
  1411. 'base' => '/site',
  1412. 'webroot' => '/site/',
  1413. ),
  1414. ),
  1415. array(
  1416. 'Apache - w/rewrite, document root set to webroot, request root, no PATH_INFO/REQUEST_URI',
  1417. array(
  1418. 'App' => array(
  1419. 'base' => false,
  1420. 'baseUrl' => false,
  1421. 'dir' => 'app',
  1422. 'webroot' => 'webroot'
  1423. ),
  1424. 'SERVER' => array(
  1425. 'SERVER_NAME' => 'localhost',
  1426. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
  1427. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  1428. 'SCRIPT_NAME' => '/index.php',
  1429. 'PHP_SELF' => '/index.php',
  1430. 'PATH_INFO' => null,
  1431. 'REQUEST_URI' => null,
  1432. ),
  1433. ),
  1434. array(
  1435. 'url' => '',
  1436. 'base' => '',
  1437. 'webroot' => '/',
  1438. ),
  1439. ),
  1440. array(
  1441. 'Nginx - w/rewrite, document root set to webroot, request root, no PATH_INFO',
  1442. array(
  1443. 'App' => array(
  1444. 'base' => false,
  1445. 'baseUrl' => false,
  1446. 'dir' => 'app',
  1447. 'webroot' => 'webroot'
  1448. ),
  1449. 'GET' => array('/posts/add' => ''),
  1450. 'SERVER' => array(
  1451. 'SERVER_NAME' => 'localhost',
  1452. 'DOCUMENT_ROOT' => '/Library/WebServer/Documents/site/app/webroot',
  1453. 'SCRIPT_FILENAME' => '/Library/WebServer/Documents/site/app/webroot/index.php',
  1454. 'SCRIPT_NAME' => '/index.php',
  1455. 'QUERY_STRING' => '/posts/add&',
  1456. 'PHP_SELF' => '/index.php',
  1457. 'PATH_INFO' => null,
  1458. 'REQUEST_URI' => '/posts/add',
  1459. ),
  1460. ),
  1461. array(
  1462. 'url' => 'posts/add',
  1463. 'base' => '',
  1464. 'webroot' => '/',
  1465. 'urlParams' => array()
  1466. ),
  1467. ),
  1468. );
  1469. }
  1470. /**
  1471. * testEnvironmentDetection method
  1472. *
  1473. * @dataProvider environmentGenerator
  1474. * @return void
  1475. */
  1476. public function testEnvironmentDetection($name, $env, $expected) {
  1477. $_GET = array();
  1478. $this->__loadEnvironment($env);
  1479. $request = new CakeRequest();
  1480. $this->assertEquals($expected['url'], $request->url, "url error");
  1481. $this->assertEquals($expected['base'], $request->base, "base error");
  1482. $this->assertEquals($expected['webroot'], $request->webroot, "webroot error");
  1483. if (isset($expected['urlParams'])) {
  1484. $this->assertEquals($expected['urlParams'], $request->query, "GET param mismatch");
  1485. }
  1486. }
  1487. /**
  1488. * test the data() method reading
  1489. *
  1490. * @return void
  1491. */
  1492. public function testDataReading() {
  1493. $_POST['data'] = array(
  1494. 'Model' => array(
  1495. 'field' => 'value'
  1496. )
  1497. );
  1498. $request = new CakeRequest('posts/index');
  1499. $result = $request->data('Model');
  1500. $this->assertEquals($_POST['data']['Model'], $result);
  1501. $result = $request->data('Model.imaginary');
  1502. $this->assertNull($result);
  1503. }
  1504. /**
  1505. * test writing with data()
  1506. *
  1507. * @return void
  1508. */
  1509. public function testDataWriting() {
  1510. $_POST['data'] = array(
  1511. 'Model' => array(
  1512. 'field' => 'value'
  1513. )
  1514. );
  1515. $request = new CakeRequest('posts/index');
  1516. $result = $request->data('Model.new_value', 'new value');
  1517. $this->assertSame($result, $request, 'Return was not $this');
  1518. $this->assertEquals('new value', $request->data['Model']['new_value']);
  1519. $request->data('Post.title', 'New post')->data('Comment.1.author', 'Mark');
  1520. $this->assertEquals('New post', $request->data['Post']['title']);
  1521. $this->assertEquals('Mark', $request->data['Comment']['1']['author']);
  1522. }
  1523. /**
  1524. * test writing falsey values.
  1525. *
  1526. * @return void
  1527. */
  1528. public function testDataWritingFalsey() {
  1529. $request = new CakeRequest('posts/index');
  1530. $request->data('Post.null', null);
  1531. $this->assertNull($request->data['Post']['null']);
  1532. $request->data('Post.false', false);
  1533. $this->assertFalse($request->data['Post']['false']);
  1534. $request->data('Post.zero', 0);
  1535. $this->assertSame(0, $request->data['Post']['zero']);
  1536. $request->data('Post.empty', '');
  1537. $this->assertSame('', $request->data['Post']['empty']);
  1538. }
  1539. /**
  1540. * test accept language
  1541. *
  1542. * @return void
  1543. */
  1544. public function testAcceptLanguage() {
  1545. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'inexistent,en-ca';
  1546. $result = CakeRequest::acceptLanguage();
  1547. $this->assertEquals(array('inexistent', 'en-ca'), $result, 'Languages do not match');
  1548. $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es_mx;en_ca';
  1549. $result = CakeRequest::acceptLanguage();
  1550. $this->assertEquals(array('es-mx', 'en-ca'), $result, 'Languages do not match');
  1551. $result = CakeRequest::acceptLanguage('en-ca');
  1552. $this->assertTrue($result);
  1553. $result = CakeRequest::acceptLanguage('en-us');
  1554. $this->assertFalse($result);
  1555. }
  1556. /**
  1557. * test the here() method
  1558. *
  1559. * @return void
  1560. */
  1561. public function testHere() {
  1562. Configure::write('App.base', '/base_path');
  1563. $_GET = array('test' => 'value');
  1564. $request = new CakeRequest('/posts/add/1/name:value');
  1565. $result = $request->here();
  1566. $this->assertEquals('/base_path/posts/add/1/name:value?test=value', $result);
  1567. $result = $request->here(false);
  1568. $this->assertEquals('/posts/add/1/name:value?test=value', $result);
  1569. $request = new CakeRequest('/posts/base_path/1/name:value');
  1570. $result = $request->here();
  1571. $this->assertEquals('/base_path/posts/base_path/1/name:value?test=value', $result);
  1572. $result = $request->here(false);
  1573. $this->assertEquals('/posts/base_path/1/name:value?test=value', $result);
  1574. }
  1575. /**
  1576. * Test the input() method.
  1577. *
  1578. * @return void
  1579. */
  1580. public function testInput() {
  1581. $request = $this->getMock('CakeRequest', array('_readInput'));
  1582. $request->expects($this->once())->method('_readInput')
  1583. ->will($this->returnValue('I came from stdin'));
  1584. $result = $request->input();
  1585. $this->assertEquals('I came from stdin', $result);
  1586. }
  1587. /**
  1588. * Test input() decoding.
  1589. *
  1590. * @return void
  1591. */
  1592. public function testInputDecode() {
  1593. $request = $this->getMock('CakeRequest', array('_readInput'));
  1594. $request->expects($this->once())->method('_readInput')
  1595. ->will($this->returnValue('{"name":"value"}'));
  1596. $result = $request->input('json_decode');
  1597. $this->assertEquals(array('name' => 'value'), (array)$result);
  1598. }
  1599. /**
  1600. * Test input() decoding with additional arguments.
  1601. *
  1602. * @return void
  1603. */
  1604. public function testInputDecodeExtraParams() {
  1605. $xml = <<<XML
  1606. <?xml version="1.0" encoding="utf-8"?>
  1607. <post>
  1608. <title id="title">Test</title>
  1609. </post>
  1610. XML;
  1611. $request = $this->getMock('CakeRequest', array('_readInput'));
  1612. $request->expects($this->once())->method('_readInput')
  1613. ->will($this->returnValue($xml));
  1614. $result = $request->input('Xml::build', array('return' => 'domdocument'));
  1615. $this->assertInstanceOf('DOMDocument', $result);
  1616. $this->assertEquals(
  1617. 'Test',
  1618. $result->getElementsByTagName('title')->item(0)->childNodes->item(0)->wholeText
  1619. );
  1620. }
  1621. /**
  1622. * Test is('requested') and isRequested()
  1623. *
  1624. * @return void
  1625. */
  1626. public function testIsRequested() {
  1627. $request = new CakeRequest('/posts/index');
  1628. $request->addParams(array(
  1629. 'controller' => 'posts',
  1630. 'action' => 'index',
  1631. 'plugin' => null,
  1632. 'requested' => 1
  1633. ));
  1634. $this->assertTrue($request->is('requested'));
  1635. $this->assertTrue($request->isRequested());
  1636. $request = new CakeRequest('/posts/index');
  1637. $request->addParams(array(
  1638. 'controller' => 'posts',
  1639. 'action' => 'index',
  1640. 'plugin' => null,
  1641. ));
  1642. $this->assertFalse($request->is('requested'));
  1643. $this->assertFalse($request->isRequested());
  1644. }
  1645. /**
  1646. * loadEnvironment method
  1647. *
  1648. * @param array $env
  1649. * @return void
  1650. */
  1651. protected function __loadEnvironment($env) {
  1652. if (isset($env['App'])) {
  1653. Configure::write('App', $env['App']);
  1654. }
  1655. if (isset($env['GET'])) {
  1656. foreach ($env['GET'] as $key => $val) {
  1657. $_GET[$key] = $val;
  1658. }
  1659. }
  1660. if (isset($env['POST'])) {
  1661. foreach ($env['POST'] as $key => $val) {
  1662. $_POST[$key] = $val;
  1663. }
  1664. }
  1665. if (isset($env['SERVER'])) {
  1666. foreach ($env['SERVER'] as $key => $val) {
  1667. $_SERVER[$key] = $val;
  1668. }
  1669. }
  1670. }
  1671. }