diff --git a/.dev-lib b/.dev-lib deleted file mode 100644 index 6ab05421..00000000 --- a/.dev-lib +++ /dev/null @@ -1,10 +0,0 @@ -PROJECT_TYPE=theme -WPCS_STANDARD=phpcs.xml.dist -PATH_EXCLUDES_PATTERN='^(.*/)?(vendors|vendor|node_modules)/.*' -DEV_LIB_SKIP=yuicompressor,codeception,grunt,jshint - -# Run integration tests when the DEV_LIB_ONLY is set to phpunit -# This is the only flag we can use to change the config file -if [ 'phpunit' == "$DEV_LIB_ONLY" ]; then - PHPUNIT_CONFIG=tests/phpunit/integration/phpunit.xml.dist -fi diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index c951f002..00000000 --- a/.editorconfig +++ /dev/null @@ -1,21 +0,0 @@ -# This file is for unifying the coding style for different editors and IDEs -# editorconfig.org - -# WordPress Coding Standards -# https://make.wordpress.org/core/handbook/coding-standards/ - -root = true - -[*] -charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true -indent_style = tab - -[{.jshintrc,*.json,*.yml}] -indent_style = space -indent_size = 2 - -[{*.txt,wp-config-sample.php}] -end_of_line = crlf \ No newline at end of file diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 77324a07..00000000 --- a/.gitattributes +++ /dev/null @@ -1,11 +0,0 @@ -# Default behaviour -* text=auto - -# Text files -*.php eol=lf - -# Binary files -*.png binary -*.jpg binary -*.gif binary -*.ico binary diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9f650cdf..00000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: php -sudo: false - -cache: - directories: - node_modules - vendor - -php: - - 5.6 - - 7.2 - -env: - - WP_VERSION=latest WP_MULTISITE=0 - - WP_VERSION=latest WP_MULTISITE=1 - - WP_VERSION=trunk WP_MULTISITE=0 - - WP_VERSION=trunk WP_MULTISITE=1 - -install: - - composer install - - export DEV_LIB_PATH=vendor/xwp/wp-dev-lib - - source $DEV_LIB_PATH/travis.install.sh - -script: - - source bin/travis.sh - -after_script: - - source $DEV_LIB_PATH/travis.after_script.sh diff --git a/bin/install-pre-commit-hook.sh b/bin/install-pre-commit-hook.sh deleted file mode 100755 index d517cb30..00000000 --- a/bin/install-pre-commit-hook.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash -# Link pre-commit hook for a repo in the directory supplied as an argument, or the parent repo of this file. -# -# USAGES: -# $ /path/to/install-pre-commit-hook.sh -# $ /path/to/install-pre-commit-hook.sh wp-content/themes/my-theme - -set -e - -# Check if Perl is installed -command -v perl >/dev/null 2>&1 || { echo >&2 "Perl is not installed, and is required by this script. See how to install it on http://learn.perl.org/installing"; exit 1; } - -# Store the initial directory to return back to it later -OLDPWD=$(pwd) - -# Navigate to the script directory -cd "$(dirname $0)" - -# Get full path of the script directory -BINDIR=$(pwd) - -# Get back to the calling directory -cd - &> /dev/null - -# If passed a destination, switch to it to get the full path and then .git/hooks directory -if [ ! -z "$1" ]; then - cd $1 - DEST=$(pwd) -fi - -# Get the hooks directory of the current git repo -cd "$(git rev-parse --git-dir)/hooks" - -# Get relative path to the original file from within the hooks directory -RELPATH=$( perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV)' "$BINDIR/pre-commit" "$(pwd)" ) - -if [ -z "$RELPATH" ]; then - echo 'Could not determine the relative path, Sorry. Try symlinking the file manually.' - exit 1 -fi - -echo "## Placing pre-commit file in $(pwd) from $RELPATH" -ln -s "$RELPATH" . - -# Return back to the calling directory -cd "$OLDPWD" &> /dev/null diff --git a/bin/pre-commit b/bin/pre-commit deleted file mode 100755 index 0c7be46e..00000000 --- a/bin/pre-commit +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -DEV_LIB_HOOK_PATH='./vendor/xwp/wp-dev-lib/pre-commit' - -# Exit if the dev lib isn't installed -if [ ! -f $DEV_LIB_HOOK_PATH ]; then - echo "Oops, the Dev Library is not install, please run composer install!" -else - # Run sniffers and unit tests. - export PATH="./vendor/bin:$PATH" - export WP_TESTS_DIR='exclude' - $DEV_LIB_HOOK_PATH - - # Run integration tests. - export WP_TESTS_DIR='' - export DEV_LIB_ONLY=phpunit - $DEV_LIB_HOOK_PATH -fi diff --git a/bin/travis.sh b/bin/travis.sh deleted file mode 100644 index b7346ada..00000000 --- a/bin/travis.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -set -e - -export PATH="./vendor/bin:$PATH" - -# Exit if the dev lib isn't installed -if [ ! -f $DEV_LIB_TRAVIS_PATH ]; then - echo "Oops, the Dev Library is not install, please run composer install!" -else - echo "## Checking files, scope $CHECK_SCOPE:" - if [[ $CHECK_SCOPE != "all" ]]; then - cat "$TEMP_DIRECTORY/paths-scope" - fi - - # Run sniffers. - lint_js_files - lint_php_files - - # Run unit tests. - echo '## Running unit tests:' - phpunit --testsuite unit - - # Run integration tests. - echo '## Running integration tests:' - export PHPUNIT_CONFIG=tests/phpunit/integration/phpunit.xml.dist - run_phpunit_travisci -fi diff --git a/lib/api/utilities/functions.php b/lib/api/utilities/functions.php index 3a1644ea..ceacd96e 100644 --- a/lib/api/utilities/functions.php +++ b/lib/api/utilities/functions.php @@ -260,17 +260,24 @@ function beans_url_to_path( $url, $force_rebuild = false ) { $blogdetails = ''; } + // It's not an internal URL. Bail out. + if ( false === stripos( parse_url( $url, PHP_URL_HOST ), parse_url( $site_url, PHP_URL_HOST ) ) ) { + if ( false === stripos( $url, parse_url( site_url(), PHP_URL_SCHEME ) ) ) { + // If no url scheme found, it's local path instead of url. + // Also path is actually relative path instead of absolute. + // Add ./ in front of the relative url to make it relative path. + // After sanitize it will be converted to absolute path. + $url = beans_sanitize_path( './' . $url ); + } + return $url; + } + // Fix protocol. It isn't needed to set SSL as it is only used to parse the URL. if ( ! parse_url( $url, PHP_URL_SCHEME ) ) { $original_url = $url; $url = 'http://' . ltrim( $url, '/' ); } - // It's not an internal URL. Bail out. - if ( false === stripos( parse_url( $url, PHP_URL_HOST ), parse_url( $site_url, PHP_URL_HOST ) ) ) { - return isset( $original_url ) ? $original_url : $url; - } - // Parse url and standardize backslashes. $url = parse_url( $url, PHP_URL_PATH ); $path = wp_normalize_path( $url ); diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index fb049156..00000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,73 +0,0 @@ - - - The code standard for Beans. - - . - - - */dist/* - node_modules/* - */vendor/* - */vendors/* - - - - - - - - - - - - - - - */tests/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/phpunit.xml.dist b/phpunit.xml.dist deleted file mode 100644 index 8ba026d7..00000000 --- a/phpunit.xml.dist +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - ./tests/phpunit/unit/ - ./tests/phpunit/unit/*/*/fixtures/ - - - - - - . - ./tests/TestCase.php - - - diff --git a/tests/phpunit/class-beans-resetter.php b/tests/phpunit/class-beans-resetter.php deleted file mode 100644 index 3f189cbb..00000000 --- a/tests/phpunit/class-beans-resetter.php +++ /dev/null @@ -1,109 +0,0 @@ -reset_global_state(); - - // Reset APIs. - $this->reset_components(); - $this->reset_actions_api(); - $this->reset_compiler_api(); - $this->reset_fields_api(); - } - - /** - * Reset the global state. - */ - protected function reset_global_state() { - $_GET = []; - $_POST = []; - unset( $GLOBALS['current_screen'] ); - } - - /** - * Resets the Beans' API Components. - */ - protected function reset_components() { - - if ( ! function_exists( 'beans_get_component_support' ) ) { - return; - } - - global $_beans_api_components_support; - $_beans_api_components_support = []; - } - - /** - * Reset the Actions API. - */ - protected function reset_actions_api() { - global $_beans_registered_actions; - $_beans_registered_actions = [ - 'added' => [], - 'modified' => [], - 'removed' => [], - 'replaced' => [], - ]; - } - - /** - * Reset the Compiler API. - */ - protected function reset_compiler_api() { - global $_beans_compiler_added_fragments; - $_beans_compiler_added_fragments = [ - 'css' => [], - 'less' => [], - 'js' => [], - ]; - - unset( $GLOBALS['wp_filesystem'] ); - } - - /** - * Reset the Fields API. - */ - protected function reset_fields_api() { - - if ( ! class_exists( '_Beans_Fields' ) ) { - return; - } - - // Reset the "registered" container. - $registered = $this->get_reflective_property( 'registered', '_Beans_Fields' ); - $registered->setValue( new _Beans_Fields(), [ - 'option' => [], - 'post_meta' => [], - 'term_meta' => [], - 'wp_customize' => [], - ] ); - - // Reset the other static properties. - foreach ( [ 'field_types_loaded', 'field_assets_hook_loaded' ] as $property_name ) { - $property = $this->get_reflective_property( $property_name, '_Beans_Fields' ); - $property->setValue( new _Beans_Fields(), [] ); - } - } -} diff --git a/tests/phpunit/functions.php b/tests/phpunit/functions.php deleted file mode 100644 index f7a839cf..00000000 --- a/tests/phpunit/functions.php +++ /dev/null @@ -1,99 +0,0 @@ -reset(); -} - -/** - * Gets the Bean's Resetter. - * - * @since 1.5.0 - * - * @return Beans_Resetter - */ -function get_beans_resetter() { - static $resetter; - - if ( is_null( $resetter ) ) { - require_once __DIR__ . '/class-beans-resetter.php'; - $resetter = new Beans_Resetter(); - } - - return $resetter; -} diff --git a/tests/phpunit/integration/api/actions/beansAddAction.php b/tests/phpunit/integration/api/actions/beansAddAction.php deleted file mode 100644 index 86ffda41..00000000 --- a/tests/phpunit/integration/api/actions/beansAddAction.php +++ /dev/null @@ -1,145 +0,0 @@ - $action ) { - // Test that the action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - - // Let's add it. - $this->assertTrue( beans_add_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ) ); - - // Now check that it was registered in Beans and WordPress. - $this->assertEquals( $action, _beans_get_action( $beans_id, 'added' ) ); - $this->check_registered_in_wp( $action['hook'], $action ); - } - } - - /** - * Test beans_add_action() should overwrite the action in both Beans and WordPress. - * - * This test makes sure nothing breaks if beans_add_action() is called more than once - * with the exact same set of conditions. - */ - public function test_should_overwrite_add_action_in_beans_and_wordpress() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Let's add it the first time. - $this->assertTrue( beans_add_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ) ); - - // Add it again. - $this->assertTrue( beans_add_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ) ); - - // Now check that it's still registered in both Beans and WordPress. - $this->assertEquals( $action, _beans_get_action( $beans_id, 'added' ) ); - $this->check_registered_in_wp( $action['hook'], $action ); - } - } - - /** - * Test beans_add_action() should use the action configuration in "replaced" status, when it's available. - */ - public function test_should_use_replaced_action_when_available() { - $replaced_action = [ - 'callback' => 'my_new_callback', - 'priority' => 47, - ]; - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // We want to store the "replaced" action first, before we add the original action. - _beans_set_action( $beans_id, $replaced_action, 'replaced', true ); - - // Next, add the original action. - beans_add_action( $beans_id, $original_action['hook'], $original_action['callback'], $original_action['priority'], $original_action['args'] ); - - // Get the newly created action. - $new_action = _beans_get_action( $beans_id, 'added' ); - - // Check if the callback and priority were replaced. - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $replaced_action['callback'], $new_action['callback'] ); - $this->assertEquals( $replaced_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Now check that the action was replaced in WordPress. - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } - - /** - * Test beans_add_action() should return false when the ID is registered to the "removed" status. - */ - public function test_should_return_false_when_removed() { - $empty_action = [ - 'hook' => null, - 'callback' => null, - 'priority' => null, - 'args' => null, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the "removed" action before we call beans_add_action(). - _beans_set_action( $beans_id, $empty_action, 'removed', true ); - - // Next, add the action. - beans_add_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ); - - // Check if the action is stored as "added". - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - - // Check that the action is not registered in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_add_action() should merge the "modified" action configuration parameters. - */ - public function test_should_merge_modified_action_parameters() { - $modified_action = [ - 'callback' => 'foo', - 'priority' => 17, - ]; - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // We want to store the "modified" action first, before we add the original action. - _beans_set_action( $beans_id, $modified_action, 'modified', true ); - - // Next, add the original action. - beans_add_action( $beans_id, $original_action['hook'], $original_action['callback'], $original_action['priority'], $original_action['args'] ); - - // Test that the original action is stored away, which allows us to reset it (if we want). - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Now check that the action was modified in WordPress. - $new_action = array_merge( $original_action, $modified_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansAddAnonymousAction.php b/tests/phpunit/integration/api/actions/beansAddAnonymousAction.php deleted file mode 100644 index 43f86d83..00000000 --- a/tests/phpunit/integration/api/actions/beansAddAnonymousAction.php +++ /dev/null @@ -1,46 +0,0 @@ -assertTrue( has_action( 'do_foo' ) ); - } - - /** - * Test _beans_add_anonymous_action() should call callback on the given hook. - */ - public function test_should_call_callback() { - _beans_add_anonymous_action( 'beans_test_do_foo', [ 'foo_test_callback', [ 'foo' ] ] ); - - Functions\when( 'foo_test_callback' ) - ->justReturn( 'foo' ); - - ob_start(); - do_action( 'beans_test_do_foo' ); - $this->assertEquals( 'foo', ob_get_clean() ); - } -} diff --git a/tests/phpunit/integration/api/actions/beansGetAction.php b/tests/phpunit/integration/api/actions/beansGetAction.php deleted file mode 100644 index 91e42196..00000000 --- a/tests/phpunit/integration/api/actions/beansGetAction.php +++ /dev/null @@ -1,127 +0,0 @@ -assertEmpty( $_beans_registered_actions[ $status ] ); - $this->assertFalse( _beans_get_action( 'foo', $status ) ); - } - } - - /** - * Test _beans_get_action() should return false when the action is not registered. - */ - public function test_should_return_false_when_action_is_not_registered() { - - foreach ( static::$test_ids as $beans_id ) { - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'removed' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'replaced' ) ); - } - } - - /** - * Test _beans_get_action() should return the "added" action. - */ - public function test_should_return_added_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['added'][ $beans_id ] = $action; - - // Test that we get the "added" action. - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - - // Make sure that it is not stored in the other registries. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'removed' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'replaced' ) ); - } - } - - /** - * Test _beans_get_action() should return the "modified" action. - */ - public function test_should_return_modified_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['modified'][ $beans_id ] = $action; - - // Test that we get the "modified" action. - $this->assertSame( $action, _beans_get_action( $beans_id, 'modified' ) ); - - // Make sure that it is not stored in the other registries. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'removed' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'replaced' ) ); - } - } - - /** - * Test _beans_get_action() should return the "removed" action. - */ - public function test_should_return_removed_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['removed'][ $beans_id ] = $action; - - // Test that we get the "removed" action. - $this->assertSame( $action, _beans_get_action( $beans_id, 'removed' ) ); - - // Make sure that it is not stored in the other registries. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'replaced' ) ); - } - } - - /** - * Test _beans_get_action() should return the "replaced" action. - */ - public function test_should_return_replaced_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['replaced'][ $beans_id ] = $action; - - // Test that we get the "replaced" action. - $this->assertSame( $action, _beans_get_action( $beans_id, 'replaced' ) ); - - // Make sure that it is not stored in the other registries. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'removed' ) ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansGetCurrentAction.php b/tests/phpunit/integration/api/actions/beansGetCurrentAction.php deleted file mode 100644 index eec30ff8..00000000 --- a/tests/phpunit/integration/api/actions/beansGetCurrentAction.php +++ /dev/null @@ -1,96 +0,0 @@ - $action ) { - // Store the action in the registry. - $_beans_registered_actions['removed'][ $beans_id ] = $action; - - // Test that it returns false. - $this->assertFalse( _beans_get_current_action( $beans_id ) ); - } - } - - /** - * Test _beans_get_current_action() should return the "added" action. - */ - public function test_should_return_added_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['added'][ $beans_id ] = $action; - - // Test that we get the "added" action. - $this->assertSame( $action, _beans_get_current_action( $beans_id ) ); - } - } - - /** - * Test _beans_get_current_action() should return false when there's a "modified" action but no "added" action. - */ - public function test_should_return_false_when_modified_but_no_added_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['modified'][ $beans_id ] = $action; - - // Run the tests. - $this->assertFalse( _beans_get_current_action( $beans_id ) ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['added'] ); - $this->assertSame( $action, $_beans_registered_actions['modified'][ $beans_id ] ); - } - } - - /** - * Test _beans_get_current_action() should return the merged "added" and "modified" action. - */ - public function test_should_return_merged_added_and_modified_action() { - global $_beans_registered_actions; - - $modified_action = [ - 'callback' => 'callback', - 'priority' => 27, - 'args' => 14, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Store the action in the registry. - $_beans_registered_actions['added'][ $beans_id ] = $action; - $_beans_registered_actions['modified'][ $beans_id ] = $modified_action; - - // Test that it merges the action. - $this->assertSame( - array_merge( $action, $modified_action ), - _beans_get_current_action( $beans_id ) - ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansMergeAction.php b/tests/phpunit/integration/api/actions/beansMergeAction.php deleted file mode 100644 index bb4330a9..00000000 --- a/tests/phpunit/integration/api/actions/beansMergeAction.php +++ /dev/null @@ -1,68 +0,0 @@ - 29, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - $merged_action = array_merge( $action, $modified_action ); - - // Test each status. - foreach ( $this->statuses as $status ) { - $_beans_registered_actions[ $status ][ $beans_id ] = $action; - $this->assertSame( $merged_action, _beans_merge_action( $beans_id, $modified_action, $status ) ); - } - } - } - - /** - * Test _beans_merge_action() should store an unregistered action. - */ - public function test_should_store_new_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - $this->assertSame( $action, _beans_merge_action( $beans_id, $action, $status ) ); - $this->assertSame( $action, $_beans_registered_actions[ $status ][ $beans_id ] ); - } - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansModifyAction.php b/tests/phpunit/integration/api/actions/beansModifyAction.php deleted file mode 100644 index 18d844e8..00000000 --- a/tests/phpunit/integration/api/actions/beansModifyAction.php +++ /dev/null @@ -1,204 +0,0 @@ -go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that it returns false. - $this->assertFalse( beans_modify_action( $beans_id ) ); - - // Verify that the action was not stored as "modified". - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action was not replaced. - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_modify_action() should register with Beans as "modified", but not add the action. - */ - public function test_should_register_as_modified_but_not_add_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check the starting state. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that it returns false. - $this->assertFalse( beans_modify_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ) ); - - // Check that it did register as "modified" in Beans. - $this->assertEquals( $action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action was not added in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_modify_action() should modify the registered action's hook. - */ - public function test_should_modify_the_action_hook() { - $modified_action = [ - 'hook' => 'foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Modify the action's hook. - $this->assertTrue( beans_modify_action( $beans_id, $modified_action['hook'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - - // Check that the modified action was added in WordPress. - $this->assertTrue( has_action( $modified_action['hook'], $original_action['callback'] ) !== false ); - } - } - - /** - * Test beans_modify_action() should modify the registered action's callback. - */ - public function test_should_modify_the_action_callback() { - $modified_action = [ - 'callback' => 'my_callback', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Modify the action's callback. - $this->assertTrue( beans_modify_action( $beans_id, null, $modified_action['callback'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - - // Check that the modified action was added in WordPress. - $this->assertTrue( has_action( $original_action['hook'], $modified_action['callback'] ) !== false ); - } - } - - /** - * Test beans_modify_action() should modify the registered action's priority level. - */ - public function test_should_modify_the_action_priority() { - global $wp_filter; - - $modified_action = [ - 'priority' => 20, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ] - ); - - // Modify the action's priority. - $this->assertTrue( beans_modify_action( $beans_id, null, null, $modified_action['priority'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $callbacks_in_wp = $wp_filter[ $original_action['hook'] ]->callbacks; - if ( isset( $callbacks_in_wp[ $original_action['priority'] ] ) ) { - $this->assertArrayNotHasKey( $original_action['callback'], $callbacks_in_wp[ $original_action['priority'] ] ); - } else { - $this->assertArrayNotHasKey( $original_action['priority'], $callbacks_in_wp ); - } - - // Check that the action's priority was modified in WordPress. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $callbacks_in_wp[ $modified_action['priority'] ][ $original_action['callback'] ] - ); - } - } - - /** - * Test beans_modify_action() should modify the registered action's number of arguments. - */ - public function test_should_modify_the_action_args() { - global $wp_filter; - - $modified_action = [ - 'args' => 7, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - $original_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - - // Modify the action's number of arguments. - $this->assertTrue( beans_modify_action( $beans_id, null, null, null, $modified_action['args'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action's number of arguments was modified in WordPress. - $this->assertEquals( - $modified_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansModifyActionArguments.php b/tests/phpunit/integration/api/actions/beansModifyActionArguments.php deleted file mode 100644 index 0676f24c..00000000 --- a/tests/phpunit/integration/api/actions/beansModifyActionArguments.php +++ /dev/null @@ -1,149 +0,0 @@ -go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - $original_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - - foreach ( $arguments as $number_of_args ) { - // Check that it returns false. - $this->assertFalse( beans_modify_action_arguments( $beans_id, $number_of_args ) ); - - // Check that the modification was not stored in Beans. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the number of arguments did not change in WordPress. - $this->assertEquals( - $original_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - } - } - } - - /** - * Test beans_modify_action_arguments() should modify the action's "args" when the new one is zero. - */ - public function test_should_modify_action_when_args_is_zero() { - global $wp_filter; - - $arguments = [ 0, 0.0, '0', '0.0' ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - $original_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - - foreach ( $arguments as $number_of_args ) { - // Modify the action's callback. - $this->assertTrue( beans_modify_action_arguments( $beans_id, $number_of_args ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( [ 'args' => (int) $number_of_args ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action's number of arguments was modified in WordPress. - $this->assertEquals( - $number_of_args, - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - } - } - } - - /** - * Test beans_modify_action_arguments() should register with Beans as "modified", but not add the action. - */ - public function test_should_register_as_modified_but_not_add_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check the starting state. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that it returns false. - $this->assertFalse( beans_modify_action_arguments( $beans_id, $action['args'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( [ 'args' => $action['args'] ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action was not added in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_modify_action_arguments() should modify the registered action's number of arguments. - */ - public function test_should_modify_the_action_args() { - global $wp_filter; - - $modified_action = [ - 'args' => 7, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Test the action before we start. - $this->assertEquals( - $original_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - - // Modify the action's number of arguments. - $this->assertTrue( beans_modify_action_arguments( $beans_id, $modified_action['args'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action's number of arguments was modified in WordPress. - $this->assertEquals( - $modified_action['args'], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ]['accepted_args'] - ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansModifyActionCallback.php b/tests/phpunit/integration/api/actions/beansModifyActionCallback.php deleted file mode 100644 index 137cdf40..00000000 --- a/tests/phpunit/integration/api/actions/beansModifyActionCallback.php +++ /dev/null @@ -1,103 +0,0 @@ -go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertTrue( has_action( $original_action['hook'], $original_action['callback'] ) !== false ); - - foreach ( $callbacks as $callback ) { - // Check that it returns false. - $this->assertFalse( beans_modify_action_callback( $beans_id, $callback ) ); - - // Check that the callback did not get stored as "modified" in Beans. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the callback did not change in WordPress. - $this->assertTrue( has_action( $original_action['hook'], $original_action['callback'] ) !== false ); - } - } - } - - /** - * Test beans_modify_action_callback() should register with Beans as "modified", but not add the action. - */ - public function test_should_register_as_modified_but_not_add_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check the starting state. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that it returns false. - $this->assertFalse( beans_modify_action_callback( $beans_id, $action['callback'] ) ); - - // Check that it did register as "modified" in Beans. - $this->assertEquals( [ 'callback' => $action['callback'] ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action was not added in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_modify_action_callback() should modify the registered action's callback. - */ - public function test_should_modify_the_action_callback() { - $modified_action = [ - 'callback' => 'my_callback', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Modify the callback. - $this->assertTrue( beans_modify_action_callback( $beans_id, $modified_action['callback'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - - // Check that the modified action was added in WordPress. - $this->assertTrue( has_action( $original_action['hook'], $modified_action['callback'] ) !== false ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansModifyActionHook.php b/tests/phpunit/integration/api/actions/beansModifyActionHook.php deleted file mode 100644 index 45a691a8..00000000 --- a/tests/phpunit/integration/api/actions/beansModifyActionHook.php +++ /dev/null @@ -1,107 +0,0 @@ -go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertTrue( has_action( $original_action['hook'], $original_action['callback'] ) !== false ); - - foreach ( $hooks as $hook ) { - // Check that it returns false. - $this->assertFalse( beans_modify_action_hook( $beans_id, $hook ) ); - - // Check that the hook did not get stored as "modified" in Beans. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the hook did not change in WordPress. - $this->assertTrue( has_action( $original_action['hook'], $original_action['callback'] ) !== false ); - } - } - } - - /** - * Test beans_modify_action_hook() should register with Beans as "modified", but not add the action. - */ - public function test_should_register_as_modified_but_not_add_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check the starting state. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that it returns false. - $this->assertFalse( beans_modify_action_hook( $beans_id, $action['hook'] ) ); - - // Check that it did register as "modified" in Beans. - $this->assertEquals( [ 'hook' => $action['hook'] ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action was not added in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_modify_action_hook() should modify the registered action's hook. - */ - public function test_should_modify_the_action_hook() { - $modified_action = [ - 'hook' => 'foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Modify the action's hook. - $this->assertTrue( beans_modify_action_hook( $beans_id, $modified_action['hook'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - - // Check that the modified action was added in WordPress. - $this->assertTrue( has_action( $modified_action['hook'], $original_action['callback'] ) !== false ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansModifyActionPriority.php b/tests/phpunit/integration/api/actions/beansModifyActionPriority.php deleted file mode 100644 index 334219cd..00000000 --- a/tests/phpunit/integration/api/actions/beansModifyActionPriority.php +++ /dev/null @@ -1,187 +0,0 @@ -go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ] - ); - - foreach ( $priorities as $priority ) { - // Check that it returns false. - $this->assertFalse( beans_modify_action_priority( $beans_id, $priority ) ); - - // Check that the priority did not get stored as "modified" in Beans. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the priority did not change in WordPress. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ] - ); - } - } - } - - /** - * Test beans_modify_action_priority() should modify the action's priority when the new one is zero. - */ - public function test_should_modify_action_when_priority_is_zero() { - global $wp_filter; - - $priorities = [ 0, 0.0, '0', '0.0' ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ] - ); - - foreach ( $priorities as $priority ) { - // Modify the priority. - $this->assertTrue( beans_modify_action_priority( $beans_id, $priority ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( [ 'priority' => (int) $priority ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the priority did change in WordPress. - $this->check_modified_in_wp( $original_action, (int) $priority ); - } - } - } - - /** - * Test beans_modify_action_priority() should register with Beans as "modified", but not add the action. - */ - public function test_should_register_as_modified_but_not_add_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check the starting state. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - - // Check that it returns false. - $this->assertFalse( beans_modify_action_priority( $beans_id, $action['priority'] ) ); - - // Check that it did register as "modified" in Beans. - $this->assertEquals( [ 'priority' => $action['priority'] ], _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the action was not added in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_modify_action_priority() should modify the registered action's priority level. - */ - public function test_should_modify_the_action_priority() { - global $wp_filter; - - $modified_action = [ - 'priority' => 20, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check the starting state. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $wp_filter[ $original_action['hook'] ]->callbacks[ $original_action['priority'] ][ $original_action['callback'] ] - ); - - // Modify the action's priority. - $this->assertTrue( beans_modify_action_priority( $beans_id, $modified_action['priority'] ) ); - - // Check that the modified action is registered as "modified" in Beans. - $this->assertEquals( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the priority did change in WordPress. - $this->check_modified_in_wp( $original_action, $modified_action['priority'] ); - } - } - - /** - * Check that the priority was modified in WordPress. - * - * @since 1.5.0 - * - * @param array $original_action The original action. - * @param int $new_priority The new priority. - * - * @return void - */ - protected function check_modified_in_wp( $original_action, $new_priority ) { - global $wp_filter; - - $callbacks_in_wp = $wp_filter[ $original_action['hook'] ]->callbacks; - - // Check that the original action was removed from WordPress. - if ( isset( $callbacks_in_wp[ $original_action['priority'] ] ) ) { - $this->assertArrayNotHasKey( $original_action['callback'], $callbacks_in_wp[ $original_action['priority'] ] ); - } else { - $this->assertArrayNotHasKey( $original_action['priority'], $callbacks_in_wp ); - } - - // Check that the action's priority was modified in WordPress. - $this->assertEquals( - [ - 'function' => $original_action['callback'], - 'accepted_args' => $original_action['args'], - ], - $callbacks_in_wp[ $new_priority ][ $original_action['callback'] ] - ); - } -} diff --git a/tests/phpunit/integration/api/actions/beansRemoveAction.php b/tests/phpunit/integration/api/actions/beansRemoveAction.php deleted file mode 100644 index 1f7ba3cb..00000000 --- a/tests/phpunit/integration/api/actions/beansRemoveAction.php +++ /dev/null @@ -1,103 +0,0 @@ - null, - 'callback' => null, - 'priority' => null, - 'args' => null, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - $this->assertFalse( _beans_get_current_action( $beans_id ) ); - - // Remove the action. Test that an empty action is returned. - $this->assertSame( $empty_action, beans_remove_action( $beans_id ) ); - - // Check that the "empty" action is registered as "removed". - $this->assertSame( $empty_action, _beans_get_action( $beans_id, 'removed' ) ); - - // Check that the original action is not registered in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_remove_action() should store the "removed" action before the original action is "added". - * Once the original action is registered, then it should be removed. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_remove_action() { - - // Remove the actions. - foreach ( static::$test_actions as $beans_id => $action ) { - beans_remove_action( $beans_id ); - } - - // Load the post, which runs beans_add_action for each of our test actions. - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check that the action is registered as "added". - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - - // Check that the action is not registered in WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } - - /** - * Test beans_remove_action() should remove a registered action. - */ - public function test_should_remove_a_registered_action() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Check that the action is registered with Beans. - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - - // Check that the action is registered with WordPress. - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Remove it. - $this->assertSame( $action, beans_remove_action( $beans_id ) ); - - // Check that the action is registered as "removed". - $this->assertSame( $action, _beans_get_action( $beans_id, 'removed' ) ); - - // Check that the action is no longer registered with WordPress. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansReplaceAction.php b/tests/phpunit/integration/api/actions/beansReplaceAction.php deleted file mode 100644 index 9c15f413..00000000 --- a/tests/phpunit/integration/api/actions/beansReplaceAction.php +++ /dev/null @@ -1,265 +0,0 @@ - $replaced_callback ]; - - foreach ( static::$test_ids as $beans_id ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - - // Now store away the "replace" hook. - $this->assertFalse( beans_replace_action( $beans_id, null, $replaced_callback ) ); - - // Check that it was stored as "replaced". - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'replaced' ) ); - - // Check that it did not store as "added". - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action() should store the "replaced" action when the original action - * has not yet been registered. Once the original action is registered, then it should be replaced. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_replace_action() { - $replaced_callback = 'my_replaced_callback'; - $replaced_action = [ 'callback' => $replaced_callback ]; - - // Store the "replaced" action. - foreach ( static::$test_ids as $beans_id ) { - beans_replace_action( $beans_id, null, $replaced_callback ); - } - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action's callback was replaced in Beans. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $replaced_callback, $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action() should return false when there's nothing to replace, - * i.e. no arguments passed. - */ - public function test_should_return_false_when_nothing_to_replace() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check it returns false. - $this->assertFalse( beans_replace_action( $beans_id ) ); - - // Verify that it did not get stored in "replaced" or "modified". - global $_beans_registered_actions; - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['replaced'] ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action has not been replaced. - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action() should replace the registered action's hook. - */ - public function test_should_replace_the_action_hook() { - $replaced_action = [ - 'hook' => 'foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Run the replace. - $this->assertTrue( beans_replace_action( $beans_id, $replaced_action['hook'] ) ); - - // Check that only the hook was replaced. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $replaced_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action() should replace the registered action's callback. - */ - public function test_should_replace_the_action_callback() { - $replaced_action = [ - 'callback' => 'foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Run the replace. - $this->assertTrue( beans_replace_action( $beans_id, null, $replaced_action['callback'] ) ); - - // Check that only the callback was replaced. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $replaced_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action() should replace the registered action's priority level. - */ - public function test_should_replace_the_action_priority() { - $replaced_action = [ - 'priority' => 52, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Run the replace. - $this->assertTrue( beans_replace_action( $beans_id, null, null, $replaced_action['priority'] ) ); - - // Check that only the priority was replaced. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $replaced_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action() should replace the registered action's number of arguments. - */ - public function test_should_replace_the_action_args() { - $replaced_action = [ - 'args' => 6, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Run the replace. - $this->assertTrue( beans_replace_action( $beans_id, null, null, null, $replaced_action['args'] ) ); - - // Check that only the number of arguments was replaced. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $replaced_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action() should replace the original registered action. - */ - public function test_should_replace_the_action() { - $replaced_action = [ - 'hook' => 'new_hook', - 'callback' => 'new_callback', - 'priority' => 99, - 'args' => 10, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check that the original action is registered in WordPress and in Beans as "added". - $this->check_registered_in_wp( $original_action['hook'], $original_action ); - $this->assertSame( $original_action, _beans_get_action( $beans_id, 'added' ) ); - - // Run the replace. - $this->assertTrue( beans_replace_action( - $beans_id, - $replaced_action['hook'], - $replaced_action['callback'], - $replaced_action['priority'], - $replaced_action['args'] - ) ); - - // Check that the "replaced" action has been stored in Beans. - $this->assertSame( $replaced_action, _beans_get_action( $beans_id, 'added' ) ); - $this->assertSame( $replaced_action, _beans_get_action( $beans_id, 'replaced' ) ); - $this->assertSame( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - - // Check that the original action was removed from WordPress. - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - - // Check that the new action is now registered in WordPress. - $this->check_registered_in_wp( $replaced_action['hook'], $replaced_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansReplaceActionArguments.php b/tests/phpunit/integration/api/actions/beansReplaceActionArguments.php deleted file mode 100644 index 9241ec27..00000000 --- a/tests/phpunit/integration/api/actions/beansReplaceActionArguments.php +++ /dev/null @@ -1,131 +0,0 @@ - 10, - ]; - - // Store the "replaced" action. - foreach ( static::$test_ids as $beans_id ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - - // Now store away the "replace" args. - $this->assertFalse( beans_replace_action_arguments( $beans_id, $replaced_action['args'] ) ); - - // Check that it was stored as "modified". - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - } - } - - /** - * Test beans_replace_action_arguments() should store the "replaced" action when the original action - * has not yet been registered. Once the original action is registered, then the arguments should be replaced. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_replace_the_args() { - $replaced_action = [ - 'args' => 10, - ]; - - // Now replace the actions. - foreach ( static::$test_ids as $beans_id ) { - beans_replace_action_arguments( $beans_id, $replaced_action['args'] ); - } - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check if it replaced the args. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $replaced_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action_arguments() should return false when "args" is not passed. - */ - public function test_should_return_false_when_no_args() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $this->assertFalse( beans_replace_action_arguments( $beans_id, '' ) ); - - // Verify that it did not get stored in "replaced" or "modified". - global $_beans_registered_actions; - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['replaced'] ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action has not been replaced. - $this->assertSame( $action_config, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action_arguments() should replace the registered action's args. - */ - public function test_should_replace_the_action_args() { - $replaced_action = [ - 'args' => 14, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $original_action = _beans_get_action( $beans_id, 'added' ); - - // Make sure the args is what we think before we get rolling. - $this->assertEquals( $action_config['args'], $original_action['args'] ); - - // Run the replace. - $this->assertTrue( beans_replace_action_arguments( $beans_id, $replaced_action['args'] ) ); - - // Check if it replaced only the args. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $replaced_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansReplaceActionCallback.php b/tests/phpunit/integration/api/actions/beansReplaceActionCallback.php deleted file mode 100644 index 3610c0ab..00000000 --- a/tests/phpunit/integration/api/actions/beansReplaceActionCallback.php +++ /dev/null @@ -1,130 +0,0 @@ - 'my_new_callback', - ]; - - foreach ( static::$test_ids as $beans_id ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - - // Now store away the "replace" callback. - $this->assertFalse( beans_replace_action_callback( $beans_id, $replaced_action['callback'] ) ); - - // Check that it was stored as "modified". - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - } - } - - /** - * Test beans_replace_action_callback() should store the "replaced" action when the original action - * has not yet been registered. Once the original action is registered, then the callback should be replaced. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_replace_the_callback() { - $replaced_action = [ - 'callback' => 'foo', - ]; - - // Now replace the actions. - foreach ( static::$test_ids as $beans_id ) { - beans_replace_action_callback( $beans_id, $replaced_action['callback'] ); - } - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check if it replaced the hook. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $replaced_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action_callback() should return false when no hook was passed. - */ - public function test_should_return_false_when_no_hook() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $this->assertFalse( beans_replace_action_callback( $beans_id, '' ) ); - - // Verify that it did not get stored in "replaced" or "modified". - global $_beans_registered_actions; - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['replaced'] ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action has not been replaced. - $this->assertSame( $action_config, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action_callback() should replace the registered action's callback. - */ - public function test_should_replace_the_action_callback() { - $replaced_action = [ - 'callback' => 'beans_foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $original_action = _beans_get_action( $beans_id, 'added' ); - - // Make sure the callback is what we think before we get rolling. - $this->assertEquals( $action_config['callback'], $original_action['callback'] ); - - // Run the replace. - $this->assertTrue( beans_replace_action_callback( $beans_id, $replaced_action['callback'] ) ); - - // Check if it replaced only the callback. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $replaced_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansReplaceActionHook.php b/tests/phpunit/integration/api/actions/beansReplaceActionHook.php deleted file mode 100644 index 51431c24..00000000 --- a/tests/phpunit/integration/api/actions/beansReplaceActionHook.php +++ /dev/null @@ -1,132 +0,0 @@ - 'my_new_hook', - ]; - - foreach ( static::$test_ids as $beans_id ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - - // Now store away the "replace" hook. - $this->assertFalse( beans_replace_action_hook( $beans_id, $replaced_action['hook'] ) ); - - // Check that it was stored as "modified". - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - } - } - - /** - * Test beans_replace_action_hook() should store the "replaced" action when the original action - * has not yet been registered. Once the original action is registered, then the hook should be replaced. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_replace_the_hook() { - $replaced_action = [ - 'hook' => 'foo', - ]; - - // Now replace the actions. - foreach ( static::$test_ids as $beans_id ) { - beans_replace_action_hook( $beans_id, $replaced_action['hook'] ); - } - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check if it replaced the hook. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $replaced_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->assertFalse( has_action( $original_action['hook'], $original_action['callback'] ) ); - $this->check_registered_in_wp( $replaced_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action_hook() should return false when no hook was passed. - */ - public function test_should_return_false_when_no_hook() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $this->assertFalse( beans_replace_action_hook( $beans_id, '' ) ); - - // Verify that it did not get stored in "replaced" or "modified". - global $_beans_registered_actions; - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['replaced'] ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action has not been replaced. - $this->assertSame( $action_config, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action_hook() should replace the registered action's hook. - */ - public function test_should_replace_the_action_hook() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $original_action = _beans_get_action( $beans_id, 'added' ); - - // Make sure the callback is what we think before we get rolling. - $this->assertEquals( $action_config['hook'], $original_action['hook'] ); - - // Set up what will get stored in Beans. - $replaced_action = [ - 'hook' => 'beans_foo', - ]; - - // Run the replace. - $this->assertTrue( beans_replace_action_hook( $beans_id, $replaced_action['hook'] ) ); - - // Check if it replaced only the hook. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $replaced_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $original_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansReplaceActionPriority.php b/tests/phpunit/integration/api/actions/beansReplaceActionPriority.php deleted file mode 100644 index 0e10b3f6..00000000 --- a/tests/phpunit/integration/api/actions/beansReplaceActionPriority.php +++ /dev/null @@ -1,130 +0,0 @@ - 99, - ]; - - foreach ( static::$test_ids as $beans_id ) { - // Test that the original action has not yet been added. - $this->assertFalse( _beans_get_action( $beans_id, 'added' ) ); - - // Now store away the "replace" priority. - $this->assertFalse( beans_replace_action_priority( $beans_id, $replaced_action['priority'] ) ); - - // Check that it was stored as "modified". - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - } - } - - /** - * Test beans_replace_action_priority() should store the "replaced" action when the original action - * has not yet been registered. Once the original action is registered, then the priority should be replaced. - * - * Intent: We are testing to ensure Beans is "load order" agnostic. - */ - public function test_should_store_and_then_replace_the_priority() { - $replaced_action = [ - 'priority' => 10000, - ]; - - // Now replace the actions. - foreach ( static::$test_ids as $beans_id ) { - beans_replace_action_priority( $beans_id, $replaced_action['priority'] ); - } - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $original_action ) { - // Check if it replaced the hook. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $replaced_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $original_action['hook'], $new_action ); - } - } - - /** - * Test beans_replace_action_priority() should return false when no priority is passed. - */ - public function test_should_return_false_when_no_hook() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $this->assertFalse( beans_replace_action_priority( $beans_id, '' ) ); - - // Verify that it did not get stored in "replaced" or "modified". - global $_beans_registered_actions; - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['replaced'] ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions['modified'] ); - - // Check that the original action has not been replaced. - $this->assertSame( $action_config, _beans_get_action( $beans_id, 'added' ) ); - } - } - - /** - * Test beans_replace_action_priority() should replace the registered action's priority. - */ - public function test_should_replace_the_action_priority() { - $replaced_action = [ - 'priority' => 999, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action_config ) { - $original_action = _beans_get_action( $beans_id, 'added' ); - - // Make sure the priority is what we think before we get rolling. - $this->assertEquals( $action_config['priority'], $original_action['priority'] ); - - // Run the replace. - $this->assertTrue( beans_replace_action_priority( $beans_id, $replaced_action['priority'] ) ); - - // Check if it replaced only the priority. - $new_action = _beans_get_action( $beans_id, 'added' ); - $this->assertEquals( $original_action['hook'], $new_action['hook'] ); - $this->assertEquals( $original_action['callback'], $new_action['callback'] ); - $this->assertEquals( $replaced_action['priority'], $new_action['priority'] ); - $this->assertEquals( $original_action['args'], $new_action['args'] ); - - // Check that the "replaced" action has been stored in Beans and WordPress. - $this->check_stored_in_beans( $beans_id, $replaced_action ); - $this->check_registered_in_wp( $new_action['hook'], $new_action ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansResetAction.php b/tests/phpunit/integration/api/actions/beansResetAction.php deleted file mode 100644 index 6f014de5..00000000 --- a/tests/phpunit/integration/api/actions/beansResetAction.php +++ /dev/null @@ -1,513 +0,0 @@ - $action ) { - $this->assertFalse( beans_reset_action( $beans_id ) ); - } - } - - /** - * Test beans_reset_action() should reset the original action after it was "removed" via beans_remove_action(). - */ - public function test_should_reset_after_remove() { - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Remove it. - beans_remove_action( $beans_id ); - - // Check that the action did get removed. - $this->assertSame( $action, _beans_get_action( $beans_id, 'removed' ) ); - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'removed' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's hook after it was "modified". - */ - public function test_should_reset_after_modifying_the_hook() { - $modified_action = [ - 'hook' => 'foo', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Now modify the hook. - beans_modify_action_hook( $beans_id, $modified_action['hook'] ); - - // Check that the hook was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertTrue( has_action( $modified_action['hook'], $action['callback'] ) !== false ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's callback after it was "modified". - */ - public function test_should_reset_after_modifying_the_callback() { - global $wp_filter; - - $modified_action = [ - 'callback' => 'my_callback', - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Grab what's registered in WordPress. - $action_in_wp = $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ]; - - // Modify the callback. - beans_modify_action_callback( $beans_id, $modified_action['callback'] ); - - // Check that the action's callback was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( $action['callback'], $action_in_wp[ $action['callback'] ]['function'] ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's priority after it was "modified". - */ - public function test_should_reset_after_modifying_the_priority() { - global $wp_filter; - - $modified_action = [ - 'priority' => 9999, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, do a hard check to ensure the original priority is registered. - $this->assertEquals( - $action['callback'], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ]['function'] - ); - - // Modify the priority. - beans_modify_action_priority( $beans_id, $modified_action['priority'] ); - - // Check that the priority was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( - $action['callback'], - $wp_filter[ $action['hook'] ]->callbacks[ $modified_action['priority'] ][ $action['callback'] ]['function'] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's args after it was "modified". - */ - public function test_should_reset_after_modifying_the_args() { - global $wp_filter; - - $modified_action = [ - 'args' => 14, - ]; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, do a hard check to ensure the original number of args is registered. - $this->assertEquals( - $action['args'], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ]['accepted_args'] - ); - - // Modify the number of arguments. - beans_modify_action_arguments( $beans_id, $modified_action['args'] ); - - // Check that the number of arguments was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( - $modified_action['args'], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ]['accepted_args'] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's callback and args after they were "modified". - */ - public function test_should_reset_after_modifying_callback_and_args() { - global $wp_filter; - - $this->go_to_post(); - - $modified_action = [ - 'callback' => 'my_callback', - 'args' => 14, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->check_the_action( $beans_id, $action ); - - // Modify the action. - beans_modify_action( $beans_id, null, $modified_action['callback'], null, $modified_action['args'] ); - - // Check that the action was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertTrue( has_action( $action['hook'], $modified_action['callback'] ) !== false ); - $this->assertEquals( - [ - 'function' => $modified_action['callback'], - 'accepted_args' => $modified_action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $modified_action['callback'] ] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's priority and args after they were "modified". - */ - public function test_should_reset_after_modifying_priority_and_args() { - global $wp_filter; - - $this->go_to_post(); - - $modified_action = [ - 'priority' => 79, - 'args' => 14, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->check_the_action( $beans_id, $action ); - - // Modify the action. - beans_modify_action( $beans_id, null, null, $modified_action['priority'], $modified_action['args'] ); - - // Check that the action was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( - [ - 'function' => $action['callback'], - 'accepted_args' => $modified_action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $modified_action['priority'] ][ $action['callback'] ] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's callback and priority after they were "modified". - */ - public function test_should_reset_after_modifying_callback_and_priority() { - global $wp_filter; - - $this->go_to_post(); - - $modified_action = [ - 'callback' => 'foo', - 'priority' => 39, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->check_the_action( $beans_id, $action ); - - // Modify the action. - beans_modify_action( $beans_id, null, $modified_action['callback'], $modified_action['priority'] ); - - // Check that the action was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( - [ - 'function' => $modified_action['callback'], - 'accepted_args' => $action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $modified_action['priority'] ][ $modified_action['callback'] ] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should reset the original action's callback, priority, and args after they were - * "modified". - */ - public function test_should_reset_after_modifying_all_but_hook() { - global $wp_filter; - - $this->go_to_post(); - - $modified_action = [ - 'callback' => 'foo', - 'priority' => 39, - 'args' => 24, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->check_the_action( $beans_id, $action ); - - // Modify the action. - beans_modify_action( $beans_id, null, $modified_action['callback'], $modified_action['priority'], $modified_action['args'] ); - - // Check that the action was modified. - $this->assertSame( $modified_action, _beans_get_action( $beans_id, 'modified' ) ); - $this->assertEquals( - [ - 'function' => $modified_action['callback'], - 'accepted_args' => $modified_action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $modified_action['priority'] ][ $modified_action['callback'] ] - ); - - // Let's reset the action. - $this->assertSame( $action, beans_reset_action( $beans_id ) ); - - // Check that the action was reset. - $this->assertFalse( _beans_get_action( $beans_id, 'modified' ) ); - $this->check_the_action( $beans_id, $action ); - } - } - - /** - * Test beans_reset_action() should not reset after replacing the action's hook. - * - * Why? "Replace" overwrites and is not resettable. - */ - public function test_should_not_reset_after_replacing_hook() { - $hook = 'foo'; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Run the replace. - beans_replace_action_hook( $beans_id, $hook ); - - // Let's try to reset the action. - $this->assertSame( $hook, beans_reset_action( $beans_id )['hook'] ); - - // Check that the action was not reset. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertTrue( has_action( $hook, $action['callback'] ) !== false ); - } - } - - /** - * Test beans_reset_action() should not reset after replacing the action's callback. - * - * Why? "Replace" overwrites and is not resettable. - */ - public function test_should_not_reset_after_replacing_callback() { - $callback = 'foo_cb'; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, check that the action is registered. - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - // Run the replace. - beans_replace_action_callback( $beans_id, $callback ); - - // Let's try to reset the action. - $this->assertSame( $callback, beans_reset_action( $beans_id )['callback'] ); - - // Check that the action was not reset. - $this->assertFalse( has_action( $action['hook'], $action['callback'] ) ); - $this->assertTrue( has_action( $action['hook'], $callback ) !== false ); - } - } - - /** - * Test beans_reset_action() should not reset after replacing the action's priority. - * - * Why? "Replace" overwrites and is not resettable. - */ - public function test_should_not_reset_after_replacing_priority() { - global $wp_filter; - - $priority = 17; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, do a hard check to ensure the original priority is registered. - $this->assertEquals( - [ - 'function' => $action['callback'], - 'accepted_args' => $action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ] - ); - - // Run the replace. - beans_replace_action_priority( $beans_id, $priority ); - - // Let's try to reset the action. - $this->assertSame( $priority, beans_reset_action( $beans_id )['priority'] ); - - // Check that the action was not reset. - $this->assertEquals( - [ - 'function' => $action['callback'], - 'accepted_args' => $action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $priority ][ $action['callback'] ] - ); - } - } - - /** - * Test beans_reset_action() should not reset after replacing the action's args. - * - * Why? "Replace" overwrites and is not resettable. - */ - public function test_should_not_reset_after_replacing_args() { - global $wp_filter; - - $args = 29; - - $this->go_to_post(); - - foreach ( static::$test_actions as $beans_id => $action ) { - // Before we start, do a hard check to ensure the original number of args is registered. - $this->assertEquals( - $action['args'], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ]['accepted_args'] - ); - - // Run the replace. - beans_replace_action_arguments( $beans_id, $args ); - - // Let's try to reset the action. - $this->assertSame( $args, beans_reset_action( $beans_id )['args'] ); - - // Check that the action was not reset. - $this->assertEquals( - $args, - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ]['accepted_args'] - ); - } - } - - /** - * Check that the action was reset. - * - * @since 1.5.0 - * - * @param string $beans_id The action's Beans ID, a unique ID tracked within Beans for this action. - * @param array $action The action to check. - * - * @return void - */ - protected function check_the_action( $beans_id, array $action ) { - global $wp_filter; - - $this->assertSame( $action, _beans_get_action( $beans_id, 'added' ) ); - $this->assertTrue( has_action( $action['hook'], $action['callback'] ) !== false ); - - $this->assertEquals( - [ - 'function' => $action['callback'], - 'accepted_args' => $action['args'], - ], - $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ][ $action['callback'] ] - ); - } -} diff --git a/tests/phpunit/integration/api/actions/beansSetAction.php b/tests/phpunit/integration/api/actions/beansSetAction.php deleted file mode 100644 index b9254c9f..00000000 --- a/tests/phpunit/integration/api/actions/beansSetAction.php +++ /dev/null @@ -1,108 +0,0 @@ - $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - // Before we start, check that the action is not set. - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions[ $status ] ); - - // Now do the tests. - $this->assertSame( $action, _beans_set_action( $beans_id, $action, $status ) ); - $this->assertArrayHasKey( $beans_id, $_beans_registered_actions[ $status ] ); - $this->assertSame( $action, $_beans_registered_actions[ $status ][ $beans_id ] ); - } - } - } - - /** - * Test _beans_set_action() should not overwrite an existing registered action. - */ - public function test_should_not_overwrite_existing_registered_action() { - global $_beans_registered_actions; - - $new_action = [ - 'hook' => 'bar', - 'callback' => 'callback_bar', - 'priority' => 20, - 'args' => 2, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - // Register the original action. - $this->assertSame( $action, _beans_set_action( $beans_id, $action, $status ) ); - - // Now test that it does not overwrite the previously registered action. - $this->assertSame( $action, _beans_set_action( $beans_id, $new_action, $status ) ); - $this->assertSame( $action, $_beans_registered_actions[ $status ][ $beans_id ] ); - } - } - } - - /** - * Test _beans_set_action() should overwrite the existing registered action when the "overwrite" - * argument is set to true. - */ - public function test_should_overwrite_existing_registered_action() { - global $_beans_registered_actions; - - $new_action = [ - 'hook' => 'bar', - 'callback' => 'callback_bar', - 'priority' => 20, - 'args' => 2, - ]; - - foreach ( static::$test_actions as $beans_id => $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - // Register the original action. - $this->assertSame( $action, _beans_set_action( $beans_id, $action, $status ) ); - $this->assertSame( $action, $_beans_registered_actions[ $status ][ $beans_id ] ); - - // Now test that it does overwrite the previously registered action. - $this->assertSame( $new_action, _beans_set_action( $beans_id, $new_action, $status, true ) ); - $this->assertSame( $new_action, $_beans_registered_actions[ $status ][ $beans_id ] ); - } - } - } -} diff --git a/tests/phpunit/integration/api/actions/beansUnsetAction.php b/tests/phpunit/integration/api/actions/beansUnsetAction.php deleted file mode 100644 index d70eec53..00000000 --- a/tests/phpunit/integration/api/actions/beansUnsetAction.php +++ /dev/null @@ -1,91 +0,0 @@ - $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - $this->assertFalse( _beans_unset_action( $beans_id, $status ) ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions[ $status ] ); - } - } - } - - /** - * Test _beans_unset_action() should unset the registered action. - */ - public function test_should_unset_registered_action() { - global $_beans_registered_actions; - - foreach ( static::$test_actions as $beans_id => $action ) { - - // Test each status. - foreach ( $this->statuses as $status ) { - // Register the action first. - _beans_set_action( $beans_id, $action, $status ); - $this->assertArrayHasKey( $beans_id, $_beans_registered_actions[ $status ] ); - - // Test that it unsets the action. - $this->assertTrue( _beans_unset_action( $beans_id, $status ) ); - $this->assertArrayNotHasKey( $beans_id, $_beans_registered_actions[ $status ] ); - } - } - } - - /** - * Test _beans_unset_action() should return false when the status is invalid. - */ - public function test_should_return_false_when_status_is_invalid() { - - foreach ( static::$test_actions as $beans_id => $action ) { - - $this->assertFalse( _beans_unset_action( $beans_id, 'invalid_status' ) ); - $this->assertFalse( _beans_unset_action( $beans_id, 'foo' ) ); - $this->assertFalse( _beans_unset_action( $beans_id, 'not_valid_either' ) ); - - // Now store the action in each status. - foreach ( $this->statuses as $status ) { - _beans_set_action( $beans_id, $action, $status ); - } - - // Run the tests again. - $this->assertFalse( _beans_unset_action( $beans_id, 'invalid_status' ) ); - $this->assertFalse( _beans_unset_action( $beans_id, 'foo' ) ); - $this->assertFalse( _beans_unset_action( $beans_id, 'not_valid_either' ) ); - } - } -} diff --git a/tests/phpunit/integration/api/actions/fixtures/test-actions.php b/tests/phpunit/integration/api/actions/fixtures/test-actions.php deleted file mode 100644 index 291530a8..00000000 --- a/tests/phpunit/integration/api/actions/fixtures/test-actions.php +++ /dev/null @@ -1,29 +0,0 @@ - [ - 'hook' => 'beans_post_header', - 'callback' => 'beans_post_meta', - 'priority' => 15, - 'args' => 1, - ], - 'beans_post_image' => [ - 'hook' => 'beans_post_body', - 'callback' => 'beans_post_image', - 'priority' => 5, - 'args' => 1, - ], - 'beans_previous_post_link' => [ - 'hook' => 'previous_post_link', - 'callback' => 'beans_previous_post_link', - 'priority' => 10, - 'args' => 4, - ], -]; diff --git a/tests/phpunit/integration/api/actions/includes/class-actions-test-case.php b/tests/phpunit/integration/api/actions/includes/class-actions-test-case.php deleted file mode 100644 index 5476b0f6..00000000 --- a/tests/phpunit/integration/api/actions/includes/class-actions-test-case.php +++ /dev/null @@ -1,215 +0,0 @@ - [], - 'modified' => [], - 'removed' => [], - 'replaced' => [], - ]; - - // Remove the test actions. - foreach ( static::$test_actions as $beans_id => $action ) { - remove_action( $action['hook'], $action['callback'], $action['priority'] ); - } - - static::$test_actions = null; - static::$test_ids = null; - } - - /** - * Cleans up the test environment after each test. - */ - public function tearDown() { - - if ( false === $this->reset_beans_registry ) { - return; - } - - global $_beans_registered_actions; - $_beans_registered_actions = [ - 'added' => [], - 'modified' => [], - 'removed' => [], - 'replaced' => [], - ]; - - parent::tearDown(); - } - - /** - * Restore the original action. - * - * @since 1.5.0 - * - * @param string $beans_id The Beans unique ID. - * - * @return void - */ - protected function restore_original( $beans_id ) { - $action = static::$test_actions[ $beans_id ]; - - _beans_unset_action( $beans_id, 'added' ); - - beans_add_action( $beans_id, $action['hook'], $action['callback'], $action['priority'], $action['args'] ); - } - - /** - * Check that it is not registered first. - * - * @since 1.5.0 - * - * @param string $id The ID to check. - * @param string $hook The hook (event name) to check. - * - * @return void - */ - protected function check_not_added( $id, $hook ) { - $this->assertFalse( _beans_get_action( $id, 'added' ) ); - $this->assertFalse( has_action( $hook ) ); - } - - /** - * Check that the action has been registered in WordPress. - * - * @since 1.5.0 - * - * @param string $hook The event's name (hook) that is registered in WordPress. - * @param array $action The action to be checked. - * @param bool $remove_action When true, it removes the action automatically to clean up this test. - * - * @return void - */ - protected function check_registered_in_wp( $hook, array $action, $remove_action = true ) { - $this->assertTrue( has_action( $hook, $action['callback'] ) !== false ); - $this->check_parameters_registered_in_wp( $action, $remove_action ); - } - - /** - * Check that the right parameters are registered in WordPress. - * - * @since 1.5.0 - * - * @param array $action The action that should be registered. - * @param bool $remove_action When true, it removes the action automatically to clean up this test. - * - * @return void - */ - protected function check_parameters_registered_in_wp( array $action, $remove_action = true ) { - global $wp_filter; - $registered_action = $wp_filter[ $action['hook'] ]->callbacks[ $action['priority'] ]; - - $this->assertArrayHasKey( $action['callback'], $registered_action ); - $this->assertEquals( $action['callback'], $registered_action[ $action['callback'] ]['function'] ); - $this->assertEquals( $action['args'], $registered_action[ $action['callback'] ]['accepted_args'] ); - - // Then remove the action. - if ( $remove_action ) { - remove_action( $action['hook'], $action['callback'], $action['priority'] ); - } - } - - /** - * Set up the original action. - * - * @since 1.5.0 - * - * @param string $id Optional. Beans ID to register. Default is 'foo'. - * - * @return array - */ - protected function setup_original_action( $id = 'foo' ) { - $action = [ - 'hook' => "{$id}_hook", - 'callback' => "callback_{$id}", - 'priority' => 10, - 'args' => 1, - ]; - - $this->check_not_added( $id, $action['hook'] ); - - // Add the original action to get us rolling. - beans_add_action( $id, $action['hook'], $action['callback'] ); - $this->assertTrue( has_action( $action['hook'] ) ); - $this->check_parameters_registered_in_wp( $action, false ); - - return $action; - } - - /** - * Simulate going to the post and loading in the template and fragments. - * - * @since 1.5.0 - * - * @return void - */ - protected function go_to_post() { - - /** - * Restore the actions. Why? The file loads once and initially adds the actions. But then we remove them - * during our tests. - */ - foreach ( static::$test_ids as $beans_id ) { - $this->restore_original( $beans_id ); - } - - $post_id = self::factory()->post->create( [ 'post_title' => 'Hello Beans' ] ); - $this->go_to( get_permalink( $post_id ) ); - do_action( 'template_redirect' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Valid use case as we need to fire this action as part of our tests. - } -} diff --git a/tests/phpunit/integration/api/actions/includes/class-replace-action-test-case.php b/tests/phpunit/integration/api/actions/includes/class-replace-action-test-case.php deleted file mode 100644 index f7ed7194..00000000 --- a/tests/phpunit/integration/api/actions/includes/class-replace-action-test-case.php +++ /dev/null @@ -1,105 +0,0 @@ -reset_beans_registry = false; - - parent::setUp(); - - // Just in case the original action is already registered, remove it. - $this->remove_original_action(); - } - - /** - * Cleans up the test environment after each test. - */ - public function tearDown() { - - // Reset and restore. - foreach ( static::$test_actions as $beans_id => $action ) { - // Reset Beans. - _beans_unset_action( $beans_id, 'modified' ); - _beans_unset_action( $beans_id, 'replaced' ); - _beans_unset_action( $beans_id, 'added' ); - - // Restore the original action. - beans_add_smart_action( $action['hook'], $action['callback'], $action['priority'], $action['args'] ); - } - - parent::tearDown(); - } - - /** - * Store the original action and then remove it. These steps allow us to set up an - * initial test where the action is not registered. Then when we're doing testing, we can - * restore it. - * - * @since 1.5.0 - * - * @return void - */ - private function remove_original_action() { - - foreach ( static::$test_actions as $beans_id => $action ) { - _beans_unset_action( $beans_id, 'added' ); - - if ( has_action( $action['hook'], $action['callback'] ) ) { - remove_action( $action['hook'], $action['callback'], $action['priority'], $action['args'] ); - } - } - } - - /** - * Merge the action's configuration with the defaults. - * - * @since 1.5.0 - * - * @param array $action The action to merge. - * - * @return array - */ - protected function merge_action_with_defaults( array $action ) { - return array_merge( - [ - 'hook' => null, - 'callback' => null, - 'priority' => null, - 'args' => null, - ], - $action - ); - } - - /** - * Check that the "replaced" action has been stored in Beans. - * - * @since 1.5.0 - * - * @param string $beans_id The Beans unique ID. - * @param array $replaced_action The "replaced" action's configuration. - * - * @return void - */ - protected function check_stored_in_beans( $beans_id, array $replaced_action ) { - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'replaced' ) ); - $this->assertEquals( $replaced_action, _beans_get_action( $beans_id, 'modified' ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/flush.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/flush.php deleted file mode 100644 index da805f17..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/flush.php +++ /dev/null @@ -1,58 +0,0 @@ -directoryExists( vfsStream::url( 'compiled/beans/compiler/' ) ); - - $this->assertNull( ( new _Beans_Compiler_Options() )->flush() ); - - // Check that it still exists and was not removed. - $this->directoryExists( vfsStream::url( 'compiled/beans/compiler/' ) ); - } - - /** - * Test _Beans_Compiler_Options::flush() should should remove the cached directory. - */ - public function test_should_remove_cached_dir() { - // Check that the cached directory exists before we start. - $this->directoryExists( vfsStream::url( 'compiled/beans/compiler/' ) ); - - $this->go_to_settings_page(); - $_POST['beans_flush_compiler_cache'] = 1; - - // Return the virtual filesystem's path to avoid wp_normalize_path converting its prefix from vfs::// to vfs:/. - Monkey\Functions\when( 'wp_normalize_path' )->returnArg(); - - $this->assertNull( ( new _Beans_Compiler_Options() )->flush() ); - $this->assertDirectoryNotExists( vfsStream::url( 'compiled/beans/compiler/' ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/register.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/register.php deleted file mode 100644 index 1a6dbf8f..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/register.php +++ /dev/null @@ -1,193 +0,0 @@ -assertNull( ( new _Beans_Compiler_Options() )->register() ); - } - - /** - * Test _Beans_Compiler_Options::register() should not register when not is_admin(), i.e. not in the backend. - */ - public function test_should_not_register_when_not_is_admin() { - set_current_screen( 'front' ); - $_GET['page'] = 'beans_settings'; - $this->assertFalse( is_admin() ); - $this->assertNull( ( new _Beans_Compiler_Options() )->register() ); - } - - /** - * Test _Beans_Compiler_Options::register() should register only the flush button when the styles and scripts are - * not supported. - */ - public function test_should_only_register_only_flush_button_when_styles_scripts_not_supported() { - $this->go_to_settings_page(); - - // Set up the tests by removing these API components. - beans_remove_api_component_support( 'wp_styles_compiler' ); - beans_remove_api_component_support( 'wp_scripts_compiler' ); - $this->assertFalse( beans_get_component_support( 'wp_styles_compiler' ) ); - $this->assertFalse( beans_get_component_support( 'wp_scripts_compiler' ) ); - - // Run the registration. - $this->assertTrue( ( new _Beans_Compiler_Options() )->register() ); - - // Check that the fields did get registered. - $registered_fields = beans_get_fields( 'option', 'compiler_options' ); - $this->assertNotEmpty( $registered_fields ); - $this->assertCount( 1, $registered_fields ); - $this->assertArraySubset( [ - 'id' => 'beans_compiler_items', - 'type' => 'flush_cache', - ], current( $registered_fields ) ); - - // Check that the metabox did get registered. - global $wp_meta_boxes; - $this->assertArrayHasKey( 'compiler_options', $wp_meta_boxes['beans_settings']['normal']['default'] ); - $this->assertEquals( 'Compiler options', $wp_meta_boxes['beans_settings']['normal']['default']['compiler_options']['title'] ); - } - - /** - * Test _Beans_Compiler_Options::register() should not register the styles options when not supported. - */ - public function test_should_not_register_styles_options_when_not_supported() { - $this->go_to_settings_page(); - - // Set up API components. - beans_remove_api_component_support( 'wp_styles_compiler' ); - beans_add_api_component_support( 'wp_scripts_compiler' ); - $this->assertFalse( beans_get_component_support( 'wp_styles_compiler' ) ); - $this->assertNotEmpty( beans_get_component_support( 'wp_scripts_compiler' ) ); - - // Run the registration. - $this->assertTrue( ( new _Beans_Compiler_Options() )->register() ); - - // Check that the right fields did get registered. - $registered_fields = beans_get_fields( 'option', 'compiler_options' ); - $this->assertCount( 2, $registered_fields ); - $this->assertArraySubset( [ - 'id' => 'beans_compiler_items', - 'type' => 'flush_cache', - ], current( $registered_fields ) ); - $this->assertArraySubset( [ - 'id' => 'beans_compile_all_scripts_group', - 'label' => 'Compile all WordPress scripts', - 'type' => 'group', - ], next( $registered_fields ) ); - - // Check that the metabox did get registered. - global $wp_meta_boxes; - $this->assertArrayHasKey( 'compiler_options', $wp_meta_boxes['beans_settings']['normal']['default'] ); - $this->assertEquals( 'Compiler options', $wp_meta_boxes['beans_settings']['normal']['default']['compiler_options']['title'] ); - } - - /** - * Test _Beans_Compiler_Options::register() should not register the scripts options when not supported. - */ - public function test_should_not_register_scripts_options_when_not_supported() { - $this->go_to_settings_page(); - - // Set up API components. - beans_add_api_component_support( 'wp_styles_compiler' ); - beans_remove_api_component_support( 'wp_scripts_compiler' ); - $this->assertNotEmpty( beans_get_component_support( 'wp_styles_compiler' ) ); - $this->assertFalse( beans_get_component_support( 'wp_scripts_compiler' ) ); - - // Run the registration. - $this->assertTrue( ( new _Beans_Compiler_Options() )->register() ); - - // Check that the right fields did get registered. - $registered_fields = beans_get_fields( 'option', 'compiler_options' ); - $this->assertCount( 2, $registered_fields ); - $this->assertArraySubset( [ - 'id' => 'beans_compiler_items', - 'type' => 'flush_cache', - ], current( $registered_fields ) ); - $this->assertArraySubset( [ - 'id' => 'beans_compile_all_styles', - 'label' => 'Compile all WordPress styles', - 'checkbox_label' => 'Select to compile styles.', - 'type' => 'checkbox', - 'default' => false, - ], next( $registered_fields ) ); - - // Check that the metabox did get registered. - global $wp_meta_boxes; - $this->assertArrayHasKey( 'compiler_options', $wp_meta_boxes['beans_settings']['normal']['default'] ); - $this->assertEquals( 'Compiler options', $wp_meta_boxes['beans_settings']['normal']['default']['compiler_options']['title'] ); - } - - /** - * Test _Beans_Compiler_Options::register() should register all options when styles and scripts are supported. - */ - public function test_should_register_all_options_when_styles_scripts_supported() { - $this->go_to_settings_page(); - - // Set up API components. - beans_add_api_component_support( 'wp_styles_compiler' ); - beans_add_api_component_support( 'wp_scripts_compiler' ); - $this->assertNotEmpty( beans_get_component_support( 'wp_styles_compiler' ) ); - $this->assertNotEmpty( beans_get_component_support( 'wp_scripts_compiler' ) ); - - // Run the registration. - $this->assertTrue( ( new _Beans_Compiler_Options() )->register() ); - - // Check that the right fields did get registered. - $registered_fields = beans_get_fields( 'option', 'compiler_options' ); - $this->assertCount( 3, $registered_fields ); - $this->assertArraySubset( [ - 'id' => 'beans_compiler_items', - 'type' => 'flush_cache', - ], current( $registered_fields ) ); - $this->assertArraySubset( [ - 'id' => 'beans_compile_all_styles', - 'label' => 'Compile all WordPress styles', - 'checkbox_label' => 'Select to compile styles.', - 'type' => 'checkbox', - 'default' => false, - ], next( $registered_fields ) ); - $this->assertArraySubset( [ - 'id' => 'beans_compile_all_scripts_group', - 'label' => 'Compile all WordPress scripts', - 'type' => 'group', - ], next( $registered_fields ) ); - - // Check that the metabox did get registered. - global $wp_meta_boxes; - $this->assertArrayHasKey( 'compiler_options', $wp_meta_boxes['beans_settings']['normal']['default'] ); - $this->assertEquals( 'Compiler options', $wp_meta_boxes['beans_settings']['normal']['default']['compiler_options']['title'] ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderFlushButton.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/renderFlushButton.php deleted file mode 100644 index 57ebf3c0..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderFlushButton.php +++ /dev/null @@ -1,55 +0,0 @@ -render_flush_button( [ 'id' => 'foo' ] ); - - $this->assertEmpty( ob_get_clean() ); - } - - /** - * Test _Beans_Compiler_Options::render_flush_button() should render when the field is for compiler options. - */ - public function test_should_render_when_field_is_compiler_items_options() { - $this->go_to_settings_page(); - $_POST = [ 'beans_flush_compiler_cache' => 1 ]; - - ob_start(); - ( new _Beans_Compiler_Options() )->render_flush_button( [ 'id' => 'beans_compiler_items' ] ); - $actual = ob_get_clean(); - - $expected = << -EOB; - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $actual ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderScriptsNotCompiledNotice.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/renderScriptsNotCompiledNotice.php deleted file mode 100644 index 1a3d79d1..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderScriptsNotCompiledNotice.php +++ /dev/null @@ -1,68 +0,0 @@ -assertFalse( _beans_is_compiler_dev_mode() ); - - $this->assertNull( ( new _Beans_Compiler_Options() )->render_scripts_not_compiled_notice() ); - } - - /** - * Test _Beans_Compiler_Options::render_scripts_not_compiled_notice() should not render when compile scripts is not - * an option. - */ - public function test_should_not_render_when_compile_scripts_not_an_option() { - add_option( 'beans_dev_mode', 1 ); - $this->assertTrue( _beans_is_compiler_dev_mode() ); - $this->assertEmpty( get_option( 'beans_compile_all_scripts' ) ); - - $this->assertNull( ( new _Beans_Compiler_Options() )->render_scripts_not_compiled_notice() ); - } - - /** - * Test _Beans_Compiler_Options::render_scripts_not_compiled_notice() should render when compile scripts is - * selected and Compiler is in dev mode. - */ - public function test_should_render_when_compile_scripts_selected_and_compiler_in_dev_mode() { - add_option( 'beans_dev_mode', 1 ); - add_option( 'beans_compile_all_scripts', 1 ); - $this->assertTrue( _beans_is_compiler_dev_mode() ); - $this->assertEquals( 1, get_option( 'beans_compile_all_scripts' ) ); - - ob_start(); - ( new _Beans_Compiler_Options() )->render_scripts_not_compiled_notice(); - $actual = ob_get_clean(); - - $expected = << -Scripts are not compiled in development mode. -EOB; - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $actual ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderStylesNotCompiledNotice.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/renderStylesNotCompiledNotice.php deleted file mode 100644 index b0c9f31c..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderStylesNotCompiledNotice.php +++ /dev/null @@ -1,68 +0,0 @@ -assertFalse( _beans_is_compiler_dev_mode() ); - - $this->assertNull( ( new _Beans_Compiler_Options() )->render_styles_not_compiled_notice() ); - } - - /** - * Test _Beans_Compiler_Options::render_styles_not_compiled_notice() should not render when compile styles is not - * an option. - */ - public function test_should_not_render_when_compile_styles_not_an_option() { - add_option( 'beans_dev_mode', 1 ); - $this->assertTrue( _beans_is_compiler_dev_mode() ); - $this->assertEmpty( get_option( 'beans_compile_all_styles' ) ); - - $this->assertNull( ( new _Beans_Compiler_Options() )->render_styles_not_compiled_notice() ); - } - - /** - * Test _Beans_Compiler_Options::render_styles_not_compiled_notice() should render when compile styles is selected - * and Compiler is in dev mode. - */ - public function test_should_render_when_compile_styles_selected_and_compiler_in_dev_mode() { - add_option( 'beans_dev_mode', 1 ); - add_option( 'beans_compile_all_styles', 1 ); - $this->assertEquals( 1, get_option( 'beans_compile_all_styles' ) ); - $this->assertTrue( _beans_is_compiler_dev_mode() ); - - ob_start(); - ( new _Beans_Compiler_Options() )->render_styles_not_compiled_notice(); - $actual = ob_get_clean(); - - $expected = << -Styles are not compiled in development mode. -EOB; - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $actual ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderSuccessNotice.php b/tests/phpunit/integration/api/compiler/beans-compiler-options/renderSuccessNotice.php deleted file mode 100644 index ab75fd2d..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler-options/renderSuccessNotice.php +++ /dev/null @@ -1,58 +0,0 @@ -go_to_settings_page(); - $this->assertArrayNotHasKey( 'beans_flush_compiler_cache', $_POST ); // phpcs:ignore WordPress.CSRF.NonceVerification.NoNonceVerification -- No need for nonce in this test. - - ob_start(); - ( new _Beans_Compiler_Options() )->render_success_notice(); - - $this->assertEmpty( ob_get_clean() ); - } - - /** - * Test _Beans_Compiler_Options::render_success_notice() should render when flushing compiler cache. - */ - public function test_should_render_when_flushing_compiler_cache() { - $this->go_to_settings_page(); - $_POST['beans_flush_compiler_cache'] = 1; - - ob_start(); - ( new _Beans_Compiler_Options() )->render_success_notice(); - $actual = ob_get_clean(); - - $expected = << -

Cache flushed successfully!

- -EOB; - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $actual ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/addContentMediaQuery.php b/tests/phpunit/integration/api/compiler/beans-compiler/addContentMediaQuery.php deleted file mode 100644 index 085359ea..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/addContentMediaQuery.php +++ /dev/null @@ -1,108 +0,0 @@ -set_current_fragment( $compiler, [ $this, __METHOD__ ] ); - $this->assertSame( $css, $compiler->add_content_media_query( $css ) ); - } - - /** - * Test _Beans_Compiler::add_content_media_query() should return original content when there are no query args. - */ - public function test_should_return_content_when_no_query_args() { - $compiler = new _Beans_Compiler( [] ); - $css = <<set_current_fragment( $compiler, 'http://foo.com/foo.css' ); - $this->assertSame( $css, $compiler->add_content_media_query( $css ) ); - - $this->set_current_fragment( $compiler, 'http://foo.com/assets/less/foo.less' ); - $this->assertSame( $css, $compiler->add_content_media_query( $css ) ); - } - - /** - * Test _Beans_Compiler::add_content_media_query() should return original content when the - * 'beans_compiler_media_query' query arg is not present in the current fragment. - */ - public function test_should_return_content_when_no_media_query() { - $compiler = new _Beans_Compiler( [] ); - $css = <<set_current_fragment( $compiler, 'http://foo.com/base.css?beans=rocks' ); - $this->assertSame( $css, $compiler->add_content_media_query( $css ) ); - - $this->set_current_fragment( $compiler, 'http://foo.com/style.css?beans=rocks&beans_compiler=media_query' ); - $this->assertSame( $css, $compiler->add_content_media_query( $css ) ); - } - - /** - * Test _Beans_Compiler::add_content_media_query() should wrap the content in the specified media query. - */ - public function test_should_wrap_content_in_media_query() { - $compiler = new _Beans_Compiler( [] ); - $css = <<set_current_fragment( $compiler, 'http://foo.com/base.css?beans_compiler_media_query=' . $media_query ); - $this->assertSame( - "@media {$media_query} {\n{$css}\n}\n", - $compiler->add_content_media_query( $css ) - ); - } - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/cacheFile.php b/tests/phpunit/integration/api/compiler/beans-compiler/cacheFile.php deleted file mode 100644 index ece67172..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/cacheFile.php +++ /dev/null @@ -1,135 +0,0 @@ - 'test-jquery', - 'type' => 'script', - 'fragments' => [ vfsStream::url( 'compiled/fixtures/jquery.test.js' ) ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - ]; - $compiler = $this->initialize_compiler( $config ); - - // Run the tests. - $this->assertTrue( $compiler->cache_file() ); - $this->assertSame( $this->get_compiled_jquery(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - - // Clean Up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::cache_file() should create the compiled JavaScript file. - */ - public function test_should_create_compiled_javascript_file() { - $config = [ - 'id' => 'test-js', - 'type' => 'script', - 'fragments' => [ vfsStream::url( 'compiled/fixtures/my-game-clock.js' ) ], - 'in_footer' => true, - 'minify_js' => true, - ]; - $compiler = $this->initialize_compiler( $config ); - - // Run the tests. - $this->assertTrue( $compiler->cache_file() ); - $this->assertSame( $this->get_compiled_js(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - - // Clean Up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::cache_file() should create the compiled CSS file. - */ - public function test_should_create_compiled_css_file() { - $config = [ - 'id' => 'test-css', - 'type' => 'style', - 'fragments' => [ vfsStream::url( 'compiled/fixtures/style.css' ) ], - ]; - $compiler = $this->initialize_compiler( $config ); - - // Run the tests. - $this->assertTrue( $compiler->cache_file() ); - $this->assertSame( $this->get_compiled_css(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - - // Clean Up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::cache_file() should create the compiled LESS file. - */ - public function test_should_create_compiled_less_file() { - $config = [ - 'id' => 'test-css', - 'type' => 'style', - 'format' => 'less', - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/variables.less' ), - vfsStream::url( 'compiled/fixtures/test.less' ), - ], - ]; - $compiler = $this->initialize_compiler( $config ); - - // Run the tests. - $this->assertTrue( $compiler->cache_file() ); - $this->assertSame( $this->get_compiled_less(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - - // Clean Up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Initialize the Compiler for the test. - * - * @since 1.0.0 - * - * @param array $config Array of runtime configuration parameters. - * - * @return _Beans_Compiler - * @throws \ReflectionException Throws an error. - */ - protected function initialize_compiler( array $config ) { - $compiler = new _Beans_Compiler( $config ); - - add_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - $compiler->filesystem(); - $this->add_virtual_directory( $config['id'] ); - $this->set_current_fragment( $compiler, $config['fragments'][0] ); - $compiler->set_filename(); - $compiler->combine_fragments(); - - return $compiler; - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/combineFragments.php b/tests/phpunit/integration/api/compiler/beans-compiler/combineFragments.php deleted file mode 100644 index 462bdcf0..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/combineFragments.php +++ /dev/null @@ -1,309 +0,0 @@ -mock_filesystem->getChild( 'fixtures' ); - $this->css = $fixtures->getChild( 'style.css' )->getContent(); - $this->less = $fixtures->getChild( 'variables.less' )->getContent() . $fixtures->getChild( 'test.less' )->getContent(); - $this->jquery = $fixtures->getChild( 'jquery.test.js' )->getContent(); - $this->js = $fixtures->getChild( 'my-game-clock.js' )->getContent(); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return an empty string when there are no fragments to combine. - */ - public function test_should_return_empty_string_when_no_fragments() { - $compiler = new _Beans_Compiler( [] ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( '', $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return an empty string when the fragment does not exist. - */ - public function test_should_return_empty_string_when_fragment_does_not_exist() { - $fragment = vfsStream::url( 'compiled/fixtures/' ) . 'invalid-file.js'; - $compiler = new _Beans_Compiler( [] ); - $this->set_current_fragment( $compiler, $fragment ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( '', $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should compile the Less fragments and return the compiled CSS. - */ - public function test_should_compile_less_and_return_css() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'style', - 'format' => 'less', - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/variables.less' ), - vfsStream::url( 'compiled/fixtures/test.less' ), - ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( true ); - - // Run the test. - $compiler->combine_fragments(); - $expected_css = <<assertSame( $expected_css, $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return minified, compiled Less from the Less combined fragments. - */ - public function test_should_return_minified_compiled_less() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'style', - 'format' => 'less', - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/variables.less' ), - vfsStream::url( 'compiled/fixtures/test.less' ), - ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( false ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertContains( $this->get_compiled_less(), $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return the original jQuery when site is not in development mode, - * but "minify_js" is disabled. - */ - public function test_should_return_original_jquery_when_minify_js_disabled() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => false, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/jquery.test.js' ), - ], - 'dependencies' => [ 'jquery' ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( false ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->jquery, $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return the original jQuery when "minify_js" is enabled, - * but the site is in development mode. - */ - public function test_should_always_return_original_jquery_when_in_dev_mode() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/jquery.test.js' ), - ], - 'dependencies' => [ 'jquery' ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( true ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->jquery, $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return minified jQuery. - */ - public function test_should_return_minified_jquery() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/jquery.test.js' ), - ], - 'dependencies' => [ 'jquery' ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( false ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->get_compiled_jquery(), $compiler->compiled_content ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return the original JavaScript when site is not in development - * mode, but "minify_js" is disabled. - */ - public function test_should_return_original_js_when_minify_js_disabled() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => false, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/my-game-clock.js' ), - ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( false ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->js, $compiler->compiled_content ); - - // Clean up. - unset( $GLOBALS['wp_filesystem'] ); - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return the original JavaScript when "minify_js" is enabled, - * but the site is in development mode. - */ - public function test_should_always_return_original_js_when_in_dev_mode() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/my-game-clock.js' ), - ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( true ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->js, $compiler->compiled_content ); - - // Clean up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::combine_fragments() should return minified JavaScript. - */ - public function test_should_return_minified_javascript() { - $compiler = new _Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/my-game-clock.js' ), - ], - ] ); - - // Set up the test. - $this->set_up_wp_filesystem( $compiler ); - $this->set_dev_mode( false ); - - // Run the test. - $compiler->combine_fragments(); - $this->assertSame( $this->get_compiled_js(), $compiler->compiled_content ); - - // Clean up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Set the WP Filesystem. - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler Instance of the compiler. - * - * @return void - */ - private function set_up_wp_filesystem( $compiler ) { - add_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - $compiler->filesystem(); - $this->assertInstanceOf( 'WP_Filesystem_Direct', $GLOBALS['wp_filesystem'] ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/fileystem.php b/tests/phpunit/integration/api/compiler/beans-compiler/fileystem.php deleted file mode 100644 index 774d2a24..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/fileystem.php +++ /dev/null @@ -1,103 +0,0 @@ -once() - ->andReturn( 'base' ); - Functions\expect( __NAMESPACE__ . '\set_wp_die_handler' ) - ->once() - ->andReturn( __NAMESPACE__ . '\mock_wp_die_handler' ); - Functions\when( __NAMESPACE__ . '\mock_wp_die_handler' ) - ->alias( function( $message ) { - $this->assertContains( 'Beans cannot work its magic', $message ); - } ); - - add_filter( 'wp_die_handler', __NAMESPACE__ . '\set_wp_die_handler' ); - - // Initialize the WP Filesystem. - $this->assertNull( $compiler->filesystem() ); - - // Clean up. - unset( $GLOBALS['wp_filesystem'] ); - remove_filter( 'wp_die_handler', __NAMESPACE__ . '\set_wp_die_handler' ); - remove_filter( 'filesystem_method', __NAMESPACE__ . '\set_filesystem_method_to_base' ); - } - - /** - * Test _Beans_Compiler::filesystem() should initialize the WP Filesystem. - */ - public function test_should_init_wp_filesystem() { - $compiler = new _Beans_Compiler( [] ); - - add_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - - // Initialize the WP Filesystem. - $this->assertTrue( $compiler->filesystem() ); - - // Check that it was initialized. - $this->assertTrue( function_exists( 'WP_Filesystem' ) ); - $this->assertTrue( class_exists( 'WP_Filesystem_Direct' ) ); - $this->assertArrayHasKey( 'wp_filesystem', $GLOBALS ); - $this->assertInstanceOf( 'WP_Filesystem_Direct', $GLOBALS['wp_filesystem'] ); - - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } - - /** - * Test _Beans_Compiler::filesystem() should set WP_Filesystem_Direct when not set as WP_Filesystem method. - */ - public function test_should_set_wp_filesystem_direct() { - // First, set something else as the WP_Filesystem method. - Functions\expect( __NAMESPACE__ . '\set_filesystem_method_to_base' ) - ->once() - ->andReturn( 'base' ); - - add_filter( 'filesystem_method', __NAMESPACE__ . '\set_filesystem_method_to_base' ); - WP_Filesystem(); - $this->assertInstanceOf( 'WP_Filesystem_Base', $GLOBALS['wp_filesystem'] ); - remove_filter( 'filesystem_method', __NAMESPACE__ . '\set_filesystem_method_to_base' ); - - // Next, let's run our Compiler's filesystem and check that it did initialize WP_Filesystem_Direct. - $compiler = new _Beans_Compiler( [] ); - - add_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - $this->assertTrue( $compiler->filesystem() ); - $this->assertInstanceOf( 'WP_Filesystem_Direct', $GLOBALS['wp_filesystem'] ); - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/formatContent.php b/tests/phpunit/integration/api/compiler/beans-compiler/formatContent.php deleted file mode 100644 index 9b3d083c..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/formatContent.php +++ /dev/null @@ -1,237 +0,0 @@ -mock_filesystem->getChild( 'fixtures' ); - $this->less = $fixtures->getChild( 'variables.less' )->getContent() . $fixtures->getChild( 'test.less' )->getContent(); - $this->jquery = $fixtures->getChild( 'jquery.test.js' )->getContent(); - $this->js = $fixtures->getChild( 'my-game-clock.js' )->getContent(); - } - - /** - * Test _Beans_Compiler::format_content() should return original content when the "type" is not - * a style or script (per the configuration). - */ - public function test_should_return_original_content_when_type_not_style_or_script() { - $compiler = new \_Beans_Compiler( [ - 'type' => 'foo', - ] ); - - // Run the tests. - $this->assertSame( $this->less, $compiler->format_content( $this->less ) ); - $this->assertSame( $this->jquery, $compiler->format_content( $this->jquery ) ); - $this->assertSame( $this->js, $compiler->format_content( $this->js ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return compiled CSS (not minified) from the Less combined - * fragments. - */ - public function test_should_return_compiled_css() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'style', - 'format' => 'less', - ] ); - - // Turn on development mode. - update_option( 'beans_dev_mode', true ); - - // Don't remove empty line before EOB; ! - $expected_css = <<assertSame( $expected_css, $compiler->format_content( $this->less ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return minified, compiled CSS from the Less combined fragments. - */ - public function test_should_return_minified_compiled_css() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'style', - 'format' => 'less', - ] ); - - // Turn off development mode. - update_option( 'beans_dev_mode', false ); - - $expected_css = <<assertSame( $expected_css, $compiler->format_content( $this->less ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return the original jQuery when site is not in development mode, - * but "minify_js" is disabled. - */ - public function test_should_return_original_jquery_when_minify_js_disabled() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => false, - ] ); - - // Turn off development mode. - update_option( 'beans_dev_mode', false ); - - // Run the test. - $this->assertSame( $this->jquery, $compiler->format_content( $this->jquery ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return the original jQuery when "minify_js" is enabled, - * but the site is in development mode. - */ - public function test_should_always_return_original_jquery_when_in_dev_mode() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - ] ); - - // Turn on development mode. - update_option( 'beans_dev_mode', true ); - - // Run the test. - $this->assertSame( $this->jquery, $compiler->format_content( $this->jquery ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return minified jQuery when "minify_js" is enabled - * and the site is not in development mode. - */ - public function test_should_return_minified_jquery_when_not_in_dev_mode_and_minify_js_enabled() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - ] ); - - // Turn off development mode. - update_option( 'beans_dev_mode', false ); - - $expected = <<assertSame( str_replace( '/$', '$', $expected ), $compiler->format_content( $this->jquery ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return the original JavaScript when site is not in development - * mode, but "minify_js" is disabled. - */ - public function test_should_return_original_js_when_minify_js_disabled() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => false, - ] ); - - // Turn off development mode. - update_option( 'beans_dev_mode', false ); - - // Run the test. - $this->assertSame( $this->js, $compiler->format_content( $this->js ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return the original JavaScript when "minify_js" is enabled, - * but the site is in development mode. - */ - public function test_should_always_return_original_js_when_in_dev_mode() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - ] ); - - // Turn on development mode. - update_option( 'beans_dev_mode', true ); - - // Run the test. - $this->assertSame( $this->js, $compiler->format_content( $this->js ) ); - } - - /** - * Test _Beans_Compiler::format_content() should return minified JavaScript when "minify_js" is enabled - * and the site is not in development mode. - */ - public function test_should_return_minified_js_when_not_in_dev_mode_and_minify_js_enabled() { - $compiler = new \_Beans_Compiler( [ - 'id' => 'test', - 'type' => 'script', - 'minify_js' => true, - ] ); - - // Turn off development mode. - update_option( 'beans_dev_mode', false ); - - $expected = <<assertSame( $expected, $compiler->format_content( $this->js ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/getInternalContent.php b/tests/phpunit/integration/api/compiler/beans-compiler/getInternalContent.php deleted file mode 100644 index 5f7d5cec..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/getInternalContent.php +++ /dev/null @@ -1,76 +0,0 @@ -assertfalse( $compiler->get_internal_content( '' ) ); - } - - /** - * Test _Beans_Compiler::get_internal_content() should return false when the file does not exist. - */ - public function test_should_return_false_when_file_does_not_exist() { - // Set up the compiler. - $fragment = vfsStream::url( 'compiled/fixtures/' ) . 'invalid-file.js'; - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - // Run the test. - $this->assertfalse( $compiler->get_internal_content( $fragment ) ); - } - - /** - * Test _Beans_Compiler::get_internal_content() should return a fragment's contents. - */ - public function test_should_return_fragment_contents() { - // Set up the compiler. - $fragment = vfsStream::url( 'compiled/fixtures/test.less' ); - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - // Set the WP Filesystem. - add_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - $compiler->filesystem(); - $this->assertInstanceOf( 'WP_Filesystem_Direct', $GLOBALS['wp_filesystem'] ); - - // Run the tests. - $contents = $compiler->get_internal_content( $fragment ); - $this->assertContains( 'body {', $contents ); - $this->assertContains( 'color: @body-color;', $contents ); - - // Clean up. - remove_filter( 'filesystem_method', [ $compiler, 'modify_filesystem_method' ] ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/getRemoteContent.php b/tests/phpunit/integration/api/compiler/beans-compiler/getRemoteContent.php deleted file mode 100644 index b36962f9..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/getRemoteContent.php +++ /dev/null @@ -1,106 +0,0 @@ -assertfalse( $compiler->get_remote_content( '' ) ); - } - - /** - * Test _Beans_Compiler::get_remote_content() should return empty string when the remote site or file does not - * exist. - */ - public function test_should_return_empty_string_when_remote_does_not_exist() { - $fragment = 'http://beans.local/invalid-file.js'; - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - // Run the test. - $this->assertSame( '', $compiler->get_remote_content( $fragment ) ); - } - - /** - * Test _Beans_Compiler::get_remote_content() should return the content when fragment is a relative url. - */ - public function test_should_return_content_when_fragment_is_relative_url() { - $fragment = '//fonts.googleapis.com/css?family=Lato'; - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - $content = $compiler->get_remote_content( $fragment ); - - // Run the tests. - $this->assertContains( "font-family: 'Lato';", $content ); - $this->assertContains( 'font-style: normal;', $content ); - $this->assertContains( 'font-weight: 400;', $content ); - $this->assertContains( "src: local('Lato Regular')", $content ); - } - - /** - * Test _Beans_Compiler::get_remote_content() should return the content when fragment is an http URL. - */ - public function test_should_return_content_when_fragment_is_http() { - $fragment = 'http://fonts.googleapis.com/css?family=Roboto'; - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - $content = $compiler->get_remote_content( $fragment ); - - // Run the tests. - $this->assertContains( "font-family: 'Roboto';", $content ); - $this->assertContains( 'font-style: normal;', $content ); - $this->assertContains( 'font-weight: 400;', $content ); - $this->assertContains( "src: local('Roboto')", $content ); - } - - /** - * Test _Beans_Compiler::get_remote_content() should return the content when fragment is an https URL. - */ - public function test_should_return_content_when_fragment_is_https() { - $fragment = 'https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css'; - $compiler = new _Beans_Compiler( [ - 'fragments' => [ $fragment ], - ] ); - $this->set_current_fragment( $compiler, $fragment ); - - $content = $compiler->get_remote_content( $fragment ); - - // Run the tests. - $this->assertContains( 'Font Awesome 4.7.0 by @davegandy - http://fontawesome.io - @fontawesome', $content ); - $this->assertContains( "@font-face{font-family:'FontAwesome';", $content ); - $this->assertContains( "src:url('../fonts/fontawesome-webfont.eot?v=4.7.0');", $content ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/replaceCssUrl.php b/tests/phpunit/integration/api/compiler/beans-compiler/replaceCssUrl.php deleted file mode 100644 index 16e71381..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/replaceCssUrl.php +++ /dev/null @@ -1,210 +0,0 @@ -assertSame( $css, $compiler->replace_css_url( $css ) ); - } - - /** - * Test _Beans_Compiler::replace_css_url() should return original content when it has a valid URI. - */ - public function test_should_return_original_content_when_valid_uri() { - $compiler = new _Beans_Compiler( [] ); - $css = <<assertSame( $css, $compiler->replace_css_url( $css ) ); - } - - /** - * Test _Beans_Compiler::replace_css_url() should convert the relative URL when it does not have ../. - */ - public function test_should_convert_relative_url_when_no_up_levels() { - $compiler = new _Beans_Compiler( [] ); - - // Set up the mocks. - $this->set_current_fragment( $compiler, 'http://foo.com/assets/less/hero.less' ); - - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - } - - /** - * Test _Beans_Compiler::replace_css_url() should convert the relative URL. - */ - public function test_should_convert_relative_url() { - $compiler = new _Beans_Compiler( [] ); - - // Set up the mocks. - $this->set_current_fragment( $compiler, 'http://foo.com/assets/less/hero.less' ); - - // Test with no spaces, single quotes, or double quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - - // Test with spaces and single quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - - // Test with spaces and double quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - } - - /** - * Test _Beans_Compiler::replace_css_url() should convert a deeper relative URL. - */ - public function test_should_convert_deeper_relative_url() { - $compiler = new _Beans_Compiler( [] ); - - // Set up the mocks. - $this->set_current_fragment( $compiler, 'http://example.com/assets/less/partials/hero.less' ); - - // Test with no spaces, single quotes, or double quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - - // Test with spaces and single quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - - // Test with spaces and double quotes. - $css = <<assertSame( $expected, $compiler->replace_css_url( $css ) ); - } - - /** - * Set the protected property "current_fragment". - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler The Compiler instance. - * @param mixed $fragment The given value to set. - * - * @return void - */ - protected function set_current_fragment( $compiler, $fragment ) { - $current_fragment = ( new \ReflectionClass( $compiler ) )->getProperty( 'current_fragment' ); - $current_fragment->setAccessible( true ); - $current_fragment->setValue( $compiler, $fragment ); - $current_fragment->setAccessible( false ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/runCompiler.php b/tests/phpunit/integration/api/compiler/beans-compiler/runCompiler.php deleted file mode 100644 index 8657cd12..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/runCompiler.php +++ /dev/null @@ -1,324 +0,0 @@ -mock_filesystem->getChild( 'fixtures' ); - $this->css = $fixtures->getChild( 'style.css' )->getContent(); - $this->less = $fixtures->getChild( 'variables.less' )->getContent() . $fixtures->getChild( 'test.less' )->getContent(); - $this->jquery = $fixtures->getChild( 'jquery.test.js' )->getContent(); - } - - /** - * Test _Beans_Compiler::cache_file() should enqueue the existing cached file when no modifications (no fragments - * have changed to warrant re-compiling the file). - */ - public function test_should_enqueue_existing_cached_file_when_no_modifications() { - $fragment = vfsStream::url( 'compiled/fixtures/jquery.test.js' ); - $config = [ - 'id' => 'test-jquery', - 'type' => 'script', - 'format' => 'js', - 'fragments' => [ vfsStream::url( 'compiled/fixtures/jquery.test.js' ) ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - 'version' => '1.5.0', - ]; - $compiler = new _Beans_Compiler( $config ); - - // Store the cached file into the virtual filesystem. - $this->add_virtual_directory( $config['id'] ); - $original_filename = $this->get_filename( $compiler, $config, filemtime( $fragment ) ); - $original_file = vfsStream::url( 'compiled/beans/compiler/' . $config['id'] . '/' . $original_filename ); - vfsStream::newFile( $original_filename ) - ->at( $this->mock_filesystem->getChild( 'compiled/beans/compiler/' . $config['id'] ) ) - ->setContent( $this->get_compiled_jquery() ); - $this->assertFileExists( $original_file ); - - // Run the compiler. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - - // Check that the "compiled" filename did not change. - $this->assertSame( $original_file, $actual_filename ); - - // Check that the file still exists. - $this->assertFileExists( $actual_filename ); - } - - /** - * Test _Beans_Compiler::cache_file() should recompile when a fragment(s) changes. When this happens, the existing - * cached file is removed and the new file is stored in the filesystem. - */ - public function test_should_recompile_when_fragments_change() { - $fragment = vfsStream::url( 'compiled/fixtures/jquery.test.js' ); - $config = [ - 'id' => 'test-script', - 'type' => 'script', - 'format' => 'js', - 'fragments' => [ $fragment ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - /** - * Set up the original "compiled" file. This is the file that should get removed during this - * test. We add the file into the virtual filesystem. - */ - $this->add_virtual_directory( $config['id'] ); - $original_filemtime = filemtime( $fragment ); - $original_filename = $this->get_filename( $compiler, $config, $original_filemtime ); - $original_file = vfsStream::url( 'compiled/beans/compiler/' . $config['id'] . '/' . $original_filename ); - vfsStream::newFile( $original_filename ) - ->at( $this->mock_filesystem->getChild( 'compiled/beans/compiler/' . $config['id'] ) ) - ->setContent( $this->get_compiled_jquery() ); - $original_hashes = explode( '-', pathinfo( $original_filename, PATHINFO_FILENAME ) ); - $this->assertFileExists( $original_file ); - - /** - * Next step is to modify the fragment, which will change its modification time. Let's add an opening - * comment to the fragment's content and then set up the modified file for our tests. - */ - $this->mock_filesystem->getChild( 'fixtures' ) - ->getChild( 'jquery.test.js' ) - ->write( $this->jquery . "\n console.log( 'Beans rocks!' ); \n" ); - $modified_filemtime = filemtime( $fragment ); - $modified_filename = $this->get_filename( $compiler, $config, $modified_filemtime ); - $modified_hashes = explode( '-', pathinfo( $modified_filename, PATHINFO_FILENAME ) ); - $modified_file = vfsStream::url( 'compiled/beans/compiler/' . $config['id'] . '/' . $modified_filename ); - $this->assertFileNotExists( $modified_file ); - - /** - * We've now completed the setup process. Let's test that the original fragment has changed by - * testing that it is not equal to the modification time, filename, and hashes. - */ - $this->assertNotEquals( $modified_filemtime, $original_filemtime ); - $this->assertNotEquals( $modified_filename, $original_filename ); - $this->assertSame( $modified_hashes[0], $original_hashes[0] ); - $this->assertNotEquals( $modified_hashes[1], $original_hashes[1] ); - - // Run the compiler. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - - // Check that the "compiled" filename is different. - $this->assertNotEquals( $original_file, $actual_filename ); - $this->assertSame( $modified_file, $actual_filename ); - - // Check that the original cached file was removed. - $this->assertFileNotExists( $original_file ); - - // Check that a new file was cached. - $this->assertFileExists( $modified_file ); - $this->assertFileExists( $actual_filename ); - } - - /** - * Test _Beans_Compiler::cache_file() should compile jQuery, saving it to the virtual filesystem and enqueuing it - * in WordPress. - */ - public function test_should_compile_save_and_enqueue_jquery() { - $fragment = vfsStream::url( 'compiled/fixtures/jquery.test.js' ); - $config = [ - 'id' => 'test-jquery', - 'type' => 'script', - 'format' => 'js', - 'fragments' => [ $fragment ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the virtual directory. - $this->add_virtual_directory( $config['id'] ); - $expected_file = vfsStream::url( - 'compiled/beans/compiler/' . $config['id'] . '/' . $this->get_filename( $compiler, $config, filemtime( $fragment ) ) - ); - - // Run the compiler. Test. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - $this->assertFileExists( $actual_filename ); - $this->assertSame( $expected_file, $actual_filename ); - $this->assertSame( $this->get_compiled_jquery(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - } - - /** - * Test _Beans_Compiler::cache_file() should compile JavaScript, saving it to the virtual filesystem and enqueuing - * it in WordPress. - */ - public function test_should_compile_save_and_enqueue_js() { - $fragment = vfsStream::url( 'compiled/fixtures/my-game-clock.js' ); - $config = [ - 'id' => 'test-js', - 'type' => 'script', - 'format' => 'js', - 'fragments' => [ $fragment ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the virtual directory. - $this->add_virtual_directory( $config['id'] ); - $expected_file = vfsStream::url( - 'compiled/beans/compiler/' . $config['id'] . '/' . $this->get_filename( $compiler, $config, filemtime( $fragment ) ) - ); - - // Run the compiler. Test. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - $this->assertFileExists( $actual_filename ); - $this->assertSame( $expected_file, $actual_filename ); - $this->assertSame( $this->get_compiled_js(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - } - - /** - * Test _Beans_Compiler::cache_file() should compile CSS, saving it to the virtual filesystem and enqueuing it in - * WordPress. - */ - public function test_should_compile_save_and_enqueue_css() { - $fragment = vfsStream::url( 'compiled/fixtures/style.css' ); - $config = [ - 'id' => 'test-css', - 'type' => 'style', - 'format' => 'css', - 'fragments' => [ $fragment ], - 'dependencies' => false, - 'in_footer' => false, - 'minify_js' => false, - 'version' => '1.5.0', - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the virtual directory. - $this->add_virtual_directory( $config['id'] ); - $expected_file = vfsStream::url( - 'compiled/beans/compiler/' . $config['id'] . '/' . $this->get_filename( $compiler, $config, filemtime( $fragment ) ) - ); - - // Run the compiler. Test. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - $this->assertFileExists( $actual_filename ); - $this->assertSame( $expected_file, $actual_filename ); - $this->assertSame( $this->get_compiled_css(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - } - - /** - * Test _Beans_Compiler::cache_file() should compile Less, saving it to the virtual filesystem and enqueuing it in - * WordPress. - */ - public function test_should_compile_save_and_enqueue_less() { - $config = [ - 'id' => 'test-css', - 'type' => 'style', - 'format' => 'less', - 'fragments' => [ - vfsStream::url( 'compiled/fixtures/variables.less' ), - vfsStream::url( 'compiled/fixtures/test.less' ), - ], - 'dependencies' => false, - 'in_footer' => false, - 'minify_js' => false, - 'version' => '1.5.0', - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the virtual directory. - $this->add_virtual_directory( $config['id'] ); - $expected_file = vfsStream::url( - 'compiled/beans/compiler/' . $config['id'] . '/' . $this->get_filename( $compiler, $config ) - ); - - // Run the compiler. Test. - $compiler->run_compiler(); - $actual_filename = $compiler->get_filename(); - $this->assertFileExists( $actual_filename ); - $this->assertSame( $expected_file, $actual_filename ); - $this->assertSame( $this->get_compiled_less(), $this->get_cached_contents( $compiler->filename, $config['id'] ) ); - } - - /** - * Get the filename from the compiler. - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler Instance of the compiler. - * - * @return string - */ - protected function get_actual_filename( $compiler ) { - $path = $compiler->get_filename(); - - if ( substr( $path, 0, 6 ) === 'vfs://' ) { - return $path; - } - - return str_replace( 'vfs:/', 'vfs://', $path ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-compiler/setFilename.php b/tests/phpunit/integration/api/compiler/beans-compiler/setFilename.php deleted file mode 100644 index b3bba301..00000000 --- a/tests/phpunit/integration/api/compiler/beans-compiler/setFilename.php +++ /dev/null @@ -1,163 +0,0 @@ -returnArg(); - } - - /** - * Test _Beans_Compiler::set_filename() should return the hash created with the modification time from each of the - * fragments. - */ - public function test_should_return_hash_created_with_fragments_filemtime() { - $fragment = vfsStream::url( 'compiled/fixtures/jquery.test.js' ); - $config = [ - 'id' => 'test-script', - 'type' => 'script', - 'format' => false, - 'fragments' => [ $fragment ], - 'dependencies' => false, - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the mocks. - $this->set_dev_mode( true ); - $this->add_virtual_directory( $config['id'] ); - - // Set the filename. Test. - $compiler->set_filename(); - $expected = $this->get_filename( $compiler, $config, filemtime( $fragment ) ); - $this->assertSame( $expected, $compiler->filename ); - } - - /** - * Test _Beans_Compiler::set_filename() should exclude external fragments. - */ - public function test_should_exclude_external_fragments() { - $fragment = vfsStream::url( 'compiled/fixtures/my-game-clock.js' ); - $config = [ - 'id' => 'test-script', - 'type' => 'script', - 'format' => false, - 'fragments' => [ - $fragment, - 'http://foo.com/my-script.js', // Should skip this one. - ], - 'dependencies' => false, - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the mocks. - $this->set_dev_mode( true ); - $this->add_virtual_directory( $config['id'] ); - - // Test that we are in dev mode & the directory does exist. - $this->assertTrue( _beans_is_compiler_dev_mode() ); - $this->directoryExists( vfsStream::url( 'compiled/beans/compiler/test-script' ) ); - $this->assertTrue( is_dir( $compiler->dir ) ); - - // Set the filename. Test. - $compiler->set_filename(); - $expected = $this->get_filename( $compiler, $config, filemtime( $fragment ) ); - $this->assertSame( $expected, $compiler->filename ); - } - - /** - * Test _Beans_Compiler::set_filename() should remove the old compiled file. - */ - public function test_should_remove_old_file() { - $fragment = vfsStream::url( 'compiled/fixtures/jquery.test.js' ); - $config = [ - 'id' => 'test', - 'type' => 'script', - 'format' => 'js', - 'fragments' => [ $fragment ], - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - 'version' => null, - ]; - $compiler = new _Beans_Compiler( $config ); - - // Set up the mocks. - $this->set_dev_mode( true ); - $this->add_virtual_directory( $config['id'] ); - - /** - * Set up the original "compiled" file. This is the file that should get removed during this - * test. We add the file into the virtual filesystem. - */ - $original_filemtime = filemtime( $fragment ); - $original_filename = $this->get_filename( $compiler, $config, $original_filemtime ); - vfsStream::newFile( $original_filename ) - ->at( $this->mock_filesystem->getChild( 'compiled/beans/compiler/' . $config['id'] ) ) - ->setContent( $this->get_compiled_jquery() ); - $original_hashes = explode( '-', pathinfo( $original_filename, PATHINFO_FILENAME ) ); - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/test/' . $original_filename ) ); - - /** - * Next step is to modify the fragment, which will change its modification time. Let's add an opening - * comment to the fragment's content and then set up the modified file for our tests. - */ - $file = $this->mock_filesystem->getChild( 'fixtures' )->getChild( 'jquery.test.js' ); - $file->write( "// changed \n" . $file->getContent() ); - $modified_filemtime = filemtime( $fragment ); - $modified_filename = $this->get_filename( $compiler, $config, $modified_filemtime ); - $modified_hashes = explode( '-', pathinfo( $modified_filename, PATHINFO_FILENAME ) ); - - /** - * We've now completed the set up process. Let's test that the original fragment has changed by - * testing that it is not equal to the modification time, filename, and hashes. - */ - $this->assertNotEquals( $modified_filemtime, $original_filemtime ); - $this->assertNotEquals( $modified_filename, $original_filename ); - $this->assertSame( $modified_hashes[0], $original_hashes[0] ); - $this->assertNotEquals( $modified_hashes[1], $original_hashes[1] ); - - /** - * Now let's run the compiler's set_filename() and test that: - * - * 1. The returned filename matches our modified filename. - * 2. The original "compiled" file was removed. - */ - $compiler->set_filename(); - $this->assertSame( $modified_filename, $compiler->filename ); - $this->assertFileNotExists( vfsStream::url( 'compiled/beans/compiler/test/' . $original_filename ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageScripts.php b/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageScripts.php deleted file mode 100644 index d88898f9..00000000 --- a/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageScripts.php +++ /dev/null @@ -1,209 +0,0 @@ -registered[ $handle ] ); - } - - $GLOBALS['wp_scripts']->done = []; - - parent::tearDown(); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when the scripts compiler is not supported. - */ - public function test_should_not_compile_when_scripts_compiler_not_supported() { - beans_remove_api_component_support( 'wp_scripts_compiler' ); - - Monkey\Functions\expect( 'get_option' )->with( 'beans_compile_all_scripts', false )->never(); - Monkey\Functions\expect( '_beans_is_compiler_dev_mode' )->never(); - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when the "compile all scripts" option is not - * set. - */ - public function test_should_not_compile_when_option_is_not_set() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - delete_option( 'beans_compile_all_scripts' ); - - Monkey\Functions\expect( '_beans_is_compiler_dev_mode' )->never(); - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when in dev mode. - */ - public function test_should_not_compile_when_in_dev_mode() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - update_option( 'beans_dev_mode', 1 ); - - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when there are no scripts. - */ - public function test_should_not_compile_when_there_are_no_scripts() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - delete_option( 'beans_dev_mode' ); - - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Run the tests. - $this->assertEmpty( $GLOBALS['wp_scripts']->queue ); - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when assets are admin bar only. - */ - public function test_should_not_compile_when_assets_are_admin_bar_only() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Enqueue the admin bar's script. - wp_enqueue_script( 'admin-bar' ); - $this->assertArrayHasKey( 'admin-bar', $GLOBALS['wp_scripts']->registered ); - $this->assertContains( 'admin-bar', $GLOBALS['wp_scripts']->queue ); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should not compile when scripts are not registered. - */ - public function test_should_not_compile_when_scripts_not_registered() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_js_fragments' )->never(); - - // Enqueue the admin bar's script. - wp_enqueue_script( 'admin-bar' ); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should compile when the script has src but no dependencies. - */ - public function test_should_compile_when_script_has_src_but_no_deps() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - - // Enqueue the scripts. - wp_enqueue_script( 'admin-bar' ); - wp_enqueue_script( 'test-compiler-js', '/foo/tests/compiler.js' ); - wp_enqueue_script( 'test-uikit-js', '/foo/tests/uikit.js' ); - - // Mock how beans_compile_js_fragments() will be called. - Monkey\Functions\expect( 'beans_compile_js_fragments' ) - ->once() - ->with( - 'beans', - [ - 'test-compiler-js' => '/foo/tests/compiler.js', - 'test-uikit-js' => '/foo/tests/uikit.js', - ], - [ - 'in_footer' => true, - 'version' => null, - ] - ) - ->andReturnNull(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_scripts() should compile scripts and dependencies. - */ - public function test_should_compile_scripts_and_deps() { - beans_add_api_component_support( 'wp_scripts_compiler' ); - update_option( 'beans_compile_all_scripts', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - - // Enqueue the scripts. - wp_enqueue_script( 'admin-bar' ); - wp_enqueue_script( 'test-compiler-js', '/foo/tests/compiler.js' ); - wp_enqueue_script( 'test-uikit-js', '/foo/tests/uikit.js', [ 'jquery' ] ); - - // Mock how beans_compile_js_fragments() will be called. - Monkey\Functions\expect( 'beans_compile_js_fragments' ) - ->once() - ->with( - 'beans', - [ - 'jquery-core' => $GLOBALS['wp_scripts']->registered['jquery-core']->src, - 'jquery-migrate' => $GLOBALS['wp_scripts']->registered['jquery-migrate']->src, - 'test-compiler-js' => '/foo/tests/compiler.js', - 'test-uikit-js' => '/foo/tests/uikit.js', - ], - [ - 'in_footer' => true, - 'version' => null, - ] - ) - ->andReturnNull(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_scripts() ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageStyles.php b/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageStyles.php deleted file mode 100644 index 8dedcf2e..00000000 --- a/tests/phpunit/integration/api/compiler/beans-page-compiler/compilePageStyles.php +++ /dev/null @@ -1,244 +0,0 @@ -registered[ $handle ] ); - } - - $GLOBALS['wp_styles']->done = []; - - parent::tearDown(); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when the styles compiler is not supported. - */ - public function test_should_not_compile_when_styles_compiler_not_supported() { - beans_remove_api_component_support( 'wp_styles_compiler' ); - - Monkey\Functions\expect( 'get_option' )->with( 'beans_compile_all_styles', false )->never(); - Monkey\Functions\expect( '_beans_is_compiler_dev_mode' )->never(); - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when the "compile all styles" option is not - * set. - */ - public function test_should_not_compile_when_option_is_not_set() { - beans_add_api_component_support( 'wp_styles_compiler' ); - delete_option( 'beans_compile_all_styles' ); - Monkey\Functions\expect( '_beans_is_compiler_dev_mode' )->never(); - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when in dev mode. - */ - public function test_should_not_compile_when_in_dev_mode() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - update_option( 'beans_dev_mode', 1 ); - Monkey\Functions\expect( 'beans_get' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when there are no styles. - */ - public function test_should_not_compile_when_there_are_no_styles() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Run the tests. - $this->assertEmpty( $GLOBALS['wp_styles']->queue ); - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when assets are admin bar only. - */ - public function test_should_not_compile_when_assets_are_admin_bar_only() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Enqueue the styles and then check that they are registered. - wp_enqueue_style( 'admin-bar' ); - wp_enqueue_style( 'open-sans' ); - wp_enqueue_style( 'dashicons' ); - $this->assertArrayHasKey( 'admin-bar', $GLOBALS['wp_styles']->registered ); - $this->assertContains( 'admin-bar', $GLOBALS['wp_styles']->queue ); - $this->assertArrayHasKey( 'open-sans', $GLOBALS['wp_styles']->registered ); - $this->assertContains( 'open-sans', $GLOBALS['wp_styles']->queue ); - $this->assertArrayHasKey( 'dashicons', $GLOBALS['wp_styles']->registered ); - $this->assertContains( 'dashicons', $GLOBALS['wp_styles']->queue ); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should not compile when the style is not registered. - */ - public function test_should_not_compile_when_style_is_not_registered() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - Monkey\Functions\expect( 'beans_compile_css_fragments' )->never(); - - // Enqueue the style. - wp_enqueue_style( 'admin-bar' ); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should compile when the style has src but no dependencies. - */ - public function test_should_compile_when_style_has_src_but_no_deps() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - - // Enqueue the styles. - wp_enqueue_style( 'admin-bar' ); - wp_enqueue_style( 'test-compiler-css', '/foo/tests/compiler.css' ); - wp_enqueue_style( 'test-uikit-css', '/foo/tests/uikit.css' ); - - // Mock how beans_compile_css_fragments() will be called. - Monkey\Functions\expect( 'beans_compile_css_fragments' ) - ->once() - ->with( - 'beans', - [ - 'test-compiler-css' => '/foo/tests/compiler.css', - 'test-uikit-css' => '/foo/tests/uikit.css', - ], - [ 'version' => null ] - ) - ->andReturnNull(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - - // Check the asset's done state. - $this->assertSame( [ 'test-compiler-css', 'test-uikit-css' ], $GLOBALS['wp_styles']->done ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should add the query arg to the compiled style's src. - */ - public function test_should_add_query_arg_to_compiled_style_src() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - - // Enqueue the styles. - wp_enqueue_style( 'admin-bar' ); - wp_enqueue_style( 'test-compiler-css', '/foo/tests/compiler.css', [], null, 'screen' ); - wp_enqueue_style( 'test-uikit-css', '/foo/tests/uikit.css', [], null, '(max-width: 640px)' ); - - // Mock how beans_compile_css_fragments() will be called. - Monkey\Functions\expect( 'beans_compile_css_fragments' ) - ->once() - ->with( - 'beans', - [ - 'test-compiler-css' => '/foo/tests/compiler.css?beans_compiler_media_query=screen', - 'test-uikit-css' => '/foo/tests/uikit.css?beans_compiler_media_query=(max-width: 640px)', - ], - [ 'version' => null ] - ) - ->andReturnNull(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - - // Check the asset's done state. - $this->assertSame( [ 'test-compiler-css', 'test-uikit-css' ], $GLOBALS['wp_styles']->done ); - } - - /** - * Test _Beans_Page_Compiler::compile_page_styles() should compile styles and dependencies. - */ - public function test_should_compile_styles_and_deps() { - beans_add_api_component_support( 'wp_styles_compiler' ); - update_option( 'beans_compile_all_styles', 1 ); - delete_option( 'beans_dev_mode' ); - Monkey\Functions\expect( 'add_query_arg' )->never(); - - // Enqueue the styles. - wp_enqueue_style( 'admin-bar' ); - wp_enqueue_style( 'test-compiler-css', '/foo/tests/compiler.css' ); - wp_enqueue_style( 'test-uikit-css', '/foo/tests/uikit.css', [ 'test-compiler-css' ] ); - - // Mock how beans_compile_css_fragments() will be called. - Monkey\Functions\expect( 'beans_compile_css_fragments' ) - ->once() - ->with( - 'beans', - [ - 'test-compiler-css' => '/foo/tests/compiler.css', - 'test-uikit-css' => '/foo/tests/uikit.css', - ], - [ 'version' => null ] - ) - ->andReturnNull(); - - // Run the tests. - $this->assertNull( ( new _Beans_Page_Compiler() )->compile_page_styles() ); - - // Check the asset's done state. - $this->assertSame( [ 'test-compiler-css', 'test-uikit-css' ], $GLOBALS['wp_styles']->done ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beans-page-compiler/dequeueScripts.php b/tests/phpunit/integration/api/compiler/beans-page-compiler/dequeueScripts.php deleted file mode 100644 index ad53250f..00000000 --- a/tests/phpunit/integration/api/compiler/beans-page-compiler/dequeueScripts.php +++ /dev/null @@ -1,130 +0,0 @@ -registered[ $handle ] ); - } - - $GLOBALS['wp_scripts']->done = []; - - parent::tearDown(); - } - - /** - * Test _Beans_Page_Compiler::dequeue_scripts() should not dequeue scripts when there are no scripts. - */ - public function test_should_not_dequeue_scripts_when_no_scripts() { - $this->assertNull( ( new _Beans_Page_Compiler() )->dequeue_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::dequeue_scripts() should not dequeue when no scripts are registered. - */ - public function test_should_not_dequeue_when_no_scripts_registered() { - $compiler = new _Beans_Page_Compiler(); - $dequeued_scripts = $this->get_reflective_property( 'dequeued_scripts', '_Beans_Page_Compiler' ); - $dequeued_scripts->setValue( $compiler, [ 'test-compiler-js', 'test-uikit-js' ] ); - - $this->assertNull( $compiler->dequeue_scripts() ); - } - - /** - * Test _Beans_Page_Compiler::dequeue_scripts() should dequeue scripts. - */ - public function test_should_dequeue_scripts() { - $compiler = new _Beans_Page_Compiler(); - $dequeued_scripts = $this->get_reflective_property( 'dequeued_scripts', '_Beans_Page_Compiler' ); - $dequeued_scripts->setValue( $compiler, [ - 'test-compiler-js' => '/foo/tests/compiler.js', - 'test-uikit-js' => '/foo/tests/uikit.js', - ] ); - - // Set up the scripts. - wp_enqueue_script( 'test-compiler-js', '/foo/tests/compiler.js' ); - wp_enqueue_script( 'test-uikit-js', '/foo/tests/uikit.js' ); - - // Run the tests. - $this->assertNull( $compiler->dequeue_scripts() ); - $this->assertSame( [ 'test-compiler-js', 'test-uikit-js' ], $GLOBALS['wp_scripts']->done ); - } - - /** - * Test _Beans_Page_Compiler::dequeue_scripts() should not print the inline localization when no scripts have - * localized data. - */ - public function test_should_not_print_inline_when_no_scripts_have_localized_data() { - $compiler = new _Beans_Page_Compiler(); - $dequeued_scripts = $this->get_reflective_property( 'dequeued_scripts', '_Beans_Page_Compiler' ); - $dequeued_scripts->setValue( $compiler, [ - 'test-compiler-js' => '/foo/tests/compiler.js', - 'test-uikit-js' => '/foo/tests/uikit.js', - ] ); - - // Set up the scripts. - wp_enqueue_script( 'test-compiler-js', '/foo/tests/compiler.js' ); - wp_enqueue_script( 'test-uikit-js', '/foo/tests/uikit.js' ); - - // Run the test. - ob_start(); - $compiler->dequeue_scripts(); - $this->assertSame( '', ob_get_clean() ); - } - - /** - * Test _Beans_Page_Compiler::dequeue_scripts() should print the inline localization content. - */ - public function test_should_print_inline_localization_content() { - $compiler = new _Beans_Page_Compiler(); - $dequeued_scripts = $this->get_reflective_property( 'dequeued_scripts', '_Beans_Page_Compiler' ); - $dequeued_scripts->setValue( $compiler, [ - 'test-compiler-js' => '/foo/tests/compiler.js', - 'test-uikit-js' => '/foo/tests/uikit.js', - ] ); - - // Set up the scripts. - wp_enqueue_script( 'test-compiler-js', '/foo/tests/compiler.js' ); - wp_localize_script( 'test-compiler-js', 'testParams', 'hello-beans' ); - wp_enqueue_script( 'test-uikit-js', '/foo/tests/uikit.js' ); - - // Run the tests. - ob_start(); - $compiler->dequeue_scripts(); - $inline_script = ob_get_clean(); - - $expected = << - var testParams = "hello-beans"; - - -EOB; - - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $inline_script ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansCompileCssFragments.php b/tests/phpunit/integration/api/compiler/beansCompileCssFragments.php deleted file mode 100644 index 3b71aa01..00000000 --- a/tests/phpunit/integration/api/compiler/beansCompileCssFragments.php +++ /dev/null @@ -1,44 +0,0 @@ -add_virtual_directory( $id ); - $path = vfsStream::url( "compiled/beans/compiler/{$id}/" ); - - // Run the tests. - $this->assertEmpty( $this->get_compiled_filename( $path ) ); - beans_compile_css_fragments( $id, $fragment ); - $filename = $this->get_compiled_filename( $path ); - $this->assertFileExists( $path . $filename ); - $this->assertStringEndsWith( '.css', $filename ); - $this->assertSame( $this->get_compiled_css(), $this->get_cached_contents( $filename, $id ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansCompileJsFragments.php b/tests/phpunit/integration/api/compiler/beansCompileJsFragments.php deleted file mode 100644 index ea83f029..00000000 --- a/tests/phpunit/integration/api/compiler/beansCompileJsFragments.php +++ /dev/null @@ -1,99 +0,0 @@ -add_virtual_directory( $id ); - $path = vfsStream::url( "compiled/beans/compiler/{$id}/" ); - - // Run the tests. - $this->assertEmpty( $this->get_compiled_filename( $path ) ); - beans_compile_js_fragments( $id, $fragment, [ - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - ] ); - $filename = $this->get_compiled_filename( $path ); - $this->assertFileExists( $path . $filename ); - $this->assertStringEndsWith( '.js', $filename ); - $this->assertSame( $this->get_compiled_jquery(), $this->get_cached_contents( $filename, $id ) ); - } - - /** - * Test beans_compile_js_fragments() should compile the JS fragment, saving it to the virtual filesystem and - * enqueuing it in WordPress. - */ - public function test_should_compile_save_and_enqueue_js() { - $id = 'test-js'; - $fragment = vfsStream::url( 'compiled/fixtures/my-game-clock.js' ); - $this->add_virtual_directory( $id ); - $path = vfsStream::url( "compiled/beans/compiler/{$id}/" ); - - // Run the tests. - $this->assertEmpty( $this->get_compiled_filename( $path ) ); - beans_compile_js_fragments( $id, $fragment, [ - 'in_footer' => true, - 'minify_js' => true, - ] ); - $filename = $this->get_compiled_filename( $path ); - $this->assertFileExists( $path . $filename ); - $this->assertStringEndsWith( '.js', $filename ); - $this->assertSame( $this->get_compiled_js(), $this->get_cached_contents( $filename, $id ) ); - } - - /** - * Test beans_compile_js_fragments() should compile the combined JS fragments, saving it to the virtual filesystem - * and enqueuing it in WordPress. - */ - public function test_should_compile_save_and_enqueue_combined_js() { - $id = 'test-js'; - $fragments = [ - vfsStream::url( 'compiled/fixtures/my-game-clock.js' ), - vfsStream::url( 'compiled/fixtures/jquery.test.js' ), - ]; - $this->add_virtual_directory( $id ); - $path = vfsStream::url( "compiled/beans/compiler/{$id}/" ); - - // Run the tests. - $this->assertEmpty( $this->get_compiled_filename( $path ) ); - beans_compile_js_fragments( $id, $fragments, [ - 'dependencies' => [ 'jquery' ], - 'in_footer' => true, - 'minify_js' => true, - ] ); - $filename = $this->get_compiled_filename( $path ); - $this->assertFileExists( $path . $filename ); - $this->assertStringEndsWith( '.js', $filename ); - - $contents = $this->get_cached_contents( $filename, $id ); - $this->assertContains( $this->get_compiled_js(), $contents ); - $this->assertContains( $this->get_compiled_jquery(), $contents ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansCompileLessFragments.php b/tests/phpunit/integration/api/compiler/beansCompileLessFragments.php deleted file mode 100644 index 5fe9b0a1..00000000 --- a/tests/phpunit/integration/api/compiler/beansCompileLessFragments.php +++ /dev/null @@ -1,47 +0,0 @@ -add_virtual_directory( $id ); - $path = vfsStream::url( "compiled/beans/compiler/{$id}/" ); - - // Run the tests. - $this->assertEmpty( $this->get_compiled_filename( $path ) ); - beans_compile_less_fragments( $id, $fragments ); - $filename = $this->get_compiled_filename( $path ); - $this->assertFileExists( $path . $filename ); - $this->assertStringEndsWith( '.css', $filename ); - $this->assertSame( $this->get_compiled_less(), $this->get_cached_contents( $filename, $id ) ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansFlushCompiler.php b/tests/phpunit/integration/api/compiler/beansFlushCompiler.php deleted file mode 100644 index 198c7efd..00000000 --- a/tests/phpunit/integration/api/compiler/beansFlushCompiler.php +++ /dev/null @@ -1,112 +0,0 @@ -never(); - - $this->assertNull( beans_flush_compiler( 'beans' ) ); - } - - /** - * Test beans_flush_compiler() should remove cached CSS file. - */ - public function test_should_remove_cached_css_file() { - $this->overwrite_virtual_filesystem(); - - // Check that both files exist before we start. - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - - // Run it. - $this->assertNull( beans_flush_compiler( 'beans', 'css' ) ); - - // Check that only the CSS file was removed. - $this->assertFileNotExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - } - - - /** - * Test beans_flush_compiler() should remove cached JS file. - */ - public function test_should_remove_cached_js_file() { - $this->overwrite_virtual_filesystem(); - - // Check that both files exist before we start. - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - - // Run it. - $this->assertNull( beans_flush_compiler( 'beans', 'js' ) ); - - // Check that only the JS file was removed. - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileNotExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - } - - /** - * Test beans_flush_compiler() should remove all cached files. - */ - public function test_should_remove_all_cached_files() { - $this->overwrite_virtual_filesystem(); - - // Check that both files exist before we start. - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - - // Run it. - $this->assertNull( beans_flush_compiler( 'beans' ) ); - - // Check that the files and directory were removed. - $this->assertFileNotExists( vfsStream::url( 'compiled/beans/compiler/beans/1234567-9876543.css' ) ); - $this->assertFileNotExists( vfsStream::url( 'compiled/beans/compiler/beans/abcd3fg-hijklmn.js' ) ); - $this->assertDirectoryNotExists( vfsStream::url( 'compiled/beans/compiler/beans' ) ); - $this->assertDirectoryNotExists( vfsStream::url( 'compiled/beans/compiler/beans/' ) ); - } - - /** - * Overwrites the virtual filesystem for this test. - */ - private function overwrite_virtual_filesystem() { - $this->mock_filesystem = vfsStream::setup( - 'compiled', - 0755, - [ - 'beans' => [ - 'compiler' => [ - 'beans' => [ - '1234567-9876543.css' => $this->get_compiled_css(), - 'abcd3fg-hijklmn.js' => $this->get_compiled_js(), - ], - ], - ], - ] - ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansGetCompilerDir.php b/tests/phpunit/integration/api/compiler/beansGetCompilerDir.php deleted file mode 100644 index 59aae7d0..00000000 --- a/tests/phpunit/integration/api/compiler/beansGetCompilerDir.php +++ /dev/null @@ -1,45 +0,0 @@ -assertSame( - vfsStream::url( 'compiled/beans/compiler/' ), - beans_get_compiler_dir() - ); - } - - /** - * Test beans_get_compiler_dir() should return the absolute path to the Beans' uploads admin compiler folder. - */ - public function test_should_return_absolute_path_to_compiler_admin_folder() { - $this->assertSame( - vfsStream::url( 'compiled/beans/admin-compiler/' ), - beans_get_compiler_dir( true ) - ); - } -} diff --git a/tests/phpunit/integration/api/compiler/beansGetCompilerUrl.php b/tests/phpunit/integration/api/compiler/beansGetCompilerUrl.php deleted file mode 100644 index 00249d0a..00000000 --- a/tests/phpunit/integration/api/compiler/beansGetCompilerUrl.php +++ /dev/null @@ -1,44 +0,0 @@ -assertSame( - site_url( 'compiled/beans/compiler/' ), - beans_get_compiler_url() - ); - } - - /** - * Test should return the URL to the Beans' admin compiler folder. - */ - public function test_should_return_url_to_compiler_admin_folder() { - $this->assertSame( - site_url( 'compiled/beans/admin-compiler/' ), - beans_get_compiler_url( true ) - ); - } -} diff --git a/tests/phpunit/integration/api/compiler/fixtures/jquery.test.js b/tests/phpunit/integration/api/compiler/fixtures/jquery.test.js deleted file mode 100644 index 73d60dc5..00000000 --- a/tests/phpunit/integration/api/compiler/fixtures/jquery.test.js +++ /dev/null @@ -1,29 +0,0 @@ -(function( $ ){ - 'use strict'; - - /** - * Initialize the script. - */ - var init = function() { - $( 'some-button' ).on( 'click', clickHandler ); - } - - /** - * Handle the button's click event. - * - * @param event - */ - var clickHandler = function( event ) { - event.preventDefault(); - - // do something cool here. - } - - /** - * Wait until the document is ready. - */ - $( document ).ready( function(){ - init(); - }); - -})( jQuery ); diff --git a/tests/phpunit/integration/api/compiler/fixtures/my-game-clock.js b/tests/phpunit/integration/api/compiler/fixtures/my-game-clock.js deleted file mode 100644 index ac082973..00000000 --- a/tests/phpunit/integration/api/compiler/fixtures/my-game-clock.js +++ /dev/null @@ -1,21 +0,0 @@ -class MyGameClock { - - /** - * Creates an instance of MyGameClock. - * - * @param maxTime Clock's timeout increment. - */ - constructor( maxTime ) { - this.maxTime = maxTime; - this.currentClock = 0; - } - - /** - * Get the remaining time on the clock. - * - * @returns {number} - */ - getRemainingTime() { - return this.maxTime - this.currentClock; - } -} \ No newline at end of file diff --git a/tests/phpunit/integration/api/compiler/fixtures/style.css b/tests/phpunit/integration/api/compiler/fixtures/style.css deleted file mode 100644 index a5aa904b..00000000 --- a/tests/phpunit/integration/api/compiler/fixtures/style.css +++ /dev/null @@ -1,16 +0,0 @@ -/*! - Stylesheet. - */ -body { - background-color: #fff; - color: #000; - font-size: 18px; -} - -a { - color: #cc0000; -} - -p { - margin-bottom: 30px; -} diff --git a/tests/phpunit/integration/api/compiler/fixtures/test.less b/tests/phpunit/integration/api/compiler/fixtures/test.less deleted file mode 100644 index fcda49a7..00000000 --- a/tests/phpunit/integration/api/compiler/fixtures/test.less +++ /dev/null @@ -1,7 +0,0 @@ -@test-font-size: 18px; - -body { - background-color: #fff; - color: @body-color; - font-size: @test-font-size; -} diff --git a/tests/phpunit/integration/api/compiler/fixtures/variables.less b/tests/phpunit/integration/api/compiler/fixtures/variables.less deleted file mode 100644 index 18615d17..00000000 --- a/tests/phpunit/integration/api/compiler/fixtures/variables.less +++ /dev/null @@ -1,8 +0,0 @@ -/** -These are the global variables. - */ -@body-color: #000; -@link-color: #039460; -@hover-color: #016F47; -@base-font: normal 18px / 22px "Helvetica Neue",Helvetica,Arial,sans-serif; -@base-font-size: 18px; /* this is an inline comment */ \ No newline at end of file diff --git a/tests/phpunit/integration/api/compiler/includes/class-base-test-case.php b/tests/phpunit/integration/api/compiler/includes/class-base-test-case.php deleted file mode 100644 index 818d815b..00000000 --- a/tests/phpunit/integration/api/compiler/includes/class-base-test-case.php +++ /dev/null @@ -1,104 +0,0 @@ -set_up_virtual_filesystem(); - $this->compiled_dir = vfsStream::url( 'compiled' ); - - // Set the Uploads directory to our virtual filesystem. - add_filter( 'upload_dir', function( array $uploads_dir ) { - $uploads_dir['path'] = $this->compiled_dir . $uploads_dir['subdir']; - $uploads_dir['url'] = str_replace( 'wp-content/uploads', 'compiled', $uploads_dir['url'] ); - $uploads_dir['basedir'] = $this->compiled_dir; - $uploads_dir['baseurl'] = str_replace( 'wp-content/uploads', 'compiled', $uploads_dir['baseurl'] ); - - return $uploads_dir; - } ); - } - - /** - * Cleans up the test environment after each test. - */ - public function tearDown() { - Mockery::close(); - parent::tearDown(); - } - - /** - * Set up the virtual filesystem. - */ - protected function set_up_virtual_filesystem() { - $this->mock_filesystem = vfsStream::setup( - 'compiled', - 0755, - $this->get_virtual_structure() - ); - } - - /** - * Get the virtual filesystem's structure. - */ - protected function get_virtual_structure() { - return [ - 'beans' => [ - 'compiler' => [ - 'index.php' => '', - ], - 'admin-compiler' => [ - 'index.php' => '', - ], - ], - ]; - } - - /** - * Set Development Mode. - * - * @since 1.5.0 - * - * @param bool $is_enabled Optional. When true, turns on development mode. Default is false. - * - * @return void - */ - protected function set_dev_mode( $is_enabled = false ) { - update_option( 'beans_dev_mode', $is_enabled ); - } -} diff --git a/tests/phpunit/integration/api/compiler/includes/class-compiler-options-test-case.php b/tests/phpunit/integration/api/compiler/includes/class-compiler-options-test-case.php deleted file mode 100644 index bda86590..00000000 --- a/tests/phpunit/integration/api/compiler/includes/class-compiler-options-test-case.php +++ /dev/null @@ -1,48 +0,0 @@ -assertTrue( is_admin() ); - } -} diff --git a/tests/phpunit/integration/api/compiler/includes/class-compiler-test-case.php b/tests/phpunit/integration/api/compiler/includes/class-compiler-test-case.php deleted file mode 100644 index c915c8e2..00000000 --- a/tests/phpunit/integration/api/compiler/includes/class-compiler-test-case.php +++ /dev/null @@ -1,327 +0,0 @@ - [], - 'less' => [], - 'js' => [], - ]; - - // Return the virtual filesystem's path to avoid wp_normalize_path converting its prefix from vfs::// to vfs:/. - Monkey\Functions\when( 'wp_normalize_path' )->returnArg(); - } - - /** - * Cleans up the test environment after each test. - */ - public function tearDown() { - wp_dequeue_script( 'test-jquery' ); - unset( $GLOBALS['wp_scripts']->registered['test-jquery'] ); - wp_dequeue_script( 'test-script' ); - unset( $GLOBALS['wp_scripts']->registered['test-script'] ); - wp_dequeue_script( 'test-js' ); - unset( $GLOBALS['wp_scripts']->registered['test-js'] ); - wp_dequeue_style( 'test-css' ); - unset( $GLOBALS['wp_styles']->registered['test-css'] ); - unset( $GLOBALS['wp_filesystem'] ); - parent::tearDown(); - } - - /** - * Set up the virtual filesystem. - */ - protected function set_up_virtual_filesystem() { - parent::set_up_virtual_filesystem(); - - // Set the fixture file dates back a week. - $fixtures_dir = $this->mock_filesystem->getChild( 'fixtures' ); - $file_modification_time = time() - ( 7 * 24 * 60 * 60 ); - foreach ( static::$fixture_filenames as $filename ) { - $fixtures_dir->getChild( $filename )->lastModified( $file_modification_time ); - } - } - - /** - * Get the virtual filesystem's structure. - */ - protected function get_virtual_structure() { - $structure = parent::get_virtual_structure(); - $structure['fixtures'] = $this->get_fixtures_content(); - - return $structure; - } - - /** - * Get the test fixture's content. - */ - private function get_fixtures_content() { - $fixtures = []; - - foreach ( static::$fixture_filenames as $filename ) { - $fixtures[ $filename ] = file_get_contents( static::$fixtures_dir . $filename ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_get_contents, WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Valid edge case. - } - - return $fixtures; - } - - /** - * Add the virtual directory to the filesystem. - * - * @since 1.5.0 - * - * @param string $dir_name Directory name. - * @param string $root_dir Optional. Root directory(ies) for the new directory. - * - * @return void - */ - protected function add_virtual_directory( $dir_name, $root_dir = 'compiled/beans/compiler' ) { - vfsStream::newDirectory( $dir_name )->at( $this->mock_filesystem->getChild( $root_dir ) ); - } - - /** - * Set the protected property "current_fragment". - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler The Compiler instance. - * @param mixed $fragment The given value to set. - * - * @return void - * @throws \ReflectionException Throws reflection error. - */ - protected function set_current_fragment( $compiler, $fragment ) { - $current_fragment = ( new \ReflectionClass( $compiler ) )->getProperty( 'current_fragment' ); - $current_fragment->setAccessible( true ); - $current_fragment->setValue( $compiler, $fragment ); - $current_fragment->setAccessible( false ); - } - - /** - * Get the filename. - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler Instance of the compiler. - * @param array $config The compiler's configuration. - * @param int $filemtime Optional. The fragment's filemtime. Default is null. - * - * @return string - */ - protected function get_filename( $compiler, $config, $filemtime = null ) { - - if ( is_null( $filemtime ) ) { - foreach ( $config['fragments'] as $index => $fragment ) { - $filemtimes[ $index ] = filemtime( $fragment ); - } - } else { - $filemtimes = [ $filemtime ]; - } - - return sprintf( - '%s-%s.%s', - $compiler->hash( $config ), - $compiler->hash( $filemtimes ), - 'style' === $config['type'] ? 'css' : 'js' - ); - } - - /** - * Set up the filesystem mocks for the fragments. - * - * @since 1.5.0 - * - * @param _Beans_Compiler $compiler Instance of the Compiler. - * @param int $times_called Optional. Number of times the mock will be called. Default is 1. - * @param string $class Mock's class name. - * - * @return void - */ - protected function mock_filesystem_for_fragments( - $compiler, - $times_called = 1, - $class = 'WP_Filesystem_Direct_Mock' - ) { - - if ( ! defined( 'FS_CHMOD_FILE' ) ) { - define( 'FS_CHMOD_FILE', 0644 ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound -- Valid constant. - } - - unset( $GLOBALS['wp_filesystem'] ); - - // Now set up the mock. - $mock = Mockery::mock( $class ); - - foreach ( $compiler->config['fragments'] as $fragment ) { - $mock->shouldReceive( 'get_contents' ) - ->times( $times_called ) - ->with( $fragment ) - ->andReturn( file_get_contents( $fragment ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, WordPress.WP.AlternativeFunctions.file_system_read_file_get_contents -- Valid in this edge case. - } - - $GLOBALS['wp_filesystem'] = $mock; // phpcs:ignore WordPress.Variables.GlobalVariables.OverrideProhibited -- Valid use case, as we are mocking the filesystem. - } - - /** - * Get the file's content. - * - * @since 1.5.0 - * - * @param string $filename Name of the file. - * @param string $id File's ID. - * - * @return string - */ - protected function get_cached_contents( $filename, $id ) { - return $this->mock_filesystem - ->getChild( 'beans/compiler/' . $id ) - ->getChild( $filename ) - ->getContent(); - } - - /** - * Get the compiled file's name. - * - * @param string $path The virtual filesystem's path. - * - * @return string - */ - protected function get_compiled_filename( $path ) { - $files = beans_scandir( $path ); - - if ( empty( $files ) ) { - return ''; - } - - return array_pop( $files ); - } - - /** - * Get the compiled jQuery. - * - * @since 1.5.0 - * - * @return string - */ - protected function get_compiled_jquery() { - $compiled_content = <<merge_field_with_default( [ - 'id' => 'beans_compile_all_styles', - 'label' => false, - 'checkbox_label' => 'Compile all WordPress styles', - 'type' => 'checkbox', - 'default' => false, - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field( $field ); - $html = ob_get_clean(); - - $expected = << -
-
- - - Compile all WordPress styles -
-
- -EOB; - // Run the tests. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - $this->assertEquals( 1, did_action( 'beans_field_checkbox' ) ); - $this->assertEquals( 0, did_action( 'beans_field_group_label' ) ); - - // Clean up. - beans_remove_action( 'beans_field_checkbox', 'beans_field_checkbox' ); - } - - /** - * Test beans_field() should render the radio field. - */ - public function test_should_render_radio_field() { - // Set up the test. - require_once BEANS_THEME_DIR . '/lib/api/fields/types/radio.php'; - beans_add_smart_action( 'beans_field_radio', 'beans_field_radio' ); - $field = $this->merge_field_with_default( [ - 'id' => 'beans_radio_test', - 'label' => 'Having fun?', - 'description' => 'Radio buttons', - 'type' => 'radio', - 'default' => 'no', - 'options' => [ - 'no' => 'No', - 'yes' => 'Yes', - ], - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field( $field ); - $html = ob_get_clean(); - - $expected = << -
-
-
- Having fun? - - -
-
-
-
Radio buttons
- -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - $this->assertEquals( 1, did_action( 'beans_field_radio' ) ); - $this->assertEquals( 0, did_action( 'beans_field_group_label' ) ); - - // Clean up. - beans_remove_action( 'beans_field_radio', 'beans_field_radio' ); - } - - /** - * Test beans_field() should render a group of fields. - */ - public function test_should_render_group_of_fields() { - // Set up the test. - require_once BEANS_THEME_DIR . '/lib/api/fields/types/activation.php'; - require_once BEANS_THEME_DIR . '/lib/api/fields/types/select.php'; - beans_add_smart_action( 'beans_field_activation', 'beans_field_activation' ); - beans_add_smart_action( 'beans_field_select', 'beans_field_select' ); - - // Prepare the group of fields. - $group = $this->merge_field_with_default( [ - 'id' => 'beans_group_test', - 'label' => 'Group of fields', - 'description' => 'This is a group of fields.', - 'type' => 'group', - 'context' => 'beans_group_tests', - 'fields' => [ - [ - 'id' => 'beans_group_activation_test', - 'label' => 'Activate Foo', - 'type' => 'activation', - 'default' => false, - ], - [ - 'id' => 'beans_group_select_test', - 'label' => 'Select Foo', - 'type' => 'select', - 'default' => 'aggressive', - 'attributes' => [ 'style' => 'margin: -3px 0 0 -8px;' ], - 'options' => [ - 'aggressive' => 'Aggressive', - 'standard' => 'Standard', - ], - ], - ], - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field( $group ); - $html = ob_get_clean(); - - $expected = << -
-
- Group of fields -
- - - -
-
- - -
-
-
-
This is a group of fields.
- -EOB; - // Run the tests. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - $this->assertEquals( 2, did_action( 'beans_field_group_label' ) ); - $this->assertEquals( 1, did_action( 'beans_field_activation' ) ); - $this->assertEquals( 1, did_action( 'beans_field_select' ) ); - - // Clean up. - beans_remove_action( 'beans_field_activation', 'beans_field_activation' ); - beans_remove_action( 'beans_field_select', 'beans_field_select' ); - } - - /** - * Test should render the single field. This is a full integration test for the Fields API. - */ - public function test_full_integration_should_render_single_field() { - $test_data = static::$test_data['single_fields']; - - // Register the fields. - beans_register_fields( $test_data['fields'], 'beans_tests', $test_data['section'] ); - $fields = beans_get_fields( 'beans_tests', $test_data['section'] ); - - // Register the checkbox, label, and description callbacks (as they've been unregistered in previous tests). - add_action( 'beans_field_checkbox', 'beans_field_checkbox' ); - add_action( 'beans_field_group_label', 'beans_field_label' ); - add_action( 'beans_field_wrap_prepend_markup', 'beans_field_label' ); - add_action( 'beans_field_wrap_append_markup', 'beans_field_description' ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field( $fields[1] ); - $html = ob_get_clean(); - - $expected = << -
-
- - - Enable the checkbox test -
-
- -EOB; - // Check the HTML. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - - // Clean up. - remove_action( 'beans_field_checkbox', 'beans_field_checkbox' ); - remove_action( 'beans_field_group_label', 'beans_field_label' ); - remove_action( 'beans_field_wrap_prepend_markup', 'beans_field_label' ); - remove_action( 'beans_field_wrap_append_markup', 'beans_field_description' ); - } - - /** - * Test should render a group of fields. This is a full integration test for the Fields API. - */ - public function test_full_integration_should_render_group_of_fields() { - $test_data = static::$test_data['group']; - - // Register the fields. - beans_register_fields( $test_data['fields'], 'beans_tests', $test_data['section'] ); - $fields = beans_get_fields( 'beans_tests', $test_data['section'] ); - - // Register each field's callback (as it's been unregistered in previous tests). - foreach ( $test_data['fields'][0]['fields'] as $field ) { - add_action( 'beans_field_' . $field['type'], 'beans_field_' . $field['type'] ); - } - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field( $fields[0] ); - $html = ob_get_clean(); - - $expected = << -
-
- Group of fields -
- - - -
-
- -
-
- - - Enable the checkbox test -
-
-
-
This is a group of fields.
- -EOB; - // Check the HTML. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - - // Clean up. - foreach ( $test_data['fields'][0]['fields'] as $field ) { - remove_action( 'beans_field_' . $field['type'], 'beans_field_' . $field['type'] ); - } - } -} diff --git a/tests/phpunit/integration/api/fields/beansGetFields.php b/tests/phpunit/integration/api/fields/beansGetFields.php deleted file mode 100644 index 9b1ba4c7..00000000 --- a/tests/phpunit/integration/api/fields/beansGetFields.php +++ /dev/null @@ -1,44 +0,0 @@ - [ - $test_data['section'] => $test_data['fields'], - ], - ]; - - // Register the fields first. - $registered = $this->get_reflective_property( 'registered', '_Beans_Fields' ); - $registered->setValue( new \_Beans_Fields(), $data_set ); - - $this->assertSame( $data_set['beans_tests'][ $test_data['section'] ], beans_get_fields( 'beans_tests', $test_data['section'] ) ); - } - } -} diff --git a/tests/phpunit/integration/api/fields/beansPreStandardizeFields.php b/tests/phpunit/integration/api/fields/beansPreStandardizeFields.php deleted file mode 100644 index 1f747974..00000000 --- a/tests/phpunit/integration/api/fields/beansPreStandardizeFields.php +++ /dev/null @@ -1,55 +0,0 @@ -assertArrayHasKey( $field['id'], $fields ); - $this->assertSame( $field, $fields[ $field['id'] ] ); - } - } - - /** - * Test _beans_pre_standardize_fields() should pre-standardize a group of fields. - */ - public function test_should_pre_standardize_group_of_fields() { - $actual = _beans_pre_standardize_fields( static::$test_data['group']['fields'] ); - - foreach ( static::$test_data['group']['fields'] as $group ) { - $this->assertArrayHasKey( $group['id'], $actual ); - - $actual_fields = $actual[ $group['id'] ]['fields']; - - // Check each of the grouped fields. - foreach ( $group['fields'] as $field ) { - $this->assertArrayHasKey( $field['id'], $actual_fields ); - $this->assertSame( $field, $actual_fields[ $field['id'] ] ); - } - } - } -} diff --git a/tests/phpunit/integration/api/fields/beansRegisterFields.php b/tests/phpunit/integration/api/fields/beansRegisterFields.php deleted file mode 100644 index 7cb1ada1..00000000 --- a/tests/phpunit/integration/api/fields/beansRegisterFields.php +++ /dev/null @@ -1,54 +0,0 @@ -assertFalse( beans_register_fields( [], '', '' ) ); - $this->assertFalse( beans_register_fields( [], 'post_meta', 'tm-beans' ) ); - } - - /** - * Test beans_register_fields() should register the fields. - */ - public function test_should_register_fields() { - $test_data = static::$test_data['single_fields']; - - $this->assertTrue( beans_register_fields( $test_data['fields'], 'beans_tests', $test_data['section'] ) ); - - // Check what was registered. - $registered_property = $this->get_reflective_property( 'registered', '_Beans_Fields' ); - $registered = $registered_property->getValue( new _Beans_Fields() ); - - $this->assertArrayHasKey( 'beans_tests', $registered ); - $this->assertArrayHasKey( $test_data['section'], $registered['beans_tests'] ); - - foreach ( $test_data['fields'] as $index => $field ) { - $expected = $this->merge_field_with_default( $field ); - $this->assertSame( $expected, $registered['beans_tests'][ $test_data['section'] ][ $index ] ); - } - } -} diff --git a/tests/phpunit/integration/api/fields/fixtures/test-fields.php b/tests/phpunit/integration/api/fields/fixtures/test-fields.php deleted file mode 100644 index 1b5d6533..00000000 --- a/tests/phpunit/integration/api/fields/fixtures/test-fields.php +++ /dev/null @@ -1,80 +0,0 @@ - [ - 'fields' => [ - [ - 'id' => 'beans_layout', - 'label' => 'Layout', - 'type' => 'radio', - 'default' => 'default_fallback', - 'options' => [ - 'default_fallback' => 'Use Default Layout', - 'c' => BEANS_THEME_DIR . 'lib/admin/assets/images/layouts/c.png', - 'c_sp' => BEANS_THEME_DIR . 'lib/admin/assets/images/layouts/c_sp.png', - 'sp_c' => BEANS_THEME_DIR . 'lib/admin/assets/images/layouts/sp_c.png', - ], - ], - [ - 'id' => 'beans_checkbox_test', - 'label' => false, - 'checkbox_label' => 'Enable the checkbox test', - 'type' => 'checkbox', - 'default' => false, - ], - [ - 'id' => 'beans_text_test', - 'type' => 'text', - 'default' => 'Testing the text field.', - ], - ], - 'context' => 'tests', - 'section' => 'tm-beans', - ], - - // Group of fields. - 'group' => [ - 'fields' => [ - [ - 'id' => 'beans_group_test', - 'label' => 'Group of fields', - 'description' => 'This is a group of fields.', - 'type' => 'group', - 'fields' => [ - [ - 'id' => 'beans_compile_all_scripts', - 'type' => 'activation', - 'default' => false, - ], - [ - 'id' => 'beans_compile_all_scripts_mode', - 'type' => 'select', - 'default' => 'aggressive', - 'attributes' => [ 'style' => 'margin: -3px 0 0 -8px;' ], - 'options' => [ - 'aggressive' => 'Aggressive', - 'standard' => 'Standard', - ], - ], - [ - 'id' => 'beans_checkbox_test', - 'label' => false, - 'checkbox_label' => 'Enable the checkbox test', - 'type' => 'checkbox', - 'default' => false, - ], - ], - ], - ], - 'context' => 'group_tests', - 'section' => 'tm-beans', - ], -]; diff --git a/tests/phpunit/integration/api/fields/includes/class-fields-test-case.php b/tests/phpunit/integration/api/fields/includes/class-fields-test-case.php deleted file mode 100644 index da4c0285..00000000 --- a/tests/phpunit/integration/api/fields/includes/class-fields-test-case.php +++ /dev/null @@ -1,93 +0,0 @@ - false, - 'description' => false, - 'default' => false, - 'context' => 'beans_tests', - 'attributes' => [], - 'db_group' => false, - ], $field ); - $field['name'] = 'beans_fields[' . $field['id'] . ']'; - - if ( 'group' === $field['type'] ) { - - foreach ( $field['fields'] as $index => $_field ) { - $field['fields'][ $index ] = $this->merge_field_with_default( $_field, $set_value ); - } - } elseif ( $set_value ) { - $field['value'] = $field['default']; - } - - return $field; - } -} diff --git a/tests/phpunit/integration/api/fields/types/beansFieldActivation.php b/tests/phpunit/integration/api/fields/types/beansFieldActivation.php deleted file mode 100644 index ca2052d1..00000000 --- a/tests/phpunit/integration/api/fields/types/beansFieldActivation.php +++ /dev/null @@ -1,85 +0,0 @@ -merge_field_with_default( [ - 'id' => 'beans_compile_all_scripts', - 'type' => 'activation', - 'default' => false, - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_activation( $field ); - $html = ob_get_clean(); - - $expected = << - - -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } - - /** - * Test beans_field_activation() should render the activation field with attributes when given. - */ - public function test_should_render_activation_field_with_attributes_when_given() { - $field = $this->merge_field_with_default( [ - 'id' => 'beans_compile_all_scripts', - 'type' => 'activation', - 'default' => false, - 'attributes' => [ - 'data-test' => 'foo', - ], - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_activation( $field ); - $html = ob_get_clean(); - - $expected = << - - -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } -} diff --git a/tests/phpunit/integration/api/fields/types/beansFieldCheckbox.php b/tests/phpunit/integration/api/fields/types/beansFieldCheckbox.php deleted file mode 100644 index 10d86c97..00000000 --- a/tests/phpunit/integration/api/fields/types/beansFieldCheckbox.php +++ /dev/null @@ -1,112 +0,0 @@ -merge_field_with_default( [ - 'id' => 'beans_compile_all_styles', - 'label' => false, - 'checkbox_label' => 'Compile all WordPress styles', - 'type' => 'checkbox', - 'default' => false, - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_checkbox( $field ); - $html = ob_get_clean(); - - $expected = << - -Compile all WordPress styles -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } - - /** - * Test beans_field_checkbox() should render the checkbox with the default label when none is given. - */ - public function test_should_render_checkbox_with_default_label_when_none_is_given() { - $field = $this->merge_field_with_default( [ - 'id' => 'beans_compile_all_styles', - 'type' => 'checkbox', - 'default' => false, - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_checkbox( $field ); - $html = ob_get_clean(); - - $expected = << - -Enable -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } - - /** - * Test beans_field_checkbox() should render the checkbox with attributes when given. - */ - public function test_should_render_checkbox_with_attributes_when_given() { - $field = $this->merge_field_with_default( [ - 'id' => 'beans_compile_all_styles', - 'checkbox_label' => 'Compile all WordPress styles', - 'type' => 'checkbox', - 'default' => false, - 'attributes' => [ - 'data-test' => 'foo', - ], - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_checkbox( $field ); - $html = ob_get_clean(); - - $expected = << - -Compile all WordPress styles -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } -} diff --git a/tests/phpunit/integration/api/fields/types/beansFieldDescription.php b/tests/phpunit/integration/api/fields/types/beansFieldDescription.php deleted file mode 100644 index eee8a65a..00000000 --- a/tests/phpunit/integration/api/fields/types/beansFieldDescription.php +++ /dev/null @@ -1,100 +0,0 @@ -merge_field_with_default( [ - 'id' => 'beans_text_test', - 'type' => 'text', - 'default' => '', - ] ); - - $this->assertNull( beans_field_description( $field ) ); - - $field['description'] = ''; - $this->assertNull( beans_field_description( $field ) ); - } - - /** - * Test beans_field_description() should render the field's description. - */ - public function test_should_render_field_description() { - $field = $this->merge_field_with_default( [ - 'id' => 'beans_text_test', - 'type' => 'text', - 'description' => 'Testing the text field.', - 'default' => '', - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_description( $field ); - $html = ob_get_clean(); - - $expected = <<Testing the text field. -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } - - - /** - * Test beans_field_description() should render the field's extended description. - */ - public function test_should_render_extended_description() { - $field = $this->merge_field_with_default( [ - 'id' => 'beans_text_test', - 'type' => 'text', - 'description' => 'Testing the text field.This is the extended part of the description.', - 'default' => '', - ] ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_description( $field ); - $html = ob_get_clean(); - - $expected = <<Testing the text field.
- More... - - -EOB; - // Run the test. - $this->assertSame( $this->format_the_html( $expected ), $this->format_the_html( $html ) ); - } -} diff --git a/tests/phpunit/integration/api/fields/types/beansFieldImage.php b/tests/phpunit/integration/api/fields/types/beansFieldImage.php deleted file mode 100644 index fc50420a..00000000 --- a/tests/phpunit/integration/api/fields/types/beansFieldImage.php +++ /dev/null @@ -1,283 +0,0 @@ -post->create(); - $image_id = self::factory()->attachment->create_object( 'image.png', $post_id, [ - 'post_mime_type' => 'image/jpeg', - 'post_type' => 'attachment', - ] ); - update_post_meta( $image_id, '_wp_attachment_image_alt', 'This is the alt value.', true ); - - $field = $this->merge_field_with_default( [ - 'id' => 'beans_image_test', - 'type' => 'image', - 'label' => 'Image Test', - 'value' => $image_id, - ], false ); - - // Run the function and grab the HTML out of the buffer. - ob_start(); - beans_field_image( $field ); - $html = ob_get_clean(); - - $expected = <<