-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Petro Sokolnykov
committed
Nov 27, 2017
1 parent
595d1cc
commit 7259f2b
Showing
8 changed files
with
308 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace sokolnikov911\YandexTurboPages; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class CounterTest extends TestCase | ||
{ | ||
public function testAppendTo() | ||
{ | ||
$counterType = uniqid(); | ||
$counterId = uniqid(); | ||
$counter = new Counter($counterType, $counterId); | ||
$channel = new Channel(); | ||
$this->assertSame($counter, $counter->appendTo($channel)); | ||
$this->assertAttributeSame([$counter], 'counters', $channel); | ||
} | ||
|
||
public function testCounterAttributes() | ||
{ | ||
$counterType = uniqid(); | ||
$counterId = uniqid(); | ||
$counter = new Counter($counterType, $counterId); | ||
$this->assertAttributeEquals($counterType, 'type', $counter); | ||
$this->assertAttributeEquals($counterId, 'id', $counter); | ||
} | ||
|
||
public function testAsXML() | ||
{ | ||
$counterType = uniqid(); | ||
$counterId = uniqid(); | ||
|
||
$counter = new Counter($counterType, $counterId); | ||
|
||
$expect = ' | ||
<yandex:analytics id="' . $counterId . '" type="' . $counterType . '"/> | ||
'; | ||
$this->assertXmlStringEqualsXmlString($expect, $counter->asXML()->asXML()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
<?php | ||
|
||
namespace sokolnikov911\YandexTurboPages; | ||
|
||
use Mockery; | ||
use PHPUnit\Framework\TestCase; | ||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; | ||
|
||
class ItemTest extends TestCase | ||
{ | ||
use MockeryPHPUnitIntegration; | ||
|
||
private $relatedItemsListInterface = '\sokolnikov911\YandexTurboPages\RelatedItemsList'; | ||
|
||
public function testTitle() | ||
{ | ||
$title = uniqid(); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->title($title)); | ||
$this->assertAttributeSame($title, 'title', $item); | ||
} | ||
|
||
public function testLink() | ||
{ | ||
$link = uniqid(); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->link($link)); | ||
$this->assertAttributeSame($link, 'link', $item); | ||
} | ||
|
||
public function testTurboContent() | ||
{ | ||
$turboContent = uniqid(); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->turboContent($turboContent)); | ||
$this->assertAttributeSame($turboContent, 'turboContent', $item); | ||
} | ||
|
||
public function testCategory() | ||
{ | ||
$category = uniqid(); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->category($category)); | ||
$this->assertAttributeSame($category, 'category', $item); | ||
} | ||
|
||
public function testAuthor() | ||
{ | ||
$author = uniqid(); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->author($author)); | ||
$this->assertAttributeSame($author, 'author', $item); | ||
} | ||
|
||
public function testPubDate() | ||
{ | ||
$pubDate = mt_rand(1000000, 9999999); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->pubDate($pubDate)); | ||
$this->assertAttributeSame($pubDate, 'pubDate', $item); | ||
} | ||
|
||
public function testAppendTo() | ||
{ | ||
$item = new Item(); | ||
$channel = new Channel(); | ||
$this->assertSame($channel, $channel->addItem($item)); | ||
$this->assertAttributeSame([$item], 'items', $channel); | ||
} | ||
|
||
public function testCdataTurboContent() | ||
{ | ||
$content = '<div>content</div>'; | ||
$pubDate = time(); | ||
|
||
$item = new Item();; | ||
$this->assertSame($item, $item->pubDate($pubDate)); | ||
$this->assertSame($item, $item->turboContent($content)); | ||
$this->assertAttributeSame($content, 'turboContent', $item); | ||
|
||
$feed = new Feed(); | ||
$channel = new Channel(); | ||
$item->appendTo($channel); | ||
$channel->appendTo($feed); | ||
|
||
$expected = '<?xml version="1.0" encoding="UTF-8"?> | ||
<rss xmlns:yandex="http://news.yandex.ru" xmlns:media="http://search.yahoo.com/mrss/" xmlns:turbo="http://turbo.yandex.ru" version="2.0"> | ||
<channel> | ||
<title/> | ||
<link/> | ||
<description/> | ||
<item turbo="true"> | ||
<title/> | ||
<link/> | ||
<turbo:content xmlns:turbo="http://turbo.yandex.ru"><![CDATA[' . $content . ']]></turbo:content> | ||
<pubDate>' . date(DATE_RSS, $pubDate). '</pubDate> | ||
</item> | ||
</channel> | ||
</rss>'; | ||
$this->assertXmlStringEqualsXmlString($expected, strval($feed)); | ||
} | ||
|
||
public function testAddRelatedItemList() | ||
{ | ||
$relatedItemsList = Mockery::mock($this->relatedItemsListInterface); | ||
$item = new Item(); | ||
$this->assertSame($item, $item->addRelatedItemsList($relatedItemsList)); | ||
$this->assertAttributeSame($relatedItemsList, 'relatedItemsList', $item); | ||
} | ||
|
||
public function testAsXML() | ||
{ | ||
$data = $this->dataForXmlTests(); | ||
|
||
$item = new Item(); | ||
$item | ||
->author($data['author']) | ||
->pubDate($data['now']) | ||
->title($data['title']) | ||
->link($data['link']) | ||
->turboContent($data['turboContent']) | ||
->category($data['category']); | ||
|
||
$expect = ' | ||
<item turbo="true"> | ||
<title>' . $data['title'] . '</title> | ||
<link>' . $data['link'] . '</link> | ||
<turbo:content xmlns:turbo="http://turbo.yandex.ru"><![CDATA[' . $data['turboContent'] . ']]></turbo:content> | ||
<pubDate>' . $data['pubDate'] . '</pubDate> | ||
<category>' . $data['category'] . '</category> | ||
<author>' . $data['author'] . '</author> | ||
</item> | ||
'; | ||
|
||
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML()); | ||
} | ||
|
||
public function testAsXMLWithRelated() | ||
{ | ||
$data = $this->dataForXmlTests(); | ||
|
||
$item = new Item(); | ||
$item | ||
->author($data['author']) | ||
->pubDate($data['now']) | ||
->title($data['title']) | ||
->link($data['link']) | ||
->turboContent($data['turboContent']) | ||
->category($data['category']); | ||
|
||
$relatedItemsList = new RelatedItemsList(); | ||
$item->addRelatedItemsList($relatedItemsList); | ||
|
||
$expect = ' | ||
<item turbo="true"> | ||
<title>' . $data['title'] . '</title> | ||
<link>' . $data['link'] . '</link> | ||
<turbo:content xmlns:turbo="http://turbo.yandex.ru"><![CDATA[' . $data['turboContent'] . ']]></turbo:content> | ||
<pubDate>' . $data['pubDate'] . '</pubDate> | ||
<category>' . $data['category'] . '</category> | ||
<author>' . $data['author'] . '</author> | ||
<yandex:related/> | ||
</item> | ||
'; | ||
|
||
$this->assertXmlStringEqualsXmlString($expect, $item->asXML()->asXML()); | ||
} | ||
|
||
private function dataForXmlTests() | ||
{ | ||
$now = time(); | ||
|
||
$data = [ | ||
'now' => $now, | ||
'pubDate' => date(DATE_RSS, $now), | ||
'title' => 'Thirst page!', | ||
'link' => 'http://www.example.com/page1.html', | ||
'turboContent' => 'Some content here!<br>Second content string.', | ||
'author' => 'John Smith', | ||
'category' => 'Auto', | ||
]; | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace sokolnikov911\YandexTurboPages; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class RelatedItemTest extends TestCase | ||
{ | ||
public function testAppendTo() | ||
{ | ||
$relatedItem = new RelatedItem('Title', 'http://site.com/page.html', 'http://site.com/img.jpg'); | ||
$relatedItemsList = new RelatedItemsList(); | ||
$this->assertSame($relatedItem, $relatedItem->appendTo($relatedItemsList)); | ||
$this->assertAttributeSame([$relatedItem], 'relatedItems', $relatedItemsList); | ||
} | ||
|
||
public function testAttributes() | ||
{ | ||
$relatedItem = new RelatedItem('Title', 'http://site.com/page.html', 'http://site.com/img.jpg'); | ||
$this->assertAttributeEquals('Title', 'title', $relatedItem); | ||
$this->assertAttributeEquals('http://site.com/page.html', 'link', $relatedItem); | ||
$this->assertAttributeEquals('http://site.com/img.jpg', 'img', $relatedItem); | ||
} | ||
|
||
public function testAsXML() | ||
{ | ||
$relatedItem = new RelatedItem('Title', 'http://site.com/page.html', 'http://site.com/img.jpg'); | ||
$expect = '<link url="http://site.com/page.html" img="http://site.com/img.jpg">Title</link>'; | ||
$this->assertXmlStringEqualsXmlString($expect, $relatedItem->asXML()->asXML()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/sokolnikov911/YandexTurboPages/RelatedItemsListTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace sokolnikov911\YandexTurboPages; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class RelatedItemsListTest extends TestCase | ||
{ | ||
public function testAppendTo() | ||
{ | ||
$relatedItemsList = new RelatedItemsList(); | ||
$item = new Item(); | ||
$this->assertSame($relatedItemsList, $relatedItemsList->appendTo($item)); | ||
$this->assertAttributeSame($relatedItemsList, 'relatedItemsList', $item); | ||
} | ||
|
||
public function testAddItem() | ||
{ | ||
$relatedItem = new RelatedItem('Title', 'http://www.site.com/page.html' | ||
, 'http://www.site.com/image.jpg'); | ||
$relatedItemsList = new RelatedItemsList(); | ||
$this->assertSame($relatedItemsList, $relatedItemsList->addItem($relatedItem)); | ||
$this->assertAttributeSame([$relatedItem], 'relatedItems', $relatedItemsList); | ||
} | ||
|
||
public function testAsXML() | ||
{ | ||
$relatedItemsList = new RelatedItemsList(); | ||
$expect = '<yandex:related/>'; | ||
$this->assertXmlStringEqualsXmlString($expect, $relatedItemsList->asXML()->asXML()); | ||
} | ||
|
||
public function testAsXMLWithRelatedPage() | ||
{ | ||
$relatedItemsList = new RelatedItemsList(); | ||
$relatedItem = new RelatedItem('Title', 'http://www.site.com/page.html' | ||
, 'http://www.site.com/image.jpg'); | ||
$this->assertSame($relatedItemsList, $relatedItemsList->addItem($relatedItem)); | ||
$expect = ' | ||
<yandex:related> | ||
<link url="http://www.site.com/page.html" img="http://www.site.com/image.jpg">Title</link> | ||
</yandex:related> | ||
'; | ||
$this->assertXmlStringEqualsXmlString($expect, $relatedItemsList->asXML()->asXML()); | ||
} | ||
} |