From 19a6dc46fe521e3f076fa910726601f483285ccb Mon Sep 17 00:00:00 2001 From: wilsonge Date: Sat, 19 Oct 2019 17:19:46 +0100 Subject: [PATCH 01/22] Add basic contact api tests --- .../api/com_contact/ContactCest.php | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/Codeception/api/com_contact/ContactCest.php diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php new file mode 100644 index 0000000000000..b8ce05b0fb287 --- /dev/null +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -0,0 +1,91 @@ +amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + + $testarticle = [ + 'alias' => 'contact-the-ceo', + 'catid' => 4, + 'language' => '*', + 'name' => 'Francine Blogs' + ]; + + $I->sendPOST('/contact', $testarticle); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/contact/1'); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/contact/1', ['name' => 'Frankie Blogs']); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendDELETE('/contact/1'); + $I->seeResponseCodeIs(HttpCode::NO_CONTENT); + } +} From 07ea6e67d13ccb040271c6ffd2b24e9600940739 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Sat, 19 Oct 2019 19:19:25 +0100 Subject: [PATCH 02/22] Fix contact delete in the API --- .../components/com_contact/src/Model/ContactModel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/administrator/components/com_contact/src/Model/ContactModel.php b/administrator/components/com_contact/src/Model/ContactModel.php index 50fdb93884f51..af4afd772b7e0 100644 --- a/administrator/components/com_contact/src/Model/ContactModel.php +++ b/administrator/components/com_contact/src/Model/ContactModel.php @@ -130,7 +130,8 @@ protected function batchUser($value, $pks, $contexts) */ protected function canDelete($record) { - if (empty($record->id) || $record->published != -2) + // We ignore the requirement for an item to be trashed when calling delete from the API + if (empty($record->id) || ($record->published != -2 && !Factory::getApplication()->isClient('api'))) { return false; } From 68d7382563580ed86b52e371695722777a8352c0 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Sat, 30 Nov 2019 21:47:46 +0000 Subject: [PATCH 03/22] Improve tests --- .../com_contact/src/Model/ContactModel.php | 2 +- .../api/com_contact/ContactCest.php | 2 +- .../api/com_content/ContentCest.php | 30 ++++++++++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/administrator/components/com_contact/src/Model/ContactModel.php b/administrator/components/com_contact/src/Model/ContactModel.php index af4afd772b7e0..68bdf3f25e2fb 100644 --- a/administrator/components/com_contact/src/Model/ContactModel.php +++ b/administrator/components/com_contact/src/Model/ContactModel.php @@ -131,7 +131,7 @@ protected function batchUser($value, $pks, $contexts) protected function canDelete($record) { // We ignore the requirement for an item to be trashed when calling delete from the API - if (empty($record->id) || ($record->published != -2 && !Factory::getApplication()->isClient('api'))) + if (empty($record->id) || $record->published != -2) { return false; } diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index b8ce05b0fb287..fab36d0baf6c0 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -80,7 +80,7 @@ public function testCrudOnArticle(ApiTester $I) $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/contact/1', ['name' => 'Frankie Blogs']); + $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'state' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amHttpAuthenticated('admin', 'admin'); diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 04b3956495202..87ce62d96db23 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -89,7 +89,7 @@ public function testCrudOnArticle(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/content/article/1', ['title' => 'Another Title']); + $I->sendPATCH('/content/article/1', ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); @@ -97,4 +97,32 @@ public function testCrudOnArticle(ApiTester $I) $I->sendDELETE('/content/article/1'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } + + /** + * Test the crud endpoints of com_content from the API. + * + * @param mixed ApiTester $I Api tester + * + * @return void + * + * @since 4.0.0 + * + * @TODO: Make these separate tests but requires sample data being installed so there are existing categories + */ + public function testCrudOnCategory(ApiTester $I) + { + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + + $testarticle = [ + 'title' => 'Just for you', + 'catid' => 2, + 'articletext' => 'A dummy article to save to the database', + 'language' => '*', + 'alias' => 'tobias' + ]; + + $I->sendPOST('/content/article', $testarticle); + } } From 8f2731a69c6d72f6f9f2203dc0c27f0f9a1f7415 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Sat, 30 Nov 2019 21:58:04 +0000 Subject: [PATCH 04/22] Update ContactModel.php --- administrator/components/com_contact/src/Model/ContactModel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/administrator/components/com_contact/src/Model/ContactModel.php b/administrator/components/com_contact/src/Model/ContactModel.php index 68bdf3f25e2fb..50fdb93884f51 100644 --- a/administrator/components/com_contact/src/Model/ContactModel.php +++ b/administrator/components/com_contact/src/Model/ContactModel.php @@ -130,7 +130,6 @@ protected function batchUser($value, $pks, $contexts) */ protected function canDelete($record) { - // We ignore the requirement for an item to be trashed when calling delete from the API if (empty($record->id) || $record->published != -2) { return false; From 706c83a433223b1157ae6e595a803fc8059c8b2f Mon Sep 17 00:00:00 2001 From: wilsonge Date: Mon, 3 Feb 2020 20:30:13 +0000 Subject: [PATCH 05/22] Test for content categories --- .../api/com_content/ContentCest.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 87ce62d96db23..eabfe3bccfb54 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -53,7 +53,7 @@ public function _after(ApiTester $I) } /** - * Test the crud endpoints of com_content from the API. + * Test the article crud endpoints of com_content from the API. * * @param mixed ApiTester $I Api tester * @@ -99,7 +99,7 @@ public function testCrudOnArticle(ApiTester $I) } /** - * Test the crud endpoints of com_content from the API. + * Test the category crud endpoints of com_content from the API. * * @param mixed ApiTester $I Api tester * @@ -116,13 +116,31 @@ public function testCrudOnCategory(ApiTester $I) $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $testarticle = [ - 'title' => 'Just for you', - 'catid' => 2, - 'articletext' => 'A dummy article to save to the database', - 'language' => '*', - 'alias' => 'tobias' + 'title' => 'A test category', + 'parent_id' => 2, + 'params' => [ + 'workflow_id' => 'inherit' + ] ]; - $I->sendPOST('/content/article', $testarticle); + $I->sendPOST('/content/categories', $testarticle); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/content/categories/8'); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendPATCH('/content/categories/8', ['title' => 'Another Title']); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendDELETE('/content/categories/8'); + $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } From 301f1f2b7a49684263fd91a41ef177d7007ac6a7 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Mon, 3 Feb 2020 23:06:23 +0000 Subject: [PATCH 06/22] Start work on tests for banners --- .../api/com_banners/BannerCest.php | 141 ++++++++++++++++++ .../api/com_contact/ContactCest.php | 48 +++++- 2 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 tests/Codeception/api/com_banners/BannerCest.php diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php new file mode 100644 index 0000000000000..d226ad2af782e --- /dev/null +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -0,0 +1,141 @@ +amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + + $testBanner = [ + 'name' => 'My Custom Advert', + 'catid' => 3, + 'description' => '', + 'custombannercode' => '', + 'metakey' => '', + 'params' => [ + 'imageurl' => '', + 'width' => '', + 'height' => '', + 'alt' => '' + ], + ]; + + $I->sendPOST('/banners', $testBanner); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/banners/1'); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendPATCH('/banners/1', ['name' => 'Different Custom Advert', 'state' => -2]); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendDELETE('/banners/1'); + $I->seeResponseCodeIs(HttpCode::NO_CONTENT); + } + + /** + * Test the category crud endpoints of com_banners from the API. + * + * @param mixed ApiTester $I Api tester + * + * @return void + * + * @since 4.0.0 + * + * @TODO: Make these separate tests but requires sample data being installed so there are existing categories + */ + public function testCrudOnCategory(ApiTester $I) + { + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + + $testarticle = [ + 'title' => 'A test category', + 'parent_id' => 3 + ]; + + $I->sendPOST('/banners/categories', $testarticle); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/banners/categories/8'); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendPATCH('/banners/categories/8', ['title' => 'Another Title']); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendDELETE('/banners/categories/8'); + $I->seeResponseCodeIs(HttpCode::NO_CONTENT); + } +} diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index fab36d0baf6c0..e006bd3c2f687 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -55,7 +55,7 @@ public function _after(ApiTester $I) * * @TODO: Make these separate tests but requires sample data being installed so there are existing contacts */ - public function testCrudOnArticle(ApiTester $I) + public function testCrudOnContact(ApiTester $I) { $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Content-Type', 'application/json'); @@ -88,4 +88,50 @@ public function testCrudOnArticle(ApiTester $I) $I->sendDELETE('/contact/1'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } + + /** + * Test the category crud endpoints of com_contact from the API. + * + * @param mixed ApiTester $I Api tester + * + * @return void + * + * @since 4.0.0 + * + * @TODO: Make these separate tests but requires sample data being installed so there are existing categories + */ + public function testCrudOnCategory(ApiTester $I) + { + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + + $testContact = [ + 'title' => 'A test category', + 'parent_id' => 4, + 'params' => [ + 'workflow_id' => 'inherit' + ] + ]; + + $I->sendPOST('/contact/categories', $testContact); + + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendGET('/contact/categories/8'); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Content-Type', 'application/json'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendPATCH('/contact/categories/8', ['title' => 'Another Title']); + $I->seeResponseCodeIs(HttpCode::OK); + + $I->amHttpAuthenticated('admin', 'admin'); + $I->haveHttpHeader('Accept', 'application/vnd.api+json'); + $I->sendDELETE('/contact/categories/8'); + $I->seeResponseCodeIs(HttpCode::NO_CONTENT); + } } From fc5569531413401cbd1f4e222a6b8ed8dc32d88d Mon Sep 17 00:00:00 2001 From: wilsonge Date: Tue, 25 Aug 2020 18:16:57 +0100 Subject: [PATCH 07/22] Move tests to bearer token approach --- .../api/com_banners/BannerCest.php | 24 ++++++++++++------- .../api/com_contact/ContactCest.php | 24 ++++++++++++------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index d226ad2af782e..b34bfa4cd23db 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -29,6 +29,14 @@ class BannerCest */ public function _before(ApiTester $I) { + // TODO: Improve this to retrieve a specific ID to replace with a known ID + $desiredUserId = 3; + $I->updateInDatabase('users', ['id' => 3], []); + $I->updateInDatabase('user_usergroup_map', ['user_id' => 3], []); + $enabledData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.enabled', 'profile_value' => 1]; + $tokenData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.token', 'profile_value' => 'dOi2m1NRrnBHlhaWK/WWxh3B5tqq1INbdf4DhUmYTI4=']; + $I->haveInDatabase('user_profiles', $enabledData); + $I->haveInDatabase('user_profiles', $tokenData); } /** @@ -57,7 +65,7 @@ public function _after(ApiTester $I) */ public function testCrudOnBanner(ApiTester $I) { - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); @@ -79,18 +87,18 @@ public function testCrudOnBanner(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendGET('/banners/1'); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendPATCH('/banners/1', ['name' => 'Different Custom Advert', 'state' => -2]); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendDELETE('/banners/1'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); @@ -109,7 +117,7 @@ public function testCrudOnBanner(ApiTester $I) */ public function testCrudOnCategory(ApiTester $I) { - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); @@ -122,18 +130,18 @@ public function testCrudOnCategory(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendGET('/banners/categories/8'); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendPATCH('/banners/categories/8', ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendDELETE('/banners/categories/8'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index e006bd3c2f687..f74d6b8800de8 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -29,6 +29,14 @@ class ContactCest */ public function _before(ApiTester $I) { + // TODO: Improve this to retrieve a specific ID to replace with a known ID + $desiredUserId = 3; + $I->updateInDatabase('users', ['id' => 3], []); + $I->updateInDatabase('user_usergroup_map', ['user_id' => 3], []); + $enabledData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.enabled', 'profile_value' => 1]; + $tokenData = ['user_id' => $desiredUserId, 'profile_key' => 'joomlatoken.token', 'profile_value' => 'dOi2m1NRrnBHlhaWK/WWxh3B5tqq1INbdf4DhUmYTI4=']; + $I->haveInDatabase('user_profiles', $enabledData); + $I->haveInDatabase('user_profiles', $tokenData); } /** @@ -57,7 +65,7 @@ public function _after(ApiTester $I) */ public function testCrudOnContact(ApiTester $I) { - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); @@ -72,18 +80,18 @@ public function testCrudOnContact(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendGET('/contact/1'); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'state' => -2]); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendDELETE('/contact/1'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); @@ -102,7 +110,7 @@ public function testCrudOnContact(ApiTester $I) */ public function testCrudOnCategory(ApiTester $I) { - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); @@ -118,18 +126,18 @@ public function testCrudOnCategory(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendGET('/contact/categories/8'); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendPATCH('/contact/categories/8', ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendDELETE('/contact/categories/8'); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); From f3fc0e437c487a3c6d7d40e96b5224b88271b7a7 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Tue, 25 Aug 2020 21:08:46 +0100 Subject: [PATCH 08/22] Fix patch banner --- tests/Codeception/api/com_banners/BannerCest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index b34bfa4cd23db..70c8e22bb524f 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -95,7 +95,9 @@ public function testCrudOnBanner(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/banners/1', ['name' => 'Different Custom Advert', 'state' => -2]); + + // Category is a required field for this patch request for now TODO: Remove this dependency + $I->sendPATCH('/banners/1', ['name' => 'Different Custom Advert', 'state' => -2, 'catid' => 3]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From 6ae76fa56b844b207870b6ae38af4c26a4cc8ccc Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 17:32:02 +0100 Subject: [PATCH 09/22] Fix category creation for non-content extensions --- .../com_categories/src/Controller/CategoriesController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/components/com_categories/src/Controller/CategoriesController.php b/api/components/com_categories/src/Controller/CategoriesController.php index c488f259aaf7d..e9cc9d3d4d6a9 100644 --- a/api/components/com_categories/src/Controller/CategoriesController.php +++ b/api/components/com_categories/src/Controller/CategoriesController.php @@ -47,7 +47,12 @@ class CategoriesController extends ApiController */ protected function preprocessSaveData(array $data): array { - $data['extension'] = $this->getExtensionFromInput(); + $extension = $this->getExtensionFromInput(); + $data['extension'] = $extension; + + // TODO: This is a hack to drop the extension into the global input object - to satisfy how state is built + // we should be able to improve this in the future + $this->input->set('extension', $extension); return $data; } From c0707deee60b83725b34ac0efedc0a9f9a4b2a78 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 21:01:31 +0100 Subject: [PATCH 10/22] Fix delete category --- tests/Codeception/api/com_banners/BannerCest.php | 4 +++- tests/Codeception/api/com_contact/ContactCest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index 70c8e22bb524f..1e3468757c246 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -140,7 +140,9 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/banners/categories/8', ['title' => 'Another Title']); + + // Unpublish in order to allow the delete in the next step + $I->sendPATCH('/banners/categories/8', ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index f74d6b8800de8..08874b3454d65 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -134,7 +134,7 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/contact/categories/8', ['title' => 'Another Title']); + $I->sendPATCH('/contact/categories/8', ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From bf142b769c830152daa29f0209a6773cc1c55c0f Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 21:23:31 +0100 Subject: [PATCH 11/22] Fix patch category --- tests/Codeception/api/com_contact/ContactCest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 08874b3454d65..7eb562b732b69 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -88,7 +88,9 @@ public function testCrudOnContact(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'state' => -2]); + + // Category is a required field for this patch request for now TODO: Remove this dependency + $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'catid' => 4, 'state' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From 8f0416f4300bb171ffb88171f3e37e1aa4ed5646 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 22:58:47 +0100 Subject: [PATCH 12/22] State => published --- tests/Codeception/api/com_contact/ContactCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 7eb562b732b69..02e65f6b78c00 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -90,7 +90,7 @@ public function testCrudOnContact(ApiTester $I) $I->haveHttpHeader('Accept', 'application/vnd.api+json'); // Category is a required field for this patch request for now TODO: Remove this dependency - $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'catid' => 4, 'state' => -2]); + $I->sendPATCH('/contact/1', ['name' => 'Frankie Blogs', 'catid' => 4, 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From a6e69a01ab38c53c6541bccab67e417c94f8668d Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 23:23:01 +0100 Subject: [PATCH 13/22] Don't hardcode catid for tests --- tests/Codeception/api/com_banners/BannerCest.php | 7 ++++--- tests/Codeception/api/com_contact/ContactCest.php | 7 ++++--- tests/Codeception/api/com_content/ContentCest.php | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index 1e3468757c246..30d5b064444df 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -131,10 +131,11 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/banners/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/banners/categories/8'); + $I->sendGET('/banners/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); @@ -142,12 +143,12 @@ public function testCrudOnCategory(ApiTester $I) $I->haveHttpHeader('Accept', 'application/vnd.api+json'); // Unpublish in order to allow the delete in the next step - $I->sendPATCH('/banners/categories/8', ['title' => 'Another Title', 'published' => -2]); + $I->sendPATCH('/banners/categories/' + $categoryId, ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/banners/categories/8'); + $I->sendDELETE('/banners/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 02e65f6b78c00..13402e6153275 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -127,21 +127,22 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/contact/categories', $testContact); $I->seeResponseCodeIs(HttpCode::OK); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/contact/categories/8'); + $I->sendGET('/contact/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/contact/categories/8', ['title' => 'Another Title', 'published' => -2]); + $I->sendPATCH('/contact/categories/' + $categoryId, ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/contact/categories/8'); + $I->sendDELETE('/contact/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index eabfe3bccfb54..ae02897f43ead 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -126,21 +126,22 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/content/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/content/categories/8'); + $I->sendGET('/content/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/content/categories/8', ['title' => 'Another Title']); + $I->sendPATCH('/content/categories/' + $categoryId, ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/content/categories/8'); + $I->sendDELETE('/content/categories/' + $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } From a0aff49c0e6605b8692161547095e481909bfee9 Mon Sep 17 00:00:00 2001 From: wilsonge Date: Thu, 27 Aug 2020 23:47:12 +0100 Subject: [PATCH 14/22] Debug --- tests/Codeception/api/com_banners/BannerCest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index 30d5b064444df..cd94c6fe7e917 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -132,6 +132,7 @@ public function testCrudOnCategory(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); + var_dump($categoryId);die; $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); From 287cffb31103a909bfebd0f9dc68272b1778a02d Mon Sep 17 00:00:00 2001 From: wilsonge Date: Fri, 28 Aug 2020 08:57:12 +0100 Subject: [PATCH 15/22] Fix --- tests/Codeception/api/com_banners/BannerCest.php | 3 +-- tests/Codeception/api/com_contact/ContactCest.php | 2 +- tests/Codeception/api/com_content/ContentCest.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index cd94c6fe7e917..7d2f7468b09c0 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -131,8 +131,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/banners/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); - var_dump($categoryId);die; + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 13402e6153275..204eb5d6f4527 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -127,7 +127,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/contact/categories', $testContact); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index ae02897f43ead..381923ce69203 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -126,7 +126,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/content/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data[0].id'); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); From 419791f94f3236f2c26acbd147bec0f91286e0b1 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Fri, 28 Aug 2020 10:20:14 +0200 Subject: [PATCH 16/22] Fixes --- tests/Codeception/api/com_banners/BannerCest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index 7d2f7468b09c0..c9b5776debfb0 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -132,6 +132,7 @@ public function testCrudOnCategory(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); +var_dump($categoryId);die; $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); From 3924dca7391204edfc77a81f458c1fe49ae5833a Mon Sep 17 00:00:00 2001 From: wilsonge Date: Fri, 28 Aug 2020 09:47:35 +0100 Subject: [PATCH 17/22] Fixes --- tests/Codeception/api/com_banners/BannerCest.php | 3 +-- tests/Codeception/api/com_contact/ContactCest.php | 2 +- tests/Codeception/api/com_content/ContentCest.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index c9b5776debfb0..b0b84a6e72715 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -131,8 +131,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/banners/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); -var_dump($categoryId);die; + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0]; $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 204eb5d6f4527..3099cc8e3fc4e 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -127,7 +127,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/contact/categories', $testContact); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0]; $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 381923ce69203..fa0bb7872d8ba 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -126,7 +126,7 @@ public function testCrudOnCategory(ApiTester $I) $I->sendPOST('/content/categories', $testarticle); $I->seeResponseCodeIs(HttpCode::OK); - $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id'); + $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0]; $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); From 4d3cfc21610089c357961848563971e5a094985e Mon Sep 17 00:00:00 2001 From: wilsonge Date: Fri, 28 Aug 2020 10:12:43 +0100 Subject: [PATCH 18/22] Append string --- tests/Codeception/api/com_banners/BannerCest.php | 6 +++--- tests/Codeception/api/com_contact/ContactCest.php | 6 +++--- tests/Codeception/api/com_content/ContentCest.php | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/Codeception/api/com_banners/BannerCest.php b/tests/Codeception/api/com_banners/BannerCest.php index b0b84a6e72715..f4723229534ea 100644 --- a/tests/Codeception/api/com_banners/BannerCest.php +++ b/tests/Codeception/api/com_banners/BannerCest.php @@ -135,7 +135,7 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/banners/categories/' + $categoryId); + $I->sendGET('/banners/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); @@ -143,12 +143,12 @@ public function testCrudOnCategory(ApiTester $I) $I->haveHttpHeader('Accept', 'application/vnd.api+json'); // Unpublish in order to allow the delete in the next step - $I->sendPATCH('/banners/categories/' + $categoryId, ['title' => 'Another Title', 'published' => -2]); + $I->sendPATCH('/banners/categories/' . $categoryId, ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/banners/categories/' + $categoryId); + $I->sendDELETE('/banners/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } diff --git a/tests/Codeception/api/com_contact/ContactCest.php b/tests/Codeception/api/com_contact/ContactCest.php index 3099cc8e3fc4e..6ae2cfcd4a5ca 100644 --- a/tests/Codeception/api/com_contact/ContactCest.php +++ b/tests/Codeception/api/com_contact/ContactCest.php @@ -131,18 +131,18 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/contact/categories/' + $categoryId); + $I->sendGET('/contact/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/contact/categories/' + $categoryId, ['title' => 'Another Title', 'published' => -2]); + $I->sendPATCH('/contact/categories/' . $categoryId, ['title' => 'Another Title', 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/contact/categories/' + $categoryId); + $I->sendDELETE('/contact/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index fa0bb7872d8ba..8b18d8a06a2a1 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -130,18 +130,18 @@ public function testCrudOnCategory(ApiTester $I) $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendGET('/content/categories/' + $categoryId); + $I->sendGET('/content/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::OK); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/content/categories/' + $categoryId, ['title' => 'Another Title']); + $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); $I->amHttpAuthenticated('admin', 'admin'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendDELETE('/content/categories/' + $categoryId); + $I->sendDELETE('/content/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); } } From bf56c740202f0c047f81c63663c7e3aa78858297 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Fri, 28 Aug 2020 13:06:50 +0200 Subject: [PATCH 19/22] Add catid to the update --- tests/Codeception/api/com_content/ContentCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 8b18d8a06a2a1..3c367e3a887d4 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -89,7 +89,7 @@ public function testCrudOnArticle(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/content/article/1', ['title' => 'Another Title']); + $I->sendPATCH('/content/article/1', ['title' => 'Another Title', 'catid' => 2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From 16746b3489f11e80b72c38a4d2bdacf67dec6bed Mon Sep 17 00:00:00 2001 From: George Wilson Date: Fri, 28 Aug 2020 13:32:19 +0200 Subject: [PATCH 20/22] Fix auth --- tests/Codeception/api/com_content/ContentCest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 3c367e3a887d4..25acd233cb339 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -111,7 +111,8 @@ public function testCrudOnArticle(ApiTester $I) */ public function testCrudOnCategory(ApiTester $I) { - $I->amHttpAuthenticated('admin', 'admin'); + + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); @@ -128,18 +129,18 @@ public function testCrudOnCategory(ApiTester $I) $I->seeResponseCodeIs(HttpCode::OK); $categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0]; - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendGET('/content/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title']); $I->seeResponseCodeIs(HttpCode::OK); - $I->amHttpAuthenticated('admin', 'admin'); + $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); $I->sendDELETE('/content/categories/' . $categoryId); $I->seeResponseCodeIs(HttpCode::NO_CONTENT); From 109e0647ae1f4d1c4292ac7d9b77a192fd272fa4 Mon Sep 17 00:00:00 2001 From: George Wilson Date: Fri, 28 Aug 2020 14:00:18 +0200 Subject: [PATCH 21/22] Add workflow --- tests/Codeception/api/com_content/ContentCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 25acd233cb339..531cbddbf5643 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -137,7 +137,7 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title']); + $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title', 'params' => ['workflow_id' => 'inherit']]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); From 4e4a3602914ed1e4bb92c0c32f6fb3da67c9a42d Mon Sep 17 00:00:00 2001 From: George Wilson Date: Fri, 28 Aug 2020 14:38:08 +0200 Subject: [PATCH 22/22] Trash article in the update --- tests/Codeception/api/com_content/ContentCest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Codeception/api/com_content/ContentCest.php b/tests/Codeception/api/com_content/ContentCest.php index 531cbddbf5643..36e7c8c59c7d0 100644 --- a/tests/Codeception/api/com_content/ContentCest.php +++ b/tests/Codeception/api/com_content/ContentCest.php @@ -137,7 +137,7 @@ public function testCrudOnCategory(ApiTester $I) $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ=='); $I->haveHttpHeader('Content-Type', 'application/json'); $I->haveHttpHeader('Accept', 'application/vnd.api+json'); - $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title', 'params' => ['workflow_id' => 'inherit']]); + $I->sendPATCH('/content/categories/' . $categoryId, ['title' => 'Another Title', 'params' => ['workflow_id' => 'inherit'], 'published' => -2]); $I->seeResponseCodeIs(HttpCode::OK); $I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');