Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Tests: add unit test workflow #72

Merged
merged 35 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
01092d7
chore: add workflow demo file
glaubersilva Oct 20, 2022
aec3ded
feature: checkout give repository
glaubersilva Oct 20, 2022
ac87b5f
feature: ls give folder
glaubersilva Oct 20, 2022
92b808d
fix: remove quotes
glaubersilva Oct 20, 2022
999f41b
fix: working-directory
glaubersilva Oct 20, 2022
a35661e
fix: ls path
glaubersilva Oct 20, 2022
67a313a
fix: checkout
glaubersilva Oct 20, 2022
e23f888
fix: checkout side by side
glaubersilva Oct 20, 2022
863612d
fix: path
glaubersilva Oct 20, 2022
e965c65
feature: composer install for give core
glaubersilva Oct 20, 2022
af3e25b
feature: add tests workflow
glaubersilva Oct 20, 2022
b235220
fix: syntax
glaubersilva Oct 20, 2022
9bae436
feature: add include-tests-workflow branch for tests
glaubersilva Oct 20, 2022
665fdcb
fix: branch name for tests
glaubersilva Oct 20, 2022
9f67090
fix: addon slug
glaubersilva Oct 21, 2022
0219828
refactor: temporary change for workflow tests
glaubersilva Oct 21, 2022
2525b2c
refactor: temporary change for workflow tests
glaubersilva Oct 21, 2022
004679d
refactor: temporary change for workflow tests
glaubersilva Oct 21, 2022
2a0e26b
refactor: use one DB per branch
glaubersilva Oct 21, 2022
150022a
refactor: revert to the original test code content
glaubersilva Oct 21, 2022
87d2544
refactor: remove test branch from action events
glaubersilva Oct 21, 2022
a8bc8c4
refactor: remove demo action
glaubersilva Oct 21, 2022
7884e56
refactor: remove comma
glaubersilva Oct 21, 2022
4116d0e
Merge branch 'develop' into feature/include-tests-workflow
Oct 31, 2022
fc8dace
test: add test comment to trigger new action
Oct 31, 2022
f68c7e7
refactor: move the order of steps around and add setupnode which migh…
Nov 1, 2022
d7e59a1
fix: build step
Nov 1, 2022
d2ee896
Merge branch 'develop' into feature/include-tests-workflow
Nov 1, 2022
689075f
tests: fix failing test
Nov 1, 2022
da7283d
tests: fix failing test for php8 named arguments
Nov 1, 2022
ef46d76
chore: update tests
Nov 1, 2022
9a1c4f3
feature: add new unit-tests action that references givewp-github-acti…
Nov 1, 2022
2f7e120
tests: use addon_slug input
Nov 1, 2022
a79c767
fix: remove unused ref
Nov 1, 2022
cd8415b
refactor: remove local testing action in favor of givewp-github-actions
Nov 1, 2022
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
148 changes: 148 additions & 0 deletions .github/workflows/wordpress-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: WordPress Tests

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master, develop ]
pull_request:
branches: [ master, develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Allows you to use this workflow as part of another workflow
workflow_call:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "test"
test:
# The type of runner that the job will run on
runs-on: ubuntu-18.04
strategy:
matrix:
php: [ 7.0, 7.4, 8.0 ]
mysql: [ 'mysql:5.6', 'mysql:8.0' ]
wordpress: [ '5.0', latest ]
exclude:
- php: 7.4
wordpress: '5.0'
- php: 8.0
wordpress: '5.0'

services:
mysql56:
image: mysql:5.6
env:
MYSQL_ROOT_PASSWORD: N0Tweak!@123!
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

# This was a total pain to get setup. The default authentication plugin changed in MySQL 8 and is incompatible
# with WordPress. So it needs to be set back to mysql_native_password. The best way to do this is to use the
# command option in docker to apply it once the container is set up... but Github Actions does not support this.
# The workaround is to execute the command in the options, but it is VITAL that it is the LAST option and that any
# environment variables are added via options. DO NOT ADD THE ENV LINE IN YAML. You've been warned.
# @see https://github.com/docker-library/mysql/issues/690
mysql80:
image: mysql:8.0
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=N0Tweak!@123! --entrypoint sh mysql:8.0 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout Addon
uses: actions/checkout@v3
with:
path: 'givewp-next-gen'

- name: Check out Give Core "develop" branch
uses: actions/checkout@v3
with:
repository: impress-org/givewp
ref: develop
path: 'give'

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

# @link https://github.com/spatie/laravel-activitylog/blob/master/.github/workflows/run-tests.yml
- name: Set Up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Store MySQL details in environment
run: |
case "$MYSQL_VERSION" in
'mysql:5.6')
MYSQL_PORT=${{ job.services.mysql56.ports[3306] }}
MYSQL_PASS=N0Tweak!@123!
;;
'mysql:8.0')
MYSQL_PORT=${{ job.services.mysql80.ports[3306] }}
MYSQL_PASS=N0Tweak!@123!
;;
esac
echo "mysql_port=$MYSQL_PORT" >> $GITHUB_ENV
echo "mysql_pass=$MYSQL_PASS" >> $GITHUB_ENV
env:
MYSQL_VERSION: ${{ matrix.mysql }}

- name: Configure MySQL
run: mysql -uroot --password='${{ env.mysql_pass}}' -h127.0.0.1 --port=${{env.mysql_port}}

- name: Set UP Give Core "develop" Branch
working-directory: './give'
run: |
composer install --no-progress --no-interaction
bash tests/includes/bin/install.sh wordpress_develop_test root ${{ env.mysql_pass }} 127.0.0.1:${{ env.mysql_port }} ${{ matrix.wordpress }}

- name: Install composer dependencies for Addon
working-directory: './givewp-next-gen'
run: composer install --no-progress --no-interaction

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16

- name: Run npm build for addon
working-directory: './givewp-next-gen'
run: |
npm ci
npm run dev

- name: Run Addon Tests Against Give Core "develop" Branch
working-directory: './givewp-next-gen'
run: php -d memory_limit=-1 vendor/bin/phpunit
env:
DB_PORT: ${{ env.mysql_port }}

- name: Check out Give Core "master" branch
uses: actions/checkout@v3
with:
repository: impress-org/givewp
ref: master
path: './give'

- name: Set UP Give Core "master" Branch
working-directory: './give'
run: |
composer install --no-progress --no-interaction
bash tests/includes/bin/install.sh wordpress_master_test root ${{ env.mysql_pass }} 127.0.0.1:${{ env.mysql_port }} ${{ matrix.wordpress }}

- name: Run Addon Tests Against Give Core "master" Branch
working-directory: './givewp-next-gen'
run: php -d memory_limit=-1 vendor/bin/phpunit
env:
DB_PORT: ${{ env.mysql_port }}
5 changes: 3 additions & 2 deletions tests/Feature/Controllers/BlockRenderControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public function testShouldReturnIframe()
$viewUrl = (new GenerateDonationFormViewRouteUrl())($formId, $formTemplateId);

$blockRenderController = new BlockRenderController();

$this->assertSame(
"<iframe data-givewp-embed src='$viewUrl'
style='width: 1px;min-width: 100%;border: 0;'></iframe>",
$blockRenderController->render(['formId' => $formId, 'formTemplateId' => $formTemplateId]));
$blockRenderController->render(['formId' => $formId, 'formTemplateId' => $formTemplateId])
);
}
}
12 changes: 5 additions & 7 deletions tests/Unit/DataTransferObjects/BlockAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ class BlockAttributesTest extends TestCase
public function attributesProvider(): array
{
return array(
['formId' => 1, 'formTemplateId' => 1],
['formId' => null, 'formTemplateId' => null],
['formId' => null, 'formTemplateId' => 1],
['formId' => 1, 'formTemplateId' => null],
['formId' => 1, null],
[null, 'formTemplateId' => 1],
[null, null],
['formId' => 1, 'formTemplateId' => 1],
['formId' => 1, 'formTemplateId' => null],
['formId' => null, 'formTemplateId' => 1],
['formId' => null, 'formTemplateId' => null],
[null, null],
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/ViewModels/FormBuilderViewModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function testShouldReturnStorageData()
$viewModel->storageData($formId),
[
'resourceURL' => rest_url(FormBuilderRestRouteConfig::NAMESPACE . '/form/' . $formId),
'previewURL' => site_url("?givewp-view=donation-form&form-id=$formId&form-template-id=classic"),
'nonce' => wp_create_nonce('wp_rest'),
'blockData' => get_post($formId)->post_content,
'settings' => get_post_meta($formId, 'formBuilderSettings', true),
Expand Down