<?php
use PHPUnit\Framework\TestCase;
final class DeFaTextTranslateTest extends TestCase
{
private $messagesResults = [];
private $translate_bot;
function setUp(): void{
$BOT_USER= '@TranslateGerman_bot';
$BOT_TOKEN= '816983194:AAH1pPCba__pNRFK7h6fFMoy-9twUuxJ-n8';
$uriParts = explode("?",$_SERVER['REQUEST_URI']);
$actual_link = "https://$_SERVER[HTTP_HOST]".$uriParts[0];
$WEBHOOK_URL= "$actual_link";
$SIGN ="پوشش خبری شهر های آلمان ".PHP_EOL."@TranslateGerman_bot";
$this->translate_bot = new TranslateGerman($BOT_USER,$BOT_TOKEN,$WEBHOOK_URL, $SIGN);
$bot = $this->getMockBuilder('Bot')
->setConstructorArgs(array($BOT_USER,$BOT_TOKEN,$WEBHOOK_URL, $SIGN))
->getMock();
$bot->method("apiRequest")->will(
$this->returnCallback(array($this, 'returnTestDataCallback'))
);
$this->translate_bot->bot = $bot;
$this->getTG()->getDB()->removeAllUserActivites();
}
/**
* @group failing
*/
public function testTextButtons(): void
{
$dbgMgr = new DebugsManager();
$debugUserID = 44903244;
$update = $dbgMgr->getUpdateForTestPerson($debugUserID);
$update["message"]["text"]="kannst du es verbessern kannst du es verbessern kannst du es verbessern?";
$this->translate_bot->process($update);
$buttonResult = json_decode($this->messagesResults[2]["reply_markup"], true);
$this->assertSame($buttonResult["inline_keyboard"][0][0]["callback_data"], DeFaTextTranslate::$key . ":tr");
}
public function testTextButtonsForLongerText(): void
{
$dbgMgr = new DebugsManager();
$debugUserID = 44903244;
$update = $dbgMgr->getUpdateForTestPerson($debugUserID);
$update["message"]["text"]="Ganz wichtig: Bitte sei spätestens 15 Minuten vor Fahrtbeginn an Deiner Haltestelle.
Ganz wichtig: Bitte sei spätestens 15 Minuten vor Fahrtbeginn an Deiner Haltestelle.";
$this->translate_bot->process($update);
$buttonResult = json_decode($this->messagesResults[2]["reply_markup"], true);
$this->assertSame($buttonResult["inline_keyboard"][0][0]["callback_data"], DeFaTextTranslate::$key . ":tr");
}
public function testDeFaTranslateWithCallback(): void
{
$dbgMgr = new DebugsManager();
$debugUserID = 44903244;
$update = $dbgMgr->getUpdateForTextTranslateCallBack($debugUserID);
$this->translate_bot->process($update);
$this->assertIsString($this->messagesResults[0]['text']);
}
public function testDeFaCallbackWhenMoreThanGuestTranslated(): void
{
$dbgMgr = new DebugsManager();
$debugUserID = 44903244;
$update = $dbgMgr->getUpdateForTextTranslateCallBack($debugUserID);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->getTG()->getDB()->insertUserActivity($debugUserID,"nothing",DeFaTextTranslate::$intentId);
$this->translate_bot->process($update);
$this->assertIsString($this->messagesResults[0]['text']);
}
function getTG(): TranslateGerman {
return $this->translate_bot;
}
public function returnTestDataCallback()
{
$args = func_get_args();
// print_r($args);
if($args[0]=="getChatMember"){
$member["status"]="member";
return $member;
}
else {
$this->messagesResults[] =
array_push($this->messagesResults, $args[1]);
}
}
/**
* @group failing
*/
}