-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
10 changed files
with
186 additions
and
76 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
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,26 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Contracts\AdminUi\Autosave; | ||
|
||
interface AutosaveServiceInterface | ||
{ | ||
public function isEnabled(): bool; | ||
|
||
/** | ||
* Returns autosave interval in milliseconds. | ||
*/ | ||
public function getInterval(): int; | ||
|
||
public function isInProgress(): bool; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function setInProgress(bool $isInProgress): void; | ||
} |
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,49 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\AdminUi\Autosave; | ||
|
||
use Ibexa\AdminUi\UserSetting\Autosave; | ||
use Ibexa\AdminUi\UserSetting\AutosaveInterval; | ||
use Ibexa\Contracts\AdminUi\Autosave\AutosaveServiceInterface; | ||
use Ibexa\User\UserSetting\UserSettingService; | ||
|
||
final class AutosaveService implements AutosaveServiceInterface | ||
{ | ||
private UserSettingService $userSettingService; | ||
|
||
private bool $inProgress = false; | ||
|
||
public function __construct(UserSettingService $userSettingService) | ||
{ | ||
$this->userSettingService = $userSettingService; | ||
} | ||
|
||
public function isEnabled(): bool | ||
{ | ||
return $this->userSettingService->getUserSetting(Autosave::IDENTIFIER)->value === Autosave::ENABLED_OPTION; | ||
} | ||
|
||
/** | ||
* Returns autosave interval in milliseconds. | ||
*/ | ||
public function getInterval(): int | ||
{ | ||
return (int)$this->userSettingService->getUserSetting(AutosaveInterval::IDENTIFIER)->value * 1000; | ||
} | ||
|
||
public function isInProgress(): bool | ||
{ | ||
return $this->inProgress; | ||
} | ||
|
||
public function setInProgress(bool $isInProgress): void | ||
{ | ||
$this->inProgress = $isInProgress; | ||
} | ||
} |
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
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
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
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
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
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,64 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\AdminUi\Autosave; | ||
|
||
use Ibexa\AdminUi\Autosave\AutosaveService; | ||
use Ibexa\AdminUi\UserSetting\Autosave; | ||
use Ibexa\AdminUi\UserSetting\AutosaveInterval; | ||
use Ibexa\User\UserSetting\UserSetting; | ||
use Ibexa\User\UserSetting\UserSettingService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class AutosaveServiceTest extends TestCase | ||
{ | ||
/** @var \Ibexa\User\UserSetting\UserSettingService&\PHPUnit\Framework\MockObject\MockObject */ | ||
private UserSettingService $userSettingService; | ||
|
||
private AutosaveService $autosaveService; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->userSettingService = $this->createMock(UserSettingService::class); | ||
$this->autosaveService = new AutosaveService($this->userSettingService); | ||
} | ||
|
||
public function testIsEnabled(): void | ||
{ | ||
$this->userSettingService | ||
->method('getUserSetting') | ||
->with(Autosave::IDENTIFIER) | ||
->willReturn($this->createUserSettingWithValue(Autosave::ENABLED_OPTION)); | ||
|
||
self::assertTrue($this->autosaveService->isEnabled()); | ||
} | ||
|
||
public function testGetInterval(): void | ||
{ | ||
$this->userSettingService | ||
->method('getUserSetting') | ||
->with(AutosaveInterval::IDENTIFIER) | ||
->willReturn($this->createUserSettingWithValue('30')); | ||
|
||
self::assertEquals(30000, $this->autosaveService->getInterval()); | ||
} | ||
|
||
public function testIsInProgress(): void | ||
{ | ||
self::assertFalse($this->autosaveService->isInProgress()); | ||
$this->autosaveService->setInProgress(true); | ||
self::assertTrue($this->autosaveService->isInProgress()); | ||
} | ||
|
||
private function createUserSettingWithValue(string $value): UserSetting | ||
{ | ||
return new UserSetting([ | ||
'value' => $value, | ||
]); | ||
} | ||
} |
Oops, something went wrong.