/tests/TestID3v2.php

http://php-reader.googlecode.com/ · PHP · 142 lines · 80 code · 15 blank · 47 comment · 0 complexity · f77157fe776a7402885bca4a0dc5fb8b MD5 · raw file

  1. <?php
  2. /**
  3. * PHP Reader Library
  4. *
  5. * Copyright (c) 2008 The PHP Reader Project Workgroup. All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above copyright notice,
  13. * this list of conditions and the following disclaimer in the documentation
  14. * and/or other materials provided with the distribution.
  15. * - Neither the name of the project workgroup nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * @package php-reader
  32. * @subpackage Tests
  33. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  34. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  35. * @version $Id: TestID3v2.php 179 2010-03-09 14:36:37Z svollbehr $
  36. */
  37. /**#@+ @ignore */
  38. require_once 'PHPUnit/Framework.php';
  39. require_once 'Zend/Media/Id3v2.php';
  40. /**#@-*/
  41. /**
  42. * Unit test case for Zend_Media_Id3v2 class.
  43. *
  44. * @package php-reader
  45. * @subpackage Tests
  46. * @author Sven Vollbehr <svollbehr@gmail.com>
  47. * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
  48. * @license http://code.google.com/p/php-reader/wiki/License New BSD License
  49. * @version $Id: TestID3v2.php 179 2010-03-09 14:36:37Z svollbehr $
  50. */
  51. final class TestID3v2 extends PHPUnit_Framework_TestCase
  52. {
  53. function testTagCreate()
  54. {
  55. $id3 = new Zend_Media_Id3v2();
  56. $id3->tit2->text = 'Title 1';
  57. $this->assertEquals('Title 1', $id3->tit2->text);
  58. $id3->tope->text = 'Artist 1';
  59. $this->assertEquals('Artist 1', $id3->tope->text);
  60. $id3->talb->text = 'Album 1';
  61. $this->assertEquals('Album 1', $id3->talb->text);
  62. $id3->tdrc->text = '2008';
  63. $this->assertEquals('2008', $id3->tdrc->text);
  64. $id3->comm->text = 'Comment 1';
  65. $this->assertEquals('Comment 1', $id3->comm->text);
  66. $id3->trck->text = '11/13';
  67. $this->assertEquals('11/13', $id3->trck->text);
  68. $id3->tcon->text = 'Classical';
  69. $this->assertEquals('Classical', $id3->tcon->text);
  70. $id3->write('id3v2.tag');
  71. }
  72. function testTagReadAfterCreate()
  73. {
  74. $id3 = new Zend_Media_Id3v2('id3v2.tag');
  75. $this->assertEquals('Title 1', $id3->tit2->text);
  76. $this->assertEquals('Artist 1', $id3->tope->text);
  77. $this->assertEquals('Album 1', $id3->talb->text);
  78. $this->assertEquals('2008', $id3->tdrc->text);
  79. $this->assertEquals('Comment 1', $id3->comm->text);
  80. $this->assertEquals('11/13', $id3->trck->text);
  81. $this->assertEquals('Classical', $id3->tcon->text);
  82. }
  83. function testTagChange()
  84. {
  85. $id3 = new Zend_Media_Id3v2('id3v2.tag');
  86. $id3->tit2->text = 'Title 2';
  87. $this->assertEquals('Title 2', $id3->tit2->text);
  88. $id3->tope->text = 'Artist 2';
  89. $this->assertEquals('Artist 2', $id3->tope->text);
  90. $id3->talb->text = 'Album 2';
  91. $this->assertEquals('Album 2', $id3->talb->text);
  92. $id3->tdrc->text = '2020';
  93. $this->assertEquals('2020', $id3->tdrc->text);
  94. $id3->comm->text = 'Comment 2';
  95. $this->assertEquals('Comment 2', $id3->comm->text);
  96. $id3->trck->text = '13/13';
  97. $this->assertEquals('13/13', $id3->trck->text);
  98. $id3->tcon->text = 'Trance';
  99. $this->assertEquals('Trance', $id3->tcon->text);
  100. $id3->write(null);
  101. }
  102. function testTagReadAfterChange()
  103. {
  104. $id3 = new Zend_Media_Id3v2('id3v2.tag');
  105. $this->assertEquals('Title 2', $id3->tit2->text);
  106. $this->assertEquals('Artist 2', $id3->tope->text);
  107. $this->assertEquals('Album 2', $id3->talb->text);
  108. $this->assertEquals('2020', $id3->tdrc->text);
  109. $this->assertEquals('Comment 2', $id3->comm->text);
  110. $this->assertEquals('13/13', $id3->trck->text);
  111. $this->assertEquals('Trance', $id3->tcon->text);
  112. }
  113. function testUnsynchronisation()
  114. {
  115. $id3 = new Zend_Media_Id3v2('id3v2.tag');
  116. $id3->tit2->text = "\xff\xf0";
  117. $id3->tcon->text = "\xff\xe0\xf0";
  118. $id3->write(null);
  119. $buffer = new Zend_Io_StringWriter();
  120. $id3->tit2->write($buffer);
  121. $this->assertEquals
  122. ("TIT2\0\0\0\x08\0\x03\0\0\0\x03\x03\xff\x00\xf0", $buffer->toString());
  123. $id3 = new Zend_Media_Id3v2('id3v2.tag');
  124. $this->assertEquals("\xff\xf0", $id3->tit2->text);
  125. $this->assertEquals("\xff\xe0\xf0", $id3->tcon->text);
  126. }
  127. }