Sprint-0 » F3_hlubek-1222811784.diff

Revised SVN Patch for code sprint 0 - Christopher Hlubek, 2008-09-30 23:59

View differences:

FLOW3/Tests/Controller/F3_FLOW3_Controller_PackageTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Controller;
4

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

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

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

  
34
	/**
35
	 * @test
36
	 * @author Tobias Liebig <mail_typo3@etobi.de>
37
	 */
38
	public function testCreateActionCallsPackageManagerCreatePackage() {
39
		$packageManager = $this->getMock('F3::FLOW3::Package::ManagerInterface');
40

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

  
45
		$packageController = new F3::FLOW3::Controller::Package($this->componentFactory, $packageManager);
46
		$packageController->injectPackageManager($packageManager);
47
		$packageController->initializeController();
48
		
49
		$argumentPackageKey = new F3::FLOW3::MVC::Controller::Argument('packageKey','Text', $this->componentFactory);
50
		$packageControllerArguments = $packageController->getArguments();
51
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
52

  
53
		$packageController->createAction();
54
	}
55
	
56
	/**
57
	 * @test
58
	 * @author Tobias Liebig <mail_typo3@etobi.de>
59
	 */
60
	public function testActivateActionCallsPackageManagerActivatePackage() {
61
		$packageManager = $this->getMock('F3::FLOW3::Package::ManagerInterface');
62

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

  
67
		$packageController = new F3::FLOW3::Controller::Package($this->componentFactory, $packageManager);
68
		$packageController->injectPackageManager($packageManager);
69
		$packageController->initializeController();
70
		
71
		$argumentPackageKey = new F3::FLOW3::MVC::Controller::Argument('packageKey','Text', $this->componentFactory);
72
		$packageControllerArguments = $packageController->getArguments();
73
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
74

  
75
		$packageController->activateAction();
76
	}
77
	
78
	/**
79
	 * @test
80
	 * @author Tobias Liebig <mail_typo3@etobi.de>
81
	 */
82
	public function testDeactivateActionCallsPackageManagerDeactivatePackage() {
83
		$packageManager = $this->getMock('F3::FLOW3::Package::ManagerInterface');
84

  
85
		$packageManager->expects($this->once())
86
			->method('deactivatePackage')
87
			->with($this->equalTo('FooBarPackageName'));
88

  
89
		$packageController = new F3::FLOW3::Controller::Package($this->componentFactory, $packageManager);
90
		$packageController->injectPackageManager($packageManager);
91
		$packageController->initializeController();
92
		
93
		$argumentPackageKey = new F3::FLOW3::MVC::Controller::Argument('packageKey','Text', $this->componentFactory);
94
		$packageControllerArguments = $packageController->getArguments();
95
		$packageControllerArguments['packageKey']->setValue('FooBarPackageName');
96

  
97
		$packageController->deactivateAction();
98
	}
99

  
100
	/**
101
	 * @test
102
	 * @author Tobias Liebig <mail_typo3@etobi.de>
103
	 */
104
	public function testCreateActionWithoutPackageKeyCallsHelpAction() {
105
		$packageManager = $this->getMock('F3::FLOW3::Package::ManagerInterface');
106
		
107
		$packageController = $this->getMock('F3::FLOW3::Controller::Package',
108
			array('helpAction'),
109
			array($this->componentFactory, $packageManager));
110
		
111
		$packageController->expects($this->once())
112
			->method('helpAction');
113
			
114
		$packageController->initializeController();
115
		
116
		$packageController->createAction();
117
	}
118

  
119
	/**
120
	 * @test
121
	 * @author Tobias Liebig <mail_typo3@etobi.de>
122
	 */
123
	public function testDefaultActionCallsHelpAction() {
124
		$packageManager = $this->getMock('F3::FLOW3::Package::ManagerInterface');
125
		
126
		$packageController = $this->getMock('F3::FLOW3::Controller::Package',
127
			array('helpAction'),
128
			array($this->componentFactory, $packageManager));
129
		
130
		$packageController->expects($this->once())
131
			->method('helpAction');
132
			
133
		$packageController->initializeController();
134
		
135
		$packageController->defaultAction();
136
	}
137
}
138
?>
FLOW3/Tests/Controller/F3_FLOW3_Controller_CacheTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Controller;
4

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

  
18
/**
19
 * Testcase for the Cache Controller (CLI)
20
 *
21
 * @package FLOW3
22
 * @subpackage Controller
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class CacheTest extends F3::Testing::BaseTestCase {
27

  
28
	/**
29
	 * @test
30
	 * @author Tobias Liebig <mail_typo3@etobi.de>
31
	 */
32
	public function testFlushActionCallsCacheManagerFlushCache() {
33
		$cacheManager = $this->getMock('F3::FLOW3::Cache::Manager');
34

  
35
		$cacheManager->expects($this->once())
36
			->method('flushCaches')
37
			->with();
38

  
39
		$cacheController = new F3::FLOW3::Controller::Cache($this->componentFactory, $this->componentFactory->getComponent('F3::FLOW3::Package::ManagerInterface'));
40
		$cacheController->injectCacheManager($cacheManager);
41
		
42
		$cacheController->flushAction();
43
	}
44
}
45

  
46
?>
FLOW3/Tests/Package/Meta/F3_FLOW3_Package_Meta_XMLWriterTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
24
/**
25
 * Testcase for the XML Meta writer
26
 *
27
 * @package FLOW3
28
 * @subpackage Tests
29
 * @version $Id:F3::FLOW3::Package::Test.php 201 2007-03-30 11:18:30Z robert $
30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31
 */
32
class XMLWriterTest extends F3::Testing::BaseTestCase {
33
	
34
	/**
35
	 * @test
36
	 * @author Christopher Hlubek <hlubek@networkteam.com>
37
	 */
38
	public function testWritePackageMetaCreatesXml() {
39
		$packageManager = $this->componentFactory->getComponent('F3::FLOW3::Package::ManagerInterface');
40
		
41
		$meta = new F3::FLOW3::Package::Meta('YetAnotherTestPackage');
42
		$meta->setTitle('Yet another test package');
43
		$meta->setDescription('A test package to test the creation of the Package.xml by the Package Manager');
44
		$meta->setVersion('0.1.1');
45
		$meta->setState('Beta');
46
		$meta->addCategory('Testing');
47
		$meta->addCategory('System');
48
		$meta->addParty(new F3::FLOW3::Package::Meta::Person('LeadDeveloper',
49
			'Robert Lemke', 'robert@typo3.org', 'http://www.flow3.org', 'TYPO3 Association', 'robert'));
50
		$meta->addParty(new F3::FLOW3::Package::Meta::Company(null, 'Acme Inc.', 'info@acme.com', 'http://www.acme.com'));
51
		$meta->addConstraint(new F3::FLOW3::Package::Meta::PackageConstraint('depends',
52
			'FLOW3', '1.0.0', '1.9.9'));
53
		$meta->addConstraint(new F3::FLOW3::Package::Meta::SystemConstraint('suggests',
54
			'Memory', '16M'));
55
		
56
		$metaWriter = new F3::FLOW3::Package::Meta::XMLWriter();
57
		
58
		$xml = $metaWriter->writePackageMeta($meta);
59
		
60
		$this->assertXmlStringEqualsXmlFile($packageManager->getPackage('FLOW3')->getResourcesPath() . 'Fixtures/Package.xml', $xml);
61
	}
62
}
63
?>
FLOW3/Tests/Package/Meta/F3_FLOW3_Package_Meta_XMLReaderTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
24
/**
25
 * Testcase for the XML Meta reader
26
 *
27
 * @package FLOW3
28
 * @subpackage Tests
29
 * @version $Id:F3::FLOW3::Package::Test.php 201 2007-03-30 11:18:30Z robert $
30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31
 */
32
class XMLReaderTest extends F3::Testing::BaseTestCase {
33
	
34
	/**
35
	 * Test the actual reading of a Package.xml file. This test
36
	 * uses the TestPackage as a fixture
37
	 * 
38
	 * @test
39
	 * @author Christopher Hlubek <hlubek@networkteam.com>
40
	 */
41
	public function readPackageMetaReadsPackageXML() {
42
		$package = $this->getMock('F3::FLOW3::Package::PackageInterface');
43

  
44
		$package->expects($this->atLeastOnce())
45
			->method('getPackageInfoPath')
46
			->will($this->returnValue(FLOW3_PATH_PACKAGES . 'TestPackage/' . F3::FLOW3::Package::Package::DIRECTORY_META . F3::FLOW3::Package::Package::FILENAME_PACKAGEINFO));
47
		
48
		$package->expects($this->any())
49
			->method('getPackageKey')
50
			->will($this->returnValue('TestPackage'));
51
			
52
		$metaReader = new F3::FLOW3::Package::Meta::XMLReader();
53
		
54
		$packageMeta = $metaReader->readPackageMeta($package);
55
		
56
		$this->assertEquals('TestPackage', $packageMeta->getPackageKey());
57
		$this->assertEquals('Test package', $packageMeta->getTitle());
58
		$this->assertEquals('0.0.1', $packageMeta->getVersion());
59
		$this->assertEquals('This package is used for testing the package- and component manager', $packageMeta->getDescription());
60
		$this->assertEquals('Alpha', $packageMeta->getState());
61
		$this->assertEquals(array('System', 'Testing'), $packageMeta->getCategories());
62
		
63
		$parties = $packageMeta->getParties();
64
		$this->assertTrue(is_array($parties));
65
		$person1 = $parties[0];
66
		$this->assertType('F3::FLOW3::Package::Meta::Person', $person1);
67
		$this->assertEquals('LeadDeveloper', $person1->getRole());
68
		$this->assertEquals('Robert Lemke', $person1->getName());
69
		$this->assertEquals('robert@typo3.org', $person1->getEmail());
70

  
71
		$constraints = $packageMeta->getConstraintsByType('depends');
72
		$this->assertTrue(is_array($constraints));
73
		
74
		$this->assertType('F3::FLOW3::Package::Meta::PackageConstraint', $constraints[0]);
75
		$this->assertEquals('depends', $constraints[0]->getConstraintType());
76
		$this->assertEquals('FLOW3', $constraints[0]->getValue());
77
		$this->assertEquals('1.0.0', $constraints[0]->getMinVersion());
78
		$this->assertEquals('1.9.9', $constraints[0]->getMaxVersion());
79
		$this->assertType('F3::FLOW3::Package::Meta::SystemConstraint', $constraints[1]);
80
		$this->assertNull($constraints[1]->getValue());
81
		$this->assertEquals('PHP', $constraints[1]->getType());
82
		$this->assertEquals('5.3.0', $constraints[1]->getMinVersion());
83
	}
84
		
85
}
86
?>
FLOW3/Tests/Package/F3_FLOW3_Package_MetaTest.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package;
4

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

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

  
24
/**
25
 * Testcase for the meta class
26
 *
27
 * @package FLOW3
28
 * @subpackage Tests
29
 * @version $Id$
30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31
 */
32
class MetaTest extends F3::Testing::BaseTestCase {
33

  
34
	/**
35
	 * @test
36
	 * @expectedException InvalidArgumentException
37
	 * @author Christopher Hlubek <hlubek@networkteam.com>
38
	 */
39
	public function settingInvalidPackageStateThrowsInvalidArgumentException() {
40
		$meta = new F3::FLOW3::Package::Meta('YetAnotherTestPackage');
41
		$meta->setState('Invalid');
42
	}
43
}
44
?>
FLOW3/Tests/Package/F3_FLOW3_Package_ManagerTest.php (working copy)
26 26
 *
27 27
 * @package FLOW3
28 28
 * @subpackage Tests
29
 * @version $Id:F3::FLOW3::Package::ManagerTest.php 201 2007-03-30 11:18:30Z robert $
29
 * @version $Id$
30 30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31 31
 */
32 32
class ManagerTest extends F3::Testing::BaseTestCase {
......
143 143
		$packageManager->initialize();
144 144
		$this->assertEquals('TestPackage', $packageManager->getCaseSensitivePackageKey('testpackage'));
145 145
	}
146

  
147
	/**
148
	 * Check creating a new package creates a package folder and returns a package
149
	 *
150
	 * @test
151
	 * @author Christopher Hlubek <hlubek@networkteam.com>
152
	 */
153
	public function testCreatePackageCreatesPackageFolderAndReturnsPackage() {
154
		$packageManager = new F3::FLOW3::Package::Manager();
155
		$packageManager->initialize();
156

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

  
159
		$this->assertType('F3::FLOW3::Package::PackageInterface', $package);
160
		$this->assertEquals('YetAnotherTestPackage', $package->getPackageKey());
161

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

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

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

  
178
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
179
		$this->assertTrue(is_file($packagePath . F3::FLOW3::Package::Package::DIRECTORY_META . F3::FLOW3::Package::Package::FILENAME_PACKAGEINFO),
180
			'Mandatory Package.xml was created');
181
	}
182
	
183
	/**
184
	 * Check createPackage uses a meta writer to write the contents of the package meta to a file
185
	 * 
186
	 * @test
187
	 * @author Christopher Hlubek <hlubek@networkteam.com>
188
	 */
189
	public function testCreatePackageWithMetadataUsesMetaWriter() {
190

  
191
		$metaWriter = $this->getMock('F3::FLOW3::Package::Meta::WriterInterface');
192
		$metaWriter->expects($this->atLeastOnce())
193
			->method('writePackageMeta')
194
			->will($this->returnValue('<package/>'));
195

  
196
		$packageManager = new F3::FLOW3::Package::Manager($metaWriter);
197
		$packageManager->initialize();
198

  
199
		$meta = $this->getMock('F3::FLOW3::Package::Meta', array(), array('YetAnotherTestPackage'));
200
		
201
		$packageManager->createPackage('YetAnotherTestPackage', $meta);
202
			
203
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
204
		$this->assertStringEqualsFile($packagePath . F3::FLOW3::Package::Package::DIRECTORY_META . F3::FLOW3::Package::Package::FILENAME_PACKAGEINFO, '<package/>');
205
	}
206

  
207
	/**
208
	 * Check create package creates the folders for
209
	 * classes, configuration, documentation, resources and tests
210
	 *
211
	 * @test
212
	 * @author Christopher Hlubek <hlubek@networkteam.com>
213
	 */
214
	public function testCreatePackageCreatesClassesConfigurationDocumentationResourcesAndTestsFolders() {
215
		$packageManager = new F3::FLOW3::Package::Manager();
216
		$packageManager->initialize();
217

  
218
		$packageManager->createPackage('YetAnotherTestPackage');
219

  
220
		$packagePath = $packageManager->getPackagePath('YetAnotherTestPackage');
221
		$this->assertTrue(is_dir($packagePath . F3::FLOW3::Package::Package::DIRECTORY_CLASSES));
222
		$this->assertTrue(is_dir($packagePath . F3::FLOW3::Package::Package::DIRECTORY_CONFIGURATION));
223
		$this->assertTrue(is_dir($packagePath . F3::FLOW3::Package::Package::DIRECTORY_DOCUMENTATION));
224
		$this->assertTrue(is_dir($packagePath . F3::FLOW3::Package::Package::DIRECTORY_RESOURCES));
225
		$this->assertTrue(is_dir($packagePath . F3::FLOW3::Package::Package::DIRECTORY_TESTS));
226
	}
227

  
228
	/**
229
	 * @test
230
	 * @author Christopher Hlubek <hlubek@networkteam.com>
231
	 */
232
	public function testCreatePackageThrowsExceptionForInvalidPackageKey() {
233
		$packageManager = new F3::FLOW3::Package::Manager();
234
		$packageManager->initialize();
235

  
236
		try {
237
			$packageManager->createPackage('Invalid_Package_Key');
238
		} catch(Exception $exception) {
239
			$this->assertEquals(1220722210, $exception->getCode(), 'createPackage() throwed an exception but with an unexpected error code.');
240
		}
241

  
242
		$this->assertFalse(is_dir(FLOW3_PATH_PACKAGES . 'Invalid_Package_Key'), 'Package folder with invalid package key was created');
243
	}
244

  
245
	/**
246
	 * Check handling of duplicate package keys in package creation
247
	 *
248
	 * @test
249
	 * @author Christopher Hlubek <hlubek@networkteam.com>
250
	 */
251
	public function testCreatePackageThrowsExceptionForExistingPackageKey() {
252
		$packageManager = new F3::FLOW3::Package::Manager();
253
		$packageManager->initialize();
254

  
255
		try {
256
			$packageManager->createPackage('TestPackage');
257
		} catch(Exception $exception) {
258
			$this->assertEquals(1220722873, $exception->getCode(), 'createPackage() throwed an exception but with an unexpected error code.');
259
			return;
260
		}
261
		$this->fail('Create package didnt throw an exception for an existing package key');
262
	}
263

  
264
	/**
265
	 * @test
266
	 * @author Thomas Hempel <thomas@typo3.org>
267
	 */
268
	public function testCreatePackageCreatesDeactivatedPackage() {
269
		$packageManager = new F3::FLOW3::Package::Manager();
270
		$packageManager->initialize();
271

  
272
		$packageKey = 'YetAnotherTestPackage';
273
		$packageManager->createPackage($packageKey);
274

  
275
		$this->assertFalse($packageManager->isPackageActive($packageKey));
276
	}
277

  
278

  
279
	/**
280
	 * Check package key validation accepts only valid keys
281
	 *
282
	 * @test
283
	 * @author Christopher Hlubek <hlubek@networkteam.com>
284
	 */
285
	public function getPackageKeyValidationWorks() {
286
		$this->assertFalse($this->packageManager->isPackageKeyValid('Invalid_Package_Key'));
287
		$this->assertFalse($this->packageManager->isPackageKeyValid('invalidPackageKey'));
288
		$this->assertFalse($this->packageManager->isPackageKeyValid('1nvalidPackageKey'));
289
		$this->assertTrue($this->packageManager->isPackageKeyValid('ValidPackageKey'));
290
	}
291

  
292
	/**
293
	 * @test
294
	 * @author Thomas Hempel <thomas@typo3.org>
295
	 */
296
	public function testDeacivatePackageRemovesPackageFromActivePackages() {
297
		$packageManager = new F3::FLOW3::Package::Manager();
298
		$packageManager->initialize();
299

  
300
		$packageKey = 'YetAnotherTestPackage';
301

  
302
		$packageManager->createPackage($packageKey);
303
		$packageManager->activatePackage($packageKey);
304
		$packageManager->deactivatePackage($packageKey);
305

  
306
		$this->assertFalse($packageManager->isPackageActive($packageKey));
307
	}
308

  
309
	/**
310
	 * @test
311
	 * @author Thomas Hempel <thomas@typo3.org>
312
	 */
313
	public function testActivatePackagesAddsPackageToActivePackages() {
314
		$packageManager = new F3::FLOW3::Package::Manager();
315
		$packageManager->initialize();
316

  
317
		$packageKey = 'YetAnotherTestPackage';
318
		$packageManager->createPackage($packageKey);
319
		$packageManager->activatePackage($packageKey);
320

  
321
		$this->assertTrue($packageManager->isPackageActive($packageKey));
322
	}
323

  
324
	/**
325
	 * @test
326
	 * @author Thomas Hempel <thomas@typo3.org>
327
	 */
328
	public function testRemovePackageThrowsErrorIfPackageIsNotAvailable() {
329
		$packageManager = new F3::FLOW3::Package::Manager();
330
		$packageManager->initialize();
331

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

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

  
357
	/**
358
	 * @test
359
	 * @author Thomas Hempel <thomas@typo3.org>
360
	 */
361
	public function testRemovePackageRemovesPackageFromAvailablePackages() {
362
		$packageManager = new F3::FLOW3::Package::Manager();
363
		$packageManager->initialize();
364

  
365
		$packageKey = 'YetAnotherTestPackage';
366
		$packageManager->createPackage($packageKey);
367
		$packageManager->removePackage($packageKey);
368

  
369
		$this->assertFalse($packageManager->isPackageAvailable($packageKey));
370
	}
371

  
372
	/**
373
	 * @test
374
	 * @author Thomas Hempel <thomas@typo3.org>
375
	 */
376
	public function testRemovePackageRemovesPackageFromActivePackages() {
377
		$packageManager = new F3::FLOW3::Package::Manager();
378
		$packageManager->initialize();
379

  
380
		$packageKey = 'YetAnotherTestPackage';
381
		$packageManager->createPackage($packageKey);
382
		$packageManager->activatePackage($packageKey);
383
		$packageManager->removePackage($packageKey);
384

  
385
		$this->assertFalse($packageManager->isPackageActive($packageKey));
386
	}
387

  
388
	/**
389
	 * @test
390
	 * @author Thomas Hempel <thomas@typo3.org>
391
	 */
392
	public function testRemovePackageRemovesPackageDirectoryFromFilesystem() {
393
		$packageManager = new F3::FLOW3::Package::Manager();
394
		$packageManager->initialize();
395

  
396
		$packageKey = 'YetAnotherTestPackage';
397
		$packageManager->createPackage($packageKey);
398
		$packagePath = $packageManager->getPackagePath($packageKey);
399

  
400
		$packageManager->removePackage($packageKey);
401

  
402
		$this->assertFalse(file_exists($packagePath), $packagePath);
403
	}
404

  
405

  
406
	/**
407
	 * Remove directories of packages created by tests
408
	 *
409
	 * @author Christopher Hlubek <hlubek@networkteam.com>
410
	 */
411
	protected function tearDown() {
412
		$yetAnotherTestPackagePath = FLOW3_PATH_PACKAGES . '/' . 'YetAnotherTestPackage';
413
		if(is_dir($yetAnotherTestPackagePath)) {
414
			F3::FLOW3::Utility::Files::removeDirectoryRecursively($yetAnotherTestPackagePath);
415
		}
416
	}
146 417
}
147 418
?>
FLOW3/Tests/Package/F3_FLOW3_Package_PackageTest.php (working copy)
26 26
 *
27 27
 * @package FLOW3
28 28
 * @subpackage Tests
29
 * @version $Id:F3::FLOW3::Package::Test.php 201 2007-03-30 11:18:30Z robert $
29
 * @version $Id$
30 30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31 31
 */
32 32
class PackageTest extends F3::Testing::BaseTestCase {
......
37 37
	 * @author  Robert Lemke <robert@typo3.org>
38 38
	 */
39 39
	public function constructThrowsPackageDoesNotExistException() {
40
		$mockPackageManager = $this->getMock('F3::FLOW3::Package::Manager', array(), array(), '', FALSE);
41
		new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'ThisPackageSurelyDoesNotExist', $mockPackageManager);
40
		new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'ThisPackageSurelyDoesNotExist');
42 41
	}
43 42

  
44 43
	/**
......
49 48
	 * @author  Robert Lemke <robert@typo3.org>
50 49
	 */
51 50
	public function constructThrowsInvalidPathException() {
52
		$mockPackageManager = $this->getMock('F3::FLOW3::Package::Manager', array(), array(), '', FALSE);
53
		new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage', $mockPackageManager);
51
		new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage');
54 52
	}
55 53

  
56 54
	/**
......
59 57
	 * @author Robert Lemke <robert@typo3.org>
60 58
	 */
61 59
	public function constructRejectsInvalidPackageKeys() {
62
		$mockPackageManager = $this->getMock('F3::FLOW3::Package::Manager', array(), array(), '', FALSE);
63
		new F3::FLOW3::Package::Package('Invalid_Package_Key', FLOW3_PATH_PACKAGES . 'TestPackage/', $mockPackageManager);
60
		new F3::FLOW3::Package::Package('Invalid_Package_Key', FLOW3_PATH_PACKAGES . 'TestPackage/');
64 61
	}
65 62

  
66 63
	/**
......
70 67
	 * @author Robert Lemke <robert@typo3.org>
71 68
	 */
72 69
	public function getClassFilesWorks() {
73
		$mockPackageManager = $this->getMock('F3::FLOW3::Package::Manager', array(), array(), '', FALSE);
74
		$package = new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/', $mockPackageManager);
70
		$package = new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/');
75 71
		$classFiles = $package->getClassFiles();
76 72

  
77 73
		$this->assertTrue(key_exists('F3::TestPackage::BasicClass', $classFiles), 'The BasicClass is not in the class files array!');
......
79 75
		$this->assertTrue($classFiles['F3::TestPackage::BasicClass'] == 'F3_TestPackage_BasicClass.php', 'Class files array contains wrong path for BasicClass!');
80 76
		$this->assertTrue($classFiles['F3::TestPackage::SubDirectory::ClassInSubDirectory'] == 'SubDirectory/F3_TestPackage_SubDirectory_ClassInSubDirectory.php', 'Class files array contains wrong path for ClassInSubDirectory!');
81 77
	}
78
	
79
	/**
80
	 * Test that getPackageMeta() uses a MetaReader instance
81
	 * 
82
	 * @test
83
	 * @author Christopher Hlubek <hlubek@networkteam.com>
84
	 */
85
	public function getPackageMetaUsesMetaReader() {
86
		$metaReader = $this->getMock('F3::FLOW3::Package::Meta::ReaderInterface');
87
		
88
		$package = new Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/', $metaReader);
89

  
90
		$meta = $this->getMock('F3::FLOW3::Package::MetaInterface');
91
		
92
		$metaReader->expects($this->once())
93
			->method('readPackageMeta')
94
			// ->with($this->identicalTo($package)) FIXME chlu: doesn't work, why?
95
			->will($this->returnValue($meta));
96
			
97
		$getPackageMetaReturnValue = $package->getPackageMeta();
98
		
99
		$this->assertSame($meta, $getPackageMetaReturnValue);
100
	}
101
	
102
	/**
103
	 * @test
104
	 * @author Christopher Hlubek <hlubek@networkteam.com>
105
	 */
106
	public function getPackageInfoPathReturnsPathToPackageXML() {
107
		$package = new F3::FLOW3::Package::Package('TestPackage', FLOW3_PATH_PACKAGES . 'TestPackage/');
108
		$packageMetaPath = $package->getPackageInfoPath();
109
		
110
		$this->assertEquals($package->getPackagePath() . Package::DIRECTORY_META . Package::FILENAME_PACKAGEINFO, $packageMetaPath);
111
	}
82 112
}
83 113
?>
FLOW3/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>
FLOW3/Classes/Controller/F3_FLOW3_Controller_Package.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Controller;
4

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

  
18
/**
19
 * Package controller to handle packages from CLI (create/activate/deactivate packages)
20
 *
21
 * @package FLOW3
22
 * @subpackage MVC
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class Package extends F3::FLOW3::MVC::Controller::ActionController {
27

  
28
	/**
29
	 * @var F3::FLOW3::Package::ManagerInterface
30
	 */
31
	protected $packageManager;
32
	
33
	/**
34
	 * @var array
35
	 */
36
	protected $supportedRequestTypes = array('F3::FLOW3::MVC::CLI::Request');
37

  
38
	/**
39
	 * Initializes this controller
40
	 *
41
	 * @return void
42
	 * @author Tobias Liebig <mail_typo3@etobi.de>
43
	 */
44
	public function initializeController() {
45
		$this->arguments->addNewArgument('packageKey');
46
	}
47

  
48
	/**
49
	 * Injects the package manager
50
	 *
51
	 * @param F3::FLOW3::Package::ManagerInterface $packageManager
52
	 * @return void
53
	 * @author Tobias Liebig <mail_typo3@etobi.de>
54
	 */
55
	public function injectPackageManager(F3::FLOW3::Package::ManagerInterface $packageManager) {
56
		$this->packageManager = $packageManager;
57
	}
58

  
59
	/**
60
	 * default action (no arguments given)
61
	 * @return void
62
	 * @author Tobias Liebig <mail_typo3@etobi.de>
63
	 */
64
	public function defaultAction() {
65
		return $this->helpAction();
66
	}
67

  
68
	/**
69
	 * Action for creating a package 
70
	 * 
71
	 * @return void
72
	 * @author Tobias Liebig <mail_typo3@etobi.de>
73
	 */
74
	public function createAction() {
75
		if ($this->arguments['packageKey'] == '') {
76
			return $this->helpAction();
77
		} else {
78
			$this->packageManager->createPackage($this->arguments['packageKey']->getValue());
79
			return 'new package "' . $this->arguments['packageKey'] . '" created.' . chr(10);
80
		}
81
	}
82

  
83
	/**
84
	 * Action for activating a package
85
	 * 
86
	 * @return void
87
	 * @author Tobias Liebig <mail_typo3@etobi.de>
88
	 */
89
	public function activateAction() {
90
		if ($this->arguments['packageKey'] == '') {
91
			return $this->helpAction();
92
		} else {
93
			$this->packageManager->activatePackage($this->arguments['packageKey']->getValue());
94
			return 'package "' . $this->arguments['packageKey'] . '" activated.' . chr(10);
95
		}
96
	}
97

  
98
	/**
99
	 * Action for deactivating a package
100
	 * 
101
	 * @return void
102
	 * @author Tobias Liebig <mail_typo3@etobi.de>
103
	 */
104
	public function deactivateAction() {
105
		if ($this->arguments['packageKey'] == '') {
106
			return $this->helpAction();
107
		} else {
108
			$this->packageManager->deactivatePackage($this->arguments['packageKey']->getValue());
109
			return 'package "' . $this->arguments['packageKey'] . '" deactivated.' . chr(10);
110
		}
111
	}
112

  
113
	/**
114
	 * Action for displaying a help screen
115
	 *
116
	 * @return void
117
	 * @author Tobias Liebig <mail_typo3@etobi.de>
118
	 */
119
	public function helpAction() {
120
		return chr(10) .
121
			'FLOW3 Package CLI Controller' . chr(10) .
122
			'Usage: php index_dev.php FLOW3 Package <command> package-key=<PACKAGE>' . chr(10).
123
			chr(10) .
124
			'<command>:' . chr(10) .
125
			'  create     - create a new package' . chr(10).
126
			'  activate   - activate a package' . chr(10).
127
			'  deactivate - activate a package' . chr(10)
128
		;
129
	}
130
}
131

  
132
?>
FLOW3/Classes/Controller/F3_FLOW3_Controller_Cache.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Controller;
4

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

  
18
/**
19
 * Package controller to handle cache from CLI (flush)
20
 *
21
 * @package FLOW3
22
 * @subpackage MVC
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class Cache extends F3::FLOW3::MVC::Controller::ActionController {
27

  
28
	/**
29
	 * @var F3::FLOW3::Cache::Manager
30
	 */
31
	protected $cacheManager;
32
	
33
	/**
34
	 * @var array
35
	 */
36
	protected $supportedRequestTypes = array('F3::FLOW3::MVC::CLI::Request');
37

  
38
	/**
39
	 * Injects the cache manager
40
	 *
41
	 * @param F3::FLOW3::Cache::Manager $cacheManager
42
	 * @return void
43
	 * @author Tobias Liebig <mail_typo3@etobi.de>
44
	 */
45
	public function injectCacheManager(F3::FLOW3::Cache::Manager $cacheManager) {
46
		$this->cacheManager = $cacheManager;
47
	}
48

  
49
	/**
50
	 * Action for cache flushing
51
	 * 
52
	 * @return void
53
	 * @author Tobias Liebig <mail_typo3@etobi.de>
54
	 */
55
	public function flushAction() {
56
		$this->cacheManager->flushCaches();
57
		return 'all caches flushed.' . chr(10);
58
	}
59
}
60

  
61
?>
FLOW3/Classes/Package/F3_FLOW3_Package_PackageInterface.php (working copy)
16 16
 *                                                                        */
17 17

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

  
24
/**
25 19
 * Interface for a TYPO3 Package class
26 20
 *
27 21
 * @package FLOW3
28 22
 * @subpackage Package
29
 * @version $Id:F3::FLOW3::Package::PackageInterface.php 203 2007-03-30 13:17:37Z robert $
23
 * @version $Id$
30 24
 * @author Robert Lemke <robert@typo3.org>
31 25
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
32 26
 */
33 27
interface PackageInterface {
34 28

  
35 29
	/**
36
	 * Constructor
37
	 *
38
	 * @param string $packageKey: Key of this package
39
	 * @param string $packagePath: Absolute path to the package's main directory
40
	 */
41
	public function __construct($packageKey, $packagePath);
42

  
43
	/**
44 30
	 * Returns the package meta object of this package.
45 31
	 *
46 32
	 * @return F3::FLOW3::Package::Meta
......
74 60
	 * @return string Path to this package's Classes directory
75 61
	 */
76 62
	public function getClassesPath();
63
	
64
	/**
65
	 * Returns the full path to this package's Package.xml file
66
	 * 
67
	 * @return string Path to this package's Package.xml file
68
	 */
69
	public function getPackageInfoPath();
77 70
}
78 71
?>
FLOW3/Classes/Package/Meta/F3_FLOW3_Package_Meta_Person.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
68
	/**
69
	 * @return string The repository username
70
	 * @author Christopher Hlubek <hlubek@networkteam.com>
71
	 */
72
	public function getRepositoryUserName() {
73
		return $this->repositoryUserName;
74
	}
75

  
76
	/**
77
	 * @return string Party type "person"
78
	 * @author Christopher Hlubek <hlubek@networkteam.com>
79
	 */
80
	public function getPartyType() {
81
		return F3::FLOW3::Package::Meta::PARTY_TYPE_PERSON;
82
	}
83
}
84
?>
FLOW3/Classes/Package/Meta/F3_FLOW3_Package_Meta_Company.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

  
18
/**
19
 * Package company party meta model
20
 *
21
 * @package FLOW3
22
 * @subpackage Package
23
 * @version $Id$
24
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
25
 */
26
class Company extends F3::FLOW3::Package::Meta::Party {
27

  
28
	/**
29
	 * Get the party type
30
	 * 
31
	 * @return string Party type "company"
32
	 * @author Christopher Hlubek <hlubek@networkteam.com>
33
	 */
34
	public function getPartyType() {
35
		return F3::FLOW3::Package::Meta::PARTY_TYPE_COMPANY;
36
	}	
37
}
38
?>
FLOW3/Classes/Package/Meta/F3_FLOW3_Package_Meta_SystemConstraint.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
59
	/**
60
	 * @return string The constraint scope
61
	 * @see F3::FLOW3::Package::Meta::Constraint::getConstraintScope()
62
	 * @author Christopher Hlubek <hlubek@networkteam.com>
63
	 */
64
	public function getConstraintScope() {
65
		return F3::FLOW3::Package::Meta::CONSTRAINT_SCOPE_SYSTEM;
66
	}
67
}
68
?>
FLOW3/Classes/Package/Meta/F3_FLOW3_Package_Meta_WriterInterface.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
24
/**
25
 * An interface for a package metadata writer
26
 *
27
 * @package FLOW3
28
 * @subpackage Package
29
 * @version $Id:F3::FLOW3::Package::.php 203 2007-03-30 13:17:37Z robert $
30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31
 */
32
interface WriterInterface {
33
	
34
	/**
35
	 * Write metadata for the given package
36
	 *
37
	 * @param F3::FLOW3::Package::MetaInterface $meta: The package meta to write
38
	 * @return string The package meta as a string
39
	 * @author Christopher Hlubek <hlubek@networkteam.com>
40
	 */
41
	public function writePackageMeta(F3::FLOW3::Package::MetaInterface $meta);
42

  
43
}
44
?>
FLOW3/Classes/Package/Meta/F3_FLOW3_Package_Meta_XMLWriter.php (revision 0)
1
<?php
2
declare(ENCODING = 'utf-8');
3
namespace F3::FLOW3::Package::Meta;
4

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

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

  
24
/**
25
 * A package meta XML writer implementation based on the Package.xml format
26
 *
27
 * @package FLOW3
28
 * @subpackage Package
29
 * @version $Id:F3::FLOW3::Package::.php 203 2007-03-30 13:17:37Z robert $
30
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License, version 2
31
 */
32
class XMLWriter implements F3::FLOW3::Package::Meta::WriterInterface {
33

  
34
	/**
35
	 * Write metadata for the given package as XML
36
	 *
37
	 * @param F3::FLOW3::Package::MetaInterface The package meta to write
38
	 * @return string The package meta in XML
39
	 * @author Christopher Hlubek <hlubek@networkteam.com>
40
	 */
41
	public function writePackageMeta(F3::FLOW3::Package::MetaInterface $meta) {	
42
		$xml = new ::XMLWriter();
43
		$xml->openMemory();	
44
		$xml->setIndent(true);
45
		$xml->setIndentString(chr(9));
46
		
47
		$xml->writeRaw('<?xml version="1.0" encoding="utf-8" standalone="yes" ?>' . chr(10));
48
		$xml->startElement('package');
49

  
50
		$xml->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
51
		$xml->writeAttribute('xmlns', 'http://typo3.org/ns/2008/flow3/package');
52
		$xml->writeAttribute('version', '1.0');
53
		
54
		$xml->writeElement('key', $meta->getPackageKey());
55
		$xml->writeElement('title', $meta->getTitle());
56
		$xml->writeElement('description', $meta->getDescription());
57
		$xml->writeElement('version', $meta->getVersion());
58
		$xml->writeElement('state', $meta->getState());
59
 
60
		if(count($meta->getCategories())) {
61
			$xml->startElement('categories');
62
			foreach ($meta->getCategories() as $category) {
63
				$xml->writeElement('category', $category);
64
			}
65
			$xml->endElement();
66
		}
67
 
68
		if(count($meta->getParties())) {
69
			$xml->startElement('parties');
70
			foreach ($meta->getParties() as $party) {
71
				$this->writeParty($xml, $party);
72
			}
73
			$xml->endElement();
74
		}
75

  
76
		if(count($meta->getConstraints())) {
77
			$xml->startElement('constraints');
78
			foreach (F3::FLOW3::Package::Meta::getConstraintTypes() as $constraintType) {
79
				$constraints = $meta->getConstraintsByType($constraintType);
80
				if (count($constraints)) {
81
					$xml->startElement($constraintType);			
82
					foreach ($constraints as $constraint) {
83
						$this->writeConstraint($xml, $constraint);
84
					}
85
					$xml->endElement();
86
				}
87
			}
88
			$xml->endElement();
89
		}
90
		
91
		
92
		$xml->endElement();
93
				
94
		return $xml->outputMemory();
95
	}
96

  
97
	
98
	/**
99
	 * Write party metadata to the XMLWriter.
100
	 * 
101
	 *
102
	 * @param ::XMLWriter $xml: The XMLWriter to write to
103
	 * @param F3::FLOW3::Package::Meta::Party $party: The party to write
104
	 * @author Christopher Hlubek <hlubek@networkteam.com>
105
	 */
106
	protected function writeParty(::XMLWriter $xml, F3::FLOW3::Package::Meta::Party $party) {
107
		$xml->startElement($party->getPartyType());
108
		
109
		if (strlen($party->getRole())) $xml->writeAttribute('role', $party->getRole());
110
		
111
		if (strlen($party->getName())) $xml->writeElement('name', $party->getName());
112
		if (strlen($party->getEmail())) $xml->writeElement('email', $party->getEmail());
113
		if (strlen($party->getWebsite())) $xml->writeElement('website', $party->getWebsite());
114
		
115
		switch ($party->getPartyType()) {
116
			case 'person':
117
				if(strlen($party->getCompany())) $xml->writeElement('company', $party->getCompany());
118
				if(strlen($party->getRepositoryUserName())) $xml->writeElement('repositoryUserName', $party->getRepositoryUserName());
119
				break;
120
			case 'company':
121
				break;
122
		}
123
		
124
		$xml->endElement();
125
	}
126

  
... This diff was truncated because it exceeds the maximum size that can be displayed.
(6-6/6)