Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.56 KB | None | 0 0
  1. class MovieStarFixture extends CakeTestFixture {
  2. // NEW TRY from http://stackoverflow.com/a/2548908/55124
  3. var $name = 'MovieStar';
  4. var $fields = array(
  5. 'id' => array(
  6. 'type'=>'string',
  7. 'null' => false,
  8. 'default' => NULL,
  9. 'length' => 36,
  10. 'key' => 'primary'),
  11.  
  12. 'movie_id' => array(
  13. 'type'=>'string',
  14. 'null' => false,
  15. 'default' => NULL,
  16. 'length' => 36),
  17.  
  18. 'trace' => array('type'=>'string', 'null' => false, 'default' => NULL),
  19. 'star_date' => array(
  20. 'type'=>'datetime',
  21. 'null' => false,
  22. 'default' => NULL),
  23. 'movie_star_type_id' => array(
  24. 'type'=>'string',
  25. 'null' => false,
  26. 'default' => NULL,
  27. 'length' => 36),
  28. 'code' => array('type'=>'text', 'null' => false, 'default' => NULL),
  29. 'amount' => array('type'=>'float', 'null' => false, 'default' => 0),
  30. 'movie_star_recurrance_id' => array(
  31. 'type'=>'string',
  32. 'null' => false,
  33. 'default' => NULL,
  34. 'length' => 36),
  35. 'open' => array('type'=>'boolean', 'null' => false, 'default' => '1'),
  36. 'loss_axia' => array('type'=>'float', 'null' => true, 'default' => 0),
  37. 'loss_mgr1' => array('type'=>'float', 'null' => true, 'default' => 0),
  38. 'loss_mgr2' => array('type'=>'float', 'null' => true, 'default' => 0),
  39. 'loss_rep' => array('type'=>'float', 'null' => true, 'default' => 0)
  40. );
  41. var $records = array(
  42. array(
  43. 'id' => '52ab9259-0070-4583-8d6f-4ac6c0a81cd7',
  44. 'movie_id' => '440b7d13-5618-4560-be1d-93c5a2900a5e',
  45. 'trace' => '3331313133423',
  46. 'star_date' => '2013-12-13',
  47. 'movie_star_type_id' => '64f7c386-6725-4c62-83ac-ae309bec8b10',
  48. 'code' => 'C01',
  49. 'amount' => '222.0000',
  50. 'movie_star_recurrance_id' => '',
  51. 'open' => true,
  52. 'loss_axia' => '23.0000',
  53. 'loss_mgr1' => '0',
  54. 'loss_mgr2' => '0',
  55. 'loss_rep' => '0'
  56. ));
  57.  
  58. // THESE ARE ALL OF THE OTHER METHODS I HAVE TRIED
  59. // Loading Fixture Methods / / / / / / / / / / / / / / / / / / / / / / / /
  60.  
  61. // #1 - Import model and records / / / / / / / / / / / / / / / / / / / / /
  62. //public $import = array('model' => 'MovieStar', 'records' => true);
  63.  
  64.  
  65. // #2 - Use onlt table info - no model / / / / / / / / / / / / / / / / / /
  66. // public $import = array('table' => 'movie_stars', 'records' => true);
  67.  
  68.  
  69. // #3 - Specify Model and Create Records - Binds Data to Database/ / / / /
  70. /*
  71. public $records = array(
  72. array(
  73. 'MovieStar' => array(
  74. 'id' => '52ab917d-549c-493b-9ef5-54a1c0a81cd7',
  75. 'movie_id' => '440b7d13-5618-4560-be1d-93c5a2900a5e',
  76. 'trace' => '3331313133',
  77. 'star_date' => '2013-12-13',
  78. 'movie_star_type_id' => '64f7c386-6725-4c62-83ac-ae309bec8b10',
  79. 'code' => 'C01',
  80. 'amount' => '122.0000',
  81. 'movie_star_recurrance_id' => '',
  82. 'open' => true,
  83. 'loss_axia' => null,
  84. 'loss_mgr1' => null,
  85. 'loss_mgr2' => null,
  86. 'loss_rep' => null
  87. )
  88. )
  89. );
  90. public $import = array('model' => 'MovieStar', 'records' => false);
  91. */
  92.  
  93. // #4 - Specify Model and Create Records in Init / / / / / / / / / / / / /
  94. // public $import = 'MovieStar';
  95.  
  96. /* public function init() {
  97. $records = array(
  98. array(
  99. 'MovieStar' => array(
  100. 'id' => '52ab917d-549c-493b-9ef5-54a1c0a81cd7',
  101. 'movie_id' => '440b7d13-5618-4560-be1d-93c5a2900a5e',
  102. 'trace' => '3331313133',
  103. 'star_date' => '2013-12-13',
  104. 'movie_star_type_id' => '64f7c386-6725-4c62-83ac-ae309bec8b10',
  105. 'code' => 'C01',
  106. 'amount' => '122.0000',
  107. 'movie_star_recurrance_id' => '523525',
  108. 'open' => true,
  109. 'loss_axia' => null,
  110. 'loss_mgr1' => null,
  111. 'loss_mgr2' => null,
  112. 'loss_rep' => null
  113. )
  114. )
  115. );
  116. parent::init();
  117. }*/
  118.  
  119. // #5 - Try Model Setup / / / / / / / / / / / / / / / / / / / / / / / /
  120. // This drops all records after the first test
  121. /*public $records = array(
  122. array(
  123. 'MovieStar' => array(
  124. 'id' => '52ab917d-549c-493b-9ef5-54a1c0a81cd7',
  125. 'movie_id' => '440b7d13-5618-4560-be1d-93c5a2900a5e',
  126. 'trace' => '3331313133',
  127. 'star_date' => '2013-12-13',
  128. 'movie_star_type_id' => '64f7c386-6725-4c62-83ac-ae309bec8b10',
  129. 'code' => 'C01',
  130. 'amount' => '122.0000',
  131. 'movie_star_recurrance_id' => '',
  132. 'open' => true,
  133. 'loss_axia' => null,
  134. 'loss_mgr1' => null,
  135. 'loss_mgr2' => null,
  136. 'loss_rep' => null
  137. )
  138. )
  139. );
  140.  
  141. }*/
  142.  
  143. <?php
  144. App::uses('Controller', 'Controller');
  145. App::uses('View', 'View');
  146. App::uses('MovieStar', 'Model');
  147.  
  148. /**
  149. * MovieStar Test Case
  150. *
  151. */
  152. class MovieStarTest extends CakeTestCase {
  153.  
  154. /**
  155. * Fixtures
  156. *
  157. * @var array
  158. */
  159. public $fixtures = array(
  160. 'app.movie_star'//,
  161. //'app.movie_star_recurrance',
  162. //'app.movie_star_type',
  163. //'app.movie',
  164. //'app.user',
  165. //'app.movie_star_line',
  166. //'app.movie_star_status'
  167. );
  168.  
  169. public $autoFixtures = false;
  170. public $dropTables = false;
  171.  
  172. /**
  173. * setUp method
  174. *
  175. * @return void
  176. */
  177. public function setUp() {
  178. parent::setUp();
  179.  
  180. $this->MovieStar =& ClassRegistry::init('MovieStar');
  181. $this->MovieStar->useDbConfig = 'test';
  182.  
  183. //$this->MovieStar->query("SELECT truncate_tables('axia')");
  184.  
  185. // load data
  186. $this->loadFixtures('MovieStar');
  187. }
  188.  
  189. /**
  190. * tearDown method
  191. *
  192. * @return void
  193. */
  194. public function testFixtures() {
  195. $numberOfResults = $this->MovieStar->find('count');
  196. debug($numberOfResults);
  197. $resultGreaterThanMinimumValue = $numberOfResults > 2;
  198. $this->assertTrue($resultGreaterThanMinimumValue);
  199. }
  200.  
  201. public function testFixtures2() {
  202. $numberOfResults = $this->MovieStar->find('count');
  203. debug('$numberOfResults');
  204. debug($numberOfResults);
  205. $resultIsZero = $numberOfResults == 0;
  206. $this->assertTrue($resultIsZero);
  207. }
  208.  
  209. public function testFindStarsByMovieId() {
  210. $movieId = '440b7d13-5618-4560-be1d-93c5a2900a5e';
  211. $result = $this->MovieStar->findStarsByMovieId($movieId);
  212. $expected = array(
  213. array(
  214. 'MovieStar' => array(
  215. 'id' => '52ab9259-0070-4583-8d6f-4ac6c0a81cd7',
  216. 'movie_id' => '440b7d13-5618-4560-be1d-93c5a2900a5e',
  217. 'trace' => '3331313133423',
  218. 'star_date' => '2013-12-13',
  219. 'movie_star_type_id' => '64f7c386-6725-4c62-83ac-ae309bec8b10',
  220. 'code' => 'C01',
  221. 'amount' => '222.0000',
  222. 'movie_star_recurrance_id' => '',
  223. 'open' => true,
  224. 'loss_axia' => '23.0000',
  225. 'loss_mgr1' => null,
  226. 'loss_mgr2' => null,
  227. 'loss_rep' => null
  228. )
  229. )
  230. );
  231.  
  232. debug("Expected");
  233. debug($expected);
  234. debug("Result");
  235. debug($result);
  236.  
  237. $this->assertEquals($expected, $result);
  238. }
  239.  
  240. public function tearDown() {
  241. //$this->MovieStar->deleteAll(true, true);
  242. //unset($this->MovieStar);
  243.  
  244. parent::tearDown();
  245. }
  246.  
  247. }
  248.  
  249. public $dropTables = false;
  250.  
  251. public $import = array('model' => 'YourModel', 'records' => false, 'connection' => 'default');
  252.  
  253. class MovieStarFixture extends CakeTestFixture {
  254.  
  255. public $import = 'MovieStar';
  256.  
  257. //data will be loaded into this fixture by the test cases
  258.  
  259. // do not truncate movie_stars table between tests
  260. public function truncate($db){
  261.  
  262. return null;
  263. }
  264.  
  265. // do not drop movie_stars table between tests
  266. public function drop($db){
  267.  
  268. return null;
  269. }
  270. }
  271.  
  272. class MovieStarFixture extends CakeTestFixture
  273. {
  274.  
  275. public $import = ['model' => 'MovieStar', 'connection' => 'default', 'records' => true];
  276.  
  277. private $created_flag = false;
  278.  
  279. public function create($db)
  280. {
  281. $success = null;
  282. if (!$this->created_flag) {
  283. $success = parent::create($db);
  284. }
  285. return $success;
  286. }
  287.  
  288. public function truncate($db)
  289. {
  290. $success = null;
  291. if (!$this->created_flag) {
  292. $success = parent::truncate($db);
  293. }
  294. return $success;
  295. }
  296.  
  297. public function insert($db)
  298. {
  299. $success = null;
  300. if (!$this->created_flag) {
  301. $success = parent::insert($db);
  302. $this->created_flag = true;
  303. }
  304. return $success;
  305. }
  306.  
  307. public function drop($db)
  308. {
  309. $success = null;
  310. if (!$this->created_flag) {
  311. $success = parent::drop($db);
  312. }
  313. }
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement