Permalink
Browse files

refactored the test suite bootstrapping and cleaned up test class nam…

…espaces
  • Loading branch information...
dbu committed Jul 31, 2011
1 parent be4a5a6 commit c482d3aaad176a761099aa6f1e8b9044de480496
Showing with 643 additions and 677 deletions.
  1. +61 −77 README.md
  2. BIN bin/jack.jar
  3. +22 −97 bootstrap.dist.php
  4. +161 −0 inc/AbstractLoader.php
  5. +59 −42 inc/{baseCase.php → BaseCase.php}
  6. +22 −0 inc/FixtureLoaderInterface.php
  7. +0 −136 inc/importexport.php
  8. BIN lib/DavexClient.jar
  9. +0 −4 lib/README
  10. BIN lib/jackrabbit-api-2.0.0.jar
  11. BIN lib/jackrabbit-core-2.0.0.jar
  12. +5 −9 phpunit.dist.xml
  13. +11 −17 tests/04_Connecting/RepositoryDescriptorsTest.php
  14. +11 −5 tests/04_Connecting/RepositoryFactoryTest.php
  15. +25 −32 tests/04_Connecting/RepositoryTest.php
  16. +9 −9 tests/04_Connecting/SessionReadMethodsTest.php
  17. +20 −3 tests/04_Connecting/{CredentialsTest.php → SimpleCredentialsTest.php}
  18. +6 −4 tests/04_Connecting/WorkspaceReadMethodsTest.php
  19. +5 −3 tests/05_Reading/BinaryReadMethodsTest.php
  20. +7 −8 tests/05_Reading/NodeReadMethodsTest.php
  21. +7 −7 tests/05_Reading/PropertyReadMethodsTest.php
  22. +12 −4 tests/05_Reading/PropertyTypesTest.php
  23. +13 −7 tests/05_Reading/SessionNamespaceRemappingTest.php
  24. +13 −20 tests/05_Reading/SessionReadMethodsTest.php
  25. +2 −1 tests/06_Query/NodeViewTest.php
  26. +3 −2 tests/06_Query/QOM/ConvertQueriesBackAndForthTest.php
  27. +10 −9 tests/06_Query/QOM/QomTestQueries.php
  28. +4 −3 tests/06_Query/QOM/QomToSql2ConverterTest.php
  29. +3 −2 tests/06_Query/QOM/Sql2ScannerTest.php
  30. +1 −0 tests/06_Query/QOM/Sql2TestQueries.php
  31. +3 −2 tests/06_Query/QOM/Sql2ToQomConverterTest.php
  32. +4 −2 tests/06_Query/QueryBaseCase.php
  33. +10 −23 tests/06_Query/QueryManagerTest.php
  34. +3 −1 tests/06_Query/QueryObjectXpathTest.php
  35. +3 −1 tests/06_Query/QueryResultsTest.php
  36. +2 −1 tests/06_Query/RowIteratorTest.php
  37. +2 −1 tests/06_Query/RowTest.php
  38. +6 −2 tests/07_Export/ExportRepositoryContentTest.php
  39. +4 −3 tests/08_NodeTypeDiscovery/NodeTypeDiscoveryTest.php
  40. +4 −3 tests/08_NodeTypeDiscovery/NodeTypeTest.php
  41. +6 −5 tests/10_Writing/AddMethodsTest.php
  42. +3 −2 tests/10_Writing/CombinedManipulationsTest.php
  43. +5 −6 tests/10_Writing/CopyMethodsTest.php
  44. +3 −2 tests/10_Writing/DeleteMethodsTest.php
  45. +5 −4 tests/10_Writing/ItemStateTest.php
  46. +4 −3 tests/10_Writing/MixinReferenceableTest.php
  47. +3 −2 tests/10_Writing/MoveMethodsTest.php
  48. +13 −8 tests/10_Writing/NamespaceRegistryTest.php
  49. +3 −2 tests/10_Writing/NodeTypeAssignementTest.php
  50. +4 −20 tests/10_Writing/SetPropertyDynamicRebindingTest.php
  51. +4 −3 tests/10_Writing/SetPropertyMethodsTest.php
  52. +5 −3 tests/10_Writing/SetPropertyTypesTest.php
  53. +6 −9 tests/11_Import/ImportRepositoryContentTest.php
  54. +4 −7 tests/15_Versioning/CheckinCheckoutNodeTest.php
  55. +4 −7 tests/15_Versioning/CreateVersionableNodeTest.php
  56. +4 −7 tests/15_Versioning/RestoreNodeTest.php
  57. +5 −12 tests/15_Versioning/VersionHistoryTest.php
  58. +7 −13 tests/15_Versioning/VersionTest.php
  59. +8 −5 tests/19_NodeTypeManagement/ManipulationTests.php
  60. +8 −10 tests/21_Transactions/TransactionMethodsTest.php
  61. +6 −7 tests/README
View
138 README.md
@@ -7,81 +7,63 @@ numbers in the JCR v2.0 specification, JSR 283.
(available at http://www.day.com/specs/jcr/2.0/index.html)
-Some of the chapters have not yet been implemented. They have a file named TODO
-in the folder.
-TODO: check existing chapters for completeness and correctness
-Some tests are missing, some are skipped although jackalope implements the feature.
-Write operations are less tested than read operations. Should go through all tests and fix failing ones and implement missing ones.
-For write, check Session::save too and add more complicated chained operations in CombinedManipulationsTest.
-
-TODO: tests should check workspace if it supports that feature and mark tests
-skipped if implemenation does not claim to implement this feature.
-
-TODO: Although generically useable this checkout comes with fixtures and data for the Jackalope API tests.
-clean out the jackalope references and move all jackalope specific stuff (the .jars and so on)
-into the jackalope api-tests folder. These tests should be clean. The only relevant folders are
-tests and fixtures, plus the .sample files, the rest should go out of this.
+Some of the chapters have not yet been implemented. They have a file named ```TODO```
+in the folder. The tests in all chapters are probably not feature complete, but
+steadily increasing. Help is of course welcome.
## Usage
The phpcr-api-tests is a suite to test compliance for implementations of
the java content repository specification.
[https://github.com/phpcr/phpcr](https://github.com/phpcr/phpcr)
-You need to provide a couple of files in order to let the tests detect your
-implementation:
-
+This test suite is independent of an actual implementation. You need to do a
+couple of things to provide proper bootstrapping for your implementation:
* Add the api tests as submodule of your project, for example in a folder tests/api
-* Copy phpunit.dist.xml to the parent folder of where you added the submodule,
- rename it to phpunit.xml and adapt as necessary.
-* All <php /> vars beginning with "jcr." are copied to the configuration array
- that is passed to the functions `getPHPCRSession`,
- `getRepository` and `getFixtureLoader`.
- TODO: configuration should be handled by bootstrap and not by baseClass
-* Write your own bootstrap file. Have a look at bootstrap.dist.php You
- have to implement the following methods:
- ** getPHPCRSession()
- ** getRepository()
- ** getSimpleCredentials()
- ** getFixtureLoader()
- TODO: make this a class and move logic for configuration into the bootstrap
-* Implement data for all the necessary fixtures. See the "fixtures/" folder for
- a JCR XML system view export of the fixture data. If your implementation can
- not import this format, you will need to convert them into a suitable format.
+* Copy phpunit.dist.xml to ../phpunit.xml and adapt as necessary.
+* Implement the bootstrapping (see below)
-Once this binding is working, run the tests with phpunit. If you use a normal
-php installation, this is usually along the lines of:
+### Bootstrapping
- $ phpunit -c path/to/folder-with-phpunit
+You find a sample bootstrap.dist.php that you can copy to ../bootstrap.php and
+adjust to your implementation. Your bootstrap must ensure that the
+```ImplementationLoader``` class extending the \PHPCR\Test\AbstractLoader
+is available in the environment.
+The ImplementationLoader is used by the \PHPCR\Test\BaseCase to acquire the
+PHPCR instances.
-You can run the tests for a specific chapter of the specification with
-phpunit -c path/to/folder-with-phpunit path/to/NN_chaptername
+See the inc/AbstractLoader.php file to see what the ImplementationLoader has to do.
+You can pass parameters from phpunit.xml into your bootstrap with the <php><var... syntax.
-### Required Fixtures
+### Fixtures loading
-The fixture loading passes strings without the file extension so you can roll
-your own fixtures if you want.
-The test suite provides default fixtures in the fixtures folder in the JCR
-system view export format. It is recommended to use those.
+The ImplementationLoader must provide a fixture loader. The fixture names are
+generic, but all names map to .xml files in the fixtures folder. Those files
+are in the JCR system view format. This is the format that is used with
+SessionInterface::import and produced by SessionInterface::exportSystemView
+If your implementation can not import that format, you will need to convert
+them into a suitable format.
-### Using jackrabbit_importexport for load your own fixtures
+We recommend not to use your phpcr implementation import() implementation to
+load the fixtures but something stripped down.
+If you use the import() implementation but have some error or bug in that
+implementation, you will get confusing errors on tests that should not fail.
-TODO: move this into jackalope, its implementation specific. and we should just
-implement the session::importXML method anyways
-The class jackrabbit_importexport can be used to import fixtures in xml format.
-It relies on jack.jar. The class can be plugged in Symfony2 autoload mechanism
-through autoload.php, which can be used to feed a MapFileClassLoader istance. E.g:
+## Running the tests
-```php
-$phpcr_loader = new MapFileClassLoader(
- __DIR__.'/../vendor/doctrine-phpcr-odm/lib/vendor/jackalope/api-test/suite/inc/autoload.php'
-);
-$phpcr_loader->register();
-```
+Once this binding is working, run the tests with phpunit. If you use a normal
+php installation, this is usually along the lines of:
+
+ $ phpunit -c path/to/folder-with/phpunit.xml
+
+You can run the tests for a specific chapter of the specification or just a
+single test case by specifying a path
+
+ $ phpunit -c path/to/folder-with/phpunit.xml path/to/suite/tests/NN_chaptername
## Dependencies
@@ -90,34 +72,35 @@ $phpcr_loader->register();
* PHPUnit in include_path
-## Implementation
+## Implementation notes
-All tests extend from the baseCase, found in inc/baseCase.php
-The baseCase prepares a couple of fixtures and assertions that can be used by
-the tests. Read the comments in that file for details.
+This test suite is made to work with all implementations of PHPCR. Never write
+tests for implementation specific things in here - use your applications unit
+or functional tests for that.
-To improve test running speed, tests should load the fixtures in the
-setupBeforeClass method.
-For the read-only tests, we have just two fixture files that cover all cases.
-For the write tests, we have one fixture per file with nodes named after the
-test names, which baseCase::setUp puts into $this->node. This way, each test
-has its own "root" node and does not influence the other tests.
-
-To add or adjust fixtures, you can use jackrabbit and the jack.jar tool to
-import and export data: http://github.com/jackalope/jackrabbit-importexport
-See the readme file of jack for details.
+All tests must extend from the PHPCR\Test\BaseCase which provides the static
+member $loader with the ImplementationLoader to load data.
+The BaseCase offers infrastructure to load fixtures efficiently and has some
+additional assertions that can be used by the tests.
+Read the comments in inc/BaseCase.php for details.
+To improve test running speed, fixture are loaded in the setupBeforeClass
+method. If you need specific fixtures, pass the name to the parent class
+setupBeforeClass method, if you do not need fixtures at all, pass false.
-## Note on JCR
+For the read-only tests, we have just two fixtures that cover all cases:
+general/base and general/query
-It would be nice if we were able to run the relevant parts of the JSR-283
-Technology Compliance Kit (TCK) against php implementations. Note that we would
-need to have some glue for things that look different in php than in Java, like
-the whole topic of Value and ValueFactory.
-[https://jira.liip.ch/browse/JACK-24](https://jira.liip.ch/browse/JACK-24)
+To only load fixtures once but reliably test write operations, have a fixture
+per test case class with nodes named after the test names. The BaseCase will
+put that name into $this->node for each test in setUp(). This way, each test
+has its own "root" node and does not influence the other tests.
-Once we manage to do that, we could hopefully also use the performance test suite
-[https://jira.liip.ch/browse/JACK-23](https://jira.liip.ch/browse/JACK-23)
+To add or adjust fixtures, please keep them in the PHPCR system view format.
+If you work on Jackalope, you can use jackrabbit and the jack.jar tool to
+import and export data:
+http://github.com/jackalope/jackrabbit-importexport
+See the readme file of jackrabbit-importexport for details.
# Contributors
@@ -127,6 +110,7 @@ Once we manage to do that, we could hopefully also use the performance test suit
* Tobias Ebnöther <ebi@liip.ch>
* Roland Schilter <roland.schilter@liip.ch>
* Uwe Jäger <uwej711@googlemail.com>
+* Johannes Stark <starkj@gmx.de>
* Lukas Kahwe Smith <lukas@liip.ch>
* Benjamin Eberlei <kontakt@beberlei.de>
* Daniel Barsotti <daniel.barsotti@liip.ch>
View
Binary file not shown.
View
@@ -1,109 +1,21 @@
<?php
/**
- * Sample bootstrap file (as used for jr_cr)
+ * Sample bootstrap file
*
- * This file does some basic stuff that's project specific.
- * Please copy the file for your project and make sure phpunit.xml includes
- * this file.
+ * the thing you MUST do is define the constants as expected in the
+ * 04_Connecting/RepositoryDescriptorsTest.php
*
- * function getRepository(config) which returns the repository
- * function getPHPCRSession(config) which returns the session
+ * Otherwise you may use this file to register autoloaders or require files
+ * to have your implementation be ready.
*
- * TODO: move the following to a base file, as they are not implementation specific
- * function getSimpleCredentials(user, password) which returns simpleCredentials
- *
- * constants necessary to the JCR 1.0/JSR-170 and JSR-283 specs
- */
-
-// Make sure we have the necessary config
-$necessaryConfigValues = array('jcr.url', 'jcr.user', 'jcr.pass', 'jcr.workspace', 'jcr.transport');
-foreach ($necessaryConfigValues as $val) {
- if (empty($GLOBALS[$val])) {
- die('Please set '.$val.' in your phpunit.xml.' . "\n");
- }
-}
-
-/**
- * autoloader: jackalope-api-tests relies on this autoloader.
- */
-function jackalopeApiTestsAutoload($class) {
- $incFile = dirname(__FILE__) . '/../lib/' . str_replace("_", DIRECTORY_SEPARATOR, $class).".php";
- if (@fopen($incFile, "r", TRUE)) {
- include($incFile);
- return $incFile;
- }
- return FALSE;
-}
-spl_autoload_register('jackalopeApiTestsAutoload');
-
-/**
- * @return string classname of the repository factory
- */
-function getRepositoryFactoryClass()
-{
- return 'Jackalope\RepositoryFactoryJackrabbit';
-}
-
-/**
- * @return hashmap to be used with the repository factory
- */
-function getRepositoryFactoryParameters($config)
-{
- return array('jackalope.jackrabbit_uri' => $config['url']);
-}
-
-/**
- * Repository lookup is implementation specific.
- * @param config The configuration where to find the repository
- * @return the repository instance
- */
-function getRepository($config) {
- if (empty($config['url']) || empty($config['transport'])) {
- return false;
- }
- return jr_cr::lookup($config['url'], $config['transport']);
-}
-
-/**
- * @param user The user name for the credentials
- * @param password The password for the credentials
- * @return the simple credentials instance for this implementation with the specified username/password
+ * Have a look at the Jackalope repository for an example how the tests are
+ * integrated https://github.com/jackalope/jackalope
*/
-function getSimpleCredentials($user, $password) {
- return new jr_cr_simplecredentials($user, $password);
-}
-/**
- * Get a session for this implementation.
- * @param config The configuration that is passed to getRepository
- * @param credentials The credentials to log into the repository. If omitted, $config['user'] and $config['pass'] is used with getSimpleCredentials
- * @return A session resulting from logging into the repository found at the $config path
+/*
+ * you need to define the following constants for the repository descriptor test for JCR 1.0/JSR-170 and JSR-283 specs
*/
-function getPHPCRSession($config, $credentials = null) {
- $repository = getRepository($config);
- if (isset($config['pass']) || isset($credentials)) {
- if (empty($config['workspace'])) {
- $config['workspace'] = null;
- }
- if (empty($credentials)) {
- $credentials = getSimpleCredentials($config['user'], $config['pass']);
- }
- return $repository->login($credentials, $config['workspace']);
- } elseif (isset($config['workspace'])) {
- return $repository->login(null, $config['workspace']);
- } else {
- return $repository->login(null, null);
- }
-}
-
-function getFixtureLoader($config)
-{
- require_once "importexport.php";
- return new jackalope_importexport(__DIR__."/fixtures", (isset($config['jackalope_jar']) ? $config['jackalope_jar'] : null));
-}
-
-/** some constants */
define('SPEC_VERSION_DESC', 'jcr.specification.version');
define('SPEC_NAME_DESC', 'jcr.specification.name');
@@ -120,3 +32,16 @@ function getFixtureLoader($config)
define('OPTION_QUERY_SQL_SUPPORTED', 'option.query.sql.supported');
define('QUERY_XPATH_POS_INDEX', 'query.xpath.pos.index');
define('QUERY_XPATH_DOC_ORDER', 'query.xpath.doc.order');
+
+/*
+ * you can do things here like registering your autoloader
+ * or require files with classes that are used but not autoloaded
+ */
+require __DIR__.'/../src/Jackalope/autoloader.php';
+
+### Load two classes needed for jackalope unit tests ###
+require __DIR__.'/../tests/Jackalope/TestCase.php';
+require __DIR__.'/../tests/Jackalope/Transport/DoctrineDBAL/DoctrineDBALTestCase.php';
+
+### Load the implementation loader class ###
+require 'ImplementationLoader.php';
Oops, something went wrong.

0 comments on commit c482d3a

Please sign in to comment.