ContactEntryTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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-2015 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/ContactEntry.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-2015 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_ContactEntryTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->entryText = file_get_contents(
  37. 'Zend/Gdata/YouTube/_files/ContactEntryDataSample1.xml',
  38. true);
  39. $this->entry = new Zend_Gdata_YouTube_ContactEntry();
  40. }
  41. private function verifyAllSamplePropertiesAreCorrect ($contactEntry) {
  42. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic/contacts/testuser',
  43. $contactEntry->id->text);
  44. $this->assertEquals('2007-09-21T02:44:41.134Z', $contactEntry->updated->text);
  45. $this->assertEquals('http://schemas.google.com/g/2005#kind', $contactEntry->category[0]->scheme);
  46. $this->assertEquals('http://gdata.youtube.com/schemas/2007#friend', $contactEntry->category[0]->term);
  47. $this->assertEquals('http://gdata.youtube.com/schemas/2007/contact.cat', $contactEntry->category[1]->scheme);
  48. $this->assertEquals('Friends', $contactEntry->category[1]->term);
  49. $this->assertEquals('text', $contactEntry->title->type);
  50. $this->assertEquals('testuser', $contactEntry->title->text);;
  51. $this->assertEquals('self', $contactEntry->getLink('self')->rel);
  52. $this->assertEquals('application/atom+xml', $contactEntry->getLink('self')->type);
  53. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic/contacts/testuser', $contactEntry->getLink('self')->href);
  54. $this->assertEquals('davidchoimusic', $contactEntry->author[0]->name->text);
  55. $this->assertEquals('http://gdata.youtube.com/feeds/users/davidchoimusic', $contactEntry->author[0]->uri->text);
  56. $this->assertEquals('testuser', $contactEntry->username->text);
  57. $this->assertEquals('accepted', $contactEntry->status->text);
  58. }
  59. public function testEmptyEntryShouldHaveNoExtensionElements() {
  60. $this->assertTrue(is_array($this->entry->extensionElements));
  61. $this->assertTrue(count($this->entry->extensionElements) == 0);
  62. }
  63. public function testEmptyEntryShouldHaveNoExtensionAttributes() {
  64. $this->assertTrue(is_array($this->entry->extensionAttributes));
  65. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  66. }
  67. public function testSampleEntryShouldHaveNoExtensionElements() {
  68. $this->entry->transferFromXML($this->entryText);
  69. $this->assertTrue(is_array($this->entry->extensionElements));
  70. $this->assertTrue(count($this->entry->extensionElements) == 0);
  71. }
  72. public function testSampleEntryShouldHaveNoExtensionAttributes() {
  73. $this->entry->transferFromXML($this->entryText);
  74. $this->assertTrue(is_array($this->entry->extensionAttributes));
  75. $this->assertTrue(count($this->entry->extensionAttributes) == 0);
  76. }
  77. public function testEmptyContactEntryToAndFromStringShouldMatch() {
  78. $entryXml = $this->entry->saveXML();
  79. $newContactEntry = new Zend_Gdata_YouTube_ContactEntry();
  80. $newContactEntry->transferFromXML($entryXml);
  81. $newContactEntryXml = $newContactEntry->saveXML();
  82. $this->assertTrue($entryXml == $newContactEntryXml);
  83. }
  84. public function testSamplePropertiesAreCorrect () {
  85. $this->entry->transferFromXML($this->entryText);
  86. $this->verifyAllSamplePropertiesAreCorrect($this->entry);
  87. }
  88. public function testConvertContactEntryToAndFromString() {
  89. $this->entry->transferFromXML($this->entryText);
  90. $entryXml = $this->entry->saveXML();
  91. $newContactEntry = new Zend_Gdata_YouTube_ContactEntry();
  92. $newContactEntry->transferFromXML($entryXml);
  93. $this->verifyAllSamplePropertiesAreCorrect($newContactEntry);
  94. $newContactEntryXml = $newContactEntry->saveXML();
  95. $this->assertEquals($entryXml, $newContactEntryXml);
  96. }
  97. }