-
- 0) : ?>
- t('Total users:')); ?>
-
+
+ 0) : ?>
+
+ t('Last hour')); ?>
+
+ t('%s%% of all users', [round($_['activeUsers']['last1hour'] * 100 / $_['storage']['num_users'], 1)])) ?>
+
0) : ?>
- t('24 hours:')); ?>
-
+
+ t('Last 24 Hours')); ?>
+
+ t('%s%% of all users', [round($_['activeUsers']['last24hours'] * 100 / $_['storage']['num_users'], 1)])) ?>
+
- 0) : ?>
- t('1 hour:')); ?>
-
+ 0) : ?>
+
+ t('Last 7 Days')); ?>
+
+ t('%s%% of all users', [round($_['activeUsers']['last7days'] * 100 / $_['storage']['num_users'], 1)])) ?>
+
- 0) : ?>
- t('5 mins:')); ?>
-
+ 0) : ?>
+
+ t('Last 30 Days')); ?>
+
+ t('%s%% of all users', [round($_['activeUsers']['last1month'] * 100 / $_['storage']['num_users'], 1)])) ?>
+
diff --git a/tests/lib/SessionStatisticsTest.php b/tests/lib/SessionStatisticsTest.php
index 0eb2d958..57744194 100644
--- a/tests/lib/SessionStatisticsTest.php
+++ b/tests/lib/SessionStatisticsTest.php
@@ -13,6 +13,8 @@
use OCA\ServerInfo\SessionStatistics;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\IDBConnection;
+use OCP\Server;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -22,72 +24,77 @@
* @package OCA\ServerInfo\Tests
*/
class SessionStatisticsTest extends TestCase {
- /** @var ITimeFactory | \PHPUnit_Framework_MockObject_MockObject */
- private $timeFactory;
+ private ITimeFactory&MockObject $timeFactory;
+ private IDBConnection $connection;
+ private SessionStatistics $instance;
+ private const TABLE = 'authtoken';
+ private const OFFSET_5MIN = 300;
+ private const OFFSET_1HOUR = 3600;
+ private const OFFSET_1DAY = 86400;
+ private const OFFSET_7DAYS = 604800;
+ private const OFFSET_1MONTH = 2592000;
+ private const OFFSET_3MONTHS = 7776000;
+ private const OFFSET_6MONTHS = 15552000;
+ private const OFFSET_1YEAR = 31536000;
+ private const CURRENT_TIME = 100000000;
- /** @var IDBConnection */
- private $connection;
-
- /** @var SessionStatistics */
- private $instance;
-
- private $table = 'authtoken';
-
- private $offset5Minutes = 300;
-
- private $offset1Hour = 3600;
-
- private $offset1Day = 86400;
-
- private $currentTime = 100000;
protected function setUp(): void {
parent::setUp();
- $this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory')
- ->disableOriginalConstructor()->getMock();
+ $this->timeFactory = $this->createMock(ITimeFactory::class);
- $this->connection = \OC::$server->getDatabaseConnection();
+ $this->connection = Server::get(IDBConnection::class);
$this->instance = new SessionStatistics($this->connection, $this->timeFactory);
}
- private function addDummyValues() {
- $this->addDummyValuesWithLastLogin($this->currentTime - $this->offset5Minutes + 1, 10);
- $this->addDummyValuesWithLastLogin($this->currentTime - $this->offset1Hour + 1, 20);
- $this->addDummyValuesWithLastLogin($this->currentTime - $this->offset1Day + 1, 30);
+ private function addDummyValues(): void {
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_5MIN + 1, 10);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_1HOUR + 1, 20);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_1DAY + 1, 30);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_7DAYS + 1, 40);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_1MONTH + 1, 50);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_3MONTHS + 1, 60);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_6MONTHS + 1, 70);
+ $this->addDummyValuesWithLastLogin(self::CURRENT_TIME - self::OFFSET_1YEAR + 1, 80);
}
- private function addDummyValuesWithLastLogin($lastActivity, $numOfEntries) {
+ private function addDummyValuesWithLastLogin($lastActivity, $numOfEntries): void {
for ($i = 0; $i < $numOfEntries; $i++) {
$query = $this->connection->getQueryBuilder();
- $query->insert($this->table)
+ $query->insert(self::TABLE)
->values(
[
'uid' => $query->createNamedParameter('user-' . ($numOfEntries + $i % 2)),
'login_name' => $query->createNamedParameter('user-' . ($numOfEntries + $i % 2)),
'password' => $query->createNamedParameter('password'),
'name' => $query->createNamedParameter('user agent'),
- 'token' => $query->createNamedParameter('token-' . ($i + $numOfEntries * 10)),
+ 'token' => $query->createNamedParameter('token-' . $this->getUniqueID()),
'type' => $query->createNamedParameter(0),
'last_activity' => $query->createNamedParameter($lastActivity),
'last_check' => $query->createNamedParameter($lastActivity),
]
);
- $query->execute();
+ $query->executeStatement();
}
}
public function testGetSessionStatistics() {
$this->addDummyValues();
$this->timeFactory->expects($this->any())->method('getTime')
- ->willReturn($this->currentTime);
+ ->willReturn(self::CURRENT_TIME);
$result = $this->instance->getSessionStatistics();
- $this->assertSame(3, count($result));
+ $this->assertSame(8, count($result));
$this->assertSame(2, $result['last5minutes']);
$this->assertSame(4, $result['last1hour']);
$this->assertSame(6, $result['last24hours']);
+ $this->assertSame(8, $result['last7days']);
+ $this->assertSame(10, $result['last1month']);
+ $this->assertSame(12, $result['last3months']);
+ $this->assertSame(14, $result['last6months']);
+ $this->assertSame(16, $result['lastyear']);
}
}