Sprint-0 » hlubek-1220827799.diff

SVN Patch for code sprint 0 - Christopher Hlubek, 2008-09-07 22:50

View differences:

Tests/Controller/F3_FLOW3_Controller_PackageTest.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Controller
20
 * @version $Id$
21
 */
22

  
23
/**
24
 * Testcase for the Package Controller (CLI)
25
 *
26
 * @package FLOW3
27
 * @subpackage Controller
28
 * @version $Id$
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Controller_PackageTest extends F3_Testing_BaseTestCase {
32

  
33

  
34
	/**
35
	 * @test
36
	 * @author Tobias Liebig <mail_typo3@etobi.de>
37
	 */
38
	public function testCreateActionCallsPackageManagerCreatePackage() {
39
		// get mocked Packagemanager
40
		$packageManager = $this->getMock('F3_FLOW3_Package_ManagerInterface');
41

  
42
		$packageManager->expects($this->once())
43
			->method('createPackage')
44
			->with($this->equalTo('FooBarPackageName'));
45

  
46
		$packageController = new F3_FLOW3_Controller_Package($this->componentFactory, $packageManager);
47
		$packageController->injectPackageManager($packageManager);
48
		$packageController->initializeController();
49
		
50
		$argumentPackageKey = new F3_FLOW3_MVC_Controller_Argument('packageKey','Text', $this->componentFactory);
51
		$packageControllerArguments = $packageController->getArguments();
52
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
53

  
54
		$packageController->createAction();
55
	}
56
	
57
	/**
58
	 * @test
59
	 * @author Tobias Liebig <mail_typo3@etobi.de>
60
	 */
61
	public function testActivateActionCallsPackageManagerActivatePackage() {
62
		// get mocked Packagemanager
63
		$packageManager = $this->getMock('F3_FLOW3_Package_ManagerInterface');
64

  
65
		$packageManager->expects($this->once())
66
			->method('activatePackage')
67
			->with($this->equalTo('FooBarPackageName'));
68

  
69
		$packageController = new F3_FLOW3_Controller_Package($this->componentFactory, $packageManager);
70
		$packageController->injectPackageManager($packageManager);
71
		$packageController->initializeController();
72
		
73
		$argumentPackageKey = new F3_FLOW3_MVC_Controller_Argument('packageKey','Text', $this->componentFactory);
74
		$packageControllerArguments = $packageController->getArguments();
75
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
76

  
77
		$packageController->activateAction();
78
	}
79
	
80
	/**
81
	 * @test
82
	 * @author Tobias Liebig <mail_typo3@etobi.de>
83
	 */
84
	public function testDeactivateActionCallsPackageManagerDeactivatePackage() {
85
		// get mocked Packagemanager
86
		$packageManager = $this->getMock('F3_FLOW3_Package_ManagerInterface');
87

  
88
		$packageManager->expects($this->once())
89
			->method('deactivatePackage')
90
			->with($this->equalTo('FooBarPackageName'));
91

  
92
		$packageController = new F3_FLOW3_Controller_Package($this->componentFactory, $packageManager);
93
		$packageController->injectPackageManager($packageManager);
94
		$packageController->initializeController();
95
		
96
		$argumentPackageKey = new F3_FLOW3_MVC_Controller_Argument('packageKey','Text', $this->componentFactory);
97
		$packageControllerArguments = $packageController->getArguments();
98
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
99

  
100
		$packageController->deactivateAction();
101
	}
102

  
103

  
104
	/**
105
	 * @test
106
	 * @author Tobias Liebig <mail_typo3@etobi.de>
107
	 */
108
	public function testCreateActionWithoutPackageKeyCallsHelpAction() {
109
		// get mocked Packagemanager
110
		$packageManager = $this->getMock('F3_FLOW3_Package_ManagerInterface');
111
		
112
		// mock method helpAction (and only that) for Package Controller
113
		$packageController = $this->getMock('F3_FLOW3_Controller_Package',
114
			array('helpAction'),
115
			array($this->componentFactory, $packageManager));
116
		
117
		$packageController->expects($this->once())
118
			->method('helpAction');
119
			
120
		$packageController->initializeController();
121
		
122
		$packageController->createAction();
123
	}
124
	
125

  
126
	/**
127
	 * @test
128
	 * @author Tobias Liebig <mail_typo3@etobi.de>
129
	 */
130
	public function testDefaultActionCallsHelpAction() {
131
		// get mocked Packagemanager
132
		$packageManager = $this->getMock('F3_FLOW3_Package_ManagerInterface');
133
		
134
		// mock method helpAction (and only that) for Package Controller
135
		$packageController = $this->getMock('F3_FLOW3_Controller_Package',
136
			array('helpAction'),
137
			array($this->componentFactory, $packageManager));
138
		
139
		$packageController->expects($this->once())
140
			->method('helpAction');
141
			
142
		$packageController->initializeController();
143
		
144
		$packageController->defaultAction();
145
	}
146
	
147
	
148
	
149
	
150

  
151
}
152

  
153
?>
Tests/Package/F3_FLOW3_Package_MetaTest.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Tests
20
 * @version $Id:F3_FLOW3_Package_Test.php 201 2007-03-30 11:18:30Z robert $
21
 */
22

  
23
/**
24
 * Testcase for the package meta class
25
 *
26
 * @package FLOW3
27
 * @subpackage Tests
28
 * @version $Id:F3_FLOW3_Package_Test.php 201 2007-03-30 11:18:30Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Package_MetaTest extends F3_Testing_BaseTestCase {
32
	
33
	/**
34
	 * @test
35
	 * @author Christopher Hlubek <hlubek@networkteam.com>
36
	 */
37
	public function getPackageMetaWorks() {
38
		$package = new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/');
39
		$packageMeta = $package->getPackageMeta();
40
		$this->assertEquals('TestPackage', $packageMeta->getPackageKey());
41
		$this->assertEquals('Test package', $packageMeta->getTitle());
42
		$this->assertEquals('0.0.1', $packageMeta->getVersion());
43
		$this->assertEquals('This package is used for testing the package- and component manager', $packageMeta->getDescription());
44
		$this->assertEquals('Alpha', $packageMeta->getState());
45
		$this->assertEquals(array('System', 'Testing'), $packageMeta->getCategories());
46
		
47
		$parties = $packageMeta->getParties();
48
		$this->assertTrue(is_array($parties));
49
		$person1 = $parties[0];
50
		$this->assertType('F3_FLOW3_Package_Meta_Person', $person1);
51
		$this->assertEquals('LeadDeveloper', $person1->getRole());
52
		$this->assertEquals('Robert Lemke', $person1->getName());
53
		$this->assertEquals('robert@typo3.org', $person1->getEmail());
54
		$person2 = $parties[1];
55
		$this->assertEquals('Smith Ltd.', $person2->getCompany());
56
		$this->assertEquals('jsmith', $person2->getRepositoryUserName());
57
		$organisation1 = $parties[2];
58
		$this->assertType('F3_FLOW3_Package_Meta_Company', $organisation1);
59
		$this->assertEquals('Sponsor', $organisation1->getRole());
60
		$this->assertEquals('John Doe Co.', $organisation1->getName());
61
		$this->assertEquals('info@johndoe.com', $organisation1->getEmail());
62
		$this->assertEquals('www.johndoe.com', $organisation1->getWebsite());
63
	}
64

  
65
	/**
66
	 * Check reading the package constraints from meta information
67
	 * 
68
	 * @test
69
	 * @author Christopher Hlubek <hlubek@networkteam.com>
70
	 */
71
	public function getPackageMetaConstraintsWorks() {
72
		$package = new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/');
73
		$packageMeta = $package->getPackageMeta();
74
		
75
		$constraints = $packageMeta->getConstraints('depends');
76
		$this->assertTrue(is_array($constraints));
77
		
78
		$this->assertType('F3_FLOW3_Package_Meta_PackageConstraint', $constraints[0]);
79
		$this->assertEquals('depends', $constraints[0]->getConstraintType());
80
		$this->assertEquals('FLOW3', $constraints[0]->getValue());
81
		$this->assertEquals('1.0.0', $constraints[0]->getMinVersion());
82
		$this->assertEquals('1.9.9', $constraints[0]->getMaxVersion());
83
		$this->assertType('F3_FLOW3_Package_Meta_SystemConstraint', $constraints[1]);
84
		$this->assertNull($constraints[1]->getValue());
85
		$this->assertEquals('PHP', $constraints[1]->getType());
86
		$this->assertEquals('5.1.0', $constraints[1]->getMinVersion());
87
	}
88

  
89

  
90
	/**
91
	 * Check constructing the meta information model then
92
	 * creating a Package.xml 
93
	 * 
94
	 * @test
95
	 * @author Christopher Hlubek <hlubek@networkteam.com>
96
	 */
97
	public function testMetaModelToXML() {
98
		$packageManager = $this->componentFactory->getComponent('F3_FLOW3_Package_ManagerInterface');
99
		
100
		$meta = new F3_FLOW3_Package_Meta('YetAnotherTestPackage');
101
		$meta->setTitle('Yet another test package');
102
		$meta->setDescription('A test package to test the creation of the Package.xml by the Package Manager');
103
		$meta->setVersion('0.1.1');
104
		$meta->setState('Beta');
105
		$meta->addCategory('Testing');
106
		$meta->addCategory('System');
107
		$meta->addParty(new F3_FLOW3_Package_Meta_Person('LeadDeveloper',
108
			'Robert Lemke', 'robert@typo3.org', 'http://www.flow3.org', 'TYPO3 Association', 'robert'));
109
		$meta->addParty(new F3_FLOW3_Package_Meta_Company(null, 'Acme Inc.', 'info@acme.com', 'http://www.acme.com'));
110
		$meta->addConstraint(new F3_FLOW3_Package_Meta_PackageConstraint('depends',
111
			'FLOW3', '1.0.0', '1.9.9'));
112
		$meta->addConstraint(new F3_FLOW3_Package_Meta_SystemConstraint('suggests',
113
			'Memory', '16M'));
114

  
115
		$xml = $meta->getPackageXML();
116
				
117
		$this->assertXmlStringEqualsXmlFile($packageManager->getPackage('FLOW3')->getResourcesPath() . 'Fixtures/Package.xml', $xml);
118
	}
119
}
120
?>
Tests/Package/F3_FLOW3_Package_ManagerTest.php (Arbeitskopie)
142 142
		$packageManager->initialize();
143 143
		$this->assertEquals('TestPackage', $packageManager->getCaseSensitivePackageKey('testpackage'));
144 144
	}
145

  
146
	/**
147
	 * Check creating a new package folder, given a package key
148
	 *
149
	 * @test
150
	 * @author Christopher Hlubek <hlubek@networkteam.com>
151
	 */
152
	public function testCreatePackageCreatesPackageFolderAndReturnsPackage() {
153
		$packageManager = new F3_FLOW3_Package_Manager();
154
		$packageManager->initialize();
155

  
156
		$package = $packageManager->createPackage('YetAnotherTestPackage');
157

  
158
		$this->assertType('F3_FLOW3_Package_PackageInterface', $package);
159
		$this->assertEquals('YetAnotherTestPackage', $package->getPackageKey());
160

  
161
		$this->assertTrue($packageManager->isPackageAvailable('YetAnotherTestPackage'));
162
	}
163

  
164
	/**
165
	 * Check creating a package creates the mandatory Package.xml
166
	 * (this doesn't check the content of the file)
167
	 *
168
	 * @test
169
	 * @author Christopher Hlubek <hlubek@networkteam.com>
170
	 */
171
	public function testCreatePackageCreatesPackageMetaFile() {
172
		$packageManager = new F3_FLOW3_Package_Manager();
173
		$packageManager->initialize();
174

  
175
		$packageManager->createPackage('YetAnotherTestPackage');
176

  
177
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
178
		$this->assertTrue(is_file($packagePath . F3_FLOW3_Package_Package::DIRECTORY_META . F3_FLOW3_Package_Package::FILENAME_PACKAGEINFO),
179
			'Mandatory Package.xml was created');
180
	}
181
	
182
	public function testCreatePackageWithMetadataCreatesPackageXML() {
183
		$packageManager = new F3_FLOW3_Package_Manager();
184
		$packageManager->initialize();
185

  
186
		$meta = $this->getMock('F3_FLOW3_Package_Meta', array('getPackageXML'), array('YetAnotherTestPackage'));
187

  
188
		$packageXML = '<package><key>YetAnotherTestPackage</key></package>';
189
		$meta->expects($this->once())
190
			->method('getPackageXML')
191
			->will($this->returnValue($packageXML));
192
		
193
		$packageManager->createPackage('YetAnotherTestPackage', $meta);
194
			
195
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
196
		$this->assertStringEqualsFile($packagePath . F3_FLOW3_Package_Package::DIRECTORY_META . F3_FLOW3_Package_Package::FILENAME_PACKAGEINFO,
197
			$packageXML);
198
	}
199

  
200
	/**
201
	 * Check create package creates the folders for
202
	 * classes, configuration, documentation, resources and tests
203
	 *
204
	 * @test
205
	 * @author Christopher Hlubek <hlubek@networkteam.com>
206
	 */
207
	public function testCreatePackageCreatesClassesConfigurationDocumentationResourcesAndTestsFolders() {
208
		$packageManager = new F3_FLOW3_Package_Manager();
209
		$packageManager->initialize();
210

  
211
		$packageManager->createPackage('YetAnotherTestPackage');
212

  
213
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
214
		$this->assertTrue(is_dir($packagePath . F3_FLOW3_Package_Package::DIRECTORY_CLASSES));
215
		$this->assertTrue(is_dir($packagePath . F3_FLOW3_Package_Package::DIRECTORY_CONFIGURATION));
216
		$this->assertTrue(is_dir($packagePath . F3_FLOW3_Package_Package::DIRECTORY_DOCUMENTATION));
217
		$this->assertTrue(is_dir($packagePath . F3_FLOW3_Package_Package::DIRECTORY_RESOURCES));
218
		$this->assertTrue(is_dir($packagePath . F3_FLOW3_Package_Package::DIRECTORY_TESTS));
219
	}
220

  
221
	/**
222
	 * @test
223
	 * @author Christopher Hlubek <hlubek@networkteam.com>
224
	 */
225
	public function testCreatePackageThrowsExceptionForInvalidPackageKey() {
226
		$packageManager = new F3_FLOW3_Package_Manager();
227
		$packageManager->initialize();
228

  
229
		try {
230
			$packageManager->createPackage('Invalid_Package_Key');
231
		} catch(Exception $exception) {
232
			$this->assertEquals(1220722210, $exception->getCode(), 'createPackage() throwed an exception but with an unexpected error code.');
233
		}
234

  
235
		$this->assertFalse(is_dir(FLOW3_PATH_PACKAGES . 'Invalid_Package_Key'), 'Package folder with invalid package key was created');
236
	}
237

  
238
	/**
239
	 * Check handling of duplicate package keys in package creation
240
	 *
241
	 * @test
242
	 * @author Christopher Hlubek <hlubek@networkteam.com>
243
	 */
244
	public function testCreatePackageThrowsExceptionForExistingPackageKey() {
245
		$packageManager = new F3_FLOW3_Package_Manager();
246
		$packageManager->initialize();
247

  
248
		try {
249
			$packageManager->createPackage('TestPackage');
250
		} catch(Exception $exception) {
251
			$this->assertEquals(1220722873, $exception->getCode(), 'createPackage() throwed an exception but with an unexpected error code.');
252
			return;
253
		}
254
		$this->fail('Create package didnt throw an exception for an existing package key');
255
	}
256

  
257
	/**
258
	 * @test
259
	 * @author Thomas Hempel <thomas@typo3.org>
260
	 */
261
	public function testCreatePackageCreatesDeactivatedPackage() {
262
		$packageManager = new F3_FLOW3_Package_Manager();
263
		$packageManager->initialize();
264

  
265
		$packageKey = 'YetAnotherTestPackage';
266
		$packageManager->createPackage($packageKey);
267

  
268
		$this->assertFalse($packageManager->isPackageActive($packageKey));
269
	}
270

  
271

  
272
	/**
273
	 * Check package key validation accepts only valid keys
274
	 *
275
	 * @test
276
	 * @author Christopher Hlubek <hlubek@networkteam.com>
277
	 */
278
	public function getPackageKeyValidationWorks() {
279
		$this->assertFalse($this->packageManager->isPackageKeyValid('Invalid_Package_Key'));
280
		$this->assertFalse($this->packageManager->isPackageKeyValid('invalidPackageKey'));
281
		$this->assertFalse($this->packageManager->isPackageKeyValid('1nvalidPackageKey'));
282
		$this->assertTrue($this->packageManager->isPackageKeyValid('ValidPackageKey'));
283
	}
284

  
285
	/*
286
	 public function testCreatePackageCreatesPackageMetaData() {
287
		$packageManager = new F3_FLOW3_Package_Manager();
288
		$packageManager->initialize();
289

  
290
		$metadata = new F3_FLOW3_Package_Meta();
291

  
292
		$package = $packageManager->createPackage('YetAnotherTestPackage', $metadata);
293
		}
294
		*/
295

  
296
	/**
297
	 * @test
298
	 * @author Thomas Hempel <thomas@typo3.org>
299
	 */
300
	public function testDeacivatePackageRemovesPackageFromActivePackages() {
301
		$packageManager = new F3_FLOW3_Package_Manager();
302
		$packageManager->initialize();
303

  
304
		$packageKey = 'YetAnotherTestPackage';
305

  
306
		$packageManager->createPackage($packageKey);
307
		$packageManager->activatePackage($packageKey);
308
		$packageManager->deactivatePackage($packageKey);
309

  
310
		$this->assertFalse($packageManager->isPackageActive($packageKey));
311
	}
312

  
313
	/**
314
	 * @test
315
	 * @author Thomas Hempel <thomas@typo3.org>
316
	 */
317
	public function testActivatePackagesAddsPackageToActivePackages() {
318
		$packageManager = new F3_FLOW3_Package_Manager();
319
		$packageManager->initialize();
320

  
321
		$packageKey = 'YetAnotherTestPackage';
322
		$packageManager->createPackage($packageKey);
323
		$packageManager->activatePackage($packageKey);
324

  
325
		$this->assertTrue($packageManager->isPackageActive($packageKey));
326
	}
327

  
328

  
329
	/**
330
	 * @test
331
	 * @author Thomas Hempel <thomas@typo3.org>
332
	 */
333
	public function testRemovePackageThrowsErrorIfPackageIsNotAvailable() {
334
		$packageManager = new F3_FLOW3_Package_Manager();
335
		$packageManager->initialize();
336

  
337
		try {
338
			$packageManager->removePackage('PrettyUnlikelyThatThisPackageExists');
339
		} catch (Exception $exception) {
340
			$this->assertEquals(1166543253, $exception->getCode(), 'removePackage() throwed an exception.');
341
			return;
342
		}
343
		$this->fail('removePackage() did not throw an exception while asking for the path to a non existent package.');
344
	}
345

  
346
	/**
347
	 * @test
348
	 * @author Thomas Hempel <thomas@typo3.org>
349
	 */
350
	public function testRemovePackgeThrowsErrorIfPackageIsProtected() {
351
		$packageManager = new F3_FLOW3_Package_Manager();
352
		$packageManager->initialize();
353
		try {
354
			$packageManager->removePackage('PHP6');
355
		} catch (Exception $exception) {
356
			$this->assertEquals(1220722120, $exception->getCode(), 'removePackage() throwed an exception.');
357
			return;
358
		}
359
		$this->fail('removePackage() did not throw an exception while asking for removing a protected package.');
360
	}
361

  
362
	/**
363
	 * @test
364
	 * @author Thomas Hempel <thomas@typo3.org>
365
	 */
366
	public function testRemovePackageRemovesPackageFromAvailablePackages() {
367
		$packageManager = new F3_FLOW3_Package_Manager();
368
		$packageManager->initialize();
369

  
370
		$packageKey = 'YetAnotherTestPackage';
371
		$packageManager->createPackage($packageKey);
372
		$packageManager->removePackage($packageKey);
373

  
374
		$this->assertFalse($packageManager->isPackageAvailable($packageKey));
375
	}
376

  
377
	/**
378
	 * @test
379
	 * @author Thomas Hempel <thomas@typo3.org>
380
	 */
381
	public function testRemovePackageRemovesPackageFromActivePackages() {
382
		$packageManager = new F3_FLOW3_Package_Manager();
383
		$packageManager->initialize();
384

  
385
		$packageKey = 'YetAnotherTestPackage';
386
		$packageManager->createPackage($packageKey);
387
		$packageManager->activatePackage($packageKey);
388
		$packageManager->removePackage($packageKey);
389

  
390
		$this->assertFalse($packageManager->isPackageActive($packageKey));
391
	}
392

  
393
	/**
394
	 * @test
395
	 * @author Thomas Hempel <thomas@typo3.org>
396
	 */
397
	public function testRemovePackageRemovesPackageDirectoryFromFilesystem() {
398
		$packageManager = new F3_FLOW3_Package_Manager();
399
		$packageManager->initialize();
400

  
401
		$packageKey = 'YetAnotherTestPackage';
402
		$packageManager->createPackage($packageKey);
403
		$packagePath = $packageManager->getPackagePath($packageKey);
404

  
405
		$packageManager->removePackage($packageKey);
406

  
407
		$this->assertFalse(file_exists($packagePath), $packagePath);
408
	}
409

  
410

  
411
	/**
412
	 * Remove directories of packages created by tests
413
	 *
414
	 * @author Christopher Hlubek <hlubek@networkteam.com>
415
	 */
416
	protected function tearDown() {
417
		$yetAnotherTestPackagePath = FLOW3_PATH_PACKAGES . '/' . 'YetAnotherTestPackage';
418
		if(is_dir($yetAnotherTestPackagePath)) {
419
			F3_FLOW3_Utility_Files::removeDirectoryRecursively($yetAnotherTestPackagePath);
420
		}
421
	}
145 422
}
146 423
?>
Tests/Package/F3_FLOW3_Package_PackageTest.php (Arbeitskopie)
36 36
	 * @author  Robert Lemke <robert@typo3.org>
37 37
	 */
38 38
	public function constructThrowsPackageDoesNotExistException() {
39
		$mockPackageManager = $this->getMock('F3_FLOW3_Package_Manager', array(), array(), '', FALSE);
40
		new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'ThisPackageSurelyDoesNotExist', $mockPackageManager);
39
		new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'ThisPackageSurelyDoesNotExist');
41 40
	}
42 41

  
43 42
	/**
......
48 47
	 * @author  Robert Lemke <robert@typo3.org>
49 48
	 */
50 49
	public function constructThrowsInvalidPathException() {
51
		$mockPackageManager = $this->getMock('F3_FLOW3_Package_Manager', array(), array(), '', FALSE);
52
		new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage', $mockPackageManager);
50
		new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage');
53 51
	}
54 52

  
55 53
	/**
......
58 56
	 * @author Robert Lemke <robert@typo3.org>
59 57
	 */
60 58
	public function constructRejectsInvalidPackageKeys() {
61
		$mockPackageManager = $this->getMock('F3_FLOW3_Package_Manager', array(), array(), '', FALSE);
62
		new F3_FLOW3_Package_Package('Invalid_Package_Key', FLOW3_PATH_PACKAGES . 'TestPackage/', $mockPackageManager);
59
		new F3_FLOW3_Package_Package('Invalid_Package_Key', FLOW3_PATH_PACKAGES . 'TestPackage/');
63 60
	}
64

  
61
	
65 62
	/**
66 63
	 * Test the method getClassFiles() without initializing the package manager
67 64
	 *
......
69 66
	 * @author Robert Lemke <robert@typo3.org>
70 67
	 */
71 68
	public function getClassFilesWorks() {
72
		$mockPackageManager = $this->getMock('F3_FLOW3_Package_Manager', array(), array(), '', FALSE);
73
		$package = new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/', $mockPackageManager);
69
		$package = new F3_FLOW3_Package_Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/');
74 70
		$classFiles = $package->getClassFiles();
75 71

  
76 72
		$this->assertTrue(key_exists('F3_TestPackage_BasicClass', $classFiles), 'The BasicClass is not in the class files array!');
Resources/Fixtures/Package.xml (Revision 0)
1
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
2
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://typo3.org/ns/2008/flow3/package" version="1.0">
3
   <key>YetAnotherTestPackage</key>
4
   <title>Yet another test package</title>
5
   <description>A test package to test the creation of the Package.xml by the Package Manager</description>
6
   <version>0.1.1</version>
7
   <state>Beta</state>
8
   <categories>
9
      <category>Testing</category>
10
      <category>System</category>
11
   </categories>
12
   <parties>
13
      <person role="LeadDeveloper">
14
         <name>Robert Lemke</name>
15
         <email>robert@typo3.org</email>
16
         <website>http://www.flow3.org</website>
17
         <company>TYPO3 Association</company>
18
         <repositoryUserName>robert</repositoryUserName>
19
      </person>
20
      <company>
21
         <name>Acme Inc.</name>
22
         <email>info@acme.com</email>
23
         <website>http://www.acme.com</website>
24
      </company>
25
   </parties>
26
   <constraints>
27
      <depends>
28
         <package minVersion="1.0.0" maxVersion="1.9.9">FLOW3</package>
29
      </depends>
30
      <suggests>
31
         <system type="Memory">16M</system>
32
      </suggests>
33
   </constraints>
34
</package>
Classes/Controller/F3_FLOW3_Controller_Package.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage MVC
20
 * @version $Id$
21
 */
22

  
23
/**
24
 * Package controller to handle packages from CLI (create/activate/deactivate packages)
25
 *
26
 * @package FLOW3
27
 * @subpackage MVC
28
 * @version $Id$
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Controller_Package extends F3_FLOW3_MVC_Controller_ActionController {
32

  
33
	/**
34
	 * @var F3_FLOW3_Package_ManagerInterface
35
	 */
36
	protected $packageManager;
37
	
38
	/**
39
	 * @var array
40
	 */
41
	protected $supportedRequestTypes = array('F3_FLOW3_MVC_CLI_Request');
42

  
43
	
44
	/**
45
	 * Initializes this controller
46
	 *
47
	 * @return void
48
	 * @author Tobias Liebig <mail_typo3@etobi.de>
49
	 */
50
	public function initializeController() {
51
		$this->arguments->addNewArgument('packageKey');
52
	}
53
	
54
	
55
	/**
56
	 * Injects the package manager
57
	 *
58
	 * @param F3_FLOW3_Package_ManagerInterface $packageManager
59
	 * @return void
60
	 * @author Tobias Liebig <mail_typo3@etobi.de>
61
	 */
62
	public function injectPackageManager(F3_FLOW3_Package_ManagerInterface $packageManager) {
63
		$this->packageManager = $packageManager;
64
	}
65

  
66
	
67
	/**
68
	 * default action (no arguments given)
69
	 * @return void
70
	 * @author Tobias Liebig <mail_typo3@etobi.de>
71
	 */
72
	public function defaultAction() {
73
		return $this->helpAction();
74
	}
75
	
76
	
77
	/**
78
	 * create the package 
79
	 * 
80
	 * @return void
81
	 * @author Tobias Liebig <mail_typo3@etobi.de>
82
	 */
83
	public function createAction() {
84
		if ($this->arguments['packageKey'] == '') {
85
			return $this->helpAction();
86
		} else {
87
			$this->packageManager->createPackage($this->arguments['packageKey']->getValue());
88
			return 'new package "' . $this->arguments['packageKey'] . '" created.' . chr(10);
89
		}
90
	}
91
	
92

  
93
	/**
94
	 * activate the package
95
	 * 
96
	 * @return void
97
	 * @author Tobias Liebig <mail_typo3@etobi.de>
98
	 */
99
	public function activateAction() {
100
		if ($this->arguments['packageKey'] == '') {
101
			return $this->helpAction();
102
		} else {
103
			$this->packageManager->activatePackage($this->arguments['packageKey']->getValue());
104
			return 'package "' . $this->arguments['packageKey'] . '" activated.' . chr(10);
105
		}
106
	}
107
	
108

  
109
	/**
110
	 * deactivate the package
111
	 * 
112
	 * @return void
113
	 * @author Tobias Liebig <mail_typo3@etobi.de>
114
	 */
115
	public function deactivateAction() {
116
		if ($this->arguments['packageKey'] == '') {
117
			return $this->helpAction();
118
		} else {
119
			$this->packageManager->deactivatePackage($this->arguments['packageKey']->getValue());
120
			return 'package "' . $this->arguments['packageKey'] . '" deactivated.' . chr(10);
121
		}
122
	}
123
	
124
	
125
	/**
126
	 * displays a help screen
127
	 *
128
	 * @return void
129
	 * @author Tobias Liebig <mail_typo3@etobi.de>
130
	 */
131
	public function helpAction() {
132
		return chr(10) .
133
			'FLOW3 Package CLI Controller' . chr(10) .
134
			'Usage: php index_dev.php FLOW3 Package <command> package-key=<PACKAGE>' . chr(10).
135
			chr(10) .
136
			'<command>:' . chr(10) .
137
			'  create     - create a new package' . chr(10).
138
			'  activate   - activate a package' . chr(10).
139
			'  deactivate - activate a package' . chr(10)
140
		;
141
	}
142
}
143

  
144
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_Company.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * Package company party meta model
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Package_Meta_Company extends F3_FLOW3_Package_Meta_Party {
32
	/**
33
	 * @return string Party type "company"
34
	 * @author Christoppher Hlubek <hlubek@networkteam.com>
35
	 */
36
	protected function getPartyType() {
37
		return 'company';
38
	}
39
	
40
}
41
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_Person.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * Package person party meta model
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Package_Meta_Person extends F3_FLOW3_Package_Meta_Party {
32
	
33
	/**
34
	 * Company of the person
35
	 * 
36
	 * @var string
37
	 */
38
	protected $company;
39
	
40
	/**
41
	 * Repository user name of the person
42
	 *
43
	 * @var unknown_type
44
	 */
45
	protected $repositoryUserName;
46
	
47
	/**
48
	 * Meta person model constructor
49
	 *
50
	 * @param string $role
51
	 * @param string $name
52
	 * @param string $email
53
	 * @param string $website
54
	 * @param string $company
55
	 * @param string $repositoryUserName
56
	 * @author Christopher Hlubek <hlubek@networkteam.com>
57
	 */
58
	public function __construct($role, $name, $email = null, $website = null, $company = null, $repositoryUserName = null) {
59
		parent::__construct($role, $name, $email, $website);
60
		
61
		$this->company = $company;
62
		$this->repositoryUserName = $repositoryUserName;
63
	}
64
	
65
	/**
66
	 * @return string The company of the person
67
	 * @author Christopher Hlubek <hlubek@networkteam.com>
68
	 */
69
	public function getCompany() {
70
		return $this->company;
71
	}
72

  
73
	/**
74
	 * @return string The repository username
75
	 * @author Christopher Hlubek <hlubek@networkteam.com>
76
	 */
77
	public function getRepositoryUserName() {
78
		return $this->repositoryUserName;
79
	}
80

  
81
	/**
82
	 * @return string Party type "person"
83
	 * @author Christopher Hlubek <hlubek@networkteam.com>
84
	 */
85
	protected function getPartyType() {
86
		return 'person';
87
	}
88
	
89
	/**
90
	 * Write additional information for the person to the XMLWriter
91
	 * 
92
	 * @param XMLWriter $xml
93
	 * @author Christopher Hlubek <hlubek@networkteam.com>
94
	 */
95
	protected function writePartyXML(XMLWriter $xml) {
96
		if(strlen($this->company)) $xml->writeElement('company', $this->company);
97
		if(strlen($this->repositoryUserName)) $xml->writeElement('repositoryUserName', $this->repositoryUserName);
98
	}
99
}
100
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_SystemConstraint.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * System constraint meta model
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Package_Meta_SystemConstraint extends F3_FLOW3_Package_Meta_Constraint {
32
	
33
	/**
34
	 * The type for a system scope constraint (e.g. "Memory")
35
	 * 
36
	 * @var string
37
	 */
38
	protected $type;
39
	
40
	/**
41
	 * Meta system constraint constructor
42
	 *
43
	 * @param string $constraintType
44
	 * @param string $type
45
	 * @param string $value
46
	 * @param string $minVersion
47
	 * @param string $maxVersion
48
	 * @author Christopher Hlubek <hlubek@networkteam.com>
49
	 */
50
	public function __construct($constraintType, $type, $value = null, $minVersion = null, $maxVersion = null) {
51
		if(!strlen($value)) $value = null;
52
		parent::__construct($constraintType, $value, $minVersion, $maxVersion);
53
		$this->type = $type;
54
	}
55
	
56
	/**
57
	 * @return string The system constraint type
58
	 * @author Christopher Hlubek <hlubek@networkteam.com>
59
	 */
60
	public function getType() {
61
		return $this->type;
62
	}
63

  
64
	/**
65
	 * @see F3_FLOW3_Package_Meta_Constraint::getConstraintScope()
66
	 * @author Christopher Hlubek <hlubek@networkteam.com>
67
	 */
68
	protected function getConstraintScope() {
69
		return 'system';
70
	}
71
	
72
	/**
73
	 * Writes an additional type attribute to the system constraint element
74
	 *
75
	 * @param XMLWriter $xml
76
	 * @author Christopher Hlubek <hlubek@networkteam.com>
77
	 */
78
	protected function writeConstraintXML(XMLWriter $xml) {
79
		if(strlen($this->type)) $xml->writeAttribute('type', $this->type);
80
	}
81
}
82
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_Party.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * Party meta model for persons and companies
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
abstract class F3_FLOW3_Package_Meta_Party {
32
	
33
	/**
34
	 * The party role
35
	 * 
36
	 * @var string
37
	 */
38
	protected $role;
39

  
40
	/**
41
	 * Name of the party
42
	 * 
43
	 * @var string
44
	 */
45
	protected $name;
46
	
47
	/**
48
	 * Email of the party
49
	 * 
50
	 * @var string
51
	 */
52
	protected $email;
53
	
54
	/**
55
	 * Website of the party
56
	 * 
57
	 * @var string
58
	 */
59
	protected $website;
60
	
61
	/**
62
	 * Meta party model constructor
63
	 *
64
	 * @param string $role
65
	 * @param string $name
66
	 * @param string $email
67
	 * @param string $website
68
	 * @author Christopher Hlubek <hlubek@networkteam.com>
69
	 */
70
	public function __construct($role, $name, $email = null, $website = null) {
71
		$this->role = $role;
72
		$this->name = $name;
73
		$this->email = $email;
74
		$this->website = $website;
75
	}
76
	
77
	/**
78
	 * @return string The role of the party
79
	 * @author Christopher Hlubek <hlubek@networkteam.com>
80
	 */
81
	public function getRole() {
82
		return $this->role;
83
	}
84
	
85
	/**
86
	 * @return string The name of the party
87
	 * @author Christopher Hlubek <hlubek@networkteam.com>
88
	 */
89
	public function getName() {
90
		return $this->name;
91
	}
92
	
93
	/**
94
	 * @return string The email of the party
95
	 * @author Christopher Hlubek <hlubek@networkteam.com>
96
	 */
97
	public function getEmail() {
98
		return $this->email;
99
	}
100
	
101
	/**
102
	 * @return string The website of the party
103
	 * @author Christopher Hlubek <hlubek@networkteam.com>
104
	 */
105
	public function getWebsite() {
106
		return $this->website;
107
	}
108

  
109
	/**
110
	 * Write general party information to the XMLWriter.
111
	 * 
112
	 * Subclasses can contribute to the XML with
113
	 * writePartyXML(...).
114
	 *
115
	 * @param XMLWriter $xml
116
	 * @author Christopher Hlubek <hlubek@networkteam.com>
117
	 */
118
	public function writeXML(XMLWriter $xml) {
119
		$xml->startElement($this->getPartyType());
120
		
121
		if(strlen($this->role))	$xml->writeAttribute('role', $this->role);
122
		
123
		if(strlen($this->name)) $xml->writeElement('name', $this->name);
124
		if(strlen($this->email)) $xml->writeElement('email', $this->email);
125
		if(strlen($this->website)) $xml->writeElement('website', $this->website);
126
		
127
		$this->writePartyXML($xml);
128
		
129
		$xml->endElement(); // party
130
	}
131
	
132
	/**
133
	 * The party type will be used for the XML element name
134
	 * of the party.
135
	 * 
136
	 * @return string The type of the party (person, company)
137
	 * @author Christopher Hlubek <hlubek@networkteam.com>
138
	 */
139
	protected abstract function getPartyType();
140
	
141
	/**
142
	 * Stub for subclass contribution to the party XML.
143
	 *
144
	 * @param XMLWriter $xml
145
	 * @author Christopher Hlubek <hlubek@networkteam.com>
146
	 */
147
	protected function writePartyXML(XMLWriter $xml) {
148
		
149
	}
150
}
151
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_PackageConstraint.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * Package constraint meta model
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
class F3_FLOW3_Package_Meta_PackageConstraint extends F3_FLOW3_Package_Meta_Constraint {
32
	/**
33
	 * @see F3_FLOW3_Package_Meta_Constraint::getConstraintScope()
34
	 * @author Christopher Hlubek <hlubek@networkteam.com>
35
	 */
36
	protected function getConstraintScope() {
37
		return 'package';
38
	}
39
}
40
?>
Classes/Package/Meta/F3_FLOW3_Package_Meta_Constraint.php (Revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3

  
4
/*                                                                        *
5
 * This script is part of the TYPO3 project - inspiring people to share!  *
6
 *                                                                        *
7
 * TYPO3 is free software; you can redistribute it and/or modify it under *
8
 * the terms of the GNU General Public License version 2 as published by  *
9
 * the Free Software Foundation.                                          *
10
 *                                                                        *
11
 * This script is distributed in the hope that it will be useful, but     *
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
13
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General      *
14
 * Public License for more details.                                       *
15
 *                                                                        */
16

  
17
/**
18
 * @package FLOW3
19
 * @subpackage Package
20
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
21
 */
22

  
23
/**
24
 * Constraint meta model
25
 *
26
 * @package FLOW3
27
 * @subpackage Package
28
 * @version $Id:F3_FLOW3_Package_Meta.php 203 2007-03-30 13:17:37Z robert $
29
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
30
 */
31
abstract class F3_FLOW3_Package_Meta_Constraint {
32
	
33
	/**
34
	 * One of depends, conflicts or suggests
35
	 *
36
	 * @var string The constraint type
37
	 */
38
	protected $constraintType;
39
	
40
	/**
41
	 * @var string The constraint name or value
42
	 */
43
	protected $value;
44
	
45
	/**
46
	 * @var string The minimum version
47
	 */
48
	protected $minVersion;
49
	
50
	/**
51
	 * @var string The maximum version
52
	 */
53
	protected $maxVersion;
54
	
55
	/**
56
	 * Meta constraint constructor
57
	 *
58
	 * @param string $constraintType
59
	 * @param string $value
60
	 * @param string $minVersion
61
	 * @param string $maxVersion
62
	 * @author Christopher Hlubek <hlubek@networkteam.com>
63
	 */
64
	public function __construct($constraintType, $value, $minVersion = null, $maxVersion = null) {
65
		$this->constraintType = $constraintType;
66
		$this->value = $value;
67
		$this->minVersion = $minVersion;
68
		$this->maxVersion = $maxVersion;
69
	}
70
	
71
	/**
72
	 * @return string The constraint name or value
73
	 * @author Christopher Hlubek <hlubek@networkteam.com>
74
	 */
75
	public function getValue() {
76
		return $this->value;
77
	}
78
	
79
	/**
80
	 * @return string The minimum version
81
	 * @author Christopher Hlubek <hlubek@networkteam.com>
82
	 */
83
	public function getMinVersion() {
84
		return $this->minVersion;
85
	}
86
	
87
	/**
88
	 * @return string The maximum version
89
	 * @author Christopher Hlubek <hlubek@networkteam.com>
90
	 */
91
	public function getMaxVersion() {
92
		return $this->maxVersion;
93
	}
94
	
95
	/**
96
	 * @return string The constraint type (depends, conflicts, suggests)
97
	 * @author Christopher Hlubek <hlubek@networkteam.com>
98
	 */
99
	public function getConstraintType() {
100
		return $this->constraintType;
101
	}
102

  
103
	/**
104
	 * Write the constraint to a XMLWriter instance. This will
105
	 * usually be used from the F3_FLOW3_Package_Meta to output
106
	 * the Package.xml.
107
	 * 
108
	 * The subclasses use the writeConstraintXML(...)
109
	 * template method to write additional XML. 
110
	 * 
111
	 * @param XMLWriter $xml: The XMLWriter to write to
112
	 * @author Christopher Hlubek <hlubek@networkteam.com>
113
	 */
114
	public function writeXML(XMLWriter $xml) {
115
		$xml->startElement($this->getConstraintScope());
116
		
117
		if(strlen($this->minVersion)) $xml->writeAttribute('minVersion', $this->minVersion);
118
		if(strlen($this->maxVersion)) $xml->writeAttribute('maxVersion', $this->maxVersion);
119
		
120
		// This has to come before text(...) to allow for writing of additional attributes from subclasses
121
		$this->writeConstraintXML($xml);
122
		
123
		if(strlen($this->value)) $xml->text($this->value);
124
		
125
		$xml->endElement(); // constraint
126
	}
127
	
128
	/**
129
	 * @return string The constraint scope (package, system)
130
	 */
131
	protected abstract function getConstraintScope();
132
	
133
	/**
134
	 * Stub method for writing additional XML
135
	 * in subclasses.
136
	 *
137
	 * @param XMLWriter $xml
138
	 */
139
	protected function writeConstraintXML(XMLWriter $xml) {
140
		
141
	}
142
}
143

  
144
?>
Classes/Package/F3_FLOW3_Package_Meta.php (Arbeitskopie)
31 31
class F3_FLOW3_Package_Meta implements F3_FLOW3_Package_MetaInterface {
32 32

  
33 33
	/**
34
	 * @var	string The package key
34
	 * @var	string	The package key
35 35
	 */
36 36
	protected $packageKey;
37 37

  
......
44 44
	 * @var string	Package title
45 45
	 */
46 46
	protected $title;
47
	
48
	/**
49
	 * @var string 	Package description
50
	 */
51
	protected $description;
47 52

  
48 53
	/**
49
	 * Constructor
54
	 * @var string 	Package state
55
	 */
56
	protected $state;
57

  
58
	/**
59
	 * @var Array of string	Package categories
60
	 */
61
	protected $categories;
62
	
63
	/**
64
	 * @var Array of F3_FLOW3_Package_Meta_Party	Package parties (person, company)
65
	 */
66
	protected $parties;
67
	
68
	/**
69
	 * @var Array of Array of F3_FLOW3_Package_Meta_Constraint	Package constraints by constraint type (depends, conflicts, suggests)
70
	 */
71
	protected $constraints;
72
	
73
	/**
74
	 * @var Array of string	Constraint types
75
	 */
76
	protected $constraintTypes = array('depends', 'conflicts', 'suggests');
77
	
78
	/**
79
	 * Package meta data constructor
50 80
	 *
51
	 * @param	string				The package key
52
	 * @param   [SimpleXMLElement]	If specified, the XML data (which must be valid package meta XML) will be used to set the meta properties
81
	 * @param	string	$packageKey: The package key
53 82
	 * @return  void
54 83
	 * @author  Robert Lemke <robert@typo3.org>
55
	 * @todo    Validate the $packageMetaXML as soon as we have a DTD / Schema for it
84
	 * @author  Christopher Hlubek <hlubek@networkteam.com>
56 85
	 */
57
	public function __construct($packageKey, SimpleXMLElement $packageMetaXML = NULL) {
58
		if ($packageMetaXML !== NULL) {
59
			$this->packageKey = (string)$packageMetaXML->packageKey;
60
			$this->version = (string)$packageMetaXML->version;
61
			$this->title = (string)$packageMetaXML->title;
86
	public function __construct($packageKey) {
87
		$this->packageKey = $packageKey;
88
	}
89
	
90
	/**
91
	 * Set meta information from the package XML
92
	 *
93
	 * @param SimpleXMLElement $packageMetaXML
94
	 * @author  Robert Lemke <robert@typo3.org>
95
	 * @author  Christopher Hlubek <hlubek@networkteam.com>
96
	 * @todo    Validate the $packageMetaXML against RelaxNG schema
97
	 * @todo	Nested too deep, refactor
98
	 */
99
	public function setMetaFromXML(SimpleXMLElement $packageMetaXML) {
100
		$this->version = (string)$packageMetaXML->version;
101
		$this->title = (string)$packageMetaXML->title;
102
		$this->description = (string)$packageMetaXML->description;
103
		$this->state = (string)$packageMetaXML->state;
104
		$this->categories = array();
105
		if($packageMetaXML->categories) {
106
			foreach($packageMetaXML->categories->category as $category) {
107
				$this->categories[] = (string)$category;
108
			}
62 109
		}
110
		$this->parties = array();
111
		if($packageMetaXML->parties) {
112
			foreach($packageMetaXML->parties->person as $person) {
113
				$role = (string)$person['role'];
114
				$this->parties[] = new F3_FLOW3_Package_Meta_Person($role,
115
					(string)$person->name, (string)$person->email, (string)$person->website,
116
					(string)$person->company, (string)$person->repositoryUserName);
117
			}
118
			foreach($packageMetaXML->parties->company as $company) {
... This diff was truncated because it exceeds the maximum size that can be displayed.
(2-2/6)