mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
Add php-cs-fixer
This commit is contained in:
parent
e00e6ece5f
commit
309ae17036
54 changed files with 4900 additions and 4106 deletions
|
|
@ -7,33 +7,33 @@ use Demostf\API\Providers\ChatProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class ChatProviderTest extends TestCase {
|
||||
/** @var ChatProvider */
|
||||
private $provider;
|
||||
/** @var ChatProvider */
|
||||
private $provider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->provider = new ChatProvider($this->getDatabaseConnection());
|
||||
}
|
||||
$this->provider = new ChatProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
||||
public function testGetEmptyChat() {
|
||||
$this->assertCount(0, $this->provider->getChat(1));
|
||||
}
|
||||
public function testGetEmptyChat() {
|
||||
$this->assertCount(0, $this->provider->getChat(1));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$message1 = new ChatMessage('foo', 2, 'bar');
|
||||
$message2 = new ChatMessage('foo2', 2, 'bar2');
|
||||
$message3 = new ChatMessage('foo2', 2, 'bar2');
|
||||
public function testStoreRetrieve() {
|
||||
$message1 = new ChatMessage('foo', 2, 'bar');
|
||||
$message2 = new ChatMessage('foo2', 2, 'bar2');
|
||||
$message3 = new ChatMessage('foo2', 2, 'bar2');
|
||||
|
||||
$this->provider->storeChatMessage(1, $message1);
|
||||
$this->provider->storeChatMessage(1, $message2);
|
||||
$this->provider->storeChatMessage(2, $message3);
|
||||
$this->provider->storeChatMessage(1, $message1);
|
||||
$this->provider->storeChatMessage(1, $message2);
|
||||
$this->provider->storeChatMessage(2, $message3);
|
||||
|
||||
$result = $this->provider->getChat(1);
|
||||
sort($result);
|
||||
$result = $this->provider->getChat(1);
|
||||
sort($result);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($message1, $result[0]);
|
||||
$this->assertEquals($message2, $result[1]);
|
||||
}
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertEquals($message1, $result[0]);
|
||||
$this->assertEquals($message2, $result[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,153 +11,153 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoListProviderTest extends TestCase {
|
||||
/** @var DemoListProvider */
|
||||
private $demoListProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoListProvider */
|
||||
private $demoListProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->demoListProvider = new DemoListProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
$this->demoListProvider = new DemoListProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
|
||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18) {
|
||||
return new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
$map,
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
$playerCount,
|
||||
$uploaderId,
|
||||
'hash',
|
||||
'backend',
|
||||
'path'
|
||||
);
|
||||
}
|
||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18) {
|
||||
return new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
$map,
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
$playerCount,
|
||||
$uploaderId,
|
||||
'hash',
|
||||
'backend',
|
||||
'path'
|
||||
);
|
||||
}
|
||||
|
||||
public function testListEmpty() {
|
||||
$this->assertEquals([], $this->demoListProvider->listDemos(1));
|
||||
}
|
||||
public function testListEmpty() {
|
||||
$this->assertEquals([], $this->demoListProvider->listDemos(1));
|
||||
}
|
||||
|
||||
public function testListSimple() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
public function testListSimple() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1);
|
||||
$this->assertCount(3, $list);
|
||||
$list = $this->demoListProvider->listDemos(1);
|
||||
$this->assertCount(3, $list);
|
||||
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id2, $list[1]->getId());
|
||||
$this->assertEquals($id1, $list[2]->getId());
|
||||
}
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id2, $list[1]->getId());
|
||||
$this->assertEquals($id1, $list[2]->getId());
|
||||
}
|
||||
|
||||
public function testFilterMap() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2'), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
public function testFilterMap() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2'), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1'), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['map' => 'map1']);
|
||||
$this->assertCount(2, $list);
|
||||
$list = $this->demoListProvider->listDemos(1, ['map' => 'map1']);
|
||||
$this->assertCount(2, $list);
|
||||
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id3, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testFilterPlayerCount() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
public function testFilterPlayerCount() {
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['playerCount' => [17, 18, 19]]);
|
||||
$this->assertCount(2, $list);
|
||||
$list = $this->demoListProvider->listDemos(1, ['playerCount' => [17, 18, 19]]);
|
||||
$this->assertCount(2, $list);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testByUploader() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
public function testByUploader() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1);
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
}
|
||||
|
||||
public function testByUploaderFilter() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 12), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
public function testByUploaderFilter() {
|
||||
$steamId = $this->getSteamId('12345', 'bar');
|
||||
$this->userProvider->store($steamId);
|
||||
$userId = $this->userProvider->get($steamId->getSteamId64())->getId();
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map1', 12), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo($userId, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo($userId + 1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1, ['playerCount' => [17, 18, 19]]);
|
||||
$list = $this->demoListProvider->listUploads($steamId->getSteamId64(), 1, ['playerCount' => [17, 18, 19]]);
|
||||
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
}
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
}
|
||||
|
||||
private function addPlayer($demoId, $userId) {
|
||||
$player = new Player(0, $demoId, 0, $userId, 'foo', 'red', 'scout');
|
||||
$this->playerProvider->store($player);
|
||||
}
|
||||
private function addPlayer($demoId, $userId) {
|
||||
$player = new Player(0, $demoId, 0, $userId, 'foo', 'red', 'scout');
|
||||
$this->playerProvider->store($player);
|
||||
}
|
||||
|
||||
public function testFilterPlayer() {
|
||||
$steamId1 = $this->getSteamId('12345', 'bar1');
|
||||
$steamId2 = $this->getSteamId('22345', 'bar2');
|
||||
$steamId3 = $this->getSteamId('32345', 'bar3');
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$userId1 = $this->userProvider->get($steamId1->getSteamId64())->getId();
|
||||
$userId2 = $this->userProvider->get($steamId2->getSteamId64())->getId();
|
||||
$userId3 = $this->userProvider->get($steamId3->getSteamId64())->getId();
|
||||
public function testFilterPlayer() {
|
||||
$steamId1 = $this->getSteamId('12345', 'bar1');
|
||||
$steamId2 = $this->getSteamId('22345', 'bar2');
|
||||
$steamId3 = $this->getSteamId('32345', 'bar3');
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$userId1 = $this->userProvider->get($steamId1->getSteamId64())->getId();
|
||||
$userId2 = $this->userProvider->get($steamId2->getSteamId64())->getId();
|
||||
$userId3 = $this->userProvider->get($steamId3->getSteamId64())->getId();
|
||||
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
$id1 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 17), 'foo', 'bar');
|
||||
$id2 = $this->demoProvider->storeDemo($this->getDemo(1, 'map2', 18), 'foo', 'bar');
|
||||
$id3 = $this->demoProvider->storeDemo($this->getDemo(1, 'map1', 12), 'foo', 'bar');
|
||||
|
||||
$this->addPlayer($id1, $userId1);
|
||||
$this->addPlayer($id1, $userId2);
|
||||
$this->addPlayer($id2, $userId1);
|
||||
$this->addPlayer($id2, $userId3);
|
||||
$this->addPlayer($id3, $userId3);
|
||||
$this->addPlayer($id1, $userId1);
|
||||
$this->addPlayer($id1, $userId2);
|
||||
$this->addPlayer($id2, $userId1);
|
||||
$this->addPlayer($id2, $userId3);
|
||||
$this->addPlayer($id3, $userId3);
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(2, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
$this->assertCount(2, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertEquals($id1, $list[1]->getId());
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId1->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(1, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
$this->assertCount(1, $list);
|
||||
$this->assertEquals($id2, $list[0]->getId());
|
||||
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId2->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
$list = $this->demoListProvider->listDemos(1, ['players' => [$steamId2->getSteamId64(), $steamId3->getSteamId64()]]);
|
||||
|
||||
$this->assertCount(0, $list);
|
||||
}
|
||||
$this->assertCount(0, $list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,187 +13,187 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class DemoProviderTest extends TestCase {
|
||||
/** @var DemoProvider */
|
||||
private $provider;
|
||||
/** @var DemoProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
/** @var PlayerProvider */
|
||||
private $playerProvider;
|
||||
|
||||
/** @var KillProvider */
|
||||
private $killProvider;
|
||||
/** @var KillProvider */
|
||||
private $killProvider;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->killProvider = new KillProvider($this->getDatabaseConnection());
|
||||
}
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->killProvider = new KillProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get(1));
|
||||
}
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get(1));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testStoreRetrieve() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$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'
|
||||
);
|
||||
$demo->setUploaderUser($uploader);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo->setUploaderUser($uploader);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
||||
$retrieved = $this->provider->get($id);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
$retrieved = $this->provider->get($id);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
|
||||
$storedData = $demo->jsonSerialize();
|
||||
$storedData['id'] = $id;
|
||||
$storedData = $demo->jsonSerialize();
|
||||
$storedData['id'] = $id;
|
||||
|
||||
$this->assertEquals($storedData, $retrieved->jsonSerialize());
|
||||
$this->assertEquals($storedData, $retrieved->jsonSerialize());
|
||||
|
||||
$this->assertEquals($id, $this->provider->demoIdByHash('hash'));
|
||||
}
|
||||
$this->assertEquals($id, $this->provider->demoIdByHash('hash'));
|
||||
}
|
||||
|
||||
public function testRetrieveWithPlayers() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testRetrieveWithPlayers() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$steamId1 = $this->getSteamId('1', 'u1');
|
||||
$steamId2 = $this->getSteamId('2', 'u2');
|
||||
$steamId3 = $this->getSteamId('3', 'u3');
|
||||
$steamId4 = $this->getSteamId('4', 'u4');
|
||||
$steamId1 = $this->getSteamId('1', 'u1');
|
||||
$steamId2 = $this->getSteamId('2', 'u2');
|
||||
$steamId3 = $this->getSteamId('3', 'u3');
|
||||
$steamId4 = $this->getSteamId('4', 'u4');
|
||||
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$this->userProvider->store($steamId4);
|
||||
$this->userProvider->store($steamId1);
|
||||
$this->userProvider->store($steamId2);
|
||||
$this->userProvider->store($steamId3);
|
||||
$this->userProvider->store($steamId4);
|
||||
|
||||
$user1 = $this->userProvider->get($steamId1->getSteamId64());
|
||||
$user2 = $this->userProvider->get($steamId2->getSteamId64());
|
||||
$user3 = $this->userProvider->get($steamId3->getSteamId64());
|
||||
$user4 = $this->userProvider->get($steamId4->getSteamId64());
|
||||
$user1 = $this->userProvider->get($steamId1->getSteamId64());
|
||||
$user2 = $this->userProvider->get($steamId2->getSteamId64());
|
||||
$user3 = $this->userProvider->get($steamId3->getSteamId64());
|
||||
$user4 = $this->userProvider->get($steamId4->getSteamId64());
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$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',
|
||||
'backend',
|
||||
'path',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'backend',
|
||||
'path',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$player1 = $this->addPlayer($id, 101, $user1->getId(), 'red', 'scout');
|
||||
$player2 = $this->addPlayer($id, 102, $user2->getId(), 'red', 'soldier');
|
||||
$player3 = $this->addPlayer($id, 103, $user3->getId(), 'blue', 'engineer');
|
||||
$player4 = $this->addPlayer($id, 104, $user4->getId(), 'blue', 'spy');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$player1 = $this->addPlayer($id, 101, $user1->getId(), 'red', 'scout');
|
||||
$player2 = $this->addPlayer($id, 102, $user2->getId(), 'red', 'soldier');
|
||||
$player3 = $this->addPlayer($id, 103, $user3->getId(), 'blue', 'engineer');
|
||||
$player4 = $this->addPlayer($id, 104, $user4->getId(), 'blue', 'spy');
|
||||
|
||||
$this->addKill($id, $user1->getId(), 0, $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), $user2->getId(), $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user4->getId(), 0, $user1->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), 0, $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user1->getId(), $user2->getId(), $user3->getId(), 'pan');
|
||||
$this->addKill($id, $user4->getId(), 0, $user1->getId(), 'pan');
|
||||
|
||||
$retrieved = $this->provider->get($id, true);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
$retrieved = $this->provider->get($id, true);
|
||||
$this->assertInstanceOf(Demo::class, $retrieved);
|
||||
|
||||
$players = $retrieved->getPlayers();
|
||||
$this->assertCount(4, $players);
|
||||
usort($players, function (DemoPlayer $a, DemoPlayer $b) {
|
||||
return $a->getUserId() - $b->getUserId();
|
||||
});
|
||||
$this->assertEquals([
|
||||
new DemoPlayer($player1, $user1->getId(), 'user_' . $user1->getId(), 'red', 'scout', '1', 'foo_medium.jpg', 2, 0, 1),
|
||||
new DemoPlayer($player2, $user2->getId(), 'user_' . $user2->getId(), 'red', 'soldier', '2', 'foo_medium.jpg', 0, 1, 0),
|
||||
new DemoPlayer($player3, $user3->getId(), 'user_' . $user3->getId(), 'blue', 'engineer', '3', 'foo_medium.jpg', 0, 0, 2),
|
||||
new DemoPlayer($player4, $user4->getId(), 'user_' . $user4->getId(), 'blue', 'spy', '4', 'foo_medium.jpg', 1, 0, 0),
|
||||
], $players);
|
||||
}
|
||||
$players = $retrieved->getPlayers();
|
||||
$this->assertCount(4, $players);
|
||||
usort($players, function (DemoPlayer $a, DemoPlayer $b) {
|
||||
return $a->getUserId() - $b->getUserId();
|
||||
});
|
||||
$this->assertEquals([
|
||||
new DemoPlayer($player1, $user1->getId(), 'user_' . $user1->getId(), 'red', 'scout', '1', 'foo_medium.jpg', 2, 0, 1),
|
||||
new DemoPlayer($player2, $user2->getId(), 'user_' . $user2->getId(), 'red', 'soldier', '2', 'foo_medium.jpg', 0, 1, 0),
|
||||
new DemoPlayer($player3, $user3->getId(), 'user_' . $user3->getId(), 'blue', 'engineer', '3', 'foo_medium.jpg', 0, 0, 2),
|
||||
new DemoPlayer($player4, $user4->getId(), 'user_' . $user4->getId(), 'blue', 'spy', '4', 'foo_medium.jpg', 1, 0, 0),
|
||||
], $players);
|
||||
}
|
||||
|
||||
private function addPlayer(int $demoId, int $demoUserId, int $userId, string $team, string $class): int {
|
||||
$player = new Player(0, $demoId, $demoUserId, $userId, 'user_' . $userId, $team, $class);
|
||||
return $this->playerProvider->store($player);
|
||||
}
|
||||
private function addPlayer(int $demoId, int $demoUserId, int $userId, string $team, string $class): int {
|
||||
$player = new Player(0, $demoId, $demoUserId, $userId, 'user_' . $userId, $team, $class);
|
||||
return $this->playerProvider->store($player);
|
||||
}
|
||||
|
||||
private function addKill(int $demoId, int $attackerId, int $assisterId, int $victimId, string $weapon): int {
|
||||
$kill = new Kill(0, $demoId, $attackerId, $assisterId, $victimId, $weapon);
|
||||
return $this->killProvider->store($kill);
|
||||
}
|
||||
private function addKill(int $demoId, int $attackerId, int $assisterId, int $victimId, string $weapon): int {
|
||||
$kill = new Kill(0, $demoId, $attackerId, $assisterId, $victimId, $weapon);
|
||||
return $this->killProvider->store($kill);
|
||||
}
|
||||
|
||||
public function testSetDemoUrl() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
public function testSetDemoUrl() {
|
||||
$uploaderSteamId = $this->getSteamId('12345', 'test');
|
||||
$this->userProvider->store($uploaderSteamId);
|
||||
|
||||
$uploader = $this->userProvider->get($uploaderSteamId->getSteamId64());
|
||||
$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'
|
||||
);
|
||||
$demo = new Demo(
|
||||
0,
|
||||
'http://example.com',
|
||||
'name',
|
||||
'server',
|
||||
12,
|
||||
'nick',
|
||||
'map',
|
||||
new \DateTime(),
|
||||
'RED',
|
||||
'BLUE',
|
||||
1,
|
||||
2,
|
||||
18,
|
||||
$uploader->getId(),
|
||||
'hash',
|
||||
'dummy',
|
||||
'path'
|
||||
);
|
||||
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id2 = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
$id2 = $this->provider->storeDemo($demo, 'dummy', 'path');
|
||||
|
||||
$this->provider->setDemoUrl($id, 'foobackend', 'http://foo.example.com', 'bar');
|
||||
$this->provider->setDemoUrl($id, 'foobackend', 'http://foo.example.com', 'bar');
|
||||
|
||||
$storedDemo = $this->provider->get($id);
|
||||
$this->assertEquals('http://foo.example.com', $storedDemo->getUrl());
|
||||
$this->assertEquals('foobackend', $storedDemo->getBackend());
|
||||
$this->assertEquals('bar', $storedDemo->getPath());
|
||||
$storedDemo = $this->provider->get($id);
|
||||
$this->assertEquals('http://foo.example.com', $storedDemo->getUrl());
|
||||
$this->assertEquals('foobackend', $storedDemo->getBackend());
|
||||
$this->assertEquals('bar', $storedDemo->getPath());
|
||||
|
||||
$storedDemo2 = $this->provider->get($id2);
|
||||
$this->assertEquals('http://example.com', $storedDemo2->getUrl());
|
||||
}
|
||||
$storedDemo2 = $this->provider->get($id2);
|
||||
$this->assertEquals('http://example.com', $storedDemo2->getUrl());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,284 +19,289 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class UploadProviderTest extends TestCase {
|
||||
/** @var RawParser */
|
||||
private $rawParser;
|
||||
/** @var HeaderParser */
|
||||
private $headerParser;
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
/** @var DemoStore */
|
||||
private $demoStore;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var DemoSaver */
|
||||
private $demoSaver;
|
||||
/** @var UploadProvider */
|
||||
private $uploadProvider;
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
/** @var RawParser */
|
||||
private $rawParser;
|
||||
/** @var HeaderParser */
|
||||
private $headerParser;
|
||||
/** @var Parser */
|
||||
private $parser;
|
||||
/** @var DemoStore */
|
||||
private $demoStore;
|
||||
/** @var UserProvider */
|
||||
private $userProvider;
|
||||
/** @var DemoProvider */
|
||||
private $demoProvider;
|
||||
/** @var DemoSaver */
|
||||
private $demoSaver;
|
||||
/** @var UploadProvider */
|
||||
private $uploadProvider;
|
||||
/** @var string */
|
||||
private $tmpDir;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->rawParser = $this->getMockBuilder(RawParser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->rawParser->expects($this->any())
|
||||
->method('parse')
|
||||
->will($this->returnCallback(function ($path) {
|
||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||
return json_decode(file_get_contents($jsonPath), true);
|
||||
}));
|
||||
$this->rawParser->expects($this->any())
|
||||
->method('parse')
|
||||
->will($this->returnCallback(function ($path) {
|
||||
$jsonPath = str_replace('.dem', '-raw.json', $path);
|
||||
return json_decode(file_get_contents($jsonPath), true);
|
||||
}));
|
||||
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
$this->tmpDir = $targetDir;
|
||||
$targetDir = tempnam(sys_get_temp_dir(), 'dummy_target_');
|
||||
unlink($targetDir);
|
||||
mkdir($targetDir);
|
||||
$this->tmpDir = $targetDir;
|
||||
|
||||
$this->headerParser = new HeaderParser();
|
||||
$this->parser = new Parser($this->rawParser);
|
||||
$this->demoStore = new DemoStore($targetDir, 'example.com');
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->demoSaver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
new ChatProvider($this->getDatabaseConnection()),
|
||||
$this->userProvider,
|
||||
$this->demoProvider
|
||||
);
|
||||
$this->headerParser = new HeaderParser();
|
||||
$this->parser = new Parser($this->rawParser);
|
||||
$this->demoStore = new DemoStore($targetDir, 'example.com');
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->demoSaver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
new ChatProvider($this->getDatabaseConnection()),
|
||||
$this->userProvider,
|
||||
$this->demoProvider
|
||||
);
|
||||
|
||||
$this->uploadProvider = new UploadProvider(
|
||||
$this->getDatabaseConnection(),
|
||||
'http://example.com',
|
||||
$this->headerParser,
|
||||
$this->parser,
|
||||
$this->demoStore,
|
||||
$this->userProvider,
|
||||
$this->demoProvider,
|
||||
$this->demoSaver
|
||||
);
|
||||
}
|
||||
$this->uploadProvider = new UploadProvider(
|
||||
$this->getDatabaseConnection(),
|
||||
'http://example.com',
|
||||
$this->headerParser,
|
||||
$this->parser,
|
||||
$this->demoStore,
|
||||
$this->userProvider,
|
||||
$this->demoProvider,
|
||||
$this->demoSaver
|
||||
);
|
||||
}
|
||||
|
||||
private function rmdirr($dir) {
|
||||
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new \RecursiveIteratorIterator($it,
|
||||
\RecursiveIteratorIterator::CHILD_FIRST);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
rmdir($file->getRealPath());
|
||||
} else {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
private function rmdirr($dir) {
|
||||
$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
$files = new \RecursiveIteratorIterator(
|
||||
$it,
|
||||
\RecursiveIteratorIterator::CHILD_FIRST
|
||||
);
|
||||
foreach ($files as $file) {
|
||||
if ($file->isDir()) {
|
||||
rmdir($file->getRealPath());
|
||||
} else {
|
||||
unlink($file->getRealPath());
|
||||
}
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
$this->rmdirr($this->tmpDir);
|
||||
public function tearDown() {
|
||||
$this->rmdirr($this->tmpDir);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testValidateHeaderToSmall() {
|
||||
$this->assertEquals('Demos needs to be at least 1KB is size', $this->uploadProvider->validateHeader(
|
||||
12,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToSmall() {
|
||||
$this->assertEquals('Demos needs to be at least 1KB is size', $this->uploadProvider->validateHeader(
|
||||
12,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateHeaderToBig() {
|
||||
$this->assertEquals('Demos cant be more than 100MB in size', $this->uploadProvider->validateHeader(
|
||||
99999999999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToBig() {
|
||||
$this->assertEquals('Demos cant be more than 100MB in size', $this->uploadProvider->validateHeader(
|
||||
99999999999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
12,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateHeaderToLong() {
|
||||
$this->assertEquals('Demos cant be longer than one hour', $this->uploadProvider->validateHeader(
|
||||
9999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
999999,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
public function testValidateHeaderToLong() {
|
||||
$this->assertEquals('Demos cant be longer than one hour', $this->uploadProvider->validateHeader(
|
||||
9999,
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
999999,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateParsedToShortNoRounds() {
|
||||
$this->assertEquals('Demos must be at least 5 minutes long', $this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(0, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
public function testValidateParsedToShortNoRounds() {
|
||||
$this->assertEquals('Demos must be at least 5 minutes long', $this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(0, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
|
||||
public function testValidateParsedToShortRounds() {
|
||||
$this->assertNull($this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(1, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
public function testValidateParsedToShortRounds() {
|
||||
$this->assertNull($this->uploadProvider->validateParsed(
|
||||
new Header(
|
||||
'HL2DEMO',
|
||||
1,
|
||||
2,
|
||||
'Server',
|
||||
'Nick',
|
||||
'cp_gullywash',
|
||||
'tf',
|
||||
60,
|
||||
12,
|
||||
12,
|
||||
12
|
||||
),
|
||||
new ParsedDemo(1, 0, [], [], [])
|
||||
));
|
||||
}
|
||||
|
||||
public function testUploadInvalidKey() {
|
||||
$this->assertEquals('Invalid key',
|
||||
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
||||
);
|
||||
}
|
||||
public function testUploadInvalidKey() {
|
||||
$this->assertEquals(
|
||||
'Invalid key',
|
||||
$this->uploadProvider->upload('asdasd', 'RED', 'BLU', 'asdasd', 'asdas')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testUploadNonDemo() {
|
||||
file_put_contents($this->tmpDir . '/foo.dem', 'asd');
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Not an HL2 demo
|
||||
*/
|
||||
public function testUploadNonDemo() {
|
||||
file_put_contents($this->tmpDir . '/foo.dem', 'asd');
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem');
|
||||
}
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem');
|
||||
}
|
||||
|
||||
public function testUploadExisting() {
|
||||
$source = fopen(__DIR__ . '/../data/product.dem', 'r');
|
||||
file_put_contents($this->tmpDir . '/foo.dem', fread($source, 2048));
|
||||
fclose($source);
|
||||
$hash = md5_file($this->tmpDir . '/foo.dem');
|
||||
public function testUploadExisting() {
|
||||
$source = fopen(__DIR__ . '/../data/product.dem', 'r');
|
||||
file_put_contents($this->tmpDir . '/foo.dem', fread($source, 2048));
|
||||
fclose($source);
|
||||
$hash = md5_file($this->tmpDir . '/foo.dem');
|
||||
|
||||
$id = $this->demoProvider->storeDemo(
|
||||
new Demo(
|
||||
0,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
12,
|
||||
'n',
|
||||
'm',
|
||||
new \DateTime(),
|
||||
'r',
|
||||
'b',
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
$hash,
|
||||
'b',
|
||||
'p'
|
||||
),
|
||||
'test', 'test'
|
||||
);
|
||||
$id = $this->demoProvider->storeDemo(
|
||||
new Demo(
|
||||
0,
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
12,
|
||||
'n',
|
||||
'm',
|
||||
new \DateTime(),
|
||||
'r',
|
||||
'b',
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
$hash,
|
||||
'b',
|
||||
'p'
|
||||
),
|
||||
'test',
|
||||
'test'
|
||||
);
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
$this->assertEquals('STV available at: http://example.com/' . $id,
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
|
||||
);
|
||||
}
|
||||
$this->assertEquals(
|
||||
'STV available at: http://example.com/' . $id,
|
||||
$this->uploadProvider->upload($token, 'RED', 'BLU', 'asdasd', $this->tmpDir . '/foo.dem')
|
||||
);
|
||||
}
|
||||
|
||||
private function saveSteamId($steamId, $name) {
|
||||
$steamId = $this->getSteamId($this->parser->convertSteamIdToCommunityId($steamId), $name);
|
||||
$this->userProvider->store($steamId);
|
||||
}
|
||||
private function saveSteamId($steamId, $name) {
|
||||
$steamId = $this->getSteamId($this->parser->convertSteamIdToCommunityId($steamId), $name);
|
||||
$this->userProvider->store($steamId);
|
||||
}
|
||||
|
||||
public function testUpload() {
|
||||
copy(__DIR__ . '/../data/product.dem', $this->tmpDir . '/foo.dem');
|
||||
copy(__DIR__ . '/../data/product-raw.json', $this->tmpDir . '/foo-raw.json');
|
||||
public function testUpload() {
|
||||
copy(__DIR__ . '/../data/product.dem', $this->tmpDir . '/foo.dem');
|
||||
copy(__DIR__ . '/../data/product-raw.json', $this->tmpDir . '/foo-raw.json');
|
||||
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
$steamId = $this->getSteamId('123', 'a');
|
||||
$token = $this->userProvider->store($steamId);
|
||||
|
||||
// pre-save the names so we dont have to get them from steam
|
||||
$this->saveSteamId('[U:1:64229260]', 'Icewind');
|
||||
$this->saveSteamId('[U:1:115748435]', 'Foz');
|
||||
$this->saveSteamId('[U:1:115754284]', 'Deity');
|
||||
$this->saveSteamId('[U:1:92428736]', 'Kireek');
|
||||
$this->saveSteamId('[U:1:22958903]', 'Vinegar');
|
||||
$this->saveSteamId('[U:1:32061783]', 'Kimo');
|
||||
$this->saveSteamId('[U:1:67502510]', 'magikarp');
|
||||
$this->saveSteamId('[U:1:55128465]', 'Solar');
|
||||
$this->saveSteamId('[U:1:301587080]', 'ztreak');
|
||||
$this->saveSteamId('[U:1:22162172]', 'TheMasterOfDisaster');
|
||||
$this->saveSteamId('[U:1:13559571]', 'Sage');
|
||||
$this->saveSteamId('[U:1:71706948]', 'Sketis');
|
||||
$this->saveSteamId('[U:1:157204170]', 'Pyla');
|
||||
$this->saveSteamId('[U:1:30838206]', 'Heavy');
|
||||
$this->saveSteamId('[U:1:174774002]', 'Soldier');
|
||||
$this->saveSteamId('[U:1:92096346]', 'Fish');
|
||||
$this->saveSteamId('[U:1:143626373]', 'Pendulum');
|
||||
$this->saveSteamId('[U:1:30220936]', 'Jedi');
|
||||
// pre-save the names so we dont have to get them from steam
|
||||
$this->saveSteamId('[U:1:64229260]', 'Icewind');
|
||||
$this->saveSteamId('[U:1:115748435]', 'Foz');
|
||||
$this->saveSteamId('[U:1:115754284]', 'Deity');
|
||||
$this->saveSteamId('[U:1:92428736]', 'Kireek');
|
||||
$this->saveSteamId('[U:1:22958903]', 'Vinegar');
|
||||
$this->saveSteamId('[U:1:32061783]', 'Kimo');
|
||||
$this->saveSteamId('[U:1:67502510]', 'magikarp');
|
||||
$this->saveSteamId('[U:1:55128465]', 'Solar');
|
||||
$this->saveSteamId('[U:1:301587080]', 'ztreak');
|
||||
$this->saveSteamId('[U:1:22162172]', 'TheMasterOfDisaster');
|
||||
$this->saveSteamId('[U:1:13559571]', 'Sage');
|
||||
$this->saveSteamId('[U:1:71706948]', 'Sketis');
|
||||
$this->saveSteamId('[U:1:157204170]', 'Pyla');
|
||||
$this->saveSteamId('[U:1:30838206]', 'Heavy');
|
||||
$this->saveSteamId('[U:1:174774002]', 'Soldier');
|
||||
$this->saveSteamId('[U:1:92096346]', 'Fish');
|
||||
$this->saveSteamId('[U:1:143626373]', 'Pendulum');
|
||||
$this->saveSteamId('[U:1:30220936]', 'Jedi');
|
||||
|
||||
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
||||
$result = $this->uploadProvider->upload($token, 'RED', 'BLU', 'foodemo', $this->tmpDir . '/foo.dem');
|
||||
$this->assertStringStartsWith('STV available at: http://example.com/', $result);
|
||||
|
||||
$demoId = (int)substr($result, strlen('STV available at: http://example.com/'));
|
||||
$demoId = (int)substr($result, strlen('STV available at: http://example.com/'));
|
||||
|
||||
$demo = $this->demoProvider->get($demoId, true);
|
||||
$demo = $this->demoProvider->get($demoId, true);
|
||||
|
||||
$this->assertNotNull($demo);
|
||||
$this->assertNotNull($demo);
|
||||
|
||||
$this->assertEquals('koth_product_rc8', $demo->getMap());
|
||||
$this->assertEquals(0, $demo->getBlueScore());
|
||||
$this->assertEquals(3, $demo->getRedScore());
|
||||
}
|
||||
$this->assertEquals('koth_product_rc8', $demo->getMap());
|
||||
$this->assertEquals(0, $demo->getBlueScore());
|
||||
$this->assertEquals(3, $demo->getRedScore());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,73 +6,73 @@ use Demostf\API\Providers\UserProvider;
|
|||
use Demostf\API\Test\TestCase;
|
||||
|
||||
class UserProviderTest extends TestCase {
|
||||
/** @var UserProvider */
|
||||
private $provider;
|
||||
/** @var UserProvider */
|
||||
private $provider;
|
||||
|
||||
/** @var \SteamId */
|
||||
private $steamId;
|
||||
/** @var \SteamId */
|
||||
private $steamId;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->steamId = $this->getSteamId('76561198024494988', 'Icewind');
|
||||
$this->provider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
$this->steamId = $this->getSteamId('76561198024494988', 'Icewind');
|
||||
$this->provider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
}
|
||||
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get('76561198024494988'));
|
||||
}
|
||||
public function testGetNonExisting() {
|
||||
$this->assertNull($this->provider->get('76561198024494988'));
|
||||
}
|
||||
|
||||
public function testStoreRetrieve() {
|
||||
$this->provider->store($this->steamId);
|
||||
public function testStoreRetrieve() {
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$user = $this->provider->get('76561198024494988');
|
||||
$user = $this->provider->get('76561198024494988');
|
||||
|
||||
$this->assertEquals($this->steamId->getNickname(), $user->getName());
|
||||
$this->assertEquals($this->steamId->getSteamId64(), $user->getSteamId());
|
||||
}
|
||||
$this->assertEquals($this->steamId->getNickname(), $user->getName());
|
||||
$this->assertEquals($this->steamId->getSteamId64(), $user->getSteamId());
|
||||
}
|
||||
|
||||
public function returnTokenExisting() {
|
||||
$token1 = $this->provider->store($this->steamId);
|
||||
$token2 = $this->provider->store($this->steamId);
|
||||
public function returnTokenExisting() {
|
||||
$token1 = $this->provider->store($this->steamId);
|
||||
$token2 = $this->provider->store($this->steamId);
|
||||
|
||||
$this->assertEquals($token1, $token2);
|
||||
}
|
||||
$this->assertEquals($token1, $token2);
|
||||
}
|
||||
|
||||
public function testDoubleInsert() {
|
||||
$this->provider->store($this->steamId);
|
||||
$this->provider->store($this->steamId);
|
||||
public function testDoubleInsert() {
|
||||
$this->provider->store($this->steamId);
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testByKey() {
|
||||
$token = $this->provider->store($this->steamId);
|
||||
public function testByKey() {
|
||||
$token = $this->provider->store($this->steamId);
|
||||
|
||||
$byKey = $this->provider->byKey($token);
|
||||
$this->assertEquals('76561198024494988', $byKey->getSteamId());
|
||||
}
|
||||
$byKey = $this->provider->byKey($token);
|
||||
$this->assertEquals('76561198024494988', $byKey->getSteamId());
|
||||
}
|
||||
|
||||
public function testSearch() {
|
||||
$result = $this->provider->search('__NOT__FOUND__');
|
||||
public function testSearch() {
|
||||
$result = $this->provider->search('__NOT__FOUND__');
|
||||
|
||||
$this->assertCount(0, $result);
|
||||
}
|
||||
$this->assertCount(0, $result);
|
||||
}
|
||||
|
||||
public function testGetIdExisting() {
|
||||
$this->provider->store($this->steamId);
|
||||
public function testGetIdExisting() {
|
||||
$this->provider->store($this->steamId);
|
||||
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
|
||||
$this->assertEquals($user->getId(), $this->provider->getUserId($this->steamId->getSteamId64()));
|
||||
}
|
||||
$this->assertEquals($user->getId(), $this->provider->getUserId($this->steamId->getSteamId64()));
|
||||
}
|
||||
|
||||
public function testGetIdNew() {
|
||||
$id = $this->provider->getUserId($this->steamId->getSteamId64());
|
||||
public function testGetIdNew() {
|
||||
$id = $this->provider->getUserId($this->steamId->getSteamId64());
|
||||
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
$user = $this->provider->get($this->steamId->getSteamId64());
|
||||
|
||||
|
||||
$this->assertEquals($user->getId(), $id);
|
||||
}
|
||||
$this->assertEquals($user->getId(), $id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue