PageRenderTime 47ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Feed/PubSubHubbub/Model/SubscriptionTest.php

https://github.com/mridgway/zf2
PHP | 98 lines | 58 code | 9 blank | 31 comment | 2 complexity | c75fed1753e1a2bf523699fb787b9508 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 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. namespace ZendTest\Feed\PubSubHubbub\Model;
  22. use Zend\Feed\PubSubHubbub\Model\Subscription;
  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 SubscriptionTest extends \PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * @group ZF-10069
  36. */
  37. public function testAllOperations()
  38. {
  39. $this->_initDb();
  40. $subscription = new 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\SubscriptionPersistence'));
  61. unset($reflection);
  62. }
  63. protected function _initDb()
  64. {
  65. if (!extension_loaded('pdo')
  66. || !in_array('sqlite', \PDO::getAvailableDrivers())
  67. ) {
  68. $this->markTestSkipped('Test only with pdo_sqlite');
  69. }
  70. $db = \Zend\Db\Db::factory('Pdo\Sqlite', array('dbname' => ':memory:'));
  71. \Zend\Db\Table\AbstractTable::setDefaultAdapter($db);
  72. $this->_createTable();
  73. }
  74. protected function _createTable()
  75. {
  76. $sql = "CREATE TABLE subscription ("
  77. . "id varchar(32) PRIMARY KEY 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. . ");";
  87. \Zend\Db\Table\AbstractTable::getDefaultAdapter()->getConnection()->query($sql);
  88. }
  89. }