diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 16:41:48 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 16:47:14 -0300 |
| commit | 535dbda6b48171f8115b455e54790de94d97d42a (patch) | |
| tree | 5c0410011e61a883bdf063ee612875a637fb1d22 /test/setup.sh | |
| download | woocommerce-535dbda6b48171f8115b455e54790de94d97d42a.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'test/setup.sh')
| -rwxr-xr-x | test/setup.sh | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/test/setup.sh b/test/setup.sh new file mode 100755 index 0000000..6925386 --- /dev/null +++ b/test/setup.sh @@ -0,0 +1,158 @@ +#!/bin/sh +# +# Stand up the WordPress + WooCommerce store the browser tests drive. +# +# Idempotent: running it again on a live stack reconfigures rather than +# rebuilds. `make clean` is what throws the volumes away. + +set -eu + +cd "$(dirname "$0")" + +SITE="http://127.0.0.1:8090" + +wp() { + docker compose exec -T cli wp "$@" +} + +printf 'bringing the stack up\n' +docker compose up -d >/dev/null + +printf 'waiting for the web server\n' +i=0 +while [ "$i" -lt 90 ]; do + code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 2 "$SITE/" 2>/dev/null || echo 000) + [ "$code" != "000" ] && break + i=$((i + 1)) + sleep 2 +done +[ "$code" = "000" ] && { printf 'web server never answered\n' >&2; exit 1; } + +if ! wp core is-installed >/dev/null 2>&1; then + printf 'installing WordPress\n' + wp core install \ + --url="$SITE" \ + --title="CEP Test Store" \ + --admin_user=admin \ + --admin_password=admin \ + --skip-email >/dev/null +fi + +wp rewrite structure '/%postname%/' >/dev/null 2>&1 +wp rewrite flush >/dev/null 2>&1 + +if ! wp plugin is-installed woocommerce >/dev/null 2>&1; then + printf 'installing WooCommerce\n' + wp plugin install woocommerce >/dev/null +fi +wp plugin activate woocommerce >/dev/null + +printf 'configuring the store\n' +wp option update woocommerce_store_address "Praça da Sé" >/dev/null +wp option update woocommerce_store_city "São Paulo" >/dev/null +wp option update woocommerce_default_country "BR:SP" >/dev/null +wp option update woocommerce_store_postcode "01001000" >/dev/null +wp option update woocommerce_currency BRL >/dev/null +wp option update woocommerce_allowed_countries all >/dev/null +wp option update woocommerce_enable_guest_checkout yes >/dev/null +wp option update woocommerce_enable_checkout_login_reminder no >/dev/null +wp option update woocommerce_calc_taxes no >/dev/null +wp option update woocommerce_cod_settings \ + '{"enabled":"yes","title":"Pagamento na entrega","description":"","instructions":""}' \ + --format=json >/dev/null +wp eval 'if ( ! WC_Shipping_Zones::get_zone( 0 )->get_shipping_methods() ) { WC_Shipping_Zones::get_zone( 0 )->add_shipping_method( "flat_rate" ); }' >/dev/null + +wp eval ' +$id = (int) get_option( "cepis_test_product", 0 ); +if ( ! $id || ! wc_get_product( $id ) ) { + $product = new WC_Product_Simple(); + $product->set_name( "Caneca" ); + $product->set_regular_price( "25" ); + $product->set_virtual( false ); + $id = $product->save(); + update_option( "cepis_test_product", $id ); +} +' >/dev/null + +wp eval ' +$blocks = 0; +foreach ( get_pages( array( "post_status" => "publish" ) ) as $page ) { + if ( has_block( "woocommerce/checkout", $page ) ) { + $blocks = (int) $page->ID; + break; + } +} +if ( ! $blocks ) { + WP_CLI::error( "no page holds the woocommerce/checkout block" ); +} +update_option( "cepis_test_blocks_page", $blocks ); +update_option( "woocommerce_checkout_page_id", $blocks ); + +$classic = get_page_by_path( "checkout-classico" ); +if ( ! $classic ) { + $id = wp_insert_post( array( + "post_title" => "Checkout classico", + "post_name" => "checkout-classico", + "post_content" => "[woocommerce_checkout]", + "post_status" => "publish", + "post_type" => "page", + ) ); +} else { + $id = (int) $classic->ID; +} +update_option( "cepis_test_classic_page", $id ); +' >/dev/null + +printf 'installing the fixture that imitates Brazilian Market on WooCommerce\n' +docker compose exec -T cli sh -c 'mkdir -p /var/www/html/wp-content/mu-plugins && cat > /var/www/html/wp-content/mu-plugins/cepis-test-br-fields.php' <<'PHP' +<?php +/** + * Adds the house-number and neighbourhood fields that "Brazilian Market on + * WooCommerce" adds, so the plugin can be tested with and without them. + * Switched by the `cepis_test_br_fields` option. + */ + +function cepis_test_br_fields( $fields, $prefix ) { + if ( 'yes' !== get_option( 'cepis_test_br_fields' ) ) { + return $fields; + } + + $fields[ $prefix . '_number' ] = array( + 'label' => 'Número', + 'required' => false, + 'class' => array( 'form-row-first', 'address-field' ), + 'priority' => 51, + ); + $fields[ $prefix . '_neighborhood' ] = array( + 'label' => 'Bairro', + 'required' => false, + 'class' => array( 'form-row-last', 'address-field' ), + 'priority' => 52, + ); + + return $fields; +} + +add_filter( 'woocommerce_billing_fields', function ( $fields ) { + return cepis_test_br_fields( $fields, 'billing' ); +} ); + +add_filter( 'woocommerce_shipping_fields', function ( $fields ) { + return cepis_test_br_fields( $fields, 'shipping' ); +} ); + +/** + * Force the site locale from an option, so the shipped translation can be + * exercised without downloading WordPress's own language pack. + */ +add_filter( 'locale', function ( $locale ) { + $forced = get_option( 'cepis_test_locale' ); + + return $forced ? $forced : $locale; +} ); +PHP + +wp plugin activate cepis-woocommerce >/dev/null + +printf 'ready: %s\n' "$SITE" |