Skip to content

Commit

Permalink
add test for WordPress SEO connector
Browse files Browse the repository at this point in the history
currently fails to reproduce #1489, #1443
  • Loading branch information
tharsheblows committed Jul 17, 2024
1 parent 2af6be4 commit 0628827
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/stream.zip
/stream-*.zip
npm-debug.log
debug.log
package.lock
.phpunit.result.cache

Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"wpackagist-plugin/easy-digital-downloads": "2.9.23",
"wpackagist-plugin/jetpack": "10.0",
"wpackagist-plugin/user-switching": "1.5.5",
"wpackagist-plugin/wordpress-seo": "23.0",
"wpackagist-theme/twentytwentythree": "^1.0",
"xwp/wait-for": "^0.0.1",
"yoast/phpunit-polyfills": "^1.1"
Expand Down Expand Up @@ -70,6 +71,10 @@
"phpunit --coverage-text",
"php local/scripts/make-clover-relative.php ./tests/reports/clover.xml"
],
"test-one": [
"phpunit",
"WP_MULTISITE=1 phpunit"
],
"test-multisite": [
"WP_MULTISITE=1 phpunit --coverage-text",
"php local/scripts/make-clover-relative.php ./tests/reports/clover.xml"
Expand Down
20 changes: 19 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions local/public/wp-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$table_prefix = 'wp_';

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'JETPACK_DEV_DEBUG', true );

// Keep the wp-contents outside of WP core directory.
Expand Down
1 change: 1 addition & 0 deletions local/public/wp-content/plugins/hello.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
* Description: A plugin used for PHP unit tests
*/


1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"test": "npm-run-all test:*",
"test:php": "npm run cli -- composer test --working-dir=wp-content/plugins/stream-src",
"test:php-multisite": "npm run cli -- composer test-multisite --working-dir=wp-content/plugins/stream-src",
"test:php:one": "npm run cli -- composer test-one --working-dir=wp-content/plugins/stream-src --",
"test-report": "npm run cli -- composer test-report --working-dir=wp-content/plugins/stream-src",
"build-containers": "docker compose --file docker-compose.build.yml build",
"push-containers": "docker compose --file docker-compose.build.yml push",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<php>
<const
name="WP_TEST_ACTIVATED_PLUGINS"
value="advanced-custom-fields/acf.php,easy-digital-downloads/easy-digital-downloads.php,jetpack/jetpack.php,user-switching/user-switching.php"
value="advanced-custom-fields/acf.php,easy-digital-downloads/easy-digital-downloads.php,jetpack/jetpack.php,user-switching/user-switching.php,wordpress-seo/wp-seo.php"
/>
</php>
<testsuites>
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function( $status = false, $args = array(), $url = '') {
define( 'EDD_USE_PHP_SESSIONS', false );
define( 'WP_USE_THEMES', false );
activate_plugin( 'easy-digital-downloads/easy-digital-downloads.php' );
activate_plugin( 'wordpress-seo/wp-seo.php' );
xwp_install_edd();

require __DIR__ . '/testcase.php';
Expand Down
83 changes: 83 additions & 0 deletions tests/tests/connectors/test-class-connector-wordpress-seo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* WP Integration Test w/ WordPress SEO plugin
*
* Tests for WordPress SEO connector class callbacks.
*
* @package WP_Stream
*/
namespace WP_Stream;

class Test_WP_Stream_Connector_WordPress_SEO extends WP_StreamTestCase {

/**
* The WordPress SEO title meta key.
*
* @var string
*/
protected $title_meta_key = '_yoast_wpseo_title';

/**
* Runs before each test
*/
public function setUp(): void {
parent::setUp();

$this->plugin->connectors->unload_connectors();

// Make partial of Connector_WordPress_SEO class, with mocked "log" function.
$this->mock = $this->getMockBuilder( Connector_WordPress_SEO::class )
->setMethods( array( 'log' ) )
->getMock();

// Register connector.
$this->mock->register();
}

/**
* Confirm that WordPress SEO is installed and active.
*/
public function test_wordpress_seo_installed_and_activated() {
$this->assertTrue( defined( 'YOAST_ENVIRONMENT' ) );
}

/**
* Tests "added_post_meta" callback function.
* callback_added_post_meta( $meta_id, $object_id, $meta_key, $meta_value )
*/
public function test_callback_added_post_meta() {

// Set expected calls for the Mock.
$this->mock->expects( $this->once() )
->method( 'log' )
->with(
$this->equalTo(
__( 'Updated "SEO title" of "Test post %%!" Post', 'stream' )
),
$this->equalTo(
array(
'meta_key' => $this->title_meta_key,
'meta_value' => 'Test meta %!',
'post_type' => 'post',
)
),
$this->greaterThan( 0 ),
'wpseo_meta',
'updated'
);

// Create post for later use.
$post_id = wp_insert_post(
array(
'post_title' => 'Test post %!',
'post_content' => 'Lorem ipsum dolor...',
'post_status' => 'publish'
)
);

update_post_meta( $post_id, $this->title_meta_key, 'Test meta %!' );

// Confirm callback execution.
$this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_added_post_meta' ) );
}
}

0 comments on commit 0628827

Please sign in to comment.