Skip to content
Snippets Groups Projects
Select Git revision
  • c484c8ec95d2e7ebe6b4f712465294e335b51295
  • master default protected
  • 1.6.4
  • 1.6.3
  • 1.6.2
  • 1.6.1
  • 1.6.0
  • 1.5.0
  • 1.4.0
  • 1.3.1
  • 1.3.0
  • 1.3.0-beta1
  • 1.2.1
  • 1.2.0
  • 1.2.0-beta5
  • 1.2.0-beta4
  • 1.2.0-beta3
  • 1.2.0-beta2
  • 1.2.0-beta1
  • 1.1.0
  • 1.0.0
21 results

AlwaysDisplayDisplayDecision.php

Blame
  • TestPostTypeStrategy.php 1.35 KiB
    <?php
    
    namespace unit;
    
    use PHPUnit\Framework\TestCase;
    use WPDesk\ShowDecision\PostTypeStrategy;
    
    
    class TestPostTypeStrategy extends TestCase {
    	const valid_post_type = 'test_post_type';
    	const invalid_post_type = 'invalid';
    
    	protected function setUp(): void {
    		require_once __DIR__ . DIRECTORY_SEPARATOR . 'Stub' . DIRECTORY_SEPARATOR . 'WP_Post.php';
    		parent::setUp();
    		\WP_Mock::setUp();
    	}
    
    	protected function tearDown(): void {
    		parent::tearDown();
    		\WP_Mock::tearDown();
    	}
    
    	public function testFailureWhenTriesUseInvalidPostType() {
    		$strategy = new PostTypeStrategy( self::invalid_post_type );
    		$this->assertFalse( $strategy->shouldDisplay() );
    	}
    
    	public function testValidPostTypeUsingGetSuccess() {
    		$_GET     = [ 'post_type' => self::valid_post_type ];
    		$strategy = new PostTypeStrategy( self::valid_post_type );
    		$this->assertTrue( $strategy->shouldDisplay() );
    	}
    
    	public function testValidPostTypeUsingPostIdSuccess() {
    		$post_id = 123;
    		$_GET    = [
    			'post' => $post_id
    		];
    		\WP_Mock::userFunction( 'get_post', [
    			'times'  => 1,
    			'return' => function () use ( $post_id ) {
    				$post            = new \WP_Post();
    				$post->ID        = $post_id;
    				$post->post_type = self::valid_post_type;
    
    				return $post;
    			}
    		] );
    
    		$strategy = new PostTypeStrategy( self::valid_post_type );
    		$this->assertTrue( $strategy->shouldDisplay() );
    	}
    
    }