Post on 17-Jul-2015
transcript
As a user, I want to see a banner for every post that has the ‘tdd’ tag associated with the post, so that the editor doesn’t have to manually add the banner to each ‘tdd’ post.
1 public function test_adding_banner_filter() { 2 $post_id = $this->factory->post->create( array( 3 'post_title' => 'Test of our banner output', 4 'post_content' => 'This is the content of our test post.', 5 'post_date' => '2014-10-01 17:28:00', 6 'post_status' => 'publish', 7 'post_type' => 'post' 8 ) ); 9 10 wp_set_post_tags( $post_id, 'tag', true ); 11 $this->go_to( get_permalink( $post_id )); 12 13 $post = \Fusion\Objects\Post::get_by_post_id( $post_id ); 14 15 $content = apply_filters( 'the_content', $post->get_content() ); 16 17 $html5 = new HTML5(); 18 $dom = $html5->loadHTML($content); 19 20 $this->assertContains( 'assets/images/topic-banners/banner.jpg', qp( $dom, 'img' )->attr('src') ); 21 22 }
1 public function adding_banner( $content ) { 2 $post = \Fusion\Objects\Post::get_by_post_id( get_the_ID() ); 3 4 if ( $post->has_tag('tdd') ) { 5 $banner = '<img src="' . esc_url( get_template_directory_uri() . '/assets/images/topic-banners/banner.jpg') . '" alt="" />'; 6 $content = $content . $banner; 7 } 8 9 return $content; 10 }