Skip to content

Commit

Permalink
style(src) cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Nov 20, 2023
1 parent afa8282 commit 66bc3f2
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 322 deletions.
60 changes: 30 additions & 30 deletions src/Codeception/Module/WPLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,28 @@ class WPLoader extends Module
*/
protected $config
= [
'loadOnly' => false,
'isolatedInstall' => true,
'installationTableHandling' => 'empty',
'wpDebug' => true,
'multisite' => false,
'skipPluggables' => false,
'dbCharset' => 'utf8',
'dbCollate' => '',
'tablePrefix' => 'wptests_',
'domain' => 'example.org',
'adminEmail' => 'admin@example.org',
'title' => 'Test Blog',
'phpBinary' => 'php',
'language' => '',
'configFile' => '',
'contentFolder' => '',
'pluginsFolder' => '',
'plugins' => [],
'activatePlugins' => [],
'activatePluginsSilently' => [],
'bootstrapActions' => '',
'theme' => '',
'loadOnly' => false,
'isolatedInstall' => true,
'installationTableHandling' => 'empty',
'wpDebug' => true,
'multisite' => false,
'skipPluggables' => false,
'dbCharset' => 'utf8',
'dbCollate' => '',
'tablePrefix' => 'wptests_',
'domain' => 'example.org',
'adminEmail' => 'admin@example.org',
'title' => 'Test Blog',
'phpBinary' => 'php',
'language' => '',
'configFile' => '',
'contentFolder' => '',
'pluginsFolder' => '',
'plugins' => [],
'activatePlugins' => [],
'activatePluginsSilently' => [],
'bootstrapActions' => '',
'theme' => '',
];

/**
Expand Down Expand Up @@ -1121,13 +1121,13 @@ public function getContentFolder($path = '')
*/
protected function getInstallationConfiguration()
{
return new Configuration( [
'tablesHandling' => isset( $this->config['installationTableHandling'] ) ?
$this->config['installationTableHandling']
: 'empty',
'activatePluginsSilently' => isset( $this->config['activatePluginsSilently'] ) ?
(array) $this->config['activatePluginsSilently']
: []
] );
return new Configuration([
'tablesHandling' => isset($this->config['installationTableHandling']) ?
$this->config['installationTableHandling']
: 'empty',
'activatePluginsSilently' => isset($this->config['activatePluginsSilently']) ?
(array) $this->config['activatePluginsSilently']
: []
]);
}
}
50 changes: 25 additions & 25 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,39 @@
createTestDatabasesIfNotExist();

// Make sure traits can be autoloaded from tests/_support/Traits
Autoload::addNamespace( '\lucatume\WPBrowser\Tests\Traits', codecept_root_dir( 'tests/_support/Traits' ) );
Autoload::addNamespace('\lucatume\WPBrowser\Tests\Traits', codecept_root_dir('tests/_support/Traits'));

// If the `uopz` extension is installed, then ensure `exit` and `die` to work normally.
if ( function_exists( 'uopz_allow_exit' ) ) {
uopz_allow_exit( true );
if (function_exists('uopz_allow_exit')) {
uopz_allow_exit(true);
}

//addListener( Events::SUITE_BEFORE, function ( Codeception\Event\SuiteEvent $event ) {
// $suiteName = $event->getSuite()->getName();
// $suiteName = $event->getSuite()->getName();
//
// if ( $suiteName !== 'wploader_plugin_silent_activation' ) {
// return;
// }
// if ( $suiteName !== 'wploader_plugin_silent_activation' ) {
// return;
// }
//
// $wpRootDir = realpath( getenv( 'WORDPRESS_ROOT_DIR' ) );
// $wpRootDir = realpath( getenv( 'WORDPRESS_ROOT_DIR' ) );
//
// if ( ! is_dir( $wpRootDir ) ) {
// throw new \RuntimeException( "The WORDPRESS_ROOT_DIR is not a valid directory." );
// }
// if ( ! is_dir( $wpRootDir ) ) {
// throw new \RuntimeException( "The WORDPRESS_ROOT_DIR is not a valid directory." );
// }
//
// $wpRootDir = rtrim( $wpRootDir, '/\\' );
// $wpRootDir = rtrim( $wpRootDir, '/\\' );
//
// foreach (
// [
// codecept_data_dir( 'plugins/doing-it-wrong-1' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-1',
// codecept_data_dir( 'plugins/doing-it-wrong-2' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-2',
// ] as $source => $destination
// ) {
// if ( ! copy(
// $source,
// $destination
// ) ) {
// throw new \RuntimeException( "Could not copy the plugin to the WordPress plugins directory." );
// }
// }
// foreach (
// [
// codecept_data_dir( 'plugins/doing-it-wrong-1' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-1',
// codecept_data_dir( 'plugins/doing-it-wrong-2' ) => $wpRootDir . '/wp-content/plugins/doing-it-wrong-2',
// ] as $source => $destination
// ) {
// if ( ! copy(
// $source,
// $destination
// ) ) {
// throw new \RuntimeException( "Could not copy the plugin to the WordPress plugins directory." );
// }
// }
//} );
12 changes: 6 additions & 6 deletions tests/_data/plugins/doing-it-right/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Plugin Name: Doing It Right
*/

register_activation_hook( __FILE__, function () {
update_option( 'doing_it_right_activation', 'activated' );
} );
register_activation_hook(__FILE__, function () {
update_option('doing_it_right_activation', 'activated');
});

add_action('plugins_loaded', function(){
global $doing_it_right_plugin_loaded;
$doing_it_right_plugin_loaded = true;
add_action('plugins_loaded', function () {
global $doing_it_right_plugin_loaded;
$doing_it_right_plugin_loaded = true;
});
15 changes: 8 additions & 7 deletions tests/_data/plugins/doing-it-wrong-1/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* Plugin Name: Doing It Wrong 1
*/

function doing_it_wrong_1_activation(){
_doing_it_wrong( __FUNCTION__, 'This is a test', '1.0.0' );
update_option('doing_it_wrong_1j_activation', 'activated');
function doing_it_wrong_1_activation()
{
_doing_it_wrong(__FUNCTION__, 'This is a test', '1.0.0');
update_option('doing_it_wrong_1j_activation', 'activated');
}
register_activation_hook(__FILE__,'doing_it_wrong_1_activation');
register_activation_hook(__FILE__, 'doing_it_wrong_1_activation');

add_action('plugins_loaded', function(){
global $doing_it_wrong_1_plugin_loaded;
$doing_it_wrong_1_plugin_loaded = true;
add_action('plugins_loaded', function () {
global $doing_it_wrong_1_plugin_loaded;
$doing_it_wrong_1_plugin_loaded = true;
});
15 changes: 8 additions & 7 deletions tests/_data/plugins/doing-it-wrong-2/plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
* Plugin Name: Doing It Wrong 2
*/

function doing_it_wrong_2_activation() {
_doing_it_wrong( __FUNCTION__, 'This is a test', '1.0.0' );
update_option('doing_it_wrong_2_activation', 'activated');
function doing_it_wrong_2_activation()
{
_doing_it_wrong(__FUNCTION__, 'This is a test', '1.0.0');
update_option('doing_it_wrong_2_activation', 'activated');
}

register_activation_hook( __FILE__, 'doing_it_wrong_2_activation' );
register_activation_hook(__FILE__, 'doing_it_wrong_2_activation');

add_action('plugins_loaded', function(){
global $doing_it_wrong_2_plugin_loaded;
$doing_it_wrong_2_plugin_loaded = true;
add_action('plugins_loaded', function () {
global $doing_it_wrong_2_plugin_loaded;
$doing_it_wrong_2_plugin_loaded = true;
});
12 changes: 6 additions & 6 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use PHPUnit\Framework\Assert;


/**
* Inherited Methods
* @method void wantToTest( $text )
Expand All @@ -18,10 +17,11 @@
*
* @SuppressWarnings(PHPMD)
*/
class AcceptanceTester extends \Codeception\Actor {
use _generated\AcceptanceTesterActions;
class AcceptanceTester extends \Codeception\Actor
{
use _generated\AcceptanceTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
97 changes: 52 additions & 45 deletions tests/acceptance/AjaxCest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

class AjaxCest {
public function _before( AcceptanceTester $I ) {
$code = <<< PHP
class AjaxCest
{
public function _before(AcceptanceTester $I)
{
$code = <<< PHP
<?php
/**
* Plugin Name: Test Ajax Plugin
Expand Down Expand Up @@ -30,53 +32,58 @@ function onTestNoPrivAjaxAction(){
});
PHP;

$I->haveMuPlugin( 'test-ajax-plugin', $code );
}
$I->haveMuPlugin('test-ajax-plugin', $code);
}

public function test_invalid_action_returns_400( AcceptanceTester $I ) {
$I->amOnAdminAjaxPage( [
'action' => 'invalid_action'
] );
$I->seeResponseCodeIs( 400 );
}
public function test_invalid_action_returns_400(AcceptanceTester $I)
{
$I->amOnAdminAjaxPage([
'action' => 'invalid_action'
]);
$I->seeResponseCodeIs(400);
}

public function test_missing_nonce_returns_403( AcceptanceTester $I ) {
$I->amOnAdminAjaxPage( [
'action' => 'test_ajax_action'
] );
$I->seeResponseCodeIs( 403 );
}
public function test_missing_nonce_returns_403(AcceptanceTester $I)
{
$I->amOnAdminAjaxPage([
'action' => 'test_ajax_action'
]);
$I->seeResponseCodeIs(403);
}

public function test_wrong_nonce_returns_403( AcceptanceTester $I ) {
$I->amOnAdminAjaxPage( [
'action' => 'test_ajax_action',
'_ajax_nonce' => 'wrong_nonce'
] );
$I->seeResponseCodeIs( 403 );
}
public function test_wrong_nonce_returns_403(AcceptanceTester $I)
{
$I->amOnAdminAjaxPage([
'action' => 'test_ajax_action',
'_ajax_nonce' => 'wrong_nonce'
]);
$I->seeResponseCodeIs(403);
}

public function test_valid_nonce_returns_200_for_visitor( AcceptanceTester $I ) {
$I->amOnPage( '/' );
$nonce = $I->grabValueFrom( '#test-ajax-nonce' );
public function test_valid_nonce_returns_200_for_visitor(AcceptanceTester $I)
{
$I->amOnPage('/');
$nonce = $I->grabValueFrom('#test-ajax-nonce');

$I->amOnAdminAjaxPage( [
'action' => 'test_ajax_action',
'_ajax_nonce' => $nonce
] );
$I->seeResponseCodeIs( 200 );
$I->canSee( json_encode( [ 'type' => 'no-priv' ] ) );
}
$I->amOnAdminAjaxPage([
'action' => 'test_ajax_action',
'_ajax_nonce' => $nonce
]);
$I->seeResponseCodeIs(200);
$I->canSee(json_encode([ 'type' => 'no-priv' ]));
}

public function test_valid_nonce_returns_200_for_admin( AcceptanceTester $I ) {
$I->loginAsAdmin();
$I->amOnPage( '/' );
$nonce = $I->grabValueFrom( '#test-ajax-nonce' );
public function test_valid_nonce_returns_200_for_admin(AcceptanceTester $I)
{
$I->loginAsAdmin();
$I->amOnPage('/');
$nonce = $I->grabValueFrom('#test-ajax-nonce');

$I->amOnAdminAjaxPage( [
'action' => 'test_ajax_action',
'_ajax_nonce' => $nonce
] );
$I->seeResponseCodeIs( 200 );
$I->canSee( json_encode( [ 'type' => 'priv' ] ) );
}
$I->amOnAdminAjaxPage([
'action' => 'test_ajax_action',
'_ajax_nonce' => $nonce
]);
$I->seeResponseCodeIs(200);
$I->canSee(json_encode([ 'type' => 'priv' ]));
}
}
Loading

0 comments on commit 66bc3f2

Please sign in to comment.