-
-
Notifications
You must be signed in to change notification settings - Fork 622
Expand file tree
/
Copy pathAddonLicenseTest.php
More file actions
111 lines (91 loc) · 2.71 KB
/
AddonLicenseTest.php
File metadata and controls
111 lines (91 loc) · 2.71 KB
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
<?php
namespace Tests\Licensing;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Addon;
use Statamic\Licensing\AddonLicense;
use Tests\TestCase;
class AddonLicenseTest extends TestCase
{
use LicenseTests;
protected function license($response = [])
{
Addon::shouldReceive('get')->with('test/addon')
->andReturn(new FakeAddonLicenseAddon('Test Addon', '1.2.3', 'rad'));
return new AddonLicense('test/addon', $response);
}
#[Test]
public function it_gets_the_addons_name()
{
$this->assertEquals($this->license()->name(), 'Test Addon');
}
#[Test]
public function it_gets_the_addons_version()
{
$this->assertEquals($this->license()->version(), '1.2.3');
}
#[Test]
public function it_gets_the_addons_edition()
{
$this->assertEquals($this->license()->edition(), 'rad');
}
#[Test]
public function it_checks_if_it_exists_on_the_marketplace()
{
$this->assertTrue($this->license(['exists' => true])->existsOnMarketplace());
$this->assertFalse($this->license(['exists' => false])->existsOnMarketplace());
}
#[Test]
public function it_gets_the_invalid_reason_for_a_range_issue()
{
$license = $this->license([
'reason' => 'outside_license_range',
'range' => ['2', '4'],
]);
$key = 'statamic::messages.licensing_error_outside_license_range';
$message = trans($key, ['start' => '2', 'end' => '4']);
$this->assertNotEquals($key, $message);
$this->assertEquals($message, $license->invalidReason());
}
#[Test]
public function it_gets_the_invalid_reason_for_a_edition_issue()
{
$license = $this->license([
'reason' => 'invalid_edition',
'edition' => 'one',
]);
$key = 'statamic::messages.licensing_error_invalid_edition';
$message = trans($key, ['edition' => 'one']);
$this->assertNotEquals($key, $message);
$this->assertEquals($message, $license->invalidReason());
}
#[Test]
public function it_gets_the_version_limit()
{
$license = $this->license(['version_limit' => 4]);
$this->assertEquals(4, $license->versionLimit());
}
}
class FakeAddonLicenseAddon
{
protected $name;
protected $version;
protected $edition;
public function __construct($name, $version, $edition)
{
$this->name = $name;
$this->version = $version;
$this->edition = $edition;
}
public function name()
{
return $this->name;
}
public function version()
{
return $this->version;
}
public function edition()
{
return $this->edition;
}
}