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

toStorageValue() public method

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

Usage Example

 /**
  * @covers \eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\Converter\AuthorConverter::toStorageValue
  */
 public function testToStorageValue()
 {
     $value = new FieldValue();
     $value->data = $this->authors;
     $storageFieldValue = new StorageFieldValue();
     $this->converter->toStorageValue($value, $storageFieldValue);
     $doc = new DOMDocument('1.0', 'utf-8');
     self::assertTrue($doc->loadXML($storageFieldValue->dataText));
     $authorsXml = $doc->getElementsByTagName('author');
     self::assertSame(count($this->authors), $authorsXml->length);
     // Loop against XML nodes and compare them to the real Author objects.
     // Then remove Author from $this->authors
     // This way, we can check if all authors have been converted in XML
     foreach ($authorsXml as $authorXml) {
         foreach ($this->authors as $i => $author) {
             if ($authorXml->getAttribute('id') == $author['id']) {
                 self::assertSame($author['name'], $authorXml->getAttribute('name'));
                 self::assertSame($author['email'], $authorXml->getAttribute('email'));
                 unset($this->authors[$i]);
                 break;
             }
         }
     }
     self::assertEmpty($this->authors, 'All authors have not been converted as expected');
 }