Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
154 changes: 154 additions & 0 deletions tests/Codeception/api/com_banners/BannerCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* @package Joomla.Tests
* @subpackage Api.tests
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Codeception\Util\HttpCode;

/**
* Class BannerCest.
*
* Basic com_banners (banner) tests.
*
* @since 4.0.0
*/
class BannerCest
{
/**
* Api test before running.
*
* @param mixed ApiTester $I Api tester
*
* @return void
*
* @since 4.0.0
*/
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);
}

/**
* Api test after running.
*
* @param mixed ApiTester $I Api tester
*
* @return void
*
* @since 4.0.0
*/
public function _after(ApiTester $I)
{
}

/**
* Test the 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 banners
*/
public function testCrudOnBanner(ApiTester $I)
{
$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$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->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/banners/1');
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');

// 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==');
$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->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$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);
$categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0];

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/banners/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$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->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/banners/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}
}
148 changes: 148 additions & 0 deletions tests/Codeception/api/com_contact/ContactCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
/**
* @package Joomla.Tests
* @subpackage Api.tests
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

use Codeception\Util\HttpCode;

/**
* Class ContactCest.
*
* Basic com_contact (contact) tests.
*
* @since 4.0.0
*/
class ContactCest
{
/**
* Api test before running.
*
* @param mixed ApiTester $I Api tester
*
* @return void
*
* @since 4.0.0
*/
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);
}

/**
* Api test after running.
*
* @param mixed ApiTester $I Api tester
*
* @return void
*
* @since 4.0.0
*/
public function _after(ApiTester $I)
{
}

/**
* Test the 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 contacts
*/
public function testCrudOnContact(ApiTester $I)
{
$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$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->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/contact/1');
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$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, 'published' => -2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$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->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$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);
$categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0];

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$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->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/contact/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}
}
52 changes: 50 additions & 2 deletions tests/Codeception/api/com_content/ContentCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -89,12 +89,60 @@ 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', 'catid' => 2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/content/article/1');
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}

/**
* Test the category 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->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');

$testarticle = [
'title' => 'A test category',
'parent_id' => 2,
'params' => [
'workflow_id' => 'inherit'
]
];

$I->sendPOST('/content/categories', $testarticle);

$I->seeResponseCodeIs(HttpCode::OK);
$categoryId = $I->grabDataFromResponseByJsonPath('$.data.id')[0];

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendGET('/content/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::OK);

$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'], 'published' => -2]);
$I->seeResponseCodeIs(HttpCode::OK);

$I->amBearerAuthenticated('c2hhMjU2OjM6ZTJmMjJlYTNlNTU0NmM1MDJhYTIzYzMwN2MxYzAwZTQ5NzJhMWRmOTUyNjY5MTk2YjE5ODJmZWMwZTcxNzgwMQ==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$I->sendDELETE('/content/categories/' . $categoryId);
$I->seeResponseCodeIs(HttpCode::NO_CONTENT);
}
}