function testTermToString() { $term_id = $this->factory->term->create(array('name' => 'New England Patriots')); $term = new TimberTerm('new-england-patriots'); $str = Timber::compile_string('{{term}}', array('term' => $term)); $this->assertEquals('New England Patriots', $str); }
function testTwigFilterDateWordPressOption() { $format = get_option('date_format'); $str = Timber::compile_string("{{now|date('" . $format . "')}}"); $empty = Timber::compile_string("{{now|date}}"); $this->assertSame($str, $empty); }
function testACFGetFieldTermTag() { $tid = $this->factory->term->create(); update_field('color', 'green', 'post_tag_' . $tid); $term = new TimberTerm($tid); $str = '{{term.color}}'; $this->assertEquals('green', Timber::compile_string($str, array('term' => $term))); }
function testLinkOnSubdirectoryInstall() { update_option('siteurl', 'http://example.org/wordpress', true); $context = Timber::get_context(); $theme = $context['site']->theme; $output = Timber::compile_string('{{site.theme.link}}', $context); $this->assertEquals('http://example.org/wp-content/themes/' . $theme->slug, $output); }
function testGetData() { $_GET['foo'] = 'bar'; $template = '{{request.get.foo}}'; $context = Timber::get_context(); $str = Timber::compile_string($template, $context); $this->assertEquals('bar', $str); }
function testTypeMethodInTwigLabels() { $post_id = $this->factory->post->create(); $post = new TimberPost($post_id); $template = '{{post.type.labels.name}}'; $str = Timber::compile_string($template, array('post' => $post)); $this->assertEquals('Posts', $str); }
function testPreviewWithSpaceInMoreTag() { $pid = $this->factory->post->create(array('post_content' => 'Lauren is a duck, but a great duck let me tell you why <!--more--> Lauren is not a duck', 'post_excerpt' => '')); $post = new TimberPost($pid); $template = '{{post.preview.length(3).force}}'; $str = Timber::compile_string($template, array('post' => $post)); $this->assertEquals('Lauren is a… <a href="' . $post->link() . '" class="read-more">Read More</a>', $str); }
function testImageResizeRetinaFilterNotAnImage() { self::enable_error_log(false); $str = 'Image? {{"/wp-content/uploads/2016/07/stuff.jpg"|retina(3)}}'; $compiled = Timber::compile_string($str); $this->assertEquals('Image? /wp-content/uploads/2016/07/stuff.jpg', $compiled); self::enable_error_log(true); }
function testPostCustomFieldPropertyConflict() { $post_id = $this->factory->post->create(array('post_title' => 'foo')); update_post_meta($post_id, 'post_title', 'bar'); $post = new TimberPost($post_id); $str = '{{post.title}}'; $result = Timber::compile_string($str, array('post' => $post)); $this->assertEquals('foo', $result); }
function testUnderscoreTypeCustomField() { $post_id = $this->factory->post->create(); update_post_meta($post_id, '_type', 'numberwang'); $post = new TimberPost($post_id); $template = '{{post._type}}'; $str = Timber::compile_string($template, array('post' => $post)); $this->assertEquals('numberwang', $str); }
function testModifiedTimeFilter() { $pid = $this->factory->post->create(); $post = new TimberPost($pid); add_filter('get_the_modified_time', function ($the_date) { return 'foobar'; }); $twig = "I was modified {{post.modified_time('F j, Y @ g:i a')}}"; $str = Timber::compile_string($twig, array('post' => $post)); $this->assertEquals('I was modified foobar', $str); }
function testDescription() { $uid = $this->factory->user->create(array('display_name' => 'Baberaham Lincoln')); update_user_meta($uid, 'description', 'Sixteenth President'); $user = new TimberUser($uid); $this->assertEquals('Sixteenth President', $user->description); $pid = $this->factory->post->create(array('post_author' => $uid)); $post = new TimberPost($pid); $str = Timber::compile_string('{{post.author.description}}', array('post' => $post)); $this->assertEquals('Sixteenth President', $str); }
function testJPEGtoJPG() { $filename = TestTimberImage::copyTestImage('jarednova.jpeg'); $str = Timber::compile_string('{{file|tojpg}}', array('file' => $filename)); $renamed = str_replace('.jpeg', '.jpg', $filename); $this->assertFileExists($renamed); $this->assertGreaterThan(1000, filesize($renamed)); $this->assertEquals('image/jpeg', mime_content_type($filename)); $this->assertEquals('image/jpeg', mime_content_type($renamed)); unlink($filename); unlink($renamed); }
function testCommentWithChildren() { $kramer = $this->factory->user->create(array('display_name' => 'Cosmo Kramer')); $post_id = $this->factory->post->create(); $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'These pretzels are making me thirsty.', 'user_id' => $kramer)); sleep(2); $comment_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'Perhaps there’s more to Newman than meets the eye.')); $child_id = $this->factory->comment->create(array('comment_post_ID' => $post_id, 'comment_content' => 'No, there’s less.', 'comment_parent' => $comment_id)); $post = new TimberPost($post_id); $comments = $post->get_comments(); $this->assertEquals(2, count($comments)); $this->assertEquals(1, count($comments[1]->children)); $twig_string = '{{comment.author.name}}'; $result = Timber::compile_string($twig_string, array('comment' => $comments[0])); $this->assertEquals('Cosmo Kramer', $result); }
function testImageResizeRetinaFilter() { $filename = TestTimberImage::copyTestImage('eastern.jpg'); $wp_filetype = wp_check_filetype(basename($filename), null); $post_id = $this->factory->post->create(); $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($filename)), 'post_excerpt' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment, $filename, $post_id); add_post_meta($post_id, '_thumbnail_id', $attach_id, true); $data = array(); $data['post'] = new TimberPost($post_id); $str = '{{post.thumbnail.src|resize(100, 50)|retina(3)}}'; $compiled = Timber::compile_string($str, $data); $img = new TimberImage($compiled); $this->assertContains('@3x', $compiled); $this->assertEquals(300, $img->width()); }
function testMeta() { $vars = $this->_initObjects(); extract($vars); $site->update('bill', 'clinton'); $post->update('thomas', 'jefferson'); $term->update('abraham', 'lincoln'); $user->update('dwight', 'einsenhower'); $user->update('teddy', 'roosevelt'); $user->update('john', 'kennedy'); $comment->update('george', 'washington'); $this->assertEquals('jefferson', $post->thomas); $this->assertEquals('lincoln', $term->abraham); $this->assertEquals('roosevelt', $user->teddy); $this->assertEquals('washington', $comment->george); $this->assertEquals('clinton', $site->bill); $this->assertEquals('jefferson', Timber::compile_string('{{post.thomas}}', array('post' => $post))); $this->assertEquals('lincoln', Timber::compile_string('{{term.abraham}}', array('term' => $term))); $this->assertEquals('roosevelt', Timber::compile_string('{{user.teddy}}', array('user' => $user))); $this->assertEquals('washington', Timber::compile_string('{{comment.george}}', array('comment' => $comment))); $this->assertEquals('clinton', Timber::compile_string('{{site.bill}}', array('site' => $site))); }
function testResizeGif() { $filename = self::copyTestImage('loading.gif'); $gif_url = str_replace(ABSPATH, 'http://' . $_SERVER['HTTP_HOST'] . '/', $filename); $str = '<img src="{{' . "'{$gif_url}'" . '|resize(200)}}" />'; $result = Timber::compile_string($str); $resized_url = str_replace('loading.gif', 'loading-200x0-c-default.gif', $gif_url); $resized_path = str_replace('http://example.org', ABSPATH, $resized_url); $resized_path = TimberURLHelper::remove_double_slashes($resized_path); $this->assertFileExists($resized_path); }
function testSeventiesDates() { $twig = "Nixon was re-elected on {{'89942400'|date('M j, Y')}}, long may he reign!"; $str = Timber::compile_string($twig); $this->assertEquals('Nixon was re-elected on Nov 7, 1972, long may he reign!', $str); }
function testTermsInTwig() { $tids[] = $this->factory->term->create(array('name' => 'Animals')); $tids[] = $this->factory->term->create(array('name' => 'Germans')); $str = '{% for term in Term(tids) %}{{term.title}} {% endfor %}'; $this->assertEquals('Animals Germans ', Timber::compile_string($str, array('tids' => $tids))); }
function testTimberUserInTwig() { $uid = $this->factory->user->create(array('display_name' => 'Peter Karl')); $str = '{{TimberUser(' . $uid . ').name}}'; $this->assertEquals('Peter Karl', Timber::compile_string($str)); }
function testInTwigStringHeadAndFooter() { global $wp_scripts; $wp_scripts = null; //send colorpicker to the header wp_enqueue_script('colorpicker', false, array(), false, false); //send fake-js to the footer wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', array(), false, true); $str = Timber::compile_string('<head>{{function("wp_head")}}</head><footer>{{function("wp_footer")}}</footer>'); $footer_tag = strpos($str, '<footer>'); $colorpicker = strpos($str, 'colorpicker'); $this->assertGreaterThan(1, $colorpicker); //make sure that footer appears after colorpicker $this->assertGreaterThan($colorpicker, $footer_tag); }
function testPostAuthorInTwig() { $author_id = $this->factory->user->create(array('display_name' => 'User 1')); $pid = $this->factory->post->create(array('post_author' => $author_id)); $post = new TimberPost($pid); $this->assertEquals('user-1', $post->author()->slug()); $this->assertEquals('User 1', $post->author()->name()); $template = 'By {{post.author}}'; $authorCompile = Timber::compile_string($template, array('post' => $post)); $template = 'By {{post.author.name}}'; $authorNameCompile = Timber::compile_string($template, array('post' => $post)); $this->assertEquals($authorCompile, $authorNameCompile); $this->assertEquals('By User 1', $authorCompile); }
/** @issue #824 */ function testTermWithNativeMeta() { $tid = $this->factory->term->create(array('name' => 'News', 'taxonomy' => 'category')); add_term_meta($tid, 'foo', 'bar'); $term = new TimberTerm($tid); $template = '{{term.foo}}'; $compiled = Timber::compile_string($template, array('term' => $term)); $this->assertEquals('bar', $compiled); }
function testMenuName() { $this->_createTestMenu(); $menu = new TimberMenu(); $str = Timber::compile_string('{{menu.items[0].title}}', array('menu' => $menu)); $this->assertEquals('Home', $str); $str = Timber::compile_string('{{menu.items[0]}}', array('menu' => $menu)); $this->assertEquals('Home', $str); }
function testGuestAuthorAvatar() { $pid = $this->factory->post->create(); $post = new TimberPost($pid); $user_login = '******'; $display_name = 'Have Featured'; $email = '*****@*****.**'; $guest_id = self::create_guest_author(array('user_email' => $email, 'user_login' => $user_login, 'display_name' => $display_name)); $attach_id = self::attach_featured_image($guest_id, 'avt-1.jpg'); $image = new Timber\Image(array('ID' => $attach_id)); global $coauthors_plus; $coauthors_plus->add_coauthors($pid, array($user_login)); $template_string = '{% for author in post.authors %}{{author.avatar.src}}{% endfor %}'; Timber\Integrations\CoAuthorsPlus::$prefer_gravatar = false; $str1 = Timber::compile_string($template_string, array('post' => $post)); $this->assertEquals($image->src(), $str1); Timber\Integrations\CoAuthorsPlus::$prefer_gravatar = true; $str2 = Timber::compile_string($template_string, array('post' => $post)); $this->assertEquals(get_avatar_url($email), $str2); }
function testTwigFilterList() { $data['authors'] = array('Tom', 'Rick', 'Harry', 'Mike'); $str = Timber::compile_string("{{authors|list}}", $data); $this->assertEquals('Tom, Rick, Harry and Mike', $str); }
function testUnixDate() { $twig = "Thing is on {{'1446127859'|date('M j, Y')}}"; $str = Timber::compile_string($twig); $this->assertEquals('Thing is on Oct 29, 2015', $str); }
function testTimberImageFromAttachment() { $iid = self::get_image_attachment(); $image = new TimberImage($iid); $post = get_post($iid); $str = '{{ TimberImage(post).src }}'; $result = Timber::compile_string($str, array('post' => $post)); $this->assertEquals($image->src(), $result); }
function testNoThumbnail() { $pid = $this->factory->post->create(); $post = new TimberPost($pid); $str = Timber::compile_string('Image?{{post.thumbnail.src}}', array('post' => $post)); $this->assertEquals('Image?', $str); }
function testTwigShortcodeWithContent() { add_shortcode('duck', function ($atts, $content) { return $content . ' says quack!'; }); $str = Timber::compile_string('{{shortcode("[duck]Lauren[/duck]")}}'); $this->assertEquals('Lauren says quack!', $str); }