@@ 2568-2584 (lines=17) @@ | ||
2565 | * |
|
2566 | * Exception case: image served by .php, should not be proxied. |
|
2567 | */ |
|
2568 | public function test_imgopt_php() |
|
2569 | { |
|
2570 | $opts = autoptimizeImages::fetch_options(); |
|
2571 | $opts['autoptimize_imgopt_checkbox_field_1'] = '1'; |
|
2572 | $opts['autoptimize_imgopt_checkbox_field_3'] = '0'; |
|
2573 | ||
2574 | $markup = <<<MARKUP |
|
2575 | <img src='/wp-content/plugins/imageplugin/image.php?id=16' width='400' height='200'> |
|
2576 | MARKUP; |
|
2577 | ||
2578 | $instance = autoptimizeImages::instance(); |
|
2579 | $instance->set_options( $opts ); |
|
2580 | $actual = $instance->filter_optimize_images( $markup ); |
|
2581 | ||
2582 | // Expecting $markup since replacement should not happen. |
|
2583 | $this->assertEquals( $markup, $actual ); |
|
2584 | } |
|
2585 | ||
2586 | /** |
|
2587 | * Test image optimization in autoptimizeImages.php. |
|
@@ 2779-2796 (lines=18) @@ | ||
2776 | /** |
|
2777 | * Test preloading of resources (e.g. fonts). |
|
2778 | */ |
|
2779 | public function test_preload() |
|
2780 | { |
|
2781 | $opts = autoptimizeExtra::fetch_options(); |
|
2782 | $opts['autoptimize_extra_text_field_7'] = 'https://whatever.com/fonts/openfuttta.woff2, https://whatever.com/css/openfuttta.css'; |
|
2783 | ||
2784 | $markup = <<<MARKUP |
|
2785 | <html><link rel="stylesheet" href="xyz.css"> |
|
2786 | MARKUP; |
|
2787 | ||
2788 | $expected = <<<MARKUP |
|
2789 | <html><link rel="preload" href="https://whatever.com/fonts/openfuttta.woff2" as="font" type="font/woff2" crossorigin><link rel="preload" href="https://whatever.com/css/openfuttta.css" as="style"><link rel="stylesheet" href="xyz.css"> |
|
2790 | MARKUP; |
|
2791 | ||
2792 | $instance = autoptimizeExtra::instance(); |
|
2793 | $instance->set_options( $opts ); |
|
2794 | $actual = $instance->filter_preload( $markup ); |
|
2795 | $this->assertEquals( $expected, $actual ); |
|
2796 | } |
|
2797 | ||
2798 | /** |
|
2799 | * Test preloading of resources (e.g. fonts). |
|
@@ 2801-2818 (lines=18) @@ | ||
2798 | /** |
|
2799 | * Test preloading of resources (e.g. fonts). |
|
2800 | */ |
|
2801 | public function test_preload_withqs() |
|
2802 | { |
|
2803 | $opts = autoptimizeExtra::fetch_options(); |
|
2804 | $opts['autoptimize_extra_text_field_7'] = 'https://whatever.com/fonts/openfuttta.woff2?123#abc, https://whatever.com/css/openfuttta.css?v=124'; |
|
2805 | ||
2806 | $markup = <<<MARKUP |
|
2807 | <html><link rel="stylesheet" href="xyz.css"> |
|
2808 | MARKUP; |
|
2809 | ||
2810 | $expected = <<<MARKUP |
|
2811 | <html><link rel="preload" href="https://whatever.com/fonts/openfuttta.woff2?123#abc" as="font" type="font/woff2" crossorigin><link rel="preload" href="https://whatever.com/css/openfuttta.css?v=124" as="style"><link rel="stylesheet" href="xyz.css"> |
|
2812 | MARKUP; |
|
2813 | ||
2814 | $instance = autoptimizeExtra::instance(); |
|
2815 | $instance->set_options( $opts ); |
|
2816 | $actual = $instance->filter_preload( $markup ); |
|
2817 | $this->assertEquals( $expected, $actual ); |
|
2818 | } |
|
2819 | ||
2820 | /** |
|
2821 | * Test aggregating Google Fonts. |
|
@@ 2823-2840 (lines=18) @@ | ||
2820 | /** |
|
2821 | * Test aggregating Google Fonts. |
|
2822 | */ |
|
2823 | public function test_google_font_aggregate_preload() |
|
2824 | { |
|
2825 | $opts = autoptimizeExtra::fetch_options(); |
|
2826 | $opts['autoptimize_extra_radio_field_4'] = '5'; |
|
2827 | ||
2828 | $markup = <<<MARKUP |
|
2829 | <link href='//fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,300,600&subset=latin,cyrillic-ext,greek-ext,greek,vietnamese,latin-ext,cyrillic' rel='stylesheet' type='text/css'><link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,700;1,400'><link rel="dummy"> |
|
2830 | MARKUP; |
|
2831 | ||
2832 | $expected = <<<MARKUP |
|
2833 | <link rel="stylesheet" media="print" onload="this.onload=null;this.media='all';" id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,400,300,600%7CCrimson+Pro:700,italic400&subset=latin%2Ccyrillic-ext%2Cgreek-ext%2Cgreek%2Cvietnamese%2Clatin-ext%2Ccyrillic&display=swap" /><link rel="dummy"> |
|
2834 | MARKUP; |
|
2835 | ||
2836 | $instance = autoptimizeExtra::instance(); |
|
2837 | $instance->set_options( $opts ); |
|
2838 | $actual = $instance->filter_optimize_google_fonts( $markup ); |
|
2839 | $this->assertEquals( $expected, $actual ); |
|
2840 | } |
|
2841 | ||
2842 | /** |
|
2843 | * Test network vs site settings: network only. |