From 511960a166aa7dd473e61e84dd4316d9ea57a90a Mon Sep 17 00:00:00 2001 From: david Date: Fri, 24 Sep 2021 13:25:23 +0200 Subject: [PATCH] 235: refactored plugin tests --- .phpcs-local.xml | 45 +++ .phpcs.xml | 51 +++ .travis.yml | 2 +- bin/install-wp-tests.sh | 181 ++++++++++ composer.json | 9 +- phpunit.xml | 34 +- .../controller/addons/addthis/Addthis.php | 4 +- .../CAOS_Host_Analyticsjs_Local.php | 4 +- .../Custom_Facebook_Feed.php | 4 +- ...hanced_Ecommerce_For_WooCommerce_Store.php | 4 +- .../Facebook_For_Woocommerce.php | 4 +- .../Ga_Google_Analytics.php | 4 +- src/addons/controller/addons/gadwp/Gadwp.php | 4 +- .../google_analytics/Google_Analytics.php | 4 +- .../google_site_kit/Google_Site_Kit.php | 4 +- .../addons/hubspot_leadin/Hubspot_Leadin.php | 4 +- .../Hubspot_Tracking_Code.php | 4 +- .../addons/instagram_feed/Instagram_Feed.php | 4 +- .../controller/addons/jetpack/Jetpack.php | 4 +- .../litespeed_cache/Litespeed_Cache.php | 4 +- .../addons/ninja_forms/Ninja_Forms.php | 4 +- .../Official_Facebook_Pixel.php | 4 +- .../addons/optinmonster/Optinmonster.php | 4 +- .../addons/pixel_caffeine/Pixel_Caffeine.php | 4 +- .../Simple_Share_Buttons_Adder.php | 4 +- .../Wd_Google_Analytics.php | 4 +- .../controller/addons/wp_piwik/Wp_Piwik.php | 4 +- src/addons/tests/bootstrap.php | 37 -- .../tests/integration/addons/addons-base.php | 37 -- .../integration/addons/test-add-to-any.php | 21 -- .../tests/integration/addons/test-addthis.php | 23 -- ...s-host-analyticsjs-local-save-ga-local.php | 30 -- .../test-caos-host-analyticsjs-local.php | 31 -- .../addons/test-custom-facebook-feed-old.php | 24 -- .../addons/test-custom-facebook-feed.php | 23 -- ...hanced-ecommerce-for-woocommerce-store.php | 19 -- .../addons/test-facebook-for-woocommerce.php | 30 -- .../addons/test-ga-google-analytics.php | 21 -- .../tests/integration/addons/test-gadwp.php | 29 -- .../addons/test-google-analyticator.php | 24 -- .../addons/test-google-analytics-plus.php | 26 -- .../addons/test-google-analytics.php | 22 -- .../addons/test-google-site-kit.php | 21 -- .../addons/test-hubspot-leadin.php | 21 -- .../addons/test-hubspot-tracking-code.php | 21 -- .../addons/test-instagram-feed.php | 21 -- .../addons/test-jetpack-facebook-widget.php | 27 -- .../addons/test-jetpack-goodreads-widget.php | 27 -- .../test-jetpack-google-maps-widget.php | 23 -- .../test-jetpack-googleplus-badge-widget.php | 21 -- ...jetpack-internet-defense-league-widget.php | 21 -- .../test-jetpack-twitter-timeline-widget.php | 21 -- .../addons/test-lightspeed-cache.php | 21 -- .../integration/addons/test-ninja-forms.php | 21 -- .../addons/test-official-facebook-pixel.php | 195 ----------- .../integration/addons/test-optinmonster.php | 21 -- .../addons/test-pixel-caffeine.php | 23 -- .../test-simple-share-buttons-adder.php | 19 -- .../addons/test-wd-google-analytics.php | 21 -- .../integration/addons/test-wp-analytify.php | 21 -- .../test-wp-google-analytics-events.php | 37 -- .../integration/addons/test-wp-mautic.php | 22 -- .../integration/addons/test-wp-piwik.php | 21 -- .../integration/test-buffer-priorities.php | 53 --- .../tests/unit/test-addon-file-name.php | 74 ---- src/addons/tests/unit/test-cookie-consent.php | 70 ---- .../tests/unit/test-get-option-name.php | 97 ------ .../tests/unit/test-latest-plugin-version.php | 54 --- .../unit/test-previous-version-active.php | 74 ---- tests/bootstrap.php | 34 +- tests/docker-compose.yml | 19 ++ tests/helpers.php | 15 + tests/integration/addons/Test_Add_To_Any.php | 24 ++ tests/integration/addons/Test_Addthis.php | 28 ++ ...OS_Host_Analyticsjs_Local_Version_1_97.php | 34 ++ .../Test_Caos_Host_Analyticsjs_Local.php | 35 ++ .../addons/Test_Custom_Facebook_Feed.php | 28 ++ ...st_Custom_Facebook_Feed_Version_2_17_1.php | 29 ++ ...hanced_Ecommerce_For_Woocommerce_Store.php | 23 ++ .../addons/Test_Facebook_For_Woocommerce.php | 37 ++ .../addons/Test_Ga_Google_Analytics.php | 28 ++ tests/integration/addons/Test_Gadwp.php | 31 ++ .../addons/Test_Google_Analyticator.php | 29 ++ .../addons/Test_Google_Analytics.php | 27 ++ .../addons/Test_Google_Site_Kit.php | 26 ++ .../addons/Test_Hubspot_Leadin.php | 26 ++ .../addons/Test_Hubspot_Tracking_Code.php | 26 ++ .../addons/Test_Instagram_Feed.php | 26 ++ .../addons/Test_Jetpack_Widgets.php | 84 +++++ .../addons/Test_Lightspeed_Cache.php | 26 ++ tests/integration/addons/Test_Ninja_Forms.php | 26 ++ .../addons/Test_Official_Facebook_Pixel.php | 315 ++++++++++++++++++ .../integration/addons/Test_Optinmonster.php | 26 ++ .../addons/Test_Pixel_Caffeine.php | 28 ++ .../Test_Simple_Share_Buttons_Adder.php | 23 ++ .../addons/Test_Wd_Google_Analytics.php | 26 ++ .../integration/addons/Test_Wp_Analytify.php | 26 ++ .../Test_Wp_Google_Analytics_Events.php | 43 +++ tests/integration/addons/Test_Wp_Mautic.php | 27 ++ tests/integration/addons/Test_Wp_Piwik.php | 26 ++ tests/test-sample.php | 20 -- tests/unit/Test_Addon_File_Name.php | 67 ++++ tests/unit/Test_Cookie_Consent.php | 68 ++++ .../unit/Test_Manipulate_Script.php | 55 ++- vendor/composer/autoload_psr4.php | 1 + vendor/composer/autoload_static.php | 5 + 106 files changed, 1697 insertions(+), 1591 deletions(-) create mode 100644 .phpcs-local.xml create mode 100644 .phpcs.xml create mode 100755 bin/install-wp-tests.sh delete mode 100755 src/addons/tests/bootstrap.php delete mode 100644 src/addons/tests/integration/addons/addons-base.php delete mode 100644 src/addons/tests/integration/addons/test-add-to-any.php delete mode 100644 src/addons/tests/integration/addons/test-addthis.php delete mode 100644 src/addons/tests/integration/addons/test-caos-host-analyticsjs-local-save-ga-local.php delete mode 100644 src/addons/tests/integration/addons/test-caos-host-analyticsjs-local.php delete mode 100644 src/addons/tests/integration/addons/test-custom-facebook-feed-old.php delete mode 100644 src/addons/tests/integration/addons/test-custom-facebook-feed.php delete mode 100644 src/addons/tests/integration/addons/test-enhanced-ecommerce-for-woocommerce-store.php delete mode 100644 src/addons/tests/integration/addons/test-facebook-for-woocommerce.php delete mode 100644 src/addons/tests/integration/addons/test-ga-google-analytics.php delete mode 100644 src/addons/tests/integration/addons/test-gadwp.php delete mode 100644 src/addons/tests/integration/addons/test-google-analyticator.php delete mode 100644 src/addons/tests/integration/addons/test-google-analytics-plus.php delete mode 100644 src/addons/tests/integration/addons/test-google-analytics.php delete mode 100644 src/addons/tests/integration/addons/test-google-site-kit.php delete mode 100644 src/addons/tests/integration/addons/test-hubspot-leadin.php delete mode 100644 src/addons/tests/integration/addons/test-hubspot-tracking-code.php delete mode 100644 src/addons/tests/integration/addons/test-instagram-feed.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-facebook-widget.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-goodreads-widget.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-google-maps-widget.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-googleplus-badge-widget.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-internet-defense-league-widget.php delete mode 100644 src/addons/tests/integration/addons/test-jetpack-twitter-timeline-widget.php delete mode 100644 src/addons/tests/integration/addons/test-lightspeed-cache.php delete mode 100644 src/addons/tests/integration/addons/test-ninja-forms.php delete mode 100644 src/addons/tests/integration/addons/test-official-facebook-pixel.php delete mode 100644 src/addons/tests/integration/addons/test-optinmonster.php delete mode 100644 src/addons/tests/integration/addons/test-pixel-caffeine.php delete mode 100644 src/addons/tests/integration/addons/test-simple-share-buttons-adder.php delete mode 100644 src/addons/tests/integration/addons/test-wd-google-analytics.php delete mode 100644 src/addons/tests/integration/addons/test-wp-analytify.php delete mode 100644 src/addons/tests/integration/addons/test-wp-google-analytics-events.php delete mode 100644 src/addons/tests/integration/addons/test-wp-mautic.php delete mode 100644 src/addons/tests/integration/addons/test-wp-piwik.php delete mode 100644 src/addons/tests/integration/test-buffer-priorities.php delete mode 100644 src/addons/tests/unit/test-addon-file-name.php delete mode 100644 src/addons/tests/unit/test-cookie-consent.php delete mode 100644 src/addons/tests/unit/test-get-option-name.php delete mode 100644 src/addons/tests/unit/test-latest-plugin-version.php delete mode 100644 src/addons/tests/unit/test-previous-version-active.php create mode 100644 tests/docker-compose.yml create mode 100644 tests/helpers.php create mode 100644 tests/integration/addons/Test_Add_To_Any.php create mode 100644 tests/integration/addons/Test_Addthis.php create mode 100644 tests/integration/addons/Test_CAOS_Host_Analyticsjs_Local_Version_1_97.php create mode 100644 tests/integration/addons/Test_Caos_Host_Analyticsjs_Local.php create mode 100644 tests/integration/addons/Test_Custom_Facebook_Feed.php create mode 100644 tests/integration/addons/Test_Custom_Facebook_Feed_Version_2_17_1.php create mode 100644 tests/integration/addons/Test_Enhanced_Ecommerce_For_Woocommerce_Store.php create mode 100644 tests/integration/addons/Test_Facebook_For_Woocommerce.php create mode 100644 tests/integration/addons/Test_Ga_Google_Analytics.php create mode 100644 tests/integration/addons/Test_Gadwp.php create mode 100644 tests/integration/addons/Test_Google_Analyticator.php create mode 100644 tests/integration/addons/Test_Google_Analytics.php create mode 100644 tests/integration/addons/Test_Google_Site_Kit.php create mode 100644 tests/integration/addons/Test_Hubspot_Leadin.php create mode 100644 tests/integration/addons/Test_Hubspot_Tracking_Code.php create mode 100644 tests/integration/addons/Test_Instagram_Feed.php create mode 100644 tests/integration/addons/Test_Jetpack_Widgets.php create mode 100644 tests/integration/addons/Test_Lightspeed_Cache.php create mode 100644 tests/integration/addons/Test_Ninja_Forms.php create mode 100644 tests/integration/addons/Test_Official_Facebook_Pixel.php create mode 100644 tests/integration/addons/Test_Optinmonster.php create mode 100644 tests/integration/addons/Test_Pixel_Caffeine.php create mode 100644 tests/integration/addons/Test_Simple_Share_Buttons_Adder.php create mode 100644 tests/integration/addons/Test_Wd_Google_Analytics.php create mode 100644 tests/integration/addons/Test_Wp_Analytify.php create mode 100644 tests/integration/addons/Test_Wp_Google_Analytics_Events.php create mode 100644 tests/integration/addons/Test_Wp_Mautic.php create mode 100644 tests/integration/addons/Test_Wp_Piwik.php delete mode 100644 tests/test-sample.php create mode 100644 tests/unit/Test_Addon_File_Name.php create mode 100644 tests/unit/Test_Cookie_Consent.php rename src/addons/tests/unit/test-manipulate-script.php => tests/unit/Test_Manipulate_Script.php (97%) diff --git a/.phpcs-local.xml b/.phpcs-local.xml new file mode 100644 index 00000000..5dd077d1 --- /dev/null +++ b/.phpcs-local.xml @@ -0,0 +1,45 @@ + + + Generally-applicable sniffs for WordPress plugins. + + + . + /vendor/ + /node_modules/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.phpcs.xml b/.phpcs.xml new file mode 100644 index 00000000..8d625753 --- /dev/null +++ b/.phpcs.xml @@ -0,0 +1,51 @@ + + + Generally-applicable sniffs for WordPress plugins. + + + . + /vendor/ + /node_modules/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.travis.yml b/.travis.yml index 39551192..7a935a6c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_script: - if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then phpenv config-rm xdebug.ini else - echo "xdebug.ini does not exist" + echo \"xdebug.ini does not exist\" fi - | bash bin/install-wp-tests.sh wordpress_test root '' localhost latest diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh new file mode 100755 index 00000000..ee05775c --- /dev/null +++ b/bin/install-wp-tests.sh @@ -0,0 +1,181 @@ +#!/usr/bin/env bash + +if [ $# -lt 3 ]; then + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 +fi + +DB_NAME=$1 +DB_USER=$2 +DB_PASS=$3 +DB_HOST=${4-localhost} +WP_VERSION=${5-latest} +SKIP_DB_CREATE=${6-false} + +TMPDIR=${TMPDIR-/tmp} +TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//") +WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} +WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/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]+\-(beta|RC)[0-9]+$ ]]; then + WP_BRANCH=${WP_VERSION%\-*} + WP_TESTS_TAG="branches/$WP_BRANCH" + +elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then + WP_TESTS_TAG="branches/$WP_VERSION" +elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + WP_TESTS_TAG="tags/${WP_VERSION%??}" + else + WP_TESTS_TAG="tags/$WP_VERSION" + fi +elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + WP_TESTS_TAG="trunk" +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 == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p $TMPDIR/wordpress-trunk + rm -rf $TMPDIR/wordpress-trunk/* + svn export --quiet https://core.svn.wordpress.org/trunk $TMPDIR/wordpress-trunk/wordpress + mv $TMPDIR/wordpress-trunk/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + # https serves multiple offers, whereas http serves single. + download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + LATEST_VERSION=${WP_VERSION%??} + else + # otherwise, scan the releases and get the most up to date minor version of the major release + local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` + LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) + fi + if [[ -z "$LATEST_VERSION" ]]; then + local ARCHIVE_NAME="wordpress-$WP_VERSION" + else + local ARCHIVE_NAME="wordpress-$LATEST_VERSION" + fi + else + local ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR + fi + + 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 + rm -rf $WP_TESTS_DIR/{includes,data} + svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn export --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + fi + + 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 + # remove all forward slashes in the end + WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s:__DIR__ . '/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 + +} + +recreate_db() { + shopt -s nocasematch + if [[ $1 =~ ^(y|yes)$ ]] + then + mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA + create_db + echo "Recreated the database ($DB_NAME)." + else + echo "Leaving the existing database ($DB_NAME) in place." + fi + shopt -u nocasematch +} + +create_db() { + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA +} + +install_db() { + + if [ ${SKIP_DB_CREATE} = "true" ]; then + return 0 + fi + + # 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 + if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ] + then + echo "Reinstalling will delete the existing test database ($DB_NAME)" + read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB + recreate_db $DELETE_EXISTING_DB + else + create_db + fi +} + +install_wp +install_test_suite +install_db diff --git a/composer.json b/composer.json index 94b32f80..c8187464 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,14 @@ "name": "cybot/cookiebot", "autoload": { "psr-4": { - "cybot\\cookiebot\\" : "src/" + "cybot\\cookiebot\\": "src/", + "cybot\\cookiebot\\tests\\": "tests/" } + }, + "scripts": { + "docker.phpunit": "cd tests && docker-compose run cookiebot phpunit", + "docker.phpcs": "cd tests && docker-compose run cookiebot phpcs", + "phpcs": "phpcs --standard=./.phpcs-local.xml ./", + "phpcbf": "phpcbf --standard=./.phpcs-local.xml ./" } } \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 498544df..afa71737 100755 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,29 +1,15 @@ + + bootstrap="tests/bootstrap.php" + backupGlobals="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" +> - - ./addons/tests/ + + ./tests/ - - - ./model - example-model - - - - - - - - - - - diff --git a/src/addons/controller/addons/addthis/Addthis.php b/src/addons/controller/addons/addthis/Addthis.php index b6a3458c..e887b8b7 100644 --- a/src/addons/controller/addons/addthis/Addthis.php +++ b/src/addons/controller/addons/addthis/Addthis.php @@ -49,7 +49,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'https://plugins.svn.wordpress.org/addthis/trunk/addthis_social_widget.php'; + public static function get_svn_url( $path = 'addthis_social_widget.php' ) { + return 'https://plugins.svn.wordpress.org/addthis/trunk/' . $path; } } diff --git a/src/addons/controller/addons/caos_host_analyticsjs_local/CAOS_Host_Analyticsjs_Local.php b/src/addons/controller/addons/caos_host_analyticsjs_local/CAOS_Host_Analyticsjs_Local.php index 50b28ec3..ddc5149f 100644 --- a/src/addons/controller/addons/caos_host_analyticsjs_local/CAOS_Host_Analyticsjs_Local.php +++ b/src/addons/controller/addons/caos_host_analyticsjs_local/CAOS_Host_Analyticsjs_Local.php @@ -93,8 +93,8 @@ public function cookiebot_addon_host_analyticsjs_local_priority() { * @since 1.8.0 * @version 2.1.3 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/host-analyticsjs-local/trunk/host-analyticsjs-local.php'; + public static function get_svn_url( $path = 'host-analyticsjs-local.php' ) { + return 'http://plugins.svn.wordpress.org/host-analyticsjs-local/trunk/' . $path; } /** diff --git a/src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php b/src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php index 7445176a..1bd79c2e 100755 --- a/src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php +++ b/src/addons/controller/addons/custom_facebook_feed/Custom_Facebook_Feed.php @@ -21,8 +21,8 @@ class Custom_Facebook_Feed extends Base_Cookiebot_Plugin_Addon implements Open_S * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/custom-facebook-feed/trunk/custom-facebook-feed.php'; + public static function get_svn_url( $path = 'custom-facebook-feed.php' ) { + return 'http://plugins.svn.wordpress.org/custom-facebook-feed/trunk/' . $path; } public function load_addon_configuration() { diff --git a/src/addons/controller/addons/enhanced_ecommerce_for_woocommerce_store/Enhanced_Ecommerce_For_WooCommerce_Store.php b/src/addons/controller/addons/enhanced_ecommerce_for_woocommerce_store/Enhanced_Ecommerce_For_WooCommerce_Store.php index 749e932d..4298b821 100644 --- a/src/addons/controller/addons/enhanced_ecommerce_for_woocommerce_store/Enhanced_Ecommerce_For_WooCommerce_Store.php +++ b/src/addons/controller/addons/enhanced_ecommerce_for_woocommerce_store/Enhanced_Ecommerce_For_WooCommerce_Store.php @@ -56,7 +56,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'https://plugins.svn.wordpress.org/enhanced-e-commerce-for-woocommerce-store/trunk/enhanced-ecommerce-google-analytics.php'; + public static function get_svn_url( $path = 'enhanced-ecommerce-google-analytics.php' ) { + return 'https://plugins.svn.wordpress.org/enhanced-e-commerce-for-woocommerce-store/trunk/' . $path; } } diff --git a/src/addons/controller/addons/facebook_for_woocommerce/Facebook_For_Woocommerce.php b/src/addons/controller/addons/facebook_for_woocommerce/Facebook_For_Woocommerce.php index cbbc10e8..47d5f0ba 100644 --- a/src/addons/controller/addons/facebook_for_woocommerce/Facebook_For_Woocommerce.php +++ b/src/addons/controller/addons/facebook_for_woocommerce/Facebook_For_Woocommerce.php @@ -123,8 +123,8 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'https://raw.githubusercontent.com/facebookincubator/facebook-for-woocommerce/master/facebook-commerce.php'; + public static function get_svn_url( $path = 'facebook-commerce.php' ) { + return 'https://raw.githubusercontent.com/facebookincubator/facebook-for-woocommerce/master/' . $path; } /** diff --git a/src/addons/controller/addons/ga_google_analytics/Ga_Google_Analytics.php b/src/addons/controller/addons/ga_google_analytics/Ga_Google_Analytics.php index 0b3fc18d..c72675a7 100644 --- a/src/addons/controller/addons/ga_google_analytics/Ga_Google_Analytics.php +++ b/src/addons/controller/addons/ga_google_analytics/Ga_Google_Analytics.php @@ -57,7 +57,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/ga-google-analytics/trunk/ga-google-analytics.php'; + public static function get_svn_url( $path = 'ga-google-analytics.php' ) { + return 'http://plugins.svn.wordpress.org/ga-google-analytics/trunk/' . $path; } } diff --git a/src/addons/controller/addons/gadwp/Gadwp.php b/src/addons/controller/addons/gadwp/Gadwp.php index 6f78387f..9ead4ddc 100644 --- a/src/addons/controller/addons/gadwp/Gadwp.php +++ b/src/addons/controller/addons/gadwp/Gadwp.php @@ -81,7 +81,7 @@ function( $atts ) { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/google-analytics-dashboard-for-wp/trunk/gadwp.php'; + public static function get_svn_url( $path = 'gadwp.php' ) { + return 'http://plugins.svn.wordpress.org/google-analytics-dashboard-for-wp/trunk/' . $path; } } diff --git a/src/addons/controller/addons/google_analytics/Google_Analytics.php b/src/addons/controller/addons/google_analytics/Google_Analytics.php index c9840213..02891839 100644 --- a/src/addons/controller/addons/google_analytics/Google_Analytics.php +++ b/src/addons/controller/addons/google_analytics/Google_Analytics.php @@ -53,7 +53,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/googleanalytics/trunk/googleanalytics.php'; + public static function get_svn_url( $path = 'googleanalytics.php' ) { + return 'http://plugins.svn.wordpress.org/googleanalytics/trunk/' . $path; } } diff --git a/src/addons/controller/addons/google_site_kit/Google_Site_Kit.php b/src/addons/controller/addons/google_site_kit/Google_Site_Kit.php index c9ed06ab..36d23629 100644 --- a/src/addons/controller/addons/google_site_kit/Google_Site_Kit.php +++ b/src/addons/controller/addons/google_site_kit/Google_Site_Kit.php @@ -45,7 +45,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/google-site-kit/trunk/google-site-kit.php'; + public static function get_svn_url( $path = 'google-site-kit.php' ) { + return 'http://plugins.svn.wordpress.org/google-site-kit/trunk/' . $path; } } diff --git a/src/addons/controller/addons/hubspot_leadin/Hubspot_Leadin.php b/src/addons/controller/addons/hubspot_leadin/Hubspot_Leadin.php index d865e65e..32ffb4c2 100644 --- a/src/addons/controller/addons/hubspot_leadin/Hubspot_Leadin.php +++ b/src/addons/controller/addons/hubspot_leadin/Hubspot_Leadin.php @@ -37,7 +37,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/leadin/trunk/leadin.php'; + public static function get_svn_url( $path = 'leadin.php' ) { + return 'http://plugins.svn.wordpress.org/leadin/trunk/' . $path; } } diff --git a/src/addons/controller/addons/hubspot_tracking_code/Hubspot_Tracking_Code.php b/src/addons/controller/addons/hubspot_tracking_code/Hubspot_Tracking_Code.php index 2de0b98f..ddc12788 100644 --- a/src/addons/controller/addons/hubspot_tracking_code/Hubspot_Tracking_Code.php +++ b/src/addons/controller/addons/hubspot_tracking_code/Hubspot_Tracking_Code.php @@ -46,7 +46,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/hubspot-tracking-code/trunk/hubspot-tracking-code.php'; + public static function get_svn_url( $path = 'hubspot-tracking-code.php' ) { + return 'http://plugins.svn.wordpress.org/hubspot-tracking-code/trunk/' . $path; } } diff --git a/src/addons/controller/addons/instagram_feed/Instagram_Feed.php b/src/addons/controller/addons/instagram_feed/Instagram_Feed.php index a05f1a2d..fdbe1c6d 100644 --- a/src/addons/controller/addons/instagram_feed/Instagram_Feed.php +++ b/src/addons/controller/addons/instagram_feed/Instagram_Feed.php @@ -33,7 +33,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/instagram-feed/trunk/instagram-feed.php'; + public static function get_svn_url( $path = 'instagram-feed.php' ) { + return 'http://plugins.svn.wordpress.org/instagram-feed/trunk/' . $path; } } diff --git a/src/addons/controller/addons/jetpack/Jetpack.php b/src/addons/controller/addons/jetpack/Jetpack.php index e2006d43..b27e00a7 100644 --- a/src/addons/controller/addons/jetpack/Jetpack.php +++ b/src/addons/controller/addons/jetpack/Jetpack.php @@ -208,7 +208,7 @@ public function get_widgets() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/jetpack/trunk/jetpack.php'; + public static function get_svn_url( $path = 'jetpack.php' ) { + return 'http://plugins.svn.wordpress.org/jetpack/trunk/' . $path; } } diff --git a/src/addons/controller/addons/litespeed_cache/Litespeed_Cache.php b/src/addons/controller/addons/litespeed_cache/Litespeed_Cache.php index bb3d8147..595f97a5 100644 --- a/src/addons/controller/addons/litespeed_cache/Litespeed_Cache.php +++ b/src/addons/controller/addons/litespeed_cache/Litespeed_Cache.php @@ -66,7 +66,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/litespeed-cache/trunk/litespeed-cache.php'; + public static function get_svn_url( $path = 'litespeed-cache.php' ) { + return 'http://plugins.svn.wordpress.org/litespeed-cache/trunk/' . $path; } } diff --git a/src/addons/controller/addons/ninja_forms/Ninja_Forms.php b/src/addons/controller/addons/ninja_forms/Ninja_Forms.php index 6cee6749..05eb2277 100644 --- a/src/addons/controller/addons/ninja_forms/Ninja_Forms.php +++ b/src/addons/controller/addons/ninja_forms/Ninja_Forms.php @@ -51,7 +51,7 @@ function ( $fields ) { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/ninja-forms/trunk/ninja-forms.php'; + public static function get_svn_url( $path = 'ninja-forms.php' ) { + return 'http://plugins.svn.wordpress.org/ninja-forms/trunk/' . $path; } } diff --git a/src/addons/controller/addons/official_facebook_pixel/Official_Facebook_Pixel.php b/src/addons/controller/addons/official_facebook_pixel/Official_Facebook_Pixel.php index 4867e99a..c773c3b7 100644 --- a/src/addons/controller/addons/official_facebook_pixel/Official_Facebook_Pixel.php +++ b/src/addons/controller/addons/official_facebook_pixel/Official_Facebook_Pixel.php @@ -263,7 +263,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'https://plugins.svn.wordpress.org/official-facebook-pixel/trunk/facebook-for-wordpress.php'; + public static function get_svn_url( $path = 'facebook-for-wordpress.php' ) { + return 'https://plugins.svn.wordpress.org/official-facebook-pixel/trunk/' . $path; } } diff --git a/src/addons/controller/addons/optinmonster/Optinmonster.php b/src/addons/controller/addons/optinmonster/Optinmonster.php index 60840a7a..bfa24918 100644 --- a/src/addons/controller/addons/optinmonster/Optinmonster.php +++ b/src/addons/controller/addons/optinmonster/Optinmonster.php @@ -43,7 +43,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'https://plugins.svn.wordpress.org/optinmonster/trunk/optin-monster-wp-api.php'; + public static function get_svn_url( $path = 'optin-monster-wp-api.php' ) { + return 'https://plugins.svn.wordpress.org/optinmonster/trunk/' . $path; } } diff --git a/src/addons/controller/addons/pixel_caffeine/Pixel_Caffeine.php b/src/addons/controller/addons/pixel_caffeine/Pixel_Caffeine.php index 764ea93a..c477a3ee 100644 --- a/src/addons/controller/addons/pixel_caffeine/Pixel_Caffeine.php +++ b/src/addons/controller/addons/pixel_caffeine/Pixel_Caffeine.php @@ -63,7 +63,7 @@ public function get_default_placeholder() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/pixel-caffeine/trunk/pixel-caffeine.php'; + public static function get_svn_url( $path = 'pixel-caffeine.php' ) { + return 'http://plugins.svn.wordpress.org/pixel-caffeine/trunk/' . $path; } } diff --git a/src/addons/controller/addons/simple_share_buttons_adder/Simple_Share_Buttons_Adder.php b/src/addons/controller/addons/simple_share_buttons_adder/Simple_Share_Buttons_Adder.php index b02e200d..ffc249c2 100644 --- a/src/addons/controller/addons/simple_share_buttons_adder/Simple_Share_Buttons_Adder.php +++ b/src/addons/controller/addons/simple_share_buttons_adder/Simple_Share_Buttons_Adder.php @@ -47,7 +47,7 @@ public function get_extra_information() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/simple-share-buttons-adder/trunk/simple-share-buttons-adder.php'; + public static function get_svn_url( $path = 'simple-share-buttons-adder.php' ) { + return 'http://plugins.svn.wordpress.org/simple-share-buttons-adder/trunk/' . $path; } } diff --git a/src/addons/controller/addons/wd_google_analytics/Wd_Google_Analytics.php b/src/addons/controller/addons/wd_google_analytics/Wd_Google_Analytics.php index 5b70c070..0f2b5022 100644 --- a/src/addons/controller/addons/wd_google_analytics/Wd_Google_Analytics.php +++ b/src/addons/controller/addons/wd_google_analytics/Wd_Google_Analytics.php @@ -41,7 +41,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/wd-google-analytics/trunk/google-analytics-wd.php'; + public static function get_svn_url( $path = 'google-analytics-wd.php' ) { + return 'http://plugins.svn.wordpress.org/wd-google-analytics/trunk/' . $path; } } diff --git a/src/addons/controller/addons/wp_piwik/Wp_Piwik.php b/src/addons/controller/addons/wp_piwik/Wp_Piwik.php index d81cb949..396e362a 100644 --- a/src/addons/controller/addons/wp_piwik/Wp_Piwik.php +++ b/src/addons/controller/addons/wp_piwik/Wp_Piwik.php @@ -55,7 +55,7 @@ public function load_addon_configuration() { * * @since 1.8.0 */ - public static function get_svn_url() { - return 'http://plugins.svn.wordpress.org/wp-piwik/trunk/wp-piwik.php'; + public static function get_svn_url( $path = 'wp-piwik.php' ) { + return 'http://plugins.svn.wordpress.org/wp-piwik/trunk/' . $path; } } diff --git a/src/addons/tests/bootstrap.php b/src/addons/tests/bootstrap.php deleted file mode 100755 index 8f8e6bd4..00000000 --- a/src/addons/tests/bootstrap.php +++ /dev/null @@ -1,37 +0,0 @@ - array( PLUGIN_PATH ), -); - -// Give access to tests_add_filter() function. -require_once $_tests_dir . '/includes/functions.php'; - -/** - * Manually load the plugin being tested. - */ -function _manually_load_plugin() { - // plugin - require dirname( dirname( __FILE__ ) ) . '/cookiebot-addons-init.php'; -} - -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); - -// Start up the WP testing environment. -require $_tests_dir . '/includes/bootstrap.php'; diff --git a/src/addons/tests/integration/addons/addons-base.php b/src/addons/tests/integration/addons/addons-base.php deleted file mode 100644 index 93e9276c..00000000 --- a/src/addons/tests/integration/addons/addons-base.php +++ /dev/null @@ -1,37 +0,0 @@ - $url, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_HTTPHEADER => array( - 'Host: plugins.svn.wordpress.org', - 'User-Agent: PostmanRuntime/7.26.1', - ), - ) - ); - - $response = curl_exec( $curl ); - - curl_close( $curl ); - - return $response; - } -} diff --git a/src/addons/tests/integration/addons/test-add-to-any.php b/src/addons/tests/integration/addons/test-add-to-any.php deleted file mode 100644 index f617e444..00000000 --- a/src/addons/tests/integration/addons/test-add-to-any.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( $url ); - - // test the content - $this->assertNotFalse( strpos( $content, "wp_enqueue_script( 'addtoany'" ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-addthis.php b/src/addons/tests/integration/addons/test-addthis.php deleted file mode 100644 index ad6cdeb9..00000000 --- a/src/addons/tests/integration/addons/test-addthis.php +++ /dev/null @@ -1,23 +0,0 @@ -curl_get_content( 'https://plugins.svn.wordpress.org/addthis/trunk/backend/AddThisPlugin.php' ); - - $this->assertNotFalse( strpos( $content, "'addthis_widget'," ) ); - $this->assertNotFalse( strpos( $content, 'window.addthis_product ' ) ); - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_enqueue_scripts\', array($this, \'enqueueScripts\'));' ) ); - - } -} diff --git a/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local-save-ga-local.php b/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local-save-ga-local.php deleted file mode 100644 index 5e7a2225..00000000 --- a/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local-save-ga-local.php +++ /dev/null @@ -1,30 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/host-analyticsjs-local/tags/1.97/save-ga-local.php' ); - - $this->assertNotFalse( - strpos( - $content, - 'add_action(\'wp_footer\', \'caos_analytics_render_tracking_code\', $sgal_enqueue_order);' - ) - ); - $this->assertNotFalse( - strpos( - $content, - 'add_action(\'wp_head\', \'caos_analytics_render_tracking_code\', $sgal_enqueue_order);' - ) - ); - } -} diff --git a/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local.php b/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local.php deleted file mode 100644 index 432285fb..00000000 --- a/src/addons/tests/integration/addons/test-caos-host-analyticsjs-local.php +++ /dev/null @@ -1,31 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/host-analyticsjs-local/trunk/includes/frontend/class-tracking.php' ); - - $this->assertNotFalse( - strpos( - $content, - 'add_filter(\'woocommerce_google_analytics_script_src\'' - ) - ); - - $this->assertNotFalse( - strpos( - $content, - '\'render_tracking_code\']' - ) - ); - } -} diff --git a/src/addons/tests/integration/addons/test-custom-facebook-feed-old.php b/src/addons/tests/integration/addons/test-custom-facebook-feed-old.php deleted file mode 100644 index ac5b9e3b..00000000 --- a/src/addons/tests/integration/addons/test-custom-facebook-feed-old.php +++ /dev/null @@ -1,24 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/custom-facebook-feed/tags/2.17.1/custom-facebook-feed.php' ); - - $this->assertNotFalse( strpos( $content, 'echo \'var cfflinkhashtags = "\' .' ) ); - $this->assertNotFalse( strpos( $content, "wp_register_script( 'cffscripts'," ) ); - $this->assertNotFalse( strpos( $content, "add_action( 'wp_footer', 'cff_js' );" ) ); - $this->assertNotFalse( strpos( $content, "add_action( 'wp_enqueue_scripts', 'cff_scripts_method' );" ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-custom-facebook-feed.php b/src/addons/tests/integration/addons/test-custom-facebook-feed.php deleted file mode 100644 index 9bb9209c..00000000 --- a/src/addons/tests/integration/addons/test-custom-facebook-feed.php +++ /dev/null @@ -1,23 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/custom-facebook-feed/trunk/inc/Custom_Facebook_Feed.php' ); - - $this->assertNotFalse( strpos( $content, 'echo \'var cfflinkhashtags = "\' . $cff_link_hashtags . \'";\';' ) ); - $this->assertNotFalse( strpos( $content, 'wp_enqueue_script( \'cffscripts\' );' ) ); - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', [ self::$instance, \'cff_js\' ] );' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-enhanced-ecommerce-for-woocommerce-store.php b/src/addons/tests/integration/addons/test-enhanced-ecommerce-for-woocommerce-store.php deleted file mode 100644 index 72eb3e73..00000000 --- a/src/addons/tests/integration/addons/test-enhanced-ecommerce-for-woocommerce-store.php +++ /dev/null @@ -1,19 +0,0 @@ -curl_get_content( 'https://plugins.svn.wordpress.org/enhanced-e-commerce-for-woocommerce-store/trunk/public/class-enhanced-ecommerce-google-analytics-public.php' ); - - $this->assertNotFalse( strpos( $content, 'wc_enqueue_js(' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-facebook-for-woocommerce.php b/src/addons/tests/integration/addons/test-facebook-for-woocommerce.php deleted file mode 100644 index b883d09c..00000000 --- a/src/addons/tests/integration/addons/test-facebook-for-woocommerce.php +++ /dev/null @@ -1,30 +0,0 @@ -assertNotFalse( strpos( $content, 'WC_Facebookcommerce' ) ); - } - - /** - * @covers \cookiebot_addons\controller\addons\facebook_for_woocommerce\Facebook_For_Woocommerce - */ - public function test_facebook_for_woocommerce_hooks() { - - $content = file_get_contents( 'https://raw.githubusercontent.com/facebookincubator/facebook-for-woocommerce/master/facebook-commerce-pixel-event.php' ); - - $this->assertNotFalse( strpos( $content, 'apply_filters( \'wc_facebook_pixel_script_attributes\',' ) ); - - } -} diff --git a/src/addons/tests/integration/addons/test-ga-google-analytics.php b/src/addons/tests/integration/addons/test-ga-google-analytics.php deleted file mode 100644 index 30b74c2f..00000000 --- a/src/addons/tests/integration/addons/test-ga-google-analytics.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/ga-google-analytics/trunk/inc/plugin-core.php' ); - - $this->assertNotFalse( strpos( $content, 'ga_google_analytics_tracking_code' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-gadwp.php b/src/addons/tests/integration/addons/test-gadwp.php deleted file mode 100644 index 35455d7e..00000000 --- a/src/addons/tests/integration/addons/test-gadwp.php +++ /dev/null @@ -1,29 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/google-analytics-dashboard-for-wp/trunk/includes/frontend/tracking/class-tracking-analytics.php' ); - - $this->assertNotFalse( strpos( $content, 'GoogleAnalyticsObject' ) ); - - $content = $this->curl_get_content( 'http://plugins.svn.wordpress.org/google-analytics-dashboard-for-wp/trunk/includes/frontend/frontend.php' ); - - $this->assertNotFalse( strpos( $content, "add_action( 'wp_head', 'exactmetrics_tracking_script', 6 );" ) ); - - $content = $this->curl_get_content( 'http://plugins.svn.wordpress.org/google-analytics-dashboard-for-wp/trunk/includes/frontend/events/class-analytics-events.php' ); - - $this->assertNotFalse( strpos( $content, "wp_enqueue_script( 'exactmetrics-frontend-script'," ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-google-analyticator.php b/src/addons/tests/integration/addons/test-google-analyticator.php deleted file mode 100644 index 0497bfa0..00000000 --- a/src/addons/tests/integration/addons/test-google-analyticator.php +++ /dev/null @@ -1,24 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/google-analyticator/trunk/google-analyticator.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_print_scripts\', \'ga_external_tracking_js\',99999);' ) ); - $this->assertNotFalse( strpos( $content, 'add_action(\'login_head\', \'add_google_analytics\', 99);' ) ); - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', \'add_google_analytics\',99);' ) ); - $this->assertNotFalse( strpos( $content, 'wp_enqueue_script(\'ga-external-tracking\', plugins_url' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-google-analytics-plus.php b/src/addons/tests/integration/addons/test-google-analytics-plus.php deleted file mode 100644 index c1b1b278..00000000 --- a/src/addons/tests/integration/addons/test-google-analytics-plus.php +++ /dev/null @@ -1,26 +0,0 @@ -assertNotFalse( strpos( $content, $needle ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-google-analytics.php b/src/addons/tests/integration/addons/test-google-analytics.php deleted file mode 100644 index e378be22..00000000 --- a/src/addons/tests/integration/addons/test-google-analytics.php +++ /dev/null @@ -1,22 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/googleanalytics/trunk/class/Ga_Frontend.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_head\', \'Ga_Frontend::insert_ga_script\' );' ) ); - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_enqueue_scripts\', \'Ga_Frontend::platform_sharethis\' );' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-google-site-kit.php b/src/addons/tests/integration/addons/test-google-site-kit.php deleted file mode 100644 index bcf7d4f7..00000000 --- a/src/addons/tests/integration/addons/test-google-site-kit.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/google-site-kit/trunk/includes/Modules/Analytics/Web_Tag.php' ); - - $this->assertNotFalse( strpos( $content, "wp_script_add_data( 'google_gtagjs', 'script_execution', 'async' );" ) ); - - } -} diff --git a/src/addons/tests/integration/addons/test-hubspot-leadin.php b/src/addons/tests/integration/addons/test-hubspot-leadin.php deleted file mode 100644 index 1fa0a94e..00000000 --- a/src/addons/tests/integration/addons/test-hubspot-leadin.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/leadin/trunk/src/class-assetsmanager.php' ); - - $this->assertNotFalse( strpos( $content, "const TRACKING_CODE = 'leadin-script-loader-js';" ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-hubspot-tracking-code.php b/src/addons/tests/integration/addons/test-hubspot-tracking-code.php deleted file mode 100644 index 8e6aed95..00000000 --- a/src/addons/tests/integration/addons/test-hubspot-tracking-code.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/hubspot-tracking-code/trunk/inc/class-hubspot-tracking-code-analytics.php' ); - - $this->assertNotFalse( strpos( $content, ' -"; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - - public function test_official_facebook_pixel_caldera_form() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressCalderaForm.php' ); - $snippet = "add_action( - 'caldera_forms_ajax_return', - array(__CLASS__, 'injectLeadEvent'), - 10, 2);"; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - - public function test_official_facebook_pixel_contact_form_7() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressContactForm7.php' ); - $snippets[] = "add_action( - 'wpcf7_submit', - array(__CLASS__, 'trackServerEvent'), - 10, 2);"; - - $snippets[] = "add_action( - 'wpcf7_feedback_response', - array(__CLASS__, 'injectLeadEvent'), - 20, 2);"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_formidable_form() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressFormidableForm.php' ); - $snippets[] = "add_action( - 'frm_after_create_entry', - array(__CLASS__, 'trackServerEvent'), - 20, - 2 - );"; - $snippets[] = "add_action( - 'wp_footer', - array(__CLASS__, 'injectLeadEvent'), - 20 - );"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_easy_digital_downloads() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressEasyDigitalDownloads.php' ); - $snippets[] = "add_action( - 'edd_payment_receipt_after', - array(__CLASS__, 'trackPurchaseEvent'), - 10, 2);"; - $snippets[] = "add_action( - 'edd_after_download_content', - array(__CLASS__, 'injectAddToCartListener') - );"; - $snippets[] = "self::addPixelFireForHook(array( - 'hook_name' => 'edd_after_checkout_cart', - 'classname' => __CLASS__, - 'inject_function' => 'injectInitiateCheckoutEvent'));"; - $snippets[] = "add_action( - 'edd_after_download_content', - array(__CLASS__, 'injectViewContentEvent'), - 40, 1 - );"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_gravity_forms() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressGravityForms.php' ); - $snippet = "add_filter( - 'gform_confirmation', - array(__CLASS__, 'injectLeadEvent'), - 10, 4);"; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - - public function test_official_facebook_pixel_mailchimp_for_wp() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressMailchimpForWp.php' ); - $snippet = "self::addPixelFireForHook(array( - 'hook_name' => 'mc4wp_form_subscribed', - 'classname' => __CLASS__, - 'inject_function' => 'injectLeadEvent')); - }"; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - - public function test_official_facebook_pixel_ninja_forms() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressNinjaForms.php' ); - $snippet = "add_action( - 'ninja_forms_submission_actions', - array(__CLASS__, 'injectLeadEvent'), - 10, 3);"; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - - public function test_official_facebook_pixel_woocommerce() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressWooCommerce.php' ); - $snippets[] = "add_action('woocommerce_after_checkout_form', - array(__CLASS__, 'trackInitiateCheckout'), - 40);"; - $snippets[] = "add_action( 'woocommerce_add_to_cart', - array(__CLASS__, 'trackAddToCartEvent'), - 40, 4);"; - $snippets[] = "add_action( 'woocommerce_thankyou', - array(__CLASS__, 'trackPurchaseEvent'), - 40);"; - $snippets[] = "add_action( 'woocommerce_payment_complete', - array(__CLASS__, 'trackPurchaseEvent'), - 40);"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_WPECommerce() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressWPECommerce.php' ); - $snippets[] = "add_action('wpsc_add_to_cart_json_response', - array(__CLASS__, 'injectAddToCartEvent'), 11);"; - $snippets[] = "self::addPixelFireForHook(array( - 'hook_name' => 'wpsc_before_shopping_cart_page', - 'classname' => __CLASS__, - 'inject_function' => 'injectInitiateCheckoutEvent'));"; - $snippets[] = "add_action( - 'wpsc_transaction_results_shutdown', - array(__CLASS__, 'injectPurchaseEvent'), 11, 3);"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_wp_forms() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressWPForms.php' ); - $snippets[] = "add_action( - 'wp_footer', - array(__CLASS__, 'injectLeadEvent'), - 20 - );"; - $snippets[] = "add_action( - 'wpforms_process_before', - array(__CLASS__, 'trackEvent'), - 20, - 2 - );"; - - foreach ( $snippets as $snippet ) { - $this->assertNotFalse( strpos( $content, $snippet ) ); - } - } - - public function test_official_facebook_pixel_integration_base() { - $content = $this->curl_get_content( self::TRUNK . 'integration/FacebookWordpressIntegrationBase.php' ); - - $snippet = 'add_action( - \'wp_footer\', - $hook_wp_footer, - 11);'; - - $this->assertNotFalse( strpos( $content, $snippet ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-optinmonster.php b/src/addons/tests/integration/addons/test-optinmonster.php deleted file mode 100644 index f3f523c1..00000000 --- a/src/addons/tests/integration/addons/test-optinmonster.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/optinmonster/trunk/OMAPI/Output.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_enqueue_scripts\', array( $this, \'api_script\' ) );' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-pixel-caffeine.php b/src/addons/tests/integration/addons/test-pixel-caffeine.php deleted file mode 100644 index 1dc943c0..00000000 --- a/src/addons/tests/integration/addons/test-pixel-caffeine.php +++ /dev/null @@ -1,23 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/pixel-caffeine/trunk/includes/class-aepc-pixel-scripts.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_head\', array( __CLASS__, \'pixel_init\' ), 99 );' ) ); - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', array( __CLASS__, \'pixel_init\' ), 1 );' ) ); - $this->assertNotFalse( strpos( $content, 'wp_register_script( \'aepc-pixel-events\',' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-simple-share-buttons-adder.php b/src/addons/tests/integration/addons/test-simple-share-buttons-adder.php deleted file mode 100644 index 3fb9ebc3..00000000 --- a/src/addons/tests/integration/addons/test-simple-share-buttons-adder.php +++ /dev/null @@ -1,19 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/simple-share-buttons-adder/trunk/php/class-styles.php' ); - - $this->assertNotFalse( strpos( $content, "wp_enqueue_script('ssba-sharethis'" ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-wd-google-analytics.php b/src/addons/tests/integration/addons/test-wd-google-analytics.php deleted file mode 100644 index a6997925..00000000 --- a/src/addons/tests/integration/addons/test-wd-google-analytics.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/wd-google-analytics/trunk/gawd_class.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', array($this, \'gawd_tracking_code\'), 99);' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-wp-analytify.php b/src/addons/tests/integration/addons/test-wp-analytify.php deleted file mode 100644 index bdc03c6f..00000000 --- a/src/addons/tests/integration/addons/test-wp-analytify.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/wp-analytify/trunk/wp-analytify.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_head\', array( $this, \'analytify_add_analytics_code\' ) );' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-wp-google-analytics-events.php b/src/addons/tests/integration/addons/test-wp-google-analytics-events.php deleted file mode 100644 index 1ee58f2d..00000000 --- a/src/addons/tests/integration/addons/test-wp-google-analytics-events.php +++ /dev/null @@ -1,37 +0,0 @@ -curl_get_content( 'https://plugins.svn.wordpress.org/wp-google-analytics-events/trunk/ga-scroll-event.php' ); - - $include_snippet = <<assertNotFalse( strpos( $content, $required_code_snippet ) ); - } - } -} diff --git a/src/addons/tests/integration/addons/test-wp-mautic.php b/src/addons/tests/integration/addons/test-wp-mautic.php deleted file mode 100644 index 25818fdb..00000000 --- a/src/addons/tests/integration/addons/test-wp-mautic.php +++ /dev/null @@ -1,22 +0,0 @@ -curl_get_content( 'https://plugins.svn.wordpress.org/wp-mautic/trunk/wpmautic.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_head\', \'wpmautic_inject_script\' );' ) ); - $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', \'wpmautic_inject_script\' );' ) ); - } -} diff --git a/src/addons/tests/integration/addons/test-wp-piwik.php b/src/addons/tests/integration/addons/test-wp-piwik.php deleted file mode 100644 index 015213a2..00000000 --- a/src/addons/tests/integration/addons/test-wp-piwik.php +++ /dev/null @@ -1,21 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/wp-piwik/trunk/classes/WP_Piwik.php' ); - - $this->assertNotFalse( strpos( $content, '\'disableCookies\' => self::$settings->getGlobalOption ( \'disable_cookies\' ) ? 1 : 0' ) ); - } -} diff --git a/src/addons/tests/integration/test-buffer-priorities.php b/src/addons/tests/integration/test-buffer-priorities.php deleted file mode 100644 index cf0cf5e6..00000000 --- a/src/addons/tests/integration/test-buffer-priorities.php +++ /dev/null @@ -1,53 +0,0 @@ -curl_get_content( 'http://plugins.svn.wordpress.org/host-analyticsjs-local/trunk/includes/frontend/class-tracking.php' ); - - $this->assertNotFalse( - strpos( - $content, - 'add_filter(\'woocommerce_google_analytics_script_src\'' - ) - ); - - $this->assertNotFalse( - strpos( - $content, - '\'render_tracking_code\']' - ) - ); - } - - /** - * @covers \cookiebot_addons\controller\addons\ga_google_analytics\Ga_Google_Analytics - */ - public function test_ga_google_analytics() { - $content = $this->curl_get_content( 'http://plugins.svn.wordpress.org/ga-google-analytics/trunk/inc/plugin-core.php' ); - - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', $function);' ) ); - $this->assertNotFalse( strpos( $content, 'add_action(\'wp_footer\', $function);' ) ); - } - - /** - * @covers \cookiebot_addons|controller\addons\google_analyticator\Google_Analyticator - */ - // public function test_google_analyticator() { - // $content = file_get_contents( 'http://plugins.svn.wordpress.org/ga-google-analytics/trunk/inc/plugin-core.php' ); - // - // $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', \'add_google_analytics\',99);' ) ); - // $this->assertNotFalse( strpos( $content, 'add_action(\'login_head\', \'add_google_analytics\', 99);' ) ); - // } -} diff --git a/src/addons/tests/unit/test-addon-file-name.php b/src/addons/tests/unit/test-addon-file-name.php deleted file mode 100644 index 77b145c6..00000000 --- a/src/addons/tests/unit/test-addon-file-name.php +++ /dev/null @@ -1,74 +0,0 @@ -get_plugins(); - } - - /** - * Load the addons through json file. - */ - private function get_plugins() { - $this->file_path = dirname( dirname( __DIR__ ) ) . '/addons.json'; - $this->file = file_get_contents( $this->file_path ); - $this->plugins = apply_filters( 'cookiebot_addons_list', json_decode( $this->file ) ); - } - - /** - * Validate if the plugins in addons.json do exist as a class in addons controller directory. - */ - public function test_plugins_are_valid() { - foreach ( $this->plugins as $plugin ) { - $check = class_exists( $plugin ); - $this->assertTrue( $check ); - } - } - - public function test_get_svn_url() { - $settingsMock = $this->getMockBuilder( 'cookiebot_addons\lib\Settings_Service_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $scriptLoaderTagMock = $this->getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - - foreach ( $this->plugins as $plugin ) { - $p = new $plugin->class( $settingsMock, $scriptLoaderTagMock, $cookieConsentMock, $bufferOutputMock ); - - if ( method_exists( $p, 'get_svn_url' ) ) { - $svn_address = $p->get_svn_url(); - if ( ! empty( $svn_address ) ) { - $content = $this->curl_get_content( $svn_address ); - $this->assertNotFalse( $content ); - } - } - } - } -} diff --git a/src/addons/tests/unit/test-cookie-consent.php b/src/addons/tests/unit/test-cookie-consent.php deleted file mode 100644 index 004af8a9..00000000 --- a/src/addons/tests/unit/test-cookie-consent.php +++ /dev/null @@ -1,70 +0,0 @@ -cookie = '{"stamp":"0boMmPgsG8gUTRvMkOLtyZ1uLvOFJobBbNb23IZO/TpY3eETvRxFfg==","necessary":"true","preferences":"true","statistics":"false","marketing":"false","ver":"1","utc":"1557479161596"}'; - } - - /** - * Test Cookie Consent with valid encoded json format - * - * @since 2.4.1 - */ - public function test_scan_cookie_with_encoded_json_format() { - $cookie_consent = new Cookie_Consent( $this->cookie ); - - $this->assertEquals( $cookie_consent->get_cookie_states(), array( 'necessary', 'preferences' ) ); - } - - /** - * Test Cookie Consent with unchecked status - * Only necessary type should be allowed - * - * @since 2.4.1 - */ - public function test_scan_cookie_with_zero_value() { - $cookie_consent = new Cookie_Consent( 0 ); - - $this->assertEquals( $cookie_consent->get_cookie_states(), array( 'necessary' ) ); - } - - /** - * Test Cookie Consent with every type checked - * - * @since 2.4.1 - */ - public function test_scan_cookie_everything_checked() { - $cookie_consent = new Cookie_Consent( - 1 ); - - $this->assertEquals( - $cookie_consent->get_cookie_states(), - array( 'necessary', 'preferences', 'statistics', 'marketing' ) - ); - } - - /** - * Test Cookie Consent with invalid encoded json format - * Should return only necessary type - * - * @since 2.4.1 - */ - public function test_scan_cookie_with_wrong_encoded_json_format() { - $cookie_consent = new Cookie_Consent( '{"test":"test"}' ); - - $this->assertEquals( $cookie_consent->get_cookie_states(), array( 'necessary' ) ); - } -} diff --git a/src/addons/tests/unit/test-get-option-name.php b/src/addons/tests/unit/test-get-option-name.php deleted file mode 100644 index ddb33859..00000000 --- a/src/addons/tests/unit/test-get-option-name.php +++ /dev/null @@ -1,97 +0,0 @@ -get_plugins(); - } - - /** - * Load the addons through json file. - * - * @since 1.8.0 - */ - private function get_plugins() { - $this->file_path = dirname( dirname( __DIR__ ) ) . '/addons.json'; - $this->file = file_get_contents( $this->file_path ); - $this->plugins = apply_filters( 'cookiebot_addons_list', json_decode( $this->file ) ); - } - - /** - * Validate if the plugins in addons.json do exist as a class in addons controller directory. - * - * @since 1.8.0 - */ - public function test_plugins_are_valid() { - foreach ( $this->plugins as $plugin ) { - $check = is_object( $plugin ) && class_exists( $plugin->class ); - $this->assertTrue( $check ); - } - } - - /** - * Check if get_option_name is unique in every addon. - * @covers \cookiebot_addons\lib\Settings_Service_Interface - * @covers \cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface - * @covers \cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface - * @covers \cookiebot_addons\lib\buffer\Buffer_Output_Interface - * - * @version 2.1.3 - * @since 1.8.0 - */ - public function test_get_option_name_unique() { - $options = array(); - - $settingsMock = $this->getMockBuilder( 'cookiebot_addons\lib\Settings_Service_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $scriptLoaderTagMock = $this->getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' ) - ->disableOriginalConstructor() - ->getMock(); - - foreach ( $this->plugins as $plugin ) { - $p = new $plugin->class( $settingsMock, $scriptLoaderTagMock, $cookieConsentMock, $bufferOutputMock ); - - // if it doesn't have parent class - if ( get_parent_class( $p ) === false ) { - // test if the option_name exists in the options array - $this->assertNotContains( $p->get_option_name(), $options ); - - // add name to options array - $options[] = $p->get_option_name(); - } - } - } - -} diff --git a/src/addons/tests/unit/test-latest-plugin-version.php b/src/addons/tests/unit/test-latest-plugin-version.php deleted file mode 100644 index 7b693790..00000000 --- a/src/addons/tests/unit/test-latest-plugin-version.php +++ /dev/null @@ -1,54 +0,0 @@ -getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' )->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' )->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' )->getMock(); - - $addonMock = new CAOS_Host_Analyticsjs_Local_Save_Ga_Local( - $settings, - $scriptLoaderTagMock, - $cookieConsentMock, - $bufferOutputMock - ); - - $this->assertFalse( $settings->is_latest_plugin_version( $addonMock ) ); - } - - /** - * Test if newer version has the latest plugin version - * - * @since 2.1.3 - */ - public function test_if_newer_version_has_latest_plugin_version() { - $settings = new Settings_Service( new \stdClass() ); - - $scriptLoaderTagMock = $this->getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' )->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' )->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' )->getMock(); - - $addonMock = new CAOS_Host_Analyticsjs_Local( - $settings, - $scriptLoaderTagMock, - $cookieConsentMock, - $bufferOutputMock - ); - - $this->assertTrue( $settings->is_latest_plugin_version( $addonMock ) ); - } -} diff --git a/src/addons/tests/unit/test-previous-version-active.php b/src/addons/tests/unit/test-previous-version-active.php deleted file mode 100644 index 67250edb..00000000 --- a/src/addons/tests/unit/test-previous-version-active.php +++ /dev/null @@ -1,74 +0,0 @@ -getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' )->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' )->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' )->getMock(); - - $addon = $this->getMockBuilder( 'cookiebot_addons\controller\addons\caos_host_analyticsjs_local_save_ga_local\CAOS_Host_Analyticsjs_Local_Save_Ga_Local' ) - ->setConstructorArgs( - array( - $settings, - $scriptLoaderTagMock, - $cookieConsentMock, - $bufferOutputMock, - ) - ) - ->getMock(); - - $addon->expects( $this->any() ) - ->method( 'is_addon_activated' ) - ->will( $this->returnValue( true ) ); - - $addon->expects( $this->any() ) - ->method( 'get_parent_class' ) - ->will( $this->returnValue( 'CAOS_Host_Analyticsjs_Local' ) ); - - $this->assertTrue( $settings->is_previous_version_active( array( $addon ), 'CAOS_Host_Analyticsjs_Local' ) ); - } - - /** - * Test if newer version has the latest plugin version - * - * @since 2.1.3 - */ - public function test_if_newer_version_has_latest_plugin_version() { - $settings = new Settings_Service( new \stdClass() ); - - $scriptLoaderTagMock = $this->getMockBuilder( 'cookiebot_addons\lib\script_loader_tag\Script_Loader_Tag_Interface' )->getMock(); - $cookieConsentMock = $this->getMockBuilder( 'cookiebot_addons\lib\Cookie_Consent_Interface' )->getMock(); - $bufferOutputMock = $this->getMockBuilder( 'cookiebot_addons\lib\buffer\Buffer_Output_Interface' )->getMock(); - - $addon = $this->getMockBuilder( 'cookiebot_addons\controller\addons\caos_host_analyticsjs_local\CAOS_Host_Analyticsjs_Local' ) - ->setConstructorArgs( - array( - $settings, - $scriptLoaderTagMock, - $cookieConsentMock, - $bufferOutputMock, - ) - ) - ->getMock(); - - $addon->expects( $this->any() ) - ->method( 'is_addon_activated' ) - ->will( $this->returnValue( true ) ); - - $this->assertFalse( $settings->is_previous_version_active( array( $addon ), 'CAOS_Host_Analyticsjs_Local' ) ); - } -} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 5e0a32ac..4c097193 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,31 +1,45 @@ = 8 ) { + echo 'The scaffolded tests cannot currently be run on PHP 8.0+. See https://github.com/wp-cli/scaffold-command/issues/285' . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped + exit( 1 ); } -if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) { - echo 'Could not find ' . esc_html( $_tests_dir ) . '/includes/functions.php, have you run bin/install-wp-tests.sh ?' . PHP_EOL; +$cybot_cookiebot_tests_dir = getenv( 'WP_TESTS_DIR' ); + +if ( ! $cybot_cookiebot_tests_dir ) { + $cybot_cookiebot_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib'; +} + +if ( ! file_exists( "{$cybot_cookiebot_tests_dir}/includes/functions.php" ) ) { + echo "Could not find {$cybot_cookiebot_tests_dir}/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped exit( 1 ); } // Give access to tests_add_filter() function. -require_once $_tests_dir . '/includes/functions.php'; +require_once "{$cybot_cookiebot_tests_dir}/includes/functions.php"; /** * Manually load the plugin being tested. */ -function _manually_load_plugin() { +function cybot_cookiebot_manually_load_plugin() { require dirname( dirname( __FILE__ ) ) . '/cookiebot.php'; } -tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); + +tests_add_filter( 'muplugins_loaded', 'cybot_cookiebot_manually_load_plugin' ); // Start up the WP testing environment. -require $_tests_dir . '/includes/bootstrap.php'; +require "{$cybot_cookiebot_tests_dir}/includes/bootstrap.php"; diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 00000000..a1d29d84 --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,19 @@ +version: '3.8' +services: + database: + environment: + MYSQL_ROOT_PASSWORD: root + image: mysql:5.7 + + cookiebot: + command: + - bash + depends_on: + - database + environment: + DATABASE_PASSWORD: root + image: futureys/phpunit-wordpress-plugin + stdin_open: true + tty: true + volumes: + - ../:/plugin \ No newline at end of file diff --git a/tests/helpers.php b/tests/helpers.php new file mode 100644 index 00000000..e1917912 --- /dev/null +++ b/tests/helpers.php @@ -0,0 +1,15 @@ +assertNotFalse( strpos( $content, "wp_enqueue_script( 'addtoany'" ) ); + } +} diff --git a/tests/integration/addons/Test_Addthis.php b/tests/integration/addons/Test_Addthis.php new file mode 100644 index 00000000..dac2600c --- /dev/null +++ b/tests/integration/addons/Test_Addthis.php @@ -0,0 +1,28 @@ +assertNotFalse( strpos( $content, "'addthis_widget'," ) ); + $this->assertNotFalse( strpos( $content, 'window.addthis_product ' ) ); + $this->assertNotFalse( strpos( $content, 'add_action(\'wp_enqueue_scripts\', array($this, \'enqueueScripts\'));' ) ); + } +} diff --git a/tests/integration/addons/Test_CAOS_Host_Analyticsjs_Local_Version_1_97.php b/tests/integration/addons/Test_CAOS_Host_Analyticsjs_Local_Version_1_97.php new file mode 100644 index 00000000..09907580 --- /dev/null +++ b/tests/integration/addons/Test_CAOS_Host_Analyticsjs_Local_Version_1_97.php @@ -0,0 +1,34 @@ +assertNotFalse( + strpos( + $content, + 'add_action(\'wp_footer\', \'caos_analytics_render_tracking_code\', $sgal_enqueue_order);' + ) + ); + $this->assertNotFalse( + strpos( + $content, + 'add_action(\'wp_head\', \'caos_analytics_render_tracking_code\', $sgal_enqueue_order);' + ) + ); + } +} diff --git a/tests/integration/addons/Test_Caos_Host_Analyticsjs_Local.php b/tests/integration/addons/Test_Caos_Host_Analyticsjs_Local.php new file mode 100644 index 00000000..c59c66f2 --- /dev/null +++ b/tests/integration/addons/Test_Caos_Host_Analyticsjs_Local.php @@ -0,0 +1,35 @@ +assertNotFalse( + strpos( + $content, + 'add_filter(\'woocommerce_google_analytics_script_src\'' + ) + ); + + $this->assertNotFalse( + strpos( + $content, + '\'render_tracking_code\']' + ) + ); + } +} diff --git a/tests/integration/addons/Test_Custom_Facebook_Feed.php b/tests/integration/addons/Test_Custom_Facebook_Feed.php new file mode 100644 index 00000000..9a378230 --- /dev/null +++ b/tests/integration/addons/Test_Custom_Facebook_Feed.php @@ -0,0 +1,28 @@ +assertNotFalse( strpos( $content, 'echo \'var cfflinkhashtags = "\' . $cff_link_hashtags . \'";\';' ) ); + $this->assertNotFalse( strpos( $content, 'wp_enqueue_script( \'cffscripts\' );' ) ); + $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', [ self::$instance, \'cff_js\' ] );' ) ); + } +} diff --git a/tests/integration/addons/Test_Custom_Facebook_Feed_Version_2_17_1.php b/tests/integration/addons/Test_Custom_Facebook_Feed_Version_2_17_1.php new file mode 100644 index 00000000..4aa85d71 --- /dev/null +++ b/tests/integration/addons/Test_Custom_Facebook_Feed_Version_2_17_1.php @@ -0,0 +1,29 @@ +assertNotFalse( strpos( $content, 'echo \'var cfflinkhashtags = "\' .' ) ); + $this->assertNotFalse( strpos( $content, "wp_register_script( 'cffscripts'," ) ); + $this->assertNotFalse( strpos( $content, "add_action( 'wp_footer', 'cff_js' );" ) ); + $this->assertNotFalse( strpos( $content, "add_action( 'wp_enqueue_scripts', 'cff_scripts_method' );" ) ); + } +} diff --git a/tests/integration/addons/Test_Enhanced_Ecommerce_For_Woocommerce_Store.php b/tests/integration/addons/Test_Enhanced_Ecommerce_For_Woocommerce_Store.php new file mode 100644 index 00000000..c66e78a2 --- /dev/null +++ b/tests/integration/addons/Test_Enhanced_Ecommerce_For_Woocommerce_Store.php @@ -0,0 +1,23 @@ +assertNotFalse( strpos( $content, 'wc_enqueue_js(' ) ); + } +} diff --git a/tests/integration/addons/Test_Facebook_For_Woocommerce.php b/tests/integration/addons/Test_Facebook_For_Woocommerce.php new file mode 100644 index 00000000..7432aee2 --- /dev/null +++ b/tests/integration/addons/Test_Facebook_For_Woocommerce.php @@ -0,0 +1,37 @@ +assertNotFalse( strpos( $content, 'WC_Facebookcommerce' ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\facebook_for_woocommerce\Facebook_For_Woocommerce + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_facebook_for_woocommerce_hooks() { + $content = remote_get_svn_contents( Facebook_For_Woocommerce::get_svn_url( 'facebook-commerce-pixel-event.php' ) ); + + $this->assertNotFalse( strpos( $content, 'apply_filters( \'wc_facebook_pixel_script_attributes\',' ) ); + } +} diff --git a/tests/integration/addons/Test_Ga_Google_Analytics.php b/tests/integration/addons/Test_Ga_Google_Analytics.php new file mode 100644 index 00000000..861dd127 --- /dev/null +++ b/tests/integration/addons/Test_Ga_Google_Analytics.php @@ -0,0 +1,28 @@ +assertNotFalse( strpos( $content, 'ga_google_analytics_tracking_code' ) ); + $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', $function);' ) ); + $this->assertNotFalse( strpos( $content, 'add_action(\'wp_footer\', $function);' ) ); + } +} diff --git a/tests/integration/addons/Test_Gadwp.php b/tests/integration/addons/Test_Gadwp.php new file mode 100644 index 00000000..ec3b9682 --- /dev/null +++ b/tests/integration/addons/Test_Gadwp.php @@ -0,0 +1,31 @@ +assertNotFalse( strpos( $content, 'GoogleAnalyticsObject' ) ); + + $content = remote_get_svn_contents( Gadwp::get_svn_url( 'includes/frontend/frontend.php' ) ); + $this->assertNotFalse( strpos( $content, "add_action( 'wp_head', 'exactmetrics_tracking_script', 6 );" ) ); + + $content = remote_get_svn_contents( Gadwp::get_svn_url( 'includes/frontend/events/class-analytics-events.php' ) ); + $this->assertNotFalse( strpos( $content, "wp_enqueue_script( 'exactmetrics-frontend-script'," ) ); + } +} diff --git a/tests/integration/addons/Test_Google_Analyticator.php b/tests/integration/addons/Test_Google_Analyticator.php new file mode 100644 index 00000000..92def93f --- /dev/null +++ b/tests/integration/addons/Test_Google_Analyticator.php @@ -0,0 +1,29 @@ +assertNotFalse( strpos( $content, 'add_action(\'wp_print_scripts\', \'ga_external_tracking_js\',99999);' ) ); + $this->assertNotFalse( strpos( $content, 'add_action(\'login_head\', \'add_google_analytics\', 99);' ) ); + $this->assertNotFalse( strpos( $content, 'add_action(\'wp_head\', \'add_google_analytics\',99);' ) ); + $this->assertNotFalse( strpos( $content, 'wp_enqueue_script(\'ga-external-tracking\', plugins_url' ) ); + } +} diff --git a/tests/integration/addons/Test_Google_Analytics.php b/tests/integration/addons/Test_Google_Analytics.php new file mode 100644 index 00000000..d1c77c68 --- /dev/null +++ b/tests/integration/addons/Test_Google_Analytics.php @@ -0,0 +1,27 @@ +assertNotFalse( strpos( $content, 'add_action( \'wp_head\', \'Ga_Frontend::insert_ga_script\' );' ) ); + $this->assertNotFalse( strpos( $content, 'add_action( \'wp_enqueue_scripts\', \'Ga_Frontend::platform_sharethis\' );' ) ); + } +} diff --git a/tests/integration/addons/Test_Google_Site_Kit.php b/tests/integration/addons/Test_Google_Site_Kit.php new file mode 100644 index 00000000..8b7b9456 --- /dev/null +++ b/tests/integration/addons/Test_Google_Site_Kit.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, "wp_script_add_data( 'google_gtagjs', 'script_execution', 'async' );" ) ); + } +} diff --git a/tests/integration/addons/Test_Hubspot_Leadin.php b/tests/integration/addons/Test_Hubspot_Leadin.php new file mode 100644 index 00000000..3a755db0 --- /dev/null +++ b/tests/integration/addons/Test_Hubspot_Leadin.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, "const TRACKING_CODE = 'leadin-script-loader-js';" ) ); + } +} diff --git a/tests/integration/addons/Test_Hubspot_Tracking_Code.php b/tests/integration/addons/Test_Hubspot_Tracking_Code.php new file mode 100644 index 00000000..32f527fa --- /dev/null +++ b/tests/integration/addons/Test_Hubspot_Tracking_Code.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, ' + +TEXT; + + $this->assertNotFalse( strpos( $content, $snippet ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_caldera_form() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressCalderaForm.php' ) ); + $snippet = <<assertNotFalse( strpos( $content, $snippet ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_contact_form_7() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressContactForm7.php' ) ); + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_formidable_form() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressFormidableForm.php' ) ); + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_easy_digital_downloads() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressEasyDigitalDownloads.php' ) ); + $snippets[] = << 'edd_after_checkout_cart', + 'classname' => __CLASS__, + 'inject_function' => 'injectInitiateCheckoutEvent')); +TEXT; + + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_gravity_forms() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressGravityForms.php' ) ); + $snippet = <<assertNotFalse( strpos( $content, $snippet ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_mailchimp_for_wp() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressMailchimpForWp.php' ) ); + $snippet = << 'mc4wp_form_subscribed', + 'classname' => __CLASS__, + 'inject_function' => 'injectLeadEvent')); + } +TEXT; + + $this->assertNotFalse( strpos( $content, $snippet ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_ninja_forms() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressNinjaForms.php' ) ); + $snippet = <<assertNotFalse( strpos( $content, $snippet ) ); + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_woocommerce() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressWooCommerce.php' ) ); + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_WPECommerce() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressWPECommerce.php' ) ); + $snippets[] = << 'wpsc_before_shopping_cart_page', + 'classname' => __CLASS__, + 'inject_function' => 'injectInitiateCheckoutEvent')); +TEXT; + + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_wp_forms() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressWPForms.php' ) ); + $snippets[] = <<assertNotFalse( strpos( $content, $snippet ) ); + } + } + + /** + * @covers \cybot\cookiebot\addons\controller\addons\official_facebook_pixel\Official_Facebook_Pixel + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_official_facebook_pixel_integration_base() { + $content = remote_get_svn_contents( Official_Facebook_Pixel::get_svn_url( 'integration/FacebookWordpressIntegrationBase.php' ) ); + + $snippet = <<assertNotFalse( strpos( $content, $snippet ) ); + } +} diff --git a/tests/integration/addons/Test_Optinmonster.php b/tests/integration/addons/Test_Optinmonster.php new file mode 100644 index 00000000..c476d6e9 --- /dev/null +++ b/tests/integration/addons/Test_Optinmonster.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, 'add_action( \'wp_enqueue_scripts\', array( $this, \'api_script\' ) );' ) ); + } +} diff --git a/tests/integration/addons/Test_Pixel_Caffeine.php b/tests/integration/addons/Test_Pixel_Caffeine.php new file mode 100644 index 00000000..870a88cb --- /dev/null +++ b/tests/integration/addons/Test_Pixel_Caffeine.php @@ -0,0 +1,28 @@ +assertNotFalse( strpos( $content, 'add_action( \'wp_head\', array( __CLASS__, \'pixel_init\' ), 99 );' ) ); + $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', array( __CLASS__, \'pixel_init\' ), 1 );' ) ); + $this->assertNotFalse( strpos( $content, 'wp_register_script( \'aepc-pixel-events\',' ) ); + } +} diff --git a/tests/integration/addons/Test_Simple_Share_Buttons_Adder.php b/tests/integration/addons/Test_Simple_Share_Buttons_Adder.php new file mode 100644 index 00000000..03045c7b --- /dev/null +++ b/tests/integration/addons/Test_Simple_Share_Buttons_Adder.php @@ -0,0 +1,23 @@ +assertNotFalse( strpos( $content, "wp_enqueue_script('ssba-sharethis'" ) ); + } +} diff --git a/tests/integration/addons/Test_Wd_Google_Analytics.php b/tests/integration/addons/Test_Wd_Google_Analytics.php new file mode 100644 index 00000000..00cfdac2 --- /dev/null +++ b/tests/integration/addons/Test_Wd_Google_Analytics.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, 'add_action(\'wp_head\', array($this, \'gawd_tracking_code\'), 99);' ) ); + } +} diff --git a/tests/integration/addons/Test_Wp_Analytify.php b/tests/integration/addons/Test_Wp_Analytify.php new file mode 100644 index 00000000..c5615b28 --- /dev/null +++ b/tests/integration/addons/Test_Wp_Analytify.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, 'add_action( \'wp_head\', array( $this, \'analytify_add_analytics_code\' ) );' ) ); + } +} diff --git a/tests/integration/addons/Test_Wp_Google_Analytics_Events.php b/tests/integration/addons/Test_Wp_Google_Analytics_Events.php new file mode 100644 index 00000000..6e5f2b86 --- /dev/null +++ b/tests/integration/addons/Test_Wp_Google_Analytics_Events.php @@ -0,0 +1,43 @@ +assertNotFalse( strpos( $content, $required_code_snippet ) ); + } + } +} diff --git a/tests/integration/addons/Test_Wp_Mautic.php b/tests/integration/addons/Test_Wp_Mautic.php new file mode 100644 index 00000000..f11c18e5 --- /dev/null +++ b/tests/integration/addons/Test_Wp_Mautic.php @@ -0,0 +1,27 @@ +assertNotFalse( strpos( $content, 'add_action( \'wp_head\', \'wpmautic_inject_script\' );' ) ); + $this->assertNotFalse( strpos( $content, 'add_action( \'wp_footer\', \'wpmautic_inject_script\' );' ) ); + } +} diff --git a/tests/integration/addons/Test_Wp_Piwik.php b/tests/integration/addons/Test_Wp_Piwik.php new file mode 100644 index 00000000..81168f70 --- /dev/null +++ b/tests/integration/addons/Test_Wp_Piwik.php @@ -0,0 +1,26 @@ +assertNotFalse( strpos( $content, '\'disableCookies\' => self::$settings->getGlobalOption ( \'disable_cookies\' ) ? 1 : 0' ) ); + } +} diff --git a/tests/test-sample.php b/tests/test-sample.php deleted file mode 100644 index b8d20dfd..00000000 --- a/tests/test-sample.php +++ /dev/null @@ -1,20 +0,0 @@ -assertTrue( true ); - } -} diff --git a/tests/unit/Test_Addon_File_Name.php b/tests/unit/Test_Addon_File_Name.php new file mode 100644 index 00000000..626c7a93 --- /dev/null +++ b/tests/unit/Test_Addon_File_Name.php @@ -0,0 +1,67 @@ +assertTrue( $check ); + } + } + + /** + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_get_svn_url() { + $settings_mock = $this->getMockBuilder( Settings_Service_Interface::class ) + ->disableOriginalConstructor() + ->getMock(); + $script_loader_tag_mock = $this->getMockBuilder( Script_Loader_Tag_Interface::class ) + ->disableOriginalConstructor() + ->getMock(); + $cookie_consent_mock = $this->getMockBuilder( Cookie_Consent_Interface::class ) + ->disableOriginalConstructor() + ->getMock(); + $buffer_output_mock = $this->getMockBuilder( Buffer_Output_Interface::class ) + ->disableOriginalConstructor() + ->getMock(); + + foreach ( PLUGIN_ADDONS as $plugin_addon_classname ) { + $plugin_addon = new $plugin_addon_classname( + $settings_mock, + $script_loader_tag_mock, + $cookie_consent_mock, + $buffer_output_mock + ); + + if ( is_a( $plugin_addon, Open_Source_Addon_Interface::class ) ) { + $svn_url = $plugin_addon->get_svn_url(); + if ( ! empty( $svn_url ) ) { + $content = remote_get_svn_contents( $svn_url ); + $this->assertNotFalse( $content ); + } + } + } + } +} diff --git a/tests/unit/Test_Cookie_Consent.php b/tests/unit/Test_Cookie_Consent.php new file mode 100644 index 00000000..a6df73a6 --- /dev/null +++ b/tests/unit/Test_Cookie_Consent.php @@ -0,0 +1,68 @@ +assertEquals( array( 'necessary', 'preferences' ), $cookie_consent->get_cookie_states() ); + } + + /** + * Test Cookie Consent with unchecked status + * Only necessary type should be allowed + * + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_scan_cookie_with_zero_value() { + $cookie_consent = new Cookie_Consent( 0 ); + + $this->assertEquals( array( 'necessary' ), $cookie_consent->get_cookie_states() ); + } + + /** + * Test Cookie Consent with every type checked + * + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_scan_cookie_everything_checked() { + $cookie_consent = new Cookie_Consent( - 1 ); + + $this->assertEquals( + array( 'necessary', 'preferences', 'statistics', 'marketing' ), + $cookie_consent->get_cookie_states() + ); + } + + /** + * Test Cookie Consent with invalid encoded json format + * Should return only necessary type + * + * @throws ExpectationFailedException + * @throws InvalidArgumentException + */ + public function test_scan_cookie_with_wrong_encoded_json_format() { + $cookie_consent = new Cookie_Consent( '{"test":"test"}' ); + + $this->assertEquals( array( 'necessary' ), $cookie_consent->get_cookie_states() ); + } +} diff --git a/src/addons/tests/unit/test-manipulate-script.php b/tests/unit/Test_Manipulate_Script.php similarity index 97% rename from src/addons/tests/unit/test-manipulate-script.php rename to tests/unit/Test_Manipulate_Script.php index f0addf3f..148a33b7 100644 --- a/src/addons/tests/unit/test-manipulate-script.php +++ b/tests/unit/Test_Manipulate_Script.php @@ -1,16 +1,23 @@ + // phpcs:disable + $buffer = << @@ -288,7 +295,9 @@ function documentInitOneSignal() { -"; + +TEXT; + // phpcs:enable $keywords = array( 'onesignal' => 'statistics', @@ -297,30 +306,20 @@ function documentInitOneSignal() { $changed_header = cookiebot_addons_manipulate_script( $buffer, $keywords ); - $expected_replacements = array(); - - ob_start(); // first match - ?> - - - - +TEXT; + $expected_replacements[] = << +TEXT; + // phpcs:disable + $expected_replacements[] = << +TEXT; + // phpcs:enable + $expected_replacements[] = << +TEXT; foreach ( $expected_replacements as $expected_replacement ) { $this->assertNotFalse( strpos( $changed_header, $expected_replacement ) ); diff --git a/vendor/composer/autoload_psr4.php b/vendor/composer/autoload_psr4.php index 1abf67b0..6f30ad11 100644 --- a/vendor/composer/autoload_psr4.php +++ b/vendor/composer/autoload_psr4.php @@ -6,5 +6,6 @@ $baseDir = dirname($vendorDir); return array( + 'cybot\\cookiebot\\tests\\' => array($baseDir . '/tests'), 'cybot\\cookiebot\\' => array($baseDir . '/src'), ); diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index dabb81bd..cc96f04d 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -9,11 +9,16 @@ class ComposerStaticInitc34673f28de77716fffd4fc05531c6e9 public static $prefixLengthsPsr4 = array ( 'c' => array ( + 'cybot\\cookiebot\\tests\\' => 22, 'cybot\\cookiebot\\' => 16, ), ); public static $prefixDirsPsr4 = array ( + 'cybot\\cookiebot\\tests\\' => + array ( + 0 => __DIR__ . '/../..' . '/tests', + ), 'cybot\\cookiebot\\' => array ( 0 => __DIR__ . '/../..' . '/src',