diff --git a/src/Collections/Sites.php b/src/Collections/Sites.php index fc342d71a..f2d148624 100644 --- a/src/Collections/Sites.php +++ b/src/Collections/Sites.php @@ -137,6 +137,19 @@ public function filterByName($regex = '(.*)') return $this->filterByRegex('name', $regex); } + /** + * Filters the members of this collection by their label. + * + * @param string $regex + * Non-delimited PHP regex to filter site names by + * + * @return Sites + */ + public function filterByLabel($regex = '(.*)') + { + return $this->filterByRegex('label', $regex); + } + /** * Filters an array of sites by the plan name. * diff --git a/src/Commands/Org/Site/ListCommand.php b/src/Commands/Org/Site/ListCommand.php index 1debec057..896dbc604 100644 --- a/src/Commands/Org/Site/ListCommand.php +++ b/src/Commands/Org/Site/ListCommand.php @@ -29,6 +29,7 @@ class ListCommand extends TerminusCommand implements SiteAwareInterface * * @field-labels * name: Name + * label: Label * id: ID * plan_name: Plan * framework: Framework @@ -36,6 +37,7 @@ class ListCommand extends TerminusCommand implements SiteAwareInterface * created: Created * tags: Tags * frozen: Is Frozen? + * @default-fields name,id,plan_name,framework,owner,created,tags,frozen * @return RowsOfFields * * @param string $organization Organization name, label, or ID diff --git a/src/Commands/Site/ListCommand.php b/src/Commands/Site/ListCommand.php index 0488e2f1c..019bbf75c 100644 --- a/src/Commands/Site/ListCommand.php +++ b/src/Commands/Site/ListCommand.php @@ -24,6 +24,7 @@ class ListCommand extends SiteCommand * * @field-labels * name: Name + * label: Label * id: ID * plan_name: Plan * framework: Framework diff --git a/tests/Functional/OrgCommandsTest.php b/tests/Functional/OrgCommandsTest.php index de898c640..9d85e3950 100644 --- a/tests/Functional/OrgCommandsTest.php +++ b/tests/Functional/OrgCommandsTest.php @@ -153,6 +153,85 @@ public function testOrgSiteListCommand() ); } + /** + * @test + * @covers \Pantheon\Terminus\Commands\Org\Site\ListCommand + * + * @group org + * @group short + */ + public function testOrgSiteListCommandWithLabelField() + { + $orgSites = $this->terminusJsonResponse( + sprintf( + "org:site:list --fields=id,label %s", + $this->getOrg() + ) + ); + $this->assertIsArray( + $orgSites, + "Response from org list should be an array of orgs" + ); + $site = array_shift($orgSites); + + $this->assertIsArray( + $site, + "row from org list array of orgs should be an org item" + ); + $this->assertArrayHasKey( + 'id', + $site, + "Sites from org list should have an id property" + ); + $this->assertArrayHasKey( + 'label', + $site, + "Sites from org list should have a label property" + ); + } + + /** + * @test + * @covers \Pantheon\Terminus\Commands\Org\Site\ListCommand + * + * @group org + * @group short + */ + public function testOrgSiteListCommandWithLabelFilter() + { + $partial_site_name = substr($this->getSiteName(), 0, -1); + $orgSites = $this->terminusJsonResponse( + sprintf( + "org:site:list --fields=id,label --filter='label*=%s' %s", + $partial_site_name, + $this->getOrg() + ) + ); + $this->assertIsArray( + $orgSites, + "Response from org list should be an array of orgs" + ); + + $this->assertGreaterThan(0, count($orgSites)); + + $site = array_shift($orgSites); + + $this->assertIsArray( + $site, + "row from org list array of orgs should be an org item" + ); + $this->assertArrayHasKey( + 'id', + $site, + "Sites from org list should have an id property" + ); + $this->assertArrayHasKey( + 'label', + $site, + "Sites from org list should have a name property" + ); + } + /** * @test * @covers \Pantheon\Terminus\Commands\Org\Upstream\ListCommand diff --git a/tests/Functional/SiteCommandsTest.php b/tests/Functional/SiteCommandsTest.php index ab85c7aa0..dec2524d3 100644 --- a/tests/Functional/SiteCommandsTest.php +++ b/tests/Functional/SiteCommandsTest.php @@ -32,6 +32,47 @@ public function testSiteListCommand() $this->assertArrayHasKey('memberships', $site); } + /** + * @test + * @covers \Pantheon\Terminus\Commands\Site\ListCommand + * + * @group site + * @group short + */ + public function testSiteListCommandWithLabelField() + { + $siteList = $this->terminusJsonResponse(sprintf('site:list --org=%s --fields=id,label', $this->getOrg())); + $this->assertIsArray($siteList); + $this->assertGreaterThan(0, count($siteList)); + + $site = array_shift($siteList); + $this->assertArrayHasKey('id', $site); + $this->assertArrayHasKey('label', $site); + } + + /** + * @test + * @covers \Pantheon\Terminus\Commands\Site\ListCommand + * + * @group site + * @group short + */ + public function testSiteListCommandWithLabelFilter() + { + $partial_site_name = substr($this->getSiteName(), 0, -1); + $siteList = $this->terminusJsonResponse(sprintf( + 'site:list --org=%s --fields=id,label --filter=\'label*=%s\'', + $this->getOrg(), + $partial_site_name + )); + $this->assertIsArray($siteList); + $this->assertGreaterThan(0, count($siteList)); + + $site = array_shift($siteList); + $this->assertArrayHasKey('id', $site); + $this->assertArrayHasKey('label', $site); + } + /** * @test * @covers \Pantheon\Terminus\Commands\Site\Org\ListCommand