forked from iron-bound-designs/exchange-addon-licensing
/
test-product.php
118 lines (96 loc) · 3.04 KB
/
test-product.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Tests for Product model.
*
* @author Iron Bound Designs
* @since 1.0
*/
use ITELIC\Product;
use ITELIC\Release;
/**
* Class ITELIC_Test_Product
*/
class ITELIC_Test_Product extends ITELIC_UnitTestCase {
public function test_getting_latest_release_for_stable_track() {
/** @var Product $product */
$product = $this->product_factory->create_and_get();
$file = $this->factory->attachment->create_object( 'file.zip', $product->ID, array(
'post_mime_type' => 'application/zip'
) );
/** @var Release $r1 */
$r1 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.0',
'type' => Release::TYPE_MAJOR,
) );
$r1->activate( \ITELIC\make_date_time( '-1 week' ) );
/** @var Release $r2 */
$r2 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.1',
'type' => Release::TYPE_MAJOR,
) );
$r2->activate( \ITELIC\make_date_time( '-2 days' ) );
/** @var Release $r3 */
$r3 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.2-alpha',
'type' => Release::TYPE_PRERELEASE,
) );
$key = $this->key_factory->create_and_get( array(
'product' => $product->ID,
'customer' => 1
) );
$activation = $this->activation_factory->create_and_get( array(
'key' => $key,
'location' => 'example.com'
) );
$latest = $product->get_latest_release_for_activation( $activation );
$this->assertEquals( $r2->get_pk(), $latest->get_pk() );
}
public function test_getting_latest_release_for_pre_release_track() {
/** @var Product $product */
$product = $this->product_factory->create_and_get();
$file = $this->factory->attachment->create_object( 'file.zip', $product->ID, array(
'post_mime_type' => 'application/zip'
) );
/** @var Release $r1 */
$r1 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.0',
'type' => Release::TYPE_MAJOR,
) );
$r1->activate( \ITELIC\make_date_time( '-1 week' ) );
/** @var Release $r2 */
$r2 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.1',
'type' => Release::TYPE_MAJOR,
) );
$r2->activate( \ITELIC\make_date_time( '-2 days' ) );
/** @var Release $r3 */
$r3 = $this->release_factory->create_and_get( array(
'product' => $product->ID,
'file' => $file,
'version' => '1.2-alpha',
'type' => Release::TYPE_PRERELEASE,
) );
$r3->activate( \ITELIC\make_date_time( 'yesterday' ) );
$key = $this->key_factory->create_and_get( array(
'product' => $product->ID,
'customer' => 1
) );
$activation = $this->activation_factory->create_and_get( array(
'key' => $key,
'location' => 'example.com',
'track' => 'pre-release'
) );
$latest = $product->get_latest_release_for_activation( $activation );
$this->assertEquals( $r3->get_pk(), $latest->get_pk() );
}
}