Skip to content

Commit

Permalink
add section.findByParent
Browse files Browse the repository at this point in the history
  • Loading branch information
Seretos committed Oct 25, 2018
1 parent ffccb8a commit 9d74539
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/api/Sections.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ public function findByNameAndParent(int $projectId, int $suiteId, string $name,
return [];
}

public function findByParent(int $projectId, int $suiteId, int $parentId = null){
$allSections = $this->all($projectId,$suiteId);
$sections = [];
foreach ($allSections as $section) {
if ((!isset($section['parent_id']) && $parentId == null) || (isset($section['parent_id']) && $section['parent_id'] == $parentId)) {
$sections[] = $section;
}
}
return $sections;
}

public function create(int $projectId, int $suiteId, string $name, string $description = null, int $parent_id = null)
{
$section = $this->connector->send_post('add_section/'.$this->encodePath($projectId),
Expand Down
13 changes: 13 additions & 0 deletions tests/api/SectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ public function findByNameAndParent(){
$this->assertSame(['id' => 2,'name' => 'section2','parent_id' => null],$this->sections->findByNameAndParent(1,2,'section2'));
}

/**
* @test
*/
public function findByParent(){
$this->mockApiConnector->expects($this->any())
->method('send_get')
->with('get_sections/1&suite_id=2')
->will($this->returnValue([['id' => 1,'name' => 'section1'],['id' => 2,'name' => 'section2','parent_id' => null],['id' => 3,'name' => 'section3','parent_id' => 1],['id' => 4,'name' => 'section4','parent_id' => 1]]));

$this->assertSame([['id' => 3,'name' => 'section3','parent_id' => 1],['id' => 4,'name' => 'section4','parent_id' => 1]],$this->sections->findByParent(1,2,1));
$this->assertSame([['id' => 1,'name' => 'section1'],['id' => 2,'name' => 'section2','parent_id' => null]],$this->sections->findByParent(1,2));
}

/**
* @test
*/
Expand Down

0 comments on commit 9d74539

Please sign in to comment.