PageRenderTime 20ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ZendFramework/tests/Zend/Gdata/YouTube/ActivityEntryTest.php

https://bitbucket.org/Dal-Papa/is-340-publish-base
PHP | 153 lines | 107 code | 17 blank | 29 comment | 5 complexity | cb48bd2facd09318d81774ca55045c3c 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_Gdata_YouTube
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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 'Zend/Gdata/YouTube/ActivityEntry.php';
  23. require_once 'Zend/Gdata/YouTube.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_YouTube
  27. * @subpackage UnitTests
  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. * @group Zend_Gdata
  31. * @group Zend_Gdata_YouTube
  32. */
  33. class Zend_Gdata_YouTube_ActivityEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->entryText = file_get_contents(
  37. 'Zend/Gdata/YouTube/_files/ActivityEntryDataSample1.xml',
  38. true);
  39. $this->entry = new Zend_Gdata_YouTube_ActivityEntry();
  40. $this->entry->setMajorProtocolVersion(2);
  41. }
  42. private function verifyAllSamplePropertiesAreCorrect ($activityEntry) {
  43. $this->assertEquals(
  44. 'tag:youtube.com,2008:event:Z2RweXRob24xMTIzNDMwMDAyMzI5NTQ2N' .
  45. 'zg2MA%3D%3D',
  46. $activityEntry->id->text);
  47. $this->assertEquals('2009-01-16T09:13:49.000-08:00',
  48. $activityEntry->updated->text);
  49. $this->assertEquals(
  50. 'http://gdata.youtube.com/schemas/2007/userevents.cat',
  51. $activityEntry->category[0]->scheme);
  52. $this->assertEquals('video_favorited',
  53. $activityEntry->category[0]->term);
  54. $this->assertEquals('http://schemas.google.com/g/2005#kind',
  55. $activityEntry->category[1]->scheme);
  56. $this->assertEquals('http://gdata.youtube.com/schemas/2007#userEvent',
  57. $activityEntry->category[1]->term);
  58. $this->assertEquals('tayzonzay has favorited a video',
  59. $activityEntry->title->text);;
  60. $this->assertEquals('self', $activityEntry->getLink('self')->rel);
  61. $this->assertEquals('application/atom+xml',
  62. $activityEntry->getLink('self')->type);
  63. $this->assertEquals(
  64. 'http://gdata.youtube.com/feeds/api/events/VGF5Wm9uZGF5MzEyaIl2' .
  65. 'MTMxOTcxMDk3NzQ5MzM%3D?v=2',
  66. $activityEntry->getLink('self')->href);
  67. $this->assertEquals('alternate',
  68. $activityEntry->getLink('alternate')->rel);
  69. $this->assertEquals('text/html',
  70. $activityEntry->getLink('alternate')->type);
  71. $this->assertEquals('http://www.youtube.com',
  72. $activityEntry->getLink('alternate')->href);
  73. $this->assertEquals('http://gdata.youtube.com/schemas/2007#video',
  74. $activityEntry->getLink(
  75. 'http://gdata.youtube.com/schemas/2007#video')->rel);
  76. $this->assertEquals('application/atom+xml', $activityEntry->getLink(
  77. 'http://gdata.youtube.com/schemas/2007#video')->type);
  78. $this->assertEquals(
  79. 'http://gdata.youtube.com/feeds/api/videos/z3U0kuLH974?v=2',
  80. $activityEntry->getLink(
  81. 'http://gdata.youtube.com/schemas/2007#video')->href);
  82. $this->assertEquals('tayzonzay', $activityEntry->author[0]->name->text);
  83. $this->assertEquals(
  84. 'http://gdata.youtube.com/feeds/api/users/tayzonzay',
  85. $activityEntry->author[0]->uri->text);
  86. }
  87. public function testEmptyEntryShouldHaveNoExtensionElements() {
  88. $this->assertTrue(is_array($this->entry->extensionElements));
  89. $this->assertTrue(count($this->entry->extensionElements) == 0);
  90. }
  91. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  92. $this->assertTrue(is_array($this->entry->extensionAttributes));
  93. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  94. }
  95. public function testSampleEntryShouldHaveNoExtensionElements() {
  96. $this->entry->transferFromXML($this->entryText);
  97. $this->assertTrue(is_array($this->entry->extensionElements));
  98. $this->assertTrue(count($this->entry->extensionElements) == 0);
  99. }
  100. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  101. $this->entry->transferFromXML($this->entryText);
  102. $this->assertTrue(is_array($this->entry->extensionAttributes));
  103. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  104. }
  105. public function testEmptyActivityEntryToAndFromStringShouldMatch() {
  106. $entryXml = $this->entry->saveXML();
  107. $newActivityEntry = new Zend_Gdata_YouTube_ActivityEntry();
  108. $newActivityEntry->transferFromXML($entryXml);
  109. $newActivityEntryXml = $newActivityEntry->saveXML();
  110. $this->assertTrue($entryXml == $newActivityEntryXml);
  111. }
  112. public function testSamplePropertiesAreCorrect () {
  113. $this->entry->transferFromXML($this->entryText);
  114. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  115. }
  116. public function testHelperMethods() {
  117. $this->entry->transferFromXML($this->entryText);
  118. $this->assertEquals('z3U0kuLH974',
  119. $this->entry->getVideoId()->getText());
  120. $this->assertEquals('foo',
  121. $this->entry->getUsername()->getText());
  122. $this->assertEquals('2',
  123. $this->entry->getRatingValue());
  124. $this->assertEquals('video_favorited',
  125. $this->entry->getActivityType());
  126. }
  127. public function testConvertActivityEntryToAndFromString() {
  128. $this->entry->transferFromXML($this->entryText);
  129. $entryXml = $this->entry->saveXML();
  130. $newActivityEntry = new Zend_Gdata_YouTube_ActivityEntry();
  131. $newActivityEntry->transferFromXML($entryXml);
  132. $this->verifyAllSamplePropertiesAreCorrect($newActivityEntry);
  133. $newActivityEntryXml = $newActivityEntry->saveXML();
  134. $this->assertEquals($entryXml, $newActivityEntryXml);
  135. }
  136. }