woocommerce/plugins/woocommerce-admin/tests/remote-inbox-notifications/mock-plugins-provider.php

81 lines
2.0 KiB
PHP
Raw Normal View History

Remote inbox notification delivery (https://github.com/woocommerce/woocommerce-admin/pull/4143) * Poll and persist specs * Process specs into admin notes * Add send at time rule processor * Fix style issues * Clear actions before recreating them to avoid dupes * Trigger the RINDS engine when a plugin is activated * Unit test SendAtTimeRuleProcessor * Implement plugins activated rule processor * Don't throw exception for unrecognised rule type. Also unit test around this. * add url_is_action_query to tell whether to wrap the URL in wc_admin_url() call or not * Add NOT rule * revert change to install.php * Drop unimplemented resend after dismissal rule * Add OR rule * Explicitly make "fail" a type of rule that can be applied to a spec * Add plugin version rule processor * Tidy up, don't need to pass $spec everywhere * Remove meta record for action state - not really needed * Move spec runner into it's own class, add some checks around re-unactioning a note * Replace if..else with switch * Just update the option * Check that the JSON coming in is an array * Change OR rule to accept an array of operands * Add Pass rule processor * Fix specs that are initially not published * Rename send at rule to publish after * Add publish before rule * Remove unused interface * Can't use PHP7's anonymous classes * New notification: How to draw attention to your online store * Add feature flag for rule-base inbox notes * rename everything to RemoteInboxNotifications from RINDS * Fix merge fail * fix test * Change preunactioned to pending * Move feature flag check into Events.php * Refactor reading a data source * Rename poll_data_sources function * Refactor EvaluateAndGetStatus::evaluate to take the rule evaluator directly * Check that the response body exists * Add validation and defensive checks * Add rule processor interface * Update note created time on status change * Move non-test dependencies into processor constructors * Update to proposed live URL * Remove setting icon as it's being deprecated Co-authored-by: Rebecca Scott <me@becdetat.com>
2020-06-05 01:51:25 +00:00
<?php
/**
* Mock plugins Provider.
*
* @package WooCommerce\Tests\RemoteInboxNotifications
*/
use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProviderInterface;
/**
* Mock plugins Provider.
*
* Returns the provided plugins instead of the current plugins. Needed for
* unit tests.
*/
class MockPluginsProvider implements PluginsProviderInterface {
/**
* Construct the mock plugins provider using the specified value for the
* active plugins slugs.
*
* @param array $active_plugin_slugs The value to use for the active plugin slugs.
* @param array $get_plugins_data The data to be used instead of get_plugins() calls.
*/
public function __construct(
$active_plugin_slugs,
$get_plugins_data = array()
) {
$this->active_plugin_slugs = $active_plugin_slugs;
$this->get_plugins_data = $get_plugins_data;
}
/**
* Get an array of provided plugin slugs.
*
* @return array
*/
public function get_active_plugin_slugs() {
return $this->active_plugin_slugs;
}
/**
* Get plugin data.
*
* @param string $plugin Path to the plugin file relative to the plugins directory or the plugin directory name.
*
* @return array|false
*/
public function get_plugin_data( $plugin ) {
$plugin_path = $this->get_plugin_path_from_slug( $plugin );
$plugins = $this->get_plugins_data;
return isset( $plugins[ $plugin_path ] ) ? $plugins[ $plugin_path ] : false;
}
/**
* Get the path to the plugin file relative to the plugins directory from the plugin slug.
*
* E.g. 'woocommerce' returns 'woocommerce/woocommerce.php'
*
* @param string $slug Plugin slug to get path for.
*
* @return string|false
*/
public function get_plugin_path_from_slug( $slug ) {
$plugins = $this->get_plugins_data;
if ( strstr( $slug, '/' ) ) {
return $slug;
}
foreach ( $plugins as $plugin_path => $data ) {
$path_parts = explode( '/', $plugin_path );
if ( $path_parts[0] === $slug ) {
return $plugin_path;
}
}
return false;
}
}