Add ProjectZomboidAdminLog (admin.txt)
Free-form English message body with verb-dispatched analyser regexes (ADDED_ITEM, ADDED_XP, GRANTED_ACCESS, CHANGED_OPTION, RELOADED_OPTIONS, TELEPORTED). Parser captures only the timestamp, since the admin name itself can include parentheses or whitespace. Detectors: filename match plus content signatures on 'added item Base.X in Y's inventory' and 'granted ROLE access level on'.
This commit is contained in:
12
test/src/Games/ProjectZomboid/fixtures/admin-minimal.txt
Normal file
12
test/src/Games/ProjectZomboid/fixtures/admin-minimal.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
[16-04-26 18:33:34.289] AdminUser added item Base.ShotgunShells in Player1's inventory.
|
||||
[16-04-26 18:33:34.290] AdminUser added item Base.ShotgunShells in Player1's inventory.
|
||||
[16-04-26 18:33:34.291] AdminUser added item Base.Bandage in Player2's inventory.
|
||||
[16-04-26 18:34:00.500] AdminUser added 750.0 Blunt xp's to Player1.
|
||||
[16-04-26 18:34:01.225] AdminUser added 525.0 Aiming xp's to Player2.
|
||||
[16-04-26 18:35:10.000] AdminUser granted admin access level on Player1.
|
||||
[16-04-26 18:35:30.115] AdminUser granted user access level on Player2.
|
||||
[16-04-26 18:36:15.500] AdminUser changed option AnnounceDeath=true.
|
||||
[16-04-26 18:36:30.812] AdminUser changed option PVP=false.
|
||||
[16-04-26 18:37:00.014] AdminUser reloaded options.
|
||||
[16-04-26 18:38:00.225] AdminUser teleported Player1 to 1100,2200,0.
|
||||
[16-04-26 18:39:15.500] AdminUser teleported Player2 to 1100,2200,-1.
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Log;
|
||||
|
||||
use IndifferentKetchup\Codex\Detective\Detective;
|
||||
use IndifferentKetchup\Codex\Log\File\PathLogFile;
|
||||
use IndifferentKetchup\Codex\Log\ProjectZomboid\ProjectZomboidAdminLog;
|
||||
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ProjectZomboidAdminLogTest extends TestCase
|
||||
{
|
||||
private function fixturePath(): string
|
||||
{
|
||||
return __DIR__ . '/../../../../src/Games/ProjectZomboid/fixtures/admin-minimal.txt';
|
||||
}
|
||||
|
||||
public function testParsesEachLineAsAnEntry(): void
|
||||
{
|
||||
$log = (new ProjectZomboidAdminLog())->setLogFile(new PathLogFile($this->fixturePath()));
|
||||
$log->parse();
|
||||
|
||||
$this->assertCount(12, $log->getEntries());
|
||||
}
|
||||
|
||||
public function testAddedItemRegexExtracts(): void
|
||||
{
|
||||
$msg = "AdminUser added item Base.ShotgunShells in Player1's inventory";
|
||||
$this->assertSame(1, preg_match(AdminPattern::ADDED_ITEM, $msg, $m));
|
||||
$this->assertSame('AdminUser', $m['admin']);
|
||||
$this->assertSame('Base.ShotgunShells', $m['item']);
|
||||
$this->assertSame('Player1', $m['target']);
|
||||
}
|
||||
|
||||
public function testAddedXpRegexExtracts(): void
|
||||
{
|
||||
$msg = "AdminUser added 750.0 Blunt xp's to Player1";
|
||||
$this->assertSame(1, preg_match(AdminPattern::ADDED_XP, $msg, $m));
|
||||
$this->assertSame('750.0', $m['amount']);
|
||||
$this->assertSame('Blunt', $m['skill']);
|
||||
$this->assertSame('Player1', $m['target']);
|
||||
}
|
||||
|
||||
public function testGrantedAccessRegexExtracts(): void
|
||||
{
|
||||
$msg = "AdminUser granted admin access level on Player1";
|
||||
$this->assertSame(1, preg_match(AdminPattern::GRANTED_ACCESS, $msg, $m));
|
||||
$this->assertSame('admin', $m['level']);
|
||||
$this->assertSame('Player1', $m['target']);
|
||||
}
|
||||
|
||||
public function testChangedOptionRegexExtracts(): void
|
||||
{
|
||||
$msg = "AdminUser changed option PVP=false";
|
||||
$this->assertSame(1, preg_match(AdminPattern::CHANGED_OPTION, $msg, $m));
|
||||
$this->assertSame('PVP', $m['option']);
|
||||
$this->assertSame('false', $m['value']);
|
||||
}
|
||||
|
||||
public function testReloadedOptionsRegexExtracts(): void
|
||||
{
|
||||
$msg = "AdminUser reloaded options";
|
||||
$this->assertSame(1, preg_match(AdminPattern::RELOADED_OPTIONS, $msg, $m));
|
||||
$this->assertSame('AdminUser', $m['admin']);
|
||||
}
|
||||
|
||||
public function testTeleportedRegexHandlesNegativeZ(): void
|
||||
{
|
||||
$msg = "AdminUser teleported Player2 to 1100,2200,-1";
|
||||
$this->assertSame(1, preg_match(AdminPattern::TELEPORTED, $msg, $m));
|
||||
$this->assertSame('Player2', $m['target']);
|
||||
$this->assertSame('-1', $m['z']);
|
||||
}
|
||||
|
||||
public function testDetectiveDispatchesByContent(): void
|
||||
{
|
||||
$detective = (new Detective())
|
||||
->setLogFile(new PathLogFile($this->fixturePath()))
|
||||
->addPossibleLogClass(ProjectZomboidAdminLog::class);
|
||||
|
||||
$this->assertInstanceOf(ProjectZomboidAdminLog::class, $detective->detect());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user