-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
262 additions
and
15 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
models/classes/Translation/Event/TranslationActionEvent.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,73 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2025 (original work) Open Assessment Technologies SA. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\tao\model\Translation\Event; | ||
|
||
use JsonSerializable; | ||
use oat\oatbox\event\Event; | ||
|
||
class TranslationActionEvent implements Event, JsonSerializable | ||
{ | ||
public const ACTION_CREATED = 'translation.created'; | ||
public const ACTION_UPDATED = 'translation.updated'; | ||
public const ACTION_DELETED = 'translation.deleted'; | ||
|
||
private string $action; | ||
private string $type; | ||
private string $originalResourceId; | ||
private string $translationResourceId; | ||
private string $locale; | ||
private array $data; | ||
|
||
public function __construct( | ||
string $action, | ||
string $type, | ||
string $originalResourceId, | ||
string $translationResourceId, | ||
string $locale, | ||
array $data = [] | ||
) { | ||
$this->action = $action; | ||
$this->type = $type; | ||
$this->originalResourceId = $originalResourceId; | ||
$this->translationResourceId = $translationResourceId; | ||
$this->locale = $locale; | ||
$this->data = $data; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return __CLASS__; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'action' => $this->action, | ||
'type' => $this->type, | ||
'originalResourceId' => $this->originalResourceId, | ||
'translationResourceId' => $this->translationResourceId, | ||
'locale' => $this->locale, | ||
'data' => $this->data, | ||
]; | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
test/unit/models/classes/Translation/Event/TranslationActionEventTest.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,56 @@ | ||
<?php | ||
|
||
/** | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; under version 2 | ||
* of the License (non-upgradable). | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* Copyright (c) 2025 (original work) Open Assessment Technologies SA. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\tao\test\unit\models\classes\Translation\Event; | ||
|
||
use JsonSerializable; | ||
use oat\oatbox\event\Event; | ||
use oat\tao\model\Translation\Event\TranslationActionEvent; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TranslationActionEventTest extends TestCase | ||
{ | ||
public function testEvent(): void | ||
{ | ||
$sut = new TranslationActionEvent( | ||
'someAction', | ||
'item', | ||
'originalResourceId', | ||
'translationResourceId', | ||
'locale' | ||
); | ||
|
||
$this->assertInstanceOf(Event::class, $sut); | ||
$this->assertInstanceOf(JsonSerializable::class, $sut); | ||
$this->assertEquals( | ||
[ | ||
'action' => 'someAction', | ||
'type' => 'item', | ||
'originalResourceId' => 'originalResourceId', | ||
'translationResourceId' => 'translationResourceId', | ||
'locale' => 'locale', | ||
'data' => [] | ||
], | ||
$sut->jsonSerialize() | ||
); | ||
} | ||
} |
Oops, something went wrong.