From 2f45696d28d76235dae4b3e0f550295835b9328c Mon Sep 17 00:00:00 2001 From: Harald Leithner Date: Mon, 27 Jun 2022 21:34:43 +0200 Subject: [PATCH 1/4] cs --- .../webauthn/src/Extension/Webauthn.php | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/plugins/system/webauthn/src/Extension/Webauthn.php b/plugins/system/webauthn/src/Extension/Webauthn.php index 9389acf9dca44..ed714ef73bd82 100644 --- a/plugins/system/webauthn/src/Extension/Webauthn.php +++ b/plugins/system/webauthn/src/Extension/Webauthn.php @@ -45,8 +45,28 @@ */ final class Webauthn extends CMSPlugin implements SubscriberInterface { + // Add WebAuthn buttons + use AdditionalLoginButtons; + + // AJAX request handlers + use AjaxHandler; + use AjaxHandlerInitCreate; + use AjaxHandlerCreate; + use AjaxHandlerSaveLabel; + use AjaxHandlerDelete; + use AjaxHandlerChallenge; + use AjaxHandlerLogin; + + // Utility methods for setting the events' return values + use EventReturnAware; use CoreEventAware; + // Custom user profile fields + use UserProfileFields; + + // Handle user profile deletion + use UserDeletion; + /** * Autoload the language files * @@ -73,27 +93,6 @@ final class Webauthn extends CMSPlugin implements SubscriberInterface */ protected $authenticationHelper; - // AJAX request handlers - use AjaxHandler; - use AjaxHandlerInitCreate; - use AjaxHandlerCreate; - use AjaxHandlerSaveLabel; - use AjaxHandlerDelete; - use AjaxHandlerChallenge; - use AjaxHandlerLogin; - - // Custom user profile fields - use UserProfileFields; - - // Handle user profile deletion - use UserDeletion; - - // Add WebAuthn buttons - use AdditionalLoginButtons; - - // Utility methods for setting the events' return values - use EventReturnAware; - /** * Constructor. Loads the language files as well. * From 88d6adfe1a8c99260607aeec6d6d07833ca084aa Mon Sep 17 00:00:00 2001 From: Brian Teeman Date: Tue, 28 Jun 2022 07:20:47 +0100 Subject: [PATCH 2/4] copyright and licence (#38159) Co-authored-by: Richard Fath --- .../src/Hotfix/AndroidKeyAttestationStatementSupport.php | 4 ++++ .../src/Hotfix/FidoU2FAttestationStatementSupport.php | 4 ++++ plugins/multifactorauth/webauthn/src/Hotfix/Server.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/plugins/multifactorauth/webauthn/src/Hotfix/AndroidKeyAttestationStatementSupport.php b/plugins/multifactorauth/webauthn/src/Hotfix/AndroidKeyAttestationStatementSupport.php index 7a9c2353a22bc..19328f845e995 100644 --- a/plugins/multifactorauth/webauthn/src/Hotfix/AndroidKeyAttestationStatementSupport.php +++ b/plugins/multifactorauth/webauthn/src/Hotfix/AndroidKeyAttestationStatementSupport.php @@ -6,6 +6,10 @@ * * @copyright (C) 2022 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt + * @copyright (C) 2014-2019 Spomky-Labs + * @license This software may be modified and distributed under the terms + * of the MIT license. + * See libraries/vendor/web-auth/webauthn-lib/LICENSE */ namespace Joomla\Plugin\Multifactorauth\Webauthn\Hotfix; diff --git a/plugins/multifactorauth/webauthn/src/Hotfix/FidoU2FAttestationStatementSupport.php b/plugins/multifactorauth/webauthn/src/Hotfix/FidoU2FAttestationStatementSupport.php index e42cefd2b76c0..6a59ddc16b3b7 100644 --- a/plugins/multifactorauth/webauthn/src/Hotfix/FidoU2FAttestationStatementSupport.php +++ b/plugins/multifactorauth/webauthn/src/Hotfix/FidoU2FAttestationStatementSupport.php @@ -6,6 +6,10 @@ * * @copyright (C) 2022 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt + * @copyright (C) 2014-2019 Spomky-Labs + * @license This software may be modified and distributed under the terms + * of the MIT license. + * See libraries/vendor/web-auth/webauthn-lib/LICENSE */ namespace Joomla\Plugin\Multifactorauth\Webauthn\Hotfix; diff --git a/plugins/multifactorauth/webauthn/src/Hotfix/Server.php b/plugins/multifactorauth/webauthn/src/Hotfix/Server.php index 07ca585e7dd44..8d75b452ec73c 100644 --- a/plugins/multifactorauth/webauthn/src/Hotfix/Server.php +++ b/plugins/multifactorauth/webauthn/src/Hotfix/Server.php @@ -6,6 +6,10 @@ * * @copyright (C) 2022 Open Source Matters, Inc. * @license GNU General Public License version 2 or later; see LICENSE.txt + * @copyright (C) 2014-2019 Spomky-Labs + * @license This software may be modified and distributed under the terms + * of the MIT license. + * See libraries/vendor/web-auth/webauthn-lib/LICENSE */ namespace Joomla\Plugin\Multifactorauth\Webauthn\Hotfix; From 3e67927520b09d08d2960c5d8e16f917a163555c Mon Sep 17 00:00:00 2001 From: Harald Leithner Date: Tue, 28 Jun 2022 09:10:42 +0200 Subject: [PATCH 3/4] [4.2] Add GitHub rebase script (#38157) * Add GitHub rebase script Co-authored-by: Brian Teeman --- build/github_rebase.php | 153 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 build/github_rebase.php diff --git a/build/github_rebase.php b/build/github_rebase.php new file mode 100644 index 0000000000000..954b0e930e808 --- /dev/null +++ b/build/github_rebase.php @@ -0,0 +1,153 @@ + + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +// Set defaults +$scriptRoot = __DIR__; +$prNumber = false; +$php = 'php'; +$git = 'git'; +$gh = 'gh'; +$checkPath = false; +$ghRepo = 'joomla/joomla-cms'; +$baseBranches = '4.1-dev'; +$targetBranch = '4.2-dev'; + +$script = array_shift($argv); + +if (empty($argv)) { + echo <<] + + Description: + Rebase all open pull requests on github to the target branch. + + --base: + The base branch of the pull request. Multiple branches can be seperated by comma. + + --target: + The target branch the pull request gets rebased to. + + --pr: + Rebase only the given PR. + + TEXT; + die(1); +} + +foreach ($argv as $arg) { + if (substr($arg, 0, 2) === '--') { + $argi = explode('=', $arg, 2); + switch ($argi[0]) { + case '--base': + $baseBranches = $argi[1]; + break; + case '--target': + $targetBranch = $argi[1]; + break; + case '--pr': + $prNumber = $argi[1]; + break; + } + } else { + $checkPath = $arg; + break; + } +} + +$cmd = $git . ' -C "' . $scriptRoot . '" rev-parse --show-toplevel'; +$output = []; +$repoScript = ''; +exec($cmd, $output, $result); +if ($result !== 0) { + $repoScript = $output[0]; + die($script . ' must be located inside of the git repository'); +} + +echo "Validate gh client...\n"; +$cmd = $gh; +$output = []; +exec($cmd, $output, $result); +if ($result !== 0) { + die('Github cli client not found. Please install the client first (https://cli.github.com)'); +} + +echo "Validate gh authentication...\n"; +$cmd = $gh . ' auth status'; +passthru($cmd, $result); +if ($result !== 0) { + die('Please login with the github cli client first. (gh auth login)'); +} + +$fieldList = [ + "number", + "author", + "baseRefName", + "headRefName", + "headRepository", + "headRepositoryOwner", + "isCrossRepository", + "maintainerCanModify", + "mergeStateStatus", + "mergeable", + "state", + "title", + "url", + "labels", +]; + +$branches = 'base:' . implode(' base:', explode(',', $baseBranches)); + +if (!empty($prNumber)) { + echo "Retrieving Pull Request " . $prNumber . "...\n"; + $cmd = $gh . ' pr view ' . $prNumber . ' --json ' . implode(',', $fieldList); +} else { + echo "Retrieving Pull Request list...\n"; + $cmd = $gh . ' pr list --limit 1000 --json ' . implode(',', $fieldList) . ' --search "is:pr is:open ' . $branches . '"'; +} + +$output = []; +exec($cmd, $output, $result); +if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to retrieve PR list.'); +} + +$json = $output[0]; + +if (!empty($prNumber)) { + $json = '[' . $json . ']'; +} + +$list = json_decode($json, true); + +echo "\nFound " . count($list) . " pull request(s).\n"; + +foreach ($list as $pr) { + echo "Rebase #" . $pr['number'] . "\n"; + + $cmd = $gh . ' pr edit ' . $pr['url'] . ' --base ' . $targetBranch; + $output = []; + exec($cmd, $output, $result); + if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to set target branch for pr #' . $pr['number']); + } + + $cmd = $gh . ' pr comment ' . $pr['url'] . ' --body "This pull request has been automatically rebased to ' . $targetBranch . '."'; + $output = []; + exec($cmd, $output, $result); + if ($result !== 0) { + var_dump([$cmd, $output, $result]); + die('Unable to create a comment for pr #' . $pr['number']); + } +} From 967d6552fd2c2321e6e09d229fd3680a7cda2e29 Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Tue, 28 Jun 2022 09:43:33 +0200 Subject: [PATCH 4/4] [4.2] Convert tests to PSR-12 (#38161) * Convert tests to psr 12 where possible * fix rules * revert ignore --- ruleset.xml | 2 +- .../Codeception/_support/AcceptanceTester.php | 87 +- tests/Codeception/_support/ApiTester.php | 10 +- .../Codeception/_support/FunctionalTester.php | 10 +- .../_support/Helper/Acceptance.php | 51 +- tests/Codeception/_support/Helper/Api.php | 101 +- .../_support/Helper/Functional.php | 2 + .../Codeception/_support/Helper/JoomlaDb.php | 380 +-- tests/Codeception/_support/Helper/Unit.php | 2 + .../Administrator/AdminFormPage.php | 4 +- .../Administrator/AdminListPage.php | 4 +- .../Acceptance/Administrator/AdminPage.php | 643 ++-- .../Administrator/BannerListPage.php | 98 +- .../Administrator/ContentCategoryListPage.php | 100 +- .../Administrator/ContentFormPage.php | 16 +- .../Administrator/ContentListPage.php | 124 +- .../Administrator/FieldListPage.php | 80 +- .../Administrator/MediaFilePage.php | 16 +- .../Administrator/MediaListPage.php | 769 ++--- .../Acceptance/Administrator/MenuFormPage.php | 72 +- .../Acceptance/Administrator/MenuListPage.php | 30 +- .../Acceptance/Administrator/UserListPage.php | 352 +- .../Page/Acceptance/Site/FrontPage.php | 44 +- .../Step/Acceptance/Administrator/Admin.php | 92 +- .../Step/Acceptance/Administrator/Banner.php | 372 +-- .../Acceptance/Administrator/Category.php | 56 +- .../Step/Acceptance/Administrator/Content.php | 451 ++- .../Step/Acceptance/Administrator/Field.php | 192 +- .../Step/Acceptance/Administrator/Media.php | 606 ++-- tests/Codeception/_support/UnitTester.php | 10 +- .../acceptance/01-install/InstallCest.php | 63 +- .../com_content/ContentCategoryListCest.php | 81 +- .../com_content/ContentFieldListCest.php | 85 +- .../com_content/ContentListCest.php | 119 +- .../components/com_media/MediaListCest.php | 2 + .../components/com_menu/MenuCest.php | 95 +- .../components/com_users/UserListCest.php | 283 +- tests/Codeception/api/BasicCest.php | 98 +- .../api/com_banners/BannerCest.php | 233 +- .../api/com_contact/ContactCest.php | 221 +- .../api/com_content/ContentCest.php | 221 +- tests/Codeception/api/com_media/MediaCest.php | 2 + tests/Integration/DBTestHelper.php | 264 +- tests/Integration/DBTestInterface.php | 46 +- tests/Integration/DBTestTrait.php | 104 +- tests/Integration/IntegrationTestCase.php | 27 +- .../Libraries/Cms/Table/TableTest.php | 590 ++-- .../Administrator/Indexer/ResultTest.php | 100 +- tests/Unit/Libraries/Cms/Access/RuleTest.php | 306 +- tests/Unit/Libraries/Cms/Access/RulesTest.php | 698 ++-- .../Application/ConsoleApplicationTest.php | 70 +- .../Console/ExtensionDiscoverCommandTest.php | 114 +- .../ExtensionDiscoverInstallCommandTest.php | 136 +- .../ExtensionDiscoverListCommandTest.php | 116 +- .../Loader/WritableContainerLoaderTest.php | 228 +- tests/Unit/Libraries/Cms/Date/DateTest.php | 335 +- .../Libraries/Cms/Document/DocumentTest.php | 1505 ++++----- .../Libraries/Cms/Environment/BrowserTest.php | 309 +- .../Unit/Libraries/Cms/Feed/FeedEntryTest.php | 811 +++-- .../Libraries/Cms/Feed/FeedFactoryTest.php | 290 +- .../Unit/Libraries/Cms/Feed/FeedLinkTest.php | 25 +- .../Libraries/Cms/Feed/FeedParserTest.php | 1047 +++--- tests/Unit/Libraries/Cms/Feed/FeedTest.php | 1019 +++--- .../Cms/Feed/Parser/AtomParserTest.php | 808 ++--- .../Cms/Feed/Parser/RssParserTest.php | 1298 ++++---- .../Libraries/Cms/Filter/OutputFilterTest.php | 166 +- .../Form/Field/AccessiblemediaFieldTest.php | 494 ++- .../Cms/Form/Rule/FilePathRuleTest.php | 108 +- .../Form/Rule/FolderPathExistsRuleTest.php | 116 +- .../Unit/Libraries/Cms/Html/JHtmlDateTest.php | 139 +- .../Libraries/Cms/Html/JHtmlNumberTest.php | 435 +-- .../Libraries/Cms/Html/JHtmlStringTest.php | 882 ++--- .../Unit/Libraries/Cms/Html/JHtmlTelTest.php | 62 +- .../Image/Filter/FilterBackgroundfillTest.php | 188 ++ .../Cms/Image/Filter/FilterBrightnessTest.php | 106 + .../Cms/Image/Filter/FilterContrastTest.php | 107 + .../Cms/Image/Filter/FilterEdgedetectTest.php | 80 + .../Libraries/Cms/Image/ImageFilterTest.php | 90 +- tests/Unit/Libraries/Cms/Image/ImageTest.php | 2865 ++++++++--------- .../Image/filter/FilterBackgroundfillTest.php | 186 -- .../Cms/Image/filter/FilterBrightnessTest.php | 104 - .../Cms/Image/filter/FilterContrastTest.php | 105 - .../Cms/Image/filter/FilterEdgedetectTest.php | 78 - .../Installer/Adapter/ModuleAdapterTest.php | 205 +- .../Libraries/Cms/Layout/BaseLayoutTest.php | 458 +-- .../Cms/MVC/Controller/BaseControllerTest.php | 1889 +++++------ .../Libraries/Cms/MVC/Model/BaseModelTest.php | 156 +- .../Cms/MVC/Model/DatabaseModelTest.php | 658 ++-- .../Libraries/Cms/MVC/Model/FormModelTest.php | 755 ++--- .../Libraries/Cms/MVC/Model/ItemModelTest.php | 165 +- .../Cms/MVC/Model/StateBehaviorTraitTest.php | 261 +- .../Cms/MVC/View/AbstractViewTest.php | 453 +-- .../Libraries/Cms/Mail/MailHelperTest.php | 501 +-- tests/Unit/Libraries/Cms/Mail/MailTest.php | 553 ++-- .../Libraries/Cms/Microdata/MicrodataTest.php | 2257 ++++++------- .../Libraries/Cms/Object/CMSObjectTest.php | 451 ++- .../Libraries/Cms/Plugin/CMSPluginTest.php | 1012 +++--- .../Cms/Session/SessionManagerTest.php | 214 +- .../Cms/Toolbar/Button/CustomButtonTest.php | 31 +- .../Libraries/Cms/Toolbar/ToolbarTest.php | 567 ++-- tests/Unit/Libraries/Cms/Uri/UriTest.php | 839 ++--- .../Cms/User/CurrentUserTraitTest.php | 51 +- tests/Unit/Libraries/Cms/VersionTest.php | 241 +- .../Requests/Extension/RequestsPluginTest.php | 575 ++-- .../Extension/SiteStatusPluginTest.php | 417 ++- tests/Unit/UnitTestCase.php | 42 +- tests/Unit/bootstrap.php | 93 +- 107 files changed, 17929 insertions(+), 17751 deletions(-) create mode 100644 tests/Unit/Libraries/Cms/Image/Filter/FilterBackgroundfillTest.php create mode 100644 tests/Unit/Libraries/Cms/Image/Filter/FilterBrightnessTest.php create mode 100644 tests/Unit/Libraries/Cms/Image/Filter/FilterContrastTest.php create mode 100644 tests/Unit/Libraries/Cms/Image/Filter/FilterEdgedetectTest.php delete mode 100644 tests/Unit/Libraries/Cms/Image/filter/FilterBackgroundfillTest.php delete mode 100644 tests/Unit/Libraries/Cms/Image/filter/FilterBrightnessTest.php delete mode 100644 tests/Unit/Libraries/Cms/Image/filter/FilterContrastTest.php delete mode 100644 tests/Unit/Libraries/Cms/Image/filter/FilterEdgedetectTest.php diff --git a/ruleset.xml b/ruleset.xml index b7a8915b51ef6..f6bcd5d2b5b03 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -10,7 +10,6 @@ media/* node_modules/* tmp/* - tests/* libraries/php-encryption/* @@ -245,6 +244,7 @@ plugins/content/pagebreak/pagebreak\.php plugins/editors/none/none\.php plugins/user/joomla/joomla\.php + tests/ diff --git a/tests/Codeception/_support/AcceptanceTester.php b/tests/Codeception/_support/AcceptanceTester.php index 0d3c7152120b7..ef267b05a0d0d 100644 --- a/tests/Codeception/_support/AcceptanceTester.php +++ b/tests/Codeception/_support/AcceptanceTester.php @@ -1,4 +1,5 @@ amOnPage($page); - } + if ($page) { + $I->amOnPage($page); + } - $I->dontSeeInPageSource('Notice:'); - $I->dontSeeInPageSource('Notice:'); - $I->dontSeeInPageSource('Warning:'); - $I->dontSeeInPageSource('Warning:'); - $I->dontSeeInPageSource('Strict standards:'); - $I->dontSeeInPageSource('Strict standards:'); - $I->dontSeeInPageSource('The requested page can\'t be found'); - } + $I->dontSeeInPageSource('Notice:'); + $I->dontSeeInPageSource('Notice:'); + $I->dontSeeInPageSource('Warning:'); + $I->dontSeeInPageSource('Warning:'); + $I->dontSeeInPageSource('Strict standards:'); + $I->dontSeeInPageSource('Strict standards:'); + $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); + } } diff --git a/tests/Codeception/_support/ApiTester.php b/tests/Codeception/_support/ApiTester.php index e6e1d237cc461..1bb62de39f878 100644 --- a/tests/Codeception/_support/ApiTester.php +++ b/tests/Codeception/_support/ApiTester.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Helper; use Codeception\Configuration; @@ -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; + } } diff --git a/tests/Codeception/_support/Helper/Api.php b/tests/Codeception/_support/Helper/Api.php index f6a6df2d3738c..96d0a1e501ce6 100644 --- a/tests/Codeception/_support/Helper/Api.php +++ b/tests/Codeception/_support/Helper/Api.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Helper; use Codeception\Module; @@ -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' => 'api@example.com', - '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' => 'api@example.com', + '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]; + } } diff --git a/tests/Codeception/_support/Helper/Functional.php b/tests/Codeception/_support/Helper/Functional.php index 20161918ee9d9..c820496795558 100644 --- a/tests/Codeception/_support/Helper/Functional.php +++ b/tests/Codeception/_support/Helper/Functional.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Helper; use Codeception\Module; diff --git a/tests/Codeception/_support/Helper/JoomlaDb.php b/tests/Codeception/_support/Helper/JoomlaDb.php index fd947d57ede30..ee7c68703dbdf 100644 --- a/tests/Codeception/_support/Helper/JoomlaDb.php +++ b/tests/Codeception/_support/Helper/JoomlaDb.php @@ -1,4 +1,5 @@ prefix = (isset($this->config['prefix'])) ? $this->config['prefix'] : ''; - - parent::_initialize(); - } - - /** - * Inserts an SQL record into a database. This record will be erased after each test. - * - * @param string $table Table - * @param array $data Data - * - * @return integer The last insert id - * - * @since 3.7.3 - */ - public function haveInDatabase($table, array $data) - { - $table = $this->addPrefix($table); - - return parent::haveInDatabase($table, $data); - } - - /** - * See an entry in the database. - * - * @param string $table Table - * @param array $criteria Criteria - * - * @return void - * - * @since 3.7.3 - */ - public function seeInDatabase($table, $criteria = []) - { - $table = $this->addPrefix($table); - - parent::seeInDatabase($table, $criteria); - } - - /** - * Don't see in database. - * - * @param string $table Table - * @param array $criteria Criteria - * - * @return void - * - * @since 3.7.3 - */ - public function dontSeeInDatabase($table, $criteria = []) - { - $table = $this->addPrefix($table); - - parent::dontSeeInDatabase($table, $criteria); - } - - /** - * Grab an entry from the database. - * - * @param string $table Table - * @param string $column Column - * @param array $criteria Criteria - * - * @return mixed - * - * @since 3.7.3 - */ - public function grabFromDatabase($table, $column, $criteria = array()) - { - $table = $this->addPrefix($table); - - return parent::grabFromDatabase($table, $column, $criteria); - } - - /** - * Asserts that the given number of records were found in the database. - * - * @param integer $expectedNumber Expected number - * @param string $table Table name - * @param array $criteria Search criteria [Optional] - * - * @return void - * - * @since 3.7.3 - */ - public function seeNumRecords($expectedNumber, $table, array $criteria = []) - { - $table = $this->addPrefix($table); - - parent::seeNumRecords($expectedNumber, $table, $criteria); - } - - /** - * Returns the number of rows in a database. - * - * @param string $table Table name - * @param array $criteria Search criteria [Optional] - * - * @return integer - * - * @since 3.7.3 - */ - public function grabNumRecords($table, array $criteria = []) - { - $table = $this->addPrefix($table); - - return parent::grabNumRecords($table, $criteria); - } - - /** - * Update an SQL record into a database. - * - * @param string $table Table name - * @param array $data Data to update in the table. Key=> value is column name => data - * @param array $criteria Search criteria [Optional] - * - * @return void - * - * @since 4.0.0 - */ - public function updateInDatabase($table, array $data, array $criteria = []) - { - $table = $this->addPrefix($table); - - parent::updateInDatabase($table, $data, $criteria); - } - - /** - * Deletes records in a database. - * - * @param string $table Table name - * @param array $criteria Search criteria [Optional] - * - * @return void - * - * @since 4.1.0 - */ - public function deleteFromDatabase($table, $criteria = []): void - { - $table = $this->addPrefix($table); - - $this->driver->deleteQueryByCriteria($table, $criteria); - } - - /** - * Add the table prefix. - * - * @param string $table Table without prefix - * - * @return string - * - * @since 3.7.3 - */ - protected function addPrefix($table) - { - return $this->prefix . $table; - } - - /** - * getConfig - * - * @param string $value Get the setting from the option - * - * @return mixed - * - * @since version - * @throws \Codeception\Exception\ModuleException - */ - public function getConfig($value) - { - return $this->getModule('Joomla\Browser\JoomlaBrowser')->_getConfig($value); - } + /** + * The table prefix. + * + * @var string + * @since 3.7.3 + */ + protected $prefix; + + /** + * Codeception Hook: called after configuration is loaded. + * + * @return void + * + * @since 3.7.3 + */ + // phpcs:ignore + public function _initialize() + { + $this->prefix = (isset($this->config['prefix'])) ? $this->config['prefix'] : ''; + + parent::_initialize(); + } + + /** + * Inserts an SQL record into a database. This record will be erased after each test. + * + * @param string $table Table + * @param array $data Data + * + * @return integer The last insert id + * + * @since 3.7.3 + */ + public function haveInDatabase($table, array $data) + { + $table = $this->addPrefix($table); + + return parent::haveInDatabase($table, $data); + } + + /** + * See an entry in the database. + * + * @param string $table Table + * @param array $criteria Criteria + * + * @return void + * + * @since 3.7.3 + */ + public function seeInDatabase($table, $criteria = []) + { + $table = $this->addPrefix($table); + + parent::seeInDatabase($table, $criteria); + } + + /** + * Don't see in database. + * + * @param string $table Table + * @param array $criteria Criteria + * + * @return void + * + * @since 3.7.3 + */ + public function dontSeeInDatabase($table, $criteria = []) + { + $table = $this->addPrefix($table); + + parent::dontSeeInDatabase($table, $criteria); + } + + /** + * Grab an entry from the database. + * + * @param string $table Table + * @param string $column Column + * @param array $criteria Criteria + * + * @return mixed + * + * @since 3.7.3 + */ + public function grabFromDatabase($table, $column, $criteria = array()) + { + $table = $this->addPrefix($table); + + return parent::grabFromDatabase($table, $column, $criteria); + } + + /** + * Asserts that the given number of records were found in the database. + * + * @param integer $expectedNumber Expected number + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * + * @return void + * + * @since 3.7.3 + */ + public function seeNumRecords($expectedNumber, $table, array $criteria = []) + { + $table = $this->addPrefix($table); + + parent::seeNumRecords($expectedNumber, $table, $criteria); + } + + /** + * Returns the number of rows in a database. + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * + * @return integer + * + * @since 3.7.3 + */ + public function grabNumRecords($table, array $criteria = []) + { + $table = $this->addPrefix($table); + + return parent::grabNumRecords($table, $criteria); + } + + /** + * Update an SQL record into a database. + * + * @param string $table Table name + * @param array $data Data to update in the table. Key=> value is column name => data + * @param array $criteria Search criteria [Optional] + * + * @return void + * + * @since 4.0.0 + */ + public function updateInDatabase($table, array $data, array $criteria = []) + { + $table = $this->addPrefix($table); + + parent::updateInDatabase($table, $data, $criteria); + } + + /** + * Deletes records in a database. + * + * @param string $table Table name + * @param array $criteria Search criteria [Optional] + * + * @return void + * + * @since 4.1.0 + */ + public function deleteFromDatabase($table, $criteria = []): void + { + $table = $this->addPrefix($table); + + $this->driver->deleteQueryByCriteria($table, $criteria); + } + + /** + * Add the table prefix. + * + * @param string $table Table without prefix + * + * @return string + * + * @since 3.7.3 + */ + protected function addPrefix($table) + { + return $this->prefix . $table; + } + + /** + * getConfig + * + * @param string $value Get the setting from the option + * + * @return mixed + * + * @since version + * @throws \Codeception\Exception\ModuleException + */ + public function getConfig($value) + { + return $this->getModule('Joomla\Browser\JoomlaBrowser')->_getConfig($value); + } } diff --git a/tests/Codeception/_support/Helper/Unit.php b/tests/Codeception/_support/Helper/Unit.php index c86afeec1e9b5..be2c96eb06a86 100644 --- a/tests/Codeception/_support/Helper/Unit.php +++ b/tests/Codeception/_support/Helper/Unit.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Helper; use Codeception\Module; diff --git a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminFormPage.php b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminFormPage.php index a4d6b7ab642e2..8e77d79e91c4c 100644 --- a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminFormPage.php +++ b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminFormPage.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Page\Acceptance\Administrator; /** @@ -17,5 +19,5 @@ */ class AdminFormPage extends AdminPage { - // @todo. + // @todo. } diff --git a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminListPage.php b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminListPage.php index 60cff02671dbd..7771c3dd79c0f 100644 --- a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminListPage.php +++ b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminListPage.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Page\Acceptance\Administrator; /** @@ -17,5 +19,5 @@ */ class AdminListPage extends AdminPage { - // @todo. + // @todo. } diff --git a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminPage.php b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminPage.php index b9e5e1716c0e0..aaf08c52aca32 100644 --- a/tests/Codeception/_support/Page/Acceptance/Administrator/AdminPage.php +++ b/tests/Codeception/_support/Page/Acceptance/Administrator/AdminPage.php @@ -1,4 +1,5 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ + namespace Page\Acceptance\Administrator; use AcceptanceTester; @@ -20,327 +22,322 @@ */ class AdminPage extends AcceptanceTester { - /** - * The element id which contains system messages. - * - * @var array - * @since 3.7.3 - */ - public static $systemMessageContainer = ['id' => 'system-message-container']; - - /** - * The form element with id "adminForm" - * - * @var array - * @since 4.0.0 - */ - public static $adminForm = ['id' => 'adminForm']; - - /** - * The element id which contains page title in administrator header. - * - * @var array - * @since 3.7.3 - */ - public static $pageTitle = ['class' => 'page-title']; - - /** - * Locator for page title. - * - * @var array - * @since 3.7.3 - */ - public static $title = ['id' => 'jform_title']; - - /** - * Locator for search input field. - * - * @var array - * @since 3.7.3 - */ - public static $filterSearch = ['id' => 'filter_search']; - - /** - * Locator for status filter under search tool. - * - * @var array - * @since 3.7.3 - */ - public static $filterPublished = 'filter_published'; - - /** - * Locator for search button icon. - * - * @var array - * @since 3.7.3 - */ - public static $iconSearch = ['xpath' => "//button[@title='Search']"]; - - /** - * Locator for the Tabs in Edit View. - * - * @var array - * @since 3.7.3 - */ - public static $tabsLocator = ['xpath' => "//div[@role='tablist']/button"]; - - /** - * Locator for the Check All checkbox. - * - * @var array - * @since 3.7.3 - */ - public static $checkAll = ['xpath' => "//thead//input[@name='checkall-toggle' or @name='toggle']"]; - - /** - * Method to search using given keyword. - * - * @param string $keyword The keyword to search - * - * @return void - * - * @since 3.7.3 - */ - public function search($keyword) - { - $I = $this; - - $I->amGoingTo('search for "' . $keyword . '"'); - $I->fillField(static::$filterSearch, $keyword); - $I->click(static::$iconSearch); - } - - /** - * Method to search user with username. - * - * @param string $keyword The username of user - * - * @return void Checkbox for given username will be checked. - * - * @since 3.7.3 - */ - public function haveItemUsingSearch($keyword) - { - $I = $this; - - $I->amOnPage(static::$url); - $I->search($keyword); - $I->checkAllResults(); - $I->wait(1); - } - - /** - * Method is used to see system message after waiting for page title. - * - * @param string $title The webpage title - * @param string $message The unpublish successful message - * - * @return void - * - * @since 3.7.3 - */ - public function seeSystemMessage($title, $message) - { - $I = $this; - - $I->waitForPageTitle($title); - $I->waitForElementVisible(self::$systemMessageContainer, TIMEOUT); - $I->see($message, self::$systemMessageContainer); - } - - /** - * Method is to Wait for page title until default timeout. - * - * @param string $title Page Title text - * - * @return void - * - * @since 3.7.3 - * - * @throws Exception - */ - public function waitForPageTitle($title) - { - $I = $this; - $I->waitForText($title, $I->getConfig('timeout'), self::$pageTitle); - } - - /** - * Function to select all the item in the Search results in Administrator List. - * - * Note: We recommend use of checkAllResults function only after searchForItem to be sure you are selecting only - * the desired result set. - * - * @return void - * - * @since 3.7.3 - */ - public function checkAllResults() - { - $I = $this; - - $I->comment("Selecting Checkall button"); - $I->click(self::$checkAll); - } - - /** - * Selects an option in a Chosen Selector based on its id. - * - * @param string $selectId The id of the element + * @param string $option The text in the