Skip to content

Unit tests - audit log #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: feature/doctrine-mapping-upgrade
Choose a base branch
from
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
62 changes: 62 additions & 0 deletions tests/Unit/SummitAttendeeBadgeAuditLogTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php namespace Tests\Unit;

/**
* Copyright 2025 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 models\main\SummitAttendeeBadgeAuditLog;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Tests\BrowserKitTestCase;
use models\main\Member;
use models\summit\Summit;
use models\summit\SummitAttendeeBadge;

/**
* Class SummitAttendeeBadgeAuditLogTest
* @package Tests\unit
*/
class SummitAttendeeBadgeAuditLogTest extends BrowserKitTestCase
{
public function test()
{
$member_repo = EntityManager::getRepository(Member::class);
$member = $member_repo->find(3);

$summit_repo = EntityManager::getRepository(Summit::class);
$summit = $summit_repo->find(56);

$badge_repo = EntityManager::getRepository(SummitAttendeeBadge::class);
$badge = $badge_repo
->createQueryBuilder('b')
->join('b.ticket', 't')
->join('t.owner', 'm')
->where('m.id = :memberId')
->setParameter('memberId', $member->getId())
->getQuery()
->getOneOrNullResult();

$log = new SummitAttendeeBadgeAuditLog($member, "UNIT_TEST", $summit, $badge);

EntityManager::persist($log);
EntityManager::flush();
EntityManager::clear();

$repo = EntityManager::getRepository(SummitAttendeeBadgeAuditLog::class);
$found_log = $repo->find($log->getId());

$this->assertInstanceOf(SummitAttendeeBadgeAuditLog::class, $found_log);
$this->assertEquals($member->getEmail(), $found_log->getUser()->getEmail());
$this->assertEquals($summit->getName(), $found_log->getSummit()->getName());
$this->assertEquals("UNIT_TEST", $found_log->getAction());
$this->assertEquals($badge->getId(), $found_log->getAttendeeBadge()->getId());
}
}
50 changes: 50 additions & 0 deletions tests/Unit/SummitAuditLogTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php namespace Tests\unit;

/**
* Copyright 2025 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 models\main\SummitAuditLog;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Tests\BrowserKitTestCase;
use models\main\Member;
use models\summit\Summit;

/**
* Class SummitAuditLogTest
* @package Tests\unit
*/
class SummitAuditLogTest extends BrowserKitTestCase
{
public function test()
{
$member_repo = EntityManager::getRepository(Member::class);
$member = $member_repo->find(3);

$summit_repo = EntityManager::getRepository(Summit::class);
$summit = $summit_repo->find(56);

$log = new SummitAuditLog($member, "UNIT_TEST", $summit);

EntityManager::persist($log);
EntityManager::flush();
EntityManager::clear();

$repo = EntityManager::getRepository(SummitAuditLog::class);
$found_log = $repo->find($log->getId());

$this->assertInstanceOf(SummitAuditLog::class, $found_log);
$this->assertEquals($member->getEmail(), $found_log->getUser()->getEmail());
$this->assertEquals($summit->getName(), $found_log->getSummit()->getName());
$this->assertEquals("UNIT_TEST", $found_log->getAction());
}
}
55 changes: 55 additions & 0 deletions tests/Unit/SummitEventAuditLogTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php namespace Tests\Unit;

/**
* Copyright 2025 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 LaravelDoctrine\ORM\Facades\EntityManager;
use models\main\SummitEventAuditLog;
use Tests\BrowserKitTestCase;
use models\main\Member;
use models\summit\Summit;
use models\summit\SummitEvent;

/**
* Class SummitEventAuditLogTest
* @package Tests\unit
*/
class SummitEventAuditLogTest extends BrowserKitTestCase
{
public function test()
{
$member_repo = EntityManager::getRepository(Member::class);
$member = $member_repo->find(3);

$summit_repo = EntityManager::getRepository(Summit::class);
$summit = $summit_repo->find(56);

$event_repo = EntityManager::getRepository(SummitEvent::class);
$event = $event_repo->findOneBy(["summitId" => 56]);

$log = new SummitEventAuditLog($member, "UNIT_TEST", $summit, $event);

EntityManager::persist($log);
EntityManager::flush();
EntityManager::clear();

$repo = EntityManager::getRepository(SummitEventAuditLog::class);
$found_log = $repo->find($log->getId());

$this->assertInstanceOf(SummitEventAuditLog::class, $found_log);
$this->assertEquals($member->getEmail(), $found_log->getUser()->getEmail());
$this->assertEquals($summit->getName(), $found_log->getSummit()->getName());
$this->assertEquals("UNIT_TEST", $found_log->getAction());
$this->assertEquals($event->getId(), $found_log->getEvent()->getId());
}
}