Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 295 additions & 27 deletions classes/class-wc-connect-nux.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions classes/class-wc-connect-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function get_option_names( $type = 'compact' ) {
'predefined_packages',
'shipping_methods_migrated',
'should_display_nux_after_jp_cxn_banner',
'should_display_nux_contextual_banner',
'needs_tax_environment_setup',
'banner_ppec',
);
Expand Down
5 changes: 3 additions & 2 deletions client/components/migration/feature-announcement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import {
import { installAndActivatePlugins } from './migration-runner';
import { TIME_TO_REMMEMBER_DISMISSAL_SECONDS } from './constants';

const FeatureAnnouncement = ( { translate, isEligable, previousMigrationState, onClose } ) => {
const [isOpen, setIsOpen] = useState(isEligable);
const FeatureAnnouncement = ( { translate, isEligable, previousMigrationState, onClose, forceOpen = false } ) => {
// Open if either normally eligible OR if forced open by the prop.
const [isOpen, setIsOpen] = useState( forceOpen || isEligable );
const [isUpdating, setIsUpdating] = useState(false);

useEffect( () => {
Expand Down
9 changes: 6 additions & 3 deletions client/components/migration/migration-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,14 @@ const installAndActivatePlugins = async( previousMigrationState ) => {
* @returns {string} The next state to run. The name of the state is the key in this object migrationStateTransitions.
*/
const getNextStateToRun = () => {
if ( ! previousMigrationState ) {
// stateInit
// Check if previousMigrationState is a valid key in the map.
// If not, or if it's falsy, default to the initial state (stateInit).
if ( ! previousMigrationState || ! MIGRATION_ENUM_TO_STATE_NAME_MAP.hasOwnProperty( previousMigrationState ) ) {
// stateInit (key 2)
return MIGRATION_ENUM_TO_STATE_NAME_MAP[ 2 ];
}

// If it's a valid key, find the corresponding state name and return its success transition.
const currentStateName = MIGRATION_ENUM_TO_STATE_NAME_MAP[ previousMigrationState ];
const nextMigrationState = getMigrationStateByName( currentStateName );
return nextMigrationState.success; // The next state is "success".
Expand All @@ -258,4 +261,4 @@ const installAndActivatePlugins = async( previousMigrationState ) => {

export {
installAndActivatePlugins
}
}
52 changes: 30 additions & 22 deletions client/wcshipping-migration-admin-notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,36 @@ const store = createStore(ShippingLabelStore.getReducer(), ShippingLabelStore.ge
const wcstWCShippingMigrationNoticeButton = document.getElementById('wcst-wcshipping-migration-notice__click');
const wcstMigrationNoticeDimissButton = document.querySelector('.wcst-wcshipping-migration-notice button.notice-dismiss');

// Add all button events
["click", "keydown"].forEach(eventName => {
// Clicking "Confirm update" will start the migration. This is the same as popping up the modal and clicking the "Update" button there.
wcstWCShippingMigrationNoticeButton.addEventListener(eventName, (evt) => {
/**
* Prevent form submission when rendered in a form or alike that listens to button click
*/
evt.preventDefault();
// Pop open feature announcement modal.
ReactDOM.render(
<Provider store={store}>
<FeatureAnnouncement />
</Provider>,
container
);
if (wcstWCShippingMigrationNoticeButton) {
// Add all button events
["click", "keydown"].forEach(eventName => {
// Clicking "Confirm update" will start the migration. This is the same as popping up the modal and clicking the "Update" button there.
wcstWCShippingMigrationNoticeButton.addEventListener(eventName, (evt) => {
/**
* Prevent form submission when rendered in a form or alike that listens to button click
*/
evt.preventDefault();
// Pop open feature announcement modal, forcing it open regardless of eligibility state.
ReactDOM.render(
<Provider store={store}>
<FeatureAnnouncement forceOpen={ true } />
</Provider>,
container
);
});
});
}

// Dismiss it for 3 days, then remove it from view.
wcstMigrationNoticeDimissButton.addEventListener(eventName, () => {
// window.wpCookies API: wordpress/wp-includes/js/utils.js
window.wpCookies.set('wcst-wcshipping-migration-dismissed', 1, TIME_TO_REMMEMBER_DISMISSAL_SECONDS)
const wcstMigrationAdminNotice = document.querySelector('.wcst-wcshipping-migration-notice');
wcstMigrationAdminNotice.remove();
// Dismiss it for 3 days, then remove it from view.
if (wcstMigrationNoticeDimissButton) {
["click", "keydown"].forEach(eventName => {
wcstMigrationNoticeDimissButton.addEventListener(eventName, () => {
// window.wpCookies API: wordpress/wp-includes/js/utils.js
window.wpCookies.set('wcst-wcshipping-migration-dismissed', 1, TIME_TO_REMMEMBER_DISMISSAL_SECONDS)
const wcstMigrationAdminNotice = document.querySelector('.wcst-wcshipping-migration-notice');
if (wcstMigrationAdminNotice) {
wcstMigrationAdminNotice.remove();
}
});
});
});
}
Empty file.
Empty file.
44 changes: 44 additions & 0 deletions tests/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y software-properties-common curl gnupg2 lsb-release

# Add ondrej/php PPA for PHP 8.2 packages
RUN add-apt-repository ppa:ondrej/php -y \
&& apt-get update

# Install PHP 8.2 and extensions
RUN apt-get install -y \
php8.2 \
php8.2-cli \
php8.2-mysql \
php8.2-xml \
php8.2-mbstring \
php8.2-curl \
php8.2-zip \
php8.2-intl \
php8.2-bcmath \
php8.2-simplexml \
php8.2-tokenizer \
php8.2-xdebug \
php-pear \
git \
subversion \
mariadb-client \
nodejs \
npm \
unzip \
&& npm install -g pnpm \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

# Install composer globally
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

WORKDIR /workspace

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
36 changes: 36 additions & 0 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.8"

services:
mariadb:
image: mariadb:10.9
container_name: mariadb_container
environment:
MYSQL_USER: wp_test
MYSQL_PASSWORD: wp_test
MYSQL_DATABASE: wordpress_default
MYSQL_ROOT_PASSWORD: root
ports:
- 3307:3306
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3

php-tests:
build: .
container_name: php_tests_container
depends_on:
- mariadb
working_dir: /workspace
tty: true
stdin_open: true
volumes:
- ../../:/workspace:cached
environment:
MYSQL_USER: wp_test
MYSQL_PASSWORD: wp_test
MYSQL_DATABASE: wordpress_default
MYSQL_ROOT_PASSWORD: root
WP_VERSION: "6.3.0" # adjust as needed
WC_VERSION: "7.6.1" # adjust as needed
3 changes: 3 additions & 0 deletions tests/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -e
exec "$@"
35 changes: 35 additions & 0 deletions tests/docker/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

WC_VERSION=${WC_VERSION:-"7.6.1"}
WP_VERSION=${WP_VERSION:-"6.3.0"}

echo "Cleaning previous WooCommerce clone..."
if [ -d /tmp/woocommerce ]; then
chmod -R u+w /tmp/woocommerce || true
rm -rf /tmp/woocommerce
fi

echo "Cloning WooCommerce $WC_VERSION..."
git clone --depth=1 --branch="$WC_VERSION" https://github.com/woocommerce/woocommerce.git /tmp/woocommerce

echo "Installing WooCommerce dependencies..."
cd /tmp/woocommerce/plugins/woocommerce
composer install
php bin/generate-feature-config.php

echo "Setting up WordPress test environment..."
mysql -h mariadb -u root -proot -e "DROP DATABASE IF EXISTS wp_test;"
bash tests/bin/install.sh wp_test root root mariadb "${WP_VERSION}"

if [[ "$WC_VERSION" == "7.5.1" || "$WC_VERSION" == "7.6.1" ]]; then
echo "Installing PHPUnit 8 for legacy WC versions..."
composer require -W phpunit/phpunit:^8
fi

echo "Installing plugin dependencies..."
cd /workspace
composer install

echo "Running PHPUnit tests..."
./vendor/bin/phpunit -c phpunit.xml.dist
26 changes: 15 additions & 11 deletions tests/php/test-class_wc-connect-nux.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class WP_Test_WC_Connect_NUX extends WC_Unit_Test_Case {

public static function set_up_before_class() {
require_once dirname( __FILE__ ) . '/../../classes/class-wc-connect-nux.php';
require_once __DIR__ . '/../../classes/class-wc-connect-nux.php';
}

public function test_get_banner_type_to_display_dev_jp() {
Expand All @@ -22,13 +22,15 @@ public function test_get_banner_type_to_display_dev_jp() {
$this->assertEquals(
WC_Connect_Nux::get_banner_type_to_display(
array(
'jetpack_connection_status' => WC_Connect_Nux::JETPACK_OFFLINE_MODE,
'tos_accepted' => true,
'can_accept_tos' => null, // irrelevant here, TOS is accepted (DEV)
'should_display_after_cxn_banner' => false,
'jetpack_connection_status' => WC_Connect_Nux::JETPACK_OFFLINE_MODE,
'tos_accepted' => true,
'can_accept_tos' => null, // irrelevant here, TOS is accepted (DEV)
'should_display_after_cxn_banner' => false,
'store_country' => 'JP',
'should_display_contextual_banner' => true,
)
),
false
'after_cxn_non_us'
);

$this->assertEquals(
Expand Down Expand Up @@ -158,13 +160,15 @@ public function test_get_banner_type_to_display_with_jp_cxn_with_tos_acceptance(
$this->assertEquals(
WC_Connect_Nux::get_banner_type_to_display(
array(
'jetpack_connection_status' => WC_Connect_Nux::JETPACK_CONNECTED,
'tos_accepted' => true,
'can_accept_tos' => true,
'should_display_after_cxn_banner' => false,
'jetpack_connection_status' => WC_Connect_Nux::JETPACK_CONNECTED,
'tos_accepted' => true,
'can_accept_tos' => true,
'should_display_after_cxn_banner' => false,
'store_country' => 'JP',
'should_display_contextual_banner' => true,
)
),
false
'after_cxn_non_us'
);
}
}
4 changes: 2 additions & 2 deletions woocommerce-services.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static function get_wcs_version() {
*
* @return string
*/
private static function get_wc_connect_base_url() {
public static function get_wc_connect_base_url() {
return trailingslashit( defined( 'WOOCOMMERCE_CONNECT_DEV_SERVER_URL' ) ? WOOCOMMERCE_CONNECT_DEV_SERVER_URL : plugins_url( 'dist/', __FILE__ ) );
}

Expand Down Expand Up @@ -814,7 +814,7 @@ public function load_dependencies() {
$payment_methods_store = new WC_Connect_Payment_Methods_Store( $settings_store, $api_client, $logger );
$tracks = new WC_Connect_Tracks( $logger, __FILE__ );
$shipping_label = new WC_Connect_Shipping_Label( $api_client, $settings_store, $schemas_store, $payment_methods_store );
$nux = new WC_Connect_Nux( $tracks, $shipping_label );
$nux = new WC_Connect_Nux( $tracks, $shipping_label, $settings_store, $payment_methods_store, $schemas_store );
$taxjar = new WC_Connect_TaxJar_Integration( $api_client, $taxes_logger, $this->wc_connect_base_url );
$paypal_ec = new WC_Connect_PayPal_EC( $api_client, $nux );
$label_reports = new WC_Connect_Label_Reports( $settings_store );
Expand Down
Loading