Skip to content

Commit eb7456d

Browse files
authored
Merge pull request #39 from boly38/feature/website
improve WebSite context
2 parents 9d85b71 + edf2607 commit eb7456d

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

src/ContextTypes/WebSite.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class WebSite extends AbstractContext
1515
'image' => null,
1616
'name' => null,
1717
'url' => null,
18+
'publisher' => Organization::class,
1819
'keywords' => null,
20+
'inLanguage' => null,
21+
'dateCreated' => null,
22+
'dateModified' => null,
23+
'datePublished' => null,
1924
'sameAs' => null,
2025
];
2126
}

tests/ContextTypes/ArticleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class ArticleTest extends TestCase
3636
'height' => 60,
3737
]
3838
],
39+
'keywords' => 'Lorem,ipsum,dolor',
40+
'inLanguage' => 'en',
3941
'dateCreated' => '2013-10-04T00:00',
4042
'dateModified' => '2013-10-04T00:00',
4143
'datePublished' => '2013-10-04T00:00',
@@ -130,6 +132,26 @@ public function shouldHavePublisherObject()
130132
], $context->getProperty('publisher'));
131133
}
132134

135+
/**
136+
* @test
137+
*/
138+
public function shouldHaveKeywords()
139+
{
140+
$context = $this->make();
141+
142+
$this->assertEquals('Lorem,ipsum,dolor', $context->getProperty('keywords'));
143+
}
144+
145+
/**
146+
* @test
147+
*/
148+
public function shouldHaveInLanguage()
149+
{
150+
$context = $this->make();
151+
152+
$this->assertEquals('en', $context->getProperty('inLanguage'));
153+
}
154+
133155
/**
134156
* @test
135157
*/

tests/ContextTypes/WebSiteTest.php

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ class WebSiteTest extends TestCase
1010

1111
protected $attributes = [
1212
'about' => 'The subject matter of the content.',
13-
'headline' => 'Headline of the article.',
13+
'headline' => 'Headline of the website.',
1414
'image' => 'https://og.github.com/mark/github-mark@1200x630.png',
1515
'name' => 'The name of the item.',
1616
'url' => 'https://schema.org/WebSite',
17+
'publisher' => [
18+
'name' => 'Google',
19+
'logo' => [
20+
'@type' => 'ImageObject',
21+
'url' => 'https://google.com/logo.jpg',
22+
'width' => 600,
23+
'height' => 60,
24+
]
25+
],
1726
'keywords' => 'about,headline,image,name,url',
27+
'inLanguage' => 'en',
28+
'dateCreated' => '2013-10-04T00:00',
29+
'dateModified' => '2013-10-04T00:00',
30+
'datePublished' => '2013-10-04T00:00',
1831
'sameAs' => 'https://schema.org/sameAs',
1932
];
2033

@@ -25,9 +38,60 @@ public function shouldGetProperties()
2538
{
2639
$context = $this->make();
2740

28-
$this->assertEquals(array_merge([
29-
'@context' => 'http://schema.org',
30-
'@type' => 'WebSite',
31-
], $this->attributes), $context->getProperties());
41+
$attributesPlus = $this->attributes;
42+
$attributesPlus['@context'] = 'http://schema.org';
43+
$attributesPlus["@type"] = 'WebSite';
44+
$attributesPlus["publisher"]["@type"] = 'Organization';
45+
46+
$this->assertEquals($context->getProperties(), $attributesPlus);
47+
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function shouldHaveHeadline()
53+
{
54+
$context = $this->make();
55+
56+
$this->assertEquals('Headline of the website.', $context->getProperty('headline'));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function shouldHavePublisherObject()
63+
{
64+
$context = $this->make();
65+
66+
$this->assertEquals([
67+
'@type' => 'Organization',
68+
'name' => 'Google',
69+
'logo' => [
70+
'@type' => 'ImageObject',
71+
'url' => 'https://google.com/logo.jpg',
72+
'height' => 60,
73+
'width' => 600,
74+
],
75+
], $context->getProperty('publisher'));
76+
}
77+
78+
/**
79+
* @test
80+
*/
81+
public function shouldHaveKeywords()
82+
{
83+
$context = $this->make();
84+
85+
$this->assertEquals('about,headline,image,name,url', $context->getProperty('keywords'));
86+
}
87+
88+
/**
89+
* @test
90+
*/
91+
public function shouldHaveInLanguage()
92+
{
93+
$context = $this->make();
94+
95+
$this->assertEquals('en', $context->getProperty('inLanguage'));
3296
}
3397
}

0 commit comments

Comments
 (0)