@@ -15,71 +15,71 @@ |
||
| 15 | 15 | ); |
| 16 | 16 | |
| 17 | 17 | public function testBasicFunctionality() { |
| 18 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 18 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 19 | 19 | |
| 20 | - $queryBuilder->select( '?name', '?email' ) |
|
| 21 | - ->where( '?person', 'test:name', '?name' ) |
|
| 22 | - ->also( 'test:email', '?email' ) |
|
| 23 | - ->limit( 10 ); |
|
| 20 | + $queryBuilder->select('?name', '?email') |
|
| 21 | + ->where('?person', 'test:name', '?name') |
|
| 22 | + ->also('test:email', '?email') |
|
| 23 | + ->limit(10); |
|
| 24 | 24 | |
| 25 | - $this->assertIsExpected( 'basic_functionality', $queryBuilder->format() ); |
|
| 25 | + $this->assertIsExpected('basic_functionality', $queryBuilder->format()); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function testOptionalFilter() { |
| 29 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 30 | - $queryBuilder->select( '?name' ) |
|
| 31 | - ->where( '?person', 'test:name', '?name' ) |
|
| 32 | - ->optional( '?person', 'test:email', '?email' ) |
|
| 33 | - ->filter( '!BOUND (?email)' ); |
|
| 29 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 30 | + $queryBuilder->select('?name') |
|
| 31 | + ->where('?person', 'test:name', '?name') |
|
| 32 | + ->optional('?person', 'test:email', '?email') |
|
| 33 | + ->filter('!BOUND (?email)'); |
|
| 34 | 34 | |
| 35 | - $this->assertIsExpected( 'optional_filter', $queryBuilder->format() ); |
|
| 35 | + $this->assertIsExpected('optional_filter', $queryBuilder->format()); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function testUnion() { |
| 39 | - $queryBuilder = new QueryBuilder( array( |
|
| 39 | + $queryBuilder = new QueryBuilder(array( |
|
| 40 | 40 | 'dc10' => 'http://purl.org/dc/elements/1.0/', |
| 41 | 41 | 'dc11' => 'http://purl.org/dc/elements/1.1/' |
| 42 | - ) ); |
|
| 42 | + )); |
|
| 43 | 43 | |
| 44 | - $queryBuilder->select( '?title', '?author' ) |
|
| 44 | + $queryBuilder->select('?title', '?author') |
|
| 45 | 45 | ->union( |
| 46 | 46 | $queryBuilder->newSubgraph() |
| 47 | - ->where( '?book', 'dc10:title', '?title' ) |
|
| 48 | - ->also( 'dc10:creator', '?author' ), |
|
| 47 | + ->where('?book', 'dc10:title', '?title') |
|
| 48 | + ->also('dc10:creator', '?author'), |
|
| 49 | 49 | $queryBuilder->newSubgraph() |
| 50 | - ->where( '?book', 'dc11:title', '?title' ) |
|
| 51 | - ->also( 'dc11:creator', '?author' ) |
|
| 50 | + ->where('?book', 'dc11:title', '?title') |
|
| 51 | + ->also('dc11:creator', '?author') |
|
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | - $this->assertIsExpected( 'union', $queryBuilder->format() ); |
|
| 54 | + $this->assertIsExpected('union', $queryBuilder->format()); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public function testUndefinedPrefixDetected() { |
| 58 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 58 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 59 | 59 | |
| 60 | - $queryBuilder->select( '?age' ) |
|
| 61 | - ->where( '?person', 'test:name', '?name' ) |
|
| 62 | - ->also( 'nyan:age', '?age' ); |
|
| 60 | + $queryBuilder->select('?age') |
|
| 61 | + ->where('?person', 'test:name', '?name') |
|
| 62 | + ->also('nyan:age', '?age'); |
|
| 63 | 63 | |
| 64 | - $this->setExpectedException( 'RangeException', 'nyan' ); |
|
| 64 | + $this->setExpectedException('RangeException', 'nyan'); |
|
| 65 | 65 | $queryBuilder->getSPARQL(); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | public function testUndefinedVariableDetected() { |
| 69 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 69 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 70 | 70 | |
| 71 | - $queryBuilder->select( '?email' ) |
|
| 72 | - ->where( '?person', 'test:name', '?name' ) |
|
| 73 | - ->also( 'test:age', '?age' ); |
|
| 71 | + $queryBuilder->select('?email') |
|
| 72 | + ->where('?person', 'test:name', '?name') |
|
| 73 | + ->also('test:age', '?age'); |
|
| 74 | 74 | |
| 75 | - $this->setExpectedException( 'RangeException', '?email' ); |
|
| 75 | + $this->setExpectedException('RangeException', '?email'); |
|
| 76 | 76 | $queryBuilder->getSPARQL(); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - private function assertIsExpected( $name, $sparql ) { |
|
| 80 | - $expected = file_get_contents( __DIR__ . '/../data/builder_' . $name . '.rq' ); |
|
| 79 | + private function assertIsExpected($name, $sparql) { |
|
| 80 | + $expected = file_get_contents(__DIR__ . '/../data/builder_' . $name . '.rq'); |
|
| 81 | 81 | |
| 82 | - $this->assertEquals( $expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq' ); |
|
| 82 | + $this->assertEquals($expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | } |
@@ -22,245 +22,245 @@ |
||
| 22 | 22 | ); |
| 23 | 23 | |
| 24 | 24 | public function testUSPresidentsAndSpouses() { |
| 25 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 25 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 26 | 26 | |
| 27 | - $queryBuilder->select( '?p', '?w', '?l', '?wl' ) |
|
| 28 | - ->where( 'wd:Q30', 'p:P6/v:P6', '?p' ) |
|
| 29 | - ->where( '?p', 'wdt:P26', '?w' ) |
|
| 27 | + $queryBuilder->select('?p', '?w', '?l', '?wl') |
|
| 28 | + ->where('wd:Q30', 'p:P6/v:P6', '?p') |
|
| 29 | + ->where('?p', 'wdt:P26', '?w') |
|
| 30 | 30 | ->optional( |
| 31 | 31 | $queryBuilder->newSubgraph() |
| 32 | - ->where( '?p', 'rdfs:label', '?l' ) |
|
| 33 | - ->filter( 'LANG(?l) = "en"' ) |
|
| 32 | + ->where('?p', 'rdfs:label', '?l') |
|
| 33 | + ->filter('LANG(?l) = "en"') |
|
| 34 | 34 | ) |
| 35 | 35 | ->optional( |
| 36 | 36 | $queryBuilder->newSubgraph() |
| 37 | - ->where( '?w', 'rdfs:label', '?wl' ) |
|
| 38 | - ->filter( 'LANG(?wl) = "en"' ) |
|
| 37 | + ->where('?w', 'rdfs:label', '?wl') |
|
| 38 | + ->filter('LANG(?wl) = "en"') |
|
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | - $this->assertIsExpected( 'US_presidents_and_spouses', $queryBuilder->format() ); |
|
| 41 | + $this->assertIsExpected('US_presidents_and_spouses', $queryBuilder->format()); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function testPresidentsAndCausesOfDeath() { |
| 45 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 45 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 46 | 46 | |
| 47 | - $queryBuilder->select( '?h', '?cause', '?hl', '?causel' ) |
|
| 48 | - ->where( '?h', 'wdt:P39', 'wd:Q11696' ) |
|
| 49 | - ->also( 'wdt:P509', '?cause' ) |
|
| 47 | + $queryBuilder->select('?h', '?cause', '?hl', '?causel') |
|
| 48 | + ->where('?h', 'wdt:P39', 'wd:Q11696') |
|
| 49 | + ->also('wdt:P509', '?cause') |
|
| 50 | 50 | ->optional( |
| 51 | 51 | $queryBuilder->newSubgraph() |
| 52 | - ->where( '?h', 'rdfs:label', '?hl' ) |
|
| 53 | - ->filter( 'LANG(?hl) = "en"' ) |
|
| 52 | + ->where('?h', 'rdfs:label', '?hl') |
|
| 53 | + ->filter('LANG(?hl) = "en"') |
|
| 54 | 54 | ) |
| 55 | 55 | ->optional( |
| 56 | 56 | $queryBuilder->newSubgraph() |
| 57 | - ->where( '?cause', 'rdfs:label', '?causel' ) |
|
| 58 | - ->filter( 'LANG(?causel) = "en"' ) |
|
| 57 | + ->where('?cause', 'rdfs:label', '?causel') |
|
| 58 | + ->filter('LANG(?causel) = "en"') |
|
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - $this->assertIsExpected( 'Presidents_and_causes_of_death', $queryBuilder->format() ); |
|
| 61 | + $this->assertIsExpected('Presidents_and_causes_of_death', $queryBuilder->format()); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | public function testPeopleBornBeforeYear1880WithNoDeathDate() { |
| 65 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 65 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 66 | 66 | |
| 67 | - $queryBuilder->select( '?h', '?date' ) |
|
| 68 | - ->where( '?h', 'wdt:P31', 'wd:Q5' ) |
|
| 69 | - ->also( 'wdt:P569', '?date' ) |
|
| 70 | - ->optional( '?h', 'wdt:P570', '?d' ) |
|
| 71 | - ->filter( '?date < "1880-01-01T00:00:00Z"^^xsd:dateTime' ) |
|
| 72 | - ->filter( '!BOUND(?d)' ) |
|
| 73 | - ->limit( 100 ); |
|
| 67 | + $queryBuilder->select('?h', '?date') |
|
| 68 | + ->where('?h', 'wdt:P31', 'wd:Q5') |
|
| 69 | + ->also('wdt:P569', '?date') |
|
| 70 | + ->optional('?h', 'wdt:P570', '?d') |
|
| 71 | + ->filter('?date < "1880-01-01T00:00:00Z"^^xsd:dateTime') |
|
| 72 | + ->filter('!BOUND(?d)') |
|
| 73 | + ->limit(100); |
|
| 74 | 74 | |
| 75 | - $this->assertIsExpected( 'People_born_before_year_1880_with_no_death_date', $queryBuilder->format() ); |
|
| 75 | + $this->assertIsExpected('People_born_before_year_1880_with_no_death_date', $queryBuilder->format()); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | public function testLargestCitiesWithFemaleMayor() { |
| 79 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 80 | - |
|
| 81 | - $queryBuilder->selectDistinct( '?city', '?citylabel', '?mayorlabel' ) |
|
| 82 | - ->where( '?city', 'wdt:P31/wdt:P279*', 'wd:Q515' ) |
|
| 83 | - ->also( 'p:P6', '?statement' ) |
|
| 84 | - ->also( 'wdt:P1082', '?population' ) |
|
| 85 | - ->where( '?statement', 'v:P6', '?mayor' ) |
|
| 86 | - ->where( '?mayor', 'wdt:P21', 'wd:Q6581072' ) |
|
| 87 | - ->filterNotExists( '?statement', 'q:P582', '?x' ) |
|
| 79 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 80 | + |
|
| 81 | + $queryBuilder->selectDistinct('?city', '?citylabel', '?mayorlabel') |
|
| 82 | + ->where('?city', 'wdt:P31/wdt:P279*', 'wd:Q515') |
|
| 83 | + ->also('p:P6', '?statement') |
|
| 84 | + ->also('wdt:P1082', '?population') |
|
| 85 | + ->where('?statement', 'v:P6', '?mayor') |
|
| 86 | + ->where('?mayor', 'wdt:P21', 'wd:Q6581072') |
|
| 87 | + ->filterNotExists('?statement', 'q:P582', '?x') |
|
| 88 | 88 | ->optional( |
| 89 | 89 | $queryBuilder->newSubgraph() |
| 90 | - ->where( '?city', 'rdfs:label', '?citylabel' ) |
|
| 91 | - ->filter( 'LANG(?citylabel) = "en"' ) |
|
| 90 | + ->where('?city', 'rdfs:label', '?citylabel') |
|
| 91 | + ->filter('LANG(?citylabel) = "en"') |
|
| 92 | 92 | ) |
| 93 | 93 | ->optional( |
| 94 | 94 | $queryBuilder->newSubgraph() |
| 95 | - ->where( '?mayor', 'rdfs:label', '?mayorlabel' ) |
|
| 96 | - ->filter( 'LANG(?mayorlabel) = "en"' ) |
|
| 95 | + ->where('?mayor', 'rdfs:label', '?mayorlabel') |
|
| 96 | + ->filter('LANG(?mayorlabel) = "en"') |
|
| 97 | 97 | ) |
| 98 | - ->orderBy( '?population', 'DESC' ) |
|
| 99 | - ->limit( 10 ); |
|
| 98 | + ->orderBy('?population', 'DESC') |
|
| 99 | + ->limit(10); |
|
| 100 | 100 | |
| 101 | - $this->assertIsExpected( 'Largest_cities_with_female_mayor', $queryBuilder->format() ); |
|
| 101 | + $this->assertIsExpected('Largest_cities_with_female_mayor', $queryBuilder->format()); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | public function testListOfCountriesOrderedByTheNumberOfTheirCitiesWithFemaleMayor() { |
| 105 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 106 | - |
|
| 107 | - $queryBuilder->select( '?country', '?label', '(COUNT(*) AS ?COUNT)' ) |
|
| 108 | - ->where( '?city', 'wdt:P31/wdt:P279*', 'wd:Q515' ) |
|
| 109 | - ->also( 'p:P6', '?statement' ) |
|
| 110 | - ->also( 'wdt:P17', '?country' ) |
|
| 111 | - ->where( '?statement', 'v:P6', '?mayor' ) |
|
| 112 | - ->where( '?mayor', 'wdt:P21', 'wd:Q6581072' ) |
|
| 113 | - ->filterNotExists( '?statement', 'q:P582', '?x' ) |
|
| 105 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 106 | + |
|
| 107 | + $queryBuilder->select('?country', '?label', '(COUNT(*) AS ?COUNT)') |
|
| 108 | + ->where('?city', 'wdt:P31/wdt:P279*', 'wd:Q515') |
|
| 109 | + ->also('p:P6', '?statement') |
|
| 110 | + ->also('wdt:P17', '?country') |
|
| 111 | + ->where('?statement', 'v:P6', '?mayor') |
|
| 112 | + ->where('?mayor', 'wdt:P21', 'wd:Q6581072') |
|
| 113 | + ->filterNotExists('?statement', 'q:P582', '?x') |
|
| 114 | 114 | ->optional( |
| 115 | 115 | $queryBuilder->newSubgraph() |
| 116 | - ->where( '?country', 'rdfs:label', '?label' ) |
|
| 117 | - ->filter( 'LANG(?label) = "en"' ) |
|
| 116 | + ->where('?country', 'rdfs:label', '?label') |
|
| 117 | + ->filter('LANG(?label) = "en"') |
|
| 118 | 118 | ) |
| 119 | - ->groupBy( '?country', '?label' ) |
|
| 120 | - ->orderBy( '?COUNT', 'DESC' ) |
|
| 121 | - ->limit( 100 ); |
|
| 119 | + ->groupBy('?country', '?label') |
|
| 120 | + ->orderBy('?COUNT', 'DESC') |
|
| 121 | + ->limit(100); |
|
| 122 | 122 | |
| 123 | - $this->assertIsExpected( 'List_of_countries_ordered_by_the_number_of_their_cities_with_female_mayor', $queryBuilder->format() ); |
|
| 123 | + $this->assertIsExpected('List_of_countries_ordered_by_the_number_of_their_cities_with_female_mayor', $queryBuilder->format()); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | public function testsHowManyStatesThisUSStateBorders() { |
| 127 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 127 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 128 | 128 | |
| 129 | - $queryBuilder->select( '?state', '?stateL', '?borders' ) |
|
| 129 | + $queryBuilder->select('?state', '?stateL', '?borders') |
|
| 130 | 130 | ->subquery( |
| 131 | 131 | $queryBuilder->newSubquery() |
| 132 | - ->select( '?state', '(COUNT (?otherState) AS ?borders)' ) |
|
| 133 | - ->where( '?state', 'wdt:P31', 'wd:Q35657' ) |
|
| 134 | - ->where( '?otherState', 'wdt:P47', '?state' ) |
|
| 135 | - ->also( 'wdt:P31', 'wd:Q35657' ) |
|
| 136 | - ->groupBy( '?state' ) |
|
| 132 | + ->select('?state', '(COUNT (?otherState) AS ?borders)') |
|
| 133 | + ->where('?state', 'wdt:P31', 'wd:Q35657') |
|
| 134 | + ->where('?otherState', 'wdt:P47', '?state') |
|
| 135 | + ->also('wdt:P31', 'wd:Q35657') |
|
| 136 | + ->groupBy('?state') |
|
| 137 | 137 | ) |
| 138 | 138 | ->optional( |
| 139 | 139 | $queryBuilder->newSubgraph() |
| 140 | - ->where( '?state', 'rdfs:label', '?stateL' ) |
|
| 141 | - ->filter( 'LANG(?stateL) = "en"' ) |
|
| 140 | + ->where('?state', 'rdfs:label', '?stateL') |
|
| 141 | + ->filter('LANG(?stateL) = "en"') |
|
| 142 | 142 | ) |
| 143 | - ->orderBy( '?borders', 'DESC' ); |
|
| 143 | + ->orderBy('?borders', 'DESC'); |
|
| 144 | 144 | |
| 145 | - $this->assertIsExpected( 'How_many_states_this_US_state_borders', $queryBuilder->format() ); |
|
| 145 | + $this->assertIsExpected('How_many_states_this_US_state_borders', $queryBuilder->format()); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | public function testWhoseBirthdayIsToday() { |
| 149 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 149 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 150 | 150 | |
| 151 | - $queryBuilder->select( '?entity', '(YEAR(?date) AS ?YEAR)' ) |
|
| 152 | - ->where( '?entityS', 'wdt:P569', '?date' ) |
|
| 153 | - ->also( 'rdfs:label', '?entity' ) |
|
| 154 | - ->filter( 'DATATYPE (?date) = xsd:dateTime' ) |
|
| 155 | - ->filter( 'MONTH (?date) = MONTH (NOW ())' ) |
|
| 156 | - ->filter( 'DAY (?date) = DAY (NOW ())' ) |
|
| 157 | - ->limit( 10 ); |
|
| 151 | + $queryBuilder->select('?entity', '(YEAR(?date) AS ?YEAR)') |
|
| 152 | + ->where('?entityS', 'wdt:P569', '?date') |
|
| 153 | + ->also('rdfs:label', '?entity') |
|
| 154 | + ->filter('DATATYPE (?date) = xsd:dateTime') |
|
| 155 | + ->filter('MONTH (?date) = MONTH (NOW ())') |
|
| 156 | + ->filter('DAY (?date) = DAY (NOW ())') |
|
| 157 | + ->limit(10); |
|
| 158 | 158 | |
| 159 | - $this->assertIsExpected( 'Whose_birthday_is_today', $queryBuilder->format() ); |
|
| 159 | + $this->assertIsExpected('Whose_birthday_is_today', $queryBuilder->format()); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | public function testWhoDiscoveredTheMostAsteroids() { |
| 163 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 163 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 164 | 164 | |
| 165 | - $queryBuilder->select( '?discoverer', '?name', '(COUNT (?asteroid) AS ?count)' ) |
|
| 166 | - ->where( '?asteroid', 'wdt:P31', 'wd:Q3863' ) |
|
| 167 | - ->also( 'wdt:P61', '?discoverer' ) |
|
| 165 | + $queryBuilder->select('?discoverer', '?name', '(COUNT (?asteroid) AS ?count)') |
|
| 166 | + ->where('?asteroid', 'wdt:P31', 'wd:Q3863') |
|
| 167 | + ->also('wdt:P61', '?discoverer') |
|
| 168 | 168 | ->optional( |
| 169 | 169 | $queryBuilder->newSubgraph() |
| 170 | - ->where( '?discoverer', 'rdfs:label', '?name' ) |
|
| 171 | - ->filter( 'LANG(?name) = "en"' ) |
|
| 170 | + ->where('?discoverer', 'rdfs:label', '?name') |
|
| 171 | + ->filter('LANG(?name) = "en"') |
|
| 172 | 172 | ) |
| 173 | - ->groupBy( '?discoverer', '?name' ) |
|
| 174 | - ->orderBy( '?count', 'DESC' ) |
|
| 175 | - ->limit( 10 ); |
|
| 173 | + ->groupBy('?discoverer', '?name') |
|
| 174 | + ->orderBy('?count', 'DESC') |
|
| 175 | + ->limit(10); |
|
| 176 | 176 | |
| 177 | - $this->assertIsExpected( 'Who_discovered_the_most_asteroids', $queryBuilder->format() ); |
|
| 177 | + $this->assertIsExpected('Who_discovered_the_most_asteroids', $queryBuilder->format()); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function testWhoDiscoveredTheMostPlanets() { |
| 181 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 181 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 182 | 182 | |
| 183 | - $queryBuilder->select( '?discoverer', '?name', '(COUNT (DISTINCT ?planet) AS ?count)' ) |
|
| 184 | - ->where( '?ppart', 'wdt:P279*', 'wd:Q634' ) |
|
| 185 | - ->where( '?planet', 'wdt:P31', '?ppart' ) |
|
| 186 | - ->also( 'wdt:P61', '?discoverer' ) |
|
| 183 | + $queryBuilder->select('?discoverer', '?name', '(COUNT (DISTINCT ?planet) AS ?count)') |
|
| 184 | + ->where('?ppart', 'wdt:P279*', 'wd:Q634') |
|
| 185 | + ->where('?planet', 'wdt:P31', '?ppart') |
|
| 186 | + ->also('wdt:P61', '?discoverer') |
|
| 187 | 187 | ->optional( |
| 188 | 188 | $queryBuilder->newSubgraph() |
| 189 | - ->where( '?discoverer', 'rdfs:label', '?name' ) |
|
| 190 | - ->filter( 'LANG(?name) = "en"' ) |
|
| 189 | + ->where('?discoverer', 'rdfs:label', '?name') |
|
| 190 | + ->filter('LANG(?name) = "en"') |
|
| 191 | 191 | ) |
| 192 | - ->groupBy( '?discoverer', '?name' ) |
|
| 193 | - ->orderBy( '?count', 'DESC' ) |
|
| 194 | - ->limit( 10 ); |
|
| 192 | + ->groupBy('?discoverer', '?name') |
|
| 193 | + ->orderBy('?count', 'DESC') |
|
| 194 | + ->limit(10); |
|
| 195 | 195 | |
| 196 | - $this->assertIsExpected( 'Who_discovered_the_most_planets', $queryBuilder->format() ); |
|
| 196 | + $this->assertIsExpected('Who_discovered_the_most_planets', $queryBuilder->format()); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | public function testAmericanUniversitiesFoundedBeforeTheStatesTheyResideInWereCreated() { |
| 200 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 201 | - |
|
| 202 | - $queryBuilder->select( '?uniName', '?founded', '?stateName', '?stateStart' ) |
|
| 203 | - ->where( '?uni', 'wdt:P31|wdt:P279/wdt:P31', 'wd:Q3918' ) |
|
| 204 | - ->also( 'wdt:P131+', '?state' ) |
|
| 205 | - ->also( 'wdt:P571', '?founded' ) |
|
| 206 | - ->where( '?state', 'wdt:P31', 'wd:Q35657' ) |
|
| 207 | - ->also( 'wdt:P571', '?stateStart' ) |
|
| 208 | - ->filter( '?founded < ?stateStart' ) |
|
| 200 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 201 | + |
|
| 202 | + $queryBuilder->select('?uniName', '?founded', '?stateName', '?stateStart') |
|
| 203 | + ->where('?uni', 'wdt:P31|wdt:P279/wdt:P31', 'wd:Q3918') |
|
| 204 | + ->also('wdt:P131+', '?state') |
|
| 205 | + ->also('wdt:P571', '?founded') |
|
| 206 | + ->where('?state', 'wdt:P31', 'wd:Q35657') |
|
| 207 | + ->also('wdt:P571', '?stateStart') |
|
| 208 | + ->filter('?founded < ?stateStart') |
|
| 209 | 209 | ->optional( |
| 210 | 210 | $queryBuilder->newSubgraph() |
| 211 | - ->where( '?state', 'rdfs:label', '?stateName' ) |
|
| 212 | - ->filter( 'LANG(?stateName) = "en"' ) |
|
| 211 | + ->where('?state', 'rdfs:label', '?stateName') |
|
| 212 | + ->filter('LANG(?stateName) = "en"') |
|
| 213 | 213 | ) |
| 214 | 214 | ->optional( |
| 215 | 215 | $queryBuilder->newSubgraph() |
| 216 | - ->where( '?uni', 'rdfs:label', '?uniName' ) |
|
| 217 | - ->filter( 'LANG(?uniName) = "en"' ) |
|
| 216 | + ->where('?uni', 'rdfs:label', '?uniName') |
|
| 217 | + ->filter('LANG(?uniName) = "en"') |
|
| 218 | 218 | ) |
| 219 | - ->limit( 10 ); |
|
| 219 | + ->limit(10); |
|
| 220 | 220 | |
| 221 | - $this->assertIsExpected( 'American_universities_founded_before_the_states_they_reside_in_were_created', $queryBuilder->format() ); |
|
| 221 | + $this->assertIsExpected('American_universities_founded_before_the_states_they_reside_in_were_created', $queryBuilder->format()); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | public function testWhatIsTheRelationBetweenTerrellBuckleyAndMiamiDolphins() { |
| 225 | - $queryBuilder = new QueryBuilder( self::$prefixes ); |
|
| 225 | + $queryBuilder = new QueryBuilder(self::$prefixes); |
|
| 226 | 226 | |
| 227 | - $queryBuilder->select( '?l' ) |
|
| 228 | - ->where( 'wd:Q5571382', '?p', 'wd:Q223243' ) |
|
| 229 | - ->where( '?property', '?ref', '?p' ) |
|
| 230 | - ->also( 'a', 'wikibase:Property' ) |
|
| 231 | - ->also( 'rdfs:label', '?l' ) |
|
| 232 | - ->filter( 'LANG(?l) = "en"' ) |
|
| 233 | - ->limit( 10 ); |
|
| 227 | + $queryBuilder->select('?l') |
|
| 228 | + ->where('wd:Q5571382', '?p', 'wd:Q223243') |
|
| 229 | + ->where('?property', '?ref', '?p') |
|
| 230 | + ->also('a', 'wikibase:Property') |
|
| 231 | + ->also('rdfs:label', '?l') |
|
| 232 | + ->filter('LANG(?l) = "en"') |
|
| 233 | + ->limit(10); |
|
| 234 | 234 | |
| 235 | - $this->assertIsExpected( 'What_is_the_relation_between_Terrell_Buckley_and_Miami_Dolphins', $queryBuilder->format() ); |
|
| 235 | + $this->assertIsExpected('What_is_the_relation_between_Terrell_Buckley_and_Miami_Dolphins', $queryBuilder->format()); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | public function testAliasesOfPropertiesWhichAreUsedMoreThanOnce() { |
| 239 | - $queryBuilder = new QueryBuilder( self::$prefixes + array( |
|
| 239 | + $queryBuilder = new QueryBuilder(self::$prefixes + array( |
|
| 240 | 240 | 'skos' => 'http://www.w3.org/2004/02/skos/core#' |
| 241 | - ) ); |
|
| 241 | + )); |
|
| 242 | 242 | |
| 243 | - $queryBuilder->select( '?property', '?alias', '?occurences' ) |
|
| 243 | + $queryBuilder->select('?property', '?alias', '?occurences') |
|
| 244 | 244 | ->subquery( |
| 245 | 245 | $queryBuilder->newSubquery() |
| 246 | - ->select( '?alias', '(COUNT (?alias) AS ?occurences)' ) |
|
| 247 | - ->where( '?tmp', 'a', 'wikibase:Property' ) |
|
| 248 | - ->also( 'skos:altLabel', '?alias' ) |
|
| 249 | - ->filter( 'LANG (?alias) = "en"' ) |
|
| 250 | - ->groupBy( '?alias' ) |
|
| 246 | + ->select('?alias', '(COUNT (?alias) AS ?occurences)') |
|
| 247 | + ->where('?tmp', 'a', 'wikibase:Property') |
|
| 248 | + ->also('skos:altLabel', '?alias') |
|
| 249 | + ->filter('LANG (?alias) = "en"') |
|
| 250 | + ->groupBy('?alias') |
|
| 251 | 251 | ) |
| 252 | - ->where( '?property', 'a', 'wikibase:Property' ) |
|
| 253 | - ->also( 'skos:altLabel', '?alias' ) |
|
| 254 | - ->filter( '?occurences > 1' ) |
|
| 255 | - ->orderBy( '?alias' ); |
|
| 252 | + ->where('?property', 'a', 'wikibase:Property') |
|
| 253 | + ->also('skos:altLabel', '?alias') |
|
| 254 | + ->filter('?occurences > 1') |
|
| 255 | + ->orderBy('?alias'); |
|
| 256 | 256 | |
| 257 | - $this->assertIsExpected( 'Aliases_of_properties_which_are_used_more_than_once', $queryBuilder->format() ); |
|
| 257 | + $this->assertIsExpected('Aliases_of_properties_which_are_used_more_than_once', $queryBuilder->format()); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - private function assertIsExpected( $name, $sparql ) { |
|
| 261 | - $expected = file_get_contents( __DIR__ . '/../data/wdqs_' . $name . '.rq' ); |
|
| 260 | + private function assertIsExpected($name, $sparql) { |
|
| 261 | + $expected = file_get_contents(__DIR__ . '/../data/wdqs_' . $name . '.rq'); |
|
| 262 | 262 | |
| 263 | - $this->assertEquals( $expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq' ); |
|
| 263 | + $this->assertEquals($expected, $sparql, 'Query didn\'t match the expected content of integration_' . $name . '.rq'); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | } |
@@ -13,20 +13,20 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * @dataProvider provideTestFormat |
| 15 | 15 | */ |
| 16 | - public function testFormat( $name ) { |
|
| 16 | + public function testFormat($name) { |
|
| 17 | 17 | $formatter = new QueryFormatter(); |
| 18 | - $sparql = file_get_contents( __DIR__ . '/../data/formatter_' . $name . '_in.rq' ); |
|
| 19 | - $expected = file_get_contents( __DIR__ . '/../data/formatter_' . $name . '_out.rq' ); |
|
| 18 | + $sparql = file_get_contents(__DIR__ . '/../data/formatter_' . $name . '_in.rq'); |
|
| 19 | + $expected = file_get_contents(__DIR__ . '/../data/formatter_' . $name . '_out.rq'); |
|
| 20 | 20 | |
| 21 | - $this->assertEquals( $expected, $formatter->format( $sparql ), |
|
| 22 | - 'Input from formatter_' . $name . '_in.rq didn\'t produce the expected output.' ); |
|
| 21 | + $this->assertEquals($expected, $formatter->format($sparql), |
|
| 22 | + 'Input from formatter_' . $name . '_in.rq didn\'t produce the expected output.'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function provideTestFormat() { |
| 26 | 26 | return array( |
| 27 | - 'Query without line-breaks' => array( 'one_line' ), |
|
| 28 | - 'Query with lots of spaces' => array( 'many_spaces' ), |
|
| 29 | - 'Query with few spaces' => array( 'few_spaces' ) |
|
| 27 | + 'Query without line-breaks' => array('one_line'), |
|
| 28 | + 'Query with lots of spaces' => array('many_spaces'), |
|
| 29 | + 'Query with few spaces' => array('few_spaces') |
|
| 30 | 30 | ); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -1,19 +1,19 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if ( PHP_SAPI !== 'cli' ) { |
|
| 4 | - die( 'Not an entry point' ); |
|
| 3 | +if (PHP_SAPI !== 'cli') { |
|
| 4 | + die('Not an entry point'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | -error_reporting( E_ALL | E_STRICT ); |
|
| 8 | -ini_set( 'display_errors', 1 ); |
|
| 7 | +error_reporting(E_ALL | E_STRICT); |
|
| 8 | +ini_set('display_errors', 1); |
|
| 9 | 9 | |
| 10 | -if ( !is_readable( __DIR__ . '/../vendor/autoload.php' ) ) { |
|
| 11 | - die( 'You need to install this package with Composer before you can run the tests' ); |
|
| 10 | +if (!is_readable(__DIR__ . '/../vendor/autoload.php')) { |
|
| 11 | + die('You need to install this package with Composer before you can run the tests'); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | $autoLoader = require_once __DIR__ . '/../vendor/autoload.php'; |
| 15 | 15 | |
| 16 | -$autoLoader->addPsr4( 'Asparagus\\Tests\\', __DIR__ . '/unit/' ); |
|
| 17 | -$autoLoader->addPsr4( 'Asparagus\\Tests\\Integration\\', __DIR__ . '/integration/' ); |
|
| 16 | +$autoLoader->addPsr4('Asparagus\\Tests\\', __DIR__ . '/unit/'); |
|
| 17 | +$autoLoader->addPsr4('Asparagus\\Tests\\Integration\\', __DIR__ . '/integration/'); |
|
| 18 | 18 | |
| 19 | -unset( $autoLoader ); |
|
| 19 | +unset($autoLoader); |
|
@@ -15,120 +15,120 @@ |
||
| 15 | 15 | /** |
| 16 | 16 | * @dataProvider provideMatchingExpressions |
| 17 | 17 | */ |
| 18 | - public function testMatchesRegex_matching( $regex, $expression ) { |
|
| 18 | + public function testMatchesRegex_matching($regex, $expression) { |
|
| 19 | 19 | $regexHelper = new RegexHelper(); |
| 20 | 20 | |
| 21 | - $this->assertTrue( $regexHelper->matchesRegex( $regex, $expression ) ); |
|
| 21 | + $this->assertTrue($regexHelper->matchesRegex($regex, $expression)); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function provideMatchingExpressions() { |
| 25 | 25 | return array( |
| 26 | - array( '\{variable}', '?abc' ), |
|
| 27 | - array( '\{variable}', '$abc' ), |
|
| 28 | - array( 'AS \{variable}', 'AS ?nyan' ), |
|
| 29 | - array( '\{iri}', 'http://www.example.com/test#' ), |
|
| 30 | - array( '\{prefix}', 'foo_bar42' ), |
|
| 31 | - array( '\{name}', 'foo_bar42' ), |
|
| 32 | - array( '\{prefixed_iri}', '<http://www.example.com/test#>' ), |
|
| 33 | - array( '\{prefixed_iri}', 'nyan:cat' ), |
|
| 34 | - array( '\{native}', '123' ), |
|
| 35 | - array( '\{native}', '"foo bar"' ), |
|
| 36 | - array( '\{path}', 'nyan:cat' ), |
|
| 37 | - array( '\{path}', '^nyan:cat' ), |
|
| 38 | - array( '\{path}', 'nyan:cat' ), |
|
| 39 | - array( '\{path}', 'nyan:cat/nyan:kitten' ), |
|
| 40 | - array( '\{path}', 'nyan:cat/nyan:kitten/cat:kitten' ), |
|
| 41 | - array( '\{path}', 'nyan:cat|nyan:kitten' ), |
|
| 42 | - array( '\{path}', 'nyan:cat*' ), |
|
| 43 | - array( '\{path}', 'nyan:cat+' ), |
|
| 44 | - array( '\{path}', 'nyan:cat?' ), |
|
| 45 | - array( '\{path}', '!nyan:cat' ), |
|
| 46 | - array( '\{path}', '!(nyan:cat|nyan:kitten)' ), |
|
| 47 | - array( '\{path}', '!^nyan:cat' ), |
|
| 48 | - array( '\{path}', '!(^nyan:cat|^nyan:kitten)' ), |
|
| 49 | - array( '\{path}', '(nyan:cat)' ), |
|
| 50 | - array( '\{function}', 'COUNT (?x)' ), |
|
| 51 | - array( '\{function}', '?x + ?y' ), |
|
| 52 | - array( '\{function}', '!BOUND (?x)' ), |
|
| 53 | - array( '\{function}', '<http://www.example.com/test#nyan>' ), |
|
| 26 | + array('\{variable}', '?abc'), |
|
| 27 | + array('\{variable}', '$abc'), |
|
| 28 | + array('AS \{variable}', 'AS ?nyan'), |
|
| 29 | + array('\{iri}', 'http://www.example.com/test#'), |
|
| 30 | + array('\{prefix}', 'foo_bar42'), |
|
| 31 | + array('\{name}', 'foo_bar42'), |
|
| 32 | + array('\{prefixed_iri}', '<http://www.example.com/test#>'), |
|
| 33 | + array('\{prefixed_iri}', 'nyan:cat'), |
|
| 34 | + array('\{native}', '123'), |
|
| 35 | + array('\{native}', '"foo bar"'), |
|
| 36 | + array('\{path}', 'nyan:cat'), |
|
| 37 | + array('\{path}', '^nyan:cat'), |
|
| 38 | + array('\{path}', 'nyan:cat'), |
|
| 39 | + array('\{path}', 'nyan:cat/nyan:kitten'), |
|
| 40 | + array('\{path}', 'nyan:cat/nyan:kitten/cat:kitten'), |
|
| 41 | + array('\{path}', 'nyan:cat|nyan:kitten'), |
|
| 42 | + array('\{path}', 'nyan:cat*'), |
|
| 43 | + array('\{path}', 'nyan:cat+'), |
|
| 44 | + array('\{path}', 'nyan:cat?'), |
|
| 45 | + array('\{path}', '!nyan:cat'), |
|
| 46 | + array('\{path}', '!(nyan:cat|nyan:kitten)'), |
|
| 47 | + array('\{path}', '!^nyan:cat'), |
|
| 48 | + array('\{path}', '!(^nyan:cat|^nyan:kitten)'), |
|
| 49 | + array('\{path}', '(nyan:cat)'), |
|
| 50 | + array('\{function}', 'COUNT (?x)'), |
|
| 51 | + array('\{function}', '?x + ?y'), |
|
| 52 | + array('\{function}', '!BOUND (?x)'), |
|
| 53 | + array('\{function}', '<http://www.example.com/test#nyan>'), |
|
| 54 | 54 | ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @dataProvider provideNonMatchingExpressions |
| 59 | 59 | */ |
| 60 | - public function testMatchesRegex_nonMatching( $regex, $expression ) { |
|
| 60 | + public function testMatchesRegex_nonMatching($regex, $expression) { |
|
| 61 | 61 | $regexHelper = new RegexHelper(); |
| 62 | 62 | |
| 63 | - $this->assertFalse( $regexHelper->matchesRegex( $regex, $expression ) ); |
|
| 63 | + $this->assertFalse($regexHelper->matchesRegex($regex, $expression)); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | public function provideNonMatchingExpressions() { |
| 67 | 67 | return array( |
| 68 | - array( '\{variable}', 'foobar' ), |
|
| 69 | - array( '\{variable}', '?foo bar' ), |
|
| 70 | - array( 'AS \{variable}', 'AS ?nyan foobar' ), |
|
| 71 | - array( '\{iri}', '<http://www.example.com/test#>' ), |
|
| 72 | - array( '\{iri}', 'http://www.example.com/te>st#' ), |
|
| 73 | - array( '\{iri}', 'http://www.example.com/te}st#' ), |
|
| 74 | - array( '\{iri}', 'http://www.example.com/te st#' ), |
|
| 75 | - array( '\{prefix}', 'nyan cat' ), |
|
| 76 | - array( '\{prefix}', 'nyan:cat' ), |
|
| 77 | - array( '\{name}', 'nyan cat' ), |
|
| 78 | - array( '\{name}', 'nyan:cat' ), |
|
| 79 | - array( '\{prefixed_iri}', 'http://www.example.com/test#nyan' ), |
|
| 80 | - array( '\{prefixed_iri}', 'nyan:cat:kitten' ), |
|
| 81 | - array( '\{native}', '"abc' ), |
|
| 82 | - array( '\{native}', 'ab123' ), |
|
| 83 | - array( '\{path}', 'foobar' ), |
|
| 84 | - array( '\{path}', '?foobar' ), |
|
| 85 | - array( '\{path}', '^!nyan:cat' ), |
|
| 86 | - array( '\{path}', '!!!nyan:cat' ), |
|
| 87 | - array( '\{path}', '()' ), |
|
| 88 | - array( '\{function}', 'FOO BAR' ), |
|
| 89 | - array( '\{function}', '(COUNT (?x))' ) |
|
| 68 | + array('\{variable}', 'foobar'), |
|
| 69 | + array('\{variable}', '?foo bar'), |
|
| 70 | + array('AS \{variable}', 'AS ?nyan foobar'), |
|
| 71 | + array('\{iri}', '<http://www.example.com/test#>'), |
|
| 72 | + array('\{iri}', 'http://www.example.com/te>st#'), |
|
| 73 | + array('\{iri}', 'http://www.example.com/te}st#'), |
|
| 74 | + array('\{iri}', 'http://www.example.com/te st#'), |
|
| 75 | + array('\{prefix}', 'nyan cat'), |
|
| 76 | + array('\{prefix}', 'nyan:cat'), |
|
| 77 | + array('\{name}', 'nyan cat'), |
|
| 78 | + array('\{name}', 'nyan:cat'), |
|
| 79 | + array('\{prefixed_iri}', 'http://www.example.com/test#nyan'), |
|
| 80 | + array('\{prefixed_iri}', 'nyan:cat:kitten'), |
|
| 81 | + array('\{native}', '"abc'), |
|
| 82 | + array('\{native}', 'ab123'), |
|
| 83 | + array('\{path}', 'foobar'), |
|
| 84 | + array('\{path}', '?foobar'), |
|
| 85 | + array('\{path}', '^!nyan:cat'), |
|
| 86 | + array('\{path}', '!!!nyan:cat'), |
|
| 87 | + array('\{path}', '()'), |
|
| 88 | + array('\{function}', 'FOO BAR'), |
|
| 89 | + array('\{function}', '(COUNT (?x))') |
|
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @dataProvider provideGetMatches |
| 95 | 95 | */ |
| 96 | - public function testGetMatches( $regex, $expression, $matches ) { |
|
| 96 | + public function testGetMatches($regex, $expression, $matches) { |
|
| 97 | 97 | $regexHelper = new RegexHelper(); |
| 98 | 98 | |
| 99 | - $this->assertEquals( $matches, $regexHelper->getMatches( $regex, $expression ) ); |
|
| 99 | + $this->assertEquals($matches, $regexHelper->getMatches($regex, $expression)); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function provideGetMatches() { |
| 103 | 103 | return array( |
| 104 | - array( '\{variable}', ' ?abc nyan $def ', array( 'abc', 'def' ) ), |
|
| 105 | - array( 'AS \{variable}', 'FOO (?x) AS ?nyan', array( 'nyan' ) ), |
|
| 106 | - array( 'AS \{variable}', 'FOO (<http://www.example.com/test?kitten> = "X AS ?kitten") AS ?nyan', array( 'nyan' ) ) |
|
| 104 | + array('\{variable}', ' ?abc nyan $def ', array('abc', 'def')), |
|
| 105 | + array('AS \{variable}', 'FOO (?x) AS ?nyan', array('nyan')), |
|
| 106 | + array('AS \{variable}', 'FOO (<http://www.example.com/test?kitten> = "X AS ?kitten") AS ?nyan', array('nyan')) |
|
| 107 | 107 | ); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
| 111 | 111 | * @dataProvider provideEscapeSequences |
| 112 | 112 | */ |
| 113 | - public function testEscapeSequences( $expression, array $matches ) { |
|
| 113 | + public function testEscapeSequences($expression, array $matches) { |
|
| 114 | 114 | $regexHelper = new RegexHelper(); |
| 115 | - $escaped = $regexHelper->escapeSequences( $expression, $replacements ); |
|
| 115 | + $escaped = $regexHelper->escapeSequences($expression, $replacements); |
|
| 116 | 116 | |
| 117 | - $this->assertEquals( $matches, array_values( $replacements ) ); |
|
| 118 | - $this->assertEquals( $expression, strtr( $escaped, $replacements ) ); |
|
| 117 | + $this->assertEquals($matches, array_values($replacements)); |
|
| 118 | + $this->assertEquals($expression, strtr($escaped, $replacements)); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | public function provideEscapeSequences() { |
| 122 | 122 | return array( |
| 123 | - array( 'foo bar', array() ), |
|
| 124 | - array( 'cat " kitten', array() ), |
|
| 125 | - array( 'I\'m a "nyan cat" and this is cool', array( '"nyan cat"' ) ), |
|
| 126 | - array( 'This is "so sweet" and it\'s a "nyan" cat', array( '"so sweet"', '"nyan"' ) ), |
|
| 127 | - array( 'This <iri> is cool', array( '<iri>' ) ), |
|
| 128 | - array( 'This <iri> is > confusing', array( '<iri>' ) ), |
|
| 129 | - array( 'A "nyan cat" with <iri> 42', array( '"nyan cat"', '<iri>' ) ), |
|
| 130 | - array( 'A "nyan <iri> cat" with 42', array( '"nyan <iri> cat"' ) ), |
|
| 131 | - array( 'A "nyan <iri cat" with <iri> 42', array( '"nyan <iri cat"', '<iri>' ) ) |
|
| 123 | + array('foo bar', array()), |
|
| 124 | + array('cat " kitten', array()), |
|
| 125 | + array('I\'m a "nyan cat" and this is cool', array('"nyan cat"')), |
|
| 126 | + array('This is "so sweet" and it\'s a "nyan" cat', array('"so sweet"', '"nyan"')), |
|
| 127 | + array('This <iri> is cool', array('<iri>')), |
|
| 128 | + array('This <iri> is > confusing', array('<iri>')), |
|
| 129 | + array('A "nyan cat" with <iri> 42', array('"nyan cat"', '<iri>')), |
|
| 130 | + array('A "nyan <iri> cat" with 42', array('"nyan <iri> cat"')), |
|
| 131 | + array('A "nyan <iri cat" with <iri> 42', array('"nyan <iri cat"', '<iri>')) |
|
| 132 | 132 | ); |
| 133 | 133 | } |
| 134 | 134 | |
@@ -16,11 +16,11 @@ discard block |
||
| 16 | 16 | $queryBuilder = new QueryBuilder(); |
| 17 | 17 | $this->assertSame( |
| 18 | 18 | $queryBuilder, |
| 19 | - $queryBuilder->select( '?a', '?b' ) |
|
| 19 | + $queryBuilder->select('?a', '?b') |
|
| 20 | 20 | ); |
| 21 | 21 | |
| 22 | 22 | // use variables ?a and ?b |
| 23 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 23 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 24 | 24 | |
| 25 | 25 | $this->assertEquals( |
| 26 | 26 | 'SELECT ?a ?b WHERE { ?a ?b ?c . }', |
@@ -30,20 +30,20 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public function testSelect_invalidArgument() { |
| 32 | 32 | $queryBuilder = new QueryBuilder(); |
| 33 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 33 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 34 | 34 | |
| 35 | - $queryBuilder->select( '?a', false ); |
|
| 35 | + $queryBuilder->select('?a', false); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function testSelectDistinct() { |
| 39 | 39 | $queryBuilder = new QueryBuilder(); |
| 40 | 40 | $this->assertSame( |
| 41 | 41 | $queryBuilder, |
| 42 | - $queryBuilder->selectDistinct( '?a', '?b' ) |
|
| 42 | + $queryBuilder->selectDistinct('?a', '?b') |
|
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | 45 | // use variables ?a and ?b |
| 46 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 46 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 47 | 47 | |
| 48 | 48 | $this->assertEquals( |
| 49 | 49 | 'SELECT DISTINCT ?a ?b WHERE { ?a ?b ?c . }', |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | $queryBuilder = new QueryBuilder(); |
| 56 | 56 | $this->assertSame( |
| 57 | 57 | $queryBuilder, |
| 58 | - $queryBuilder->selectReduced( '?a', '?b' ) |
|
| 58 | + $queryBuilder->selectReduced('?a', '?b') |
|
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | // use variables ?a and ?b |
| 62 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 62 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 63 | 63 | |
| 64 | 64 | $this->assertEquals( |
| 65 | 65 | 'SELECT REDUCED ?a ?b WHERE { ?a ?b ?c . }', |
@@ -71,11 +71,11 @@ discard block |
||
| 71 | 71 | $queryBuilder = new QueryBuilder(); |
| 72 | 72 | $this->assertSame( |
| 73 | 73 | $queryBuilder, |
| 74 | - $queryBuilder->describe( '?a', '?b', '<foo:bar>' ) |
|
| 74 | + $queryBuilder->describe('?a', '?b', '<foo:bar>') |
|
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | // use variables ?a and ?b |
| 78 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 78 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 79 | 79 | |
| 80 | 80 | $this->assertEquals( |
| 81 | 81 | 'DESCRIBE ?a ?b <foo:bar> WHERE { ?a ?b ?c . }', |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | $queryBuilder = new QueryBuilder(); |
| 88 | 88 | $this->assertSame( |
| 89 | 89 | $queryBuilder, |
| 90 | - $queryBuilder->describe( 'foo:bar' ) |
|
| 90 | + $queryBuilder->describe('foo:bar') |
|
| 91 | 91 | ); |
| 92 | 92 | |
| 93 | 93 | // use variables ?a and ?b |
| 94 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 94 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 95 | 95 | |
| 96 | - $this->setExpectedException( 'RangeException' ); |
|
| 96 | + $this->setExpectedException('RangeException'); |
|
| 97 | 97 | $queryBuilder->getSPARQL(); |
| 98 | 98 | } |
| 99 | 99 | |
@@ -101,18 +101,18 @@ discard block |
||
| 101 | 101 | $queryBuilder = new QueryBuilder(); |
| 102 | 102 | $this->assertSame( |
| 103 | 103 | $queryBuilder, |
| 104 | - $queryBuilder->select( '?a', '?b' ) |
|
| 104 | + $queryBuilder->select('?a', '?b') |
|
| 105 | 105 | ); |
| 106 | 106 | |
| 107 | - $this->setExpectedException( 'RuntimeException' ); |
|
| 108 | - $queryBuilder->describe( 'foo:bar' ); |
|
| 107 | + $this->setExpectedException('RuntimeException'); |
|
| 108 | + $queryBuilder->describe('foo:bar'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | public function testWhere() { |
| 112 | 112 | $queryBuilder = new QueryBuilder(); |
| 113 | 113 | $this->assertSame( |
| 114 | 114 | $queryBuilder, |
| 115 | - $queryBuilder->where( '?a', '?b', '?c' ) |
|
| 115 | + $queryBuilder->where('?a', '?b', '?c') |
|
| 116 | 116 | ); |
| 117 | 117 | } |
| 118 | 118 | |
@@ -120,25 +120,25 @@ discard block |
||
| 120 | 120 | $queryBuilder = new QueryBuilder(); |
| 121 | 121 | $this->assertSame( |
| 122 | 122 | $queryBuilder, |
| 123 | - $queryBuilder->also( '?a', '?b', '?c' ) |
|
| 123 | + $queryBuilder->also('?a', '?b', '?c') |
|
| 124 | 124 | ); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | public function testAlso_knownSubject() { |
| 128 | 128 | $queryBuilder = new QueryBuilder(); |
| 129 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 129 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 130 | 130 | $this->assertSame( |
| 131 | 131 | $queryBuilder, |
| 132 | - $queryBuilder->also( '?x', '?y' ) |
|
| 132 | + $queryBuilder->also('?x', '?y') |
|
| 133 | 133 | ); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | public function testAlso_knownPredicate() { |
| 137 | 137 | $queryBuilder = new QueryBuilder(); |
| 138 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 138 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 139 | 139 | $this->assertSame( |
| 140 | 140 | $queryBuilder, |
| 141 | - $queryBuilder->also( '?z' ) |
|
| 141 | + $queryBuilder->also('?z') |
|
| 142 | 142 | ); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $queryBuilder = new QueryBuilder(); |
| 147 | 147 | $this->assertSame( |
| 148 | 148 | $queryBuilder, |
| 149 | - $queryBuilder->filter( 'AVG (?x) > 9' ) |
|
| 149 | + $queryBuilder->filter('AVG (?x) > 9') |
|
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | $queryBuilder = new QueryBuilder(); |
| 155 | 155 | $this->assertSame( |
| 156 | 156 | $queryBuilder, |
| 157 | - $queryBuilder->filterExists( $queryBuilder->newSubgraph() ) |
|
| 157 | + $queryBuilder->filterExists($queryBuilder->newSubgraph()) |
|
| 158 | 158 | ); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $queryBuilder = new QueryBuilder(); |
| 163 | 163 | $this->assertSame( |
| 164 | 164 | $queryBuilder, |
| 165 | - $queryBuilder->filterNotExists( $queryBuilder->newSubgraph() ) |
|
| 165 | + $queryBuilder->filterNotExists($queryBuilder->newSubgraph()) |
|
| 166 | 166 | ); |
| 167 | 167 | } |
| 168 | 168 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | $queryBuilder = new QueryBuilder(); |
| 171 | 171 | $this->assertSame( |
| 172 | 172 | $queryBuilder, |
| 173 | - $queryBuilder->optional( '?a', '?b', '?c' ) |
|
| 173 | + $queryBuilder->optional('?a', '?b', '?c') |
|
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $queryBuilder = new QueryBuilder(); |
| 179 | 179 | $this->assertSame( |
| 180 | 180 | $queryBuilder, |
| 181 | - $queryBuilder->union( $queryBuilder->newSubgraph() ) |
|
| 181 | + $queryBuilder->union($queryBuilder->newSubgraph()) |
|
| 182 | 182 | ); |
| 183 | 183 | } |
| 184 | 184 | |
@@ -186,29 +186,29 @@ discard block |
||
| 186 | 186 | $queryBuilder = new QueryBuilder(); |
| 187 | 187 | $this->assertSame( |
| 188 | 188 | $queryBuilder, |
| 189 | - $queryBuilder->subquery( $queryBuilder->newSubquery() ) |
|
| 189 | + $queryBuilder->subquery($queryBuilder->newSubquery()) |
|
| 190 | 190 | ); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | public function testNewSubquery() { |
| 194 | - $queryBuilder = new QueryBuilder( array( 'a' => 'b' ) ); |
|
| 194 | + $queryBuilder = new QueryBuilder(array('a' => 'b')); |
|
| 195 | 195 | $this->assertEquals( |
| 196 | - new QueryBuilder( array( 'a' => 'b' ) ), |
|
| 196 | + new QueryBuilder(array('a' => 'b')), |
|
| 197 | 197 | $queryBuilder->newSubquery() |
| 198 | 198 | ); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | public function testNewSubgraph() { |
| 202 | 202 | $queryBuilder = new QueryBuilder(); |
| 203 | - $this->assertInstanceOf( 'Asparagus\GraphBuilder', $queryBuilder->newSubgraph() ); |
|
| 204 | - $this->assertNotSame( $queryBuilder->newSubgraph(), $queryBuilder->newSubgraph() ); |
|
| 203 | + $this->assertInstanceOf('Asparagus\GraphBuilder', $queryBuilder->newSubgraph()); |
|
| 204 | + $this->assertNotSame($queryBuilder->newSubgraph(), $queryBuilder->newSubgraph()); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | public function testGroupBy() { |
| 208 | 208 | $queryBuilder = new QueryBuilder(); |
| 209 | 209 | $this->assertSame( |
| 210 | 210 | $queryBuilder, |
| 211 | - $queryBuilder->groupBy( '?test' ) |
|
| 211 | + $queryBuilder->groupBy('?test') |
|
| 212 | 212 | ); |
| 213 | 213 | } |
| 214 | 214 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $queryBuilder = new QueryBuilder(); |
| 217 | 217 | $this->assertSame( |
| 218 | 218 | $queryBuilder, |
| 219 | - $queryBuilder->having( 'AVG(?size) > 10' ) |
|
| 219 | + $queryBuilder->having('AVG(?size) > 10') |
|
| 220 | 220 | ); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $queryBuilder = new QueryBuilder(); |
| 225 | 225 | $this->assertSame( |
| 226 | 226 | $queryBuilder, |
| 227 | - $queryBuilder->orderBy( '?test' ) |
|
| 227 | + $queryBuilder->orderBy('?test') |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $queryBuilder = new QueryBuilder(); |
| 233 | 233 | $this->assertSame( |
| 234 | 234 | $queryBuilder, |
| 235 | - $queryBuilder->limit( 5 ) |
|
| 235 | + $queryBuilder->limit(5) |
|
| 236 | 236 | ); |
| 237 | 237 | } |
| 238 | 238 | |
@@ -240,52 +240,52 @@ discard block |
||
| 240 | 240 | $queryBuilder = new QueryBuilder(); |
| 241 | 241 | $this->assertSame( |
| 242 | 242 | $queryBuilder, |
| 243 | - $queryBuilder->offset( 5 ) |
|
| 243 | + $queryBuilder->offset(5) |
|
| 244 | 244 | ); |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | public function testGetSPARQL() { |
| 248 | 248 | $queryBuilder = new QueryBuilder(); |
| 249 | 249 | |
| 250 | - $this->assertEquals( 'SELECT * WHERE { }', $queryBuilder->getSPARQL() ); |
|
| 250 | + $this->assertEquals('SELECT * WHERE { }', $queryBuilder->getSPARQL()); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | public function testGetSPARQL_withPrefixes() { |
| 254 | - $queryBuilder = new QueryBuilder( array( 'foo' => 'bar' ) ); |
|
| 254 | + $queryBuilder = new QueryBuilder(array('foo' => 'bar')); |
|
| 255 | 255 | |
| 256 | - $this->assertEquals( 'PREFIX foo: <bar> SELECT * WHERE { }', $queryBuilder->getSPARQL() ); |
|
| 256 | + $this->assertEquals('PREFIX foo: <bar> SELECT * WHERE { }', $queryBuilder->getSPARQL()); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | public function testGetSPARQL_noPrefixes() { |
| 260 | - $queryBuilder = new QueryBuilder( array( 'foo' => 'bar' ) ); |
|
| 260 | + $queryBuilder = new QueryBuilder(array('foo' => 'bar')); |
|
| 261 | 261 | |
| 262 | - $this->assertEquals( 'SELECT * WHERE { }', $queryBuilder->getSPARQL( false ) ); |
|
| 262 | + $this->assertEquals('SELECT * WHERE { }', $queryBuilder->getSPARQL(false)); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | public function testGetSPARQL_undefinedVariable() { |
| 266 | 266 | $queryBuilder = new QueryBuilder(); |
| 267 | - $this->setExpectedException( 'RangeException', '?x' ); |
|
| 267 | + $this->setExpectedException('RangeException', '?x'); |
|
| 268 | 268 | |
| 269 | - $queryBuilder->select( '?x' )->getSPARQL(); |
|
| 269 | + $queryBuilder->select('?x')->getSPARQL(); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | public function testGetSPARQL_undefinedPrefix() { |
| 273 | 273 | $queryBuilder = new QueryBuilder(); |
| 274 | - $this->setExpectedException( 'RangeException', 'foo, nyan' ); |
|
| 274 | + $this->setExpectedException('RangeException', 'foo, nyan'); |
|
| 275 | 275 | |
| 276 | - $queryBuilder->where( '?x', 'foo:bar', 'nyan:data' )->getSPARQL(); |
|
| 276 | + $queryBuilder->where('?x', 'foo:bar', 'nyan:data')->getSPARQL(); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | public function testToString() { |
| 280 | 280 | $queryBuilder = new QueryBuilder(); |
| 281 | 281 | |
| 282 | - $this->assertEquals( 'SELECT * WHERE { }', strval( $queryBuilder ) ); |
|
| 282 | + $this->assertEquals('SELECT * WHERE { }', strval($queryBuilder)); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | public function testFormat() { |
| 286 | 286 | $queryBuilder = new QueryBuilder(); |
| 287 | 287 | |
| 288 | - $this->assertEquals( "SELECT * WHERE {\n}\n", $queryBuilder->format() ); |
|
| 288 | + $this->assertEquals("SELECT * WHERE {\n}\n", $queryBuilder->format()); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | } |
@@ -15,23 +15,23 @@ discard block |
||
| 15 | 15 | /** |
| 16 | 16 | * @dataProvider provideDataOk |
| 17 | 17 | */ |
| 18 | - public function testValidate_variablesOk( array $defined, array $used ) { |
|
| 18 | + public function testValidate_variablesOk(array $defined, array $used) { |
|
| 19 | 19 | $usageValidator = new UsageValidator(); |
| 20 | - $usageValidator->trackDefinedVariables( $defined ); |
|
| 21 | - $usageValidator->trackUsedVariables( $used ); |
|
| 20 | + $usageValidator->trackDefinedVariables($defined); |
|
| 21 | + $usageValidator->trackUsedVariables($used); |
|
| 22 | 22 | $usageValidator->validate(); |
| 23 | 23 | |
| 24 | - $this->assertTrue( true ); |
|
| 24 | + $this->assertTrue(true); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * @dataProvider provideDataInvalid |
| 29 | 29 | */ |
| 30 | - public function testValidate_variablesInvalid( array $defined, array $used ) { |
|
| 30 | + public function testValidate_variablesInvalid(array $defined, array $used) { |
|
| 31 | 31 | $usageValidator = new UsageValidator(); |
| 32 | - $usageValidator->trackDefinedVariables( $defined ); |
|
| 33 | - $usageValidator->trackUsedVariables( $used ); |
|
| 34 | - $this->setExpectedException( 'RangeException' ); |
|
| 32 | + $usageValidator->trackDefinedVariables($defined); |
|
| 33 | + $usageValidator->trackUsedVariables($used); |
|
| 34 | + $this->setExpectedException('RangeException'); |
|
| 35 | 35 | |
| 36 | 36 | $usageValidator->validate(); |
| 37 | 37 | } |
@@ -39,82 +39,82 @@ discard block |
||
| 39 | 39 | /** |
| 40 | 40 | * @dataProvider provideDataOk |
| 41 | 41 | */ |
| 42 | - public function testValidate_prefixesOk( array $defined, array $used ) { |
|
| 42 | + public function testValidate_prefixesOk(array $defined, array $used) { |
|
| 43 | 43 | $usageValidator = new UsageValidator(); |
| 44 | - $usageValidator->trackDefinedPrefixes( $defined ); |
|
| 45 | - $usageValidator->trackUsedPrefixes( $used ); |
|
| 44 | + $usageValidator->trackDefinedPrefixes($defined); |
|
| 45 | + $usageValidator->trackUsedPrefixes($used); |
|
| 46 | 46 | $usageValidator->validate(); |
| 47 | 47 | |
| 48 | - $this->assertTrue( true ); |
|
| 48 | + $this->assertTrue(true); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @dataProvider provideDataInvalid |
| 53 | 53 | */ |
| 54 | - public function testValidate_prefixesInvalid( array $defined, array $used ) { |
|
| 54 | + public function testValidate_prefixesInvalid(array $defined, array $used) { |
|
| 55 | 55 | $usageValidator = new UsageValidator(); |
| 56 | - $usageValidator->trackDefinedPrefixes( $defined ); |
|
| 57 | - $usageValidator->trackUsedPrefixes( $used ); |
|
| 58 | - $this->setExpectedException( 'RangeException' ); |
|
| 56 | + $usageValidator->trackDefinedPrefixes($defined); |
|
| 57 | + $usageValidator->trackUsedPrefixes($used); |
|
| 58 | + $this->setExpectedException('RangeException'); |
|
| 59 | 59 | |
| 60 | 60 | $usageValidator->validate(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function provideDataOk() { |
| 64 | 64 | return array( |
| 65 | - array( array(), array() ), |
|
| 66 | - array( array( 'foo', 'bar' ), array() ), |
|
| 67 | - array( array( 'foo', 'bar' ), array( 'foo' ) ), |
|
| 68 | - array( array( 'foo', 'bar' ), array( 'foo', 'bar' ) ), |
|
| 65 | + array(array(), array()), |
|
| 66 | + array(array('foo', 'bar'), array()), |
|
| 67 | + array(array('foo', 'bar'), array('foo')), |
|
| 68 | + array(array('foo', 'bar'), array('foo', 'bar')), |
|
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function provideDataInvalid() { |
| 73 | 73 | return array( |
| 74 | - array( array(), array( 'foo', 'bar' ) ), |
|
| 75 | - array( array( 'foo' ), array( 'foo', 'bar' ) ), |
|
| 76 | - array( array( 'bar' ), array( 'foo', 'bar' ) ), |
|
| 74 | + array(array(), array('foo', 'bar')), |
|
| 75 | + array(array('foo'), array('foo', 'bar')), |
|
| 76 | + array(array('bar'), array('foo', 'bar')), |
|
| 77 | 77 | ); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | 81 | * @dataProvider provideTrackVariablesParsing |
| 82 | 82 | */ |
| 83 | - public function testTrackVariablesParsing( $input, $expected ) { |
|
| 83 | + public function testTrackVariablesParsing($input, $expected) { |
|
| 84 | 84 | $usageValidator = new UsageValidator(); |
| 85 | - $usageValidator->trackUsedVariables( $input ); |
|
| 86 | - $this->setExpectedException( 'RangeException', $expected ); |
|
| 85 | + $usageValidator->trackUsedVariables($input); |
|
| 86 | + $this->setExpectedException('RangeException', $expected); |
|
| 87 | 87 | |
| 88 | 88 | $usageValidator->validate(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | public function provideTrackVariablesParsing() { |
| 92 | 92 | return array( |
| 93 | - array( 'foo ?abc bar', '?abc' ), |
|
| 94 | - array( 'foo $abc bar', '?abc' ), |
|
| 95 | - array( '?foo abc $bar', '?foo, ?bar' ), |
|
| 96 | - array( 'foo.?abc', '?abc' ), |
|
| 97 | - array( '?foo$bar', '?foo' ), |
|
| 98 | - array( '?foo AS ?bar', '?foo' ) |
|
| 93 | + array('foo ?abc bar', '?abc'), |
|
| 94 | + array('foo $abc bar', '?abc'), |
|
| 95 | + array('?foo abc $bar', '?foo, ?bar'), |
|
| 96 | + array('foo.?abc', '?abc'), |
|
| 97 | + array('?foo$bar', '?foo'), |
|
| 98 | + array('?foo AS ?bar', '?foo') |
|
| 99 | 99 | ); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * @dataProvider provideTrackPrefixesParsing |
| 104 | 104 | */ |
| 105 | - public function testTrackPrefixesParsing( $input, $expected ) { |
|
| 105 | + public function testTrackPrefixesParsing($input, $expected) { |
|
| 106 | 106 | $usageValidator = new UsageValidator(); |
| 107 | - $usageValidator->trackUsedPrefixes( $input ); |
|
| 108 | - $this->setExpectedException( 'RangeException', $expected ); |
|
| 107 | + $usageValidator->trackUsedPrefixes($input); |
|
| 108 | + $this->setExpectedException('RangeException', $expected); |
|
| 109 | 109 | |
| 110 | 110 | $usageValidator->validate(); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | public function provideTrackPrefixesParsing() { |
| 114 | 114 | return array( |
| 115 | - array( 'abc foo:bar def', array( 'foo' ) ), |
|
| 116 | - array( 'foo:abc xxx bar:def', array( 'foo', 'bar' ) ), |
|
| 117 | - array( 'abc.foo:bar', array( 'foo' ) ) |
|
| 115 | + array('abc foo:bar def', array('foo')), |
|
| 116 | + array('foo:abc xxx bar:def', array('foo', 'bar')), |
|
| 117 | + array('abc.foo:bar', array('foo')) |
|
| 118 | 118 | ); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -15,183 +15,183 @@ |
||
| 15 | 15 | class GraphBuilderTest extends \PHPUnit_Framework_TestCase { |
| 16 | 16 | |
| 17 | 17 | public function testWhere() { |
| 18 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 18 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 19 | 19 | $this->assertSame( |
| 20 | 20 | $graphBuilder, |
| 21 | - $graphBuilder->where( '?a', '?b', '?c' ) |
|
| 21 | + $graphBuilder->where('?a', '?b', '?c') |
|
| 22 | 22 | ); |
| 23 | 23 | |
| 24 | - $this->assertEquals( ' ?a ?b ?c .', $graphBuilder->getSPARQL() ); |
|
| 24 | + $this->assertEquals(' ?a ?b ?c .', $graphBuilder->getSPARQL()); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function testWhere_invalidSubject() { |
| 28 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 29 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 28 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 29 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 30 | 30 | |
| 31 | - $graphBuilder->where( null, '?b', '?c' ); |
|
| 31 | + $graphBuilder->where(null, '?b', '?c'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function testWhere_invalidPredicate() { |
| 35 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 36 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 35 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 36 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 37 | 37 | |
| 38 | - $graphBuilder->where( '?a', null, '?c' ); |
|
| 38 | + $graphBuilder->where('?a', null, '?c'); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function testWhere_invalidObject() { |
| 42 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 43 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 42 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 43 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 44 | 44 | |
| 45 | - $graphBuilder->where( '?a', '?b', null ); |
|
| 45 | + $graphBuilder->where('?a', '?b', null); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function testAlso_knownSubject() { |
| 49 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 50 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 49 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 50 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 51 | 51 | $this->assertSame( |
| 52 | 52 | $graphBuilder, |
| 53 | - $graphBuilder->also( '?x', '?y' ) |
|
| 53 | + $graphBuilder->also('?x', '?y') |
|
| 54 | 54 | ); |
| 55 | 55 | |
| 56 | - $this->assertEquals( ' ?a ?b ?c ; ?x ?y .', $graphBuilder->getSPARQL() ); |
|
| 56 | + $this->assertEquals(' ?a ?b ?c ; ?x ?y .', $graphBuilder->getSPARQL()); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function testAlso_knownPredicate() { |
| 60 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 61 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 60 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 61 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 62 | 62 | $this->assertSame( |
| 63 | 63 | $graphBuilder, |
| 64 | - $graphBuilder->also( '?x' ) |
|
| 64 | + $graphBuilder->also('?x') |
|
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $this->assertEquals( ' ?a ?b ?c , ?x .', $graphBuilder->getSPARQL() ); |
|
| 67 | + $this->assertEquals(' ?a ?b ?c , ?x .', $graphBuilder->getSPARQL()); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | public function testAlso_unknownSubject() { |
| 71 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 72 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 71 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 72 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 73 | 73 | |
| 74 | - $graphBuilder->also( '?x', '?y' ); |
|
| 74 | + $graphBuilder->also('?x', '?y'); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function testAlso_unknownPredicate() { |
| 78 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 79 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 78 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 79 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 80 | 80 | |
| 81 | - $graphBuilder->also( '?y' ); |
|
| 81 | + $graphBuilder->also('?y'); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | public function testFilter() { |
| 85 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 85 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 86 | 86 | $this->assertSame( |
| 87 | 87 | $graphBuilder, |
| 88 | - $graphBuilder->filter( 'AVG (?x) > 5' ) |
|
| 88 | + $graphBuilder->filter('AVG (?x) > 5') |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | - $this->assertEquals( ' FILTER (AVG (?x) > 5)', $graphBuilder->getSPARQL() ); |
|
| 91 | + $this->assertEquals(' FILTER (AVG (?x) > 5)', $graphBuilder->getSPARQL()); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | public function testFilter_invalidExpression() { |
| 95 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 96 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 95 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 96 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 97 | 97 | |
| 98 | - $graphBuilder->filter( 'FooBar' ); |
|
| 98 | + $graphBuilder->filter('FooBar'); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | public function testFilterExists() { |
| 102 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 103 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 102 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 103 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 104 | 104 | $this->assertSame( |
| 105 | 105 | $graphBuilder, |
| 106 | - $graphBuilder->filterExists( $graphBuilder ) |
|
| 106 | + $graphBuilder->filterExists($graphBuilder) |
|
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - $this->assertEquals( ' ?a ?b ?c . FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 109 | + $this->assertEquals(' ?a ?b ?c . FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | public function testFilterExists_triple() { |
| 113 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 113 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 114 | 114 | $this->assertSame( |
| 115 | 115 | $graphBuilder, |
| 116 | - $graphBuilder->filterExists( '?a', '?b', '?c' ) |
|
| 116 | + $graphBuilder->filterExists('?a', '?b', '?c') |
|
| 117 | 117 | ); |
| 118 | 118 | |
| 119 | - $this->assertEquals( ' FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 119 | + $this->assertEquals(' FILTER EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | public function testFilterNotExists() { |
| 123 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 124 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 123 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 124 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 125 | 125 | $this->assertSame( |
| 126 | 126 | $graphBuilder, |
| 127 | - $graphBuilder->filterNotExists( $graphBuilder ) |
|
| 127 | + $graphBuilder->filterNotExists($graphBuilder) |
|
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | - $this->assertEquals( ' ?a ?b ?c . FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 130 | + $this->assertEquals(' ?a ?b ?c . FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | public function testFilterNotExists_triple() { |
| 134 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 134 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 135 | 135 | $this->assertSame( |
| 136 | 136 | $graphBuilder, |
| 137 | - $graphBuilder->filterNotExists( '?a', '?b', '?c' ) |
|
| 137 | + $graphBuilder->filterNotExists('?a', '?b', '?c') |
|
| 138 | 138 | ); |
| 139 | 139 | |
| 140 | - $this->assertEquals( ' FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 140 | + $this->assertEquals(' FILTER NOT EXISTS { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | public function testOptional() { |
| 144 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 145 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 144 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 145 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 146 | 146 | $this->assertSame( |
| 147 | 147 | $graphBuilder, |
| 148 | - $graphBuilder->optional( $graphBuilder ) |
|
| 148 | + $graphBuilder->optional($graphBuilder) |
|
| 149 | 149 | ); |
| 150 | 150 | |
| 151 | - $this->assertEquals( ' ?a ?b ?c . OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 151 | + $this->assertEquals(' ?a ?b ?c . OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | public function testOptional_triple() { |
| 155 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 155 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 156 | 156 | $this->assertSame( |
| 157 | 157 | $graphBuilder, |
| 158 | - $graphBuilder->optional( '?a', '?b', '?c' ) |
|
| 158 | + $graphBuilder->optional('?a', '?b', '?c') |
|
| 159 | 159 | ); |
| 160 | 160 | |
| 161 | - $this->assertEquals( ' OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 161 | + $this->assertEquals(' OPTIONAL { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | public function testUnion() { |
| 165 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 166 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 165 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 166 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 167 | 167 | $this->assertSame( |
| 168 | 168 | $graphBuilder, |
| 169 | - $graphBuilder->union( $graphBuilder, $graphBuilder ) |
|
| 169 | + $graphBuilder->union($graphBuilder, $graphBuilder) |
|
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | - $this->assertEquals( ' ?a ?b ?c . { ?a ?b ?c . } UNION { ?a ?b ?c . }', $graphBuilder->getSPARQL() ); |
|
| 172 | + $this->assertEquals(' ?a ?b ?c . { ?a ?b ?c . } UNION { ?a ?b ?c . }', $graphBuilder->getSPARQL()); |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | public function testSubquery() { |
| 176 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 176 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 177 | 177 | $queryBuilder = new QueryBuilder(); |
| 178 | - $queryBuilder->where( '?a', '?b', '?c' ); |
|
| 178 | + $queryBuilder->where('?a', '?b', '?c'); |
|
| 179 | 179 | $this->assertSame( |
| 180 | 180 | $graphBuilder, |
| 181 | - $graphBuilder->subquery( $queryBuilder ) |
|
| 181 | + $graphBuilder->subquery($queryBuilder) |
|
| 182 | 182 | ); |
| 183 | 183 | |
| 184 | - $this->assertEquals( ' { SELECT * WHERE { ?a ?b ?c . } }', $graphBuilder->getSPARQL() ); |
|
| 184 | + $this->assertEquals(' { SELECT * WHERE { ?a ?b ?c . } }', $graphBuilder->getSPARQL()); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | public function testGetSPARQL() { |
| 188 | - $graphBuilder = new GraphBuilder( new UsageValidator() ); |
|
| 189 | - $graphBuilder->where( '?a', '?b', '?c' ); |
|
| 190 | - $graphBuilder->also( '?x', '?y' ); |
|
| 191 | - $graphBuilder->also( '?z' ); |
|
| 192 | - $graphBuilder->where( '?a', '?b', '?z' ); |
|
| 188 | + $graphBuilder = new GraphBuilder(new UsageValidator()); |
|
| 189 | + $graphBuilder->where('?a', '?b', '?c'); |
|
| 190 | + $graphBuilder->also('?x', '?y'); |
|
| 191 | + $graphBuilder->also('?z'); |
|
| 192 | + $graphBuilder->where('?a', '?b', '?z'); |
|
| 193 | 193 | |
| 194 | - $this->assertEquals( ' ?a ?b ?c , ?z ; ?x ?y , ?z .', $graphBuilder->getSPARQL() ); |
|
| 194 | + $this->assertEquals(' ?a ?b ?c , ?z ; ?x ?y , ?z .', $graphBuilder->getSPARQL()); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | } |
@@ -15,84 +15,84 @@ |
||
| 15 | 15 | /** |
| 16 | 16 | * @dataProvider provideValidExpressions |
| 17 | 17 | */ |
| 18 | - public function testValidate_validExpressions( $expression, $options ) { |
|
| 18 | + public function testValidate_validExpressions($expression, $options) { |
|
| 19 | 19 | $expressionValidator = new ExpressionValidator(); |
| 20 | - $expressionValidator->validate( $expression, $options ); |
|
| 20 | + $expressionValidator->validate($expression, $options); |
|
| 21 | 21 | |
| 22 | - $this->assertTrue( true ); |
|
| 22 | + $this->assertTrue(true); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function provideValidExpressions() { |
| 26 | 26 | return array( |
| 27 | - array( '?a', ExpressionValidator::VALIDATE_VARIABLE ), |
|
| 28 | - array( '$b', ExpressionValidator::VALIDATE_VARIABLE ), |
|
| 29 | - array( 'http://www.example.com/test#', ExpressionValidator::VALIDATE_IRI ), |
|
| 30 | - array( 'abc', ExpressionValidator::VALIDATE_PREFIX ), |
|
| 31 | - array( 'test:FooBar', ExpressionValidator::VALIDATE_PREFIXED_IRI ), |
|
| 32 | - array( '<http://www.example.com/test#>', ExpressionValidator::VALIDATE_PREFIXED_IRI ), |
|
| 33 | - array( '123', ExpressionValidator::VALIDATE_NATIVE ), |
|
| 34 | - array( '"Foo bar"', ExpressionValidator::VALIDATE_NATIVE ), |
|
| 35 | - array( 'foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
| 36 | - array( 'foaf:knows/foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
| 37 | - array( 'foaf:knows/^foaf:knows', ExpressionValidator::VALIDATE_PATH ), |
|
| 38 | - array( 'foaf:knows+/foaf:name', ExpressionValidator::VALIDATE_PATH ), |
|
| 39 | - array( '(ex:motherOf|ex:fatherOf)+', ExpressionValidator::VALIDATE_PATH ), |
|
| 40 | - array( 'rdf:type/rdfs:subClassOf*', ExpressionValidator::VALIDATE_PATH ), |
|
| 41 | - array( '^rdf:type', ExpressionValidator::VALIDATE_PATH ), |
|
| 42 | - array( '!(rdf:type|^rdf:type)', ExpressionValidator::VALIDATE_PATH ), |
|
| 43 | - array( 'CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 44 | - array( '?abc', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 45 | - array( '?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 46 | - array( '?x * ?x < ?y', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 47 | - array( 'CONTAINS (?x, ")))"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 48 | - array( '<http://www.example.com/test#nyan> ?p ?q', ExpressionValidator::VALIDATE_FUNCTION ), |
|
| 49 | - array( '(COUNT (?x) AS ?count)', ExpressionValidator::VALIDATE_FUNCTION_AS ), |
|
| 27 | + array('?a', ExpressionValidator::VALIDATE_VARIABLE), |
|
| 28 | + array('$b', ExpressionValidator::VALIDATE_VARIABLE), |
|
| 29 | + array('http://www.example.com/test#', ExpressionValidator::VALIDATE_IRI), |
|
| 30 | + array('abc', ExpressionValidator::VALIDATE_PREFIX), |
|
| 31 | + array('test:FooBar', ExpressionValidator::VALIDATE_PREFIXED_IRI), |
|
| 32 | + array('<http://www.example.com/test#>', ExpressionValidator::VALIDATE_PREFIXED_IRI), |
|
| 33 | + array('123', ExpressionValidator::VALIDATE_NATIVE), |
|
| 34 | + array('"Foo bar"', ExpressionValidator::VALIDATE_NATIVE), |
|
| 35 | + array('foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
| 36 | + array('foaf:knows/foaf:knows/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
| 37 | + array('foaf:knows/^foaf:knows', ExpressionValidator::VALIDATE_PATH), |
|
| 38 | + array('foaf:knows+/foaf:name', ExpressionValidator::VALIDATE_PATH), |
|
| 39 | + array('(ex:motherOf|ex:fatherOf)+', ExpressionValidator::VALIDATE_PATH), |
|
| 40 | + array('rdf:type/rdfs:subClassOf*', ExpressionValidator::VALIDATE_PATH), |
|
| 41 | + array('^rdf:type', ExpressionValidator::VALIDATE_PATH), |
|
| 42 | + array('!(rdf:type|^rdf:type)', ExpressionValidator::VALIDATE_PATH), |
|
| 43 | + array('CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 44 | + array('?abc', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 45 | + array('?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 46 | + array('?x * ?x < ?y', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 47 | + array('CONTAINS (?x, ")))"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 48 | + array('<http://www.example.com/test#nyan> ?p ?q', ExpressionValidator::VALIDATE_FUNCTION), |
|
| 49 | + array('(COUNT (?x) AS ?count)', ExpressionValidator::VALIDATE_FUNCTION_AS), |
|
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @dataProvider provideInvalidExpressions |
| 55 | 55 | */ |
| 56 | - public function testValidate_invalidExpressions( $expression, $options, $errorMessage ) { |
|
| 56 | + public function testValidate_invalidExpressions($expression, $options, $errorMessage) { |
|
| 57 | 57 | $expressionValidator = new ExpressionValidator(); |
| 58 | - $this->setExpectedException( 'InvalidArgumentException', $errorMessage ); |
|
| 58 | + $this->setExpectedException('InvalidArgumentException', $errorMessage); |
|
| 59 | 59 | |
| 60 | - $expressionValidator->validate( $expression, $options ); |
|
| 60 | + $expressionValidator->validate($expression, $options); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | public function provideInvalidExpressions() { |
| 64 | 64 | return array( |
| 65 | - array( 'nyan', ExpressionValidator::VALIDATE_VARIABLE, 'variable' ), |
|
| 66 | - array( '<http://www.example.com/test#>', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 67 | - array( 'http://www.example.com/test#> foo bar', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 68 | - array( '<abc><>', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 69 | - array( 'http://www.example.com/te st#', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 70 | - array( 'http://www.example.com/test#ab\cd', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 71 | - array( 'http://www.example.com/test#ab|cd', ExpressionValidator::VALIDATE_IRI, 'IRI' ), |
|
| 72 | - array( 'ab:cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
| 73 | - array( 'ab/cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
| 74 | - array( 'ab cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix' ), |
|
| 75 | - array( 'foobar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI' ), |
|
| 76 | - array( 'test:Foo:Bar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI' ), |
|
| 77 | - array( '"abc', ExpressionValidator::VALIDATE_NATIVE, 'native' ), |
|
| 78 | - array( 'abc123', ExpressionValidator::VALIDATE_NATIVE, 'native' ), |
|
| 79 | - array( 'foobar (?x > ?y)', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
| 80 | - array( '(RAND ())', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
| 81 | - array( 'COUNT (?x) + 5) * ?a', ExpressionValidator::VALIDATE_FUNCTION, 'function' ), |
|
| 82 | - array( 'CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
| 83 | - array( '?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
| 84 | - array( ' AS ?abc', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
| 85 | - array( 'COUNT (?x) AS ?count', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment' ), |
|
| 86 | - array( '', ExpressionValidator::VALIDATE_ALL, 'or a' ), |
|
| 87 | - array( ' ', ExpressionValidator::VALIDATE_ALL, 'or a' ), |
|
| 65 | + array('nyan', ExpressionValidator::VALIDATE_VARIABLE, 'variable'), |
|
| 66 | + array('<http://www.example.com/test#>', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 67 | + array('http://www.example.com/test#> foo bar', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 68 | + array('<abc><>', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 69 | + array('http://www.example.com/te st#', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 70 | + array('http://www.example.com/test#ab\cd', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 71 | + array('http://www.example.com/test#ab|cd', ExpressionValidator::VALIDATE_IRI, 'IRI'), |
|
| 72 | + array('ab:cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
| 73 | + array('ab/cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
| 74 | + array('ab cd', ExpressionValidator::VALIDATE_PREFIX, 'prefix'), |
|
| 75 | + array('foobar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI'), |
|
| 76 | + array('test:Foo:Bar', ExpressionValidator::VALIDATE_PREFIXED_IRI, 'prefixed IRI'), |
|
| 77 | + array('"abc', ExpressionValidator::VALIDATE_NATIVE, 'native'), |
|
| 78 | + array('abc123', ExpressionValidator::VALIDATE_NATIVE, 'native'), |
|
| 79 | + array('foobar (?x > ?y)', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
| 80 | + array('(RAND ())', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
| 81 | + array('COUNT (?x) + 5) * ?a', ExpressionValidator::VALIDATE_FUNCTION, 'function'), |
|
| 82 | + array('CONTAINS (?x, "test"^^xsd:string)', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
| 83 | + array('?x + ?y > ?z', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
| 84 | + array(' AS ?abc', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
| 85 | + array('COUNT (?x) AS ?count', ExpressionValidator::VALIDATE_FUNCTION_AS, 'function with variable assignment'), |
|
| 86 | + array('', ExpressionValidator::VALIDATE_ALL, 'or a'), |
|
| 87 | + array(' ', ExpressionValidator::VALIDATE_ALL, 'or a'), |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | public function testValidate_invalidArgument() { |
| 92 | 92 | $expressionValidator = new ExpressionValidator(); |
| 93 | - $this->setExpectedException( 'InvalidArgumentException' ); |
|
| 93 | + $this->setExpectedException('InvalidArgumentException'); |
|
| 94 | 94 | |
| 95 | - $expressionValidator->validate( null, ExpressionValidator::VALIDATE_ALL ); |
|
| 95 | + $expressionValidator->validate(null, ExpressionValidator::VALIDATE_ALL); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | } |