Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function format($subject, array $change_set): ?string
}

try {
$attendeeEmail = $subject->getAttendee()?->getEmail() ?? 'Unknown';
$attendeeId = $subject->getAttendee()?->getId() ?? 'unknown';
$attendeeEmail = $subject->getInvitee()?->getEmail() ?? 'Unknown';
$attendeeId = $subject->getInvitee()?->getId() ?? 'unknown';
$eventTitle = $subject->getEvent()?->getTitle() ?? 'Unknown Event';
$eventId = $subject->getEvent()?->getId() ?? 'unknown';
$id = $subject->getId() ?? 'unknown';
Expand Down
32 changes: 32 additions & 0 deletions config/audit_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,5 +256,37 @@
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\ExtraQuestionTypeValueAuditLogFormatter::class,
],
\models\main\Company::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\CompanyAuditLogFormatter::class,
],
\models\summit\PresentationCategory::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationCategoryAuditLogFormatter::class,
],
\models\summit\PresentationCategoryGroup::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationCategoryGroupAuditLogFormatter::class,
],
\models\summit\PresentationType::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationTypeAuditLogFormatter::class,
],
\models\summit\RSVP::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPInvitation::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPInvitationAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPTemplateAuditLogFormatter::class,
],
]
];
97 changes: 97 additions & 0 deletions tests/OpenTelemetry/Formatters/CompanyAuditLogFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

namespace Tests\OpenTelemetry\Formatters;

/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Audit\ConcreteFormatters\CompanyAuditLogFormatter;
use App\Audit\Interfaces\IAuditStrategy;
use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder;
use Mockery;
use Tests\TestCase;

class CompanyAuditLogFormatterTest extends TestCase
{
private mixed $mockSubject;

protected function setUp(): void
{
parent::setUp();
$this->mockSubject = $this->createMockSubject();
}

protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}

private function createMockSubject(): mixed
{
$mock = Mockery::mock('models\main\Company');

// Configure return values
$mock->shouldReceive('getId')->andReturn(1);
$mock->shouldReceive('getName')->andReturn('TechCorp Inc');
$mock->shouldReceive('getCity')->andReturn('San Francisco');
$mock->shouldReceive('getCountry')->andReturn('USA');
$mock->shouldReceive('isDisplayOnSite')->andReturn(true);

return $mock;
}

public function testSubjectCreationAuditMessage(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('created', $result);
$this->assertStringContainsString('TechCorp Inc', $result);
$this->assertStringContainsString('San Francisco', $result);
}

public function testSubjectUpdateAuditMessage(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE);
$formatter->setContext(AuditContextBuilder::default()->build());
$changeSet = [
'city' => ['San Francisco', 'Los Angeles'],
'country' => ['USA', 'USA']
];

$result = $formatter->format($this->mockSubject, $changeSet);

$this->assertNotNull($result);
$this->assertStringContainsString('updated', $result);
}

public function testSubjectDeletionAuditMessage(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('deleted', $result);
}

public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Tests\OpenTelemetry\Formatters;

/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Audit\ConcreteFormatters\PresentationCategoryAuditLogFormatter;
use App\Audit\Interfaces\IAuditStrategy;
use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder;
use Mockery;
use Tests\TestCase;

class PresentationCategoryAuditLogFormatterTest extends TestCase
{
private mixed $mockSubject;
private mixed $mockSummit;

protected function setUp(): void
{
parent::setUp();
$this->mockSummit = $this->createMockSummit();
$this->mockSubject = $this->createMockSubject();
}

protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}

private function createMockSummit(): mixed
{
$mock = Mockery::mock('models\summit\Summit');
$mock->shouldReceive('getName')->andReturn('OpenStack Summit 2024');
return $mock;
}

private function createMockSubject(): mixed
{
$mock = Mockery::mock('models\summit\PresentationCategory');

// Configure return values
$mock->shouldReceive('getId')->andReturn(10);
$mock->shouldReceive('getTitle')->andReturn('Cloud Architecture');
$mock->shouldReceive('getCode')->andReturn('CLOUD-ARCH');
$mock->shouldReceive('getSummit')->andReturn($this->mockSummit);

return $mock;
}

public function testSubjectCreationAuditMessage(): void
{
$formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('created', $result);
$this->assertStringContainsString('Cloud Architecture', $result);
$this->assertStringContainsString('CLOUD-ARCH', $result);
}

public function testSubjectUpdateAuditMessage(): void
{
$formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE);
$formatter->setContext(AuditContextBuilder::default()->build());
$changeSet = [
'title' => ['Cloud Architecture', 'Infrastructure & Architecture']
];

$result = $formatter->format($this->mockSubject, $changeSet);

$this->assertNotNull($result);
$this->assertStringContainsString('updated', $result);
}

public function testSubjectDeletionAuditMessage(): void
{
$formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('deleted', $result);
}

public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace Tests\OpenTelemetry\Formatters;

/**
* Copyright 2026 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use App\Audit\ConcreteFormatters\PresentationCategoryGroupAuditLogFormatter;
use App\Audit\Interfaces\IAuditStrategy;
use Tests\OpenTelemetry\Formatters\Support\AuditContextBuilder;
use Mockery;
use Tests\TestCase;

class PresentationCategoryGroupAuditLogFormatterTest extends TestCase
{
private mixed $mockSubject;

protected function setUp(): void
{
parent::setUp();
$this->mockSubject = $this->createMockSubject();
}

protected function tearDown(): void
{
Mockery::close();
parent::tearDown();
}

private function createMockSubject(): mixed
{
$mockSummit = Mockery::mock('models\summit\Summit');
$mockSummit->shouldReceive('getName')->andReturn('OpenStack Summit');

$mock = Mockery::mock('models\summit\PresentationCategoryGroup');

// Configure return values
$mock->shouldReceive('getId')->andReturn(5);
$mock->shouldReceive('getName')->andReturn('Technical Tracks');
$mock->shouldReceive('getDescription')->andReturn('Group for technical presentations');
$mock->shouldReceive('getSummit')->andReturn($mockSummit);
$mock->shouldReceive('getColor')->andReturn('#FF5733');
$mock->shouldReceive('getMaxAttendeeVotes')->andReturn(3);

return $mock;
}

public function testSubjectCreationAuditMessage(): void
{
$formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('created', $result);
$this->assertStringContainsString('Technical Tracks', $result);
}

public function testSubjectUpdateAuditMessage(): void
{
$formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE);
$formatter->setContext(AuditContextBuilder::default()->build());
$changeSet = [
'name' => ['Technical Tracks', 'Core Technical Topics']
];

$result = $formatter->format($this->mockSubject, $changeSet);

$this->assertNotNull($result);
$this->assertStringContainsString('updated', $result);
}

public function testSubjectDeletionAuditMessage(): void
{
$formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_DELETION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('deleted', $result);
}

public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new PresentationCategoryGroupAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
}
}
Loading