Completed
Branch develop (6e04c9)
by
unknown
02:44
created

bootstrap.php ➔ test_rest_expand_compact_links()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
eloc 12
nc 4
nop 1
dl 0
loc 18
rs 9.2
1
<?php
2
/**
3
 * Bootstrap the plugin unit testing environment.
4
 *
5
 * @package WordPress
6
 * @subpackage JSON API
7
 */
8
9
/**
10
 * Determine where the WP test suite lives.
11
 *
12
 * Support for:
13
 * 1. `WP_DEVELOP_DIR` environment variable, which points to a checkout
14
 *   of the develop.svn.wordpress.org repository (this is recommended)
15
 * 2. `WP_TESTS_DIR` environment variable, which points to a checkout
16
 * 3. `WP_ROOT_DIR` environment variable, which points to a checkout
17
 * 4. Plugin installed inside of WordPress.org developer checkout
18
 * 5. Tests checked out to /tmp
19
 */
20
if ( false !== getenv( 'WP_DEVELOP_DIR' ) ) {
21
	$test_root = getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit';
22
} else if ( false !== getenv( 'WP_TESTS_DIR' ) ) {
23
	$test_root = getenv( 'WP_TESTS_DIR' );
24
} else if ( false !== getenv( 'WP_ROOT_DIR' ) ) {
25
	$test_root = getenv( 'WP_ROOT_DIR' ) . '/tests/phpunit';
26
} else if ( file_exists( '../../../../tests/phpunit/includes/bootstrap.php' ) ) {
27
	$test_root = '../../../../tests/phpunit';
28
} else if ( file_exists( '/tmp/wordpress-tests-lib/includes/bootstrap.php' ) ) {
29
	$test_root = '/tmp/wordpress-tests-lib';
30
}
31
32
require $test_root . '/includes/functions.php';
33
34
function _manually_load_plugin() {
35
	require dirname( __FILE__ ) . '/../plugin.php';
36
}
37
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
38
39
require $test_root . '/includes/bootstrap.php';
40
41
define( 'REST_TESTS_IMPOSSIBLY_HIGH_NUMBER', 99999999 );
42
define( 'REST_REQUEST', true );
43
44
// Helper classes
45
if ( ! class_exists( 'WP_Test_REST_TestCase' ) ) {
46
	require_once dirname( __FILE__ ) . '/class-wp-test-rest-testcase.php';
47
}
48
function test_rest_expand_compact_links( $links ) {
49
	if ( empty( $links['curies'] ) ) {
50
		return $links;
51
	}
52
	foreach ( $links as $rel => $links_array ) {
53
		if ( ! strpos( $rel, ':' ) ) {
54
			continue;
55
		}
56
57
		$name = explode( ':', $rel );
58
59
		$curie = wp_list_filter( $links['curies'], array( 'name' => $name[0] ) );
60
		$full_uri = str_replace( '{rel}', $name[1], $curie[0]['href'] );
61
		$links[ $full_uri ] = $links_array;
62
		unset( $links[ $rel ] );
63
	}
64
	return $links;
65
}
66
67
require_once dirname( __FILE__ ) . '/class-wp-test-rest-controller-testcase.php';
68
require_once dirname( __FILE__ ) . '/class-wp-test-rest-post-type-controller-testcase.php';
69
require_once dirname( __FILE__ ) . '/class-wp-test-spy-rest-server.php';
70
require_once dirname( __FILE__ ) . '/class-wp-rest-test-controller.php';
71