-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds unit tests and is_module_active method to SAL. #11010
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7dc57e3
Added a bare bones unit test suite for the Site SAL class.
zinigor 98eb251
Added a simple test suite for the Post object.
zinigor 3ed138e
Added a mandatory is_module_active method to the Site SAL class.
zinigor 6df6eeb
Fixed a number in a comment, removed fiddling with HTTPS.
zinigor 8837184
Switched static var usage to self.
zinigor 9c3bff1
Removed is_user_member_of_blog calls in favor of API permissions.
zinigor 6fcd58d
Added a user blog membership check in the API endpoint instead of SAL.
zinigor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,54 @@ | ||
<?php | ||
|
||
require_once dirname( __FILE__ ) . '/../../../sal/class.json-api-platform.php'; | ||
|
||
class SalSiteTest extends WP_UnitTestCase { | ||
static $token; | ||
static $site; | ||
|
||
static function setUpBeforeClass( ) { | ||
parent::setUpBeforeClass(); | ||
|
||
self::$token = (object) array( | ||
'blog_id' => get_current_blog_id(), | ||
'user_id' => get_current_user_id(), | ||
'external_user_id' => 2, | ||
'role' => 'administrator' | ||
); | ||
|
||
$platform = wpcom_get_sal_platform( self::$token ); | ||
|
||
self::$site = $platform->get_site( self::$token->blog_id ); | ||
} | ||
|
||
function test_uses_synced_api_post_type_whitelist_if_available() { | ||
|
||
$this->assertFalse( self::$site->is_post_type_allowed( 'my_new_type' ) ); | ||
} | ||
|
||
function test_is_module_active() { | ||
|
||
// Picking random 3 modules from an array of existing ones to not slow down the test | ||
$modules = array_rand( Jetpack::get_available_modules(), 3 ); | ||
|
||
foreach ( $modules as $module ) { | ||
Jetpack::deactivate_module( $module ); | ||
|
||
$this->assertEquals( | ||
Jetpack::is_module_active( $module ), | ||
self::$site->is_module_active( $module ) | ||
); | ||
|
||
Jetpack::activate_module( $module ); | ||
|
||
$this->assertEquals( | ||
Jetpack::is_module_active( $module ), | ||
self::$site->is_module_active( $module ) | ||
); | ||
} | ||
} | ||
|
||
function test_interface() { | ||
$this->assertTrue( method_exists( 'SAL_Site', 'is_module_active' ) ); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
require_once dirname( __FILE__ ) . '/../../../sal/class.json-api-platform.php'; | ||
|
||
class SalPostsTest extends WP_UnitTestCase { | ||
static $token; | ||
static $site; | ||
|
||
static function setUpBeforeClass() { | ||
parent::setUpBeforeClass(); | ||
|
||
self::$token = (object) array( | ||
'blog_id' => get_current_blog_id(), | ||
'user_id' => get_current_user_id(), | ||
'external_user_id' => 2, | ||
'role' => 'administrator' | ||
); | ||
|
||
$platform = wpcom_get_sal_platform( self::$token ); | ||
|
||
self::$site = $platform->get_site( self::$token->blog_id ); | ||
} | ||
|
||
function test_returns_content_wrapped_in_a_post_object() { | ||
// Insert the post into the database | ||
$post_id = wp_insert_post( array( | ||
'post_title' => 'Title', | ||
'post_content' => 'The content.', | ||
'post_status' => 'publish', | ||
'post_author' => get_current_user_id() | ||
) ); | ||
|
||
$post = get_post( $post_id ); | ||
|
||
$wrapped_post = self::$site->wrap_post( $post, 'display' ); | ||
|
||
$this->assertEquals( $post->post_type, $wrapped_post->get_type() ); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we remove the check from here we will want to add it in
json-endpoints/class.wpcom-json-api-get-site-endpoint.php