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

TestAndStrategy.php

Blame
  • TestAndStrategy.php 1.26 KiB
    <?php
    
    
    namespace unit;
    
    use WPDesk\ShowDecision\AndStrategy;
    
    
    class TestAndStrategy extends \WP_Mock\Tools\TestCase
    {
    
        public function testShouldReturnTrueWhenAllConditionsAreTrue()
        {
            // Given
            $strategy1 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy1->method('shouldDisplay')->willReturn(true);
    
            $strategy2 = $this->createMock(\WPDesk\ShowDecision\ShouldShowStrategy::class);
            $strategy2->method('shouldDisplay')->willReturn(true);
    
            $andStrategy = new AndStrategy($strategy1);
            $andStrategy->addCondition($strategy2);
    
            // When & Then
            $this->assertTrue($andStrategy->shouldDisplay());
        }
    
        public function testShouldReturnFalseWhenAnyConditionIsFalse()
        {
            // 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);
    
            $andStrategy = new AndStrategy($strategy1);
            $andStrategy->addCondition($strategy2);
    
            // When & Then
            $this->assertFalse($andStrategy->shouldDisplay());
        }
    
    }