Fix bot API file IDs

This commit is contained in:
Daniil Gentili 2020-02-04 17:34:02 +01:00
parent dcd6500737
commit e4ba475970
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 207 additions and 141 deletions

View File

@ -30,7 +30,8 @@
"amphp/byte-stream": "^1",
"danog/dns-over-https": "^0.2",
"amphp/http-client-cookies": "^1",
"amphp/uri": "^0.1"
"amphp/uri": "^0.1",
"danog/tg-file-decoder": "^0.1"
},
"require-dev": {
"vlucas/phpdotenv": "^3",

View File

@ -19,7 +19,6 @@
namespace danog\MadelineProto\Stream;
use Amp\Promise;
use Amp\Socket\EncryptableSocket;
use Amp\Socket\Socket;

View File

@ -19,9 +19,23 @@
namespace danog\MadelineProto\TL\Conversion;
use danog\Decoder\FileId;
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceDialogPhoto;
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceLegacy;
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceStickersetThumbnail;
use danog\Decoder\PhotoSizeSource\PhotoSizeSourceThumbnail;
use danog\MadelineProto\MTProtoTools\PeerHandler;
use danog\MadelineProto\Tools;
use tgseclib\Math\BigInteger;
use const danog\Decoder\ANIMATION;
use const danog\Decoder\AUDIO;
use const danog\Decoder\DOCUMENT;
use const danog\Decoder\PHOTO;
use const danog\Decoder\PROFILE_PHOTO;
use const danog\Decoder\STICKER;
use const danog\Decoder\THUMBNAIL;
use const danog\Decoder\VIDEO;
use const danog\Decoder\VIDEO_NOTE;
use const danog\Decoder\VOICE;
trait BotAPIFiles
{
@ -34,120 +48,165 @@ trait BotAPIFiles
$photoSize['location']['secret'] = $photo['location']['secret'] ?? 0;
$photoSize['location']['dc_id'] = $photo['dc_id'] ?? 0;
$photoSize['location']['_'] = $thumbnail ? 'bot_thumbnail' : 'bot_photo';
$data = (yield from $this->TL->serializeObject(['type' => 'File'], $photoSize['location'], 'File')) . \chr(2);
return ['file_id' => \danog\MadelineProto\Tools::base64urlEncode(\danog\MadelineProto\Tools::rleEncode($data)), 'width' => $photoSize['w'], 'height' => $photoSize['h'], 'file_size' => isset($photoSize['size']) ? $photoSize['size'] : \strlen($photoSize['bytes']), 'mime_type' => 'image/jpeg', 'file_name' => $photoSize['location']['volume_id'] . '_' . $photoSize['location']['local_id'] . $ext];
$data = (yield from $this->TL->serializeObject(['type' => 'File'], $photoSize['location'], 'File')).\chr(2);
return ['file_id' => \danog\MadelineProto\Tools::base64urlEncode(\danog\MadelineProto\Tools::rleEncode($data)), 'width' => $photoSize['w'], 'height' => $photoSize['h'], 'file_size' => isset($photoSize['size']) ? $photoSize['size'] : \strlen($photoSize['bytes']), 'mime_type' => 'image/jpeg', 'file_name' => $photoSize['location']['volume_id'].'_'.$photoSize['location']['local_id'].$ext];
}
/**
* Unpack bot API file ID.
*
* @param string $file_id Bot API file ID
* @param string $fileId Bot API file ID
*
* @return array Unpacked file ID
*/
public function unpackFileId(string $file_id): array
public function unpackFileId(string $fileId): array
{
$file_id = Tools::rleDecode(Tools::base64urlDecode($file_id));
$version = \ord($file_id[\strlen($file_id) - 1]);
$subVersion = $version === 4 ? \ord($file_id[\strlen($file_id) - 2]) : 0;
$this->logger("Got file ID with version {$version}.{$subVersion}");
if (!\in_array($version, [2, 4])) {
$fileId = FileId::fromBotAPI($fileId);
$this->logger("Got file ID with version {$fileId->getVersion()}.{$fileId->getSubVersion()}");
if (!\in_array($fileId->getVersion(), [2, 4])) {
throw new Exception("Invalid bot API file ID version {$version}");
}
$res = \fopen('php://memory', 'rw+b');
\fwrite($res, $file_id);
\fseek($res, 0);
$file_id = $res;
$deserialized = $this->TL->deserialize($file_id);
$res = ['type' => \str_replace('bot_', '', $deserialized['_'])];
if (\in_array($res['type'], ['profile_photo', 'thumbnail', 'photo'])) {
$deserialized['secret'] = 0;
$deserialized['photosize_source'] = $version >= 4 ? Tools::unpackSignedInt(\stream_get_contents($file_id, 4)) : 0;
// Legacy, Thumbnail, DialogPhotoSmall, DialogPhotoBig, StickerSetThumbnail
switch ($deserialized['photosize_source']) {
case 0:
$deserialized['secret'] = \stream_get_contents($file_id, 8);
break;
case 1:
$deserialized['file_type'] = Tools::unpackSignedInt(\stream_get_contents($file_id, 4));
$deserialized['thumbnail_type'] = \chr(Tools::unpackSignedInt(\stream_get_contents($file_id, 4)));
break;
case 2:
case 3:
$deserialized['photo_size'] = $deserialized['photosize_source'] === 2 ? 'photo_small' : 'photo_big';
$deserialized['dialog_id'] = (string) new BigInteger(\strrev(\stream_get_contents($file_id, 8)), -256);
$deserialized['dialog_access_hash'] = \stream_get_contents($file_id, 8);
break;
case 4:
$deserialized['sticker_set_id'] = Tools::unpackSignedInt(\stream_get_contents($file_id, 4));
$deserialized['sticker_set_access_hash'] = \stream_get_contents($file_id, 8);
break;
}
$deserialized['local_id'] = Tools::unpackSignedInt(\stream_get_contents($file_id, 4));
}
switch ($deserialized['_']) {
case 'bot_profile_photo':
if ($deserialized['dialog_id'] < 0) {
$res['Chat'] = ['_' => $deserialized['dialog_id'] < -1000000000000 ? 'channel' : 'chat', 'id' => $deserialized['dialog_id'] < -1000000000000 ? PeerHandler::fromSupergroup($deserialized['dialog_id']) : -$deserialized['dialog_id'], 'access_hash' => $deserialized['dialog_access_hash'], 'photo' => ['_' => 'chatPhoto', 'dc_id' => $deserialized['dc_id'], $deserialized['photo_size'] => ['_' => 'fileLocationToBeDeprecated', 'volume_id' => $deserialized['volume_id'], 'local_id' => $deserialized['local_id']]], 'min' => true];
$photoSize = $fileId->hasPhotoSizeSource() ? $fileId->getPhotoSizeSource() : null;
switch ($fileId->getType()) {
case PROFILE_PHOTO:
/**
* @var $photoSize PhotoSizeSourceDialogPhoto
*/
if ($photoSize->getDialogId() < 0) {
$res['Chat'] = [
'_' => $photoSize->getDialogId() < -1000000000000 ? 'channel' : 'chat',
'id' => $photoSize->getDialogId() < -1000000000000 ? PeerHandler::fromSupergroup($photoSize->getDialogId()) : -$photoSize->getDialogId(),
'access_hash' => $photoSize->getDialogAccessHash(),
'photo' => [
'_' => 'chatPhoto',
'dc_id' => $fileId->getDcId(),
$photoSize->isSmallDialogPhoto() ? 'photo_small' : 'photo_big' => [
'_' => 'fileLocationToBeDeprecated',
'volume_id' => $fileId->getVolumeId(),
'local_id' => $fileId->getLocalId()
]
],
'min' => true
];
return $res;
}
$res['User'] = ['_' => 'user', 'id' => $deserialized['dialog_id'], 'access_hash' => $deserialized['dialog_access_hash'], 'photo' => ['_' => 'userProfilePhoto', 'dc_id' => $deserialized['dc_id'], 'photo_id' => $deserialized['id'], $deserialized['photo_size'] => ['_' => 'fileLocationToBeDeprecated', 'volume_id' => $deserialized['volume_id'], 'local_id' => $deserialized['local_id']]], 'min' => true];
$res['User'] = [
'_' => 'user',
'id' => $photoSize->getDialogId(),
'access_hash' => $photoSize->getDialogAccessHash(),
'photo' => [
'_' => 'userProfilePhoto',
'dc_id' => $fileId->getDcId(),
'photo_id' => $fileId->getId(),
$photoSize->isSmallDialogPhoto() ? 'photo_small' : 'photo_big' => [
'_' => 'fileLocationToBeDeprecated',
'volume_id' => $fileId->getVolumeId(),
'local_id' => $fileId->getLocalId()
]
],
'min' => true
];
return $res;
case 'bot_thumbnail':
$res['InputFileLocation'] = ['_' => $deserialized['file_type'] >= 3 ? 'inputDocumentFileLocation' : 'inputPhotoFileLocation', 'id' => $deserialized['id'], 'access_hash' => $deserialized['access_hash'], 'file_reference' => '', 'thumb_size' => (string) $deserialized['thumbnail_type']];
$res['name'] = $deserialized['id'] . '_' . $deserialized['thumbnail_type'];
case THUMBNAIL:
$res['InputFileLocation'] = [
'_' => $photoSize->getThumbFileType() <= PHOTO ? 'inputPhotoFileLocation' : 'inputDocumentFileLocation',
'id' => $fileId->getId(),
'access_hash' => $fileId->getAccessHash(),
'file_reference' => $fileId->getFileReference(),
'thumb_size' => $photoSize->getThumbType()
];
$res['name'] = $fileId->getId().'_'.$photoSize->getThumbType();
$res['ext'] = 'jpg';
$res['mime'] = 'image/jpeg';
$res['InputMedia'] = ['_' => $deserialized['file_type'] >= 3 ? 'inputMediaDocument' : 'inputMediaPhoto', 'id' => ['_' => $deserialized['file_type'] >= 3 ? 'inputDocument' : 'inputPhoto', 'id' => $deserialized['id'], 'access_hash' => $deserialized['access_hash']]];
$res['InputMedia'] = [
'_' => $photoSize->getThumbFileType() <= PHOTO ? 'inputMediaPhoto' : 'inputMediaDocument',
'id' => [
'_' => $photoSize->getThumbFileType() <= PHOTO ? 'inputPhoto' : 'inputDocument',
'id' => $fileId->getId(),
'access_hash' => $fileId->getAccessHash(),
'file_reference' => $fileId->getFileReference(),
]
];
return $res;
case 'bot_photo':
if ($deserialized['photosize_source'] === 0) {
$constructor['id'] = $deserialized['id'];
$constructor['access_hash'] = $deserialized['access_hash'];
unset($deserialized['id'], $deserialized['access_hash']);
$deserialized['_'] = $deserialized['secret'] ? 'fileLocation' : 'fileLocationToBeDeprecated';
$constructor['sizes'][0] = ['_' => 'photoSize', 'type' => '', 'location' => $deserialized];
$res['MessageMedia'] = ['_' => 'messageMediaPhoto', 'photo' => $constructor, 'caption' => ''];
return $res;
case PHOTO:
$constructor = [
'_' => 'photo',
'id' => $fileId->getId(),
'access_hash' => $fileId->getAccessHash(),
'file_reference' => $fileId->getFileReference(),
'dc_id' => $fileId->getDcId(),
'sizes' => []
];
$constructor['sizes'][] = [
'_' => 'photoSize',
'type' => $photoSize instanceof PhotoSizeSourceThumbnail ? $photoSize->getThumbType() : '',
'location' => [
'_' => $photoSize instanceof PhotoSizeSourceLegacy ? 'fileLocation' : 'fileLocationToBeDeprecated',
'dc_id' => $fileId->getDcId(),
'local_id' => $fileId->getLocalId(),
'volume_id' => $fileId->getVolumeId(),
'secret' => $photoSize instanceof PhotoSizeSourceLegacy ? $photoSize->getSecret() : ''
]
];
$res['MessageMedia'] = [
'_' => 'messageMediaPhoto',
'photo' => $constructor,
'caption' => ''
];
return $res;
case VOICE:
$attribute = [
'_' => 'documentAttributeAudio',
'voice' => true
];
break;
case VIDEO:
$attribute = [
'_' => 'documentAttributeVideo',
'round_message' => false
];
break;
case DOCUMENT:
$attribute = [];
break;
case STICKER:
$attribute = [
'_' => 'documentAttributeSticker',
'alt' => ''
];
if ($photoSize instanceof PhotoSizeSourceStickersetThumbnail) {
$attribute['stickerset'] = [
'_' => 'inputStickerSetID',
'id' => $photoSize->getStickerSetId(),
'access_hash' => $photoSize->getStickerSetAccessHash()
];
}
$res['MessageMedia'] = ['_' => 'photo', 'id' => $deserialized['id'], 'access_hash' => $deserialized['access_hash'], 'sizes' => [['_' => 'photoSize', 'type' => $deserialized['thumbnail_type'], 'location' => ['_' => 'fileLocationToBeDeprecated', 'local_id' => $deserialized['local_id'], 'volume_id' => $deserialized['local_id']]]], 'dc_id' => $deserialized['dc_id']];
return $res;
case 'bot_voice':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => true]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_video':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeVideo', 'round_message' => false]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_document':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => []]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_sticker':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeSticker']]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_audio':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAudio', 'voice' => false]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_gif':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeAnimated']]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
case 'bot_video_note':
unset($deserialized['_']);
$constructor = \array_merge($deserialized, ['_' => 'document', 'mime_type' => '', 'attributes' => [['_' => 'documentAttributeVideo', 'round_message' => true]]]);
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
break;
case AUDIO:
$attribute = ['_' => 'documentAttributeAudio', 'voice' => false];
break;
case ANIMATION:
$attribute = ['_' => 'documentAttributeAnimated'];
break;
case VIDEO_NOTE:
$attribute = ['_' => 'documentAttributeVideo', 'round_message' => true];
break;
default:
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['file_type_invalid'], $type));
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['file_type_invalid'], $fileId->getTypeName()));
}
$constructor = [
'_' => 'document',
'id' => $fileId->getId(),
'access_hash' => $fileId->getAccessHash(),
'file_reference' => $fileId->getFileReference(),
'dc_id' => $fileId->getDcId(),
'mime_type' => '',
'attributes' => [$attribute]
];
$res['MessageMedia'] = ['_' => 'messageMediaDocument', 'document' => $constructor, 'caption' => ''];
return $res;
}
}

View File

@ -273,7 +273,7 @@ class TL
}
}
if (empty($TL_dict) || empty($TL_dict['constructors']) || !isset($TL_dict['methods'])) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['src_file_invalid'] . $file);
throw new Exception(\danog\MadelineProto\Lang::$current_lang['src_file_invalid'].$file);
}
$this->API->logger->logger(\danog\MadelineProto\Lang::$current_lang['translating_obj'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
foreach ($TL_dict['constructors'] as $elem) {
@ -420,6 +420,9 @@ class TL
if (\is_string($object) && \strlen($object) === 9 && $object[0] === 'a') {
return \substr($object, 1);
}
if (\is_array($object) && \count($object) === 2) {
return \pack('l2', ...$object); // For bot API on 32bit
}
if (!\is_numeric($object)) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['not_numeric']);
}
@ -454,18 +457,18 @@ class TL
if (!\is_string($object)) {
throw new Exception("You didn't provide a valid string");
}
$object = \pack('C*', ...\unpack('C*', $object));
//$object = \pack('C*', ...\unpack('C*', $object));
$l = \strlen($object);
$concat = '';
if ($l <= 253) {
$concat .= \chr($l);
$concat .= $object;
$concat .= \pack('@' . \danog\MadelineProto\Tools::posmod(-$l - 1, 4));
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l - 1, 4));
} else {
$concat .= \chr(254);
$concat .= \substr(\danog\MadelineProto\Tools::packSignedInt($l), 0, 3);
$concat .= $object;
$concat .= \pack('@' . \danog\MadelineProto\Tools::posmod(-$l, 4));
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l, 4));
}
return $concat;
case 'bytes':
@ -480,12 +483,12 @@ class TL
if ($l <= 253) {
$concat .= \chr($l);
$concat .= $object;
$concat .= \pack('@' . \danog\MadelineProto\Tools::posmod(-$l - 1, 4));
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l - 1, 4));
} else {
$concat .= \chr(254);
$concat .= \substr(\danog\MadelineProto\Tools::packSignedInt($l), 0, 3);
$concat .= $object;
$concat .= \pack('@' . \danog\MadelineProto\Tools::posmod(-$l, 4));
$concat .= \pack('@'.\danog\MadelineProto\Tools::posmod(-$l, 4));
}
return $concat;
case 'Bool':
@ -499,7 +502,7 @@ class TL
throw new Exception(\danog\MadelineProto\Lang::$current_lang['array_invalid']);
}
if (isset($object['_'])) {
throw new Exception('You must provide an array of ' . $type['subtype'] . ' objects, not a ' . $type['subtype'] . " object. Example: [['_' => " . $type['subtype'] . ', ... ]]');
throw new Exception('You must provide an array of '.$type['subtype'].' objects, not a '.$type['subtype']." object. Example: [['_' => ".$type['subtype'].', ... ]]');
}
$concat = $this->constructors->findByPredicate('vector')['id'];
$concat .= \danog\MadelineProto\Tools::packUnsignedInt(\count($object));
@ -560,7 +563,7 @@ class TL
$constructorData = $this->constructors->findByPredicate('inputMessageEntityMentionName');
}
$concat = $bare ? '' : $constructorData['id'];
return $concat . (yield from $this->serializeParams($constructorData, $object, '', $layer));
return $concat.(yield from $this->serializeParams($constructorData, $object, '', $layer));
}
/**
* Serialize method.
@ -637,9 +640,9 @@ class TL
}
$tl = $this->methods->findByMethod($method);
if ($tl === false) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['method_not_found'] . $method);
throw new Exception(\danog\MadelineProto\Lang::$current_lang['method_not_found'].$method);
}
return $tl['id'] . (yield from $this->serializeParams($tl, $arguments, $method));
return $tl['id'].(yield from $this->serializeParams($tl, $arguments, $method));
}
/**
* Serialize parameters.
@ -724,11 +727,11 @@ class TL
$serialized .= \pack('@4');
continue;
}
if (($id = $this->constructors->findByPredicate(\lcfirst($current_argument['type']) . 'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
if (($id = $this->constructors->findByPredicate(\lcfirst($current_argument['type']).'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
$serialized .= $id['id'];
continue;
}
if (($id = $this->constructors->findByPredicate('input' . $current_argument['type'] . 'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
if (($id = $this->constructors->findByPredicate('input'.$current_argument['type'].'Empty', isset($tl['layer']) ? $tl['layer'] : -1)) && $id['type'] === $current_argument['type']) {
$serialized .= $id['id'];
continue;
}
@ -831,7 +834,7 @@ class TL
throw new Exception(\danog\MadelineProto\Lang::$current_lang['length_too_big']);
}
if ($l === 254) {
$long_len = \unpack('V', \stream_get_contents($stream, 3) . \chr(0))[1];
$long_len = \unpack('V', \stream_get_contents($stream, 3).\chr(0))[1];
$x = \stream_get_contents($stream, $long_len);
$resto = \danog\MadelineProto\Tools::posmod(-$long_len, 4);
if ($resto > 0) {
@ -853,7 +856,7 @@ class TL
$constructorData = $this->constructors->findById($id);
if ($constructorData === false) {
$constructorData = $this->methods->findById($id);
$constructorData['predicate'] = 'method_' . $constructorData['method'];
$constructorData['predicate'] = 'method_'.$constructorData['method'];
}
if ($constructorData === false) {
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error_id'], $type['type'], \bin2hex(\strrev($id))));
@ -865,7 +868,7 @@ class TL
case 'vector':
break;
default:
throw new Exception(\danog\MadelineProto\Lang::$current_lang['vector_invalid'] . $constructorData['predicate']);
throw new Exception(\danog\MadelineProto\Lang::$current_lang['vector_invalid'].$constructorData['predicate']);
}
// no break
case 'vector':
@ -881,7 +884,7 @@ class TL
$checkType = \substr($type['type'], 1);
$constructorData = $this->constructors->findByType($checkType);
if ($constructorData === false) {
throw new Exception(\danog\MadelineProto\Lang::$current_lang['constructor_not_found'] . $checkType);
throw new Exception(\danog\MadelineProto\Lang::$current_lang['constructor_not_found'].$checkType);
}
} else {
$constructorData = $this->constructors->findByPredicate($type['type']);
@ -893,7 +896,7 @@ class TL
if ($constructorData === false) {
throw new Exception(\sprintf(\danog\MadelineProto\Lang::$current_lang['type_extract_error_id'], $type['type'], \bin2hex(\strrev($id))));
}
$constructorData['predicate'] = 'method_' . $constructorData['method'];
$constructorData['predicate'] = 'method_'.$constructorData['method'];
}
}
}

View File

@ -114,29 +114,13 @@ export TEST_USERNAME=danogentili
export TEST_DESTINATION_GROUPS='["@danogentili"]'
export MTPROTO_SETTINGS='{"logger":{"logger_level":5}}'
php tools/makephar.php $HOME/phar5 "madeline$php$branch.phar" $TRAVIS_COMMIT
cp tests/testing.php tests/testingBackup.php
#set +e
#tests/testing.php <<EOF
#m
#$API_ID
#$API_HASH
#b
#$BOT_TOKEN
#n
#n
#n
#
#EOF
#export TRAVIS_PHAR="madeline$php$branch.phar"
#set -e
#tests/testing.php
#cp tests/testingBackup.php tests/testing.php
#rm testing.madeline
tests/testing.php <<EOF
runTestSimple()
{
tests/testing.php
}
runTest()
{
tests/testing.php <<EOF
m
$API_ID
$API_HASH
@ -147,8 +131,28 @@ n
n
EOF
}
echo "Testing with previous version..."
cp tests/testing.php tests/testingBackup.php
runTest
echo "Testing with new version (upgrade)..."
php tools/makephar.php $HOME/phar5 "madeline$php$branch.phar" $TRAVIS_COMMIT
export TRAVIS_PHAR="madeline$php$branch.phar"
runTestSimple
echo "Testing with new version (restart)"
cp tests/testingBackup.php tests/testing.php
tests/testing.php
rm testing.madeline
runTest
echo "Testing with new version (reload)"
cp tests/testingBackup.php tests/testing.php
runTestSimple
eval "$(ssh-agent -s)"
echo -e "$private_key" > madeline_rsa