Skip to content

Commit e7097c2

Browse files
Automatic tests for CometQL api
1 parent 0ecb548 commit e7097c2

File tree

12 files changed

+165
-0
lines changed

12 files changed

+165
-0
lines changed

api/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## JavaScript API
3+
4+
See documentation here [EN](https://comet-server.com/wiki/doku.php/en:comet:javascript_api#javascript_api) [RU](https://comet-server.com/wiki/doku.php/comet:javascript_api#javascript_api)

coverage/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
## Calculate coverage
3+
4+
Scripts for calculate coverage in tests

tests/api-tests/index.html

Whitespace-only changes.

tests/api-tests/readme.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Automatic tests
2+
3+
Automatic tests for CometQL api

tests/api-tests/test.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
// More info about CppComet http://comet-server.org/doku.php/en
4+
// More info about CometQL http://comet-server.org/doku.php/en:comet:cometql
5+
// More info about auth in CppComet http://comet-server.org/doku.php/en:comet:authentication
6+
7+
header('Content-Type: text/html; charset=utf-8');
8+
header("Access-Control-Allow-Origin: *");
9+
if($_SERVER['REQUEST_METHOD'] == 'OPTIONS')
10+
{
11+
exit();
12+
}
13+
14+
ini_set('display_errors','on');
15+
error_reporting (E_ALL);
16+
session_start();
17+
18+
include './utils/timetest.php';
19+
include './utils/testClass.php';
20+
21+
$count = 100;
22+
if(isset($_GET['count']))
23+
{
24+
$count = $_GET['count'];
25+
if($count > 100)
26+
{
27+
return "-1";
28+
}
29+
}
30+
31+
$test = preg_replace("#[^A-z0-9\_\-]#usi", "", $_GET['test']);
32+
if(!file_exists("./tests/".$test.".php"))
33+
{
34+
return "-1";
35+
}
36+
37+
include "./tests/".$test.".php";
38+
39+
// We connect to the comet server with login and password for the access demo (you can get your data for connection after registration at comet-server.com)
40+
// Login 15
41+
// Password lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8
42+
// CometQL_v1 database
43+
$cppTest->init([
44+
"host" => "app.comet-server.ru",
45+
"user" => "15",
46+
"password" => "lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8",
47+
"api_version" => "CometQL_v1"
48+
]);
49+
50+
51+
$cppTest->start();
52+
timeTest::test('cpp', 'test');
53+
for($i =0; $i<$count; $i++)
54+
{
55+
$cppTest->test();
56+
}
57+
$t = timeTest::test('cpp','test');
58+
$t = $t[count($t) - 1];
59+
60+
$cppTest->stop();
61+
62+
echo json_encode([
63+
'count' => $count,
64+
'test' => $test,
65+
'time' => $t['time']
66+
]);
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
class test_mysqli_connect extends testClass{
4+
5+
function test()
6+
{
7+
$l = mysqli_connect($this->opt['host'], $this->opt['user'], $this->opt['password'], $this->opt['api_version']);
8+
echo mysqli_error($l)."\n";
9+
mysqli_close($l);
10+
}
11+
}
12+
13+
$cppTest = new test_mysqli_connect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
class users_auth_insert extends testClass{
5+
6+
public $count = 0;
7+
8+
function test()
9+
{
10+
$this->count++;
11+
$query = "INSERT INTO users_auth (id, hash )VALUES (".$this->count.", 'hash".$this->count."');";
12+
mysqli_query($this->link, $query);
13+
}
14+
}
15+
16+
$cppTest = new users_auth_insert();
17+

tests/api-tests/utils/testClass.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
class testClass{
4+
5+
public $link;
6+
public $opt;
7+
8+
function init($opt){
9+
$this->opt = $opt;
10+
}
11+
12+
function start()
13+
{
14+
$this->link = mysqli_connect(
15+
$this->opt['host'],
16+
$this->opt['user'],
17+
$this->opt['password'],
18+
$this->opt['api_version']);
19+
if(!$this->link || mysqli_errno($this->link))
20+
{
21+
echo "Error:". mysqli_error($this->link);
22+
exit();
23+
}
24+
}
25+
26+
function test(){
27+
28+
}
29+
30+
function stop()
31+
{
32+
mysqli_close($this->link);
33+
}
34+
35+
}

tests/api-tests/utils/timetest.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
class timeTest{
4+
5+
public static $timeTestArray = array();
6+
public static function test($group, $name = '')
7+
{
8+
if(!isset(self::$timeTestArray[$group]))
9+
{
10+
self::$timeTestArray[$group] = array();
11+
self::$timeTestArray[$group][] = array("now" =>microtime(true), "name" => $name, "delta" => 0, "time" => 0 );
12+
return self::$timeTestArray[$group];
13+
}
14+
15+
self::$timeTestArray[$group][] = array(
16+
"now" =>microtime(true),
17+
"name" => $name,
18+
"time" => microtime(true) - self::$timeTestArray[$group][0]["now"], // Общее время на группу
19+
"delta" => microtime(true) - self::$timeTestArray[$group][count(self::$timeTestArray[$group])-1]["now"] // Время на последнеею операцию
20+
);
21+
return self::$timeTestArray[$group];
22+
}
23+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)