diff --git a/tests/phpunit/tests/content-parser/class-test-markpub.php b/tests/phpunit/tests/content-parser/class-test-markpub.php index 2fa50e5..bf59ea3 100644 --- a/tests/phpunit/tests/content-parser/class-test-markpub.php +++ b/tests/phpunit/tests/content-parser/class-test-markpub.php @@ -82,7 +82,7 @@ public function test_converts_headings() { $content = '
echo "hello";';
$result = $this->parser->parse( $content, $post );
- $md = $result['text']['markdown'];
- $this->assertStringContainsString( '```', $md );
- $this->assertStringContainsString( 'echo "hello";', $md );
+ $this->assertSame( "```\necho \"hello\";\n```", $result['text']['markdown'] );
}
/**
@@ -174,7 +172,7 @@ public function test_converts_separator() {
. 'After
'; $result = $this->parser->parse( $content, $post ); - $this->assertStringContainsString( '---', $result['text']['markdown'] ); + $this->assertSame( "Before\n\n---\n\nAfter", $result['text']['markdown'] ); } /** @@ -188,22 +186,33 @@ public function test_empty_content() { /** * Test the atmosphere_html_to_markdown filter. + * + * Verifies the filter callback receives ($markdown, $content) so + * callers can inspect the raw source alongside the conversion. */ public function test_html_to_markdown_filter() { + $received = array(); + \add_filter( 'atmosphere_html_to_markdown', - static fn() => 'custom markdown', + static function ( $markdown, $content ) use ( &$received ) { + $received = array( + 'markdown' => $markdown, + 'content' => $content, + ); + return 'custom markdown'; + }, 10, 2 ); $post = self::factory()->post->create_and_get(); - $result = $this->parser->parse( - 'Hello
', - $post - ); + $source = 'Hello
'; + $result = $this->parser->parse( $source, $post ); $this->assertSame( 'custom markdown', $result['text']['markdown'] ); + $this->assertSame( 'Hello', $received['markdown'] ); + $this->assertSame( $source, $received['content'] ); \remove_all_filters( 'atmosphere_html_to_markdown' ); } @@ -265,4 +274,318 @@ public function test_parse_returns_null_when_markdown_is_empty() { $this->assertNull( $this->parser->parse( $content, $post ) ); } + + /** + * Test ordered list produces numbered markdown. + */ + public function test_listing_ordered() { + $post = self::factory()->post->create_and_get(); + $content = "\n' + . ''; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( '> Paragraph text', $result['text']['markdown'] ); + } + + /** + * Test quote block prefixes every inner line. + */ + public function test_quote_prefixes_every_line() { + $post = self::factory()->post->create_and_get(); + $content = 'Paragraph text
' + . '
' + . ''; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( "> First\n> Second", $result['text']['markdown'] ); + } + + /** + * Test quote falls back to innerHTML when no innerBlocks are present. + */ + public function test_quote_innerhtml_fallback() { + $post = self::factory()->post->create_and_get(); + $content = 'First
' + . 'Second
' + . '
Direct quote text'; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( '> Direct quote text', $result['text']['markdown'] ); + } + + /** + * Test core/group containers flatten inner block markdown. + */ + public function test_container_group() { + $post = self::factory()->post->create_and_get(); + $content = '
Inside group
' + . 'Inside columns
' + . 'Inside column
' + . 'Inside unknown
' + . 'After
'; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( 'After', $result['text']['markdown'] ); + } + + /** + * Test heading defaults to level 2 when attrs.level is missing. + */ + public function test_heading_defaults_to_level_2() { + $post = self::factory()->post->create_and_get(); + $content = 'After
'; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( 'After', $result['text']['markdown'] ); + } + + /** + * Test whitespace-only paragraph block is skipped cleanly. + * + * Mixed with a non-empty sibling so a regression returning "" from + * paragraph() would produce a leading blank line and fail the exact + * assertion (the whole-post empty guard would otherwise hide it). + */ + public function test_paragraph_whitespace_is_skipped_cleanly() { + $post = self::factory()->post->create_and_get(); + $content = "\n\n" + . '
After
'; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( 'After', $result['text']['markdown'] ); + } + + /** + * Test code block emits the configured language in the fence. + */ + public function test_code_emits_language_fence() { + $post = self::factory()->post->create_and_get(); + $content = 'echo 1;';
+
+ $result = $this->parser->parse( $content, $post );
+
+ $this->assertStringStartsWith( "```php\n", $result['text']['markdown'] );
+ }
+
+ /**
+ * Test code block decodes HTML entities inside the fence.
+ */
+ public function test_code_decodes_html_entities() {
+ $post = self::factory()->post->create_and_get();
+ $content = '<div>';
+
+ $result = $this->parser->parse( $content, $post );
+
+ $this->assertSame( "```\nSee Foo.
'; + + $result = $this->parser->parse( $content, $post ); + $md = $result['text']['markdown']; + + $this->assertStringContainsString( '%28bar%29', $md ); + $this->assertStringNotContainsString( '(bar)', $md ); + } + + /** + * Testline1
line2
AT&T’s
'; + + $result = $this->parser->parse( $content, $post ); + $md = $result['text']['markdown']; + + $this->assertStringContainsString( 'AT&T', $md ); + $this->assertStringContainsString( "\xE2\x80\x99", $md ); + } + + /** + * Test inlineLook
here
bold italic
'; + + $result = $this->parser->parse( $content, $post ); + + $this->assertSame( '**bold *italic***', $result['text']['markdown'] ); + } }