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
Showing
2 changed files
with
206 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
<?php | ||
/** | ||
* User: Salavat Sitdikov | ||
*/ | ||
|
||
namespace SSitdikov\TelegraphAPI\Tests\Page; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SSitdikov\TelegraphAPI\Type\ContentType\ImageType; | ||
use SSitdikov\TelegraphAPI\Type\ContentType\LinkType; | ||
use SSitdikov\TelegraphAPI\Type\ContentType\ParagraphType; | ||
use SSitdikov\TelegraphAPI\Type\ContentType\YoutubeType; | ||
|
||
class ContentTypesTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function linkType() | ||
{ | ||
$link = new LinkType(); | ||
$link->setText('Test link'); | ||
$link->setHref('https://github.com'); | ||
|
||
$this->assertJson(json_encode([ | ||
'tag' => 'a', | ||
'attrs' => ['href' => 'https://github.com'], | ||
'children' => ['Test link'] | ||
]), json_encode($link)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function imageType() | ||
{ | ||
$image = new ImageType(); | ||
$image->setSrc('https://github.com/logo.png'); | ||
|
||
$this->assertJson(json_encode([ | ||
'tag' => 'img', | ||
'attrs' => [ | ||
'src' => 'https://github.com/logo.png', | ||
] | ||
]), json_encode($image)); | ||
|
||
$image->setCaption('Test caption'); | ||
|
||
$this->assertJson(json_encode([ | ||
'tag' => 'figure', | ||
'children' => [ | ||
[ | ||
'tag' => 'img', | ||
'attrs' => ['src' => 'https://github.com/logo.png'], | ||
], | ||
[ | ||
'tag' => 'figcaption', | ||
'children' => [ | ||
'Test caption' | ||
] | ||
] | ||
] | ||
]), json_encode($image)); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function paragraphType() | ||
{ | ||
$paragraph = new ParagraphType(); | ||
$paragraph->setText('Test'); | ||
|
||
$this->assertJson( | ||
json_encode([ | ||
'tag' => 'p', | ||
'children' => [ | ||
'Test' | ||
] | ||
]), | ||
json_encode($paragraph) | ||
); | ||
|
||
$paragraph->addContentElement( | ||
$paragraph | ||
); | ||
|
||
$this->assertJson( | ||
json_encode([ | ||
'tag' => 'p', | ||
'children' => [ | ||
'Test', | ||
[ | ||
'tag' => 'p', | ||
'children' => [ | ||
'Test' | ||
] | ||
] | ||
] | ||
]), | ||
json_encode($paragraph) | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function youtubeType() | ||
{ | ||
$youtube = new YoutubeType(); | ||
$youtube->setSrc('test'); | ||
$youtube->setCaption('Caption'); | ||
|
||
$this->assertJson( | ||
json_encode([ | ||
'tag' => 'figure', | ||
'children' => [ | ||
[ | ||
'tag' => 'iframe', | ||
'attrs' => [ | ||
'src' => 'test', | ||
] | ||
], | ||
[ | ||
'tag' => 'figcaption', | ||
'children' => [ | ||
'Caption' | ||
] | ||
] | ||
] | ||
]), | ||
json_encode($youtube) | ||
); | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
/** | ||
* User: Salavat Sitdikov | ||
*/ | ||
|
||
namespace SSitdikov\TelegraphAPI\Tests\Page; | ||
|
||
use SSitdikov\TelegraphAPI\Request\CreatePageRequest; | ||
use PHPUnit\Framework\TestCase; | ||
use SSitdikov\TelegraphAPI\Request\RequestInterface; | ||
use SSitdikov\TelegraphAPI\Type\Account; | ||
use SSitdikov\TelegraphAPI\Type\ContentType\LinkType; | ||
use SSitdikov\TelegraphAPI\Type\Page; | ||
|
||
class CreatePageRequestTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function simpleCreatePageRequest() | ||
{ | ||
$title = md5(random_bytes(16)); | ||
$accessToken = md5(random_bytes(16)); | ||
$content = []; | ||
|
||
$page = new Page(); | ||
$page->setTitle($title); | ||
$page->setContent($content); | ||
|
||
$account = new Account(); | ||
$account->setAccessToken($accessToken); | ||
|
||
$request = new CreatePageRequest($page, $account); | ||
|
||
$this->assertEquals(RequestInterface::POST, $request->getMethod()); | ||
$this->assertEquals('createPage', $request->getUrlRequest()); | ||
|
||
$expectedParams = [ | ||
'json' => [ | ||
'access_token' => $accessToken, | ||
'title' => $title, | ||
'content' => $content, | ||
] | ||
]; | ||
$this->assertEquals( $expectedParams, $request->getParams()); | ||
$authorUrl = md5(random_bytes(16)); | ||
$authorName = md5(random_bytes(16)); | ||
|
||
$page->setAuthorUrl($authorUrl); | ||
$page->setAuthorName($authorName); | ||
|
||
$request = new CreatePageRequest($page, $account); | ||
|
||
$request->isReturnContent(); | ||
$expectedParams = [ | ||
'json' => [ | ||
'access_token' => $accessToken, | ||
'title' => $title, | ||
'content' => $content, | ||
'author_name' => $authorName, | ||
'author_url' => $authorUrl, | ||
'return_content' => true | ||
] | ||
]; | ||
|
||
$this->assertEquals($expectedParams, $request->getParams()); | ||
} | ||
|
||
} |