MyModelTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. <?php
  2. App::uses('MyModel', 'Tools.Model');
  3. App::uses('MyCakeTestCase', 'Tools.TestSuite');
  4. class MyModelTest extends MyCakeTestCase {
  5. public $Model;
  6. public $App;
  7. public $modelName = 'User';
  8. public $fixtures = array('core.user', 'core.post', 'core.author');
  9. public function setUp() {
  10. parent::setUp();
  11. $this->Model = ClassRegistry::init('Post');
  12. $this->App = ClassRegistry::init('User');
  13. }
  14. public function testObject() {
  15. $this->Model = ClassRegistry::init('MyModel');
  16. $this->assertTrue(is_object($this->Model));
  17. $this->assertInstanceOf('MyModel', $this->Model);
  18. }
  19. public function testGet() {
  20. $record = $this->Model->get(2);
  21. $this->assertEquals(2, $record['Post']['id']);
  22. $record = $this->Model->get(2, array('fields'=>'id', 'created'));
  23. $this->assertEquals(2, count($record['Post']));
  24. $record = $this->Model->get(2, array('fields'=>'id', 'title', 'body'), array('Author'));
  25. $this->assertEquals(3, $record['Author']['id']);
  26. }
  27. public function testEnum() {
  28. $array = array(
  29. 1 => 'foo',
  30. 2 => 'bar',
  31. );
  32. $res = AppTestModel::enum(null, $array, false);
  33. $this->assertEquals($array, $res);
  34. $res = AppTestModel::enum(2, $array, false);
  35. $this->assertEquals('bar', $res);
  36. $res = AppTestModel::enum('2', $array, false);
  37. $this->assertEquals('bar', $res);
  38. $res = AppTestModel::enum(3, $array, false);
  39. $this->assertFalse($res);
  40. }
  41. /**
  42. * more tests in MyModel Test directly
  43. */
  44. public function testGetFalse() {
  45. $this->App->order = array();
  46. $is = $this->App->get('xyz');
  47. $this->assertSame(array(), $is);
  48. }
  49. /**
  50. * test auto inc value of the current table
  51. */
  52. public function testGetNextAutoIncrement() {
  53. $this->out($this->_header(__FUNCTION__));
  54. $is = $this->App->getNextAutoIncrement();
  55. $this->out(returns($is));
  56. $schema = $this->App->schema('id');
  57. if ($schema['length'] == 36) {
  58. $this->assertFalse($is);
  59. } else {
  60. $this->assertTrue(is_int($is));
  61. }
  62. }
  63. public function testDeconstruct() {
  64. $data = array('year'=>'2010', 'month'=>'10', 'day'=>11);
  65. $res = $this->App->deconstruct('User.dob', $data);
  66. $this->assertEquals('2010-10-11', $res);
  67. $res = $this->App->deconstruct('User.dob', $data, 'datetime');
  68. $this->assertEquals('2010-10-11 00:00:00', $res);
  69. }
  70. /**
  71. * test that strings are correctly escaped using '
  72. */
  73. public function testEscapeValue() {
  74. $res = $this->App->escapeValue(4);
  75. $this->assertSame(4, $res);
  76. $res = $this->App->escapeValue('4');
  77. $this->assertSame('4', $res);
  78. $res = $this->App->escapeValue('a');
  79. $this->assertSame('\'a\'', $res);
  80. $res = $this->App->escapeValue(true);
  81. $this->assertSame(1, $res);
  82. $res = $this->App->escapeValue(false);
  83. $this->assertSame(0, $res);
  84. $res = $this->App->escapeValue(null);
  85. $this->assertSame(null, $res);
  86. # comparison to cakes escapeField here (which use ` to escape)
  87. $res = $this->App->escapeField('dob');
  88. $this->assertSame('`User`.`dob`', $res);
  89. }
  90. /**
  91. * test truncate
  92. */
  93. public function testTruncate() {
  94. $is = $this->App->find('count');
  95. $this->assertEquals(4, $is);
  96. $is = $this->App->getNextAutoIncrement();
  97. $this->assertEquals(5, $is);
  98. $is = $this->App->truncate();
  99. $is = $this->App->find('count');
  100. $this->assertEquals(0, $is);
  101. $is = $this->App->getNextAutoIncrement();
  102. $this->assertEquals(1, $is);
  103. }
  104. public function testValidateIdentical() {
  105. $this->out($this->_header(__FUNCTION__));
  106. $this->App->data = array($this->App->alias=>array('y'=>'efg'));
  107. $is = $this->App->validateIdentical(array('x'=>'efg'), 'y');
  108. $this->assertTrue($is);
  109. $this->App->data = array($this->App->alias=>array('y'=>'2'));
  110. $is = $this->App->validateIdentical(array('x'=>2), 'y');
  111. $this->assertFalse($is);
  112. $this->App->data = array($this->App->alias=>array('y'=>'3'));
  113. $is = $this->App->validateIdentical(array('x'=>3), 'y', array('cast'=>'int'));
  114. $this->assertTrue($is);
  115. $this->App->data = array($this->App->alias=>array('y'=>'3'));
  116. $is = $this->App->validateIdentical(array('x'=>3), 'y', array('cast'=>'string'));
  117. $this->assertTrue($is);
  118. }
  119. public function testValidateKey() {
  120. $this->out($this->_header(__FUNCTION__));
  121. //$this->App->data = array($this->App->alias=>array('y'=>'efg'));
  122. $testModel = new AppTestModel();
  123. $is = $testModel->validateKey(array('id'=>'2'));
  124. $this->assertFalse($is);
  125. $is = $testModel->validateKey(array('id'=>2));
  126. $this->assertFalse($is);
  127. $is = $testModel->validateKey(array('id'=>'4e6f-a2f2-19a4ab957338'));
  128. $this->assertFalse($is);
  129. $is = $testModel->validateKey(array('id'=>'4dff6725-f0e8-4e6f-a2f2-19a4ab957338'));
  130. $this->assertTrue($is);
  131. $is = $testModel->validateKey(array('id'=>''));
  132. $this->assertFalse($is);
  133. $is = $testModel->validateKey(array('id'=>''), array('allowEmpty'=>true));
  134. $this->assertTrue($is);
  135. $is = $testModel->validateKey(array('foreign_id'=>'2'));
  136. $this->assertTrue($is);
  137. $is = $testModel->validateKey(array('foreign_id'=>2));
  138. $this->assertTrue($is);
  139. $is = $testModel->validateKey(array('foreign_id'=>2.3));
  140. $this->assertFalse($is);
  141. $is = $testModel->validateKey(array('foreign_id'=>-2));
  142. $this->assertFalse($is);
  143. $is = $testModel->validateKey(array('foreign_id'=>'4dff6725-f0e8-4e6f-a2f2-19a4ab957338'));
  144. $this->assertFalse($is);
  145. $is = $testModel->validateKey(array('foreign_id'=>0));
  146. $this->assertFalse($is);
  147. $is = $testModel->validateKey(array('foreign_id'=>0), array('allowEmpty'=>true));
  148. $this->assertTrue($is);
  149. }
  150. public function testValidateEnum() {
  151. $this->out($this->_header(__FUNCTION__));
  152. //$this->App->data = array($this->App->alias=>array('y'=>'efg'));
  153. $testModel = new AppTestModel();
  154. $is = $testModel->validateEnum(array('x'=>'1'), true);
  155. $this->assertTrue($is);
  156. $is = $testModel->validateEnum(array('x'=>'4'), true);
  157. $this->assertFalse($is);
  158. $is = $testModel->validateEnum(array('x'=>'5'), true, array('4', '5'));
  159. $this->assertTrue($is);
  160. $is = $testModel->validateEnum(array('some_key'=>'3'), 'x', array('4', '5'));
  161. $this->assertTrue($is);
  162. }
  163. public function testGuaranteeFields() {
  164. $this->out($this->_header(__FUNCTION__));
  165. $res = $this->App->guaranteeFields(array());
  166. debug($res);
  167. $this->assertTrue(empty($res));
  168. $res = $this->App->guaranteeFields(array('x', 'y'));
  169. debug($res);
  170. $this->assertTrue(!empty($res));
  171. $this->assertEquals($res, array($this->modelName=>array('x'=>'', 'y'=>'')));
  172. $res = $this->App->guaranteeFields(array('x', 'OtherModel.y'));
  173. debug($res);
  174. $this->assertTrue(!empty($res));
  175. $this->assertEquals($res, array($this->modelName=>array('x'=>''), 'OtherModel'=>array('y'=>'')));
  176. }
  177. public function testSet() {
  178. $this->out($this->_header(__FUNCTION__));
  179. $data = array($this->modelName=>array('x'=>'hey'), 'OtherModel'=>array('y'=>''));
  180. $this->App->data = array();
  181. $res = $this->App->set($data, null, array('x', 'z'));
  182. $this->out($res);
  183. $this->assertTrue(!empty($res));
  184. $this->assertEquals($res, array($this->modelName=>array('x'=>'hey', 'z'=>''), 'OtherModel'=>array('y'=>'')));
  185. $res = $this->App->data;
  186. $this->out($res);
  187. $this->assertTrue(!empty($res));
  188. $this->assertEquals($res, array($this->modelName=>array('x'=>'hey', 'z'=>''), 'OtherModel'=>array('y'=>'')));
  189. }
  190. public function testValidateWithGuaranteeFields() {
  191. $this->out($this->_header(__FUNCTION__));
  192. $data = array($this->modelName=>array('x'=>'hey'), 'OtherModel'=>array('y'=>''));
  193. $data = $this->App->guaranteeFields(array('x', 'z'), $data);
  194. $this->out($data);
  195. $this->assertTrue(!empty($data));
  196. $this->assertEquals(array($this->modelName=>array('x'=>'hey', 'z'=>''), 'OtherModel'=>array('y'=>'')), $data);
  197. $res = $this->App->set($data);
  198. $this->out($res);
  199. $this->assertTrue(!empty($res));
  200. $this->assertEquals($res, array($this->modelName=>array('x'=>'hey', 'z'=>''), 'OtherModel'=>array('y'=>'')));
  201. }
  202. // not really working?
  203. public function testBlacklist() {
  204. $this->out($this->_header(__FUNCTION__));
  205. $data = array($this->modelName=>array('name'=>'e', 'x'=>'hey'), 'OtherModel'=>array('y'=>''));
  206. $schema = $this->App->schema();
  207. $data = $this->App->blacklist(array('x', 'z'));
  208. $this->out($data);
  209. if (!empty($schema)) {
  210. $this->assertTrue(!empty($data));
  211. } else {
  212. $this->assertTrue(empty($data));
  213. }
  214. //$this->assertEquals($data, array($this->modelName=>array('x'=>'hey', 'z'=>''), 'OtherModel'=>array('y'=>'')));
  215. }
  216. public function testAppInvalidate() {
  217. $this->out($this->_header(__FUNCTION__));
  218. $this->App->create();
  219. $this->App->invalidate('fieldx', __('e %s f', 33));
  220. $res = $this->App->validationErrors;
  221. $this->out($res);
  222. $this->assertTrue(!empty($res));
  223. $this->App->create();
  224. $this->App->invalidate('Model.fieldy', __('e %s f %s g', 33, 'xyz'));
  225. $res = $this->App->validationErrors;
  226. $this->out($res);
  227. $this->assertTrue(!empty($res) && $res['Model.fieldy'][0] == 'e 33 f xyz g');
  228. $this->App->create();
  229. $this->App->invalidate('fieldy', __('e %s f %s g %s', true, 'xyz', 55));
  230. $res = $this->App->validationErrors;
  231. $this->out($res);
  232. $this->assertTrue(!empty($res) && $res['fieldy'][0] == 'e 1 f xyz g 55');
  233. $this->App->create();
  234. $this->App->invalidate('fieldy', array('valErrMandatoryField'));
  235. $res = $this->App->validationErrors;
  236. $this->out($res);
  237. $this->assertTrue(!empty($res));
  238. $this->App->create();
  239. $this->App->invalidate('fieldy', 'valErrMandatoryField');
  240. $res = $this->App->validationErrors;
  241. $this->out($res);
  242. $this->assertTrue(!empty($res));
  243. $this->App->create();
  244. $this->App->invalidate('fieldy', __('a %s b %s c %s %s %s %s %s h %s', 1, 2, 3, 4, 5, 6, 7, 8));
  245. $res = $this->App->validationErrors;
  246. $this->out($res);
  247. $this->assertTrue(!empty($res) && $res['fieldy'][0] == 'a 1 b 2 c 3 4 5 6 7 h 8');
  248. }
  249. public function testAppValidateDate() {
  250. $this->out($this->_header(__FUNCTION__));
  251. $data = array('field' => '2010-01-22');
  252. $res = $this->App->validateDate($data);
  253. debug($res);
  254. $this->assertTrue($res);
  255. $data = array('field' => '2010-02-29');
  256. $res = $this->App->validateDate($data);
  257. debug($res);
  258. $this->assertFalse($res);
  259. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-22'));
  260. $data = array('field' => '2010-02-23 11:11:11');
  261. $res = $this->App->validateDate($data, array('after'=>'after'));
  262. debug($res);
  263. $this->assertTrue($res);
  264. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-24 11:11:11'));
  265. $data = array('field' => '2010-02-23');
  266. $res = $this->App->validateDate($data, array('after'=>'after'));
  267. debug($res);
  268. $this->assertFalse($res);
  269. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-25'));
  270. $data = array('field' => '2010-02-25');
  271. $res = $this->App->validateDate($data, array('after'=>'after'));
  272. debug($res);
  273. $this->assertTrue($res);
  274. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-25'));
  275. $data = array('field' => '2010-02-25');
  276. $res = $this->App->validateDate($data, array('after'=>'after', 'min'=>1));
  277. debug($res);
  278. $this->assertFalse($res);
  279. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-24'));
  280. $data = array('field' => '2010-02-25');
  281. $res = $this->App->validateDate($data, array('after'=>'after', 'min'=>2));
  282. debug($res);
  283. $this->assertFalse($res);
  284. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-24'));
  285. $data = array('field' => '2010-02-25');
  286. $res = $this->App->validateDate($data, array('after'=>'after', 'min'=>1));
  287. debug($res);
  288. $this->assertTrue($res);
  289. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-24'));
  290. $data = array('field' => '2010-02-25');
  291. $res = $this->App->validateDate($data, array('after'=>'after', 'min'=>2));
  292. debug($res);
  293. $this->assertFalse($res);
  294. $this->App->data = array($this->App->alias=>array('before'=>'2010-02-24'));
  295. $data = array('field' => '2010-02-24');
  296. $res = $this->App->validateDate($data, array('before'=>'before', 'min'=>1));
  297. debug($res);
  298. $this->assertFalse($res);
  299. $this->App->data = array($this->App->alias=>array('before'=>'2010-02-25'));
  300. $data = array('field' => '2010-02-24');
  301. $res = $this->App->validateDate($data, array('before'=>'before', 'min'=>1));
  302. debug($res);
  303. $this->assertTrue($res);
  304. $this->App->data = array($this->App->alias=>array('before'=>'2010-02-25'));
  305. $data = array('field' => '2010-02-24');
  306. $res = $this->App->validateDate($data, array('before'=>'before', 'min'=>2));
  307. debug($res);
  308. $this->assertFalse($res);
  309. $this->App->data = array($this->App->alias=>array('before'=>'2010-02-26'));
  310. $data = array('field' => '2010-02-24');
  311. $res = $this->App->validateDate($data, array('before'=>'before', 'min'=>2));
  312. debug($res);
  313. $this->assertTrue($res);
  314. }
  315. public function testAppValidateDatetime() {
  316. $this->out($this->_header(__FUNCTION__));
  317. $data = array('field' => '2010-01-22 11:11:11');
  318. $res = $this->App->validateDatetime($data);
  319. debug($res);
  320. $this->assertTrue($res);
  321. $data = array('field' => '2010-01-22 11:61:11');
  322. $res = $this->App->validateDatetime($data);
  323. debug($res);
  324. $this->assertFalse($res);
  325. $data = array('field' => '2010-02-29 11:11:11');
  326. $res = $this->App->validateDatetime($data);
  327. debug($res);
  328. $this->assertFalse($res);
  329. $data = array('field' => '');
  330. $res = $this->App->validateDatetime($data, array('allowEmpty'=>true));
  331. debug($res);
  332. $this->assertTrue($res);
  333. $data = array('field' => '0000-00-00 00:00:00');
  334. $res = $this->App->validateDatetime($data, array('allowEmpty'=>true));
  335. debug($res);
  336. $this->assertTrue($res);
  337. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-22 11:11:11'));
  338. $data = array('field' => '2010-02-23 11:11:11');
  339. $res = $this->App->validateDatetime($data, array('after'=>'after'));
  340. debug($res);
  341. $this->assertTrue($res);
  342. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-24 11:11:11'));
  343. $data = array('field' => '2010-02-23 11:11:11');
  344. $res = $this->App->validateDatetime($data, array('after'=>'after'));
  345. debug($res);
  346. $this->assertFalse($res);
  347. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:11'));
  348. $data = array('field' => '2010-02-23 11:11:11');
  349. $res = $this->App->validateDatetime($data, array('after'=>'after'));
  350. debug($res);
  351. $this->assertFalse($res);
  352. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:11'));
  353. $data = array('field' => '2010-02-23 11:11:11');
  354. $res = $this->App->validateDatetime($data, array('after'=>'after', 'min'=>1));
  355. debug($res);
  356. $this->assertFalse($res);
  357. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:11'));
  358. $data = array('field' => '2010-02-23 11:11:11');
  359. $res = $this->App->validateDatetime($data, array('after'=>'after', 'min'=>0));
  360. debug($res);
  361. $this->assertTrue($res);
  362. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:10'));
  363. $data = array('field' => '2010-02-23 11:11:11');
  364. $res = $this->App->validateDatetime($data, array('after'=>'after'));
  365. debug($res);
  366. $this->assertTrue($res);
  367. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:12'));
  368. $data = array('field' => '2010-02-23 11:11:11');
  369. $res = $this->App->validateDatetime($data, array('after'=>'after'));
  370. debug($res);
  371. $this->assertFalse($res);
  372. }
  373. public function testAppValidateTime() {
  374. $this->out($this->_header(__FUNCTION__));
  375. $data = array('field' => '11:21:11');
  376. $res = $this->App->validateTime($data);
  377. debug($res);
  378. $this->assertTrue($res);
  379. $data = array('field' => '11:71:11');
  380. $res = $this->App->validateTime($data);
  381. debug($res);
  382. $this->assertFalse($res);
  383. $this->App->data = array($this->App->alias=>array('before'=>'2010-02-23 11:11:12'));
  384. $data = array('field' => '2010-02-23 11:11:11');
  385. $res = $this->App->validateTime($data, array('before'=>'before'));
  386. debug($res);
  387. $this->assertTrue($res);
  388. $this->App->data = array($this->App->alias=>array('after'=>'2010-02-23 11:11:12'));
  389. $data = array('field' => '2010-02-23 11:11:11');
  390. $res = $this->App->validateTime($data, array('after'=>'after'));
  391. debug($res);
  392. $this->assertFalse($res);
  393. }
  394. public function testAppValidateUrl() {
  395. $this->out($this->_header(__FUNCTION__));
  396. $data = array('field' => 'www.dereuromark.de');
  397. $res = $this->App->validateUrl($data, array('allowEmpty'=>true));
  398. $this->assertTrue($res);
  399. $data = array('field' => 'www.xxxde');
  400. $res = $this->App->validateUrl($data, array('allowEmpty'=>true));
  401. $this->assertFalse($res);
  402. $data = array('field' => 'www.dereuromark.de');
  403. $res = $this->App->validateUrl($data, array('allowEmpty'=>true, 'autoComplete'=>false));
  404. $this->assertFalse($res);
  405. $data = array('field' => 'http://www.dereuromark.de');
  406. $res = $this->App->validateUrl($data, array('allowEmpty'=>true, 'autoComplete'=>false));
  407. $this->assertTrue($res);
  408. $data = array('field' => 'www.dereuromark.de');
  409. $res = $this->App->validateUrl($data, array('strict'=>true));
  410. $this->assertTrue($res); # aha
  411. $data = array('field' => 'http://www.dereuromark.de');
  412. $res = $this->App->validateUrl($data, array('strict'=>false));
  413. $this->assertTrue($res);
  414. $this->skipIf(empty($_SERVER['HTTP_HOST']), 'No HTTP_HOST');
  415. $data = array('field' => 'http://xyz.de/some/link');
  416. $res = $this->App->validateUrl($data, array('deep'=>false, 'sameDomain'=>true));
  417. $this->assertFalse($res);
  418. $data = array('field' => '/some/link');
  419. $res = $this->App->validateUrl($data, array('deep'=>false, 'autoComplete'=>true));
  420. $this->assertTrue($_SERVER['HTTP_HOST'] === 'localhost' ? !$res : $res);
  421. $data = array('field' => 'http://'.$_SERVER['HTTP_HOST'].'/some/link');
  422. $res = $this->App->validateUrl($data, array('deep'=>false));
  423. $this->assertTrue($_SERVER['HTTP_HOST'] === 'localhost' ? !$res : $res);
  424. $data = array('field' => '/some/link');
  425. $res = $this->App->validateUrl($data, array('deep'=>false, 'autoComplete'=>false));
  426. $this->assertTrue((env('REMOTE_ADDR') !== '127.0.0.1') ? !$res : $res);
  427. //$this->skipIf(strpos($_SERVER['HTTP_HOST'], '.') === false, 'No online HTTP_HOST');
  428. $data = array('field' => '/some/link');
  429. $res = $this->App->validateUrl($data, array('deep'=>false, 'sameDomain'=>true));
  430. $this->assertTrue($_SERVER['HTTP_HOST'] === 'localhost' ? !$res : $res);
  431. $data = array('field' => 'https://github.com/');
  432. $res = $this->App->validateUrl($data, array('deep'=>false));
  433. $this->assertTrue($res);
  434. $data = array('field' => 'https://github.com/');
  435. $res = $this->App->validateUrl($data, array('deep'=>true));
  436. $this->assertTrue($res);
  437. }
  438. }
  439. class Post extends MyModel {
  440. public $belongsTo = 'Author';
  441. }
  442. class User extends MyModel {
  443. }
  444. class AppTestModel extends MyModel {
  445. public $useTable = false;
  446. protected $_schema = array(
  447. 'id' => array (
  448. 'type' => 'string',
  449. 'null' => false,
  450. 'default' => '',
  451. 'length' => 36,
  452. 'key' => 'primary',
  453. 'collate' => 'utf8_unicode_ci',
  454. 'charset' => 'utf8',
  455. ),
  456. 'foreign_id' => array (
  457. 'type' => 'integer',
  458. 'null' => false,
  459. 'default' => '0',
  460. 'length' => 10,
  461. ),
  462. );
  463. public static function x() {
  464. return array('1'=>'x', '2'=>'y', '3'=>'z');
  465. }
  466. }