Skip to content

Commit

Permalink
WIP: Integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Nov 8, 2024
1 parent 0f2c05b commit 32fa787
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Google Font V1 Template</title>
<link href="https://example.com/wp-content/cache/wp-rocket/fonts/example.com/input_v1/70d57d4fc2ebfc2c090d3a76133094d2.css" rel="stylesheet">
<link href="https://example.org/wp-content/cache/wp-rocket/fonts/example.org/70d57d4fc2ebfc2c090d3a76133094d2.css" rel="stylesheet">
<style>
.roboto-font {
font-family: 'Roboto', sans-serif;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@

'testShouldCombineV1Font' => [
'config' => [
'url' => 'https://example.com/input_v1',
'html' => file_get_contents( __DIR__ . '/HTML/input_v1.php' ),
'is_allowed' => true,
'files' => [
[
'path' => '/wp-content/cache/wp-rocket/fonts/example.org/70d57d4fc2ebfc2c090d3a76133094d2.css'
]
]
],
'expected' => file_get_contents( __DIR__ . '/HTML/expected_v1.php' ),
],
'testShouldCombineV2' => [
'config' => [
'html' => file_get_contents( __DIR__ . '/HTML/input_v2.php' ),
'is_allowed' => true,
],
'expected' => file_get_contents( __DIR__ . '/HTML/expected_v2.php' ),
],
'testShouldCombineV1AndV2' => [
'config' => [
'html' => file_get_contents( __DIR__ . '/HTML/input_v1_v2.php' ),
'is_allowed' => true,
],
'expected' => file_get_contents( __DIR__ . '/HTML/expected_v1_v2.php' ),
],
'testShouldBailOutAsNoGoogleFontIncluded' => [
'config' => [
'html' => '<html><body></body></html>',
'is_allowed' => true,
],
'expected' => '<html><body></body></html>',
]
// 'testShouldCombineV2' => [
// 'config' => [
// 'html' => file_get_contents( __DIR__ . '/HTML/input_v2.php' ),
// 'is_allowed' => true,
// ],
// 'expected' => file_get_contents( __DIR__ . '/HTML/expected_v2.php' ),
// ],
// 'testShouldCombineV1AndV2' => [
// 'config' => [
// 'html' => file_get_contents( __DIR__ . '/HTML/input_v1_v2.php' ),
// 'is_allowed' => true,
// ],
// 'expected' => file_get_contents( __DIR__ . '/HTML/expected_v1_v2.php' ),
// ],
// 'testShouldBailOutAsNoGoogleFontIncluded' => [
// 'config' => [
// 'html' => '<html><body></body></html>',
// 'is_allowed' => true,
// ],
// 'expected' => '<html><body></body></html>',
// ]
];
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,39 @@
/**
* @group GoogleFontHost
*/
class Test_RewriteFonts extends TestCase {
class Test_RewriteFonts extends FilesystemTestCase {
protected $path_to_test_data = '/inc/Engine/Media/Fonts/Frontend/Controller/rewriteFonts.php';
private $context;
private $combineV1;
private $combineV2;


public function set_up() {
parent::set_up();
error_reporting(E_ALL);
ini_set('display_errors', '1');

$this->context = Mockery::mock( Context::class );

$this->combineV1 = Mockery::mock( Combine::class );
$this->combineV2 = Mockery::mock( CombineV2::class );
}
/**
* @dataProvider configTestData
* @dataProvider providerTestData
*/
public function testShouldDoExpected( $config, $expected ) {
$context = Mockery::mock(Context::class);

$context->shouldReceive('is_allowed')
$this->context->shouldReceive('is_allowed')
->once()
->andReturn( $config['is_allowed'] );

$controller = new Controller($context, new Combine(), new CombineV2());
$controller = new Controller( $this->context, $this->combineV1, $this->combineV2 );
// foreach ($config['files'] as $file) {
// $directory = dirname($file['path']);
// if (!is_dir($directory)) {
// mkdir($directory, 0777, true);
// }
// file_put_contents($file['path'], '');
// }

$result = $controller->rewrite_fonts( $config['html'] );

Expand Down

0 comments on commit 32fa787

Please sign in to comment.