Repository navigation
Wordpress 51884 #844
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
Open
Yeora
wants to merge
18
commits into
WordPress:master
Choose a base branch
from
Yeora:WORDPRESS-51884
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Wordpress 51884 #844
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
09aa9d3
Merge pull request #1 from WordPress/master
Yeora e6f35c4
Added reset community-events-location Button
Yeora 06db13b
removed letter in comment
Yeora 65a21dc
Fixed indentation
Yeora aa5888e
fixed indentation
Yeora 4c42408
fixed lowercase
Yeora 41733bd
Added Tests for Ticket #51884
Yeora 900e12f
Changed Group Annotation to ajax
Yeora a505d12
Fixed PHP Unit Test
Yeora ace6051
Fixed CodingStyle
Yeora cad1562
fixed coding standards
Yeora c45d275
fixed coding standards
Yeora 2f0fb8f
fixed codingstandards
Yeora af02f1a
fixed codingstandards
Yeora fc946b4
fixed codingstandards
Yeora f601227
fixed iandunns annotations
Yeora ecb9605
Fixed Codingstyle
Yeora 7e2cb21
Fixed Codingstyle
Yeora 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,110 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Admin Ajax functions to be tested. | ||
| */ | ||
| require_once ABSPATH . 'wp-admin/includes/ajax-actions.php'; | ||
|
|
||
| /** | ||
| * Testing Ajax Community_Event_location functionality. | ||
| * | ||
| * @package WordPress | ||
| * @subpackage UnitTests | ||
| * @since 5.7.0 | ||
| * @group ajax | ||
| */ | ||
| class Tests_Community_Event_location extends WP_Ajax_UnitTestCase { | ||
| private $user_id; | ||
|
|
||
| /** | ||
| * Runs before each Test | ||
| */ | ||
| public function setUp() { | ||
| parent::setUp(); | ||
| $wp_user = get_user_by( 'email', WP_TESTS_EMAIL ); | ||
| update_user_meta( $wp_user->ID, 'community-events-location', 'DummyData' ); | ||
|
|
||
| wp_set_current_user( $wp_user->ID ); | ||
| $this->user_id = $wp_user->ID; | ||
| } | ||
|
|
||
| /** | ||
| * Tests the new Clear Community Events Location Ajax endpoint without nonce | ||
| */ | ||
| public function test_clear_community_events_location_without_nonce() { | ||
| // Before should be set to 'DummyData' | ||
| $content = get_user_meta( $this->user_id, 'community-events-location', true ); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| $this->handleAjaxCall(); | ||
|
|
||
| // After Failed Ajax Call should be still 'DummyData'; | ||
| $content = $this->getCommunityEventsContent(); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests the new Clear Community Events Location Ajax endpoint with wrong nonce | ||
| */ | ||
| public function test_clear_community_events_location_with_wrong_nonce() { | ||
| // Before should be set to 'DummyData' | ||
| $content = get_user_meta( $this->user_id, 'community-events-location', true ); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| $_POST['_wpnonce'] = wp_create_nonce( 'community_events_but_wrong_nonce' ); | ||
| $this->handleAjaxCall(); | ||
|
|
||
| // After Failed Ajax Call should be still 'DummyData'; | ||
| $content = $this->getCommunityEventsContent(); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests the new Clear Community Events Location Ajax endpoint without being logged in | ||
| */ | ||
| public function test_clear_community_events_location_logged_out() { | ||
| $this->logout(); | ||
|
|
||
| // Before should be set to 'DummyData' | ||
| $content = get_user_meta( $this->user_id, 'community-events-location', true ); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| $_POST['_wpnonce'] = wp_create_nonce( 'community_events' ); | ||
| $this->handleAjaxCall(); | ||
|
|
||
| // After Failed Ajax Call should be still 'DummyData'; | ||
| $content = $this->getCommunityEventsContent(); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests the new Clear Community Events Location Ajax endpoint in the correct way | ||
| */ | ||
| public function test_clear_community_events_location() { | ||
| // Before should be set to 'DummyData' | ||
| $content = $this->getCommunityEventsContent(); | ||
| $this->assertNotTrue( $this->isNullOrEmptyString( $content ) ); | ||
| $_POST['_wpnonce'] = wp_create_nonce( 'community_events' ); | ||
| $this->handleAjaxCall(); | ||
|
|
||
| // After Ajax Call should be set to null | ||
| $content = $this->getCommunityEventsContent(); | ||
| $this->assertTrue( $this->isNullOrEmptyString( $content ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @return mixed | ||
| */ | ||
| private function getCommunityEventsContent() { | ||
| return get_user_meta( $this->user_id, 'community-events-location', true ); | ||
| } | ||
|
|
||
| private function handleAjaxCall() { | ||
| try { | ||
| $this->_handleAjax( 'clear-community-events' ); | ||
| } catch ( WPDieException $e ) { | ||
| unset( $e ); | ||
| } | ||
| } | ||
|
|
||
| private function isNullOrEmptyString( $string ) { | ||
| return ( ! isset( $string ) || trim( $string ) === '' ); | ||
| } | ||
| } |
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.
This would be the 3rd place the above code is duplicated. It'd be nice to create a
getRequestParams()function to keep it DRY.