Inheritance: extends Apple_Actions\API_Action
コード例 #1
0
 public function testJSONErrorsFail()
 {
     $this->settings->set('component_alerts', 'none');
     $this->settings->set('json_alerts', 'fail');
     $response = $this->dummy_response();
     $api = $this->prophet->prophesize('\\Apple_Push_API\\API');
     $api->post_article_to_channel(Argument::cetera())->willReturn($response)->shouldNotBeCalled();
     // We need to create an iframe, so run as administrator
     $user_id = $this->set_admin();
     // Create post
     $post_id = $this->factory->post->create(array('post_content' => 'ÂÂîî'));
     $action = new Push($this->settings, $post_id);
     $action->set_api($api->reveal());
     try {
         $action->perform();
     } catch (Action_Exception $e) {
         // An admin error notice was created
         $notices = get_user_meta($user_id, 'apple_news_notice', true);
         $this->assertNotEmpty($notices);
         $component_notice = end($notices);
         $this->assertEquals('The following JSON errors were detected and prevented publishing: Invalid unicode character sequences were found that could cause display issues on Apple News: ÂÂîî', $e->getMessage());
         // The post was not sent to Apple News
         $this->assertEquals(null, get_post_meta($post_id, 'apple_news_api_id', true));
         $this->assertEquals(null, get_post_meta($post_id, 'apple_news_api_created_at', true));
         $this->assertEquals(null, get_post_meta($post_id, 'apple_news_api_modified_at', true));
         $this->assertEquals(null, get_post_meta($post_id, 'apple_news_api_share_url', true));
         $this->assertEquals(null, get_post_meta($post_id, 'apple_news_api_deleted', true));
     }
 }