OracleTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Paginator_Adapter_DbSelect
  24. */
  25. require_once 'Zend/Paginator/Adapter/DbSelect.php';
  26. /**
  27. * @see Zend_Db_Adapter_Oracle
  28. */
  29. require_once 'Zend/Db/Adapter/Oracle.php';
  30. /**
  31. * @see Zend_Paginator_Adapter_DbSelectTest
  32. */
  33. require_once 'Zend/Paginator/Adapter/DbSelectTest.php';
  34. require_once dirname(__FILE__) . '/../../_files/TestTable.php';
  35. /**
  36. * @category Zend
  37. * @package Zend_Paginator
  38. * @subpackage UnitTests
  39. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  40. * @license http://framework.zend.com/license/new-bsd New BSD License
  41. * @group Zend_Paginator
  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. if (! extension_loaded('oci8')) {
  77. $this->markTestSkipped('Oci8 extension is not loaded');
  78. }
  79. if (! TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED) {
  80. $this->markTestSkipped('Oracle is required');
  81. }
  82. $this->_dropTable();
  83. $this->_db = null;
  84. $this->_adapter = null;
  85. }
  86. protected function _createTable ()
  87. {
  88. $this->_db->query(
  89. 'create table "test" (
  90. "number" NUMBER(5),
  91. "testgroup" NUMBER(3),
  92. constraint "pk_test" primary key ("number")
  93. )');
  94. $this->_db->query(
  95. 'create table "test_empty" (
  96. "number" NUMBER(5),
  97. "testgroup" NUMBER(3),
  98. constraint "pk_test_empty" primary key ("number")
  99. )');
  100. }
  101. protected function _populateTable ()
  102. {
  103. for ($i = 1; $i < 251; $i ++) {
  104. $this->_db->query('insert into "test" values (' . $i . ', 1)');
  105. $this->_db->query('insert into "test" values (' . ($i + 250) . ', 2)');
  106. }
  107. }
  108. protected function _dropTable ()
  109. {
  110. try {
  111. $this->_db->query('drop table "test"');
  112. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  113. try {
  114. $this->_db->query('drop table "test_empty"');
  115. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  116. }
  117. public function testGroupByQueryOnEmptyTableReturnsRowCountZero()
  118. {
  119. $query = $this->_db->select()
  120. ->from('test_empty')
  121. ->order('number ASC')
  122. ->limit(1000, 0);
  123. $adapter = new Zend_Paginator_Adapter_DbSelect($query);
  124. $this->assertEquals(0, $adapter->count());
  125. }
  126. }