-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update continent rest api and add testcase.
- Loading branch information
Showing
2 changed files
with
82 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace WeDevs\Dokan\Test\Continents; | ||
|
||
use WeDevs\Dokan\Test\DokanTestCase; | ||
|
||
class RestApi extends DokanTestCase { | ||
|
||
/** | ||
* The namespace of the REST route. | ||
* | ||
* @var string Dokan API Namespace | ||
*/ | ||
protected $rest_base = 'data/continents'; | ||
|
||
/** | ||
* Test that the endpoint exist. | ||
*/ | ||
public function test_if_get_all_continents_api_exists() { | ||
$routes = $this->server->get_routes( $this->namespace ); | ||
$full_route = $this->get_route( $this->rest_base ); | ||
|
||
$this->assertArrayHasKey( $full_route, $routes ); | ||
} | ||
|
||
/** | ||
* Test that the endpoint exist. | ||
*/ | ||
public function test_if_get_a_single_continent_api_exists() { | ||
$routes = $this->server->get_routes( $this->namespace ); | ||
$full_route = $this->get_route( $this->rest_base . '/(?P<location>[\w-]+)' ); | ||
|
||
$this->assertArrayHasKey( $full_route, $routes ); | ||
} | ||
|
||
public function test_that_we_can_get_all_continents() { | ||
wp_set_current_user( $this->seller_id1 ); | ||
|
||
$response = $this->get_request( $this->rest_base ); | ||
|
||
$this->assertEquals( 200, $response->get_status() ); | ||
|
||
$data = $response->get_data(); | ||
|
||
$this->assertIsArray( $data ); | ||
$this->assertArrayHasKey( 'code', $data[0] ); | ||
$this->assertArrayHasKey( 'name', $data[0] ); | ||
$this->assertArrayHasKey( 'countries', $data[0] ); | ||
} | ||
|
||
public function test_that_we_can_get_single_continent_item_by_code() { | ||
wp_set_current_user( $this->seller_id1 ); | ||
|
||
$response = $this->get_request( $this->rest_base . '/AS' ); | ||
|
||
$this->assertEquals( 200, $response->get_status() ); | ||
|
||
$data = $response->get_data(); | ||
|
||
$this->assertIsArray( $data ); | ||
$this->assertArrayHasKey( 'code', $data ); | ||
$this->assertArrayHasKey( 'name', $data ); | ||
$this->assertArrayHasKey( 'countries', $data ); | ||
} | ||
} |