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 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
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>'; | ||
} | ||
); |
95 changes: 95 additions & 0 deletions
95
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,95 @@ | ||
/** | ||
* 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 Single Product', | ||
dataTestId: 'woocommerce_before_single_product', | ||
content: 'Hook: woocommerce_before_single_product', | ||
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: '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' ); | ||
} ); |