-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
4 changed files
with
71 additions
and
67 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 |
---|---|---|
@@ -1,39 +1,33 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Services\Parser\Parsers; | ||
|
||
use Tests\TestCase; | ||
use Coyote\Repositories\Eloquent\WordRepository; | ||
use Coyote\Services\Parser\Parsers\Censore; | ||
|
||
class CensoreTest extends TestCase | ||
class CensoreTest extends \Tests\TestCase | ||
{ | ||
/** | ||
* @var \Coyote\Services\Parser\Parsers\Censore | ||
*/ | ||
protected $parser; | ||
protected Censore $parser; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$word = new \Coyote\Repositories\Eloquent\WordRepository(app()); | ||
$this->parser = new \Coyote\Services\Parser\Parsers\Censore($word); | ||
$this->parser = new Censore(new WordRepository(app())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function testHashCodeTag() | ||
{ | ||
$text = '<code></code><code>kurczak'; | ||
|
||
$result = $this->parser->parse($text); | ||
$this->assertEquals($result, $text); | ||
|
||
$text = '<code><code><code></code><code>kurczak'; | ||
|
||
$result = $this->parser->parse($text); | ||
$this->assertEquals($result, $text); | ||
|
||
$text = '</code></code><code>kurczak'; | ||
$this->assertIdentity('<code></code><code>kurczak'); | ||
$this->assertIdentity('<code><code><code></code><code>kurczak'); | ||
$this->assertIdentity('</code></code><code>kurczak'); | ||
} | ||
|
||
$result = $this->parser->parse($text); | ||
$this->assertEquals($result, $text); | ||
private function assertIdentity(string $content): void | ||
{ | ||
$this->assertSame( | ||
$this->parser->parse($content), | ||
$content); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,58 +1,42 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Services\Parser\Parsers; | ||
|
||
use Coyote\Services\Parser\Parsers\Purifier; | ||
use Tests\TestCase; | ||
|
||
class PurifierTest extends TestCase | ||
class PurifierTest extends \Tests\TestCase | ||
{ | ||
public function testParseLinks() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<a href="http://www.wp.pl">http://www.wp.pl</a>'; | ||
$this->assertEquals($input, $parser->parse($input)); | ||
$this->assertIdentity('<a href="http://www.wp.pl">http://www.wp.pl</a>'); | ||
} | ||
|
||
public function testParseBlockquotes() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<blockquote>lorem ipsum<blockquote>lorem ipsum</blockquote></blockquote>'; | ||
$this->assertEquals($input, $parser->parse($input)); | ||
$this->assertIdentity('<blockquote>lorem ipsum<blockquote>lorem ipsum</blockquote></blockquote>'); | ||
} | ||
|
||
public function testParseUnderscore() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<u>foo</u>'; | ||
$this->assertEquals($input, $parser->parse($input)); | ||
$this->assertIdentity('<u>foo</u>'); | ||
} | ||
|
||
public function testAllowKbd() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<kbd>Ctrl</kbd>'; | ||
$this->assertEquals($input, $parser->parse($input)); | ||
$this->assertIdentity('<kbd>Ctrl</kbd>'); | ||
} | ||
|
||
public function testAllowMark() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<mark>Ctrl</mark>'; | ||
$this->assertEquals($input, $parser->parse($input)); | ||
$this->assertIdentity('<mark>Ctrl</mark>'); | ||
} | ||
|
||
public function testAllowIframeInsideSpan() | ||
{ | ||
$parser = new Purifier(); | ||
|
||
$input = '<p><span class="embed-responsive embed-responsive-16by9"><iframe src="https://youtube.com/embed/enOjqwOE1ec" class="embed-responsive-item"></iframe></span></p>'; | ||
$this->assertSame($input, $parser->parse($input)); | ||
$this->assertIdentity('<p><span class="embed-responsive embed-responsive-16by9"><iframe src="https://youtube.com/embed/enOjqwOE1ec" class="embed-responsive-item"></iframe></span></p>'); | ||
} | ||
|
||
private function assertIdentity(string $input): void | ||
{ | ||
$this->assertEquals($input, (new Purifier())->parse($input)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Services\Parser\Parsers; | ||
|
||
use Coyote\Repositories\Eloquent\PageRepository; | ||
use Coyote\Repositories\Eloquent\UserRepository; | ||
use Coyote\Services\Parser\Parsers\SimpleMarkdown; | ||
use Tests\TestCase; | ||
|
||
class SimpleMarkdownTest extends TestCase | ||
class SimpleMarkdownTest extends \Tests\TestCase | ||
{ | ||
public function testDoNotChangeLineBreaks() | ||
{ | ||
$markdown = new SimpleMarkdown($this->app[UserRepository::class], $this->app[PageRepository::class], 'host'); | ||
|
||
$input = "one\ntwo\nthree"; | ||
$this->assertEquals($input, trim($markdown->parse($input))); | ||
$this->assertIdentity($markdown, "one\ntwo\nthree\n"); | ||
} | ||
|
||
public function testAutolinkExtension() | ||
{ | ||
$markdown = new SimpleMarkdown($this->app[UserRepository::class], $this->app[PageRepository::class], 'host'); | ||
|
||
$link = 'https://docs.djangoproject.com/en/2.0/#first-steps'; | ||
$this->assertEquals("<a href=\"$link\">$link</a>", trim($markdown->parse($link))); | ||
$this->assertEquals("<a href=\"$link\">$link</a>\n", $markdown->parse($link)); | ||
} | ||
|
||
private function assertIdentity(SimpleMarkdown $markdown, string $input): void | ||
{ | ||
$this->assertEquals($input, $markdown->parse($input)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,46 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Services\Parser\Parsers; | ||
|
||
use Coyote\Services\Parser\Parsers\Smilies; | ||
use Tests\TestCase; | ||
|
||
class SmiliesTest extends TestCase | ||
class SmiliesTest extends \Tests\TestCase | ||
{ | ||
// tests | ||
public function testParseSmilies() | ||
/** | ||
* @test | ||
*/ | ||
public function test() | ||
{ | ||
$parser = new Smilies(); | ||
$this->assertSame('<img class="img-smile" alt=":)" title=":)" src="/img/smilies/smile.gif">', $parser->parse(':)')); | ||
} | ||
|
||
$this->assertMatchesRegularExpression('/<img class="img-smile" alt="\:\)" title="\:\)" src=\"\/img\/smilies\/smile\.gif\">/', $parser->parse(':)')); | ||
$this->assertMatchesRegularExpression('/<p><img class="img-smile" alt="\:\)" title="\:\)" src="\/img\/smilies\/smile.gif"><\/p>/', $parser->parse('<p>:)</p>')); | ||
$this->assertMatchesRegularExpression('/\(\:\)\)/', $parser->parse('(:))')); | ||
$this->assertEquals('admin:)', $parser->parse('admin:)')); | ||
/** | ||
* @test | ||
*/ | ||
public function smileInParenthesis() | ||
{ | ||
$this->assertIdentity(new Smilies(), '(:))'); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function smileInParagraph() | ||
{ | ||
$parser = new Smilies(); | ||
$this->assertSame('<p><img class="img-smile" alt=":)" title=":)" src="/img/smilies/smile.gif"></p>', $parser->parse('<p>:)</p>')); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function smileAfterWord() | ||
{ | ||
$this->assertIdentity(new Smilies(), 'admin:)'); | ||
} | ||
|
||
private function assertIdentity(Smilies $parser, string $text): void | ||
{ | ||
$this->assertEquals($text, $parser->parse($text)); | ||
} | ||
} |