PageRenderTime 50ms CodeModel.GetById 6ms app.highlight 31ms RepoModel.GetById 4ms app.codeStats 0ms

/tests/TestID3Frame.php

http://php-reader.googlecode.com/
PHP | 1231 lines | 732 code | 86 blank | 413 comment | 138 complexity | e8c41e55ea6bf5a2bba7ba271922325f 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: TestID3Frame.php 179 2010-03-09 14:36:37Z svollbehr $
  36 */
  37
  38/**#@+ @ignore */
  39require_once 'PHPUnit/Framework.php';
  40require_once 'Zend/Io/Reader.php';
  41/**#@-*/
  42
  43/**
  44 * Unit test case for all ID3 frames.
  45 *
  46 * @package    php-reader
  47 * @subpackage Tests
  48 * @author     Ryan Butterfield <buttza@gmail.com>
  49 * @author     Sven Vollbehr <svollbehr@gmail.com>
  50 * @copyright  Copyright (c) 2008 The PHP Reader Project Workgroup
  51 * @license    http://code.google.com/p/php-reader/wiki/License New BSD License
  52 * @version    $Id: TestID3Frame.php 179 2010-03-09 14:36:37Z svollbehr $
  53 */
  54final class TestID3Frame extends PHPUnit_Framework_TestCase
  55{
  56  const INITIALIZE = 1;
  57  const DRYRUN = 2;
  58  const RUN = 3;
  59
  60  private $testText = "abcdefghijklmnopqrstuvwxyzедц1234567890!@#\$%^&*()-";
  61  private $testLink = 'http://www.abcdefghijklmnopqrstuvwxyz.com.xyz/qwerty.php?asdf=1234&zxcv=%20';
  62  private $testDate = '20070707';
  63  private $testCurrency = 'AUD';
  64  private $testIdentifier = 'TEST';
  65  private $testPrice = '169.12';
  66  private $testInt8 = -0x7a;
  67  private $testInt16 = -0x7aff;
  68  private $testInt24 = 0x7affca;
  69  private $testInt32 = -0x7affcafe;
  70  private $testUInt8 = 0xfa;
  71  private $testUInt16 = 0xfaff;
  72  private $testUInt32 = 0xfaffcafe;
  73
  74  /**
  75   * Data provider for the ID3 frame test case. Finds all frames and builds
  76   * input combinations necessary to test all variations of each frame.
  77   */
  78  public static function provider()
  79  {
  80    /* Ignore WIP frames */
  81    $ignore = array('Aspi.php', 'Mllt.php');
  82
  83    /* Load all frames */
  84    $dir = opendir('../src/Zend/Media/Id3/Frame');
  85    while (($file = readdir($dir)) !== false)
  86      if (preg_match("/^.+\.php$/", $file) && !in_array($file, $ignore))
  87        require_once('Zend/Media/Id3/Frame/' . $file);
  88    foreach (get_declared_classes() as $class)
  89      if (strpos($class, "Zend_Media_Id3_Frame_") === 0)
  90        $identifiers[] = substr($class, 10);
  91    closedir($dir);
  92
  93    /* Build up all valid combinations */
  94    $tests = array();
  95    foreach ($identifiers as $identifier)
  96    {
  97      if (!method_exists('TestID3Frame', 'frame' . $identifier . '0'))
  98        continue; // skip if no handlers registered
  99
 100      $class = 'Zend_Media_Id3_Frame_' . $identifier;
 101      $encodings = $languages = $timings = array(null);
 102      if (in_array('Zend_Media_Id3_Encoding', class_implements($class)))
 103        array_push($encodings, Zend_Media_Id3_Encoding::ISO88591,
 104            Zend_Media_Id3_Encoding::UTF16, Zend_Media_Id3_Encoding::UTF16BE,
 105            Zend_Media_Id3_Encoding::UTF8);
 106      if (in_array('Zend_Media_Id3_Language', class_implements($class)))
 107        array_push($languages, 'eng', 'und');
 108      if (in_array('Zend_Media_Id3_Timing', class_implements($class)))
 109        array_push($timings, Zend_Media_Id3_Timing::MPEG_FRAMES,
 110            Zend_Media_Id3_Timing::MILLISECONDS);
 111
 112      foreach ($encodings as $encoding)
 113        foreach ($languages as $language)
 114          foreach ($timings as $timing)
 115            $tests[] = array($identifier, $encoding, $language, $timing);
 116    }
 117
 118    return $tests;
 119  }
 120
 121  /**
 122   * Test a given frame by identifier, its text encoding (if provided),
 123   * its language (if provided) and its timing (also if provided).
 124   *
 125   * The test involves finding frame functions that will test the given frame
 126   * identifier, constructing and setting up the frame, testing the constructed
 127   * frame, saving the frame to a string then re-creating the frame using the
 128   * string and testing for a final time.
 129   *
 130   * @param string $identifier The frame identifier.
 131   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding}
 132   *        for strings in this frame.
 133   * @param string $language The language code.
 134   * @param integer $timing The timing format.
 135   *
 136   * @dataProvider provider
 137   */
 138  public function testFrame($identifier, $encoding, $language, $timing)
 139  {
 140    /* Iterate through all test case functions for this frame identifier */
 141    $class = 'Zend_Media_Id3_Frame_' . $identifier;
 142    $test = 0;
 143    while (method_exists($this, $method = "frame" . $identifier . $test++)) {
 144
 145      /* Setup and verify the frame */
 146      $frame = new $class();
 147      call_user_func(array($this, $method),
 148        $frame, self::INITIALIZE, $encoding, $language, $timing);
 149      call_user_func(array($this, $method),
 150        $frame, self::DRYRUN, $encoding, $language, $timing);
 151
 152      if (isset($encoding)) {
 153        $this->assertTrue(method_exists($frame, 'setEncoding'));
 154        $frame->setEncoding($encoding);
 155        $this->assertTrue(method_exists($frame, 'getEncoding'));
 156        $this->assertEquals($encoding, $frame->getEncoding());
 157      }
 158      if (isset($language)) {
 159        $this->assertTrue(method_exists($frame, 'setLanguage'));
 160        $frame->setLanguage($language);
 161        $this->assertTrue(method_exists($frame, 'getLanguage'));
 162        $this->assertEquals($language, $frame->getLanguage());
 163      }
 164      if (isset($timing)) {
 165        $this->assertTrue(method_exists($frame, 'setFormat'));
 166        $frame->setFormat($timing);
 167        $this->assertTrue(method_exists($frame, 'getFormat'));
 168        $this->assertEquals($timing, $frame->getFormat());
 169      }
 170
 171      for ($i = 0; $i < 2; $i++) {
 172        /* Convert to string representation and store in an in-memory buffer */
 173        if ($i > 0)
 174          $existing = $data;
 175        $length = strlen($data = '' . $frame);
 176        $this->assertTrue(($fd = fopen('php://temp', 'r+b')) !== false);
 177        $this->assertEquals($length, fwrite($fd, $data, $length));
 178        $this->assertTrue(rewind($fd));
 179
 180        /* Construct a frame using the reader and verify */
 181        $frame = new $class($reader = new Zend_Io_Reader($fd));
 182        call_user_func(array($this, $method),
 183          $frame, self::RUN, $encoding, $language, $timing);
 184        if (isset($language))
 185          $this->assertEquals($language, $frame->getLanguage());
 186        if (isset($timing))
 187          $this->assertEquals($timing, $frame->getFormat());
 188      }
 189    }
 190  }
 191
 192  /**
 193   * The first AENC frame test.
 194   *
 195   * @param Zend_Media_Id3_Frame_AENC $frame The frame to test.
 196   * @param boolean $action The requested action.
 197   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 198   *        in this frame.
 199   * @param string $language The language code.
 200   * @param integer $timing The timing format.
 201   */
 202  private function frameAENC0
 203      (&$frame, $action, $encoding, $language, $timing)
 204  {
 205    $owner = $this->testText;
 206    $previewStart = $this->testUInt16;
 207    $previewLength = $this->testUInt16 - 1;
 208    $encryptionInfo = $this->testText;
 209
 210    if ($action == self::INITIALIZE) {
 211      $frame->setOwner($owner);
 212      $frame->setPreviewStart($previewStart);
 213      $frame->setPreviewLength($previewLength);
 214      $frame->setEncryptionInfo($encryptionInfo);
 215    } else {
 216      $this->assertEquals($owner, $frame->getOwner());
 217      $this->assertEquals($previewStart, $frame->getPreviewStart());
 218      $this->assertEquals($previewLength, $frame->getPreviewLength());
 219      $this->assertEquals($encryptionInfo, $frame->getEncryptionInfo());
 220    }
 221  }
 222
 223  /**
 224   * The first APIC frame test.
 225   *
 226   * @param Zend_Media_Id3_Frame_APIC $frame The frame to test.
 227   * @param boolean $action The requested action.
 228   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 229   *        in this frame.
 230   * @param string $language The language code.
 231   * @param integer $timing The timing format.
 232   */
 233  private function frameAPIC0
 234      (&$frame, $action, $encoding, $language, $timing)
 235  {
 236    $mimeType = $this->testText;
 237    $imageType = $this->testUInt8;
 238    $description = $this->convert($this->testText, $encoding);
 239    $imageData = $this->testText;
 240    $imageSize = strlen($imageData);
 241
 242    if ($action == self::INITIALIZE) {
 243      $frame->setMimeType($mimeType);
 244      $frame->setImageType($imageType);
 245      $frame->setDescription($description);
 246      $frame->setImageData($imageData);
 247    } else {
 248      $this->assertEquals($mimeType, $frame->getMimeType());
 249      $this->assertEquals($imageType, $frame->getImageType());
 250      if ($action == self::DRYRUN)
 251        $this->assertEquals($description, $frame->getDescription());
 252      else
 253        $this->assertEquals($this->testText, $frame->getDescription());
 254      $this->assertEquals($imageData, $frame->getImageData());
 255      $this->assertEquals($imageSize, $frame->getImageSize());
 256    }
 257  }
 258
 259  /**
 260   * The first COMM frame test.
 261   *
 262   * @param Zend_Media_Id3_Frame_COMM $frame The frame to test.
 263   * @param boolean $action The requested action.
 264   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 265   *        in this frame.
 266   * @param string $language The language code.
 267   * @param integer $timing The timing format.
 268   */
 269  private function frameCOMM0
 270      (&$frame, $action, $encoding, $language, $timing)
 271  {
 272    $description = $this->convert($this->testText, $encoding);
 273    $text = $this->convert($this->testText, $encoding);
 274
 275    if ($action == self::INITIALIZE) {
 276      $frame->setDescription($description);
 277      $frame->setText($text);
 278    } else {
 279      if ($action == self::DRYRUN) {
 280        $this->assertEquals($description, $frame->getDescription());
 281        $this->assertEquals($text, $frame->getText());
 282      } else {
 283        $this->assertEquals($this->testText, $frame->getDescription());
 284        $this->assertEquals($this->testText, $frame->getText());
 285      }
 286    }
 287  }
 288
 289  /**
 290   * The first COMR frame test.
 291   *
 292   * @param Zend_Media_Id3_Frame_COMR $frame The frame to test.
 293   * @param boolean $action The requested action.
 294   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 295   *        in this frame.
 296   * @param string $language The language code.
 297   * @param integer $timing The timing format.
 298   */
 299  private function frameCOMR0
 300      (&$frame, $action, $encoding, $language, $timing)
 301  {
 302    $currency = $this->testCurrency;
 303    $price = $this->testText;
 304    $date = $this->testDate;
 305    $contact = $this->testLink;
 306    $delivery = $this->testUInt8;
 307    $seller = $this->convert($this->testText, $encoding);
 308    $description = $this->convert($this->testText, $encoding);
 309    $mimeType = $this->testText;
 310    $imageData = $this->testText;
 311    $imageSize = strlen($imageData);
 312
 313    if ($action == self::INITIALIZE) {
 314      $frame->setCurrency($currency);
 315      $frame->setPrice($price);
 316      $frame->setDate($date);
 317      $frame->setContact($contact);
 318      $frame->setDelivery($delivery);
 319      $frame->setSeller($seller);
 320      $frame->setDescription($description);
 321      $frame->setMimeType($mimeType);
 322      $frame->setImageData($imageData);
 323    } else {
 324      $this->assertEquals($currency, $frame->getCurrency());
 325      $this->assertEquals($price, $frame->getPrice());
 326      $this->assertEquals($date, $frame->getDate());
 327      $this->assertEquals($contact, $frame->getContact());
 328      $this->assertEquals($delivery, $frame->getDelivery());
 329      if ($action == self::DRYRUN) {
 330        $this->assertEquals($seller, $frame->getSeller());
 331        $this->assertEquals($description, $frame->getDescription());
 332      } else {
 333        $this->assertEquals($this->testText, $frame->getSeller());
 334        $this->assertEquals($this->testText, $frame->getDescription());
 335      }
 336      $this->assertEquals($mimeType, $frame->getMimeType());
 337      $this->assertEquals($imageData, $frame->getImageData());
 338      $this->assertEquals($imageSize, $frame->getImageSize());
 339    }
 340  }
 341
 342  /**
 343   * The first ENCR frame test.
 344   *
 345   * @param Zend_Media_Id3_Frame_ENCR $frame The frame to test.
 346   * @param boolean $action The requested action.
 347   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 348   *        in this frame.
 349   * @param string $language The language code.
 350   * @param integer $timing The timing format.
 351   */
 352  private function frameENCR0
 353      (&$frame, $action, $encoding, $language, $timing)
 354  {
 355    $owner = $this->testLink;
 356    $method = $this->testInt8;
 357    $encryptionData = $this->testText;
 358
 359    if ($action == self::INITIALIZE) {
 360      $frame->setOwner($owner);
 361      $frame->setMethod($method);
 362      $frame->setEncryptionData($encryptionData);
 363    } else {
 364      $this->assertEquals($owner, $frame->getOwner());
 365      $this->assertEquals($method, $frame->getMethod());
 366      $this->assertEquals($encryptionData, $frame->getEncryptionData());
 367    }
 368  }
 369
 370  /**
 371   * The first EQU2 frame test.
 372   *
 373   * @param Zend_Media_Id3_Frame_EQU2 $frame The frame to test.
 374   * @param boolean $action The requested action.
 375   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 376   *        in this frame.
 377   * @param string $language The language code.
 378   * @param integer $timing The timing format.
 379   */
 380  private function frameEQU20
 381      (&$frame, $action, $encoding, $language, $timing)
 382  {
 383    $interpolation = $this->testInt8;
 384    $device = $this->testText;
 385    $adjustments[0] = -32767.0 / 512.0;
 386    $adjustments[2047] = -1.0;
 387    $adjustments[8191] = 0.0;
 388    $adjustments[16383] = 1.0;
 389    $adjustments[32767] = 32767.0 / 512.0;
 390
 391    if ($action == self::INITIALIZE) {
 392      foreach ($adjustments as $frequency => $adjustment)
 393        $frame->addAdjustment($frequency, $adjustment);
 394      $this->assertEquals($adjustments, $frame->getAdjustments());
 395
 396      $frame->setInterpolation($interpolation);
 397      $frame->setDevice($device);
 398      $frame->setAdjustments($adjustments);
 399    } else {
 400      $this->assertEquals($interpolation, $frame->getInterpolation());
 401      $this->assertEquals($device, $frame->getDevice());
 402      $this->assertEquals($adjustments, $frame->getAdjustments());
 403    }
 404  }
 405
 406  /**
 407   * The first EQUA frame test.
 408   *
 409   * @param Zend_Media_Id3_Frame_EQUA $frame The frame to test.
 410   * @param boolean $action The requested action.
 411   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 412   *        in this frame.
 413   * @param string $language The language code.
 414   * @param integer $timing The timing format.
 415   */
 416  private function frameEQUA0
 417      (&$frame, $action, $encoding, $language, $timing)
 418  {
 419    $adjustments[0] = -65535;
 420    $adjustments[2047] = -4096;
 421    $adjustments[8191] = 0;
 422    $adjustments[16383] = 4096;
 423    $adjustments[32767] = 65535;
 424
 425    if ($action == self::INITIALIZE) {
 426      foreach ($adjustments as $frequency => $adjustment)
 427        $frame->addAdjustment($frequency, $adjustment);
 428      $this->assertEquals($adjustments, $frame->getAdjustments());
 429
 430      $frame->setAdjustments($adjustments);
 431    } else {
 432      $this->assertEquals($adjustments, $frame->getAdjustments());
 433    }
 434  }
 435
 436  /**
 437   * The first ETCO frame test.
 438   *
 439   * @param Zend_Media_Id3_Frame_ETCO $frame The frame to test.
 440   * @param boolean $action The requested action.
 441   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 442   *        in this frame.
 443   * @param string $language The language code.
 444   * @param integer $timing The timing format.
 445   */
 446  private function frameETCO0
 447      (&$frame, $action, $encoding, $language, $timing)
 448  {
 449    $events[0] = array_search('Intro end', Zend_Media_Id3_Frame_ETCO::$types);
 450    $events[0xFFFF] = array_search('Verse start', Zend_Media_Id3_Frame_ETCO::$types);
 451    $events[0xFFFFF] = array_search('Verse end', Zend_Media_Id3_Frame_ETCO::$types);
 452    $events[0xFFFFFF] = array_search
 453      ('Audio end (start of silence)', Zend_Media_Id3_Frame_ETCO::$types);
 454    $events[0xFFFFFFFF] = array_search
 455      ('Audio file ends', Zend_Media_Id3_Frame_ETCO::$types);
 456
 457    if ($action == self::INITIALIZE)
 458      $frame->setEvents($events);
 459    else
 460      $this->assertEquals($events, $frame->getEvents());
 461  }
 462
 463  /**
 464   * The first GEOB frame test.
 465   *
 466   * @param Zend_Media_Id3_Frame_GEOB $frame The frame to test.
 467   * @param boolean $action The requested action.
 468   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 469   *        in this frame.
 470   * @param string $language The language code.
 471   * @param integer $timing The timing format.
 472   */
 473  private function frameGEOB0
 474      (&$frame, $action, $encoding, $language, $timing)
 475  {
 476    $mimeType = $this->testText;
 477    $filename = $this->convert($this->testText, $encoding);
 478    $description = $this->convert($this->testText, $encoding);
 479    $objectData = $this->testText;
 480
 481    if ($action == self::INITIALIZE) {
 482      $frame->setMimeType($mimeType);
 483      $frame->setFilename($filename);
 484      $frame->setDescription($description);
 485      $frame->setObjectData($objectData);
 486    } else {
 487      $this->assertEquals($mimeType, $frame->getMimeType());
 488      if ($action == self::DRYRUN) {
 489        $this->assertEquals($filename, $frame->getFilename());
 490        $this->assertEquals($description, $frame->getDescription());
 491      } else {
 492        $this->assertEquals($this->testText, $frame->getFilename());
 493        $this->assertEquals($this->testText, $frame->getDescription());
 494      }
 495      $this->assertEquals($objectData, $frame->getObjectData());
 496    }
 497  }
 498
 499  /**
 500   * The first GRID frame test.
 501   *
 502   * @param Zend_Media_Id3_Frame_GRID $frame The frame to test.
 503   * @param boolean $action The requested action.
 504   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 505   *        in this frame.
 506   * @param string $language The language code.
 507   * @param integer $timing The timing format.
 508   */
 509  private function frameGRID0
 510      (&$frame, $action, $encoding, $language, $timing)
 511  {
 512    $owner = $this->testLink;
 513    $group = $this->testUInt8;
 514    $groupData = $this->testText;
 515
 516    if ($action == self::INITIALIZE) {
 517      $frame->setOwner($owner);
 518      $frame->setGroup($group);
 519      $frame->setGroupData($groupData);
 520    } else {
 521      $this->assertEquals($owner, $frame->getOwner());
 522      $this->assertEquals($group, $frame->getGroup());
 523      $this->assertEquals($groupData, $frame->getGroupData());
 524    }
 525  }
 526
 527  /**
 528   * The first IPLS frame test.
 529   *
 530   * @param Zend_Media_Id3_Frame_IPLS $frame The frame to test.
 531   * @param boolean $action The requested action.
 532   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 533   *        in this frame.
 534   * @param string $language The language code.
 535   * @param integer $timing The timing format.
 536   */
 537  private function frameIPLS0
 538      (&$frame, $action, $encoding, $language, $timing)
 539  {
 540    $testText = $this->convert($this->testText, $encoding);
 541    for ($i = 0; $i < 3; $i++) {
 542      $convertedPeople[] = array($testText => $testText);
 543      $originalPeople[] = array($this->testText => $this->testText);
 544    }
 545
 546    if ($action == self::INITIALIZE) {
 547      foreach ($convertedPeople as $entry)
 548        foreach ($entry as $involvement => $person)
 549          $frame->addPerson($involvement, $person);
 550      $this->assertEquals($convertedPeople, $frame->getPeople());
 551
 552      $frame->setPeople($convertedPeople);
 553    } else {
 554      if ($action == self::DRYRUN)
 555        $this->assertEquals($convertedPeople, $frame->getPeople());
 556      else
 557        $this->assertEquals($originalPeople, $frame->getPeople());
 558    }
 559  }
 560
 561  /**
 562   * The first LINK frame test.
 563   *
 564   * @param Zend_Media_Id3_Frame_LINK $frame The frame to test.
 565   * @param boolean $action The requested action.
 566   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 567   *        in this frame.
 568   * @param string $language The language code.
 569   * @param integer $timing The timing format.
 570   */
 571  private function frameLINK0
 572      (&$frame, $action, $encoding, $language, $timing)
 573  {
 574    $target = $this->testIdentifier;
 575    $url = $this->testLink;
 576    $qualifier = $this->testText;
 577
 578    if ($action == self::INITIALIZE) {
 579      $frame->setTarget($target);
 580      $frame->setUrl($url);
 581      $frame->setQualifier($qualifier);
 582    } else {
 583      $this->assertEquals($target, $frame->getTarget());
 584      $this->assertEquals($url, $frame->getUrl());
 585      $this->assertEquals($qualifier, $frame->getQualifier());
 586    }
 587  }
 588
 589  /**
 590   * The first MCDI frame test.
 591   *
 592   * @param Zend_Media_Id3_Frame_MCDI $frame The frame to test.
 593   * @param boolean $action The requested action.
 594   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 595   *        in this frame.
 596   * @param string $language The language code.
 597   * @param integer $timing The timing format.
 598   */
 599  private function frameMCDI0
 600      (&$frame, $action, $encoding, $language, $timing)
 601  {
 602    $data = $this->testText;
 603
 604    if ($action == self::INITIALIZE)
 605      $frame->setData($data);
 606    else
 607      $this->assertEquals($data, $frame->getData());
 608  }
 609
 610  /**
 611   * The first OWNE frame test.
 612   *
 613   * @param Zend_Media_Id3_Frame_OWNE $frame The frame to test.
 614   * @param boolean $action The requested action.
 615   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 616   *        in this frame.
 617   * @param string $language The language code.
 618   * @param integer $timing The timing format.
 619   */
 620  private function frameOWNE0
 621      (&$frame, $action, $encoding, $language, $timing)
 622  {
 623    $currency = $this->testCurrency;
 624    $price = $this->testPrice;
 625    $date = $this->testDate;
 626    $seller = $this->convert($this->testText, $encoding);
 627
 628    if ($action == self::INITIALIZE) {
 629      $frame->setCurrency($currency);
 630      $frame->setPrice(0.0 + $price);
 631      $frame->setDate($date);
 632      $frame->setSeller($seller);
 633    } else {
 634      $this->assertEquals($currency, $frame->getCurrency());
 635      $this->assertEquals($price, $frame->getPrice());
 636      $this->assertEquals($date, $frame->getDate());
 637      if ($action == self::DRYRUN)
 638        $this->assertEquals($seller, $frame->getSeller());
 639      else
 640        $this->assertEquals($this->testText, $frame->getSeller());
 641    }
 642  }
 643
 644  /**
 645   * The first PCNT frame test.
 646   *
 647   * @param Zend_Media_Id3_Frame_PCNT $frame The frame to test.
 648   * @param boolean $action The requested action.
 649   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 650   *        in this frame.
 651   * @param string $language The language code.
 652   * @param integer $timing The timing format.
 653   */
 654  private function framePCNT0
 655      (&$frame, $action, $encoding, $language, $timing)
 656  {
 657    $counter = $this->testUInt32;
 658
 659    if ($action == self::INITIALIZE) {
 660      for ($i = 0; $i < 123; $i++)
 661        $frame->addCounter();
 662      $this->assertEquals(123, $frame->getCounter());
 663
 664      $frame->setCounter($counter);
 665    } else {
 666      $this->assertEquals($counter, $frame->getCounter());
 667    }
 668  }
 669
 670  /**
 671   * The first POPM frame test.
 672   *
 673   * @param Zend_Media_Id3_Frame_POPM $frame The frame to test.
 674   * @param boolean $action The requested action.
 675   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 676   *        in this frame.
 677   * @param string $language The language code.
 678   * @param integer $timing The timing format.
 679   */
 680  private function framePOPM0
 681      (&$frame, $action, $encoding, $language, $timing)
 682  {
 683    $owner = $this->testLink;
 684    $rating = $this->testUInt8;
 685    $counter = $this->testUInt32;
 686
 687    if ($action == self::INITIALIZE) {
 688      $frame->setOwner($owner);
 689      $frame->setRating($rating);
 690      $frame->setCounter($counter);
 691    } else {
 692      $this->assertEquals($owner, $frame->getOwner());
 693      $this->assertEquals($rating, $frame->getRating());
 694      $this->assertEquals($counter, $frame->getCounter());
 695    }
 696  }
 697
 698  /**
 699   * The first POSS frame test.
 700   *
 701   * @param Zend_Media_Id3_Frame_POSS $frame The frame to test.
 702   * @param boolean $action The requested action.
 703   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 704   *        in this frame.
 705   * @param string $language The language code.
 706   * @param integer $timing The timing format.
 707   */
 708  private function framePOSS0
 709      (&$frame, $action, $encoding, $language, $timing)
 710  {
 711    $position = $this->testUInt32;
 712
 713    if ($action == self::INITIALIZE)
 714      $frame->setPosition($position);
 715    else
 716      $this->assertEquals($position, $frame->getPosition());
 717  }
 718
 719  /**
 720   * The first PRIV frame test.
 721   *
 722   * @param Zend_Media_Id3_Frame_PRIV $frame The frame to test.
 723   * @param boolean $action The requested action.
 724   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 725   *        in this frame.
 726   * @param string $language The language code.
 727   * @param integer $timing The timing format.
 728   */
 729  private function framePRIV0
 730      (&$frame, $action, $encoding, $language, $timing)
 731  {
 732    $owner = $this->testText;
 733    $privateData = $this->testText;
 734
 735    if ($action == self::INITIALIZE) {
 736      $frame->setOwner($owner);
 737      $frame->setPrivateData($privateData);
 738    } else {
 739      $this->assertEquals($owner, $frame->getOwner());
 740      $this->assertEquals($privateData, $frame->getPrivateData());
 741    }
 742  }
 743
 744  /**
 745   * The first RBUF frame test.
 746   *
 747   * @param Zend_Media_Id3_Frame_RBUF $frame The frame to test.
 748   * @param boolean $action The requested action.
 749   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 750   *        in this frame.
 751   * @param string $language The language code.
 752   * @param integer $timing The timing format.
 753   */
 754  private function frameRBUF0
 755      (&$frame, $action, $encoding, $language, $timing)
 756  {
 757    $bufferSize = $this->testInt24;
 758    $flags = $this->testInt8;
 759    $offset = $this->testInt32;
 760
 761    if ($action == self::INITIALIZE) {
 762      $frame->setBufferSize($bufferSize);
 763      $frame->setInfoFlags($flags);
 764      $frame->setOffset($offset);
 765    } else {
 766      $this->assertEquals($bufferSize, $frame->getBufferSize());
 767      $this->assertEquals($flags, $frame->getInfoFlags());
 768      $this->assertEquals($offset, $frame->getOffset());
 769    }
 770  }
 771
 772  /**
 773   * The first RVA2 frame test.
 774   *
 775   * @param Zend_Media_Id3_Frame_RVA2 $frame The frame to test.
 776   * @param boolean $action The requested action.
 777   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 778   *        in this frame.
 779   * @param string $language The language code.
 780   * @param integer $timing The timing format.
 781   */
 782  private function frameRVA20
 783      (&$frame, $action, $encoding, $language, $timing)
 784  {
 785    $device = $this->testText;
 786    $adjustments[0] = array(Zend_Media_Id3_Frame_RVA2::channelType => 0,
 787      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -32767.0 / 512.0,
 788      Zend_Media_Id3_Frame_RVA2::peakVolume => 0x0);
 789    $adjustments[1] = array(Zend_Media_Id3_Frame_RVA2::channelType => 1,
 790      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -8191.0 / 512.0,
 791      Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7f);
 792    $adjustments[2] = array(Zend_Media_Id3_Frame_RVA2::channelType => 2,
 793      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -2047.0 / 512.0,
 794      Zend_Media_Id3_Frame_RVA2::peakVolume => 0xff);
 795    $adjustments[3] = array(Zend_Media_Id3_Frame_RVA2::channelType => 3,
 796      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => -1.0,
 797      Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fff);
 798    $adjustments[4] = array(Zend_Media_Id3_Frame_RVA2::channelType => 4,
 799      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 0.0,
 800      Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffff);
 801    $adjustments[5] = array(Zend_Media_Id3_Frame_RVA2::channelType => 5,
 802      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 1.0,
 803      Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fffff);
 804    $adjustments[6] = array(Zend_Media_Id3_Frame_RVA2::channelType => 6,
 805      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 2047.0 / 512.0,
 806      Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffffff);
 807    $adjustments[7] = array(Zend_Media_Id3_Frame_RVA2::channelType => 7,
 808      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 8191.0 / 512.0,
 809      Zend_Media_Id3_Frame_RVA2::peakVolume => 0x7fffffff);
 810    $adjustments[8] = array(Zend_Media_Id3_Frame_RVA2::channelType => 8,
 811      Zend_Media_Id3_Frame_RVA2::volumeAdjustment => 32767.0 / 512.0,
 812      Zend_Media_Id3_Frame_RVA2::peakVolume => 0xffffffff);
 813
 814    if ($action == self::INITIALIZE) {
 815      $frame->setDevice($device);
 816      $frame->setAdjustments($adjustments);
 817    } else {
 818      $this->assertEquals($device, $frame->getDevice());
 819      $this->assertEquals($adjustments, $frame->getAdjustments());
 820    }
 821  }
 822
 823  /**
 824   * The first RVAD frame test.
 825   *
 826   * @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
 827   * @param boolean $action The requested action.
 828   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 829   *        in this frame.
 830   * @param string $language The language code.
 831   * @param integer $timing The timing format.
 832   */
 833  private function frameRVAD0
 834      (&$frame, $action, $encoding, $language, $timing)
 835  {
 836    $adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
 837    $adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
 838    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
 839    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
 840
 841    if ($action == self::INITIALIZE)
 842      $frame->setAdjustments($adjustments);
 843    else
 844      $this->assertEquals($adjustments, $frame->getAdjustments());
 845  }
 846
 847  /**
 848   * The second RVAD frame test.
 849   *
 850   * @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
 851   * @param boolean $action The requested action.
 852   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 853   *        in this frame.
 854   * @param string $language The language code.
 855   * @param integer $timing The timing format.
 856   */
 857  private function frameRVAD1
 858      (&$frame, $action, $encoding, $language, $timing)
 859  {
 860    $adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
 861    $adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
 862    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
 863    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
 864    $adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
 865    $adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
 866    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
 867    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
 868
 869    if ($action == self::INITIALIZE)
 870      $frame->setAdjustments($adjustments);
 871    else
 872      $this->assertEquals($adjustments, $frame->getAdjustments());
 873  }
 874
 875  /**
 876   * The third RVAD frame test.
 877   *
 878   * @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
 879   * @param boolean $action The requested action.
 880   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 881   *        in this frame.
 882   * @param string $language The language code.
 883   * @param integer $timing The timing format.
 884   */
 885  private function frameRVAD2
 886      (&$frame, $action, $encoding, $language, $timing)
 887  {
 888    $adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
 889    $adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
 890    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
 891    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
 892    $adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
 893    $adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
 894    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
 895    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
 896    $adjustments[Zend_Media_Id3_Frame_RVAD::center] = 0xf;
 897    $adjustments[Zend_Media_Id3_Frame_RVAD::peakCenter] = 0x7;
 898
 899    if ($action == self::INITIALIZE)
 900      $frame->setAdjustments($adjustments);
 901    else
 902      $this->assertEquals($adjustments, $frame->getAdjustments());
 903  }
 904
 905  /**
 906   * The fourth RVAD frame test.
 907   *
 908   * @param Zend_Media_Id3_Frame_RVAD $frame The frame to test.
 909   * @param boolean $action The requested action.
 910   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 911   *        in this frame.
 912   * @param string $language The language code.
 913   * @param integer $timing The timing format.
 914   */
 915  private function frameRVAD3
 916      (&$frame, $action, $encoding, $language, $timing)
 917  {
 918    $adjustments[Zend_Media_Id3_Frame_RVAD::right] = -0xffff;
 919    $adjustments[Zend_Media_Id3_Frame_RVAD::left] = 0xffff;
 920    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRight] = 0xffff;
 921    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeft] = 0xfff;
 922    $adjustments[Zend_Media_Id3_Frame_RVAD::rightBack] = -0xff;
 923    $adjustments[Zend_Media_Id3_Frame_RVAD::leftBack] = 0xff;
 924    $adjustments[Zend_Media_Id3_Frame_RVAD::peakRightBack] = 0xff;
 925    $adjustments[Zend_Media_Id3_Frame_RVAD::peakLeftBack] = 0xf;
 926    $adjustments[Zend_Media_Id3_Frame_RVAD::center] = 0xf;
 927    $adjustments[Zend_Media_Id3_Frame_RVAD::peakCenter] = 0x7;
 928    $adjustments[Zend_Media_Id3_Frame_RVAD::bass] = 0x0;
 929    $adjustments[Zend_Media_Id3_Frame_RVAD::peakBass] = 0x0;
 930
 931    if ($action == self::INITIALIZE)
 932      $frame->setAdjustments($adjustments);
 933    else
 934      $this->assertEquals($adjustments, $frame->getAdjustments());
 935  }
 936
 937  /**
 938   * The first RVRB frame test.
 939   *
 940   * @param Zend_Media_Id3_Frame_RVRB $frame The frame to test.
 941   * @param boolean $action The requested action.
 942   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 943   *        in this frame.
 944   * @param string $language The language code.
 945   * @param integer $timing The timing format.
 946   */
 947  private function frameRVRB0
 948      (&$frame, $action, $encoding, $language, $timing)
 949  {
 950    $reverbLeft = $this->testUInt16;
 951    $reverbRight = $this->testUInt16 - 1;
 952    $reverbBouncesLeft = $this->testUInt8;
 953    $reverbBouncesRight = $this->testUInt8 - 1;
 954    $reverbFeedbackLtoL = $this->testUInt8 - 2;
 955    $reverbFeedbackLtoR = $this->testUInt8 - 3;
 956    $reverbFeedbackRtoR = $this->testUInt8 - 4;
 957    $reverbFeedbackRtoL = $this->testUInt8 - 5;
 958    $premixLtoR = $this->testUInt8 - 6;
 959    $premixRtoL = $this->testUInt8 - 7;
 960
 961    if ($action == self::INITIALIZE) {
 962      $frame->setReverbLeft($reverbLeft);
 963      $frame->setReverbRight($reverbRight);
 964      $frame->setReverbBouncesLeft($reverbBouncesLeft);
 965      $frame->setReverbBouncesRight($reverbBouncesRight);
 966      $frame->setReverbFeedbackLtoL($reverbFeedbackLtoL);
 967      $frame->setReverbFeedbackLtoR($reverbFeedbackLtoR);
 968      $frame->setReverbFeedbackRtoR($reverbFeedbackRtoR);
 969      $frame->setReverbFeedbackRtoL($reverbFeedbackRtoL);
 970      $frame->setPremixLtoR($premixLtoR);
 971      $frame->setPremixRtoL($premixRtoL);
 972    } else {
 973      $this->assertEquals($reverbLeft, $frame->getReverbLeft());
 974      $this->assertEquals($reverbRight, $frame->getReverbRight());
 975      $this->assertEquals($reverbBouncesLeft, $frame->getReverbBouncesLeft());
 976      $this->assertEquals($reverbBouncesRight, $frame->getReverbBouncesRight());
 977      $this->assertEquals($reverbFeedbackLtoL, $frame->getReverbFeedbackLtoL());
 978      $this->assertEquals($reverbFeedbackLtoR, $frame->getReverbFeedbackLtoR());
 979      $this->assertEquals($reverbFeedbackRtoR, $frame->getReverbFeedbackRtoR());
 980      $this->assertEquals($reverbFeedbackRtoL, $frame->getReverbFeedbackRtoL());
 981      $this->assertEquals($premixLtoR, $frame->getPremixLtoR());
 982      $this->assertEquals($premixRtoL, $frame->getPremixRtoL());
 983    }
 984  }
 985
 986  /**
 987   * The first SEEK frame test.
 988   *
 989   * @param Zend_Media_Id3_Frame_SEEK $frame The frame to test.
 990   * @param boolean $action The requested action.
 991   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
 992   *        in this frame.
 993   * @param string $language The language code.
 994   * @param integer $timing The timing format.
 995   */
 996  private function frameSEEK0
 997      (&$frame, $action, $encoding, $language, $timing)
 998  {
 999    $minOffset = $this->testInt32;
1000
1001    if ($action == self::INITIALIZE)
1002      $frame->setMinimumOffset($minOffset);
1003    else
1004      $this->assertEquals($minOffset, $frame->getMinimumOffset());
1005  }
1006
1007  /**
1008   * The first SIGN frame test.
1009   *
1010   * @param Zend_Media_Id3_Frame_SIGN $frame The frame to test.
1011   * @param boolean $action The requested action.
1012   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1013   *        in this frame.
1014   * @param string $language The language code.
1015   * @param integer $timing The timing format.
1016   */
1017  private function frameSIGN0
1018      (&$frame, $action, $encoding, $language, $timing)
1019  {
1020    $group = $this->testUInt8;
1021    $signature = $this->testText;
1022
1023    if ($action == self::INITIALIZE) {
1024      $frame->setGroup($group);
1025      $frame->setSignature($signature);
1026    } else {
1027      $this->assertEquals($group, $frame->getGroup());
1028      $this->assertEquals($signature, $frame->getSignature());
1029    }
1030  }
1031
1032  /**
1033   * The first SYLT frame test.
1034   *
1035   * @param Zend_Media_Id3_Frame_SYLT $frame The frame to test.
1036   * @param boolean $action The requested action.
1037   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1038   *        in this frame.
1039   * @param string $language The language code.
1040   * @param integer $timing The timing format.
1041   */
1042  private function frameSYLT0
1043      (&$frame, $action, $encoding, $language, $timing)
1044  {
1045    $type = $this->testUInt8;
1046    $description = $this->convert($this->testText, $encoding);
1047    $events[0] = $description;
1048    $events[0xFFFF] = $description;
1049    $events[0xFFFFF] = $description;
1050    $events[0xFFFFFF] = $description;
1051    $events[0xFFFFFFFF] = $description;
1052
1053    if ($action == self::INITIALIZE) {
1054      $frame->setType($type);
1055      $frame->setDescription($description);
1056      $frame->setEvents($events);
1057    } else {
1058      $this->assertEquals($type, $frame->getType());
1059      if ($action == self::DRYRUN)
1060        $this->assertEquals($description, $frame->getDescription());
1061      else
1062        $this->assertEquals($this->testText, $frame->getDescription());
1063      foreach ($frame->getEvents() as $value)
1064        $this->assertEquals($action == self::DRYRUN ? $description : $this->testText, $value);
1065    }
1066  }
1067
1068  /**
1069   * The first SYTC frame test.
1070   *
1071   * @param Zend_Media_Id3_Frame_SYTC $frame The frame to test.
1072   * @param boolean $action The requested action.
1073   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1074   *        in this frame.
1075   * @param string $language The language code.
1076   * @param integer $timing The timing format.
1077   */
1078  private function frameSYTC0
1079      (&$frame, $action, $encoding, $language, $timing)
1080  {
1081    $events[0] = Zend_Media_Id3_Frame_SYTC::BEAT_FREE;
1082    $events[0xFFFF] = Zend_Media_Id3_Frame_SYTC::SINGLE_BEAT;
1083    $events[0xFFFFF] = 0xFF;
1084    $events[0xFFFFFF] = 0xFF + 1;
1085    $events[0xFFFFFFFF] = 0xFF + 0xFF;
1086
1087    if ($action == self::INITIALIZE)
1088      $frame->setEvents($events);
1089    else
1090      $this->assertEquals($events, $frame->getEvents());
1091  }
1092
1093  /**
1094   * The first TXXX frame test.
1095   *
1096   * @param Zend_Media_Id3_Frame_TXXX $frame The frame to test.
1097   * @param boolean $action The requested action.
1098   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1099   *        in this frame.
1100   * @param string $language The language code.
1101   * @param integer $timing The timing format.
1102   */
1103  private function frameTXXX0
1104      (&$frame, $action, $encoding, $language, $timing)
1105  {
1106    $description = $this->convert($this->testText, $encoding);
1107    $text = $this->convert($this->testText, $encoding);
1108
1109    if ($action == self::INITIALIZE) {
1110      $frame->setDescription($description);
1111      $frame->setText($text);
1112    } else {
1113      if ($action == self::DRYRUN) {
1114        $this->assertEquals($description, $frame->getDescription());
1115        $this->assertEquals($text, $frame->getText());
1116      } else {
1117        $this->assertEquals($this->testText, $frame->getDescription());
1118        $this->assertEquals($this->testText, $frame->getText());
1119      }
1120    }
1121  }
1122
1123  /**
1124   * The first USER frame test.
1125   *
1126   * @param Zend_Media_Id3_Frame_USER $frame The frame to test.
1127   * @param boolean $action The requested action.
1128   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1129   *        in this frame.
1130   * @param string $language The language code.
1131   * @param integer $timing The timing format.
1132   */
1133  private function frameUSER0
1134      (&$frame, $action, $encoding, $language, $timing)
1135  {
1136    $text = $this->convert($this->testText, $encoding);
1137
1138    if ($action == self::INITIALIZE)
1139      $frame->setText($text);
1140    else {
1141      if ($action == self::DRYRUN)
1142        $this->assertEquals($text, $frame->getText());
1143      else
1144        $this->assertEquals($this->testText, $frame->getText());
1145    }
1146  }
1147
1148  /**
1149   * The first USLT frame test.
1150   *
1151   * @param Zend_Media_Id3_Frame_USLT $frame The frame to test.
1152   * @param boolean $action The requested action.
1153   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1154   *        in this frame.
1155   * @param string $language The language code.
1156   * @param integer $timing The timing format.
1157   */
1158  private function frameUSLT0
1159      (&$frame, $action, $encoding, $language, $timing)
1160  {
1161    $description = $this->convert($this->testText, $encoding);
1162    $text = $this->convert($this->testText, $encoding);
1163
1164    if ($action == self::INITIALIZE) {
1165      $frame->setDescription($description);
1166      $frame->setText($text);
1167    } else {
1168      if ($action == self::DRYRUN) {
1169        $this->assertEquals($description, $frame->getDescription());
1170        $this->assertEquals($text, $frame->getText());
1171      } else {
1172        $this->assertEquals($this->testText, $frame->getDescription());
1173        $this->assertEquals($this->testText, $frame->getText());
1174      }
1175    }
1176  }
1177
1178  /**
1179   * The first WXXX frame test.
1180   *
1181   * @param Zend_Media_Id3_Frame_WXXX $frame The frame to test.
1182   * @param boolean $action The requested action.
1183   * @param integer $encoding The {@link Zend_Media_Id3_Encoding text encoding} for strings
1184   *        in this frame.
1185   * @param string $language The language code.
1186   * @param integer $timing The timing format.
1187   */
1188  private function frameWXXX0
1189      (&$frame, $action, $encoding, $language, $timing)
1190  {
1191    $description = $this->convert($this->testText, $encoding);
1192    $link = $this->testLink;
1193
1194    if ($action == self::INITIALIZE) {
1195      $frame->setDescription($description);
1196      $frame->setLink($link);
1197    } else {
1198      if ($action == self::DRYRUN)
1199        $this->assertEquals($description, $frame->getDescription());
1200      else
1201        $this->assertEquals($this->testText, $frame->getDescription());
1202      $this->assertEquals($link, $frame->getLink());
1203    }
1204  }
1205
1206  /**
1207   * Helper function to convert a string into a string of the given encoding.
1208   *
1209   * @param string $text The string to convert.
1210   * @param integer $encoding The text encoding to convert to.
1211   * @return string
1212   */
1213  private static function convert($text, $encoding)
1214  {
1215    if ($encoding === null)
1216      $encoding = Zend_Media_Id3_Encoding::UTF8;
1217
1218    switch ($encoding) {
1219    case Zend_Media_Id3_Encoding::ISO88591:
1220      return iconv('utf-8', 'iso-8859-1', $text);
1221    case Zend_Media_Id3_Encoding::UTF16:
1222      return iconv('utf-8', 'utf-16', $text);
1223    case Zend_Media_Id3_Encoding::UTF16LE:
1224      return iconv('utf-8', 'utf-16le', $text);
1225    case Zend_Media_Id3_Encoding::UTF16BE:
1226      return iconv('utf-8', 'utf-16be', $text);
1227    default: // Zend_Media_Id3_Encoding::UTF8
1228      return $text;
1229    }
1230  }
1231}