29
29
30
30
namespace OCA \Circles \Command ;
31
31
32
- use daita \MySmallPhpTools \Exceptions \RequestContentException ;
33
32
use daita \MySmallPhpTools \Exceptions \RequestNetworkException ;
34
- use daita \MySmallPhpTools \Exceptions \RequestResultSizeException ;
35
- use daita \MySmallPhpTools \Exceptions \RequestServerException ;
36
33
use daita \MySmallPhpTools \Model \Nextcloud \NC19Request ;
37
34
use daita \MySmallPhpTools \Model \Request ;
38
35
use daita \MySmallPhpTools \Traits \Nextcloud \TNC19Request ;
@@ -110,7 +107,7 @@ protected function configure() {
110
107
$ this ->setName ('circles:test ' )
111
108
->setDescription ('testing some features ' )
112
109
->addOption ('delay ' , 'd ' , InputOption::VALUE_REQUIRED , 'delay before checking result ' )
113
- ->addOption ('url ' , '' , InputOption::VALUE_REQUIRED , 'specify a source url ' );
110
+ ->addOption ('url ' , '' , InputOption::VALUE_REQUIRED , 'specify a source url ' , '' );
114
111
}
115
112
116
113
@@ -126,12 +123,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126
123
$ this ->delay = (int )$ input ->getOption ('delay ' );
127
124
}
128
125
129
- // $url = $input->getOption('url');
130
- if (!$ this ->testLocalAddress ($ output )) {
126
+ $ this ->configService ->setAppValue (ConfigService::TEST_NC_BASE , '' );
127
+ $ this ->configService ->setAppValue (ConfigService::TEST_NC_BASE , $ input ->getOption ('url ' ));
128
+
129
+ if (!$ this ->testRequest ($ output , 'GET ' , 'core.CSRFToken.index ' )) {
131
130
return 0 ;
132
131
}
133
132
134
- $ instances = array_merge ($ this ->globalScaleService ->getInstances (true ));
133
+ if (!$ this ->testRequest (
134
+ $ output , 'POST ' , 'circles.GlobalScale.asyncBroadcast ' ,
135
+ ['token ' => 'test-dummy-token ' ]
136
+ )) {
137
+ return 0 ;
138
+ }
135
139
136
140
$ test = new GSEvent (GSEvent::TEST , true , true );
137
141
$ test ->setAsync (true );
@@ -144,6 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
144
148
$ wrappers = $ this ->gsUpstreamService ->getEventsByToken ($ token );
145
149
146
150
$ result = [];
151
+ $ instances = array_merge ($ this ->globalScaleService ->getInstances (true ));
147
152
foreach ($ wrappers as $ wrapper ) {
148
153
$ result [$ wrapper ->getInstance ()] = $ wrapper ->getEvent ();
149
154
}
@@ -159,33 +164,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
159
164
}
160
165
}
161
166
167
+ $ this ->configService ->setAppValue (ConfigService::TEST_NC_BASE , '' );
168
+
162
169
return 0 ;
163
170
}
164
171
165
172
166
173
/**
167
- * @param OutputInterface $output
174
+ * @param OutputInterface $o
175
+ * @param string $type
176
+ * @param string $route
177
+ * @param array $args
168
178
*
169
179
* @return bool
170
- * @throws RequestContentException
171
180
* @throws RequestNetworkException
172
- * @throws RequestResultSizeException
173
- * @throws RequestServerException
174
181
*/
175
- private function testLocalAddress (OutputInterface $ output ): bool {
176
- $ absolute = $ this ->urlGenerator ->linkToRouteAbsolute ('core.CSRFToken.index ' );
177
- $ output ->write ('- Simple request on ' . $ absolute . ': ' );
178
-
179
- $ request = new NC19Request ('' , Request::TYPE_GET );
180
- $ this ->configService ->configureRequest ($ request );
181
- $ request ->setAddressFromUrl ($ absolute );
182
+ private function testRequest (OutputInterface $ o , string $ type , string $ route , array $ args = []): bool {
183
+ $ request = new NC19Request ('' , Request::type ($ type ));
184
+ $ this ->configService ->configureRequest ($ request , $ route , $ args );
182
185
186
+ $ o ->write ('- ' . $ type . ' request on ' . $ request ->getCompleteUrl () . ': ' );
183
187
$ this ->doRequest ($ request );
188
+
184
189
$ color = 'error ' ;
185
190
if ($ request ->getResultCode () === 200 ) {
186
191
$ color = 'info ' ;
187
192
}
188
- $ output ->writeln ('< ' . $ color . '> ' . $ request ->getResultCode () . '</ ' . $ color . '> ' );
193
+ $ o ->writeln ('< ' . $ color . '> ' . $ request ->getResultCode () . '</ ' . $ color . '> ' );
189
194
190
195
if ($ request ->getResultCode () === 200 ) {
191
196
return true ;
0 commit comments