Implement wp site get command to enable site operations by URL by Copilot · Pull Request #571 · wp-cli/entity-command · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
128 changes: 128 additions & 0 deletions features/site.feature
Original file line number Diff line number Diff line change
Expand Up @@ -763,3 +763,131 @@ Feature: Manage sites in a multisite installation
Then STDOUT should be a table containing rows:
| blog_id | public |
| 2 | 1 |

Scenario: Get site by ID
Given a WP multisite install

When I run `wp site create --slug=testsite --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get {SITE_ID} --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

When I run `wp site get {SITE_ID}`
Then STDOUT should be a table containing rows:
| Field | Value |
| blog_id | {SITE_ID} |

Scenario: Get site by URL
Given a WP multisite install

When I run `wp site create --slug=testsite --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}
And I run `wp site list --blog_id={SITE_ID} --field=url`
And save STDOUT as {SITE_URL}

When I run `wp site get {SITE_URL} --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

Scenario: Get site by URL with subdirectory
Given a WP multisite subdirectory install

When I run `wp site create --slug=mysubdir --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get http://example.com/mysubdir/ --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

Scenario: Use site get with site delete
Given a WP multisite install

When I run `wp site create --slug=deleteme --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get http://example.com/deleteme/ --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""
And save STDOUT as {BLOG_ID}

When I run `wp site delete {BLOG_ID} --yes`
Then STDOUT should contain:
"""
Success: The site at
"""
And STDOUT should contain:
"""
was deleted.
"""

Scenario: Get site with invalid URL should fail
Given a WP multisite install

When I try `wp site get http://example.com/nonexistent/ --field=blog_id`
Then STDERR should contain:
"""
Error: Could not find site with URL: http://example.com/nonexistent/
"""
And the return code should be 1

Scenario: Get site by domain without scheme
Given a WP multisite subdirectory install

When I run `wp site create --slug=noscheme --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get example.com/noscheme/ --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

Scenario: Get site by simple domain path
Given a WP multisite subdirectory install

When I run `wp site create --slug=simplepath --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get example.com/simplepath --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

Scenario: Get site by subdomain without scheme
Given a WP multisite subdomain install

When I run `wp site create --slug=subdomain --porcelain`
Then STDOUT should be a number
And save STDOUT as {SITE_ID}

When I run `wp site get subdomain.example.com --field=blog_id`
Then STDOUT should be:
"""
{SITE_ID}
"""

Scenario: Get main site by domain
Given a WP multisite install

When I run `wp site get example.com --field=blog_id`
Then STDOUT should be:
"""
1
"""
133 changes: 133 additions & 0 deletions src/Site_Command.php