blob: ae72c5b51fa7b60f2a0621beb468d4aa21a2c952 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<?php
namespace OCA\OJSXC\Utility;
use OCA\OJSXC\AppInfo\Application;
/**
* @group DB
*/
class MapperTestUtility extends TestCase {
/**
* @var \OCP\AppFramework\IAppContainer
*/
protected $container;
protected $entityName;
protected $mapperName;
protected $host;
protected $userId;
protected function setUp() {
parent::setUp();
$app = new Application();
$this->overwriteApplicationService($app, 'Host','localhost');
$this->overwriteApplicationService($app, 'UserId', 'admin');
$this->container = $app->getContainer();
$this->mapper = $this->container[$this->mapperName];
$this->host = 'localhost';
$this->userId = 'admin';
$con = $this->container->getServer()->getDatabaseConnection();
$con->executeQuery('DELETE FROM ' . $this->mapper->getTableName());
}
protected function tearDown() {
$con = $this->container->getServer()->getDatabaseConnection();
$con->executeQuery('DELETE FROM ' . $this->mapper->getTableName());
}
protected function fetchAll(){
$con = $this->container->getServer()->getDatabaseConnection();
$stmt = $con->executeQuery('SELECT * FROM ' . $this->mapper->getTableName());
$entities = [];
while($row = $stmt->fetch()){
$entities[] = call_user_func($this->entityName . '::fromRow', $row);;
}
$stmt->closeCursor();
return $entities;
}
protected function fetchAllAsArray($tableName = null){
if (is_null($tableName)) {
$tableName = $this->mapper->getTableName();
} else {
}
$con = $this->container->getServer()->getDatabaseConnection();
$stmt = $con->executeQuery('SELECT * FROM ' . $tableName);
$result = [];
while($row = $stmt->fetch()){
$result[] = $row;
}
$stmt->closeCursor();
return $result;
}
public function getLastInsertedId() {
return $this->container->getServer()->getDatabaseConnection()->lastInsertId();
}
}
|