mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
prepare for private demos
This commit is contained in:
parent
1fef02679a
commit
4f07dbbf34
13 changed files with 131 additions and 25 deletions
|
|
@ -51,7 +51,8 @@ class DemoListProviderTest extends TestCase {
|
|||
$uploaderId,
|
||||
'hash',
|
||||
'backend',
|
||||
'path'
|
||||
'path',
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ class DemoProviderTest extends TestCase {
|
|||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
'path',
|
||||
null,
|
||||
);
|
||||
$demo->setUploaderUser($uploader);
|
||||
|
||||
|
|
@ -114,8 +115,7 @@ class DemoProviderTest extends TestCase {
|
|||
'hash',
|
||||
'backend',
|
||||
'path',
|
||||
'dummy',
|
||||
'path'
|
||||
null,
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
|
@ -179,7 +179,8 @@ class DemoProviderTest extends TestCase {
|
|||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
'path',
|
||||
null,
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
|
@ -195,4 +196,61 @@ class DemoProviderTest extends TestCase {
|
|||
$storedDemo2 = $this->provider->get($id2);
|
||||
$this->assertEquals('http://example.com', $storedDemo2->getUrl());
|
||||
}
|
||||
|
||||
public function privateDateProvider() {
|
||||
return [
|
||||
['2 days', false],
|
||||
['-2 days', true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider privateDateProvider
|
||||
*/
|
||||
public function testPrivateDemo(string $until, bool $visible) {
|
||||
$now = new \DateTimeImmutable();
|
||||
$until = \DateInterval::createFromDateString($until);
|
||||
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId, 'test');
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path',
|
||||
$now->add($until),
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
||||
$this->provider->setDemoUrl($id, 'foobackend', 'http://foo.example.com', 'bar');
|
||||
|
||||
$storedDemo = $this->provider->get($id);
|
||||
$json = $storedDemo->jsonSerialize();
|
||||
if ($visible) {
|
||||
$this->assertEquals('http://foo.example.com', $json['url']);
|
||||
} else {
|
||||
$this->assertEquals('', $json['url']);
|
||||
}
|
||||
|
||||
$storedDemo->showPrivateData(true);
|
||||
$json = $storedDemo->jsonSerialize();
|
||||
$this->assertEquals('http://foo.example.com', $json['url']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ class UploadProviderTest extends TestCase {
|
|||
|
||||
public function testUploadInvalidKey() {
|
||||
$this->expectException(InvalidKeyException::class);
|
||||
$this->uploadProvider->upload('dummy', 'RED', 'BLU', 'dummy', 'dummy');
|
||||
$this->uploadProvider->upload('dummy', 'RED', 'BLU', 'dummy', 'dummy', false);
|
||||
}
|
||||
|
||||
public function testUploadNonDemo() {
|
||||
|
|
@ -226,7 +226,7 @@ class UploadProviderTest extends TestCase {
|
|||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId, 'a');
|
||||
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'dummy', $this->tmpDir . '/foo.dem');
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'dummy', $this->tmpDir . '/foo.dem', false);
|
||||
}
|
||||
|
||||
public function testUploadExisting() {
|
||||
|
|
@ -253,7 +253,8 @@ class UploadProviderTest extends TestCase {
|
|||
1,
|
||||
$hash,
|
||||
'b',
|
||||
'p'
|
||||
'p',
|
||||
null,
|
||||
),
|
||||
'test',
|
||||
'test'
|
||||
|
|
@ -264,7 +265,7 @@ class UploadProviderTest extends TestCase {
|
|||
|
||||
$this->assertEquals(
|
||||
'STV available at: http://example.com/' . $id,
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'dummy', $this->tmpDir . '/foo.dem')
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'dummy', $this->tmpDir . '/foo.dem', false)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -298,14 +299,15 @@ class UploadProviderTest extends TestCase {
|
|||
|
||||
public function uploadProvider(): array {
|
||||
return [
|
||||
[__DIR__ . '/../data/product.dem', __DIR__ . '/../data/product-raw.json', 'koth_product_rc8', 0, 3],
|
||||
[__DIR__ . '/../data/product.dem', __DIR__ . '/../data/product-raw.json', 'koth_product_rc8', 0, 3, false],
|
||||
[__DIR__ . '/../data/product.dem', __DIR__ . '/../data/product-raw.json', 'koth_product_rc8', 0, 3, true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider uploadProvider
|
||||
*/
|
||||
public function testUpload(string $demo, string $parsed, string $map, int $blue, int $red) {
|
||||
public function testUpload(string $demo, string $parsed, string $map, int $blue, int $red, bool $private) {
|
||||
copy($demo, $this->tmpDir . '/foo.dem');
|
||||
copy($parsed, $this->tmpDir . '/foo-raw.json');
|
||||
|
||||
|
|
@ -314,7 +316,7 @@ class UploadProviderTest extends TestCase {
|
|||
|
||||
$this->preloadNames();
|
||||
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem', $private);
|
||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
||||
|
||||
$demoId = (int) substr($result, \strlen('STV available at: http://example.com/'));
|
||||
|
|
@ -326,5 +328,16 @@ class UploadProviderTest extends TestCase {
|
|||
$this->assertEquals($map, $demo->getMap());
|
||||
$this->assertEquals($blue, $demo->getBlueScore());
|
||||
$this->assertEquals($red, $demo->getRedScore());
|
||||
|
||||
$json = $demo->jsonSerialize();
|
||||
if ($private) {
|
||||
$this->assertEquals('', $json['url']);
|
||||
$this->assertEquals('', $json['backend']);
|
||||
$this->assertEquals('', $json['path']);
|
||||
} else {
|
||||
$this->assertEquals($demo->getUrl(), $json['url']);
|
||||
$this->assertEquals($demo->getBackend(), $json['backend']);
|
||||
$this->assertEquals($demo->getPath(), $json['path']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue