403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/wbs24.saleemailcvetdvor/tests/unit/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/cvetdv.ru/bitrix/modules/wbs24.saleemailcvetdvor/tests/unit/MainTest.php
<?php
namespace Wbs24\Saleemailcvetdvor;

use Bitrix\Main\Loader;

class MainTest extends BitrixTestCase
{
    public function test_getEmail()
    {
        // входные параметры
        $orderCity = 'Фрязево';

        // результат для проверки
        $expectedResult = 'Vpolceni.al@yandex.ru';

        // заглушки
        Loader::includeModule('iblock');

        $CIBlockResultStub = $this->createMock(\CIBlockResult::class);
        $fetchResults = [
            [
                'ID' => 11,
                'NAME' => 'Фрязево',
            ],
            false,
        ];
        $CIBlockResultStub->method('Fetch')
            ->will($this->onConsecutiveCalls(...$fetchResults));

        $CIBlockElementStub = $this->createMock(Wrappers\CIBlockElement::class);
        $CIBlockElementStub->method('GetList')
            ->willReturn($CIBlockResultStub);

        $OptionStub = $this->createMock(Wrappers\Option::class);
        $OptionStub->method('get')
            ->will($this->returnCallback(
                function ($moduleId, $option) {
                    if ($option == 'destanation_iblock_id') {
                        $value = 1;
                    }
                    if ($option == 'city_1') {
                        $value = 'Александров';
                    }
                    if ($option == 'email_1') {
                        $value = 'Vpolceni.al@yandex.ru';
                    }
                    if ($option == 'sender_city_11') {
                        $value = 'Александров';
                    }

                    return $value ?? '';
                }
            ));

        // вычисление результата
        $object = new Main([
            'Option' => $OptionStub,
            'CIBlockElement' => $CIBlockElementStub,
            'Admin' => new \stdClass(),
        ]);
        $result = $object->getEmail($orderCity);

        // проверка
        $this->assertEquals($expectedResult, $result);
    }

    public function test_getRegionFromDelivery()
    {
        // входные параметры
        $OrderStub = $this->getMockBuilder(\stdClass::class)
            ->setMethods(['getDeliverySystemId'])
            ->getMock();
        $OrderStub->method('getDeliverySystemId')
            ->willReturn([1]);

        // результат для проверки
        $expectedResult = 'Москва';

        // заглушки
        // Option
        $OptionStub = $this->createMock(Wrappers\Option::class);
        $OptionStub->method('get')
            ->will($this->returnCallback(
                function ($moduleId, $option) {
                    //if ($option == 'some') {
                    //    $value = '';
                    //}

                    return '';
                }
            ));

        // Admin
        $AdminStub = $this->createMock(Admin::class);
        $AdminStub->method('getSenderCityList')
            ->willReturn([
                'Москва',
                'Санкт-Питербург',
                'Сочи',
            ]);

        // DeliveryServices
        $ResultStub = $this->getMockBuilder(\stdClass::class)
            ->setMethods(['fetchAll'])
            ->getMock();
        $allFetchResults = [
            [
                'ID' => 1,
                'NAME' => 'Самовывоз в г. Москва',
            ],
        ];
        $ResultStub->method('fetchAll')
            ->willReturn($allFetchResults);

        $DeliveryServicesStub = $this->getMockBuilder(Wrappers\DeliveryServices::class)
            ->setMethods(['getList'])
            ->getMock();
        $DeliveryServicesStub->method('getList')
            ->willReturn($ResultStub);

        // вычисление результата
        $object = new Main([
            'Option' => $OptionStub,
            'Admin' => $AdminStub,
            'DeliveryServices' => $DeliveryServicesStub,
        ]);
        $result = $object->getRegionFromDelivery($OrderStub);

        // проверка
        $this->assertEquals($expectedResult, $result);
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit