-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a488cf
commit c928908
Showing
6 changed files
with
198 additions
and
29 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Assets package. | ||
* | ||
* (c) Inpsyde GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Inpsyde\Assets\Tests\Unit\Caching; | ||
|
||
use Brain\Monkey\Functions; | ||
use Inpsyde\Assets\AssetManager; | ||
use Inpsyde\Assets\Caching\IgnoreCacheHandler; | ||
use Inpsyde\Assets\Script; | ||
use Inpsyde\Assets\Style; | ||
use Inpsyde\Assets\Tests\Unit\AbstractTestCase; | ||
use Inpsyde\Assets\Util\AssetHookResolver; | ||
use Inpsyde\WpContext; | ||
use function PHPUnit\Framework\assertSame; | ||
|
||
class IgnoreCacheHandlerTest extends AbstractTestCase | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
Functions\when('wp_scripts')->justReturn(\Mockery::mock('WP_Scripts')); | ||
Functions\when('wp_styles')->justReturn(\Mockery::mock('WP_Styles')); | ||
} | ||
|
||
public function testExtractHandles(): void | ||
{ | ||
$assetsManager = $this->factoryAssetManager(); | ||
$ignoreCacheHandler = new IgnoreCacheHandler(); | ||
$assetsManager->register( | ||
new Script('example-1', 'script1.js'), | ||
new Script('example-2', 'script2.js'), | ||
new Style('example-3', 'style1.css'), | ||
new Style('example-4', 'style2.css') | ||
); | ||
|
||
$ignoreCacheHandlerReflection = new \ReflectionClass(IgnoreCacheHandler::class); | ||
$extractHandlesMethod = $ignoreCacheHandlerReflection->getMethod('extractHandles'); | ||
$extractHandlesMethod->setAccessible(true); | ||
|
||
assertSame( | ||
[ | ||
Script::class => [ | ||
'example-1', 'example-2', | ||
], | ||
Style::class => [ | ||
'example-3', 'example-4', | ||
], | ||
], | ||
$extractHandlesMethod->invoke($ignoreCacheHandler, $assetsManager) | ||
); | ||
} | ||
|
||
private function factoryAssetManager(?string $context = null): AssetManager | ||
{ | ||
$wpContext = WpContext::new()->force($context ?? WpContext::FRONTOFFICE); | ||
$resolver = new AssetHookResolver($wpContext); | ||
return new AssetManager($resolver); | ||
} | ||
} |
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 | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Assets package. | ||
* | ||
* (c) Inpsyde GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Inpsyde\Assets\Tests\Unit\Caching; | ||
|
||
use Inpsyde\Assets\Caching\IgnoreSitegroundCache; | ||
use Inpsyde\Assets\Tests\Unit\AbstractTestCase; | ||
use function PHPUnit\Framework\assertSame; | ||
|
||
class IgnoreSitegroundCacheTest extends AbstractTestCase | ||
{ | ||
public function testApplyExcludedHandlers(): void | ||
{ | ||
$excluded = ['excluded-1', 'excluded-2']; | ||
$toExclude = ['to-exclude-1', 'to-exclude-2']; | ||
|
||
$ignoreSitegroundCacheReflection = new \ReflectionClass(IgnoreSitegroundCache::class); | ||
$applyExcludedHandlesMethod = $ignoreSitegroundCacheReflection->getMethod('applyExcludedHandles'); | ||
$applyExcludedHandlesMethod->setAccessible(true); | ||
|
||
assertSame( | ||
['excluded-1', 'excluded-2', 'to-exclude-1', 'to-exclude-2'], | ||
$applyExcludedHandlesMethod->invoke(new IgnoreSitegroundCache(), $excluded, $toExclude) | ||
); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Assets package. | ||
* | ||
* (c) Inpsyde GmbH | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Inpsyde\Assets\Tests\Unit\Caching; | ||
|
||
use Inpsyde\Assets\Caching\IgnoreW3TotalCache; | ||
use Inpsyde\Assets\Tests\Unit\AbstractTestCase; | ||
use function PHPUnit\Framework\assertSame; | ||
|
||
class IgnoreW3TotalCacheTest extends AbstractTestCase | ||
{ | ||
public function testDetermineMinification(): void | ||
{ | ||
$scriptTag = '<script src="example.js" id="assets-plugin-script-js"></script>'; | ||
|
||
$ignoreW3TotalCacheReflection = new \ReflectionClass(IgnoreW3TotalCache::class); | ||
$determineMinificationMethod = $ignoreW3TotalCacheReflection->getMethod('determineMinification'); | ||
$determineMinificationMethod->setAccessible(true); | ||
|
||
assertSame( | ||
false, | ||
$determineMinificationMethod->invoke(new IgnoreW3TotalCache(), true, $scriptTag, ['assets-plugin-script']) | ||
); | ||
assertSame( | ||
true, | ||
$determineMinificationMethod->invoke(new IgnoreW3TotalCache(), true, $scriptTag, ['assets-plugin-script-example']) | ||
); | ||
assertSame( | ||
true, | ||
$determineMinificationMethod->invoke(new IgnoreW3TotalCache(), true, $scriptTag, []) | ||
); | ||
assertSame( | ||
false, | ||
$determineMinificationMethod->invoke(new IgnoreW3TotalCache(), false, $scriptTag, []) | ||
); | ||
} | ||
} |