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
64 changes: 64 additions & 0 deletions config/audit_log.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationCategoryGroupAuditLogFormatter::class,
],
\models\summit\PrivatePresentationCategoryGroup::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationCategoryGroupAuditLogFormatter::class,
],
\models\summit\PresentationAttendeeVote::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\PresentationAttendeeVoteAuditLogFormatter::class,
Expand Down Expand Up @@ -316,6 +320,66 @@
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\SponsorAuditLogFormatter::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\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\RSVPMemberEmailQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPMemberFirstNameQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPMemberLastNameQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPTextBoxQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPTextAreaQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPCheckBoxListQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPRadioButtonListQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPDropDownQuestionTemplate::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\RSVPQuestionTemplateAuditLogFormatter::class,
],
\App\Models\Foundation\Summit\Events\RSVP\RSVPLiteralContentQuestionTemplate::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,
],
\models\summit\SummitEventType::class => [
'enabled' => true,
'strategy' => \App\Audit\ConcreteFormatters\SummitEventTypeAuditLogFormatter::class,
Expand Down
107 changes: 107 additions & 0 deletions tests/OpenTelemetry/Formatters/CompanyAuditLogFormatterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?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 testFormatterHandlesEmptyChangeSet(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

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

public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
Comment on lines +101 to +105
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Set formatter context in invalid-subject test to isolate the assertion.

This test currently verifies null without the same context setup used elsewhere, so a future context-related failure could mask the real intent (invalid subject handling).

Proposed patch
 public function testFormatterReturnsNullForInvalidSubject(): void
 {
     $formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
+    $formatter->setContext(AuditContextBuilder::default()->build());
     $result = $formatter->format(new \stdClass(), []);
     $this->assertNull($result);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
public function testFormatterReturnsNullForInvalidSubject(): void
{
$formatter = new CompanyAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_CREATION);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format(new \stdClass(), []);
$this->assertNull($result);
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/OpenTelemetry/Formatters/CompanyAuditLogFormatterTest.php` around lines
91 - 95, The test testFormatterReturnsNullForInvalidSubject should set the
formatter's context before calling format so the assertion isolates
invalid-subject behavior; update the test to configure the
CompanyAuditLogFormatter instance (constructed with
IAuditStrategy::EVENT_ENTITY_CREATION) with the same context used in other tests
(e.g. call the formatter's context-setting method used elsewhere in the suite)
and then call $formatter->format(new \stdClass(), []) and assertNull the result.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?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 testFormatterHandlesEmptyChangeSet(): void
{
$formatter = new PresentationCategoryAuditLogFormatter(IAuditStrategy::EVENT_ENTITY_UPDATE);
$formatter->setContext(AuditContextBuilder::default()->build());
$result = $formatter->format($this->mockSubject, []);

$this->assertNotNull($result);
$this->assertStringContainsString('updated', $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
Expand Up @@ -46,13 +46,16 @@ class PresentationCategoryGroupAuditLogFormatterManyToManyTest extends TestCase
private const LOG_REMOVED_IDS_PAYLOAD = 'Removed IDs: [10,11,12]';
private const LOG_REMOVED_IDS_DIFF = 'Removed IDs: [1]';
private const LOG_ADDED_IDS_DIFF = 'Added IDs: [3]';
private const LOG_NO_CHANGES = 'Added IDs: [], Removed IDs: []';
private const DELETED_IDS_PAYLOAD = [10, 11, 12];
private const SNAPSHOT_IDS_EMPTY = [];
private const CURRENT_IDS_EMPTY = [];
private const SNAPSHOT_IDS_REMOVE_ONE = [1, 2, 3];
private const CURRENT_IDS_REMOVE_ONE = [2, 3];
private const SNAPSHOT_IDS_UPDATE = [1, 2];
private const CURRENT_IDS_UPDATE = [2, 3];
private const SNAPSHOT_IDS_NO_CHANGES = [1, 2];
private const CURRENT_IDS_NO_CHANGES = [1, 2];

protected function tearDown(): void
{
Expand Down Expand Up @@ -144,6 +147,21 @@ public function testManyToManyUpdateUsesAddedAndRemovedIdsFromCollectionDiff():
$this->assertStringContainsString(self::LOG_REMOVED_IDS_DIFF, $result);
}

public function testManyToManyUpdateReturnsNoChangesWhenDiffEmpty(): void
{
$group = $this->makeGroup();
$formatter = $this->makeFormatter(IAuditStrategy::EVENT_COLLECTION_MANYTOMANY_UPDATE);
$collection = $this->makeCollection(self::SNAPSHOT_IDS_NO_CHANGES, self::CURRENT_IDS_NO_CHANGES);

$result = $formatter->format($group, [
'collection' => $collection,
]);

$this->assertNotNull($result);
$this->assertStringContainsString(self::LOG_UPDATED_M2M, $result);
$this->assertStringContainsString(self::LOG_NO_CHANGES, $result);
}

public static function providesNullCasesForManyToMany(): array
{
return [
Expand Down
Loading
Loading