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