1 | <?php |
---|
2 | /** |
---|
3 | * Test wp_set_option_autoload(). |
---|
4 | * |
---|
5 | * @group option |
---|
6 | * |
---|
7 | * @covers ::wp_set_option_autoload |
---|
8 | */ |
---|
9 | class Tests_Option_WpSetOptionAutoload extends WP_UnitTestCase { |
---|
10 | |
---|
11 | /** |
---|
12 | * Tests that setting an option's autoload value to 'yes' works as expected. |
---|
13 | * |
---|
14 | * @ticket 58964 |
---|
15 | */ |
---|
16 | public function test_wp_set_option_autoload_yes() { |
---|
17 | global $wpdb; |
---|
18 | |
---|
19 | $option = 'test_option'; |
---|
20 | $value = 'value'; |
---|
21 | |
---|
22 | add_option( $option, $value, '', 'no' ); |
---|
23 | |
---|
24 | $this->assertTrue( wp_set_option_autoload( $option, 'yes' ), 'Function did not succeed' ); |
---|
25 | $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); |
---|
26 | $this->assertFalse( wp_cache_get( $option, 'options' ), 'Option not deleted from individual cache' ); |
---|
27 | $this->assertFalse( wp_cache_get( 'alloptions', 'options' ), 'Alloptions cache not cleared' ); |
---|
28 | } |
---|
29 | |
---|
30 | /** |
---|
31 | * Tests that setting an option's autoload value to 'no' works as expected. |
---|
32 | * |
---|
33 | * @ticket 58964 |
---|
34 | */ |
---|
35 | public function test_wp_set_option_autoload_no() { |
---|
36 | global $wpdb; |
---|
37 | |
---|
38 | $option = 'test_option'; |
---|
39 | $value = 'value'; |
---|
40 | |
---|
41 | add_option( $option, $value, '', 'yes' ); |
---|
42 | |
---|
43 | $this->assertTrue( wp_set_option_autoload( $option, 'no' ), 'Function did not succeed' ); |
---|
44 | $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); |
---|
45 | $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), 'Option not deleted from alloptions cache' ); |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * Tests that setting an option's autoload value to the same value as prior works as expected. |
---|
50 | * |
---|
51 | * @ticket 58964 |
---|
52 | */ |
---|
53 | public function test_wp_set_option_autoload_same() { |
---|
54 | global $wpdb; |
---|
55 | |
---|
56 | $option = 'test_option'; |
---|
57 | $value = 'value'; |
---|
58 | |
---|
59 | add_option( $option, $value, '', 'yes' ); |
---|
60 | |
---|
61 | $this->assertFalse( wp_set_option_autoload( $option, 'yes' ), 'Function did unexpectedly succeed' ); |
---|
62 | $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value unexpectedly updated in database' ); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Tests that setting a missing option's autoload value does not do anything. |
---|
67 | * |
---|
68 | * @ticket 58964 |
---|
69 | */ |
---|
70 | public function test_wp_set_option_autoload_missing() { |
---|
71 | global $wpdb; |
---|
72 | |
---|
73 | $option = 'test_option'; |
---|
74 | |
---|
75 | $this->assertFalse( wp_set_option_autoload( $option, 'yes' ), 'Function did unexpectedly succeed' ); |
---|
76 | $this->assertNull( $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Missing option autoload value was set in database' ); |
---|
77 | $this->assertArrayNotHasKey( $option, wp_cache_get( 'alloptions', 'options' ), 'Missing option found in alloptions cache' ); |
---|
78 | $this->assertFalse( wp_cache_get( $option, 'options' ), 'Missing option found in individual cache' ); |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Tests setting an option's autoload value to boolean true. |
---|
83 | * |
---|
84 | * @ticket 58964 |
---|
85 | */ |
---|
86 | public function test_wp_set_option_autoload_true() { |
---|
87 | global $wpdb; |
---|
88 | |
---|
89 | $option = 'test_option'; |
---|
90 | $value = 'value'; |
---|
91 | |
---|
92 | add_option( $option, $value, '', false ); |
---|
93 | |
---|
94 | $this->assertTrue( wp_set_option_autoload( $option, true ), 'Function did not succeed' ); |
---|
95 | $this->assertSame( 'yes', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Tests setting an option's autoload value to boolean false. |
---|
100 | * |
---|
101 | * @ticket 58964 |
---|
102 | */ |
---|
103 | public function test_wp_set_option_autoload_false() { |
---|
104 | global $wpdb; |
---|
105 | |
---|
106 | $option = 'test_option'; |
---|
107 | $value = 'value'; |
---|
108 | |
---|
109 | add_option( $option, $value, '', true ); |
---|
110 | |
---|
111 | $this->assertTrue( wp_set_option_autoload( $option, false ), 'Function did not succeed' ); |
---|
112 | $this->assertSame( 'no', $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option ) ), 'Option autoload value not updated in database' ); |
---|
113 | } |
---|
114 | } |
---|