Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2] Convert tests to PSR-12 #38161

Merged
merged 5 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<exclude-pattern type="relative">media/*</exclude-pattern>
<exclude-pattern type="relative">node_modules/*</exclude-pattern>
<exclude-pattern type="relative">tmp/*</exclude-pattern>
<exclude-pattern type="relative">tests/*</exclude-pattern>

<!-- Exclude 3rd party libraries and Framework code. -->
<exclude-pattern type="relative">libraries/php-encryption/*</exclude-pattern>
Expand Down Expand Up @@ -245,6 +244,7 @@
<exclude-pattern type="relative">plugins/content/pagebreak/pagebreak\.php</exclude-pattern>
<exclude-pattern type="relative">plugins/editors/none/none\.php</exclude-pattern>
<exclude-pattern type="relative">plugins/user/joomla/joomla\.php</exclude-pattern>
<exclude-pattern type="relative">tests/</exclude-pattern>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
Expand Down
87 changes: 44 additions & 43 deletions tests/Codeception/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Tests
* @subpackage AcceptanceTester
Expand All @@ -7,6 +8,7 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// phpcs:ignoreFile
use Codeception\Actor;
use Codeception\Lib\Friend;

Expand All @@ -33,53 +35,52 @@
*/
class AcceptanceTester extends Actor
{
use _generated\AcceptanceTesterActions;
use _generated\AcceptanceTesterActions;

/**
* Function to check for PHP Notices or Warnings.
*
* @param string $page Optional, if not given checks will be done in the current page
*
* @note doAdminLogin() before
*
* @since 3.7.3
*
* @return void
*/
public function checkForPhpNoticesOrWarnings($page = null)
{
$I = $this;
/**
* Function to check for PHP Notices or Warnings.
*
* @param string $page Optional, if not given checks will be done in the current page
*
* @note doAdminLogin() before
*
* @since 3.7.3
*
* @return void
*/
public function checkForPhpNoticesOrWarnings($page = null)
{
$I = $this;

if ($page)
{
$I->amOnPage($page);
}
if ($page) {
$I->amOnPage($page);
}

$I->dontSeeInPageSource('Notice:');
$I->dontSeeInPageSource('<b>Notice</b>:');
$I->dontSeeInPageSource('Warning:');
$I->dontSeeInPageSource('<b>Warning</b>:');
$I->dontSeeInPageSource('Strict standards:');
$I->dontSeeInPageSource('<b>Strict standards</b>:');
$I->dontSeeInPageSource('The requested page can\'t be found');
}
$I->dontSeeInPageSource('Notice:');
$I->dontSeeInPageSource('<b>Notice</b>:');
$I->dontSeeInPageSource('Warning:');
$I->dontSeeInPageSource('<b>Warning</b>:');
$I->dontSeeInPageSource('Strict standards:');
$I->dontSeeInPageSource('<b>Strict standards</b>:');
$I->dontSeeInPageSource('The requested page can\'t be found');
}

/**
* Function to wait for JS to be properly loaded on page change.
*
* @param integer|float $timeout Time to wait for JS to be ready
*
* @since 4.0.0
*
* @return void
*/
public function waitForJsOnPageLoad($timeout = 1)
{
$I = $this;
/**
* Function to wait for JS to be properly loaded on page change.
*
* @param integer|float $timeout Time to wait for JS to be ready
*
* @since 4.0.0
*
* @return void
*/
public function waitForJsOnPageLoad($timeout = 1)
{
$I = $this;

$I->waitForJS('return document.readyState == "complete"', $timeout);
$I->waitForJS('return document.readyState == "complete"', $timeout);

// Wait an additional 500ms to make sure that really all JS is loaded
$I->wait(0.5);
}
// Wait an additional 500ms to make sure that really all JS is loaded
$I->wait(0.5);
}
}
10 changes: 6 additions & 4 deletions tests/Codeception/_support/ApiTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Tests
* @subpackage AcceptanceTester
Expand All @@ -7,6 +8,7 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// phpcs:ignoreFile
use Codeception\Actor;
use Codeception\Lib\Friend;

Expand All @@ -30,9 +32,9 @@
*/
class ApiTester extends Actor
{
use _generated\ApiTesterActions;
use _generated\ApiTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
10 changes: 6 additions & 4 deletions tests/Codeception/_support/FunctionalTester.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @package Joomla.Tests
* @subpackage FunctionalTester
Expand All @@ -7,6 +8,7 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// phpcs:ignoreFile
use Codeception\Actor;
use Codeception\Lib\Friend;

Expand All @@ -32,9 +34,9 @@
*/
class FunctionalTester extends Actor
{
use _generated\FunctionalTesterActions;
use _generated\FunctionalTesterActions;

/**
* Define custom actions here
*/
/**
* Define custom actions here
*/
}
51 changes: 26 additions & 25 deletions tests/Codeception/_support/Helper/Acceptance.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* @package Joomla.Tests
* @subpackage Helper
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Helper;

use Codeception\Configuration;
Expand All @@ -24,31 +26,30 @@
*/
class Acceptance extends Module
{
/**
* Array of the configuration settings.
*
* @var array
* @since 3.7.3
*/
protected static $acceptanceSuiteConfiguration = [];
/**
* Array of the configuration settings.
*
* @var array
* @since 3.7.3
*/
protected static $acceptanceSuiteConfiguration = [];

/**
* Function to get Configuration from the acceptance.suite.yml to be used by a test
*
* @return array
*
* @since 3.7.3
*
* @throws ConfigurationException
* @throws Exception
*/
public function getSuiteConfiguration()
{
if (empty(self::$acceptanceSuiteConfiguration))
{
self::$acceptanceSuiteConfiguration = Configuration::suiteSettings('acceptance', Configuration::config());
}
/**
* Function to get Configuration from the acceptance.suite.yml to be used by a test
*
* @return array
*
* @since 3.7.3
*
* @throws ConfigurationException
* @throws Exception
*/
public function getSuiteConfiguration()
{
if (empty(self::$acceptanceSuiteConfiguration)) {
self::$acceptanceSuiteConfiguration = Configuration::suiteSettings('acceptance', Configuration::config());
}

return self::$acceptanceSuiteConfiguration;
}
return self::$acceptanceSuiteConfiguration;
}
}
101 changes: 51 additions & 50 deletions tests/Codeception/_support/Helper/Api.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* @package Joomla.Tests
* @subpackage Helper
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Helper;

use Codeception\Module;
Expand All @@ -21,58 +23,57 @@
*/
class Api extends Module
{
/**
* Creates a user for API authentication and returns a bearer token.
*
* @return string The token
*
* @since 4.1.0
*/
public function getBearerToken(): string
{
/** @var JoomlaDb $db */
$db = $this->getModule('Helper\\JoomlaDb');
/**
* Creates a user for API authentication and returns a bearer token.
*
* @return string The token
*
* @since 4.1.0
*/
public function getBearerToken(): string
{
/** @var JoomlaDb $db */
$db = $this->getModule('Helper\\JoomlaDb');

$desiredUserId = 3;
$desiredUserId = 3;

if (!$db->grabFromDatabase('users', 'id', ['id' => $desiredUserId]))
{
$db->haveInDatabase(
'users',
[
'id' => $desiredUserId,
'name' => 'API',
'email' => '[email protected]',
'username' => 'api',
'password' => '123',
'block' => 0,
'registerDate' => '2000-01-01',
'params' => '{}'
],
[]
);
$db->haveInDatabase('user_usergroup_map', ['user_id' => $desiredUserId, 'group_id' => 8]);
$enabledData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.enabled', 'profile_value' => 1];
$tokenData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.token', 'profile_value' => 'dOi2m1NRrnBHlhaWK/WWxh3B5tqq1INbdf4DhUmYTI4='];
$db->haveInDatabase('user_profiles', $enabledData);
$db->haveInDatabase('user_profiles', $tokenData);
}
if (!$db->grabFromDatabase('users', 'id', ['id' => $desiredUserId])) {
$db->haveInDatabase(
'users',
[
'id' => $desiredUserId,
'name' => 'API',
'email' => '[email protected]',
'username' => 'api',
'password' => '123',
'block' => 0,
'registerDate' => '2000-01-01',
'params' => '{}'
],
[]
);
$db->haveInDatabase('user_usergroup_map', ['user_id' => $desiredUserId, 'group_id' => 8]);
$enabledData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.enabled', 'profile_value' => 1];
$tokenData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.token', 'profile_value' => 'dOi2m1NRrnBHlhaWK/WWxh3B5tqq1INbdf4DhUmYTI4='];
$db->haveInDatabase('user_profiles', $enabledData);
$db->haveInDatabase('user_profiles', $tokenData);
}

return 'c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==';
}
return 'c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==';
}

/**
* Creates a user for API authentication and returns a bearer token.
*
* @param string $name The name of the config key
* @param string $module The module
*
* @return string The config key
*
* @since 4.1.0
*/
public function getConfig($name, $module = 'Helper\Api'): string
{
return $this->getModule($module)->_getConfig()[$name];
}
/**
* Creates a user for API authentication and returns a bearer token.
*
* @param string $name The name of the config key
* @param string $module The module
*
* @return string The config key
*
* @since 4.1.0
*/
public function getConfig($name, $module = 'Helper\Api'): string
{
return $this->getModule($module)->_getConfig()[$name];
}
}
2 changes: 2 additions & 0 deletions tests/Codeception/_support/Helper/Functional.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

/**
* @package Joomla.Tests
* @subpackage Helper
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Helper;

use Codeception\Module;
Expand Down
Loading