コード例 #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();
 }
コード例 #2
0
ファイル: ReplyTest.php プロジェクト: hweining/wechat-php-sdk
 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();
 }