OrcaleTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * DboOracleTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2010, 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-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @package cake.libs
  16. * @since CakePHP(tm) v 1.2.0
  17. * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  18. */
  19. require_once LIBS . 'model' . DS . 'datasources' . DS . 'dbo_source.php';
  20. require_once LIBS . 'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_oracle.php';
  21. /**
  22. * DboOracleTest class
  23. *
  24. * @package cake.tests.cases.libs.model.datasources.dbo
  25. */
  26. class DboOracleTest extends CakeTestCase {
  27. /**
  28. * fixtures property
  29. */
  30. public $fixtures = array('core.oracle_user');
  31. /**
  32. * setup method
  33. *
  34. * @access public
  35. * @return void
  36. */
  37. function setUp() {
  38. $this->_initDb();
  39. }
  40. /**
  41. * skip method
  42. *
  43. * @access public
  44. * @return void
  45. */
  46. function skip() {
  47. $this->_initDb();
  48. $this->skipUnless($this->db->config['driver'] == 'oracle', '%s Oracle connection not available');
  49. }
  50. /**
  51. * testLastErrorStatement method
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function testLastErrorStatement() {
  57. if ($this->skip('testLastErrorStatement')) {
  58. return;
  59. }
  60. $this->expectError();
  61. $this->db->execute("SELECT ' FROM dual");
  62. $e = $this->db->lastError();
  63. $r = 'ORA-01756: quoted string not properly terminated';
  64. $this->assertEqual($e, $r);
  65. }
  66. /**
  67. * testLastErrorConnect method
  68. *
  69. * @access public
  70. * @return void
  71. */
  72. function testLastErrorConnect() {
  73. if ($this->skip('testLastErrorConnect')) {
  74. return;
  75. }
  76. $config = $this->db->config;
  77. $old_pw = $this->db->config['password'];
  78. $this->db->config['password'] = 'keepmeout';
  79. $this->db->connect();
  80. $e = $this->db->lastError();
  81. $r = 'ORA-01017: invalid username/password; logon denied';
  82. $this->assertEqual($e, $r);
  83. $this->db->config['password'] = $old_pw;
  84. $this->db->connect();
  85. }
  86. /**
  87. * testName method
  88. *
  89. * @access public
  90. * @return void
  91. */
  92. function testName() {
  93. $Db = $this->db;
  94. #$Db = new DboOracle($config = null, $autoConnect = false);
  95. $r = $Db->name($Db->name($Db->name('foo.last_update_date')));
  96. $e = 'foo.last_update_date';
  97. $this->assertEqual($e, $r);
  98. $r = $Db->name($Db->name($Db->name('foo._update')));
  99. $e = 'foo."_update"';
  100. $this->assertEqual($e, $r);
  101. $r = $Db->name($Db->name($Db->name('foo.last_update_date')));
  102. $e = 'foo.last_update_date';
  103. $this->assertEqual($e, $r);
  104. $r = $Db->name($Db->name($Db->name('last_update_date')));
  105. $e = 'last_update_date';
  106. $this->assertEqual($e, $r);
  107. $r = $Db->name($Db->name($Db->name('_update')));
  108. $e = '"_update"';
  109. $this->assertEqual($e, $r);
  110. }
  111. }