/tests/Zend/Paginator/Adapter/DbSelect/OracleTest.php

https://github.com/tanduy/zf · PHP · 140 lines · 78 code · 19 blank · 43 comment · 3 complexity · 35cf913afa045e20472b361e8829172c MD5 · raw file

  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-2010 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. 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_Paginator
  43. */
  44. class Zend_Paginator_Adapter_DbSelect_OracleTest extends Zend_Paginator_Adapter_DbSelectTest
  45. {
  46. /**
  47. * Prepares the environment before running a test.
  48. */
  49. protected function setUp ()
  50. {
  51. if (! extension_loaded('oci8')) {
  52. $this->markTestSkipped('Oci8 extension is not loaded');
  53. }
  54. if (! TESTS_ZEND_DB_ADAPTER_ORACLE_ENABLED) {
  55. $this->markTestSkipped('Oracle is required');
  56. }
  57. $this->_db = new Zend_Db_Adapter_Oracle(
  58. array('host' => TESTS_ZEND_DB_ADAPTER_ORACLE_HOSTNAME ,
  59. 'username' => TESTS_ZEND_DB_ADAPTER_ORACLE_USERNAME ,
  60. 'password' => TESTS_ZEND_DB_ADAPTER_ORACLE_PASSWORD ,
  61. 'dbname' => TESTS_ZEND_DB_ADAPTER_ORACLE_SID));
  62. $this->_dropTable();
  63. $this->_createTable();
  64. $this->_populateTable();
  65. $this->_table = new TestTable($this->_db);
  66. $this->_query = $this->_db->select()
  67. ->from('test')
  68. ->order('number ASC') // ZF-3740
  69. ->limit(1000, 0); // ZF-3727
  70. $this->_adapter = new Zend_Paginator_Adapter_DbSelect($this->_query);
  71. }
  72. /**
  73. * Cleans up the environment after running a test.
  74. */
  75. protected function tearDown ()
  76. {
  77. $this->_dropTable();
  78. $this->_db = null;
  79. $this->_adapter = null;
  80. }
  81. protected function _createTable ()
  82. {
  83. $this->_db->query(
  84. 'create table "test" (
  85. "number" NUMBER(5),
  86. "testgroup" NUMBER(3),
  87. constraint "pk_test" primary key ("number")
  88. )');
  89. $this->_db->query(
  90. 'create table "test_empty" (
  91. "number" NUMBER(5),
  92. "testgroup" NUMBER(3),
  93. constraint "pk_test_empty" primary key ("number")
  94. )');
  95. }
  96. protected function _populateTable ()
  97. {
  98. for ($i = 1; $i < 251; $i ++) {
  99. $this->_db->query('insert into "test" values (' . $i . ', 1)');
  100. $this->_db->query('insert into "test" values (' . ($i + 250) . ', 2)');
  101. }
  102. }
  103. protected function _dropTable ()
  104. {
  105. try {
  106. $this->_db->query('drop table "test"');
  107. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  108. try {
  109. $this->_db->query('drop table "test_empty"');
  110. } catch (Zend_Db_Statement_Oracle_Exception $e) {}
  111. }
  112. public function testGroupByQueryOnEmptyTableReturnsRowCountZero()
  113. {
  114. $query = $this->_db->select()
  115. ->from('test_empty')
  116. ->order('number ASC')
  117. ->limit(1000, 0);
  118. $adapter = new Zend_Paginator_Adapter_DbSelect($query);
  119. $this->assertEquals(0, $adapter->count());
  120. }
  121. }