Add AdminGrantedAccessInformation insight
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analysis\Information;
|
||||||
|
use IndifferentKetchup\Codex\Analysis\PatternInsightInterface;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||||
|
|
||||||
|
class AdminGrantedAccessInformation extends Information implements PatternInsightInterface
|
||||||
|
{
|
||||||
|
public static function getPatterns(): array
|
||||||
|
{
|
||||||
|
return [AdminPattern::GRANTED_ACCESS_ENTRY];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMatches(array $matches, mixed $patternKey): void
|
||||||
|
{
|
||||||
|
$this->setLabel('Admin granted access');
|
||||||
|
$this->setValue(sprintf(
|
||||||
|
'%s granted %s to %s',
|
||||||
|
$matches['admin'],
|
||||||
|
$matches['level'],
|
||||||
|
$matches['target']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,4 +36,6 @@ class AdminPattern
|
|||||||
public const string ADDED_ITEM_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added item (?<item>Base\.\S+) in (?<target>.+?)\'s inventory\.?$/';
|
public const string ADDED_ITEM_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added item (?<item>Base\.\S+) in (?<target>.+?)\'s inventory\.?$/';
|
||||||
|
|
||||||
public const string ADDED_XP_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added (?<amount>[\d.]+) (?<skill>\S+) xp\'s to (?<target>.+?)\.?$/';
|
public const string ADDED_XP_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) added (?<amount>[\d.]+) (?<skill>\S+) xp\'s to (?<target>.+?)\.?$/';
|
||||||
|
|
||||||
|
public const string GRANTED_ACCESS_ENTRY = '/^\[\d{2}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}\] (?<admin>.+?) granted (?<level>\w+) access level on (?<target>.+?)\.?$/';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IndifferentKetchup\Codex\Test\Tests\Games\ProjectZomboid\Analysis;
|
||||||
|
|
||||||
|
use IndifferentKetchup\Codex\Analysis\ProjectZomboid\AdminGrantedAccessInformation;
|
||||||
|
use IndifferentKetchup\Codex\Pattern\ProjectZomboid\AdminPattern;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AdminGrantedAccessInformationTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testGetPatternsReturnsEntryRegex(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([AdminPattern::GRANTED_ACCESS_ENTRY], AdminGrantedAccessInformation::getPatterns());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEntryRegexMatchesFullLine(): void
|
||||||
|
{
|
||||||
|
$line = "[16-04-26 18:35:10.000] AdminUser granted admin access level on Player1.";
|
||||||
|
$this->assertSame(1, preg_match(AdminPattern::GRANTED_ACCESS_ENTRY, $line, $m));
|
||||||
|
|
||||||
|
$insight = new AdminGrantedAccessInformation();
|
||||||
|
$insight->setMatches($m, 0);
|
||||||
|
|
||||||
|
$this->assertSame('Admin granted access', $insight->getLabel());
|
||||||
|
$this->assertSame('AdminUser granted admin to Player1', $insight->getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user