diff --git a/inc/Engine/Common/Cache/FilesystemCache.php b/inc/Engine/Common/Cache/FilesystemCache.php index d3c0d43478..61187e0216 100644 --- a/inc/Engine/Common/Cache/FilesystemCache.php +++ b/inc/Engine/Common/Cache/FilesystemCache.php @@ -243,6 +243,10 @@ public function generate_path( string $url ): string { * @return bool */ public function is_accessible(): bool { + $base_path = $this->get_base_path(); + if ( ! $this->filesystem->exists( $base_path ) ) { + rocket_mkdir_p( $base_path, $this->filesystem ); + } $root_path = $this->get_root_path(); if ( ! $this->filesystem->exists( $root_path ) ) { rocket_mkdir_p( $root_path, $this->filesystem ); diff --git a/tests/Unit/inc/Engine/Common/Cache/FilesystemCache/isAccessible.php b/tests/Unit/inc/Engine/Common/Cache/FilesystemCache/isAccessible.php index 43f0c0c2c7..f762df0017 100644 --- a/tests/Unit/inc/Engine/Common/Cache/FilesystemCache/isAccessible.php +++ b/tests/Unit/inc/Engine/Common/Cache/FilesystemCache/isAccessible.php @@ -11,7 +11,7 @@ /** * Test class covering \WP_Rocket\Engine\Common\Cache\FilesystemCache::is_accessible */ -class TestIsAccessible extends TestCase { +class Test_IsAccessible extends TestCase { protected $root_folder; protected $filesystem; protected $filesystemcache; @@ -27,17 +27,35 @@ public function set_up() { /** * @dataProvider configTestData + * @throws \Exception */ public function testShouldReturnAsExpected( $config, $expected ) { - Functions\when('rocket_get_constant')->justReturn($config['root']); - Functions\when('get_current_blog_id')->justReturn( 1 ); + Functions\when('rocket_get_constant')->justReturn($config['root']); + Functions\when('get_current_blog_id')->justReturn( 1 ); - $this->filesystem->shouldReceive('exists')->with($expected['path'])->andReturn($config['exists']); - if( ! $config['exists']) { - Functions\expect('rocket_mkdir_p')->with($expected['path'], $this->filesystem); - } - $this->filesystem->shouldReceive('is_writable')->with($expected['path'])->andReturn($config['is_writable']); + $base_path = $config['root'] . $this->root_folder; + $root_path = $expected['path']; + + + $this->filesystem->shouldReceive('exists') + ->with($base_path) + ->andReturn($config['exists']); + + if( ! $config['exists']) { + Functions\expect('rocket_mkdir_p')->with($base_path, $this->filesystem); + } + + $this->filesystem->shouldReceive('exists') + ->with($root_path) + ->andReturn($config['exists']); + + if (!$config['exists']) { + Functions\expect('rocket_mkdir_p') + ->with($root_path, $this->filesystem); + } + + $this->filesystem->shouldReceive('is_writable')->with($root_path)->andReturn($config['is_writable']); - $this->assertSame($expected['output'], $this->filesystemcache->is_accessible()); + $this->assertSame($expected['output'], $this->filesystemcache->is_accessible()); } }