2929
3030namespace OCA \Circles \Command ;
3131
32- use daita \MySmallPhpTools \Exceptions \RequestContentException ;
3332use daita \MySmallPhpTools \Exceptions \RequestNetworkException ;
34- use daita \MySmallPhpTools \Exceptions \RequestResultSizeException ;
35- use daita \MySmallPhpTools \Exceptions \RequestServerException ;
3633use daita \MySmallPhpTools \Model \Nextcloud \NC19Request ;
3734use daita \MySmallPhpTools \Model \Request ;
3835use daita \MySmallPhpTools \Traits \Nextcloud \TNC19Request ;
@@ -110,7 +107,7 @@ protected function configure() {
110107 $ this ->setName ('circles:test ' )
111108 ->setDescription ('testing some features ' )
112109 ->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 ' , '' );
114111 }
115112
116113
@@ -126,12 +123,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126123 $ this ->delay = (int )$ input ->getOption ('delay ' );
127124 }
128125
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 ' )) {
131130 return 0 ;
132131 }
133132
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+ }
135139
136140 $ test = new GSEvent (GSEvent::TEST , true , true );
137141 $ test ->setAsync (true );
@@ -144,6 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
144148 $ wrappers = $ this ->gsUpstreamService ->getEventsByToken ($ token );
145149
146150 $ result = [];
151+ $ instances = array_merge ($ this ->globalScaleService ->getInstances (true ));
147152 foreach ($ wrappers as $ wrapper ) {
148153 $ result [$ wrapper ->getInstance ()] = $ wrapper ->getEvent ();
149154 }
@@ -159,33 +164,33 @@ protected function execute(InputInterface $input, OutputInterface $output): int
159164 }
160165 }
161166
167+ $ this ->configService ->setAppValue (ConfigService::TEST_NC_BASE , '' );
168+
162169 return 0 ;
163170 }
164171
165172
166173 /**
167- * @param OutputInterface $output
174+ * @param OutputInterface $o
175+ * @param string $type
176+ * @param string $route
177+ * @param array $args
168178 *
169179 * @return bool
170- * @throws RequestContentException
171180 * @throws RequestNetworkException
172- * @throws RequestResultSizeException
173- * @throws RequestServerException
174181 */
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 );
182185
186+ $ o ->write ('- ' . $ type . ' request on ' . $ request ->getCompleteUrl () . ': ' );
183187 $ this ->doRequest ($ request );
188+
184189 $ color = 'error ' ;
185190 if ($ request ->getResultCode () === 200 ) {
186191 $ color = 'info ' ;
187192 }
188- $ output ->writeln ('< ' . $ color . '> ' . $ request ->getResultCode () . '</ ' . $ color . '> ' );
193+ $ o ->writeln ('< ' . $ color . '> ' . $ request ->getResultCode () . '</ ' . $ color . '> ' );
189194
190195 if ($ request ->getResultCode () === 200 ) {
191196 return true ;
0 commit comments