Skip to content

Commit 46193bd

Browse files
committed
Add some tests
1 parent fe16392 commit 46193bd

File tree

7 files changed

+476
-5
lines changed

7 files changed

+476
-5
lines changed

src/Tags/Audio.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class Audio extends Tag
2525
];
2626

2727
/**
28-
* @return mixed
28+
* @return string
2929
*/
30-
public function getUrl()
30+
public function getUrl(): string
3131
{
3232
return $this->url;
3333
}
3434

3535
/**
3636
* @param string $url
3737
*
38-
* @return Video
38+
* @return Audio
3939
*/
4040
public function setUrl(string $url): Audio
4141
{
@@ -49,7 +49,7 @@ public function setUrl(string $url): Audio
4949
*
5050
* @throws OpenGraphException
5151
*
52-
* @return Image
52+
* @return Audio
5353
*/
5454
public function setAttributes(array $attributes): Audio
5555
{
@@ -66,6 +66,14 @@ public function setAttributes(array $attributes): Audio
6666
return $this;
6767
}
6868

69+
/**
70+
* @return array
71+
*/
72+
public function getAttributes(): array
73+
{
74+
return $this->attributes;
75+
}
76+
6977
public function render()
7078
{
7179
$this->getOpenGraph()->render([

src/Tags/Music.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public function setAttrAlbum(array $attrAlbum): Music
123123
*/
124124
public function getReleaseDate(): \DateTime
125125
{
126-
return $this->release_date;
126+
return new \DateTime($this->release_date);
127127
}
128128

129129
/**

tests/Unit/src/Tags/AudioTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
namespace umanskyi31\opengraph\test\Unit\src\Tags;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use umanskyi31\opengraph\OpenGraph;
6+
use umanskyi31\opengraph\Tags\Audio;
7+
8+
class AudioTest extends TestCase
9+
{
10+
/**
11+
* @var OpenGraph
12+
*/
13+
protected $opengraph;
14+
15+
protected function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->opengraph = new OpenGraph();
20+
}
21+
22+
public function testSetUrl()
23+
{
24+
$audio = new Audio($this->opengraph);
25+
26+
$url = 'https://umanskyi.com/test.mp3';
27+
28+
$audio->setUrl($url);
29+
30+
$this->assertSame($url, $audio->getUrl());
31+
32+
}
33+
34+
public function testSetAttribute()
35+
{
36+
$audio = new Audio($this->opengraph);
37+
38+
$attr = [
39+
'type' => 'test',
40+
'secure_url' => 'https://umanskyi.com/test.mp3'
41+
];
42+
43+
$audio->setAttributes($attr);
44+
45+
$this->assertEquals($attr, $audio->getAttributes());
46+
}
47+
48+
/**
49+
* @expectedException \Exception
50+
* @expectedExceptionMessage Invalid values
51+
* @expectedExceptionCode 500
52+
*/
53+
public function testSetAttributeFailure()
54+
{
55+
$audio = new Audio($this->opengraph);
56+
57+
$attr = [
58+
'type' => 'test',
59+
'secure_url' => 'https://umanskyi.com/test.mp3',
60+
'not_valid_url' => 'test'
61+
];
62+
63+
$audio->setAttributes($attr);
64+
65+
$this->assertEquals($attr, $audio->getAttributes());
66+
}
67+
68+
}

tests/Unit/src/Tags/BookTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
namespace umanskyi31\opengraph\test\Unit\src\Tags;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use umanskyi31\opengraph\OpenGraph;
6+
use umanskyi31\opengraph\Tags\Book;
7+
8+
class BookTest extends TestCase
9+
{
10+
/**
11+
* @var OpenGraph
12+
*/
13+
protected $opengraph;
14+
15+
protected function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->opengraph = new OpenGraph();
20+
}
21+
22+
public function testAuthor()
23+
{
24+
$book = new Book($this->opengraph);
25+
26+
$authors = ['John Doe', 'Mike Doe'];
27+
28+
$book->setAuthor($authors);
29+
30+
$this->assertSame($authors, $book->getAuthor());
31+
}
32+
33+
public function testReleaseDate()
34+
{
35+
$book = new Book($this->opengraph);
36+
37+
$date = new \DateTime('2011-01-01');
38+
39+
$book->setReleaseDate($date);
40+
41+
$this->assertEquals($date, $book->getReleaseDate());
42+
}
43+
44+
public function testTag()
45+
{
46+
$book = new Book($this->opengraph);
47+
48+
$tags = ['Avatar', 'Game'];
49+
50+
$book->setTag($tags);
51+
52+
$this->assertSame($tags, $book->getTag());
53+
}
54+
55+
public function testIsbn()
56+
{
57+
$book = new Book($this->opengraph);
58+
59+
$isbn = '9305581bn34';
60+
61+
$book->setIsbn($isbn);
62+
63+
$this->assertSame($isbn, $book->getIsbn());
64+
}
65+
}

tests/Unit/src/Tags/ImageTest.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace umanskyi31\opengraph\test\Unit\src\Tags;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use umanskyi31\opengraph\OpenGraph;
6+
use umanskyi31\opengraph\Tags\Image;
7+
8+
class ImageTest extends TestCase
9+
{
10+
/**
11+
* @var OpenGraph
12+
*/
13+
protected $opengraph;
14+
15+
protected function setUp()
16+
{
17+
parent::setUp();
18+
19+
$this->opengraph = new OpenGraph();
20+
}
21+
22+
public function testSetUrl()
23+
{
24+
$audio = new Image($this->opengraph);
25+
26+
$url = 'https://umanskyi.com/test.png';
27+
28+
$audio->setUrl($url);
29+
30+
$this->assertSame($url, $audio->getUrl());
31+
32+
}
33+
34+
public function testSetAttribute()
35+
{
36+
$audio = new Image($this->opengraph);
37+
38+
$attr = [
39+
'width' => 10,
40+
'height' => 10,
41+
'type' => 'jpg',
42+
'alt' => 'Test',
43+
'secure_url' => 'https://umanskyi.com/test.png'
44+
];
45+
46+
$audio->setAttributes($attr);
47+
48+
$this->assertEquals($attr, $audio->getAttributes());
49+
}
50+
51+
/**
52+
* @expectedException \Exception
53+
* @expectedExceptionMessage Invalid values
54+
* @expectedExceptionCode 500
55+
*/
56+
public function testSetAttributeFailure()
57+
{
58+
$audio = new Image($this->opengraph);
59+
60+
$attr = [
61+
'type' => 'jpg',
62+
'secure_url' => 'https://umanskyi.com/test.jpg',
63+
'not_valid_url' => 'test'
64+
];
65+
66+
$audio->setAttributes($attr);
67+
68+
$this->assertEquals($attr, $audio->getAttributes());
69+
}
70+
}

0 commit comments

Comments
 (0)