Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b2be2b8
wip
louiswol94 Jul 1, 2025
510e49e
wip
louiswol94 Jul 2, 2025
4fef005
wip
louiswol94 Jul 2, 2025
f65f5bc
wip
louiswol94 Jul 2, 2025
c7f3d3c
wip
louiswol94 Jul 2, 2025
29a540c
wip
louiswol94 Jul 2, 2025
c47c344
wip
louiswol94 Jul 2, 2025
b66db45
wip
louiswol94 Jul 2, 2025
55561ca
wip
louiswol94 Jul 2, 2025
f2720ac
wip
louiswol94 Jul 2, 2025
6477f86
wip
louiswol94 Jul 2, 2025
0eda7c9
wip
louiswol94 Jul 2, 2025
759aabd
wip
louiswol94 Jul 2, 2025
18bcfa3
wip
louiswol94 Jul 2, 2025
dc91357
wip
louiswol94 Jul 2, 2025
1d99420
wip
louiswol94 Jul 2, 2025
918e769
wip
louiswol94 Jul 2, 2025
737b3cf
wip
louiswol94 Jul 2, 2025
20ec189
wip
louiswol94 Jul 2, 2025
04e706d
wip
louiswol94 Jul 2, 2025
890481a
wip
louiswol94 Jul 5, 2025
3f5eea3
wip
louiswol94 Jul 5, 2025
69449a0
wip
louiswol94 Jul 5, 2025
91b7546
wip
louiswol94 Jul 5, 2025
0029e0f
wip
louiswol94 Jul 5, 2025
1a7789e
wip
louiswol94 Jul 5, 2025
dcc44ce
wip
louiswol94 Jul 5, 2025
87b9b2d
wip
louiswol94 Jul 5, 2025
9c168bf
wip
louiswol94 Jul 6, 2025
531ee35
wip
louiswol94 Jul 6, 2025
0b19d6e
wip
louiswol94 Jul 6, 2025
ff80d08
wip
louiswol94 Jul 6, 2025
b533854
wip
louiswol94 Jul 6, 2025
b983aa7
wip
louiswol94 Jul 6, 2025
e3a96ab
wip
louiswol94 Jul 6, 2025
a071dc8
wip
louiswol94 Jul 6, 2025
07f542b
wip
louiswol94 Jul 7, 2025
1970826
wip
louiswol94 Jul 7, 2025
4cd5ee8
wip
louiswol94 Jul 7, 2025
4d84a24
sync all changes from pro
louiswol94 Jul 24, 2025
4e16d45
Update version number and changelog for v3.7.0.
sheabunge Aug 29, 2025
8279304
Merge branch 'core' into flat-file
louiswol94 Oct 7, 2025
89825fb
Merge branch 'edit-refresh/core' into flat-file
louiswol94 Oct 7, 2025
68d0d3a
sync changes from pro
louiswol94 Oct 7, 2025
5a43f3c
remove unrelated changes
louiswol94 Oct 7, 2025
b72b791
Merge branch 'core' into flat-file
louiswol94 Oct 9, 2025
f384c78
file bases E2E tests
louiswol94 Oct 9, 2025
347abe7
update playwright command
louiswol94 Oct 9, 2025
c331651
fix playwright storage state
louiswol94 Oct 9, 2025
555bb31
clear opcache cache on save
louiswol94 Oct 9, 2025
0d36e23
eslint fix
louiswol94 Oct 9, 2025
73672e2
fix e2e test snippet for list page tests
louiswol94 Oct 9, 2025
819f7c0
reusable playwright workflow
louiswol94 Oct 9, 2025
1df506b
remove debug steps from playwright workflow
louiswol94 Oct 9, 2025
3e4a082
add workflow permissions
louiswol94 Oct 9, 2025
350ba54
remove permissions
louiswol94 Oct 9, 2025
8187aab
remove permissions
louiswol94 Oct 9, 2025
1680b33
Merge remote-tracking branch 'origin/core/core-beta' into flat-file
imantsk Oct 16, 2025
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
104 changes: 104 additions & 0 deletions .github/workflows/playwright-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Playwright Test Runner

on:
workflow_call:
inputs:
test-mode:
required: true
type: string
description: 'Test mode: default or file-based-execution'
project-name:
required: true
type: string
description: 'Playwright project name to run'

jobs:
playwright-test:
name: Playwright tests (${{ inputs.test-mode == 'default' && 'Default Mode' || 'File-based Execution' }})
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up PHP
uses: codesnippetspro/setup-php@v2
with:
php-version: "8.1"

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'npm'

- name: Compute dependency hash
id: deps-hash
run: |
set -euo pipefail
tmpfile=$(mktemp)
for f in src/composer.lock package-lock.json; do
if [ -f "$f" ]; then
cat "$f" >> "$tmpfile"
fi
done
if [ -s "$tmpfile" ]; then
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8)
else
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)
fi
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT"

- name: Get build cache
id: deps-cache
uses: actions/cache/restore@v4
with:
path: |
node_modules
src/vendor
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
restore-keys: |
${{ runner.os }}-deps-

- name: Install workflow dependencies (wp-env, playwright)
if: steps.deps-cache.outputs.cache-hit != 'true'
run: npm run prepare-environment:ci && npm run bundle

- name: Save vendor and node_modules cache
if: steps.deps-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
src/vendor
node_modules
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}

- name: Start WordPress environment
run: |
npx wp-env start

- name: Activate code-snippets plugin
run: npx wp-env run cli wp plugin activate code-snippets

- name: WordPress debug information
run: |
npx wp-env run cli wp core version
npx wp-env run cli wp --info

- name: Install playwright/test
run: |
npx playwright install chromium

- name: Run Playwright tests
run: npm run test:playwright -- --project=${{ inputs.project-name }}

- name: Stop WordPress environment
if: always()
run: npx wp-env stop

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-test-results-${{ inputs.test-mode }}
path: test-results/
if-no-files-found: ignore
retention-days: 2
118 changes: 21 additions & 97 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,107 +24,31 @@ concurrency:
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
Playwright:
name: Playwright test on PHP 8.1
runs-on: ubuntu-22.04
playwright-default:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up PHP
uses: codesnippetspro/setup-php@v2
with:
php-version: "8.1"

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version-file: .node-version
cache: 'npm'

- name: Compute dependency hash
id: deps-hash
run: |
set -euo pipefail
# concatenate existing lock files (src/composer.lock and package-lock.json)
tmpfile=$(mktemp)
for f in src/composer.lock package-lock.json; do
if [ -f "$f" ]; then
cat "$f" >> "$tmpfile"
fi
done
if [ -s "$tmpfile" ]; then
deps_hash=$(shasum -a 1 "$tmpfile" | awk '{print $1}' | cut -c1-8)
else
# no lock files found, fall back to short commit sha
deps_hash=$(echo "${GITHUB_SHA:-unknown}" | cut -c1-8)
fi
echo "deps_hash=$deps_hash" >> "$GITHUB_OUTPUT"

- name: Get build cache
id: deps-cache
uses: actions/cache/restore@v4
with:
path: |
node_modules
src/vendor
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}
restore-keys: |
${{ runner.os }}-deps-

- name: Install workflow dependencies (wp-env, playwright)
if: steps.deps-cache.outputs.cache-hit != 'true'
run: npm run prepare-environment:ci && npm run bundle

- name: Save vendor and node_modules cache
if: steps.deps-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
src/vendor
node_modules
key: ${{ runner.os }}-deps-${{ steps.deps-hash.outputs.deps_hash }}

- name: Start WordPress environment
run: |
npx wp-env start
uses: ./.github/workflows/playwright-test.yml
with:
test-mode: 'default'
project-name: 'chromium-db-snippets'

- name: Activate code-snippets plugin
run: npx wp-env run cli wp plugin activate code-snippets

- name: WordPress debug information
run: |
npx wp-env run cli wp core version
npx wp-env run cli wp --info

- name: Install playwright/test
run: |
npx playwright install chromium

- name: Run Playwright tests
run: npm run test:playwright

- name: Stop WordPress environment
if: always()
run: npx wp-env stop

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-test-results
path: test-results/
if-no-files-found: ignore
retention-days: 2
playwright-file-based-execution:
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'run-tests')
uses: ./.github/workflows/playwright-test.yml
with:
test-mode: 'file-based-execution'
project-name: 'chromium-file-based-snippets'

test-result:
needs: [Playwright]
if: always() && (needs.Playwright.result != 'skipped')
needs: [playwright-default, playwright-file-based-execution]
if: always() && (needs.playwright-default.result != 'skipped' || needs.playwright-file-based-execution.result != 'skipped')
runs-on: ubuntu-22.04
name: Playwright - Test Results
name: Playwright - Test Results Summary
steps:
- name: Test status
run: echo "Test status is - ${{ needs.Playwright.result }}"
- name: Check Playwright status
if: ${{ needs.Playwright.result != 'success' && needs.Playwright.result != 'skipped' }}
- name: Test status summary
run: |
echo "Default Mode: ${{ needs.playwright-default.result }}"
echo "File-based Execution: ${{ needs.playwright-file-based-execution.result }}"

- name: Check overall status
if: ${{ (needs.playwright-default.result != 'success' && needs.playwright-default.result != 'skipped') || (needs.playwright-file-based-execution.result != 'success' && needs.playwright-file-based-execution.result != 'skipped') }}
run: exit 1
19 changes: 19 additions & 0 deletions src/php/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ class Plugin {
*/
public Licensing $licensing;

/**
* Handles snippet handler registration.
*
* @var Snippet_Handler_Registry
*/
public Snippet_Handler_Registry $snippet_handler_registry;

/**
* Class constructor
*
Expand Down Expand Up @@ -130,6 +137,18 @@ public function load_plugin() {
// Cloud List Table shared functions.
require_once $includes_path . '/cloud/list-table-shared-ops.php';

// Snippet files.
$this->snippet_handler_registry = new Snippet_Handler_Registry( [
'php' => new Php_Snippet_Handler(),
'html' => new Html_Snippet_Handler(),
] );

$fs = new WordPress_File_System_Adapter();

$config_repo = new Snippet_Config_Repository( $fs );

( new Snippet_Files( $this->snippet_handler_registry, $fs, $config_repo ) )->register_hooks();

$this->front_end = new Front_End();
$this->cloud_api = new Cloud_API();

Expand Down
2 changes: 1 addition & 1 deletion src/php/class-snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function get_type_from_scope( string $scope ): string {
*
* @return string The snippet type – will be a filename extension.
*/
protected function get_type(): string {
public function get_type(): string {
return self::get_type_from_scope( $this->scope );
}

Expand Down
54 changes: 52 additions & 2 deletions src/php/evaluation/class-evaluate-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Code_Snippets\DB;
use Code_Snippets\Snippet;
use Code_Snippets\Settings;
use Code_Snippets\Snippet_Files;
use function Code_Snippets\code_snippets;

/**
* Class for evaluating content snippets.
Expand Down Expand Up @@ -40,8 +43,13 @@ public function __construct( DB $db ) {
* Initialise class functions.
*/
public function init() {
add_action( 'wp_head', [ $this, 'load_head_content' ] );
add_action( 'wp_footer', [ $this, 'load_footer_content' ] );
if ( Snippet_Files::is_active() ) {
add_action( 'wp_head', [ $this, 'load_head_content_from_flat_files' ] );
add_action( 'wp_footer', [ $this, 'load_footer_content_from_flat_files' ] );
} else {
add_action( 'wp_head', [ $this, 'load_head_content' ] );
add_action( 'wp_footer', [ $this, 'load_footer_content' ] );
}
}

/**
Expand Down Expand Up @@ -77,4 +85,46 @@ public function load_head_content() {
public function load_footer_content() {
$this->print_content_snippets( 'footer-content' );
}

public function load_head_content_from_flat_files() {
$this->load_content_snippets_from_flat_files( 'head-content' );
}

public function load_footer_content_from_flat_files() {
$this->load_content_snippets_from_flat_files( 'footer-content' );
}

private function populate_active_snippets_from_flat_files() {
$handler = code_snippets()->snippet_handler_registry->get_handler( 'html' );
$dir_name = $handler->get_dir_name();
$ext = $handler->get_file_extension();

$scopes = [ 'head-content', 'footer-content' ];
$all_snippets = Snippet_Files::get_active_snippets_from_flat_files( $scopes, $dir_name );

foreach ( $all_snippets as $snippet ) {
$scope = $snippet['scope'];

// Add file path information to the snippet for later use
$table_name = Snippet_Files::get_hashed_table_name( $snippet['table'] );
$base_path = Snippet_Files::get_base_dir( $table_name, $dir_name );
$snippet['file_path'] = $base_path . '/' . $snippet['id'] . '.' . $ext;

$this->active_snippets[ $scope ][] = $snippet;
}
}

private function load_content_snippets_from_flat_files( string $scope ) {
if ( is_null( $this->active_snippets ) ) {
$this->populate_active_snippets_from_flat_files();
}

if ( ! isset( $this->active_snippets[ $scope ] ) ) {
return;
}

foreach ( $this->active_snippets[ $scope ] as $snippet ) {
require_once $snippet['file_path'];
}
}
}
Loading
Loading