Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CrochetFeve0251 committed Sep 21, 2023
1 parent 0747f76 commit 9b4976d
Show file tree
Hide file tree
Showing 17 changed files with 503 additions and 727 deletions.
790 changes: 392 additions & 398 deletions inc/ThirdParty/Plugins/PageBuilder/Elementor.php

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<?php

$input = file_get_contents(__DIR__ . '/HTML/input.html');
$output = file_get_contents(__DIR__ . '/HTML/output.html');
$output_added = file_get_contents(__DIR__ . '/HTML/output_added.html');
return [
'' => [
'config' => [
'boxes' => [],
'user_id' => 10,
'can' => true,
'transient' => true,
'notice' => true,
],
'expected' => [
'notice' => [
'status' => 'warning',
'dismissible' => '',
'dismiss_button' => 'maybe_clear_cache_change_notice',
'message' => '<strong>WP Rocket:</strong> Your Elementor template was updated. Clear the Used CSS if the layout, design or CSS styles were changed.',
'action' => 'clear_cache',
]
]
],
'AddScript' => [
'config' => [
'html' => $input,
'script' => 'script',
'is_allowed' => true,
],
'expected' => $output_added
],
'NotAllowedShouldReturnSame' => [
'config' => [
'html' => $input,
'script' => 'script',
'is_allowed' => false,
],
'expected' => $output
],
'NoScriptShould' => [
'config' => [
'html' => $input,
'script' => false,
'is_allowed' => true,
],
'expected' => $output
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'remove_unused_css' => true,
'user_id' => 10,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
],
'change' => true,
],
Expand All @@ -31,15 +31,15 @@
'remove_unused_css' => true,
'user_id' => 10,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
],
'change' => false,
],
'expected' => [
'user_id' => 10,
'transient' => false,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
]
]
],
Expand All @@ -53,15 +53,15 @@
'remove_unused_css' => false,
'user_id' => 10,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
],
'change' => false,
],
'expected' => [
'user_id' => 10,
'transient' => false,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
]
]
],
Expand All @@ -75,15 +75,15 @@
'remove_unused_css' => true,
'user_id' => 10,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
],
'change' => false,
],
'expected' => [
'user_id' => 10,
'transient' => false,
'boxes' => [
'maybe_clear_cache_change_notice' => true
'maybe_clear_cache_change_notice'
]
]
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace ThirdParty\Plugins\PageBuilder\Elementor;
use Mockery;
use WP_Filesystem_Direct;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Common\Ajax\AjaxHandler;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
use WP_Rocket\Engine\Optimization\RUCSS\Controller\UsedCSS;
use WP_Rocket\ThirdParty\Plugins\PageBuilder\Elementor;

trait ElementorTestTrait
{
/**
* @var Options_Data
*/
protected $options;

protected $filesystem;

/**
* @var HTML
*/
protected $delayjs_html;

/**
* @var UsedCSS
*/
protected $used_css;

/**
* @var AjaxHandler
*/
protected $ajax_handler;

/**
* @var Elementor
*/
protected $elementor;

public function set_up() {
parent::set_up();
$this->options = Mockery::mock(Options_Data::class);
$this->filesystem = Mockery::mock(WP_Filesystem_Direct::class);
$this->delayjs_html = Mockery::mock(HTML::class);
$this->used_css = Mockery::mock(UsedCSS::class);
$this->ajax_handler = Mockery::mock(AjaxHandler::class);

$this->elementor = new Elementor($this->options, $this->filesystem, $this->delayjs_html, $this->used_css, $this->ajax_handler);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\PageBuilder\Elementor;

use Mockery;
use ThirdParty\Plugins\PageBuilder\Elementor\ElementorTestTrait;
use WP_Filesystem_Direct;
use WP_Rocket\ThirdParty\Plugins\PageBuilder\Elementor;
use WP_Rocket\Admin\Options_Data;
Expand All @@ -18,37 +19,7 @@
*/
class Test_addFixAnimationScript extends TestCase {

/**
* @var Options_Data
*/
protected $options;

protected $filesystem;

/**
* @var HTML
*/
protected $delayjs_html;

/**
* @var UsedCSS
*/
protected $used_css;

/**
* @var Elementor
*/
protected $elementor;

public function set_up() {
parent::set_up();
$this->options = Mockery::mock(Options_Data::class);
$this->filesystem = Mockery::mock(WP_Filesystem_Direct::class);
$this->delayjs_html = Mockery::mock(HTML::class);
$this->used_css = Mockery::mock(UsedCSS::class);

$this->elementor = new Elementor($this->options, $this->filesystem, $this->delayjs_html, $this->used_css);
}
use ElementorTestTrait;

/**
* @dataProvider configTestData
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Mockery;
use Brain\Monkey\Functions;
use ThirdParty\Plugins\PageBuilder\Elementor\ElementorTestTrait;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
use WP_Rocket\Tests\Unit\TestCase;
Expand All @@ -15,13 +16,7 @@
* @group ThirdParty
*/
class Test_ClearCache extends TestCase {
private $elementor;

public function setUp() : void {
parent::setUp();

$this->elementor = new Elementor( Mockery::mock( Options_Data::class ), null, Mockery::mock( HTML::class ), Mockery::mock( UsedCSS::class ) );
}
use ElementorTestTrait;

public function testShouldDoNothingWhenNotExternal() {
Functions\when( 'get_option' )->justReturn( 'internal' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Mockery;
use Brain\Monkey\Functions;
use ThirdParty\Plugins\PageBuilder\Elementor\ElementorTestTrait;
use WP_Rocket\Tests\Unit\TestCase;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
Expand All @@ -15,10 +16,7 @@
* @group HealthCheck
*/
class Test_ClearRelatedPostCache extends TestCase {
private $elementor;
private $wpdb;
private $options;
private $used_css;
use ElementorTestTrait;

public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
Expand All @@ -36,9 +34,6 @@ protected function setUp(): void {
require_once WP_ROCKET_PLUGIN_ROOT . 'inc/common/purge.php';
}

$this->options = Mockery::mock( Options_Data::class );
$this->used_css = Mockery::mock( UsedCSS::class );
$this->elementor = new Elementor( $this->options, null, Mockery::mock( HTML::class ), $this->used_css );
$GLOBALS['wpdb'] = $this->wpdb = new wpdb();

Check warning on line 37 in tests/Unit/inc/ThirdParty/Plugins/PageBuilder/Elementor/clearRelatedPostCache.php

View workflow job for this annotation

GitHub Actions / WP latest with PHP 8.2 on ubuntu-latest.

Creation of dynamic property WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\PageBuilder\Elementor\Test_ClearRelatedPostCache::$wpdb is deprecated

Check warning on line 37 in tests/Unit/inc/ThirdParty/Plugins/PageBuilder/Elementor/clearRelatedPostCache.php

View workflow job for this annotation

GitHub Actions / WP latest with PHP 8.2 on ubuntu-latest.

Creation of dynamic property WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\PageBuilder\Elementor\Test_ClearRelatedPostCache::$wpdb is deprecated

Check warning on line 37 in tests/Unit/inc/ThirdParty/Plugins/PageBuilder/Elementor/clearRelatedPostCache.php

View workflow job for this annotation

GitHub Actions / WP latest with PHP 8.2 on ubuntu-latest.

Creation of dynamic property WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\PageBuilder\Elementor\Test_ClearRelatedPostCache::$wpdb is deprecated

Check warning on line 37 in tests/Unit/inc/ThirdParty/Plugins/PageBuilder/Elementor/clearRelatedPostCache.php

View workflow job for this annotation

GitHub Actions / WP latest with PHP 8.2 on ubuntu-latest.

Creation of dynamic property WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\PageBuilder\Elementor\Test_ClearRelatedPostCache::$wpdb is deprecated
}

Expand All @@ -64,7 +59,7 @@ public function testShouldDoAsExpected( $config ) {
Functions\expect( 'get_post_status' )
->twice()
->andReturn( $config['post_status'] );

foreach ( $config['results'] as $result ) {
if ( 'publish' === $config['post_status'] ) {
$this->options->shouldReceive( 'get' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Mockery;
use Brain\Monkey\Functions;
use ThirdParty\Plugins\PageBuilder\Elementor\ElementorTestTrait;
use WP_Rocket\Tests\Unit\TestCase;
use WP_Rocket\Admin\Options_Data;
use WP_Rocket\Engine\Optimization\DelayJS\HTML;
Expand All @@ -16,15 +17,7 @@
* @group ThirdParty
*/
class Test_ExcludeJs extends TestCase {
private $options;
private $elementor;

public function setUp(): void {
parent::setUp();

$this->options = Mockery::mock( Options_Data::class );
$this->elementor = new Elementor( $this->options, null, Mockery::mock( HTML::class ), Mockery::mock( UsedCSS::class ) );
}
use ElementorTestTrait;

/**
* @dataProvider configTestData
Expand Down
Loading

0 comments on commit 9b4976d

Please sign in to comment.