2
0

OracleTest.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Paginator
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: DbSelectTest.php 12278 2008-11-03 20:39:46Z mikaelkael $
  21. */
  22. require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  23. /**
  24. * @see Zend_Paginator_Adapter_DbSelect
  25. */
  26. require_once 'Zend/Paginator/Adapter/DbSelect.php';
  27. /**
  28. * @see Zend_Db_Adapter_Oracle
  29. */
  30. require_once 'Zend/Db/Adapter/Oracle.php';
  31. /**
  32. * @see Zend_Paginator_Adapter_DbSelectTest
  33. */
  34. require_once 'Zend/Paginator/Adapter/DbSelectTest.php';
  35. require_once dirname(__FILE__) . '/../../_files/TestTable.php';
  36. /**
  37. * @category Zend
  38. * @package Zend_Paginator
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. */
  43. class Zend_Paginator_Adapter_DbSelect_OracleTest extends Zend_Paginator_Adapter_DbSelectTest
  44. {
  45. /**
  46. * Prepares the environment before running a test.
  47. */
  48. protected function setUp ()
  49. {
  50. if (! extension_loaded('oci8')) {
  51. $this->markTestSkipped('Oci8 extension is not loaded');
  52. }
  53. if (! TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED) {
  54. $this->markTestSkipped('Oracle is required');
  55. }
  56. $this->_db = new Zend_Db_Adapter_Oracle(
  57. array('host' => TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME ,
  58. 'username' => TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME ,
  59. 'password' => TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD ,
  60. 'dbname' => TESTS_ZEND_DB_ADAPTER_ORACLE_SID));
  61. $this->_dropTable();
  62. $this->_createTable();
  63. $this->_populateTable();
  64. $this->_table = new TestTable($this->_db);
  65. $this->_query = $this->_db->select()
  66. ->from('test')
  67. ->order('number ASC') // ZF-3740
  68. ->limit(1000, 0); // ZF-3727
  69. $this->_adapter = new Zend_Paginator_Adapter_DbSelect($this->_query);
  70. }
  71. /**
  72. * Cleans up the environment after running a test.
  73. */
  74. protected function tearDown ()
  75. {
  76. $this->_dropTable();
  77. $this->_db = null;
  78. $this->_adapter = null;
  79. }
  80. protected function _createTable ()
  81. {
  82. $this->_db->query(
  83. 'create table "test" (
  84. "number" NUMBER(5),
  85. "testgroup" NUMBER(3),
  86. constraint "pk_test" primary key ("number")
  87. )');
  88. $this->_db->query(
  89. 'create table "test_empty" (
  90. "number" NUMBER(5),
  91. "testgroup" NUMBER(3),
  92. constraint "pk_test_empty" primary key ("number")
  93. )');
  94. }
  95. protected function _populateTable ()
  96. {
  97. for ($i = 1; $i < 251; $i ++) {
  98. $this->_db->query('insert into "test" values (' . $i . ', 1)');
  99. $this->_db->query('insert into "test" values (' . ($i + 250) . ', 2)');
  100. }
  101. }
  102. protected function _dropTable ()
  103. {
  104. try {
  105. $this->_db->query('drop table "test"');
  106. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  107. try {
  108. $this->_db->query('drop table "test_empty"');
  109. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  110. }
  111. public function testGroupByQueryOnEmptyTableReturnsRowCountZero()
  112. {
  113. $query = $this->_db->select()
  114. ->from('test_empty')
  115. ->order('number ASC')
  116. ->limit(1000, 0);
  117. $adapter = new Zend_Paginator_Adapter_DbSelect($query);
  118. $this->assertEquals(0, $adapter->count());
  119. }
  120. }