Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/dev/tests/integration/testsuite/Magento/Paypal/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/dev/tests/integration/testsuite/Magento/Paypal/Model/HostedproTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Paypal\Model;

use Magento\Framework\DataObject;
use Magento\Paypal\Model\Api\Nvp;
use Magento\Paypal\Model\Config;
use Magento\Paypal\Model\Hostedpro;
use Magento\Paypal\Model\Hostedpro\RequestFactory;
use Magento\Paypal\Model\ProFactory;
use Magento\Sales\Model\Order;
use Magento\TestFramework\Helper\Bootstrap;

/**
 * Class HostedproTest
 * @package Magento\Paypal\Model
 */
class HostedproTest extends \PHPUnit\Framework\TestCase
{
    /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    private $objectManager;

    /**
     * @var \Magento\Paypal\Model\Hostedpro
     */
    private $model;

    /**
     * @var \Magento\Paypal\Model\Api\Nvp|\PHPUnit\Framework\MockObject\MockObject
     */
    private $api;

    protected function setUp(): void
    {
        $this->objectManager = Bootstrap::getObjectManager();

        $this->api = $this->getMockBuilder(Nvp::class)
            ->disableOriginalConstructor()
            ->setMethods(['call'])
            ->getMock();

        $proFactory = $this->getProFactory();

        $this->model = $this->objectManager
            ->create(Hostedpro::class, [
                'proFactory' => $proFactory
            ]);
    }

    /**
     * @covers \Magento\Paypal\Model\Hostedpro::initialize
     * @magentoDataFixture Magento/Paypal/_files/order_hostedpro.php
     */
    public function testInitialize()
    {
        /** @var \Magento\Sales\Model\Order $order */
        $order = $this->objectManager->create(Order::class);
        $order->loadByIncrementId('100000001');
        $payment = $order->getPayment();

        $this->model->setInfoInstance($payment);

        $this->api->expects(static::once())
            ->method('call')
            ->willReturn([
                'EMAILLINK' => 'https://securepayments.sandbox.paypal.com/webapps/HostedSoleSolutionApp/webflow/'
            ]);

        $state = $this->objectManager->create(DataObject::class);
        $this->model->initialize(Config::PAYMENT_ACTION_AUTH, $state);

        static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getState());
        static::assertEquals(Order::STATE_PENDING_PAYMENT, $state->getStatus());
        static::assertFalse($state->getIsNotified());
    }

    /**
     * Get mock for config
     * @return \PHPUnit\Framework\MockObject\MockObject
     */
    protected function getConfig()
    {
        $config = $this->getMockBuilder(Config::class)
            ->disableOriginalConstructor()
            ->setMethods(['getValue'])
            ->getMock();
        $config->expects(static::any())
            ->method('getValue')
            ->with('payment_action')
            ->willReturn(Config::PAYMENT_ACTION_AUTH);
        return $config;
    }

    /**
     * Create mock for Pro factory
     * @return \PHPUnit\Framework\MockObject\MockObject
     */
    protected function getProFactory()
    {
        $pro = $this->getMockBuilder(Pro::class)
            ->disableOriginalConstructor()
            ->setMethods(['getApi', 'setMethod', 'getConfig', '__wakeup'])
            ->getMock();

        $config = $this->getConfig();
        $pro->expects(static::any())
            ->method('getConfig')
            ->willReturn($config);
        $pro->expects(static::any())
            ->method('getApi')
            ->willReturn($this->api);

        $proFactory = $this->getMockBuilder(ProFactory::class)
            ->disableOriginalConstructor()
            ->setMethods(['create'])
            ->getMock();
        $proFactory->expects(static::once())
            ->method('create')
            ->willReturn($pro);
        return $proFactory;
    }
}

Spamworldpro Mini