Skip to content

Commit

Permalink
Add integration tests folder with a proof-of-concept test
Browse files Browse the repository at this point in the history
  • Loading branch information
enricobattocchi committed Jun 29, 2023
1 parent 93bad42 commit 7a81692
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 0 deletions.
43 changes: 43 additions & 0 deletions phpunit-integration.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/integration/bootstrap.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
verbose="true"
>
<testsuites>
<testsuite name="duplicatepost">
<directory suffix="-test.php">./tests/integration</directory>
</testsuite>
</testsuites>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="false">
<file>./admin-functions.php</file>
<file>./common-functions.php</file>
<file>./duplicate-post.php</file>
<file>./options.php</file>
<directory>./compat</directory>
<directory>./src</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
<log type="coverage-clover" target="build/logs/clover-integration.xml"/>
</logging>

</phpunit>
73 changes: 73 additions & 0 deletions tests/integration/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Yoast Duplicate Post plugin test file.
*
* @package Yoast\WP\Duplicate_Post\Tests
*/

use Yoast\WPTestUtils\WPIntegration;

// Disable xdebug backtrace.
if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
}

echo 'Welcome to the Duplicate Post Test Suite' . PHP_EOL;
echo 'Version: 1.0' . PHP_EOL . PHP_EOL;

/*
* Set up info needed for checking the status of a GitHub issue.
*/
$GLOBALS['github_repo'] = [
'name' => 'Yoast Duplicate Post',
'organisation' => 'Yoast',
'repo_slug' => 'duplicate-post',
'api_key' => false,
'private' => true,
];

if ( getenv( 'GITHUB_API_KEY' ) !== false ) {
$GLOBALS['github_repo']['api_key'] = getenv( 'GITHUB_API_KEY' );
}

if ( ! defined( 'WP_TESTS_FORCE_KNOWN_BUGS' ) ) {
define( 'WP_TESTS_FORCE_KNOWN_BUGS', ( getenv( 'WP_TESTS_FORCE_KNOWN_BUGS' ) === '1' ) );
}

if ( ! defined( 'YOAST_DUPLICATE_POST_TEST_ROOT_DIR' ) ) {
define( 'YOAST_DUPLICATE_POST_TEST_ROOT_DIR', __DIR__ . '/' ); // Includes trailing slash.
}

/*
* Load the plugin(s).
*/
require_once dirname( dirname( __DIR__ ) ) . '/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php';

$GLOBALS['wp_tests_options'] = [
'active_plugins' => [
'duplicate-post/duplicate-post',
],
];

$_wp_tests_dir = WPIntegration\get_path_to_wp_test_dir();
if ( $_wp_tests_dir === false ) {
$_wp_tests_dir = YOAST_DUPLICATE_POST_TEST_ROOT_DIR . '../../../../tests/phpunit/';
}


// Load some helpful functions.
require_once $_wp_tests_dir . 'includes/functions.php';

/**
* Activates this plugin in WordPress so it can be tested.
*/
function _manually_load_plugin() {
require YOAST_DUPLICATE_POST_TEST_ROOT_DIR . '../../duplicate-post.php';
}

tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

/*
* Load WordPress, which will load the Composer autoload file, and load the MockObject autoloader after that.
*/
WPIntegration\bootstrap_it();
54 changes: 54 additions & 0 deletions tests/integration/post-duplicator-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Yoast\WP\Duplicate_Post\Tests\Integration;

/**
* Yoast Duplicate Post plugin test file.
*
* @package Yoast\WP\Duplicate_Post\Tests
*/

use Yoast\WPTestUtils\WPIntegration\TestCase;
use Yoast\WP\Duplicate_Post\Post_Duplicator;

/**
* Class Post_Duplicator.
*
* @coversDefaultClass \Yoast\WP\Duplicate_Post\Post_Duplicator
*/
class Post_Duplicator_Test extends TestCase {

/**
* Instance of the Post_Duplicator class.
*
* @var Post_Duplicator
*/
private $instance;

/**
* Setting up the instance of Post_Duplicator.
*/
public function set_up() {
parent::set_up();

$this->instance = new Post_Duplicator();
}

/**
* Tests whether the admin page is generated correctly.
*
* @covers ::create_duplicate
* @covers ::get_default_options
* @covers ::generate_copy_title
* @covers ::generate_copy_status
* @covers ::generate_copy_author
*/
public function test_create_duplicate() {

$post = $this->factory->post->create_and_get();

$id = $this->instance->create_duplicate( $post );

$this->assertTrue( \is_int( $id ) );
}
}

0 comments on commit 7a81692

Please sign in to comment.