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

feature(init): init

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #8641 failed with stages
in 3 minutes and 52 seconds
Showing with 573 additions and 0 deletions
<?php
/**
* @var string $plugin_version
* @var string $plugin_name
* @var string $plugin_class_name
* @var string $plugin_text_domain
* @var string $plugin_dir
* @var string $plugin_file
* @var array $requirements
* @var string $product_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die();
}
// Code in PHP >= 5.3 but understandable by older parsers
if ( PHP_VERSION_ID > 50300 ) {
require_once $plugin_dir . '/vendor/autoload.php';
$plugin_init_factory = new \WPDesk\Plugin\Flow\Initialization\Simple\SimpleFactory( true );
}
require dirname( __FILE__ ) . '/plugin-init-php52.php';
\ No newline at end of file
<?php
/**
* @var string $plugin_version
* @var string $plugin_name
* @var string $plugin_class_name
* @var string $plugin_text_domain
* @var string $plugin_dir
* @var string $plugin_file
* @var array $requirements
* @var string $product_id
* @var WPDesk\Plugin\Flow\Initialization\InitializationFactory|void $plugin_init_factory
*/
if ( ! defined( 'ABSPATH' ) ) {
die();
}
// Code in PHP >= 5.3 but understandable by older parsers
if ( PHP_VERSION_ID > 50300 ) {
require_once $plugin_dir . '/vendor/autoload.php';
if ( ! isset( $plugin_init_factory ) ) {
$plugin_init_factory = new \WPDesk\Plugin\Flow\Initialization\Simple\SimpleFactory();
}
if ( ! isset( $plugin_shops ) || ! is_array( $plugin_shops ) ) {
$plugin_shops = array();
}
$bootstrap = new WPDesk\Plugin\Flow\PluginBootstrap(
$plugin_version,
null, // deprecated
$plugin_name,
$plugin_class_name,
$plugin_text_domain,
$plugin_dir,
$plugin_file,
$requirements,
$product_id,
$plugin_init_factory,
$plugin_shops
);
$bootstrap->run();
// all optional vars must be cleared
unset($plugin_init_factory);
} else {
/** @noinspection PhpDeprecationInspection */
$php52_function = create_function( '',
'echo sprintf( __("<p><strong style=\'color: red;\'>PHP version is older than 5.3 so no WP Desk plugins will work. Please contact your host and ask them to upgrade. </strong></p>", \'wp-plugin-flow-common\') );' );
add_action( 'admin_notices', $php52_function );
}
\ No newline at end of file
<?php
class Stub_Plugin extends WPDesk\PluginBuilder\Plugin\AbstractPlugin {
}
\ No newline at end of file
This diff is collapsed.
version: '2.0'
services:
wordpress:
image: wpdesknet/phpunit-woocommerce:0-0
volumes:
- .././:/opt/project
depends_on:
- mysql0
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql0
wordpress-0-1:
image: wpdesknet/phpunit-woocommerce:0-1
volumes:
- .././:/opt/project
depends_on:
- mysql1
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql1
wordpress-0-2:
image: wpdesknet/phpunit-woocommerce:0-2
volumes:
- .././:/opt/project
depends_on:
- mysql2
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql2
wordpress-0-3:
image: wpdesknet/phpunit-woocommerce:0-3
volumes:
- .././:/opt/project
depends_on:
- mysql3
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql3
wordpress-0-4:
image: wpdesknet/phpunit-woocommerce:0-4
volumes:
- .././:/opt/project
depends_on:
- mysql4
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql4
wordpress-0-5:
image: wpdesknet/phpunit-woocommerce:0-5
volumes:
- .././:/opt/project
depends_on:
- mysql5
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql5
wordpress-1-0:
image: wpdesknet/phpunit-woocommerce:1-0
volumes:
- .././:/opt/project
depends_on:
- mysql0
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql0
wordpress-2-0:
image: wpdesknet/phpunit-woocommerce:2-0
volumes:
- .././:/opt/project
depends_on:
- mysql0
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql0
wordpress-3-0:
image: wpdesknet/phpunit-woocommerce:3-0
volumes:
- .././:/opt/project
depends_on:
- mysql0
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql0
wordpress-4-0:
image: wpdesknet/phpunit-woocommerce:4-0
volumes:
- .././:/opt/project
depends_on:
- mysql0
environment:
WORDPRESS_DB_NAME: wptest
WORDPRESS_DB_USER: mysql
WORDPRESS_DB_PASSWORD: mysql
WORDPRESS_DB_HOST: mysql0
mysql0:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
mysql1:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
mysql2:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
mysql3:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
mysql4:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
mysql5:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: mysql
MYSQL_DATABASE: wptest
MYSQL_USER: mysql
MYSQL_PASSWORD: mysql
<?php
use WPDesk\Plugin\Flow\Initialization\Simple\TrackerInstanceAsFilterTrait;
class Test_Plugin_Start_Using_Flow extends WP_UnitTestCase {
const TESTED_PLUGIN_CLASS = 'Flexible_Checkout_Fields_Plugin';
/**
* Start prepared plugin.
*
* @param string $flow_file Path to file with flow to use.
*/
private function plugin_start_from_flow_file($flow_file) {
$plugin_name = 'Flexible Checkout Fields';
$plugin_class_name = self::TESTED_PLUGIN_CLASS;
$plugin_text_domain = 'flexible-checkout-fields';
$plugin_release_timestamp = date( 'Y-m-d' );
$plugin_version = '1.0';
$product_id = 'Flexible Checkout Fields';
$plugin_file = DEPENDENT_PLUGINS_DIR . '/flexible-checkout-fields/flexible-checkout-fields.php';
$plugin_dir = dirname( $plugin_file );
$requirements = [
'php' => '5.6',
'wp' => '4.5',
];
defined('FLEXIBLE_CHECKOUT_FIELDS_VERSION') || define( 'FLEXIBLE_CHECKOUT_FIELDS_VERSION', $plugin_version );
require_once $plugin_dir . '/inc/wpdesk-woo27-functions.php';
// we need to inject Prefixed names as library is not prefixed and plugin libraries also are not prefixed
if (!class_exists(\FcfVendor\WPDesk_Plugin_Info::class)) {
class_alias( \WPDesk_Plugin_Info::class, \FcfVendor\WPDesk_Plugin_Info::class );
class_alias( \WPDesk\PluginBuilder\Plugin\AbstractPlugin::class, \FcfVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin::class );
}
require $flow_file;
do_action( 'plugins_loaded' );
}
/**
* Assert that prepared plugin is running.
*/
private function assert_plugin_started() {
/** @var \WPDesk\PluginBuilder\Storage\StorageFactory $storage */
$storage = new \WPDesk\PluginBuilder\Storage\StorageFactory();
$storage = $storage->create_storage();
$plugin = $storage->get_from_storage(self::TESTED_PLUGIN_CLASS);
$this->assertInstanceOf( self::TESTED_PLUGIN_CLASS, $plugin, 'Plugin works.' );
}
public function test_plugin_paid_can_start() {
remove_all_actions('wpdesk_tracker_instance');
$this->plugin_start_from_flow_file(__DIR__ . '/../../src/plugin-init-php52.php');
$this->assert_plugin_started();
}
// disabled until new builder loaded into tested FCF plugin
// public function test_plugin_free_can_start() {
// remove_all_actions('wpdesk_tracker_instance');
// $this->plugin_start_from_flow_file(__DIR__ . '/../../src/plugin-init-php52-free.php');
// $this->assert_plugin_started();
// }
}
<?php
// disable xdebug backtrace
if ( function_exists( 'xdebug_disable' ) ) {
xdebug_disable();
}
define( 'DOING_TESTS', true );
if ( getenv( 'DEPENDENT_PLUGINS_DIR' ) !== false ) {
define( 'DEPENDENT_PLUGINS_DIR', getenv( 'DEPENDENT_PLUGINS_DIR' ) );
} else {
define( 'DEPENDENT_PLUGINS_DIR', '/tmp/plugins' );
}
if ( getenv( 'PLUGIN_PATH' ) !== false ) {
define( 'PLUGIN_PATH', getenv( 'PLUGIN_PATH' ) );
} else {
define( 'PLUGIN_PATH', __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR );
}
require_once( getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit/includes/functions.php' );
tests_add_filter( 'muplugins_loaded', function () {
$plugins_to_active = get_option( 'active_plugins' );
$plugins_to_active[] = 'woocommerce/woocommerce.php';
update_option( 'active_plugins', $plugins_to_active );
}, 100 );
putenv( 'WP_TESTS_DIR=' . getenv( 'WP_DEVELOP_DIR' ) . '/tests/phpunit' );
require_once( getenv( 'WC_DEVELOP_DIR' ) . '/tests/legacy/bootstrap.php' );
#!/bin/bash
if [ ! -d $DEPENDENT_PLUGINS_DIR/flexible-checkout-fields ]
then
echo "FCF"
/tmp/clone.sh git@gitlab.com:wpdesk/flexible-checkout-fields.git $DEPENDENT_PLUGINS_DIR/flexible-checkout-fields master
cd $DEPENDENT_PLUGINS_DIR/flexible-checkout-fields/
composer install
cd /tmp
fi
echo
<?php
use WPDesk\Plugin\Flow\Initialization\InitializationFactory;
use WPDesk\Plugin\Flow\Initialization\InitializationStrategy;
use WPDesk\Plugin\Flow\PluginBootstrap;
class Test_Plugin_Bootstrap extends \WP_Mock\Tools\TestCase {
const WP_VERSION = 5.5;
public function setUp() {
WP_Mock::setUp();
WP_Mock::userFunction( 'get_locale',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'load_plugin_textdomain',
[
'return' => true,
] );
WP_Mock::userFunction( 'get_bloginfo',
[
'return' => self::WP_VERSION,
] );
WP_Mock::userFunction( 'plugin_basename',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'plugins_url',
[
'return' => 'whatever',
] );
! defined( 'WP_PLUGIN_DIR' ) && define( 'WP_PLUGIN_DIR', __DIR__ . '/../../Stub/' );
}
public function tearDown() {
WP_Mock::tearDown();
}
public function test_free_plugin_can_reach_build_phase() {
$plugin_version = '1.0.0';
$plugin_release_timestamp = '2019-07-18 15:28';
$plugin_name = 'whatever';
$plugin_class_name = 'whatever';
$plugin_text_domain = 'whatever';
$product_id = 'whatever';
$plugin_file = 'whatever';
$plugin_dir = 'whatever';
$requirements = [
'php' => 5.6,
'wp' => self::WP_VERSION,
];
$plugin_build_factory = $this->createMock( InitializationFactory::class );
/** @noinspection PhpParamsInspection */
$bootstrap = new PluginBootstrap(
$plugin_version,
$plugin_release_timestamp,
$plugin_name,
$plugin_class_name,
$plugin_text_domain,
$plugin_dir,
$plugin_file,
$requirements,
$product_id,
$plugin_build_factory,
[]
);
$plugin_build_factory->expects( $this->once() )
->method( 'create_initialization_strategy' )
->willReturn($this->createMock( InitializationStrategy::class));
$bootstrap->run();
}
}
<?php
use WPDesk\Plugin\Flow\Initialization\Simple\SimplePaidStrategy;
class Test_Plugin_Initialization_Strategy_Simple extends \WP_Mock\Tools\TestCase {
const WP_VERSION = 5.5;
public function setUp() {
WP_Mock::setUp();
}
public function tearDown() {
WP_Mock::tearDown();
}
/**
* @runInSeparateProcess
*/
public function test_strategy_can_build_front() {
$info = new \WPDesk_Plugin_Info();
$info->set_class_name( Stub_Plugin::class );
WP_Mock::userFunction( 'plugin_dir_url',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'is_admin',
[
'return' => false,
] );
WP_Mock::userFunction( 'get_option',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'plugin_basename',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'trailingslashit' )->andReturnArg( 0 );
WP_Mock::userFunction( 'plugins_url' )->andReturnArg( 0 );
$strategy = new SimplePaidStrategy( $info );
$this->assertInstanceOf( Stub_Plugin::class, $strategy->run_init( $info ), "Plugin should be actually built" );
}
}
<?php
use WPDesk\Plugin\Flow\Initialization\Simple\SimpleFactory;
use WPDesk\Plugin\Flow\Initialization\Simple\SimpleFreeStrategy;
use WPDesk\Plugin\Flow\Initialization\Simple\SimplePaidStrategy;
class Test_Plugin_Initialization_Strategy_Simple_Factory extends \WP_Mock\Tools\TestCase {
public function setUp() {
WP_Mock::setUp();
}
public function tearDown() {
WP_Mock::tearDown();
}
public function test_free_plugin_can_create_free_strategy() {
$stubInfo = new \WPDesk_Plugin_Info();
$factory = new SimpleFactory(true);
$strategy = $factory->create_initialization_strategy($stubInfo);
$this->assertInstanceOf(SimpleFreeStrategy::class, $strategy, 'Free strategy should be created');
}
public function test_free_plugin_can_create_standard_strategy() {
$stubInfo = new \WPDesk_Plugin_Info();
$factory = new SimpleFactory();
$strategy = $factory->create_initialization_strategy($stubInfo);
$this->assertInstanceOf( SimplePaidStrategy::class, $strategy, 'Standard strategy should be created');
}
}
<?php
use WPDesk\Plugin\Flow\Initialization\Simple\SimpleFreeStrategy;
class Test_Plugin_Initialization_Strategy_Simple_Free extends \WP_Mock\Tools\TestCase {
public function setUp() {
WP_Mock::setUp();
}
public function tearDown() {
WP_Mock::tearDown();
}
/**
* @runInSeparateProcess
*/
public function test_strategy_can_build() {
$info = new \WPDesk_Plugin_Info();
$info->set_class_name( Stub_Plugin::class );
WP_Mock::userFunction( 'plugin_dir_url',
[
'return' => 'whatever',
] );
WP_Mock::userFunction( 'plugin_basename',
[
'return' => 'whatever',
] );
$strategy = new SimpleFreeStrategy( $info );
$this->assertInstanceOf( Stub_Plugin::class, $strategy->run_init( $info ), "Plugin should be actually built" );
}
}
<?php
/**
* PHPUnit bootstrap file
*/
require_once __DIR__ . '/../../vendor/autoload.php';
WP_Mock::setUsePatchwork( true );
WP_Mock::bootstrap();
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