-
-
Notifications
You must be signed in to change notification settings - Fork 529
/
Copy pathMakeUrlTest.php
169 lines (162 loc) · 5.35 KB
/
MakeUrlTest.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
/*
* This file is part of the MODX Revolution package.
*
* Copyright (c) MODX, LLC
*
* For complete copyright and license information, see the COPYRIGHT and LICENSE
* files found in the top-level directory of this distribution.
*
*/
/**
* Tests related to verifying and setting up the test environment.
*
* @package modx-test
* @subpackage modx
* @group Cases
* @group Request
* @group MakeUrl
*/
class MakeUrlTest extends MODxTestCase {
public function setUp(): void
{
parent::setUp();
/** @var modResource $resource */
$resource = $this->modx->newObject('modResource');
$resource->fromArray(array(
'id' => 12345,
'pagetitle' => 'Unit Test Resource',
'type' => 'document',
'contentType' => 1,
'longtitle' => '',
'description' => '',
'alias' => 'unit-test',
'published' => true,
'parent' => 0,
'isfolder' => true,
'menuindex' => 99999,
'content' => '<h2>A Unit Test Resource</h2>',
'template' => 0,
'searchable' => true,
'cacheable' => true,
'deleted' => false,
'menutitle' => 'Unit Test Resource',
'hidemenu' => false,
'class_key' => 'modDocument',
'context_key' => 'web',
'content_type' => 1,
),'',true,true);
$resource->save();
$resource = $this->modx->newObject('modResource');
$resource->fromArray(array(
'id' => 12346,
'parent' => 12345,
'pagetitle' => 'Unit Test Child Resource',
'type' => 'document',
'contentType' => 1,
'longtitle' => '',
'description' => '',
'alias' => 'child',
'published' => true,
'isfolder' => false,
'menuindex' => 99999,
'content' => '<h2>A Unit Test Child Resource</h2>',
'template' => 0,
'searchable' => true,
'cacheable' => true,
'deleted' => false,
'menutitle' => 'Unit Test Child Resource',
'hidemenu' => false,
'class_key' => 'modDocument',
'context_key' => 'web',
'content_type' => 1,
),'',true,true);
$resource->save();
$this->modx->setOption('friendly_urls', true);
$this->modx->setOption('automatic_alias', true);
$this->modx->setOption('use_alias_path', true);
$this->modx->setOption('cache_alias_map', false);
//$this->modx->context->prepare(true);
$this->modx->context->aliasMap = null;
}
public function tearDown(): void
{
parent::tearDown();
/** @var modResource $resource */
$resource = $this->modx->getObject('modResource',array('pagetitle' => 'Unit Test Resource'));
if ($resource) $resource->remove();
$resource = $this->modx->getObject('modResource',array('pagetitle' => 'Unit Test Child Resource'));
if ($resource) $resource->remove();
}
/**
* Test a single call to makeUrl with the base Resource and no parameters
*
* @param int $id
* @param string $expected
* @dataProvider providerSingleParameter
*/
public function testSingleParameter($id,$expected) {
$url = $this->modx->makeUrl($id);
$this->assertEquals($expected, $url);
}
/**
* @return array
*/
public function providerSingleParameter() {
return array(
// Dummy data to pass on first makeUrl
array(12345, ''),
array(12345, 'unit-test/'),
array(12346, 'unit-test/child.html'),
);
}
/**
* Test a call to makeUrl with REQUEST arguments
* @param int $id
* @param array $arguments
* @param string $expected
* @param boolean $xhtmlUrls
* @dataProvider providerArguments
* @depends testSingleParameter
*/
public function testArguments($id,array $arguments,$expected,$xhtmlUrls = false) {
$this->modx->setOption('xhtml_urls',$xhtmlUrls);
$url = $this->modx->makeUrl($id,'',$arguments);
$this->assertEquals($expected,$url);
}
/**
* @return array
*/
public function providerArguments() {
return array(
array(12345,array(),'unit-test/'),
array(12345,array('one' => 1),'unit-test/?one=1'),
array(12345,array('one' => 1,'two' => 2),'unit-test/?one=1&two=2'),
array(12345,array('one' => 1,'two' => 2),'unit-test/?one=1&two=2',true),
);
}
/**
* Test a call to makeUrl with REQUEST arguments
* @param int $id
* @param string $scheme
* @param string $expected
* @dataProvider providerScheme
* @depends testSingleParameter
*/
public function testScheme($id,$scheme,$expected) {
$url = $this->modx->makeUrl($id,'',null,$scheme);
$this->assertEquals($expected,$url);
}
/**
* @return array
*/
public function providerScheme() {
return array(
array(12345,'','unit-test/'),
array(12345,'abs','/unit-test/'),
array(12345,'full','http://unit.modx.com/unit-test/'),
array(12345,'http','http://unit.modx.com/unit-test/'),
array(12345,'https','https://unit.modx.com/unit-test/'),
);
}
}