Passed
Push — develop ( b405cd...984b92 )
by Remco
05:42
created

SubscriptionTest::test_get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Subscription test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2018 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Payments
9
 */
10
11
namespace Pronamic\WordPress\Pay\Subscriptions;
12
13
use WP_UnitTestCase;
14
15
/**
16
 * Subscription test
17
 *
18
 * @author Remco Tolsma
19
 * @version 1.0
20
 */
21
class SubscriptionTest extends WP_UnitTestCase {
22
	/**
23
	 * Test construct subscription object.
24
	 */
25
	public function test_construct() {
26
		$subscription = new Subscription();
27
28
		$this->assertInstanceOf( __NAMESPACE__ . '\Subscription', $subscription );
29
	}
30
31
	/**
32
	 * Test set and get.
33
	 *
34
	 * @dataProvider get_and_set_provider
35
	 */
36
	public function test_set_and_get( $set_function, $get_function, $value ) {
37
		$subscription = new Subscription();
38
39
		$subscription->$set_function( $value );
40
41
		$this->assertEquals( $value, $subscription->$get_function() );
42
	}
43
44
	public function get_and_set_provider() {
45
		return array(
46
			array( 'set_id',             'get_id',             uniqid()    ),
47
			array( 'set_status',         'get_status',         'completed' ),
48
			array( 'set_transaction_id', 'get_transaction_id', uniqid()    ),
49
		);
50
	}
51
52
	/**
53
	 * Test set.
54
	 *
55
	 * @dataProvider set_provider
56
	 */
57
	public function test_set( $set_function, $property, $value ) {
58
		$subscription = new Subscription();
59
60
		$subscription->$set_function( $value );
61
62
		$this->assertEquals( $value, $subscription->$property );
63
	}
64
65
	public function set_provider() {
66
		return array(
67
			array( 'set_consumer_name', 'consumer_name', 'John Doe' ),
68
			array( 'set_consumer_iban', 'consumer_iban', 'NL56 RABO 0108 6347 79' ),
69
			array( 'set_consumer_bic',  'consumer_bic',  'RABONL2U' ),
70
		);
71
	}
72
73
	/**
74
	 * Test get.
75
	 *
76
	 * @dataProvider get_provider
77
	 */
78
	public function test_get( $property, $get_function, $value ) {
79
		$subscription = new Subscription();
80
81
		$subscription->$property = $value;
82
83
		$this->assertEquals( $value, $subscription->$get_function() );
84
	}
85
86
	public function get_provider() {
87
		return array(
88
			array( 'key',                 'get_key',             uniqid() ),
89
			array( 'source',              'get_source',          'woocommerce' ),
90
			array( 'source_id',           'get_source_id',       '1234' ),
91
			array( 'frequency',           'get_frequency',       'daily' ),
92
			array( 'interval',            'get_interval',        '1' ),
93
			array( 'interval_period',     'get_interval_period', 'Y' ),
94
			array( 'description',         'get_description',     'Lorem ipsum dolor sit amet, consectetur.' ),
95
			array( 'currency',            'get_currency',        'EUR' ),
96
			array( 'amount',              'get_amount',          89.95 ),
97
		);
98
	}
99
100
	/**
101
	 * Test getting no subscription.
102
	 *
103
	 * @see https://github.com/easydigitaldownloads/easy-digital-downloads/blob/2.8.18/tests/tests-payment-class.php#L70-L79
104
	 */
105
	public function test_getting_no_subscription() {
106
		$subscription = new Subscription();
107
108
		$this->assertNull( $subscription->get_id() );
109
	}
110
}
111