bootstrap.php ➔ _manually_load_plugin()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 46

Duplication

Lines 4
Ratio 8.7 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 0
dl 4
loc 46
rs 9.1781
c 0
b 0
f 0
1
<?php
2
/**
3
 * WP tests bootstrap.
4
 */
5
6
$_tests_dir = getenv( 'WP_TESTS_DIR' );
7
if ( ! $_tests_dir ) {
8
    $tmp_dir = getenv( 'TMPDIR' );
9
    if ( ! empty( $tmp_dir ) ) {
10
        $_tests_dir = rtrim( $tmp_dir, '/' ) . '/wordpress-tests-lib';
11
        if ( ! is_dir( $_tests_dir ) ) {
12
            $_tests_dir = null;
13
        }
14
    }
15
}
16
17
if ( ! $_tests_dir ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $_tests_dir of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
18
    $_tests_dir = '/tmp/wordpress-tests-lib';
19
}
20
21
require_once $_tests_dir . '/includes/functions.php';
22
23
function _manually_load_plugin() {
24
    define( 'AUTOPTIMIZE_INIT_EARLIER', true );
25
26
    // For overriding cache dirs and whatnot. Kinda works if you keep a few things in mind.
27
    if ( getenv('CUSTOM_CONSTANTS' ) ) {
28
        define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/c/ao/' );
29
        $pathname = WP_CONTENT_DIR . AUTOPTIMIZE_CACHE_CHILD_DIR;
30 View Code Duplication
        if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
            $blog_id   = get_current_blog_id();
32
            $pathname .= $blog_id . '/';
33
        }
34
        define( 'AUTOPTIMIZE_CACHE_DIR', $pathname );
35
36
        $custom_site_url = 'http://localhost/wordpress';
37
        define( 'AUTOPTIMIZE_WP_SITE_URL', $custom_site_url );
38
        add_filter( 'site_url', function( $url, $path, $scheme, $blog_id ) use ( $custom_site_url ) {
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $scheme is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $blog_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
            return $custom_site_url;
40
        }, 10, 4 );
41
        add_filter( 'content_url', function( $url, $path ) use ( $custom_site_url ) {
0 ignored issues
show
Unused Code introduced by
The parameter $url is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $path is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
42
            return $custom_site_url . '/wp-content';
43
        }, 10, 2 );
44
        define( 'AO_TEST_SUBFOLDER_INSTALL', true );
45
46
        define( 'CUSTOM_CONSTANTS_USED', true );
47
    } else {
48
        define( 'CUSTOM_CONSTANTS_USED', false );
49
        define( 'AO_TEST_SUBFOLDER_INSTALL', false );
50
    }
51
52
    /*
53
    $active_plugins = array('autoptimize/autoptimize.php');
54
    update_option( 'active_plugins', $active_plugins );
55
    */
56
57
    update_option( 'autoptimize_js', 1 );
58
    update_option( 'autoptimize_css', 1 );
59
    update_option( 'autoptimize_html', 0 );
60
    update_option( 'autoptimize_cdn_url', 'http://cdn.example.org' );
61
    update_option( 'autoptimize_cache_nogzip', 1 );
62
63
    add_filter( 'autoptimize_css_include_inline', function( $include_inline ) {
0 ignored issues
show
Unused Code introduced by
The parameter $include_inline is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
        return true;
65
    });
66
67
    require dirname( dirname( __FILE__ ) ) . '/autoptimize.php';
68
}
69
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
70
71
require $_tests_dir . '/includes/bootstrap.php';
72