Example #1
0
 public function testEmptyPOST()
 {
     ExitTestHelper::init();
     $wechat = new MyWechat($this->token);
     $this->assertEquals('缺少数据', ExitTestHelper::getFirstExitOutput(), 'SDK should output "no data" (in chinese, utf-8).');
     ExitTestHelper::clean();
 }
 /**
  * Php exit() handler.
  * Make it private, to prevent invoking outside.
  *
  * @param string $param (Optional) Exit message.
  */
 private static function exitHandler($param = NULL)
 {
     if (!self::$have_exit) {
         self::$have_exit = TRUE;
         echo $param ?: '';
         self::$first_exit_output = ob_get_contents();
         if (self::$first_exit_output === FALSE) {
             self::$first_exit_output = '';
         }
     }
     return FALSE;
 }
Example #3
0
 public function testEventOnLink()
 {
     ExitTestHelper::init();
     $this->fillLinkMsg('netputer/wechat-php-sdk', '微信公众平台 PHP SDK', 'https://github.com/netputer/wechat-php-sdk');
     $wechat = $this->mockBuilder->getMock();
     $wechat->expects($this->once())->method('onLink');
     $wechat->run();
     $this->assertEquals('netputer/wechat-php-sdk', $wechat->publicGetRequest('title'));
     $this->assertEquals('微信公众平台 PHP SDK', $wechat->publicGetRequest('description'));
     $this->assertEquals('https://github.com/netputer/wechat-php-sdk', $wechat->publicGetRequest('url'));
     // 应无exit
     $this->assertFalse(ExitTestHelper::isThereExit(), "There shouldn't be any exit() was invoked.");
     ExitTestHelper::clean();
 }
Example #4
0
 public function testReplyNews()
 {
     ExitTestHelper::init();
     $this->fillTextMsg('收到文本消息');
     $wechat = new MyWechat($this->token);
     $items = array(new NewsResponseItem('Travis CI', 'Free Hosted Continuous Integration Platform for the Open Source Community', 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'https://travis-ci.org/netputer/wechat-php-sdk'), new NewsResponseItem('Travis CI 2', '2 Free Hosted Continuous Integration Platform for the Open Source Community', 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'https://travis-ci.org/netputer/wechat-php-sdk'));
     // 回复图文消息
     $wechat->publicResponseNews($items);
     // 截获输出,解析
     $this->setResponse(ExitTestHelper::getFirstExitOutput());
     // 回复的to、from与填充的传入消息的to、from相反
     $this->assertEquals($this->fromUser, $this->getResponseField('tousername'));
     $this->assertEquals($this->toUser, $this->getResponseField('fromusername'));
     $this->assertEquals('0', $this->getResponseField('funcflag'));
     $this->assertEquals('news', $this->getResponseField('msgtype'));
     // 验证图文消息内容
     $this->assertEquals('2', $this->getResponseField('articlecount'));
     $articles = (array) $this->getResponseField('articles');
     $article = array_change_key_case((array) $articles['item'][0], CASE_LOWER);
     $this->assertEquals(array('title' => 'Travis CI', 'description' => 'Free Hosted Continuous Integration Platform for the Open Source Community', 'picurl' => 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'url' => 'https://travis-ci.org/netputer/wechat-php-sdk'), $article);
     $article = array_change_key_case((array) $articles['item'][1], CASE_LOWER);
     $this->assertEquals(array('title' => 'Travis CI 2', 'description' => '2 Free Hosted Continuous Integration Platform for the Open Source Community', 'picurl' => 'https://travis-ci.org/netputer/wechat-php-sdk.png', 'url' => 'https://travis-ci.org/netputer/wechat-php-sdk'), $article);
     ExitTestHelper::clean();
 }