ContentTest.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_App
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2014 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/App/Extension/Content.php';
  23. require_once 'Zend/Gdata/App.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Gdata_App
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2014 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_App
  32. */
  33. class Zend_Gdata_App_ContentTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function setUp() {
  36. $this->contentText = file_get_contents(
  37. 'Zend/Gdata/App/_files/ContentElementSample1.xml',
  38. true);
  39. $this->contentText2 = file_get_contents(
  40. 'Zend/Gdata/App/_files/ContentElementSample2.xml',
  41. true);
  42. $this->content = new Zend_Gdata_App_Extension_Content();
  43. }
  44. public function testEmptyContentShouldHaveEmptyExtensionsList() {
  45. $this->assertTrue(is_array($this->content->extensionElements));
  46. $this->assertTrue(count($this->content->extensionElements) == 0);
  47. }
  48. public function testEmptyContentToAndFromStringShouldMatch() {
  49. $contentXml = $this->content->saveXML();
  50. $newContent = new Zend_Gdata_App_Extension_Content();
  51. $newContent->transferFromXML($contentXml);
  52. $newContentXml = $newContent->saveXML();
  53. $this->assertTrue($contentXml == $newContentXml);
  54. }
  55. public function testContentWithTextAndTypeToAndFromStringShouldMatch() {
  56. $this->content->text = '<img src="http://www.example.com/image.jpg"/>';
  57. $this->content->type = 'xhtml';
  58. $contentXml = $this->content->saveXML();
  59. $newContent = new Zend_Gdata_App_Extension_Content();
  60. $newContent->transferFromXML($contentXml);
  61. $newContentXml = $newContent->saveXML();
  62. $this->assertEquals($newContentXml, $contentXml);
  63. $this->assertEquals('<img src="http://www.example.com/image.jpg"/>', $newContent->text);
  64. $this->assertEquals('xhtml', $newContent->type);
  65. }
  66. public function testContentWithSrcAndTypeToAndFromStringShouldMatch() {
  67. $this->content->src = 'http://www.example.com/image.png';
  68. $this->content->type = 'image/png';
  69. $contentXml = $this->content->saveXML();
  70. $newContent = new Zend_Gdata_App_Extension_Content();
  71. $newContent->transferFromXML($contentXml);
  72. $newContentXml = $newContent->saveXML();
  73. $this->assertEquals($newContentXml, $contentXml);
  74. $this->assertEquals('http://www.example.com/image.png', $newContent->src);
  75. $this->assertEquals('image/png', $newContent->type);
  76. }
  77. public function testConvertContentWithSrcAndTypeToAndFromString() {
  78. $this->content->transferFromXML($this->contentText);
  79. $this->assertEquals('http://www.example.com/image.png', $this->content->src);
  80. $this->assertEquals('image/png', $this->content->type);
  81. }
  82. public function testConvertContentWithTextAndTypeToAndFromString() {
  83. $this->content->transferFromXML($this->contentText2);
  84. $this->assertEquals('xhtml', $this->content->type);
  85. $this->assertEquals(1, count($this->content->extensionElements));
  86. }
  87. }