Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added logic to clean root files (#5761)
Co-authored-by: Vasilis Manthos <vmanthos@gmail.com>
- Loading branch information
1 parent
252cead
commit fee96d7
Showing
7 changed files
with
259 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...xtures/inc/ThirdParty/Plugins/I18n/WPML/onChangeDirectoryForDefaultLanguageCleanCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
return [ | ||
'noFieldsShouldNotClean' => [ | ||
'config' => [ | ||
'old' => [ | ||
|
||
], | ||
'new' => [ | ||
|
||
], | ||
'should_clean' => false, | ||
], | ||
'expected' => [ | ||
|
||
] | ||
], | ||
'SameFieldsShouldNotClean' => [ | ||
'config' => [ | ||
'old' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => false, | ||
] | ||
], | ||
'new' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => false, | ||
] | ||
], | ||
'should_clean' => false, | ||
], | ||
'expected' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => false, | ||
] | ||
] | ||
], | ||
'differentFieldsShouldClean' => [ | ||
'config' => [ | ||
'old' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => false, | ||
] | ||
], | ||
'new' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => true, | ||
] | ||
], | ||
'should_clean' => true, | ||
], | ||
'expected' => [ | ||
'urls' => [ | ||
'directory_for_default_language' => true, | ||
] | ||
] | ||
], | ||
|
||
]; |
15 changes: 15 additions & 0 deletions
15
tests/Fixtures/inc/ThirdParty/Plugins/I18n/WPML/removeRootCachedFiles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
return [ | ||
'removeFilesOnRoot' => [ | ||
'config' => [ | ||
'home_url' => 'https/example.org', | ||
'host' => 'example.org', | ||
'entries' => [ | ||
'entry_path' => [], | ||
], | ||
'path' => 'path', | ||
'cache_path' => 'pathexample.org/', | ||
'entry_path' => 'pathexample.org/entry_path', | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...s/Unit/inc/ThirdParty/Plugins/I18n/WPML/onChangeDirectoryForDefaultLanguageCleanCache.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\I18n\WPML; | ||
|
||
use WP_Rocket\ThirdParty\Plugins\I18n\WPML; | ||
use Mockery; | ||
use WP_Filesystem_Direct; | ||
|
||
|
||
use WP_Rocket\Tests\Unit\TestCase; | ||
use Brain\Monkey\Functions; | ||
|
||
/** | ||
* @covers \WP_Rocket\ThirdParty\Plugins\I18n\WPML::on_change_directory_for_default_language_clean_cache | ||
*/ | ||
class Test_onChangeDirectoryForDefaultLanguageCleanCache extends TestCase { | ||
|
||
/** | ||
* @var WP_Filesystem_Direct | ||
*/ | ||
protected $filesystem; | ||
|
||
/** | ||
* @var WPML | ||
*/ | ||
protected $wpml; | ||
|
||
public function set_up() { | ||
parent::set_up(); | ||
$this->filesystem = Mockery::mock(WP_Filesystem_Direct::class); | ||
|
||
$this->wpml = new WPML($this->filesystem); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldReturnAsExpected( $config, $expected ) | ||
{ | ||
if($config['should_clean']) { | ||
Functions\expect('rocket_clean_domain'); | ||
} else { | ||
Functions\expect('rocket_clean_domain')->never(); | ||
} | ||
$this->assertSame($expected, $this->wpml->on_change_directory_for_default_language_clean_cache($config['new'], $config['old'])); | ||
|
||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Unit/inc/ThirdParty/Plugins/I18n/WPML/removeRootCachedFiles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\ThirdParty\Plugins\I18n\WPML; | ||
|
||
use Mockery; | ||
use WP_Filesystem_Direct; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
use WP_Rocket\ThirdParty\Plugins\I18n\WPML; | ||
use Brain\Monkey\Functions; | ||
use Brain\Monkey\Filters; | ||
|
||
class Test_RemoveRootCachedFiles extends TestCase | ||
{ | ||
protected $subscriber; | ||
protected $filesystem; | ||
|
||
protected function set_up() | ||
{ | ||
parent::set_up(); | ||
$this->filesystem = Mockery::mock( WP_Filesystem_Direct::class ); | ||
$this->subscriber = new WPML($this->filesystem); | ||
} | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldAsExpected( $config ) { | ||
Functions\expect('home_url')->andReturn($config['home_url']); | ||
Functions\expect('wp_parse_url')->with($config['home_url'], PHP_URL_HOST)->andReturn($config['host']); | ||
Functions\expect('_rocket_get_wp_rocket_cache_path')->with($config['home_url'], PHP_URL_HOST)->andReturn($config['path']); | ||
$this->filesystem->expects()->dirlist($config['cache_path'])->andReturn($config['entries']); | ||
$this->filesystem->expects()->is_dir($config['entry_path'])->andReturn(false); | ||
$this->filesystem->expects()->delete($config['entry_path']); | ||
$this->subscriber->remove_root_cached_files(); | ||
} | ||
} |