1 | <?php |
||
16 | class LocationParserTest extends \ValueParsers\Test\StringValueParserTest { |
||
17 | |||
18 | /** |
||
19 | * @see ValueParserTestBase::validInputProvider |
||
20 | * |
||
21 | * @since 3.0 |
||
22 | * |
||
23 | * @return array |
||
24 | */ |
||
25 | public function validInputProvider() { |
||
26 | $argLists = []; |
||
27 | |||
28 | $valid = [ |
||
29 | '55.7557860 N, 37.6176330 W' => [ 55.7557860, -37.6176330 ], |
||
30 | '55.7557860, -37.6176330' => [ 55.7557860, -37.6176330 ], |
||
31 | '55 S, 37.6176330 W' => [ -55, -37.6176330 ], |
||
32 | '-55, -37.6176330' => [ -55, -37.6176330 ], |
||
33 | '5.5S,37W ' => [ -5.5, -37 ], |
||
34 | '-5.5,-37 ' => [ -5.5, -37 ], |
||
35 | '4,2' => [ 4, 2 ], |
||
36 | ]; |
||
37 | |||
38 | foreach ( $valid as $value => $expected ) { |
||
39 | $expected = new Location( new LatLongValue( $expected[0], $expected[1] ) ); |
||
40 | $argLists[] = [ (string)$value, $expected ]; |
||
41 | } |
||
42 | |||
43 | $location = new Location( new LatLongValue( 4, 2 ) ); |
||
44 | $location->setTitle( 'Title' ); |
||
45 | $location->setText( 'some description' ); |
||
46 | $argLists[] = [ '4,2~Title~some description', $location ]; |
||
47 | |||
48 | return $argLists; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @see ValueParserTestBase::requireDataValue |
||
53 | * |
||
54 | * @since 3.0 |
||
55 | * |
||
56 | * @return boolean |
||
57 | */ |
||
58 | protected function requireDataValue() { |
||
61 | |||
62 | /** |
||
63 | * @dataProvider titleProvider |
||
64 | */ |
||
65 | public function testGivenTitleThatIsNotLink_titleIsSetAndLinkIsNot( $title ) { |
||
66 | $parser = new LocationParser(); |
||
67 | $location = $parser->parse( '4,2~' . $title ); |
||
68 | |||
69 | $this->assertTitleAndLinkAre( $location, $title, '' ); |
||
70 | } |
||
71 | |||
72 | public function titleProvider() { |
||
73 | return [ |
||
74 | [ '' ], |
||
75 | [ 'Title' ], |
||
76 | [ 'Some title' ], |
||
77 | [ 'link' ], |
||
78 | [ 'links:foo' ], |
||
79 | ]; |
||
80 | } |
||
81 | |||
82 | protected function assertTitleAndLinkAre( Location $location, $title, $link ) { |
||
83 | $this->assertHasJsonKeyWithValue( $location, 'title', $title ); |
||
84 | $this->assertHasJsonKeyWithValue( $location, 'link', $link ); |
||
85 | } |
||
86 | |||
87 | protected function assertHasJsonKeyWithValue( Location $polygon, $key, $value ) { |
||
88 | $json = $polygon->getJSONObject(); |
||
89 | |||
90 | $this->assertArrayHasKey( $key, $json ); |
||
91 | $this->assertEquals( |
||
92 | $value, |
||
93 | $json[$key] |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @dataProvider linkProvider |
||
99 | */ |
||
100 | public function testGivenTitleThatIsLink_linkIsSetAndTitleIsNot( $link ) { |
||
101 | $parser = new LocationParser(); |
||
102 | $location = $parser->parse( '4,2~link:' . $link ); |
||
103 | |||
104 | $this->assertTitleAndLinkAre( $location, '', $link ); |
||
105 | } |
||
106 | |||
107 | public function linkProvider() { |
||
108 | return [ |
||
109 | [ 'https://semantic-mediawiki.org' ], |
||
110 | [ 'http://www.semantic-mediawiki.org' ], |
||
111 | [ 'irc://freenode.net' ], |
||
112 | ]; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @dataProvider titleLinkProvider |
||
117 | */ |
||
118 | // public function testGivenPageTitleAsLink_pageTitleIsTurnedIntoUrl( $link ) { |
||
119 | // $parser = new LocationParser(); |
||
120 | // $location = $parser->parse( '4,2~link:' . $link ); |
||
121 | // |
||
122 | // $linkUrl = Title::newFromText( $link )->getFullURL(); |
||
123 | // $this->assertTitleAndLinkAre( $location, '', $linkUrl ); |
||
124 | // } |
||
125 | // |
||
126 | // public function titleLinkProvider() { |
||
127 | // return array( |
||
128 | // array( 'Foo' ), |
||
129 | // array( 'Some_Page' ), |
||
130 | // ); |
||
131 | // } |
||
132 | |||
133 | protected function getInstance() { |
||
136 | |||
137 | public function testGivenAddressAndNoTitle_addressIsSetAsTitle() { |
||
138 | $location = ( new LocationParser() )->parse( 'Tempelhofer Ufer 42' ); |
||
139 | |||
140 | $this->assertSame( 'Tempelhofer Ufer 42', $location->getTitle ); |
||
141 | } |
||
142 | |||
143 | public function testGivenAddressAndTitle_addressIsNotUsedAsTitle() { |
||
144 | $location = ( new LocationParser() )->parse( 'Tempelhofer Ufer 42~Great title of doom' ); |
||
148 | |||
149 | public function testGivenCoordinatesAndNoTitle_noTitleIsSet() { |
||
154 | |||
155 | } |
||
156 |