Passed
Push — master ( 63bc59...352b21 )
by Aimeos
148:01 queued 75:12
created

TextAddTestData::getData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
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), 2015-2020
6
 */
7
8
9
namespace Aimeos\MW\Setup\Task;
10
11
12
/**
13
 * Adds attribute test data and all items from other domains.
14
 */
15
class TextAddTestData extends \Aimeos\MW\Setup\Task\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 getPreDependencies() : array
23
	{
24
		return ['MShopSetLocale'];
25
	}
26
27
28
	/**
29
	 * Adds text test data.
30
	 */
31
	public function migrate()
32
	{
33
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
34
35
		$this->msg( 'Adding text test data', 0 );
36
37
		$this->additional->setEditor( 'core:lib/mshoplib' );
38
		$this->process( $this->getData() );
39
40
		$this->status( 'done' );
41
	}
42
43
44
	/**
45
	 * Returns the test data array
46
	 *
47
	 * @return array Multi-dimensional array of test data
48
	 */
49
	protected function getData()
50
	{
51
		$path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'text.php';
52
53
		if( ( $testdata = include( $path ) ) == false ) {
54
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for text domain', $path ) );
55
		}
56
57
		return $testdata;
58
	}
59
60
61
	/**
62
	 * Returns the manager for the current setup task
63
	 *
64
	 * @param string $domain Domain name of the manager
65
	 * @return \Aimeos\MShop\Common\Manager\Iface Manager object
66
	 */
67
	protected function getManager( $domain )
68
	{
69
		if( $domain === 'text' ) {
70
			return \Aimeos\MShop\Text\Manager\Factory::create( $this->additional, 'Standard' );
71
		}
72
73
		return parent::getManager( $domain );
74
	}
75
76
77
	/**
78
	 * Adds the text data from the given array
79
	 *
80
	 * @param array Multi-dimensional array of test data
0 ignored issues
show
Documentation Bug introduced by
The doc comment Multi-dimensional at position 0 could not be parsed: Unknown type name 'Multi-dimensional' at position 0 in Multi-dimensional.
Loading history...
81
	 */
82
	protected function process( array $testdata )
83
	{
84
		$manager = $this->getManager( 'text' );
85
		$manager->begin();
86
87
		$this->storeTypes( $testdata, ['text/type', 'text/lists/type'] );
88
89
		$manager->commit();
90
	}
91
}
92