Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Aug 25, 2020
1 parent 07ea6e6 commit 68d7382
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Codeception/api/com_contact/ContactCest.php
Expand Up @@ -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');
Expand Down
30 changes: 29 additions & 1 deletion tests/Codeception/api/com_content/ContentCest.php
Expand Up @@ -89,12 +89,40 @@ 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==');
$I->haveHttpHeader('Accept', 'application/vnd.api+json');
$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);
}
}

0 comments on commit 68d7382

Please sign in to comment.