-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
3 changed files
with
61 additions
and
37 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
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,60 @@ | ||
<?php | ||
|
||
class TestTimberPostPreview extends WP_UnitTestCase { | ||
|
||
function testDoubleEllipsis(){ | ||
$post_id = $this->factory->post->create(); | ||
$post = new TimberPost($post_id); | ||
$post->post_excerpt = 'this is super dooper trooper long words'; | ||
$prev = $post->get_preview(3, true); | ||
$this->assertEquals(1, substr_count($prev, '…')); | ||
} | ||
|
||
function testGetPreview() { | ||
global $wp_rewrite; | ||
$struc = false; | ||
$wp_rewrite->permalink_structure = $struc; | ||
update_option('permalink_structure', $struc); | ||
$post_id = $this->factory->post->create(array('post_content' => 'this is super dooper trooper long words')); | ||
$post = new TimberPost($post_id); | ||
|
||
// no excerpt | ||
$post->post_excerpt = ''; | ||
$preview = $post->get_preview(3); | ||
$this->assertRegExp('/this is super … <a href="http:\/\/example.org\/\?p=\d+" class="read-more">Read More<\/a>/', $preview); | ||
|
||
// excerpt set, force is false, no read more | ||
$post->post_excerpt = 'this is excerpt longer than three words'; | ||
$preview = $post->get_preview(3, false, ''); | ||
$this->assertEquals($preview, $post->post_excerpt); | ||
|
||
// custom read more set | ||
$post->post_excerpt = ''; | ||
$preview = $post->get_preview(3, false, 'Custom more'); | ||
$this->assertRegExp('/this is super … <a href="http:\/\/example.org\/\?p=\d+" class="read-more">Custom more<\/a>/', $preview); | ||
|
||
// content with <!--more--> tag, force false | ||
$post->post_content = 'this is super dooper<!--more--> trooper long words'; | ||
$preview = $post->get_preview(2, false, ''); | ||
$this->assertEquals('this is super dooper', $preview); | ||
} | ||
|
||
function testShortcodesInPreviewFromContent() { | ||
add_shortcode('mythang', function($text) { | ||
return 'mythangy'; | ||
}); | ||
$pid = $this->factory->post->create( array('post_content' => 'jared [mythang]', 'post_excerpt' => '') ); | ||
$post = new TimberPost( $pid ); | ||
$this->assertEquals('jared mythangy … <a href="'.$post->link().'" class="read-more">Read More</a>', $post->get_preview()); | ||
} | ||
|
||
function testShortcodesInPreviewFromContentWithMoreTag() { | ||
add_shortcode('duck', function($text) { | ||
return 'Quack!'; | ||
}); | ||
$pid = $this->factory->post->create( array('post_content' => 'jared [duck] <!--more--> joojoo', 'post_excerpt' => '') ); | ||
$post = new TimberPost( $pid ); | ||
$this->assertEquals('jared Quack! <a href="'.$post->link().'" class="read-more">Read More</a>', $post->get_preview()); | ||
} | ||
|
||
} |
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