<?php

namespace Tests\WechatPlatform\Http;

use Modules\WechatPlatform\Http\Controllers\KFMessageController;
use PHPUnit\Framework\TestCase;
use Tests\UsedTestCase;

class KFMessageControllerTest extends UsedTestCase
{

    public function testAdd()
    {
        $STR =  <<<AAA
文本内容<a href="http://www.qq.com" data-miniprogram-appid="appid" data-miniprogram-path="pages/index/index">点击跳小程序</a>
AAA;

        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('post','http://localhost/api/wechatPlatform/kfMessage/add', [
            'name' => 'liuzj-test-'. uniqid(),
            'send_at' => date('Y-m-d H:i:s', strtotime('tomorrow')),
            'message_type' => 1,
            'u_type' => 1,
            'message_content' => [
                ['text' => '普通文本👌🏻'],
                ['text' => $STR]
            ]
        ]);
        $this->dumpJson($res);
    }

    public function testList()
    {
        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('get','http://localhost/api/wechatPlatform/kfMessage/list', [
        ]);
        $this->dumpJson($res);
    }

    public function testupdateContent()
    {
        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('post','http://localhost/api/wechatPlatform/kfMessage/updateContent', [
            'id' => 4,
            'name' => 'change-'.uniqid(),
            'message_type' => 1,
            'message_content' => [
                ['text' => 'changexxxx']
            ],
            'u_type' => 2,
            'uc_unique_key' => uniqid('',true),
            'send_at' => date('Y-m-d H:i:s', strtotime('+2 hour'))
        ]);
        $this->dumpJson($res);
    }

    public function testupdateGZH()
    {
        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('post','http://localhost/api/wechatPlatform/kfMessage/updateGZH', [
            'id' => 4,
            'gzh_ids' => [1,2]
        ]);
        $this->dumpJson($res);
    }

    public function teststop()
    {
        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('post','http://localhost/api/wechatPlatform/kfMessage/stop', [
            'id' => 3
        ]);
        $this->dumpJson($res);
    }

    public function testdelete()
    {
        $res = $this->withHeaders([
            'Authorization' => 'Bearer '. $this->token,
        ])->json('post','http://localhost/api/wechatPlatform/kfMessage/delete', [
            'id' => 3
        ]);
        $this->dumpJson($res);
    }
}
