PageRenderTime 57ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/music/lib/tests/TestID3Frame.php

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