Skip to content

Commit 7d8a95e

Browse files
committed
Add tests
1 parent cabe9ea commit 7d8a95e

File tree

7 files changed

+812
-0
lines changed

7 files changed

+812
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\SyliusSEOPlugin\Tests\OpenGraph\Type\Music;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Setono\SyliusSEOPlugin\OpenGraph\OpenGraph;
9+
use Setono\SyliusSEOPlugin\OpenGraph\Type\Music\Album;
10+
11+
final class AlbumTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function it_returns_correct_type(): void
17+
{
18+
$album = new Album();
19+
20+
self::assertSame('music.album', $album->getType());
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function it_returns_empty_html_by_default(): void
27+
{
28+
$album = new Album();
29+
30+
self::assertSame('', $album->toHtml());
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function it_renders_songs(): void
37+
{
38+
$album = new Album(songs: [
39+
'https://example.com/song/1',
40+
'https://example.com/song/2',
41+
]);
42+
43+
$expected = '<meta property="music:song" content="https://example.com/song/1">' . "\n" .
44+
'<meta property="music:song" content="https://example.com/song/2">';
45+
46+
self::assertSame($expected, $album->toHtml());
47+
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function it_renders_song_discs(): void
53+
{
54+
$album = new Album(songDiscs: [1, 2]);
55+
56+
$expected = '<meta property="music:song:disc" content="1">' . "\n" .
57+
'<meta property="music:song:disc" content="2">';
58+
59+
self::assertSame($expected, $album->toHtml());
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function it_renders_song_tracks(): void
66+
{
67+
$album = new Album(songTracks: [1, 5, 10]);
68+
69+
$expected = '<meta property="music:song:track" content="1">' . "\n" .
70+
'<meta property="music:song:track" content="5">' . "\n" .
71+
'<meta property="music:song:track" content="10">';
72+
73+
self::assertSame($expected, $album->toHtml());
74+
}
75+
76+
/**
77+
* @test
78+
*/
79+
public function it_renders_musicians(): void
80+
{
81+
$album = new Album(musicians: ['https://example.com/artist/1']);
82+
83+
self::assertSame('<meta property="music:musician" content="https://example.com/artist/1">', $album->toHtml());
84+
}
85+
86+
/**
87+
* @test
88+
*/
89+
public function it_renders_release_date(): void
90+
{
91+
$date = new \DateTimeImmutable('2024-06-15T00:00:00+00:00');
92+
$album = new Album(releaseDate: $date);
93+
94+
self::assertSame('<meta property="music:release_date" content="2024-06-15T00:00:00+00:00">', $album->toHtml());
95+
}
96+
97+
/**
98+
* @test
99+
*/
100+
public function it_works_with_open_graph(): void
101+
{
102+
$releaseDate = new \DateTimeImmutable('2024-06-15T00:00:00+00:00');
103+
104+
$og = (new OpenGraph())
105+
->title('Greatest Hits')
106+
->type(new Album(
107+
songs: ['https://example.com/song/1'],
108+
musicians: ['https://example.com/artist/1'],
109+
releaseDate: $releaseDate,
110+
));
111+
112+
$html = $og->toHtml();
113+
114+
self::assertStringContainsString('<meta property="og:title" content="Greatest Hits">', $html);
115+
self::assertStringContainsString('<meta property="og:type" content="music.album">', $html);
116+
self::assertStringContainsString('<meta property="music:song" content="https://example.com/song/1">', $html);
117+
self::assertStringContainsString('<meta property="music:musician" content="https://example.com/artist/1">', $html);
118+
self::assertStringContainsString('<meta property="music:release_date" content="2024-06-15T00:00:00+00:00">', $html);
119+
}
120+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\SyliusSEOPlugin\Tests\OpenGraph\Type\Music;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Setono\SyliusSEOPlugin\OpenGraph\OpenGraph;
9+
use Setono\SyliusSEOPlugin\OpenGraph\Type\Music\Playlist;
10+
11+
final class PlaylistTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function it_returns_correct_type(): void
17+
{
18+
$playlist = new Playlist();
19+
20+
self::assertSame('music.playlist', $playlist->getType());
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function it_returns_empty_html_by_default(): void
27+
{
28+
$playlist = new Playlist();
29+
30+
self::assertSame('', $playlist->toHtml());
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function it_renders_songs(): void
37+
{
38+
$playlist = new Playlist(songs: [
39+
'https://example.com/song/1',
40+
'https://example.com/song/2',
41+
]);
42+
43+
$expected = '<meta property="music:song" content="https://example.com/song/1">' . "\n" .
44+
'<meta property="music:song" content="https://example.com/song/2">';
45+
46+
self::assertSame($expected, $playlist->toHtml());
47+
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function it_renders_song_discs(): void
53+
{
54+
$playlist = new Playlist(songDiscs: [1, 2]);
55+
56+
$expected = '<meta property="music:song:disc" content="1">' . "\n" .
57+
'<meta property="music:song:disc" content="2">';
58+
59+
self::assertSame($expected, $playlist->toHtml());
60+
}
61+
62+
/**
63+
* @test
64+
*/
65+
public function it_renders_song_tracks(): void
66+
{
67+
$playlist = new Playlist(songTracks: [1, 5]);
68+
69+
$expected = '<meta property="music:song:track" content="1">' . "\n" .
70+
'<meta property="music:song:track" content="5">';
71+
72+
self::assertSame($expected, $playlist->toHtml());
73+
}
74+
75+
/**
76+
* @test
77+
*/
78+
public function it_renders_creators(): void
79+
{
80+
$playlist = new Playlist(creators: ['https://example.com/profile/1']);
81+
82+
self::assertSame('<meta property="music:creator" content="https://example.com/profile/1">', $playlist->toHtml());
83+
}
84+
85+
/**
86+
* @test
87+
*/
88+
public function it_works_with_open_graph(): void
89+
{
90+
$og = (new OpenGraph())
91+
->title('My Playlist')
92+
->type(new Playlist(
93+
songs: ['https://example.com/song/1'],
94+
creators: ['https://example.com/profile/1'],
95+
));
96+
97+
$html = $og->toHtml();
98+
99+
self::assertStringContainsString('<meta property="og:title" content="My Playlist">', $html);
100+
self::assertStringContainsString('<meta property="og:type" content="music.playlist">', $html);
101+
self::assertStringContainsString('<meta property="music:song" content="https://example.com/song/1">', $html);
102+
self::assertStringContainsString('<meta property="music:creator" content="https://example.com/profile/1">', $html);
103+
}
104+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Setono\SyliusSEOPlugin\Tests\OpenGraph\Type\Music;
6+
7+
use PHPUnit\Framework\TestCase;
8+
use Setono\SyliusSEOPlugin\OpenGraph\OpenGraph;
9+
use Setono\SyliusSEOPlugin\OpenGraph\Type\Music\RadioStation;
10+
11+
final class RadioStationTest extends TestCase
12+
{
13+
/**
14+
* @test
15+
*/
16+
public function it_returns_correct_type(): void
17+
{
18+
$radioStation = new RadioStation();
19+
20+
self::assertSame('music.radio_station', $radioStation->getType());
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function it_returns_empty_html_by_default(): void
27+
{
28+
$radioStation = new RadioStation();
29+
30+
self::assertSame('', $radioStation->toHtml());
31+
}
32+
33+
/**
34+
* @test
35+
*/
36+
public function it_renders_creators(): void
37+
{
38+
$radioStation = new RadioStation(creators: [
39+
'https://example.com/profile/1',
40+
'https://example.com/profile/2',
41+
]);
42+
43+
$expected = '<meta property="music:creator" content="https://example.com/profile/1">' . "\n" .
44+
'<meta property="music:creator" content="https://example.com/profile/2">';
45+
46+
self::assertSame($expected, $radioStation->toHtml());
47+
}
48+
49+
/**
50+
* @test
51+
*/
52+
public function it_works_with_open_graph(): void
53+
{
54+
$og = (new OpenGraph())
55+
->title('Cool FM')
56+
->type(new RadioStation(creators: ['https://example.com/profile/1']));
57+
58+
$html = $og->toHtml();
59+
60+
self::assertStringContainsString('<meta property="og:title" content="Cool FM">', $html);
61+
self::assertStringContainsString('<meta property="og:type" content="music.radio_station">', $html);
62+
self::assertStringContainsString('<meta property="music:creator" content="https://example.com/profile/1">', $html);
63+
}
64+
}

0 commit comments

Comments
 (0)