Skip to content

Commit

Permalink
Removed Laravel related stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyhuy committed Jan 4, 2020
1 parent e67a485 commit dcf6a87
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 203 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean tincidunt urna m

## Contribution

- Project derived from [Graham Campbell](https://github.com/GrahamCampbell)'s [emoji parser](https://github.com/AltThree/Emoji) for Laravel 5.
- Project derived from [Graham Campbell](https://github.com/GrahamCampbell)'s [emoji parser](https://github.com/AltThree/Emoji) for Laravel
- **Johnny Huynh** - Initial changes

## License
Expand Down
11 changes: 1 addition & 10 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "johnnyhuy/laravel-useful-commonmark-extension",
"type": "library",
"description": "Laravel useful CommonMark extension for Laravel 5",
"description": "Laravel useful CommonMark extension for Laravel 5, 6 & 7",
"keywords": ["youtube", "php", "laravel", "markdown", "commonmark", "phpleague", "laravel-package"],
"license": "MIT",
"authors": [
Expand All @@ -21,15 +21,11 @@
"require": {
"php": "^7.1.3",
"ext-json": "*",
"laravel/framework": "~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0",
"league/commonmark": "^1.1.0",
"spatie/commonmark-highlighter": "^2.1"
},
"require-dev": {
"mockery/mockery": "^1.2",
"graham-campbell/analyzer": "^2.0",
"graham-campbell/markdown": "^11.1.0",
"graham-campbell/testbench": "^5.0",
"phpunit/phpunit": "^7.0"
},
"autoload": {
Expand All @@ -48,11 +44,6 @@
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
},
"laravel": {
"providers": [
"JohnnyHuy\\Laravel\\UsefulCommonMarkExtensionServiceProvider"
]
}
},
"minimum-stability": "stable"
Expand Down
1 change: 0 additions & 1 deletion src/Inline/Renderer/CodepenRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function render(AbstractInline $inline, ElementRendererInterface $htmlRen

// Use a oEmbed route to get codepen details
$apiUrl = "https://codepen.io/api/oembed?url={$inline->getUrl()}&format=json";

$apiResponse = $this->getContent($apiUrl);

//seems that the used codepen url is invalid
Expand Down
34 changes: 0 additions & 34 deletions src/UsefulCommonMarkExtensionServiceProvider.php

This file was deleted.

43 changes: 2 additions & 41 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,8 @@

namespace JohnnyHuy\Laravel\Markdown\Tests;

use GrahamCampbell\Markdown\MarkdownServiceProvider;
use GrahamCampbell\TestBench\AbstractPackageTestCase;
use Illuminate\Contracts\Foundation\Application;
use JohnnyHuy\Laravel\UsefulCommonMarkExtension;
use JohnnyHuy\Laravel\UsefulCommonMarkExtensionServiceProvider;
use PHPUnit\Framework\TestCase;

class BaseTestCase extends AbstractPackageTestCase
class BaseTestCase extends TestCase
{
/**
* Setup the application environment.
*
* @param Application $app
*
* @return void
*/
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app->config->set('markdown.extensions', [UsefulCommonMarkExtension::class]);
}

/**
* Get the required service providers.
*
* @param Application $app
*
* @return string[]
*/
protected function getRequiredServiceProviders($app)
{
return [MarkdownServiceProvider::class];
}

/**
* Get the service provider class.
*
* @param string $app
* @return string
*/
protected function getServiceProviderClass($app)
{
return UsefulCommonMarkExtensionServiceProvider::class;
}
}
34 changes: 31 additions & 3 deletions tests/Elements/Block/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace JohnnyHuy\Laravel\Markdown\Tests\Elements\Block;

use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use JohnnyHuy\Laravel\Block\Element\BlockColor;
use JohnnyHuy\Laravel\Block\Parser\ColorParser;
use JohnnyHuy\Laravel\Block\Renderer\ColorBlockRenderer;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use PHPUnit\Framework\ExpectationFailedException;
use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

/**
Expand Down Expand Up @@ -51,7 +57,18 @@ public function failedStrings()
*/
public function testShouldRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addBlockParser(new ColorParser());
$environment->addBlockRenderer(BlockColor::class, new ColorBlockRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}

/**
Expand All @@ -63,6 +80,17 @@ public function testShouldRender($input, $output)
*/
public function testShouldNotRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addBlockParser(new ColorParser());
$environment->addBlockRenderer(BlockColor::class, new ColorBlockRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}
}
34 changes: 31 additions & 3 deletions tests/Elements/Block/TextAlignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

namespace JohnnyHuy\Laravel\Markdown\Tests\Elements\Block;

use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use JohnnyHuy\Laravel\Block\Element\TextAlignment;
use JohnnyHuy\Laravel\Block\Parser\TextAlignmentParser;
use JohnnyHuy\Laravel\Block\Renderer\TextAlignmentRenderer;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use PHPUnit\Framework\ExpectationFailedException;
use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

/**
Expand Down Expand Up @@ -48,7 +54,18 @@ public function failedStrings()
*/
public function testShouldRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addBlockParser(new TextAlignmentParser());
$environment->addBlockRenderer(TextAlignment::class, new TextAlignmentRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}

/**
Expand All @@ -60,6 +77,17 @@ public function testShouldRender($input, $output)
*/
public function testShouldNotRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addBlockParser(new TextAlignmentParser());
$environment->addBlockRenderer(TextAlignment::class, new TextAlignmentRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}
}
32 changes: 26 additions & 6 deletions tests/Elements/Inline/CodepenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace JohnnyHuy\Laravel\Markdown\Tests\Elements\Inline;

use JohnnyHuy\Laravel\Inline\Renderer\CodepenRenderer;
use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use Mockery;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use JohnnyHuy\Laravel\Inline\Element\Codepen;
use PHPUnit\Framework\ExpectationFailedException;
use JohnnyHuy\Laravel\Inline\Parser\CodepenParser;
use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use JohnnyHuy\Laravel\Inline\Renderer\CodepenRenderer;
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

/**
Expand Down Expand Up @@ -50,16 +56,20 @@ public function failedStrings()
public function testShouldRender($input, $output)
{
// Arrange
$mock = Mockery::mock(CodepenRenderer::class)
$rendererMock = Mockery::mock(CodepenRenderer::class)
->makePartial()
->shouldReceive('getContent')
->withAnyArgs()
->once()
->andReturn(file_get_contents(__DIR__ . '/../../Fakes/CodePen.json'));
$this->app->instance(CodepenRenderer::class, $mock->getMock());
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addInlineParser(new CodepenParser());
$environment->addInlineRenderer(Codepen::class, $rendererMock->getMock());

// Act
$html = $this->app->markdown->convertToHtml($input);
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
Expand All @@ -74,6 +84,16 @@ public function testShouldRender($input, $output)
*/
public function testShouldNotRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addInlineParser(new CodepenParser());
$environment->addInlineRenderer(Codepen::class, new CodepenRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Assert
$this->assertSame("$output\n", $html);
}
}
38 changes: 35 additions & 3 deletions tests/Elements/Inline/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

namespace JohnnyHuy\Laravel\Markdown\Tests\Elements\Inline;

use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use JohnnyHuy\Laravel\Block\Parser\ColorParser;
use JohnnyHuy\Laravel\Inline\Element\InlineColor;
use JohnnyHuy\Laravel\Inline\Parser\CloseColorParser;
use JohnnyHuy\Laravel\Inline\Parser\OpenColorParser;
use JohnnyHuy\Laravel\Inline\Renderer\ColorInlineRenderer;
use PHPUnit\Framework\ExpectationFailedException;
use JohnnyHuy\Laravel\Markdown\Tests\BaseTestCase;
use SebastianBergmann\RecursionContext\InvalidArgumentException;

/**
Expand Down Expand Up @@ -46,7 +54,19 @@ public static function failedStrings(): array
*/
public function testShouldRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addInlineParser(new CloseColorParser());
$environment->addInlineParser(new OpenColorParser());
$environment->addInlineRenderer(InlineColor::class, new ColorInlineRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}

/**
Expand All @@ -58,6 +78,18 @@ public function testShouldRender($input, $output)
*/
public function testShouldNotRender($input, $output)
{
$this->assertSame("$output\n", $this->app->markdown->convertToHtml($input));
// Arrange
$environment = Environment::createCommonMarkEnvironment();
$parser = new DocParser($environment);
$htmlRenderer = new HtmlRenderer($environment);
$environment->addInlineParser(new CloseColorParser());
$environment->addInlineParser(new OpenColorParser());
$environment->addInlineRenderer(InlineColor::class, new ColorInlineRenderer());

// Act
$html = $htmlRenderer->renderBlock($parser->parse($input));

// Arrange
$this->assertSame("$output\n", $html);
}
}
Loading

0 comments on commit dcf6a87

Please sign in to comment.