-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5.2] Add languages API endpoint (#42136)
* GET languages * correct fix * cs * Update api/components/com_installer/src/View/Languages/JsonapiView.php Co-authored-by: Quy <[email protected]> * __DEPLOY_VERSION__ * __DEPLOY_VERSION__ * 2023 * cs * cs
- Loading branch information
Showing
4 changed files
with
110 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
api/components/com_installer/src/Controller/LanguagesController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/** | ||
* @package Joomla.API | ||
* @subpackage com_installer | ||
* | ||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\Component\Installer\Api\Controller; | ||
|
||
use Joomla\CMS\MVC\Controller\ApiController; | ||
|
||
// phpcs:disable PSR1.Files.SideEffects | ||
\defined('_JEXEC') or die; | ||
// phpcs:enable PSR1.Files.SideEffects | ||
|
||
/** | ||
* The manage controller | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class LanguagesController extends ApiController | ||
{ | ||
/** | ||
* The content type of the item. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $contentType = 'languages'; | ||
|
||
/** | ||
* The default view for the display method. | ||
* | ||
* @var string | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $default_view = 'languages'; | ||
} |
57 changes: 57 additions & 0 deletions
57
api/components/com_installer/src/View/Languages/JsonapiView.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* @package Joomla.API | ||
* @subpackage com_installer | ||
* | ||
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\Component\Installer\Api\View\Languages; | ||
|
||
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView; | ||
|
||
// phpcs:disable PSR1.Files.SideEffects | ||
\defined('_JEXEC') or die; | ||
// phpcs:enable PSR1.Files.SideEffects | ||
|
||
/** | ||
* The languages view | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
class JsonapiView extends BaseApiView | ||
{ | ||
/** | ||
* The fields to render item in the documents | ||
* | ||
* @var array | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected $fieldsToRenderList = [ | ||
'name', | ||
'element', | ||
'version', | ||
'type', | ||
'detailsurl', | ||
]; | ||
|
||
protected $i = 0; | ||
|
||
/** | ||
* Prepare item before render. | ||
* | ||
* @param object $item The model item | ||
* | ||
* @return object | ||
* | ||
* @since __DEPLOY_VERSION__ | ||
*/ | ||
protected function prepareItem($item) | ||
{ | ||
$item->id = ++$this->i; | ||
|
||
return parent::prepareItem($item); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('Test that languages API endpoint', () => { | ||
it('can deliver a list of languages', () => { | ||
cy.api_get('/languages') | ||
.then((response) => cy.wrap(response).its('body').its('data.0').its('type') | ||
.should('include', 'languages')); | ||
}); | ||
}); |