Exemplo n.º 1
0
    /**
     * @test
     */
    public function shouldAllowGetPreviouslySetConfig()
    {
        $config = new PaymentConfig();

        $config->setConfig(array('foo' => 'fooVal'));

        $this->assertEquals(array('foo' => 'fooVal'), $config->getConfig());
    }
    /**
     * @test
     */
    public function shouldCreatePaymentUsingConfigOnGetPayment()
    {
        $paymentConfig = new PaymentConfig();
        $paymentConfig->setConfig($config = array('foo' => 'fooVal', 'bar' => 'barVal'));
        $paymentConfig->setFactoryName($factoryName = 'theFactoryName');
        $paymentConfig->setPaymentName($paymentName = 'thePaymentName');

        $payment = new Payment();

        $paymentFactoryMock = $this->getMock('Payum\Core\PaymentFactoryInterface');
        $paymentFactoryMock
            ->expects($this->once())
            ->method('create')
            ->with($config)
            ->willReturn($payment)
        ;

        $staticRegistryMock = $this->createRegistryMock();
        $staticRegistryMock
            ->expects($this->once())
            ->method('getPaymentFactory')
            ->with($factoryName)
            ->willReturn($paymentFactoryMock)
        ;

        $storageMock = $this->createStorageMock();
        $storageMock
            ->expects($this->once())
            ->method('findBy')
            ->with(array('paymentName' => $paymentName))
            ->willReturn($paymentConfig)
        ;

        $registry = new DynamicRegistry($storageMock, $staticRegistryMock);

        $this->assertSame($payment, $registry->getPayment($paymentName));
    }
    /**
     * @test
     */
    public function shouldAddConfigFieldsIfPaymentConfigHasFactorySet()
    {
        $this->fooPaymentFactoryMock
            ->expects($this->once())
            ->method('createConfig')
            ->with(array())
            ->willReturn(array(
                'payum.default_options' => array(
                    'username' => 'defaultName',
                    'password' => 'defaultPass',
                    'sandbox' => true,
                ),
                'payum.required_options' => array(),
            ))
        ;

        $paymentConfig = new PaymentConfig();
        $paymentConfig->setFactoryName('foo');
        $paymentConfig->setPaymentName('theName');
        $paymentConfig->setConfig(array(
            'username' => 'modelName',
            'password' => 'modelPass',
            'sandbox' => false,
        ));

        $form = $this->formFactory->create('payum_payment_config', $paymentConfig);


        $this->assertTrue($form->has('config'));

        $this->assertTrue($form->get('config')->has('username'));
        $this->assertEquals('modelName', $form->get('config')->get('username')->getData());

        $this->assertTrue($form->get('config')->has('password'));
        $this->assertEquals('modelPass', $form->get('config')->get('password')->getData());

        $this->assertTrue($form->get('config')->has('sandbox'));
        $this->assertEquals(false, $form->get('config')->get('sandbox')->getData());
    }