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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Thumbs.db
vendor
.phpunit.result.cache
.php-cs-fixer.cache
.codex
64 changes: 64 additions & 0 deletions Controllers/Api/SwagMigrationTimezone.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use SwagMigrationConnector\Controllers\SwagMigrationApiControllerBase;
use SwagMigrationConnector\Service\ControllerReturnStruct;

class Shopware_Controllers_Api_SwagMigrationTimezone extends SwagMigrationApiControllerBase
{
/**
* @return void
*/
public function indexAction()
{
$dbConfig = $this->container->getParameter('shopware.db');
if (!\is_array($dbConfig)) {
$this->assignEmptyResult();

return;
}

if (!$this->hasTimezoneConfig($dbConfig)) {
$this->assignEmptyResult();

return;
}

$timezone = $dbConfig['timezone'];
Comment thread
DennisGarding marked this conversation as resolved.
if ($timezone === '') {
$timezone = null;
}

$response = new ControllerReturnStruct([
['timezone' => $timezone],
]);

$this->view->assign($response->jsonSerialize());
}

/**
* @param array<string, mixed> $dbConfig
*
* @return bool
*/
private function hasTimezoneConfig(array $dbConfig)
{
return isset($dbConfig['timezone']);
}
Comment thread
MalteJanz marked this conversation as resolved.

/**
* @return void
*/
private function assignEmptyResult()
{
$response = new ControllerReturnStruct([
['timezone' => null],
]);

$this->view->assign($response->jsonSerialize());
}
}
1 change: 1 addition & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<argument>%shopware.release.version%</argument>
<argument>%shopware.release.version_text%</argument>
<argument>%shopware.release.revision%</argument>
<argument>%shopware.db%</argument>
</service>

<service id="swag_migration_connector.service.plugin_information_service" class="SwagMigrationConnector\Service\PluginInformationService" public="true">
Expand Down
102 changes: 102 additions & 0 deletions Tests/Functional/Controllers/SwagMigrationTimezoneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* (c) shopware AG <info@shopware.com>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SwagMigrationConnector\Tests\Functional\Controllers;

use Shopware\Components\DependencyInjection\Container;
use Shopware_Controllers_Api_SwagMigrationTimezone as SwagMigrationTimezone;
use SwagMigrationConnector\Tests\Functional\ContainerTrait;
use SwagMigrationConnector\Tests\Functional\Controllers\ControllerFactory\Arguments;
use SwagMigrationConnector\Tests\Functional\Controllers\ControllerFactory\ControllerFactory;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

require __DIR__ . '/../../../Controllers/Api/SwagMigrationTimezone.php';

class SwagMigrationTimezoneTest extends \Enlight_Components_Test_Controller_TestCase
{
use ContainerTrait;

/**
* @return void
*/
public function testIndexActionReturnsConfiguredDatabaseTimezone()
{
$container = $this->getContainer();
$dbConfig = $container->getParameter('shopware.db');
static::assertTrue(\is_array($dbConfig));

$configuredTimezone = $dbConfig['timezone'];
$timezone = $configuredTimezone === '' ? null : $configuredTimezone;

$controller = ControllerFactory::createController(
SwagMigrationTimezone::class,
new Arguments($container)
);

$controller->indexAction();

$this->assertTimezoneResponse($timezone, $controller);
}

/**
* @return void
*/
public function testIndexActionReturnsNullTimezoneWhenDatabaseConfigHasNoTimezone()
{
$controller = $this->createControllerWithDatabaseConfig([]);
$controller->indexAction();

$this->assertTimezoneResponse(null, $controller);
}

/**
* @return void
*/
public function testIndexActionReturnsNullTimezoneWhenDatabaseConfigIsNotArray()
{
$controller = $this->createControllerWithDatabaseConfig('invalid');
$controller->indexAction();

$this->assertTimezoneResponse(null, $controller);
}

/**
* @param array<string, mixed>|string $dbConfig
*
* @return SwagMigrationTimezone
*/
private function createControllerWithDatabaseConfig($dbConfig)
{
$container = new Container(new ParameterBag([
'shopware.db' => $dbConfig,
]));

return ControllerFactory::createController(
SwagMigrationTimezone::class,
new Arguments($container)
);
}

/**
* @param string|null $timezone
* @param SwagMigrationTimezone $controller
*
* @return void
*/
private function assertTimezoneResponse($timezone, $controller)
{
static::assertSame([
'data' => [
[
'timezone' => $timezone,
],
],
'isLastRequest' => false,
'success' => true,
], $controller->View()->getAssign());
}
}
Loading