Completed
Push — master ( ae05be...d1fded )
by Aimeos
02:33
created
jobs/tests/Controller/Jobs/Product/Export/Sitemap/StandardTest.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -18,18 +18,18 @@  discard block
 block discarded – undo
18 18
 
19 19
 	protected function setUp()
20 20
 	{
21
-		\Aimeos\MShop\Factory::setCache( true );
21
+		\Aimeos\MShop\Factory::setCache(true);
22 22
 
23 23
 		$this->context = \TestHelperJobs::getContext();
24 24
 		$this->aimeos = \TestHelperJobs::getAimeos();
25 25
 
26
-		$this->object = new \Aimeos\Controller\Jobs\Product\Export\Sitemap\Standard( $this->context, $this->aimeos );
26
+		$this->object = new \Aimeos\Controller\Jobs\Product\Export\Sitemap\Standard($this->context, $this->aimeos);
27 27
 	}
28 28
 
29 29
 
30 30
 	protected function tearDown()
31 31
 	{
32
-		\Aimeos\MShop\Factory::setCache( false );
32
+		\Aimeos\MShop\Factory::setCache(false);
33 33
 		\Aimeos\MShop\Factory::clear();
34 34
 
35 35
 		$this->object = null;
@@ -38,40 +38,40 @@  discard block
 block discarded – undo
38 38
 
39 39
 	public function testGetName()
40 40
 	{
41
-		$this->assertEquals( 'Product site map', $this->object->getName() );
41
+		$this->assertEquals('Product site map', $this->object->getName());
42 42
 	}
43 43
 
44 44
 
45 45
 	public function testGetDescription()
46 46
 	{
47 47
 		$text = 'Creates a product site map for search engines';
48
-		$this->assertEquals( $text, $this->object->getDescription() );
48
+		$this->assertEquals($text, $this->object->getDescription());
49 49
 	}
50 50
 
51 51
 
52 52
 	public function testRun()
53 53
 	{
54
-		$this->context->getConfig()->set( 'controller/jobs/product/export/sitemap/max-items', 5 );
54
+		$this->context->getConfig()->set('controller/jobs/product/export/sitemap/max-items', 5);
55 55
 
56 56
 		$this->object->run();
57 57
 
58 58
 		$ds = DIRECTORY_SEPARATOR;
59
-		$this->assertFileExists( 'tmp' . $ds . 'aimeos-sitemap-1.xml.gz' );
60
-		$this->assertFileExists( 'tmp' . $ds . 'aimeos-sitemap-2.xml.gz' );
61
-		$this->assertFileExists( 'tmp' . $ds . 'aimeos-sitemap-index.xml.gz' );
59
+		$this->assertFileExists('tmp' . $ds . 'aimeos-sitemap-1.xml.gz');
60
+		$this->assertFileExists('tmp' . $ds . 'aimeos-sitemap-2.xml.gz');
61
+		$this->assertFileExists('tmp' . $ds . 'aimeos-sitemap-index.xml.gz');
62 62
 
63
-		$file1 = gzread( gzopen( 'tmp' . $ds . 'aimeos-sitemap-1.xml.gz', 'rb' ), 0x1000 );
64
-		$file2 = gzread( gzopen( 'tmp' . $ds . 'aimeos-sitemap-2.xml.gz', 'rb' ), 0x1000 );
65
-		$index = gzread( gzopen( 'tmp' . $ds . 'aimeos-sitemap-index.xml.gz', 'rb' ), 0x1000 );
63
+		$file1 = gzread(gzopen('tmp' . $ds . 'aimeos-sitemap-1.xml.gz', 'rb'), 0x1000);
64
+		$file2 = gzread(gzopen('tmp' . $ds . 'aimeos-sitemap-2.xml.gz', 'rb'), 0x1000);
65
+		$index = gzread(gzopen('tmp' . $ds . 'aimeos-sitemap-index.xml.gz', 'rb'), 0x1000);
66 66
 
67
-		unlink( 'tmp' . $ds . 'aimeos-sitemap-1.xml.gz' );
68
-		unlink( 'tmp' . $ds . 'aimeos-sitemap-2.xml.gz' );
69
-		unlink( 'tmp' . $ds . 'aimeos-sitemap-index.xml.gz' );
67
+		unlink('tmp' . $ds . 'aimeos-sitemap-1.xml.gz');
68
+		unlink('tmp' . $ds . 'aimeos-sitemap-2.xml.gz');
69
+		unlink('tmp' . $ds . 'aimeos-sitemap-index.xml.gz');
70 70
 
71
-		$this->assertContains( 'Cafe_Noire_Expresso', $file2 );
72
-		$this->assertContains( 'Unittest%3A_Bundle', $file2 );
71
+		$this->assertContains('Cafe_Noire_Expresso', $file2);
72
+		$this->assertContains('Unittest%3A_Bundle', $file2);
73 73
 
74
-		$this->assertContains( 'aimeos-sitemap-1.xml.gz', $index );
75
-		$this->assertContains( 'aimeos-sitemap-2.xml.gz', $index );
74
+		$this->assertContains('aimeos-sitemap-1.xml.gz', $index);
75
+		$this->assertContains('aimeos-sitemap-2.xml.gz', $index);
76 76
 	}
77 77
 }
78 78
\ No newline at end of file
Please login to merge, or discard this patch.
controller/jobs/src/Controller/Jobs/Product/Export/Sitemap/Standard.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 */
29 29
 	public function getName()
30 30
 	{
31
-		return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product site map' );
31
+		return $this->getContext()->getI18n()->dt('controller/jobs', 'Product site map');
32 32
 	}
33 33
 
34 34
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 */
40 40
 	public function getDescription()
41 41
 	{
42
-		return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Creates a product site map for search engines' );
42
+		return $this->getContext()->getI18n()->dt('controller/jobs', 'Creates a product site map for search engines');
43 43
 	}
44 44
 
45 45
 
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
 	{
53 53
 		$container = $this->createContainer();
54 54
 
55
-		$files = $this->export( $container );
56
-		$this->createSitemapIndex( $container, $files );
55
+		$files = $this->export($container);
56
+		$this->createSitemapIndex($container, $files);
57 57
 
58 58
 		$container->close();
59 59
 	}
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @param \Aimeos\MW\Container\Content\Iface $content File content object
66 66
 	 * @param \Aimeos\MShop\Product\Item\Iface[] $items List of product items
67 67
 	 */
68
-	protected function addItems( \Aimeos\MW\Container\Content\Iface $content, array $items )
68
+	protected function addItems(\Aimeos\MW\Container\Content\Iface $content, array $items)
69 69
 	{
70 70
 		$config = $this->getContext()->getConfig();
71 71
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		 * @see controller/jobs/product/export/sitemap/max-items
97 97
 		 * @see controller/jobs/product/export/sitemap/max-query
98 98
 		 */
99
-		$changefreq = $config->get( 'controller/jobs/product/export/sitemap/changefreq', 'daily' );
99
+		$changefreq = $config->get('controller/jobs/product/export/sitemap/changefreq', 'daily');
100 100
 
101 101
 		/** controller/jobs/product/export/sitemap/standard/template-items
102 102
 		 * Relative path to the XML items template of the product site map job controller.
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$view->siteItems = $items;
130 130
 		$view->siteFreq = $changefreq;
131 131
 
132
-		$content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) );
132
+		$content->add($view->render($context->getConfig()->get($tplconf, $default)));
133 133
 	}
134 134
 
135 135
 
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		 * @see controller/jobs/product/export/sitemap/max-query
176 176
 		 * @see controller/jobs/product/export/sitemap/changefreq
177 177
 		 */
178
-		$location = $config->get( 'controller/jobs/product/export/sitemap/location' );
178
+		$location = $config->get('controller/jobs/product/export/sitemap/location');
179 179
 
180 180
 		/** controller/jobs/product/export/sitemap/container/options
181 181
 		 * List of file container options for the site map files
@@ -196,16 +196,16 @@  discard block
 block discarded – undo
196 196
 		 * @see controller/jobs/product/export/sitemap/max-query
197 197
 		 * @see controller/jobs/product/export/sitemap/changefreq
198 198
 		 */
199
-		$default = array( 'gzip-mode' => 'wb' );
200
-		$options = $config->get( 'controller/jobs/product/export/sitemap/container/options', $default );
199
+		$default = array('gzip-mode' => 'wb');
200
+		$options = $config->get('controller/jobs/product/export/sitemap/container/options', $default);
201 201
 
202
-		if( $location === null )
202
+		if ($location === null)
203 203
 		{
204
-			$msg = sprintf( 'Required configuration for "%1$s" is missing', 'controller/jobs/product/export/sitemap/location' );
205
-			throw new \Aimeos\Controller\Jobs\Exception( $msg );
204
+			$msg = sprintf('Required configuration for "%1$s" is missing', 'controller/jobs/product/export/sitemap/location');
205
+			throw new \Aimeos\Controller\Jobs\Exception($msg);
206 206
 		}
207 207
 
208
-		return \Aimeos\MW\Container\Factory::getContainer( $location, 'Directory', 'Gzip', $options );
208
+		return \Aimeos\MW\Container\Factory::getContainer($location, 'Directory', 'Gzip', $options);
209 209
 	}
210 210
 
211 211
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
 	 * @param integer $filenum New file number
217 217
 	 * @return \Aimeos\MW\Container\Content\Iface New content object
218 218
 	 */
219
-	protected function createContent( \Aimeos\MW\Container\Iface $container, $filenum )
219
+	protected function createContent(\Aimeos\MW\Container\Iface $container, $filenum)
220 220
 	{
221 221
 		/** controller/jobs/product/export/sitemap/standard/template-header
222 222
 		 * Relative path to the XML site map header template of the product site map job controller.
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
 		$context = $this->getContext();
247 247
 		$view = $context->getView();
248 248
 
249
-		$content = $container->create( $this->getFilename( $filenum ) );
250
-		$content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) );
251
-		$container->add( $content );
249
+		$content = $container->create($this->getFilename($filenum));
250
+		$content->add($view->render($context->getConfig()->get($tplconf, $default)));
251
+		$container->add($content);
252 252
 
253 253
 		return $content;
254 254
 	}
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 *
260 260
 	 * @param \Aimeos\MW\Container\Content\Iface $content
261 261
 	 */
262
-	protected function closeContent( \Aimeos\MW\Container\Content\Iface $content )
262
+	protected function closeContent(\Aimeos\MW\Container\Content\Iface $content)
263 263
 	{
264 264
 		/** controller/jobs/product/export/sitemap/standard/template-footer
265 265
 		 * Relative path to the XML site map footer template of the product site map job controller.
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
 		$context = $this->getContext();
290 290
 		$view = $context->getView();
291 291
 
292
-		$content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) );
292
+		$content->add($view->render($context->getConfig()->get($tplconf, $default)));
293 293
 	}
294 294
 
295 295
 
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	 * @param \Aimeos\MW\Container\Iface $container File container object
300 300
 	 * @param array $files List of generated site map file names
301 301
 	 */
302
-	protected function createSitemapIndex( \Aimeos\MW\Container\Iface $container, array $files )
302
+	protected function createSitemapIndex(\Aimeos\MW\Container\Iface $container, array $files)
303 303
 	{
304 304
 		/** controller/jobs/product/export/sitemap/standard/template-index
305 305
 		 * Relative path to the XML site map index template of the product site map job controller.
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 
332 332
 		$view->siteFiles = $files;
333 333
 
334
-		$content = $container->create( 'aimeos-sitemap-index.xml' );
335
-		$content->add( $view->render( $context->getConfig()->get( $tplconf, $default ) ) );
336
-		$container->add( $content );
334
+		$content = $container->create('aimeos-sitemap-index.xml');
335
+		$content->add($view->render($context->getConfig()->get($tplconf, $default)));
336
+		$container->add($content);
337 337
 	}
338 338
 
339 339
 
@@ -344,46 +344,46 @@  discard block
 block discarded – undo
344 344
 	 * @param boolean $default True to filter exported products by default criteria
345 345
 	 * @return array List of content (file) names
346 346
 	 */
347
-	protected function export( \Aimeos\MW\Container\Iface $container, $default = true )
347
+	protected function export(\Aimeos\MW\Container\Iface $container, $default = true)
348 348
 	{
349
-		$domains = array( 'attribute', 'media', 'price', 'product', 'text' );
349
+		$domains = array('attribute', 'media', 'price', 'product', 'text');
350 350
 
351
-		$domains = $this->getConfig( 'domains', $domains );
352
-		$maxItems = $this->getConfig( 'max-items', 10000 );
353
-		$maxQuery = $this->getConfig( 'max-query', 1000 );
351
+		$domains = $this->getConfig('domains', $domains);
352
+		$maxItems = $this->getConfig('max-items', 10000);
353
+		$maxQuery = $this->getConfig('max-query', 1000);
354 354
 
355 355
 		$start = 0; $filenum = 1;
356 356
 		$names = [];
357 357
 
358
-		$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'index' );
358
+		$manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'index');
359 359
 
360
-		$search = $manager->createSearch( $default );
361
-		$search->setConditions( $search->compare( '!=', 'index.catalog.id', null ) );
362
-		$search->setSortations( array( $search->sort( '+', 'product.id' ) ) );
363
-		$search->setSlice( 0, $maxQuery );
360
+		$search = $manager->createSearch($default);
361
+		$search->setConditions($search->compare('!=', 'index.catalog.id', null));
362
+		$search->setSortations(array($search->sort('+', 'product.id')));
363
+		$search->setSlice(0, $maxQuery);
364 364
 
365
-		$content = $this->createContent( $container, $filenum );
365
+		$content = $this->createContent($container, $filenum);
366 366
 		$names[] = $content->getResource();
367 367
 
368 368
 		do
369 369
 		{
370
-			$items = $manager->searchItems( $search, $domains );
371
-			$this->addItems( $content, $items );
370
+			$items = $manager->searchItems($search, $domains);
371
+			$this->addItems($content, $items);
372 372
 
373
-			$count = count( $items );
373
+			$count = count($items);
374 374
 			$start += $count;
375
-			$search->setSlice( $start, $maxQuery );
375
+			$search->setSlice($start, $maxQuery);
376 376
 
377
-			if( $start + $maxQuery > $maxItems * $filenum )
377
+			if ($start + $maxQuery > $maxItems * $filenum)
378 378
 			{
379
-				$this->closeContent( $content );
380
-				$content = $this->createContent( $container, ++$filenum );
379
+				$this->closeContent($content);
380
+				$content = $this->createContent($container, ++$filenum);
381 381
 				$names[] = $content->getResource();
382 382
 			}
383 383
 		}
384
-		while( $count >= $search->getSliceSize() );
384
+		while ($count >= $search->getSliceSize());
385 385
 
386
-		$this->closeContent( $content );
386
+		$this->closeContent($content);
387 387
 
388 388
 		return $names;
389 389
 	}
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
 	 * @param mixed $default Default value if name is unknown
397 397
 	 * @return mixed Configuration value
398 398
 	 */
399
-	protected function getConfig( $name, $default = null )
399
+	protected function getConfig($name, $default = null)
400 400
 	{
401 401
 		$config = $this->getContext()->getConfig();
402 402
 
403
-		switch( $name )
403
+		switch ($name)
404 404
 		{
405 405
 			case 'domain':
406 406
 				return [];
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
 				 * @see controller/jobs/product/export/sitemap/max-query
428 428
 				 * @see controller/jobs/product/export/sitemap/changefreq
429 429
 				 */
430
-				return $config->get( 'controller/jobs/product/export/sitemap/max-items', 50000 );
430
+				return $config->get('controller/jobs/product/export/sitemap/max-items', 50000);
431 431
 
432 432
 			case 'max-query':
433 433
 				/** controller/jobs/product/export/sitemap/max-query
@@ -447,7 +447,7 @@  discard block
 block discarded – undo
447 447
 				 * @see controller/jobs/product/export/sitemap/max-items
448 448
 				 * @see controller/jobs/product/export/sitemap/changefreq
449 449
 				 */
450
-				return $config->get( 'controller/jobs/product/export/sitemap/max-query', 1000 );
450
+				return $config->get('controller/jobs/product/export/sitemap/max-query', 1000);
451 451
 		}
452 452
 
453 453
 		return $default;
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
 	 * @param integer $number Current file number
461 461
 	 * @return string New file name
462 462
 	 */
463
-	protected function getFilename( $number )
463
+	protected function getFilename($number)
464 464
 	{
465
-		return sprintf( 'aimeos-sitemap-%d.xml', $number );
465
+		return sprintf('aimeos-sitemap-%d.xml', $number);
466 466
 	}
467 467
 }
Please login to merge, or discard this patch.