Skip to content
Snippets Groups Projects
Commit c52ff062 authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

Merge branch 'feature/refactor' into 'devel'

Feature/refactor

See merge request !6
parents 57d76f5a 80b9f313
No related branches found
No related tags found
2 merge requests!8Devel,!6Feature/refactor
Pipeline #8184 passed
/vendor/
.idea
composer.lock
build-coverage
\ No newline at end of file
variables:
WPDESK_CI_VERSION: 1.10.19
WPDESK_CI_VERSION: 1.10.19-library
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
......@@ -13,8 +13,6 @@ variables:
stages:
- tools
- tests
- pre-deploy
- deploy
.template: &job-test-template
stage: tests
......@@ -78,18 +76,6 @@ stages:
- tags
only:
.template: &job-deploy-template
image: wpdesknet/amazon-svn-deploy
stage: deploy
dependencies:
- build to deploy
- unit test lastest coverage
- integration test lastest coverage
retry: 2
when: manual
only:
- tags
before_script:
- cd ${CI_PROJECT_DIR}
......@@ -119,16 +105,7 @@ churn metrics:
- echo ${WPDESK_CI_VERSION}
- composer require bmitch/churn-php
- composer update --no-progress
- vendor/bin/churn run classes inc
#code style test:
# stage: tests
# image: wpdesknet/phpunit-woocommerce:0-0
# allow_failure: true
# script:
# - echo ${WPDESK_CI_VERSION}
# - composer update --no-progress
# - vendor/bin/phpcs
- vendor/bin/churn run src
unit test lastest:
<<: *job-test-unit-template-fast
......@@ -175,136 +152,3 @@ integration test current woocommerce:
- rm -rf woocommerce
- git clone https://github.com/woocommerce/woocommerce.git
- cd ${CI_PROJECT_DIR}
acceptance test:
image: wpdesknet/node
variables:
CI_DEBUG_SERVICES: trace
services:
- name: mysql:5.6
alias: mysqltests
- name: wpdesknet/apache-woocommerce:latest
alias: wootests
- name: selenium/standalone-chrome
alias: selenium
artifacts:
when: always
expire_in: 1 day
name: "error logs"
paths:
- ${CI_PROJECT_DIR}/acceptance
stage: tests
allow_failure: true
script:
- cd ${CI_PROJECT_DIR}
- composer update --no-progress --no-dev
- if [[ -f ${CI_PROJECT_DIR}/tests/acceptance/prepare.sh ]]; then sh ${CI_PROJECT_DIR}/tests/acceptance/prepare.sh; fi
- export MYSQL_IP=$(awk '/^[[:space:]]*($|#)/{next} /mysqltests/{print $1; exit}' /etc/hosts)
- export WOOTESTS_IP=$(awk '/^[[:space:]]*($|#)/{next} /wootests/{print $1; exit}' /etc/hosts)
- echo "http://wootests/wpdesk_init.php?mysql_ip=${MYSQL_IP}&wootests_ip=${WOOTESTS_IP}"
- wget -O /tmp/wpdesk_init.txt "http://wootests/wpdesk_init.php?mysql_ip=${MYSQL_IP}&wootests_ip=${WOOTESTS_IP}"
- tail -50 /tmp/wpdesk_init.txt
- sh /tmp/clone.sh git@gitlab.com:wpdesk/plugins-tests.git /tmp/tests headless
- cd /tmp/tests
- npm install
- npm install -g grunt-cli
- cd node_modules/.bin
- ./webdriver-manager update
- cd ../
- mkdir -p ${CI_PROJECT_DIR}/acceptance/reports/html/screenshot
- grunt chrome-${CI_PROJECT_NAME}
apigen docs:
image:
name: wpdesknet/apigen
stage: pre-deploy
artifacts:
expire_in: 1 day
name: "docs"
paths:
- docs/
script:
- echo ${WPDESK_CI_VERSION}
- ls -l
- /app/vendor/bin/apigen generate
- php /app/hooks-docs.php ${CI_PROJECT_DIR}
only:
- tags
pages:
stage: deploy
dependencies:
- apigen docs
script:
- rm -rf public
- mv docs/ public/
- 'curl -X POST --data-urlencode "payload={\"text\": \"Dokumentacja projektu ${CI_PROJECT_NAME} w wersji ${CI_COMMIT_REF_NAME} umieszczona w <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}/pages|pages> \", }" https://hooks.slack.com/services/${SLACK_AUTH}'
artifacts:
expire_in: 1 day
paths:
- public
only:
- tags
build to deploy:
image: wpdesknet/phpunit-woocommerce:4-0
stage: pre-deploy
artifacts:
expire_in: 1 month
name: "production release"
paths:
- release
- release.zip
script:
- echo ${WPDESK_CI_VERSION}
- php --version
- ls -l
- /tmp/set_version.sh ${CI_COMMIT_REF_NAME}
- rm -rf ${CI_PROJECT_DIR}/release ${CI_PROJECT_DIR}/release.zip /tmp/release
- mkdir /tmp/release
- mkdir -p ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- cp -rf ${CI_PROJECT_DIR}/* /tmp/release
- cp -rf /tmp/release/* ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- cd ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME}
- composer install --no-dev --no-progress --optimize-autoloader
- rm -rf build-coverage release tests docs .git .editorconfig .gitignore .gitlab-ci.yml apigen.neon phpunit.xml acceptance test_soap.php .gitlab
- rm -rf composer.json composer.lock phpcs.xml.dist phpunit-integration.xml phpunit-unit.xml composer.phar wp-cli.phar
- cd ../
- zip -r -q ../release.zip ./
only:
- tags
deploy to shop:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- /tmp/deploy_shop.sh ${CI_PROJECT_NAME} release.zip ${CI_PROJECT_NAME}.zip
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do sklepu w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wpdesk shop
url: https://wpdeskplugin.s3.amazonaws.com/${CI_PROJECT_NAME}.zip
deploy to demo:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- /tmp/deploy_demo.sh release/${CI_PROJECT_NAME} ${CI_PROJECT_NAME}
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do demo w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wpdesk demo
url: https://demo.wpdesk.org
deploy to repository:
<<: *job-deploy-template
script:
- echo ${WPDESK_CI_VERSION}
- rm -rf /tmp/svn-repository
- mkdir /tmp/svn-repository
- /tmp/deploy_repository.sh ${CI_PROJECT_NAME} ${CI_PROJECT_DIR}/release/${CI_PROJECT_NAME} /tmp/svn-repository
- 'curl -X POST --data-urlencode "payload={\"text\": \"Projekt <https://gitlab.com/wpdesk/${CI_PROJECT_NAME}|${CI_PROJECT_NAME}> zdeployowany do repozytorium WP w wersji ${CI_COMMIT_REF_NAME}\", }" https://hooks.slack.com/services/${SLACK_AUTH}'
environment:
name: wordpress repository
url: https://downloads.wordpress.org/plugin/${CI_PROJECT_NAME}.${CI_COMMIT_REF_NAME}.zip
### Select WooCommerce version e.g: [x] 2.6
<!--- Select the WooCommerce version on which the error occurred -->
- [ ] [2.6](http://woo26.tests.wpdesk.org)
- [ ] [2.7](http://woo27.tests.wpdesk.org)
- [ ] [3.0](http://woo30.tests.wpdesk.org)
- [ ] [3.1](http://woo31.tests.wpdesk.org)
- [ ] [3.2](http://woo32.tests.wpdesk.org)
- [ ] [3.3](http://woo33.tests.wpdesk.org)
- [ ] [3.4](http://woo34.tests.wpdesk.org)
- [ ] [Stable](https://stable.wpdesk.org/)
### Select PHP version e.g: [x] 5.6
<!--- Select the PHP version on which the error occurred -->
- [ ] 5.3
- [ ] 5.5
- [ ] 5.6
- [ ] 7.1
- [ ] 7.2
## Steps to Reproduce
<!--- Provide a link to a live example, or an unambiguous set of steps to -->
1.
2.
## Expected Behavior
<!--- Tell what should happen -->
1.
\ No newline at end of file
Wp-basic-requirements is a simple library for WordPress plugins to check if the environment meets the requirements
and if the requirements are not met shows proper notice to user.
Library have to be compatible with PHP 5.2.x as it's the lowest possible version for WordPress.
Requirements may be:
- Minimal PHP version
- Minimal WordPress version
- Minimal WooCommerce version
- Required PHP module
- Required PHP setting
- OpenSSL version
\ No newline at end of file
<?php
if ( ! interface_exists( 'WPDesk_Translable' ) ) {
require_once 'Translable.php';
if ( ! interface_exists( 'WPDesk_Translatable' ) ) {
require_once 'Translatable.php';
}
/**
* Checks requirements for plugin
* have to be compatible with PHP 5.2.x
*/
class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
class WPDesk_Basic_Requirement_Checker implements WPDesk_Translatable {
const EXTENSION_NAME_OPENSSL = 'openssl';
const HOOK_ADMIN_NOTICES_ACTION = 'admin_notices';
/** @var string */
private $plugin_name = '';
private $plugin_name;
/** @var string */
private $plugin_file = '';
private $plugin_file;
/** @var string */
private $min_php_version;
/** @var string */
......@@ -107,7 +107,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return $this
*/
public function add_plugin_require( $plugin_name, $nice_plugin_name = null ) {
if ( is_null( $nice_plugin_name ) ) {
if ( $nice_plugin_name === null ) {
$this->plugin_require[ $plugin_name ] = $plugin_name;
} else {
$this->plugin_require[ $plugin_name ] = $nice_plugin_name;
......@@ -123,7 +123,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return $this
*/
public function add_php_module_require( $module_name, $nice_name = null ) {
if ( is_null( $nice_name ) ) {
if ( $nice_name === null ) {
$this->module_require[ $module_name ] = $module_name;
} else {
$this->module_require[ $module_name ] = $nice_name;
......@@ -158,19 +158,19 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
*/
private function prepare_requirement_notices() {
$notices = array();
if ( ! $this->is_php_at_least( $this->min_php_version ) ) {
if ( ! self::is_php_at_least( $this->min_php_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on PHP versions older than %s. Please contact your host and ask them to upgrade.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_php_version ) );
}
if ( ! $this->is_wp_at_least( $this->min_wp_version ) ) {
if ( ! self::is_wp_at_least( $this->min_wp_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on WordPress versions older than %s. Please update WordPress.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wp_version ) );
}
if ( ! is_null( $this->min_wc_version ) && $this->can_check_plugin_version() && ! $this->is_wc_at_least( $this->min_wc_version ) ) {
if ( $this->min_wc_version !== null && $this->can_check_plugin_version() && ! self::is_wc_at_least( $this->min_wc_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run on WooCommerce versions older than %s. Please update WooCommerce.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), $this->min_wc_version ) );
}
if ( ! is_null( $this->min_openssl_version ) && ! $this->is_open_ssl_at_least( $this->min_openssl_version ) ) {
if ( $this->min_openssl_version !== null && ! self::is_open_ssl_at_least( $this->min_openssl_version ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run without OpenSSL module version at least %s. Please update OpenSSL module.',
$this->get_text_domain() ), esc_html( $this->plugin_name ),
'0x' . dechex( $this->min_openssl_version ) ) );
......@@ -189,7 +189,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return mixed
*/
public static function is_php_at_least( $min_version ) {
return version_compare( phpversion(), $min_version, '>=' );
return version_compare( PHP_VERSION, $min_version, '>=' );
}
/**
......@@ -258,7 +258,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
private function append_plugin_require_notices( $notices ) {
if ( count( $this->plugin_require ) > 0 ) {
foreach ( $this->plugin_require as $plugin_name => $nice_plugin_name ) {
if ( ! $this->is_wp_plugin_active( $plugin_name ) ) {
if ( ! self::is_wp_plugin_active( $plugin_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run without %s active. Please install and activate %s plugin.',
$this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_plugin_name ) ), esc_html( basename( $nice_plugin_name ) ) ) );
......@@ -294,7 +294,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
private function append_module_require_notices( $notices ) {
if ( count( $this->module_require ) > 0 ) {
foreach ( $this->module_require as $module_name => $nice_module_name ) {
if ( ! $this->is_module_active( $module_name ) ) {
if ( ! self::is_module_active( $module_name ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run without %s php module installed. Please contact your host and ask them to install %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ),
esc_html( basename( $nice_module_name ) ), esc_html( basename( $nice_module_name ) ) ) );
......@@ -322,7 +322,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
private function append_settings_require_notices( $notices ) {
if ( count( $this->setting_require ) > 0 ) {
foreach ( $this->setting_require as $setting => $value ) {
if ( ! $this->is_setting_set( $setting, $value ) ) {
if ( ! self::is_setting_set( $setting, $value ) ) {
$notices[] = $this->prepare_notice_message( sprintf( __( 'The &#8220;%s&#8221; plugin cannot run without %s php setting set to %s. Please contact your host and ask them to set %s.',
$this->get_text_domain() ), esc_html( $this->plugin_name ), esc_html( basename( $setting ) ),
esc_html( basename( $value ) ), esc_html( basename( $setting ) ) ) );
......@@ -340,7 +340,7 @@ class WPDesk_Basic_Requirement_Checker implements WPDesk_Translable {
* @return bool
*/
public static function is_setting_set( $name, $value ) {
return ini_get( $name ) === strval( $value );
return ini_get( $name ) === (string) $value;
}
/**
......
<?php
if ( ! interface_exists( 'WPDesk_Translable' ) ) {
require_once dirname(__FILE__) . '/../Translable.php';
if ( ! interface_exists( 'WPDesk_Translatable' ) ) {
require_once __DIR__ . '/../Translatable.php';
}
......@@ -10,7 +10,7 @@ if ( ! interface_exists( 'WPDesk_Translable' ) ) {
*
* have to be compatible with PHP 5.2.x
*/
interface WPDesk_Has_Plugin_Info extends WPDesk_Translable {
interface WPDesk_Has_Plugin_Info extends WPDesk_Translatable {
/**
* @return string
*/
......
<?php
if ( ! interface_exists( 'WPDesk_Translable' ) ) {
require_once dirname(__FILE__) . '/../Translable.php';
if ( ! interface_exists( 'WPDesk_Translatable' ) ) {
require_once __DIR__ . '/../Translatable.php';
}
if ( ! class_exists( 'WPDesk_Buildable' ) ) {
require_once dirname(__FILE__) . '/../Buildable.php';
require_once __DIR__ . '/../Buildable.php';
}
if ( ! class_exists( 'WPDesk_Has_Plugin_Info' ) ) {
require_once 'Has_Plugin_Info.php';
......@@ -15,7 +15,7 @@ if ( ! class_exists( 'WPDesk_Has_Plugin_Info' ) ) {
*
* have to be compatible with PHP 5.2.x
*/
class WPDesk_Plugin_Info implements WPDesk_Translable, WPDesk_Buildable, WPDesk_Has_Plugin_Info {
class WPDesk_Plugin_Info implements WPDesk_Translatable, WPDesk_Buildable, WPDesk_Has_Plugin_Info {
/** @var string */
private $plugin_file_name;
......
......@@ -5,7 +5,7 @@
*
* have to be compatible with PHP 5.2.x
*/
interface WPDesk_Translable {
interface WPDesk_Translatable {
/** @return string */
public function get_text_domain();
}
\ No newline at end of file
......@@ -154,23 +154,13 @@ class Test_Basic_Requirement_Checker extends PHPUnit\Framework\TestCase {
$requirements = $this->create_requirements_for_php_wp( self::ALWAYS_NOT_VALID_PHP_VERSION,
self::ALWAYS_VALID_WP_VERSION );
WP_Mock::expectActionAdded( WPDesk_Basic_Requirement_Checker::HOOK_ADMIN_NOTICES_ACTION,
[ $requirements, 'deactivate_action' ] );
WP_Mock::expectActionAdded( WPDesk_Basic_Requirement_Checker::HOOK_ADMIN_NOTICES_ACTION,
[ $requirements, 'render_notices_action' ] );
$this->assertFalse( $requirements->are_requirements_met() );
$requirements->disable_plugin_render_notice();
WP_Mock::wpFunction( 'deactivate_plugins' )
->once();
WP_Mock::wpFunction( 'plugin_basename' )
->once()
->andReturn( 'whatever' );
$this->expectOutputRegex( '/cannot run on PHP/' );
$requirements->deactivate_action();
$requirements->render_notices_action();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment