Skip to content

Commit

Permalink
feat: WIP - Handle configuration module to save and display the form
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Freoua-Alma committed Dec 2, 2024
1 parent a9a4b43 commit 6d8ccce
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 0 deletions.
33 changes: 33 additions & 0 deletions alma/exceptions/AlmaFormConfigurationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* 2018-2024 Alma SAS.
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma SAS <[email protected]>
* @copyright 2018-2024 Alma SAS
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\PrestaShop\Exceptions;

if (!defined('_PS_VERSION_')) {
exit;
}

class AlmaFormConfigurationException extends AlmaException
{
}
82 changes: 82 additions & 0 deletions alma/lib/Services/AlmaConfigurationService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
/**
* 2018-2024 Alma SAS.
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma SAS <[email protected]>
* @copyright 2018-2024 Alma SAS
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\Prestashop\Services;

use Alma\PrestaShop\Exceptions\AlmaApiKeyException;
use Alma\PrestaShop\Factories\ClientFactory;
use Alma\PrestaShop\Forms\ApiAdminFormBuilder;
use Alma\PrestaShop\Logger;
use Alma\PrestaShop\Model\AlmaApiKeyModel;
use Alma\PrestaShop\Proxy\ToolsProxy;

if (!defined('_PS_VERSION_')) {
exit;
}

class AlmaConfigurationService
{
/**
* @var \Alma\PrestaShop\Model\AlmaApiKeyModel
*/
private $almaApiKeyModel;
/**
* @var \Alma\PrestaShop\Proxy\ToolsProxy|mixed|null
*/
private $toolsProxy;

public function __construct(
$almaApiKeyModel = null,
$toolsProxy = null,
$clientFactory = null
) {
if (!$almaApiKeyModel) {
$almaApiKeyModel = new AlmaApiKeyModel();
}
$this->almaApiKeyModel = $almaApiKeyModel;

if (!$toolsProxy) {
$toolsProxy = new ToolsProxy();
}
$this->toolsProxy = $toolsProxy;

if (!$clientFactory) {
$clientFactory = new ClientFactory();
}
}

public function saveConfiguration()
{
try {
$currentMode = $this->toolsProxy->getValue(ApiAdminFormBuilder::ALMA_API_MODE);
$this->almaApiKeyModel->checkActiveApiKey($currentMode);
} catch (AlmaApiKeyException $e) {
Logger::instance()->error($e->getMessage());
}
}

public function getConfiguration()
{
}
}
54 changes: 54 additions & 0 deletions alma/tests/Unit/Services/AlmaConfigurationServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* 2018-2024 Alma SAS.
*
* THE MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* @author Alma SAS <[email protected]>
* @copyright 2018-2024 Alma SAS
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\PrestaShop\Tests\Unit\Services;

use Alma\PrestaShop\Model\AlmaApiKeyModel;
use Alma\Prestashop\Services\AlmaConfigurationService;
use PHPUnit\Framework\TestCase;

class AlmaConfigurationServiceTest extends TestCase
{
/**
* @var AlmaConfigurationService
*/
protected $almaconfigurationService;

public function setUp()
{
$this->almaApiKeyModel = $this->createMock(AlmaApiKeyModel::class);
$this->almaconfigurationService = new AlmaConfigurationService(
$this->almaApiKeyModel
);
}

public function tearDown()
{
$this->almaApiKeyModel = null;
}

public function testSaveConfiguration()
{
}
}

0 comments on commit 6d8ccce

Please sign in to comment.