ContentTest.php 3.6 KB

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