<?php
/*
* This file is part of the webmozart/expression package.
*
* (c) Bernhard Schussek <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Webmozart\Expression\Tests\Selector;
use ArrayIterator;
use PHPUnit_Framework_TestCase;
use Webmozart\Expression\Constraint\EndsWith;
use Webmozart\Expression\Constraint\GreaterThan;
use Webmozart\Expression\Logic\AndX;
use Webmozart\Expression\Selector\AtMost;
/**
* @since 1.0
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class AtMostTest extends PHPUnit_Framework_TestCase
{
public function testEvaluate()
{
$atMost1 = new AtMost(1, new GreaterThan(10));
$atMost2 = new AtMost(2, new GreaterThan(10));
$this->assertFalse($atMost1->evaluate(array(9, 10, 11, 12)));
$this->assertTrue($atMost1->evaluate(array(9, 10, 11)));
$this->assertTrue($atMost1->evaluate(array(9, 10)));
$this->assertFalse($atMost1->evaluate(new ArrayIterator(array(9, 10, 11, 12))));
$this->assertTrue($atMost1->evaluate(new ArrayIterator(array(9, 10, 11))));
$this->assertTrue($atMost1->evaluate(new ArrayIterator(array(9, 10))));
$this->assertFalse($atMost2->evaluate(array(9, 10, 11, 12, 13)));
$this->assertTrue($atMost2->evaluate(array(9, 10, 11, 12)));
$this->assertTrue($atMost2->evaluate(array(9, 10, 11)));
$this->assertTrue($atMost2->evaluate(array(9, 10)));
$this->assertFalse($atMost2->evaluate(new ArrayIterator(array(9, 10, 11, 12, 13))));
$this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10, 11, 12))));
$this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10, 11))));
$this->assertTrue($atMost2->evaluate(new ArrayIterator(array(9, 10))));
$this->assertTrue($atMost1->evaluate(array()));
$this->assertFalse($atMost1->evaluate('foobar'));
}
public function testToString()
{
$expr1 = new AtMost(1, new GreaterThan(10));
$expr2 = new AtMost(2, new EndsWith('.css'));
$expr3 = new AtMost(3, new AndX(array(
new GreaterThan(10),
new EndsWith('.css'),
)));
$this->assertSame('atMost(1, >10)', $expr1->toString());
$this->assertSame('atMost(2, endsWith(".css"))', $expr2->toString());
$this->assertSame('atMost(3, >10 && endsWith(".css"))', $expr3->toString());
}
}
<?php
namespace WP_Rocket\Tests\Unit\inc\Engine\License\Upgrade;
use Brain\Monkey\Functions;
use Mockery;
use WP_Rocket\Engine\License\API\Pricing;
use WP_Rocket\Engine\License\API\User;
use WP_Rocket\Engine\License\Upgrade;
use WP_Rocket\Tests\Unit\TestCase;
/**
* @covers \WP_Rocket\Engine\License\Upgrade::display_upgrade_popin
*
* @group License
*/
class DisplayUpgradePopin extends TestCase {
private $pricing;
private $user;
private $upgrade;
public function setUp() : void {
parent::setUp();
Functions\stubTranslationFunctions();
$this->pricing = Mockery::mock( Pricing::class );
$this->user = Mockery::mock( User::class );
$this->upgrade = Mockery::mock(
Upgrade::class . '[generate]',
[
$this->pricing,
$this->user,
'views',
]
);
}
/**
* @dataProvider configTestData
*/
public function testShouldReturnExpected( $config, $expected ) {
$this->user->shouldReceive( 'get_license_type' )
->atMost()
->twice()
->andReturn( $config['license_account'] );
$this->user->shouldReceive( 'is_license_expired' )
->atMost()
->once()
->andReturn( $config['licence_expiration'] );
if ( ! is_null( $expected ) ) {
$this->pricing->shouldReceive( 'get_single_websites_count' )
->atMost()
->once()
->andReturn( $config['pricing']['single']['websites'] );
$this->pricing->shouldReceive( 'get_plus_websites_count' )
->atMost()
->twice()
->andReturn( $config['pricing']['plus']['websites'] );
$this->pricing->shouldReceive( 'get_single_to_plus_price' )
->atMost()
->once()
->andReturn( $config['pricing']['plus']['price'] );
$this->pricing->shouldReceive( 'get_regular_single_to_plus_price' )
->atMost()
->once()
->andReturn( $config['pricing']['plus']['regular'] );
$this->user->shouldReceive( 'get_upgrade_plus_url' )
->atMost()
->once()
->andReturn( $config['pricing']['plus']['upgrade_url'] );
$this->pricing->shouldReceive( 'get_single_to_infinite_price' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['price'] );
$this->pricing->shouldReceive( 'get_regular_single_to_infinite_price' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['regular'] );
$this->pricing->shouldReceive( 'get_infinite_websites_count' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['websites'] );
$this->user->shouldReceive( 'get_upgrade_infinite_url' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['upgrade_url'] );
$this->pricing->shouldReceive( 'get_plus_to_infinite_price' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['price'] );
$this->pricing->shouldReceive( 'get_regular_plus_to_infinite_price' )
->atMost()
->once()
->andReturn( $config['pricing']['infinite']['regular'] );
$this->pricing->shouldReceive( 'is_promo_active' )
->andReturn( $config['promo_active'] );
$this->upgrade->shouldReceive( 'generate' )
->once()
->with(
'upgrade-popin',
$expected
)
->andReturn( '' );
$this->expectOutputString( '' );
} else {
$this->upgrade->shouldReceive( 'generate' )
->never();
}
$this->upgrade->display_upgrade_popin();
}
}