Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the Disclaimers widget and functions from Largo #1501

Closed
wants to merge 14 commits into from

Conversation

benlk
Copy link
Collaborator

@benlk benlk commented Jul 10, 2018

This PR removes the "Disclaimers" functionality from Largo in favor of the plugin https://github.com/INN/disclaimers.

Changes

  • removes Largo Disclaimers widget and its post meta boxes
  • removes Largo theme options for enabling the disclaimers widget and for setting the default, site-wide option
  • removes tests for the Disclaimers widget and corrects a few tests that mentioned it in comments, erroneously
  • removes code docs about the Disclaimers widget
  • provides a migration function for the Largo-style settings to the INN/disclaimers plugin's settings. This must be completed before merging.

Things not changed

  • does not remove styles for the disclaimers widget

Closes #1500.

corrects comments in tests for largo-post-series-links and largo-series-posts
removes post metaboxes
removes sitewide options
@benlk benlk added this to the 0.6 - Performance & SEO milestone Jul 10, 2018
@benlk benlk changed the title 1500 remove disclaimers Remove the Disclaimers widget and functions from Largo Jul 26, 2018
@benlk
Copy link
Collaborator Author

benlk commented Jul 26, 2018

Here's the testing workflow for this PR:

  1. Get Largo 0.5.5.3, because that way we can test the update trigger without bumping the versino number past 0.5.5.4 yet:
    • Install Largo 0.5.5.3 on a new site, or
    • git checkout v0.5.5.3 in your existing Largo testing site, then with a database editor find the option_name equal to the name of the directory your Largo install is in, and change the Largo version number in there from 0.5.5.4 to 0.5.5.3
  2. Manually install https://github.com/INN/disclaimers/releases/tag/v0.1.0 in the plugins directory, but don't activate it.
  3. Log in.
  4. In Theme Options > Advanced > Disclaimers, enable disclaimers and set it to something appropriate. Save your settings.
  5. wp db dump
  6. git checkout 1500-remove-disclaimers
  7. Refresh the dashboard.
  8. Click the banner to update the Largo; update the Largo.
  9. 🤔
  10. wp db reset; wp db import the-dump-you-created-earlier.sql
  11. repeat

@benlk
Copy link
Collaborator Author

benlk commented Jul 26, 2018

The present problem is that, when the update function AJAX call is initialized, the optionsframework option is set, but when the optionframework update is made, the option is empty:

2018/07/26 19:07:51 [error] 328#0: *2551 FastCGI sent in stderr: "PHP message: 'This isn't the default disclaimer widget setting.'
PHP message: 'option: 'This isn\'t the default disclaimer widget setting.''
PHP message: 'option: false'
PHP message: 'something's wrong with the default disclaimer'
PHP message: 'return: '" while reading response header from upstream, client: 127.0.0.1, server: , request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:/Users/blk/.valet/valet.sock:", host: "largo.test", referrer: "http://largo.test/wp-admin/index.php?page=update-largo"

@benlk
Copy link
Collaborator Author

benlk commented Jul 27, 2018

PHP message: 'This isn't the default disclaimer widget setting.'
PHP message: 'running updates: 'This isn\'t the default disclaimer widget setting.''
PHP message: 'post setting defaults: false'
PHP message: 'post-pre-0.4: false'
PHP message: 'post-pre-0.5: false'
PHP message: 'option: false'
PHP message: 'something's wrong with the default disclaimer'
PHP message: 'return: '

So it's something in the function that sets Largo's defaults.

@benlk
Copy link
Collaborator Author

benlk commented Jul 28, 2018

PHP message: 'running updates: 'This isn\'t the default disclaimer widget setting.''
PHP message: 'so here's the baffling thing. This is the default disclaimer as written to the database.'
PHP message: 'This isn't the default disclaimer widget setting.'
PHP message: 'And this is it immediately afterwards, using of_get_option'
PHP message: 'post setting defaults: false'

…ility earlier in largo_perform_update to where the defaults haven't yet been set. I do not know why the thing was not working, but it was not. Maybe this works?
It's not ralistic to expect that people will be using INN/deploy-tools
to run tests, especially when the test-runner there assumes a Vagrant
box that is unmaintained and no longer used by INN.

Therefore, generally follow the instructions in https://make.wordpress.org/cli/handbook/plugin-unit-tests/

    you@yours:~/sites/largo/wp-content/themes/largo$ WP_TESTS_DIR=/tmp/wordpress-tests-lib/ bin/install-wp-tests.sh <dbname> <dbuser> <dbpass> <dbhost> latest
    you@yours:~/sites/largo/wp-content/themes/largo$ WP_TESTS_DIR=/tmp/wordpress-tests-lib/ phpunit --verbose
@benlk
Copy link
Collaborator Author

benlk commented Jul 31, 2018

There were 2 failures:
1) UpdateTestFunctions::test_largo_disclaimers_plugin_compatibility_1
It looks like update_option() failed?
Failed asserting that false is true.
/tmp/wordpress/src/wp-content/themes/largo/tests/inc/test-update.php:491
2) UpdateTestFunctions::test_largo_disclaimers_plugin_compatibility_2
The function largo_disclaimers_plugin_compatibility did not work as expected; the set option did not match the optionsframework option.
Failed asserting that false matches expected 'test message:c4ca4238a0b923820dcc509a6f75849b'.
/tmp/wordpress/src/wp-content/themes/largo/tests/inc/test-update.php:503

In the interests of not thrashing travis, I tried to set up tests locally, by following the instructions at https://make.wordpress.org/cli/handbook/plugin-unit-tests/ as documented in 5d99f1a:

    you@yours:~/sites/largo/wp-content/themes/largo$ WP_TESTS_DIR=/tmp/wordpress-tests-lib/ bin/install-wp-tests.sh <dbname> <dbuser> <dbpass> <dbhost> latest
    you@yours:~/sites/largo/wp-content/themes/largo$ WP_TESTS_DIR=/tmp/wordpress-tests-lib/ phpunit --verbose

This works, up to the point where the tests are run:

$ WP_TESTS_DIR=/tmp/wordpress-tests-lib/ phpunit --verbose
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
PHP Fatal error: Uncaught Error: Call to undefined function of_get_default_values() in /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php:20
Stack trace:
#0 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/class-wp-hook.php(286): MockOptionsFramework->populate_defaults('')
#1 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#2 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-settings.php(471): do_action('wp_loaded')
#4 /private/tmp/wordpress-tests-lib/includes/bootstrap.php(105): require_once('/private/var/fo...')
#5 /Users/blk/sites/largo/wp-content/themes/largo/tests/bootstrap.php(36): require('/private/tmp/wo...')
#6 phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php(64): include_once('/Users/blk/site...')
#7 phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/Users/blk/site...')
#8 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/Users/blk/site...')
#9 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstrap('/Users/blk/site...')
#10 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(159): PHPUnit\TextUI\Command->handleArguments(Array)
#11 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#12 /usr/local/bin/phpunit(569): PHPUnit\TextUI\Command::main()
#13 {main}
thrown in /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php on line 20

Fatal error: Uncaught Error: Call to undefined function of_get_default_values() in /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php:20
Stack trace:
#0 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/class-wp-hook.php(286): MockOptionsFramework->populate_defaults('')
#1 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)
#2 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
#3 /private/var/folders/3j/x3hprpwd11b39vwddy435rp80000gn/T/wordpress/wp-settings.php(471): do_action('wp_loaded')
#4 /private/tmp/wordpress-tests-lib/includes/bootstrap.php(105): require_once('/private/var/fo...')
#5 /Users/blk/sites/largo/wp-content/themes/largo/tests/bootstrap.php(36): require('/private/tmp/wo...')
#6 phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php(64): include_once('/Users/blk/site...')
#7 phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php(48): PHPUnit\Util\Fileloader::load('/Users/blk/site...')
#8 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(991): PHPUnit\Util\Fileloader::checkAndLoad('/Users/blk/site...')
#9 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(788): PHPUnit\TextUI\Command->handleBootstrap('/Users/blk/site...')
#10 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(159): PHPUnit\TextUI\Command->handleArguments(Array)
#11 phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php(148): PHPUnit\TextUI\Command->run(Array, true)
#12 /usr/local/bin/phpunit(569): PHPUnit\TextUI\Command::main()
#13 {main}
thrown in /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php on line 20

This is a difference in behavior between the local tests and Travis; Travis does not have this problem. I'm also running the local tests on PHP 7.2 with PHPUnit 6.5.9, and Travis is running them against all current PHP versions except 7.2, as mentioned in #1503.

The relevant error is this call to of_get_default_values(), which should have all error-handling suppressed because it's prefaced with an @:

https://github.com/INN/largo/blob/1c1023ef9b2654c75339f1411e0d632df104f54e/tests/mock/mock-options-framework.php#L20

As far as I can tell by putting some debugging code in the bootstrap file, before the requires $wp_tests_dir . '/includes/bootstrap.php';, it looks like no WordPress files are yet loaded. Here's the debugging functions added:

function benlk_test( $value ) {
       if ( preg_match( '/largo/', $value ) ) {
               return true;
       }
       return false;
}
function benlk_ack() {
       $files = get_included_files();
       echo(var_export( array_filter( $files, 'benlk_test' ), true));
}

They were added just before the final line of bootstrap.php:

https://github.com/INN/largo/blob/1c1023ef9b2654c75339f1411e0d632df104f54e/tests/bootstrap.php#L23-L25

The result was as follows:

array (
  534 => '/Users/blk/sites/largo/wp-content/themes/largo/tests/bootstrap.php',
  538 => '/Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php',
  539 => '/Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-admin-functions.php',
)

There were no other Largo files than those three active at this time.

I believe what's blocking me from running tests locally is twofold:

  • something on my system and/or PHP 7.2 is preventing the @ from silencing that error.
  • the theme Largo is not active, despite how bootstrap.php sets $GLOBALS['wp_tests_options']['stylesheet'] = 'largo' and template likewise, so the file containing of_get_default_values() has not yet been included.

And yet, this works on Travis.

@benlk
Copy link
Collaborator Author

benlk commented Jul 31, 2018

Activating the theme that way causes no detriments to the (failing) Travis tests, and the tests now run on my computer with PHP 7.2. Small progress.

@benlk
Copy link
Collaborator Author

benlk commented Jul 31, 2018

By applying the reflection function technique seen in that StackOverflow link, we can see that the of_get_option and of_set_option functions used in the tests are still being supplied by the mocks, not by the production Largo functions.

    function test_largo_disclaimers_plugin_compatibility_3() {
        // https://stackoverflow.com/a/2222404
        $reflfunc = new ReflectionFunction( 'of_get_option' );
        echo "\n get: " . $reflfunc->getFilename() . ':' . $reflfunc->getStartLine();
        $set = new ReflectionFunction( 'of_get_option' );
        echo "\n set: " . $set->getFilename() . ':' . $set->getStartLine();
        echo "\n";
    }
 get: /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php:51
 set: /Users/blk/sites/largo/wp-content/themes/largo/tests/mock/mock-options-framework.php:51

So ... this isn't a problem with the optionsframework. Something's wrong with either the test or the function itself.

I'm still really, really confused why setting an optionsframework option in one line, then in the function called on the next line, the optionsframework option retrieved by the same mock framework as the setter used is something different entirely, an unset value.

For tomorrow:

Within a single test, determine whether a setter and getter with no intervening calls results in the getter retrieving what the setter set.I don't want to have to test the optionsframework mock, but maybe that's the place to start tomorrow.

@benlk
Copy link
Collaborator Author

benlk commented Jul 31, 2018

// test that of_get_option and of_set_option work
function test_largo_disclaimers_plugin_compatibility_3() {
    $message = 'test message:' . md5( date( 'N' ) );
    $option_key = 'reallyshouldnothavetodothis';
    of_set_option( $option_key, $message );
    $option = of_get_option( $option_key ); 
    $this->assertEquals( $message, $option, 'wtf' );
}

That test passes, so the optionsframework getter/setter mock works.

// test that of_get_option and of_set_option work
function test_largo_disclaimers_plugin_compatibility_3() {
    $message = 'test message:' . md5( date( 'N' ) );
    $option_key = 'reallyshouldnothavetodothis';
    update_option( $option_key, $message );
    $option = get_option( $option_key );
    $this->assertEquals( $message, $option, 'wtf' );
}

That test passes, so the WordPress core options stuff works.

So something is wrong with the test or with the migration function. Further debugging of the test and migration function is needed, and I don't have time for that today.

Next steps:

  • slather the test with debug echo "\n" . var_dump( $variable, true ); statements (the error_log is suppressed by the testrunner)
  • slather the largo_disclaimers_plugin_compatibility() with same
  • figure out what's broken.

@benlk benlk removed this from the 0.6 - Gutenberg, SEO, Performance milestone Nov 6, 2018
@benlk
Copy link
Collaborator Author

benlk commented Nov 6, 2018

Bumping this out of the 0.6 milestone as well

@benlk
Copy link
Collaborator Author

benlk commented Aug 21, 2019

tests may be failing locally because the plugin would already be installed in a local testing env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant