SubscriptionTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 UnitTests
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
  22. require_once 'Zend/Feed/Pubsubhubbub/Model/Subscription.php';
  23. /**
  24. * @category Zend
  25. * @package Zend_Feed
  26. * @subpackage UnitTests
  27. * @group Zend_Feed
  28. * @group Zend_Feed_Pubsubhubbub_Model
  29. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Feed_Pubsubhubbub_Model_SubscriptionTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * @group ZF-10069
  36. */
  37. public function testAllOperations()
  38. {
  39. $this->_initDb();
  40. $subscription = new Zend_Feed_Pubsubhubbub_Model_Subscription();
  41. $id = uniqid();
  42. $this->assertFalse($subscription->hasSubscription($id));
  43. $this->assertFalse($subscription->getSubscription($id));
  44. $this->assertFalse($subscription->deleteSubscription($id));
  45. $this->assertTrue($subscription->setSubscription(array('id' => $id)));
  46. $this->assertTrue($subscription->hasSubscription($id));
  47. $dataSubscription = $subscription->getSubscription($id);
  48. $this->assertType('array', $dataSubscription);
  49. $keys = array('id', 'topic_url', 'hub_url',
  50. 'created_time', 'lease_seconds',
  51. 'verify_token', 'secret',
  52. 'expiration_time', 'subscription_state');
  53. $this->assertSame($keys, array_keys($dataSubscription));
  54. $this->assertFalse($subscription->setSubscription(array('id' => $id)));
  55. $this->assertTrue($subscription->deleteSubscription($id));
  56. }
  57. public function testImpemetsSubscriptionInterface()
  58. {
  59. $reflection = new ReflectionClass('Zend_Feed_Pubsubhubbub_Model_Subscription');
  60. $this->assertTrue($reflection->implementsInterface('Zend_Feed_Pubsubhubbub_Model_SubscriptionInterface'));
  61. unset($reflection);
  62. }
  63. protected function _initDb()
  64. {
  65. if (!extension_loaded('pdo')) {
  66. $this->markTestSkipped("extension 'PDO' is not loaded");
  67. }
  68. if (!in_array('sqlite', PDO::getAvailableDrivers())) {
  69. $this->markTestSkipped("PDO driver 'sqlite' is not available");
  70. }
  71. $db = Zend_Db::factory('Pdo_Sqlite', array('dbname' => ':memory:'));
  72. Zend_Db_Table::setDefaultAdapter($db);
  73. $this->_createTable();
  74. }
  75. protected function _createTable()
  76. {
  77. $sql = "CREATE TABLE subscription ("
  78. . "id varchar(32) NOT NULL DEFAULT '', "
  79. . "topic_url varchar(255) DEFAULT NULL, "
  80. . "hub_url varchar(255) DEFAULT NULL, "
  81. . "created_time datetime DEFAULT NULL, "
  82. . "lease_seconds bigint(20) DEFAULT NULL, "
  83. . "verify_token varchar(255) DEFAULT NULL, "
  84. . "secret varchar(255) DEFAULT NULL, "
  85. . "expiration_time datetime DEFAULT NULL, "
  86. . "subscription_state varchar(12) DEFAULT NULL, "
  87. . "PRIMARY KEY (id) "
  88. . ");";
  89. Zend_Db_Table::getDefaultAdapter()->getConnection()->query($sql);
  90. }
  91. }