SubscriptionTest.php 3.7 KB

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