OracleTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * DboOracleTest file
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright 2005-2011, 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-2011, 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 CAKE . 'Model' . DS . 'Datasource' . DS . 'DboSource.php';
  20. require_once CAKE . 'Model' . DS . 'Datasource' . DS . 'Database' . DS . '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. public function setUp() {
  38. $this->Dbo = ConnectionManager::getDataSource('test');
  39. if (!($this->Dbo instanceof Oracle)) {
  40. $this->markTestSkipped('The Oracle extension is not available.');
  41. }
  42. }
  43. /**
  44. * testLastErrorStatement method
  45. *
  46. * @access public
  47. * @return void
  48. */
  49. public function testLastErrorStatement() {
  50. $this->expectError();
  51. $this->db->execute("SELECT ' FROM dual");
  52. $e = $this->db->lastError();
  53. $r = 'ORA-01756: quoted string not properly terminated';
  54. $this->assertEqual($e, $r);
  55. }
  56. /**
  57. * testLastErrorConnect method
  58. *
  59. * @access public
  60. * @return void
  61. */
  62. public function testLastErrorConnect() {
  63. $config = $this->db->config;
  64. $old_pw = $this->db->config['password'];
  65. $this->db->config['password'] = 'keepmeout';
  66. $this->db->connect();
  67. $e = $this->db->lastError();
  68. $r = 'ORA-01017: invalid username/password; logon denied';
  69. $this->assertEqual($e, $r);
  70. $this->db->config['password'] = $old_pw;
  71. $this->db->connect();
  72. }
  73. /**
  74. * testName method
  75. *
  76. * @access public
  77. * @return void
  78. */
  79. public function testName() {
  80. $Db = $this->db;
  81. #$Db = new DboOracle($config = null, $autoConnect = false);
  82. $r = $Db->name($Db->name($Db->name('foo.last_update_date')));
  83. $e = 'foo.last_update_date';
  84. $this->assertEqual($e, $r);
  85. $r = $Db->name($Db->name($Db->name('foo._update')));
  86. $e = 'foo."_update"';
  87. $this->assertEqual($e, $r);
  88. $r = $Db->name($Db->name($Db->name('foo.last_update_date')));
  89. $e = 'foo.last_update_date';
  90. $this->assertEqual($e, $r);
  91. $r = $Db->name($Db->name($Db->name('last_update_date')));
  92. $e = 'last_update_date';
  93. $this->assertEqual($e, $r);
  94. $r = $Db->name($Db->name($Db->name('_update')));
  95. $e = '"_update"';
  96. $this->assertEqual($e, $r);
  97. }
  98. }