Skip to content
Snippets Groups Projects
Commit efb2dbda authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'feature/factory' into 'master'

interface, factory and some renaming

See merge request !10
parents 5cd4ac45 1b2a5cc1
No related branches found
No related tags found
1 merge request!10interface, factory and some renaming
Pipeline #8482 passed with stages
in 2 minutes and 16 seconds
## [2.3.0] - 2019-03-25
### Added
- Factory
- Interface
### Changed
- Minor internal action renaming
\ No newline at end of file
......@@ -4,11 +4,16 @@ if ( ! interface_exists( 'WPDesk_Translatable' ) ) {
require_once 'Translatable.php';
}
if ( ! interface_exists( 'WPDesk_Requirement_Checker' ) ) {
require_once 'Requirement_Checker.php';
}
/**
* Checks requirements for plugin
* have to be compatible with PHP 5.2.x
*/
class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable, WPDesk_Requirement_Checker
{
const EXTENSION_NAME_OPENSSL = 'openssl';
const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices';
......@@ -349,7 +354,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @deprecated use render_notices or disable_plugin
*/
public function disable_plugin_render_notice() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'render_notices_action' ) );
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action') );
}
/**
......@@ -358,7 +363,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return void
*/
public function render_notices() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'render_notices_action' ) );
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_render_notices_action') );
}
/**
......@@ -367,7 +372,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
* @return void
*/
public function disable_plugin() {
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'deactivate_action' ) );
add_action( self::HOOK_ADMIN_NOTICES_ACTION, array( $this, 'handle_deactivate_action') );
}
/**
......@@ -375,22 +380,22 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
*
* @return void
*/
public function deactivate_action() {
public function handle_deactivate_action() {
if ( isset( $this->plugin_file ) ) {
deactivate_plugins( plugin_basename( $this->plugin_file ) );
}
}
/**
* Should be called as WordPress action
*
/**
* Should be called as WordPress action
*
* @internal Do not use as public. Public only for wp action.
*
* @return void
*/
public function render_notices_action() {
foreach ( $this->notices as $notice ) {
echo $notice;
}
}
* @return void
*/
public function handle_render_notices_action() {
foreach ( $this->notices as $notice ) {
echo $notice;
}
}
}
<?php
if ( ! class_exists('Basic_Requirement_Checker')) {
require_once 'Basic_Requirement_Checker.php';
}
class WPDesk_Basic_Requirement_Checker_Factory
{
/**
* @param $plugin_file
* @param $plugin_name
* @param $text_domain
* @param $php_version
* @param $wp_version
*
* @return WPDesk_Requirement_Checker
*/
public function create_requirement_checker($plugin_file, $plugin_name, $text_domain)
{
return new WPDesk_Basic_Requirement_Checker($plugin_file, $plugin_name, $text_domain, null, null);
}
}
<?php
/**
* Checks requirements for plugin
* have to be compatible with PHP 5.2.x
*/
interface WPDesk_Requirement_Checker
{
/**
* @param string $version
*
* @return $this
*/
public function set_min_php_require($version);
/**
* @param string $version
*
* @return $this
*/
public function set_min_wp_require($version);
/**
* @param string $version
*
* @return $this
*/
public function set_min_wc_require($version);
/**
* @param $version
*
* @return $this
*/
public function set_min_openssl_require($version);
/**
* @param string $plugin_name
* @param string $nice_plugin_name Nice plugin name for better looks in notice
*
* @return $this
*/
public function add_plugin_require($plugin_name, $nice_plugin_name = null);
/**
* @param string $module_name
* @param string $nice_name Nice module name for better looks in notice
*
* @return $this
*/
public function add_php_module_require($module_name, $nice_name = null);
/**
* @param string $setting
* @param mixed $value
*
* @return $this
*/
public function add_php_setting_require($setting, $value);
/**
* @return bool
*/
public function are_requirements_met();
/**
* @return void
*/
public function disable_plugin_render_notice();
/**
* @return void
*/
public function render_notices();
/**
* Renders requirement notices in admin panel
*
* @return void
*/
public function disable_plugin();
}
\ No newline at end of file
<?php
interface WPDesk_Requirement_Checker_Factory
{
/**
* @param $plugin_file
* @param $plugin_name
* @param $text_domain
* @param $php_version
* @param $wp_version
*
* @return WPDesk_Requirement_Checker
*/
public function create_requirement_checker($plugin_file, $plugin_name, $text_domain);
}
......@@ -46,7 +46,7 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
$requirements->set_min_php_require( self::ALWAYS_NOT_VALID_PHP_VERSION );
$requirements->are_requirements_met();
$this->expectOutputRegex( "/PHP/" );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
/**
......@@ -73,7 +73,7 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
'Should fail because required WP should be at least ' . $wp_version_fail );
$this->expectOutputRegex( "/WordPress/" );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
/**
......@@ -88,7 +88,7 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
$this->assertTrue( $requirements->are_requirements_met(), 'Curl should exists' );
$this->expectOutputRegex( "/^$/" );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
public function test_plugin_check_with_multisite() {
......@@ -122,7 +122,7 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
$this->assertFalse( $requirements->are_requirements_met(), 'Plugin should not exists' );
$this->expectOutputRegex( "/$not_existing_plugin_name/" );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
/**
......@@ -147,7 +147,7 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
'Requirement OpenSSL should fail for that high number' );
$this->expectOutputRegex( '/without OpenSSL module/' );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
public function test_deactivate_plugin_notice() {
......@@ -155,13 +155,13 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
self::ALWAYS_VALID_WP_VERSION );
WP_Mock::expectActionAdded( WPDesk_Basic_Requirement_Checker::HOOK_ADMIN_NOTICES_ACTION,
[ $requirements, 'render_notices_action' ] );
[ $requirements, 'handle_render_notices_action'] );
$this->assertFalse( $requirements->are_requirements_met() );
$requirements->disable_plugin();
$requirements->render_notices();
$this->expectOutputRegex( '/cannot run on PHP/' );
$requirements->render_notices_action();
$requirements->handle_render_notices_action();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment