1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: aappen |
5
|
|
|
* Date: 01.10.18 |
6
|
|
|
* Time: 16:59 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace seretos\testrail\api; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Sections extends AbstractApi |
13
|
|
|
{ |
14
|
|
|
private $cache = []; |
15
|
|
|
public function all(int $projectId, int $suiteId) |
16
|
|
|
{ |
17
|
|
|
if (!isset($this->cache[$projectId][$suiteId])) { |
18
|
|
|
$this->cache[$projectId][$suiteId] = $this->connector->send_get('get_sections/'.$this->encodePath($projectId).'&suite_id='.$this->encodePath($suiteId)); |
19
|
|
|
} |
20
|
|
|
return $this->cache[$projectId][$suiteId]; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function get(int $sectionId) |
24
|
|
|
{ |
25
|
|
|
return $this->connector->send_get('get_section/'.$this->encodePath($sectionId)); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function findByName(int $projectId, int $suiteId, string $name) |
29
|
|
|
{ |
30
|
|
|
$allSections = $this->all($projectId, $suiteId); |
31
|
|
|
foreach ($allSections as $section) { |
32
|
|
|
if ($section['name'] === $name) { |
33
|
|
|
return $section; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function findByNameAndParent(int $projectId, int $suiteId, string $name, int $parentId = null) |
40
|
|
|
{ |
41
|
|
|
$allSections = $this->all($projectId, $suiteId); |
42
|
|
|
foreach ($allSections as $section) { |
43
|
|
|
if ($section['name'] === $name && $section['parent_id'] == $parentId) { |
44
|
|
|
return $section; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
return []; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function findByParent(int $projectId, int $suiteId, int $parentId = null) { |
51
|
|
|
$allSections = $this->all($projectId, $suiteId); |
52
|
|
|
$sections = []; |
53
|
|
|
foreach ($allSections as $section) { |
54
|
|
|
if ((!isset($section['parent_id']) && $parentId == null) || (isset($section['parent_id']) && $section['parent_id'] == $parentId)) { |
|
|
|
|
55
|
|
|
$sections[] = $section; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
return $sections; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function create(int $projectId, int $suiteId, string $name, string $description = null, int $parent_id = null) |
62
|
|
|
{ |
63
|
|
|
$section = $this->connector->send_post('add_section/'.$this->encodePath($projectId), |
64
|
|
|
['name' => $name, |
65
|
|
|
'description' => $description, |
66
|
|
|
'suite_id' => $suiteId, |
67
|
|
|
'parent_id' => $parent_id]); |
68
|
|
|
unset($this->cache[$projectId][$suiteId]); |
69
|
|
|
return $section; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param int $sectionId |
74
|
|
|
* @param array $parameters { |
75
|
|
|
* @var string $name |
76
|
|
|
* @var string $description |
77
|
|
|
* } |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
|
|
public function update(int $sectionId, array $parameters = []) { |
81
|
|
|
$section = $this->connector->send_post('update_section/'.$this->encodePath($sectionId), $parameters); |
82
|
|
|
$this->cache = []; |
83
|
|
|
return $section; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function delete(int $sectionId) { |
87
|
|
|
$this->connector->send_post('delete_section/'.$this->encodePath($sectionId), []); |
88
|
|
|
$this->cache = []; |
89
|
|
|
} |
90
|
|
|
} |