Automattic / WPCOM-Legacy-Redirector

WordPress plugin for handling large volumes of legacy redirects in a scalable manner.
20 stars 16 forks source link

Bugfix/77 wpcom vip add role caps fix #94

Closed ovidiul closed 3 years ago

ovidiul commented 3 years ago

It fixes the issue mentioned in #77 by renaming the activation hook to admin_init and adding a version check to only init the roles once when the version changes as per https://docs.wpvip.com/how-tos/customize-user-roles/ .

PR #93 might need to be merged before this.

ovidiul commented 3 years ago

Hi Gary, I've rebased my PR and added the requested changes.

Let me know if you see further adjustments needed.

ovidiul commented 3 years ago

Looking better, but I'm still not seeing a test that checks that update_option() was only called once when $capability->register() called twice. Have a look at brain-wp.github.io/BrainMonkey/docs/functions-expect.html which allows you to test for exactly this. Set the Function\expects, ensure the saved option is empty, call register twice, and see if the test is green (Might need to put that into a unit test, rather than the integration test)

I've added a unit test in tests/unit/CapabilityTest.php

We do have a related test in tests/integration/CapabilityTest.php , method test_register which checks the return of the register method, I guess another one doesn't hurt.

GaryJones commented 3 years ago

I've squashed all of the commits, and rebased on to develop, so we'll have a clean history.