Skip to content
Snippets Groups Projects
Select Git revision
  • 5e54f36b1166a5cc8f65ca69d435de90155ac683
  • master default protected
  • 1.1.0
  • 1.0
4 results

TestOrStrategy.php

Blame
  • TestOrStrategy.php 1.25 KiB
    <?php
    
    
    namespace unit;
    
    use WPDesk\ShowDecision\OrStrategy;
    
    class TestOrStrategy extends \WP_Mock\Tools\TestCase
    {
    
        public function testShouldReturnTrueWhenAnyConditionsAreTrue()
        {
            // Given
            $strategy1 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy1->method('shouldDisplay')->willReturn(true);
    
            $strategy2 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy2->method('shouldDisplay')->willReturn(false);
    
            $orStrategy = new OrStrategy($strategy1);
            $orStrategy->addCondition($strategy2);
    
            // When & Then
            $this->assertTrue($orStrategy->shouldDisplay());
        }
    
        public function testShouldReturnFalseWhenAllConditionsAreFalse()
        {
            // Given
            $strategy1 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy1->method('shouldDisplay')->willReturn(false);
    
            $strategy2 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy2->method('shouldDisplay')->willReturn(false);
    
            $orStrategy = new OrStrategy($strategy1);
            $orStrategy->addCondition($strategy2);
    
            // When & Then
            $this->assertFalse($orStrategy->shouldDisplay());
        }
    
    }