Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/MicrodataPhpDOMElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ public function itemValue() {
if (!empty($datetime))
return $datetime;
default:
return $this->textContent;
if ($this->getAttribute('content')) {
return $this->getAttribute('content');
} else {
return $this->textContent;
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions tests/data/recipe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>recipe test</title>
</head>
<body>
<div itemscope itemtype="http://schema.org/Recipe">
<span itemprop="name">Mom's World Famous Banana Bread</span>
By <span itemprop="author">John Smith</span>,
<meta itemprop="datePublished" content="2009-05-08">
May 8, 2009
<img itemprop="image" src="bananabread.jpg"
alt="Banana bread on a plate"/>
<span itemprop="description">This classic banana bread recipe comes
from my mom -- the walnuts add a nice texture and flavor to the banana
bread.</span>
Prep Time:
<meta itemprop="prepTime" content="PT15M">
15 minutes
Cook time:
<meta itemprop="cookTime" content="PT1H">
1 hour
Yield: <span itemprop="recipeYield">1 loaf</span>

<div itemprop="nutrition"
itemscope itemtype="http://schema.org/NutritionInformation">
Nutrition facts:
<span itemprop="calories">240 calories</span>,
<span itemprop="fatContent">9 grams fat</span>
</div>
Ingredients:
- <span itemprop="recipeIngredient">3 or 4 ripe bananas, smashed</span>
- <span itemprop="recipeIngredient">1 egg</span>
- <span itemprop="recipeIngredient">3/4 cup of sugar</span>
...
Instructions:
<span itemprop="recipeInstructions">
Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add
the flour last. Pour the mixture into a loaf pan and bake for one hour.
</span>
140 comments:
<meta itemprop="interactionCount" content="UserComments:140"/>
From Janel, May 5 -- thank you, great recipe!
...
</div>
</body>
</html>
59 changes: 59 additions & 0 deletions tests/data/recipeItempropContent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>recipe itemprop content</title>
</head>
<body>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>recipe test</title>
</head>
<body>
<div itemscope itemtype="http://schema.org/Recipe">
<span itemprop="name">Mom's World Famous Banana Bread</span>
By <span itemprop="author">John Smith</span>,
<meta itemprop="datePublished" content="2009-05-08">
May 8, 2009
<img itemprop="image" src="bananabread.jpg"
alt="Banana bread on a plate"/>
<span itemprop="description">This classic banana bread recipe comes
from my mom -- the walnuts add a nice texture and flavor to the banana
bread.</span>
Prep Time:
<span itemprop="prepTime" content="PT1H10M">1 hour, 10 minutes</span>
Cook time:
<span itemprop="cookTime" content="PT15M">15 minutes</span>

Yield: <span itemprop="recipeYield">1 loaf</span>

<div itemprop="nutrition"
itemscope itemtype="http://schema.org/NutritionInformation">
Nutrition facts:
<span itemprop="calories">240 calories</span>,
<span itemprop="fatContent">9 grams fat</span>
</div>
Ingredients:
- <span itemprop="recipeIngredient">3 or 4 ripe bananas, smashed</span>
- <span itemprop="recipeIngredient">1 egg</span>
- <span itemprop="recipeIngredient">3/4 cup of sugar</span>
...
Instructions:
<span itemprop="recipeInstructions">
Preheat the oven to 350 degrees. Mix in the ingredients in a bowl. Add
the flour last. Pour the mixture into a loaf pan and bake for one hour.
</span>
140 comments:
<meta itemprop="interactionCount" content="UserComments:140"/>
From Janel, May 5 -- thank you, great recipe!
...
</div>
</body>
</html>


</body>
</html>
22 changes: 22 additions & 0 deletions tests/src/MicrodataPhpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ public function testNestedItem() {
$this->assertEquals($address->properties['addressCountry'][0], "Germany", 'addressCountry property of nested item should be Germany.');
}

/**
* test recipe prep time
*/
public function testRecipePrepTimeType() {
$config = $this->getConfig('recipe.html');
$microdata = new MicrodataPhp($config);
$data = $microdata->obj();

$this->assertEquals("PT15M", $data->items[0]->properties['prepTime'][0], 'recipe prepTime should be PT15M');
}

/**
* test recipe prep time
*/
public function testRecipePrepTimeContentType() {
$config = $this->getConfig('recipeItempropContent.html');
$microdata = new MicrodataPhp($config);
$data = $microdata->obj();

$this->assertEquals("PT1H10M", $data->items[0]->properties['prepTime'][0], 'recipe prepTime should be PT1H10M');
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down