PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 38/**#@+ @ignore */
 39require_once 'PHPUnit/Framework.php';
 40require_once 'Zend/Media/Id3v2.php';
 41/**#@-*/
 42
 43/**
 44 * Unit test case for Zend_Media_Id3v2 class.
 45 *
 46 * @package    php-reader
 47 * @subpackage Tests
 48 * @author     Sven Vollbehr <svollbehr@gmail.com>
 49 * @copyright  Copyright (c) 2008 The PHP Reader Project Workgroup
 50 * @license    http://code.google.com/p/php-reader/wiki/License New BSD License
 51 * @version    $Id: TestID3v2.php 179 2010-03-09 14:36:37Z svollbehr $
 52 */
 53final class TestID3v2 extends PHPUnit_Framework_TestCase
 54{
 55  function testTagCreate()
 56  {
 57    $id3 = new Zend_Media_Id3v2();
 58
 59    $id3->tit2->text = 'Title 1';
 60    $this->assertEquals('Title 1',   $id3->tit2->text);
 61    $id3->tope->text = 'Artist 1';
 62    $this->assertEquals('Artist 1',  $id3->tope->text);
 63    $id3->talb->text = 'Album 1';
 64    $this->assertEquals('Album 1',   $id3->talb->text);
 65    $id3->tdrc->text = '2008';
 66    $this->assertEquals('2008',      $id3->tdrc->text);
 67    $id3->comm->text = 'Comment 1';
 68    $this->assertEquals('Comment 1', $id3->comm->text);
 69    $id3->trck->text = '11/13';
 70    $this->assertEquals('11/13',     $id3->trck->text);
 71    $id3->tcon->text = 'Classical';
 72    $this->assertEquals('Classical', $id3->tcon->text);
 73
 74    $id3->write('id3v2.tag');
 75  }
 76
 77  function testTagReadAfterCreate()
 78  {
 79    $id3 = new Zend_Media_Id3v2('id3v2.tag');
 80
 81    $this->assertEquals('Title 1',   $id3->tit2->text);
 82    $this->assertEquals('Artist 1',  $id3->tope->text);
 83    $this->assertEquals('Album 1',   $id3->talb->text);
 84    $this->assertEquals('2008',      $id3->tdrc->text);
 85    $this->assertEquals('Comment 1', $id3->comm->text);
 86    $this->assertEquals('11/13',     $id3->trck->text);
 87    $this->assertEquals('Classical', $id3->tcon->text);
 88  }
 89
 90  function testTagChange()
 91  {
 92    $id3 = new Zend_Media_Id3v2('id3v2.tag');
 93
 94    $id3->tit2->text = 'Title 2';
 95    $this->assertEquals('Title 2',   $id3->tit2->text);
 96    $id3->tope->text = 'Artist 2';
 97    $this->assertEquals('Artist 2',  $id3->tope->text);
 98    $id3->talb->text = 'Album 2';
 99    $this->assertEquals('Album 2',   $id3->talb->text);
100    $id3->tdrc->text = '2020';
101    $this->assertEquals('2020',      $id3->tdrc->text);
102    $id3->comm->text = 'Comment 2';
103    $this->assertEquals('Comment 2', $id3->comm->text);
104    $id3->trck->text = '13/13';
105    $this->assertEquals('13/13',     $id3->trck->text);
106    $id3->tcon->text = 'Trance';
107    $this->assertEquals('Trance',    $id3->tcon->text);
108
109    $id3->write(null);
110  }
111
112  function testTagReadAfterChange()
113  {
114    $id3 = new Zend_Media_Id3v2('id3v2.tag');
115
116    $this->assertEquals('Title 2',   $id3->tit2->text);
117    $this->assertEquals('Artist 2',  $id3->tope->text);
118    $this->assertEquals('Album 2',   $id3->talb->text);
119    $this->assertEquals('2020',      $id3->tdrc->text);
120    $this->assertEquals('Comment 2', $id3->comm->text);
121    $this->assertEquals('13/13',     $id3->trck->text);
122    $this->assertEquals('Trance',    $id3->tcon->text);
123  }
124
125  function testUnsynchronisation()
126  {
127    $id3 = new Zend_Media_Id3v2('id3v2.tag');
128    $id3->tit2->text = "\xff\xf0";
129    $id3->tcon->text = "\xff\xe0\xf0";
130
131    $id3->write(null);
132
133    $buffer = new Zend_Io_StringWriter();
134    $id3->tit2->write($buffer);
135    $this->assertEquals
136      ("TIT2\0\0\0\x08\0\x03\0\0\0\x03\x03\xff\x00\xf0", $buffer->toString());
137
138    $id3 = new Zend_Media_Id3v2('id3v2.tag');
139    $this->assertEquals("\xff\xf0",     $id3->tit2->text);
140    $this->assertEquals("\xff\xe0\xf0", $id3->tcon->text);
141  }
142}