Skip to content

Commit 15ce03c

Browse files
committed
Add ITTrait installStringPlugin
It's easy to test with simple plugins that are just a few lines of inline string. Add a function to support this.
1 parent 4323525 commit 15ce03c

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

tests/integration/ITTrait.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ public function getOptionValue( string $option_name ): string {
105105
return $lines[ count( $lines ) - 1 ];
106106
}
107107

108+
/**
109+
* Install a plugin from a string
110+
*/
111+
public function installStringPlugin(
112+
string $plugin_name,
113+
string $plugin_content,
114+
): void {
115+
$plugin_dir = ITEnv::getPluginsDir() . '/' . $plugin_name;
116+
$result = exec( 'mkdir -p ' . escapeshellarg( $plugin_dir ) );
117+
$this->assertNotFalse( $result );
118+
$plugin_filename = $plugin_dir . '/' . $plugin_name . '.php';
119+
$written = file_put_contents( $plugin_filename, $plugin_content );
120+
$this->assertNotFalse( $written );
121+
$this->wpCli( [ 'plugin', 'activate', $plugin_name ] );
122+
}
123+
108124
public function setOptionValue(
109125
string $option_name,
110126
string $option_value,

tests/integration/OptionsTest.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,10 @@ public function testCliCommands(): void {
9595
);
9696
}
9797

98-
public function testOptionFilters(): void
99-
{
100-
$plugin_dir = ITEnv::getPluginsDir() . '/options-test';
101-
98+
public function testOptionFilters(): void {
10299
$this->assertEquals( '0', $this->getOptionValue( 'processQueueImmediately' ) );
103100

104-
exec( 'mkdir -p ' . escapeshellarg( $plugin_dir ) );
105-
file_put_contents( $plugin_dir . '/options-test.php', $this->optionsTestFilters() );
106-
$this->wpCli( [ 'plugin', 'activate', 'options-test' ] );
107-
$this->assertEquals( '1', $this->getOptionValue( 'processQueueImmediately' ) );
108-
}
109-
110-
private function optionsTestFilters(): string
111-
{
112-
return <<<PHP
101+
$plugin = <<<PHP
113102
<?php
114103
115104
/**
@@ -125,5 +114,8 @@ function processQueueImmediately_filter ( $val ) {
125114
}
126115
add_filter( 'static_deploy_option_processQueueImmediately', 'processQueueImmediately_filter' );
127116
PHP;
117+
$this->installStringPlugin( 'options-test', $plugin );
118+
119+
$this->assertEquals( '1', $this->getOptionValue( 'processQueueImmediately' ) );
128120
}
129121
}

0 commit comments

Comments
 (0)