Skip to content

Commit dbbfbf2

Browse files
author
Aarjan Langereis
committed
According to https://schema.org/Event, Event should extend Thing
1 parent 4d43922 commit dbbfbf2

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/ContextTypes/Event.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
namespace JsonLd\ContextTypes;
44

5-
class Event extends AbstractContext
5+
class Event extends Thing
66
{
77
/**
88
* Property structure
99
*
1010
* @var array
1111
*/
12-
protected $structure = [
12+
protected $extendedStructure = [
1313
'name' => null,
1414
'startDate' => null,
1515
'endDate' => null,
@@ -18,7 +18,20 @@ class Event extends AbstractContext
1818
'location' => Place::class,
1919
];
2020

21-
/**
21+
/**
22+
* Constructor. Merges extendedStructure up
23+
*
24+
* @param array $attributes
25+
* @param array $extendedStructure
26+
*/
27+
public function __construct(array $attributes, array $extendedStructure = [])
28+
{
29+
parent::__construct(
30+
$attributes, array_merge($this->structure, $this->extendedStructure, $extendedStructure)
31+
);
32+
}
33+
34+
/**
2235
* Set offers attributes.
2336
*
2437
* @param mixed $values

tests/ContextTypes/EventTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class EventTest extends TestCase
2727
'postalCode' => '06514',
2828
],
2929
],
30+
'image' => 'https://google.com/some_logo.png',
31+
'description' => 'A description',
3032
];
3133

3234
/**
@@ -64,4 +66,28 @@ public function shouldHaveLocationObject()
6466
],
6567
], $context->getProperty('location'));
6668
}
69+
70+
/**
71+
* @test
72+
*/
73+
public function shouldHaveImage()
74+
{
75+
$context = $this->make();
76+
77+
$this->assertEquals(
78+
'https://google.com/some_logo.png'
79+
, $context->getProperty('image'));
80+
}
81+
82+
/**
83+
* @test
84+
*/
85+
public function shouldHaveDescription()
86+
{
87+
$context = $this->make();
88+
89+
$this->assertEquals(
90+
'A description'
91+
, $context->getProperty('description'));
92+
}
6793
}

0 commit comments

Comments
 (0)