Passed
Push — master ( b3daa9...df431e )
by Aimeos
14:40 queued 03:57
created

CmsAddTestData::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 18
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2021
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Adds cms test data and all items from other domains.
14
 */
15
class CmsAddTestData extends BaseAddTestData
16
{
17
	/**
18
	 * Returns the list of task names which this task depends on.
19
	 *
20
	 * @return string[] List of task names
21
	 */
22
	public function after() : array
23
	{
24
		return ['MShopSetLocale'];
25
	}
26
27
28
	/**
29
	 * Adds cms test data.
30
	 */
31
	public function up()
32
	{
33
		$this->info( 'Adding cms test data', 'v' );
34
35
		$this->context()->setEditor( 'ai-cms-grapesjs:lib/custom' );
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\CmsAddTestData. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
		$this->/** @scrutinizer ignore-call */ 
36
         context()->setEditor( 'ai-cms-grapesjs:lib/custom' );
Loading history...
36
		$this->process( $this->getData() );
37
	}
38
39
40
	/**
41
	 * Returns the test data array
42
	 *
43
	 * @return array Multi-dimensional array of test data
44
	 */
45
	protected function getData()
46
	{
47
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cms.php';
48
49
		if( ( $testdata = include( $path ) ) == false ) {
50
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for cms domain', $path ) );
51
		}
52
53
		return $testdata;
54
	}
55
56
57
	/**
58
	 * Adds the product data from the given array
59
	 *
60
	 * @param array $testdata Multi-dimensional array of test data
61
	 */
62
	protected function process( array $testdata )
63
	{
64
		$manager = $this->getManager( 'cms' );
65
		$listManager = $manager->getSubManager( 'lists' );
66
67
		$manager->begin();
68
69
		$this->storeTypes( $testdata, ['cms/lists/type'] );
70
71
		foreach( $testdata['cms'] as $entry )
72
		{
73
			$item = $manager->create()->fromArray( $entry );
74
			$item = $this->addListData( $listManager, $item, $entry );
75
76
			$manager->save( $item );
77
		}
78
79
		$manager->commit();
80
	}
81
}
82