PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / playwright / QuickEdit / wc-product / setup.php

setup.php in Extendify 3.1.0, at tests/playwright/QuickEdit/wc-product/setup.php

102 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 require '/wordpress/wp-load.php';
3
4 // Bypass WC's onboarding tasklist + setup wizard. Spec runs front-end
5 // only, but the admin redirects can intercept on first visit.
6 update_option('woocommerce_admin_install_timestamp', time());
7 update_option('woocommerce_task_list_hidden', 'yes');
8 update_option('woocommerce_extended_task_list_hidden', 'yes');
9
10 $uploadDir = wp_upload_dir();
11 if (!empty($uploadDir['path']) && !file_exists($uploadDir['path'])) {
12 wp_mkdir_p($uploadDir['path']);
13 }
14 require_once ABSPATH . 'wp-admin/includes/image.php';
15
16 $pngBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkAAIAAAoAAv/lxKUAAAAASUVORK5CYII=';
17
18 $primaryPath = trailingslashit($uploadDir['path']) . 'qe-wc-product.png';
19 file_put_contents($primaryPath, base64_decode($pngBase64));
20 $primaryImgId = wp_insert_attachment(
21 [
22 'post_mime_type' => 'image/png',
23 'post_title' => 'QE WC Product Primary',
24 'post_status' => 'inherit',
25 ],
26 $primaryPath
27 );
28 wp_update_attachment_metadata(
29 $primaryImgId,
30 wp_generate_attachment_metadata($primaryImgId, $primaryPath)
31 );
32
33 // Second image so the image-picker swap test has a distinct target.
34 $altPath = trailingslashit($uploadDir['path']) . 'qe-wc-product-alt.png';
35 file_put_contents($altPath, base64_decode($pngBase64));
36 $altImgId = wp_insert_attachment(
37 [
38 'post_mime_type' => 'image/png',
39 'post_title' => 'QE WC Product Alt',
40 'post_status' => 'inherit',
41 ],
42 $altPath
43 );
44 wp_update_attachment_metadata(
45 $altImgId,
46 wp_generate_attachment_metadata($altImgId, $altPath)
47 );
48
49 // Seed one WC product covering every field WCProductTagger maps:
50 // name (post_title), short_description (post_excerpt), regular + sale
51 // price (postmeta via the product object so derived _price stays in
52 // sync), and featured image (post thumbnail).
53 $productId = wp_insert_post([
54 'post_type' => 'product',
55 'post_status' => 'publish',
56 'post_title' => 'Original Product Name',
57 'post_excerpt' => 'Original short description.',
58 'post_content' => 'Long description content.',
59 ]);
60 set_post_thumbnail($productId, $primaryImgId);
61
62 if (function_exists('wc_get_product')) {
63 $product = wc_get_product($productId);
64 if ($product) {
65 $product->set_regular_price('30');
66 $product->set_sale_price('20');
67 $product->set_price('20');
68 $product->save();
69 }
70 }
71
72 // Front page: a core/query loop scoped to the seeded product so its
73 // postId context flows into the inner blocks (post-title, post-excerpt,
74 // product-price, product-image). WCProductTagger reads
75 // blockObj->context['postId'] from each — a regular page sidesteps any
76 // extendable + WC single-product template resolution differences and
77 // keeps the rendered DOM predictable across WC + wp-playground boots.
78 $content = '<!-- wp:query {"query":{"perPage":1,"postType":"product","postIn":[' . (int) $productId . ']}} -->'
79 . "\n<div class=\"wp-block-query\">"
80 . "\n<!-- wp:post-template -->"
81 . "\n<!-- wp:post-title {\"isLink\":false} /-->"
82 . "\n<!-- wp:post-excerpt /-->"
83 . "\n<!-- wp:woocommerce/product-price /-->"
84 . "\n<!-- wp:woocommerce/product-image /-->"
85 . "\n<!-- /wp:post-template -->"
86 . "\n</div>"
87 . "\n<!-- /wp:query -->";
88
89 $pageId = wp_insert_post([
90 'post_type' => 'page',
91 'post_status' => 'publish',
92 'post_title' => 'QE WC Product Home',
93 'post_content' => $content,
94 ]);
95
96 update_option('show_on_front', 'page');
97 update_option('page_on_front', $pageId);
98
99 update_option('extendify_qe_test_product_id', (int) $productId);
100 update_option('extendify_qe_test_primary_image_id', (int) $primaryImgId);
101 update_option('extendify_qe_test_alt_image_id', (int) $altImgId);
102