testCreateReturnsAPaymentIdLargerThanZero()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
require_once 'Intraface/modules/onlinepayment/OnlinePayment.php';
3
require_once 'Intraface/functions.php';
4
require_once 'DB/Sql.php';
5
6
class OnlinePaymentTest extends PHPUnit_Framework_TestCase
7
{
8
    private $kernel;
0 ignored issues
show
Unused Code introduced by
The property $kernel is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
9
10
    function setUp()
11
    {
12
        $db = MDB2::singleton(DB_DSN);
13
        $db->query('TRUNCATE onlinepayment');
14
    }
15
16 View Code Duplication
    function createKernel()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
    {
18
        $kernel = new Stub_Kernel;
19
        $kernel->setting->set('intranet', 'onlinepayment.provider_key', 1);
20
        $kernel->setting->set('intranet', 'onlinepayment.quickpay.md5_secret', 'abc');
21
        $kernel->setting->set('intranet', 'onlinepayment.quickpay.merchant_id', 12345678);
22
        return $kernel;
23
    }
24
25
    function testConstruct()
26
    {
27
        $this->markTestIncomplete(
28
            'This test has not been implemented yet - QP changed since.'
29
        );
30
        $onlinepayment = new OnlinePayment($this->createKernel());
31
        $this->assertEquals('OnlinePayment', get_class($onlinepayment));
32
    }
33
34
    function testFactoryWithTypeProvider()
35
    {
36
        $this->markTestIncomplete(
37
            'This test has not been implemented yet - QP changed since.'
38
        );
39
        $onlinepayment = OnlinePayment::factory($this->createKernel(), 'provider', 'quickpay');
40
        $this->assertEquals('OnlinePaymentQuickPay', get_class($onlinepayment));
41
    }
42
43
    function testSaveWithEmptyArray()
44
    {
45
        $this->markTestIncomplete(
46
            'This test has not been implemented yet - QP changed since.'
47
        );
48
        $onlinepayment = new OnlinePayment($this->createKernel());
49
        $this->assertEquals(0, $onlinepayment->save(array()));
50
        $this->assertEquals(2, $onlinepayment->error->count());
51
    }
52
53
    function testSaveWithValidDataReturnsInteger()
54
    {
55
        $this->markTestIncomplete(
56
            'This test has not been implemented yet - QP changed since.'
57
        );
58
        $onlinepayment = new OnlinePayment($this->createKernel());
59
        $this->assertTrue($onlinepayment->save(array(
60
            'belong_to' => 'invoice',
61
            'belong_to_id' => 1,
62
            'transaction_number' => 1,
63
            'transaction_status' => '000',
64
            'amount' => 100)) > 0);
65
    }
66
67
    function testUpdateWithValidDataReturnsInteger()
68
    {
69
        $this->markTestIncomplete(
70
            'This test has not been implemented yet - QP changed since.'
71
        );
72
        $onlinepayment = new OnlinePayment($this->createKernel());
73
        $data = array(
74
            'belong_to' => 'invoice',
75
            'belong_to_id' => 1,
76
            'transaction_number' => 1,
77
            'transaction_status' => '000',
78
            'amount' => 100,
79
            'original_amount' => 100,
80
            'dk_original_amount' => 100,
81
            'dk_amount' => 100);
82
        $this->assertTrue($onlinepayment->save($data) > 0);
83
        // $this->assertTrue($onlinepayment->setStatus('authorized'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
84
        $id = $onlinepayment->update($data);
85
        $this->assertTrue($id > 0);
86
    }
87
88
    function testLoad()
89
    {
90
        $this->markTestIncomplete(
91
            'This test has not been implemented yet - QP changed since.'
92
        );
93
        $onlinepayment = new OnlinePayment($this->createKernel());
94
        $onlinepayment->save(array(
95
            'belong_to' => 'invoice',
96
            'belong_to_id' => 1,
97
            'transaction_number' => 1,
98
            'transaction_status' => '000',
99
            'amount' => 100));
100
101
        $onlinepayment = new OnlinePayment($this->createKernel(), 1);
102
103
        $this->assertEquals(1, $onlinepayment->get('id'));
104
        $this->assertEquals(date('d-m-Y'), $onlinepayment->get('dk_date_created'));
105
        $this->assertEquals(2, $onlinepayment->get('belong_to_key'));
106
        $this->assertEquals('invoice', $onlinepayment->get('belong_to'));
107
        $this->assertEquals(1, $onlinepayment->get('belong_to_id'));
108
        $this->assertEquals('authorized', $onlinepayment->get('status'));
109
        $this->assertEquals(100, $onlinepayment->get('amount'));
110
        $this->assertEquals('100,00', $onlinepayment->get('dk_amount'));
111
    }
112
113
    function testCreateReturnsAPaymentIdLargerThanZero()
114
    {
115
        $this->markTestIncomplete(
116
            'This test has not been implemented yet - QP changed since.'
117
        );
118
        $onlinepayment = new OnlinePayment($this->createKernel());
119
        $id = $onlinepayment->create();
120
        $this->assertTrue($id > 0);
121
    }
122
}
123