forked from beezwax/WP-Publish-to-Apple-News
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #962 from alleyinteractive/feature/v2.3.3
Release v2.3.3
- Loading branch information
Showing
12 changed files
with
167 additions
and
62 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,56 +1,97 @@ | ||
<?php | ||
/** | ||
* Publish to Apple News tests: Apple_News_Admin_Action_Index_Delete_Test class | ||
* | ||
* @package Apple_News | ||
* @subpackage Tests | ||
*/ | ||
|
||
use \Apple_Actions\Index\Delete as Delete; | ||
use \Apple_Exporter\Settings as Settings; | ||
use \Prophecy\Argument as Argument; | ||
use Apple_Actions\Index\Delete; | ||
|
||
class Admin_Action_Index_Delete_Test extends WP_UnitTestCase { | ||
/** | ||
* A class to test the functionality of the Apple_Actions\Index\Delete class. | ||
* | ||
* @package Apple_News | ||
* @subpackage Tests | ||
*/ | ||
class Apple_News_Admin_Action_Index_Delete_Test extends Apple_News_Testcase { | ||
/** | ||
* Tests the behavior of the automatic delete setting. | ||
*/ | ||
public function test_auto_delete() { | ||
// Create a post, which will automatically be published. | ||
$this->become_admin(); | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post_id = self::factory()->post->create(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
|
||
private $prophet; | ||
// Add an HTTP response for the delete operation, then delete the article, and verify it was triggered. | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
wp_delete_post( $post_id, true ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
|
||
public function setup() { | ||
parent::setup(); | ||
// Create a new article and move it to the trash and verify that the delete operation was not triggered. | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post_id = self::factory()->post->create(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
wp_delete_post( $post_id ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
array_pop( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
|
||
$this->prophet = new \Prophecy\Prophet; | ||
$this->settings = new Settings(); | ||
$this->settings->set( 'api_key', 'foo' ); | ||
$this->settings->set( 'api_secret', 'bar' ); | ||
$this->settings->set( 'api_channel', 'baz' ); | ||
} | ||
|
||
public function tearDown() { | ||
$this->prophet->checkPredictions(); | ||
} | ||
|
||
public function testActionPerform() { | ||
$remote_id = uniqid(); | ||
$api = $this->prophet->prophesize( '\Apple_Push_API\API' ); | ||
$api->delete_article( $remote_id ) | ||
->shouldBeCalled(); | ||
|
||
// Create post with dummy remote id | ||
$post_id = $this->factory->post->create(); | ||
update_post_meta( $post_id, 'apple_news_api_id', $remote_id ); | ||
// Create a new article and move it to draft status and verify that the delete operation was not triggered. | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post = self::factory()->post->create_and_get(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
$post->post_status = 'draft'; | ||
wp_update_post( $post ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
array_pop( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
|
||
$action = new Delete( $this->settings, $post_id ); | ||
$action->set_api( $api->reveal() ); | ||
$action->perform(); | ||
// Opt in to delete on trash via filter, create a new article, move it to the trash, and verify that the delete operation was triggered. | ||
add_filter( 'apple_news_should_post_delete_on_trash', '__return_true' ); | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post_id = self::factory()->post->create(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
wp_delete_post( $post_id ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
remove_filter( 'apple_news_should_post_delete_on_trash', '__return_true' ); | ||
|
||
$this->assertNotEquals( null, get_post_meta( $post_id, 'apple_news_api_deleted', true ) ); | ||
$this->assertEquals( null, get_post_meta( $post_id, 'apple_news_api_id', true ) ); | ||
} | ||
|
||
public function testActionPerformWhenNotPushed() { | ||
// Expect an exception | ||
$this->setExpectedException( '\Apple_Actions\Action_Exception', 'This post has not been pushed to Apple News, cannot delete.' ); | ||
|
||
$api = $this->prophet->prophesize( '\Push_API\API' ); | ||
$post_id = $this->factory->post->create(); | ||
// Opt in to delete on unpublish via filter, create a new article, move it to draft, and verify that the delete operation was triggered. | ||
add_filter( 'apple_news_should_post_delete_on_unpublish', '__return_true' ); | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post = self::factory()->post->create_and_get(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
$post->post_status = 'draft'; | ||
wp_update_post( $post ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
remove_filter( 'apple_news_should_post_delete_on_unpublish', '__return_true' ); | ||
|
||
$action = new Delete( $this->settings, $post_id ); | ||
$action->set_api( $api->reveal() ); | ||
$action->perform(); | ||
// Opt in to delete on unpublish via filter, create a new article, move it to the trash, and verify that the delete operation was triggered. | ||
add_filter( 'apple_news_should_post_delete_on_unpublish', '__return_true' ); | ||
$this->add_http_response( 'POST', 'https://news-api.apple.com/channels/foo/articles', wp_json_encode( $this->fake_article_response() ) ); | ||
$this->assertNotEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$post_id = self::factory()->post->create(); | ||
$this->assertEmpty( $this->http_responses['POST']['https://news-api.apple.com/channels/foo/articles'] ); | ||
$this->add_http_response( 'DELETE', 'https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456' ); | ||
$this->assertNotEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
wp_delete_post( $post_id ); | ||
$this->assertEmpty( $this->http_responses['DELETE']['https://news-api.apple.com/articles/abcd1234-ef56-ab78-cd90-efabcdef123456'] ); | ||
remove_filter( 'apple_news_should_post_delete_on_unpublish', '__return_true' ); | ||
} | ||
|
||
} | ||
|
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