tests.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. error_reporting(E_ALL);
  3. include ('api/autoloader.php');
  4. define('OK', ' [OK]' . PHP_EOL);
  5. define('ERR', ' [FAIL]' . PHP_EOL);
  6. if (ubRouting::optionCliCheck('run', false)) {
  7. $dumpFlag = ubRouting::optionCliCheck('dump', false) ? true : false;
  8. /**
  9. * Models creation
  10. */
  11. $todo = new NyanORM('todo');
  12. $magicTodo = new nya_todo();
  13. if (is_object($todo)) {
  14. print('Normal model creation:' . OK);
  15. } else {
  16. print('Normal model creation:' . ERR);
  17. }
  18. if (is_object($magicTodo)) {
  19. print('Magic model creation:' . OK);
  20. } else {
  21. print('Magic model creation:' . ERR);
  22. }
  23. /**
  24. * Data selection
  25. */
  26. $allTodos = $todo->getAll();
  27. if (is_array($allTodos)) {
  28. print('Model data selection:' . OK);
  29. } else {
  30. print('Model data selection:' . ERR);
  31. }
  32. if (!empty($allTodos)) {
  33. print('Not empty data received:' . OK);
  34. } else {
  35. print('Not empty data received:' . ERR);
  36. }
  37. if ($dumpFlag) {
  38. print_r($allTodos);
  39. print(PHP_EOL);
  40. }
  41. /**
  42. * New data record creation
  43. */
  44. $controlString = 'testing text string';
  45. $todo->data('text', $controlString);
  46. $todo->create();
  47. $newRecordId = $todo->getLastId();
  48. if (!empty($newRecordId)) {
  49. print('New record ID received:' . OK);
  50. /**
  51. * Checking data inside
  52. */
  53. $todo->where('id', '=', $newRecordId);
  54. $recordData = $todo->getAll();
  55. if (!empty($recordData)) {
  56. print('Not empty new record data received:' . OK);
  57. if ($recordData[0]['text'] == $controlString) {
  58. print('Proper data received from created record:' . OK);
  59. } else {
  60. print('Proper data received from created record:' . ERR);
  61. }
  62. } else {
  63. print('Not empty new record data received:' . ERR);
  64. }
  65. /**
  66. * Data update
  67. */
  68. $newDataString = 'updated string here';
  69. $todo->data('text', $newDataString);
  70. $todo->where('id', '=', $newRecordId);
  71. $todo->save();
  72. $todo->where('id', '=', $newRecordId);
  73. $recordData = $todo->getAll();
  74. if ($recordData[0]['text'] != $controlString) {
  75. print('Record update succefull:' . OK);
  76. if ($recordData[0]['text'] == $newDataString) {
  77. print('Record updated data proper:' . OK);
  78. } else {
  79. print('Record updated data proper:' . ERR);
  80. }
  81. } else {
  82. print('Record update succefull:' . ERR);
  83. }
  84. /**
  85. * Record deletion
  86. */
  87. $todo->where('id', '=', $newRecordId);
  88. $todo->delete();
  89. //checking is record rly deleted
  90. $todo->where('id', '=', $newRecordId);
  91. $recordData = $todo->getAll();
  92. if (empty($recordData)) {
  93. print('Record deletion succefull:' . OK);
  94. } else {
  95. print('Record deletion succefull:' . ERR);
  96. }
  97. } else {
  98. print('Not empty data received:' . ERR);
  99. }
  100. } else {
  101. print('Usage: php ./tests.php --run [--dump]' . PHP_EOL);
  102. }