Skip to content
Snippets Groups Projects
Select Git revision
  • b9ad68abbf50843cba715710bf7f2cdffeb39846
  • master default protected
  • bugfix/wordpress-review
  • bugfix/prevent-error-notice
  • remove-arrow
  • feature/update-message
  • feature/minimum-plugin-version-check-demo1
  • feature/plugin-name
  • 3.7.1
  • 3.7.0
  • 3.6.3
  • 3.6.2
  • 3.6.1
  • 3.6.0
  • 3.6.0-beta3
  • 3.6.0-beta2
  • 3.6.0-beta1
  • 3.5.2
  • 3.5.1
  • 3.5.0
  • 3.4.0
  • 3.3.0
  • 3.2.8
  • 3.2.7
  • 3.2.6
  • 3.2.5
  • 3.2.4
  • 3.2.3
28 results

Basic_Requirement_Checker.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() );
    	}
    
    }