Skip to content

Commit 7f484c2

Browse files
authored
Merge pull request #87 from Kit/updated-coding-standards
Use `WordPress` Coding Standards ruleset
2 parents 32f9809 + 1a8c827 commit 7f484c2

File tree

6 files changed

+63
-23
lines changed

6 files changed

+63
-23
lines changed

.env.dist.testing

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ TEST_SITE_TABLE_PREFIX=wp_
77
TEST_SITE_ADMIN_USERNAME=admin
88
TEST_SITE_ADMIN_PASSWORD=password
99
TEST_SITE_WP_ADMIN_PATH=/wp-admin
10-
WP_ROOT_FOLDER="/home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress"
10+
WP_ROOT_FOLDER="/var/www/html"
1111
WP_ENVIRONMENT_TYPE=local
1212
TEST_DB_NAME=test
1313
TEST_DB_HOST=localhost
@@ -17,7 +17,7 @@ TEST_TABLE_PREFIX=wp_
1717
TEST_SITE_WP_URL=http://127.0.0.1
1818
TEST_SITE_WP_DOMAIN=127.0.0.1
1919
20-
TEST_SITE_CONFIG_FILE="/home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress/wp-content/plugins/convertkit-wordpress-libraries/tests/_support/WpunitTesterConfig.php"
20+
TEST_SITE_CONFIG_FILE="/var/www/html/wp-content/plugins/convertkit-wordpress-libraries/tests/_support/WpunitTesterConfig.php"
2121
CONVERTKIT_API_BROADCAST_ID="8697158"
2222
CONVERTKIT_API_CUSTOM_FIELD_ID="258240"
2323
CONVERTKIT_API_FORM_ID="2765139"

.github/workflows/tests.yml

+23-14
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717

1818
# Virtual Environment to use.
1919
# @see: https://github.com/actions/virtual-environments
20-
runs-on: ubuntu-20.04
20+
runs-on: ubuntu-latest
2121

2222
# Environment Variables.
2323
# Accessible by using ${{ env.NAME }}
2424
# Use ${{ secrets.NAME }} to include any GitHub Secrets in ${{ env.NAME }}
2525
# The base folder will always be /home/runner/work/github-repo-name/github-repo-name
2626
env:
27-
ROOT_DIR: /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress
28-
PLUGIN_DIR: /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress/wp-content/plugins/convertkit-wordpress-libraries
27+
ROOT_DIR: /var/www/html
28+
PLUGIN_DIR: /var/www/html/wp-content/plugins/convertkit-wordpress-libraries
2929
DB_NAME: test
3030
DB_USER: root
3131
DB_PASS: root
@@ -51,6 +51,13 @@ jobs:
5151

5252
# Steps to install, configure and run tests
5353
steps:
54+
# Checkout Plugin to /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries
55+
# We cannot checkout to ${{ env.PLUGIN_DIR }} as GitHub Actions require it be first placed in /home/runner/work/repo/repo
56+
- name: Checkout Plugin
57+
uses: actions/checkout@v4
58+
with:
59+
path: /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries
60+
5461
- name: Start MySQL
5562
run: sudo systemctl start mysql.service
5663

@@ -65,17 +72,15 @@ jobs:
6572

6673
# Some workflows checkout WordPress from GitHub, but that seems to bring a bunch of uncompiled files with it.
6774
# Instead download from wordpress.org stable.
68-
- name: Download WordPress
69-
run: wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz
70-
71-
- name: Extract WordPress
72-
run: tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz
73-
74-
# Checkout (copy) this repository's Plugin to this VM.
75-
- name: Checkout Plugin
76-
uses: actions/checkout@v4
77-
with:
78-
path: ${{ env.PLUGIN_DIR }}
75+
- name: Download and Extract WordPress
76+
run: |
77+
sudo chown -R runner:docker /var/www/html
78+
ls -la /var/www/html
79+
cd /var/www/html
80+
wget https://wordpress.org/wordpress-${{ matrix.wp-versions }}.tar.gz
81+
tar xfz wordpress-${{ matrix.wp-versions }}.tar.gz
82+
mv wordpress/* .
83+
rm -rf wordpress wordpress-${{ matrix.wp-versions }}.tar.gz
7984
8085
# We install WP-CLI, as it provides useful commands to setup and install WordPress through the command line.
8186
- name: Install WP-CLI
@@ -97,6 +102,10 @@ jobs:
97102
working-directory: ${{ env.ROOT_DIR }}
98103
run: wp-cli plugin install ${{ env.INSTALL_PLUGINS }}
99104

105+
# Move Plugin
106+
- name: Move Plugin
107+
run: mv /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/convertkit-wordpress-libraries ${{ env.PLUGIN_DIR }}
108+
100109
# Install PHP version to run tests against.
101110
- name: Install PHP
102111
uses: shivammathur/setup-php@v2

phpcs.xml

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<!-- Exclude traits from the PHP SDK. -->
1515
<exclude-pattern>class-convertkit-api-traits.php</exclude-pattern>
1616

17-
<!-- Check that code meets WordPress-Extra standards. -->
18-
<rule ref="WordPress-Extra">
17+
<!-- Check that code meets WordPress standards - this includes core, docs and extra. -->
18+
<rule ref="WordPress">
1919
<!--
2020
We may want a middle ground though. The best way to do this is add the
2121
entire ruleset, then rule by rule, remove ones that don't suit a project.
@@ -33,13 +33,11 @@
3333
<exclude name="WordPress.Security.EscapeOutput"/>
3434
-->
3535
<exclude name="WordPress.PHP.YodaConditions" />
36+
<exclude name="WordPress.DB.SlowDBQuery.slow_db_query_meta_query" />
3637
<exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose" />
3738
<exclude name="PSR2.Classes.ClassDeclaration.CloseBraceAfterBody" />
3839
</rule>
3940

40-
<!-- Check that code is documented to WordPress Standards. -->
41-
<rule ref="WordPress-Docs"/>
42-
4341
<!-- Add in some extra rules from other standards. -->
4442
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
4543
<rule ref="Generic.Commenting.Todo"/>

phpstan.neon.dist

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ parameters:
1616

1717
# Location of WordPress Plugins for PHPStan to scan, building symbols.
1818
scanDirectories:
19-
- /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress/wp-content/plugins
19+
- /var/www/html/wp-content/plugins
2020

2121
# Location of constants for PHPStan to scan, building symbols.
2222
scanFiles:
23-
- /home/runner/work/convertkit-wordpress-libraries/convertkit-wordpress-libraries/wordpress/wp-config.php
23+
- /var/www/html/wp-config.php
2424

2525
# Don't report unmatched ignored errors on older PHP versions (7.2, 7.3)
2626
reportUnmatchedIgnoredErrors: false

src/class-convertkit-api-v4.php

+1
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ public function get_access_token_by_api_key_and_secret( $api_key, $api_secret )
492492
array(
493493
'api_key' => $api_key,
494494
'api_secret' => $api_secret,
495+
'client_id' => $this->client_id,
495496
)
496497
);
497498

tests/wpunit/APITest.php

+32
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,38 @@ public function testGetAccessTokenByInvalidAPIKeyAndSecret()
604604
$this->assertEquals('Authorization Failed: API Secret not valid', $result->get_error_message());
605605
}
606606

607+
/**
608+
* Test that fetching an Access Token using an invalid client ID returns a WP_Error.
609+
*
610+
* @since 2.0.7
611+
*/
612+
public function testGetAccessTokenByAPIKeyAndSecretWithInvalidClientID()
613+
{
614+
$api = new ConvertKit_API_V4( 'invalidClientID', $_ENV['CONVERTKIT_OAUTH_REDIRECT_URI'] );
615+
$result = $api->get_access_token_by_api_key_and_secret(
616+
$_ENV['CONVERTKIT_API_KEY'],
617+
$_ENV['CONVERTKIT_API_SECRET']
618+
);
619+
$this->assertInstanceOf(WP_Error::class, $result);
620+
$this->assertEquals($result->get_error_code(), $this->errorCode);
621+
}
622+
623+
/**
624+
* Test that fetching an Access Token using a blank client ID returns a WP_Error.
625+
*
626+
* @since 2.0.7
627+
*/
628+
public function testGetAccessTokenByAPIKeyAndSecretWithBlankClientID()
629+
{
630+
$api = new ConvertKit_API_V4( '', $_ENV['CONVERTKIT_OAUTH_REDIRECT_URI'] );
631+
$result = $api->get_access_token_by_api_key_and_secret(
632+
$_ENV['CONVERTKIT_API_KEY'],
633+
$_ENV['CONVERTKIT_API_SECRET']
634+
);
635+
$this->assertInstanceOf(WP_Error::class, $result);
636+
$this->assertEquals($result->get_error_code(), $this->errorCode);
637+
}
638+
607639
/**
608640
* Test that supplying valid API credentials to the API class returns the expected account information.
609641
*

0 commit comments

Comments
 (0)