diff --git a/composer.json b/composer.json
index ac3e80b..6df7ea9 100644
--- a/composer.json
+++ b/composer.json
@@ -19,13 +19,18 @@
"install-codestandards": [
"Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
],
- "test:unit": "phpunit"
+ "test": "./vendor/bin/phpunit --colors --stop-on-failure"
},
"autoload": {
"psr-4": {
"GiveDivi\\": "src/"
}
},
+ "autoload-dev": {
+ "psr-4": {
+ "GiveDivi\\Tests\\": "tests/"
+ }
+ },
"config": {
"platform": {
"php": "7.2"
diff --git a/give-divi.php b/give-divi.php
index 490414f..6d9edfc 100644
--- a/give-divi.php
+++ b/give-divi.php
@@ -4,7 +4,7 @@
* Plugin URI: https://go.givewp.com/divi-addon
* Description: Use GiveWP shortcodes as Divi modules
* Version: 2.0.0
- * Requires at least: 6.0
+ * Requires at least: 6.3
* Requires PHP: 7.2
* Author: GiveWP
* Author URI: https://givewp.com/
diff --git a/phpunit.xml b/phpunit.xml
index 3f08636..a1b4ad0 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,33 +1,21 @@
-
-
- ./tests/unit/tests
-
-
-
-
- ./templates/
- ./tests/
- ./tmp/
- ./languages/
- ./tests/
- ./templates/
- ./includes/libraries/
- ./includes/admin/tools/export
- ./includes/admin/reporting/tools/
-
-
-
-
-
-
\ No newline at end of file
+ bootstrap="tests/bootstrap.php"
+ backupGlobals="false"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ verbose="true"
+>
+
+
+ ./tests/Unit
+ ./tests/Unit
+
+
+ ./tests/Feature
+ ./tests/Feature
+
+
+
diff --git a/readme.txt b/readme.txt
index 205b50f..197ada7 100644
--- a/readme.txt
+++ b/readme.txt
@@ -2,8 +2,8 @@
Contributors: givewp, dlocc, webdevmattcrom, jason_the_adams
Donate link: https://givewp.com/
Tags: givewp, donation, divi, divi modules, fundraising
-Requires at least: 6.0
-Tested up to: 6.4
+Requires at least: 6.3
+Tested up to: 6.5
Requires PHP: 7.2
Stable tag: 2.0.0
Requires Give: 3.0.0
@@ -94,7 +94,7 @@ Automatic updates should work like a charm; as always though, ensure you back up
== Changelog ==
-### 2.0.0 February 12th, 2024 ###
+### 2.0.0 May 15th, 2024 ###
* New: Added compatibility with the GiveWP visual form builder
### 1.0.3 March 3rd, 2022 ###
diff --git a/tests/Unit/TestGiveDivi.php b/tests/Unit/TestGiveDivi.php
new file mode 100644
index 0000000..a547121
--- /dev/null
+++ b/tests/Unit/TestGiveDivi.php
@@ -0,0 +1,90 @@
+ "Stable tag"
+ ]
+ );
+
+ $plugin = get_plugin_data(GIVE_DIVI_ADDON_FILE);
+
+ $this->assertEquals(GIVE_DIVI_ADDON_VERSION, $readme['Version']);
+ $this->assertEquals(GIVE_DIVI_ADDON_VERSION, $plugin['Version']);
+ $this->assertEquals($readme['Version'], $plugin['Version']);
+ }
+
+ /**
+ * @since 2.0.0
+ */
+ public function testHasMinimumGiveWPVersion(): void
+ {
+ $this->assertSame('3.0.0', GIVE_DIVI_ADDON_MIN_GIVE_VERSION);
+ }
+
+ /**
+ * @since 2.0.0
+ */
+ public function testIsCompatibleWithGiveWP(): void
+ {
+ $this->assertFalse(version_compare(GIVE_VERSION, GIVE_DIVI_ADDON_MIN_GIVE_VERSION, '<'));
+ }
+
+ /**
+ * @since 2.0.0
+ */
+ public function testCheckRequirementsShouldReturnTrue(): void
+ {
+ $this->assertTrue(Environment::giveMinRequiredVersionCheck());
+ }
+
+ /**
+ * @since 2.0.0
+ */
+ public function testReadMeRequiresPHPVersionMatchesPluginVersion(): void
+ {
+ $readme = get_file_data(
+ trailingslashit(GIVE_DIVI_ADDON_DIR) . "readme.txt",
+ [
+ "RequiresPHP" => "Requires PHP"
+ ]
+ );
+
+ $plugin = get_plugin_data(GIVE_DIVI_ADDON_FILE);
+
+ $this->assertEquals($plugin['RequiresPHP'], $readme['RequiresPHP']);
+ }
+
+ /**
+ * @since 2.0.0
+ */
+ public function testReadMeRequiresWPVersionMatchesPluginHeaderVersion(): void
+ {
+ $readme = get_file_data(
+ trailingslashit(GIVE_DIVI_ADDON_DIR) . "readme.txt",
+ [
+ "RequiresWP" => "Requires at least"
+ ]
+ );
+
+ $plugin = get_plugin_data(GIVE_DIVI_ADDON_FILE);
+
+ $this->assertEquals($plugin['RequiresWP'], $readme['RequiresWP']);
+ }
+}
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
new file mode 100644
index 0000000..d1f67c2
--- /dev/null
+++ b/tests/bootstrap.php
@@ -0,0 +1,7 @@
+load();
diff --git a/tests/unit/README.md b/tests/unit/README.md
deleted file mode 100644
index 72c74ae..0000000
--- a/tests/unit/README.md
+++ /dev/null
@@ -1,67 +0,0 @@
-# Give Unit Tests [![Build Status](https://api.travis-ci.org/impress-org/give.png?branch=master)](https://api.travis-ci.org/impress-org/give)
-
-This folder contains instructions and test code for Give PHPUnit testing.
-
-## Initial Setup
-
-1) Install [PHPUnit](http://phpunit.de/) by following their [installation guide](https://phpunit.de/getting-started.html). If you've installed it correctly, this should display the version:
-
- `$ phpunit --version`
-
- Note: WordPress requires specific version constraints for PHPUnit ( 5.4 >= PHPUNIT <= 7.x ). If you have a different version of PHPUnit installed globally then you can run a per-project version of PHPUnit with `/vendor/bin/phpunit`.
-
-2) Install WordPress and the WP Unit Test library using the `install.sh` script located in `give/tests/bin/` directory. Change to the plugin root directory and type:
-
- `$ tests/wordpress/bin/install.sh [db-host]`
-
-Sample usage: `$ tests/bin/install.sh give_tests root root`
-
-Note: Running the installer a second time will not update the WordPress configuration. Instead, when making changes to the database and/or database user these values will need to be updated directly in `tmp/wordpress-tests-lib/wp-tests-config.php` (or the relative file on your operating system).
-
-**Important**: The `` database will be created if it doesn't exist and all data will be removed during testing.
-
-For more information on how to write PHPUnit Tests, see [PHPUnit's Website](http://www.phpunit.de/manual/3.6/en/writing-tests-for-phpunit.html).
-
-Are you using Pressmatic? Check out this [helpful article](https://tommcfarlin.com/unit-testing-with-pressmatic/) by Tom McFarlin on setting up PHPUnit on Pressmatic.
-
-## Loading dependent plugins
-
-The core Give plugin and the Divi Builder plugin need to be symlinked to the test WordPress install, here is an example command for symlinking a local copy to the tmp directory:
-
-`ln -s ~/Code/impress-org/givewp /tmp/wordpress/wp-content/plugins/give`
-`ln -s ~/Code/divi/divi-builder /tmp/wordpress/wp-content/plugins/divi-builder`
-
-Note: Ignore the deprecated notice thrown by Divi Builder.
-
-Note: I tried installing Give from the WordPress.org download link, but ran into an error that I have not been able to resolve. Therefor the plugin needs to be loaded manually. This might actually be a better way, since it provides control over what versioning.
-
-## Running Tests
-
-Change directory to the plugin root directory and run:
-
- $ phpunit
-
-The tests will execute and you'll be presented with a summary. Code coverage documentation is automatically generated as HTML in the `tmp/coverage` directory.
-
-You can run specific tests using `--filter` followed by the class name and method to test:
-
- $ phpunit --filter Tests_Templates::test_get_donation_form
-
-A text code coverage summary can be displayed using the `--coverage-text` option:
-
- $ phpunit --coverage-text
-
-
-## Writing Tests
-
-* Each test method should cover a single method or function with one or more assertions
-* A single method or function can have multiple associated test methods if it's a large or complex method
-* Use the test coverage HTML report (under `tmp/coverage/index.html`) to examine which lines your tests are covering and aim for 100%® coverage
-* Prefer `assertsEquals()` where possible as it tests both type & equality
-* Only methods prefixed with `test` will be run so use helper methods liberally to keep test methods small and reduce code duplication.
-* Use data providers where possible. Read more about data providers [here](https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers).
-* Filters persist between test cases so be sure to remove them in your test method or in the `tearDown()` method.
-
-## Automated Tests
-
-Tests are automatically run via [Github Actions](https://github.com/impress-org/givewp/actions) for each commit and pull request.
diff --git a/tests/unit/bin/install.sh b/tests/unit/bin/install.sh
deleted file mode 100755
index ecbf857..0000000
--- a/tests/unit/bin/install.sh
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/usr/bin/env bash
-
-if [ $# -lt 3 ]; then
- echo "usage: $0 [db-host] [wp-version]"
- exit 1
-fi
-
-DB_NAME=$1
-DB_USER=$2
-DB_PASS=$3
-DB_HOST=${4-localhost}
-WP_VERSION=${5-latest}
-
-WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib}
-WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/}
-
-download() {
- if [ `which curl` ]; then
- curl -s "$1" > "$2";
- elif [ `which wget` ]; then
- wget -nv -O "$2" "$1"
- fi
-}
-
-if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
- WP_TESTS_TAG="tags/$WP_VERSION"
-else
- # http serves a single offer, whereas https serves multiple. we only want one
- download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
- grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
- LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
- if [[ -z "$LATEST_VERSION" ]]; then
- echo "Latest WordPress version could not be found"
- exit 1
- fi
- WP_TESTS_TAG="tags/$LATEST_VERSION"
-fi
-
-set -ex
-
-install_wp() {
-
- if [ -d $WP_CORE_DIR ]; then
- return;
- fi
-
- mkdir -p $WP_CORE_DIR
-
- if [ $WP_VERSION == 'latest' ]; then
- local ARCHIVE_NAME='latest'
- else
- local ARCHIVE_NAME="wordpress-$WP_VERSION"
- fi
-
- download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
- tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
-
- download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
-}
-
-install_test_suite() {
- # portable in-place argument for both GNU sed and Mac OSX sed
- if [[ $(uname -s) == 'Darwin' ]]; then
- local ioption='-i .bak'
- else
- local ioption='-i'
- fi
-
- # set up testing suite if it doesn't yet exist
- if [ ! -d $WP_TESTS_DIR ]; then
- # set up testing suite
- mkdir -p $WP_TESTS_DIR
- svn co https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
- fi
-
- cd $WP_TESTS_DIR
-
- if [ ! -f wp-tests-config.php ]; then
- download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
- sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR':" "$WP_TESTS_DIR"/wp-tests-config.php
- sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
- sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
- sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
- sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
- fi
-
-}
-
-install_db() {
- # parse DB_HOST for port or socket references
- local PARTS=(${DB_HOST//\:/ })
- local DB_HOSTNAME=${PARTS[0]};
- local DB_SOCK_OR_PORT=${PARTS[1]};
- local EXTRA=""
-
- if ! [ -z $DB_HOSTNAME ] ; then
- if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
- EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
- elif ! [ -z $DB_SOCK_OR_PORT ] ; then
- EXTRA=" --socket=$DB_SOCK_OR_PORT"
- elif ! [ -z $DB_HOSTNAME ] ; then
- EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
- fi
- fi
-
- # create database
- mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
-}
-
-install_wp
-install_test_suite
-install_db
\ No newline at end of file
diff --git a/tests/unit/bootstrap.php b/tests/unit/bootstrap.php
deleted file mode 100644
index d703cb9..0000000
--- a/tests/unit/bootstrap.php
+++ /dev/null
@@ -1,137 +0,0 @@
-tests_dir = dirname( __FILE__ );
- $this->plugin_dir = dirname( dirname( $this->tests_dir ) );
- $this->wp_tests_dir = getenv( 'WP_TESTS_DIR' ) ? getenv( 'WP_TESTS_DIR' ) : '/tmp/wordpress-tests-lib';
- $manual_bootstrap = isset( $GLOBALS['manual_bootstrap'] ) ? (bool) $GLOBALS['manual_bootstrap'] : true;
-
- // Load test function so tests_add_filter() is available
- require_once $this->wp_tests_dir . '/includes/functions.php';
-
- // Load Give
- tests_add_filter( 'muplugins_loaded', array( $this, 'load_give' ) );
-
- // Install Give
- tests_add_filter( 'setup_theme', array( $this, 'setup' ) );
-
- // Load the WP testing environment
- if ( $manual_bootstrap ) {
- require_once $this->wp_tests_dir . '/includes/bootstrap.php';
-
- // Load Give testing framework
- // Note: you must copy code of this function to your include function of bootstrap class
- // Or use Give_Unit_Tests_Bootstrap::includes();
- $this->includes();
- }
- }
-
-
- /**
- * Load Give
- *
- * @since 1.3.2
- */
- public function load_give() {
- require_once $this->plugin_dir . '/give-divi.php';
-
- // Update array with plugins to include ...
- $plugins_to_active = array(
- 'give/give.php',
- 'divi-builder/divi-builder.php',
- 'give-divi/give-divi.php',
- );
-
- update_option( 'active_plugins', $plugins_to_active );
- }
-
- /**
- * Install Give after the test environment and Give have been loaded.
- *
- * @since 1.3.2
- *
- * @global WP_Roles $wp_roles
- */
- public function setup() {
-
- // reload capabilities after install, see https://core.trac.wordpress.org/ticket/28374
- $current_user = new WP_User( 1 );
- $current_user->set_role( 'administrator' );
- wp_update_user(
- array(
- 'ID' => 1,
- 'first_name' => 'Admin',
- 'last_name' => 'User',
- )
- );
- add_filter( 'give_log_email_errors', '__return_false' );
-
- }
-
- /**
- * Load Give-specific test cases
- *
- * @since 1.3.2
- */
- public function includes() {
-
- // test cases
- require_once $this->tests_dir . '/framework/class-give-unit-test-case.php';
-
- // Helpers
- require_once $this->tests_dir . '/framework/helpers/shims.php';
- }
-
- /**
- * Get the single class instance.
- *
- * @since 1.3.2
- * @return Give_Unit_Tests_Bootstrap
- */
- public static function instance() {
- if ( is_null( self::$instance ) ) {
- self::$instance = new self();
- }
-
- return self::$instance;
- }
-}
-
-Give_Unit_Tests_Bootstrap::instance();
diff --git a/tests/unit/framework/class-give-unit-test-case.php b/tests/unit/framework/class-give-unit-test-case.php
deleted file mode 100644
index de757a7..0000000
--- a/tests/unit/framework/class-give-unit-test-case.php
+++ /dev/null
@@ -1,103 +0,0 @@
-assertNotInstanceOf( 'WP_Error', $actual, $message );
- }
-
- /**
- * Asserts thing is WP_Error.
- *
- * @param mixed $actual
- * @param string $message
- */
- public function assertIsWPError( $actual, $message = '' ) {
- $this->assertInstanceOf( 'WP_Error', $actual, $message );
- }
-
- /**
- * Backport assertNotFalse to PHPUnit 3.6.12 which only runs in PHP 5.2.
- *
- * @since 1.0
- * @param $condition
- * @param string $message
- * @return mixed
- */
- public static function assertNotFalse( $condition, $message = '' ) {
-
- if ( version_compare( phpversion(), '5.3', '<' ) ) {
-
- self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message );
-
- } else {
-
- parent::assertNotFalse( $condition, $message );
- }
- }
-}
diff --git a/tests/unit/framework/helpers/shims.php b/tests/unit/framework/helpers/shims.php
deleted file mode 100644
index e88c9a4..0000000
--- a/tests/unit/framework/helpers/shims.php
+++ /dev/null
@@ -1,25 +0,0 @@
-publicly_queryable || ( $post_type_object->_builtin && $post_type_object->public );
- }
-}
diff --git a/tests/unit/tests/ExampleTest.php b/tests/unit/tests/ExampleTest.php
deleted file mode 100644
index 6e1049a..0000000
--- a/tests/unit/tests/ExampleTest.php
+++ /dev/null
@@ -1,19 +0,0 @@
-assertEquals( true, true );
- }
-
- public function testDiviVersion() {
- $this->assertEquals( ET_BUILDER_PLUGIN_VERSION, '4.5.3' );
- }
-
- public function testGiveVersion() {
- $this->assertEquals( GIVE_VERSION, '2.9.5' );
- }
-
-}