1 | <?php |
||
24 | class MongoDBTest extends \PHPUnit_Framework_TestCase { |
||
25 | |||
26 | public function testMongoDbStore() { |
||
27 | try { |
||
28 | $this->setupMongoDb(); |
||
29 | } catch( MongoConnectionException $e ) { |
||
30 | $this->markTestSkipped( 'MongoDB is not running: ' . $e->getMessage() ); |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | $store = $this->getEntityStoreFromConfiguration(); |
||
35 | |||
36 | $this->assertEquals( |
||
37 | new ItemId( 'Q1' ), |
||
38 | $store->getItemLookup()->getItemForId( new ItemId( 'Q1' ) )->getId() |
||
39 | ); |
||
40 | |||
41 | $this->assertEquals( |
||
42 | new PropertyId( 'P1' ), |
||
43 | $store->getPropertyLookup()->getPropertyForId( new PropertyId( 'P1' ) )->getId() |
||
44 | ); |
||
45 | |||
46 | $results = $store->getEntityDocumentLookup()->getEntityDocumentsForIds( |
||
47 | [ new ItemId( 'Q1' ), new ItemId( 'Q1000' ) ] |
||
48 | ); |
||
49 | $this->assertEquals( 1, count( $results ) ); |
||
50 | $this->assertEquals( new ItemId( 'Q1' ), $results[0]->getId() ); |
||
51 | |||
52 | $this->assertEquals( |
||
53 | [ new ItemId( 'Q1' ) ], |
||
54 | $store->getItemIdForTermLookup()->getItemIdsForTerm( new Term( 'en', 'universe' ) ) |
||
55 | ); |
||
56 | |||
57 | $this->assertEquals( |
||
58 | [], |
||
59 | $store->getItemIdForTermLookup()->getItemIdsForTerm( new Term( 'pl', 'Kosmos' ) ) |
||
60 | ); |
||
61 | |||
62 | $this->assertEquals( |
||
63 | [ new PropertyId( 'P16' ) ], |
||
64 | $store->getPropertyIdForTermLookup()->getPropertyIdsForTerm( new Term( 'en', 'highway system' ) ) |
||
65 | ); |
||
66 | |||
67 | $this->assertEquals( |
||
68 | [ new PropertyId( 'P16' ) ], |
||
69 | $store->getPropertyIdForQueryLookup()->getPropertyIdsForQuery( |
||
70 | new AnyValue(), |
||
71 | new QueryOptions( 1, 0 ) |
||
72 | ) |
||
73 | ); |
||
74 | |||
75 | $this->assertEquals( |
||
76 | [ new ItemId( 'Q1' ) ], |
||
77 | $store->getItemIdForQueryLookup()->getItemIdsForQuery( |
||
78 | new SomeProperty( |
||
79 | new EntityIdValue( new PropertyId( 'P18' ) ), |
||
80 | new ValueDescription( new StringValue( 'Hubble ultra deep field.jpg' ) ) |
||
81 | ), |
||
82 | new QueryOptions( 10, 0 ) |
||
83 | ) |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | private function setupMongoDb() { |
||
88 | $this->importCommand( 'import-json-dump', 'valid.json' ); |
||
89 | $this->importCommand( 'import-incremental-xml-dump', 'valid-incremental.xml' ); |
||
90 | } |
||
91 | |||
92 | private function importCommand( $command, $file ) { |
||
93 | $applicationFactory = new CliApplicationFactory(); |
||
94 | $importCommand = $applicationFactory->newApplication()->find( $command ); |
||
95 | $input = new ArrayInput( [ |
||
96 | 'command' => $command, |
||
97 | 'file' => __DIR__ . '/../data/' . $file, |
||
98 | 'configuration' => __DIR__ . '/../data/valid-config-mongodb.json' |
||
99 | ] ); |
||
100 | $importCommand->run( $input, new NullOutput() ); |
||
101 | } |
||
102 | |||
103 | private function getEntityStoreFromConfiguration() { |
||
107 | } |
||
108 |