eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\AuthorConverter::toFieldValue PHP Method

toFieldValue() public method

Converts data from $value to $fieldValue.
public toFieldValue ( StorageFieldValue $value, eZ\Publish\SPI\Persistence\Content\FieldValue $fieldValue )
$value eZ\Publish\Core\Persistence\Legacy\Content\StorageFieldValue
$fieldValue eZ\Publish\SPI\Persistence\Content\FieldValue
    public function toFieldValue(StorageFieldValue $value, FieldValue $fieldValue)
    {
        $fieldValue->data = $this->restoreValueFromXmlString($value->dataText);
    }

Usage Example

    /**
     * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\AuthorConverter::toFieldValue
     */
    public function testToFieldValue()
    {
        $storageFieldValue = new StorageFieldValue();
        $storageFieldValue->dataText = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<ezauthor>
    <authors>
        <author id="1" name="Boba Fett" email="*****@*****.**"/>
        <author id="2" name="Darth Vader" email="*****@*****.**"/>
        <author id="3" name="Luke Skywalker" email="*****@*****.**"/>
    </authors>
</ezauthor>
EOT;
        $doc = new DOMDocument('1.0', 'utf-8');
        self::assertTrue($doc->loadXML($storageFieldValue->dataText));
        $authorsXml = $doc->getElementsByTagName('author');
        $fieldValue = new FieldValue();
        $this->converter->toFieldValue($storageFieldValue, $fieldValue);
        self::assertInternalType('array', $fieldValue->data);
        $authorsXml = $doc->getElementsByTagName('author');
        self::assertSame($authorsXml->length, count($fieldValue->data));
        $aAuthors = $fieldValue->data;
        foreach ($fieldValue->data as $i => $author) {
            foreach ($authorsXml as $authorXml) {
                if ($authorXml->getAttribute('id') == $author['id']) {
                    self::assertSame($authorXml->getAttribute('name'), $author['name']);
                    self::assertSame($authorXml->getAttribute('email'), $author['email']);
                    unset($aAuthors[$i]);
                    break;
                }
            }
        }
        self::assertEmpty($aAuthors, 'All authors have not been converted as expected from storage');
    }