Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36bada3

Browse files
obenlandpfefferle
andauthoredMay 13, 2025··
Surge: Don't use AP constant in wp-config. (#1696)
Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent fc779c5 commit 36bada3

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed
 

‎integration/class-surge.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@
1515
* @see https://wordpress.org/plugins/surge/
1616
*/
1717
class Surge {
18-
/**
19-
* The define for the Surge cache config.
20-
*
21-
* @var string
22-
*/
23-
public static $cache_config = "define( 'WP_CACHE_CONFIG', '' . ACTIVITYPUB_PLUGIN_DIR . 'integration/surge-cache-config.php' );";
2418

2519
/**
26-
* The pattern to find the define for the Surge cache config.
20+
* The pattern to find the Surge cache config constant.
2721
*
2822
* @var string
2923
*/
@@ -66,9 +60,9 @@ public static function add_cache_config() {
6660
// Add a WP_CACHE_CONFIG to wp-config.php.
6761
$anchor = "/* That's all, stop editing!";
6862
if ( false !== \strpos( $config, $anchor ) ) {
69-
$config = \str_replace( $anchor, self::$cache_config . PHP_EOL . PHP_EOL . $anchor, $config );
63+
$config = \str_replace( $anchor, self::get_cache_config() . PHP_EOL . PHP_EOL . $anchor, $config );
7064
} elseif ( false !== \strpos( $config, '<?php' ) ) {
71-
$config = \str_replace( '<?php', '<?php' . PHP_EOL . PHP_EOL . self::$cache_config . PHP_EOL, $config );
65+
$config = \str_replace( '<?php', '<?php' . PHP_EOL . PHP_EOL . self::get_cache_config() . PHP_EOL, $config );
7266
}
7367

7468
$wp_filesystem->put_contents( $file, $config, FS_CHMOD_FILE );
@@ -177,11 +171,20 @@ public static function test_surge_integration() {
177171
\sprintf(
178172
// translators: %s: Plugin directory path.
179173
\__( 'To enable the ActivityPub integration with Surge, add the following line to your <code>wp-config.php</code> file: <br /><code>%s</code>', 'activitypub' ),
180-
self::$cache_config
174+
self::get_cache_config()
181175
)
182176
);
183177
}
184178

185179
return $result;
186180
}
181+
182+
/**
183+
* Get the cache config.
184+
*
185+
* @return string The cache config.
186+
*/
187+
public static function get_cache_config() {
188+
return \sprintf( "define( 'WP_CACHE_CONFIG', '%s/integration/surge-cache-config.php' );", \rtrim( ACTIVITYPUB_PLUGIN_DIR, '/' ) );
189+
}
187190
}

‎tests/integration/class-test-akismet.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/**
1414
* Test Akismet Integration class.
1515
*
16+
* @group integration
1617
* @coversDefaultClass \Activitypub\Integration\Akismet
1718
*/
1819
class Test_Akismet extends WP_UnitTestCase {

‎tests/integration/class-test-enable-mastodon-apps.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* Test class for Enable Mastodon Apps integration.
1414
*
15+
* @group integration
1516
* @coversDefaultClass \Activitypub\Integration\Enable_Mastodon_Apps
1617
*/
1718
class Test_Enable_Mastodon_Apps extends \WP_UnitTestCase {

‎tests/integration/class-test-seriously-simple-podcasting.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/**
1111
* Test class for Seriously Simple Podcasting integration.
1212
*
13+
* @group integration
1314
* @coversDefaultClass \Activitypub\Integration\Seriously_Simple_Podcasting
1415
*/
1516
class Test_Seriously_Simple_Podcasting extends \WP_UnitTestCase {

‎tests/integration/class-test-surge.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
/**
1313
* Test Surge integration.
14+
*
15+
* @group integration
16+
* @coversDefaultClass \Activitypub\Integration\Surge
1417
*/
1518
class Test_Surge extends \WP_UnitTestCase {
1619
/**
@@ -21,11 +24,11 @@ class Test_Surge extends \WP_UnitTestCase {
2124
private $test_file;
2225

2326
/**
24-
* Original config file path.
27+
* Config contents.
2528
*
2629
* @var string
2730
*/
28-
private $original_config_file;
31+
private $config_contents;
2932

3033
/**
3134
* Original cache config.
@@ -83,7 +86,7 @@ public function test_add_cache_config() {
8386

8487
$this->assertStringContainsString( '<?php', $file, 'File should start with PHP opening tag' );
8588
$this->assertStringContainsString( "/* That's all, stop editing! */", $file, 'Comment should be present' );
86-
$this->assertStringContainsString( Surge::$cache_config, $file, 'Config line should be present' );
89+
$this->assertStringContainsString( Surge::get_cache_config(), $file, 'Config line should be present' );
8790
}
8891

8992
/**
@@ -101,7 +104,7 @@ public function test_remove_cache_config() {
101104
// phpcs:ignore
102105
$actual = \file_get_contents( Surge::get_config_file_path() );
103106
$this->assertStringContainsString( '<?php', $actual, 'File should start with PHP opening tag' );
104-
$this->assertStringNotContainsString( Surge::$cache_config, $actual, 'Config line should be removed' );
107+
$this->assertStringNotContainsString( Surge::get_cache_config(), $actual, 'Config line should be removed' );
105108
$this->assertStringContainsString( "/* That's all, stop editing! */", $actual, 'Comment should be present' );
106109
}
107110

@@ -115,7 +118,7 @@ public function test_init_with_surge_active() {
115118

116119
// phpcs:ignore
117120
$before = \file_get_contents( Surge::get_config_file_path() );
118-
$this->assertStringNotContainsString( Surge::$cache_config, $before );
121+
$this->assertStringNotContainsString( Surge::get_cache_config(), $before );
119122

120123
Surge::init();
121124

@@ -124,7 +127,7 @@ public function test_init_with_surge_active() {
124127

125128
// phpcs:ignore
126129
$after = \file_get_contents( Surge::get_config_file_path() );
127-
$this->assertStringContainsString( Surge::$cache_config, $after );
130+
$this->assertStringContainsString( Surge::get_cache_config(), $after );
128131

129132
\remove_all_filters( 'pre_option_active_plugins' );
130133
}
@@ -145,7 +148,7 @@ public function get_active_plugins() {
145148
*/
146149
public function test_init_with_surge_inactive() {
147150
// phpcs:ignore
148-
\file_put_contents( Surge::get_config_file_path(), "<?php\n" . Surge::$cache_config . "\n\n/* That's all, stop editing! */" );
151+
\file_put_contents( Surge::get_config_file_path(), "<?php\n" . Surge::get_cache_config() . "\n\n/* That's all, stop editing! */" );
149152
\add_filter( 'pre_option_active_plugins', array( $this, 'get_inactive_plugins' ) );
150153

151154
Surge::init();
@@ -155,7 +158,7 @@ public function test_init_with_surge_inactive() {
155158

156159
// phpcs:ignore
157160
$after = \file_get_contents( Surge::get_config_file_path() );
158-
$this->assertStringNotContainsString( Surge::$cache_config, $after );
161+
$this->assertStringNotContainsString( Surge::get_cache_config(), $after );
159162

160163
\remove_all_filters( 'pre_option_active_plugins' );
161164
}

0 commit comments

Comments
 (0)
Please sign in to comment.