ModelBaseTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. class EmptyModel extends \Entity\ModelBase
  3. {
  4. public function install()
  5. {
  6. $dbPrefix = $this->getDbPrefix();
  7. $result = self::$dbo->exec("CREATE TABLE IF NOT EXISTS `{$dbPrefix}emptymodel` (`id` INTEGER(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY)");
  8. if ($result === false)
  9. throw new \Exception(get_class().": ".self::$dbo->errorInfo()[2]);
  10. return true;
  11. }
  12. }
  13. class ModelBaseTest extends PHPUnit_Framework_TestCase
  14. {
  15. public function testModelCreation()
  16. {
  17. list($server, $mysqlConfig) = require("test/config.php");
  18. $dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
  19. $dbh->exec("DROP DATABASE ".$mysqlConfig[4][1]);
  20. $dbh->exec("CREATE DATABASE ".$mysqlConfig[4][1]);
  21. \Entity\ModelBase::init($mysqlConfig);
  22. $context = new \Tools\Context($server, false);
  23. \Entity\ModelBase::setup();
  24. }
  25. public function testInstallFailure()
  26. {
  27. list($server, $mysqlConfig) = require("test/config.php");
  28. $dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
  29. $dbh->exec("DROP DATABASE ".$mysqlConfig[4][1]);
  30. \Entity\ModelBase::init($mysqlConfig);
  31. $context = new \Tools\Context($server, false);
  32. $this->assertFalse(\Entity\ModelBase::setup());
  33. }
  34. public function testEmptyTable()
  35. {
  36. list($server, $mysqlConfig) = require("test/config.php");
  37. $dbh = new PDO($mysqlConfig[4][0], $mysqlConfig[1], $mysqlConfig[2]);
  38. $dbh->exec("CREATE DATABASE IF NOT EXISTS ".$mysqlConfig[4][1]);
  39. $table = new EmptyModel();
  40. $this->assertTrue($table->install());
  41. $item = new EmptyModel();
  42. $item->save();
  43. $item2 = new EmptyModel($item->id);
  44. $this->assertEquals($item->id, $item2->id);
  45. }
  46. public function testSelects()
  47. {
  48. //TODO
  49. }
  50. }