This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook
woocommerce_single_product_summary
action to `core/post-excerp…
…t` block (#11953) * hook woocommerce_single_product_summary into core/post-excerpt block * Add E2E tests * improve E2E test
- Loading branch information
Showing
3 changed files
with
244 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
tests/e2e/tests/single-product-template/compatibility-plugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
/** | ||
* Plugin Name: Compatibility Layer Plugin | ||
* Description: Adds custom content to the Shop page with Product Collection included | ||
* @package WordPress | ||
*/ | ||
|
||
add_action( | ||
'woocommerce_before_main_content', | ||
function () { | ||
echo '<p data-testid="woocommerce_before_main_content"> | ||
Hook: woocommerce_before_main_content | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_sidebar', | ||
function () { | ||
echo '<p data-testid="woocommerce_sidebar"> | ||
Hook: woocommerce_sidebar | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_before_single_product', | ||
function () { | ||
echo '<p data-testid="woocommerce_before_single_product"> | ||
Hook: woocommerce_before_single_product | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_before_single_product_summary', | ||
function () { | ||
echo '<p data-testid="woocommerce_before_single_product_summary"> | ||
Hook: woocommerce_before_single_product_summary | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_single_product_summary', | ||
function () { | ||
echo '<p data-testid="woocommerce_single_product_summary"> | ||
Hook: woocommerce_single_product_summary | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_before_add_to_cart_button', | ||
function () { | ||
echo '<p data-testid="woocommerce_before_add_to_cart_button"> | ||
Hook: woocommerce_before_add_to_cart_button | ||
</p>'; | ||
} | ||
); | ||
|
||
|
||
add_action( | ||
'woocommerce_product_meta_start', | ||
function () { | ||
echo '<p data-testid="woocommerce_product_meta_start"> | ||
Hook: woocommerce_product_meta_start | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_product_meta_end', | ||
function () { | ||
echo '<p data-testid="woocommerce_product_meta_end"> | ||
Hook: woocommerce_product_meta_end | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_share', | ||
function () { | ||
echo '<p data-testid="woocommerce_share"> | ||
Hook: woocommerce_share | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_after_single_product_summary', | ||
function () { | ||
echo '<p data-testid="woocommerce_after_single_product_summary"> | ||
Hook: woocommerce_after_single_product_summary | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_after_single_product', | ||
function () { | ||
echo '<p data-testid="woocommerce_after_single_product"> | ||
Hook: woocommerce_after_single_product | ||
</p>'; | ||
} | ||
); | ||
|
||
add_action( | ||
'woocommerce_after_main_content', | ||
function () { | ||
echo '<p data-testid="woocommerce_after_main_content"> | ||
Hook: woocommerce_after_main_content | ||
</p>'; | ||
} | ||
); |
125 changes: 125 additions & 0 deletions
125
tests/e2e/tests/single-product-template/single-product-template-compatibility-layer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect } from '@woocommerce/e2e-playwright-utils'; | ||
import { | ||
installPluginFromPHPFile, | ||
uninstallPluginFromPHPFile, | ||
} from '@woocommerce/e2e-mocks/custom-plugins'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
type Scenario = { | ||
title: string; | ||
dataTestId: string; | ||
content: string; | ||
amount: number; | ||
}; | ||
|
||
const singleOccurranceScenarios: Scenario[] = [ | ||
{ | ||
title: 'Before Main Content', | ||
dataTestId: 'woocommerce_before_main_content', | ||
content: 'Hook: woocommerce_before_main_content', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Sidebar', | ||
dataTestId: 'woocommerce_sidebar', | ||
content: 'Hook: woocommerce_sidebar', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Before Single Product', | ||
dataTestId: 'woocommerce_before_single_product', | ||
content: 'Hook: woocommerce_before_single_product', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Before Single Product Summary', | ||
dataTestId: 'woocommerce_before_single_product_summary', | ||
content: 'Hook: woocommerce_before_single_product_summary', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Before Add To Cart Button', | ||
dataTestId: 'woocommerce_before_add_to_cart_button', | ||
content: 'Hook: woocommerce_before_add_to_cart_button', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Single Product Summary', | ||
dataTestId: 'woocommerce_single_product_summary', | ||
content: 'Hook: woocommerce_single_product_summary', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Product Meta Start', | ||
dataTestId: 'woocommerce_product_meta_start', | ||
content: 'Hook: woocommerce_product_meta_start', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Product Meta End', | ||
dataTestId: 'woocommerce_product_meta_end', | ||
content: 'Hook: woocommerce_product_meta_end', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'Share', | ||
dataTestId: 'woocommerce_share', | ||
content: 'Hook: woocommerce_share', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'After Single Product Summary', | ||
dataTestId: 'woocommerce_after_single_product_summary', | ||
content: 'Hook: woocommerce_after_single_product_summary', | ||
amount: 1, | ||
}, | ||
{ | ||
title: 'After Single Product', | ||
dataTestId: 'woocommerce_after_single_product', | ||
content: 'Hook: woocommerce_after_single_product', | ||
amount: 1, | ||
}, | ||
]; | ||
|
||
const compatiblityPluginFileName = 'compatibility-plugin.php'; | ||
|
||
test.describe( 'Compatibility Layer with Product Collection block', () => { | ||
test.beforeAll( async () => { | ||
await installPluginFromPHPFile( | ||
`${ __dirname }/${ compatiblityPluginFileName }` | ||
); | ||
} ); | ||
|
||
test.describe( | ||
'Product Archive with Product Collection block', | ||
async () => { | ||
test.beforeAll( async ( { page } ) => { | ||
await page.goto( '/product/hoodie/' ); | ||
} ); | ||
|
||
for ( const scenario of singleOccurranceScenarios ) { | ||
test( `${ scenario.title } is attached to the page`, async ( { | ||
page, | ||
} ) => { | ||
const hooks = page.getByTestId( scenario.dataTestId ); | ||
|
||
await expect( hooks ).toHaveCount( scenario.amount ); | ||
await expect( hooks ).toHaveText( scenario.content ); | ||
} ); | ||
} | ||
} | ||
); | ||
} ); | ||
|
||
test.afterAll( async ( { requestUtils } ) => { | ||
await uninstallPluginFromPHPFile( | ||
`${ __dirname }/${ compatiblityPluginFileName }` | ||
); | ||
await requestUtils.deleteAllTemplates( 'wp_template' ); | ||
} ); |