-
Notifications
You must be signed in to change notification settings - Fork 3
Feature adding test #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
axel2309
wants to merge
12
commits into
un-zero-un:master
Choose a base branch
from
axel2309:feature-adding-test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5945097
Added more test cases and resolve sf4.2 deprecation
axel2309 391a19e
adding Twig extension to render AST in a html template
axel2309 e580491
fixed code inspection faill due to the multiple supported version of …
axel2309 60afe22
More test with unknown generic block type
axel2309 0b6cba1
added Twig Extension test and more html rendering test
axel2309 8622bfe
added php7.4 test support
axel2309 487c1dc
added test on Twig getFunction
axel2309 0f0f9bb
Added more coverage on IsoContentExtension
axel2309 572d360
added more JsonRenderer test
axel2309 f36c99d
Fix deprecation error durring build
axel2309 80a22ee
test name in snake_case ans cs fix
axel2309 8d1227d
fixed typo
axel2309 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| parameters: | ||
| reportUnmatchedIgnoredErrors: false | ||
| excludes_analyse: | ||
| - 'vendor/*' | ||
|
|
||
| ignoreErrors: | ||
| # Symfony 3.4 compatibility | ||
| - '/Call to function method_exists\(\) with .Symfony\\\\Component…. and .getRootNode. will always evaluate to false/' | ||
| - '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).#' | ||
| - '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::getRootNode\(\)/' | ||
| - '/Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)/' | ||
| - '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder constructor invoked with 0 parameters, 1-3 required./' | ||
| - '/Class Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder does not have a constructor and must be instantiated without any parameters/' |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
src/Bridge/Symfony/Bundle/Extension/Twig/IsoContentExtension.php
This file contains hidden or 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,28 @@ | ||
| <?php | ||
|
|
||
| namespace Isocontent\Bridge\Symfony\Bundle\Extension\Twig; | ||
|
|
||
| use Isocontent\AST\NodeList; | ||
| use Isocontent\Renderer\HTMLRenderer; | ||
| use Twig\Extension\AbstractExtension; | ||
| use Twig\TwigFunction; | ||
|
|
||
| /** | ||
| * Twig extension for displaying IsoContent | ||
| * | ||
| * @author Yohan Giarelli <[email protected]> | ||
| */ | ||
| class IsoContentExtension extends AbstractExtension | ||
| { | ||
| public function getFunctions() | ||
| { | ||
| return [ | ||
| new TwigFunction('display_isocontent', [$this, 'displayIsoContent']), | ||
| ]; | ||
| } | ||
|
|
||
| public function displayIsoContent(NodeList $ast): ?string | ||
| { | ||
| return (new HTMLRenderer)->render($ast); | ||
| } | ||
| } |
86 changes: 86 additions & 0 deletions
86
tests/Bridge/Symfony/Bundle/Extension/Twig/IsoContentExtensionTest.php
This file contains hidden or 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,86 @@ | ||
| <?php | ||
|
|
||
| namespace Isocontent\Tests\Bridge\Symfony\Bundle\Extension\Twig; | ||
|
|
||
| use Isocontent\AST\BlockNode; | ||
| use Isocontent\AST\NodeList; | ||
| use Isocontent\AST\TextNode; | ||
| use Isocontent\Bridge\Symfony\Bundle\Extension\Twig\IsoContentExtension; | ||
| use PHPUnit\Framework\TestCase; | ||
| use Twig\TwigFunction; | ||
|
|
||
| class IsoContentExtensionTest extends TestCase | ||
| { | ||
| /** | ||
| * @dataProvider astProvider | ||
| */ | ||
| public function testDisplayIsoContentFunction(NodeList $ast, string $expect) | ||
|
||
| { | ||
| $extension = new IsoContentExtension(); | ||
| $this->assertEquals($expect, $extension->displayIsoContent($ast)); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider functionProvider | ||
| */ | ||
| public function testGetTwigFunctions(string $expect,TwigFunction $function) | ||
| { | ||
| $this->assertSame($expect, $function->getName()); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing new line |
||
| public function testGetFunction(){ | ||
| $extension = new IsoContentExtension(); | ||
| $this->assertTrue(is_array($extension->getFunctions())); | ||
| $functions = $extension->getFunctions(); | ||
| $this->assertInstanceOf(TwigFunction::class,$functions[0]); | ||
| } | ||
| public static function astProvider() | ||
| { | ||
| return [ | ||
| [ | ||
| NodeList::fromArray([TextNode::fromText('Foo')]), | ||
| 'Foo', | ||
| ], | ||
| [ | ||
| NodeList::fromArray([ | ||
| BlockNode::fromBlockType('inline_text', [], NodeList::fromArray([ | ||
| TextNode::fromText('Foo') | ||
| ])), | ||
| ]), | ||
| '<span>Foo</span>', | ||
| ], | ||
| [ | ||
| NodeList::fromArray([ | ||
| BlockNode::fromBlockType('paragraph', [], NodeList::fromArray([ | ||
| TextNode::fromText('Some paragraph '), | ||
| BlockNode::fromBlockType('inline_text', [], NodeList::fromArray([ | ||
| TextNode::fromText('with some inline text'), | ||
| ])), | ||
| BlockNode::fromBlockType('list', ['ordered' => false], NodeList::fromArray([ | ||
| BlockNode::fromBlockType('list_item', [], NodeList::fromArray([ | ||
| TextNode::fromText('Unsorted'), | ||
| ])), | ||
| BlockNode::fromBlockType('list_item', [], NodeList::fromArray([ | ||
| TextNode::fromText('data'), | ||
| ])) | ||
| ])) | ||
| ])), | ||
| ]), | ||
| '<p>Some paragraph <span>with some inline text</span><ul><li>Unsorted</li><li>data</li></ul></p>' | ||
| ], | ||
| [ | ||
| NodeList::fromArray([]), | ||
| '' | ||
| ], | ||
|
|
||
| ]; | ||
| } | ||
|
|
||
| public function functionProvider() | ||
| { | ||
| $extension = new IsoContentExtension(); | ||
| $function = $extension->getFunctions(); | ||
| return[ | ||
| ['display_isocontent', $function[0]], | ||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing