Add support for encoding option

git-svn-id: http://php-reader.googlecode.com/svn/trunk@129 51a70ab9-7547-0410-9469-37e369ee0574
This commit is contained in:
svollbehr
2008-12-28 19:00:44 +00:00
parent b4cae3bf42
commit c97e87fbc6
16 changed files with 602 additions and 276 deletions

View File

@@ -183,7 +183,7 @@ class ID3_Frame extends ID3_Object
$this->_size = $dataLength; $this->_size = $dataLength;
if ($this->hasFlag(self::UNSYNCHRONISATION) || if ($this->hasFlag(self::UNSYNCHRONISATION) ||
$this->getOption("unsyncronisation", false) === true) $this->getOption("unsynchronisation", false) === true)
$this->_data = $this->decodeUnsynchronisation($this->_data); $this->_data = $this->decodeUnsynchronisation($this->_data);
} }
} }
@@ -285,8 +285,9 @@ class ID3_Frame extends ID3_Object
$data = Transform::toUInt32BE($this->encodeSynchsafe32($this->_size)) . $data = Transform::toUInt32BE($this->encodeSynchsafe32($this->_size)) .
$data; $data;
$flags |= self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION; $flags |= self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION;
$this->setOption("unsyncronisation", true); $this->setOption("unsynchronisation", true);
} } else
$flags &= ~(self::DATA_LENGTH_INDICATOR | self::UNSYNCHRONISATION);
} }
return Transform::toString8(substr($this->_identifier, 0, 4), 4) . return Transform::toString8(substr($this->_identifier, 0, 4), 4) .
Transform::toUInt32BE($this->encodeSynchsafe32($size)) . Transform::toUInt32BE($this->encodeSynchsafe32($size)) .

View File

@@ -80,7 +80,7 @@ final class ID3_Frame_APIC extends ID3_Frame
"Publisher/Studio logotype"); "Publisher/Studio logotype");
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_mimeType = "image/unknown"; private $_mimeType = "image/unknown";
@@ -107,29 +107,41 @@ final class ID3_Frame_APIC extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_mimeType = substr $this->_mimeType = substr
($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1); ($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1);
$this->_imageType = Transform::fromUInt8($this->_data[++$pos]); $this->_imageType = Transform::fromUInt8($this->_data[++$pos]);
$this->_data = substr($this->_data, $pos + 1); $this->_data = substr($this->_data, $pos + 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list ($this->_description, $this->_imageData) = list ($this->_description, $this->_imageData) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list ($this->_description, $this->_imageData) = list ($this->_description, $this->_imageData) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_imageData) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
($this->_description, "utf-8");
break; break;
default: default:
list ($this->_description, $this->_imageData) = list ($this->_description, $this->_imageData) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
($this->_description, "iso-8859-1");
} }
$this->_imageSize = strlen($this->_imageData); $this->_imageSize = strlen($this->_imageData);
@@ -138,6 +150,11 @@ final class ID3_Frame_APIC extends ID3_Frame
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -145,6 +162,12 @@ final class ID3_Frame_APIC extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -59,7 +59,7 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
* *
* @var integer * @var integer
*/ */
protected $_encoding = ID3_Encoding::UTF8; protected $_encoding;
/** /**
* The text array. * The text array.
@@ -78,29 +78,43 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1); $this->_data = substr($this->_data, 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
$this->_text = $this->_text = $this->convertString
$this->explodeString16(Transform::fromString16($this->_data)); ($this->explodeString16(Transform::fromString16($this->_data)),
"utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
$this->_text = $this->_text = $this->convertString
$this->explodeString16(Transform::fromString16BE($this->_data)); ($this->explodeString16(Transform::fromString16BE($this->_data)),
"utf-16be");
break;
case self::UTF8:
$this->_text = $this->convertString
($this->explodeString8(Transform::fromString8($this->_data)), "utf-8");
break; break;
default: default:
$this->_text = $this->_text = $this->convertString
$this->explodeString8(Transform::fromString8($this->_data)); ($this->explodeString8(Transform::fromString8($this->_data)),
"iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -108,6 +122,12 @@ abstract class ID3_Frame_AbstractText extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -62,7 +62,7 @@ final class ID3_Frame_COMM extends ID3_Frame
implements ID3_Encoding, ID3_Language implements ID3_Encoding, ID3_Language
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_language = "und"; private $_language = "und";
@@ -83,39 +83,60 @@ final class ID3_Frame_COMM extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3); $this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX") if ($this->_language == "XXX")
$this->_language = "und"; $this->_language = "und";
$this->_data = substr($this->_data, 4); $this->_data = substr($this->_data, 4);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString16($this->_text); (Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(Transform::fromString16($this->_text), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString16BE($this->_text); (Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(Transform::fromString16BE($this->_text), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "utf-8");
break; break;
default: default:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString8($this->_text); (Transform::fromString8($this->_description), "iso-8859-1");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -123,6 +144,12 @@ final class ID3_Frame_COMM extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -72,7 +72,7 @@ final class ID3_Frame_COMR extends ID3_Frame
"Non-musical merchandise"); "Non-musical merchandise");
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_currency = "EUR"; private $_currency = "EUR";
@@ -114,10 +114,12 @@ final class ID3_Frame_COMR extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
list($pricing, $this->_data) = list($pricing, $this->_data) =
$this->explodeString8(substr($this->_data, 1), 2); $this->explodeString8(substr($this->_data, 1), 2);
$this->_currency = substr($pricing, 0, 3); $this->_currency = substr($pricing, 0, 3);
@@ -128,24 +130,38 @@ final class ID3_Frame_COMR extends ID3_Frame
$this->_delivery = Transform::fromUInt8($this->_data[0]); $this->_delivery = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1); $this->_data = substr($this->_data, 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list ($this->_seller, $this->_description, $this->_data) = list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString16($this->_data, 3); $this->explodeString16($this->_data, 3);
$this->_seller = Transform::fromString16($this->_seller); $this->_seller = $this->convertString
$this->_description = Transform::fromString16($this->_description); (Transform::fromString16($this->_seller), "utf-16");
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list ($this->_seller, $this->_description, $this->_data) = list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString16($this->_data, 3); $this->explodeString16($this->_data, 3);
$this->_seller = Transform::fromString16BE($this->_seller); $this->_seller = $this->convertString
$this->_description = Transform::fromString16BE($this->_description); (Transform::fromString16BE($this->_seller), "utf-16be");
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString8($this->_data, 3);
$this->_seller = $this->convertString
(Transform::fromString8($this->_seller), "utf-8");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break; break;
default: default:
list ($this->_seller, $this->_description, $this->_data) = list ($this->_seller, $this->_description, $this->_data) =
$this->explodeString8($this->_data, 3); $this->explodeString8($this->_data, 3);
$this->_seller = Transform::fromString8($this->_seller); $this->_seller = $this->convertString
$this->_description = Transform::fromString8($this->_description); (Transform::fromString8($this->_seller), "iso-8859-1");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
} }
if (strlen($this->_data) == 0) if (strlen($this->_data) == 0)
@@ -160,6 +176,11 @@ final class ID3_Frame_COMR extends ID3_Frame
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -167,6 +188,12 @@ final class ID3_Frame_COMR extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -56,7 +56,7 @@ final class ID3_Frame_GEOB extends ID3_Frame
implements ID3_Encoding implements ID3_Encoding
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_mimeType; private $_mimeType;
@@ -80,38 +80,59 @@ final class ID3_Frame_GEOB extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_mimeType = substr $this->_mimeType = substr
($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1); ($this->_data, 1, ($pos = strpos($this->_data, "\0", 1)) - 1);
$this->_data = substr($this->_data, $pos + 1); $this->_data = substr($this->_data, $pos + 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list ($this->_filename, $this->_description, $this->_objectData) = list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString16($this->_data, 3); $this->explodeString16($this->_data, 3);
$this->_filename = Transform::fromString16($this->_filename); $this->_filename = $this->convertString
$this->_description = Transform::fromString16($this->_description); (Transform::fromString16($this->_filename), "utf-16");
$this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list ($this->_filename, $this->_description, $this->_objectData) = list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString16($this->_data, 3); $this->explodeString16($this->_data, 3);
$this->_filename = Transform::fromString16BE($this->_filename); $this->_filename = $this->convertString
$this->_description = Transform::fromString16BE($this->_description); (Transform::fromString16BE($this->_filename), "utf-16be");
$this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString8($this->_data, 3);
$this->_filename = $this->convertString
(Transform::fromString8($this->_filename), "utf-8");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break; break;
default: default:
list ($this->_filename, $this->_description, $this->_objectData) = list ($this->_filename, $this->_description, $this->_objectData) =
$this->explodeString8($this->_data, 3); $this->explodeString8($this->_data, 3);
$this->_filename = Transform::fromString8($this->_filename); $this->_filename = $this->convertString
$this->_description = Transform::fromString8($this->_description); (Transform::fromString8($this->_filename), "iso-8859-1");
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -119,6 +140,12 @@ final class ID3_Frame_GEOB extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_IPLS extends ID3_Frame
implements ID3_Encoding implements ID3_Encoding
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var Array */ /** @var Array */
private $_people = array(); private $_people = array();
@@ -74,25 +74,32 @@ final class ID3_Frame_IPLS extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$data = substr($this->_data, 1); $data = substr($this->_data, 1);
$order = Transform::MACHINE_ENDIAN_ORDER; $order = Transform::MACHINE_ENDIAN_ORDER;
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
$data = $this->explodeString16($data); $data = $this->explodeString16($data);
foreach ($data as &$str) foreach ($data as &$str)
$str = Transform::fromString16($str, $order); $str = $this->convertString
(Transform::fromString16($str, $order), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
$data = $this->explodeString16($data); $data = $this->explodeString16($data);
foreach ($data as &$str) foreach ($data as &$str)
$str = Transform::fromString16BE($str); $str = $this->convertString
(Transform::fromString16BE($str), "utf-16be");
break;
case self::UTF8:
$data = $this->convertString($this->explodeString8($data), "utf-8");
break; break;
default: default:
$data = $this->explodeString8($data); $data = $this->convertString($this->explodeString8($data), "iso-8859-1");
} }
for ($i = 0; $i < count($data) - 1; $i += 2) for ($i = 0; $i < count($data) - 1; $i += 2)
@@ -102,6 +109,11 @@ final class ID3_Frame_IPLS extends ID3_Frame
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -109,6 +121,12 @@ final class ID3_Frame_IPLS extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_OWNE extends ID3_Frame
implements ID3_Encoding implements ID3_Encoding
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_currency = "EUR"; private $_currency = "EUR";
@@ -83,10 +83,12 @@ final class ID3_Frame_OWNE extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
list($tmp, $this->_data) = list($tmp, $this->_data) =
$this->explodeString8(substr($this->_data, 1), 2); $this->explodeString8(substr($this->_data, 1), 2);
$this->_currency = substr($tmp, 0, 3); $this->_currency = substr($tmp, 0, 3);
@@ -94,21 +96,33 @@ final class ID3_Frame_OWNE extends ID3_Frame
$this->_date = substr($this->_data, 0, 8); $this->_date = substr($this->_data, 0, 8);
$this->_data = substr($this->_data, 8); $this->_data = substr($this->_data, 8);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
$this->_seller = Transform::fromString16($this->_data); $this->_seller = $this->convertString
(Transform::fromString16($this->_data), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
$this->_seller = Transform::fromString16BE($this->_data); $this->_seller = $this->convertString
(Transform::fromString16BE($this->_data), "utf-16be");
break;
case self::UTF8:
$this->_seller = $this->convertString
(Transform::fromString8($this->_data), "utf-8");
break; break;
default: default:
$this->_seller = Transform::fromString8($this->_data); $this->_seller = $this->convertString
(Transform::fromString8($this->_data), "iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -116,6 +130,12 @@ final class ID3_Frame_OWNE extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -72,7 +72,7 @@ final class ID3_Frame_SYLT extends ID3_Frame
"Chord", "Trivia", "URLs to webpages", "URLs to images"); "Chord", "Trivia", "URLs to webpages", "URLs to images");
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_language = "und"; private $_language = "und";
@@ -99,10 +99,12 @@ final class ID3_Frame_SYLT extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3); $this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX") if ($this->_language == "XXX")
$this->_language = "und"; $this->_language = "und";
@@ -110,39 +112,57 @@ final class ID3_Frame_SYLT extends ID3_Frame
$this->_type = Transform::fromUInt8($this->_data[5]); $this->_type = Transform::fromUInt8($this->_data[5]);
$this->_data = substr($this->_data, 6); $this->_data = substr($this->_data, 6);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list($this->_description, $this->_data) = list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list($this->_description, $this->_data) = list($this->_description, $this->_data) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
break; break;
default: default:
list($this->_description, $this->_data) = list($this->_description, $this->_data) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description); $this->_description = $this->convertString
(Transform::fromString8($this->_description), "iso-8859-1");
} }
while (strlen($this->_data) > 0) { while (strlen($this->_data) > 0) {
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list($syllable, $this->_data) = list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16($syllable); $syllable = $this->convertString
(Transform::fromString16($syllable), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list($syllable, $this->_data) = list($syllable, $this->_data) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$syllable = Transform::fromString16BE($syllable); $syllable = $this->convertString
(Transform::fromString16BE($syllable), "utf-16be");
break;
case self::UTF8:
list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2);
$syllable = $this->convertString
(Transform::fromString8($syllable), "utf-8");
break; break;
default: default:
list($syllable, $this->_data) = list($syllable, $this->_data) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
$syllable = Transform::fromString8($syllable); $syllable = $this->convertString
(Transform::fromString8($syllable), "iso-8859-1");
} }
$this->_events[Transform::fromUInt32BE(substr($this->_data, 0, 4))] = $this->_events[Transform::fromUInt32BE(substr($this->_data, 0, 4))] =
$syllable; $syllable;
@@ -154,6 +174,11 @@ final class ID3_Frame_SYLT extends ID3_Frame
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -161,6 +186,12 @@ final class ID3_Frame_SYLT extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -72,28 +72,39 @@ final class ID3_Frame_TXXX extends ID3_Frame_AbstractText
{ {
ID3_Frame::__construct($reader, $options); ID3_Frame::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1); $this->_data = substr($this->_data, 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list($this->_description, $this->_text) = list($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
$this->_text = array(Transform::fromString16($this->_text)); (Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(array(Transform::fromString16($this->_text)), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list($this->_description, $this->_text) = list($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
$this->_text = array(Transform::fromString16BE($this->_text)); (Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(array(Transform::fromString16BE($this->_text)), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_text) = $this->convertString
($this->explodeString8($this->_data, 2), "utf-8");
$this->_text = array($this->_text);
break; break;
default: default:
list($this->_description, $this->_text) = list($this->_description, $this->_text) = $this->convertString
$this->explodeString8($this->_data, 2); ($this->explodeString8($this->_data, 2), "iso-8859-1");
$this->_text = array($this->_text); $this->_text = array($this->_text);
} }
} }

View File

@@ -60,7 +60,7 @@ final class ID3_Frame_USER extends ID3_Frame
implements ID3_Encoding, ID3_Language implements ID3_Encoding, ID3_Language
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_language = "und"; private $_language = "und";
@@ -78,30 +78,44 @@ final class ID3_Frame_USER extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3); $this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX") if ($this->_language == "XXX")
$this->_language = "und"; $this->_language = "und";
$this->_data = substr($this->_data, 4); $this->_data = substr($this->_data, 4);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
$this->_text = Transform::fromString16($this->_data); $this->_text = $this->convertString
(Transform::fromString16($this->_data), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
$this->_text = Transform::fromString16BE($this->_data); $this->_text = $this->convertString
(Transform::fromString16BE($this->_data), "utf-16be");
break;
case self::UTF8:
$this->_text = $this->convertString
(Transform::fromString8($this->_data), "utf-8");
break; break;
default: default:
$this->_text = Transform::fromString8($this->_data); $this->_text = $this->convertString
(Transform::fromString8($this->_data), "iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -109,6 +123,12 @@ final class ID3_Frame_USER extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_USLT extends ID3_Frame
implements ID3_Encoding, ID3_Language implements ID3_Encoding, ID3_Language
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_language = "und"; private $_language = "und";
@@ -80,39 +80,60 @@ final class ID3_Frame_USLT extends ID3_Frame
{ {
parent::__construct($reader, $options); parent::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_language = substr($this->_data, 1, 3); $this->_language = substr($this->_data, 1, 3);
if ($this->_language == "XXX") if ($this->_language == "XXX")
$this->_language = "und"; $this->_language = "und";
$this->_data = substr($this->_data, 4); $this->_data = substr($this->_data, 4);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString16($this->_text); (Transform::fromString16($this->_description), "utf-16");
$this->_text = $this->convertString
(Transform::fromString16($this->_text), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString16BE($this->_text); (Transform::fromString16BE($this->_description), "utf-16be");
$this->_text = $this->convertString
(Transform::fromString16BE($this->_text), "utf-16be");
break;
case self::UTF8:
list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString
(Transform::fromString8($this->_description), "utf-8");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "utf-8");
break; break;
default: default:
list ($this->_description, $this->_text) = list ($this->_description, $this->_text) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
$this->_description = Transform::fromString8($this->_description); $this->_description = $this->convertString
$this->_text = Transform::fromString8($this->_text); (Transform::fromString8($this->_description), "iso-8859-1");
$this->_text = $this->convertString
(Transform::fromString8($this->_text), "iso-8859-1");
} }
} }
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer * @return integer
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -120,6 +141,12 @@ final class ID3_Frame_USLT extends ID3_Frame
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -59,7 +59,7 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
implements ID3_Encoding implements ID3_Encoding
{ {
/** @var integer */ /** @var integer */
private $_encoding = ID3_Encoding::UTF8; private $_encoding;
/** @var string */ /** @var string */
private $_description; private $_description;
@@ -74,27 +74,37 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
{ {
ID3_Frame::__construct($reader, $options); ID3_Frame::__construct($reader, $options);
$this->_encoding = $this->getOption("encoding", ID3_Encoding::UTF8);
if ($reader === null) if ($reader === null)
return; return;
$this->_encoding = Transform::fromUInt8($this->_data[0]); $encoding = Transform::fromUInt8($this->_data[0]);
$this->_data = substr($this->_data, 1); $this->_data = substr($this->_data, 1);
switch ($this->_encoding) { switch ($encoding) {
case self::UTF16: case self::UTF16:
list($this->_description, $this->_link) = list($this->_description, $this->_link) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16($this->_description); $this->_description = $this->convertString
(Transform::fromString16($this->_description), "utf-16");
break; break;
case self::UTF16BE: case self::UTF16BE:
list($this->_description, $this->_link) = list($this->_description, $this->_link) =
$this->explodeString16($this->_data, 2); $this->explodeString16($this->_data, 2);
$this->_description = Transform::fromString16BE($this->_description); $this->_description = $this->convertString
(Transform::fromString16BE($this->_description), "utf-16be");
break;
case self::UTF8:
list($this->_description, $this->_link) =
$this->explodeString8($this->_data, 2);
$this->_description = $this->convertString($this->_description, "utf-8");
break; break;
default: default:
list($this->_description, $this->_link) = list($this->_description, $this->_link) =
$this->explodeString8($this->_data, 2); $this->explodeString8($this->_data, 2);
break; $this->_description = $this->convertString
($this->_description, "iso-8859-1");
} }
$this->_link = implode($this->explodeString8($this->_link, 1), ""); $this->_link = implode($this->explodeString8($this->_link, 1), "");
} }
@@ -102,6 +112,11 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
/** /**
* Returns the text encoding. * Returns the text encoding.
* *
* All the strings read from a file are automatically converted to the
* character encoding specified with the <var>encoding</var> option. See
* {@link ID3v2} for details. This method returns the original text encoding
* used to write the frame.
*
* @return integer The encoding. * @return integer The encoding.
*/ */
public function getEncoding() { return $this->_encoding; } public function getEncoding() { return $this->_encoding; }
@@ -109,6 +124,12 @@ final class ID3_Frame_WXXX extends ID3_Frame_AbstractLink
/** /**
* Sets the text encoding. * Sets the text encoding.
* *
* All the string written to the frame are done so using given character
* encoding. No conversions of existing data take place upon the call to this
* method thus all texts must be given in given character encoding.
*
* The default character encoding used to write the frame is UTF-8.
*
* @see ID3_Encoding * @see ID3_Encoding
* @param integer $encoding The text encoding. * @param integer $encoding The text encoding.
*/ */

View File

@@ -195,7 +195,7 @@ abstract class ID3_Object
/** /**
* Reverses the unsynchronisation scheme from the given data string. * Reverses the unsynchronisation scheme from the given data string.
* *
* @see encodeUnsyncronisation * @see encodeUnsynchronisation
* @param string $data The input data. * @param string $data The input data.
* @return string * @return string
*/ */
@@ -248,4 +248,42 @@ abstract class ID3_Object
{ {
return preg_split("/\\x00/", $value, $limit); return preg_split("/\\x00/", $value, $limit);
} }
/**
* Converts string to requested character encoding and returns it. See the
* documentation of iconv for accepted values for encoding.
*
* @param string|Array $string
* @param string $encoding
*/
protected function convertString($string, $encoding)
{
$target = $this->getOption("encoding", ID3_Encoding::UTF8);
switch ($target) {
case ID3_Encoding::UTF16:
$target = "utf-16";
break;
case ID3_Encoding::UTF16LE:
$target = "utf-16le";
break;
case ID3_Encoding::UTF16BE:
$target = "utf-16be";
break;
case ID3_Encoding::UTF8:
$target = "utf-8";
break;
default:
$target = "iso-8859-1";
}
if (strtolower($target) == strtolower($encoding))
return $string;
if (is_array($string))
foreach ($string as $key => $value)
$string[$key] = iconv($encoding, $target, $value);
else
$string = iconv($encoding, $target, $string);
return $string;
}
} }

View File

@@ -96,6 +96,10 @@ final class ID3v2
* may also be given as the only parameter. * may also be given as the only parameter.
* *
* The following options are currently recognized: * The following options are currently recognized:
* o encoding -- Indicates the encoding that all the texts are presented
* with. By default this is set to ID3_Encoding::UTF8. See the
* documentation of the {@link ID3_Encoding} interface for accepted
* values. Conversions are carried out using iconv.
* o version -- The ID3v2 tag version to use in write operation. This option * o version -- The ID3v2 tag version to use in write operation. This option
* is automatically set when a tag is read from a file and defaults to * is automatically set when a tag is read from a file and defaults to
* version 4.0 for tag write. * version 4.0 for tag write.

View File

@@ -46,13 +46,18 @@ require_once("Reader.php");
* @package php-reader * @package php-reader
* @subpackage Tests * @subpackage Tests
* @author Ryan Butterfield <buttza@gmail.com> * @author Ryan Butterfield <buttza@gmail.com>
* @author Sven Vollbehr <svollbehr@gmail.com>
* @copyright Copyright (c) 2008 The PHP Reader Project Workgroup * @copyright Copyright (c) 2008 The PHP Reader Project Workgroup
* @license http://code.google.com/p/php-reader/wiki/License New BSD License * @license http://code.google.com/p/php-reader/wiki/License New BSD License
* @version $Rev$ * @version $Rev$
*/ */
final class TestID3Frame extends PHPUnit_Framework_TestCase final class TestID3Frame extends PHPUnit_Framework_TestCase
{ {
private $testText = "abcdefghijklmnopqrstuvwxyz1234567890!@#\$%^&*()-"; const INITIALIZE = 1;
const DRYRUN = 2;
const RUN = 3;
private $testText = "abcdefghijklmnopqrstuvwxyzåäö1234567890!@#\$%^&*()-";
private $testLink = "http://www.abcdefghijklmnopqrstuvwxyz.com.xyz/qwerty.php?asdf=1234&zxcv=%20"; private $testLink = "http://www.abcdefghijklmnopqrstuvwxyz.com.xyz/qwerty.php?asdf=1234&zxcv=%20";
private $testDate = "20070707"; private $testDate = "20070707";
private $testCurrency = "AUD"; private $testCurrency = "AUD";
@@ -138,9 +143,9 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/* Setup and verify the frame */ /* Setup and verify the frame */
$frame = new $class(); $frame = new $class();
call_user_func(array($this, $method), call_user_func(array($this, $method),
$frame, true, $encoding, $language, $timing); $frame, self::INITIALIZE, $encoding, $language, $timing);
call_user_func(array($this, $method), call_user_func(array($this, $method),
$frame, false, $encoding, $language, $timing); $frame, self::DRYRUN, $encoding, $language, $timing);
if (isset($encoding)) { if (isset($encoding)) {
$this->assertTrue(method_exists($frame, "setEncoding")); $this->assertTrue(method_exists($frame, "setEncoding"));
@@ -166,8 +171,6 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
if ($i > 0) if ($i > 0)
$existing = $data; $existing = $data;
$length = strlen($data = "" . $frame); $length = strlen($data = "" . $frame);
if ($i > 0)
$this->assertEquals($existing, $data);
$this->assertTrue(($fd = fopen("php://temp", "r+b")) !== false); $this->assertTrue(($fd = fopen("php://temp", "r+b")) !== false);
$this->assertEquals($length, fwrite($fd, $data, $length)); $this->assertEquals($length, fwrite($fd, $data, $length));
$this->assertTrue(rewind($fd)); $this->assertTrue(rewind($fd));
@@ -175,9 +178,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
/* Construct a frame using the reader and verify */ /* Construct a frame using the reader and verify */
$frame = new $class($reader = new Reader($fd)); $frame = new $class($reader = new Reader($fd));
call_user_func(array($this, $method), call_user_func(array($this, $method),
$frame, false, $encoding, $language, $timing); $frame, self::RUN, $encoding, $language, $timing);
if (isset($encoding))
$this->assertEquals($encoding, $frame->getEncoding());
if (isset($language)) if (isset($language))
$this->assertEquals($language, $frame->getLanguage()); $this->assertEquals($language, $frame->getLanguage());
if (isset($timing)) if (isset($timing))
@@ -186,65 +187,25 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
} }
} }
/**
* The first AbstractLink frame test.
*
* @param ID3_Frame_AbstractLink $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
*/
/*private function frameAbstractLink0(&$frame, $construct, $encoding, $language, $timing) {
$link = $this->testLink;
if ($construct)
$frame->setLink($link);
else
$this->assertEquals($link, $frame->getLink());
}*/
/**
* The first AbstractText frame test.
*
* @param ID3_Frame_AbstractText $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame.
* @param string $language The language code.
* @param integer $timing The timing format.
*/
/*private function frameAbstractText0
(&$frame, $construct, $encoding, $language, $timing)
{
$text = $this->convert($this->testText, $encoding);
if ($construct)
$frame->setText($text);
else
$this->assertEquals($text, $frame->getText());
}*/
/** /**
* The first AENC frame test. * The first AENC frame test.
* *
* @param ID3_Frame_AENC $frame The frame to test. * @param ID3_Frame_AENC $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameAENC0 private function frameAENC0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$owner = $this->testText; $owner = $this->testText;
$previewStart = $this->testUInt16; $previewStart = $this->testUInt16;
$previewLength = $this->testUInt16 - 1; $previewLength = $this->testUInt16 - 1;
$encryptionInfo = $this->testText; $encryptionInfo = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setOwner($owner); $frame->setOwner($owner);
$frame->setPreviewStart($previewStart); $frame->setPreviewStart($previewStart);
$frame->setPreviewLength($previewLength); $frame->setPreviewLength($previewLength);
@@ -261,14 +222,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first APIC frame test. * The first APIC frame test.
* *
* @param ID3_Frame_APIC $frame The frame to test. * @param ID3_Frame_APIC $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameAPIC0 private function frameAPIC0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$mimeType = $this->testText; $mimeType = $this->testText;
$imageType = $this->testUInt8; $imageType = $this->testUInt8;
@@ -276,7 +237,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$imageData = $this->testText; $imageData = $this->testText;
$imageSize = strlen($imageData); $imageSize = strlen($imageData);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setMimeType($mimeType); $frame->setMimeType($mimeType);
$frame->setImageType($imageType); $frame->setImageType($imageType);
$frame->setDescription($description); $frame->setDescription($description);
@@ -284,7 +245,10 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
} else { } else {
$this->assertEquals($mimeType, $frame->getMimeType()); $this->assertEquals($mimeType, $frame->getMimeType());
$this->assertEquals($imageType, $frame->getImageType()); $this->assertEquals($imageType, $frame->getImageType());
if ($action == self::DRYRUN)
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
else
$this->assertEquals($this->testText, $frame->getDescription());
$this->assertEquals($imageData, $frame->getImageData()); $this->assertEquals($imageData, $frame->getImageData());
$this->assertEquals($imageSize, $frame->getImageSize()); $this->assertEquals($imageSize, $frame->getImageSize());
} }
@@ -294,24 +258,29 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first COMM frame test. * The first COMM frame test.
* *
* @param ID3_Frame_COMM $frame The frame to test. * @param ID3_Frame_COMM $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameCOMM0 private function frameCOMM0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
$text = $this->convert($this->testText, $encoding); $text = $this->convert($this->testText, $encoding);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setDescription($description); $frame->setDescription($description);
$frame->setText($text); $frame->setText($text);
} else { } else {
if ($action == self::DRYRUN) {
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
$this->assertEquals($text, $frame->getText()); $this->assertEquals($text, $frame->getText());
} else {
$this->assertEquals($this->testText, $frame->getDescription());
$this->assertEquals($this->testText, $frame->getText());
}
} }
} }
@@ -319,14 +288,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first COMR frame test. * The first COMR frame test.
* *
* @param ID3_Frame_COMR $frame The frame to test. * @param ID3_Frame_COMR $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameCOMR0 private function frameCOMR0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$currency = $this->testCurrency; $currency = $this->testCurrency;
$price = $this->testText; $price = $this->testText;
@@ -339,7 +308,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$imageData = $this->testText; $imageData = $this->testText;
$imageSize = strlen($imageData); $imageSize = strlen($imageData);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setCurrency($currency); $frame->setCurrency($currency);
$frame->setPrice($price); $frame->setPrice($price);
$frame->setDate($date); $frame->setDate($date);
@@ -355,8 +324,13 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$this->assertEquals($date, $frame->getDate()); $this->assertEquals($date, $frame->getDate());
$this->assertEquals($contact, $frame->getContact()); $this->assertEquals($contact, $frame->getContact());
$this->assertEquals($delivery, $frame->getDelivery()); $this->assertEquals($delivery, $frame->getDelivery());
if ($action == self::DRYRUN) {
$this->assertEquals($seller, $frame->getSeller()); $this->assertEquals($seller, $frame->getSeller());
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
} else {
$this->assertEquals($this->testText, $frame->getSeller());
$this->assertEquals($this->testText, $frame->getDescription());
}
$this->assertEquals($mimeType, $frame->getMimeType()); $this->assertEquals($mimeType, $frame->getMimeType());
$this->assertEquals($imageData, $frame->getImageData()); $this->assertEquals($imageData, $frame->getImageData());
$this->assertEquals($imageSize, $frame->getImageSize()); $this->assertEquals($imageSize, $frame->getImageSize());
@@ -367,20 +341,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first ENCR frame test. * The first ENCR frame test.
* *
* @param ID3_Frame_ENCR $frame The frame to test. * @param ID3_Frame_ENCR $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameENCR0 private function frameENCR0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$owner = $this->testLink; $owner = $this->testLink;
$method = $this->testInt8; $method = $this->testInt8;
$encryptionData = $this->testText; $encryptionData = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setOwner($owner); $frame->setOwner($owner);
$frame->setMethod($method); $frame->setMethod($method);
$frame->setEncryptionData($encryptionData); $frame->setEncryptionData($encryptionData);
@@ -395,14 +369,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first EQU2 frame test. * The first EQU2 frame test.
* *
* @param ID3_Frame_EQU2 $frame The frame to test. * @param ID3_Frame_EQU2 $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameEQU20 private function frameEQU20
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$interpolation = $this->testInt8; $interpolation = $this->testInt8;
$device = $this->testText; $device = $this->testText;
@@ -412,7 +386,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$adjustments[16383] = 1.0; $adjustments[16383] = 1.0;
$adjustments[32767] = 32767.0 / 512.0; $adjustments[32767] = 32767.0 / 512.0;
if ($construct) { if ($action == self::INITIALIZE) {
foreach ($adjustments as $frequency => $adjustment) foreach ($adjustments as $frequency => $adjustment)
$frame->addAdjustment($frequency, $adjustment); $frame->addAdjustment($frequency, $adjustment);
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -431,14 +405,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first EQUA frame test. * The first EQUA frame test.
* *
* @param ID3_Frame_EQUA $frame The frame to test. * @param ID3_Frame_EQUA $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameEQUA0 private function frameEQUA0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$adjustments[0] = -65535; $adjustments[0] = -65535;
$adjustments[2047] = -4096; $adjustments[2047] = -4096;
@@ -446,7 +420,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$adjustments[16383] = 4096; $adjustments[16383] = 4096;
$adjustments[32767] = 65535; $adjustments[32767] = 65535;
if ($construct) { if ($action == self::INITIALIZE) {
foreach ($adjustments as $frequency => $adjustment) foreach ($adjustments as $frequency => $adjustment)
$frame->addAdjustment($frequency, $adjustment); $frame->addAdjustment($frequency, $adjustment);
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -461,14 +435,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first ETCO frame test. * The first ETCO frame test.
* *
* @param ID3_Frame_ETCO $frame The frame to test. * @param ID3_Frame_ETCO $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameETCO0 private function frameETCO0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$events[0] = array_search("Intro end", ID3_Frame_ETCO::$types); $events[0] = array_search("Intro end", ID3_Frame_ETCO::$types);
$events[0xFFFF] = array_search("Verse start", ID3_Frame_ETCO::$types); $events[0xFFFF] = array_search("Verse start", ID3_Frame_ETCO::$types);
@@ -478,7 +452,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$events[0xFFFFFFFF] = array_search $events[0xFFFFFFFF] = array_search
("Audio file ends", ID3_Frame_ETCO::$types); ("Audio file ends", ID3_Frame_ETCO::$types);
if ($construct) if ($action == self::INITIALIZE)
$frame->setEvents($events); $frame->setEvents($events);
else else
$this->assertEquals($events, $frame->getEvents()); $this->assertEquals($events, $frame->getEvents());
@@ -488,29 +462,34 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first GEOB frame test. * The first GEOB frame test.
* *
* @param ID3_Frame_GEOB $frame The frame to test. * @param ID3_Frame_GEOB $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameGEOB0 private function frameGEOB0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$mimeType = $this->testText; $mimeType = $this->testText;
$filename = $this->convert($this->testText, $encoding); $filename = $this->convert($this->testText, $encoding);
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
$objectData = $this->testText; $objectData = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setMimeType($mimeType); $frame->setMimeType($mimeType);
$frame->setFilename($filename); $frame->setFilename($filename);
$frame->setDescription($description); $frame->setDescription($description);
$frame->setObjectData($objectData); $frame->setObjectData($objectData);
} else { } else {
$this->assertEquals($mimeType, $frame->getMimeType()); $this->assertEquals($mimeType, $frame->getMimeType());
if ($action == self::DRYRUN) {
$this->assertEquals($filename, $frame->getFilename()); $this->assertEquals($filename, $frame->getFilename());
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
} else {
$this->assertEquals($this->testText, $frame->getFilename());
$this->assertEquals($this->testText, $frame->getDescription());
}
$this->assertEquals($objectData, $frame->getObjectData()); $this->assertEquals($objectData, $frame->getObjectData());
} }
} }
@@ -519,20 +498,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first GRID frame test. * The first GRID frame test.
* *
* @param ID3_Frame_GRID $frame The frame to test. * @param ID3_Frame_GRID $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameGRID0 private function frameGRID0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$owner = $this->testLink; $owner = $this->testLink;
$group = $this->testUInt8; $group = $this->testUInt8;
$groupData = $this->testText; $groupData = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setOwner($owner); $frame->setOwner($owner);
$frame->setGroup($group); $frame->setGroup($group);
$frame->setGroupData($groupData); $frame->setGroupData($groupData);
@@ -547,28 +526,33 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first IPLS frame test. * The first IPLS frame test.
* *
* @param ID3_Frame_IPLS $frame The frame to test. * @param ID3_Frame_IPLS $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameIPLS0 private function frameIPLS0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$testText = $this->convert($this->testText, $encoding); $testText = $this->convert($this->testText, $encoding);
for ($i = 0; $i < 3; $i++) for ($i = 0; $i < 3; $i++) {
$people[] = array($testText => $testText); $convertedPeople[] = array($testText => $testText);
$originalPeople[] = array($this->testText => $this->testText);
}
if ($construct) { if ($action == self::INITIALIZE) {
foreach ($people as $entry) foreach ($convertedPeople as $entry)
foreach ($entry as $involvement => $person) foreach ($entry as $involvement => $person)
$frame->addPerson($involvement, $person); $frame->addPerson($involvement, $person);
$this->assertEquals($people, $frame->getPeople()); $this->assertEquals($convertedPeople, $frame->getPeople());
$frame->setPeople($people); $frame->setPeople($convertedPeople);
} else { } else {
$this->assertEquals($people, $frame->getPeople()); if ($action == self::DRYRUN)
$this->assertEquals($convertedPeople, $frame->getPeople());
else
$this->assertEquals($originalPeople, $frame->getPeople());
} }
} }
@@ -576,20 +560,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first LINK frame test. * The first LINK frame test.
* *
* @param ID3_Frame_LINK $frame The frame to test. * @param ID3_Frame_LINK $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameLINK0 private function frameLINK0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$target = $this->testIdentifier; $target = $this->testIdentifier;
$url = $this->testLink; $url = $this->testLink;
$qualifier = $this->testText; $qualifier = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setTarget($target); $frame->setTarget($target);
$frame->setUrl($url); $frame->setUrl($url);
$frame->setQualifier($qualifier); $frame->setQualifier($qualifier);
@@ -604,18 +588,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first MCDI frame test. * The first MCDI frame test.
* *
* @param ID3_Frame_MCDI $frame The frame to test. * @param ID3_Frame_MCDI $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameMCDI0 private function frameMCDI0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$data = $this->testText; $data = $this->testText;
if ($construct) if ($action == self::INITIALIZE)
$frame->setData($data); $frame->setData($data);
else else
$this->assertEquals($data, $frame->getData()); $this->assertEquals($data, $frame->getData());
@@ -625,21 +609,21 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first OWNE frame test. * The first OWNE frame test.
* *
* @param ID3_Frame_OWNE $frame The frame to test. * @param ID3_Frame_OWNE $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameOWNE0 private function frameOWNE0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$currency = $this->testCurrency; $currency = $this->testCurrency;
$price = $this->testPrice; $price = $this->testPrice;
$date = $this->testDate; $date = $this->testDate;
$seller = $this->convert($this->testText, $encoding); $seller = $this->convert($this->testText, $encoding);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setCurrency($currency); $frame->setCurrency($currency);
$frame->setPrice(0.0 + $price); $frame->setPrice(0.0 + $price);
$frame->setDate($date); $frame->setDate($date);
@@ -648,7 +632,10 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$this->assertEquals($currency, $frame->getCurrency()); $this->assertEquals($currency, $frame->getCurrency());
$this->assertEquals($price, $frame->getPrice()); $this->assertEquals($price, $frame->getPrice());
$this->assertEquals($date, $frame->getDate()); $this->assertEquals($date, $frame->getDate());
if ($action == self::DRYRUN)
$this->assertEquals($seller, $frame->getSeller()); $this->assertEquals($seller, $frame->getSeller());
else
$this->assertEquals($this->testText, $frame->getSeller());
} }
} }
@@ -656,18 +643,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first PCNT frame test. * The first PCNT frame test.
* *
* @param ID3_Frame_PCNT $frame The frame to test. * @param ID3_Frame_PCNT $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function framePCNT0 private function framePCNT0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$counter = $this->testUInt32; $counter = $this->testUInt32;
if ($construct) { if ($action == self::INITIALIZE) {
for ($i = 0; $i < 123; $i++) for ($i = 0; $i < 123; $i++)
$frame->addCounter(); $frame->addCounter();
$this->assertEquals(123, $frame->getCounter()); $this->assertEquals(123, $frame->getCounter());
@@ -682,20 +669,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first POPM frame test. * The first POPM frame test.
* *
* @param ID3_Frame_POPM $frame The frame to test. * @param ID3_Frame_POPM $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function framePOPM0 private function framePOPM0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$owner = $this->testLink; $owner = $this->testLink;
$rating = $this->testUInt8; $rating = $this->testUInt8;
$counter = $this->testUInt32; $counter = $this->testUInt32;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setOwner($owner); $frame->setOwner($owner);
$frame->setRating($rating); $frame->setRating($rating);
$frame->setCounter($counter); $frame->setCounter($counter);
@@ -710,18 +697,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first POSS frame test. * The first POSS frame test.
* *
* @param ID3_Frame_POSS $frame The frame to test. * @param ID3_Frame_POSS $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function framePOSS0 private function framePOSS0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$position = $this->testUInt32; $position = $this->testUInt32;
if ($construct) if ($action == self::INITIALIZE)
$frame->setPosition($position); $frame->setPosition($position);
else else
$this->assertEquals($position, $frame->getPosition()); $this->assertEquals($position, $frame->getPosition());
@@ -731,19 +718,19 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first PRIV frame test. * The first PRIV frame test.
* *
* @param ID3_Frame_PRIV $frame The frame to test. * @param ID3_Frame_PRIV $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function framePRIV0 private function framePRIV0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$owner = $this->testText; $owner = $this->testText;
$privateData = $this->testText; $privateData = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setOwner($owner); $frame->setOwner($owner);
$frame->setPrivateData($privateData); $frame->setPrivateData($privateData);
} else { } else {
@@ -756,20 +743,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first RBUF frame test. * The first RBUF frame test.
* *
* @param ID3_Frame_RBUF $frame The frame to test. * @param ID3_Frame_RBUF $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRBUF0 private function frameRBUF0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$bufferSize = $this->testInt24; $bufferSize = $this->testInt24;
$flags = $this->testInt8; $flags = $this->testInt8;
$offset = $this->testInt32; $offset = $this->testInt32;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setBufferSize($bufferSize); $frame->setBufferSize($bufferSize);
$frame->setInfoFlags($flags); $frame->setInfoFlags($flags);
$frame->setOffset($offset); $frame->setOffset($offset);
@@ -784,14 +771,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first RVA2 frame test. * The first RVA2 frame test.
* *
* @param ID3_Frame_RVA2 $frame The frame to test. * @param ID3_Frame_RVA2 $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVA20 private function frameRVA20
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$device = $this->testText; $device = $this->testText;
$adjustments[0] = array(ID3_Frame_RVA2::channelType => 0, $adjustments[0] = array(ID3_Frame_RVA2::channelType => 0,
@@ -822,7 +809,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
ID3_Frame_RVA2::volumeAdjustment => 32767.0 / 512.0, ID3_Frame_RVA2::volumeAdjustment => 32767.0 / 512.0,
ID3_Frame_RVA2::peakVolume => 0xffffffff); ID3_Frame_RVA2::peakVolume => 0xffffffff);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setDevice($device); $frame->setDevice($device);
$frame->setAdjustments($adjustments); $frame->setAdjustments($adjustments);
} else { } else {
@@ -835,21 +822,21 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first RVAD frame test. * The first RVAD frame test.
* *
* @param ID3_Frame_RVAD $frame The frame to test. * @param ID3_Frame_RVAD $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVAD0 private function frameRVAD0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$adjustments[ID3_Frame_RVAD::right] = -0xffff; $adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff; $adjustments[ID3_Frame_RVAD::left] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakRight] = 0xffff; $adjustments[ID3_Frame_RVAD::peakRight] = 0xffff;
$adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff; $adjustments[ID3_Frame_RVAD::peakLeft] = 0xfff;
if ($construct) if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments); $frame->setAdjustments($adjustments);
else else
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -859,14 +846,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The second RVAD frame test. * The second RVAD frame test.
* *
* @param ID3_Frame_RVAD $frame The frame to test. * @param ID3_Frame_RVAD $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVAD1 private function frameRVAD1
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$adjustments[ID3_Frame_RVAD::right] = -0xffff; $adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff; $adjustments[ID3_Frame_RVAD::left] = 0xffff;
@@ -877,7 +864,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$adjustments[ID3_Frame_RVAD::peakRightBack] = 0xff; $adjustments[ID3_Frame_RVAD::peakRightBack] = 0xff;
$adjustments[ID3_Frame_RVAD::peakLeftBack] = 0xf; $adjustments[ID3_Frame_RVAD::peakLeftBack] = 0xf;
if ($construct) if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments); $frame->setAdjustments($adjustments);
else else
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -887,14 +874,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The third RVAD frame test. * The third RVAD frame test.
* *
* @param ID3_Frame_RVAD $frame The frame to test. * @param ID3_Frame_RVAD $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVAD2 private function frameRVAD2
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$adjustments[ID3_Frame_RVAD::right] = -0xffff; $adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff; $adjustments[ID3_Frame_RVAD::left] = 0xffff;
@@ -907,7 +894,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$adjustments[ID3_Frame_RVAD::center] = 0xf; $adjustments[ID3_Frame_RVAD::center] = 0xf;
$adjustments[ID3_Frame_RVAD::peakCenter] = 0x7; $adjustments[ID3_Frame_RVAD::peakCenter] = 0x7;
if ($construct) if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments); $frame->setAdjustments($adjustments);
else else
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -917,14 +904,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The fourth RVAD frame test. * The fourth RVAD frame test.
* *
* @param ID3_Frame_RVAD $frame The frame to test. * @param ID3_Frame_RVAD $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVAD3 private function frameRVAD3
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$adjustments[ID3_Frame_RVAD::right] = -0xffff; $adjustments[ID3_Frame_RVAD::right] = -0xffff;
$adjustments[ID3_Frame_RVAD::left] = 0xffff; $adjustments[ID3_Frame_RVAD::left] = 0xffff;
@@ -939,7 +926,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$adjustments[ID3_Frame_RVAD::bass] = 0x0; $adjustments[ID3_Frame_RVAD::bass] = 0x0;
$adjustments[ID3_Frame_RVAD::peakBass] = 0x0; $adjustments[ID3_Frame_RVAD::peakBass] = 0x0;
if ($construct) if ($action == self::INITIALIZE)
$frame->setAdjustments($adjustments); $frame->setAdjustments($adjustments);
else else
$this->assertEquals($adjustments, $frame->getAdjustments()); $this->assertEquals($adjustments, $frame->getAdjustments());
@@ -949,14 +936,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first RVRB frame test. * The first RVRB frame test.
* *
* @param ID3_Frame_RVRB $frame The frame to test. * @param ID3_Frame_RVRB $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameRVRB0 private function frameRVRB0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$reverbLeft = $this->testUInt16; $reverbLeft = $this->testUInt16;
$reverbRight = $this->testUInt16 - 1; $reverbRight = $this->testUInt16 - 1;
@@ -969,7 +956,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$premixLtoR = $this->testUInt8 - 6; $premixLtoR = $this->testUInt8 - 6;
$premixRtoL = $this->testUInt8 - 7; $premixRtoL = $this->testUInt8 - 7;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setReverbLeft($reverbLeft); $frame->setReverbLeft($reverbLeft);
$frame->setReverbRight($reverbRight); $frame->setReverbRight($reverbRight);
$frame->setReverbBouncesLeft($reverbBouncesLeft); $frame->setReverbBouncesLeft($reverbBouncesLeft);
@@ -998,18 +985,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first SEEK frame test. * The first SEEK frame test.
* *
* @param ID3_Frame_SEEK $frame The frame to test. * @param ID3_Frame_SEEK $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameSEEK0 private function frameSEEK0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$minOffset = $this->testInt32; $minOffset = $this->testInt32;
if ($construct) if ($action == self::INITIALIZE)
$frame->setMinimumOffset($minOffset); $frame->setMinimumOffset($minOffset);
else else
$this->assertEquals($minOffset, $frame->getMinimumOffset()); $this->assertEquals($minOffset, $frame->getMinimumOffset());
@@ -1019,19 +1006,19 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first SIGN frame test. * The first SIGN frame test.
* *
* @param ID3_Frame_SIGN $frame The frame to test. * @param ID3_Frame_SIGN $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameSIGN0 private function frameSIGN0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$group = $this->testUInt8; $group = $this->testUInt8;
$signature = $this->testText; $signature = $this->testText;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setGroup($group); $frame->setGroup($group);
$frame->setSignature($signature); $frame->setSignature($signature);
} else { } else {
@@ -1044,14 +1031,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first SYLT frame test. * The first SYLT frame test.
* *
* @param ID3_Frame_SYLT $frame The frame to test. * @param ID3_Frame_SYLT $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameSYLT0 private function frameSYLT0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$type = $this->testUInt8; $type = $this->testUInt8;
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
@@ -1061,14 +1048,18 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$events[0xFFFFFF] = $description; $events[0xFFFFFF] = $description;
$events[0xFFFFFFFF] = $description; $events[0xFFFFFFFF] = $description;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setType($type); $frame->setType($type);
$frame->setDescription($description); $frame->setDescription($description);
$frame->setEvents($events); $frame->setEvents($events);
} else { } else {
$this->assertEquals($type, $frame->getType()); $this->assertEquals($type, $frame->getType());
if ($action == self::DRYRUN)
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
$this->assertEquals($events, $frame->getEvents()); else
$this->assertEquals($this->testText, $frame->getDescription());
foreach ($frame->getEvents() as $value)
$this->assertEquals($action == self::DRYRUN ? $description : $this->testText, $value);
} }
} }
@@ -1076,14 +1067,14 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first SYTC frame test. * The first SYTC frame test.
* *
* @param ID3_Frame_SYTC $frame The frame to test. * @param ID3_Frame_SYTC $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameSYTC0 private function frameSYTC0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$events[0] = ID3_Frame_SYTC::BEAT_FREE; $events[0] = ID3_Frame_SYTC::BEAT_FREE;
$events[0xFFFF] = ID3_Frame_SYTC::SINGLE_BEAT; $events[0xFFFF] = ID3_Frame_SYTC::SINGLE_BEAT;
@@ -1091,7 +1082,7 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
$events[0xFFFFFF] = 0xFF + 1; $events[0xFFFFFF] = 0xFF + 1;
$events[0xFFFFFFFF] = 0xFF + 0xFF; $events[0xFFFFFFFF] = 0xFF + 0xFF;
if ($construct) if ($action == self::INITIALIZE)
$frame->setEvents($events); $frame->setEvents($events);
else else
$this->assertEquals($events, $frame->getEvents()); $this->assertEquals($events, $frame->getEvents());
@@ -1101,24 +1092,29 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first TXXX frame test. * The first TXXX frame test.
* *
* @param ID3_Frame_TXXX $frame The frame to test. * @param ID3_Frame_TXXX $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameTXXX0 private function frameTXXX0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
$text = $this->convert($this->testText, $encoding); $text = $this->convert($this->testText, $encoding);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setDescription($description); $frame->setDescription($description);
$frame->setText($text); $frame->setText($text);
} else { } else {
if ($action == self::DRYRUN) {
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
$this->assertEquals($text, $frame->getText()); $this->assertEquals($text, $frame->getText());
} else {
$this->assertEquals($this->testText, $frame->getDescription());
$this->assertEquals($this->testText, $frame->getText());
}
} }
} }
@@ -1126,45 +1122,54 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first USER frame test. * The first USER frame test.
* *
* @param ID3_Frame_USER $frame The frame to test. * @param ID3_Frame_USER $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameUSER0 private function frameUSER0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$text = $this->convert($this->testText, $encoding); $text = $this->convert($this->testText, $encoding);
if ($construct) if ($action == self::INITIALIZE)
$frame->setText($text); $frame->setText($text);
else else {
if ($action == self::DRYRUN)
$this->assertEquals($text, $frame->getText()); $this->assertEquals($text, $frame->getText());
else
$this->assertEquals($this->testText, $frame->getText());
}
} }
/** /**
* The first USLT frame test. * The first USLT frame test.
* *
* @param ID3_Frame_USLT $frame The frame to test. * @param ID3_Frame_USLT $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameUSLT0 private function frameUSLT0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
$text = $this->convert($this->testText, $encoding); $text = $this->convert($this->testText, $encoding);
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setDescription($description); $frame->setDescription($description);
$frame->setText($text); $frame->setText($text);
} else { } else {
if ($action == self::DRYRUN) {
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
$this->assertEquals($text, $frame->getText()); $this->assertEquals($text, $frame->getText());
} else {
$this->assertEquals($this->testText, $frame->getDescription());
$this->assertEquals($this->testText, $frame->getText());
}
} }
} }
@@ -1172,23 +1177,26 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
* The first WXXX frame test. * The first WXXX frame test.
* *
* @param ID3_Frame_WXXX $frame The frame to test. * @param ID3_Frame_WXXX $frame The frame to test.
* @param boolean $construct Whether construction or testing should occur. * @param boolean $action The requested action.
* @param integer $encoding The {@link ID3_Encoding text encoding} for strings * @param integer $encoding The {@link ID3_Encoding text encoding} for strings
* in this frame. * in this frame.
* @param string $language The language code. * @param string $language The language code.
* @param integer $timing The timing format. * @param integer $timing The timing format.
*/ */
private function frameWXXX0 private function frameWXXX0
(&$frame, $construct, $encoding, $language, $timing) (&$frame, $action, $encoding, $language, $timing)
{ {
$description = $this->convert($this->testText, $encoding); $description = $this->convert($this->testText, $encoding);
$link = $this->testLink; $link = $this->testLink;
if ($construct) { if ($action == self::INITIALIZE) {
$frame->setDescription($description); $frame->setDescription($description);
$frame->setLink($link); $frame->setLink($link);
} else { } else {
if ($action == self::DRYRUN)
$this->assertEquals($description, $frame->getDescription()); $this->assertEquals($description, $frame->getDescription());
else
$this->assertEquals($this->testText, $frame->getDescription());
$this->assertEquals($link, $frame->getLink()); $this->assertEquals($link, $frame->getLink());
} }
} }
@@ -1202,17 +1210,20 @@ final class TestID3Frame extends PHPUnit_Framework_TestCase
*/ */
private static function convert($text, $encoding) private static function convert($text, $encoding)
{ {
if ($encoding === null)
$encoding = ID3_Encoding::UTF8;
switch ($encoding) { switch ($encoding) {
case ID3_Encoding::ISO88591: case ID3_Encoding::ISO88591:
return iconv("ascii", "ISO-8859-1", $text); return iconv("utf-8", "iso-8859-1", $text);
case ID3_Encoding::UTF16: case ID3_Encoding::UTF16:
return iconv("ascii", "UTF-16", $text); return iconv("utf-8", "utf-16", $text);
case ID3_Encoding::UTF16LE: case ID3_Encoding::UTF16LE:
return substr(iconv("ascii", "UTF-16LE", $text), 2); return iconv("utf-8", "utf-16le", $text);
case ID3_Encoding::UTF16BE: case ID3_Encoding::UTF16BE:
return iconv("ascii", "UTF-16BE", $text); return iconv("utf-8", "utf-16be", $text);
default: // ID3_Encoding::UTF8 default: // ID3_Encoding::UTF8
return iconv("ascii", "UTF-8", $text); return $text;
} }
} }
} }