/**
  * @param Schema $schema
  * @param int $indentLevel
  */
 protected function generatePropertiesJsonLd(Schema $schema, $indentLevel = 0)
 {
     $propertyKeys = array_keys($schema->getProperties());
     $lastProperty = end($propertyKeys);
     /**
      * @var string|Schema $value
      */
     foreach ($schema->getProperties() as $property => $value) {
         if ($lastProperty == $property) {
             $isExcludeComma = true;
         } else {
             $isExcludeComma = false;
         }
         if ($value instanceof Schema) {
             $this->append('"' . $property . '": {', $indentLevel, true);
             $this->append('"@type": "' . $value->getType() . '"', $indentLevel + 1, !(bool) $value->getProperties());
             $this->generatePropertiesJsonLd($value, $indentLevel + 1);
             $this->append('}', $indentLevel, $isExcludeComma);
         } else {
             $value = htmlentities($value);
             $this->append('"' . $property . '": "' . $value . '"', $indentLevel, $isExcludeComma);
         }
     }
 }
 public function testOutputMicrodata()
 {
     $this->expectOutputString($this->schema->getMicrodata());
     $this->schema->outputMicrodata();
 }
Exemple #3
0
 public function testGetSchemaValue()
 {
     $propertyName = 'name';
     $name = 'Author';
     $schema = new Schema('Book');
     $schema->addProperty($propertyName, $name);
     $this->expectOutputString($name);
     $schema->outputProperty($propertyName);
 }
 public function testOutputJsonLd()
 {
     $this->expectOutputString($this->schema->getJsonLd());
     $this->schema->outputJsonLd();
 }