forked from GlotPress/GlotPress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcase.php
70 lines (56 loc) · 1.53 KB
/
testcase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require_once dirname( __FILE__ ) . '/factory.php';
class GP_UnitTestCase extends WP_UnitTestCase {
/**
* @var string
*/
public $url = 'http://example.org/';
/**
* @var GP_UnitTest_Factory
*/
public $factory;
function setUp(): void {
parent::setUp();
$this->factory = new GP_UnitTest_Factory();
global $wp_rewrite;
if ( GP_TESTS_PERMALINK_STRUCTURE != $wp_rewrite->permalink_structure ) {
$this->set_permalink_structure( GP_TESTS_PERMALINK_STRUCTURE );
}
}
/**
* Utility method that resets permalinks and flushes rewrites.
*
* Also updates the pre_option filter for `permalink_structure`.
*
* @global WP_Rewrite $wp_rewrite
*
* @param string $structure Optional. Permalink structure to set. Default empty.
*/
public function set_permalink_structure( $structure = '' ) {
global $wp_tests_options;
$wp_tests_options['permalink_structure'] = $structure;
parent::set_permalink_structure( $structure );
}
function clean_up_global_scope() {
parent::clean_up_global_scope();
$locales = &GP_Locales::instance();
$locales->locales = array();
$_GET = array();
$_POST = array();
/**
* @todo re-initialize all thing objects
*/
GP::$translation_set = new GP_Translation_Set;
GP::$original = new GP_Original;
}
function set_normal_user_as_current() {
$user = $this->factory->user->create();
wp_set_current_user( $user );
return $user;
}
function set_admin_user_as_current() {
$admin = $this->factory->user->create_admin();
wp_set_current_user( $admin );
return $admin;
}
}