From 437ab4aecd52e33a38bcf865b6ce1fa38493d0e7 Mon Sep 17 00:00:00 2001 From: Eric GELOEN Date: Thu, 3 Jul 2014 22:48:18 +0200 Subject: [PATCH] [2.0] Refactor core --- CONTRIBUTING.md | 70 + README.md | 81 +- composer.json | 24 +- doc/controls/index.md | 19 + doc/controls/map_type.md | 60 + doc/{usage => }/controls/overview.md | 19 +- doc/controls/pan.md | 39 + doc/controls/rotate.md | 39 + doc/controls/scale.md | 46 + doc/controls/street_view.md | 39 + doc/controls/zoom.md | 50 + doc/events/dom_event.md | 49 + doc/events/event.md | 43 + doc/events/index.md | 14 + doc/helpers/container.md | 78 + doc/helpers/rendering.md | 146 ++ doc/installation.md | 31 +- doc/layers/index.md | 12 + doc/layers/kml_layer.md | 38 + doc/map.md | 154 ++ doc/{usage => }/overlays/circle.md | 44 +- doc/overlays/encoded_polyline.md | 38 + doc/overlays/ground_overlay.md | 49 + doc/overlays/icon.md | 58 + doc/overlays/index.md | 21 + doc/overlays/info_window.md | 103 + doc/overlays/marker.md | 90 + doc/overlays/marker_cluster.md | 50 + doc/{usage => }/overlays/marker_shape.md | 45 +- doc/overlays/polygon.md | 45 + doc/overlays/polyline.md | 45 + doc/overlays/rectangle.md | 44 + doc/places/autocomplete.md | 93 + doc/{usage => }/places/index.md | 2 +- doc/services/business_account.md | 60 + .../services/directions/directions.md | 96 +- doc/services/directions/directions_request.md | 100 + .../distance_matrix/distance_matrix.md | 61 +- .../distance_matrix_request.md | 78 + doc/services/geocoding/geocoder.md | 53 + doc/services/geocoding/geocoder_request.md | 45 + .../services/geocoding/ivory_geocoder.md | 24 +- doc/services/index.md | 11 + doc/usage.md | 139 +- doc/usage/controls/index.md | 13 - doc/usage/controls/map_type.md | 143 -- doc/usage/controls/pan.md | 79 - doc/usage/controls/rotate.md | 79 - doc/usage/controls/scale.md | 97 - doc/usage/controls/street_view.md | 79 - doc/usage/controls/zoom.md | 106 - doc/usage/events.md | 76 - doc/usage/helper/container.md | 78 - doc/usage/helper/extension.md | 70 - doc/usage/layers/index.md | 7 - doc/usage/layers/kml_layer.md | 33 - doc/usage/map.md | 184 -- doc/usage/overlays/encoded_polyline.md | 36 - doc/usage/overlays/ground_overlay.md | 31 - doc/usage/overlays/index.md | 15 - doc/usage/overlays/info_box.md | 39 - doc/usage/overlays/info_window.md | 82 - doc/usage/overlays/marker.md | 126 -- doc/usage/overlays/marker_cluster.md | 116 - doc/usage/overlays/marker_image.md | 46 - doc/usage/overlays/polygon.md | 48 - doc/usage/overlays/polyline.md | 48 - doc/usage/overlays/rectangle.md | 36 - doc/usage/places/autocomplete.md | 71 - doc/usage/services/business_account.md | 97 - .../services/directions/directions_request.md | 47 - .../distance_matrix_request.md | 40 - doc/usage/services/geocoding/geocoder.md | 60 - .../services/geocoding/geocoder_request.md | 33 - doc/usage/services/index.md | 8 - .../AbstractJavascriptVariableAsset.php | 91 - src/Assets/AbstractOptionsAsset.php | 119 +- src/Assets/AbstractUninstantiableAsset.php | 30 + src/Assets/AbstractVariableAsset.php | 53 + src/Base/Bound.php | 162 +- src/Base/Coordinate.php | 78 +- src/Base/Point.php | 49 +- src/Base/Size.php | 106 +- src/Controls/ControlPosition.php | 41 +- src/Controls/Controls.php | 251 +++ src/Controls/MapTypeControl.php | 110 +- src/Controls/MapTypeControlStyle.php | 32 +- src/Controls/OverviewMapControl.php | 24 +- src/Controls/PanControl.php | 16 +- src/Controls/RotateControl.php | 16 +- src/Controls/ScaleControl.php | 51 +- src/Controls/ScaleControlStyle.php | 30 +- src/Controls/StreetViewControl.php | 12 +- src/Controls/ZoomControl.php | 23 +- src/Controls/ZoomControlStyle.php | 32 +- src/Events/DomEvent.php | 59 + src/Events/Event.php | 99 +- src/Events/EventManager.php | 148 -- src/Events/Events.php | 421 ++++ src/Events/MouseEvent.php | 33 +- src/Exception/AssetException.php | 62 - src/Exception/BaseException.php | 142 -- src/Exception/ControlException.php | 98 - src/Exception/DirectionsException.php | 328 --- src/Exception/DistanceMatrixException.php | 190 -- src/Exception/EventException.php | 60 - src/Exception/GeocodingException.php | 254 --- src/Exception/HelperException.php | 141 -- src/Exception/LayerException.php | 30 - src/Exception/MapException.php | 249 --- src/Exception/OverlayException.php | 536 ----- src/Exception/PlaceException.php | 148 -- src/Exception/ServiceException.php | 100 - src/Helper/ApiHelper.php | 98 - src/Helper/Base/BoundHelper.php | 96 - src/Helper/Base/SizeHelper.php | 49 - src/Helper/Controls/ControlPositionHelper.php | 53 - src/Helper/Controls/MapTypeControlHelper.php | 159 -- .../Controls/MapTypeControlStyleHelper.php | 44 - src/Helper/Controls/PanControlHelper.php | 77 - src/Helper/Controls/RotateControlHelper.php | 77 - src/Helper/Controls/ScaleControlHelper.php | 112 - .../Controls/ScaleControlStyleHelper.php | 42 - .../Controls/StreetViewControlHelper.php | 80 - src/Helper/Controls/ZoomControlHelper.php | 112 - .../Controls/ZoomControlStyleHelper.php | 44 - src/Helper/Events/EventManagerHelper.php | 96 - .../Extension/AbstractExtensionHelper.php | 46 - src/Helper/Extension/CoreExtensionHelper.php | 152 -- .../Extension/ExtensionHelperInterface.php | 49 - .../Extension/InfoBoxExtensionHelper.php | 112 - src/Helper/Layers/KMLLayerHelper.php | 47 - src/Helper/MapHelper.php | 1937 ----------------- src/Helper/MapTypeIdHelper.php | 45 - src/Helper/Overlays/AnimationHelper.php | 43 - src/Helper/Overlays/EncodedPolylineHelper.php | 87 - src/Helper/Overlays/InfoBoxHelper.php | 36 - src/Helper/Overlays/InfoWindowHelper.php | 94 - .../AbstractMarkerClusterHelper.php | 62 - .../DefaultMarkerClusterHelper.php | 147 -- .../MarkerCluster/JsMarkerClusterHelper.php | 73 - .../MarkerCluster/MarkerClusterHelper.php | 141 -- .../MarkerClusterHelperInterface.php | 53 - src/Helper/Overlays/MarkerHelper.php | 106 - src/Helper/Overlays/MarkerImageHelper.php | 42 - src/Helper/Places/AutocompleteHelper.php | 240 -- src/Helpers/AbstractEvent.php | 55 + src/Helpers/AbstractHelper.php | 55 + .../Aggregators/AbstractAggregator.php | 54 + .../Aggregators/Base/BoundAggregator.php | 139 ++ .../Aggregators/Base/CoordinateAggregator.php | 327 +++ .../Aggregators/Base/PointAggregator.php | 115 + .../Aggregators/Base/SizeAggregator.php | 143 ++ .../Aggregators/Events/DomEventAggregator.php | 36 + .../Events/DomEventOnceAggregator.php | 36 + .../Aggregators/Events/EventAggregator.php | 36 + .../Events/EventOnceAggregator.php | 36 + .../Aggregators/Layers/KmlLayerAggregator.php | 36 + .../Aggregators/Overlays/CircleAggregator.php | 36 + .../Overlays/EncodedPolylineAggregator.php | 36 + .../Overlays/ExtendableAggregator.php | 36 + .../Overlays/GroundOverlayAggregator.php | 36 + .../Aggregators/Overlays/IconAggregator.php | 92 + .../Overlays/InfoWindowAggregator.php | 104 + .../Aggregators/Overlays/MarkerAggregator.php | 36 + .../Overlays/MarkerShapeAggregator.php | 88 + .../Overlays/PolygonAggregator.php | 36 + .../Overlays/PolylineAggregator.php | 36 + .../Overlays/RectangleAggregator.php | 36 + .../Places/AutocompleteBoundAggregator.php | 40 + .../AutocompleteCoordinateAggregator.php | 79 + src/Helpers/ApiEvent.php | 396 ++++ src/Helpers/ApiEvents.php | 29 + src/Helpers/ApiHelper.php | 37 + .../Factories/AbstractHelperFactory.php | 78 + .../IvoryGoogleMapExtension.php | 36 + .../Resources/aggregators.xml | 181 ++ .../Resources/event_dispatcher.xml | 21 + .../DependencyInjection/Resources/helpers.xml | 45 + .../Resources/renderers.xml | 387 ++++ .../Resources/subscribers.xml | 518 +++++ src/Helpers/Factories/HelperFactory.php | 1350 ++++++++++++ .../Factories/HelperFactoryInterface.php | 41 + .../Factories/Symfony2HelperFactory.php | 563 +++++ src/Helpers/MapEvent.php | 45 + src/Helpers/MapEvents.php | 60 + src/Helpers/MapHelper.php | 87 + src/Helpers/PlacesAutocompleteEvent.php | 45 + src/Helpers/PlacesAutocompleteEvents.php | 31 + src/Helpers/PlacesAutocompleteHelper.php | 75 + .../Renderers/AbstractJsonRenderer.php} | 31 +- src/Helpers/Renderers/Base/BoundRenderer.php | 42 + .../Renderers/Base/CoordinateRenderer.php} | 13 +- .../Renderers/Base/PointRenderer.php} | 15 +- src/Helpers/Renderers/Base/SizeRenderer.php | 40 + .../Controls/ControlPositionRenderer.php | 32 + .../Renderers/Controls/ControlsRenderer.php | 267 +++ .../Controls/MapTypeControlRenderer.php | 148 ++ .../Controls/MapTypeControlStyleRenderer.php | 32 + .../Controls/OverviewMapControlRenderer.php} | 10 +- .../Renderers/Controls/PanControlRenderer.php | 77 + .../Controls/RotateControlRenderer.php | 81 + .../Controls/ScaleControlRenderer.php | 81 + .../Controls/ScaleControlStyleRenderer.php | 32 + .../Controls/StreetViewControlRenderer.php | 81 + .../Controls/ZoomControlRenderer.php | 104 + .../Controls/ZoomControlStyleRenderer.php | 32 + .../Renderers/Events/DomEventOnceRenderer.php | 40 + .../Renderers/Events/DomEventRenderer.php | 40 + .../Renderers/Events/EventOnceRenderer.php | 39 + .../Renderers/Events/EventRenderer.php | 39 + .../Renderers/Geometry/EncodingRenderer.php} | 20 +- .../Renderers/Layers/KmlLayerRenderer.php | 42 + src/Helpers/Renderers/LoaderRenderer.php | 64 + src/Helpers/Renderers/MapBoundRenderer.php | 34 + src/Helpers/Renderers/MapCenterRenderer.php | 34 + .../Renderers/MapContainerRenderer.php | 64 + src/Helpers/Renderers/MapRenderer.php | 123 ++ src/Helpers/Renderers/MapTypeIdRenderer.php | 32 + .../Overlays/AbstractInfoWindowRenderer.php | 60 + .../Renderers/Overlays/AnimationRenderer.php | 32 + .../Renderers/Overlays/CircleRenderer.php} | 22 +- .../Overlays/EncodedPolylineRenderer.php | 81 + .../Renderers/Overlays/ExtendableRenderer.php | 36 + .../Overlays/GroundOverlayRenderer.php} | 17 +- .../Renderers/Overlays/IconRenderer.php | 55 + .../Renderers/Overlays/InfoBoxRenderer.php | 38 + .../Overlays/InfoWindowCloseRenderer.php | 34 + .../Overlays/InfoWindowOpenRenderer.php | 44 + .../Renderers/Overlays/InfoWindowRenderer.php | 28 + .../Overlays/MarkerClusterRenderer.php | 52 + .../Renderers/Overlays/MarkerRenderer.php | 105 + .../Overlays/MarkerShapeRenderer.php} | 19 +- .../Renderers/Overlays/PolygonRenderer.php} | 23 +- .../Renderers/Overlays/PolylineRenderer.php} | 21 +- .../Renderers/Overlays/RectangleRenderer.php} | 20 +- .../Places/AutocompleteContainerRenderer.php | 37 + .../Renderers/Places/AutocompleteRenderer.php | 57 + .../AbstractFormatterSubscriber.php | 55 + .../Subscribers/ApiJavascriptSubscriber.php | 124 ++ .../Subscribers/Base/BaseSubscriber.php | 45 + .../Subscribers/Base/BoundSubscriber.php | 118 + .../Subscribers/Base/CoordinateSubscriber.php | 118 + .../Subscribers/Base/PointSubscriber.php | 118 + .../Subscribers/Base/SizeSubscriber.php | 118 + .../Events/DomEventOnceSubscriber.php | 118 + .../Subscribers/Events/DomEventSubscriber.php | 118 + .../Events/EventOnceSubscriber.php | 118 + .../Subscribers/Events/EventSubscriber.php | 118 + .../Subscribers/Events/EventsSubscriber.php | 45 + src/Helpers/Subscribers/Formatter.php | 488 +++++ .../Subscribers/Layers/KmlLayerSubscriber.php | 118 + .../Subscribers/Layers/LayersSubscriber.php | 42 + .../Subscribers/MapBoundSubscriber.php | 82 + .../Subscribers/MapCenterSubscriber.php | 82 + .../Subscribers/MapContainerSubscriber.php | 95 + .../Subscribers/MapFinishSubscriber.php | 46 + src/Helpers/Subscribers/MapHtmlSubscriber.php | 55 + src/Helpers/Subscribers/MapInitSubscriber.php | 43 + .../Subscribers/MapJavascriptSubscriber.php | 76 + .../Subscribers/MapStylesheetSubscriber.php | 49 + src/Helpers/Subscribers/MapSubscriber.php | 86 + .../Subscribers/Overlays/CircleSubscriber.php | 118 + .../Overlays/EncodedPolylineSubscriber.php | 139 ++ .../Overlays/ExtendableSubscriber.php | 115 + .../Overlays/GroundOverlaySubscriber.php | 118 + .../Subscribers/Overlays/IconSubscriber.php | 118 + .../Overlays/InfoWindowCloseSubscriber.php | 126 ++ .../Overlays/InfoWindowOpenSubscriber.php | 117 + .../Overlays/InfoWindowSubscriber.php | 176 ++ .../Overlays/MarkerClusterSubscriber.php | 120 + .../Overlays/MarkerOpenEventSubscriber.php | 144 ++ .../Overlays/MarkerShapeSubscriber.php | 118 + .../Subscribers/Overlays/MarkerSubscriber.php | 122 ++ .../Overlays/OverlaysSubscriber.php | 53 + .../Overlays/PolygonSubscriber.php | 118 + .../Overlays/PolylineSubscriber.php | 118 + .../Overlays/RectangleSubscriber.php | 118 + .../Places/AutocompleteBaseSubscriber.php | 50 + .../Places/AutocompleteBoundSubscriber.php | 118 + .../AutocompleteContainerSubscriber.php | 87 + .../AutocompleteCoordinateSubscriber.php | 118 + .../Places/AutocompleteHtmlSubscriber.php | 58 + .../Places/AutocompleteInitSubscriber.php | 45 + .../AutocompleteJavascriptSubscriber.php | 79 + .../Places/AutocompleteSubscriber.php | 88 + src/Layers/KMLLayer.php | 68 - src/Layers/KmlLayer.php | 58 + src/Layers/Layers.php | 120 + src/Map.php | 1093 ++-------- src/MapTypeId.php | 33 +- src/Overlays/Animation.php | 31 +- src/Overlays/Circle.php | 75 +- src/Overlays/EncodedPolyline.php | 38 +- src/Overlays/ExtendableInterface.php | 12 +- src/Overlays/GroundOverlay.php | 97 +- src/Overlays/Icon.php | 192 ++ src/Overlays/InfoWindow.php | 273 +-- .../InfoWindowType.php} | 10 +- src/Overlays/Marker.php | 243 +-- src/Overlays/MarkerCluster.php | 120 +- src/Overlays/MarkerClusterType.php | 25 + src/Overlays/MarkerImage.php | 309 --- src/Overlays/MarkerShape.php | 145 +- src/Overlays/MarkerShapeType.php | 26 + src/Overlays/Overlays.php | 1027 +++++++++ src/Overlays/Polygon.php | 112 +- src/Overlays/Polyline.php | 112 +- src/Overlays/Rectangle.php | 77 +- src/Places/Autocomplete.php | 486 ++--- .../AutocompleteComponentRestriction.php | 28 +- src/Places/AutocompleteType.php | 32 +- src/Services/AbstractService.php | 99 +- src/Services/Base/Distance.php | 40 +- src/Services/Base/Duration.php | 40 +- src/Services/Base/TravelMode.php | 33 +- src/Services/Base/UnitSystem.php | 31 +- src/Services/BusinessAccount.php | 18 +- src/Services/Directions/Directions.php | 392 ++-- src/Services/Directions/DirectionsLeg.php | 228 +- src/Services/Directions/DirectionsRequest.php | 410 ++-- .../Directions/DirectionsResponse.php | 101 +- src/Services/Directions/DirectionsRoute.php | 302 ++- src/Services/Directions/DirectionsStatus.php | 37 +- src/Services/Directions/DirectionsStep.php | 70 +- .../Directions/DirectionsWaypoint.php | 89 +- .../DistanceMatrix/DistanceMatrix.php | 209 +- .../DistanceMatrixElementStatus.php | 33 +- .../DistanceMatrix/DistanceMatrixRequest.php | 352 +-- .../DistanceMatrix/DistanceMatrixResponse.php | 272 ++- .../DistanceMatrixResponseElement.php | 80 +- .../DistanceMatrixResponseRow.php | 87 +- .../DistanceMatrix/DistanceMatrixStatus.php | 37 +- src/Services/Geocoding/Geocoder.php | 4 +- .../Geocoding/GeocoderAddressComponent.php | 181 ++ .../{Result => }/GeocoderGeometry.php | 67 +- .../Geocoding/GeocoderLocationType.php | 28 + src/Services/Geocoding/GeocoderProvider.php | 434 +--- src/Services/Geocoding/GeocoderRequest.php | 236 +- src/Services/Geocoding/GeocoderResponse.php | 155 ++ src/Services/Geocoding/GeocoderResult.php | 323 +++ src/Services/Geocoding/GeocoderStatus.php | 31 + .../Result/GeocoderAddressComponent.php | 138 -- .../Geocoding/Result/GeocoderLocationType.php | 51 - .../Geocoding/Result/GeocoderResponse.php | 100 - .../Geocoding/Result/GeocoderResult.php | 222 -- .../Geocoding/Result/GeocoderStatus.php | 57 - src/Services/{Utils => }/XmlParser.php | 48 +- tests/AbstractTestCase.php | 452 ++++ tests/Assets/AbstractTestCase.php | 32 + tests/Assets/JavascriptVariableAssetTest.php | 86 - tests/Assets/OptionsAssetTest.php | 171 +- tests/Assets/UninstantiableAssetTest.php | 29 + tests/Assets/VariableAssetTest.php | 70 + tests/Base/BoundTest.php | 138 +- tests/Base/CoordinateTest.php | 127 +- tests/Base/PointTest.php | 56 +- tests/Base/SizeTest.php | 166 +- tests/Controls/AbstractTestCase.php | 92 + tests/Controls/ControlPositionTest.php | 35 +- tests/Controls/ControlsTest.php | 311 +++ tests/Controls/MapTypeControlStyleTest.php | 17 +- tests/Controls/MapTypeControlTest.php | 126 +- tests/Controls/OverviewMapControlTest.php | 12 +- tests/Controls/PanControlTest.php | 15 +- tests/Controls/RotateControlTest.php | 15 +- tests/Controls/ScaleControlStyleTest.php | 11 +- tests/Controls/ScaleControlTest.php | 25 +- tests/Controls/StreetViewControlTest.php | 15 +- tests/Controls/ZoomControlStyleTest.php | 17 +- tests/Controls/ZoomControlTest.php | 30 +- tests/Events/AbstractTestCase.php | 42 + tests/Events/DomEventTest.php | 90 + tests/Events/EventManagerTest.php | 97 - tests/Events/EventTest.php | 98 +- tests/Events/EventsTest.php | 461 ++++ tests/Events/MouseEventTest.php | 23 +- tests/Helper/AbstractHelperTest.php | 58 - tests/Helper/ApiHelperTest.php | 135 -- tests/Helper/Base/BoundHelperTest.php | 146 -- tests/Helper/Base/CoordinateHelperTest.php | 53 - tests/Helper/Base/PointHelperTest.php | 42 - tests/Helper/Base/SizeHelperTest.php | 50 - .../Controls/ControlPositionHelperTest.php | 115 - .../Controls/MapTypeControlHelperTest.php | 97 - .../MapTypeControlStyleHelperTest.php | 69 - .../Controls/OverviewMapControlHelperTest.php | 49 - .../Helper/Controls/PanControlHelperTest.php | 70 - .../Controls/RotateControlHelperTest.php | 70 - .../Controls/ScaleControlHelperTest.php | 78 - .../Controls/ScaleControlStyleHelperTest.php | 59 - .../Controls/StreetViewControlHelperTest.php | 70 - .../Helper/Controls/ZoomControlHelperTest.php | 78 - .../Controls/ZoomControlStyleHelperTest.php | 69 - .../Helper/Events/EventManagerHelperTest.php | 86 - .../Extension/CoreExtensionHelperTest.php | 149 -- .../Extension/InfoBoxExtensionHelperTest.php | 134 -- tests/Helper/Geometry/EncodingHelperTest.php | 66 - tests/Helper/Layers/KMLLayerHelperTest.php | 79 - tests/Helper/MapHelperTest.php | 1280 ----------- tests/Helper/MapTypeIdHelperTest.php | 59 - tests/Helper/Overlays/AnimationHelperTest.php | 57 - tests/Helper/Overlays/CircleHelperTest.php | 70 - .../Overlays/EncodedPolylineHelperTest.php | 98 - .../Overlays/GroundOverlayHelperTest.php | 90 - tests/Helper/Overlays/InfoBoxHelperTest.php | 68 - .../Helper/Overlays/InfoWindowHelperTest.php | 134 -- .../AbstractMarkerClusterHelperTest.php | 55 - .../DefaultMarkerClusterHelperTest.php | 112 - .../JsMarkerClusterHelperTest.php | 119 - .../MarkerCluster/MarkerClusterHelperTest.php | 140 -- tests/Helper/Overlays/MarkerHelperTest.php | 168 -- .../Helper/Overlays/MarkerImageHelperTest.php | 68 - .../Helper/Overlays/MarkerShapeHelperTest.php | 75 - tests/Helper/Overlays/PolygonHelperTest.php | 102 - tests/Helper/Overlays/PolylineHelperTest.php | 102 - tests/Helper/Overlays/RectangleHelperTest.php | 90 - .../Helper/Places/AutocompleteHelperTest.php | 290 --- tests/Helpers/AbstractHelperTest.php | 39 + tests/Helpers/AbstractTestCase.php | 1060 +++++++++ .../Aggregators/Base/BoundAggregatorTest.php | 306 +++ .../Base/CoordinateAggregatorTest.php | 788 +++++++ .../Aggregators/Base/PointAggregatorTest.php | 221 ++ .../Aggregators/Base/SizeAggregatorTest.php | 291 +++ .../Events/DomEventAggregatorTest.php | 108 + .../Events/DomEventOnceAggregatorTest.php | 111 + .../Events/EventAggregatorTest.php | 108 + .../Events/EventOnceAggregatorTest.php | 111 + .../Layers/KmlLayerAggregatorTest.php | 108 + .../Overlays/CircleAggregatorTest.php | 108 + .../EncodedPolylineAggregatorTest.php | 111 + .../Overlays/ExtendableAggregatorTest.php | 108 + .../Overlays/GroundOverlayAggregatorTest.php | 111 + .../Overlays/IconAggregatorTest.php | 160 ++ .../Overlays/InfoWindowAggregatorTest.php | 241 ++ .../Overlays/MarkerAggregatorTest.php | 108 + .../Overlays/MarkerShapeAggregatorTest.php | 148 ++ .../Overlays/PolygonAggregatorTest.php | 108 + .../Overlays/PolylineAggregatorTest.php | 108 + .../Overlays/RectangleAggregatorTest.php | 108 + .../AutocompleteBoundAggregatorTest.php | 78 + .../AutocompleteCoordinateAggregatorTest.php | 144 ++ tests/Helpers/ApiEventTest.php | 390 ++++ tests/Helpers/ApiEventsTest.php | 50 + tests/Helpers/ApiHelperTest.php | 85 + tests/Helpers/EventTest.php | 65 + .../Factories/AbstractHelperFactoryTest.php | 652 ++++++ tests/Helpers/Factories/HelperFactoryTest.php | 1529 +++++++++++++ .../Factories/Symfony2HelperFactoryTest.php | 358 +++ tests/Helpers/HelperTest.php | 57 + tests/Helpers/MapEventTest.php | 55 + tests/Helpers/MapEventsTest.php | 94 + tests/Helpers/MapHelperTest.php | 132 ++ tests/Helpers/PlacesAutocompleteEventTest.php | 54 + .../Helpers/PlacesAutocompleteEventsTest.php | 63 + .../Helpers/PlacesAutocompleteHelperTest.php | 128 ++ tests/Helpers/Renderers/AbstractTestCase.php | 196 ++ .../Renderers/Base/BoundRendererTest.php | 119 + .../Renderers/Base/CoordinateRendererTest.php | 95 + .../Renderers/Base/PointRendererTest.php | 70 + .../Renderers/Base/SizeRendererTest.php | 120 + .../Controls/ControlPositionRendererTest.php | 74 + .../Controls/ControlsRendererTest.php | 512 +++++ .../Controls/MapTypeControlRendererTest.php | 171 ++ .../MapTypeControlStyleRendererTest.php | 65 + .../OverviewMapControlRendererTest.php | 80 + .../Controls/PanControlRendererTest.php | 88 + .../Controls/RotateControlRendererTest.php | 88 + .../Controls/ScaleControlRendererTest.php | 89 + .../ScaleControlStyleRendererTest.php | 51 + .../StreetViewControlRendererTest.php | 88 + .../Controls/ZoomControlRendererTest.php | 106 + .../Controls/ZoomControlStyleRendererTest.php | 65 + .../Events/DomEventOnceRendererTest.php | 104 + .../Renderers/Events/DomEventRendererTest.php | 104 + .../Events/EventOnceRendererTest.php | 75 + .../Renderers/Events/EventRendererTest.php | 75 + .../Geometry/EncodingRendererTest.php | 50 + tests/Helpers/Renderers/JsonRendererTest.php | 60 + .../Renderers/Layers/KmlLayerRendererTest.php | 88 + .../Helpers/Renderers/LoaderRendererTest.php | 85 + .../Renderers/MapBoundRendererTest.php | 82 + .../Renderers/MapCenterRendererTest.php | 82 + .../Renderers/MapContainerRendererTest.php | 87 + tests/Helpers/Renderers/MapRendererTest.php | 163 ++ .../Renderers/MapTypeIdRendererTest.php | 65 + .../Overlays/AnimationRendererTest.php | 64 + .../Renderers/Overlays/CircleRendererTest.php | 107 + .../Overlays/EncodedPolylineRendererTest.php | 112 + .../Overlays/ExtendableRendererTest.php | 54 + .../Overlays/GroundOverlayRendererTest.php | 107 + .../Renderers/Overlays/IconRendererTest.php | 192 ++ .../Overlays/InfoBoxRendererTest.php | 173 ++ .../Overlays/InfoWindowCloseRendererTest.php | 64 + .../Overlays/InfoWindowOpenRendererTest.php | 109 + .../Overlays/InfoWindowRendererTest.php | 165 ++ .../Overlays/MarkerClusterRendererTest.php | 94 + .../Renderers/Overlays/MarkerRendererTest.php | 271 +++ .../Overlays/MarkerShapeRendererTest.php | 75 + .../Overlays/PolygonRendererTest.php | 137 ++ .../Overlays/PolylineRendererTest.php | 137 ++ .../Overlays/RectangleRendererTest.php | 123 ++ .../AutocompleteContainerRendererTest.php | 55 + .../Places/AutocompleteRendererTest.php | 165 ++ .../AbstractFormatterSubscriberTest.php | 39 + .../Helpers/Subscribers/AbstractTestCase.php | 540 +++++ .../ApiJavascriptSubscriberTest.php | 220 ++ .../Subscribers/Base/BaseSubscriberTest.php | 72 + .../Subscribers/Base/BoundSubscriberTest.php | 141 ++ .../Base/CoordinateSubscriberTest.php | 145 ++ .../Subscribers/Base/PointSubscriberTest.php | 141 ++ .../Subscribers/Base/SizeSubscriberTest.php | 139 ++ .../Events/DomEventOnceSubscriberTest.php | 145 ++ .../Events/DomEventSubscriberTest.php | 141 ++ .../Events/EventOnceSubscriberTest.php | 143 ++ .../Events/EventSubscriberTest.php | 141 ++ .../Events/EventsSubscriberTest.php | 72 + .../Subscribers/FormatterSubscriberTest.php | 64 + tests/Helpers/Subscribers/FormatterTest.php | 994 +++++++++ .../Layers/KmlLayerSubscriberTest.php | 142 ++ .../Layers/LayersSubscriberTest.php | 67 + .../Subscribers/MapBoundSubscriberTest.php | 173 ++ .../Subscribers/MapCenterSubscriberTest.php | 173 ++ .../MapContainerSubscriberTest.php | 114 + .../Subscribers/MapFinishSubscriberTest.php | 72 + .../Subscribers/MapHtmlSubscriberTest.php | 159 ++ .../Subscribers/MapInitSubscriberTest.php | 69 + .../MapJavascriptSubscriberTest.php | 190 ++ .../MapStylesheetSubscriberTest.php | 105 + .../Helpers/Subscribers/MapSubscriberTest.php | 121 + .../Overlays/CircleSubscriberTest.php | 142 ++ .../EncodedPolylineSubscriberTest.php | 184 ++ .../Overlays/ExtendableSubscriberTest.php | 167 ++ .../Overlays/GroundOverlaySubscriberTest.php | 142 ++ .../Overlays/IconSubscriberTest.php | 139 ++ .../Overlays/InfoWIndowSubscriberTest.php | 232 ++ .../InfoWindowCloseSubscriberTest.php | 188 ++ .../Overlays/InfoWindowOpenSubscriberTest.php | 168 ++ .../Overlays/MarkerClusterSubscriberTest.php | 232 ++ .../MarkerOpenEventSubscriberTest.php | 257 +++ .../Overlays/MarkerShapeSubscriberTest.php | 143 ++ .../Overlays/MarkerSubscriberTest.php | 213 ++ .../Overlays/OverlaysSubscriberTest.php | 79 + .../Overlays/PolygonSubscriberTest.php | 142 ++ .../Overlays/PolylineSubscriberTest.php | 142 ++ .../Overlays/RectangleSubscriberTest.php | 142 ++ .../Places/AutocompleteBaseSubscriberTest.php | 70 + .../AutocompleteBoundSubscriberTest.php | 141 ++ .../AutocompleteContainerSubscriberTest.php | 120 + .../AutocompleteCoordinateSubscriberTest.php | 145 ++ .../Places/AutocompleteHtmlSubscriberTest.php | 140 ++ .../Places/AutocompleteInitSubscriberTest.php | 70 + .../AutocompleteJavascriptSubscriberTest.php | 150 ++ .../Places/AutocompleteSubscriberTest.php | 124 ++ tests/Layers/AbstractTestCase.php | 32 + tests/Layers/KMLLayerTest.php | 69 - tests/Layers/KmlLayerTest.php | 64 + tests/Layers/LayersTest.php | 149 ++ tests/MapTest.php | 919 ++------ tests/MapTypeIdTest.php | 21 +- tests/Overlays/AbstractExtendableTest.php | 40 + tests/Overlays/AbstractTestCase.php | 152 ++ tests/Overlays/AnimationTest.php | 15 +- tests/Overlays/CircleTest.php | 75 +- tests/Overlays/EncodedPolylineTest.php | 37 +- tests/Overlays/GroundOverlayTest.php | 118 +- tests/Overlays/IconTest.php | 215 ++ tests/Overlays/InfoWindowTest.php | 206 +- tests/Overlays/InfoWindowTypeTest.php | 33 + tests/Overlays/MarkerClusterTest.php | 124 +- tests/Overlays/MarkerClusterTypeTest.php | 33 + tests/Overlays/MarkerImageTest.php | 249 --- tests/Overlays/MarkerShapeTest.php | 143 +- tests/Overlays/MarkerShapeTypeTest.php | 34 + tests/Overlays/MarkerTest.php | 307 ++- tests/Overlays/OverlaysTest.php | 1546 +++++++++++++ tests/Overlays/PolygonTest.php | 139 +- tests/Overlays/PolylineTest.php | 139 +- tests/Overlays/RectangleTest.php | 108 +- .../AutocompleteComponentRestrictionTest.php | 15 +- tests/Places/AutocompleteTest.php | 433 ++-- tests/Places/AutocompleteTypeTest.php | 23 +- tests/Services/AbstractServiceTest.php | 195 -- tests/Services/AbstractTestCase.php | 104 + tests/Services/Base/DistanceTest.php | 37 +- tests/Services/Base/DurationTest.php | 37 +- tests/Services/Base/TravelModeTest.php | 23 +- tests/Services/Base/UnitSystemTest.php | 19 +- tests/Services/BusinessAccountTest.php | 73 +- .../Services/Directions/AbstractTestCase.php | 110 + .../Services/Directions/DirectionsLegTest.php | 292 ++- .../Directions/DirectionsRequestTest.php | 430 ++-- .../Directions/DirectionsResponseTest.php | 124 +- .../Directions/DirectionsRouteTest.php | 369 +++- .../Directions/DirectionsStatusTest.php | 27 +- .../Directions/DirectionsStepTest.php | 95 +- tests/Services/Directions/DirectionsTest.php | 291 +-- .../Directions/DirectionsWaypointTest.php | 80 +- .../DistanceMatrix/AbstractTestCase.php | 66 + .../DistanceMatrixElementStatusTest.php | 17 +- .../DistanceMatrixRequestTest.php | 402 ++-- .../DistanceMatrixResponseElementTest.php | 70 +- .../DistanceMatrixResponseRowTest.php | 115 +- .../DistanceMatrixResponseTest.php | 331 ++- .../DistanceMatrixStatusTest.php | 25 +- .../DistanceMatrix/DistanceMatrixTest.php | 234 +- tests/Services/Geocoding/AbstractTestCase.php | 102 + .../GeocoderAddressComponentTest.php | 179 ++ .../Geocoding/GeocoderGeometryTest.php | 108 + .../Geocoding/GeocoderLocationTypeTest.php | 35 + .../Geocoding/GeocoderProviderTest.php | 250 +-- .../Geocoding/GeocoderRequestTest.php | 194 +- .../Geocoding/GeocoderResponseTest.php | 170 ++ .../Services/Geocoding/GeocoderResultTest.php | 316 +++ .../Services/Geocoding/GeocoderStatusTest.php | 38 + tests/Services/Geocoding/GeocoderTest.php | 109 +- .../Result/GeocoderAddressComponentTest.php | 117 - .../Geocoding/Result/GeocoderGeometryTest.php | 114 - .../Result/GeocoderLocationTypeTest.php | 34 - .../Geocoding/Result/GeocoderResponseTest.php | 93 - .../Geocoding/Result/GeocoderResultTest.php | 181 -- .../Geocoding/Result/GeocoderStatusTest.php | 37 - tests/Services/ServiceTest.php | 157 ++ tests/Services/Utils/XmlParserTest.php | 62 - tests/Services/XmlParserTest.php | 68 + 625 files changed, 53002 insertions(+), 25153 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 doc/controls/index.md create mode 100644 doc/controls/map_type.md rename doc/{usage => }/controls/overview.md (54%) create mode 100644 doc/controls/pan.md create mode 100644 doc/controls/rotate.md create mode 100644 doc/controls/scale.md create mode 100644 doc/controls/street_view.md create mode 100644 doc/controls/zoom.md create mode 100644 doc/events/dom_event.md create mode 100644 doc/events/event.md create mode 100644 doc/events/index.md create mode 100644 doc/helpers/container.md create mode 100644 doc/helpers/rendering.md create mode 100644 doc/layers/index.md create mode 100644 doc/layers/kml_layer.md create mode 100644 doc/map.md rename doc/{usage => }/overlays/circle.md (56%) create mode 100644 doc/overlays/encoded_polyline.md create mode 100644 doc/overlays/ground_overlay.md create mode 100644 doc/overlays/icon.md create mode 100644 doc/overlays/index.md create mode 100644 doc/overlays/info_window.md create mode 100644 doc/overlays/marker.md create mode 100644 doc/overlays/marker_cluster.md rename doc/{usage => }/overlays/marker_shape.md (56%) create mode 100644 doc/overlays/polygon.md create mode 100644 doc/overlays/polyline.md create mode 100644 doc/overlays/rectangle.md create mode 100644 doc/places/autocomplete.md rename doc/{usage => }/places/index.md (72%) create mode 100644 doc/services/business_account.md rename doc/{usage => }/services/directions/directions.md (67%) create mode 100644 doc/services/directions/directions_request.md rename doc/{usage => }/services/distance_matrix/distance_matrix.md (64%) create mode 100644 doc/services/distance_matrix/distance_matrix_request.md create mode 100644 doc/services/geocoding/geocoder.md create mode 100644 doc/services/geocoding/geocoder_request.md rename doc/{usage => }/services/geocoding/ivory_geocoder.md (83%) create mode 100644 doc/services/index.md delete mode 100644 doc/usage/controls/index.md delete mode 100644 doc/usage/controls/map_type.md delete mode 100644 doc/usage/controls/pan.md delete mode 100644 doc/usage/controls/rotate.md delete mode 100644 doc/usage/controls/scale.md delete mode 100644 doc/usage/controls/street_view.md delete mode 100644 doc/usage/controls/zoom.md delete mode 100644 doc/usage/events.md delete mode 100644 doc/usage/helper/container.md delete mode 100644 doc/usage/helper/extension.md delete mode 100644 doc/usage/layers/index.md delete mode 100644 doc/usage/layers/kml_layer.md delete mode 100644 doc/usage/map.md delete mode 100644 doc/usage/overlays/encoded_polyline.md delete mode 100644 doc/usage/overlays/ground_overlay.md delete mode 100644 doc/usage/overlays/index.md delete mode 100644 doc/usage/overlays/info_box.md delete mode 100644 doc/usage/overlays/info_window.md delete mode 100644 doc/usage/overlays/marker.md delete mode 100644 doc/usage/overlays/marker_cluster.md delete mode 100644 doc/usage/overlays/marker_image.md delete mode 100644 doc/usage/overlays/polygon.md delete mode 100644 doc/usage/overlays/polyline.md delete mode 100644 doc/usage/overlays/rectangle.md delete mode 100644 doc/usage/places/autocomplete.md delete mode 100644 doc/usage/services/business_account.md delete mode 100644 doc/usage/services/directions/directions_request.md delete mode 100644 doc/usage/services/distance_matrix/distance_matrix_request.md delete mode 100644 doc/usage/services/geocoding/geocoder.md delete mode 100644 doc/usage/services/geocoding/geocoder_request.md delete mode 100644 doc/usage/services/index.md delete mode 100644 src/Assets/AbstractJavascriptVariableAsset.php create mode 100644 src/Assets/AbstractUninstantiableAsset.php create mode 100644 src/Assets/AbstractVariableAsset.php create mode 100644 src/Controls/Controls.php create mode 100644 src/Events/DomEvent.php delete mode 100644 src/Events/EventManager.php create mode 100644 src/Events/Events.php delete mode 100644 src/Exception/AssetException.php delete mode 100644 src/Exception/BaseException.php delete mode 100644 src/Exception/ControlException.php delete mode 100644 src/Exception/DirectionsException.php delete mode 100644 src/Exception/DistanceMatrixException.php delete mode 100644 src/Exception/EventException.php delete mode 100644 src/Exception/GeocodingException.php delete mode 100644 src/Exception/HelperException.php delete mode 100644 src/Exception/LayerException.php delete mode 100644 src/Exception/MapException.php delete mode 100644 src/Exception/OverlayException.php delete mode 100644 src/Exception/PlaceException.php delete mode 100644 src/Exception/ServiceException.php delete mode 100644 src/Helper/ApiHelper.php delete mode 100644 src/Helper/Base/BoundHelper.php delete mode 100644 src/Helper/Base/SizeHelper.php delete mode 100644 src/Helper/Controls/ControlPositionHelper.php delete mode 100644 src/Helper/Controls/MapTypeControlHelper.php delete mode 100644 src/Helper/Controls/MapTypeControlStyleHelper.php delete mode 100644 src/Helper/Controls/PanControlHelper.php delete mode 100644 src/Helper/Controls/RotateControlHelper.php delete mode 100644 src/Helper/Controls/ScaleControlHelper.php delete mode 100644 src/Helper/Controls/ScaleControlStyleHelper.php delete mode 100644 src/Helper/Controls/StreetViewControlHelper.php delete mode 100644 src/Helper/Controls/ZoomControlHelper.php delete mode 100644 src/Helper/Controls/ZoomControlStyleHelper.php delete mode 100644 src/Helper/Events/EventManagerHelper.php delete mode 100644 src/Helper/Extension/AbstractExtensionHelper.php delete mode 100644 src/Helper/Extension/CoreExtensionHelper.php delete mode 100644 src/Helper/Extension/ExtensionHelperInterface.php delete mode 100644 src/Helper/Extension/InfoBoxExtensionHelper.php delete mode 100644 src/Helper/Layers/KMLLayerHelper.php delete mode 100644 src/Helper/MapHelper.php delete mode 100644 src/Helper/MapTypeIdHelper.php delete mode 100644 src/Helper/Overlays/AnimationHelper.php delete mode 100644 src/Helper/Overlays/EncodedPolylineHelper.php delete mode 100644 src/Helper/Overlays/InfoBoxHelper.php delete mode 100644 src/Helper/Overlays/InfoWindowHelper.php delete mode 100644 src/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelper.php delete mode 100644 src/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelper.php delete mode 100644 src/Helper/Overlays/MarkerCluster/JsMarkerClusterHelper.php delete mode 100644 src/Helper/Overlays/MarkerCluster/MarkerClusterHelper.php delete mode 100644 src/Helper/Overlays/MarkerCluster/MarkerClusterHelperInterface.php delete mode 100644 src/Helper/Overlays/MarkerHelper.php delete mode 100644 src/Helper/Overlays/MarkerImageHelper.php delete mode 100644 src/Helper/Places/AutocompleteHelper.php create mode 100644 src/Helpers/AbstractEvent.php create mode 100644 src/Helpers/AbstractHelper.php create mode 100644 src/Helpers/Aggregators/AbstractAggregator.php create mode 100644 src/Helpers/Aggregators/Base/BoundAggregator.php create mode 100644 src/Helpers/Aggregators/Base/CoordinateAggregator.php create mode 100644 src/Helpers/Aggregators/Base/PointAggregator.php create mode 100644 src/Helpers/Aggregators/Base/SizeAggregator.php create mode 100644 src/Helpers/Aggregators/Events/DomEventAggregator.php create mode 100644 src/Helpers/Aggregators/Events/DomEventOnceAggregator.php create mode 100644 src/Helpers/Aggregators/Events/EventAggregator.php create mode 100644 src/Helpers/Aggregators/Events/EventOnceAggregator.php create mode 100644 src/Helpers/Aggregators/Layers/KmlLayerAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/CircleAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/EncodedPolylineAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/ExtendableAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/GroundOverlayAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/IconAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/InfoWindowAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/MarkerAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/MarkerShapeAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/PolygonAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/PolylineAggregator.php create mode 100644 src/Helpers/Aggregators/Overlays/RectangleAggregator.php create mode 100644 src/Helpers/Aggregators/Places/AutocompleteBoundAggregator.php create mode 100644 src/Helpers/Aggregators/Places/AutocompleteCoordinateAggregator.php create mode 100644 src/Helpers/ApiEvent.php create mode 100644 src/Helpers/ApiEvents.php create mode 100644 src/Helpers/ApiHelper.php create mode 100644 src/Helpers/Factories/AbstractHelperFactory.php create mode 100644 src/Helpers/Factories/DependencyInjection/IvoryGoogleMapExtension.php create mode 100644 src/Helpers/Factories/DependencyInjection/Resources/aggregators.xml create mode 100644 src/Helpers/Factories/DependencyInjection/Resources/event_dispatcher.xml create mode 100644 src/Helpers/Factories/DependencyInjection/Resources/helpers.xml create mode 100644 src/Helpers/Factories/DependencyInjection/Resources/renderers.xml create mode 100644 src/Helpers/Factories/DependencyInjection/Resources/subscribers.xml create mode 100644 src/Helpers/Factories/HelperFactory.php create mode 100644 src/Helpers/Factories/HelperFactoryInterface.php create mode 100644 src/Helpers/Factories/Symfony2HelperFactory.php create mode 100644 src/Helpers/MapEvent.php create mode 100644 src/Helpers/MapEvents.php create mode 100644 src/Helpers/MapHelper.php create mode 100644 src/Helpers/PlacesAutocompleteEvent.php create mode 100644 src/Helpers/PlacesAutocompleteEvents.php create mode 100644 src/Helpers/PlacesAutocompleteHelper.php rename src/{Helper/AbstractHelper.php => Helpers/Renderers/AbstractJsonRenderer.php} (55%) create mode 100644 src/Helpers/Renderers/Base/BoundRenderer.php rename src/{Helper/Base/CoordinateHelper.php => Helpers/Renderers/Base/CoordinateRenderer.php} (68%) rename src/{Helper/Base/PointHelper.php => Helpers/Renderers/Base/PointRenderer.php} (62%) create mode 100644 src/Helpers/Renderers/Base/SizeRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ControlPositionRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ControlsRenderer.php create mode 100644 src/Helpers/Renderers/Controls/MapTypeControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/MapTypeControlStyleRenderer.php rename src/{Helper/Controls/OverviewMapControlHelper.php => Helpers/Renderers/Controls/OverviewMapControlRenderer.php} (73%) create mode 100644 src/Helpers/Renderers/Controls/PanControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/RotateControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ScaleControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ScaleControlStyleRenderer.php create mode 100644 src/Helpers/Renderers/Controls/StreetViewControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ZoomControlRenderer.php create mode 100644 src/Helpers/Renderers/Controls/ZoomControlStyleRenderer.php create mode 100644 src/Helpers/Renderers/Events/DomEventOnceRenderer.php create mode 100644 src/Helpers/Renderers/Events/DomEventRenderer.php create mode 100644 src/Helpers/Renderers/Events/EventOnceRenderer.php create mode 100644 src/Helpers/Renderers/Events/EventRenderer.php rename src/{Helper/Geometry/EncodingHelper.php => Helpers/Renderers/Geometry/EncodingRenderer.php} (51%) create mode 100644 src/Helpers/Renderers/Layers/KmlLayerRenderer.php create mode 100644 src/Helpers/Renderers/LoaderRenderer.php create mode 100644 src/Helpers/Renderers/MapBoundRenderer.php create mode 100644 src/Helpers/Renderers/MapCenterRenderer.php create mode 100644 src/Helpers/Renderers/MapContainerRenderer.php create mode 100644 src/Helpers/Renderers/MapRenderer.php create mode 100644 src/Helpers/Renderers/MapTypeIdRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/AbstractInfoWindowRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/AnimationRenderer.php rename src/{Helper/Overlays/CircleHelper.php => Helpers/Renderers/Overlays/CircleRenderer.php} (59%) create mode 100644 src/Helpers/Renderers/Overlays/EncodedPolylineRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/ExtendableRenderer.php rename src/{Helper/Overlays/GroundOverlayHelper.php => Helpers/Renderers/Overlays/GroundOverlayRenderer.php} (66%) create mode 100644 src/Helpers/Renderers/Overlays/IconRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/InfoBoxRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/InfoWindowCloseRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/InfoWindowOpenRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/InfoWindowRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/MarkerClusterRenderer.php create mode 100644 src/Helpers/Renderers/Overlays/MarkerRenderer.php rename src/{Helper/Overlays/MarkerShapeHelper.php => Helpers/Renderers/Overlays/MarkerShapeRenderer.php} (55%) rename src/{Helper/Overlays/PolygonHelper.php => Helpers/Renderers/Overlays/PolygonRenderer.php} (57%) rename src/{Helper/Overlays/PolylineHelper.php => Helpers/Renderers/Overlays/PolylineRenderer.php} (62%) rename src/{Helper/Overlays/RectangleHelper.php => Helpers/Renderers/Overlays/RectangleRenderer.php} (58%) create mode 100644 src/Helpers/Renderers/Places/AutocompleteContainerRenderer.php create mode 100644 src/Helpers/Renderers/Places/AutocompleteRenderer.php create mode 100644 src/Helpers/Subscribers/AbstractFormatterSubscriber.php create mode 100644 src/Helpers/Subscribers/ApiJavascriptSubscriber.php create mode 100644 src/Helpers/Subscribers/Base/BaseSubscriber.php create mode 100644 src/Helpers/Subscribers/Base/BoundSubscriber.php create mode 100644 src/Helpers/Subscribers/Base/CoordinateSubscriber.php create mode 100644 src/Helpers/Subscribers/Base/PointSubscriber.php create mode 100644 src/Helpers/Subscribers/Base/SizeSubscriber.php create mode 100644 src/Helpers/Subscribers/Events/DomEventOnceSubscriber.php create mode 100644 src/Helpers/Subscribers/Events/DomEventSubscriber.php create mode 100644 src/Helpers/Subscribers/Events/EventOnceSubscriber.php create mode 100644 src/Helpers/Subscribers/Events/EventSubscriber.php create mode 100644 src/Helpers/Subscribers/Events/EventsSubscriber.php create mode 100644 src/Helpers/Subscribers/Formatter.php create mode 100644 src/Helpers/Subscribers/Layers/KmlLayerSubscriber.php create mode 100644 src/Helpers/Subscribers/Layers/LayersSubscriber.php create mode 100644 src/Helpers/Subscribers/MapBoundSubscriber.php create mode 100644 src/Helpers/Subscribers/MapCenterSubscriber.php create mode 100644 src/Helpers/Subscribers/MapContainerSubscriber.php create mode 100644 src/Helpers/Subscribers/MapFinishSubscriber.php create mode 100644 src/Helpers/Subscribers/MapHtmlSubscriber.php create mode 100644 src/Helpers/Subscribers/MapInitSubscriber.php create mode 100644 src/Helpers/Subscribers/MapJavascriptSubscriber.php create mode 100644 src/Helpers/Subscribers/MapStylesheetSubscriber.php create mode 100644 src/Helpers/Subscribers/MapSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/CircleSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/EncodedPolylineSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/ExtendableSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/GroundOverlaySubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/IconSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/InfoWindowSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/MarkerClusterSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/MarkerShapeSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/MarkerSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/OverlaysSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/PolygonSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/PolylineSubscriber.php create mode 100644 src/Helpers/Subscribers/Overlays/RectangleSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteBaseSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteBoundSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteContainerSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteHtmlSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteInitSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriber.php create mode 100644 src/Helpers/Subscribers/Places/AutocompleteSubscriber.php delete mode 100644 src/Layers/KMLLayer.php create mode 100644 src/Layers/KmlLayer.php create mode 100644 src/Layers/Layers.php create mode 100644 src/Overlays/Icon.php rename src/{Exception/Exception.php => Overlays/InfoWindowType.php} (56%) create mode 100644 src/Overlays/MarkerClusterType.php delete mode 100644 src/Overlays/MarkerImage.php create mode 100644 src/Overlays/MarkerShapeType.php create mode 100644 src/Overlays/Overlays.php create mode 100644 src/Services/Geocoding/GeocoderAddressComponent.php rename src/Services/Geocoding/{Result => }/GeocoderGeometry.php (56%) create mode 100644 src/Services/Geocoding/GeocoderLocationType.php create mode 100644 src/Services/Geocoding/GeocoderResponse.php create mode 100644 src/Services/Geocoding/GeocoderResult.php create mode 100644 src/Services/Geocoding/GeocoderStatus.php delete mode 100644 src/Services/Geocoding/Result/GeocoderAddressComponent.php delete mode 100644 src/Services/Geocoding/Result/GeocoderLocationType.php delete mode 100644 src/Services/Geocoding/Result/GeocoderResponse.php delete mode 100644 src/Services/Geocoding/Result/GeocoderResult.php delete mode 100644 src/Services/Geocoding/Result/GeocoderStatus.php rename src/Services/{Utils => }/XmlParser.php (56%) create mode 100644 tests/AbstractTestCase.php create mode 100644 tests/Assets/AbstractTestCase.php delete mode 100644 tests/Assets/JavascriptVariableAssetTest.php create mode 100644 tests/Assets/UninstantiableAssetTest.php create mode 100644 tests/Assets/VariableAssetTest.php create mode 100644 tests/Controls/AbstractTestCase.php create mode 100644 tests/Controls/ControlsTest.php create mode 100644 tests/Events/AbstractTestCase.php create mode 100644 tests/Events/DomEventTest.php delete mode 100644 tests/Events/EventManagerTest.php create mode 100644 tests/Events/EventsTest.php delete mode 100644 tests/Helper/AbstractHelperTest.php delete mode 100644 tests/Helper/ApiHelperTest.php delete mode 100644 tests/Helper/Base/BoundHelperTest.php delete mode 100644 tests/Helper/Base/CoordinateHelperTest.php delete mode 100644 tests/Helper/Base/PointHelperTest.php delete mode 100644 tests/Helper/Base/SizeHelperTest.php delete mode 100644 tests/Helper/Controls/ControlPositionHelperTest.php delete mode 100644 tests/Helper/Controls/MapTypeControlHelperTest.php delete mode 100644 tests/Helper/Controls/MapTypeControlStyleHelperTest.php delete mode 100644 tests/Helper/Controls/OverviewMapControlHelperTest.php delete mode 100644 tests/Helper/Controls/PanControlHelperTest.php delete mode 100644 tests/Helper/Controls/RotateControlHelperTest.php delete mode 100644 tests/Helper/Controls/ScaleControlHelperTest.php delete mode 100644 tests/Helper/Controls/ScaleControlStyleHelperTest.php delete mode 100644 tests/Helper/Controls/StreetViewControlHelperTest.php delete mode 100644 tests/Helper/Controls/ZoomControlHelperTest.php delete mode 100644 tests/Helper/Controls/ZoomControlStyleHelperTest.php delete mode 100644 tests/Helper/Events/EventManagerHelperTest.php delete mode 100644 tests/Helper/Extension/CoreExtensionHelperTest.php delete mode 100644 tests/Helper/Extension/InfoBoxExtensionHelperTest.php delete mode 100644 tests/Helper/Geometry/EncodingHelperTest.php delete mode 100644 tests/Helper/Layers/KMLLayerHelperTest.php delete mode 100644 tests/Helper/MapHelperTest.php delete mode 100644 tests/Helper/MapTypeIdHelperTest.php delete mode 100644 tests/Helper/Overlays/AnimationHelperTest.php delete mode 100644 tests/Helper/Overlays/CircleHelperTest.php delete mode 100644 tests/Helper/Overlays/EncodedPolylineHelperTest.php delete mode 100644 tests/Helper/Overlays/GroundOverlayHelperTest.php delete mode 100644 tests/Helper/Overlays/InfoBoxHelperTest.php delete mode 100644 tests/Helper/Overlays/InfoWindowHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerCluster/JsMarkerClusterHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerCluster/MarkerClusterHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerImageHelperTest.php delete mode 100644 tests/Helper/Overlays/MarkerShapeHelperTest.php delete mode 100644 tests/Helper/Overlays/PolygonHelperTest.php delete mode 100644 tests/Helper/Overlays/PolylineHelperTest.php delete mode 100644 tests/Helper/Overlays/RectangleHelperTest.php delete mode 100644 tests/Helper/Places/AutocompleteHelperTest.php create mode 100644 tests/Helpers/AbstractHelperTest.php create mode 100644 tests/Helpers/AbstractTestCase.php create mode 100644 tests/Helpers/Aggregators/Base/BoundAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Base/CoordinateAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Base/PointAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Base/SizeAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Events/DomEventAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Events/DomEventOnceAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Events/EventAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Events/EventOnceAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Layers/KmlLayerAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/CircleAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/EncodedPolylineAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/ExtendableAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/GroundOverlayAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/IconAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/InfoWindowAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/MarkerAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/MarkerShapeAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/PolygonAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/PolylineAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Overlays/RectangleAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Places/AutocompleteBoundAggregatorTest.php create mode 100644 tests/Helpers/Aggregators/Places/AutocompleteCoordinateAggregatorTest.php create mode 100644 tests/Helpers/ApiEventTest.php create mode 100644 tests/Helpers/ApiEventsTest.php create mode 100644 tests/Helpers/ApiHelperTest.php create mode 100644 tests/Helpers/EventTest.php create mode 100644 tests/Helpers/Factories/AbstractHelperFactoryTest.php create mode 100644 tests/Helpers/Factories/HelperFactoryTest.php create mode 100644 tests/Helpers/Factories/Symfony2HelperFactoryTest.php create mode 100644 tests/Helpers/HelperTest.php create mode 100644 tests/Helpers/MapEventTest.php create mode 100644 tests/Helpers/MapEventsTest.php create mode 100644 tests/Helpers/MapHelperTest.php create mode 100644 tests/Helpers/PlacesAutocompleteEventTest.php create mode 100644 tests/Helpers/PlacesAutocompleteEventsTest.php create mode 100644 tests/Helpers/PlacesAutocompleteHelperTest.php create mode 100644 tests/Helpers/Renderers/AbstractTestCase.php create mode 100644 tests/Helpers/Renderers/Base/BoundRendererTest.php create mode 100644 tests/Helpers/Renderers/Base/CoordinateRendererTest.php create mode 100644 tests/Helpers/Renderers/Base/PointRendererTest.php create mode 100644 tests/Helpers/Renderers/Base/SizeRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ControlPositionRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ControlsRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/MapTypeControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/MapTypeControlStyleRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/OverviewMapControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/PanControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/RotateControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ScaleControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ScaleControlStyleRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/StreetViewControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ZoomControlRendererTest.php create mode 100644 tests/Helpers/Renderers/Controls/ZoomControlStyleRendererTest.php create mode 100644 tests/Helpers/Renderers/Events/DomEventOnceRendererTest.php create mode 100644 tests/Helpers/Renderers/Events/DomEventRendererTest.php create mode 100644 tests/Helpers/Renderers/Events/EventOnceRendererTest.php create mode 100644 tests/Helpers/Renderers/Events/EventRendererTest.php create mode 100644 tests/Helpers/Renderers/Geometry/EncodingRendererTest.php create mode 100644 tests/Helpers/Renderers/JsonRendererTest.php create mode 100644 tests/Helpers/Renderers/Layers/KmlLayerRendererTest.php create mode 100644 tests/Helpers/Renderers/LoaderRendererTest.php create mode 100644 tests/Helpers/Renderers/MapBoundRendererTest.php create mode 100644 tests/Helpers/Renderers/MapCenterRendererTest.php create mode 100644 tests/Helpers/Renderers/MapContainerRendererTest.php create mode 100644 tests/Helpers/Renderers/MapRendererTest.php create mode 100644 tests/Helpers/Renderers/MapTypeIdRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/AnimationRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/CircleRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/EncodedPolylineRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/ExtendableRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/GroundOverlayRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/IconRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/InfoBoxRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/InfoWindowCloseRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/InfoWindowOpenRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/InfoWindowRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/MarkerClusterRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/MarkerRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/MarkerShapeRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/PolygonRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/PolylineRendererTest.php create mode 100644 tests/Helpers/Renderers/Overlays/RectangleRendererTest.php create mode 100644 tests/Helpers/Renderers/Places/AutocompleteContainerRendererTest.php create mode 100644 tests/Helpers/Renderers/Places/AutocompleteRendererTest.php create mode 100644 tests/Helpers/Subscribers/AbstractFormatterSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/AbstractTestCase.php create mode 100644 tests/Helpers/Subscribers/ApiJavascriptSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Base/BaseSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Base/BoundSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Base/CoordinateSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Base/PointSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Base/SizeSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Events/DomEventOnceSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Events/DomEventSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Events/EventOnceSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Events/EventSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Events/EventsSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/FormatterSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/FormatterTest.php create mode 100644 tests/Helpers/Subscribers/Layers/KmlLayerSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Layers/LayersSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapBoundSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapCenterSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapContainerSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapFinishSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapHtmlSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapInitSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapJavascriptSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapStylesheetSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/MapSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/CircleSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/EncodedPolylineSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/ExtendableSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/GroundOverlaySubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/IconSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/InfoWIndowSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/MarkerClusterSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/MarkerShapeSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/MarkerSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/OverlaysSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/PolygonSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/PolylineSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Overlays/RectangleSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteBaseSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteBoundSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteContainerSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteHtmlSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteInitSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriberTest.php create mode 100644 tests/Helpers/Subscribers/Places/AutocompleteSubscriberTest.php create mode 100644 tests/Layers/AbstractTestCase.php delete mode 100644 tests/Layers/KMLLayerTest.php create mode 100644 tests/Layers/KmlLayerTest.php create mode 100644 tests/Layers/LayersTest.php create mode 100644 tests/Overlays/AbstractExtendableTest.php create mode 100644 tests/Overlays/AbstractTestCase.php create mode 100644 tests/Overlays/IconTest.php create mode 100644 tests/Overlays/InfoWindowTypeTest.php create mode 100644 tests/Overlays/MarkerClusterTypeTest.php delete mode 100644 tests/Overlays/MarkerImageTest.php create mode 100644 tests/Overlays/MarkerShapeTypeTest.php create mode 100644 tests/Overlays/OverlaysTest.php delete mode 100644 tests/Services/AbstractServiceTest.php create mode 100644 tests/Services/AbstractTestCase.php create mode 100644 tests/Services/Directions/AbstractTestCase.php create mode 100644 tests/Services/DistanceMatrix/AbstractTestCase.php create mode 100644 tests/Services/Geocoding/AbstractTestCase.php create mode 100644 tests/Services/Geocoding/GeocoderAddressComponentTest.php create mode 100644 tests/Services/Geocoding/GeocoderGeometryTest.php create mode 100644 tests/Services/Geocoding/GeocoderLocationTypeTest.php create mode 100644 tests/Services/Geocoding/GeocoderResponseTest.php create mode 100644 tests/Services/Geocoding/GeocoderResultTest.php create mode 100644 tests/Services/Geocoding/GeocoderStatusTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderAddressComponentTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderGeometryTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderLocationTypeTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderResponseTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderResultTest.php delete mode 100644 tests/Services/Geocoding/Result/GeocoderStatusTest.php create mode 100644 tests/Services/ServiceTest.php delete mode 100644 tests/Services/Utils/XmlParserTest.php create mode 100644 tests/Services/XmlParserTest.php diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..5fd9f7de --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,70 @@ +# Contributing + +If you're here, you would like to contribute to this repository and you're really welcome! + +## Coding standard + +This repository follows the [PSR-2 standard](http://www.php-fig.org/psr/psr-2/) and so, if you want to contribute, +you must follow these rules. + +## Feature request + +If you think a feature is missing, please report it or even better implement it :). If you report it, describe the more +precisely what you would like to see implemented and we will discuss what is the best approach for it. If you can do +some search before submitting it and link the resources to your description, you're awesome! It will allow me to more +easily understood/implement it. + +## Bug report + +If you think you have detected a bug or a doc issue, please report it or even better fix it :). If you report it, +please be the more precise possible. Here a little list of required informations: + + * Precise description of the bug. + +## Bug fix + +If you're here, you are going to fix a bug and you're the best! To do it, first fork the repository, clone it and +create a new branch with the following commands: + +``` bash +$ git clone git@github.com:your-name/ivory-google-map.git +$ git checkout -b bug-fix-description +``` + +Then, install the dependencies through [Composer](https://getcomposer.org/): + +``` bash +$ composer install +``` + +When you're on the new branch with the dependencies, code as much as you want and when the fix is ready, don't commit +it immediately. Before, you will need to add tests and update the doc. For the tests, everything is tested with +[PHPUnit](http://phpunit.de/) and the doc is in the markdown format under the `doc` directory. + +To run the tests, use the following command: + +``` bash +$ bin/phpunit +``` + +When you have fixed the bug, tested it and documented it, you can commit and push it with the following commands: + +``` bash +$ git commit -m "Bug fix description" +$ git push origin bug-fix-description +``` + +If you have reworked you patch, please squash all your commits in a single one with the following commands (here, we +will assume you would like to squash 3 commits in a single one): + +``` bash +$ git rebase -i HEAD~3 +``` + +If your branch conflicts with the master branch, you will need to rebase and repush it with the following commands: + +``` bash +$ git remote add upstream git@github.com:egeloen/ivory-google-map.git +$ git pull --rebase upstream master +$ git push origin bug-fix-description -f +``` diff --git a/README.md b/README.md index 04b3d85d..14d09846 100644 --- a/README.md +++ b/README.md @@ -2,49 +2,57 @@ [![Build Status](https://secure.travis-ci.org/egeloen/ivory-google-map.png?branch=master)](http://travis-ci.org/egeloen/ivory-google-map) [![Coverage Status](https://coveralls.io/repos/egeloen/ivory-google-map/badge.png?branch=master)](https://coveralls.io/r/egeloen/ivory-google-map?branch=master) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egeloen/ivory-google-map/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egeloen/ivory-google-map/?branch=master) +[![Dependency Status](http://www.versioneye.com/php/egeloen:google-map/badge.svg)](http://www.versioneye.com/php/egeloen:google-map) + +[![Latest Stable Version](https://poser.pugx.org/egeloen/google-map/v/stable.svg)](https://packagist.org/packages/egeloen/google-map) +[![Latest Unstable Version](https://poser.pugx.org/egeloen/google-map/v/unstable.svg)](https://packagist.org/packages/egeloen/google-map) +[![Total Downloads](https://poser.pugx.org/egeloen/google-map/downloads.svg)](https://packagist.org/packages/egeloen/google-map) +[![License](https://poser.pugx.org/egeloen/google-map/license.svg)](https://packagist.org/packages/egeloen/google-map) The Ivory Google Map project provides a Google Map integration for your PHP 5.3+ Project. It allows you to manage map, -controls, overlays, events & services through the Google Map API v3. +controls, overlays, layers, events and services through the Google Map API v3. ## Documentation - 1. [Installation](http://github.com/egeloen/ivory-google-map/blob/master/doc/installation.md) - 2. [Usage](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage.md) - - [Map](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/map.md) - - [Overlays](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/index.md) - - [Marker](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker.md) - - [Info window](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_window.md) - - [Info box](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_box.md) - - [Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polyline.md) - - [Encoded Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md) - - [Polygon](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polygon.md) - - [Rectangle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/rectangle.md) - - [Circle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/circle.md) - - [Ground overlay](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/ground_overlay.md) - - [Marker cluster](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_cluster.md) - - [Controls](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/index.md) - - [Map type](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/map_type.md) - - [Overview](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/overview.md) - - [Pan](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/pan.md) - - [Rotate](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/rotate.md) - - [Scale](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/scale.md) - - [Street view](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/street_view.md) - - [Zoom](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/zoom.md) - - [Layers](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/layers/index.md) - - [KML Layer](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/layers/kml_layer.md) - - [Events](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/events.md) - - [Places](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/places/index.md) - - [Autocomplete](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/places/autocomplete.md) - - [Services](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/index.md) - - [Geocoding API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/geocoding/geocoder.md) - - [Directions API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/directions/directions.md) - - [Distance Matrix API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/distance_matrix/distance_matrix.md) - - [Business Account](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/business_account.md) + - [Installation](/doc/installation.md) + - [Usage](/doc/usage.md) + - [Map](/doc/map.md) + - [Overlays](/doc/overlays/index.md) + - [Marker](/doc/overlays/marker.md) + - [Info window](/doc/overlays/info_window.md) + - [Polyline](/doc/overlays/polyline.md) + - [Encoded Polyline](/doc/overlays/encoded_polyline.md) + - [Polygon](/doc/overlays/polygon.md) + - [Rectangle](/doc/overlays/rectangle.md) + - [Circle](/doc/overlays/circle.md) + - [Ground overlay](/doc/overlays/ground_overlay.md) + - [Marker cluster](/doc/overlays/marker_cluster.md) + - [Controls](/doc/controls/index.md) + - [Map type](/doc/controls/map_type.md) + - [Overview](/doc/controls/overview.md) + - [Pan](/doc/controls/pan.md) + - [Rotate](/doc/controls/rotate.md) + - [Scale](/doc/controls/scale.md) + - [Street view](/doc/controls/street_view.md) + - [Zoom](/doc/controls/zoom.md) + - [Layers](/doc/layers/index.md) + - [Kml layer](/doc/layers/kml_layer.md) + - [Events](/doc/events/index.md) + - [Event](/doc/events/event.md) + - [Dom event](/doc/events/dom_event.md) + - [Places](/doc/places/index.md) + - [Autocomplete](/doc/places/autocomplete.md) + - [Services](/doc/services/index.md) + - [Geocoding API](/doc/services/geocoding/geocoder.md) + - [Directions API](/doc/services/directions/directions.md) + - [Distance Matrix API](/doc/services/distance_matrix/distance_matrix.md) + - [Business Account](/doc/services/business_account.md) ## Testing -The library is fully unit tested by [PHPUnit](http://www.phpunit.de/) with a code coverage close to **100%**. To execute -the test suite, check the travis [configuration](https://github.com/egeloen/ivory-google-map/blob/master/.travis.yml). +The library is fully unit tested by [PHPUnit](http://www.phpunit.de/) with a code coverage close to **100%**. To +execute the test suite, check the travis [configuration](/.travis.yml). ## Contribution @@ -53,5 +61,4 @@ We love contributors! Ivory is an open source project. If you'd like to contribu ## License The Ivory Google Map is under the MIT license. For the full copyright and license information, please read the -[LICENSE](https://github.com/egeloen/ivory-google-map/blob/master/LICENSE) file that was distributed with this source -code. +[LICENSE](/LICENSE) file that was distributed with this source code. diff --git a/composer.json b/composer.json index c8181ac8..fcb13e3a 100644 --- a/composer.json +++ b/composer.json @@ -11,17 +11,29 @@ ], "require": { "php": ">=5.3.0", - "egeloen/json-builder": "~1.0.0" + "egeloen/json-builder": "~1.0.0", + "symfony/event-dispatcher": "~2.0" }, "require-dev": { "phpunit/phpunit": "~4.0", - "widop/http-adapter": "~1.1.0", - "willdurand/geocoder": "~2.0", - "satooshi/php-coveralls": "~0.6" + "phpunit/phpunit-mock-objects": "dev-matcher-verify as 2.3.x-dev", + "egeloen/http-adapter": "~0.1", + "satooshi/php-coveralls": "~0.6", + "symfony/dependency-injection": "~2.0", + "symfony/config": "~2.0", + "willdurand/geocoder": "~2.0" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/egeloen/phpunit-mock-objects.git" + } + ], "suggest": { - "widop/http-adapter": "Allows to use services", - "willdurand/geocoder": "Allows to use geocoding service" + "egeloen/http-adapter": "Allows to use services", + "symfony/dependency-injection": "Allows to use the container helper factory", + "symfony/config": "Allows to use the container helper factory", + "willdurand/geocoder": "Allows to use the geocoding service" }, "autoload": { "psr-4": { "Ivory\\GoogleMap\\": "src/" } diff --git a/doc/controls/index.md b/doc/controls/index.md new file mode 100644 index 00000000..ca215664 --- /dev/null +++ b/doc/controls/index.md @@ -0,0 +1,19 @@ +# Controls + +The maps on Google Maps contain UI elements for allowing user interaction through the map. These elements are known as +`controls` and you can include variations of these controls in your Google Maps API application. Alternatively, you +can do nothing and let the Google Maps API handle all control behavior. + +The controls bag is accessible via: + +``` php +$controls = $map->getControls(); +``` + + 1. [Map type control](/doc/controls/map_type.md) + 2. [Overview](/doc/controls/overview.md) + 3. [Pan](/doc/controls/pan.md) + 4. [Rotate](/doc/controls/rotate.md) + 5. [Scale](/doc/controls/scale.md) + 6. [Street view](/doc/controls/street_view.md) + 7. [Zoom](/doc/controls/zoom.md) diff --git a/doc/controls/map_type.md b/doc/controls/map_type.md new file mode 100644 index 00000000..8d1f670e --- /dev/null +++ b/doc/controls/map_type.md @@ -0,0 +1,60 @@ +# Map type control + +The map type control lets the user toggle between map types (such as ROADMAP and SATELLITE). This control appears by +default in the top right corner of the map. + +## Build your map type control + +``` php +use Ivory\GoogleMap\Controls\MapTypeControl; + +$mapTypeControl = new MapTypeControl(); +``` + +## Configure the map type control + +### Configure the map type control IDs + +``` php +use Ivory\GoogleMap\MapTypeId; + +$mapTypeControl->addMapTypeId(MapTypeId::HYBRID); +$mapTypeControl->addMapTypeId(MapTypeId::ROADMAP); +$mapTypeControl->addMapTypeId(MapTypeId::SATELLITE); +$mapTypeControl->addMapTypeId(MapTypeId::TERRAIN); +``` + +### Configure the map type control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$mapTypeControl->setControlPosition(ControlPosition::TOP_LEFT); +$mapTypeControl->setControlPosition(ControlPosition::TOP_CENTER); +$mapTypeControl->setControlPosition(ControlPosition::TOP_RIGHT); +$mapTypeControl->setControlPosition(ControlPosition::LEFT_TOP); +$mapTypeControl->setControlPosition(ControlPosition::LEFT_CENTER); +$mapTypeControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$mapTypeControl->setControlPosition(ControlPosition::RIGHT_TOP); +$mapTypeControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$mapTypeControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +### Configure the map type control style + +``` php +use Ivory\GoogleMap\Controls\MapTypeControlStyle; + +$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::DEFAULT_); +$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::DROPDOWN_MENU); +$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::HORIZONTAL_BAR); +``` + +## Set your map type control on the map + +``` php +$map->getControls()->setMapTypeControl($mapTypeControl); +``` diff --git a/doc/usage/controls/overview.md b/doc/controls/overview.md similarity index 54% rename from doc/usage/controls/overview.md rename to doc/controls/overview.md index d3c20ee0..e6e6ea3d 100644 --- a/doc/usage/controls/overview.md +++ b/doc/controls/overview.md @@ -9,19 +9,18 @@ This control appears by default in the bottom right corner of the map, and is by use Ivory\GoogleMap\Controls\OverviewMapControl; $overviewMapControl = new OverviewMapControl(); - -// Configure your overview map control -$overviewMapControl->setOpened(false); ``` -## Add your overview map control to the map +## Configure your overview map control -``` php -use Ivory\GoogleMap\Controls\OverviewMapControl; +### Configure the initial open state -$overviewMapControl = new OverviewMapControl(); +``` +$overviewMapControl->setOpened(true); +``` -// Add your overview map control to the map -$map->setOverviewMapControl($overviewMapControl); -$map->setOverviewMapControl(false); +## Set your overview map control on the map + +``` php +$map->getControls()->setOverviewMapControl($overviewMapControl); ``` diff --git a/doc/controls/pan.md b/doc/controls/pan.md new file mode 100644 index 00000000..28f0d58f --- /dev/null +++ b/doc/controls/pan.md @@ -0,0 +1,39 @@ +# Pan control + +The Pan control displays buttons for panning the map. This control appears by default in the top left corner of the +map on non-touch devices. The Pan control also allows you to rotate 45° imagery, if available. + +## Build your pan control + +``` php +use Ivory\GoogleMap\Controls\PanControl; + +$panControl = new PanControl(); +``` + +## Configure the pan control + +### Configure the pan control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$panControl->setControlPosition(ControlPosition::TOP_LEFT); +$panControl->setControlPosition(ControlPosition::TOP_CENTER); +$panControl->setControlPosition(ControlPosition::TOP_RIGHT); +$panControl->setControlPosition(ControlPosition::LEFT_TOP); +$panControl->setControlPosition(ControlPosition::LEFT_CENTER); +$panControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$panControl->setControlPosition(ControlPosition::RIGHT_TOP); +$panControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$panControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$panControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$panControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$panControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +## Set your pan control on the map + +``` php +$map->getControls()->setPanControl($panControl); +``` diff --git a/doc/controls/rotate.md b/doc/controls/rotate.md new file mode 100644 index 00000000..fee70969 --- /dev/null +++ b/doc/controls/rotate.md @@ -0,0 +1,39 @@ +# Rotate control + +The Rotate control contains a small circular icon which allows you to rotate maps containing oblique imagery. This +control appears by default in the top left corner of the map. + +## Build your rotate control + +``` php +use Ivory\GoogleMap\Controls\RotateControl; + +$rotateControl = new RotateControl(); +``` + +## Configure the rotate control + +### Configure the rotate control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$rotateControl->setControlPosition(ControlPosition::TOP_LEFT); +$rotateControl->setControlPosition(ControlPosition::TOP_CENTER); +$rotateControl->setControlPosition(ControlPosition::TOP_RIGHT); +$rotateControl->setControlPosition(ControlPosition::LEFT_TOP); +$rotateControl->setControlPosition(ControlPosition::LEFT_CENTER); +$rotateControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$rotateControl->setControlPosition(ControlPosition::RIGHT_TOP); +$rotateControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$rotateControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$rotateControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$rotateControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$rotateControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +## Set your rotate control on the map + +``` php +$map->getControls()->setRotateControl($rotateControl); +``` diff --git a/doc/controls/scale.md b/doc/controls/scale.md new file mode 100644 index 00000000..cf2917db --- /dev/null +++ b/doc/controls/scale.md @@ -0,0 +1,46 @@ +# Scale control + +The Scale control displays a map scale element. This control is not enabled by default. + +## Build your scale control + +``` php +use Ivory\GoogleMap\Controls\ScaleControl; + +$scaleControl = new ScaleControl(); +``` + +## Configure your scale control + +### Configure your scale control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$scaleControl->setControlPosition(ControlPosition::TOP_LEFT); +$scaleControl->setControlPosition(ControlPosition::TOP_CENTER); +$scaleControl->setControlPosition(ControlPosition::TOP_RIGHT); +$scaleControl->setControlPosition(ControlPosition::LEFT_TOP); +$scaleControl->setControlPosition(ControlPosition::LEFT_CENTER); +$scaleControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$scaleControl->setControlPosition(ControlPosition::RIGHT_TOP); +$scaleControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$scaleControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$scaleControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$scaleControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$scaleControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +### Configure your scale control style + +``` php +use Ivory\GoogleMap\Controls\ScaleControlStyle; + +$scaleControl->setScaleControlStyle(ScaleControlStyle::DEFAULT_); +``` + +## Set your scale control on the map + +``` php +$map->getControls()->setScaleControl($scaleControl); +``` diff --git a/doc/controls/street_view.md b/doc/controls/street_view.md new file mode 100644 index 00000000..e05079bc --- /dev/null +++ b/doc/controls/street_view.md @@ -0,0 +1,39 @@ +# Street view control + +The Street View control contains a Pegman icon which can be dragged onto the map to enable Street View. This control +appears by default in the top left corner of the map. + +## Build your street view control + +``` php +use Ivory\GoogleMap\Controls\StreetViewControl; + +$streetViewControl = new StreetViewControl(); +``` + +## Configure the street view control + +### Configure the street view control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$streetViewControl->setControlPosition(ControlPosition::TOP_LEFT); +$streetViewControl->setControlPosition(ControlPosition::TOP_CENTER); +$streetViewControl->setControlPosition(ControlPosition::TOP_RIGHT); +$streetViewControl->setControlPosition(ControlPosition::LEFT_TOP); +$streetViewControl->setControlPosition(ControlPosition::LEFT_CENTER); +$streetViewControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$streetViewControl->setControlPosition(ControlPosition::RIGHT_TOP); +$streetViewControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$streetViewControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$streetViewControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$streetViewControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$streetViewControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +## Set your street view control on the map + +``` php +$map->getControls()->setStreetViewControl($streetViewControl); +``` diff --git a/doc/controls/zoom.md b/doc/controls/zoom.md new file mode 100644 index 00000000..30b97ae6 --- /dev/null +++ b/doc/controls/zoom.md @@ -0,0 +1,50 @@ +# Zoom control + +The Zoom control displays a slider (for large maps) or small "+/-" buttons (for small maps) to control the zoom level +of the map. This control appears by default in the top left corner of the map on non-touch devices or in the bottom +left corner on touch devices. + +## Build your zoom control + +``` php +use Ivory\GoogleMap\Controls\ZoomControl; + +$zoomControl = new ZoomControl(); +``` + +## Configure your zoom control + +### Configure your zoom control position + +``` php +use Ivory\GoogleMap\Controls\ControlPosition; + +$zoomControl->setControlPosition(ControlPosition::TOP_LEFT); +$zoomControl->setControlPosition(ControlPosition::TOP_CENTER); +$zoomControl->setControlPosition(ControlPosition::TOP_RIGHT); +$zoomControl->setControlPosition(ControlPosition::LEFT_TOP); +$zoomControl->setControlPosition(ControlPosition::LEFT_CENTER); +$zoomControl->setControlPosition(ControlPosition::LEFT_BOTTOM); +$zoomControl->setControlPosition(ControlPosition::RIGHT_TOP); +$zoomControl->setControlPosition(ControlPosition::RIGHT_CENTER); +$zoomControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); +$zoomControl->setControlPosition(ControlPosition::BOTTOM_LEFT); +$zoomControl->setControlPosition(ControlPosition::BOTTOM_CENTER); +$zoomControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); +``` + +### Configure your zoom control style + +``` php +use Ivory\GoogleMap\Controls\ZoomControlStyle; + +$zoomControl->setZoomControlStyle(ZoomControlStyle::DEFAULT_); +$zoomControl->setZoomControlStyle(ZoomControlStyle::LARGE); +$zoomControl->setZoomControlStyle(ZoomControlStyle::SMALL); +``` + +## Set your zoom control on the map + +``` php +$map->getControls()->setZoomControl($zoomControl); +``` diff --git a/doc/events/dom_event.md b/doc/events/dom_event.md new file mode 100644 index 00000000..bd8514b0 --- /dev/null +++ b/doc/events/dom_event.md @@ -0,0 +1,49 @@ +# Dom event + +## Build your dom event + +``` php +use Ivory\GoogleMap\Events\DomEvent; + +$domEvent = new DomEvent(); +``` + +## Configure your dom event + +### Configure the variable + +``` php +$domEvent->setVariable('event'); +``` + +### Configure the instance + +``` php +$domEvent->setInstance($instance); +``` + +### Configure the event name + +``` php +$domEvent->setEventName($domEventName); +``` + +### Configure the handle + +``` php +$domEvent->setHandle($handle); +``` + +### Configure the capture state + +``` php +$domEvent->setCapture(true); +``` + +## Add your dom event on the map + +``` php +$map->getEvents()->addDomEvent($domEvent); +// or +$map->getEvents()->addDomEventOnce($domEvent); +``` diff --git a/doc/events/event.md b/doc/events/event.md new file mode 100644 index 00000000..fd2db4eb --- /dev/null +++ b/doc/events/event.md @@ -0,0 +1,43 @@ +# Event + +## Build your event + +``` php +use Ivory\GoogleMap\Events\Event; + +$event = new Event(); +``` + +## Configure your event + +### Configure the variable + +``` php +$event->setVariable('event'); +``` + +### Configure the instance + +``` php +$event->setInstance($instance); +``` + +### Configure the event name + +``` php +$event->setEventName($eventName); +``` + +### Configure the handle + +``` php +$event->setHandle($handle); +``` + +## Add your event on the map + +``` php +$map->getEvents()->addEvent($event); +// or +$map->getEvents()->addEventOnce($event); +``` diff --git a/doc/events/index.md b/doc/events/index.md new file mode 100644 index 00000000..0d31dbcc --- /dev/null +++ b/doc/events/index.md @@ -0,0 +1,14 @@ +# Events + +JavaScript within the browser is event driven, meaning that JavaScript responds to interactions by generating events, +and expects a program to listen to interesting events. The event model for the Google Maps API V3 is similar to that +used in V2 of the API, though much has changed under the hood. + +The events bag is accessible via: + +``` php +$events = $map->getEvents(); +``` + + 1. [Event](/doc/events/event.md) + 2. [Dom event](/doc/events/dom_event.md) diff --git a/doc/helpers/container.md b/doc/helpers/container.md new file mode 100644 index 00000000..8d68c626 --- /dev/null +++ b/doc/helpers/container.md @@ -0,0 +1,78 @@ +# JS Container + +When you call `$mapHelper->renderJavascripts($map)`, the library will generate for you all needed JS code for +displaying your map. Obviously, all the code is organized in order to reuse created objects in the client side +(your JS scripts). + +As explain in the doc, a map has a variable which is used to render the code. For example, you have a map with +`my_map` as variable, then the output will be: + +``` +my_map = new new google.maps.Map(/* ... */); +``` + +There is many objects which have a variable (coordinates, markers, etc). All these objects are rendered like a map +(except for the instanciation part :)). So, you can use every objects though his variable. + +Additionally, a container is builded for each map in order to more easily reuse all the related objects of a map +instead of directly relying on each variable. For a map named `my_map`, the output will be: + +``` json +{ + "base": { + "coordinates": [], + "bounds": [], + "points": [], + "sizes": [] + }, + "map": null, + "overlays": { + "circles": [], + "encoded_polylines": [], + "ground_overlays": [], + "polygons": [], + "polylines": [], + "rectangles": [], + "info_windows": [], + "info_boxes": [], + "icons": [], + "marker_shapes": [], + "markers": [], + "marker_cluster": null + }, + "layers": { + "kml_layers": [] + }, + "events": { + "dom_events": [], + "dom_events_once": [], + "events": [], + "events_once": [] + }, + "functions": { + "info_windows": { + "close": function () {} + }, + "to_array": function (o) { + var a=[];for(var k in o){a.push(o[k]);}return a; + } + } +} +``` + +Each objects is aliased by his variable in the container. If you have a circle named "my_circle", then you can access +it like that: + +``` +var my_circle = my_map_container.circles.my_circle; +``` + +If you want to iterate all markers on you map, you can easily archive it: + +``` +for (marker in my_map_container.markers) { + var my_marker = my_map_container.markers[marker]; + + // Do what you want with your marker... +} +``` diff --git a/doc/helpers/rendering.md b/doc/helpers/rendering.md new file mode 100644 index 00000000..1909bd14 --- /dev/null +++ b/doc/helpers/rendering.md @@ -0,0 +1,146 @@ +# Rendering + +The rendering process is probably the more complex part of the library and so maybe the more complex one to +understand... Don't be afraid, rendering a map is very simple but how it is archive internally can be difficult to +understand for beginners. + +## Overview + +Rendering a map is done in two steps. First, you render the map and then, you render the goole map api loading which +will trigger asynchronously the rendering of the previously rendered map. Everything is done asynchronously in order to +be able to trigger the api loading at the very end of the page and the map/api rendering are decoupled in order to +make the api helper awares of the multiple elements which have been rendered. Basically, you can render multiple maps +on the same page or a map with a places autocomplete. So, decoupling them makes the api helper able to trigger the +rendering of all the elements rendered. + +In all helpers, the main concept is everything is done around an event dispatcher. Basically, when you render something, +an event dedicated to this specific rendering is dispatched and then, the subscribers appends/wraps the code which is +finally returned. Internally, each subscriber uses renderers which are responsible to render a specific feature (for +example render a coordinate instantiation), aggregators which are responsible to aggregate objects before rendering +them (for example aggregate all coordinates over the map graph object) and a formatter in order to make the code +readable in debug mode and do other internal stuff. + +On top of this concept, to give you helpers with all core subscribers registered, multiple factory implementations are +available. + +Here an example of two maps and one places autocomplete rendered on the same page: + +``` php +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Places\Autocomplete; + +$autocomplete = new Autocomplete(); +$map1 = new Map(); +$map2 = new Map(); + +$helperFactory = new HelperFactory(); + +$autocompleteHelper = $helperFactory->createPlacesAutocompleteHelper(); +$mapHelper = $helperFactory->createMapHelper(); +$apiHelper = $helperFactory->createApiHelper(); + +echo $autocompleteHelper->render($autocomplete); +echo $mapHelper->render($map1); +echo $mapHelper->render($map2); +echo $apiHelper->render(array($autocomplete, $map1, $map2)); +``` + +## Helper factory + +As explain, an helper factory allows you to create fully configured helpers which are mandatory to render a map. There +are multiple implementations which implement `Ivory\GoogleMap\Helpers\Factories\HelperFactoryInterface`: + + - PHP helper factory: A plain PHP implementation which does not require any dependency. + - Symfony2 helper factory: An implementation using the Symfony dependency injection component. + +An important concept is the fact there is only one instance of each object except for the event dispatcher. + +### PHP factory + +``` php +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; + +$helperFactory = new HelperFactory(); +``` + +By default, the helper factory is configured for a prod environment but you can enable the debug with: + +``` php +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; + +$helperFactory = new HelperFactory(true); +// or +$helperFactory->setDebug(true); +``` + +### Symfony2 factory + +``` php +use Ivory\GoogleMap\Helpers\Factories\Symfony2HelperFactory; + +$helperFactory = new Symfony2HelperFactory(); +``` + +By default, the helper factory is configured for a prod environment but without caching. To enable it: + +``` php +use Ivory\GoogleMap\Helpers\Factories\Symfony2HelperFactory; + +$helperFactory = new Symfony2HelperFactory(false, 4, __DIR__.'/cache'); +// or +$helperFactory->setCachePath(__DIR__.'/cache'); +``` + +## Map helper + +The map helper is available through the helper factory: + +``` php +$mapHelper = $helperFactory->createMapHelper(); +``` + +The main method of the map helper is the `render` which renders all html code included html, js and css but you can +render each of them individually: + +``` php +echo $mapHelper->render($map); +// or +echo $mapHelper->renderHtml($map); +echo $mapHelper->renderJavascript($map); +echo $mapHelper->renderStylesheet($map); +``` + +Additionally, the rendered map objects are stored in a container as explained [here](/doc/helpers/container.md). + +## Places autocomplete helper + +The places autocomplete helper is available through the helper factory: + +``` php +$autocompleteHelper = $helperFactory->createPlacesAutocompleteHelper(); +``` + +The main method of the places autocomplete helper is the `render` which renders all html code included html and js but +you can render each of them individually: + +``` php +echo $autocompleteHelper->render($map); +// or +echo $autocompleteHelper->renderHtml($map); +echo $autocompleteHelper->renderJavascript($map); +``` + +## Api helper + +The api helper is available through the helper factory: + +``` php +$apiHelper = $helperFactory->createApiHelper(); +``` + +To render the api loading, you can use: + +``` php +echo $apiHelper->render(array($map, autocompleteHelper)); +``` diff --git a/doc/installation.md b/doc/installation.md index 028a0fab..ae4e6bbe 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -8,7 +8,7 @@ you. Composer comes with a simple phar file. To easily access it from anywhere on your system, you can execute: -``` +``` bash $ curl -s https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer ``` @@ -17,13 +17,13 @@ $ sudo mv composer.phar /usr/local/bin/composer ### Mandatories dependencies -Create a ``composer.json`` file at the root directory of your project and simply require the -``egeloen/google-map`` package: +Create a `composer.json` file at the root directory of your project and simply require the +`egeloen/google-map` package: -``` +``` json { "require": { - "egeloen/google-map": "dev-master" + "egeloen/google-map": "*" } } ``` @@ -32,7 +32,7 @@ Create a ``composer.json`` file at the root directory of your project and simply If you want to use Geocoding stuff, you will need [Geocoder](http://github.com/willdurand/Geocoder): -``` +``` json { "require": { "willdurand/geocoder": "*" @@ -41,12 +41,23 @@ If you want to use Geocoding stuff, you will need [Geocoder](http://github.com/w ``` If you want to use Directions or Distance Matrix stuff, you will need an -[http adapter](http://github.com/widop/http-adapter): +[http adapter](http://github.com/egeloen/ivory-http-adapter): +``` json +{ + "require": { + "egeloen/http-adapter": "*" + } +} ``` + +If you want to use the container helper factory, you will need the +[Symfony2 Dependency Injection component](http://symfony.com/doc/current/components/dependency_injection/index.html): + +``` json { "require": { - "widop/http-adapter": "1.0.*" + "symfony/dependency-injection": "*" } } ``` @@ -55,11 +66,11 @@ If you want to use Directions or Distance Matrix stuff, you will need an Now, you have define your dependencies, you can install them: -``` +``` bash $ composer install ``` -Composer will automatically download your dependencies & create an autoload file in the ``vendor`` directory. +Composer will automatically download your dependencies & create an autoload file in the `vendor` directory. ## Autoload diff --git a/doc/layers/index.md b/doc/layers/index.md new file mode 100644 index 00000000..6714f1d8 --- /dev/null +++ b/doc/layers/index.md @@ -0,0 +1,12 @@ +# Layers + +Layers are objects on the map that consist of one or more separate items, but are manipulated as a single unit. Layers +generally reflect collections of objects that you add on top of the map to designate a common association. + +The layers bag is accessible via: + +``` php +$layers = $map->getLayers(); +``` + + 1. [Kml layer](/doc/layers/kml_layer.md) diff --git a/doc/layers/kml_layer.md b/doc/layers/kml_layer.md new file mode 100644 index 00000000..954bbdd7 --- /dev/null +++ b/doc/layers/kml_layer.md @@ -0,0 +1,38 @@ +# KML Layer + +The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. For more +information, see official [documentation](http://code.google.com/apis/maps/documentation/javascript/layers.html#KmlLayers). + +## Build your kml layer + +``` php +use Ivory\GoogleMap\Layers\KmlLayer; + +$kmlLayer = new KmlLayer('url'); +``` + +## Configure your kml layer + +### Configure the variable + +``` php +$kmlLayer->setVariable('kml_layer'); +``` + +### Configure the url + +``` php +$kmlLayer->setUrl('url'); +``` + +### Configure the options + +``` php +$kmlLayer->setOption('clickable', true); +``` + +## Add your kml layer on the map + +``` php +$map->getLayers()->addKmlLayer($kmlLayer); +``` diff --git a/doc/map.md b/doc/map.md new file mode 100644 index 00000000..c3175c6c --- /dev/null +++ b/doc/map.md @@ -0,0 +1,154 @@ +# Map + +The Map is the central point of the library. It allows you to manipulate all available options. If you render the +default map, the library will generate a map of 300px by 300px, centered on the coordinate (0, 0), configured with a +zoom of 3 and using the default controls. + +## Build your map + +``` php +use Ivory\GoogleMap\Map; + +$map = new Map(); +``` + +## Configure the map + +### Configure the variable + +``` php +$map->setVariable('map'); +``` + +### Configure the html container id + +``` php +$map->setHtmlContainerId('map'); +``` + +### Configure the center + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$map->setCenter(new Coordinate(1, 2)); +``` + +### Configure the bound + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; + +$map->setBound(new Bound(new Coordinate(-2.1, -3.9), new Coordinate(2.6, 1.4))); +``` + +### Configure map center and zoom + +For configurating the map center & zoom, you have three possibilities: + + 1. Standard center coordinate and zoom + 2. Fitting a bound + 3. Fitting a bound which extends overlays + +#### Standard center coordinate and zoom + +To use the standard center coordinate & zoom, you need to disable the auto zoom flag & configure the center/zoom. + +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Map; + +$map = new Map(); + +// Disable the auto zoom flag (default: disabled) +$map->getOverlays()->setAutoZoom(false); + +// Sets the center (default: (0, 0)). +$map->setCenter(new Coordinate(1, 2)); + +// Sets the zoom (default: 3) +$map->setMapOption('zoom', 5); +``` + +#### Fitting a bound + +For fitting a bound, you need to enable the auto zoom flag & configure bound south west & nort east coordinates. +If you extend overlays with the bound, the map will fit the overlays coordinate instead of bound coordinates. + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Map; + +$map = new Map(); + +// Enable the auto zoom flag (default: disabled) +$map->getOverlays()->setAutoZoom(true); + +// Sets the bound +$map->setBound(new Bound(new Coordinate(-2.1, -3.9), new Coordinate(2.6, 1.4)); +``` + +#### Fitting a bound which extends overlays + +For fitting a bound which extends overlays, you need to enable the auto zoom flag & add overlays to the bound. +In the [overlays documentation](/doc/overlays/index.md), you learn how you can add overlays on the map. If the auto +zoom flag is enabled and you add some overlays on the map, the map bound will automatically extends your overlay. So, +at the end, all your overlays will be visible on your screen. + +``` php +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\Marker; + +$map = new Map(); + +// Enable the auto zoom flag (default: false) +$map->getOverlays()->setAutoZoom(true); + +// Add marker to your map +$map->getOverlays()->addMarker(new Marker()); +``` + +### Configure the map option + +``` php +use Ivory\GoogleMap\MapTypeId; + +$map->setMapOption('mapTypeId', MapTypeId::ROADMAP); +$map->setMapOption('zoom', 4); +``` + +### Configure the stylesheet option + +``` php +$map->setStylesheetOption('width', '300px'); +``` + +### Configure the language + +``` php +$map->setLanguage('en'); +``` + +### Configure the libraries + +``` php +$map->setLibraries(array('places', 'geometry')); +``` + +### Configure overlays + +The overlays documentation is available [here](/doc/overlays/index.md). + +### Configure controls + +The controls documentation is available [here](/doc/controls/index.md). + +### Configure layers + +The layers documentation is available [here](/doc/layers/index.md). + +### Configure events + +The events documentation is available [here](/doc/events/index.md). diff --git a/doc/usage/overlays/circle.md b/doc/overlays/circle.md similarity index 56% rename from doc/usage/overlays/circle.md rename to doc/overlays/circle.md index 68440b1e..98e9c6d0 100644 --- a/doc/usage/overlays/circle.md +++ b/doc/overlays/circle.md @@ -8,30 +8,42 @@ center of the circle, radius of the circle, in meters. ## Build your circle ``` php +use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Overlays\Circle; -$circle = new Circle(); +$circle = new Circle(new Coordinate(1, 2), 3); +``` -// Configure your circle options -$circle->setPrefixJavascriptVariable('circle_'); -$circle->setCenter(0, 0, true); -$circle->setRadius(1); +## Configure your circle -$circle->setOption('clickable', false); -$circle->setOption('strokeWeight', 2); -$circle->setOptions(array( - 'clickable' => false, - 'strokeWeight' => 2, -)); +### Configure the variable + +``` php +$circle->setVariable('circle'); ``` -## Add your circle to the map +### Configure the center ``` php -use Ivory\GoogleMap\Overlays\Circle; +use Ivory\GoogleMap\Base\Coordinate; + +$circle->setCenter(new Coordinate(1, 2); +``` -$circle = new Circle(); +### Configure the radius -// Add your circle to the map -$map->addCircle($circle); +``` php +$circle->setRadius(1); +``` + +### Configure the options + +``` php +$circle->setOption('clickable', false); +``` + +## Add your circle on the map + +``` php +$map->getOverlays()->addCircle($circle); ``` diff --git a/doc/overlays/encoded_polyline.md b/doc/overlays/encoded_polyline.md new file mode 100644 index 00000000..b76dd695 --- /dev/null +++ b/doc/overlays/encoded_polyline.md @@ -0,0 +1,38 @@ +# Encoded Polyline + +The Encoded Polyline class defines a [Polyline](/doc/overlays/polyline.md) which has been encoded using the algorithm +described [here](http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html). + +## Build your encoded polyline + +``` php +use Ivory\GoogleMap\Overlays\EncodedPolyline; + +$encodedPolyline = new EncodedPolyline('value'); +``` + +## Configure your encoded polyline + +### Configure the variable + +``` php +$encodedPolyline->setVariable('encoded_polyline'); +``` + +### Configure the value + +``` php +$encodedPolyline->setValue('value'); +``` + +### Configure the options + +``` php +$polyline->setOption('geodesic', true); +``` + +## Add your encoded polyline on the map + +``` php +$map->getOverlays()->addEncodedPolyline($encodedPolyline); +``` diff --git a/doc/overlays/ground_overlay.md b/doc/overlays/ground_overlay.md new file mode 100644 index 00000000..7f50917e --- /dev/null +++ b/doc/overlays/ground_overlay.md @@ -0,0 +1,49 @@ +# Ground overlay + +Polygons are useful overlays to represent arbitrarily-sized areas, but they cannot display images. If you have an image +that you wish to place on a map, you can use a GroundOverlay object. + +## Build your ground overlay + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\GroundOverlay; + +$groundOverlay = new GroundOverlay('url', new Bound(new Coordinate(1.1, 2.2), new Coordinate(3.3, 4.4)); +``` + +## Configure your ground overlay + +### Configure the variable + +``` php +$groundOverlay->setVariable('ground_overlay'); +``` + +### Configure the url + +``` php +$groundOverlay->setUrl('url'); +``` + +### Configure the bound + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; + +$groundOverlay->setBound(new Bound(new Coordinate(1.1, 2.2), new Coordinate(3.3, 4.4)); +``` + +### Configure the options + +``` php +$groundOverlay->setOption('clickable', false); +``` + +## Add your ground overlay on the map + +``` php +$map->getOverlays()->addGroundOverlay($groundOverlay); +``` diff --git a/doc/overlays/icon.md b/doc/overlays/icon.md new file mode 100644 index 00000000..7fe3565b --- /dev/null +++ b/doc/overlays/icon.md @@ -0,0 +1,58 @@ +# Icon + +Markers may define an icon to show in place of the default icon or a shadow to shown in place of the default shadow. +Defining an icon or a shadow involves setting a number of properties that define the visual behavior of the marker. + +## Build your icon + +``` php +use Ivory\GoogleMap\Overlays\Icon; + +$icon = new Icon('url'); +``` + +## Configure your icon + +### Configure the variable + +``` php +$icon->setVariable('icon'); +``` + +### Configure the url + +``` php +$icon->setUrl('url'); +``` + +### Configure the anchor + +``` php +use Ivory\GoogleMap\Base\Point; + +$icon->setAnchor(new Point(20, 34)); +``` + +### Configure the origin + +``` php +use Ivory\GoogleMap\Base\Point; + +$icon->setOrigin(new Point(0, 0)); +``` + +### Configure the size + +``` php +use Ivory\GoogleMap\Base\Size; + +$icon->setSize(new Size(20, 34, 'px', 'px')); +``` + +### Configure the scaled size + +``` php +use Ivory\GoogleMap\Base\Size; + +$icon->setScaledSize(new Size(20, 34, 'px', 'px')); +``` diff --git a/doc/overlays/index.md b/doc/overlays/index.md new file mode 100644 index 00000000..250a1f4d --- /dev/null +++ b/doc/overlays/index.md @@ -0,0 +1,21 @@ +# Overlays + +Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom +the map. Overlays reflect objects that you "add" on the map to designate points, lines, areas, or collections of +objects. + +The overlays bag is accessible via: + +``` php +$overlays = $map->getOverlays(); +``` + + 1. [Marker](/doc/overlays/marker.md) + 2. [Info window](/doc/overlays/info_window.md) + 3. [Polyline](/doc/overlays/polyline.md) + 4. [Encoded Polyline](/doc/overlays/encoded_polyline.md) + 5. [Polygon](/doc/overlays/polygon.md) + 6. [Rectangle](/doc/overlays/rectangle.md) + 7. [Circle](/doc/overlays/circle.md) + 8. [Ground overlay](/doc/overlays/ground_overlay.md) + 9. [Marker cluster](/doc/overlays/marker_cluster.md) diff --git a/doc/overlays/info_window.md b/doc/overlays/info_window.md new file mode 100644 index 00000000..497745fd --- /dev/null +++ b/doc/overlays/info_window.md @@ -0,0 +1,103 @@ +# Info window + +Info window displays content in a floating window above the map. The info window looks a little like a comic-book word +balloon. It has a content area and a tapered stem, where the tip of the stem is at a specified location on the map. + +## Build your info window + +``` php +use Ivory\GoogleMap\Overlays\InfoWindow; + +$infoWindow = new InfoWindow('content'); +``` + +## Configure your info window + +### Configure the variable + +``` php +$infoWindow->setVariable('info_window'); +``` + +### Configure the content + +``` php +$infoWindow->setContent('

Default content

'); +``` + +### Configure the position + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$infoWindow->setPosition(new Coordinate(2, 1); +``` + +Be aware, that the position is not needed if you attach your info window on a marker as it will be placed at the +marker position. + +### Configure the pixel offset + +``` php +use Ivory\GoogleMap\Base\Size; + +$infoWindow->setPixelOffset(new Size(1.1, 2.1, 'px', 'pt')); +``` + +### Configure the initial open state + +``` php +$infoWindow->setOpen(false); +``` + +### Configure the open event + +``` php +use Ivory\GoogleMap\Events\MouseEvent; + +$infoWindow->setOpenEvent(MouseEvent::CLICK); +$infoWindow->setOpenEvent(MouseEvent::DBLCLICK); +$infoWindow->setOpenEvent(MouseEvent::MOUSEUP); +$infoWindow->setOpenEvent(MouseEvent::MOUSEDOWN); +$infoWindow->setOpenEvent(MouseEvent::MOUSEOVER); +$infoWindow->setOpenEvent(MouseEvent::MOUSEOUT); +``` + +### Configure the auto open state + +``` php +$infoWindow->setAutoOpen(true); +``` + +### Configure the auto close state + +``` php +$infoWindow->setAutoClose(false); +``` + +### Configure the type + +``` php +use Ivory\GoogleMap\Overlays\InfoWindowType; + +$infoWindow->setType(InfoWindowType::DEFAULT_); +$infoWindow->setType(InfoWindowType::INFOBOX); +``` + +### Configure the options + +``` php +$infoWindow->setOption('disableAutoPan', true); +``` + +## Add your info window on the map + +``` php +$map->getOverlays()->addInfoWindow($infoWindow); +``` + +## Set your info window on a marker + +``` php +$marker->setInfoWindow($infoWindow); +``` diff --git a/doc/overlays/marker.md b/doc/overlays/marker.md new file mode 100644 index 00000000..a826735b --- /dev/null +++ b/doc/overlays/marker.md @@ -0,0 +1,90 @@ +# Marker + +Markers identify locations on the map. By default, they use a standard icon. + +## Build your marker + +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\Marker; + +$marker = new Marker(new Coordinate(1.1, 2.2)); +``` + +## Configure your marker + +### Configure the variable + +``` php +$marker->setVariable('marker'); +``` + +### Configure the position + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$marker->setPosition(new Coordinate(1, 2)); +``` + +### Configure the animation + +``` php +use Ivory\GoogleMap\Overlays\Animation; + +$marker->setAnimation(Animation::BOUNCE); +$marker->setAnimation(Animation::DROP); +``` + +### Configure the options + +``` php +$marker->setOption('clickable', false); +``` + +## Configure the icon + +``` php +use Ivory\GoogleMap\Overlays\Icon; + +$marker->setIcon(new Icon('url')); +``` + +The complete icon configuration is available [here](/doc/overlays/icon.md). + +### Configure the shadow + +``` php +use Ivory\GoogleMap\Overlays\Icon; + +$marker->setShadow(new Icon('url')); +``` + +The complete shadow configuration is available [here](/doc/overlays/icon.md). + +### Configure the shape + +``` php +use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\GoogleMap\Overlays\MarkerShapeType; + +$marker->setShadow(new MarkerShape(MarkerShapeType::CIRCLE, array(1, 2, 3)); +``` + +The complete marker shape configuration is available [here](/doc/overlays/marker_shape.md). + +### Configure the info window + +``` php +use Ivory\GoogleMap\Overlays\InfoWindow; + +$marker->setInfoWindow(new InfoWindow('content')); +``` + +The complete info window configuration is available [here](/doc/overlays/info_window.md). + +## Add your marker on the map + +``` php +$map->getOverlays()->addMarker($marker); +``` diff --git a/doc/overlays/marker_cluster.md b/doc/overlays/marker_cluster.md new file mode 100644 index 00000000..0669762e --- /dev/null +++ b/doc/overlays/marker_cluster.md @@ -0,0 +1,50 @@ +# Marker Cluster + +Some applications are required to display a large number of locations or markers. Despite the v3 JavaScript API's +significant improvement to performance, naively plotting thousands of markers on a map can quickly lead to to a +degraded user experience. Too many markers on the map cause both visual overload and sluggish interaction with the map. +To overcome this poor performance, the information displayed on the map needs to be simplified, we need a marker +clustering solution. + +## Build your marker cluster + +``` php +use Ivory\GoogleMap\Overlays\MarkerCluster; + +$markerCluster = new MarkerCluster(); +``` + +## Configure your marker cluster + +### Configure the markers + +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\Marker; + +$markerCluster->addMarker(new Marker(new Coordinate(1.1, 2.1))); +``` + +### Configure the type + +``` php +use Ivory\GoogleMap\Overlays\MarkerClusterType; + +// Default marker cluster (none) +$markerCluster->setType(MarkerClusterType::_DEFAULT); + +// Google marker cluster (http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html) +$markerCluster->setType(MarkerCluster::MARKER_CLUSTER); +``` + +### Configure the options + +``` php +$markerCluster->setOption('maxZoom', 15); +``` + +## Set the marker cluster on the map + +``` php +$map->getOverlays()->setMarkerCluster($markerCluster); +``` diff --git a/doc/usage/overlays/marker_shape.md b/doc/overlays/marker_shape.md similarity index 56% rename from doc/usage/overlays/marker_shape.md rename to doc/overlays/marker_shape.md index c4a382e5..8cea9213 100644 --- a/doc/usage/overlays/marker_shape.md +++ b/doc/overlays/marker_shape.md @@ -1,8 +1,8 @@ # Marker shape -This object defines the marker shape to use in determination of a marker's clickable region. -The shape consists of two properties "type" and "coordinates" which define the general type of marker and coordinates -specific to that type of marker. +This object defines the marker shape to use in determination of a marker's clickable region. The shape consists of two +properties "type" and "coordinates" which define the general type of marker and coordinates specific to that type of +marker. The format of this attribute depends on the value of the type and follows the w3 AREA coords specification found at http://www.w3.org/TR/REC-html40/struct/objects.html#adef-coords. The coordinates attribute is an array of integers that @@ -10,37 +10,42 @@ specify the pixel position of the shape relative to the top-left corner of the t the value of type as follows: - circle: coordinates is [x1, y1, r] where x1, y2 are the coordinates of the center of the circle, and r is the radius - of the circle. + of the circle. - poly: coordinates is [x1, y1, x2, y2 ... xn, yn] where each x, y pair contains the coordinates of one vertex of the - polygon. + polygon. - rect: coordinates is [x1, y1, x2, y2] where x1, y1 are the coordinates of the upper-left corner of the rectangle - and x2, y2 are the coordinates of the lower-right coordinates of the rectangle. + and x2, y2 are the coordinates of the lower-right coordinates of the rectangle. ## Build your marker shape ``` php use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\GoogleMap\Overlays\MarkerShapeType; -$markerShape = new MarkerShape(); +$markerShape = new MarkerShape(MarkerShapeType::CIRCLE, array(1, 2, 3)); +``` -// Configure your marker shape options -$markerShape->setPrefixJavascriptVariable('marker_shape_'); -$markerShape->setType('poly'); -$markerShape->setCoordinates(array(1, 1, 1, -1, -1, -1, -1, 1)); +## Configure your marker shape -// If the marker shape type is "poly", you can add coordinate one by one -$markerShape->addPolyCoordinates(1, 1); -``` +### Configure the variable -## Add your marker shape to the marker +``` php +$markerShape->setVariable('marker_shape'); -Now you have configurated your marker shape, you need to add it to your marker. +### Configure the type ``` php -use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\GoogleMap\Overlays\MarkerShapeType; + +$markerShape->setType(MarkerShapeType::POLYGON); +``` -$markerShape = new MarkerShape(); +### Configure the coordinates -// Add your marker shape to the marker -$marker->setShape($markerShape); +``` php +$markerShape->setCoordinates(array(1, 1, 1, -1, -1, -1, -1, 1)); +``` + +``` php +$markerShape->addPolyCoordinates(1, 1); ``` diff --git a/doc/overlays/polygon.md b/doc/overlays/polygon.md new file mode 100644 index 00000000..a30f5e5d --- /dev/null +++ b/doc/overlays/polygon.md @@ -0,0 +1,45 @@ +# Polygon + +Polygon objects are similar to polyline objects in that they consist of a series of coordinates in an ordered sequence. +However, instead of being open-ended, polygons are designed to define regions within a closed loop. + +## Build your polygon + +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\Polygon; + +$polygon = new Polygon(array( + new Coordinate(1, 2), + new Coordinate(2, -1), + new Coordinate(0, 0) +)); +``` + +## Configure your polygon + +### Configure the variable + +``` php +$polygon->setVariable('polygon'); +``` + +### Configure the coordinate + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$polygon->addCoordinate(new Coordinate(1, 2)); +``` + +### Configure the options + +``` php +$polygon->setOption('fillColor', '#000000'); +``` + +## Add your polygon on the map + +``` php +$map->getOverlays()->addPolygon($polygon); +``` diff --git a/doc/overlays/polyline.md b/doc/overlays/polyline.md new file mode 100644 index 00000000..17f065f3 --- /dev/null +++ b/doc/overlays/polyline.md @@ -0,0 +1,45 @@ +# Polyline + +The Polyline class defines a linear overlay of connected line segments on the map. A Polyline object consists of an +array of coordinates, and creates a series of line segments that connect those locations in an ordered sequence. + +## Build your polyline + +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\Polyline; + +$polyline = new Polyline(array( + new Coordinate(1, 2), + new Coordinate(2, -1), + new Coordinate(0, 0) +)); +``` + +## Configure your polyline + +### Configure the variable + +``` php +$polyline->setVariable('polyline'); +``` + +### Configure the coordinates + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$polyline->addCoordinate(new Coordinate(1, 2)); +``` + +### Configure the options + +``` php +$polyline->setOption('geodesic', true); +``` + +## Add your polyline on the map + +``` php +$map->getOverlays()->addPolyline($polyline); +``` diff --git a/doc/overlays/rectangle.md b/doc/overlays/rectangle.md new file mode 100644 index 00000000..1bba8d9c --- /dev/null +++ b/doc/overlays/rectangle.md @@ -0,0 +1,44 @@ +# Rectangle + +A Rectangle is similar to a Polygon in that you can define custom colors, weights, and opacities for the edge of the +rectangle (the "stroke") and custom colors and opacities for the area within the enclosed region (the "fill"). Unlike a +Polygon, you do not define paths for a Rectangle; instead, a rectangle has one additional property which defines its +shape: the bound. + +## Build your rectangle + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Overlays\Rectangle; + +$rectangle = new Rectangle(new Bound(new Coordinate(-1, -1), new Coordinate(1, 1)); +``` + +## Configure your rectangle + +### Configure the variable + +``` php +$rectangle->setVariable('rectangle'); +``` + +### Configure the bound + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; + +$rectangle->setBound(new Bound(new Coordinate(-1, -1), new Coordinate(1, 1)); +``` + +### Configure the options + +``` php +$rectangle->setOption('clickable', false); +``` + +## Add your rectangle on the map + +``` php +$map->getOverlays()->addRectangle($rectangle); +``` diff --git a/doc/places/autocomplete.md b/doc/places/autocomplete.md new file mode 100644 index 00000000..fb7490d0 --- /dev/null +++ b/doc/places/autocomplete.md @@ -0,0 +1,93 @@ +# Autocomplete + +The Places Autocomplete feature attaches to a text field on your web page, and monitors that field for character +entries. As text is entered, Autocomplete returns Place predictions to the application in the form of a drop-down pick +list. You can use the Places Autocomplete feature to help users find a specific location, or assist them with filling +out address fields in online forms. + +## Create your autocomplete + +``` php +use Ivory\GoogleMap\Places\Autocomplete; + +$autocomplete = new Autocomplete(); +``` + +## Configure your autocomplete + +### Configure the variable + +``` php +$autocomplete->setVariable('place_autocomplete'); +``` + +### Configure the input id + +``` php +$autocomplete->setInputId('place_input'); +``` + +### Configure the input attributes + +``` php +$autocomplete->setInputAttribute('class', 'my-class'); +``` + +### Configure the value + +``` php +$autocomplete->setValue('foo'); +``` + +### Configure the types + +``` php +use Ivory\GoogleMap\Places\AutocompleteType; + +$autocomplete->addType(AutocompleteType::ESTABLISHMENT); +``` + +### Configure the component restrictions + +``` php +use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; + +$autocomplete->setComponentRestriction(AutocompleteComponentRestriction::COUNTRY, 'fr'); +``` + +### Configure the bound + +``` php +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; + +$autocomplete->setBound(new Bound(new Coordinate(-2.1, -3.9), new Coordinate(2.6, 1.4))); +``` + +### Configure the language + +``` php +$autocomplete->setLanguage('en'); +``` + +## Render your autocomplete + +Now, you have builded and configured your map, you can render it. The map rendering documentation is available +[here](/doc/helpers/rendering.md). + +Example: + +``` php +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; +use Ivory\GoogleMap\Places\Autocomplete; + +$autocomplete = new Autocomplete(); + +$helperFactory = new HelperFactory(); + +$autocompleteHelper = $helperFactory->createPlacesAutocompleteHelper(); +$apiHelper = $helperFactory->createApiHelper(); + +echo $autocompleteHelper->render($autocomplete); +echo $apiHelper->render(array($autocomplete)); +``` diff --git a/doc/usage/places/index.md b/doc/places/index.md similarity index 72% rename from doc/usage/places/index.md rename to doc/places/index.md index 59f73411..3c8d7b5b 100644 --- a/doc/usage/places/index.md +++ b/doc/places/index.md @@ -4,4 +4,4 @@ The Google Places JavaScript library's functions enable your application to sear establishments, geographic locations, or prominent points of interest) contained within a defined area, such as the bounds of a map, or around a fixed point. - 1. [Autocomplete](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/places/autocomplete.md) + 1. [Autocomplete](/doc/places/autocomplete.md) diff --git a/doc/services/business_account.md b/doc/services/business_account.md new file mode 100644 index 00000000..7e43c9fd --- /dev/null +++ b/doc/services/business_account.md @@ -0,0 +1,60 @@ +# Business Account + +When using a service for business purpose, you will receive a business account from Google. This one allows you to +bypass Google limitation according to your billing plan. + +## Create your business account + +``` php +use Ivory\GoogleMap\Services\BusinessAccount; + +$businessAccount = new BusinessAccount('client_id', 'secret'); +``` + +## Configure your business account + +### Configure the client id + +``` php +$businessAccount->setClient('client_id'); +``` + +The client identifier is not prefixed by `gme-` (it is automatically prepended by the library). + +### Configure the secret + +``` php +$businessAccount->setSecret('secret'); +``` + +### Configure the channel + +``` php +$businessAccount->setChannel('channel'); +``` + +## Set the business account on the service + +### Geocoder + +``` php +use Ivory\GoogleMap\Services\BusinessAccount; + +$geocoderProvider->setBusinessAccount(new BusinessAccount('client_id', 'secret')); +``` + +## Directions + +``` php +use Ivory\GoogleMap\Services\BusinessAccount; + +$directions->setBusinessAccount(new BusinessAccount('client_id', 'secret')); +``` + +## Distance Matrix + +``` php +use Ivory\GoogleMap\Services\BusinessAccount; + +$distanceMatrix->setBusinessAccount(new BusinessAccount('client_id', 'secret')); +``` diff --git a/doc/usage/services/directions/directions.md b/doc/services/directions/directions.md similarity index 67% rename from doc/usage/services/directions/directions.md rename to doc/services/directions/directions.md index e4515a69..a5a009d0 100644 --- a/doc/usage/services/directions/directions.md +++ b/doc/services/directions/directions.md @@ -1,55 +1,54 @@ # Directions API -The Directions API uses [widop/http-adapter](http://github.com/widop/http-adapter) which is a PHP 5.3 library for -issuing http requests. +The Directions API uses [egeloen/http-adapter](http://github.com/egeloen/ivory-http-adapter) which is a PHP 5.3 +library for issuing http requests. The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints. -## Request the directions service +## Build your directions service ``` php use Ivory\GoogleMap\Services\Directions\Directions; -use Widop\HttpAdapter\CurlHttpAdapter; +use Ivory\HttpAdapter\SocketHttpAdapter; -$directions = new Directions(new CurlHttpAdapter()); +$directions = new Directions(new SocketHttpAdapter()); ``` -If you want to use it with a business account, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/business_account.md). +If you want to use it with a business account, you can read this [documentation](/doc/services/business_account.md). -## Request a direction +## Route a request ``` php -$response = $directions->route('New York', 'Washington'); +use Ivory\GoogleMap\Services\Directions\DirectionsRequest; + +$response = $directions->route(new DirectionsRequest('New York', 'Washington')); ``` -The directions service allows you to route a much more advance request. If you want to learn more, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/directions/directions_request.md). +If you want to learn more about the request, you can read this +[documentation](/doc/services/directions/directions_request.md). ## Directions response -When you have requested your direction, the returned object is an ``Ivory\GoogleMap\Services\Directions\DirectionsResponse``. +When you have requested your direction, the response is an `Ivory\GoogleMap\Services\Directions\DirectionsResponse`. It wraps a status & routes. ### Directions status -The available status are defined by the ``Ivory\GoogleMap\Services\Directions\DirectionsStatus`` constants. +The available status are defined by the `Ivory\GoogleMap\Services\Directions\DirectionsStatus` constants. ``` php -// Get the status $status = $response->getStatus(); ``` ### Directions routes A request can return many routes. The directions response wraps an array of -``Ivory\GoogleMap\Services\Directions\DirectionsRoute``. +`Ivory\GoogleMap\Services\Directions\DirectionsRoute`. ``` php -// Get the routes $routes = $reponse->getRoutes(); ``` @@ -59,11 +58,7 @@ A directions route wraps a bound, a copyrights, legs, an overview polyline (enco order if you use it in your request. ``` php -// Get the routes -$routes = $reponse->getRoutes(); - -// Iterate each routes -foreach ($routes as $route) { +foreach ($reponse->getRoutes() as $route) { } ``` @@ -73,7 +68,6 @@ foreach ($routes as $route) { The bound defines the viewport bounding box of this route. ``` php -// Get the bound $bound = $route->getBound(); ``` @@ -82,7 +76,6 @@ $bound = $route->getBound(); The copyrights defines the text to be displayed for this route. You must handle and display this information yourself. ``` php -// Get the copyrights $copyrights = $route->getCopyrights(); ``` @@ -93,27 +86,23 @@ the given route. A separate leg will be present for each waypoint or destination will contain exactly one leg within the legs array.) Each leg consists of a series of steps. ``` php -// Get the legs $legs = $route->getLegs(); ``` ### Overview polyline -The overview polyline is an [encoded polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md) -which represents the route. +The overview polyline is an [encoded polyline](/doc/overlays/encoded_polyline.md) which represents the route. ``` php -// Get the overview polyline $overviewPolyline = $route->getOverviewPolyline(); ``` ### Summary -The summari is a short textual description for the route, suitable for naming and disambiguating the route from +The summary is a short textual description for the route, suitable for naming and disambiguating the route from alternatives. ``` php -// Get the summary $summary = $route->getSummary(); ``` @@ -123,7 +112,6 @@ It is an array of warnings to be displayed when showing these directions. You mu yourself. ``` php -// Get the warnings $warnings = $route->getWarnings(); ``` @@ -133,42 +121,33 @@ It contains an array indicating the order of any waypoints in the calculated rou the request was passed `optimize:true` within its `waypoints` parameter. ``` php -// Get the waypoint order $waypointOrder = $route->getWaypointOrder(); ``` ## Directions leg -A directions legs wraps a distance, a durations, a start location, an end location, a start address, an end address, +A directions legs wraps a distance, a durations, a start location, an end location, a start address, an end address and steps. ``` php -// Get the legs -$legs = $route->getLegs(); - -// Iterate each leg -foreach ($legs as $leg) { +foreach ($route->getLegs() as $leg) { } ``` ### Distance -It indicates the total distance covered by this leg. It represented by the -`Ivory\GoogleMap\Services\Base\Distance`. +It indicates the total distance covered by this leg. It represented by the `Ivory\GoogleMap\Services\Base\Distance`. ``` php -// Gets the distance $duration = $leg->getDistance(); ``` ### Duration -It indicates the total duration of this leg. It is represented by the -`Ivory\GoogleMap\Services\Base\Duration`. +It indicates the total duration of this leg. It is represented by the `Ivory\GoogleMap\Services\Base\Duration`. ``` php -// Gets the duration $duration = $leg->getDuration(); ``` @@ -178,17 +157,14 @@ The start location is the coordinate of the start of this leg. It is represented `Ivory\GoogleMap\Base\Coordinate`. ``` php -// Gets the start location $startLocation = $leg->getStartLocation(); ``` ### End location -The end location is the coordinate of the end of this leg. It is represented by the -`Ivory\GoogleMap\Base\Coordinate`. +The end location is the coordinate of the end of this leg. It is represented by the `Ivory\GoogleMap\Base\Coordinate`. ``` php -// Gets the end location $endLocation = $leg->getEndLocation(); ``` @@ -197,7 +173,6 @@ $endLocation = $leg->getEndLocation(); It contains the human-readable address (typically a street address) reflecting the start location. ``` php -// Gets the start address $startAddress = $leg->getStartAddress(); ``` @@ -206,7 +181,6 @@ $startAddress = $leg->getStartAddress(); It contains the human-readable address (typically a street address) reflecting the end location. ``` php -// Gets the end address $endAddress = $leg->getEndAddress(); ``` @@ -215,7 +189,6 @@ $endAddress = $leg->getEndAddress(); A leg contains an array of steps denoting information about each separate step of the leg of the journey. ``` php -// Gets the directions steps. $steps = $leg->getSteps(); ``` @@ -231,11 +204,7 @@ A step wraps a distance, a durations, a start location, an end location, instruc a travel mode. ``` php -// Gets the directions steps. -$steps = $leg->getSteps(); - -// Iterate each step -foreach ($steps as $step) { +foreach ($leg->getSteps() as $step) { } ``` @@ -246,7 +215,6 @@ It contains the distance covered by this step until the next step. This field ma unknown. ``` php -// Gets the distance. $distance = $step->getDistance(); ``` @@ -256,27 +224,22 @@ It contains the typical time required to perform the step, until the next step. duration is unknown. ``` php -// Gets the duration. $duration = $step->getDuration(); ``` ### Start Location -It contains the location of the starting point of this step. It is represented by the -`Ivory\GoogleMap\Base\Coordinate`. +It contains the location of the starting point of this step. It is represented by the `Ivory\GoogleMap\Base\Coordinate`. ``` php -// Gets the start location. $startLocation = $step->getStartLocation(); ``` ### End Location -It contains the location of the ending point of this step. It is represented by the -`Ivory\GoogleMap\Base\Coordinate`. +It contains the location of the ending point of this step. It is represented by the `Ivory\GoogleMap\Base\Coordinate`. ``` php -// Gets the end location. $endLocation = $step->getEndLocation(); ``` @@ -285,25 +248,22 @@ $endLocation = $step->getEndLocation(); It contains formatted instructions for this step, presented as an HTML text string. ``` php -// Gets the instructions. $instructions = $step->getInstructions(); ``` ### Encoded polyline -It represents the step as an [encoded polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md). +It represents the step as an [encoded polyline](/doc/overlays/encoded_polyline.md). ``` php -// Gets the encoded polyline. $encodedPolyline = $step->getEncodedPolyline(); ``` ### Travel Mode -It contains the travel mode of this step. it is represented by the `Ivory\GoogleMap\Services\Base\TravelMode` +It contains the travel mode of this step. It is represented by the `Ivory\GoogleMap\Services\Base\TravelMode` constants. ``` php -// Gets the travel mode. $travelMode = $step->getTravelMode(); ``` diff --git a/doc/services/directions/directions_request.md b/doc/services/directions/directions_request.md new file mode 100644 index 00000000..7f034909 --- /dev/null +++ b/doc/services/directions/directions_request.md @@ -0,0 +1,100 @@ +# Directions Request + +## Build your directions request + +``` php +use Ivory\GoogleMap\Services\Directions\DirectionsRequest; + +$request = new DirectionsRequest('New York', 'Philadelphia'); +``` + +## Configure your directions request + +### Configure the origin + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$request->setOrigin('New York') +$request->setOrigin(new (1.1, 2.1)); +``` + +The origin can be either a string or an `Ivory\GoogleMap\Base\Coordinate`. + +### Configure the destination + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$request->setDestination('Washington'); +$request->setDestination(new Coordinate(2.1, 1.1)); +``` + +The destination can be either a string or an `Ivory\GoogleMap\Base\Coordinate`. + +### Configure the waypoints + +``` php +$request->addWaypoint('Philadelphia'); +$request->addWaypoint(1.2, 2.2, true); +``` + +The waypoints can be either a string or an `Ivory\GoogleMap\Base\Coordinate`. + +### Configure the optimize waypoints + +``` php +$request->setOptimizeWaypoints(true); +``` + +### Configure the avoid highways + +``` php +$request->setAvoidHighways(true); +``` + +### Configure the avoid tolls + +``` php +$request->setAvoidTolls(true); +``` + +### Configure the provide route alternatives + +``` php +$request->setProvideRouteAlternatives(true); +``` + +### Configure the region + +``` php +$request->setRegion('us'); +``` + +### Configure the language + +``` php +$request->setLanguage('en'); +``` + +### Configure the travel mode + +``` php +use Ivory\GoogleMap\Services\Base\TravelMode; + +$request->setTravelMode(TravelMode::DRIVING); +``` + +### Configure the unit system + +``` php +use Ivory\GoogleMap\Services\Base\UnitSystem; + +$request->setUnitSystem(UnitSystem::METRIC); +``` + +### Configure the sensor + +``` php +$request->setSensor(false); +``` diff --git a/doc/usage/services/distance_matrix/distance_matrix.md b/doc/services/distance_matrix/distance_matrix.md similarity index 64% rename from doc/usage/services/distance_matrix/distance_matrix.md rename to doc/services/distance_matrix/distance_matrix.md index be4ec90b..cadd8af6 100644 --- a/doc/usage/services/distance_matrix/distance_matrix.md +++ b/doc/services/distance_matrix/distance_matrix.md @@ -1,48 +1,50 @@ # Distance Matrix API -The Distance Matrix API uses [widop/http-adapter](http://github.com/widop/http-adapter) which is a PHP 5.3 library for -issuing http requests. +The Distance Matrix API uses [egeloen/http-adapter](http://github.com/egeloen/ivory-http-adapter) which is a PHP 5.3 +library for issuing http requests. The Google Distance Matrix API is a service that provides travel distance and time for a matrix of origins and destinations. The information returned is based on the recommended route between start and end points, as calculated by the Google Maps API, and consists of rows containing duration and distance values for each pair. This service does not return detailed route information. Route information can be obtained by passing the desired -single origin and destination to the -[Directions API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/directions/directions.md). +single origin and destination to the [Directions API](/doc/services/directions/directions.md). -## Request the distance matrix service +## Build your distance matrix service ``` php use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrix; -use Widop\HttpAdapter\CurlHttpAdapter; +use Ivory\HttpAdapter\SocketHttpAdapter; -$distanceMatrix = new DistanceMatrix(new CurlHttpAdapter()); +$distanceMatrix = new DistanceMatrix(new SocketHttpAdapter()); ``` -If you want to use it with a business account, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/business_account.md). +If you want to use it with a business account, you can read this [documentation](/doc/services/business_account.md). -## Processes a request +## Process a request ``` php -$response = $distanceMatrix->process(array('Vancouver BC'), array('San Francisco')); +use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest; + +$response = $distanceMatrix->process(new DistanceMatrixRequest( + array('Vancouver BC'), + array('San Francisco') +)); ``` -The distance matrix allows you to proceess a much more advanced request. If you want to lear more, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/distance_matrix/distance_matrix_request.md). +If you want to learn more about the distance matrix request, you can read this +[documentation](/doc/services/distance_matrix/distance_matrix_request.md). ## Distance matrix response When you have requested your distance matrix, the returned object is an -``Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse``. It wraps a status, origins, destinations and rows. +`Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse`. It wraps a status, origins, destinations and rows. ### Distance matrix status -The available status are defined by the ``Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixStatus`` constants. +The available status are defined by the `Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixStatus` constants. ``` php -// Get the status $status = $response->getStatus(); ``` @@ -52,7 +54,6 @@ It contains an array of addresses as returned by the API from your original requ geocoder and localized according to the language parameter passed with the request. ``` php -// Get the origins $origins = $response->getOrigins(); ``` @@ -62,11 +63,10 @@ It contains an array of addresses as returned by the API from your original requ these are localized if appropriate. ``` php -// Get the destinations $destinations = $response->getDestinations(); ``` -### Directions rows +### Distance matrix rows When the Distance Matrix API returns results, it places them within a rows array. Even if no results are returned (such as when the origins and/or destinations don't exist), it still returns an empty array. Rows are ordered according @@ -77,12 +77,23 @@ Each row array contains one or more distance matrix element entries, which in tu single origin-destination pairing. ``` php -// Get the rows -foreach ($rows as $row) { - $elements = $row->getElements(); +$rows = $response->getRows(); +``` + +## Distance matrix row + +``` php +foreach ($response->getRows() as $row) { + } ``` +### Distance matrix elements + +``` php +$elements = $row->getElements(); +``` + ## Distance matrix element The information about each origin-destination pairing is represented by the @@ -90,14 +101,14 @@ The information about each origin-destination pairing is represented by the a distance. ``` php -foreach ($elements as $element) { - // Play with distance matrix element. +foreach ($row->getElements() as $element) { + } ``` ### Distance matrix element status -The available status are defined by the ``Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixElementStatus`` +The available status are defined by the `Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixElementStatus` constants. ``` php diff --git a/doc/services/distance_matrix/distance_matrix_request.md b/doc/services/distance_matrix/distance_matrix_request.md new file mode 100644 index 00000000..1da95c27 --- /dev/null +++ b/doc/services/distance_matrix/distance_matrix_request.md @@ -0,0 +1,78 @@ +# Distance Matrix Request + +## Build your distance matrix request + +``` php +use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest; + +$request = new DistanceMatrixRequest( + array('New York'), + array('Washington') +); +``` + +## Configure your distance matrix request + +### Configure the origins + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$request->setOrigins(array('New York')); +$request->setOrigins(array(new Coordinate(1.1, 2.1))); +``` + +### Configure the destinations + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$request->setDestinations(array('Washington')); +$request->setDestinations(array(new Coordinate(2.1, 1.1))); +``` + +### Configure the avoid highways + +``` php +$request->setAvoidHighways(true); +``` + +### Configure the avoid tolls + +``` php +$request->setAvoidTolls(true); +``` + +### Configure the region + +``` php +$request->setRegion('us'); +``` + +### Configure the language + +``` php +$request->setLanguage('en'); +``` + +### Configure the travel mode + +``` php +use Ivory\GoogleMap\Services\Base\TravelMode; + +$request->setTravelMode(TravelMode::DRIVING); +``` + +### Configure the unit system + +``` php +use Ivory\GoogleMap\Services\Base\UnitSystem; + +$request->setUnitSystem(UnitSystem::METRIC); +``` + +### Configure the sensor + +``` php +$request->setSensor(false); +``` diff --git a/doc/services/geocoding/geocoder.md b/doc/services/geocoding/geocoder.md new file mode 100644 index 00000000..f6f10505 --- /dev/null +++ b/doc/services/geocoding/geocoder.md @@ -0,0 +1,53 @@ +# Geocoding API + +The Geocoding API uses [Geocoder](http://github.com/willdurand/Geocoder) which is a PHP 5.3 library for issuing +Geocoding. So, first, I would recommend you to read his documentation. + +Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic +coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. +Additionally, the service allows you to perform the converse operation (turning coordinates into addresses). This +process is known as "reverse geocoding". + +## Create your geocoder + +``` php +use Ivory\GoogleMap\Services\Geocoding\Geocoder; + +$geocoder = new Geocoder(); +``` + +## Configure your geocoder + +``` php +use Ivory\GoogleMap\Services\Geocoding\GeocoderProvider; +use Geocoder\HttpAdapter\CurlHttpAdapter; + +$geocoder->registerProviders(array( + new GeocoderProvider(new CurlHttpAdapter()), +)); +``` + +### The standard geocoder + +If you use the standard Geocoder components, I recommend you to directly read this own documentation available +[here](http://www.geocoder-php.org). + +### The Ivory geocoder + +The specific Ivory Google Map Geocoder has been added to allow you to geocode a very advanced request & use the +response to directly build your overlays without having to construct the objects by yourself. If you are interested +about this geocoder, the documentation is available [here](/doc/services/geocoding/ivory_geocoder.md). + +## Geocode your request + +``` php +use Ivory\GoogleMap\Services\Geocoding\GeocoderRequest; + +$request = new GeocoderRequest(); + +// Geocode your request +$response = $geocoder->geocode($request); +``` + +If you want to learn more about the geocoder request, you can read this +[documentation](/doc/services/geocoding/geocoder_request.md). diff --git a/doc/services/geocoding/geocoder_request.md b/doc/services/geocoding/geocoder_request.md new file mode 100644 index 00000000..7076d8eb --- /dev/null +++ b/doc/services/geocoding/geocoder_request.md @@ -0,0 +1,45 @@ +# Geocoder Request + +## Create your geocoder request + +``` php +use Ivory\GoogleMap\Services\Geocoding\GeocoderRequest; + +$request = new GeocoderRequest(); +``` + +## Configure your geocoder request + +### Configure your location + +``` php +use Ivory\GoogleMap\Base\Coordinate; + +$request->setLocation('1600 Amphitheatre Parkway, Mountain View, CA'); +// or +$request->setCoordinate(new Coordinate(1.1, 2.1)); +``` + +### Configure the bound + +``` php +$request->setBound(-1.1, -2.1, 2.1, 1.1, true, true); +``` + +### Configure the region + +``` php +$request->setRegion('en'); +``` + +### Configure the language + +``` php +$request->setLanguage('en'); +``` + +### Configure the sensor + +``` php +$request->setSensor(false); +``` diff --git a/doc/usage/services/geocoding/ivory_geocoder.md b/doc/services/geocoding/ivory_geocoder.md similarity index 83% rename from doc/usage/services/geocoding/ivory_geocoder.md rename to doc/services/geocoding/ivory_geocoder.md index fd4022e6..8fd07039 100644 --- a/doc/usage/services/geocoding/ivory_geocoder.md +++ b/doc/services/geocoding/ivory_geocoder.md @@ -8,7 +8,7 @@ The library allows you to request the google map geocoding API by two different simple address (IP or street) or an advanced geocoder request. If you want to use it with a business account, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/business_account.md). +[documentation](/doc/services/business_account.md). ### Simple address @@ -29,16 +29,16 @@ $response = $geocoder->geocode('1600 Amphitheatre Parkway, Mountain View, CA'); ### Advanced geocoder request If you want to build an advanced request, read this specific -[documenation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/geocoding/geocoder_request.md). +[documenation](/doc/services/geocoding/geocoder_request.md). ## Geocoder response -When you have requested your position, the returned object is an ``Ivory\GoogleMap\Services\Geocoding\GeocoderResponse``. +When you have requested your position, the returned object is an `Ivory\GoogleMap\Services\Geocoding\GeocoderResponse`. It wraps a geocoder status & geocoder results. ### Geocoder status -The available status are defined by the ``Ivory\GoogleMap\Services\Geocoding\GeocoderStatus`` constants. +The available status are defined by the `Ivory\GoogleMap\Services\Geocoding\GeocoderStatus` constants. ``` php // Get the geocoder status @@ -47,7 +47,7 @@ $status = $response->getStatus(); ### Geocoder results -A request can return many results. The geocoder response wraps an array of ``Ivory\GoogleMap\Services\Geocoding\GeocoderResult``. +A request can return many results. The geocoder response wraps an array of `Ivory\GoogleMap\Services\Geocoding\GeocoderResult`. ``` php // Get the geocoder results @@ -61,7 +61,7 @@ types. #### Human readable address -The method ``getFormattedAddress`` is a string containing the human-readable address of this location. Often this +The method `getFormattedAddress` is a string containing the human-readable address of this location. Often this address is equivalent to the "postal address," which sometimes differs from country to country. (Note that some countries, such as the United Kingdom, do not allow distribution of true postal addresses due to licensing restrictions). @@ -78,7 +78,7 @@ foreach ($results as $result) { #### Address informations -The method ``getAddressComponents`` returns an array containing the separate address components. Each address_component +The method `getAddressComponents` returns an array containing the separate address components. Each address_component typically contains: - types which is an array indicating the type of the address component. @@ -116,12 +116,12 @@ foreach ($results as $result) { Geometry contains the following information: - - location which is an ``Ivory\GoogleMap\Base\Coordinate``. + - location which is an `Ivory\GoogleMap\Base\Coordinate`. - location type stores additional data about the specified location. The available possibilites are describes by the - ``Ivory\GoogleMap\Services\Geocoding\GeocoderLocationType`` constants. - - viewport which contains the recommended viewport for displaying the returned result, specified as ``Ivory\GoogleMap\Base\Bound``. + `Ivory\GoogleMap\Services\Geocoding\GeocoderLocationType` constants. + - viewport which contains the recommended viewport for displaying the returned result, specified as `Ivory\GoogleMap\Base\Bound`. - bounds (optionally returned) which stores the bounding box which can fully contain the returned result, specified as - ``Ivory\GoogleMap\Base\Bound``. Note that these bounds may not match the recommended viewport. + `Ivory\GoogleMap\Base\Bound`. Note that these bounds may not match the recommended viewport. ``` php // Get the geocoder results @@ -188,7 +188,7 @@ foreach ($response->getResults() as $result) { // Position the marker $marker->setPosition($result->getGeometry()->getLocation()); - // Add the marker to the map + // Add the marker on the map $map->addMarker($marker); } ``` diff --git a/doc/services/index.md b/doc/services/index.md new file mode 100644 index 00000000..48500e1a --- /dev/null +++ b/doc/services/index.md @@ -0,0 +1,11 @@ +# Google Map API Services + +The Google Maps Web Services are a collection of HTTP interfaces to Google services providing geographic data for your +maps applications. + + 1. [Directions API](/doc/services/directions/directions.md) + 2. [Distance Matrix API](/doc/services/distance_matrix/distance_matrix.md) + 3. [Geocoding API](/doc/services/geocoding/geocoder.md) + +Additionally, all services can be configured with a google business account as documented +[here](/doc/services/business_account.md) diff --git a/doc/usage.md b/doc/usage.md index 0ae06012..c6a10037 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -6,7 +6,11 @@ for the next parts. ## Build your map -First of all, if you want to render a map, you will need to build one. So let's go: +The Map is the central point of the library. It allows you to manipulate all available options. If you render the +default map, the library will generate a map of 300px by 300px, centered on the coordinate (0, 0), configured with a +zoom of 3 and using the default controls. + +Example: ``` php use Ivory\GoogleMap\Map; @@ -14,137 +18,34 @@ use Ivory\GoogleMap\Map; $map = new Map(); ``` -The Map is the central point of the library. It allows you to manipulate all available options. If you render the -default map, the library will generate a map of 300px by 300px, centered on the coordinate (0, 0), configured with a -zoom of 3 & using the default controls. - ## Configure your map -Now, you have a map, you can configure it easily. The complete map configuration is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/map.md). - -### Configure overlays - -Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom -the map. Overlays reflect objects that you "add" to the map to designate points, lines, areas, or collections of -objects. - - 1. [Marker](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker.md) - 2. [Info window](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_window.md) - 3. [Info box](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_box.md) - 4. [Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polyline.md) - 5. [Encoded Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md) - 6. [Polygon](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polygon.md) - 7. [Rectangle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/rectangle.md) - 8. [Circle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/circle.md) - 9. [Ground overlay](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/ground_overlay.md) - 10. [Marker cluster](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_cluster.md) - -### Configure controls - -The maps on Google Maps contain UI elements for allowing user interaction through the map. These elements are known as -``controls`` and you can include variations of these controls in your Google Maps API application. Alternatively, you -can do nothing and let the Google Maps API handle all control behavior. - - 1. [Map type control](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/map_type.md) - 2. [Overview](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/overview.md) - 3. [Pan](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/pan.md) - 4. [Rotate](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/rotate.md) - 5. [Scale](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/scale.md) - 6. [Street view](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/street_view.md) - 7. [Zoom](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/zoom.md) +Now, you have a map, you can configure it easily. The map configuration is available [here](/doc/map.md). -### Configure events +Example: -The complete events configuration is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/events.md). - -### Configure additional libraries - -Sometimes, you want to use the map & other Google Map related libraries. The bundle provides many integrations but not -all of them. If you need a custom libraries, you can use the following API on your map: +``` php +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Overlays\Marker; -``` -$map->setLibraries(array('places', 'geometry')); -$libraries = $map->getLibraries(); -$hasLibraries = $map->hasLibraries(); +$map->getOverlays()->addMarker(new Marker(new Coordinate(1.1, 2.2))); ``` ## Render your map -Now, you have builded & configured your map, you can render it. For this purpose, you will need the -`Ivory\GoogleMap\Helper\MapHelper` which allows to render the map html container & some javascript for being -able to render it. - -``` -use Ivory\GoogleMap\Helper\MapHelper; - -$mapHelper = new MapHelper(); -``` - -### Render the HTML container - -``` -echo $mapHelper->renderHtmlContainer($map); -``` - -This function renders an html div block with the HTML container ID, the width & the height configured: - -``` html -
-``` - -### Render the javascript - -``` -echo $mapHelper->renderJavascripts($map); -``` - -This function renders an html javascript block with all code needed for displaying your map. - -``` html - -``` - -The generated code is organized to be reusable in the client side. If you want to learn more, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/helper/container.md). +Now, you have builded and configured your map, you can render it. The map rendering documentation is available +[here](/doc/helpers/rendering.md). -Additionally, the library allows you to add/render your own javascript libraires and append some code just before or -after the generated code through extensions. If you want to learn more about that, you can read this -[documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/helper/extension.md). +Example: -### Render the CSS (Optional) - -Additionally, you can configure some CSS directly on the map. - -``` -echo $mapHelper->renderStylesheets($map); -``` +``` php +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; -This function renders an html style block with the CSS configured. +$helperFactory = new HelperFactory(); -``` html - -``` +$mapHelper = $helperFactory->createMapHelper(); +$apiHelper = $helperFactory->createApiHelper(); -If you want to render all of them, you can use: - -``` echo $mapHelper->render($map); +echo $apiHelper->render(array($map)); ``` - -``` html - -
- -``` - -There is many other methods you can use if you only render specific "parts" of the map. I let you read the class :) diff --git a/doc/usage/controls/index.md b/doc/usage/controls/index.md deleted file mode 100644 index 0f709748..00000000 --- a/doc/usage/controls/index.md +++ /dev/null @@ -1,13 +0,0 @@ -# Controls - -The maps on Google Maps contain UI elements for allowing user interaction through the map. These elements are known as -controls and you can include variations of these controls in your Google Maps API application. Alternatively, you can -do nothing and let the Google Maps API handle all control behavior. - - 1. [Map type](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/map_type.md) - 2. [Overview](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/overview.md) - 3. [Pan](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/pan.md) - 4. [Rotate](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/rotate.md) - 5. [Scale](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/scale.md) - 6. [Street view](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/street_view.md) - 7. [Zoom](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/zoom.md) diff --git a/doc/usage/controls/map_type.md b/doc/usage/controls/map_type.md deleted file mode 100644 index 69071327..00000000 --- a/doc/usage/controls/map_type.md +++ /dev/null @@ -1,143 +0,0 @@ -# Map type control - -The map type control lets the user toggle between map types (such as ROADMAP and SATELLITE). This control appears by -default in the top right corner of the map. - -## Build your map type control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\MapTypeId; - -$mapTypeControl = new MapTypeControl(); - -// Configure your map type control -$mapTypeControl->setMapTypeIds(array(MapTypeId::ROADMAP, MapTypeId::SATELLITE)); - -$mapTypeControl->addMapTypeId(MapTypeId::ROADMAP); -$mapTypeControl->addMapTypeId(MapTypeId::SATELLITE); - -$mapTypeControl->setControlPosition(ControlPosition::TOP_RIGHT); - -$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::DEFAULT_); -``` - -## Configure the map type control IDs - -For configurating the map type ids, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\MapTypeId`` is here. It allows you to access all constants which describe map types. If you don't -want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\MapTypeId; -use Ivory\GoogleMap\Controls\MapTypeControl; - -$mapTypeControl = new MapTypeControl(); - -// Add your map type -$mapTypeControl->addMapTypeId(MapTypeId::HYBRID); -$mapTypeControl->addMapTypeId('hybrid'); - -$mapTypeControl->addMapTypeId(MapTypeId::ROADMAP); -$mapTypeControl->addMapTypeId('roadmap'); - -$mapTypeControl->addMapTypeId(MapTypeId::SATELLITE); -$mapTypeControl->addMapTypeId('satellite'); - -$mapTypeControl->addMapTypeId(MapTypeId::TERRAIN); -$mapTypeControl->addMapTypeId('terrain'); -``` - -## Configure the map type control position - -For configurating the map type control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControl; - -$mapTypeControl = new MapTypeControl(); - -// Sets your control position -$mapTypeControl->setControlPosition(ControlPosition::TOP_LEFT); -$mapTypeControl->setControlPosition('top_left'); - -$mapTypeControl->setControlPosition(ControlPosition::TOP_CENTER); -$mapTypeControl->setControlPosition('top_center'); - -$mapTypeControl->setControlPosition(ControlPosition::TOP_RIGHT); -$mapTypeControl->setControlPosition('top_right'); - -$mapTypeControl->setControlPosition(ControlPosition::LEFT_TOP); -$mapTypeControl->setControlPosition('left_top'); - -$mapTypeControl->setControlPosition(ControlPosition::LEFT_CENTER); -$mapTypeControl->setControlPosition('left_center'); - -$mapTypeControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$mapTypeControl->setControlPosition('left_bottom'); - -$mapTypeControl->setControlPosition(ControlPosition::RIGHT_TOP); -$mapTypeControl->setControlPosition('right_top'); - -$mapTypeControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$mapTypeControl->setControlPosition('right_center'); - -$mapTypeControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$mapTypeControl->setControlPosition('right_bottom'); - -$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$mapTypeControl->setControlPosition('bottom_left'); - -$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$mapTypeControl->setControlPosition('bottom_center'); - -$mapTypeControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$mapTypeControl->setControlPosition('bottom_right'); -``` - -## Configure the map type control style - -For configurating the map type control style, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\MapTypeControlStyle`` is here. It allows you to access all constants which describe map type -control style. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; - -$mapTypeControl = new MapTypeControl(); - -// Sets your map type control style -$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::DEFAULT_); -$mapTypeControl->setMapTypeControlStyle('default'); - -$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::DROPDOWN_MENU); -$mapTypeControl->setMapTypeControlStyle('dropdown_menu'); - -$mapTypeControl->setMapTypeControlStyle(MapTypeControlStyle::HORIZONTAL_BAR); -$mapTypeControl->setMapTypeControlStyle('horizontal_bar'); -``` - -## Add your map type control to the map - -``` php -use Ivory\GoogleMapBundle\Model\MapTypeId; -use Ivory\GoogleMapBundle\Model\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMapBundle\Model\Controls\MapTypeControlStyle; - -$mapTypeControl = new MapTypeControl(); - -// Add your map type control to the map -$map->setMapTypeControl($mapTypeControl); -$map->setMapTypeControl( - array(MapTypeId::ROADMAP, MapTypeId::SATELLITE), - ControlPosition::TOP_RIGHT, - MapTypeControlStyle::DEFAULT_ -); -``` diff --git a/doc/usage/controls/pan.md b/doc/usage/controls/pan.md deleted file mode 100644 index 0a8c1218..00000000 --- a/doc/usage/controls/pan.md +++ /dev/null @@ -1,79 +0,0 @@ -# Pan control - -The Pan control displays buttons for panning the map. This control appears by default in the top left corner of the -map on non-touch devices. The Pan control also allows you to rotate 45° imagery, if available. - -## Build your pan control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\PanControl; - -$panControl = new PanControl(); - -// Configure your pan control -$panControl->setControlPosition(ControlPosition::TOP_LEFT); -``` - -## Configure the pan control position - -For configurating the pan control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\PanControl; - -$panControl = new PanControl(); - -// Sets your control position -$panControl->setControlPosition(ControlPosition::TOP_LEFT); -$panControl->setControlPosition('top_left'); - -$panControl->setControlPosition(ControlPosition::TOP_CENTER); -$panControl->setControlPosition('top_center'); - -$panControl->setControlPosition(ControlPosition::TOP_RIGHT); -$panControl->setControlPosition('top_right'); - -$panControl->setControlPosition(ControlPosition::LEFT_TOP); -$panControl->setControlPosition('left_top'); - -$panControl->setControlPosition(ControlPosition::LEFT_CENTER); -$panControl->setControlPosition('left_center'); - -$panControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$panControl->setControlPosition('left_bottom'); - -$panControl->setControlPosition(ControlPosition::RIGHT_TOP); -$panControl->setControlPosition('right_top'); - -$panControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$panControl->setControlPosition('right_center'); - -$panControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$panControl->setControlPosition('right_bottom'); - -$panControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$panControl->setControlPosition('bottom_left'); - -$panControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$panControl->setControlPosition('bottom_center'); - -$panControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$panControl->setControlPosition('bottom_right'); -``` - -## Add your pan control to the map - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\PanControl; - -$panControl = new PanControl(); - -// Add your pan control to the map -$map->setPanControl($panControl); -$map->setPanControl(ControlPosition::TOP_LEFT); -``` diff --git a/doc/usage/controls/rotate.md b/doc/usage/controls/rotate.md deleted file mode 100644 index 028b1c48..00000000 --- a/doc/usage/controls/rotate.md +++ /dev/null @@ -1,79 +0,0 @@ -# Rotate control - -The Rotate control contains a small circular icon which allows you to rotate maps containing oblique imagery. This -control appears by default in the top left corner of the map. - -## Build your rotate control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\RotateControl; - -$rotateControl = new RotateControl(); - -// Configure your rotate control -$rotateControl->setControlPosition(ControlPosition::TOP_LEFT); -``` - -## Configure the rotate control position - -For configurating the rotate control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\RotateControl; - -$rotateControl = new RotateControl(): - -// Sets your control position -$rotateControl->setControlPosition(ControlPosition::TOP_LEFT); -$rotateControl->setControlPosition('top_left'); - -$rotateControl->setControlPosition(ControlPosition::TOP_CENTER); -$rotateControl->setControlPosition('top_center'); - -$rotateControl->setControlPosition(ControlPosition::TOP_RIGHT); -$rotateControl->setControlPosition('top_right'); - -$rotateControl->setControlPosition(ControlPosition::LEFT_TOP); -$rotateControl->setControlPosition('left_top'); - -$rotateControl->setControlPosition(ControlPosition::LEFT_CENTER); -$rotateControl->setControlPosition('left_center'); - -$rotateControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$rotateControl->setControlPosition('left_bottom'); - -$rotateControl->setControlPosition(ControlPosition::RIGHT_TOP); -$rotateControl->setControlPosition('right_top'); - -$rotateControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$rotateControl->setControlPosition('right_center'); - -$rotateControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$rotateControl->setControlPosition('right_bottom'); - -$rotateControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$rotateControl->setControlPosition('bottom_left'); - -$rotateControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$rotateControl->setControlPosition('bottom_center'); - -$rotateControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$rotateControl->setControlPosition('bottom_right'); -``` - -## Add your rotate control to the map - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\RotateControl; - -$rotateControl = new RotateControl(); - -// Add your rotate control to the map -$map->setRotateControl($rotateControl); -$map->setRotateControl(ControlPosition::TOP_LEFT); -``` diff --git a/doc/usage/controls/scale.md b/doc/usage/controls/scale.md deleted file mode 100644 index 2db0e804..00000000 --- a/doc/usage/controls/scale.md +++ /dev/null @@ -1,97 +0,0 @@ -# Scale control - -The Scale control displays a map scale element. This control is not enabled by default. - -## Build your scale control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Controls\ScaleControlStyle; - -$scaleControl = new ScaleControl(); - -// Configure your scale control -$scaleControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$scaleControl->setScaleControlStyle(ScaleControlStyle::DEFAULT_); -``` - -## Configure your scale control position - -For configurating the pan control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ScaleControl; - -$scaleControl = new ScaleControl(); - -// Sets your control position -$scaleControl->setControlPosition(ControlPosition::TOP_LEFT); -$scaleControl->setControlPosition('top_left'); - -$scaleControl->setControlPosition(ControlPosition::TOP_CENTER); -$scaleControl->setControlPosition('top_center'); - -$scaleControl->setControlPosition(ControlPosition::TOP_RIGHT); -$scaleControl->setControlPosition('top_right'); - -$scaleControl->setControlPosition(ControlPosition::LEFT_TOP); -$scaleControl->setControlPosition('left_top'); - -$scaleControl->setControlPosition(ControlPosition::LEFT_CENTER); -$scaleControl->setControlPosition('left_center'); - -$scaleControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$scaleControl->setControlPosition('left_bottom'); - -$scaleControl->setControlPosition(ControlPosition::RIGHT_TOP); -$scaleControl->setControlPosition('right_top'); - -$scaleControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$scaleControl->setControlPosition('right_center'); - -$scaleControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$scaleControl->setControlPosition('right_bottom'); - -$scaleControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$scaleControl->setControlPosition('bottom_left'); - -$scaleControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$scaleControl->setControlPosition('bottom_center'); - -$scaleControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$scaleControl->setControlPosition('bottom_right'); -``` - -## Configure your scale control style - -For configurating the scale control style, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ScaleControlStyle`` is here. It allows you to access all constants which describe scale -control style. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Controls\ScaleControlStyle; - -$scaleControl = new ScaleControl(); - -// Sets your scale control style -$scaleControl->setScaleControlStyle(ScaleControlStyle::DEFAULT_); -``` - -## Add your scale control to the map - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Controls\ScaleControlStyle; - -$scaleControl = new ScaleControl(); - -// Add your scale control to the map -$map->setScaleControl($scaleControl); -$map->setScaleControl(ControlPosition::BOTTOM_LEFT, ScaleControlStyle::DEFAULT_); -``` diff --git a/doc/usage/controls/street_view.md b/doc/usage/controls/street_view.md deleted file mode 100644 index 9101a3b0..00000000 --- a/doc/usage/controls/street_view.md +++ /dev/null @@ -1,79 +0,0 @@ -# Street view control - -The Street View control contains a Pegman icon which can be dragged onto the map to enable Street View. This control -appears by default in the top left corner of the map. - -## Build your street view control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\StreetViewControl; - -$streetViewControl = new StreetViewControl(); - -// Configure your street view control -$streetViewControl->setControlPosition(ControlPosition::TOP_LEFT); -``` - -## Configure the street view control position - -For configurating the street view control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\StreetViewControl; - -$streetViewControl = new StreetViewControl(); - -// Sets your control position -$streetViewControl->setControlPosition(ControlPosition::TOP_LEFT); -$streetViewControl->setControlPosition('top_left'); - -$streetViewControl->setControlPosition(ControlPosition::TOP_CENTER); -$streetViewControl->setControlPosition('top_center'); - -$streetViewControl->setControlPosition(ControlPosition::TOP_RIGHT); -$streetViewControl->setControlPosition('top_right'); - -$streetViewControl->setControlPosition(ControlPosition::LEFT_TOP); -$streetViewControl->setControlPosition('left_top'); - -$streetViewControl->setControlPosition(ControlPosition::LEFT_CENTER); -$streetViewControl->setControlPosition('left_center'); - -$streetViewControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$streetViewControl->setControlPosition('left_bottom'); - -$streetViewControl->setControlPosition(ControlPosition::RIGHT_TOP); -$streetViewControl->setControlPosition('right_top'); - -$streetViewControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$streetViewControl->setControlPosition('right_center'); - -$streetViewControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$streetViewControl->setControlPosition('right_bottom'); - -$streetViewControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$streetViewControl->setControlPosition('bottom_left'); - -$streetViewControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$streetViewControl->setControlPosition('bottom_center'); - -$streetViewControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$streetViewControl->setControlPosition('bottom_right'); -``` - -## Add your street view control to the map - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\StreetViewControl; - -$streetViewControl = new StreetViewControl(); - -// Add your street view control to the map -$map->setStreetViewControl($streetViewControl); -$map->setStreetViewControl(ControlPosition::TOP_LEFT); -``` diff --git a/doc/usage/controls/zoom.md b/doc/usage/controls/zoom.md deleted file mode 100644 index e5cf2ec1..00000000 --- a/doc/usage/controls/zoom.md +++ /dev/null @@ -1,106 +0,0 @@ -# Zoom control - -The Zoom control displays a slider (for large maps) or small "+/-" buttons (for small maps) to control the zoom level -of the map. This control appears by default in the top left corner of the map on non-touch devices or in the bottom -left corner on touch devices. - -## Build your zoom control - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Controls\ZoomControlStyle; - -$zoomControl = new ZoomControl(); - -// Configure your zoom control -$zoomControl->setControlPosition(ControlPosition::TOP_LEFT); -$zoomControl->setZoomControlStyle(ZoomControlStyle::DEFAULT_); -``` - -## Configure your zoom control position - -For configurating the zoom control position, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ControlPosition`` is here. It allows you to access all constants which describe control -position. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ZoomControl; - -$zoomControl = new ZoomControl(); - -// Sets your control position -$zoomControl->setControlPosition(ControlPosition::TOP_LEFT); -$zoomControl->setControlPosition('top_left'); - -$zoomControl->setControlPosition(ControlPosition::TOP_CENTER); -$zoomControl->setControlPosition('top_center'); - -$zoomControl->setControlPosition(ControlPosition::TOP_RIGHT); -$zoomControl->setControlPosition('top_right'); - -$zoomControl->setControlPosition(ControlPosition::LEFT_TOP); -$zoomControl->setControlPosition('left_top'); - -$zoomControl->setControlPosition(ControlPosition::LEFT_CENTER); -$zoomControl->setControlPosition('left_center'); - -$zoomControl->setControlPosition(ControlPosition::LEFT_BOTTOM); -$zoomControl->setControlPosition('left_bottom'); - -$zoomControl->setControlPosition(ControlPosition::RIGHT_TOP); -$zoomControl->setControlPosition('right_top'); - -$zoomControl->setControlPosition(ControlPosition::RIGHT_CENTER); -$zoomControl->setControlPosition('right_center'); - -$zoomControl->setControlPosition(ControlPosition::RIGHT_BOTTOM); -$zoomControl->setControlPosition('right_bottom'); - -$zoomControl->setControlPosition(ControlPosition::BOTTOM_LEFT); -$zoomControl->setControlPosition('bottom_left'); - -$zoomControl->setControlPosition(ControlPosition::BOTTOM_CENTER); -$zoomControl->setControlPosition('bottom_center'); - -$zoomControl->setControlPosition(ControlPosition::BOTTOM_RIGHT); -$zoomControl->setControlPosition('bottom_right'); -``` - -## Configure your zoom control style - -For configurating the zoom control style, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Controls\ZoomControlStyle`` is here. It allows you to access all constants which describe zoom -control style. If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Controls\ZoomControlStyle; - -$zoomControl = new ZoomControl(); - -// Sets your zoom control style -$zoomControl->setZoomControlStyle(ZoomControlStyle::DEFAULT_); -$zoomControl->setZoomControlStyle('default'); - -$zoomControl->setZoomControlStyle(ZoomControlStyle::LARGE); -$zoomControl->setZoomControlStyle('large'); - -$zoomControl->setZoomControlStyle(ZoomControlStyle::SMALL); -$zoomControl->setZoomControlStyle('small'); -``` - -## Add your zoom control to the map - -``` php -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Controls\ZoomControlStyle; - -$zoomControl = new ZoomControl(); - -// Add your zoom control to the map -$map->setZoomControl($zoomControl); -$map->setZoomControl(ControlPosition::TOP_LEFT, ZoomControlStyle::DEFAULT_); -``` diff --git a/doc/usage/events.md b/doc/usage/events.md deleted file mode 100644 index 00e93f66..00000000 --- a/doc/usage/events.md +++ /dev/null @@ -1,76 +0,0 @@ -# Events - -JavaScript within the browser is event driven, meaning that JavaScript responds to interactions by generating events, -and expects a program to listen to interesting events. The event model for the Google Maps API V3 is similar to that -used in V2 of the API, though much has changed under the hood. There are two types of events: - - - User events (such as "click" mouse events) are propagated from the DOM to the Google Maps API. These events are - separate and distinct from standard DOM events. - - MVC state change notifications reflect changes in Maps API objects and are named using a property_changed convention. - -## Build your event - -``` php -use Ivory\GoogleMap\Events\Event; - -$event = new Event(); - -// Configure your event -$event->setInstance($instance); -$event->setEventName($eventName); -$event->setHandle($handle); - -// It can only be used with a DOM event -// By default, the capture flag is false -$event->setCapture(true); -``` - -### Instance - -The ``$instance`` variable describes the javascript variable which registers the event. Each Ivory google map objects -which can register an event have a method called ``getJavascriptVariable`` which identifies this variable. - -For example, in the case of an info window, it can be: - -``` php -$instance = $infoWindow->getJavascriptVariable(); -``` - -### Event name - -Each object has his own event name which are described in the google map documentation. - -### Handle - -The ``$handle`` is the javascript function which is executed when the event is triggered. - -For example, it can be: - -``` php -$handle = 'function(){alert("The event has been triggered");}' -``` - -## Add your event to the map - -The map wraps an event manager which allows you to add events. Like describes in the introduction, two differents type -of event can be used. - -### DOM event - -``` php -// Add a DOM event -$map->getEventManager()->addDomEvent($event); - -// Add a DOM event which will be triggered only one time -$map->getEventManager()->addDomEventOnce($event); -``` - -### MVC event - -``` php -// Add an event -$map->getEventManager()->addEvent($event); - -// Add an event which will be triggered only one time -$map->getEventManager()->addEventOnce($event); -``` diff --git a/doc/usage/helper/container.md b/doc/usage/helper/container.md deleted file mode 100644 index 604e8668..00000000 --- a/doc/usage/helper/container.md +++ /dev/null @@ -1,78 +0,0 @@ -# JS Container - -When you call `$mapHelper->renderJavascripts($map)`, the library will generate for you all needed JS code for -displaying your map. Obviously, it is not the anarchy, all the sheet is organized in order to reuse created objects in -the client side (your JS scripts). - -As explain in the doc, a map has a javascript variable which is used to render the code. For example, you have a -map with `my_map` as javascript variable, then the output will be: - -``` -my_map = new new google.maps.Map(/* ... */); -``` - -There is many objects which have a javascript variable (coordinates, markers, etc). All these objects are rendered like -a map (except for the instanciation part :)). So, you can use every objects though his javascript variable. - -Additionally, a container is builded for each map in order to more easily reuse all the related objects of a map -instead of directly relying on each javascript variable. For a map named `my_map`, the output will be: - -``` -my_map_container = { - // Base - "coordinates": {}, - "bounds": {}, - "points: {}, - "sizes": {}, - - // Map - map: null, - - // Overlays - "circles": {}, - "encoded_polylines": {}, - "ground_overlays": {}, - "polygons": {}, - "polylines": {}, - "rectangles": {}, - "info_windows": {}, - "marker_images": {}, - "marker_shapes": {}, - "markers": {}, - "marker_cluster": null, - - // Layers - "kml_layers": {}, - - // Event Manager - "event_manager": { - "dom_events": {}, - "dom_events_once": {}, - "events": {}, - "events_once": {} - }, - - // Internal - "closable_info_windows": {} - "functions": { - "to_array": function { /* ... */ } - } -} -``` - -Each objects is aliased by his javascript variable in the container. If you have a circle named "my_circle", then you -can access it like that: - -``` -var my_circle = my_map_container.circles.my_circle; -``` - -If you want to iterate all markers on you map, you can easily archieve it: - -``` -for (marker in my_map_container.markers) { - var my_marker = my_map_container.markers[marker]; - - // Do what you want with your marker... -} -``` diff --git a/doc/usage/helper/extension.md b/doc/usage/helper/extension.md deleted file mode 100644 index d6e22ebe..00000000 --- a/doc/usage/helper/extension.md +++ /dev/null @@ -1,70 +0,0 @@ -# Extension - -An extension helper allows you to add/render additional libraries and/or append some javascript code just before/after -the generated one. To understand how it works, you will dig into a simple example. - -First, you need to create your own extension: - -``` php -namespace My\Own\Helper\Extension; - -use Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface; -use Ivory\GoogleMap\Map; - -class MyExtensionHelper implements ExtensionHelperInterface -{ - /** - * {@inheritdoc} - */ - public function renderLibraries(Map $map) - { - // Here, we can render additional libraries... - return ''.PHP_EOL; - } - - /** - * {@inheritdoc} - */ - public function renderBefore(Map $map) - { - // Here, we can render js code just before the generated one. - return 'var before = \'before\''.PHP_EOL; - } - - /** - * {@inheritdoc} - */ - public function renderAfter(Map $map) - { - // Here, we can render js code just after the generated one. - return 'var after = \'after\''.PHP_EOL; - } -} -``` - -Then, you need to register you extension on the map helper & simply render your map: - -``` php -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Helper\MapHelper; -use My\Own\Helper\Extension\MyExtensionHelper; - -$mapHelper = new MapHelper(); -$mapHelper->setExtensionHelper('my_extension', new MyExtensionHelper()); - -$map = new Map(); - -$output = $mapHelper->renderJavascripts($map); -``` - -The output will be: - -``` html -// Google map loading... - - -``` diff --git a/doc/usage/layers/index.md b/doc/usage/layers/index.md deleted file mode 100644 index 723225dc..00000000 --- a/doc/usage/layers/index.md +++ /dev/null @@ -1,7 +0,0 @@ -# Google Map Layers - - 1. [KML Layer](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/layers/kml_layer.md) - 2. Fusion Table Layer - 3. Traffic Layer - 4. Bicycling Layer - 5. Panorama Layer diff --git a/doc/usage/layers/kml_layer.md b/doc/usage/layers/kml_layer.md deleted file mode 100644 index 6dfc4be4..00000000 --- a/doc/usage/layers/kml_layer.md +++ /dev/null @@ -1,33 +0,0 @@ -# KML Layer - -The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. For more -information, see official [documentation](http://code.google.com/apis/maps/documentation/javascript/layers.html#KMLLayers). - -## Build your KML layer - -``` php -use Ivory\GoogleMap\Layers\KMLLayer; - -$kmlLayer = new KMLLayer(); - -// Configure your KML layer options -$kmlLayer->setUrl('http://www.domain.com/kml_layer.kml'); - -$kmlLayer->setOption('clickable', true); -$kmlLayer->setOption('suppressInfoWindows', false); -$kmlLayer->setOptions(array( - 'clickable' => true, - 'suppressInfoWindows' => false, -)); -``` - -## Add your KML layer to the map - -``` php -use Ivory\GoogleMap\Layers\KMLLayer; - -$kmlLayer = new KMLLayer(); - -// Add your KML layer to the map -$map->addKMLLayer($kmlLayer); -``` diff --git a/doc/usage/map.md b/doc/usage/map.md deleted file mode 100644 index 78e46aa5..00000000 --- a/doc/usage/map.md +++ /dev/null @@ -1,184 +0,0 @@ -# Map - -## Build your map - -``` php -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\MapTypeId; - -$map = new Map(); - -$map->setPrefixJavascriptVariable('map_'); -$map->setHtmlContainerId('map_canvas'); - -$map->setAsync(false); -$map->setAutoZoom(false); - -$map->setCenter(0, 0, true); -$map->setMapOption('zoom', 3); - -$map->setBound(-2.1, -3.9, 2.6, 1.4, true, true); - -$map->setMapOption('mapTypeId', MapTypeId::ROADMAP); -$map->setMapOption('mapTypeId', 'roadmap'); - -$map->setMapOption('disableDefaultUI', true); -$map->setMapOption('disableDoubleClickZoom', true); -$map->setMapOptions(array( - 'disableDefaultUI' => true, - 'disableDoubleClickZoom' => true, -)); - -$map->setStylesheetOption('width', '300px'); -$map->setStylesheetOption('height', '300px'); -$map->setStylesheetOptions(array( - 'width' => '300px', - 'height' => '300px', -)); - -$map->setLanguage('en'); -``` - -## Configure map center & zoom - -For configurating the map center & zoom, you have three possibilities: - - 1. Standard center coordinate & zoom - 2. Fitting a bound - 3. Fitting a bound which extends overlays - -### Standard center coordinate & zoom - -To use the standard center coordinate & zoom, you need to disable the auto zoom flag & configure the center/zoom. - -``` php -use Ivory\GoogleMap\Map; - -$map = new Map(); - -// Disable the auto zoom flag -$map->setAutoZoom(false); - -// Sets the center -$map->setCenter(0, 0, true); - -// Sets the zoom -$map->setMapOption('zoom', 3); -``` - -### Fitting a bound - -For fitting a bound, you need to enable the auto zoom flag & configure bound south west & nort east coordinates. -If you extend overlays with the bound, the map will fit the overlays coordinate instead of bound coordinates. - -``` php -use Ivory\GoogleMap\Map; - -$map = new Map(); - -// Enable the auto zoom flag -$map->setAutoZoom(true); - -// Sets the bound coordinates -$map->setBound(-2.1, -3.9, 2.6, 1.4, true, true); -``` - -### Fitting a bound which extends overlays - -For fitting a bound which extends overlays, you need to enable the auto zoom flag & add overlays to the bound. -In the [overlays documentation](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/index.md), -you learn how you can add overlays to the map. If the auto zoom flag is enabled and you add some overlays to the map, -the map bound will automatically extends your overlay. So, at the end, all your overlays will be visible on your sreen. - -``` php -use Ivory\GoogleMap\Map, - Ivory\GoogleMap\Overlays\Marker; - -$map = new Map(); - -// Enable the auto zoom flag -$map->setAutoZoom(true); - -// Add marker overlay to your map -$map->addMarker(new Marker()); -``` - -## Configure map type - -For configurating the map type, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\MapTypeId`` is here. It allows you to access all constants which describe map types. If you don't -want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\MapTypeId; - -$map = new Map(); - -// Sets your map type -$map->setMapOption('mapTypeId', MapTypeId::HYBRID); -$map->setMapOption('mapTypeId', 'hybrid'); - -$map->setMapOption('mapTypeId', MapTypeId::ROADMAP); -$map->setMapOption('mapTypeId', 'roadmap'); - -$map->setMapOption('mapTypeId', MapTypeId::SATELLITE); -$map->setMapOption('mapTypeId', 'satellite'); - -$map->setMapOption('mapTypeId', MapTypeId::TERRAIN); -$map->setMapOption('mapTypeId', 'terrain'); -``` - -## Loading map asynchronously - -For loading the map asynchronously, you need to set the async property to true. Enabling this feature the map will load -asynchronously, allowing you to load the map through AJAX. To do this, the javascript code is wrapped by a function -called ``load_ivory_google_map`` and the script responsible to load Google API adds the ``callback`` parameter with -this value. - -``` php -use Ivory\GoogleMap\Map; - -$map = new Map(); -$map->setAsync(true); -``` - -The helper renders an html javascript block with all code needed for displaying your map wrapped in the -``load_ivory_google_map`` function. - -``` html - -``` - -## Add overlays to your map - -Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the map. -Overlays reflect objects that you "add" to the map to designate points, lines, areas, or collections of objects. - - 1. [Marker](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker.md) - 2. [Info window](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_window.md) - 3. [Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polyline.md) - 4. [EncodedPolyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md) - 5. [Polygon](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polygon.md) - 6. [Rectangle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/rectangle.md) - 7. [Circle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/circle.md) - 8. [Ground overlay](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/ground_overlay.md) - 9. [Marker cluster](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_cluster.md) - -## Configure map control options - -The maps on Google Maps contain UI elements for allowing user interaction through the map. -These elements are known as controls and you can include variations of these controls in your Google Maps API application. -Alternatively, you can do nothing and let the Google Maps API handle all control behavior. - - 1. [Map type](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/map_type.md) - 2. [Overview](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/overview.md) - 3. [Pan](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/pan.md) - 4. [Rotate](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/rotate.md) - 5. [Scale](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/scale.md) - 6. [Street view](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/street_view.md) - 7. [Zoom](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/controls/zoom.md) diff --git a/doc/usage/overlays/encoded_polyline.md b/doc/usage/overlays/encoded_polyline.md deleted file mode 100644 index 2a187aec..00000000 --- a/doc/usage/overlays/encoded_polyline.md +++ /dev/null @@ -1,36 +0,0 @@ -# Encoded Polyline - -The Encoded Polyline class defines a [Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polyline.md) -which has been encoded using the algorithm described -[here](http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html). - -## Build your encoded polyline - -``` php -use Ivory\GoogleMap\Overlays\EncodedPolyline; - -$encodedPolyline = new EncodedPolyline(); - -// Configure your encoded polyline options -$polyline->setPrefixJavascriptVariable('polyline_'); - -$encodedPolyline->setValue('encoded_polyline_value'); - -$polyline->setOption('geodesic', true); -$polyline->setOption('strokeColor', '#ffffff'); -$polyline->setOptions(array( - 'geodesic' => true, - 'strokeColor' => '#ffffff', -)); -``` - -## Add your encoded polyline to the map - -``` php -use Ivory\GoogleMap\Overlays\EncodedPolyline; - -$encodedPolyline = new EncodedPolyline(); - -// Add your encoded polyline to the map -$map->addEncodedPolyline($encodedPolyline); -``` diff --git a/doc/usage/overlays/ground_overlay.md b/doc/usage/overlays/ground_overlay.md deleted file mode 100644 index 9078da75..00000000 --- a/doc/usage/overlays/ground_overlay.md +++ /dev/null @@ -1,31 +0,0 @@ -# Ground overlay - -Polygons are useful overlays to represent arbitrarily-sized areas, but they cannot display images. If you have an image -that you wish to place on a map, you can use a GroundOverlay object. - -## Build your ground overlay - -``` php -use Ivory\GoogleMap\Overlays\GroundOverlay; - -$groundOverlay = new GroundOverlay(); - -// Configure your ground overlay options -$groundOverlay->setPrefixJavascriptVariable('ground_overlay_'); -$groundOverlay->setUrl('url'); -$groundOverlay->setBound(-1, -1, 1, 1, true, true); - -$groundOverlay->setOption('clickable', false); -$groundOverlay->setOptions(array('clickable' => false)); -``` - -## Add your ground overlay to the map - -``` php -use Ivory\GoogleMap\Overlays\GroundOverlay; - -$groundOverlay = new GroundOverlay(); - -// Add your ground overlay to the map -$map->addGroundOverlay($groundOverlay); -``` diff --git a/doc/usage/overlays/index.md b/doc/usage/overlays/index.md deleted file mode 100644 index 4de369bd..00000000 --- a/doc/usage/overlays/index.md +++ /dev/null @@ -1,15 +0,0 @@ -# Overlays - -Overlays are objects on the map that are tied to latitude/longitude coordinates, so they move when you drag or zoom the -map. Overlays reflect objects that you "add" to the map to designate points, lines, areas, or collections of objects. - - 1. [Marker](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker.md) - 2. [Info window](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_window.md) - 3. [Info box](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_box.md) - 4. [Polyline](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polyline.md) - 5. [Encoded Polyline]((http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/encoded_polyline.md) - 6. [Polygon](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/polygon.md) - 7. [Rectangle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/rectangle.md) - 8. [Circle](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/circle.md) - 9. [Ground overlay](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/ground_overlay.md) - 10. [Marker cluster](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_cluster.md) diff --git a/doc/usage/overlays/info_box.md b/doc/usage/overlays/info_box.md deleted file mode 100644 index e85074dc..00000000 --- a/doc/usage/overlays/info_box.md +++ /dev/null @@ -1,39 +0,0 @@ -# Info box - -Info box displays content in a floating window above the map. Basically, it is the same as an -[info window](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/info_window.md) but through a -different implementation. The Ivory Google Map library allows you to easily use this implementation by simply replacing -the info window helper & registering a new [extension helper](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/helper/extension.md). - -So, on the map side, nothing change, you can still use an `InfoWindow`: - -``` php -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\InfoWindow; - -$map = new Map(); - -$infoWindow = new InfoWindow(); -$infoWindow->setPosition(1.1, 2.1); - -$map->addInfoWindow($infoWindow); -``` - -Now, to render the info window as info box, you need to replace the info window helper by the info box helper & -register the info box helper extension: - -``` php -use Ivory\GoogleMap\Helper\Extension\InfoBoxExtensionHelper; -use Ivory\GoogleMap\Helper\MapHelper; -use Ivory\GoogleMap\Helper\Overlays\InfoBoxHelper; - -// Configure your map... - -$mapHelper = new MapHelper(); -$mapHelper->setInfoWindowHelper(new InfoBoxHelper()); -$mapHelper->setExtensionHelper('info_box', new InfoBoxExtensionHelper()); - -$output = $mapHelper->render($map); -``` - -The map output will wrap InfoBox objects instead of the InfoWindow ones. diff --git a/doc/usage/overlays/info_window.md b/doc/usage/overlays/info_window.md deleted file mode 100644 index f73bed62..00000000 --- a/doc/usage/overlays/info_window.md +++ /dev/null @@ -1,82 +0,0 @@ -# Info window - -Info window displays content in a floating window above the map. The info window looks a little like a comic-book word -balloon. It has a content area and a tapered stem, where the tip of the stem is at a specified location on the map. - -## Build your info window - -``` php -use Ivory\GoogleMap\Overlays\InfoWindow; - -$infoWindow = new InfoWindow(); - -// Configure your info window options -$infoWindow->setPrefixJavascriptVariable('info_window_'); -$infoWindow->setPosition(0, 0, true); -$infoWindow->setPixelOffset(1.1, 2.1, 'px', 'pt'); -$infoWindow->setContent('

Default content

'); -$infoWindow->setOpen(false); -$infoWindow->setAutoOpen(true); -$infoWindow->setOpenEvent(MouseEvent::CLICK); -$infoWindow->setAutoClose(false); -$infoWindow->setOption('disableAutoPan', true); -$infoWindow->setOption('zIndex', 10); -$infoWindow->setOptions(array( - 'disableAutoPan' => true, - 'zIndex' => 10, -)); -``` - -## Add your info window to the map - -``` php -use Ivory\GoogleMap\Overlays\InfoWindow; - -$infoWindow = new InfoWindow(); - -// Add your info window to the map -$map->addInfoWindow($infoWindow); -``` - -## Add your info window to a marker - -``` php -use Ivory\GoogleMap\Overlays\InfoWindow; - -$infoWindow = new InfoWindow(); - -// Add your info window to the marker -$marker->setInfoWindow($infoWindow); -``` - -## Configure info window open event - -For configurating the info window open event, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Events\MouseEvent`` is here. It allows you to access all constants which describe open event. If you -don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Events\MouseEvent; -use Ivory\GoogleMap\Overlays\InfoWindow; - -$infoWindow = new InfoWindow(); - -// Sets your open event -$infoWindow->setOpenEvent(MouseEvent::CLICK); -$infoWindow->setOpenEvent('click'); - -$infoWindow->setOpenEvent(MouseEvent::DBLCLICK); -$infoWindow->setOpenEvent('dblclick'); - -$infoWindow->setOpenEvent(MouseEvent::MOUSEUP); -$infoWindow->setOpenEvent('mouseup'); - -$infoWindow->setOpenEvent(MouseEvent::MOUSEDOWN); -$infoWindow->setOpenEvent('mousedown'); - -$infoWindow->setOpenEvent(MouseEvent::MOUSEOVER); -$infoWindow->setOpenEvent('mouseover'); - -$infoWindow->setOpenEvent(MouseEvent::MOUSEOUT); -$infoWindow->setOpenEvent('mouseout'); -``` diff --git a/doc/usage/overlays/marker.md b/doc/usage/overlays/marker.md deleted file mode 100644 index b5af9679..00000000 --- a/doc/usage/overlays/marker.md +++ /dev/null @@ -1,126 +0,0 @@ -# Marker - -Markers identify locations on the map. By default, they use a standard icon. - -## Build your marker - -``` php -use Ivory\GoogleMap\Overlays\Animation; -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Configure your marker options -$marker->setPrefixJavascriptVariable('marker_'); -$marker->setPosition(0, 0, true); -$marker->setAnimation(Animation::DROP); - -$marker->setOption('clickable', false); -$marker->setOption('flat', true); -$marker->setOptions(array( - 'clickable' => false, - 'flat' => true, -)); -``` - -## Configure marker animation - -For configurating the marker animation, the better way is to follow the oriented object way. For that, the -``Ivory\GoogleMap\Overlays\Animation`` is here. It allows you to access all constants which describe marker animation. -If you don't want to use this class, you can directly use the constant value. - -``` php -use Ivory\GoogleMap\Overlays\Animation; -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Sets your marker animation -$marker->setAnimation(Animation::BOUNCE); -$marker->setAnimation('bounce'); - -$marker->setAnimation(Animation::DROP); -$marker->setAnimation('drop'); -``` - -## Configure marker icon - -By default, the marker uses a standard icon. If you want to change this icon, two ways are available. You can use an -icon url or a marker image. The first solution is appropriated if you build an icon which doesn't need any specific -configuration (anchor, origin, size or scaled size). If you want to build an advanced icon, you must use the marker -image. - -### Configure marker icon URL - -``` php -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Sets the icon URL -$marker->setIcon('http://maps.gstatic.com/mapfiles/markers/marker.png'); -``` - -### Configure marker image - -The complete marker image configuration is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_image.md). - -``` php -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Sets the marker image -$marker->setIcon($markerImage); -``` - -## Configure marker shadow - -Like marker icon, the marker uses a standard shadow but if you want to change this shadow, two ways are available. You -can use a shadow url or a marker image. The first solution is appropriated if you build a shadow which doesn't need any -specific configuration (anchor, origin, size or scaled size). If you want to build an advanced shadow, you must use the -marker image. - -### Configure shadow URL - -``` php -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Sets the shadow URL -$marker->setShadow('http://maps.gstatic.com/mapfiles/markers/marker.png'); -``` - -### Configure marker image - -The complete marker image configuration is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_image.md). - -``` php -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Sets the marker image -$marker->setShadow($markerImage); -``` - -## Configure marker shape - -The complete marker shape configuration is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/overlays/marker_shape.md). - -## Add your marker to the map - -Now you have configurated your marker, you need to add it to the map. - -``` php -use Ivory\GoogleMap\Overlays\Marker; - -$marker = new Marker(); - -// Add your marker to the map -$map->addMarker($marker); -``` diff --git a/doc/usage/overlays/marker_cluster.md b/doc/usage/overlays/marker_cluster.md deleted file mode 100644 index 6e8657fa..00000000 --- a/doc/usage/overlays/marker_cluster.md +++ /dev/null @@ -1,116 +0,0 @@ -# Marker Cluster - -Some applications are required to display a large number of locations or markers. Despite the v3 JavaScript API's -significant improvement to performance, naively plotting thousands of markers on a map can quickly lead to to a -degraded user experience. Too many markers on the map cause both visual overload and sluggish interaction with the map. -To overcome this poor performance, the information displayed on the map needs to be simplified, we need a marker -clustering solution. - -The library provides one which can be easily used & extended :) - -In fact, when you use a marker in your map, internally, a marker cluster is used. A map always manages markers with a -marker cluster. Then, a marker cluster is a simple object which stores a type, markers & options: - -``` php -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -$map = new Map(); - -$markerCluster = $map->getMarkerCluster(); -$map->setMarkerCluster($markerCluster); - -$type = $markerCluster->getType(); -$markers = $markerCluster->getMarkers(); -$options = $markerCluster->getOptions(); -``` - -## Default Marker Cluster - -The default marker cluster is the marker cluster which does nothing... As a map has always a marker cluster, this -implementation allows to fallback on the default google map behavior. To enable it: - -``` php -use Ivory\GoogleMap\Overlays\MarkerCluster; - -$markerCluster->setType(MarkerCluster::_DEFAULT); -$markerCluster->setType('default'); -``` - -## Javascript Marker Cluster - -The javascript marker cluster provides a [MarkerCluster](http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/examples.html) -integration. To enable it: - -``` php -use Ivory\GoogleMap\Overlays\MarkerCluster; - -$markerCluster->setType(MarkerCluster::MARKER_CLUSTER); -$markerCluster->setType('marker_cluster'); -``` - -As this library can be configured, you can use options for that: - -``` php -$markerCluster->setOption('gridSize', 50); -$markerCluster->setOption('maxZoom', 15); -``` - -## Create your own marker cluster - -As explain in the introduction, the marker cluster can be easily extended, meaning your can manage yourself the -clustering. So, first step is create your own implementation: - -``` php -namespace Acme\GoogleMap; - -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\AbstractMarkerClusterHelper; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -class MyFuckingMarkerClusterHelper extends AbstractMarkerClusterHelper -{ - /** - * {@inheritdoc} - */ - public function render(MarkerCluster $markerCluster, Map $map) - { - // Your implementation - } - - /** - * {@inheritdoc} - */ - public function renderMarkers(MarkerCluster $markerCluster, Map $map) - { - // Your implementation - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(MarkerCluster $markerCluster, Map $map) - { - // Your implementation - } -} -``` - -After, you must register your marker cluster helper: - -``` php -use Acme\GoogleMap\MyFuckingMarkerClusterHelper; -use Ivory\GoogleMap\Helper\MapHelper; - -$mapHelper = new MapHelper(); -$markerClusterHelper = new MyFuckingMarkerClusterHelper(); - -$mapHelper->getMarkerClusterHelper()->addHelper('my_helper', $markerClusterHelper); -``` - -Then, just use it: - -``` php -$map = new Map(); -$map->getMarkerCluster()->setType('my_helper'); -``` diff --git a/doc/usage/overlays/marker_image.md b/doc/usage/overlays/marker_image.md deleted file mode 100644 index c067aede..00000000 --- a/doc/usage/overlays/marker_image.md +++ /dev/null @@ -1,46 +0,0 @@ -# Marker image (Equivalent to marker icon & marker shape) - -Markers may define an icon to show in place of the default icon or a shadow to shown in place of the default shadow. -Defining an icon or a shadow involves setting a number of properties that define the visual behavior of the marker. - -## Build your marker image - -``` php -use Ivory\GoogleMap\Overlays\MarkerImage; - -$markerImage = new MarkerImage(); - -// Configure your marker image options -$markerImage->setPrefixJavascriptVariable('marker_image_'); -$markerImage->setUrl('http://maps.gstatic.com/mapfiles/markers/marker.png'); -$markerImage->setAnchor(20, 34); -$markerImage->setOrigin(0, 0); -$markerImage->setSize(20, 34, "px", "px"); -$markerImage->setScaledSize(20, 34, "px", "px"); -``` - -## Add your marker image to a marker - -Now you have configurated your marker image, you need to add it like an icon or a shadow to your marker. - -### Adds the marker image to a marker as icon - -``` php -use Ivory\GoogleMap\Overlays\MarkerImage; - -$markerImage = new MarkerImage(); - -// Add your marker image to the marker like an icon -$marker->setIcon($markerImage); -``` - -### Add your marker image to the marker as shadow - -``` php -use Ivory\GoogleMap\Overlays\MarkerImage; - -$markerImage = new MarkerImage(); - -// Add your marker image to the marker like a shadow -$marker->setShadow($markerImage); -``` diff --git a/doc/usage/overlays/polygon.md b/doc/usage/overlays/polygon.md deleted file mode 100644 index 58e18489..00000000 --- a/doc/usage/overlays/polygon.md +++ /dev/null @@ -1,48 +0,0 @@ -# Polygon - -Polygon objects are similar to polyline objects in that they consist of a series of coordinates in an ordered sequence. -However, instead of being open-ended, polygons are designed to define regions within a closed loop. - -## Build your polygon - -``` php -use Ivory\GoogleMap\Overlays\Polygon; - -$polygon = new Polygon(); - -// Configure your polygon options -$polygon->setPrefixJavascriptVariable('polygon_'); - -$polygon->setOption('fillColor', '#000000'); -$polygon->setOption('fillOpacity', 0.5); -$polygon->setOptions(array( - 'fillColor' => '#000000', - 'fillOpacity' => 0.5, -)); -``` - -## Add coordinate to your polygon - -Like describe in the introduction, a polygon object consists of an array of coordinates. So, you need to add coordinate -to your polygon. - -``` php -use Ivory\GoogleMap\Overlays\Polygon; - -$polygon = new Polygon(); - -// Add coordinates to your polygon -$polygon->addCoordinate(0, 0, true); -$polygon->addCoordinate(1, 1, true); -``` - -## Add your polygon to the map - -``` php -use Ivory\GoogleMap\Overlays\Polygon; - -$polygon = new Polygon(); - -// Add your polygon to the map -$map->addPolygon($polygon); -``` diff --git a/doc/usage/overlays/polyline.md b/doc/usage/overlays/polyline.md deleted file mode 100644 index e10db35d..00000000 --- a/doc/usage/overlays/polyline.md +++ /dev/null @@ -1,48 +0,0 @@ -# Polyline - -The Polyline class defines a linear overlay of connected line segments on the map. A Polyline object consists of an -array of coordinates, and creates a series of line segments that connect those locations in an ordered sequence. - -## Build your polyline - -``` php -use Ivory\GoogleMap\Overlays\Polyline; - -$polyline = new Polyline(); - -// Configure your polyline options -$polyline->setPrefixJavascriptVariable('polyline_'); - -$polyline->setOption('geodesic', true); -$polyline->setOption('strokeColor', '#ffffff'); -$polyline->setOptions(array( - 'geodesic' => true, - 'strokeColor' => '#ffffff', -)); -``` - -## Add coordinate to your polyline - -Like describe in the introduction, a polyline object consists of an array of coordinates. So, you need to add -coordinate to your polyline. - -``` php -use Ivory\GoogleMap\Overlays\Polyline; - -$polyline = new Polyline(); - -// Add coordinates to your polyline -$polyline->addCoordinate(0, 0, true); -$polyline->addCoordinate(1, 1, true); -``` - -## Add your polyline to the map - -``` php -use Ivory\GoogleMap\Overlays\Polyline; - -$polyline = new Polyline(); - -// Add your polyline to the map -$map->addPolyline($polyline); -``` diff --git a/doc/usage/overlays/rectangle.md b/doc/usage/overlays/rectangle.md deleted file mode 100644 index cb6e8de8..00000000 --- a/doc/usage/overlays/rectangle.md +++ /dev/null @@ -1,36 +0,0 @@ -# Rectangle - -A Rectangle is similar to a Polygon in that you can define custom colors, weights, and opacities for the edge of the -rectangle (the "stroke") and custom colors and opacities for the area within the enclosed region (the "fill"). Unlike a -Polygon, you do not define paths for a Rectangle; instead, a rectangle has one additional property which defines its -shape : the bound. - -## Build your rectangle - -``` php -use Ivory\GoogleMap\Overlays\Rectangle; - -$rectangle = new Rectangle(); - -// Configure your rectangle options -$rectangle->setPrefixJavascriptVariable('rectangle_'); -$rectangle->setBound(-1, -1, 1, 1, true, true); - -$rectangle->setOption('clickable', false); -$rectangle->setOption('strokeColor', '#ffffff'); -$rectangle->setOptions(array( - 'clickable' => false, - 'strokeColor' => '#ffffff', -)); -``` - -## Add your rectangle to the map - -``` php -use Ivory\GoogleMap\Overlays\Rectangle; - -$rectangle = new Rectangle(); - -// Add your rectangle to the map -$map->addRectangle($rectangle); -``` diff --git a/doc/usage/places/autocomplete.md b/doc/usage/places/autocomplete.md deleted file mode 100644 index d3fcb292..00000000 --- a/doc/usage/places/autocomplete.md +++ /dev/null @@ -1,71 +0,0 @@ -# Autocomplete - -The Places Autocomplete feature attaches to a text field on your web page, and monitors that field for character -entries. As text is entered, Autocomplete returns Place predictions to the application in the form of a drop-down pick -list. You can use the Places Autocomplete feature to help users find a specific location, or assist them with filling -out address fields in online forms. - -## Build your autocomplete - -In order to use the Google Autocomplete feature, you need to build & configure it. - -``` php -use Ivory\GoogleMap\Places\Autocomplete; -use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; -use Ivory\GoogleMap\Places\AutocompleteType; - -$autocomplete = new Autocomplete(); - -$autocomplete->setPrefixJavascriptVariable('place_autocomplete_'); -$autocomplete->setInputId('place_input'); - -$autocomplete->setInputAttributes(array('class' => 'my-class')); -$autocomplete->setInputAttribute('class', 'my-class'); - -$autocomplete->setValue('foo'); - -$autocomplete->setTypes(array(AutocompleteType::ESTABLISHMENT)); -$autocomplete->setComponentRestrictions(array(AutocompleteComponentRestriction::COUNTRY => 'fr')); -$autocomplete->setBound(-2.1, -3.9, 2.6, 1.4, true, true); - -$autocomplete->setAsync(false); -$autocomplete->setLanguage('en'); -``` - -## Render your autocomplete - -Now, you have builded & configured your autocomplete, you can render it. For this purpose, you will need the -`Ivory\GoogleMap\Helper\Places\AutocompleteHelper` which allows to render the autocomplete html container & some -javascript for being able to render it. - -``` php -use Ivory\GoogleMap\Helper\Places\AutocompleteHelper; - -$autocompleteHelper = new AutocompleteHelper(); -``` - -### Render the HTML container - -``` -echo $autocompleteHelper->renderHtmlContainer($autocomplete); -``` - -This function renders an html input with the ID, the value & the html attributes: - -``` html - -``` - -### Render the javascript - -``` -echo $autocompleteHelper->renderJavascripts($autocomplete); -``` - -This function renders an html javascript block with all code needed for displaying your autocomplete. - -``` html - -``` diff --git a/doc/usage/services/business_account.md b/doc/usage/services/business_account.md deleted file mode 100644 index 64690d68..00000000 --- a/doc/usage/services/business_account.md +++ /dev/null @@ -1,97 +0,0 @@ -# Business Account - -When using a service for business purpose, you will receive a business account from Google. This one allows you to -bypass Google limitation according to your billing plan. In order to use this feature, you will need an -`Ivory\GoogleMap\Services\BusinessAccount`: - -``` php -use Ivory\GoogleMap\Services\BusinessAccount; - -$businessAccount = new BusinessAccount('client_id', 'secret'); - -$clientId = $businessAccount->getClientId(); -$businessAccount->setClientId($clientId); - -$secret = $businessAccount->getSecret(); -$businessAccount->setSecret($secret); -``` - -Note that the client identifier is not prefixed by `gme-` (it is automatically prepended by the library). - -Additionally, you can use channel: - -``` -$businessAccount = new BusinessAccount('client_id', 'secret', 'my_channel'); - -$channel = $businessAccount->getChannel(); -$businessAccount->setChannel($channel); -``` - -## Geocoder - -If you want to use the geocoder service with a Google business account, you need to set it on the provider and then, -everything is done automatically: - -``` php -use Ivory\GoogleMap\Services\BusinessAccount; -use Ivory\GoogleMap\Services\Geocoding\Geocoder; -use Ivory\GoogleMap\Services\Geocoding\GeocoderProvider; -use Geocoder\HttpAdapter\CurlHttpAdapter; - - -$provider = new GeocoderProvider(new CurlHttpAdapter()) - -$provider->setBusinessAccount(new BusinessAccount('client_id', 'secret')); -$businessAccount = $provider->getBusinessAccount(); - -$geocoder = new Geocoder(); -$geocoder->registerProviders(array($provider)); - -$response = $geocoder->geocode('1600 Amphitheatre Parkway, Mountain View, CA'); -``` - -If you want to go back the normal behavior (anonymous), you need to reset the business account to `null`: - -``` php -$geocoder->setBusinessAccount(null); -``` - -## Directions - -If you want to use the directions service with a Google business account, you need to set it on the service and then, -everything is done automatically: - -``` php -use Ivory\GoogleMap\Services\BusinessAccount; - -$directions->setBusinessAccount(new BusinessAccount('client_id', 'secret')); -$businessAccount = $directions->getBusinessAccount(); - -$response = $directions->route('Lille', 'Paris') -``` - -If you want to go back the normal behavior (anonymous), you need to reset the business account to `null`: - -``` php -$directions->setBusinessAccount(null); -``` - -## Distance Matrix - -If you want to use the distance matrix service with a Google business account, you need to set it on the service and -then, everything is done automatically: - -``` php -use Ivory\GoogleMap\Services\BusinessAccount; - -$distanceMatrix->setBusinessAccount(new BusinessAccount('client_id', 'secret')); -$businessAccount = $distanceMatrix->getBusinessAccount(); - -$response = $distanceMatrix->process(array('Vancouver BC'), array('San Francisco')); -``` - -If you want to go back the normal behavior (anonymous), you need to reset the business account to `null`: - -``` php -$distanceMatrix->setBusinessAccount(null); -``` diff --git a/doc/usage/services/directions/directions_request.md b/doc/usage/services/directions/directions_request.md deleted file mode 100644 index 16202c80..00000000 --- a/doc/usage/services/directions/directions_request.md +++ /dev/null @@ -1,47 +0,0 @@ -# Directions Request - -## Build a directions request - -``` php -use Ivory\GoogleMap\Services\Directions\DirectionsRequest; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - -$request = new DirectionsRequest(); - -// Set your origin -$request->setOrigin('New York') -$request->setOrigin(1.1, 2.1, true); - -// Set your destination -$request->setDestination('Washington'); -$request->setDestination(2.1, 1.1, true); - -// Set your waypoints -$request->addWaypoint('Philadelphia'); -$request->addWaypoint(1.2, 2.2, true); - -// If you use waypoint, optimize it -$request->setOptimizeWaypoints(true); - -$request->setAvoidHighways(true); -$request->setAvoidTolls(true); -$request->setProvideRouteAlternatives(true); - -$request->setRegion('us'); -$request->setLanguage('en'); -$request->setTravelMode(TravelMode::DRIVING); -$request->setUnitSystem(UnitSystem::METRIC); -$request->setSensor(false); -``` - -## Route your request - -``` php -use Ivory\GoogleMap\Services\Directions\DirectionsRequest; - -$request = new DirectionsRequest(); - -// Route your request -$response = $directions->route($request); -``` diff --git a/doc/usage/services/distance_matrix/distance_matrix_request.md b/doc/usage/services/distance_matrix/distance_matrix_request.md deleted file mode 100644 index a122b154..00000000 --- a/doc/usage/services/distance_matrix/distance_matrix_request.md +++ /dev/null @@ -1,40 +0,0 @@ -# Distance Matrix Request - -## Build a distance matrix request - -``` php -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - -$request = new DistanceMatrixRequest(); - -// Set your origins -$request->setOrigins(array('New York')); -$request->setOrigins(array(new Coordinate(1.1, 2.1, true))); - -// Set your destinations -$request->setDestinations(array('Washington')); -$request->setDestinations(array(new Coordinate(2.1, 1.1, true))); - -$request->setAvoidHighways(true); -$request->setAvoidTolls(true); - -$request->setRegion('us'); -$request->setLanguage('en'); -$request->setTravelMode(TravelMode::DRIVING); -$request->setUnitSystem(UnitSystem::METRIC); -$request->setSensor(false); -``` - -## Process your request - -``` php -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest; - -$request = new DistanceMatrixRequest(); - -// Process your request -$response = $distanceMatrix->process($request); -``` diff --git a/doc/usage/services/geocoding/geocoder.md b/doc/usage/services/geocoding/geocoder.md deleted file mode 100644 index 3c8f61e3..00000000 --- a/doc/usage/services/geocoding/geocoder.md +++ /dev/null @@ -1,60 +0,0 @@ -# Geocoding API - -The Geocoding API uses [Geocoder](http://github.com/willdurand/Geocoder) which is a PHP 5.3 library for issuing -Geocoding. So, I recommend you to read his documentation. - -Geocoding is the process of converting addresses (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic -coordinates (like latitude 37.423021 and longitude -122.083739), which you can use to place markers or position the map. -Additionally, the service allows you to perform the converse operation (turning coordinates into addresses). This -process is known as "reverse geocoding". - -## Request a geocoder - -``` php -use Ivory\GoogleMap\Services\Geocoding\Geocoder; - -$geocoder = new Geocoder(); -``` - -The Ivory Google Map Geocoder allows you to build all available geocoder directly by configuration file. - -Available providers: - - - ``Geocoder\Provider\BindMapsProvider`` - - ``Geocoder\Provider\FreeGeoIpProvider`` - - ``Geocoder\Provider\GoogleMapsProvider`` - - ``Geocoder\Provider\HostIpProvider`` - - ``Geocoder\Provider\IpInfoDbProvider`` - - ``Geocoder\Provider\YahooProvider`` - - ``Ivory\GoogleMapBundle\Model\Services\Geocoding\Provider`` - -Available adapters: - - - ``Geocoder\HttpAdapter\BuzzHttpAdapter`` - - ``Geocoder\HttpAdapter\CurlHttpAdapter`` - - ``Geocoder\HttpAdapter\GuzzleHttpAdapter`` - - ``Geocoder\HttpAdapter\ZendHttpAdapter`` - -To use these providers/adapters, simply register them: - -``` php -use Ivory\GoogleMap\Services\Geocoding\Geocoder; -use Ivory\GoogleMap\Services\Geocoding\GeocoderProvider; -use Geocoder\HttpAdapter\CurlHttpAdapter; - -$geocoder = new Geocoder(); -$geocoder->registerProviders(array( - new GeocoderProvider(new CurlHttpAdapter()), -)); -``` - -## The standard Geocoder - -If you use the standard Geocoder components, I recommand you to directly read this own documentation available -[here](http://www.geocoder-php.org/). - -## The Ivory Google Map Geocoder - -The specific Ivory Google Map Geocoder has been added to allow you to geocode a very advanced request & use the -response to directly build your overlays. If you are interested about this geocoder, the documentation is available -[here](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/geocoding/ivory_geocoder.md). diff --git a/doc/usage/services/geocoding/geocoder_request.md b/doc/usage/services/geocoding/geocoder_request.md deleted file mode 100644 index a9c5a620..00000000 --- a/doc/usage/services/geocoding/geocoder_request.md +++ /dev/null @@ -1,33 +0,0 @@ -# Geocoder Request - -## Build a geocoder request - -``` php -use Ivory\GoogleMap\Services\Geocoding\GeocoderRequest; - -$request = new GeocoderRequest(); - -// Set address -$request->setAddress('1600 Amphitheatre Parkway, Mountain View, CA'); - -// Or set coordinate (reverse geocoding) -$request->setCoordinate(1.1, 2.1, true); - -$request->setBound(-1.1, -2.1, 2.1, 1.1, true, true); -$request->setRegion('en'); -$request->setLanguage('en'); -$request->setSensor(false); -``` - -If you set an address & a coordinate, address takes precedence over coordinate. - -## Geocoloate your request - -``` php -use Ivory\GoogleMap\Services\Geocoding\GeocoderRequest; - -$request = new GeocoderRequest(); - -// Geocode your request -$response = $geocoder->geocode($request); -``` diff --git a/doc/usage/services/index.md b/doc/usage/services/index.md deleted file mode 100644 index 97a3144c..00000000 --- a/doc/usage/services/index.md +++ /dev/null @@ -1,8 +0,0 @@ -# Google Map API Services - - 1. [Directions API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/directions/directions.md) - 2. Distance Matrix API - 3. Elevation API - 4. [Geocoding API](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/geocoding/geocoder.md) - 5. Places API - 6. [Business Account](http://github.com/egeloen/ivory-google-map/blob/master/doc/usage/services/business_account.md) diff --git a/src/Assets/AbstractJavascriptVariableAsset.php b/src/Assets/AbstractJavascriptVariableAsset.php deleted file mode 100644 index 8faf50b2..00000000 --- a/src/Assets/AbstractJavascriptVariableAsset.php +++ /dev/null @@ -1,91 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Assets; - -use Ivory\GoogleMap\Exception\AssetException; - -/** - * Allow easy generation of unique javascript variable for any class model that requires it. - * - * @author GeLo - */ -abstract class AbstractJavascriptVariableAsset -{ - /** @var string */ - protected $javascriptVariable; - - /** - * Creates a javascript variable asset. - */ - public function __construct($javascriptVariable = null) - { - if ($javascriptVariable === null) { - $javascriptVariable = $this->generateJavascriptVariable(); - } - - $this->setJavascriptVariable($javascriptVariable); - } - - /** - * Sets the prefix of the javascript variable. - * - * @param string $prefixJavascriptVariable The prefix of the javascript variable. - * - * @throws \Ivory\GoogleMap\Exception\AssetException If the prefix javascript variable is not valid. - */ - public function setPrefixJavascriptVariable($prefixJavascriptVariable) - { - if (!is_string($prefixJavascriptVariable)) { - throw AssetException::invalidPrefixJavascriptVariable(); - } - - $this->javascriptVariable = $this->generateJavascriptVariable($prefixJavascriptVariable); - } - - /** - * Gets the javascript variable which describes the asset. - * - * @return string The javascript variable. - */ - public function getJavascriptVariable() - { - return $this->javascriptVariable; - } - - /** - * Sets the javascript variable which describes the asset - * - * @param string $javascriptVariable The javascript variable. - * - * @throws \Ivory\GoogleMap\Exception\AssetException If the javascript variable is not valid. - */ - public function setJavascriptVariable($javascriptVariable) - { - if (!is_string($javascriptVariable)) { - throw AssetException::invalidJavascriptVariable(); - } - - $this->javascriptVariable = $javascriptVariable; - } - - /** - * Generates a unique javascript variable which can be prefixed. - * - * @param string $prefix The prefix. - * - * @return string The unique javascript variable. - */ - protected function generateJavascriptVariable($prefix = null) - { - return str_replace('.', '', uniqid($prefix, true)); - } -} diff --git a/src/Assets/AbstractOptionsAsset.php b/src/Assets/AbstractOptionsAsset.php index 9bfb5a85..f0801c37 100644 --- a/src/Assets/AbstractOptionsAsset.php +++ b/src/Assets/AbstractOptionsAsset.php @@ -11,57 +11,45 @@ namespace Ivory\GoogleMap\Assets; -use Ivory\GoogleMap\Exception\AssetException; - /** - * Allow easy add of options for any class model that requires it. + * Abstract options asset. * * @author GeLo */ -abstract class AbstractOptionsAsset extends AbstractJavascriptVariableAsset +abstract class AbstractOptionsAsset extends AbstractVariableAsset { /** @var array */ - protected $options; + protected $options = array(); /** * Creates an options asset. * - * @param string $javascriptVariable The javascript variable. - * @param array $options The options. + * @param string|null $prefix The variable prefix. + * @param array $options The options. */ - public function __construct($javascriptVariable = null, array $options = array()) + public function __construct($prefix = null, array $options = array()) { - parent::__construct($javascriptVariable); + parent::__construct($prefix); - $this->setOptions($options); + $this->addOptions($options); } /** - * Checks if there is option. - * - * @return boolean TRUE if there is option else FALSE. + * Resets the options. */ - public function hasOptions() + public function resetOptions() { - return !empty($this->options); + $this->options = array(); } /** - * Checks if the option exists. + * Checks if there are options. * - * @param string $option The option. - * - * @throws \Ivory\GoogleMap\Exception\AssetException If the option is not valid. - * - * @return boolean TRUE if the option exists else FALSE. + * @return boolean TRUE if there are options else FALSE. */ - public function hasOption($option) + public function hasOptions() { - if (!is_string($option)) { - throw AssetException::invalidOption(); - } - - return isset($this->options[$option]); + return !empty($this->options); } /** @@ -81,61 +69,76 @@ public function getOptions() */ public function setOptions(array $options) { - $this->options = array(); + $this->resetOptions(); + $this->addOptions($options); + } - foreach ($options as $option => $value) { - $this->setOption($option, $value); + /** + * Adds the options. + * + * @param array $options The options. + */ + public function addOptions(array $options) + { + foreach ($options as $name => $value) { + $this->setOption($name, $value); } } /** - * Gets a specific option. - * - * @param string $option The option. + * Removes the options. * - * @throws \Ivory\GoogleMap\Exception\AssetException If the option does not exist. - * - * @return mixed The option value. + * @param array $names The option names. */ - public function getOption($option) + public function removeOptions(array $names) { - if (!$this->hasOption($option)) { - throw AssetException::optionDoesNotExist($option); + foreach ($names as $name) { + $this->removeOption($name); } + } - return $this->options[$option]; + /** + * Checks if there is an option. + * + * @param string $name The option name. + * + * @return boolean TRUE if there is the option else FALSE. + */ + public function hasOption($name) + { + return array_key_exists($name, $this->options); } /** - * Sets a specific option. + * Gets an option. * - * @param string $option The option - * @param mixed $value The option value. + * @param string $name The option name. * - * @throws \Ivory\GoogleMap\Exception\AssetException If the option is not valid. + * @return mixed The option value. */ - public function setOption($option, $value) + public function getOption($name) { - if (!is_string($option)) { - throw AssetException::invalidOption(); - } + return $this->hasOption($name) ? $this->options[$name] : null; + } - $this->options[$option] = $value; + /** + * Sets an option. + * + * @param string $name The option name. + * @param mixed $value The option value. + */ + public function setOption($name, $value) + { + $this->options[$name] = $value; } /** * Removes an option. * - * @param string $option The option. - * - * @throws \Ivory\GoogleMap\Exception\AssetException If the option does not exist. + * @param string $name The option name. */ - public function removeOption($option) + public function removeOption($name) { - if (!$this->hasOption($option)) { - throw AssetException::optionDoesNotExist($option); - } - - unset($this->options[$option]); + unset($this->options[$name]); } } diff --git a/src/Assets/AbstractUninstantiableAsset.php b/src/Assets/AbstractUninstantiableAsset.php new file mode 100644 index 00000000..cf16190f --- /dev/null +++ b/src/Assets/AbstractUninstantiableAsset.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Assets; + +/** + * Uninstantiable asset. + * + * @author GeLo + */ +abstract class AbstractUninstantiableAsset +{ + /** + * Disabled constructor. + * + * @codeCoverageIgnore + */ + final private function __construct() + { + + } +} diff --git a/src/Assets/AbstractVariableAsset.php b/src/Assets/AbstractVariableAsset.php new file mode 100644 index 00000000..9ececb5d --- /dev/null +++ b/src/Assets/AbstractVariableAsset.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Assets; + +/** + * Abstract variable asset. + * + * @author GeLo + */ +abstract class AbstractVariableAsset +{ + /** @var string */ + protected $variable; + + /** + * Creates a variable asset. + * + * @param string|null $prefix The variable prefix. + */ + public function __construct($prefix = null) + { + $this->setVariable(str_replace('.', '', uniqid($prefix, true))); + } + + /** + * Gets the variable. + * + * @return string The variable. + */ + public function getVariable() + { + return $this->variable; + } + + /** + * Sets the variable. + * + * @param string $variable The variable. + */ + public function setVariable($variable) + { + $this->variable = $variable; + } +} diff --git a/src/Base/Bound.php b/src/Base/Bound.php index acfe7718..e0251db7 100644 --- a/src/Base/Bound.php +++ b/src/Base/Bound.php @@ -11,189 +11,103 @@ namespace Ivory\GoogleMap\Base; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\BaseException; -use Ivory\GoogleMap\Overlays\ExtendableInterface; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Bound wich describes a google map bound. + * Bound. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLngBounds * @author GeLo */ -class Bound extends AbstractJavascriptVariableAsset +class Bound extends AbstractVariableAsset { - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|null */ protected $southWest; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|null */ protected $northEast; - /** @var array */ - protected $extends; - /** * Creates a bound. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $southWest The south west coordinate. + * @param \Ivory\GoogleMap\Base\Coordinate|null $northEast The north east coordinate. */ - public function __construct(Coordinate $southWest = null, Coordinate $northEast = null, array $extends = array()) + public function __construct(Coordinate $southWest = null, Coordinate $northEast = null) { - $this->setPrefixJavascriptVariable('bound_'); + parent::__construct('bound_'); $this->setSouthWest($southWest); $this->setNorthEast($northEast); - $this->setExtends($extends); } /** - * Checks if the bound has coordinates. + * Checks if there are coordinates (south west and north east). * - * @return boolean TRUE if the bound has coordinates else FALSE. + * @return boolean TRUE if there are coordinates else FALSE. */ public function hasCoordinates() { - return ($this->southWest !== null) && ($this->northEast !== null); - } - - /** - * Gets the south west coordinate. - * - * @return \Ivory\GoogleMap\Base\Coordinate The south west coordinate. - */ - public function getSouthWest() - { - return $this->southWest; - } - - /** - * Sets the south west coordinate. - * - * Available prototypes: - * - function setSouthWest(Ivory\GoogleMap\Base\Coordinate $southWest = null) - * - function setSouthWest(double $latitude, double $longitude, boolean $noWrap = true) - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the south west coordinate is not valid (prototypes). - */ - public function setSouthWest() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->southWest = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->southWest === null) { - $this->southWest = new Coordinate(); - } - - $this->southWest->setLatitude($args[0]); - $this->southWest->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->southWest->setNoWrap($args[2]); - } - } elseif (!isset($args[0])) { - $this->southWest = null; - } else { - throw BaseException::invalidBoundSouthWest(); - } - } - - /** - * Gets the north east coordinate. - * - * @return \Ivory\GoogleMap\Base\Coordinate The northh east coordinate. - */ - public function getNorthEast() - { - return $this->northEast; + return $this->hasSouthWest() && $this->hasNorthEast(); } /** - * Sets the north east coordinate. - * - * Available prototypes: - * - function setNorthEast(Ivory\GoogleMap\Base\Coordinate $northEast = null) - * - function setNorthEast(double $latitude, double $longitude, boolean $noWrap = true) + * Checks if there is a south west. * - * @throws \Ivory\GoogleMap\Exception\BaseException If the north east coordinate is not valid (prototypes). + * @return boolean TRUE if there is a south west else FALSE. */ - public function setNorthEast() + public function hasSouthWest() { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->northEast = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->northEast === null) { - $this->northEast = new Coordinate(); - } - - $this->northEast->setLatitude($args[0]); - $this->northEast->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->northEast->setNoWrap($args[2]); - } - } elseif (!isset($args[0])) { - $this->northEast = null; - } else { - throw BaseException::invalidBoundNorthEast(); - } + return $this->southWest !== null; } /** - * Checks if the bound extends something. + * Gets the south west. * - * @return boolean TRUE if the bound extends somethind else FALSE. + * @return \Ivory\GoogleMap\Base\Coordinate|null The south west. */ - public function hasExtends() + public function getSouthWest() { - return !empty($this->extends); + return $this->southWest; } /** - * Gets the google map objects that the bound extends. + * Sets the south west. * - * @return array The objects that the bound extends. + * @param \Ivory\GoogleMap\Base\Coordinate|null $southWest The south west. */ - public function getExtends() + public function setSouthWest(Coordinate $southWest = null) { - return $this->extends; + $this->southWest = $southWest; } /** - * Sets the google map objects that the bound extends. + * Checks if there is a north east. * - * @param array $extends The objects that the bound extends. + * @return boolean TRUE if there is a north east. */ - public function setExtends($extends) + public function hasNorthEast() { - $this->extends = array(); - - foreach ($extends as $extend) { - $this->extend($extend); - } + return $this->northEast !== null; } /** - * Adds an object that the bound extends. + * Gets the north east. * - * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The object that the bound extends. + * @return \Ivory\GoogleMap\Base\Coordinate|null The northh east. */ - public function extend(ExtendableInterface $extend) + public function getNorthEast() { - $this->extends[] = $extend; + return $this->northEast; } /** - * Gets the center of the bound. + * Sets the north east. * - * @return \Ivory\GoogleMap\Base\Coordinate The bound center. + * @param \Ivory\GoogleMap\Base\Coordinate|null $northEast The north east. */ - public function getCenter() + public function setNorthEast(Coordinate $northEast = null) { - $centerLatitude = ($this->getSouthWest()->getLatitude() + $this->getNorthEast()->getLatitude()) / 2; - $centerLongitude = ($this->getSouthWest()->getLongitude() + $this->getNorthEast()->getLongitude()) / 2; - - return new Coordinate($centerLatitude, $centerLongitude); + $this->northEast = $northEast; } } diff --git a/src/Base/Coordinate.php b/src/Base/Coordinate.php index 4bf65748..db94769f 100644 --- a/src/Base/Coordinate.php +++ b/src/Base/Coordinate.php @@ -11,46 +11,40 @@ namespace Ivory\GoogleMap\Base; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\BaseException; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Coordinate which describes a google map coordinate. + * Coordinate. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng * @author GeLo */ -class Coordinate extends AbstractJavascriptVariableAsset +class Coordinate extends AbstractVariableAsset { - /** @var double */ + /** @var float */ protected $latitude; - /** @var double */ + /** @var float */ protected $longitude; - /** @var boolean */ - protected $noWrap; - /** - * Create a coordinate + * Creates a coordinate. * - * @param double $latitude The latitude. - * @param double $longitude The longitude. - * @param boolean $noWrap The no wrap flag. + * @param float $latitude The latitude. + * @param float $longitude The longitude. */ - public function __construct($latitude = 0, $longitude = 0, $noWrap = true) + public function __construct($latitude, $longitude) { - $this->setPrefixJavascriptVariable('coordinate_'); + parent::__construct('coordinate_'); $this->setLatitude($latitude); $this->setLongitude($longitude); - $this->setNoWrap($noWrap); } /** * Gets the latitude. * - * @return double The latitude. + * @return float The latitude. */ public function getLatitude() { @@ -60,19 +54,23 @@ public function getLatitude() /** * Sets the latitude * - * @param double $latitude The latitude. - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the latitude is not valid. + * @param float $latitude The latitude. */ public function setLatitude($latitude) { - if (!is_numeric($latitude) && ($latitude !== null)) { - throw BaseException::invalidCoordinateLatitude(); - } - $this->latitude = $latitude; } + /** + * Checks if the latitude is not wrapped. + * + * @return boolean TRUE if the latitude is not wrapped else FALSE. + */ + public function isLatitudeNoWrap() + { + return $this->latitude < -90 || $this->latitude > 90; + } + /** * Gets the longitude * @@ -86,42 +84,30 @@ public function getLongitude() /** * Sets the longitude. * - * @param double $longitude The longitude. - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the longitude is not valid. + * @param float $longitude The longitude. */ public function setLongitude($longitude) { - if (!is_numeric($longitude) && ($longitude !== null)) { - throw BaseException::invalidCoordinateLongitude(); - } - $this->longitude = $longitude; } /** - * Check if the coordinate is not wrap. + * Checks if the longitude is not wrapped. * - * @return boolean TRUE if the coordinate is not wrap else FALSE. + * @return boolean TRUE if the longitude is not wrapped else FALSE. */ - public function isNoWrap() + public function isLongitudeNoWrap() { - return $this->noWrap; + return $this->longitude < -180 || $this->longitude > 180; } /** - * Sets if the coordinate is wrap. + * Checks if the latitude or the longitude are not wrapped. * - * @param boolean $noWrap TRUE if the coordinate is not wrap else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the no wrap flag is not valid. + * @return boolean TRUE if the latitude or the longitude are not wrapped else FALSE. */ - public function setNoWrap($noWrap) + public function isNoWrap() { - if (!is_bool($noWrap) && ($noWrap !== null)) { - throw BaseException::invalidCoordinateNoWrap(); - } - - $this->noWrap = $noWrap; + return $this->isLatitudeNoWrap() || $this->isLongitudeNoWrap(); } } diff --git a/src/Base/Point.php b/src/Base/Point.php index 60f9d283..59c47db5 100644 --- a/src/Base/Point.php +++ b/src/Base/Point.php @@ -11,41 +11,40 @@ namespace Ivory\GoogleMap\Base; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\BaseException; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Point which describes a google map point + * Point. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Point + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Point * @author GeLo */ -class Point extends AbstractJavascriptVariableAsset +class Point extends AbstractVariableAsset { - /** @var double */ + /** @var float */ protected $x; - /** @var double */ + /** @var float */ protected $y; /** * Creates a point. * - * @param double $x X coordinate. - * @param double $y Y coordinate. + * @param float $x The X. + * @param float $y The Y. */ - public function __construct($x = 0, $y = 0) + public function __construct($x, $y) { - $this->setPrefixJavascriptVariable('point_'); + parent::__construct('point_'); $this->setX($x); $this->setY($y); } /** - * Gets the x coordinate. + * Gets the X. * - * @return double The x coordinate. + * @return float The X. */ public function getX() { @@ -53,25 +52,19 @@ public function getX() } /** - * Sets the x coordinate. + * Sets the X. * - * @param double $x The x coordinate. - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the X coordinate is not valid. + * @param float $x The X. */ public function setX($x) { - if (!is_numeric($x)) { - throw BaseException::invalidPointX(); - } - $this->x = $x; } /** - * Gets the y coordinate. + * Gets the Y. * - * @return double The Y coordinate. + * @return float The Y. */ public function getY() { @@ -79,18 +72,12 @@ public function getY() } /** - * Sets the y coordinate. + * Sets the Y. * - * @param double $y The y coordinate. - * - * @throws \Ivory\GoogleMap\Exception\BaseException If the Y coordinate is not valid. + * @param float $y The Y. */ public function setY($y) { - if (!is_numeric($y)) { - throw BaseException::invalidPointY(); - } - $this->y = $y; } } diff --git a/src/Base/Size.php b/src/Base/Size.php index 135b09ae..db9b7fdf 100644 --- a/src/Base/Size.php +++ b/src/Base/Size.php @@ -11,52 +11,50 @@ namespace Ivory\GoogleMap\Base; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\BaseException; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Size which describes a google map size. + * Size. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Size + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Size * @author GeLo */ -class Size extends AbstractJavascriptVariableAsset +class Size extends AbstractVariableAsset { - /** @var double */ + /** @var float */ protected $width; - /** @var double */ + /** @var float */ protected $height; - /** @var string */ + /** @var string|null */ protected $widthUnit; - /** @var string */ + /** @var string|null */ protected $heightUnit; /** - * Create a size. + * Creates a size. * - * @param double $width The width. - * @param double $height The height. - * @param string $widthUnit The width unit. - * @param string $heightUnit The height unit. + * @param float $width The width. + * @param float $height The height. + * @param string|null $widthUnit The width unit. + * @param string|null $heightUnit The height unit. */ - public function __construct($width = 1, $height = 1, $widthUnit = null, $heightUnit = null) + public function __construct($width, $height, $widthUnit = null, $heightUnit = null) { - $this->setPrefixJavascriptVariable('size_'); + parent::__construct('size_'); $this->setWidth($width); $this->setHeight($height); - $this->setWidthUnit($widthUnit); $this->setHeightUnit($heightUnit); } /** - * Gets the width size. + * Gets the width. * - * @return double The width size. + * @return float The width. */ public function getWidth() { @@ -64,25 +62,19 @@ public function getWidth() } /** - * Sets the width size. - * - * @param double $width The width size. + * Sets the width. * - * @throws \Ivory\GoogleMap\Exception\BaseException If the width is not valid. + * @param float $width The width. */ public function setWidth($width) { - if (!is_numeric($width)) { - throw BaseException::invalidSizeWidth(); - } - $this->width = $width; } /** - * Gets the height size + * Gets the height. * - * @return double The height size. + * @return float The height. */ public function getHeight() { @@ -90,35 +82,29 @@ public function getHeight() } /** - * Sets the height size. - * - * @param double $height The height size. + * Sets the height. * - * @throws \Ivory\GoogleMap\Exception\BaseException If the height is not valid. + * @param float $height The height. */ public function setHeight($height) { - if (!is_numeric($height)) { - throw BaseException::invalidSizeHeight(); - } - $this->height = $height; } /** - * Checks if the size has units. + * Checks if there is a width unit. * - * @return boolean TRUE if the size has units else FALSE. + * @return boolean TRUE if there is a width unit else FALSE. */ - public function hasUnits() + public function hasWidthUnit() { - return ($this->widthUnit !== null) && ($this->heightUnit !== null); + return $this->widthUnit !== null; } /** - * Gets the width unit size. + * Gets the width unit. * - * @return string The width unit size. + * @return string|null The width unit. */ public function getWidthUnit() { @@ -126,25 +112,29 @@ public function getWidthUnit() } /** - * Sets the width unit size. - * - * @param string $widthUnit The width unit size. + * Sets the width unit. * - * @throws \Ivory\GoogleMap\Exception\BaseException If the width unit is not valid. + * @param string|null $widthUnit The width unit. */ public function setWidthUnit($widthUnit) { - if (!is_string($widthUnit) && ($widthUnit !== null)) { - throw BaseException::invalidSizeWidthUnit(); - } - $this->widthUnit = $widthUnit; } /** - * Gets the height unit size. + * Checks if there is an height unit. * - * @return string The height unit size. + * @return boolean TRUE if there is an height unit else FALSE. + */ + public function hasHeightUnit() + { + return $this->heightUnit !== null; + } + + /** + * Gets the height unit. + * + * @return string|null The height unit. */ public function getHeightUnit() { @@ -152,18 +142,12 @@ public function getHeightUnit() } /** - * Sets the height unit size. - * - * @param string $heightUnit The height unit size. + * Sets the height unit. * - * @throws \Ivory\GoogleMap\Exception\BaseException If the height unit is not valid. + * @param string|null $heightUnit The height unit. */ public function setHeightUnit($heightUnit) { - if (!is_string($heightUnit) && ($heightUnit !== null)) { - throw BaseException::invalidSizeHeightUnit(); - } - $this->heightUnit = $heightUnit; } } diff --git a/src/Controls/ControlPosition.php b/src/Controls/ControlPosition.php index f2e30adf..dce369e1 100644 --- a/src/Controls/ControlPosition.php +++ b/src/Controls/ControlPosition.php @@ -11,13 +11,15 @@ namespace Ivory\GoogleMap\Controls; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Control position which describes a google map control position. + * Control position. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ControlPosition + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ControlPosition * @author GeLo */ -class ControlPosition +class ControlPosition extends AbstractUninstantiableAsset { const BOTTOM_CENTER = 'bottom_center'; const BOTTOM_LEFT = 'bottom_left'; @@ -31,37 +33,4 @@ class ControlPosition const TOP_CENTER = 'top_center'; const TOP_LEFT = 'top_left'; const TOP_RIGHT = 'top_right'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available control positions. - * - * @return array The control positions. - */ - public static function getControlPositions() - { - return array( - self::BOTTOM_CENTER, - self::BOTTOM_LEFT, - self::BOTTOM_RIGHT, - self::LEFT_BOTTOM, - self::LEFT_CENTER, - self::LEFT_TOP, - self::RIGHT_BOTTOM, - self::RIGHT_CENTER, - self::RIGHT_TOP, - self::TOP_CENTER, - self::TOP_LEFT, - self::TOP_RIGHT, - ); - } } diff --git a/src/Controls/Controls.php b/src/Controls/Controls.php new file mode 100644 index 00000000..a27aadb1 --- /dev/null +++ b/src/Controls/Controls.php @@ -0,0 +1,251 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Controls; + +/** + * Controls. + * + * @author GeLo + */ +class Controls +{ + /** @var \Ivory\GoogleMap\Controls\MapTypeControl|null */ + protected $mapTypeControl; + + /** @var \Ivory\GoogleMap\Controls\OverviewMapControl|null */ + protected $overviewMapControl; + + /** @var \Ivory\GoogleMap\Controls\PanControl|null */ + protected $panControl; + + /** @var \Ivory\GoogleMap\Controls\RotateControl|null */ + protected $rotateControl; + + /** @var \Ivory\GoogleMap\Controls\ScaleControl|null */ + protected $scaleControl; + + /** @var \Ivory\GoogleMap\Controls\StreetViewControl|null */ + protected $streetViewControl; + + /** @var \Ivory\GoogleMap\Controls\ZoomControl|null */ + protected $zoomControl; + + /** + * Checks if there is a map type control. + * + * @return boolean TRUE if there is a map type control else FALSE. + */ + public function hasMapTypeControl() + { + return $this->mapTypeControl !== null; + } + + /** + * Gets the map type control. + * + * @return \Ivory\GoogleMap\Controls\MapTypeControl|null The map type control. + */ + public function getMapTypeControl() + { + return $this->mapTypeControl; + } + + /** + * Sets the map type control. + * + * @param \Ivory\GoogleMap\Controls\MapTypeControl|null $mapTypeControl The map type control. + */ + public function setMapTypeControl(MapTypeControl $mapTypeControl = null) + { + $this->mapTypeControl = $mapTypeControl; + } + + /** + * Checks if there is an overview map control. + * + * @return boolean TRUE if there is an overview map control else FALSE. + */ + public function hasOverviewMapControl() + { + return $this->overviewMapControl !== null; + } + + /** + * Gets the overview map control. + * + * @return \Ivory\GoogleMap\Controls\OverviewMapControl|null The overview map control. + */ + public function getOverviewMapControl() + { + return $this->overviewMapControl; + } + + /** + * Sets the overview map control. + * + * @param \Ivory\GoogleMap\Controls\OverviewMapControl|null $overviewMapControl The overview map control. + */ + public function setOverviewMapControl(OverviewMapControl $overviewMapControl = null) + { + $this->overviewMapControl = $overviewMapControl; + } + + /** + * Checks if there is a pan control. + * + * @return boolean TRUE if there is a pan control else FALSE. + */ + public function hasPanControl() + { + return $this->panControl !== null; + } + + /** + * Gets the pan control. + * + * @return \Ivory\GoogleMap\Controls\PanControl|null The pan control. + */ + public function getPanControl() + { + return $this->panControl; + } + + /** + * Sets the pan control. + * + * @param \Ivory\GoogleMap\Controls\PanControl|null $panControl The pan control. + */ + public function setPanControl(PanControl $panControl = null) + { + $this->panControl = $panControl; + } + + /** + * Checks if there is a rotate control. + * + * @return boolean TRUE if there is a rotate control else FALSE. + */ + public function hasRotateControl() + { + return $this->rotateControl !== null; + } + + /** + * Gets the rotate control. + * + * @return \Ivory\GoogleMap\Controls\RotateControl|null The rotate control. + */ + public function getRotateControl() + { + return $this->rotateControl; + } + + /** + * Sets the rotate control. + * + * @param \Ivory\GoogleMap\Controls\RotateControl|null $rotateControl The rotate control. + */ + public function setRotateControl(RotateControl $rotateControl = null) + { + $this->rotateControl = $rotateControl; + } + + /** + * Checks if there is a scale control else FALSE. + * + * @return boolean TRUE if there is a scale control else FALSE. + */ + public function hasScaleControl() + { + return $this->scaleControl !== null; + } + + /** + * Gets the scale control. + * + * @return \Ivory\GoogleMap\Controls\ScaleControl|null The scale control. + */ + public function getScaleControl() + { + return $this->scaleControl; + } + + /** + * Sets the scale control. + * + * @param \Ivory\GoogleMap\Controls\ScaleControl|null $scaleControl The scale control. + */ + public function setScaleControl(ScaleControl $scaleControl = null) + { + $this->scaleControl = $scaleControl; + } + + /** + * Checks if there is a street view control. + * + * @return boolean TRUE if there is a street view control else FALSE. + */ + public function hasStreetViewControl() + { + return $this->streetViewControl !== null; + } + + /** + * Gets the street view control. + * + * @return \Ivory\GoogleMap\Controls\StreetViewControl|null The street view control. + */ + public function getStreetViewControl() + { + return $this->streetViewControl; + } + + /** + * Sets the street view control. + * + * @param \Ivory\GoogleMap\Controls\StreetViewControl|null $streetViewControl The street view control. + */ + public function setStreetViewControl(StreetViewControl $streetViewControl = null) + { + $this->streetViewControl = $streetViewControl; + } + + /** + * Checks if there is a zoom control. + * + * @return boolean TRUE if there is a zoom control else FALSE. + */ + public function hasZoomControl() + { + return $this->zoomControl !== null; + } + + /** + * Gets the zoom control. + * + * @return \Ivory\GoogleMap\Controls\ZoomControl|null The zoom control. + */ + public function getZoomControl() + { + return $this->zoomControl; + } + + /** + * Sets the zoom control. + * + * @param \Ivory\GoogleMap\Controls\ZoomControl|null $zoomControl The zoom control. + */ + public function setZoomControl(ZoomControl $zoomControl = null) + { + $this->zoomControl = $zoomControl; + } +} diff --git a/src/Controls/MapTypeControl.php b/src/Controls/MapTypeControl.php index 7e27cd6b..dd4bd46a 100644 --- a/src/Controls/MapTypeControl.php +++ b/src/Controls/MapTypeControl.php @@ -11,19 +11,18 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; use Ivory\GoogleMap\MapTypeId; /** - * Map type control options describes a google map type control options. + * Map type control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MapTypeControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapTypeControlOptions * @author GeLo */ class MapTypeControl { /** @var array */ - protected $mapTypeIds; + protected $mapTypeIds = array(); /** @var string */ protected $controlPosition; @@ -32,9 +31,9 @@ class MapTypeControl protected $mapTypeControlStyle; /** - * Create a map type control. + * Creates a map type control. * - * @param array $mapTypeIds The map type IDs. + * @param array $mapTypeIds The map type ids. * @param string $controlPosition The control position. * @param string $mapTypeControlStyle The map type control style. */ @@ -43,15 +42,33 @@ public function __construct( $controlPosition = ControlPosition::TOP_RIGHT, $mapTypeControlStyle = MapTypeControlStyle::DEFAULT_ ) { - $this->setMapTypeIds($mapTypeIds); + $this->addMapTypeIds($mapTypeIds); $this->setControlPosition($controlPosition); $this->setMapTypeControlStyle($mapTypeControlStyle); } /** - * Gets the map type IDs. + * Resets the map types ids. + */ + public function resetMapTypeIds() + { + $this->mapTypeIds = array(); + } + + /** + * Checks if there are map types ids. + * + * @return boolean TRUE if there are map type ids else FALSE. + */ + public function hasMapTypeIds() + { + return !empty($this->mapTypeIds); + } + + /** + * Gets the map type ids. * - * @return array The map type IDs. + * @return array The map type ids. */ public function getMapTypeIds() { @@ -59,37 +76,74 @@ public function getMapTypeIds() } /** - * Sets the map type IDs. + * Sets the map type ids. * - * @param array $mapTypeIds The map type IDs. + * @param array $mapTypeIds The map type ids. */ - public function setMapTypeIds($mapTypeIds) + public function setMapTypeIds(array $mapTypeIds) { - $this->mapTypeIds = array(); + $this->resetMapTypeIds(); + $this->addMapTypeIds($mapTypeIds); + } + /** + * Adds the map type ids. + * + * @param array $mapTypeIds The map type ids. + */ + public function addMapTypeIds(array $mapTypeIds) + { foreach ($mapTypeIds as $mapTypeId) { $this->addMapTypeId($mapTypeId); } } /** - * Add a map type ID. + * Removes the map type ids. * - * @param string $mapTypeId The map type ID to add. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the map type ID is not valid. + * @param array $mapTypeIds The map type ids. */ - public function addMapTypeId($mapTypeId) + public function removeMapTypeIds(array $mapTypeIds) { - if (!in_array($mapTypeId, MapTypeId::getMapTypeIds())) { - throw ControlException::invalidMapTypeId(); + foreach ($mapTypeIds as $mapTypeId) { + $this->removeMapTypeId($mapTypeId); } + } - if (!in_array($mapTypeId, $this->mapTypeIds)) { + /** + * Checks if there is a map type id. + * + * @param string $mapTypeId The map type id. + * + * @return boolean TRUE if there is the map type id else FALSE. + */ + public function hasMapTypeId($mapTypeId) + { + return in_array($mapTypeId, $this->mapTypeIds, true); + } + + /** + * Adds a map type id. + * + * @param string $mapTypeId The map type id. + */ + public function addMapTypeId($mapTypeId) + { + if (!$this->hasMapTypeId($mapTypeId)) { $this->mapTypeIds[] = $mapTypeId; } } + /** + * Removes a map type id. + * + * @param string $mapTypeId The map type id. + */ + public function removeMapTypeId($mapTypeId) + { + unset($this->mapTypeIds[array_search($mapTypeId, $this->mapTypeIds, true)]); + } + /** * Gets the control position. * @@ -104,15 +158,9 @@ public function getControlPosition() * Sets the control position. * * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. */ public function setControlPosition($controlPosition) { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - $this->controlPosition = $controlPosition; } @@ -129,16 +177,10 @@ public function getMapTypeControlStyle() /** * Sets the map type control style. * - * @param type $mapTypeControlStyle The map type control style. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the map type control style is not valid. + * @param string $mapTypeControlStyle The map type control style. */ public function setMapTypeControlStyle($mapTypeControlStyle) { - if (!in_array($mapTypeControlStyle, MapTypeControlStyle::getMapTypeControlStyles())) { - throw ControlException::invalidMapTypeControlStyle(); - } - $this->mapTypeControlStyle = $mapTypeControlStyle; } } diff --git a/src/Controls/MapTypeControlStyle.php b/src/Controls/MapTypeControlStyle.php index 9f7374f6..87a20eb8 100644 --- a/src/Controls/MapTypeControlStyle.php +++ b/src/Controls/MapTypeControlStyle.php @@ -11,39 +11,17 @@ namespace Ivory\GoogleMap\Controls; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Map type control style which describes a google map type control style. + * Map type control style. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ControlPosition + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ControlPosition * @author GeLo */ -class MapTypeControlStyle +class MapTypeControlStyle extends AbstractUninstantiableAsset { const DEFAULT_ = 'default'; const DROPDOWN_MENU = 'dropdown_menu'; const HORIZONTAL_BAR = 'horizontal_bar'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available map type control styles. - * - * @return array The map type control styles. - */ - public static function getMapTypeControlStyles() - { - return array( - self::DEFAULT_, - self::DROPDOWN_MENU, - self::HORIZONTAL_BAR, - ); - } } diff --git a/src/Controls/OverviewMapControl.php b/src/Controls/OverviewMapControl.php index 8d368e61..24a0b723 100644 --- a/src/Controls/OverviewMapControl.php +++ b/src/Controls/OverviewMapControl.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * An overview map control describes a google map overview control. + * Overview map control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#OverviewMapControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#OverviewMapControlOptions * @author GeLo */ class OverviewMapControl @@ -25,9 +23,9 @@ class OverviewMapControl protected $opened; /** - * Create an overview map control. + * Creates an overview map control. * - * @param boolean $opened TRUE if the overview map control is opened else FALSE. + * @param boolean $opened TRUE if it is opened else FALSE. */ public function __construct($opened = false) { @@ -35,9 +33,9 @@ public function __construct($opened = false) } /** - * Checks if the overview map control is opened. + * Checks if it is opened. * - * @return boolean TRUE if the overview map control is opened else FALSE. + * @return boolean TRUE if it is opened else FALSE. */ public function isOpened() { @@ -45,18 +43,12 @@ public function isOpened() } /** - * Sets if the overview map control is opened. - * - * @param boolean $opened TRUE if the overview map control is opened else FALSE. + * Sets if it is opened. * - * @throws \Ivory\GoogleMap\Exception\ControlException If the opened flag is not valid. + * @param boolean $opened TRUE if it is opened else FALSE. */ public function setOpened($opened) { - if (!is_bool($opened)) { - throw ControlException::invalidOverviewMapControlOpened(); - } - $this->opened = $opened; } } diff --git a/src/Controls/PanControl.php b/src/Controls/PanControl.php index d35905b9..7be7ebfd 100644 --- a/src/Controls/PanControl.php +++ b/src/Controls/PanControl.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * A pan control describes a google map pan control. + * Pan control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#PanControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#PanControlOptions * @author GeLo */ class PanControl @@ -25,9 +23,9 @@ class PanControl protected $controlPosition; /** - * Create a pan control. + * Creates a pan control. * - * @param string $controlPosition The pan control position. + * @param string $controlPosition The control position. */ public function __construct($controlPosition = ControlPosition::TOP_LEFT) { @@ -48,15 +46,9 @@ public function getControlPosition() * Sets the control position. * * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. */ public function setControlPosition($controlPosition) { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - $this->controlPosition = $controlPosition; } } diff --git a/src/Controls/RotateControl.php b/src/Controls/RotateControl.php index 2531a575..0be11f2b 100644 --- a/src/Controls/RotateControl.php +++ b/src/Controls/RotateControl.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * A rotate control describes a google map rotate control. + * Rotate control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#RotateControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#RotateControlOptions * @author GeLo */ class RotateControl @@ -25,9 +23,9 @@ class RotateControl protected $controlPosition; /** - * Create a rotate control. + * Creates a rotate control. * - * @param string $controlPosition The rotate control position. + * @param string $controlPosition The control position. */ public function __construct($controlPosition = ControlPosition::TOP_LEFT) { @@ -48,15 +46,9 @@ public function getControlPosition() * Sets the control position. * * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. */ public function setControlPosition($controlPosition) { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - $this->controlPosition = $controlPosition; } } diff --git a/src/Controls/ScaleControl.php b/src/Controls/ScaleControl.php index 2f03772a..4d84ccc1 100644 --- a/src/Controls/ScaleControl.php +++ b/src/Controls/ScaleControl.php @@ -11,60 +11,25 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * Scale control options describes a google map scale control options + * Scale control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ScaleControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ScaleControlOptions * @author GeLo */ class ScaleControl { - /** @var string */ - protected $controlPosition; - /** @var string */ protected $scaleControlStyle; /** * Creates a scale control. * - * @param string $controlPosition The control position. * @param string $scaleControlStyle The scale control style. */ - public function __construct( - $controlPosition = ControlPosition::BOTTOM_LEFT, - $scaleControlStyle = ScaleControlStyle::DEFAULT_ - ) { - $this->setControlPosition($controlPosition); - $this->setScaleControlStyle($scaleControlStyle); - } - - /** - * Gets the control position. - * - * @return string The control position. - */ - public function getControlPosition() + public function __construct($scaleControlStyle = ScaleControlStyle::DEFAULT_) { - return $this->controlPosition; - } - - /** - * Sets the control position. - * - * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. - */ - public function setControlPosition($controlPosition) - { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - - $this->controlPosition = $controlPosition; + $this->setScaleControlStyle($scaleControlStyle); } /** @@ -80,16 +45,10 @@ public function getScaleControlStyle() /** * Sets the scale control style. * - * @param type $scaleControlStyle The scale control style. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the scale control style is not valid. + * @param string $scaleControlStyle The scale control style. */ public function setScaleControlStyle($scaleControlStyle) { - if (!in_array($scaleControlStyle, ScaleControlStyle::getScaleControlStyles())) { - throw ControlException::invalidScaleControlStyle(); - } - $this->scaleControlStyle = $scaleControlStyle; } } diff --git a/src/Controls/ScaleControlStyle.php b/src/Controls/ScaleControlStyle.php index e513be8a..04f1729f 100644 --- a/src/Controls/ScaleControlStyle.php +++ b/src/Controls/ScaleControlStyle.php @@ -11,35 +11,15 @@ namespace Ivory\GoogleMap\Controls; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Scale control style which describes a google map scale control style. + * Scale control style. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ScaleControlStyle + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ScaleControlStyle * @author GeLo */ -class ScaleControlStyle +class ScaleControlStyle extends AbstractUninstantiableAsset { const DEFAULT_ = 'default'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available map scale control styles - * - * @return array The map scale constrol styles. - */ - public static function getScaleControlStyles() - { - return array( - self::DEFAULT_, - ); - } } diff --git a/src/Controls/StreetViewControl.php b/src/Controls/StreetViewControl.php index 36604709..f1a4a703 100644 --- a/src/Controls/StreetViewControl.php +++ b/src/Controls/StreetViewControl.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * A street view control describes a google map street view control. + * Street view control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#StreetViewControlOptions * @author GeLo */ class StreetViewControl @@ -48,15 +46,9 @@ public function getControlPosition() * Sets the control position. * * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. */ public function setControlPosition($controlPosition) { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - $this->controlPosition = $controlPosition; } } diff --git a/src/Controls/ZoomControl.php b/src/Controls/ZoomControl.php index 75dae652..ec0f6e67 100644 --- a/src/Controls/ZoomControl.php +++ b/src/Controls/ZoomControl.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Controls; -use Ivory\GoogleMap\Exception\ControlException; - /** - * A zoom control describes a google map zoom control. + * Zoom control. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ZoomControlOptions + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ZoomControlOptions * @author GeLo */ class ZoomControl @@ -28,7 +26,10 @@ class ZoomControl protected $zoomControlStyle; /** - * Create a zoom control + * Creates a zoom control. + * + * @param string $controlPosition The control position. + * @param string $zoomControlStyle The zoom control style. */ public function __construct( $controlPosition = ControlPosition::TOP_LEFT, @@ -52,15 +53,9 @@ public function getControlPosition() * Sets the control position. * * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the control position is not valid. */ public function setControlPosition($controlPosition) { - if (!in_array($controlPosition, ControlPosition::getControlPositions())) { - throw ControlException::invalidControlPosition(); - } - $this->controlPosition = $controlPosition; } @@ -78,15 +73,9 @@ public function getZoomControlStyle() * Sets the zoom control style. * * @param string $zoomControlStyle The zoom control style. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the zoom control style is not valid. */ public function setZoomControlStyle($zoomControlStyle) { - if (!in_array($zoomControlStyle, ZoomControlStyle::getZoomControlStyles())) { - throw ControlException::invalidZoomControlStyle(); - } - $this->zoomControlStyle = $zoomControlStyle; } } diff --git a/src/Controls/ZoomControlStyle.php b/src/Controls/ZoomControlStyle.php index 79bc2a39..438b6b6a 100644 --- a/src/Controls/ZoomControlStyle.php +++ b/src/Controls/ZoomControlStyle.php @@ -11,39 +11,17 @@ namespace Ivory\GoogleMap\Controls; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Zoom control style which describes a google map zoom control style. + * Zoom control style. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#ZoomControlStyle + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#ZoomControlStyle * @author GeLo */ -class ZoomControlStyle +class ZoomControlStyle extends AbstractUninstantiableAsset { const DEFAULT_ = 'default'; const LARGE = 'large'; const SMALL = 'small'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available map zoom control styles. - * - * @return array The map zoom control styles. - */ - public static function getZoomControlStyles() - { - return array( - self::DEFAULT_, - self::LARGE, - self::SMALL, - ); - } } diff --git a/src/Events/DomEvent.php b/src/Events/DomEvent.php new file mode 100644 index 00000000..71dbd05f --- /dev/null +++ b/src/Events/DomEvent.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Events; + +/** + * Dom event. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener + * @author GeLo + */ +class DomEvent extends Event +{ + /** @var boolean */ + protected $capture; + + /** + * Creates a dom event. + * + * @param string $instance The instance. + * @param string $eventName The event name. + * @param string $handle The handle. + * @param boolean $capture TRUE if it is captured else FALSE. + */ + public function __construct($instance, $eventName, $handle, $capture = false) + { + parent::__construct($instance, $eventName, $handle); + + $this->setCapture($capture); + } + + /** + * Checks if it is captured. + * + * @return boolean TRUE if it is captured else FALSE. + */ + public function isCapture() + { + return $this->capture; + } + + /** + * Sets if it is captured. + * + * @param boolean $capture TRUE if it is captured else FALSE. + */ + public function setCapture($capture) + { + $this->capture = $capture; + } +} diff --git a/src/Events/Event.php b/src/Events/Event.php index 8de5abe7..ce808854 100644 --- a/src/Events/Event.php +++ b/src/Events/Event.php @@ -11,16 +11,15 @@ namespace Ivory\GoogleMap\Events; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\EventException; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Event which describes a google map event. + * Event. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener * @author GeLo */ -class Event extends AbstractJavascriptVariableAsset +class Event extends AbstractVariableAsset { /** @var string */ protected $instance; @@ -31,40 +30,26 @@ class Event extends AbstractJavascriptVariableAsset /** @var string */ protected $handle; - /** @var boolean */ - protected $capture; - /** * Creates an event. * - * @param string $instance The event object instance. - * @param string $eventName The event name. - * @param string $handle The event function handle. - * @param boolean $capture The event capture. + * @param string $instance The instance. + * @param string $eventName The event name. + * @param string $handle The handle. */ - public function __construct($instance = null, $eventName = null, $handle = null, $capture = false) + public function __construct($instance, $eventName, $handle) { - $this->setPrefixJavascriptVariable('event_'); - - if ($instance !== null) { - $this->setInstance($instance); - } - - if ($eventName !== null) { - $this->setEventName($eventName); - } + parent::__construct('event_'); - if ($handle !== null) { - $this->setHandle($handle); - } - - $this->setCapture($capture); + $this->setInstance($instance); + $this->setEventName($eventName); + $this->setHandle($handle); } /** - * Gets the event object instance. + * Gets the instance. * - * @return string The event object instance. + * @return string The instance. */ public function getInstance() { @@ -72,18 +57,12 @@ public function getInstance() } /** - * Sets the event object instance. - * - * @param string $instance The event object instance. + * Sets the instance. * - * @throws \Ivory\GoogleMap\Exception\EventException If the instance is not valid. + * @param string $instance The instance. */ public function setInstance($instance) { - if (!is_string($instance)) { - throw EventException::invalidInstance(); - } - $this->instance = $instance; } @@ -101,22 +80,16 @@ public function getEventName() * Sets the event name. * * @param string $eventName The event name. - * - * @throws \Ivory\GoogleMap\Exception\EventException If the event name is not valid. */ public function setEventName($eventName) { - if (!is_string($eventName)) { - throw EventException::invalidEventName(); - } - $this->eventName = $eventName; } /** - * Gets the event function handle. + * Gets the handle. * - * @return string The event function handle. + * @return string The handle. */ public function getHandle() { @@ -124,44 +97,12 @@ public function getHandle() } /** - * Sets the event function handle. - * - * @param string $handle The event function handle. + * Sets the handle. * - * @throws \Ivory\GoogleMap\Exception\EventException If the handle is not valid. + * @param string $handle The handle. */ public function setHandle($handle) { - if (!is_string($handle)) { - throw EventException::invalidHandle(); - } - $this->handle = $handle; } - - /** - * Checks if the event is capture. - * - * @return boolean TRUE if the event is capture else FALSE. - */ - public function isCapture() - { - return $this->capture; - } - - /** - * Sets if the event is capture. - * - * @param boolean $capture TRUE if the event is capture else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\EventException If the capture is not valid. - */ - public function setCapture($capture) - { - if (!is_bool($capture)) { - throw EventException::invalidCapture(); - } - - $this->capture = $capture; - } } diff --git a/src/Events/EventManager.php b/src/Events/EventManager.php deleted file mode 100644 index 2fc812bc..00000000 --- a/src/Events/EventManager.php +++ /dev/null @@ -1,148 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Events; - -/** - * Event manager which manages the google map event. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener - * @author GeLo - */ -class EventManager -{ - /** @var array */ - protected $domEvents; - - /** @var array */ - protected $domEventsOnce; - - /** @var array */ - protected $events; - - /** @var array */ - protected $eventsOnce; - - /** - * Creates an event manager. - * - * @param array $domEvents The dom events.Z - * @param array $domEventsOnce The dom events which are triggered only one time. - * @param array $events The events. - * @param array $eventsOnce The events which are triggered only one time. - */ - public function __construct( - array $domEvents = array(), - array $domEventsOnce = array(), - array $events = array(), - array $eventsOnce = array() - ) { - $this->domEvents = array(); - foreach ($domEvents as $domEvent) { - $this->addDomEvent($domEvent); - } - - $this->domEventsOnce = array(); - foreach ($domEventsOnce as $domEventOnce) { - $this->addDomEventOnce($domEventOnce); - } - - $this->events = array(); - foreach ($events as $event) { - $this->addEvent($event); - } - - $this->eventsOnce = array(); - foreach ($eventsOnce as $eventOnce) { - $this->addEventOnce($eventOnce); - } - } - - /** - * Gets the dom events. - * - * @return array The dom events. - */ - public function getDomEvents() - { - return $this->domEvents; - } - - /** - * Add a dom event. - * - * @param \Ivory\GoogleMap\Events\Event $domEvent The dom event. - */ - public function addDomEvent(Event $domEvent) - { - $this->domEvents[] = $domEvent; - } - - /** - * Gets the dom events which are just triggered one time. - * - * @return array The dom events which are just triggered one time. - */ - public function getDomEventsOnce() - { - return $this->domEventsOnce; - } - - /** - * Adds a dom event which is just triggered one time. - * - * @param \Ivory\GoogleMap\Events\Event $domEventOnce A dom event which is just triggered one time. - */ - public function addDomEventOnce(Event $domEventOnce) - { - $this->domEventsOnce[] = $domEventOnce; - } - - /** - * Gets the events. - * - * @return array The events. - */ - public function getEvents() - { - return $this->events; - } - - /** - * Adds an event. - * - * @param \Ivory\GoogleMap\Events\Event $event An event. - */ - public function addEvent(Event $event) - { - $this->events[] = $event; - } - - /** - * Gets the events which are just triggered one time. - * - * @return array The events which are just triggered one time. - */ - public function getEventsOnce() - { - return $this->eventsOnce; - } - - /** - * Adds an event which is just triggered one time. - * - * @param \Ivory\GoogleMap\Events\Event $eventOnce An event which is just triggered one time. - */ - public function addEventOnce(Event $eventOnce) - { - $this->eventsOnce[] = $eventOnce; - } -} diff --git a/src/Events/Events.php b/src/Events/Events.php new file mode 100644 index 00000000..d06c84fd --- /dev/null +++ b/src/Events/Events.php @@ -0,0 +1,421 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Events; + +/** + * Events. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapsEventListener + * @author GeLo + */ +class Events +{ + /** @var array */ + protected $events = array(); + + /** @var array */ + protected $eventsOnce = array(); + + /** @var array */ + protected $domEvents = array(); + + /** @var array */ + protected $domEventsOnce = array(); + + /** + * Resets the events. + */ + public function resetEvents() + { + $this->events = array(); + } + + /** + * Checks if there are events. + * + * @return boolean TRUE if there are events else FALSE. + */ + public function hasEvents() + { + return !empty($this->events); + } + + /** + * Gets the events. + * + * @return array The events. + */ + public function getEvents() + { + return $this->events; + } + + /** + * Sets the events. + * + * @param array $events The events. + */ + public function setEvents(array $events) + { + $this->resetEvents(); + $this->addEvents($events); + } + + /** + * Adds the events. + * + * @param array $events The events. + */ + public function addEvents(array $events) + { + foreach ($events as $event) { + $this->addEvent($event); + } + } + + /** + * Removes the events. + * + * @param array $events The events. + */ + public function removeEvents(array $events) + { + foreach ($events as $event) { + $this->removeEvent($event); + } + } + + /** + * Checks if there is an event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + * + * @return boolean TRUE if there is the event else FALSE. + */ + public function hasEvent(Event $event) + { + return in_array($event, $this->events, true); + } + + /** + * Adds an event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + */ + public function addEvent(Event $event) + { + if (!$this->hasEvent($event)) { + $this->events[] = $event; + } + } + + /** + * Removes an event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + */ + public function removeEvent(Event $event) + { + unset($this->events[array_search($event, $this->events, true)]); + } + + /** + * Resets the events once. + */ + public function resetEventsOnce() + { + $this->eventsOnce = array(); + } + + /** + * Checks if there are events once. + * + * @return boolean TRUE if there are events once else FALSE. + */ + public function hasEventsOnce() + { + return !empty($this->eventsOnce); + } + + /** + * Gets the events once. + * + * @return array The events once. + */ + public function getEventsOnce() + { + return $this->eventsOnce; + } + + /** + * Sets the events once. + * + * @param array $eventsOnce The events once. + */ + public function setEventsOnce(array $eventsOnce) + { + $this->resetEventsOnce(); + $this->addEventsOnce($eventsOnce); + } + + /** + * Adds the events once. + * + * @param array $eventsOnce The events once. + */ + public function addEventsOnce(array $eventsOnce) + { + foreach ($eventsOnce as $eventOnce) { + $this->addEventOnce($eventOnce); + } + } + + /** + * Removes the events once. + * + * @param array $eventsOnce The events once. + */ + public function removeEventsOnce(array $eventsOnce) + { + foreach ($eventsOnce as $eventOnce) { + $this->removeEventOnce($eventOnce); + } + } + + /** + * Checks if there is an event once. + * + * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. + * + * @return boolean TRUE if there is the dom event once else FALSE. + */ + public function hasEventOnce(Event $eventOnce) + { + return in_array($eventOnce, $this->eventsOnce, true); + } + + /** + * Adds an event once. + * + * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. + */ + public function addEventOnce(Event $eventOnce) + { + if (!$this->hasEventOnce($eventOnce)) { + $this->eventsOnce[] = $eventOnce; + } + } + + /** + * Removes an event once. + * + * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. + */ + public function removeEventOnce(Event $eventOnce) + { + unset($this->eventsOnce[array_search($eventOnce, $this->eventsOnce, true)]); + } + + /** + * Resets the dom events. + */ + public function resetDomEvents() + { + $this->domEvents = array(); + } + + /** + * Checks if there are dom events. + * + * @return boolean TRUE if there are dom events else FALSE. + */ + public function hasDomEvents() + { + return !empty($this->domEvents); + } + + /** + * Gets the dom events. + * + * @return array The dom events. + */ + public function getDomEvents() + { + return $this->domEvents; + } + + /** + * Sets the dom events. + * + * @param array $domEvents The dom events. + */ + public function setDomEvents(array $domEvents) + { + $this->resetDomEvents(); + $this->addDomEvents($domEvents); + } + + /** + * Adds the dom events. + * + * @param array $domEvents The dom events. + */ + public function addDomEvents(array $domEvents) + { + foreach ($domEvents as $domEvent) { + $this->addDomEvent($domEvent); + } + } + + /** + * Removes the dom events. + * + * @param array $domEvents The dom events. + */ + public function removeDomEvents(array $domEvents) + { + foreach ($domEvents as $domEvent) { + $this->removeDomEvent($domEvent); + } + } + + /** + * Checks if there is a dom event. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + * + * @return boolean TRUE if there is the dom event else FALSE. + */ + public function hasDomEvent(DomEvent $domEvent) + { + return in_array($domEvent, $this->domEvents, true); + } + + /** + * Adds a dom event. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + */ + public function addDomEvent(DomEvent $domEvent) + { + if (!$this->hasDomEvent($domEvent)) { + $this->domEvents[] = $domEvent; + } + } + + /** + * Removes a dom event. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + */ + public function removeDomEvent(DomEvent $domEvent) + { + unset($this->domEvents[array_search($domEvent, $this->domEvents, true)]); + } + + /** + * Resets the dom events once. + */ + public function resetDomEventsOnce() + { + $this->domEventsOnce = array(); + } + + /** + * Checks if there are dom events once. + * + * @return boolean TRUE if there are dom events once else FALSE. + */ + public function hasDomEventsOnce() + { + return !empty($this->domEventsOnce); + } + + /** + * Gets the dom events once. + * + * @return array The dom events once. + */ + public function getDomEventsOnce() + { + return $this->domEventsOnce; + } + + /** + * Sets the dom events once. + * + * @param array $domEventsOnce The dom events once. + */ + public function setDomEventsOnce(array $domEventsOnce) + { + $this->resetDomEventsOnce(); + $this->addDomEventsOnce($domEventsOnce); + } + + /** + * Adds the dom events once. + * + * @param array $domEventsOnce The dom events once. + */ + public function addDomEventsOnce(array $domEventsOnce) + { + foreach ($domEventsOnce as $domEventOnce) { + $this->addDomEventOnce($domEventOnce); + } + } + + /** + * Removes the dom events once. + * + * @param array $domEventsOnce The dom events once. + */ + public function removeDomEventsOnce(array $domEventsOnce) + { + foreach ($domEventsOnce as $domEventOnce) { + $this->removeDomEventOnce($domEventOnce); + } + } + + /** + * Checks if there is a dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEventOnce The dom event once. + * + * @return boolean TRUE if there is the dom event once else FALSE. + */ + public function hasDomEventOnce(DomEvent $domEventOnce) + { + return in_array($domEventOnce, $this->domEventsOnce, true); + } + + /** + * Adds a dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEventOnce A dom event once. + */ + public function addDomEventOnce(DomEvent $domEventOnce) + { + if (!$this->hasDomEventOnce($domEventOnce)) { + $this->domEventsOnce[] = $domEventOnce; + } + } + + /** + * Removes a dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEventOnce The dom event once. + */ + public function removeDomEventOnce(DomEvent $domEventOnce) + { + unset($this->domEventsOnce[array_search($domEventOnce, $this->domEventsOnce, true)]); + } +} diff --git a/src/Events/MouseEvent.php b/src/Events/MouseEvent.php index b5026464..dbae8ed8 100644 --- a/src/Events/MouseEvent.php +++ b/src/Events/MouseEvent.php @@ -11,12 +11,14 @@ namespace Ivory\GoogleMap\Events; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Mouse event describes the google map mouse event. + * Mouse event. * * @author GeLo */ -class MouseEvent +class MouseEvent extends AbstractUninstantiableAsset { const CLICK = 'click'; const DBLCLICK = 'dblclick'; @@ -24,31 +26,4 @@ class MouseEvent const MOUSEDOWN = 'mousedown'; const MOUSEOVER = 'mouseover'; const MOUSEOUT = 'mouseout'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available mouse events. - * - * @return array The mouse events. - */ - public static function getMouseEvents() - { - return array( - self::CLICK, - self::DBLCLICK, - self::MOUSEUP, - self::MOUSEDOWN, - self::MOUSEOVER, - self::MOUSEOUT, - ); - } } diff --git a/src/Exception/AssetException.php b/src/Exception/AssetException.php deleted file mode 100644 index 7d63b07c..00000000 --- a/src/Exception/AssetException.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Asset exception. - * - * @author GeLo - */ -class AssetException extends Exception -{ - /** - * Gets the "INVALID JAVASCRIPT VARIABLE" exception. - * - * @return \Ivory\GoogleMap\Exception\AssetException The "INVALID JAVASCRIPT VARIABLE" exception. - */ - public static function invalidJavascriptVariable() - { - return new static('The javascript variable must be a string value.'); - } - - /** - * Gets the "INVALID OPTION" exception. - * - * @return \Ivory\GoogleMap\Exception\AssetException The "INVALID OPTION" exception. - */ - public static function invalidOption() - { - return new static('The option property must be a string value.'); - } - - /** - * Gets the "INVALID PREFIX JAVASCRIPT VARIABLE" exception. - * - * @return \Ivory\GoogleMap\Exception\AssetException The "INVALID PREFIX JAVASCRIPT VARIABLE" exception. - */ - public static function invalidPrefixJavascriptVariable() - { - return new static('The prefix of a javascript variable must be a string value.'); - } - - /** - * Gets the "OPTION DOES NOT EXIST" exception. - * - * @param string $option The option. - * - * @return \Ivory\GoogleMap\Exception\AssetException The "OPTION DOES NOT EXIST" exception. - */ - public static function optionDoesNotExist($option) - { - return new static(sprintf('The option "%s" does not exist.', $option)); - } -} diff --git a/src/Exception/BaseException.php b/src/Exception/BaseException.php deleted file mode 100644 index eb4a6b55..00000000 --- a/src/Exception/BaseException.php +++ /dev/null @@ -1,142 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Base exception. - * - * @author GeLo - */ -class BaseException extends Exception -{ - /** - * Gets the "INVALID BOUND NORTH EAST" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID BOUND NORTH EAST" exception. - */ - public static function invalidBoundNorthEast() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The north east setter arguments is invalid.', - 'The available prototypes are :', - ' - function setNorthEast(Ivory\GoogleMap\Base\Coordinate $northEast)', - ' - function setNorthEast(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID BOUND SOUTH WEST" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID BOUND SOUTH WEST" exception. - */ - public static function invalidBoundSouthWest() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The south west setter arguments is invalid.', - 'The available prototypes are :', - ' - function setSouthWest(Ivory\GoogleMap\Base\Coordinate $southWest)', - ' - function setSouthWest(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID COORDINATE LATITUDE" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID COORDINATE LATITUDE" exception. - */ - public static function invalidCoordinateLatitude() - { - return new static('The latitude of a coordinate must be a numeric value.'); - } - - /** - * Gets the "INVALID COORDINATE LONGITUDE" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID COORDINATE LONGITUDE" exception. - */ - public static function invalidCoordinateLongitude() - { - return new static('The longitude of a coordinate must be a numeric value.'); - } - - /** - * Gets the "INVALID COORDINATE NO WRAP" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID COORDINATE NO WRAP" exception. - */ - public static function invalidCoordinateNoWrap() - { - return new static('The no wrap coordinate property must be a boolean value.'); - } - - /** - * Gets the "INVALID POINT X" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID POINT X" exception. - */ - public static function invalidPointX() - { - return new static('The x coordinate of a point must be a numeric value.'); - } - - /** - * Gets the "INVALID POINT Y" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID POINT Y" exception. - */ - public static function invalidPointY() - { - return new static('The y coordinate of a point must be a numeric value.'); - } - - /** - * Gets the "INVALID SIZE HEIGHT" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID SIZE HEIGHT" exception. - */ - public static function invalidSizeHeight() - { - return new static('The height of a size must be a numeric value.'); - } - - /** - * Gets the "INVALID SIZE HEIGHT UNIT" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID SIZE HEIGHT UNIT" exception. - */ - public static function invalidSizeHeightUnit() - { - return new static('The height unit of a size must be a string value.'); - } - - /** - * Gets the "INVALID SIZE WIDTH" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID SIZE WIDTH" exception. - */ - public static function invalidSizeWidth() - { - return new static('The width of a size must be a numeric value.'); - } - - /** - * Gets the "INVALID SIZE WIDTH UNIT" exception. - * - * @return \Ivory\GoogleMap\Exception\BaseException The "INVALID SIZE WIDTH UNIT" exception. - */ - public static function invalidSizeWidthUnit() - { - return new static('The width unit of a size must be a string value.'); - } -} diff --git a/src/Exception/ControlException.php b/src/Exception/ControlException.php deleted file mode 100644 index 541e0050..00000000 --- a/src/Exception/ControlException.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Controls\ZoomControlStyle; -use Ivory\GoogleMap\MapTypeId; - -/** - * Control exception. - * - * @author GeLo - */ -class ControlException extends Exception -{ - /** - * Gets the "INVALID CONTROL POSITION" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID CONTROL POSITION" exception. - */ - public static function invalidControlPosition() - { - return new static(sprintf( - 'The control position can only be : %s.', - implode(', ', ControlPosition::getControlPositions()) - )); - } - - /** - * Gets the "INVALID MAP TYPE CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID MAP TYPE CONTROL STYLE" exception. - */ - public static function invalidMapTypeControlStyle() - { - return new static(sprintf( - 'The map type control style can only be : %s.', - implode(', ', MapTypeControlStyle::getMapTypeControlStyles()) - )); - } - - /** - * Gets the "INVALID MAP TYPE ID" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID MAP TYPE ID" exception. - */ - public static function invalidMapTypeId() - { - return new static(sprintf('The map type id can only be : %s.', implode(', ', MapTypeId::getMapTypeIds()))); - } - - /** - * Gets the "INVALID OVERVIEW MAP CONTROL OPENED" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID OVERVIEW MAP CONTROL OPENED" exception. - */ - public static function invalidOverviewMapControlOpened() - { - return new static('The opened property of an overview map control must be a boolean value.'); - } - - /** - * Gets the "INVALID SCALE CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID SCALE CONTROL STYLE" exception. - */ - public static function invalidScaleControlStyle() - { - return new static(sprintf( - 'The scale control style of a scale control can only be : %s.', - implode(', ', ScaleControlStyle::getScaleControlStyles()) - )); - } - - /** - * Gets the "INVALID ZOOM CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\ControlException The "INVALID ZOOM CONTROL STYLE" exception. - */ - public static function invalidZoomControlStyle() - { - return new static(sprintf( - 'The zoom control style of a zoom control can only be : %s.', - implode(', ', ZoomControlStyle::getZoomControlStyles()) - )); - } -} diff --git a/src/Exception/DirectionsException.php b/src/Exception/DirectionsException.php deleted file mode 100644 index 4a726d60..00000000 --- a/src/Exception/DirectionsException.php +++ /dev/null @@ -1,328 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Services\Directions\DirectionsStatus; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - -/** - * Directions exception. - * - * @author GeLo - */ -class DirectionsException extends ServiceException -{ - /** - * Gets the "INVALID DIRECTIONS LEG END ADDRESS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS LEG END ADDRESS" exception. - */ - public static function invalidDirectionsLegEndAddress() - { - return new static('The leg end address must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS LEG START ADDRESS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS LEG START ADDRESS" exception. - */ - public static function invalidDirectionsLegStartAddress() - { - return new static('The leg start address must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST" exception. - */ - public static function invalidDirectionsRequest() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The directions request is not valid. It needs at least an origin and a destination.', - 'If you add waypoint to the directions request, it needs at least a location.', - 'If travel mode is "TRANSIT", it needs either a departure time or an arrival time.' - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST PARAMETERS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST PARAMETERS" exception. - */ - public static function invalidDirectionsRequestParameters() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The route arguments are invalid.', - 'The available prototypes are:', - '- function route(string $origin, string $destination)', - '- function route(Ivory\GoogleMap\Services\Directions\DirectionsRequest $request)' - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST AVOID HIGHWAYS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST AVOID HIGHWAYS" exception. - */ - public static function invalidDirectionsRequestAvoidHighways() - { - return new static('The directions request avoid hightways flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST AVOID TOLLS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST AVOID TOLLS" exception. - */ - public static function invalidDirectionsRequestAvoidTolls() - { - return new static('The directions request avoid tolls flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST DESTINATION" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST DESTINATION" exception. - */ - public static function invalidDirectionsRequestDestination() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The destination setter arguments are invalid.', - 'The available prototypes are :', - ' - function setDestination(string $destination)', - ' - function setDestination(Ivory\GoogleMap\Base\Coordinate $destination)', - ' - function setDestination(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST OPTIMIZE WAYPOINTS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST OPTIMIZE WAYPOINTS" - * exception. - */ - public static function invalidDirectionsRequestOptimizeWaypoints() - { - return new static('The directions request optimize waypoints flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST ORIGIN" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST ORIGIN" exception. - */ - public static function invalidDirectionsRequestOrigin() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The origin setter arguments are invalid.', - 'The available prototypes are :', - ' - function setOrigin(string $destination)', - ' - function setOrigin(Ivory\GoogleMap\Base\Coordinate $destination)', - ' - function setOrigin(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST PROVIDE ROUTE ALTERNATIVES" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST PROVIDE ROUTE - * ALTERNATIVES" exception. - */ - public static function invalidDirectionsRequestProvideRouteAlternatives() - { - return new static('The directions request provide route alternatives flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST REGION" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST REGION" exception. - */ - public static function invalidDirectionsRequestRegion() - { - return new static('The directions request region must be a string with two characters.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST LANGUAGE" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST LANGUAGE" exception. - */ - public static function invalidDirectionsRequestLanguage() - { - return new static('The directions request language must be a string with two or five characters.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST SENSOR" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST SENSOR" exception. - */ - public static function invalidDirectionsRequestSensor() - { - return new static('The directions request sensor flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST TRAVEL MODE" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST TRAVEL MODE" exception. - */ - public static function invalidDirectionsRequestTravelMode() - { - return new static(sprintf( - 'The directions request travel mode can only be : %s.', - implode(', ', TravelMode::getTravelModes()) - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST UNIT SYSTEM" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST UNIT SYSTEM" exception. - */ - public static function invalidDirectionsRequestUnitSystem() - { - return new static(sprintf( - 'The directions request unit system can only be : %s.', - implode(', ', UnitSystem::getUnitSystems()) - )); - } - - /** - * Gets the "INVALID DIRECTIONS REQUEST WAYPOINT" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS REQUEST WAYPOINT" exception. - */ - public static function invalidDirectionsRequestWaypoint() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The waypoint adder arguments are invalid.', - 'The available prototypes are :', - ' - function addWaypoint(Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint)', - ' - function addWaypoint(string $location)', - ' - function addWaypoint(Ivory\GoogleMap\Base\Coordinate $location)', - ' - function addWaypoint(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DIRECTIONS RESPONSE STATUS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS RESPONSE STATUS" exception. - */ - public static function invalidDirectionsResponseStatus() - { - return new static(sprintf( - 'The directions response status can only be : %s.', - implode(', ', DirectionsStatus::getDirectionsStatus()) - )); - } - - /** - * Gets the "INVALID DIRECTIONS ROUTE COPYRIGHTS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS ROUTE COPYRIGHTS" exception. - */ - public static function invalidDirectionsRouteCopyrights() - { - return new static('The directions route copyrights must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS ROUTE SUMMARY" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS ROUTE SUMMARY" exception. - */ - public static function invalidDirectionsRouteSummary() - { - return new static('The directions route summary must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS ROUTE WARNING" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS ROUTE WARNING" exception. - */ - public static function invalidDirectionsRouteWarning() - { - return new static('The directions route warning must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS ROUTE WAYPOINT ORDER" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS ROUTE WAYPOINT ORDER" exception. - */ - public static function invalidDirectionsRouteWaypointOrder() - { - return new static('The directions route waypoint order must be an integer value.'); - } - - /** - * Gets the "INALID DIRECTIONS STEP INSTRUCTIONS" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INALID DIRECTIONS STEP INSTRUCTIONS" exception. - */ - public static function invalidDirectionsStepInstructions() - { - return new static('The step instructions must be a string value.'); - } - - /** - * Gets the "INVALID DIRECTIONS STEP TRAVEL MODE" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS STEP TRAVEL MODE" exception. - */ - public static function invalidDirectionsStepTravelMode() - { - return new static(sprintf( - 'The directions step travel mode can only be : %s.', - implode(', ', TravelMode::getTravelModes()) - )); - } - - /** - * Gets the "INVALID DIRECTIONS WAYPOINT LOCATION" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS WAYPOINT LOCATION" exception. - */ - public static function invalidDirectionsWaypointLocation() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The location setter arguments are invalid.', - 'The available prototypes are :', - ' - function setLocation(string $destination)', - ' - function setLocation(Ivory\GoogleMap\Base\Coordinate $destination)', - ' - function setLocation(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DIRECTIONS WAYPOINT STOPOPVER" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DIRECTIONS WAYPOINT STOPOPVER" exception. - */ - public static function invalidDirectionsWaypointStopover() - { - return new static('The directions waypoint stopover flag must be a boolean value.'); - } -} diff --git a/src/Exception/DistanceMatrixException.php b/src/Exception/DistanceMatrixException.php deleted file mode 100644 index 09ada47e..00000000 --- a/src/Exception/DistanceMatrixException.php +++ /dev/null @@ -1,190 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixStatus; -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixElementStatus; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - -/** - * DistanceMatrix exception. - * - * @author GeLo - * @author Tyler Sommer - */ -class DistanceMatrixException extends ServiceException -{ - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST" exception. - */ - public static function invalidDistanceMatrixRequest() - { - return new static('The directions request is not valid. It needs at least one origin and one destination.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST PARAMETERS" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST PARAMETERS" exception. - */ - public static function invalidDistanceMatrixRequestParameters() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The process arguments are invalid.', - 'The available prototypes are:', - '- function process(array $origins, array $destinations)', - '- function process(Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $request)' - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST DESTINATION" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST DESTINATION" exception. - */ - public static function invalidDistanceMatrixRequestDestination() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The destination adder arguments are invalid.', - 'The available prototypes are :', - ' - function addDestination(string $destination)', - ' - function addDestination(Ivory\GoogleMap\Base\Coordinate $destination)', - ' - function addDestination(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST ORIGIN" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST ORIGIN" exception. - */ - public static function invalidDistanceMatrixRequestOrigin() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The origin adder arguments are invalid.', - 'The available prototypes are :', - ' - function addOrigin(string $origin)', - ' - function addOrigin(Ivory\GoogleMap\Base\Coordinate $origin)', - ' - function addOrigin(double $latitude, double $longitude, boolean $noWrap)' - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST REGION" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST REGION" exception. - */ - public static function invalidDistanceMatrixRequestRegion() - { - return new static('The distance matrix request region must be a string with two characters.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST LANGUAGE" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST LANGUAGE" exception. - */ - public static function invalidDistanceMatrixRequestLanguage() - { - return new static('The distance matrix request language must be a string with two or five characters.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST SENSOR" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST SENSOR" exception. - */ - public static function invalidDistanceMatrixRequestSensor() - { - return new static('The distance matrix request sensor flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST TRAVEL MODE" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST TRAVEL MODE" exception. - */ - public static function invalidDistanceMatrixRequestTravelMode() - { - $travelModes = array_diff(TravelMode::getTravelModes(), array(TravelMode::TRANSIT)); - - return new static(sprintf( - 'The distance matrix request travel mode can only be : %s.', - implode(', ', $travelModes) - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST UNIT SYSTEM" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST UNIT SYSTEM" exception. - */ - public static function invalidDistanceMatrixRequestUnitSystem() - { - return new static(sprintf( - 'The distance matrix request unit system can only be : %s.', - implode(', ', UnitSystem::getUnitSystems()) - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST AVOID HIGHWAYS" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST AVOID HIGHWAYS" exception. - */ - public static function invalidDistanceMatrixRequestAvoidHighways() - { - return new static('The distance matrix request avoid hightways flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX REQUEST AVOID TOLLS" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX REQUEST AVOID TOLLS" exception. - */ - public static function invalidDistanceMatrixRequestAvoidTolls() - { - return new static('The distance matrix request avoid tolls flag must be a boolean value.'); - } - - /** - * Gets the "INVALID DISTANCE MATRIX RESPONSE STATUS" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX RESPONSE STATUS" exception. - */ - public static function invalidDistanceMatrixResponseStatus() - { - return new static(sprintf( - 'The distance matrix response status can only be : %s.', - implode(', ', DistanceMatrixStatus::getDistanceMatrixStatus()) - )); - } - - /** - * Gets the "INVALID DISTANCE MATRIX RESPONSE ELEMENT STATUS" exception. - * - * @return \Ivory\GoogleMap\Exception\DistanceMatrixException The "INVALID DISTANCE MATRIX RESPONSE ELEMENT STATUS" exception. - */ - public static function invalidDistanceMatrixResponseElementStatus() - { - return new static(sprintf( - 'The distance matrix response element status can only be : %s.', - implode(', ', DistanceMatrixElementStatus::getDistanceMatrixElementStatus()) - )); - } -} diff --git a/src/Exception/EventException.php b/src/Exception/EventException.php deleted file mode 100644 index 17a80134..00000000 --- a/src/Exception/EventException.php +++ /dev/null @@ -1,60 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Event exception. - * - * @author GeLo - */ -class EventException extends Exception -{ - /** - * Gets the "INVALID CAPTURE" exception. - * - * @return \Ivory\GoogleMap\Exception\EventException The "INVALID CAPTURE" exception. - */ - public static function invalidCapture() - { - return new static('The capture property of an event must be a boolean value.'); - } - - /** - * Gets the "INVALID EVENT NAME" exception. - * - * @return \Ivory\GoogleMap\Exception\EventException The "INVALID EVENT NAME" exception. - */ - public static function invalidEventName() - { - return new static('The event name of an event must be a string value.'); - } - - /** - * Gets the "INVALID HANDLE" exception. - * - * @return \Ivory\GoogleMap\Exception\EventException The "INVALID HANDLE" exception. - */ - public static function invalidHandle() - { - return new static('The handle of an event must be a string value.'); - } - - /** - * Gets the "INVALID INSTANCE" exception. - * - * @return \Ivory\GoogleMap\Exception\EventException The "INVALID INSTANCE" exception. - */ - public static function invalidInstance() - { - return new static('The instance of an event must be a string value.'); - } -} diff --git a/src/Exception/GeocodingException.php b/src/Exception/GeocodingException.php deleted file mode 100644 index 6fca2e09..00000000 --- a/src/Exception/GeocodingException.php +++ /dev/null @@ -1,254 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderLocationType; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderStatus; - -/** - * Geocoding exception. - * - * @author GeLo - */ -class GeocodingException extends ServiceException -{ - /** - * Gets the "INVALID GEOCODER ADDRESS COMPONENT LONG NAME" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER ADDRESS COMPONENT LONG NAME" - * exception. - */ - public static function invalidGeocoderAddressComponentLongName() - { - return new static('The geocoder address component long name must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER ADDRESS COMPONENT SHORT NAME" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER ADDRESS COMPONENT SHORT NAME" - * exception. - */ - public static function invalidGeocoderAddressComponentShortName() - { - return new static('The geocoder address component short name must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER ADDRESS COMPONENT TYPE" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER ADDRESS COMPONENT TYPE" exception. - */ - public static function invalidGeocoderAddressComponentType() - { - return new static('The geocoder address component type must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER LOCATION TYPE" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER LOCATION TYPE" exception. - */ - public static function invalidGeocoderLocationType() - { - return new static(sprintf( - 'The geocoder geometry location type can only be : %s.', - implode(', ', GeocoderLocationType::getGeocoderLocationTypes()) - )); - } - - /** - * Gets the "INVALID GEOCODER PROVIDER FORMAT" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER PROVIDER FORMAT" exception. - */ - public static function invalidGeocoderProviderFormat() - { - return new static(sprintf( - 'The geocoder provider format can only be : %s.', - implode(', ', array('json', 'xml')) - )); - } - - /** - * Gets the "INVALID GEOCODER PROVIDER HTTPS" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER PROVIDER HTTPS" exception. - */ - public static function invalidGeocoderProviderHttps() - { - return new static('The geocoder provider https flag must be a boolean value.'); - } - - /** - * Gets the "INVALID GEOCODER PROVIDER REQUEST" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER PROVIDER REQUEST" exception. - */ - public static function invalidGeocoderProviderRequest() - { - return new static('The geocoder request is not valid. It needs at least an address or a coordinate.'); - } - - /** - * Gets the "INVALID GEOCODER PROVIDER REQUEST ARGUMENTS" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER PROVIDER REQUEST ARGUMENTS" - * exception. - */ - public static function invalidGeocoderProviderRequestArguments() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The geolocate argument is invalid.', - 'The available prototypes are :', - ' - function geocode(string $address)', - ' - function geocode(Ivory\GoogleMap\Services\Geocoding\GeocoderRequest $request)' - )); - } - - /** - * Gets the "INVALID GEOCODER PROVIDER URL" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER PROVIDER URL" exception. - */ - public static function invalidGeocoderProviderUrl() - { - return new static('The geocoder provider url must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER REQUEST ADDRESS" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST ADDRESS" exception. - */ - public static function invalidGeocoderRequestAddress() - { - return new static('The geocoder request address must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER REQUEST BOUND" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST BOUND" exception. - */ - public static function invalidGeocoderRequestBound() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The bound setter arguments are invalid.', - 'The available prototypes are :', - ' - function setBound(Ivory\GoogleMap\Base\Bound $bound = null)', - ' - function setBound('. - 'Ivory\GoogleMap\Base\Coordinate $southWest, '. - 'Ivory\GoogleMap\Base\Coordinate $northEast'. - ')', - ' - function setBound('. - 'double $southWestLatitude, '. - 'double $southWestLongitude, '. - 'double $northEastLatitude, '. - 'double $northEastLongitude, '. - 'boolean southWestNoWrap = true, '. - 'boolean $northEastNoWrap = true'. - ')' - )); - } - - /** - * Gets the "INVALID GEOCODER REQUEST COORDINATE" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST COORDINATE" exception. - */ - public static function invalidGeocoderRequestCoordinate() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The coordinate setter arguments is invalid.', - 'The available prototypes are :', - ' - function setCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate = null)', - ' - function setCoordinate(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID GEOCODER REQUEST REGION" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST REGION" exception. - */ - public static function invalidGeocoderRequestRegion() - { - return new static('The geocoder request region must be a string with two characters.'); - } - - /** - * Gets the "INVALID GEOCODER REQUEST LANGUAGE" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST LANGUAGE" exception. - */ - public static function invalidGeocoderRequestLanguage() - { - return new static('The geocoder request language must be a string with two or five characters.'); - } - - /** - * Gets the "INVALID GEOCODER REQUEST SENSOR" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER REQUEST SENSOR" exception. - */ - public static function invalidGeocoderRequestSensor() - { - return new static('The geocoder request sensor flag must be a boolean value.'); - } - - /** - * Gets the "INVALID GEOCODER RESPONSE STATUS" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER RESPONSE STATUS" exception. - */ - public static function invalidGeocoderResponseStatus() - { - return new static(sprintf( - 'The geocoder response status can only be : %s.', - implode(', ', GeocoderStatus::getGeocoderStatus()) - )); - } - - /** - * Gets the "INVALID GEOCODER RESULT FORMATTED ADDRESS" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER RESULT FORMATTED ADDRESS" exception. - */ - public static function invalidGeocoderResultFormattedAddress() - { - return new static('The geocoder result formatted address must be a string value.'); - } - - /** - * Gets the "INVALID GEOCODER RESULT PARTIAL MATCH" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER RESULT PARTIAL MATCH" exception. - */ - public static function invalidGeocoderResultPartialMatch() - { - return new static('The geocoder result partial match flag must be a boolean value.'); - } - - /** - * Gets the "INVALID GEOCODER RESULT TYPE" exception. - * - * @return \Ivory\GoogleMap\Exception\GeocodingException The "INVALID GEOCODER RESULT TYPE" exception. - */ - public static function invalidGeocoderResultType() - { - return new static('The geocoder result type must be a string value.'); - } -} diff --git a/src/Exception/HelperException.php b/src/Exception/HelperException.php deleted file mode 100644 index d43db1fb..00000000 --- a/src/Exception/HelperException.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Controls\ZoomControlStyle; -use Ivory\GoogleMap\Overlays\Animation; -use Ivory\GoogleMap\MapTypeId; - -/** - * Helper exception. - * - * @author GeLo - */ -class HelperException extends Exception -{ - /** - * Gets the "INVALID ANIMATION" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID ANIMATION" exception. - */ - public static function invalidAnimation() - { - return new static(sprintf('The animation can only be : %s.', implode(', ', Animation::getAnimations()))); - } - - /** - * Gets the "INVALID AUTOCOMPLETE BOUND" exception. - * - * @return \Ivory\GoogleMap\Exception\TemplatingException The "INVALID AUTOCOMPLETE BOUND" exception. - */ - public static function invalidAutocompleteBound() - { - return new static('The place autocomplete bound must have coordinates.'); - } - - /** - * Gets the "INVALID CONTROL POSITION" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID CONTROL POSITION" exception. - */ - public static function invalidControlPosition() - { - return new static(sprintf( - 'The control position can only be : %s.', - implode(', ', ControlPosition::getControlPositions()) - )); - } - - /** - * Gets the "INVALID ENCODED PATH" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID ENCODED PATH" exception. - */ - public static function invalidEncodedPath() - { - return new static('The encoded path must be a string value.'); - } - - /** - * Gets the "INVALID EXTENSION" exception. - * - * @param string $name The "INVALID EXTENSION" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID EXTENSION" exception. - */ - public static function invalidExtension($name) - { - return new static(sprintf('The extension helper "%s" does not exist.', $name)); - } - - /** - * Gets the "INVALID MAP TYPE CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID MAP TYPE CONTROL STYLE" exception. - */ - public static function invalidMapTypeControlStyle() - { - return new static(sprintf( - 'The map type control style can only be : %s.', - implode(', ', MapTypeControlStyle::getMapTypeControlStyles()) - )); - } - - /** - * Gets the "INVALID MAP TYPE ID" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID MAP TYPE ID" exception. - */ - public static function invalidMapTypeId() - { - return new static(sprintf('The map type id can only be : %s.', implode(', ', MapTypeId::getMapTypeIds()))); - } - - /** - * Gets the "INVALID MARKER CLUSTER HELPER" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID MARKER CLUSTER HELPER" exception. - */ - public static function invalidMarkerClusterHelper() - { - return new static('The marker cluster helper can not be resolved.'); - } - - /** - * Gets the "INVALID SCALE CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID SCALE CONTROL STYLE" exception. - */ - public static function invalidScaleControlStyle() - { - return new static(sprintf( - 'The scale control style can only be : %s.', - implode(', ', ScaleControlStyle::getScaleControlStyles()) - )); - } - - /** - * Gets the "INVALID ZOOM CONTROL STYLE" exception. - * - * @return \Ivory\GoogleMap\Exception\HelperException The "INVALID ZOOM CONTROL STYLE" exception. - */ - public static function invalidZoomControlStyle() - { - return new static(sprintf( - 'The zoom control style can only be : %s.', - implode(', ', ZoomControlStyle::getZoomControlStyles()) - )); - } -} diff --git a/src/Exception/LayerException.php b/src/Exception/LayerException.php deleted file mode 100644 index fca53820..00000000 --- a/src/Exception/LayerException.php +++ /dev/null @@ -1,30 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Layer exception. - * - * @author GeLo - */ -class LayerException extends Exception -{ - /** - * Gets the "INVALID KML LAYER URL" exception. - * - * @return \Ivory\GoogleMap\Exception\LayerException The "INVALID KML LAYER URL" exception. - */ - public static function invalidKmlLayerUrl() - { - return new static('The kml layer url must be a string value.'); - } -} diff --git a/src/Exception/MapException.php b/src/Exception/MapException.php deleted file mode 100644 index fcb13bb1..00000000 --- a/src/Exception/MapException.php +++ /dev/null @@ -1,249 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Ivory google map exception. - * - * @author GeLo - */ -class MapException extends Exception -{ - /** - * Gets the "INVALID ASYNC" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID ASYNC" exception. - */ - public static function invalidAsync() - { - return new static('The asynchronous load of a map must be a boolean value.'); - } - - /** - * Gets the "INVALID AUTO ZOOM" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID AUTO ZOOM" exception. - */ - public static function invalidAutoZoom() - { - return new static('The auto zoom of a map must be a boolean value.'); - } - - /** - * Gets the "INVALID BOUND" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID BOUND" exception. - */ - public static function invalidBound() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The bound setter arguments is invalid.', - 'The available prototypes are :', - ' - function setBound(Ivory\GoogleMap\Base\Bound $bound)', - ' - function setBount('. - 'Ivory\GoogleMap\Base\Coordinate $southWest, '. - 'Ivory\GoogleMap\Base\Coordinate $northEast'. - ')', - ' - function setBound('. - 'double $southWestLatitude, '. - 'double $southWestLongitude, '. - 'double $northEastLatitude, '. - 'double $northEastLongitude, '. - 'boolean southWestNoWrap = true, '. - 'boolean $northEastNoWrap = true'. - ')' - )); - } - - /** - * Gets the "INVALID CENTER" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID CENTER" exception. - */ - public static function invalidCenter() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The center setter arguments is invalid.', - 'The available prototypes are :', - ' - function setCenter(Ivory\GoogleMap\Base\Coordinate $center)', - ' - function setCenter(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID HTML CONTAINER ID" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID HTML CONTAINER ID" exception. - */ - public static function invalidHtmlContainerId() - { - return new static('The html container id of a map must be a string value.'); - } - - /** - * Gets the "INVALID MAP OPTION" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID MAP OPTION" exception. - */ - public static function invalidMapOption() - { - return new static('The map option property of a map must be a string value.'); - } - - /** - * Gets the "INVALID MAP TYPE CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INAVLID MAP TYPE CONTROL" exception. - */ - public static function invalidMapTypeControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The map type control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setMapTypeControl(Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl = null)', - ' - function setMaptypeControl(array $mapTypeIds, string $controlPosition, string $mapTypeControlStyle)' - )); - } - - /** - * Gets the "INVALID OVERVIEW MAP CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID OVERVIEW MAP CONTROL" exception. - */ - public static function invalidOverviewMapControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The overview map control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setOverviewMapControl(Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl = null)', - ' - function setOverviewMapControl(boolean $opened)' - )); - } - - /** - * Gets the "INVALID PAN CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID PAN CONTROL" exception. - */ - public static function invalidPanControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The pan control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setPanControl(Ivory\GoogleMap\Controls\PanControl $panControl = null)', - ' - function setPanControl(string $controlPosition)' - )); - } - - /** - * Gets the "INVALID ROTATE CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID ROTATE CONTROL" exception. - */ - public static function invalidRotateControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The rotate control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setRotateControl(Ivory\GoogleMap\Controls\RotateControl $rotateControl = null)', - ' - function setRotateControl(string $controlPosition)' - )); - } - - /** - * Gets the "INVALID SCALE CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID SCALE CONTROL" exception. - */ - public static function invalidScaleControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The scale control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setScaleControl(Ivory\GoogleMap\Controls\ScaleControl $scaleControl = null)', - ' - function setScaleControl(string $controlPosition, string $scaleControlStyle)' - )); - } - - /** - * Gets the "INVALID STREET VIEW CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID STREET VIEW CONTROL" exception. - */ - public static function invalidStreetViewControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The street view control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setStreetViewControl(Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl = null)', - ' - function setStreetViewControl(string $controlPosition)' - )); - } - - /** - * Gets the "INVALID ZOOM CONTROL" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INVALID ZOOM CONTROL" exception. - */ - public static function invalidZoomControl() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The zoom control setter arguments is invalid.', - 'The available prototypes are :', - ' - function setZoomControl(Ivory\GoogleMap\Controls\ZoomControl $zoomControl = null)', - ' - function setZoomControl(string $controlPosition, string $zoomControlStyle)' - )); - } - - /** - * Gets the "INVALID STYLESHEET OPTION" exception. - * - * @return \Ivory\GoogleMap\Exception\MapException The "INAVLID STYLESHEET OPTION" exception. - */ - public static function invalidStylesheetOption() - { - return new static('The stylesheet option property of a map must be a string value.'); - } - - /** - * Gets the "MAP OPTION DOES NOT EXIST" exception. - * - * @param string $mapOption The map option. - * - * @return \Ivory\GoogleMap\Exception\MapException The "MAP OPTION DOES NOT EXIST" exception. - */ - public static function mapOptionDoesNotExist($mapOption) - { - return new static(sprintf('The map option "%s" does not exist.', $mapOption)); - } - - /** - * Gets the "STYLESHEET OPTION DOES NOT EXIST" exception. - * - * @param string $stylesheetOption The stylesheet option. - * - * @return \Ivory\GoogleMap\Exception\MapException The "STYLESHEET OPTION DOES NOT EXIST" exception. - */ - public static function stylesheetOptionDoesNotExist($stylesheetOption) - { - return new static(sprintf('The stylesheet option "%s" does not exist.', $stylesheetOption)); - } -} diff --git a/src/Exception/OverlayException.php b/src/Exception/OverlayException.php deleted file mode 100644 index bf9abbb5..00000000 --- a/src/Exception/OverlayException.php +++ /dev/null @@ -1,536 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Events\MouseEvent; -use Ivory\GoogleMap\Overlays\Animation; - -/** - * Overlay exception. - * - * @author GeLo - */ -class OverlayException extends Exception -{ - /** - * Gets the "INVALID CIRCLE CENTER" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID CIRCLE CENTER" exception. - */ - public static function invalidCircleCenter() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The center setter arguments is invalid.', - 'The available prototypes are :', - ' - function setCenter(Ivory\GoogleMap\Base\Coordinate $center)', - ' - function setCenter(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID CIRCLE RADIUS" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID CIRCLE RADIUS" exception. - */ - public static function invalidCircleRadius() - { - return new static('The radius of a circle must be a numeric value.'); - } - - /** - * Gets the "INVALID ENCODED POLYLINE VALUE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID ENCODED POLYLINE VALUE" exception. - */ - public static function invalidEncodedPolylineValue() - { - return new static('The encoded polyline value must be a string value.'); - } - - /** - * Gets the "INVALID GROUND OVERLAY BOUND COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID GROUND OVERLAY BOUND COORDINATES" exception. - */ - public static function invalidGroundOverlayBoundCoordinates() - { - return new static('A ground overlay bound must have a south west & a north east coordinate.'); - } - - /** - * Gets the "INVALID GROUND OVERLAY URL" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID GROUND OVERLAY URL" exception. - */ - public static function invalidGroundOverlayUrl() - { - return new static('The url of a ground overlay must be a string value.'); - } - - /** - * Gets the "INVALID GROUND OVERLAY" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID GROUND OVERLAY" exception. - */ - public static function invalidGroundOverlayBound() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The bound setter arguments is invalid.', - 'The available prototypes are :', - ' - public function setBound(Ivory\GoogleMapBundle\Model\Base\Bound $bound)', - ' - public function setBount('. - 'Ivory\GoogleMapBundle\Model\Base\Coordinate $southWest, '. - 'Ivory\GoogleMapBundle\Model\Base\Coordinate $northEast'. - ')', - ' - public function setBound('. - 'double $southWestLatitude, '. - 'double $southWestLongitude, '. - 'double $northEastLatitude, '. - 'double $northEastLongitude, '. - 'boolean southWestNoWrap = true, '. - 'boolean $northEastNoWrap = true'. - ')' - )); - } - - /** - * Gets the "INVALID INFO WINDOW AUTO CLOSE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW AUTO CLOSE" exception. - */ - public static function invalidInfoWindowAutoClose() - { - return new static('The info window auto close flag must be a boolean value.'); - } - - /** - * Gets the "INVALID INFO WINDOW AUTO OPEN" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW AUTO OPEN" exception. - */ - public static function invalidInfoWindowAutoOpen() - { - return new static('The auto open property of an info window must be a boolean value.'); - } - - /** - * Gets the "INVALID INFO WINDOW CONTENT" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW CONTENT" exception. - */ - public static function invalidInfoWindowContent() - { - return new static('The content of an info window must be a string value.'); - } - - /** - * Gets the "INVALID INFO WINDOW OPEN" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW OPEN" exception. - */ - public static function invalidInfoWindowOpen() - { - return new static('The open property of an info window must be a boolean value.'); - } - - /** - * Gets the "INVALID INFO WINDOW OPEN EVENT" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW OPEN EVENT" exception. - */ - public static function invalidInfoWindowOpenEvent() - { - return new static(sprintf( - 'The only available open event are : %s.', - implode(', ', MouseEvent::getMouseEvents()) - )); - } - - /** - * Gets the "INVALID INFO WINDOW POSITION" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW POSITION" exception. - */ - public static function invalidInfoWindowPosition() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The position setter arguments is invalid.', - 'The available prototypes are :', - ' - function setPosition(Ivory\GoogleMap\Base\Coordinate $position)', - ' - function setPosition(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID INFO WINDOW PIXEL OFFSET" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID INFO WINDOW PIXEL OFFSET" exception. - */ - public static function invalidInfoWindowPixelOffset() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The pixel offset setter arguments is invalid.', - 'The available prototypes are :', - ' - function setPixelOffset(Ivory\GoogleMap\Base\Size $scaledSize)', - ' - function setPixelOffset('. - 'double $width, '. - 'double $height, '. - 'string $widthUnit = null, '. - 'string $heightUnit = null'. - ')' - )); - } - - /** - * Gets the "INVALID MARKER ANIMATION" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER ANIMATION" exception. - */ - public static function invalidMarkerAnimation() - { - return new static(sprintf( - 'The animation of a marker can only be : %s.', - implode(', ', Animation::getAnimations()) - )); - } - - /** - * Gets the "INVALID MARKER ICON" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER ICON" exception. - */ - public static function invalidMarkerIcon() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The icon setter arguments is invalid.', - 'The available prototypes are :', - ' - function setIcon(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null)', - ' - function setIcon(string $url = null)' - )); - } - - /** - * Gets the "INVALID MARKER ICON URL" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER ICON URL" exception. - */ - public static function invalidMarkerIconUrl() - { - return new static('A marker image icon must have an url.'); - } - - /** - * Gets the "INVALID MARKER IMAGE ANCHOR" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER IMAGE ANCHOR" exception. - */ - public static function invalidMarkerImageAnchor() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The anchor setter arguments is invalid.', - 'The available prototypes are :', - ' - function setAnchor(Ivory\GoogleMap\Base\Point $anchor)', - ' - function setAnchor(double x, double y)' - )); - } - - /** - * Gets the "INVALID MARKER IMAGE ORIGIN" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER IMAGE ORIGIN" exception. - */ - public static function invalidMarkerImageOrigin() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The origin setter arguments is invalid.', - 'The available prototypes are :', - ' - function setOrigin(Ivory\GoogleMap\Base\Point $origin)', - ' - function setOrigin(double x, double y)' - )); - } - - /** - * Gets the "INVALID MARKER IMAGE SCALED SIZE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER IMAGE SCALED SIZE" exception. - */ - public static function invalidMarkerImageScaledSize() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The scaled size setter arguments is invalid.', - 'The available prototypes are :', - ' - function setScaledSize(Ivory\GoogleMap\Base\Size $scaledSize = null)', - ' - function setScaledSize('. - 'double $width, '. - 'double $height, '. - 'string $widthUnit = null, '. - 'string $heightUnit = null'. - ')' - )); - } - - /** - * Gets the "INVALID MARKER IMAGE SIZE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER IMAGE SIZE" exception. - */ - public static function invalidMarkerImageSize() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The size setter arguments is invalid.', - 'The available prototypes are :', - ' - function setSize(Ivory\GoogleMap\Base\Size $size = null)', - ' - function setSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null)' - )); - } - - /** - * Gets the "INVALID MARKER IMAGE URL" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER IMAGE URL" exception. - */ - public static function invalidMarkeImageUrl() - { - return new static('The url of a maker image must be a string value.'); - } - - /** - * Gets the "INVALID MARKER POSITION" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER POSITION" exception. - */ - public static function invalidMarkerPosition() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The position setter arguments is invalid.', - 'The available prototypes are :', - ' - function setPosition(Ivory\GoogleMap\Base\Coordinate $position)', - ' - function setPosition(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID MARKER SHADOW URL" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHADOW URL" exception. - */ - public static function invalidMarkerShadowUrl() - { - return new static('A marker image shadow must have an url.'); - } - - /** - * Gets the "INVALID MARKER SHADOW" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHADOW" exception. - */ - public static function invalidMarkerShadow() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The shadow setter arguments is invalid.', - 'The available prototypes are :', - ' - function setShadow(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null)', - ' - function setShadow(string $url = null)' - )); - } - - /** - * Gets the "INVALID MARKER SHAPE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE" exception. - */ - public static function invalidMarkerShape() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The shape setter arguments is invalid.', - 'The available prototypes are :', - ' - function setShape(Ivory\GoogleMap\Overlays\MarkerShape $shape = null)', - ' - function setShape(string $type, array $coordinates)' - )); - } - - /** - * Gets the "INVALID MARKER SHAPE COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE COORDINATES" exception. - */ - public static function invalidMarkerShapeCoordinates() - { - return new static('A marker shape must have coordinates.'); - } - - /** - * Gets the "INVALID MARKER SHAPE ADD POLY COORDINATE CALL" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE ADD POLY COORDINATE CALL" - * exception. - */ - public static function invalidMarkerShapeAddPolyCoordinateCall() - { - return new static(sprintf( - 'The %s method can only be use with a marker shape which has type poly.', - 'MarkerShape::addPolyCoordinate($x, $y)' - )); - } - - /** - * Gets the "INVALID MARKER SHAPE TYPE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE TYPE" exception. - */ - public static function invalidMarkerShapeType() - { - return new static(sprintf( - 'The type of a marker shape can only be : %s.', - implode(', ', array('circle', 'poly', 'rect')) - )); - } - - /** - * Gets the "INVALID MARKER SHAPE CIRCLE COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE CIRCLE COORDINATES" exception. - */ - public static function invalidMarkerShapeCircleCoordinates() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s', - 'The coordinates setter arguments is invalid if the marker shape type is circle.', - 'The available prototype is : function setCoordinates(array(double $x, double $y, double $r))' - )); - } - - /** - * Gets the "INVALID MARKER SHAPE POLY COORDINATE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE POLY COORDINATE" exception. - */ - public static function invalidMarkerShapePolyCoordinate() - { - return new static('The x & y coordinates of a poly marker shape must be numeric values.'); - } - - /** - * Gets the "INVALID MARKER SHAPE POLY COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE POLY COORDINATES" exception. - */ - public static function invalidMarkerShapePolyCoordinates() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s', - 'The coordinates setter arguments is invalid if the marker shape type is poly.', - 'The available prototype is : function setCoordinates('. - 'array(double $x1, double $y1, '. - '..., '. - 'double $xn, double $yn'. - ')' - )); - } - - /** - * Gets the "INVALID MARKER SHAPE RECT COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID MARKER SHAPE RECT COORDINATES" exception. - */ - public static function invalidMarkerShapeRectCoordinates() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s', - 'The coordinates setter arguments is invalid if the marker shape type is rect.', - 'The available prototype is : function setCoordinates('. - 'array(double $x1, double $y1, double $x2, double $y2)'. - ')' - )); - } - - /** - * Gets the "INVALID POLYGON COORDINATE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID POLYGON COORDINATE" exception. - */ - public static function invalidPolygonCoordinate() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The coordinate adder arguments is invalid.', - 'The available prototypes are :', - ' - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate)', - ' - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID POLYLINE COORDINATE" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID POLYLINE COORDINATE" exception. - */ - public static function invalidPolylineCoordinate() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The coordinate adder arguments is invalid.', - 'The available prototypes are :', - ' - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate)', - ' - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true)' - )); - } - - /** - * Gets the "INVALID RECTANGLE BOUND" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID RECTANGLE BOUND" exception. - */ - public static function invalidRectangleBound() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The bound setter arguments is invalid.', - 'The available prototypes are :', - ' - function setBound(Ivory\GoogleMap\Base\Bound $bound)', - ' - function setBount('. - 'Ivory\GoogleMap\Base\Coordinate $southWest, '. - 'Ivory\GoogleMap\Base\Coordinate $northEast'. - ')', - ' - function setBound('. - 'double $southWestLatitude, '. - 'double $southWestLongitude, '. - 'double $northEastLatitude, '. - 'double $northEastLongitude, '. - 'boolean southWestNoWrap = true, '. - 'boolean $northEastNoWrap = true'. - ')' - )); - } - - /** - * Gets the "INVALID RECTANGLE BOUND COORDINATES" exception. - * - * @return \Ivory\GoogleMap\Exception\OverlayException The "INVALID RECTANGLE BOUND COORDINATES" exception. - */ - public static function invalidRectangleBoundCoordinates() - { - return new static('A rectangle bound must have a south west & a north east coordinate.'); - } -} diff --git a/src/Exception/PlaceException.php b/src/Exception/PlaceException.php deleted file mode 100644 index b7954f20..00000000 --- a/src/Exception/PlaceException.php +++ /dev/null @@ -1,148 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -use Ivory\GoogleMap\Places\AutocompleteType; -use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; - -/** - * Place exception. - * - * @author GeLo - */ -class PlaceException extends Exception -{ - /** - * Gets the "AUTOCOMPLETE COMPONENT RESTRICTION TYPE ALREADY EXISTS" exception. - * - * @param string $type The type. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "AUTOCOMPLETE RESTRICTION TYPE ALREADY EXISTS" exception. - */ - public static function autocompleteComponentRestrictionAlreadyExists($type) - { - return new static(sprintf('The place autocomplete component restriction type "%s" already exists.', $type)); - } - - /**s - * Gets the "AUTOCOMPLETE COMPONENT RESTRICTION TYPE DOES NOT EXIST" exception. - * - * @param string $type The type. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "AUTOCOMPLETE RESTRICTION TYPE DOES DOES NOT EXIST" exception. - */ - public static function autocompleteComponentRestrictionDoesNotExist($type) - { - return new static(sprintf('The place autocomplete component restriction type "%s" does not exist.', $type)); - } - - /** - * Gets the "AUTOCOMPLETE TYPE ALREADY EXISTS" exception. - * - * @param string $type The type. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "AUTOCOMPLETE TYPE ALREADY EXISTS" exception. - */ - public static function autocompleteTypeAlreadyExists($type) - { - return new static(sprintf('The place autocomplete type "%s" already exists.', $type)); - } - - /** - * Gets the "AUTOCOMPLETE TYPE DOES NOT EXIST" exception. - * - * @param string $type The type. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "AUTOCOMPLETE TYPE DOES NOT EXIST" exception. - */ - public static function autocompleteTypeDoesNotExist($type) - { - return new static(sprintf('The place autocomplete type "%s" does not exist.', $type)); - } - - /** - * Gets the "INVALID AUTOCOMPLETE ASYNC" exception. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "INVALID AUTOCOMPLETE ASYNC" exception. - */ - public static function invalidAutocompleteAsync() - { - return new static('The asynchronous load of a place autocomplete must be a boolean value.'); - } - - /** - * Gets the "INVALID AUTOCOMPLETE BOUND" exception. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "INVALID AUTOCOMPLETE BOUND" exception. - */ - public static function invalidAutocompleteBound() - { - return new static(sprintf( - '%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s'.PHP_EOL.'%s', - 'The bound setter arguments is invalid.', - 'The available prototypes are :', - ' - function setBound(Ivory\GoogleMap\Base\Bound $bound)', - ' - function setBount('. - 'Ivory\GoogleMap\Base\Coordinate $southWest, '. - 'Ivory\GoogleMap\Base\Coordinate $northEast'. - ')', - ' - function setBound('. - 'double $southWestLatitude, '. - 'double $southWestLongitude, '. - 'double $northEastLatitude, '. - 'double $northEastLongitude, '. - 'boolean southWestNoWrap = true, '. - 'boolean $northEastNoWrap = true'. - ')' - )); - } - - /** - * Gets the "INVALID AUTOCOMPLETE COMPONENT RESTRICTION" exception. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "INVALID AUTOCOMPLETE COMPONENT RESTRICTION" exception. - */ - public static function invalidAutocompleteComponentRestriction() - { - return new static( - sprintf( - 'The place autocomplete component restriction can only be: %s.', - implode(', ', AutocompleteComponentRestriction::getAvailableAutocompleteComponentRestrictions()) - ) - ); - } - - /** - * Gets the "INVALID AUTOCOMPLETE INPUT ID" exception. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "INVALID AUTOCOMPLETE INPUT ID" exception. - */ - public static function invalidAutocompleteInputId() - { - return new static('The place autocomplete input ID must be a string value.'); - } - - /** - * Gets the "INVALID AUTOCOMPLETE TYPE" exception. - * - * @return \Ivory\GoogleMap\Exception\PlaceException The "INVALID AUTOCOMPLETE TYPE" exception. - */ - public static function invalidAutocompleteType() - { - return new static( - sprintf( - 'The place autocomplete type can only be: %s.', - implode(', ', AutocompleteType::getAvailableAutocompleteTypes()) - ) - ); - } -} diff --git a/src/Exception/ServiceException.php b/src/Exception/ServiceException.php deleted file mode 100644 index 8fa53220..00000000 --- a/src/Exception/ServiceException.php +++ /dev/null @@ -1,100 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Exception; - -/** - * Service exception. - * - * @author GeLo - */ -class ServiceException extends Exception -{ - /** - * Gets the "INVALID SERVICE FORMAT" exception. - * - * @return \Ivory\GoogleMap\Exception\ServiceException The "INVALID SERVICE FORMAT" exception. - */ - public static function invalidServiceFormat() - { - return new static(sprintf('The service format can only be : %s.', implode(', ', array('json', 'xml')))); - } - - /** - * Gets the "INVALID SERVICE HTTPS" exception. - * - * @return \Ivory\GoogleMap\Exception\ServiceException The "INVALID SERVICE HTTPS" exception. - */ - public static function invalidServiceHttps() - { - return new static('The service https flag must be a boolean value.'); - } - - /** - * Gets the "INVALID SERVICE RESULT" exception. - * - * @return \Ivory\GoogleMap\Exception\ServiceException The "INVALID SERVICE RESULT" exception. - */ - public static function invalidServiceResult() - { - return new static('The service result is not valid.'); - } - - /** - * Gets the "INVALID SERVICE URL" exception. - * - * @return \Ivory\GoogleMap\Exception\ServiceException The "INVALID SERVICE URL" exception. - */ - public static function invalidServiceUrl() - { - return new static('The service url must be a string value.'); - } - - /** - * Gets the "INVALID DISTANCE TEXT" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DISTANCE TEXT" exception. - */ - public static function invalidDistanceText() - { - return new static('The distance text must be a string value.'); - } - - /** - * Gets the "INVALID DISTANCE VALUE" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DISTANCE VALUE" exception. - */ - public static function invalidDistanceValue() - { - return new static('The distance value must be a numeric value.'); - } - - /** - * Gets the "INVALID DURATION TEXT" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DURATION TEXT" exception. - */ - public static function invalidDurationText() - { - return new static('The duration text must be a string value.'); - } - - /** - * Gets the "INVALID DURATION VALUE" exception. - * - * @return \Ivory\GoogleMap\Exception\DirectionsException The "INVALID DURATION VALUE" exception. - */ - public static function invalidDurationValue() - { - return new static('The duration value must be a numeric value.'); - } -} diff --git a/src/Helper/ApiHelper.php b/src/Helper/ApiHelper.php deleted file mode 100644 index be8998df..00000000 --- a/src/Helper/ApiHelper.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper; - -/** - * Google Map API helper. - * - * @author GeLo - */ -class ApiHelper extends AbstractHelper -{ - /** @var boolean */ - protected $loaded; - - /** - * Creates a Google Map API helper. - */ - public function __construct() - { - parent::__construct(); - - $this->loaded = false; - } - - /** - * Checks/Sets if the API is already loaded. - * - * @param boolean $loaded TRUE if the API is already loaded else FALSE. - * - * @return boolean TRUE if the API is already loaded else FALSE. - */ - public function isLoaded($loaded = null) - { - if ($loaded !== null) { - $this->loaded = (bool) $loaded; - } - - return $this->loaded; - } - - /** - * Renders the API. - * - * @param string $language The language. - * @param array $libraries Additionnal libraries. - * @param string $callback A JS callback. - * @param boolean $sensor The sensor flag. - * - * @return string The HTML output. - */ - public function render( - $language = 'en', - array $libraries = array(), - $callback = null, - $sensor = false - ) - { - $otherParameters = array(); - - if (!empty($libraries)) { - $otherParameters['libraries'] = implode(',', $libraries); - } - - $otherParameters['language'] = $language; - $otherParameters['sensor'] = json_encode((bool) $sensor); - - $this->jsonBuilder - ->reset() - ->setValue('[other_params]', urldecode(http_build_query($otherParameters))); - - if ($callback !== null) { - $this->jsonBuilder->setValue('[callback]', $callback, false); - } - - $callbackFunction = 'load_ivory_google_map_api'; - $url = sprintf('//www.google.com/jsapi?callback=%s', $callbackFunction); - $loader = sprintf('google.load("maps", "3", %s);', $this->jsonBuilder->build()); - - $output = array(); - $output[] = ''.PHP_EOL; - $output[] = sprintf(''.PHP_EOL, $url); - - $this->loaded = true; - - return implode('', $output); - } -} diff --git a/src/Helper/Base/BoundHelper.php b/src/Helper/Base/BoundHelper.php deleted file mode 100644 index 25094dbd..00000000 --- a/src/Helper/Base/BoundHelper.php +++ /dev/null @@ -1,96 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Overlays\Circle; -use Ivory\GoogleMap\Overlays\EncodedPolyline; -use Ivory\GoogleMap\Overlays\GroundOverlay; -use Ivory\GoogleMap\Overlays\InfoWindow; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\Polyline; -use Ivory\GoogleMap\Overlays\Polygon; -use Ivory\GoogleMap\Overlays\Rectangle; - -/** - * Bound helper. - * - * @author GeLo - */ -class BoundHelper -{ - /** - * Renders the bound. - * - * @param \Ivory\GoogleMap\Base\Bound $bound The bound. - * - * @return string The JS output. - */ - public function render(Bound $bound) - { - if ($bound->hasExtends() || !$bound->hasCoordinates()) { - return sprintf('%s = new google.maps.LatLngBounds();'.PHP_EOL, $bound->getJavascriptVariable()); - } - - return sprintf( - '%s = new google.maps.LatLngBounds(%s, %s);'.PHP_EOL, - $bound->getJavascriptVariable(), - $bound->getSouthWest()->getJavascriptVariable(), - $bound->getNorthEast()->getJavascriptVariable() - ); - } - - /** - * Renders the bound's extend of a marker. - * - * @param \Ivory\GoogleMap\Base\Bound $bound The bound. - * - * @return string The JS output. - */ - public function renderExtends(Bound $bound) - { - $output = array(); - - foreach ($bound->getExtends() as $extend) { - if (($extend instanceof Marker) || ($extend instanceof InfoWindow)) { - $output[] = sprintf( - '%s.extend(%s.getPosition());'.PHP_EOL, - $bound->getJavascriptVariable(), - $extend->getJavascriptVariable() - ); - } elseif (($extend instanceof Polyline) - || ($extend instanceof EncodedPolyline) - || ($extend instanceof Polygon) - ) { - $output[] = sprintf( - '%s.getPath().forEach(function(element){%s.extend(element)});'.PHP_EOL, - $extend->getJavascriptVariable(), - $bound->getJavascriptVariable() - ); - } elseif (($extend instanceof Rectangle) || ($extend instanceof GroundOverlay)) { - $output[] = sprintf( - '%s.union(%s);'.PHP_EOL, - $bound->getJavascriptVariable(), - $extend->getBound()->getJavascriptVariable() - ); - } elseif ($extend instanceof Circle) { - $output[] = sprintf( - '%s.union(%s.getBounds());'.PHP_EOL, - $bound->getJavascriptVariable(), - $extend->getJavascriptVariable() - ); - } - } - - return implode('', $output); - } -} diff --git a/src/Helper/Base/SizeHelper.php b/src/Helper/Base/SizeHelper.php deleted file mode 100644 index 16a8cd33..00000000 --- a/src/Helper/Base/SizeHelper.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Size; - -/** - * Size helper. - * - * @author GeLo - */ -class SizeHelper -{ - /** - * Renders a size. - * - * @param \Ivory\GoogleMap\Base\Size $size The size. - * - * @return string The JS output. - */ - public function render(Size $size) - { - if ($size->hasUnits()) { - return sprintf( - '%s = new google.maps.Size(%s, %s, "%s", "%s");'.PHP_EOL, - $size->getJavascriptVariable(), - $size->getWidth(), - $size->getHeight(), - $size->getWidthUnit(), - $size->getHeightUnit() - ); - } - - return sprintf( - '%s = new google.maps.Size(%s, %s);'.PHP_EOL, - $size->getJavascriptVariable(), - $size->getWidth(), $size->getHeight() - ); - } -} diff --git a/src/Helper/Controls/ControlPositionHelper.php b/src/Helper/Controls/ControlPositionHelper.php deleted file mode 100644 index 54383eb6..00000000 --- a/src/Helper/Controls/ControlPositionHelper.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Exception\HelperException; - -/** - * Control position helper. - * - * @author GeLo - */ -class ControlPositionHelper -{ - /** - * Renders a control position. - * - * @param string $controlPosition The control position. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the control position is not valid. - * - * @return The JS output. - */ - public function render($controlPosition) - { - switch ($controlPosition) { - case ControlPosition::BOTTOM_CENTER: - case ControlPosition::BOTTOM_LEFT: - case ControlPosition::BOTTOM_RIGHT: - case ControlPosition::LEFT_BOTTOM: - case ControlPosition::LEFT_CENTER: - case ControlPosition::LEFT_TOP: - case ControlPosition::RIGHT_BOTTOM: - case ControlPosition::RIGHT_CENTER: - case ControlPosition::RIGHT_TOP: - case ControlPosition::TOP_CENTER: - case ControlPosition::TOP_LEFT: - case ControlPosition::TOP_RIGHT: - return sprintf('google.maps.ControlPosition.%s', strtoupper($controlPosition)); - default: - throw HelperException::invalidControlPosition(); - } - } -} diff --git a/src/Helper/Controls/MapTypeControlHelper.php b/src/Helper/Controls/MapTypeControlHelper.php deleted file mode 100644 index 142ab5ac..00000000 --- a/src/Helper/Controls/MapTypeControlHelper.php +++ /dev/null @@ -1,159 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Helper\MapTypeIdHelper; - -/** - * Map type control helper. - * - * @author GeLo - */ -class MapTypeControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\MapTypeIdHelper */ - protected $mapTypeIdHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\MapTypeControleStyleHelper */ - protected $mapTypeControlStyleHelper; - - /** - * Construct a map type control helper. - * - * @param \Ivory\GoogleMap\Helper\MapTypeIdHelper $mapTypeIdHelper The map type ID helper. - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - * @param \Ivory\GoogleMap\Helper\Controls\MapTypeControleStyleHelper $mapTypeControlStyleHelper The map type control style helper. - */ - public function __construct( - MapTypeIdHelper $mapTypeIdHelper = null, - ControlPositionHelper $controlPositionHelper = null, - MapTypeControlStyleHelper $mapTypeControlStyleHelper = null - ) { - parent::__construct(); - - if ($mapTypeIdHelper === null) { - $mapTypeIdHelper = new MapTypeIdHelper(); - } - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - if ($mapTypeControlStyleHelper === null) { - $mapTypeControlStyleHelper = new MapTypeControlStyleHelper(); - } - - $this->setMapTypeIdHelper($mapTypeIdHelper); - $this->setControlPositionHelper($controlPositionHelper); - $this->setMapTypeControlStyleHelper($mapTypeControlStyleHelper); - } - - /** - * Gets the map type ID helper. - * - * @return \Ivory\GoogleMap\Helper\MapTypeIdHelper The map type ID helper. - */ - public function getMapTypeIdHelper() - { - return $this->mapTypeIdHelper; - } - - /** - * Sets the map type ID helper. - * - * @param \Ivory\GoogleMap\Helper\MapTypeIdHelper $mapTypeIdHelper The map type ID helper. - */ - public function setMapTypeIdHelper(MapTypeIdHelper $mapTypeIdHelper) - { - $this->mapTypeIdHelper = $mapTypeIdHelper; - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Gets the map type control style helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper The map type control style helper. - */ - public function getMapTypeControlStyleHelper() - { - return $this->mapTypeControlStyleHelper; - } - - /** - * Sets the map type control style helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper $mapTypeControlStyleHelper The map type - * control style - * helper. - */ - public function setMapTypeControlStyleHelper(MapTypeControlStyleHelper $mapTypeControlStyleHelper) - { - $this->mapTypeControlStyleHelper = $mapTypeControlStyleHelper; - } - - /** - * Renders a map type control. - * - * @param \Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl The map type control. - * - * @return string The JS output. - */ - public function render(MapTypeControl $mapTypeControl) - { - $this->jsonBuilder->reset(); - - foreach ($mapTypeControl->getMapTypeIds() as $index => $mapTypeId) { - $this->jsonBuilder->setValue( - sprintf('[mapTypeIds][%d]', $index), - $this->mapTypeIdHelper->render($mapTypeId), - false - ); - } - - return $this->jsonBuilder - ->setValue( - '[position]', - $this->controlPositionHelper->render($mapTypeControl->getControlPosition()), - false - ) - ->setValue( - '[style]', - $this->mapTypeControlStyleHelper->render($mapTypeControl->getMapTypeControlStyle()), - false - ) - ->build(); - } -} diff --git a/src/Helper/Controls/MapTypeControlStyleHelper.php b/src/Helper/Controls/MapTypeControlStyleHelper.php deleted file mode 100644 index 80ee9256..00000000 --- a/src/Helper/Controls/MapTypeControlStyleHelper.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Exception\HelperException; - -/** - * Map type control style helper. - * - * @author GeLo - */ -class MapTypeControlStyleHelper -{ - /** - * Renders a map type control style. - * - * @param string $mapTypeControlStyle The map type control style. - * - * @throws \Ivory\GoogleMap\Exception\ControlException If the map type control style is not valid. - * - * @return string The JS output. - */ - public function render($mapTypeControlStyle) - { - switch ($mapTypeControlStyle) { - case MapTypeControlStyle::DEFAULT_: - case MapTypeControlStyle::DROPDOWN_MENU: - case MapTypeControlStyle::HORIZONTAL_BAR: - return sprintf('google.maps.MapTypeControlStyle.%s', strtoupper($mapTypeControlStyle)); - default: - throw HelperException::invalidMapTypeControlStyle(); - } - } -} diff --git a/src/Helper/Controls/PanControlHelper.php b/src/Helper/Controls/PanControlHelper.php deleted file mode 100644 index 20e1c405..00000000 --- a/src/Helper/Controls/PanControlHelper.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\PanControl; -use Ivory\GoogleMap\Helper\AbstractHelper; - -/** - * Pan control helper. - * - * @author GeLo - */ -class PanControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** - * Creates a pan control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function __construct(ControlPositionHelper $controlPositionHelper = null) - { - parent::__construct(); - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - $this->setControlPositionHelper($controlPositionHelper); - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Renders a pan control. - * - * @param \Ivory\GoogleMap\Controls\PanControl $panControl The pan control. - * - * @return string The JS output. - */ - public function render(PanControl $panControl) - { - return $this->jsonBuilder - ->reset() - ->setValue('[position]', $this->controlPositionHelper->render($panControl->getControlPosition()), false) - ->build(); - } -} diff --git a/src/Helper/Controls/RotateControlHelper.php b/src/Helper/Controls/RotateControlHelper.php deleted file mode 100644 index 43ef4165..00000000 --- a/src/Helper/Controls/RotateControlHelper.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\RotateControl; -use Ivory\GoogleMap\Helper\AbstractHelper; - -/** - * Rotate control helper. - * - * @author GeLo - */ -class RotateControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** - * Creates a rotate control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function __construct(ControlPositionHelper $controlPositionHelper = null) - { - parent::__construct(); - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - $this->setControlPositionHelper($controlPositionHelper); - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Renders a rotate control. - * - * @param \Ivory\GoogleMap\Controls\RotateControl $rotateControl The rotate control. - * - * @return string The JS output. - */ - public function render(RotateControl $rotateControl) - { - return $this->jsonBuilder - ->reset() - ->setValue('[position]', $this->controlPositionHelper->render($rotateControl->getControlPosition()), false) - ->build(); - } -} diff --git a/src/Helper/Controls/ScaleControlHelper.php b/src/Helper/Controls/ScaleControlHelper.php deleted file mode 100644 index 4c3fddc6..00000000 --- a/src/Helper/Controls/ScaleControlHelper.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Helper\AbstractHelper; - -/** - * Scale control helper. - * - * @author GeLo - */ -class ScaleControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\ScaleControleStyleHelper */ - protected $scaleControlStyleHelper; - - /** - * Construct a scale control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position - * helper. - * @param \Ivory\GoogleMap\Helper\Controls\ScaleControleStyleHelper $scaleControlStyleHelper The scale control - * style helper. - */ - public function __construct( - ControlPositionHelper $controlPositionHelper = null, - ScaleControlStyleHelper $scaleControlStyleHelper = null - ) { - parent::__construct(); - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - if ($scaleControlStyleHelper === null) { - $scaleControlStyleHelper = new ScaleControlStyleHelper(); - } - - $this->setControlPositionHelper($controlPositionHelper); - $this->setScaleControlStyleHelper($scaleControlStyleHelper); - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Gets the scale control style helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper The scale control style helper. - */ - public function getScaleControlStyleHelper() - { - return $this->scaleControlStyleHelper; - } - - /** - * Sets the scale control style helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper $scaleControlStyleHelper The scale control style - * helper. - */ - public function setScaleControlStyleHelper(ScaleControlStyleHelper $scaleControlStyleHelper) - { - $this->scaleControlStyleHelper = $scaleControlStyleHelper; - } - - /** - * Renders a scale control. - * - * @param \Ivory\GoogleMap\Controls\ScaleControl $scaleControl The scale control. - * - * @return string The JS output. - */ - public function render(ScaleControl $scaleControl) - { - return $this->jsonBuilder - ->reset() - ->setValue('[position]', $this->controlPositionHelper->render($scaleControl->getControlPosition()), false) - ->setValue('[style]', $this->scaleControlStyleHelper->render($scaleControl->getScaleControlStyle()), false) - ->build(); - } -} diff --git a/src/Helper/Controls/ScaleControlStyleHelper.php b/src/Helper/Controls/ScaleControlStyleHelper.php deleted file mode 100644 index bda47d86..00000000 --- a/src/Helper/Controls/ScaleControlStyleHelper.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Exception\HelperException; - -/** - * Scale control style helper. - * - * @author GeLo - */ -class ScaleControlStyleHelper -{ - /** - * Renders a scale control style. - * - * @param string $scaleControlStyle The scale control style. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the scale control style is not valid. - * - * @return string The JS output. - */ - public function render($scaleControlStyle) - { - switch ($scaleControlStyle) { - case ScaleControlStyle::DEFAULT_: - return sprintf('google.maps.ScaleControlStyle.%s', strtoupper($scaleControlStyle)); - default: - throw HelperException::invalidScaleControlStyle(); - } - } -} diff --git a/src/Helper/Controls/StreetViewControlHelper.php b/src/Helper/Controls/StreetViewControlHelper.php deleted file mode 100644 index 69dd3f36..00000000 --- a/src/Helper/Controls/StreetViewControlHelper.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\StreetViewControl; -use Ivory\GoogleMap\Helper\AbstractHelper; - -/** - * Street view control helper. - * - * @author GeLo - */ -class StreetViewControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** - * Creates a street view control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function __construct(ControlPositionHelper $controlPositionHelper = null) - { - parent::__construct(); - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - $this->setControlPositionHelper($controlPositionHelper); - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Renders the street view control - * - * @param Ivory\GoogleMapBundle\Model\Controls\StreetViewControl $streetViewControl - * @return string HTML output - */ - public function render(StreetViewControl $streetViewControl) - { - return $this->jsonBuilder - ->reset() - ->setValue( - '[position]', - $this->controlPositionHelper->render($streetViewControl->getControlPosition()), - false - ) - ->build(); - } -} diff --git a/src/Helper/Controls/ZoomControlHelper.php b/src/Helper/Controls/ZoomControlHelper.php deleted file mode 100644 index 41e8dbf0..00000000 --- a/src/Helper/Controls/ZoomControlHelper.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Helper\AbstractHelper; - -/** - * Zoom control helper. - * - * @author GeLo - */ -class ZoomControlHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** @var \vory\GoogleMap\Templating\Helper\Controls\ZoomControlStyleHelper */ - protected $zoomControlStyleHelper; - - /** - * Create a zoom control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position - * helper. - * @param \Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper $zoomControlStyleHelper The zoom control style - * helper. - */ - public function __construct( - ControlPositionHelper $controlPositionHelper = null, - ZoomControlStyleHelper $zoomControlStyleHelper = null - ) { - parent::__construct(); - - if ($controlPositionHelper === null) { - $controlPositionHelper = new ControlPositionHelper(); - } - - if ($zoomControlStyleHelper === null) { - $zoomControlStyleHelper = new ZoomControlStyleHelper(); - } - - $this->setControlPositionHelper($controlPositionHelper); - $this->setZoomControlStyleHelper($zoomControlStyleHelper); - } - - /** - * Gets the control position helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper The control position helper. - */ - public function getControlPositionHelper() - { - return $this->controlPositionHelper; - } - - /** - * Sets the control position helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper $controlPositionHelper The control position helper. - */ - public function setControlPositionHelper(ControlPositionHelper $controlPositionHelper) - { - $this->controlPositionHelper = $controlPositionHelper; - } - - /** - * Gets the zoom control style helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper The zoom control style helper. - */ - public function getZoomControlStyleHelper() - { - return $this->zoomControlStyleHelper; - } - - /** - * Sets the zoom control style helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper $zoomControlStyleHelper The zoom control style - * helper. - */ - public function setZoomControlStyleHelper(ZoomControlStyleHelper $zoomControlStyleHelper) - { - $this->zoomControlStyleHelper = $zoomControlStyleHelper; - } - - /** - * Renders a zoom control. - * - * @param \Ivory\GoogleMap\Controls\ZoomControl $zoomControl The zoom control. - * - * @return string The JS output. - */ - public function render(ZoomControl $zoomControl) - { - return $this->jsonBuilder - ->reset() - ->setValue('[position]', $this->controlPositionHelper->render($zoomControl->getControlPosition()), false) - ->setValue('[style]', $this->zoomControlStyleHelper->render($zoomControl->getZoomControlStyle()), false) - ->build(); - } -} diff --git a/src/Helper/Controls/ZoomControlStyleHelper.php b/src/Helper/Controls/ZoomControlStyleHelper.php deleted file mode 100644 index b6ebbe1d..00000000 --- a/src/Helper/Controls/ZoomControlStyleHelper.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ZoomControlStyle; -use Ivory\GoogleMap\Exception\HelperException; - -/** - * Zoom control style helper. - * - * @author GeLo - */ -class ZoomControlStyleHelper -{ - /** - * Renders a zoom control style. - * - * @param string $zoomControlStyle The zoom control style. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If thhe zoom control style is not valid. - * - * @return string The JS output. - */ - public function render($zoomControlStyle) - { - switch ($zoomControlStyle) { - case ZoomControlStyle::DEFAULT_: - case ZoomControlStyle::LARGE: - case ZoomControlStyle::SMALL: - return sprintf('google.maps.ZoomControlStyle.%s', strtoupper($zoomControlStyle)); - default: - throw HelperException::invalidZoomControlStyle(); - } - } -} diff --git a/src/Helper/Events/EventManagerHelper.php b/src/Helper/Events/EventManagerHelper.php deleted file mode 100644 index c86549bf..00000000 --- a/src/Helper/Events/EventManagerHelper.php +++ /dev/null @@ -1,96 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Events; - -use Ivory\GoogleMap\Events\Event; - -/** - * Event manager helper. - * - * @author GeLo - */ -class EventManagerHelper -{ - /** - * Renders a dom event. - * - * @param \Ivory\GoogleMap\Events\Event $domEvent The dom event. - * - * @return string The JS output. - */ - public function renderDomEvent(Event $domEvent) - { - return sprintf( - '%s = google.maps.event.addDomListener(%s, "%s", %s, %s);'.PHP_EOL, - $domEvent->getJavascriptVariable(), - $domEvent->getInstance(), - $domEvent->getEventName(), - $domEvent->getHandle(), - json_encode($domEvent->isCapture()) - ); - } - - /** - * Renders a dom event once. - * - * @param \Ivory\GoogleMap\Events\Event $domEventOnce The dom event once. - * - * @return string The JS output. - */ - public function renderDomEventOnce(Event $domEventOnce) - { - return sprintf( - '%s = google.maps.event.addDomListenerOnce(%s, "%s", %s, %s);'.PHP_EOL, - $domEventOnce->getJavascriptVariable(), - $domEventOnce->getInstance(), - $domEventOnce->getEventName(), - $domEventOnce->getHandle(), - json_encode($domEventOnce->isCapture()) - ); - } - - /** - * Renders an event. - * - * @param \Ivory\GoogleMap\Events\Event $event The event. - * - * @return string The JS output. - */ - public function renderEvent(Event $event) - { - return sprintf( - '%s = google.maps.event.addListener(%s, "%s", %s);'.PHP_EOL, - $event->getJavascriptVariable(), - $event->getInstance(), - $event->getEventName(), - $event->getHandle() - ); - } - - /** - * Renders an event once. - * - * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. - * - * @return string The JS output. - */ - public function renderEventOnce(Event $eventOnce) - { - return sprintf( - '%s = google.maps.event.addListenerOnce(%s, "%s", %s);'.PHP_EOL, - $eventOnce->getJavascriptVariable(), - $eventOnce->getInstance(), - $eventOnce->getEventName(), - $eventOnce->getHandle() - ); - } -} diff --git a/src/Helper/Extension/AbstractExtensionHelper.php b/src/Helper/Extension/AbstractExtensionHelper.php deleted file mode 100644 index 5e704afc..00000000 --- a/src/Helper/Extension/AbstractExtensionHelper.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Extension; - -/** - * Abstract extension. - * - * @author GeLo - */ -abstract class AbstractExtensionHelper implements ExtensionHelperInterface -{ - /** - * Renders a library. - * - * @param string $source The library source. - * @param string|null $callback The javascript callback. - * - * @return string The HTML output. - */ - protected function renderLibrary($source, $callback = null) - { - if ($callback === null) { - return sprintf(''.PHP_EOL, $source); - } - - $output = array(); - - $output[] = 'var s = document.createElement("script");'.PHP_EOL; - $output[] = 's.type = "text/javascript";'.PHP_EOL; - $output[] = 's.async = true;'.PHP_EOL; - $output[] = sprintf('s.src = "%s";'.PHP_EOL, $source); - $output[] = sprintf('s.addEventListener("load", function () { %s(); }, false);'.PHP_EOL, $callback); - $output[] = 'document.getElementsByTagName("head")[0].appendChild(s);'.PHP_EOL; - - return implode('', $output); - } -} diff --git a/src/Helper/Extension/CoreExtensionHelper.php b/src/Helper/Extension/CoreExtensionHelper.php deleted file mode 100644 index c697a25b..00000000 --- a/src/Helper/Extension/CoreExtensionHelper.php +++ /dev/null @@ -1,152 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Extension; - -use Ivory\GoogleMap\Helper\ApiHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper; -use Ivory\GoogleMap\Map; - -/** - * Core extension helper. - * - * @author GeLo - */ -class CoreExtensionHelper implements ExtensionHelperInterface -{ - /** @var \Ivory\GoogleMap\Helper\ApiHelper */ - protected $apiHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper */ - protected $markerClusterHelper; - - /** - * Creates a core extension helper. - * - * @param \Ivory\GoogleMap\Helper\ApiHelper $apiHelper The api helper. - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper $markerClusterHelper The marker cluster helper. - */ - public function __construct(ApiHelper $apiHelper = null, MarkerClusterHelper $markerClusterHelper = null) - { - if ($apiHelper === null) { - $apiHelper = new ApiHelper(); - } - - if ($markerClusterHelper === null) { - $markerClusterHelper = new MarkerClusterHelper(); - } - - $this->setApiHelper($apiHelper); - $this->setMarkerClusterHelper($markerClusterHelper); - } - - /** - * Gets the api helper. - * - * @return \Ivory\GoogleMap\Helper\ApiHelper The api helper. - */ - public function getApiHelper() - { - return $this->apiHelper; - } - - /** - * Sets the api helper. - * - * @param \Ivory\GoogleMap\Helper\ApiHelper $apiHelper The api helper. - */ - public function setApiHelper(ApiHelper $apiHelper) - { - $this->apiHelper = $apiHelper; - } - - /** - * Gets the marker cluster helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper The marker cluster helper. - */ - public function getMarkerClusterHelper() - { - return $this->markerClusterHelper; - } - - /** - * Sets the marker cluster helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper $markerClusterHelper The marker cluster helper. - */ - public function setMarkerClusterHelper(MarkerClusterHelper $markerClusterHelper) - { - $this->markerClusterHelper = $markerClusterHelper; - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(Map $map) - { - if ($this->apiHelper->isLoaded()) { - return; - } - - $callback = null; - - if ($map->isAsync()) { - $callback = 'load_ivory_google_map'; - } - - $output = array(); - - $output[] = $this->apiHelper->render($map->getLanguage(), $this->getLibraries($map), $callback); - $output[] = $this->markerClusterHelper->renderLibraries($map->getMarkerCluster(), $map); - - return implode('', $output); - } - - /** - * {@inheritdoc} - */ - public function renderBefore(Map $map) - { - if ($map->isAsync()) { - return 'function load_ivory_google_map() {'.PHP_EOL; - } - } - - /** - * {@inheritdoc} - */ - public function renderAfter(Map $map) - { - if ($map->isAsync()) { - return '}'.PHP_EOL; - } - } - - /** - * Gets the libraries needed for the map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The map libraries. - */ - protected function getLibraries(Map $map) - { - $libraries = $map->getLibraries(); - - $encodedPolylines = $map->getEncodedPolylines(); - if (!empty($encodedPolylines)) { - $libraries[] = 'geometry'; - } - - return array_unique($libraries); - } -} diff --git a/src/Helper/Extension/ExtensionHelperInterface.php b/src/Helper/Extension/ExtensionHelperInterface.php deleted file mode 100644 index 0cd3d451..00000000 --- a/src/Helper/Extension/ExtensionHelperInterface.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Extension; - -use Ivory\GoogleMap\Map; - -/** - * Extension helper. - * - * @author GeLo - */ -interface ExtensionHelperInterface -{ - /** - * Renders libraires. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The html output. - */ - public function renderLibraries(Map $map); - - /** - * Renders JS code just before the generated one. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderBefore(Map $map); - - /** - * Renders JS code just after the generated one. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderAfter(Map $map); -} diff --git a/src/Helper/Extension/InfoBoxExtensionHelper.php b/src/Helper/Extension/InfoBoxExtensionHelper.php deleted file mode 100644 index f78b4299..00000000 --- a/src/Helper/Extension/InfoBoxExtensionHelper.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Extension; - -use Ivory\GoogleMap\Map; - -/** - * InfoBox extension helper. - * - * @author GeLo - */ -class InfoBoxExtensionHelper extends AbstractExtensionHelper -{ - /** @var string */ - protected $source; - - /** @var string */ - protected $callback; - - /** - * Creates an info box extension helper. - * - * @param string $source The info box source URL. - * @param string $callback The info box callback. - */ - public function __construct( - $source = '//google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js', - $callback = 'load_ivory_google_map_info_box' - ) { - $this->setSource($source); - $this->setCallback($callback); - } - - /** - * Gets the info box source URL. - * - * @return string The info box source URL. - */ - public function getSource() - { - return $this->source; - } - - /** - * Sets the info box source URL. - * - * @param string $source The info box source URL. - */ - public function setSource($source) - { - $this->source = $source; - } - - /** - * Gets the javascript callback. - * - * @return string The javascript callback. - */ - public function getCallback() - { - return $this->callback; - } - - /** - * Sets the javascript callback. - * - * @param string $callback The javascript callback. - */ - public function setCallback($callback) - { - $this->callback = $callback; - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(Map $map) - { - if (!$map->isAsync()) { - return $this->renderLibrary($this->source); - } - } - - /** - * {@inheritdoc} - */ - public function renderBefore(Map $map) - { - if ($map->isAsync()) { - return sprintf('function %s () {'.PHP_EOL, $this->callback); - } - } - - /** - * {@inheritdoc} - */ - public function renderAfter(Map $map) - { - if ($map->isAsync()) { - return '}'.PHP_EOL.$this->renderLibrary($this->source, $this->callback); - } - } -} diff --git a/src/Helper/Layers/KMLLayerHelper.php b/src/Helper/Layers/KMLLayerHelper.php deleted file mode 100644 index cb6d0cfd..00000000 --- a/src/Helper/Layers/KMLLayerHelper.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Layers; - -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Layers\KMLLayer; -use Ivory\GoogleMap\Map; - -/** - * KML Layer helper. - * - * @author GeLo - */ -class KMLLayerHelper extends AbstractHelper -{ - /** - * Renders a kml layer. - * - * @param \Ivory\GoogleMap\Layers\KMLLayer $kmlLayer The KML layer. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function render(KMLLayer $kmlLayer, Map $map) - { - $this->jsonBuilder - ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValues($kmlLayer->getOptions()); - - return sprintf( - '%s = new google.maps.KmlLayer("%s", %s);'.PHP_EOL, - $kmlLayer->getJavascriptVariable(), - $kmlLayer->getUrl(), - $this->jsonBuilder->build() - ); - } -} diff --git a/src/Helper/MapHelper.php b/src/Helper/MapHelper.php deleted file mode 100644 index abf12d98..00000000 --- a/src/Helper/MapHelper.php +++ /dev/null @@ -1,1937 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper; - -use Ivory\GoogleMap\Exception\HelperException; -use Ivory\GoogleMap\Helper\Base\BoundHelper; -use Ivory\GoogleMap\Helper\Base\CoordinateHelper; -use Ivory\GoogleMap\Helper\Base\PointHelper; -use Ivory\GoogleMap\Helper\Base\SizeHelper; -use Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper; -use Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper; -use Ivory\GoogleMap\Helper\Controls\PanControlHelper; -use Ivory\GoogleMap\Helper\Controls\RotateControlHelper; -use Ivory\GoogleMap\Helper\Controls\ScaleControlHelper; -use Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper; -use Ivory\GoogleMap\Helper\Controls\ZoomControlHelper; -use Ivory\GoogleMap\Helper\Events\EventManagerHelper; -use Ivory\GoogleMap\Helper\Extension\CoreExtensionHelper; -use Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface; -use Ivory\GoogleMap\Helper\Layers\KMLLayerHelper; -use Ivory\GoogleMap\Helper\MapTypeIdHelper; -use Ivory\GoogleMap\Helper\Overlays\CircleHelper; -use Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper; -use Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper; -use Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface; -use Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper; -use Ivory\GoogleMap\Helper\Overlays\PolygonHelper; -use Ivory\GoogleMap\Helper\Overlays\PolylineHelper; -use Ivory\GoogleMap\Helper\Overlays\RectangleHelper; -use Ivory\GoogleMap\Map; - -/** - * Map helper. - * - * @author GeLo - */ -class MapHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Base\CoordinateHelper */ - protected $coordinateHelper; - - /** @var \Ivory\GoogleMap\Helper\Base\BoundHelper */ - protected $boundHelper; - - /** @var \Ivory\GoogleMap\Helper\Base\PointHelper */ - protected $pointHelper; - - /** @var \Ivory\GoogleMap\Helper\Base\SizeHelper */ - protected $sizeHelper; - - /** @var \Ivory\GoogleMap\Helper\MapTypeIdHelper */ - protected $mapTypeIdHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper */ - protected $mapTypeControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper */ - protected $overviewMapControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\PanControlHelper */ - protected $panControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\RotateControlHelper */ - protected $rotateControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\ScaleControlHelper */ - protected $scaleControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper */ - protected $streetViewControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Controls\ZoomControlHelper */ - protected $zoomControlHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface */ - protected $markerClusterHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper */ - protected $markerImageHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper */ - protected $markerShapeHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper */ - protected $infoWindowHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\PolylineHelper */ - protected $polylineHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper */ - protected $encodedPolylineHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\PolygonHelper */ - protected $polygonHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\RectangleHelper */ - protected $rectangleHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\CircleHelper */ - protected $circleHelper; - - /** @var \Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper */ - protected $groundOverlayHelper; - - /** @var \Ivory\GoogleMap\Helper\Layers\KMLLayerHelper */ - protected $kmlLayerHelper; - - /** @var \Ivory\GoogleMap\Helper\Events\EventManagerHelper */ - protected $eventManagerHelper; - - /** @var array */ - protected $extensionHelpers; - - /** - * Creates a map helper. - * - * @param \Ivory\GoogleMap\Helper\Base\CoordinateHelper $coordinateHelper The coordinate helper. - * @param \Ivory\GoogleMap\Helper\Base\BoundHelper $boundHelper The bound helper. - * @param \Ivory\GoogleMap\Helper\Base\PointHelper $pointHelper The point helper. - * @param \Ivory\GoogleMap\Helper\Base\SizeHelper $sizeHelper The size helper. - * @param \Ivory\GoogleMap\Helper\MapTypeIdHelper $mapTypeIdHelper The map type id helper. - * @param \Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper $mapTypeControlHelper The map type control helper. - * @param \Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper $overviewMapControlHelper The overview map control helper. - * @param \Ivory\GoogleMap\Helper\Controls\PanControlHelper $panControlHelper The pan control helper. - * @param \Ivory\GoogleMap\Helper\Controls\RotateControlHelper $rotateControlHelper The rotate control helper. - * @param \Ivory\GoogleMap\Helper\Controls\ScaleControlHelper $scaleControlHelper The scale control helper. - * @param \Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper $streetViewControlHelper The street view control helper. - * @param \Ivory\GoogleMap\Helper\Controls\ZoomControlHelper $zoomControlHelper The zoom control helper. - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerClusterHelperInterface $markerClusterHelper The marker cluster helper. - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper $markerImageHelper The marker image helper. - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper $markerShapeHelper The marker shape helper. - * @param \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper $infoWindowHelper The info window helper. - * @param \Ivory\GoogleMap\Helper\Overlays\PolylineHelper $polylineHelper The polyline helper. - * @param \Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper $encodedPolylineHelper The encoded polyline helper. - * @param \Ivory\GoogleMap\Helper\Overlays\PolygonHelper $polygonHelper The polygon helper. - * @param \Ivory\GoogleMap\Helper\Overlays\RectangleHelper $rectangleHelper The rectangle helper. - * @param \Ivory\GoogleMap\Helper\Overlays\CircleHelper $circleHelper The circle helper. - * @param \Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper $groundOverlayHelper The ground overlay helper. - * @param \Ivory\GoogleMap\Helper\Layers\KMLLayerHelper $kmlLayerHelper The KML layer helper. - * @param \Ivory\GoogleMap\Helper\Events\EventManagerHelper $eventManagerHelper The event manager helper. - * @param array $extensionHelpers The extension helpers. - */ - public function __construct( - CoordinateHelper $coordinateHelper = null, - BoundHelper $boundHelper = null, - PointHelper $pointHelper = null, - SizeHelper $sizeHelper = null, - MapTypeIdHelper $mapTypeIdHelper = null, - MapTypeControlHelper $mapTypeControlHelper = null, - OverviewMapControlHelper $overviewMapControlHelper = null, - PanControlHelper $panControlHelper = null, - RotateControlHelper $rotateControlHelper = null, - ScaleControlHelper $scaleControlHelper = null, - StreetViewControlHelper $streetViewControlHelper = null, - ZoomControlHelper $zoomControlHelper = null, - MarkerClusterHelperInterface $markerClusterHelper = null, - MarkerImageHelper $markerImageHelper = null, - MarkerShapeHelper $markerShapeHelper = null, - InfoWindowHelper $infoWindowHelper = null, - PolylineHelper $polylineHelper = null, - EncodedPolylineHelper $encodedPolylineHelper = null, - PolygonHelper $polygonHelper = null, - RectangleHelper $rectangleHelper = null, - CircleHelper $circleHelper = null, - GroundOverlayHelper $groundOverlayHelper = null, - KMLLayerHelper $kmlLayerHelper = null, - EventManagerHelper $eventManagerHelper = null, - array $extensionHelpers = array() - ) { - parent::__construct(); - - if ($coordinateHelper === null) { - $coordinateHelper = new CoordinateHelper(); - } - - if ($boundHelper === null) { - $boundHelper = new BoundHelper(); - } - - if ($pointHelper === null) { - $pointHelper = new PointHelper(); - } - - if ($sizeHelper === null) { - $sizeHelper = new SizeHelper(); - } - - if ($mapTypeIdHelper === null) { - $mapTypeIdHelper = new MapTypeIdHelper(); - } - - if ($mapTypeControlHelper === null) { - $mapTypeControlHelper = new MapTypeControlHelper(); - } - - if ($overviewMapControlHelper === null) { - $overviewMapControlHelper = new OverviewMapControlHelper(); - } - - if ($panControlHelper === null) { - $panControlHelper = new PanControlHelper(); - } - - if ($rotateControlHelper === null) { - $rotateControlHelper = new RotateControlHelper(); - } - - if ($scaleControlHelper === null) { - $scaleControlHelper = new ScaleControlHelper(); - } - - if ($streetViewControlHelper === null) { - $streetViewControlHelper = new StreetViewControlHelper(); - } - - if ($zoomControlHelper === null) { - $zoomControlHelper = new ZoomControlHelper(); - } - - if ($markerClusterHelper === null) { - $markerClusterHelper = new MarkerClusterHelper(); - } - - if ($markerImageHelper === null) { - $markerImageHelper = new MarkerImageHelper(); - } - - if ($markerShapeHelper === null) { - $markerShapeHelper = new MarkerShapeHelper(); - } - - if ($infoWindowHelper === null) { - $infoWindowHelper = new InfoWindowHelper(); - } - - if ($polylineHelper === null) { - $polylineHelper = new PolylineHelper(); - } - - if ($encodedPolylineHelper === null) { - $encodedPolylineHelper = new EncodedPolylineHelper(); - } - - if ($polygonHelper === null) { - $polygonHelper = new PolygonHelper(); - } - - if ($rectangleHelper === null) { - $rectangleHelper = new RectangleHelper(); - } - - if ($circleHelper === null) { - $circleHelper = new CircleHelper(); - } - - if ($groundOverlayHelper === null) { - $groundOverlayHelper = new GroundOverlayHelper(); - } - - if ($kmlLayerHelper === null) { - $kmlLayerHelper = new KMLLayerHelper(); - } - - if ($eventManagerHelper === null) { - $eventManagerHelper = new EventManagerHelper(); - } - - if (empty($extensionHelpers)) { - $extensionHelpers['core'] = new CoreExtensionHelper(); - } - - $this->setCoordinateHelper($coordinateHelper); - $this->setBoundHelper($boundHelper); - $this->setPointHelper($pointHelper); - $this->setSizeHelper($sizeHelper); - - $this->setMapTypeIdHelper($mapTypeIdHelper); - $this->setMapTypeControlHelper($mapTypeControlHelper); - $this->setOverviewMapControlHelper($overviewMapControlHelper); - $this->setPanControlHelper($panControlHelper); - $this->setRotateControlHelper($rotateControlHelper); - $this->setScaleControlHelper($scaleControlHelper); - $this->setStreetViewControlHelper($streetViewControlHelper); - $this->setZoomControlHelper($zoomControlHelper); - - $this->setMarkerClusterHelper($markerClusterHelper); - $this->setMarkerImageHelper($markerImageHelper); - $this->setMarkerShapeHelper($markerShapeHelper); - $this->setInfoWindowHelper($infoWindowHelper); - $this->setPolylineHelper($polylineHelper); - $this->setEncodedPolylineHelper($encodedPolylineHelper); - $this->setPolygonHelper($polygonHelper); - $this->setRectangleHelper($rectangleHelper); - $this->setCircleHelper($circleHelper); - $this->setGroundOverlayHelper($groundOverlayHelper); - - $this->setKmlLayerHelper($kmlLayerHelper); - - $this->setEventManagerHelper($eventManagerHelper); - - $this->setExtensionHelpers($extensionHelpers); - } - - /** - * Gets the coordinate helper. - * - * @return \Ivory\GoogleMap\Helper\Base\CoordinateHelper The coordinate helper. - */ - public function getCoordinateHelper() - { - return $this->coordinateHelper; - } - - /** - * Sets the coordinate helper. - * - * @param \Ivory\GoogleMap\Helper\Base\CoordinateHelper $coordinateHelper The coordinate helper. - */ - public function setCoordinateHelper(CoordinateHelper $coordinateHelper) - { - $this->coordinateHelper = $coordinateHelper; - } - - /** - * Gets the bound helper. - * - * @return \Ivory\GoogleMap\Helper\Base\BoundHelper The bound helper. - */ - public function getBoundHelper() - { - return $this->boundHelper; - } - - /** - * Sets the bound helper. - * - * @param \Ivory\GoogleMap\Helper\Base\BoundHelper $boundHelper The bound helper. - */ - public function setBoundHelper(BoundHelper $boundHelper) - { - $this->boundHelper = $boundHelper; - } - - /** - * Gets the point helper. - * - * @return \Ivory\GoogleMap\Helper\Base\PointHelper The point helper. - */ - public function getPointHelper() - { - return $this->pointHelper; - } - - /** - * Sets the point helper. - * - * @param \Ivory\GoogleMap\Helper\Base\PointHelper $pointHelper The point helper. - */ - public function setPointHelper(PointHelper $pointHelper) - { - $this->pointHelper = $pointHelper; - } - - /** - * Gets the size helper. - * - * @return \Ivory\GoogleMap\Helper\Base\SizeHelper The size helper. - */ - public function getSizeHelper() - { - return $this->sizeHelper; - } - - /** - * Sets the size helper. - * - * @param \Ivory\GoogleMap\Helper\Base\SizeHelper $sizeHelper The size helper. - */ - public function setSizeHelper(SizeHelper $sizeHelper) - { - $this->sizeHelper = $sizeHelper; - } - - /** - * Gets the map type id helper. - * - * @return \Ivory\GoogleMap\Helper\MapTypeIdHelper The map type id helper. - */ - public function getMapTypeIdHelper() - { - return $this->mapTypeIdHelper; - } - - /** - * Sets the map type id helper. - * - * @param \Ivory\GoogleMap\Helper\MapTypeIdHelper $mapTypeIdHelper The map type id helper. - */ - public function setMapTypeIdHelper(MapTypeIdHelper $mapTypeIdHelper) - { - $this->mapTypeIdHelper = $mapTypeIdHelper; - } - - /** - * Gets the map type control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper The map type control helper. - */ - public function getMapTypeControlHelper() - { - return $this->mapTypeControlHelper; - } - - /** - * Sets the map type control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper $mapTypeControlHelper The map type control helper. - */ - public function setMapTypeControlHelper(MapTypeControlHelper $mapTypeControlHelper) - { - $this->mapTypeControlHelper = $mapTypeControlHelper; - } - - /** - * Gets the overview map control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper The overview map control helper. - */ - public function getOverviewMapControlHelper() - { - return $this->overviewMapControlHelper; - } - - /** - * Sets the overview map control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper $overviewMapControlHelper The overview map - * control helper. - */ - public function setOverviewMapControlHelper(OverviewMapControlHelper $overviewMapControlHelper) - { - $this->overviewMapControlHelper = $overviewMapControlHelper; - } - - /** - * Gets the pan control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\PanControlHelper The pan control helper. - */ - public function getPanControlHelper() - { - return $this->panControlHelper; - } - - /** - * Sets the pan control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\PanControlHelper $panControlHelper The pan control helper. - */ - public function setPanControlHelper(PanControlHelper $panControlHelper) - { - $this->panControlHelper = $panControlHelper; - } - - /** - * Gets the rotate control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\RotateControlHelper The rotate control helper. - */ - public function getRotateControlHelper() - { - return $this->rotateControlHelper; - } - - /** - * Sets the rotate control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\RotateControlHelper $rotateControlHelper The rotate control helper. - */ - public function setRotateControlHelper(RotateControlHelper $rotateControlHelper) - { - $this->rotateControlHelper = $rotateControlHelper; - } - - /** - * Gets the scale control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ScaleControlHelper The scale control helper. - */ - public function getScaleControlHelper() - { - return $this->scaleControlHelper; - } - - /** - * Sets the scale control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ScaleControlHelper $scaleControlHelper The scale control helper. - */ - public function setScaleControlHelper(ScaleControlHelper $scaleControlHelper) - { - $this->scaleControlHelper = $scaleControlHelper; - } - - /** - * Gets the street view control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper The street view control helper. - */ - public function getStreetViewControlHelper() - { - return $this->streetViewControlHelper; - } - - /** - * Sets the street view control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper $streetViewControlHelper The street view control - * helper. - */ - public function setStreetViewControlHelper(StreetViewControlHelper $streetViewControlHelper) - { - $this->streetViewControlHelper = $streetViewControlHelper; - } - - /** - * Gets the zoom control helper. - * - * @return \Ivory\GoogleMap\Helper\Controls\ZoomControlHelper The zoom control helper. - */ - public function getZoomControlHelper() - { - return $this->zoomControlHelper; - } - - /** - * Sets the zoom control helper. - * - * @param \Ivory\GoogleMap\Helper\Controls\ZoomControlHelper $zoomControlHelper The zoom control helper. - */ - public function setZoomControlHelper(ZoomControlHelper $zoomControlHelper) - { - $this->zoomControlHelper = $zoomControlHelper; - } - - /** - * Gets the marker cluster helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface The marker cluster helper. - */ - public function getMarkerClusterHelper() - { - return $this->markerClusterHelper; - } - - /** - * Sets the marker cluster helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface $markerClusterHelper The marker cluster helper. - */ - public function setMarkerClusterHelper(MarkerClusterHelperInterface $markerClusterHelper) - { - $this->markerClusterHelper = $markerClusterHelper; - } - - /** - * Gets the marker image helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper The marker image helper. - */ - public function getMarkerImageHelper() - { - return $this->markerImageHelper; - } - - /** - * Sets the marker image helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper $markerImageHelper The marker image helper. - */ - public function setMarkerImageHelper(MarkerImageHelper $markerImageHelper) - { - $this->markerImageHelper = $markerImageHelper; - } - - /** - * Gets the marker shape helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper The marker shape helper. - */ - public function getMarkerShapeHelper() - { - return $this->markerShapeHelper; - } - - /** - * Sets the marker shape helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper $markerShapeHelper The marker shape helper. - */ - public function setMarkerShapeHelper(MarkerShapeHelper $markerShapeHelper) - { - $this->markerShapeHelper = $markerShapeHelper; - } - - /** - * Gets the info window helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper The info window helper. - */ - public function getInfoWindowHelper() - { - return $this->infoWindowHelper; - } - - /** - * Sets the info window helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper $infoWindowHelper The info window helper. - */ - public function setInfoWindowHelper(InfoWindowHelper $infoWindowHelper) - { - $this->infoWindowHelper = $infoWindowHelper; - } - - /** - * Gets the polyline helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\PolylineHelper The polyline helper. - */ - public function getPolylineHelper() - { - return $this->polylineHelper; - } - - /** - * Sets the polyline helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\PolylineHelper $polylineHelper The polyline helper. - */ - public function setPolylineHelper(PolylineHelper $polylineHelper) - { - $this->polylineHelper = $polylineHelper; - } - - /** - * Gets the encoded polyline helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper The encoded polyline helper. - */ - public function getEncodedPolylineHelper() - { - return $this->encodedPolylineHelper; - } - - /** - * Sets the encoded polyline helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper $encodedPolylineHelper The encoded polyline helper. - */ - public function setEncodedPolylineHelper(EncodedPolylineHelper $encodedPolylineHelper) - { - $this->encodedPolylineHelper = $encodedPolylineHelper; - } - - /** - * Gets the polygon helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\PolygonHelper The polygon helper. - */ - public function getPolygonHelper() - { - return $this->polygonHelper; - } - - /** - * Sets the polygon helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\PolygonHelper $polygonHelper The polygon helper. - */ - public function setPolygonHelper(PolygonHelper $polygonHelper) - { - $this->polygonHelper = $polygonHelper; - } - - /** - * Gets the rectangle helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\RectangleHelper The rectangle helper. - */ - public function getRectangleHelper() - { - return $this->rectangleHelper; - } - - /** - * Sets the rectangle helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\RectangleHelper $rectangleHelper The rectangle helper. - */ - public function setRectangleHelper(RectangleHelper $rectangleHelper) - { - $this->rectangleHelper = $rectangleHelper; - } - - /** - * Gets the circle helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\CircleHelper The circle helper. - */ - public function getCircleHelper() - { - return $this->circleHelper; - } - - /** - * Sets the circle helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\CircleHelper $circleHelper The circle helper. - */ - public function setCircleHelper(CircleHelper $circleHelper) - { - $this->circleHelper = $circleHelper; - } - - /** - * Gets the ground overlay helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper The ground overlay helper. - */ - public function getGroundOverlayHelper() - { - return $this->groundOverlayHelper; - } - - /** - * Sets the ground overlay helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper $groundOverlayHelper The ground overlay helper. - */ - public function setGroundOverlayHelper(GroundOverlayHelper $groundOverlayHelper) - { - $this->groundOverlayHelper = $groundOverlayHelper; - } - - /** - * Gets the KML layer helper. - * - * @return \Ivory\GoogleMap\Helper\Layers\KMLLayerHelper The KML layer helper. - */ - public function getKmlLayerHelper() - { - return $this->kmlLayerHelper; - } - - /** - * Sets the KML layer helper. - * - * @param \Ivory\GoogleMap\Helper\Layers\KMLLayerHelper $kmlLayerHelper The KML layer helper. - */ - public function setKmlLayerHelper(KMLLayerHelper $kmlLayerHelper) - { - $this->kmlLayerHelper = $kmlLayerHelper; - } - - /** - * Gets the event manager helper. - * - * @return \Ivory\GoogleMap\Helper\Events\EventManagerHelper The event manager helper. - */ - public function getEventManagerHelper() - { - return $this->eventManagerHelper; - } - - /** - * Sets the event manager helper. - * - * @param \Ivory\GoogleMap\Helper\Events\EventManagerHelper $eventManagerHelper The event manager helper. - */ - public function setEventManagerHelper(EventManagerHelper $eventManagerHelper) - { - $this->eventManagerHelper = $eventManagerHelper; - } - - /** - * Checks if the map helper has extensions. - * - * @return boolean TRUE if the map helper has extensions else FALSE. - */ - public function hasExtensionHelpers() - { - return !empty($this->extensionHelpers); - } - - /** - * Gets the map extension helpers. - * - * @return array The map extension helpers. - */ - public function getExtensionHelpers() - { - return $this->extensionHelpers; - } - - /** - * Sets the map extension helpers. - * - * @param array $extensionHelpers The map extension helpers. - */ - public function setExtensionHelpers(array $extensionHelpers) - { - $this->extensionHelpers = array(); - - foreach ($extensionHelpers as $name => $extensionHelper) { - $this->setExtensionHelper($name, $extensionHelper); - } - } - - /** - * Checks if the map helper has a specific extension helper. - * - * @param string $name The extension helper name. - * - * @return boolean TRUE if the map helper has a specific extension helper else FALSE. - */ - public function hasExtensionHelper($name) - { - return isset($this->extensionHelpers[$name]); - } - - /** - * Gets a specific extension helper. - * - * @param string $name The extension helper name. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the extension helper does not exist. - * - * @return \Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface The extension helper. - */ - public function getExtensionHelper($name) - { - if (!$this->hasExtensionHelper($name)) { - throw HelperException::invalidExtension($name); - } - - return $this->extensionHelpers[$name]; - } - - /** - * Sets an extension helper. - * - * @param string $name The extension helper name. - * @param \Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface $extensionHelper The extension helper. - */ - public function setExtensionHelper($name, ExtensionHelperInterface $extensionHelper) - { - $this->extensionHelpers[$name] = $extensionHelper; - } - - /** - * Removes an extension helper. - * - * @param string $name The extension helper name. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the extension helper does not exist. - */ - public function removeExtensionHelper($name) - { - if (!$this->hasExtensionHelper($name)) { - throw HelperException::invalidExtension($name); - } - - unset($this->extensionHelpers[$name]); - } - - /** - * Renders the html (container & stylesheets). - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The HTML output. - */ - public function render(Map $map) - { - return implode('', array( - $this->renderHtmlContainer($map), - $this->renderStylesheets($map), - $this->renderJavascripts($map) - )); - } - - /** - * Renders the map container. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The HTML output. - */ - public function renderHtmlContainer(Map $map) - { - return sprintf( - '
'.PHP_EOL, - $map->getHtmlContainerId(), - $map->getStylesheetOption('width'), - $map->getStylesheetOption('height') - ); - } - - /** - * Renders the html map stylesheets. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The HTML output. - */ - public function renderStylesheets(Map $map) - { - $html = array(); - - $html[] = ''.PHP_EOL; - - return implode('', $html); - } - - /** - * Renders the map javascripts. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The HTML output. - */ - public function renderJavascripts(Map $map) - { - $output = array(); - - if (!$map->isAsync()) { - $output[] = $this->renderJsLibraries($map); - } - - $output[] = ''.PHP_EOL; - - if ($map->isAsync()) { - $output[] = $this->renderJsLibraries($map); - } - - return implode('', $output); - } - - /** - * Renders the javascript libraries. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The HTML output. - */ - public function renderJsLibraries(Map $map) - { - $output = array(); - - foreach ($this->getExtensionHelpers() as $extension) { - $output[] = $extension->renderLibraries($map); - } - - return implode('', $output); - } - - /** - * Renders JS code just before the generated one. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsBefore(Map $map) - { - $output = array(); - - foreach ($this->getExtensionHelpers() as $extension) { - $output[] = $extension->renderBefore($map); - } - - return implode('', $output); - } - - /** - * Renders JS code just after the generated one. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsAfter(Map $map) - { - $output = array(); - - foreach (array_reverse($this->getExtensionHelpers()) as $extension) { - $output[] = $extension->renderAfter($map); - } - - return implode('', $output); - } - - /** - * Renders the javascript container. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainer(Map $map) - { - $output = array(); - - $output[] = $this->renderJsContainerInit($map); - - $output[] = $this->renderJsContainerCoordinates($map); - $output[] = $this->renderJsContainerBounds($map); - $output[] = $this->renderJsContainerPoints($map); - $output[] = $this->renderJsContainerSizes($map); - - $output[] = $this->renderJsContainerMap($map); - - $output[] = $this->renderJsContainerCircles($map); - $output[] = $this->renderJsContainerEncodedPolylines($map); - $output[] = $this->renderJsContainerGroundOverlays($map); - $output[] = $this->renderJsContainerPolygons($map); - $output[] = $this->renderJsContainerPolylines($map); - $output[] = $this->renderJsContainerRectangles($map); - $output[] = $this->renderJsContainerInfoWindows($map); - $output[] = $this->renderJsContainerMarkerImages($map); - $output[] = $this->renderJsContainerMarkerShapes($map); - $output[] = $this->renderJsContainerMarkerCluster($map); - - $output[] = $this->renderJsContainerKMLLayers($map); - - $output[] = $this->renderJsContainerEventManager($map); - - $output[] = $this->renderJsContainerExtra($map); - - return implode('', $output); - } - - /** - * Renders the javascript container initialization (empty container). - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerInit(Map $map) - { - $this->jsonBuilder - ->reset() - ->setJsonEncodeOptions(JSON_FORCE_OBJECT) - // Map - ->setValue('[map]', null) - // Base - ->setValue('[coordinates]', array()) - ->setValue('[bounds]', array()) - ->setValue('[points]', array()) - ->setValue('[sizes]', array()) - // Overlays - ->setValue('[circles]', array()) - ->setValue('[encoded_polylines]', array()) - ->setValue('[ground_overlays]', array()) - ->setValue('[polygons]', array()) - ->setValue('[polylines]', array()) - ->setValue('[rectangles]', array()) - ->setValue('[info_windows]', array()) - ->setValue('[marker_images]', array()) - ->setValue('[marker_shapes]', array()) - ->setValue('[markers]', array()) - ->setValue('[marker_cluster]', null) - // Layers - ->setValue('[kml_layers]', array()) - // Event Manager - ->setValue('[event_manager][dom_events]', array()) - ->setValue('[event_manager][dom_events_once]', array()) - ->setValue('[event_manager][events]', array()) - ->setValue('[event_manager][events_once]', array()) - // Internal - ->setValue('[closable_info_windows]', array()) - ->setValue( - '[functions][to_array]', - 'function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }', - false - ); - - return sprintf('%s = %s;'.PHP_EOL, $this->getJsContainerName($map), $this->jsonBuilder->build()); - } - - /** - * Renders the javascript container coordinates. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerCoordinates(Map $map) - { - $output = array(); - - foreach ($this->computeCoordinates($map) as $coordinate) { - $output[] = sprintf( - '%s.coordinates.%s = %s', - $this->getJsContainerName($map), - $coordinate->getJavascriptVariable(), - $this->coordinateHelper->render($coordinate) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container bounds. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerBounds(Map $map) - { - $output = array(); - - foreach ($this->computeBounds($map) as $bound) { - $output[] = sprintf( - '%s.bounds.%s = %s', - $this->getJsContainerName($map), - $bound->getJavascriptVariable(), - $this->boundHelper->render($bound) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container points. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerPoints(Map $map) - { - $output = array(); - - foreach ($this->computePoints($map) as $point) { - $output[] = sprintf( - '%s.points.%s = %s', - $this->getJsContainerName($map), - $point->getJavascriptVariable(), - $this->pointHelper->render($point) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container sizes. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerSizes(Map $map) - { - $output = array(); - - foreach ($this->computeSizes($map) as $size) { - $output[] = sprintf( - '%s.sizes.%s = %s', - $this->getJsContainerName($map), - $size->getJavascriptVariable(), - $this->sizeHelper->render($size) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerMap(Map $map) - { - return sprintf('%s.map = %s', $this->getJsContainerName($map), $this->renderMap($map)); - } - - /** - * Renders the javascript container circles. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerCircles(Map $map) - { - $output = array(); - - foreach ($map->getCircles() as $circle) { - $output[] = sprintf( - '%s.circles.%s = %s', - $this->getJsContainerName($map), - $circle->getJavascriptVariable(), - $this->circleHelper->render($circle, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container encoded polylines. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerEncodedPolylines(Map $map) - { - $output = array(); - - foreach ($map->getEncodedPolylines() as $encodedPolyline) { - $output[] = sprintf( - '%s.encoded_polylines.%s = %s', - $this->getJsContainerName($map), - $encodedPolyline->getJavascriptVariable(), - $this->encodedPolylineHelper->render($encodedPolyline, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container ground overlays. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerGroundOverlays(Map $map) - { - $output = array(); - - foreach ($map->getGroundOverlays() as $groundOverlay) { - $output[] = sprintf( - '%s.ground_overlays.%s = %s', - $this->getJsContainerName($map), - $groundOverlay->getJavascriptVariable(), - $this->groundOverlayHelper->render($groundOverlay, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container polygons. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerPolygons(Map $map) - { - $output = array(); - - foreach ($map->getPolygons() as $polygon) { - $output[] = sprintf( - '%s.polygons.%s = %s', - $this->getJsContainerName($map), - $polygon->getJavascriptVariable(), - $this->polygonHelper->render($polygon, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container polylines. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerPolylines(Map $map) - { - $output = array(); - - foreach ($map->getPolylines() as $polyline) { - $output[] = sprintf( - '%s.polylines.%s = %s', - $this->getJsContainerName($map), - $polyline->getJavascriptVariable(), - $this->polylineHelper->render($polyline, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container rectangles. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerRectangles(Map $map) - { - $output = array(); - - foreach ($map->getRectangles() as $rectangle) { - $output[] = sprintf( - '%s.rectangles.%s = %s', - $this->getJsContainerName($map), - $rectangle->getJavascriptVariable(), - $this->rectangleHelper->render($rectangle, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container info windows. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerInfoWindows(Map $map) - { - $output = array(); - - $mapInfoWindows = $map->getInfoWindows(); - $markerInfoWindows = $this->computeMarkerInfoWindows($map); - - foreach ($mapInfoWindows as $mapInfoWindow) { - $output[] = sprintf( - '%s.info_windows.%s = %s', - $this->getJsContainerName($map), - $mapInfoWindow->getJavascriptVariable(), - $this->infoWindowHelper->render($mapInfoWindow) - ); - } - - foreach ($markerInfoWindows as $markerInfoWindow) { - $output[] = sprintf( - '%s.info_windows.%s = %s', - $this->getJsContainerName($map), - $markerInfoWindow->getJavascriptVariable(), - $this->infoWindowHelper->render($markerInfoWindow, false) - ); - } - - foreach (array_merge($mapInfoWindows, $markerInfoWindows) as $infoWindow) { - if ($infoWindow->isAutoClose()) { - $output[] = sprintf( - '%s.closable_info_windows.%s = %s;'.PHP_EOL, - $this->getJsContainerName($map), - $infoWindow->getJavascriptVariable(), - $infoWindow->getJavascriptVariable() - ); - } - } - - return implode('', $output); - } - - /** - * Renders the javascript container maker images. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerMarkerImages(Map $map) - { - $output = array(); - - foreach ($this->computeMarkerImages($map) as $markerImage) { - $output[] = sprintf( - '%s.marker_images.%s = %s', - $this->getJsContainerName($map), - $markerImage->getJavascriptVariable(), - $this->markerImageHelper->render($markerImage) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container marker shapes. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerMarkerShapes(Map $map) - { - $output = array(); - - foreach ($this->computeMarkerShapes($map) as $markerShape) { - $output[] = sprintf( - '%s.marker_shapes.%s = %s', - $this->getJsContainerName($map), - $markerShape->getJavascriptVariable(), - $this->markerShapeHelper->render($markerShape) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container marker cluster. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerMarkerCluster(Map $map) - { - $output = array( - $this->markerClusterHelper->renderMarkers($map->getMarkerCluster(), $map), - $this->markerClusterHelper->render($map->getMarkerCluster(), $map), - ); - - return implode('', $output); - } - - /** - * Renders the javascript container KML layer. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerKMLLayers(Map $map) - { - $output = array(); - - foreach ($map->getKMLLayers() as $kmlLayer) { - $output[] = sprintf( - '%s.kml_layers.%s = %s', - $this->getJsContainerName($map), - $kmlLayer->getJavascriptVariable(), - $this->kmlLayerHelper->render($kmlLayer, $map) - ); - } - - return implode('', $output); - } - - /** - * Renders the javascript container event manager. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerEventManager(Map $map) - { - $output = array(); - - foreach ($map->getEventManager()->getDomEvents() as $domEvent) { - $output[] = sprintf( - '%s.event_manager.dom_events.%s = %s', - $this->getJsContainerName($map), - $domEvent->getJavascriptVariable(), - $this->eventManagerHelper->renderDomEvent($domEvent) - ); - } - - foreach ($map->getEventManager()->getDomEventsOnce() as $domEventOnce) { - $output[] = sprintf( - '%s.event_manager.dom_events_once.%s = %s', - $this->getJsContainerName($map), - $domEventOnce->getJavascriptVariable(), - $this->eventManagerHelper->renderDomEventOnce($domEventOnce) - ); - } - - foreach ($map->getEventManager()->getEvents() as $event) { - $output[] = sprintf( - '%s.event_manager.events.%s = %s', - $this->getJsContainerName($map), - $event->getJavascriptVariable(), - $this->eventManagerHelper->renderEvent($event) - ); - } - - foreach ($map->getEventManager()->getEventsOnce() as $eventOnce) { - $output[] = sprintf( - '%s.event_manager.events_once.%s = %s', - $this->getJsContainerName($map), - $eventOnce->getJavascriptVariable(), - $this->eventManagerHelper->renderEventOnce($eventOnce) - ); - } - - return implode('', $output); - } - - /** - * Renders the js container extra. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderJsContainerExtra(Map $map) - { - $output = array(); - - foreach ($map->getInfoWindows() as $infoWindow) { - if ($infoWindow->isOpen()) { - $output[] = $this->infoWindowHelper->renderOpen($infoWindow, $map); - } - } - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isOpen()) { - $output[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker); - } - } - - foreach ($this->computeBounds($map) as $bound) { - if ($bound->hasExtends()) { - $output[] = $this->boundHelper->renderExtends($bound); - } - } - - if ($map->isAutoZoom()) { - $output[] = $this->renderMapBound($map); - } else { - $output[] = $this->renderMapCenter($map); - } - - return implode('', $output); - } - - /** - * Renders the map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderMap(Map $map) - { - $mapTypeId = $map->getMapOption('mapTypeId'); - $map->removeMapOption('mapTypeId'); - - $this->jsonBuilder - ->reset() - ->setValue('[mapTypeId]', $this->mapTypeIdHelper->render($mapTypeId), false); - - $this->renderMapControls($map); - - if ($map->isAutoZoom()) { - $map->removeMapOption('zoom'); - } - - $this->jsonBuilder->setValues($map->getMapOptions()); - - return sprintf( - '%s = new google.maps.Map(document.getElementById("%s"), %s);'.PHP_EOL, - $map->getJavascriptVariable(), - $map->getHtmlContainerId(), - $this->jsonBuilder->build() - ); - } - - /** - * Renders the map center. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string Ths JS output. - */ - public function renderMapCenter(Map $map) - { - return sprintf( - '%s.setCenter(%s);'.PHP_EOL, - $map->getJavascriptVariable(), - $map->getCenter()->getJavascriptVariable() - ); - } - - /** - * Renders the map bound. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderMapBound(Map $map) - { - return sprintf( - '%s.fitBounds(%s);'.PHP_EOL, - $map->getJavascriptVariable(), - $map->getBound()->getJavascriptVariable() - ); - } - - /** - * Computes the coordinates of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed coordinated. - */ - protected function computeCoordinates(Map $map) - { - $coordinates = array(); - - if (!$map->isAutoZoom() && !in_array($map->getCenter(), $coordinates)) { - $coordinates[] = $map->getCenter(); - } - - foreach ($this->computeBounds($map) as $bound) { - if (!$bound->hasExtends() && $bound->hasCoordinates()) { - if (!in_array($bound->getSouthWest(), $coordinates)) { - $coordinates[] = $bound->getSouthWest(); - } - - if (!in_array($bound->getNorthEast(), $coordinates)) { - $coordinates[] = $bound->getNorthEast(); - } - } - } - - foreach ($map->getCircles() as $circle) { - if (!in_array($circle->getCenter(), $coordinates)) { - $coordinates[] = $circle->getCenter(); - } - } - - foreach ($map->getInfoWindows() as $infoWindow) { - if (!in_array($infoWindow->getPosition(), $coordinates)) { - $coordinates[] = $infoWindow->getPosition(); - } - } - - foreach ($map->getMarkers() as $marker) { - if (!in_array($marker->getPosition(), $coordinates)) { - $coordinates[] = $marker->getPosition(); - } - } - - foreach ($map->getPolygons() as $polygon) { - foreach ($polygon->getCoordinates() as $polygonCoordinate) { - if (!in_array($polygonCoordinate, $coordinates)) { - $coordinates[] = $polygonCoordinate; - } - } - } - - foreach ($map->getPolylines() as $polyline) { - foreach ($polyline->getCoordinates() as $polylineCoordinate) { - if (!in_array($polylineCoordinate, $coordinates)) { - $coordinates[] = $polylineCoordinate; - } - } - } - - return $coordinates; - } - - /** - * Computes the bounds of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed bounds. - */ - protected function computeBounds(Map $map) - { - $bounds = array(); - - if ($map->isAutoZoom() && !in_array($map->getBound(), $bounds)) { - $bounds[] = $map->getBound(); - } - - foreach ($map->getGroundOverlays() as $groundOverlay) { - if (!in_array($groundOverlay->getBound(), $bounds)) { - $bounds[] = $groundOverlay->getBound(); - } - } - - foreach ($map->getRectangles() as $rectangle) { - if (!in_array($rectangle->getBound(), $bounds)) { - $bounds[] = $rectangle->getBound(); - } - } - - return $bounds; - } - - /** - * Computes the points of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed points. - */ - protected function computePoints(Map $map) - { - $points = array(); - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasIcon()) { - if ($marker->getIcon()->hasAnchor() && !in_array($marker->getIcon()->getAnchor(), $points)) { - $points[] = $marker->getIcon()->getAnchor(); - } - - if ($marker->getIcon()->hasOrigin() && !in_array($marker->getIcon()->getOrigin(), $points)) { - $points[] = $marker->getIcon()->getOrigin(); - } - } - - if ($marker->hasShadow()) { - if ($marker->getShadow()->hasAnchor() && !in_array($marker->getShadow()->getAnchor(), $points)) { - $points[] = $marker->getShadow()->getAnchor(); - } - - if ($marker->getShadow()->hasOrigin() && !in_array($marker->getShadow()->getOrigin(), $points)) { - $points[] = $marker->getShadow()->getOrigin(); - } - } - } - - return $points; - } - - /** - * Computes the sizes of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed sizes. - */ - protected function computeSizes(Map $map) - { - $sizes = array(); - - foreach (array_merge($map->getInfoWindows(), $this->computeMarkerInfoWindows($map)) as $infoWindow) { - if ($infoWindow->hasPixelOffset() && !in_array($infoWindow->getPixelOffset(), $sizes)) { - $sizes[] = $infoWindow->getPixelOffset(); - } - } - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasIcon()) { - if ($marker->getIcon()->hasSize() && !in_array($marker->getIcon()->getSize(), $sizes)) { - $sizes[] = $marker->getIcon()->getSize(); - } - - if ($marker->getIcon()->hasScaledSize() && !in_array($marker->getIcon()->getScaledSize(), $sizes)) { - $sizes[] = $marker->getIcon()->getScaledSize(); - } - } - - if ($marker->hasShadow()) { - if ($marker->getShadow()->hasSize() && !in_array($marker->getShadow()->getSize(), $sizes)) { - $sizes[] = $marker->getShadow()->getSize(); - } - - if ($marker->getShadow()->hasScaledSize() && !in_array($marker->getShadow()->getScaledSize(), $sizes)) { - $sizes[] = $marker->getShadow()->getScaledSize(); - } - } - } - - return $sizes; - } - - /** - * Computes the marker images of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed marker images. - */ - protected function computeMarkerImages(Map $map) - { - $markerImages = array(); - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasIcon() && !in_array($marker->getIcon(), $markerImages)) { - $markerImages[] = $marker->getIcon(); - } - - if ($marker->hasShadow() && !in_array($marker->getShadow(), $markerImages)) { - $markerImages[] = $marker->getShadow(); - } - } - - return $markerImages; - } - - /** - * Computes the marker shapes of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed marker shapes. - */ - protected function computeMarkerShapes(Map $map) - { - $markerShapes = array(); - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasShape() && !in_array($marker->getShape(), $markerShapes)) { - $markerShapes[] = $marker->getShape(); - } - } - - return $markerShapes; - } - - /** - * Computes the marker info windows of a map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return array The computed marker info windows. - */ - protected function computeMarkerInfoWindows(Map $map) - { - $infoWinfows = array(); - - foreach ($map->getMarkers() as $marker) { - if ($marker->hasInfoWindow() && !in_array($marker->getInfoWindow(), $infoWinfows)) { - $infoWinfows[] = $marker->getInfoWindow(); - } - } - - return $infoWinfows; - } - - /** - * Renders the map controls in the json builder. - * - * @param \Ivory\GoogleMap\Map $map The map. - */ - protected function renderMapControls(Map $map) - { - $controlNames = array( - 'MapTypeControl', - 'OverviewMapControl', - 'PanControl', - 'RotateControl', - 'ScaleControl', - 'StreetViewControl', - 'ZoomControl', - ); - - foreach ($controlNames as $controlName) { - $controlHelper = lcfirst($controlName).'Helper'; - $this->renderMapControl($map, $controlName, $this->$controlHelper); - } - } - - /** - * Renders a map control in the json builder. - * - * @param \Ivory\GoogleMap\Map $map The map. - * @param string $controlName The control name. - * @param mixed $controlHelper The control helper. - */ - protected function renderMapControl(Map $map, $controlName, $controlHelper) - { - $lcFirstControlName = lcfirst($controlName); - - if (!$map->hasMapOption($lcFirstControlName)) { - return; - } - - $this->jsonBuilder->setValue( - sprintf('[%s]', $lcFirstControlName), - (bool) $map->getMapOption($lcFirstControlName) - ); - - if ($map->getMapOption($lcFirstControlName)) { - $hasControlMethod = 'has'.$controlName; - if ($map->$hasControlMethod()) { - $getControlMethod = 'get'.$controlName; - - $this->jsonBuilder->setValue( - sprintf('[%sOptions]', $lcFirstControlName), - $controlHelper->render($map->$getControlMethod()), - false - ); - } - } - - $map->removeMapOption($lcFirstControlName); - } -} diff --git a/src/Helper/MapTypeIdHelper.php b/src/Helper/MapTypeIdHelper.php deleted file mode 100644 index 8c18f551..00000000 --- a/src/Helper/MapTypeIdHelper.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper; - -use Ivory\GoogleMap\Exception\HelperException; -use Ivory\GoogleMap\MapTypeId; - -/** - * Map type ID helper. - * - * @author GeLo - */ -class MapTypeIdHelper -{ - /** - * Renders a map map type ID. - * - * @param string $mapTypeId The map type ID. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the map type ID is not valid. - * - * @return string The JS output. - */ - public function render($mapTypeId) - { - switch ($mapTypeId) { - case MapTypeId::HYBRID: - case MapTypeId::ROADMAP: - case MapTypeId::SATELLITE: - case MapTypeId::TERRAIN: - return sprintf('google.maps.MapTypeId.%s', strtoupper($mapTypeId)); - default: - throw HelperException::invalidMapTypeId(); - } - } -} diff --git a/src/Helper/Overlays/AnimationHelper.php b/src/Helper/Overlays/AnimationHelper.php deleted file mode 100644 index bdc13fa5..00000000 --- a/src/Helper/Overlays/AnimationHelper.php +++ /dev/null @@ -1,43 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Exception\HelperException; -use Ivory\GoogleMap\Overlays\Animation; - -/** - * Animation helper. - * - * @author GeLo - */ -class AnimationHelper -{ - /** - * Renders an animation. - * - * @param string $animation The animation. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the animation is not valid. - * - * @return string The JS output. - */ - public function render($animation) - { - switch ($animation) { - case Animation::BOUNCE: - case Animation::DROP: - return sprintf('google.maps.Animation.%s', strtoupper($animation)); - default: - throw HelperException::invalidAnimation(); - } - } -} diff --git a/src/Helper/Overlays/EncodedPolylineHelper.php b/src/Helper/Overlays/EncodedPolylineHelper.php deleted file mode 100644 index 2dc89aa0..00000000 --- a/src/Helper/Overlays/EncodedPolylineHelper.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\EncodedPolyline; -use Ivory\GoogleMap\Helper\Geometry\EncodingHelper; - -/** - * Encoded polyline helper. - * - * @author GeLo - */ -class EncodedPolylineHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Geometry\EncodingHelper */ - protected $encodingHelper; - - /** - * Creates an encoded polyline helper. - * - * @param \Ivory\GoogleMap\Helper\Geometry\EncodingHelper $encodingHelper The encoding helper. - */ - public function __construct(EncodingHelper $encodingHelper = null) - { - parent::__construct(); - - if ($encodingHelper === null) { - $encodingHelper = new EncodingHelper(); - } - - $this->setEncodingHelper($encodingHelper); - } - - /** - * Gets the encoding helper. - * - * @return \Ivory\GoogleMap\Helper\Geometry\EncodingHelper The encoding helper. - */ - public function getEncodingHelper() - { - return $this->encodingHelper; - } - - /** - * Sets the encoding helper. - * - * @param \Ivory\GoogleMap\Helper\Geometry\EncodingHelper $encodingHelper The encoding helper. - */ - public function setEncodingHelper(EncodingHelper $encodingHelper) - { - $this->encodingHelper = $encodingHelper; - } - - /** - * Renders an encoded polyline. - * - * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function render(EncodedPolyline $encodedPolyline, Map $map) - { - $this->jsonBuilder - ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValue('[path]', $this->encodingHelper->renderDecodePath($encodedPolyline->getValue()), false) - ->setValues($encodedPolyline->getOptions()); - - return sprintf( - '%s = new google.maps.Polyline(%s);'.PHP_EOL, - $encodedPolyline->getJavascriptVariable(), - $this->jsonBuilder->build() - ); - } -} diff --git a/src/Helper/Overlays/InfoBoxHelper.php b/src/Helper/Overlays/InfoBoxHelper.php deleted file mode 100644 index daee2d64..00000000 --- a/src/Helper/Overlays/InfoBoxHelper.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\InfoWindow; - -/** - * InfoBox helper. - * - * @author GeLo - */ -class InfoBoxHelper extends InfoWindowHelper -{ - /** - * {@inheritdoc} - */ - public function render(InfoWindow $infoWindow, $renderPosition = true) - { - $this->doRender($infoWindow, $renderPosition); - - return sprintf( - '%s = new InfoBox(%s);'.PHP_EOL, - $infoWindow->getJavascriptVariable(), - $this->jsonBuilder->build() - ); - } -} diff --git a/src/Helper/Overlays/InfoWindowHelper.php b/src/Helper/Overlays/InfoWindowHelper.php deleted file mode 100644 index b1b84667..00000000 --- a/src/Helper/Overlays/InfoWindowHelper.php +++ /dev/null @@ -1,94 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\InfoWindow; - -/** - * Info window helper. - * - * @author GeLo - */ -class InfoWindowHelper extends AbstractHelper -{ - /** - * Renders an info window. - * - * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. - * @param boolean $renderPosition TRUE if the position is rendered else FALSE. - * - * @return string The JS output. - */ - public function render(InfoWindow $infoWindow, $renderPosition = true) - { - $this->doRender($infoWindow, $renderPosition); - - return sprintf( - '%s = new google.maps.InfoWindow(%s);'.PHP_EOL, - $infoWindow->getJavascriptVariable(), - $this->jsonBuilder->build() - ); - } - - /** - * Renders the info window open flag. - * - * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. - * @param \Ivory\GoogleMap\Map $map The map. - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. - * - * @return string The JS output. - */ - public function renderOpen(InfoWindow $infoWindow, Map $map, Marker $marker = null) - { - if ($marker !== null) { - return sprintf( - '%s.open(%s, %s);'.PHP_EOL, - $infoWindow->getJavascriptVariable(), - $map->getJavascriptVariable(), - $marker->getJavascriptVariable() - ); - } - - return sprintf('%s.open(%s);'.PHP_EOL, $infoWindow->getJavascriptVariable(), $map->getJavascriptVariable()); - } - - /** - * Configures the json builder in order to render an info window. - * - * @param \Ivory\GoogleMap\Helper\Overlays\InfoWinfow $infoWindow The info window. - * @param boolean $renderPosition TRUE if the position is rendered else FALSE. - */ - protected function doRender(InfoWindow $infoWindow, $renderPosition) - { - $this->jsonBuilder->reset(); - - if ($renderPosition) { - $this->jsonBuilder->setValue('[position]', $infoWindow->getPosition()->getJavascriptVariable(), false); - } - - if ($infoWindow->hasPixelOffset()) { - $this->jsonBuilder->setValue( - '[pixelOffset]', - $infoWindow->getPixelOffset()->getJavascriptVariable(), - false - ); - } - - $this->jsonBuilder - ->setValue('[content]', $infoWindow->getContent()) - ->setValues($infoWindow->getOptions()); - } -} diff --git a/src/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelper.php b/src/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelper.php deleted file mode 100644 index 4a31a964..00000000 --- a/src/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelper.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerHelper; - -/** - * Abstract marker cluster helper. - * - * @author GeLo - */ -abstract class AbstractMarkerClusterHelper extends AbstractHelper implements MarkerClusterHelperInterface -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerHelper */ - protected $markerHelper; - - /** - * Creates a default marker cluster helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerHelper $markerHelper The marker helper. - */ - public function __construct(MarkerHelper $markerHelper = null) - { - parent::__construct(); - - if ($markerHelper === null) { - $markerHelper = new MarkerHelper(); - } - - $this->setMarkerHelper($markerHelper); - } - - /** - * Gets the marker helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerHelper The marker helper. - */ - public function getMarkerHelper() - { - return $this->markerHelper; - } - - /** - * Sets the marker helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerHelper $markerHelper The marker helper. - */ - public function setMarkerHelper(MarkerHelper $markerHelper) - { - $this->markerHelper = $markerHelper; - } -} diff --git a/src/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelper.php b/src/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelper.php deleted file mode 100644 index 2cfcfe00..00000000 --- a/src/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelper.php +++ /dev/null @@ -1,147 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Events\Event; -use Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper; -use Ivory\GoogleMap\Helper\Overlays\MarkerHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -/** - * Default marker cluster helper. - * - * @author GeLo - */ -class DefaultMarkerClusterHelper extends AbstractMarkerClusterHelper -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper */ - protected $infoWindowHelper; - - /** - * Creates a default marker cluster helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerHelper $markerHelper The marker helper. - * @param \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper $infoWindowHelper The info window helper. - */ - public function __construct(MarkerHelper $markerHelper = null, InfoWindowHelper $infoWindowHelper = null) - { - parent::__construct($markerHelper); - - if ($infoWindowHelper === null) { - $infoWindowHelper = new InfoWindowHelper(); - } - - $this->setInfoWindowHelper($infoWindowHelper); - } - - /** - * Gets the info window helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper The info window helper. - */ - public function getInfoWindowHelper() - { - return $this->infoWindowHelper; - } - - /** - * Sets the info window helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper $infoWindowHelper The info window helper. - */ - public function setInfoWindowHelper(InfoWindowHelper $infoWindowHelper) - { - $this->infoWindowHelper = $infoWindowHelper; - } - - /** - * {@inheritdoc} - */ - public function render(MarkerCluster $markerCluster, Map $map) - { - - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(MarkerCluster $markerCluster, Map $map) - { - - } - - /** - * {@inheritdoc} - */ - public function renderMarkers(MarkerCluster $markerCluster, Map $map) - { - $output = array(); - - foreach ($markerCluster->getMarkers() as $marker) { - $output[] = $this->renderMarker($marker, $map); - - if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isAutoOpen()) { - $this->registerInfoWindowEvent($marker, $map); - } - } - - return implode('', $output); - } - - /** - * Renders a marker with the js map container. - * - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - protected function renderMarker(Marker $marker, Map $map) - { - return sprintf( - '%s.markers.%s = %s', - $this->getJsContainerName($map), - $marker->getJavascriptVariable(), - $this->markerHelper->render($marker, $map) - ); - } - - /** - * Registers the info window event (auto open). - * - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. - * @param \Ivory\GoogleMap\Map $map The map. - */ - protected function registerInfoWindowEvent(Marker $marker, Map $map) - { - $closableInfoWindows = sprintf('%s.closable_info_windows', $this->getJsContainerName($map)); - - $handle = <<infoWindowHelper->renderOpen($marker->getInfoWindow(), $map, $marker)} -} -EOF; - - $event = new Event(); - $event->setJavascriptVariable(sprintf('%s_%s', $marker->getJavascriptVariable(), 'info_window_event')); - $event->setInstance($marker->getJavascriptVariable()); - $event->setEventName($marker->getInfoWindow()->getOpenEvent()); - $event->setHandle($handle); - - $map->getEventManager()->addEvent($event); - } -} diff --git a/src/Helper/Overlays/MarkerCluster/JsMarkerClusterHelper.php b/src/Helper/Overlays/MarkerCluster/JsMarkerClusterHelper.php deleted file mode 100644 index cf9032e1..00000000 --- a/src/Helper/Overlays/MarkerCluster/JsMarkerClusterHelper.php +++ /dev/null @@ -1,73 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -/** - * Javascript marker cluster helper. - * - * @author GeLo - */ -class JsMarkerClusterHelper extends DefaultMarkerClusterHelper -{ - /** - * {@inheritdoc} - */ - public function render(MarkerCluster $markerCluster, Map $map) - { - $this->jsonBuilder - ->reset() - ->setValues($markerCluster->getOptions()); - - return sprintf('%s = new MarkerClusterer(%s, %s, %s);'.PHP_EOL, - $markerCluster->getJavascriptVariable(), - $map->getJavascriptVariable(), - sprintf( - '%s.functions.to_array(%s.markers)', - $this->getJsContainerName($map), - $this->getJsContainerName($map) - ), - $this->jsonBuilder->build() - ); - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(MarkerCluster $markerCluster, Map $map) - { - $url = '//google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js'; - - return sprintf(''.PHP_EOL, $url); - } - - /** - * Renders a marker with the js map container. - * - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - protected function renderMarker(Marker $marker, Map $map) - { - return sprintf( - '%s.markers.%s = %s', - $this->getJsContainerName($map), - $marker->getJavascriptVariable(), - $this->markerHelper->render($marker) - ); - } -} diff --git a/src/Helper/Overlays/MarkerCluster/MarkerClusterHelper.php b/src/Helper/Overlays/MarkerCluster/MarkerClusterHelper.php deleted file mode 100644 index c7073fcb..00000000 --- a/src/Helper/Overlays/MarkerCluster/MarkerClusterHelper.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Exception\HelperException; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -/** - * Marker cluster helper. - * - * @author GeLo - */ -class MarkerClusterHelper implements MarkerClusterHelperInterface -{ - /** @var array */ - protected $helpers; - - /** - * Creates a marker cluster helper. - */ - public function __construct(array $helpers = array()) - { - if (empty($helpers)) { - $helpers = array( - MarkerCluster::_DEFAULT => new DefaultMarkerClusterHelper(), - MarkerCluster::MARKER_CLUSTER => new JsMarkerClusterHelper(), - ); - } - - $this->setHelpers($helpers); - } - - /** - * Checks if the marker cluster helper has helpers. - * - * @return boolean TRUE if the marker cluster helper has helpers else FALSE. - */ - public function hasHelpers() - { - return !empty($this->helpers); - } - - /** - * Gets the marker cluster helper helpers. - * - * @return array The marker cluster helper helpers. - */ - public function getHelpers() - { - return $this->helpers; - } - - /** - * Sets the marker cluster helper helpers. - * - * @param array $helpers The marker cluster helper helpers. - */ - public function setHelpers(array $helpers) - { - $this->helpers = array(); - - foreach ($helpers as $name => $helper) { - $this->setHelper($name, $helper); - } - } - - /** - * Checks if the marker cluster helper has a specific helper. - * - * @param string $name The marker cluster type. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface The marker cluster helper. - */ - public function hasHelper($name) - { - return isset($this->helpers[$name]); - } - - /** - * Gets a specific marker cluster helper. - * - * @param string $name The marker cluster type. - * - * @throws \Ivory\GoogleMap\Exception\HelperException If the helper does not exist. - * - * @return \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface The marker cluster helper. - */ - public function getHelper($name) - { - if (!$this->hasHelper($name)) { - throw HelperException::invalidMarkerClusterHelper(); - } - - return $this->helpers[$name]; - } - - /** - * Sets a specific marker cluster helper. - * - * @param string $name The marker cluster type. - * @param \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface $helper The marker cluster helper. - */ - public function setHelper($name, MarkerClusterHelperInterface $helper = null) - { - $this->helpers[$name] = $helper; - } - - /** - * {@inheritdoc} - */ - public function render(MarkerCluster $markerCluster, Map $map) - { - return $this->getHelper($markerCluster->getType())->render($markerCluster, $map); - } - - /** - * {@inheritdoc} - */ - public function renderMarkers(MarkerCluster $markerCluster, Map $map) - { - return $this->getHelper($markerCluster->getType())->renderMarkers($markerCluster, $map); - } - - /** - * {@inheritdoc} - */ - public function renderLibraries(MarkerCluster $markerCluster, Map $map) - { - return $this->getHelper($markerCluster->getType())->renderLibraries($markerCluster, $map); - } -} diff --git a/src/Helper/Overlays/MarkerCluster/MarkerClusterHelperInterface.php b/src/Helper/Overlays/MarkerCluster/MarkerClusterHelperInterface.php deleted file mode 100644 index 95889270..00000000 --- a/src/Helper/Overlays/MarkerCluster/MarkerClusterHelperInterface.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -/** - * Marker cluster helper. - * - * @author GeLo - */ -interface MarkerClusterHelperInterface -{ - /** - * Renders a marker cluster with the js map container. - * - * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. - * @param \Ivory\GoogleMap\Map $map The map - * - * @return string The JS output. - */ - public function render(MarkerCluster $markerCluster, Map $map); - - /** - * Renders the markers of a marker cluster with the js container. - * - * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function renderMarkers(MarkerCluster $markerCluster, Map $map); - - /** - * Renders the marker cluster libraries. - * - * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The html output. - */ - public function renderLibraries(MarkerCluster $markerCluster, Map $map); -} diff --git a/src/Helper/Overlays/MarkerHelper.php b/src/Helper/Overlays/MarkerHelper.php deleted file mode 100644 index 64462fa1..00000000 --- a/src/Helper/Overlays/MarkerHelper.php +++ /dev/null @@ -1,106 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\Marker; - -/** - * Marker helper. - * - * @author GeLo - */ -class MarkerHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\AnimationHelper */ - protected $animationHelper; - - /** - * Creates a marker helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\AnimationHelper $animationHelper The animation helper. - */ - public function __construct(AnimationHelper $animationHelper = null) - { - parent::__construct(); - - if ($animationHelper === null) { - $animationHelper = new AnimationHelper(); - } - - $this->setAnimationHelper($animationHelper); - } - - /** - * Gets the animation helper. - * - * @return \Ivory\GoogleMap\Helper\Overlays\AnimationHelper The animation helper. - */ - public function getAnimationHelper() - { - return $this->animationHelper; - } - - /** - * Sets the animation helper. - * - * @param \Ivory\GoogleMap\Helper\Overlays\AnimationHelper $animationHelper The animation helper. - */ - public function setAnimationHelper(AnimationHelper $animationHelper) - { - $this->animationHelper = $animationHelper; - } - - /** - * Renders a marker. - * - * @param Ivory\GoogleMap\Overlays\Marker $marker The marker. - * @param Ivory\GoogleMap\Map $map The map. - * - * @return string The JS output. - */ - public function render(Marker $marker, Map $map = null) - { - $this->jsonBuilder - ->reset() - ->setValue('[position]', $marker->getPosition()->getJavascriptVariable(), false); - - if ($map !== null) { - $this->jsonBuilder->setValue('[map]', $map->getJavascriptVariable(), false); - } - - if ($marker->hasAnimation()) { - $this->jsonBuilder->setValue('[animation]', $this->animationHelper->render($marker->getAnimation()), false); - } - - if ($marker->hasIcon()) { - $this->jsonBuilder->setValue('[icon]', $marker->getIcon()->getJavascriptVariable(), false); - } - - if ($marker->hasShadow()) { - $this->jsonBuilder->setValue('[shadow]', $marker->getShadow()->getJavascriptVariable(), false); - } - - if ($marker->hasShape()) { - $this->jsonBuilder->setValue('[shape]', $marker->getShape()->getJavascriptVariable(), false); - } - - $this->jsonBuilder->setValues($marker->getOptions()); - - return sprintf( - '%s = new google.maps.Marker(%s);'.PHP_EOL, - $marker->getJavascriptVariable(), - $this->jsonBuilder->build() - ); - } -} diff --git a/src/Helper/Overlays/MarkerImageHelper.php b/src/Helper/Overlays/MarkerImageHelper.php deleted file mode 100644 index d8315a86..00000000 --- a/src/Helper/Overlays/MarkerImageHelper.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\MarkerImage; - -/** - * Marker image helper. - * - * @author GeLo - */ -class MarkerImageHelper -{ - /** - * Renders a marker image. - * - * @param \Ivory\GoogleMap\Overlays\MarkerImage $markerImage The marker image. - * - * @return string The JS output. - */ - public function render(MarkerImage $markerImage) - { - return sprintf( - '%s = new google.maps.MarkerImage("%s", %s, %s, %s, %s);'.PHP_EOL, - $markerImage->getJavascriptVariable(), - $markerImage->getUrl(), - $markerImage->hasSize() ? $markerImage->getSize()->getJavascriptVariable() : 'null', - $markerImage->hasOrigin() ? $markerImage->getOrigin()->getJavascriptVariable() : 'null', - $markerImage->hasAnchor() ? $markerImage->getAnchor()->getJavascriptVariable() : 'null', - $markerImage->hasScaledSize() ? $markerImage->getScaledSize()->getJavascriptVariable() : 'null' - ); - } -} diff --git a/src/Helper/Places/AutocompleteHelper.php b/src/Helper/Places/AutocompleteHelper.php deleted file mode 100644 index 1a9fb08d..00000000 --- a/src/Helper/Places/AutocompleteHelper.php +++ /dev/null @@ -1,240 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Helper\Places; - -use Ivory\GoogleMap\Exception\HelperException; -use Ivory\GoogleMap\Helper\AbstractHelper; -use Ivory\GoogleMap\Helper\ApiHelper; -use Ivory\GoogleMap\Helper\Base\CoordinateHelper; -use Ivory\GoogleMap\Helper\Base\BoundHelper; -use Ivory\GoogleMap\Places\Autocomplete; - -/** - * Places autocomplete helper. - * - * @author GeLo - */ -class AutocompleteHelper extends AbstractHelper -{ - /** @var \Ivory\GoogleMap\Helper\ApiHelper */ - protected $apiHelper; - - /** @var \Ivory\GoogleMap\Helper\Base\CoordinateHelper */ - protected $coordinateHelper; - - /** @var \Ivory\GoogleMap\Helper\Base\BoundHelper */ - protected $boundHelper; - - /** - * Creates an autocomplete helper. - * - * @param \Ivory\GoogleMap\Helper\ApiHelper $apiHelper The API helper. - * @param \Ivory\GoogleMap\Helper\Base\CoordinateHelper $coordinateHelper The coordinate helper. - * @param \Ivory\GoogleMap\Helper\Base\BoundHelper $boundHelper The bound helper. - */ - public function __construct( - ApiHelper $apiHelper = null, - CoordinateHelper $coordinateHelper = null, - BoundHelper $boundHelper = null - ) - { - parent::__construct(); - - if ($apiHelper === null) { - $apiHelper = new ApiHelper(); - } - - if ($coordinateHelper === null) { - $coordinateHelper = new CoordinateHelper(); - } - - if ($boundHelper === null) { - $boundHelper = new BoundHelper(); - } - - $this->setApiHelper($apiHelper); - $this->setCoordinateHelper($coordinateHelper); - $this->setBoundHelper($boundHelper); - } - - /** - * Gets the API helper. - * - * @return \Ivory\GoogleMap\Helper\ApiHelper The API helper. - */ - public function getApiHelper() - { - return $this->apiHelper; - } - - /** - * Sets the API helper. - * - * @param \Ivory\GoogleMap\Helper\ApiHelper $apiHelper The API helper. - */ - public function setApiHelper(ApiHelper $apiHelper) - { - $this->apiHelper = $apiHelper; - } - - /** - * Gets the coordinate helper. - * - * @return \Ivory\GoogleMap\Helper\Base\CoordinateHelper The coordinate helper. - */ - public function getCoordinateHelper() - { - return $this->coordinateHelper; - } - - /** - * Sets the coordinate helper. - * - * @param \Ivory\GoogleMap\Helper\Base\CoordinateHelper $coordinateHelper The coordinate helper. - */ - public function setCoordinateHelper(CoordinateHelper $coordinateHelper) - { - $this->coordinateHelper = $coordinateHelper; - } - - /** - * Gets the bound helper. - * - * @return \Ivory\GoogleMap\Helper\Base\BoundHelper The bound helper. - */ - public function getBoundHelper() - { - return $this->boundHelper; - } - - /** - * Sets the bound helper. - * - * @param \Ivory\GoogleMap\Helper\Base\BoundHelper $boundHelper The bound helper. - */ - public function setBoundHelper(BoundHelper $boundHelper) - { - $this->boundHelper = $boundHelper; - } - - /** - * Renders the autocomplete HTML container. - * - * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. - * - * @return string The HTML output. - */ - public function renderHtmlContainer(Autocomplete $autocomplete) - { - $inputAttributes = $autocomplete->getInputAttributes(); - - $inputAttributes['id'] = $autocomplete->getInputId(); - - if ($autocomplete->hasValue()) { - $inputAttributes['value'] = $autocomplete->getValue(); - } - - $htmlAttributes = array(); - foreach ($inputAttributes as $attribute => $value) { - $htmlAttributes[] = sprintf('%s="%s"', $attribute, $value); - } - - return sprintf(''.PHP_EOL, implode(' ', $htmlAttributes)); - } - - /** - * Renders the autocomplete javascripts. - * - * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. - * - * @throws \Ivory\GoogleMap\Exception\HelperException if the autocomplete bound does not have coordinates. - * - * @return string The HTML output. - */ - public function renderJavascripts(Autocomplete $autocomplete) - { - $output = array(); - - if (!$this->apiHelper->isLoaded() && !$autocomplete->isAsync()) { - $output[] = $this->apiHelper->render($autocomplete->getLanguage(), array('places')); - } - - $output[] = ''.PHP_EOL; - - if (!$this->apiHelper->isLoaded() && $autocomplete->isAsync()) { - $output[] = $this->apiHelper->render( - $autocomplete->getLanguage(), - array('places'), - 'load_ivory_google_place' - ); - } - - return implode('', $output); - } - - /** - * Renders the autocomplete. - * - * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. - * - * @return string The JS output. - */ - public function renderAutocomplete(Autocomplete $autocomplete) - { - $this->jsonBuilder->reset(); - - if ($autocomplete->hasTypes()) { - $this->jsonBuilder->setValue('[types]', $autocomplete->getTypes()); - } - - if ($autocomplete->hasBound()) { - $this->jsonBuilder->setValue('[bounds]', $autocomplete->getBound()->getJavascriptVariable(), false); - } - - if ($autocomplete->hasComponentRestrictions()) { - $this->jsonBuilder->setValue('[componentRestrictions]', $autocomplete->getComponentRestrictions()); - } - - if (!$this->jsonBuilder->hasValues()) { - $this->jsonBuilder->setJsonEncodeOptions(JSON_FORCE_OBJECT); - } - - return sprintf( - '%s = new google.maps.places.Autocomplete(document.getElementById(\'%s\'), %s);'.PHP_EOL, - $autocomplete->getJavascriptVariable(), - $autocomplete->getInputId(), - $this->jsonBuilder->build() - ); - } -} diff --git a/src/Helpers/AbstractEvent.php b/src/Helpers/AbstractEvent.php new file mode 100644 index 00000000..16e32bd4 --- /dev/null +++ b/src/Helpers/AbstractEvent.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Symfony\Component\EventDispatcher\Event; + +/** + * Abstract event. + * + * @author GeLo + */ +abstract class AbstractEvent extends Event +{ + /** @var string|null */ + protected $code; + + /** + * Gets the code. + * + * @return string|null The code. + */ + public function getCode() + { + return $this->code; + } + + /** + * Sets the code. + * + * @param string $code The code. + */ + public function setCode($code) + { + $this->code = $code; + } + + /** + * Adds a code. + * + * @param string $code The code. + */ + public function addCode($code) + { + $this->code .= $code; + } +} diff --git a/src/Helpers/AbstractHelper.php b/src/Helpers/AbstractHelper.php new file mode 100644 index 00000000..b8f70797 --- /dev/null +++ b/src/Helpers/AbstractHelper.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Symfony\Component\EventDispatcher\EventDispatcherInterface; + +/** + * Abstract helper. + * + * @author GeLo + */ +abstract class AbstractHelper +{ + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ + protected $eventDispatcher; + + /** + * Creates an helper. + * + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher The event dispatcher. + */ + public function __construct(EventDispatcherInterface $eventDispatcher) + { + $this->setEventDispatcher($eventDispatcher); + } + + /** + * Gets the event dispatcher. + * + * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface The event dispatcher. + */ + public function getEventDispatcher() + { + return $this->eventDispatcher; + } + + /** + * Sets the event dispatcher. + * + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher The event dispatcher. + */ + public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) + { + $this->eventDispatcher = $eventDispatcher; + } +} diff --git a/src/Helpers/Aggregators/AbstractAggregator.php b/src/Helpers/Aggregators/AbstractAggregator.php new file mode 100644 index 00000000..00bfd782 --- /dev/null +++ b/src/Helpers/Aggregators/AbstractAggregator.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators; + +/** + * Aggregator. + * + * @author GeLo + */ +class AbstractAggregator +{ + /** + * Aggregates values according to the previous values. + * + * @param array $values The values. + * @param array $previousValues The previous values. + * + * @return array The aggregated values. + */ + protected function aggregateValues(array $values, array $previousValues = array()) + { + foreach ($values as $value) { + $previousValues = $this->aggregateValue($value, $previousValues); + } + + return $previousValues; + } + + /** + * Aggregates a value according to the previous values. + * + * @param mixed $value The value. + * @param array $previousValues The previous values. + * + * @return array The aggregated values. + */ + protected function aggregateValue($value, array $previousValues = array()) + { + if (!in_array($value, $previousValues, true)) { + $previousValues[] = $value; + } + + return $previousValues; + } +} diff --git a/src/Helpers/Aggregators/Base/BoundAggregator.php b/src/Helpers/Aggregators/Base/BoundAggregator.php new file mode 100644 index 00000000..2a64b1e6 --- /dev/null +++ b/src/Helpers/Aggregators/Base/BoundAggregator.php @@ -0,0 +1,139 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator; +use Ivory\GoogleMap\Map; + +/** + * Bound aggregator. + * + * @author GeLo + */ +class BoundAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator */ + protected $groundOverlayAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator */ + protected $rectangleAggregator; + + /** + * Creates a map bound aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator|null $groundOverlayAggregator The ground overlay aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator|null $rectangleAggregator The rectangle aggregator. + */ + public function __construct( + GroundOverlayAggregator $groundOverlayAggregator = null, + RectangleAggregator $rectangleAggregator = null + ) { + $this->setGroundOverlayAggregator($groundOverlayAggregator ?: new GroundOverlayAggregator()); + $this->setRectangleAggregator($rectangleAggregator ?: new RectangleAggregator()); + } + + /** + * Gets the ground overlay aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator The ground overlay aggregator. + */ + public function getGroundOverlayAggregator() + { + return $this->groundOverlayAggregator; + } + + /** + * Sets the ground overlay aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator $groundOverlayAggregator The ground overlay aggregator. + */ + public function setGroundOverlayAggregator(GroundOverlayAggregator $groundOverlayAggregator) + { + $this->groundOverlayAggregator = $groundOverlayAggregator; + } + + /** + * Gets the rectangle aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator The rectangle aggregator. + */ + public function getRectangleAggregator() + { + return $this->rectangleAggregator; + } + + /** + * Sets the rectangle aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator $rectangleAggregator The rectangle aggregator. + */ + public function setRectangleAggregator(RectangleAggregator $rectangleAggregator) + { + $this->rectangleAggregator = $rectangleAggregator; + } + + /** + * Aggregates the bounds. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $bounds The bounds. + * + * @return array The aggregated bounds. + */ + public function aggregate(Map $map, array $bounds = array()) + { + if ($map->getOverlays()->isAutoZoom()) { + $bounds = $this->aggregateValue($map->getBound(), $bounds); + } + + $bounds = $this->aggregateGroundOverlays($map, $bounds); + $bounds = $this->aggregateRectangles($map, $bounds); + + return $bounds; + } + + /** + * Aggregates the ground overlays bounds. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $bounds The bounds. + * + * @return array The aggregated bounds. + */ + public function aggregateGroundOverlays(Map $map, array $bounds = array()) + { + foreach ($this->groundOverlayAggregator->aggregate($map) as $groundOverlay) { + $bounds = $this->aggregateValue($groundOverlay->getBound(), $bounds); + } + + return $bounds; + } + + /** + * Aggregates the rectangles bounds. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $bounds The bounds. + * + * @return array The aggregated bounds. + */ + public function aggregateRectangles(Map $map, array $bounds = array()) + { + foreach ($this->rectangleAggregator->aggregate($map) as $rectangle) { + $bounds = $this->aggregateValue($rectangle->getBound(), $bounds); + } + + return $bounds; + } +} diff --git a/src/Helpers/Aggregators/Base/CoordinateAggregator.php b/src/Helpers/Aggregators/Base/CoordinateAggregator.php new file mode 100644 index 00000000..bb6d6715 --- /dev/null +++ b/src/Helpers/Aggregators/Base/CoordinateAggregator.php @@ -0,0 +1,327 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator; +use Ivory\GoogleMap\Map; + +/** + * Coordinate aggregator. + * + * @author GeLo + */ +class CoordinateAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator */ + protected $circleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator */ + protected $polygonAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator */ + protected $polylineAggregator; + + /** + * Creates a coordinate aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator|null $boundAggregator The bound aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator|null $circleAggregator The circle aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|null $infoWindowAggregator The info window aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator|null $polygonAggregator The polygon aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator|null $polylineAggregator The polyline aggregator. + */ + public function __construct( + BoundAggregator $boundAggregator = null, + CircleAggregator $circleAggregator = null, + InfoWindowAggregator $infoWindowAggregator = null, + MarkerAggregator $markerAggregator = null, + PolygonAggregator $polygonAggregator = null, + PolylineAggregator $polylineAggregator = null + ) { + $this->setBoundAggregator($boundAggregator ?: new BoundAggregator()); + $this->setCircleAggregator($circleAggregator ?: new CircleAggregator()); + $this->setInfoWindowAggregator($infoWindowAggregator ?: new InfoWindowAggregator()); + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + $this->setPolygonAggregator($polygonAggregator ?: new PolygonAggregator()); + $this->setPolylineAggregator($polylineAggregator ?: new PolylineAggregator()); + } + + /** + * Gets the bound aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator The bound aggregator. + */ + public function getBoundAggregator() + { + return $this->boundAggregator; + } + + /** + * Sets the bound aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator $boundAggregator The bound aggregator. + */ + public function setBoundAggregator(BoundAggregator $boundAggregator) + { + $this->boundAggregator = $boundAggregator; + } + + /** + * Gets the circle aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator The circle aggregator. + */ + public function getCircleAggregator() + { + return $this->circleAggregator; + } + + /** + * Sets the circle aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator $circleAggregator The circle aggregator. + */ + public function setCircleAggregator(CircleAggregator $circleAggregator) + { + $this->circleAggregator = $circleAggregator; + } + + /** + * Gets the info window aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator The info window aggregator. + */ + public function getInfoWindowAggregator() + { + return $this->infoWindowAggregator; + } + + /** + * Sets the info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + public function setInfoWindowAggregator(InfoWindowAggregator $infoWindowAggregator) + { + $this->infoWindowAggregator = $infoWindowAggregator; + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Gets the polygon aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator The polygon aggregator. + */ + public function getPolygonAggregator() + { + return $this->polygonAggregator; + } + + /** + * Sets the polygon aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator $polygonAggregator The polygon aggregator. + */ + public function setPolygonAggregator(PolygonAggregator $polygonAggregator) + { + $this->polygonAggregator = $polygonAggregator; + } + + /** + * Gets the polyline aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator The polyline aggregator. + */ + public function getPolylineAggregator() + { + return $this->polylineAggregator; + } + + /** + * Sets the polyline aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator $polylineAggregator The polyline aggregator. + */ + public function setPolylineAggregator(PolylineAggregator $polylineAggregator) + { + $this->polylineAggregator = $polylineAggregator; + } + + /** + * Aggregates the coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregate(Map $map, array $coordinates = array()) + { + if (!$map->getOverlays()->isAutoZoom()) { + $coordinates = $this->aggregateValue($map->getCenter(), $coordinates); + } + + $coordinates = $this->aggregateBounds($map, $coordinates); + $coordinates = $this->aggregateCircles($map, $coordinates); + $coordinates = $this->aggregateInfoWindows($map, $coordinates); + $coordinates = $this->aggregateMarkers($map, $coordinates); + $coordinates = $this->aggregatePolygons($map, $coordinates); + $coordinates = $this->aggregatePolylines($map, $coordinates); + + return $coordinates; + } + + /** + * Aggregates the bounds coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregateBounds(Map $map, array $coordinates = array()) + { + foreach ($this->boundAggregator->aggregate($map) as $bound) { + if ($bound->hasCoordinates()) { + $coordinates = $this->aggregateValue($bound->getSouthWest(), $coordinates); + $coordinates = $this->aggregateValue($bound->getNorthEast(), $coordinates); + } + } + + return $coordinates; + } + + /** + * Aggregates the cirlces coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregateCircles(Map $map, array $coordinates = array()) + { + foreach ($this->circleAggregator->aggregate($map) as $circle) { + $coordinates = $this->aggregateValue($circle->getCenter(), $coordinates); + } + + return $coordinates; + } + + /** + * Aggregates the info windows coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregateInfoWindows(Map $map, array $coordinates = array()) + { + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->hasPosition()) { + $coordinates = $this->aggregateValue($infoWindow->getPosition(), $coordinates); + } + } + + return $coordinates; + } + + /** + * Aggregates the markers coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregateMarkers(Map $map, array $coordinates = array()) + { + foreach ($this->markerAggregator->aggregate($map) as $marker) { + $coordinates = $this->aggregateValue($marker->getPosition(), $coordinates); + } + + return $coordinates; + } + + /** + * Aggregates the polygons coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregatePolygons(Map $map, array $coordinates = array()) + { + foreach ($this->polygonAggregator->aggregate($map) as $polygon) { + foreach ($polygon->getCoordinates() as $coordinate) { + $coordinates = $this->aggregateValue($coordinate, $coordinates); + } + } + + return $coordinates; + } + + /** + * Aggregates the polylines coordinates. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregatePolylines(Map $map, array $coordinates = array()) + { + foreach ($this->polylineAggregator->aggregate($map) as $polyline) { + foreach ($polyline->getCoordinates() as $coordinate) { + $coordinates = $this->aggregateValue($coordinate, $coordinates); + } + } + + return $coordinates; + } +} diff --git a/src/Helpers/Aggregators/Base/PointAggregator.php b/src/Helpers/Aggregators/Base/PointAggregator.php new file mode 100644 index 00000000..f1e7b11f --- /dev/null +++ b/src/Helpers/Aggregators/Base/PointAggregator.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\Icon; + +/** + * Point aggregator. + * + * @author GeLo + */ +class PointAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** + * Creates a point aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + */ + public function __construct(MarkerAggregator $markerAggregator = null) + { + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Aggregates the points of a map. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $points The points. + * + * @return array The aggregated points. + */ + public function aggregate(Map $map, array $points = array()) + { + return $this->aggregateMarkers($map, $points); + } + + /** + * Aggregates the markers points. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $points The points. + * + * @return array The aggregated points. + */ + public function aggregateMarkers(Map $map, array $points = array()) + { + foreach ($this->markerAggregator->aggregate($map) as $marker) { + if ($marker->hasIcon()) { + $points = $this->aggregateIcon($marker->getIcon(), $points); + } + + if ($marker->hasShadow()) { + $points = $this->aggregateIcon($marker->getShadow(), $points); + } + } + + return $points; + } + + /** + * Aggregates the icons points. + * + * @param \Ivory\GoogleMap\Overlays\Icon $icon The icon. + * @param array $points The points. + * + * @return array The aggregated points. + */ + protected function aggregateIcon(Icon $icon, array $points = array()) + { + if ($icon->hasAnchor()) { + $points = $this->aggregateValue($icon->getAnchor(), $points); + } + + if ($icon->hasOrigin()) { + $points = $this->aggregateValue($icon->getOrigin(), $points); + } + + return $points; + } +} diff --git a/src/Helpers/Aggregators/Base/SizeAggregator.php b/src/Helpers/Aggregators/Base/SizeAggregator.php new file mode 100644 index 00000000..0a49b334 --- /dev/null +++ b/src/Helpers/Aggregators/Base/SizeAggregator.php @@ -0,0 +1,143 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator; +use Ivory\GoogleMap\Map; + +/** + * Size aggregator. + * + * @author GeLo + */ +class SizeAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator */ + protected $iconAggregator; + + /** + * Creates a size aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|null $infoWindowAggregator The info window aggregator. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator|null $iconAggregator The icon aggregator. + */ + public function __construct( + InfoWindowAggregator $infoWindowAggregator = null, + IconAggregator $iconAggregator = null + ) { + $this->setInfoWindowAggregator($infoWindowAggregator ?: new InfoWindowAggregator()); + $this->setIconAggregator($iconAggregator ?: new IconAggregator()); + } + + /** + * Gets the info window aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator The info window aggregator. + */ + public function getInfoWindowAggregator() + { + return $this->infoWindowAggregator; + } + + /** + * Sets the info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + public function setInfoWindowAggregator(InfoWindowAggregator $infoWindowAggregator) + { + $this->infoWindowAggregator = $infoWindowAggregator; + } + + /** + * Gets the icon aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator The icon aggregator. + */ + public function getIconAggregator() + { + return $this->iconAggregator; + } + + /** + * Sets the icon aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator $iconAggregator The icon aggregator. + */ + public function setIconAggregator(IconAggregator $iconAggregator) + { + $this->iconAggregator = $iconAggregator; + } + + /** + * Aggregates the sizes of a map. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $sizes The sizes. + * + * @return array The aggregated sizes. + */ + public function aggregate(Map $map, array $sizes = array()) + { + $sizes = $this->aggregateInfoWindows($map, $sizes); + $sizes = $this->aggregateIcons($map, $sizes); + + return $sizes; + } + + /** + * Aggregates the info windows sizes. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $sizes The sizes. + * + * @return array The aggregated sizes. + */ + public function aggregateInfoWindows(Map $map, array $sizes = array()) + { + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->hasPixelOffset()) { + $sizes = $this->aggregateValue($infoWindow->getPixelOffset(), $sizes); + } + } + + return $sizes; + } + + /** + * Aggregates the icons sizes. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $sizes The sizes. + * + * @return array The aggregated sizes. + */ + public function aggregateIcons(Map $map, array $sizes = array()) + { + foreach ($this->iconAggregator->aggregate($map) as $icon) { + if ($icon->hasSize()) { + $sizes = $this->aggregateValue($icon->getSize(), $sizes); + } + + if ($icon->hasScaledSize()) { + $sizes = $this->aggregateValue($icon->getScaledSize(), $sizes); + } + } + + return $sizes; + } +} diff --git a/src/Helpers/Aggregators/Events/DomEventAggregator.php b/src/Helpers/Aggregators/Events/DomEventAggregator.php new file mode 100644 index 00000000..3c44256b --- /dev/null +++ b/src/Helpers/Aggregators/Events/DomEventAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Dom event aggregator. + * + * @author GeLo + */ +class DomEventAggregator extends AbstractAggregator +{ + /** + * Aggregates the dom events. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $domEvents The dom events. + * + * @return array The aggregated dom events. + */ + public function aggregate(Map $map, array $domEvents = array()) + { + return $this->aggregateValues($map->getEvents()->getDomEvents(), $domEvents); + } +} diff --git a/src/Helpers/Aggregators/Events/DomEventOnceAggregator.php b/src/Helpers/Aggregators/Events/DomEventOnceAggregator.php new file mode 100644 index 00000000..6bb032ad --- /dev/null +++ b/src/Helpers/Aggregators/Events/DomEventOnceAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Dom event once aggregator. + * + * @author GeLo + */ +class DomEventOnceAggregator extends AbstractAggregator +{ + /** + * Aggregates the dom events once. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $domEventsOnce The dom events once. + * + * @return array The aggregated dom events once. + */ + public function aggregate(Map $map, array $domEventsOnce = array()) + { + return $this->aggregateValues($map->getEvents()->getDomEventsOnce(), $domEventsOnce); + } +} diff --git a/src/Helpers/Aggregators/Events/EventAggregator.php b/src/Helpers/Aggregators/Events/EventAggregator.php new file mode 100644 index 00000000..c4b12eda --- /dev/null +++ b/src/Helpers/Aggregators/Events/EventAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Event aggregator. + * + * @author GeLo + */ +class EventAggregator extends AbstractAggregator +{ + /** + * Aggregates the events. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $events The events. + * + * @return array The aggregated events. + */ + public function aggregate(Map $map, array $events = array()) + { + return $this->aggregateValues($map->getEvents()->getEvents(), $events); + } +} diff --git a/src/Helpers/Aggregators/Events/EventOnceAggregator.php b/src/Helpers/Aggregators/Events/EventOnceAggregator.php new file mode 100644 index 00000000..e2dfd373 --- /dev/null +++ b/src/Helpers/Aggregators/Events/EventOnceAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Event once aggregator. + * + * @author GeLo + */ +class EventOnceAggregator extends AbstractAggregator +{ + /** + * Aggregates the events once. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $eventsOnce The events once. + * + * @return array The aggregated events once. + */ + public function aggregate(Map $map, array $eventsOnce = array()) + { + return $this->aggregateValues($map->getEvents()->getEventsOnce(), $eventsOnce); + } +} diff --git a/src/Helpers/Aggregators/Layers/KmlLayerAggregator.php b/src/Helpers/Aggregators/Layers/KmlLayerAggregator.php new file mode 100644 index 00000000..26ca279f --- /dev/null +++ b/src/Helpers/Aggregators/Layers/KmlLayerAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Layers; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Kml layer aggregator. + * + * @author GeLo + */ +class KmlLayerAggregator extends AbstractAggregator +{ + /** + * Aggregates the kml layers. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $kmlLayers The kml layers. + * + * @return array The aggregated kml layers. + */ + public function aggregate(Map $map, array $kmlLayers = array()) + { + return $this->aggregateValues($map->getLayers()->getKmlLayers(), $kmlLayers); + } +} diff --git a/src/Helpers/Aggregators/Overlays/CircleAggregator.php b/src/Helpers/Aggregators/Overlays/CircleAggregator.php new file mode 100644 index 00000000..a3992eb4 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/CircleAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Circle aggregator. + * + * @author GeLo + */ +class CircleAggregator extends AbstractAggregator +{ + /** + * Aggregates the circles. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $circles The circles. + * + * @return array The aggregated circles. + */ + public function aggregate(Map $map, array $circles = array()) + { + return $this->aggregateValues($map->getOverlays()->getCircles(), $circles); + } +} diff --git a/src/Helpers/Aggregators/Overlays/EncodedPolylineAggregator.php b/src/Helpers/Aggregators/Overlays/EncodedPolylineAggregator.php new file mode 100644 index 00000000..fd419365 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/EncodedPolylineAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Encoded polyline aggregator. + * + * @author GeLo + */ +class EncodedPolylineAggregator extends AbstractAggregator +{ + /** + * Aggregates the encoded polylines. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $encodedPolylines The encoded polylines. + * + * @return array The aggregated encoded polylines. + */ + public function aggregate(Map $map, array $encodedPolylines = array()) + { + return $this->aggregateValues($map->getOverlays()->getEncodedPolylines(), $encodedPolylines); + } +} diff --git a/src/Helpers/Aggregators/Overlays/ExtendableAggregator.php b/src/Helpers/Aggregators/Overlays/ExtendableAggregator.php new file mode 100644 index 00000000..bd7b1901 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/ExtendableAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Extendable aggregator. + * + * @author GeLo + */ +class ExtendableAggregator extends AbstractAggregator +{ + /** + * Aggregates the extends. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $extends The extends. + * + * @return array The aggregated extends. + */ + public function aggregate(Map $map, array $extends = array()) + { + return $this->aggregateValues($map->getOverlays()->getExtends(), $extends); + } +} diff --git a/src/Helpers/Aggregators/Overlays/GroundOverlayAggregator.php b/src/Helpers/Aggregators/Overlays/GroundOverlayAggregator.php new file mode 100644 index 00000000..c4097971 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/GroundOverlayAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Ground overlay aggregator. + * + * @author GeLo + */ +class GroundOverlayAggregator extends AbstractAggregator +{ + /** + * Aggregates the ground overlays. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $groundOverlays The ground overlays. + * + * @return array The aggregated ground overlays. + */ + public function aggregate(Map $map, array $groundOverlays = array()) + { + return $this->aggregateValues($map->getOverlays()->getGroundOverlays(), $groundOverlays); + } +} diff --git a/src/Helpers/Aggregators/Overlays/IconAggregator.php b/src/Helpers/Aggregators/Overlays/IconAggregator.php new file mode 100644 index 00000000..ac60d029 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/IconAggregator.php @@ -0,0 +1,92 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Icon aggregator. + * + * @author GeLo + */ +class IconAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** + * Creates an icon aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + */ + public function __construct(MarkerAggregator $markerAggregator = null) + { + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Aggregates the icons. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $icons The icons. + * + * @return array The aggregated icones. + */ + public function aggregate(Map $map, array $icons = array()) + { + return $this->aggregateMarkers($map, $icons); + } + + /** + * Aggregates the markers icons. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $icons The icones. + * + * @return array The aggregated icons. + */ + public function aggregateMarkers(Map $map, array $icons = array()) + { + foreach ($this->markerAggregator->aggregate($map) as $marker) { + if ($marker->hasIcon()) { + $icons = $this->aggregateValue($marker->getIcon(), $icons); + } + + if ($marker->hasShadow()) { + $icons = $this->aggregateValue($marker->getShadow(), $icons); + } + } + + return $icons; + } +} diff --git a/src/Helpers/Aggregators/Overlays/InfoWindowAggregator.php b/src/Helpers/Aggregators/Overlays/InfoWindowAggregator.php new file mode 100644 index 00000000..83bdf372 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/InfoWindowAggregator.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Info window aggregator. + * + * @author GeLo + */ +class InfoWindowAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** + * Creates an info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + */ + public function __construct(MarkerAggregator $markerAggregator = null) + { + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Aggregates the info windows. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $infoWindows The info windows. + * + * @return array The aggregated info windows. + */ + public function aggregate(Map $map, array $infoWindows = array()) + { + $infoWindows = $this->aggregateInfoWindows($map, $infoWindows); + $infoWindows = $this->aggregateMarkers($map, $infoWindows); + + return $infoWindows; + } + + /** + * Aggregates the overlays info windows. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $infoWindows The info windows. + * + * @return array The aggregated info windows. + */ + public function aggregateInfoWindows(Map $map, array $infoWindows = array()) + { + return $this->aggregateValues($map->getOverlays()->getInfoWindows(), $infoWindows); + } + + /** + * Aggregates the markers info windows. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $infoWindows The info windows. + * + * @return array The aggregated info windows. + */ + public function aggregateMarkers(Map $map, array $infoWindows = array()) + { + foreach ($this->markerAggregator->aggregate($map) as $marker) { + if ($marker->hasInfoWindow()) { + $infoWindows = $this->aggregateValue($marker->getInfoWindow(), $infoWindows); + } + } + + return $infoWindows; + } +} diff --git a/src/Helpers/Aggregators/Overlays/MarkerAggregator.php b/src/Helpers/Aggregators/Overlays/MarkerAggregator.php new file mode 100644 index 00000000..12073b3f --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/MarkerAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Marker aggregator. + * + * @author GeLo + */ +class MarkerAggregator extends AbstractAggregator +{ + /** + * Aggregates the markers. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $markers The markers. + * + * @return array The aggregated markers. + */ + public function aggregate(Map $map, array $markers = array()) + { + return $this->aggregateValues($map->getOverlays()->getMarkers(), $markers); + } +} diff --git a/src/Helpers/Aggregators/Overlays/MarkerShapeAggregator.php b/src/Helpers/Aggregators/Overlays/MarkerShapeAggregator.php new file mode 100644 index 00000000..3cb034c9 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/MarkerShapeAggregator.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Marker shape aggregator. + * + * @author GeLo + */ +class MarkerShapeAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** + * Creates a map marker shape aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + */ + public function __construct(MarkerAggregator $markerAggregator = null) + { + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Aggregates the marker shapes. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $markerShapes The marker shapes. + * + * @return array The aggregated marker shapes. + */ + public function aggregate(Map $map, array $markerShapes = array()) + { + return $this->aggregateMarkers($map, $markerShapes); + } + + /** + * Aggregates the markers marker shapes. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $markerShapes The marker shapes. + * + * @return array The aggregated markers marker shapes. + */ + public function aggregateMarkers(Map $map, array $markerShapes = array()) + { + foreach ($this->markerAggregator->aggregate($map) as $marker) { + if ($marker->hasShape()) { + $markerShapes = $this->aggregateValue($marker->getShape(), $markerShapes); + } + } + + return $markerShapes; + } +} diff --git a/src/Helpers/Aggregators/Overlays/PolygonAggregator.php b/src/Helpers/Aggregators/Overlays/PolygonAggregator.php new file mode 100644 index 00000000..5645376e --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/PolygonAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Polygon aggregator. + * + * @author GeLo + */ +class PolygonAggregator extends AbstractAggregator +{ + /** + * Aggregates the polygons. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $polygons The polygons. + * + * @return array The aggregated polygons. + */ + public function aggregate(Map $map, array $polygons = array()) + { + return $this->aggregateValues($map->getOverlays()->getPolygons(), $polygons); + } +} diff --git a/src/Helpers/Aggregators/Overlays/PolylineAggregator.php b/src/Helpers/Aggregators/Overlays/PolylineAggregator.php new file mode 100644 index 00000000..5ac40903 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/PolylineAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Polyline aggregator. + * + * @author GeLo + */ +class PolylineAggregator extends AbstractAggregator +{ + /** + * Aggregates the polylines. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $polylines The polylines. + * + * @return array The aggregated polylines. + */ + public function aggregate(Map $map, array $polylines = array()) + { + return $this->aggregateValues($map->getOverlays()->getPolylines(), $polylines); + } +} diff --git a/src/Helpers/Aggregators/Overlays/RectangleAggregator.php b/src/Helpers/Aggregators/Overlays/RectangleAggregator.php new file mode 100644 index 00000000..a9d54ea1 --- /dev/null +++ b/src/Helpers/Aggregators/Overlays/RectangleAggregator.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Map; + +/** + * Rectangle agregator. + * + * @author GeLo + */ +class RectangleAggregator extends AbstractAggregator +{ + /** + * Aggregates the rectangles. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param array $rectangles The rectangles. + * + * @return array The aggregated rectangles. + */ + public function aggregate(Map $map, array $rectangles = array()) + { + return $this->aggregateValues($map->getOverlays()->getRectangles(), $rectangles); + } +} diff --git a/src/Helpers/Aggregators/Places/AutocompleteBoundAggregator.php b/src/Helpers/Aggregators/Places/AutocompleteBoundAggregator.php new file mode 100644 index 00000000..e4bc64b7 --- /dev/null +++ b/src/Helpers/Aggregators/Places/AutocompleteBoundAggregator.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Places; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Places\Autocomplete; + +/** + * Autocomplete bound aggregator. + * + * @author GeLo + */ +class AutocompleteBoundAggregator extends AbstractAggregator +{ + /** + * Aggregates the bounds. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * @param array $bounds The bounds. + * + * @return array The aggregated bounds. + */ + public function aggregate(Autocomplete $autocomplete, array $bounds = array()) + { + if ($autocomplete->hasBound()) { + return $this->aggregateValue($autocomplete->getBound(), $bounds); + } + + return $bounds; + } +} diff --git a/src/Helpers/Aggregators/Places/AutocompleteCoordinateAggregator.php b/src/Helpers/Aggregators/Places/AutocompleteCoordinateAggregator.php new file mode 100644 index 00000000..e699c98d --- /dev/null +++ b/src/Helpers/Aggregators/Places/AutocompleteCoordinateAggregator.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Aggregators\Places; + +use Ivory\GoogleMap\Helpers\Aggregators\AbstractAggregator; +use Ivory\GoogleMap\Places\Autocomplete; + +/** + * Autocomplete coordinate aggregator. + * + * @author GeLo + */ +class AutocompleteCoordinateAggregator extends AbstractAggregator +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator */ + protected $boundAggregator; + + /** + * Creates an autocomplete coordinate aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator $boundAggregator The bound aggregator. + */ + public function __construct(AutocompleteBoundAggregator $boundAggregator = null) + { + $this->setBoundAggregator($boundAggregator ?: new AutocompleteBoundAggregator()); + } + + /** + * Gets the bound aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator The bound aggregator. + */ + public function getBoundAggregator() + { + return $this->boundAggregator; + } + + /** + * Sets the bound aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator $boundAggregator The bound aggregator. + */ + public function setBoundAggregator(AutocompleteBoundAggregator $boundAggregator) + { + $this->boundAggregator = $boundAggregator; + } + + /** + * Aggregates the coordinates. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * @param array $coordinates The coordinates. + * + * @return array The aggregated coordinates. + */ + public function aggregate(Autocomplete $autocomplete, array $coordinates = array()) + { + foreach ($this->boundAggregator->aggregate($autocomplete) as $bound) { + if ($bound->hasSouthWest()) { + $coordinates = $this->aggregateValue($bound->getSouthWest(), $coordinates); + } + + if ($bound->hasNorthEast()) { + $coordinates = $this->aggregateValue($bound->getNorthEast(), $coordinates); + } + } + + return $coordinates; + } +} diff --git a/src/Helpers/ApiEvent.php b/src/Helpers/ApiEvent.php new file mode 100644 index 00000000..28fae09e --- /dev/null +++ b/src/Helpers/ApiEvent.php @@ -0,0 +1,396 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +/** + * Api event. + * + * @author GeLo + */ +class ApiEvent extends AbstractEvent +{ + const MAP = 'Ivory\GoogleMap\Map'; + const PLACES_AUTOCOMPLETE = 'Ivory\GoogleMap\Places\Autocomplete'; + + /** @var array */ + protected $items; + + /** @var string */ + protected $language = 'en'; + + /** @var array */ + protected $sources = array(); + + /** @var array */ + protected $libraries = array(); + + /** @var array */ + protected $callbacks = array(); + + /** + * Creates an api event. + * + * @param array $items The items. + */ + public function __construct(array $items) + { + $this->items = $items; + } + + /** + * Checks if there are items. + * + * @param string|null $class The item class. + * + * @return boolean TRUE if there are items else FALSE. + */ + public function hasItems($class = null) + { + $items = $this->getItems($class); + + return !empty($items); + } + + /** + * Gets the items. + * + * @param string|null $class The items class. + * + * @return array The items. + */ + public function getItems($class = null) + { + if ($class === null) { + return $this->items; + } + + $items = array(); + foreach ($this->items as $item) { + if ($item instanceof $class) { + $items[] = $item; + } + } + + return $items; + } + + /** + * Gets the language. + * + * @return string The language. + */ + public function getLanguage() + { + return $this->language; + } + + /** + * Sets the language. + * + * @param string $language The language. + */ + public function setLanguage($language) + { + $this->language = $language; + } + + /** + * Resets the sources. + */ + public function resetSources() + { + $this->sources = array(); + } + + /** + * Checks if there are sources. + * + * @return boolean TRUE if there are sources else FALSE. + */ + public function hasSources() + { + return !empty($this->sources); + } + + /** + * Gets the sources. + * + * @return array The sources. + */ + public function getSources() + { + return $this->sources; + } + + /** + * Sets the sources. + * + * @param array $sources The sources. + */ + public function setSources(array $sources) + { + $this->resetSources(); + $this->addSources($sources); + } + + /** + * Adds the sources. + * + * @param array $sources The sources. + */ + public function addSources(array $sources) + { + foreach ($sources as $source) { + $this->addSource($source); + } + } + + /** + * Removes the sources. + * + * @param array $sources The sources. + */ + public function removeSources(array $sources) + { + foreach ($sources as $source) { + $this->removeSource($source); + } + } + + /** + * Check if there is a source. + * + * @param string $source The source. + * + * @return boolean TRUE if there is the source else FALSE. + */ + public function hasSource($source) + { + return in_array($source, $this->sources, true); + } + + /** + * Adds a source. + * + * @param string $source The source. + */ + public function addSource($source) + { + if (!in_array($source, $this->sources, true)) { + $this->sources[] = $source; + } + } + + /** + * Removes a source. + * + * @param string $source The source. + */ + public function removeSource($source) + { + unset($this->sources[array_search($source, $this->sources, true)]); + } + + /** + * Resets the libraries. + */ + public function resetLibraries() + { + $this->libraries = array(); + } + + /** + * Checks if there are libraries. + * + * @return boolean TRUE if there are libraries else FALSE. + */ + public function hasLibraries() + { + return !empty($this->libraries); + } + + /** + * Gets the libraries. + * + * @return array The libraries. + */ + public function getLibraries() + { + return $this->libraries; + } + + /** + * Sets the libraries. + * + * @param array $libraries The libraries. + */ + public function setLibraries(array $libraries) + { + $this->resetLibraries(); + $this->addLibraries($libraries); + } + + /** + * Adds the libraries. + * + * @param array $libraries The libraries. + */ + public function addLibraries(array $libraries) + { + foreach ($libraries as $library) { + $this->addLibrary($library); + } + } + + /** + * Removes the libraries. + * + * @param array $libraries The libraries. + */ + public function removeLibraries(array $libraries) + { + foreach ($libraries as $library) { + $this->removeLibrary($library); + } + } + + /** + * Checks if there is a library. + * + * @param string $library The library. + * + * @return boolean TRUE if there is the library else FALSE. + */ + public function hasLibrary($library) + { + return in_array($library, $this->libraries, true); + } + + /** + * Adds a library. + * + * @param string $library The library. + */ + public function addLibrary($library) + { + if (!in_array($library, $this->libraries, true)) { + $this->libraries[] = $library; + } + } + + /** + * Removes a library. + * + * @param string $library The library. + */ + public function removeLibrary($library) + { + unset($this->libraries[array_search($library, $this->libraries, true)]); + } + + /** + * Resets the callbacks. + */ + public function resetCallbacks() + { + $this->callbacks = array(); + } + + /** + * Checks if there are callbacks. + * + * @return boolean TRUE if there are callbacks else FALSE. + */ + public function hasCallbacks() + { + return !empty($this->callbacks); + } + + /** + * Gets the callbacks. + * + * @return array The callbacks. + */ + public function getCallbacks() + { + return $this->callbacks; + } + + /** + * Sets the callbacks. + * + * @param array $callbacks The callbacks. + */ + public function setCallbacks(array $callbacks) + { + $this->resetCallbacks(); + $this->addCallbacks($callbacks); + } + + /** + * Adds the callbacks. + * + * @param array $callbacks The callbacks. + */ + public function addCallbacks(array $callbacks) + { + foreach ($callbacks as $callback) { + $this->addCallback($callback); + } + } + + /** + * Removes the callbacks. + * + * @param array $callbacks The callbacks. + */ + public function removeCallbacks(array $callbacks) + { + foreach ($callbacks as $callback) { + $this->removeCallback($callback); + } + } + + /** + * Checks if there is a callback. + * + * @param string $callback The callback. + * + * @return boolean TRUE if there is the callback else FALSE. + */ + public function hasCallback($callback) + { + return in_array($callback, $this->callbacks, true); + } + + /** + * Adds a callback. + * + * @param string $callback The callback. + */ + public function addCallback($callback) + { + if (!in_array($callback, $this->callbacks, true)) { + $this->callbacks[] = $callback; + } + } + + /** + * Removes a callback. + * + * @param string $callback The callback. + */ + public function removeCallback($callback) + { + unset($this->callbacks[array_search($callback, $this->callbacks, true)]); + } +} diff --git a/src/Helpers/ApiEvents.php b/src/Helpers/ApiEvents.php new file mode 100644 index 00000000..3a1be0ec --- /dev/null +++ b/src/Helpers/ApiEvents.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Api events. + * + * @author GeLo + */ +class ApiEvents extends AbstractUninstantiableAsset +{ + const JAVASCRIPT = 'ivory.google_map.api.javascript'; + const JAVASCRIPT_MAP = 'ivory.google_map.api.javascript.map'; + const JAVASCRIPT_MAP_ENCODED_POLYLINE = 'ivory.google_map.api.javascript.map.encoded_polyline'; + const JAVASCRIPT_MAP_MARKER_CLUSTER = 'ivory.google_map.api.javascript.map.marker_cluster'; + const JAVASCRIPT_MAP_INFO_WINDOW = 'ivory.google_map.api.javascript.map.info_window'; + const JAVASCRIPT_PLACES_AUTOCOMPLETE = 'ivory.google_map.api.javascript.places.autocomplete'; +} diff --git a/src/Helpers/ApiHelper.php b/src/Helpers/ApiHelper.php new file mode 100644 index 00000000..21c08935 --- /dev/null +++ b/src/Helpers/ApiHelper.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; + +/** + * Api helper. + * + * @author GeLo + */ +class ApiHelper extends AbstractHelper +{ + /** + * Renders the api. + * + * @param array $items The item(s). + * + * @return string The rendered api. + */ + public function render(array $items) + { + $this->eventDispatcher->dispatch(ApiEvents::JAVASCRIPT, $apiEvent = new ApiEvent($items)); + + return $apiEvent->getCode(); + } +} diff --git a/src/Helpers/Factories/AbstractHelperFactory.php b/src/Helpers/Factories/AbstractHelperFactory.php new file mode 100644 index 00000000..907c22e0 --- /dev/null +++ b/src/Helpers/Factories/AbstractHelperFactory.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Factories; + +/** + * Abstract helper factory. + * + * @author GeLo + */ +abstract class AbstractHelperFactory implements HelperFactoryInterface +{ + /** @var boolean */ + protected $debug; + + /** @var integer */ + protected $indentation; + + /** + * Creates an helper factory. + * + * @param boolean $debug The debug. + * @param integer $indentation The indentation. + */ + public function __construct($debug = false, $indentation = 4) + { + $this->setDebug($debug); + $this->setIndentation($indentation); + } + + /** + * Checks if it is debug. + * + * @return boolean TRUE if it is debug else FALSE. + */ + public function isDebug() + { + return $this->debug; + } + + /** + * Sets if it is debug. + * + * @param boolean $debug TRUE if it is debug else FALSE. + */ + public function setDebug($debug) + { + $this->debug = $debug; + } + + /** + * Gets the indentation. + * + * @return integer The indentation. + */ + public function getIndentation() + { + return $this->indentation; + } + + /** + * Sets the indentation. + * + * @param integer $indentation The indentation. + */ + public function setIndentation($indentation) + { + $this->indentation = $indentation; + } +} diff --git a/src/Helpers/Factories/DependencyInjection/IvoryGoogleMapExtension.php b/src/Helpers/Factories/DependencyInjection/IvoryGoogleMapExtension.php new file mode 100644 index 00000000..585e5c72 --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/IvoryGoogleMapExtension.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Factories\DependencyInjection; + +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; +use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; + +/** + * Ivory google map extension. + * + * @author GeLo + */ +class IvoryGoogleMapExtension extends Extension +{ + /** + * {@inheritdoc} + */ + public function load(array $config, ContainerBuilder $container) + { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/Resources')); + foreach (array('aggregators', 'renderers', 'subscribers', 'event_dispatcher', 'helpers') as $resource) { + $loader->load($resource.'.xml'); + } + } +} diff --git a/src/Helpers/Factories/DependencyInjection/Resources/aggregators.xml b/src/Helpers/Factories/DependencyInjection/Resources/aggregators.xml new file mode 100644 index 00000000..60f5af7e --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/Resources/aggregators.xml @@ -0,0 +1,181 @@ + + + + + + Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator + Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator + Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator + Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator + + + Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator + Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator + Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator + Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator + + + Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator + + + Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator + Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator + + + Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator + Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Helpers/Factories/DependencyInjection/Resources/event_dispatcher.xml b/src/Helpers/Factories/DependencyInjection/Resources/event_dispatcher.xml new file mode 100644 index 00000000..39f0a287 --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/Resources/event_dispatcher.xml @@ -0,0 +1,21 @@ + + + + + Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher + + + + + + + + diff --git a/src/Helpers/Factories/DependencyInjection/Resources/helpers.xml b/src/Helpers/Factories/DependencyInjection/Resources/helpers.xml new file mode 100644 index 00000000..b1c31467 --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/Resources/helpers.xml @@ -0,0 +1,45 @@ + + + + + Ivory\GoogleMap\Helpers\AbstractHelper + Ivory\GoogleMap\Helpers\ApiHelper + Ivory\GoogleMap\Helpers\MapHelper + Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper + + + + + + + + + + + + + + diff --git a/src/Helpers/Factories/DependencyInjection/Resources/renderers.xml b/src/Helpers/Factories/DependencyInjection/Resources/renderers.xml new file mode 100644 index 00000000..3ec0e6b8 --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/Resources/renderers.xml @@ -0,0 +1,387 @@ + + + + + + Ivory\JsonBuilder\JsonBuilder + Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer + Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer + Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer + Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer + Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer + Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer + Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer + Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer + Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer + + + Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer + Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer + + + Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer + + + Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer + Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer + Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer + Ivory\GoogleMap\Helpers\Renderers\MapRenderer + Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Helpers/Factories/DependencyInjection/Resources/subscribers.xml b/src/Helpers/Factories/DependencyInjection/Resources/subscribers.xml new file mode 100644 index 00000000..d5ecb5c1 --- /dev/null +++ b/src/Helpers/Factories/DependencyInjection/Resources/subscribers.xml @@ -0,0 +1,518 @@ + + + + + + Ivory\GoogleMap\Helpers\Subscribers\Formatter + Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\Base\BaseSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Base\BoundSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Base\CoordinateSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Base\PointSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Base\SizeSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventOnceSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Events\EventOnceSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Events\EventSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Events\EventsSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\Layers\LayersSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Layers\KmlLayerSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\Overlays\CircleSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\EncodedPolylineSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\ExtendableSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\GroundOverlaySubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\IconSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowCloseSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowOpenSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerClusterSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerOpenEventSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerShapeSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\OverlaysSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolygonSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolylineSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Overlays\RectangleSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBaseSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBoundSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteContainerSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteCoordinateSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteHtmlSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteInitSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteJavascriptSubscriber + Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\ApiJavascriptSubscriber + + + Ivory\GoogleMap\Helpers\Subscribers\MapBoundSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapCenterSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapContainerSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapFinishSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapHtmlSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapInitSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapJavascriptSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapStylesheetSubscriber + Ivory\GoogleMap\Helpers\Subscribers\MapSubscriber + + + + + + %ivory.google_map.debug% + %ivory.google_map.indentation% + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Helpers/Factories/HelperFactory.php b/src/Helpers/Factories/HelperFactory.php new file mode 100644 index 00000000..b48915cf --- /dev/null +++ b/src/Helpers/Factories/HelperFactory.php @@ -0,0 +1,1350 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Factories; + +use Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator; +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator; +use Ivory\GoogleMap\Helpers\ApiHelper; +use Ivory\GoogleMap\Helpers\MapHelper; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer; +use Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\ApiJavascriptSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Base\BaseSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Base\BoundSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Base\CoordinateSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Base\PointSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Base\SizeSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventOnceSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventOnceSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventsSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; +use Ivory\GoogleMap\Helpers\Subscribers\Layers\KmlLayerSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Layers\LayersSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapBoundSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapCenterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapContainerSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapFinishSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapHtmlSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapInitSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapJavascriptSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapStylesheetSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\MapSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\CircleSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\EncodedPolylineSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\ExtendableSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\GroundOverlaySubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\IconSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowCloseSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowOpenSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerClusterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerOpenEventSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerShapeSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\OverlaysSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolygonSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolylineSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\RectangleSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBaseSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBoundSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteContainerSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteCoordinateSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteHtmlSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteInitSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteJavascriptSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteSubscriber; +use Ivory\JsonBuilder\JsonBuilder; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Helper factory. + * + * @author GeLo + */ +class HelperFactory extends AbstractHelperFactory +{ + /** @var \Ivory\JsonBuilder\JsonBuilder */ + protected $jsonBuilder; + + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Formatter */ + protected $formatter; + + /** @var array */ + protected $aggregators = array(); + + /** @var array */ + protected $renderers = array(); + + /** @var array */ + protected $subscribers = array(); + + /** + * {@inheritdoc} + */ + public function __construct($debug = false, $indentation = 4) + { + $this->setJsonBuilder(new JsonBuilder()); + $this->setFormatter(new Formatter()); + + parent::__construct($debug, $indentation); + + $this->resetAggregators(); + $this->resetRenderers(); + $this->resetSubscribers(); + } + + /** + * {@inheritdoc} + */ + public function setDebug($debug) + { + $this->formatter->setDebug($debug); + parent::setDebug($debug); + } + + /** + * {@inheritdoc} + */ + public function setIndentation($indentation) + { + $this->formatter->setIndentation($indentation); + parent::setIndentation($indentation); + } + + /** + * Gets the json builder. + * + * @return \Ivory\JsonBuilder\JsonBuilder The json builder. + */ + public function getJsonBuilder() + { + return $this->jsonBuilder; + } + + /** + * Sets the json builder. + * + * @param \Ivory\JsonBuilder\JsonBuilder $jsonBuilder The json builder. + */ + public function setJsonBuilder(JsonBuilder $jsonBuilder) + { + $this->jsonBuilder = $jsonBuilder; + + foreach ($this->renderers as $renderer) { + if ($renderer instanceof AbstractJsonRenderer) { + $renderer->setJsonBuilder($jsonBuilder); + } + } + } + + /** + * Gets the formatter. + * + * @return \Ivory\GoogleMap\Helpers\Subscribers\Formatter The formatter. + */ + public function getFormatter() + { + return $this->formatter; + } + + /** + * Sets the formatter. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter $formatter The formatter. + */ + public function setFormatter(Formatter $formatter) + { + $this->formatter = $formatter; + + foreach ($this->subscribers as $subscriber) { + if ($subscriber instanceof AbstractFormatterSubscriber) { + $subscriber->setFormatter($formatter); + } + } + } + + /** + * Resets the aggregators. + */ + public function resetAggregators() + { + $this->aggregators = array(); + + $this->aggregators['autocomplete_bound'] = new AutocompleteBoundAggregator(); + $this->aggregators['autocomplete_coordinate'] = new AutocompleteCoordinateAggregator( + $this->aggregators['autocomplete_bound'] + ); + + $this->aggregators['marker'] = new MarkerAggregator(); + $this->aggregators['circle'] = new CircleAggregator(); + $this->aggregators['encoded_polyline'] = new EncodedPolylineAggregator(); + $this->aggregators['extendable'] = new ExtendableAggregator(); + $this->aggregators['ground_overlay'] = new GroundOverlayAggregator(); + $this->aggregators['icon'] = new IconAggregator($this->aggregators['marker']); + $this->aggregators['info_window'] = new InfoWindowAggregator($this->aggregators['marker']); + $this->aggregators['marker_shape'] = new MarkerShapeAggregator($this->aggregators['marker']); + $this->aggregators['polygon'] = new PolygonAggregator(); + $this->aggregators['polyline'] = new PolylineAggregator(); + $this->aggregators['rectangle'] = new RectangleAggregator(); + + $this->aggregators['kml_layer'] = new KmlLayerAggregator(); + + $this->aggregators['dom_event_once'] = new DomEventOnceAggregator(); + $this->aggregators['dom_event'] = new DomEventAggregator(); + $this->aggregators['event_once'] = new EventOnceAggregator(); + $this->aggregators['event'] = new EventAggregator(); + + $this->aggregators['bound'] = new BoundAggregator( + $this->aggregators['ground_overlay'], + $this->aggregators['rectangle'] + ); + + $this->aggregators['coordinate'] = new CoordinateAggregator( + $this->aggregators['bound'], + $this->aggregators['circle'], + $this->aggregators['info_window'], + $this->aggregators['marker'], + $this->aggregators['polygon'], + $this->aggregators['polyline'] + ); + + $this->aggregators['point'] = new PointAggregator($this->aggregators['marker']); + $this->aggregators['size'] = new SizeAggregator( + $this->aggregators['info_window'], + $this->aggregators['icon'] + ); + } + + /** + * Checks if there are aggregators. + * + * @return boolean TRUE if there are aggragtors else FALSE. + */ + public function hasAggregators() + { + return !empty($this->aggregators); + } + + /** + * Gets the aggregators. + * + * @return array The aggregators. + */ + public function getAggregators() + { + return $this->aggregators; + } + + /** + * Sets the aggregators. + * + * @param array $aggregators The aggregators. + */ + public function setAggregators(array $aggregators) + { + $this->resetAggregators(); + $this->addAggregators($aggregators); + } + + /** + * Adds the aggregators. + * + * @param array $aggregators The aggregators. + */ + public function addAggregators(array $aggregators) + { + foreach ($aggregators as $name => $aggregator) { + $this->setAggregator($name, $aggregator); + } + } + + /** + * Removes the aggregators. + * + * @param array $names The names. + */ + public function removeAggregators(array $names) + { + foreach ($names as $name) { + $this->removeAggregator($name); + } + } + + /** + * Checks if there is an aggregator. + * + * @param string $name The name. + * + * @return boolean TRUE if there is the aggregator else FALSE. + */ + public function hasAggregator($name) + { + return isset($this->aggregators[$name]); + } + + /** + * Gets an agregator. + * + * @param string $name The aggregator name. + * + * @return object|null The aggregator. + */ + public function getAggregator($name) + { + return $this->hasAggregator($name) ? $this->aggregators[$name] : null; + } + + /** + * Sets an aggregators. + * + * @param string $name The name. + * @param object $aggregator The aggregator. + */ + public function setAggregator($name, $aggregator) + { + $this->aggregators[$name] = $aggregator; + + switch ($name) { + case 'bound': + $this->aggregators['coordinate']->setBoundAggregator($aggregator); + $this->subscribers['bound']->setBoundAggregator($aggregator); + break; + + case 'circle': + $this->aggregators['coordinate']->setCircleAggregator($aggregator); + $this->subscribers['circle']->setCircleAggregator($aggregator); + break; + + case 'coordinate': + $this->subscribers['coordinate']->setCoordinateAggregator($aggregator); + break; + + case 'dom_event': + $this->subscribers['dom_event']->setDomEventAggregator($aggregator); + break; + + case 'dom_event_once': + $this->subscribers['dom_event_once']->setDomEventOnceAggregator($aggregator); + break; + + case 'encoded_polyline': + $this->subscribers['encoded_polyline']->setEncodedPolylineAggregator($aggregator); + break; + + case 'event': + $this->subscribers['event']->setEventAggregator($aggregator); + break; + + case 'event_once': + $this->subscribers['event_once']->setEventOnceAggregator($aggregator); + break; + + case 'extendable': + $this->subscribers['extendable']->setExtendableAggregator($aggregator); + break; + + case 'ground_overlay': + $this->aggregators['bound']->setGroundOverlayAggregator($aggregator); + $this->subscribers['ground_overlay']->setGroundOverlayAggregator($aggregator); + break; + + case 'icon': + $this->aggregators['size']->setIconAggregator($aggregator); + $this->subscribers['icon']->setIconAggregator($aggregator); + break; + + case 'info_window': + foreach (array('coordinate', 'size') as $value) { + $this->aggregators[$value]->setInfoWindowAggregator($aggregator); + } + + foreach (array('info_window_close', 'info_window_open', 'info_window') as $value) { + $this->subscribers[$value]->setInfoWindowAggregator($aggregator); + } + break; + + case 'kml_layer': + $this->subscribers['kml_layer']->setKmlLayerAggregator($aggregator); + break; + + case 'marker': + foreach (array('coordinate', 'icon', 'info_window', 'marker_shape', 'point') as $value) { + $this->aggregators[$value]->setMarkerAggregator($aggregator); + } + + foreach (array('marker_open_event', 'marker') as $value) { + $this->subscribers[$value]->setMarkerAggregator($aggregator); + } + break; + + case 'marker_shape': + $this->subscribers['marker_shape']->setMarkerShapeAggregator($aggregator); + break; + + case 'point': + $this->subscribers['point']->setPointAggregator($aggregator); + break; + + case 'size': + $this->subscribers['size']->setSizeAggregator($aggregator); + break; + + case 'polygon': + $this->aggregators['coordinate']->setPolygonAggregator($aggregator); + $this->subscribers['polygon']->setPolygonAggregator($aggregator); + break; + + case 'polyline': + $this->aggregators['coordinate']->setPolylineAggregator($aggregator); + $this->subscribers['polyline']->setPolylineAggregator($aggregator); + break; + + case 'rectangle': + $this->aggregators['bound']->setRectangleAggregator($aggregator); + $this->subscribers['rectangle']->setRectangleAggregator($aggregator); + break; + + case 'autocomplete_bound': + $this->aggregators['autocomplete_coordinate']->setBoundAggregator($aggregator); + $this->subscribers['autocomplete_bound']->setBoundAggregator($aggregator); + break; + + case 'autocomplete_coordinate': + $this->subscribers['autocomplete_coordinate']->setCoordinateAggregator($aggregator); + break; + } + } + + /** + * Removes an aggregator. + * + * @param string $name The name. + */ + public function removeAggregator($name) + { + $aggregators = array( + 'autocomplete_bound', + 'autocomplete_coordinate', + 'marker', + 'circle', + 'encoded_polyline', + 'extendable', + 'ground_overlay', + 'icon', + 'info_window', + 'marker_shape', + 'polygon', + 'polyline', + 'rectangle', + 'kml_layer', + 'dom_event_once', + 'dom_event', + 'event_once', + 'event', + 'bound', + 'ground_overlay', + 'rectangle', + 'coordinate', + 'bound', + 'circle', + 'info_window', + 'marker', + 'polygon', + 'polyline', + 'point', + 'size', + ); + + if (!in_array($name, $aggregators, true)) { + unset($this->aggregators[$name]); + } + } + + /** + * Resets the renderers. + */ + public function resetRenderers() + { + $this->renderers = array(); + + $this->renderers['bound'] = new BoundRenderer(); + $this->renderers['coordinate'] = new CoordinateRenderer(); + $this->renderers['point'] = new PointRenderer(); + $this->renderers['size'] = new SizeRenderer(); + + $this->renderers['dom_event_once'] = new DomEventOnceRenderer(); + $this->renderers['dom_event'] = new DomEventRenderer(); + $this->renderers['event_once'] = new EventOnceRenderer(); + $this->renderers['event'] = new EventRenderer(); + + $this->renderers['encoding'] = new EncodingRenderer(); + + $this->renderers['kml_layer'] = new KmlLayerRenderer($this->jsonBuilder); + + $this->renderers['animation'] = new AnimationRenderer(); + $this->renderers['circle'] = new CircleRenderer($this->jsonBuilder); + + $this->renderers['encoded_polyline'] = new EncodedPolylineRenderer( + $this->jsonBuilder, + $this->renderers['encoding'] + ); + + $this->renderers['extendable'] = new ExtendableRenderer(); + $this->renderers['ground_overlay'] = new GroundOverlayRenderer($this->jsonBuilder); + $this->renderers['icon'] = new IconRenderer($this->jsonBuilder); + $this->renderers['info_window_close'] = new InfoWindowCloseRenderer(); + $this->renderers['info_window_open'] = new InfoWindowOpenRenderer(); + $this->renderers['info_window'] = new InfoWindowRenderer($this->jsonBuilder); + $this->renderers['info_box'] = new InfoBoxRenderer($this->jsonBuilder); + $this->renderers['marker_cluster'] = new MarkerClusterRenderer($this->jsonBuilder); + $this->renderers['marker_shape'] = new MarkerShapeRenderer($this->jsonBuilder); + $this->renderers['marker'] = new MarkerRenderer($this->jsonBuilder, $this->renderers['animation']); + $this->renderers['polygon'] = new PolygonRenderer($this->jsonBuilder); + $this->renderers['polyline'] = new PolylineRenderer($this->jsonBuilder); + $this->renderers['rectangle'] = new RectangleRenderer($this->jsonBuilder); + + $this->renderers['autocomplete_container'] = new AutocompleteContainerRenderer($this->jsonBuilder); + $this->renderers['autocomplete'] = new AutocompleteRenderer($this->jsonBuilder); + + $this->renderers['loader'] = new LoaderRenderer($this->jsonBuilder); + + $this->renderers['map_bound'] = new MapBoundRenderer(); + $this->renderers['map_center'] = new MapCenterRenderer(); + $this->renderers['map_container'] = new MapContainerRenderer($this->jsonBuilder); + $this->renderers['map_type_id'] = new MapTypeIdRenderer(); + + $this->renderers['control_position'] = new ControlPositionRenderer(); + $this->renderers['map_type_control_style'] = new MapTypeControlStyleRenderer(); + $this->renderers['overview_map_control'] = new OverviewMapControlRenderer($this->jsonBuilder); + + $this->renderers['pan_control'] = new PanControlRenderer( + $this->jsonBuilder, + $this->renderers['control_position'] + ); + + $this->renderers['rotate_control'] = new RotateControlRenderer( + $this->jsonBuilder, + $this->renderers['control_position'] + ); + + $this->renderers['scale_control_style'] = new ScaleControlStyleRenderer(); + + $this->renderers['scale_control'] = new ScaleControlRenderer( + $this->jsonBuilder, + $this->renderers['scale_control_style'] + ); + + $this->renderers['street_view_control'] = new StreetViewControlRenderer( + $this->jsonBuilder, + $this->renderers['control_position'] + ); + + $this->renderers['zoom_control_style'] = new ZoomControlStyleRenderer(); + + $this->renderers['zoom_control'] = new ZoomControlRenderer( + $this->jsonBuilder, + $this->renderers['control_position'], + $this->renderers['zoom_control_style'] + ); + + $this->renderers['map_type_control'] = new MapTypeControlRenderer( + $this->jsonBuilder, + $this->renderers['map_type_id'], + $this->renderers['control_position'], + $this->renderers['map_type_control_style'] + ); + + $this->renderers['controls'] = new ControlsRenderer( + $this->renderers['map_type_control'], + $this->renderers['overview_map_control'], + $this->renderers['pan_control'], + $this->renderers['rotate_control'], + $this->renderers['scale_control'], + $this->renderers['street_view_control'], + $this->renderers['zoom_control'] + ); + + $this->renderers['map'] = new MapRenderer( + $this->jsonBuilder, + $this->renderers['map_type_id'], + $this->renderers['controls'] + ); + } + + /** + * Checks if there are renderers. + * + * @return boolean TRUE if there are renderers else FALSE. + */ + public function hasRenderers() + { + return !empty($this->renderers); + } + + /** + * Gets the renderers. + * + * @return array The renderers. + */ + public function getRenderers() + { + return $this->renderers; + } + + /** + * Sets the renderers. + * + * @param array $renderers The renderers. + */ + public function setRenderers(array $renderers) + { + $this->resetRenderers(); + $this->addRenderers($renderers); + } + + /** + * Adds the renderers. + * + * @param array $renderers The renderers. + */ + public function addRenderers(array $renderers) + { + foreach ($renderers as $name => $renderer) { + $this->setRenderer($name, $renderer); + } + } + + /** + * Removes the renderers. + * + * @param array $names The names. + */ + public function removeRenderers(array $names) + { + foreach ($names as $name) { + $this->removeRenderer($name); + } + } + + /** + * Checks if there is a renderer. + * + * @param string $name The name. + * + * @return boolean TRUE if there is the renderer else FALSE. + */ + public function hasRenderer($name) + { + return isset($this->renderers[$name]); + } + + /** + * Gets a renderer. + * + * @param string $name The name. + * + * @return object|null The renderer. + */ + public function getRenderer($name) + { + return $this->hasRenderer($name) ? $this->renderers[$name] : null; + } + + /** + * Sets the renderer. + * + * @param string $name The name. + * @param object $renderer The renderer. + */ + public function setRenderer($name, $renderer) + { + $this->renderers[$name] = $renderer; + + switch ($name) { + case 'animation': + $this->renderers['marker']->setAnimationRenderer($renderer); + break; + + case 'autocomplete': + $this->subscribers['autocomplete']->setAutocompleteRenderer($renderer); + break; + + case 'autocomplete_container': + $this->subscribers['autocomplete_container']->setContainerRenderer($renderer); + break; + + case 'bound': + foreach (array('bound', 'autocomplete_bound') as $value) { + $this->subscribers[$value]->setBoundRenderer($renderer); + } + break; + + case 'circle': + $this->subscribers['circle']->setCircleRenderer($renderer); + break; + + case 'coordinate': + foreach (array('coordinate', 'autocomplete_coordinate') as $value) { + $this->subscribers[$value]->setCoordinateRenderer($renderer); + } + break; + + case 'controls': + $this->renderers['map']->setControlsRenderer($renderer); + break; + + case 'control_position': + $values = array( + 'map_type_control', + 'pan_control', + 'rotate_control', + 'street_view_control', + 'zoom_control', + ); + + foreach ($values as $value) { + $this->renderers[$value]->setControlPositionRenderer($renderer); + } + break; + + case 'dom_event': + $this->subscribers['dom_event']->setDomEventRenderer($renderer); + break; + + case 'dom_event_once': + $this->subscribers['dom_event_once']->setDomEventOnceRenderer($renderer); + break; + + case 'encoded_polyline': + $this->subscribers['encoded_polyline']->setEncodedPolylineRenderer($renderer); + break; + + case 'encoding': + $this->renderers['encoded_polyline']->setEncodingRenderer($renderer); + break; + + case 'event': + $this->subscribers['event']->setEventRenderer($renderer); + break; + + case 'event_once': + $this->subscribers['event_once']->setEventOnceRenderer($renderer); + break; + + case 'extendable': + $this->subscribers['extendable']->setExtendableRenderer($renderer); + break; + + case 'ground_overlay': + $this->subscribers['ground_overlay']->setGroundOverlayRenderer($renderer); + break; + + case 'icon': + $this->subscribers['icon']->setIconRenderer($renderer); + break; + + case 'info_box': + $this->subscribers['info_window']->setInfoBoxRenderer($renderer); + break; + + case 'info_window': + $this->subscribers['info_window']->setInfoWindowRenderer($renderer); + break; + + case 'info_window_close': + $this->subscribers['info_window_close']->setInfoWindowCloseRenderer($renderer); + break; + + case 'info_window_open': + foreach (array('info_window_open', 'marker_open_event') as $value) { + $this->subscribers[$value]->setInfoWindowOpenRenderer($renderer); + } + break; + + case 'kml_layer': + $this->subscribers['kml_layer']->setKmlLayerRenderer($renderer); + break; + + case 'loader': + $this->subscribers['api_javascript']->setLoaderRenderer($renderer); + break; + + case 'map': + $this->subscribers['map']->setMapRenderer($renderer); + break; + + case 'map_bound': + $this->subscribers['map_bound']->setMapBoundRenderer($renderer); + break; + + case 'map_center': + $this->subscribers['map_center']->setMapCenterRenderer($renderer); + break; + + case 'map_container': + $this->subscribers['map_container']->setContainerRenderer($renderer); + break; + + case 'map_type_control': + $this->renderers['controls']->setMapTypeControlRenderer($renderer); + break; + + case 'map_type_control_style': + $this->renderers['map_type_control']->setMapTypeControlStyleRenderer($renderer); + break; + + case 'map_type_id': + foreach (array('map_type_control', 'map') as $value) { + $this->renderers[$value]->setMapTypeIdRenderer($renderer); + } + break; + + case 'marker': + $this->subscribers['marker']->setMarkerRenderer($renderer); + break; + + case 'marker_cluster': + $this->subscribers['marker_cluster']->setMarkerClusterRenderer($renderer); + break; + + case 'marker_shape': + $this->subscribers['marker_shape']->setMarkerShapeRenderer($renderer); + break; + + case 'overview_map_control': + $this->renderers['controls']->setOverviewMapControlRenderer($renderer); + break; + + case 'pan_control': + $this->renderers['controls']->setPanControlRenderer($renderer); + break; + + case 'point': + $this->subscribers['point']->setPointRenderer($renderer); + break; + + case 'polygon': + $this->subscribers['polygon']->setPolygonRenderer($renderer); + break; + + case 'polyline': + $this->subscribers['polyline']->setPolylineRenderer($renderer); + break; + + case 'rectangle': + $this->subscribers['rectangle']->setRectangleRenderer($renderer); + break; + + case 'rotate_control': + $this->renderers['controls']->setRotateControlRenderer($renderer); + break; + + case 'scale_control': + $this->renderers['controls']->setScaleControlRenderer($renderer); + break; + + case 'scale_control_style': + $this->renderers['scale_control']->setScaleControlStyleRenderer($renderer); + break; + + case 'size': + $this->subscribers['size']->setSizeRenderer($renderer); + break; + + case 'street_view_control': + $this->renderers['controls']->setStreetViewControlRenderer($renderer); + break; + + case 'zoom_control': + $this->renderers['controls']->setZoomControlRenderer($renderer); + break; + + case 'zoom_control_style': + $this->renderers['zoom_control']->setZoomControlStyleRenderer($renderer); + break; + } + } + + /** + * Removes a renderer. + * + * @param string $name The name. + */ + public function removeRenderer($name) + { + $renderers = array( + 'bound', + 'coordinate', + 'point', + 'size', + 'dom_event_once', + 'dom_event', + 'event_once', + 'event', + 'encoding', + 'kml_layer', + 'animation', + 'circle', + 'encoded_polyline', + 'extendable', + 'ground_overlay', + 'icon', + 'info_window_close', + 'info_window_open', + 'info_window', + 'info_box', + 'marker_cluster', + 'marker_shape', + 'marker', + 'polygon', + 'polyline', + 'rectangle', + 'autocomplete_container', + 'autocomplete', + 'loader', + 'map_bound', + 'map_center', + 'map_container', + 'map_type_id', + 'control_position', + 'map_type_control_style', + 'overview_map_control', + 'pan_control', + 'rotate_control', + 'scale_control_style', + 'scale_control', + 'street_view_control', + 'zoom_control_style', + 'zoom_control', + 'map_type_control', + 'controls', + 'map', + ); + + if (!in_array($name, $renderers, true)) { + unset($this->renderers[$name]); + } + } + + /** + * Resets the subscribers. + */ + public function resetSubscribers() + { + $this->subscribers = array(); + + $this->subscribers['base'] = new BaseSubscriber(); + $this->subscribers['events'] = new EventsSubscriber(); + $this->subscribers['layers'] = new LayersSubscriber(); + $this->subscribers['overlays'] = new OverlaysSubscriber(); + $this->subscribers['autocomplete_base'] = new AutocompleteBaseSubscriber(); + + $this->subscribers['bound'] = new BoundSubscriber( + $this->formatter, + $this->aggregators['bound'], + $this->renderers['bound'] + ); + + $this->subscribers['coordinate'] = new CoordinateSubscriber( + $this->formatter, + $this->aggregators['coordinate'], + $this->renderers['coordinate'] + ); + + $this->subscribers['point'] = new PointSubscriber( + $this->formatter, + $this->aggregators['point'], + $this->renderers['point'] + ); + + $this->subscribers['size'] = new SizeSubscriber( + $this->formatter, + $this->aggregators['size'], + $this->renderers['size'] + ); + + $this->subscribers['dom_event_once'] = new DomEventOnceSubscriber( + $this->formatter, + $this->aggregators['dom_event_once'], + $this->renderers['dom_event_once'] + ); + + $this->subscribers['dom_event'] = new DomEventSubscriber( + $this->formatter, + $this->aggregators['dom_event'], + $this->renderers['dom_event'] + ); + + $this->subscribers['event_once'] = new EventOnceSubscriber( + $this->formatter, + $this->aggregators['event_once'], + $this->renderers['event_once'] + ); + + $this->subscribers['event'] = new EventSubscriber( + $this->formatter, + $this->aggregators['event'], + $this->renderers['event'] + ); + + $this->subscribers['kml_layer'] = new KmlLayerSubscriber( + $this->formatter, + $this->aggregators['kml_layer'], + $this->renderers['kml_layer'] + ); + + $this->subscribers['circle'] = new CircleSubscriber( + $this->formatter, + $this->aggregators['circle'], + $this->renderers['circle'] + ); + + $this->subscribers['encoded_polyline'] = new EncodedPolylineSubscriber( + $this->formatter, + $this->aggregators['encoded_polyline'], + $this->renderers['encoded_polyline'] + ); + + $this->subscribers['extendable'] = new ExtendableSubscriber( + $this->formatter, + $this->aggregators['extendable'], + $this->renderers['extendable'] + ); + + $this->subscribers['ground_overlay'] = new GroundOverlaySubscriber( + $this->formatter, + $this->aggregators['ground_overlay'], + $this->renderers['ground_overlay'] + ); + + $this->subscribers['icon'] = new IconSubscriber( + $this->formatter, + $this->aggregators['icon'], + $this->renderers['icon'] + ); + + $this->subscribers['info_window_close'] = new InfoWindowCloseSubscriber( + $this->formatter, + $this->aggregators['info_window'], + $this->renderers['info_window_close'] + ); + + $this->subscribers['info_window_open'] = new InfoWindowOpenSubscriber( + $this->formatter, + $this->aggregators['info_window'], + $this->renderers['info_window_open'] + ); + + $this->subscribers['info_window'] = new InfoWindowSubscriber( + $this->formatter, + $this->aggregators['info_window'], + $this->renderers['info_window'], + $this->renderers['info_box'] + ); + + $this->subscribers['marker_cluster'] = new MarkerClusterSubscriber( + $this->formatter, + $this->renderers['marker_cluster'] + ); + + $this->subscribers['marker_open_event'] = new MarkerOpenEventSubscriber( + $this->formatter, + $this->aggregators['marker'], + $this->renderers['info_window_open'] + ); + + $this->subscribers['marker_shape'] = new MarkerShapeSubscriber( + $this->formatter, + $this->aggregators['marker_shape'], + $this->renderers['marker_shape'] + ); + + $this->subscribers['marker'] = new MarkerSubscriber( + $this->formatter, + $this->aggregators['marker'], + $this->renderers['marker'] + ); + + $this->subscribers['polygon'] = new PolygonSubscriber( + $this->formatter, + $this->aggregators['polygon'], + $this->renderers['polygon'] + ); + + $this->subscribers['polyline'] = new PolylineSubscriber( + $this->formatter, + $this->aggregators['polyline'], + $this->renderers['polyline'] + ); + + $this->subscribers['rectangle'] = new RectangleSubscriber( + $this->formatter, + $this->aggregators['rectangle'], + $this->renderers['rectangle'] + ); + + $this->subscribers['autocomplete_bound'] = new AutocompleteBoundSubscriber( + $this->formatter, + $this->aggregators['autocomplete_bound'], + $this->renderers['bound'] + ); + + $this->subscribers['autocomplete_coordinate'] = new AutocompleteCoordinateSubscriber( + $this->formatter, + $this->aggregators['autocomplete_coordinate'], + $this->renderers['coordinate'] + ); + + $this->subscribers['autocomplete_container'] = new AutocompleteContainerSubscriber( + $this->formatter, + $this->renderers['autocomplete_container'] + ); + + $this->subscribers['autocomplete_html'] = new AutocompleteHtmlSubscriber($this->formatter); + $this->subscribers['autocomplete_init'] = new AutocompleteInitSubscriber(); + $this->subscribers['autocomplete_javascript'] = new AutocompleteJavascriptSubscriber($this->formatter); + + $this->subscribers['autocomplete'] = new AutocompleteSubscriber( + $this->formatter, + $this->renderers['autocomplete'] + ); + + $this->subscribers['api_javascript'] = new ApiJavascriptSubscriber( + $this->formatter, + $this->renderers['loader'] + ); + + $this->subscribers['map_bound'] = new MapBoundSubscriber($this->formatter, $this->renderers['map_bound']); + $this->subscribers['map_center'] = new MapCenterSubscriber($this->formatter, $this->renderers['map_center']); + + $this->subscribers['map_container'] = new MapContainerSubscriber( + $this->formatter, + $this->renderers['map_container'] + ); + + $this->subscribers['map_finish'] = new MapFinishSubscriber(); + $this->subscribers['map_html'] = new MapHtmlSubscriber($this->formatter); + $this->subscribers['map_init'] = new MapInitSubscriber(); + $this->subscribers['map_javascript'] = new MapJavascriptSubscriber($this->formatter); + $this->subscribers['map_stylesheet'] = new MapStylesheetSubscriber($this->formatter); + $this->subscribers['map'] = new MapSubscriber($this->formatter, $this->renderers['map']); + } + + /** + * Checks if there are subscribers. + * + * @return boolean TRUE if there are subscribers else FALSE. + */ + public function hasSubscribers() + { + return !empty($this->subscribers); + } + + /** + * Gets the subscribers. + * + * @return array The subscribers. + */ + public function getSubscribers() + { + return $this->subscribers; + } + + /** + * Sets the subscribers. + * + * @param array $subscribers The subscribers. + */ + public function setSubscribers(array $subscribers) + { + $this->resetSubscribers(); + $this->addSubscribers($subscribers); + } + + /** + * Adds the subscribers. + * + * @param array $subscribers The subscribers. + */ + public function addSubscribers(array $subscribers) + { + foreach ($subscribers as $name => $subscriber) { + $this->setSubscriber($name, $subscriber); + } + } + + /** + * Removes the subscribers. + * + * @param array $names The names. + */ + public function removeSubscribers(array $names) + { + foreach ($names as $name) { + $this->removeSubscriber($name); + } + } + + /** + * Checks if there is a subscriber. + * + * @param string $name The name. + * + * @return boolean TRUE if there is a subscriber else FALSE. + */ + public function hasSubscriber($name) + { + return isset($this->subscribers[$name]); + } + + /** + * Gets a subscriber. + * + * @param string $name The name. + * + * @return \Symfony\Component\EventDispatcher\EventSubscriberInterface|null The subscriber. + */ + public function getSubscriber($name) + { + return $this->hasSubscriber($name) ? $this->subscribers[$name] : null; + } + + /** + * Sets a subscrber. + * + * @param string $name The name. + * @param \Symfony\Component\EventDispatcher\EventSubscriberInterface $subscriber The subscriber. + */ + public function setSubscriber($name, EventSubscriberInterface $subscriber) + { + $this->subscribers[$name] = $subscriber; + } + + /** + * Removes a subscriber. + * + * @param string $name The name. + */ + public function removeSubscriber($name) + { + unset($this->subscribers[$name]); + } + + /** + * {@inheritdoc} + */ + public function createApiHelper() + { + return new ApiHelper($this->createEventDispatcher()); + } + + /** + * {@inheritdoc} + */ + public function createMapHelper() + { + return new MapHelper($this->createEventDispatcher()); + } + + /** + * {@inheritdoc} + */ + public function createPlacesAutocompleteHelper() + { + return new PlacesAutocompleteHelper($this->createEventDispatcher()); + } + + /** + * Creates an event dispatcher. + * + * @return \Symfony\Component\EventDispatcher\EventDispatcher The event dispatcher. + */ + protected function createEventDispatcher() + { + $eventDispatcher = new EventDispatcher(); + foreach ($this->subscribers as $subscriber) { + $eventDispatcher->addSubscriber($subscriber); + } + + return $eventDispatcher; + } +} diff --git a/src/Helpers/Factories/HelperFactoryInterface.php b/src/Helpers/Factories/HelperFactoryInterface.php new file mode 100644 index 00000000..5c19b637 --- /dev/null +++ b/src/Helpers/Factories/HelperFactoryInterface.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Factories; + +/** + * Helper factory interface. + * + * @author GeLo + */ +interface HelperFactoryInterface +{ + /** + * Creates an api helper. + * + * @return \Ivory\GoogleMap\Helpers\ApiHelper The api helper. + */ + public function createApiHelper(); + + /** + * Creates a map helper. + * + * @return \Ivory\GoogleMap\Helpers\MapHelper The map helper. + */ + public function createMapHelper(); + + /** + * Creates a places autocomplete helper. + * + * @return \Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper The places autocomplete helper. + */ + public function createPlacesAutocompleteHelper(); +} diff --git a/src/Helpers/Factories/Symfony2HelperFactory.php b/src/Helpers/Factories/Symfony2HelperFactory.php new file mode 100644 index 00000000..d7f26934 --- /dev/null +++ b/src/Helpers/Factories/Symfony2HelperFactory.php @@ -0,0 +1,563 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Factories; + +use Ivory\GoogleMap\Helpers\Factories\DependencyInjection\IvoryGoogleMapExtension; +use Symfony\Component\Config\ConfigCache; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Dumper\PhpDumper; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; +use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; + +/** + * Symfony 2 helper factory. + * + * @author GeLo + */ +class Symfony2HelperFactory extends AbstractHelperFactory +{ + /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var string|null */ + protected $cachePath; + + /** @var string */ + protected $containerName; + + /** @var array */ + protected $parameters; + + /** @var array */ + protected $extensions; + + /** @var array */ + protected $compilerPasses; + + /** + * Creates a Symfony 2 helper factory. + * + * @param boolean $debug The debug. + * @param integer $indentation The indentation. + * @param string|null $cachePath The cache path. + * @param string $containerName The container name. + * @param array $parameters The parameters. + * @param array $extensions The extensions. + * @param array $compilerPasses The compiler passes. + */ + public function __construct( + $debug = false, + $indentation = 4, + $cachePath = null, + $containerName = 'IvoryGoogleMapContainer', + array $parameters = array(), + array $extensions = array(), + array $compilerPasses = array() + ) { + parent::__construct($debug, $indentation); + + $this->setCachePath($cachePath); + $this->setContainerName($containerName); + $this->setParameters($parameters); + $this->setExtensions($extensions); + $this->setCompilerPasses($compilerPasses); + } + + /** + * {@inheritdoc} + */ + public function setDebug($debug) + { + parent::setDebug($debug); + + $this->container = null; + $this->setParameter('ivory.google_map.debug', $debug); + } + + /** + * {@inheritdoc} + */ + public function setIndentation($indentation) + { + parent::setIndentation($indentation); + + $this->container = null; + $this->setParameter('ivory.google_map.indentation', $indentation); + } + + /** + * Checks if there is a cache path. + * + * @return boolean TRUE if there is a cache path else FALSE. + */ + public function hasCachePath() + { + return $this->cachePath !== null; + } + + /** + * Gets the cache path. + * + * @return string|null The cache path. + */ + public function getCachePath() + { + return $this->cachePath; + } + + /** + * Sets the cache path. + * + * @param string|null $cachePath The cache path. + */ + public function setCachePath($cachePath) + { + $this->container = null; + $this->cachePath = $cachePath; + } + + /** + * Gets the container name. + * + * @return string The container name. + */ + public function getContainerName() + { + return $this->containerName; + } + + /** + * Sets the container name. + * + * @param string $containerName The container name. + */ + public function setContainerName($containerName) + { + $this->container = null; + $this->containerName = $containerName; + } + + /** + * Resets the parameters. + */ + public function resetParameters() + { + $this->container = null; + $this->parameters = array( + 'ivory.google_map.debug' => $this->debug, + 'ivory.google_map.indentation' => $this->indentation, + ); + } + + /** + * Checks if there are parameters. + * + * @return boolean TRUE if there are parameters else FALSE. + */ + public function hasParameters() + { + return !empty($this->parameters); + } + + /** + * Gets the parameters. + * + * @return array The parameters. + */ + public function getParameters() + { + return $this->parameters; + } + + /** + * Sets the parameters. + * + * @param array $parameters The parameters. + */ + public function setParameters(array $parameters) + { + $this->resetParameters(); + $this->addParameters($parameters); + } + + /** + * Adds the parameters. + * + * @param array $parameters The parameters. + */ + public function addParameters(array $parameters) + { + foreach ($parameters as $name => $value) { + $this->setParameter($name, $value); + } + } + + /** + * Removes the parameters. + * + * @param array $names The names. + */ + public function removeParameters(array $names) + { + foreach ($names as $name) { + $this->removeParameter($name); + } + } + + /** + * Checks if there is a parameter. + * + * @param string $name The name. + * + * @return boolean TRUE if there is a parameter else FALSE. + */ + public function hasParameter($name) + { + return isset($this->parameters[$name]); + } + + /** + * Gets a parameter. + * + * @param string $name The name. + * + * @return mixed|null The parameter. + */ + public function getParameter($name) + { + return $this->hasParameter($name) ? $this->parameters[$name] : null; + } + + /** + * Sets a parameter. + * + * @param string $name The name. + * @param mixed $value The value. + */ + public function setParameter($name, $value) + { + $this->container = null; + $this->parameters[$name] = $value; + } + + /** + * Removes a parameter. + * + * @param string $name The name. + */ + public function removeParameter($name) + { + if (!in_array($name, array('ivory.google_map.debug', 'ivory.google_map.indentation'), true)) { + $this->container = null; + unset($this->parameters[$name]); + } + } + + /** + * Resets the extensions. + */ + public function resetExtensions() + { + $this->container = null; + $this->extensions = array(new IvoryGoogleMapExtension()); + } + + /** + * Checks if there are extensions. + * + * @return boolean TRUE if there are extensions else FALSE. + */ + public function hasExtensions() + { + return !empty($this->extensions); + } + + /** + * Gets the extensions. + * + * @return array The extensions. + */ + public function getExtensions() + { + return $this->extensions; + } + + /** + * Sets the extension. + * + * @param array $extensions The extensions. + */ + public function setExtensions(array $extensions) + { + $this->resetExtensions(); + $this->addExtensions($extensions); + } + + /** + * Adds the extensions. + * + * @param array $extensions The extensions. + */ + public function addExtensions(array $extensions) + { + foreach ($extensions as $extension) { + $this->addExtension($extension); + } + } + + /** + * Removes the extensions. + * + * @param array $extensions The extensions. + */ + public function removeExtensions(array $extensions) + { + foreach ($extensions as $extension) { + $this->removeExtension($extension); + } + } + + /** + * Checks if there is an extension. + * + * @param \Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension The extension. + * + * @return boolean TRUE if there is the extension else FALSE. + */ + public function hasExtension(ExtensionInterface $extension) + { + return in_array($extension, $this->extensions, true); + } + + /** + * Adds an extension. + * + * @param \Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension The extension. + */ + public function addExtension(ExtensionInterface $extension) + { + $this->container = null; + + if (!$this->hasExtension($extension)) { + $this->extensions[] = $extension; + } + } + + /** + * Removes an extension. + * + * @param \Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension The extension. + */ + public function removeExtension(ExtensionInterface $extension) + { + $this->container = null; + unset($this->extensions[array_search($extension, $this->extensions, true)]); + } + + /** + * Resets the compiler passes. + */ + public function resetCompilerPasses() + { + $this->container = null; + $this->compilerPasses = array( + new ResolveParameterPlaceHoldersPass(), + new RegisterListenersPass( + 'ivory.google_map.helpers.event_dispatcher', + 'ivory.google_map.helpers.listener', + 'ivory.google_map.helpers.subscriber' + ), + ); + } + + /** + * Checks if there are compiler passes. + * + * @return boolean TRUE if there are compiler passes else FALSE. + */ + public function hasCompilerPasses() + { + return !empty($this->compilerPasses); + } + + /** + * Gets the compiler passes. + * + * @return array The compiler passes. + */ + public function getCompilerPasses() + { + return $this->compilerPasses; + } + + /** + * Sets the compiler passes. + * + * @param array $compilerPasses The compiler passes. + */ + public function setCompilerPasses(array $compilerPasses) + { + $this->resetCompilerPasses(); + $this->addCompilerPasses($compilerPasses); + } + + /** + * Adds the compiler passes. + * + * @param array $compilerPasses The compiler passes. + */ + public function addCompilerPasses(array $compilerPasses) + { + foreach ($compilerPasses as $compilerPass) { + $this->addCompilerPass($compilerPass); + } + } + + /** + * Removes the compiler passes. + * + * @param array $compilerPasses The compiler passes. + */ + public function removeCompilerPasses(array $compilerPasses) + { + foreach ($compilerPasses as $compilerPass) { + $this->removeCompilerPass($compilerPass); + } + } + + /** + * Checks if there is a compiler pass. + * + * @param \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $compilerPass The compiler pass. + * + * @return boolean TRUE if there is a compiler pass else FALSE. + */ + public function hasCompilerPass(CompilerPassInterface $compilerPass) + { + return in_array($compilerPass, $this->compilerPasses, true); + } + + /** + * Adds a compiler pass. + * + * @param \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $compilerPass The compiler pass. + */ + public function addCompilerPass(CompilerPassInterface $compilerPass) + { + $this->container = null; + + if (!in_array($compilerPass, $this->compilerPasses)) { + $this->compilerPasses[] = $compilerPass; + } + } + + /** + * Removes a compiler pass. + * + * @param \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $compilerPass The compiler pass. + */ + public function removeCompilerPass(CompilerPassInterface $compilerPass) + { + $this->container = null; + unset($this->compilerPasses[array_search($compilerPass, $this->compilerPasses, true)]); + } + + /** + * {@inheritdoc} + */ + public function createApiHelper() + { + return $this->getContainer()->get('ivory.google_map.helpers.api'); + } + + /** + * {@inheritdoc} + */ + public function createMapHelper() + { + return $this->getContainer()->get('ivory.google_map.helpers.map'); + } + + /** + * {@inheritdoc} + */ + public function createPlacesAutocompleteHelper() + { + return $this->getContainer()->get('ivory.google_map.helpers.places.autocomplete'); + } + + /** + * Gets the container. + * + * @return \Symfony\Component\DependencyInjection\ContainerInterface The container. + */ + protected function getContainer() + { + if ($this->container === null) { + $this->container = $this->createContainer(); + } + + return $this->container; + } + + /** + * Creates the container. + * + * @return \Symfony\Component\DependencyInjection\ContainerInterface The container. + */ + protected function createContainer() + { + if (!$this->hasCachePath()) { + return $this->buildContainer(); + } + + $config = new ConfigCache($containerPath = $this->cachePath.'/'.$this->containerName.'.php', $this->debug); + + if (!$config->isFresh()) { + $dumper = new PhpDumper($containerBuilder = $this->buildContainer()); + $config->write($dumper->dump(array('class' => $this->containerName)), $containerBuilder->getResources()); + } + + require_once $containerPath; + + return new $this->containerName(); + } + + /** + * Builds the container. + * + * @return \Symfony\Component\DependencyInjection\ContainerBuilder The container. + */ + protected function buildContainer() + { + $containerBuilder = new ContainerBuilder(); + + foreach ($this->parameters as $name => $value) { + $containerBuilder->setParameter($name, $value); + } + + foreach ($this->extensions as $extension) { + $containerBuilder->registerExtension($extension); + $containerBuilder->loadFromExtension($extension->getAlias()); + } + + foreach ($this->compilerPasses as $compilerPass) { + $containerBuilder->addCompilerPass($compilerPass); + } + + $containerBuilder->compile(); + + return $containerBuilder; + } +} diff --git a/src/Helpers/MapEvent.php b/src/Helpers/MapEvent.php new file mode 100644 index 00000000..55e96676 --- /dev/null +++ b/src/Helpers/MapEvent.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Map; + +/** + * Map event. + * + * @author GeLo + */ +class MapEvent extends AbstractEvent +{ + /** @var \Ivory\GoogleMap\Map */ + protected $map; + + /** + * Creates a map event. + * + * @param \Ivory\GoogleMap\Map $map The map. + */ + public function __construct(Map $map) + { + $this->map = $map; + } + + /** + * Gets the map. + * + * @return \Ivory\GoogleMap\Map The map. + */ + public function getMap() + { + return $this->map; + } +} diff --git a/src/Helpers/MapEvents.php b/src/Helpers/MapEvents.php new file mode 100644 index 00000000..c5d8e262 --- /dev/null +++ b/src/Helpers/MapEvents.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Map events. + * + * @author GeLo + */ +class MapEvents extends AbstractUninstantiableAsset +{ + const HTML = 'ivory.google_map.map.html'; + const STYLESHEET = 'ivory.google_map.map.stylesheet'; + const JAVASCRIPT = 'ivory.google_map.map.javascript'; + const JAVASCRIPT_INIT = 'ivory.google_map.map.javascript.init'; + const JAVASCRIPT_INIT_MARKER_OPEN_EVENT = 'ivory.google_map.map.javascript.init.marker_open_event'; + const JAVASCRIPT_INIT_CONTAINER = 'ivory.google_map.map.javascript.init.container'; + const JAVASCRIPT_BASE = 'ivory.google_map.map.javascript.base'; + const JAVASCRIPT_BASE_COORDINATE = 'ivory.google_map.map.javascript.base.coordinate'; + const JAVASCRIPT_BASE_BOUND = 'ivory.google_map.map.javascript.base.bound'; + const JAVASCRIPT_BASE_POINT = 'ivory.google_map.map.javascript.base.point'; + const JAVASCRIPT_BASE_SIZE = 'ivory.google_map.map.javascript.base.size'; + const JAVASCRIPT_MAP = 'ivory.google_map.map.javascript.map'; + const JAVASCRIPT_OVERLAYS = 'ivory.google_map.map.javascript.overlays'; + const JAVASCRIPT_OVERLAYS_CIRCLE = 'ivory.google_map.map.javascript.overlays.circle'; + const JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE = 'ivory.google_map.map.javascript.overlays.encoded_polyline'; + const JAVASCRIPT_OVERLAYS_GROUND_OVERLAY = 'ivory.google_map.map.javascript.overlays.ground_overlay'; + const JAVASCRIPT_OVERLAYS_POLYGON = 'ivory.google_map.map.javascript.overlays.polygon'; + const JAVASCRIPT_OVERLAYS_POLYLINE = 'ivory.google_map.map.javascript.overlays.polyline'; + const JAVASCRIPT_OVERLAYS_RECTANGLE = 'ivory.google_map.map.javascript.overlays.rectangle'; + const JAVASCRIPT_OVERLAYS_INFO_WINDOW = 'ivory.google_map.map.javascript.overlays.info_window'; + const JAVASCRIPT_OVERLAYS_ICON = 'ivory.google_map.map.javascript.overlays.marker_image'; + const JAVASCRIPT_OVERLAYS_MARKER_SHAPE = 'ivory.google_map.map.javascript.overlays.marker_shape'; + const JAVASCRIPT_OVERLAYS_MARKER = 'ivory.google_map.map.javascript.overlays.marker'; + const JAVASCRIPT_OVERLAYS_MARKER_CLUSTER = 'ivory.google_map.map.javascript.overlays.marker_cluster'; + const JAVASCRIPT_LAYERS = 'ivory.google_map.map.javascript.layers'; + const JAVASCRIPT_LAYERS_KML_LAYER = 'ivory.google_map.map.javascript.layers.kml_layer'; + const JAVASCRIPT_EVENTS = 'ivory.google_map.map.javascript.events'; + const JAVASCRIPT_EVENTS_DOM_EVENT = 'ivory.google_map.map.javascript.events.dom_event'; + const JAVASCRIPT_EVENTS_DOM_EVENT_ONCE = 'ivory.google_map.map.javascript.events.dom_event_once'; + const JAVASCRIPT_EVENTS_EVENT = 'ivory.google_map.map.javascript.events.event'; + const JAVASCRIPT_EVENTS_EVENT_ONCE = 'ivory.google_map.map.javascript.events.event_once'; + const JAVASCRIPT_FINISH = 'ivory.google_map.map.javascript.finish'; + const JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE = 'ivory.google_map.map.javascript.finish.info_window_close'; + const JAVASCRIPT_FINISH_INFO_WINDOW_OPEN = 'ivory.google_map.map.javascript.finish.info_window_open'; + const JAVASCRIPT_FINISH_EXTENDABLE = 'ivory.google_map.map.javascript.finish.extendable'; + const JAVASCRIPT_FINISH_MAP_CENTER = 'ivory.google_map.map.javascript.finish.map_center'; + const JAVASCRIPT_FINISH_MAP_BOUND = 'ivory.google_map.map.javascript.finish.map_bound'; +} diff --git a/src/Helpers/MapHelper.php b/src/Helpers/MapHelper.php new file mode 100644 index 00000000..44d9df96 --- /dev/null +++ b/src/Helpers/MapHelper.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Map; + +/** + * Map helper. + * + * @author GeLo + */ +class MapHelper extends AbstractHelper +{ + /** + * Renders the map. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered map. + */ + public function render(Map $map) + { + return $this->renderStylesheet($map).$this->renderHtml($map).$this->renderJavascript($map); + } + + /** + * Renders the html. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered html. + */ + public function renderHtml(Map $map) + { + return $this->doRender($map, MapEvents::HTML); + } + + /** + * Renders the stylesheet. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered stylesheet. + */ + public function renderStylesheet(Map $map) + { + return $this->doRender($map, MapEvents::STYLESHEET); + } + + /** + * Renders the javascript. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered javascript. + */ + public function renderJavascript(Map $map) + { + return $this->doRender($map, MapEvents::JAVASCRIPT); + } + + /** + * Does the rendering of a map event. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param string $eventName The event name. + * + * @return string The rendered map event. + */ + protected function doRender(Map $map, $eventName) + { + $this->eventDispatcher->dispatch($eventName, $mapEvent = new MapEvent($map)); + + return $mapEvent->getCode(); + } +} diff --git a/src/Helpers/PlacesAutocompleteEvent.php b/src/Helpers/PlacesAutocompleteEvent.php new file mode 100644 index 00000000..4b8923df --- /dev/null +++ b/src/Helpers/PlacesAutocompleteEvent.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Places\Autocomplete; + +/** + * Places autocomplete event. + * + * @author GeLo + */ +class PlacesAutocompleteEvent extends AbstractEvent +{ + /** @var \Ivory\GoogleMap\Places\Autocomplete */ + protected $autocomplete; + + /** + * Creates a places autocomplete event. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + */ + public function __construct(Autocomplete $autocomplete) + { + $this->autocomplete = $autocomplete; + } + + /** + * Gets the autocomplete. + * + * @return \Ivory\GoogleMap\Places\Autocomplete The autocomplete. + */ + public function getAutocomplete() + { + return $this->autocomplete; + } +} diff --git a/src/Helpers/PlacesAutocompleteEvents.php b/src/Helpers/PlacesAutocompleteEvents.php new file mode 100644 index 00000000..5c25bb32 --- /dev/null +++ b/src/Helpers/PlacesAutocompleteEvents.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Places autocomplete events. + * + * @author GeLo + */ +class PlacesAutocompleteEvents extends AbstractUninstantiableAsset +{ + const HTML = 'ivory.google_map.places_autocomplete.html'; + const JAVASCRIPT = 'ivory.google_map.places_autocomplete.javascript'; + const JAVASCRIPT_INIT = 'ivory.google_map.places_autocomplete.javascript.init'; + const JAVASCRIPT_INIT_CONTAINER = 'ivory.google_map.places_autocomplete.javascript.init.container'; + const JAVASCRIPT_BASE = 'ivory.google_map.places_autocomplete.javascript.base'; + const JAVASCRIPT_BASE_COORDINATE = 'ivory.google_map.places_autocomplete.javascript.base.coordinate'; + const JAVASCRIPT_BASE_BOUND = 'ivory.google_map.places_autocomplete.javascript.base.bound'; + const JAVASCRIPT_AUTOCOMPLETE = 'ivory.google_map.places_autocomplete.javascript.autocomplete'; +} diff --git a/src/Helpers/PlacesAutocompleteHelper.php b/src/Helpers/PlacesAutocompleteHelper.php new file mode 100644 index 00000000..5b0f01d4 --- /dev/null +++ b/src/Helpers/PlacesAutocompleteHelper.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Places\Autocomplete; + +/** + * Places autocomplete helper. + * + * @author GeLo + */ +class PlacesAutocompleteHelper extends AbstractHelper +{ + /** + * Renders the autocomplete. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * + * @return string The rendered autocomplete. + */ + public function render(Autocomplete $autocomplete) + { + return $this->renderHtml($autocomplete).$this->renderJavascript($autocomplete); + } + + /** + * Renders the html. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * + * @return string The rendered html. + */ + public function renderHtml(Autocomplete $autocomplete) + { + return $this->doRender($autocomplete, PlacesAutocompleteEvents::HTML); + } + + /** + * Renders the javascript. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * + * @return string The rendered javascript. + */ + public function renderJavascript(Autocomplete $autocomplete) + { + return $this->doRender($autocomplete, PlacesAutocompleteEvents::JAVASCRIPT); + } + + /** + * Does the rendering of a places autocomplete event. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * @param string $eventName The event name. + * + * @return string The rendered places autocomplete event. + */ + protected function doRender(Autocomplete $autocomplete, $eventName) + { + $this->eventDispatcher->dispatch($eventName, $autocompleteEvent = new PlacesAutocompleteEvent($autocomplete)); + + return $autocompleteEvent->getCode(); + } +} diff --git a/src/Helper/AbstractHelper.php b/src/Helpers/Renderers/AbstractJsonRenderer.php similarity index 55% rename from src/Helper/AbstractHelper.php rename to src/Helpers/Renderers/AbstractJsonRenderer.php index c5d68135..c4931b74 100644 --- a/src/Helper/AbstractHelper.php +++ b/src/Helpers/Renderers/AbstractJsonRenderer.php @@ -9,33 +9,28 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper; +namespace Ivory\GoogleMap\Helpers\Renderers; -use Ivory\GoogleMap\Map; use Ivory\JsonBuilder\JsonBuilder; /** - * Abstract helper. + * Abstract json renderer. * * @author GeLo */ -abstract class AbstractHelper +abstract class AbstractJsonRenderer { - /** @var \Ivory\GoogleMap\Helper\Utils\JsonBuilder */ + /** @var \Ivory\JsonBuilder\JsonBuilder */ protected $jsonBuilder; /** - * Creates an helper. + * Creates an abstract json renderer. * - * @param \Ivory\JsonBuilder\JsonBuilder $jsonBuilder The json builder. + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. */ public function __construct(JsonBuilder $jsonBuilder = null) { - if ($jsonBuilder === null) { - $jsonBuilder = new JsonBuilder(); - } - - $this->setJsonBuilder($jsonBuilder); + $this->setJsonBuilder($jsonBuilder ?: new JsonBuilder()); } /** @@ -57,16 +52,4 @@ public function setJsonBuilder(JsonBuilder $jsonBuilder) { $this->jsonBuilder = $jsonBuilder; } - - /** - * Gets the javascript container name according to the map. - * - * @param \Ivory\GoogleMap\Map $map The map. - * - * @return string The javascript container name. - */ - protected function getJsContainerName(Map $map) - { - return $map->getJavascriptVariable().'_container'; - } } diff --git a/src/Helpers/Renderers/Base/BoundRenderer.php b/src/Helpers/Renderers/Base/BoundRenderer.php new file mode 100644 index 00000000..75255d18 --- /dev/null +++ b/src/Helpers/Renderers/Base/BoundRenderer.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Base\Bound; + +/** + * Bound renderer. + * + * @author GeLo + */ +class BoundRenderer +{ + /** + * Renders a bound. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. + * + * @return string The rendered bound. + */ + public function render(Bound $bound) + { + if (!$bound->hasCoordinates()) { + return 'new google.maps.LatLngBounds()'; + } + + return sprintf( + 'new google.maps.LatLngBounds(%s,%s)', + $bound->getSouthWest()->getVariable(), + $bound->getNorthEast()->getVariable() + ); + } +} diff --git a/src/Helper/Base/CoordinateHelper.php b/src/Helpers/Renderers/Base/CoordinateRenderer.php similarity index 68% rename from src/Helper/Base/CoordinateHelper.php rename to src/Helpers/Renderers/Base/CoordinateRenderer.php index 3d8da451..515fb09a 100644 --- a/src/Helper/Base/CoordinateHelper.php +++ b/src/Helpers/Renderers/Base/CoordinateRenderer.php @@ -9,32 +9,31 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Base; +namespace Ivory\GoogleMap\Helpers\Renderers\Base; use Ivory\GoogleMap\Base\Coordinate; /** - * Coordinate templating helper. + * Coordinate renderer. * * @author GeLo */ -class CoordinateHelper +class CoordinateRenderer { /** * Renders a coordinate. * * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. * - * @return string The JS output. + * @return string The rendered coordinate. */ public function render(Coordinate $coordinate) { return sprintf( - '%s = new google.maps.LatLng(%s, %s, %s);'.PHP_EOL, - $coordinate->getJavascriptVariable(), + 'new google.maps.LatLng(%s,%s,%s)', $coordinate->getLatitude(), $coordinate->getLongitude(), - json_encode($coordinate->isNoWrap()) + $coordinate->isNoWrap() ? 'true' : 'false' ); } } diff --git a/src/Helper/Base/PointHelper.php b/src/Helpers/Renderers/Base/PointRenderer.php similarity index 62% rename from src/Helper/Base/PointHelper.php rename to src/Helpers/Renderers/Base/PointRenderer.php index cd3def82..f99489a5 100644 --- a/src/Helper/Base/PointHelper.php +++ b/src/Helpers/Renderers/Base/PointRenderer.php @@ -9,31 +9,26 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Base; +namespace Ivory\GoogleMap\Helpers\Renderers\Base; use Ivory\GoogleMap\Base\Point; /** - * Point helper. + * Point renderer. * * @author GeLo */ -class PointHelper +class PointRenderer { /** * Renders a point. * * @param \Ivory\GoogleMap\Base\Point $point The point. * - * @return string The JS output. + * @return string The rendered point. */ public function render(Point $point) { - return sprintf( - '%s = new google.maps.Point(%s, %s);'.PHP_EOL, - $point->getJavascriptVariable(), - $point->getX(), - $point->getY() - ); + return sprintf('new google.maps.Point(%s,%s)', $point->getX(), $point->getY()); } } diff --git a/src/Helpers/Renderers/Base/SizeRenderer.php b/src/Helpers/Renderers/Base/SizeRenderer.php new file mode 100644 index 00000000..95b482bb --- /dev/null +++ b/src/Helpers/Renderers/Base/SizeRenderer.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Base\Size; + +/** + * Size renderer. + * + * @author GeLo + */ +class SizeRenderer +{ + /** + * Renders a size. + * + * @param \Ivory\GoogleMap\Base\Size $size The size. + * + * @return string The rendered size. + */ + public function render(Size $size) + { + return sprintf( + 'new google.maps.Size(%s,%s,%s,%s)', + $size->getWidth(), + $size->getHeight(), + $size->hasWidthUnit() ? '"'.$size->getWidthUnit().'"' : 'null', + $size->hasHeightUnit() ? '"'.$size->getHeightUnit().'"' : 'null' + ); + } +} diff --git a/src/Helpers/Renderers/Controls/ControlPositionRenderer.php b/src/Helpers/Renderers/Controls/ControlPositionRenderer.php new file mode 100644 index 00000000..8b7053c5 --- /dev/null +++ b/src/Helpers/Renderers/Controls/ControlPositionRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +/** + * Control position renderer. + * + * @author GeLo + */ +class ControlPositionRenderer +{ + /** + * Renders a control position. + * + * @param string $controlPosition The control position. + * + * @return The rendered control position. + */ + public function render($controlPosition) + { + return 'google.maps.ControlPosition.'.strtoupper($controlPosition); + } +} diff --git a/src/Helpers/Renderers/Controls/ControlsRenderer.php b/src/Helpers/Renderers/Controls/ControlsRenderer.php new file mode 100644 index 00000000..da631d35 --- /dev/null +++ b/src/Helpers/Renderers/Controls/ControlsRenderer.php @@ -0,0 +1,267 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Map; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Controls renderer. + * + * @author GeLo + */ +class ControlsRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer */ + protected $mapTypeControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer */ + protected $overviewMapControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer */ + protected $panControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer */ + protected $rotateControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer */ + protected $scaleControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer */ + protected $streetViewControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer */ + protected $zoomControlRenderer; + + /** + * Creates a controls renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer|null $mapTypeControlRenderer The map type control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer|null $overviewMapControlRenderer The overview map control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer|null $panControlRenderer The pan control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer|null $rotateControlRenderer The rotate control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer|null $scaleControlRenderer The scale control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer|null $streetViewControlRenderer The street view control renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer|null $zoomControlRenderer The zoom control renderer. + */ + public function __construct( + MapTypeControlRenderer $mapTypeControlRenderer = null, + OverviewMapControlRenderer $overviewMapControlRenderer = null, + PanControlRenderer $panControlRenderer = null, + RotateControlRenderer $rotateControlRenderer = null, + ScaleControlRenderer $scaleControlRenderer = null, + StreetViewControlRenderer $streetViewControlRenderer = null, + ZoomControlRenderer $zoomControlRenderer = null + ) { + $this->setMapTypeControlRenderer($mapTypeControlRenderer ?: new MapTypeControlRenderer()); + $this->setOverviewMapControlRenderer($overviewMapControlRenderer ?: new OverviewMapControlRenderer()); + $this->setPanControlRenderer($panControlRenderer ?: new PanControlRenderer()); + $this->setRotateControlRenderer($rotateControlRenderer ?: new RotateControlRenderer()); + $this->setScaleControlRenderer($scaleControlRenderer ?: new ScaleControlRenderer()); + $this->setStreetViewControlRenderer($streetViewControlRenderer ?: new StreetViewControlRenderer()); + $this->setZoomControlRenderer($zoomControlRenderer ?: new ZoomControlRenderer()); + } + + /** + * Gets the map type control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer The map type control renderer. + */ + public function getMapTypeControlRenderer() + { + return $this->mapTypeControlRenderer; + } + + /** + * Sets the map type control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer $mapTypeControlRenderer The map type control renderer. + */ + public function setMapTypeControlRenderer(MapTypeControlRenderer $mapTypeControlRenderer) + { + $this->mapTypeControlRenderer = $mapTypeControlRenderer; + } + + /** + * Gets the overview map control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer The overview map control renderer. + */ + public function getOverviewMapControlRenderer() + { + return $this->overviewMapControlRenderer; + } + + /** + * Sets the overview map control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer $overviewMapControlRenderer The overview map control renderer. + */ + public function setOverviewMapControlRenderer(OverviewMapControlRenderer $overviewMapControlRenderer) + { + $this->overviewMapControlRenderer = $overviewMapControlRenderer; + } + + /** + * Gets the pan control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer The pan control renderer. + */ + public function getPanControlRenderer() + { + return $this->panControlRenderer; + } + + /** + * Sets the pan control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer $panControlRenderer The pan control renderer. + */ + public function setPanControlRenderer(PanControlRenderer $panControlRenderer) + { + $this->panControlRenderer = $panControlRenderer; + } + + /** + * Gets the rotate control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer The rotate control renderer. + */ + public function getRotateControlRenderer() + { + return $this->rotateControlRenderer; + } + + /** + * Sets the rotate control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer $rotateControlRenderer The rotate control renderer. + */ + public function setRotateControlRenderer(RotateControlRenderer $rotateControlRenderer) + { + $this->rotateControlRenderer = $rotateControlRenderer; + } + + /** + * Gets the scale control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer The scale control renderer. + */ + public function getScaleControlRenderer() + { + return $this->scaleControlRenderer; + } + + /** + * Sets the scale control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer $scaleControlRenderer The scale control renderer. + */ + public function setScaleControlRenderer(ScaleControlRenderer $scaleControlRenderer) + { + $this->scaleControlRenderer = $scaleControlRenderer; + } + + /** + * Gets the street view control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer The street view control renderer. + */ + public function getStreetViewControlRenderer() + { + return $this->streetViewControlRenderer; + } + + /** + * Sets the street view control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer $streetViewControlRenderer The street view control renderer. + */ + public function setStreetViewControlRenderer(StreetViewControlRenderer $streetViewControlRenderer) + { + $this->streetViewControlRenderer = $streetViewControlRenderer; + } + + /** + * Gets the zoom control renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer The zoom control renderer. + */ + public function getZoomControlRenderer() + { + return $this->zoomControlRenderer; + } + + /** + * Sets the zoom control renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer $zoomControlRenderer The zoom control renderer. + */ + public function setZoomControlRenderer(ZoomControlRenderer $zoomControlRenderer) + { + $this->zoomControlRenderer = $zoomControlRenderer; + } + + /** + * Renders a controls. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param \Ivory\JsonBuilder\JsonBuilder $jsonBuilder The json builder. + */ + public function render(Map $map, JsonBuilder $jsonBuilder) + { + $controls = array( + 'MapTypeControl', + 'OverviewMapControl', + 'PanControl', + 'RotateControl', + 'ScaleControl', + 'StreetViewControl', + 'ZoomControl', + ); + + foreach ($controls as $control) { + $this->renderControl($control, $map, $jsonBuilder); + } + } + + /** + * Renders a control. + * + * @param string $control The control. + * @param \Ivory\GoogleMap\Map $map The map. + * @param \Ivory\JsonBuilder\JsonBuilder $jsonBuilder The json builder. + */ + protected function renderControl($control, Map $map, JsonBuilder $jsonBuilder) + { + $controlProperty = lcfirst($control); + $hasControlProperty = $map->hasMapOption($controlProperty); + $hasControl = $map->getControls()->{'has'.$control}(); + + if (!$hasControlProperty && !$hasControl) { + return; + } + + $jsonBuilder->setValue( + sprintf('[%s]', $controlProperty), + ($hasControlProperty && $map->getMapOption($controlProperty)) || $hasControl + ); + + if ($hasControl) { + $jsonBuilder->setValue( + sprintf('[%sOptions]', $controlProperty), + $this->{$controlProperty.'Renderer'}->render($map->getControls()->{'get'.$control}()), + false + ); + } + } +} diff --git a/src/Helpers/Renderers/Controls/MapTypeControlRenderer.php b/src/Helpers/Renderers/Controls/MapTypeControlRenderer.php new file mode 100644 index 00000000..7473435b --- /dev/null +++ b/src/Helpers/Renderers/Controls/MapTypeControlRenderer.php @@ -0,0 +1,148 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\MapTypeControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Map type control renderer. + * + * @author GeLo + */ +class MapTypeControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer */ + protected $mapTypeIdRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer */ + protected $mapTypeControlStyleRenderer; + + /** + * Creates a map type control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer|null $mapTypeIdRenderer The map type id renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|null $controlPositionRenderer The control position renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer|null $mapTypeControlStyleRenderer The map type control style renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + MapTypeIdRenderer $mapTypeIdRenderer = null, + ControlPositionRenderer $controlPositionRenderer = null, + MapTypeControlStyleRenderer $mapTypeControlStyleRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setMapTypeIdRenderer($mapTypeIdRenderer ?: new MapTypeIdRenderer()); + $this->setControlPositionRenderer($controlPositionRenderer ?: new ControlPositionRenderer()); + $this->setMapTypeControlStyleRenderer($mapTypeControlStyleRenderer ?: new MapTypeControlStyleRenderer()); + } + + /** + * Gets the map type id renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer The map type id renderer. + */ + public function getMapTypeIdRenderer() + { + return $this->mapTypeIdRenderer; + } + + /** + * Sets the map type id renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer $mapTypeIdRenderer The map type id renderer. + */ + public function setMapTypeIdRenderer(MapTypeIdRenderer $mapTypeIdRenderer) + { + $this->mapTypeIdRenderer = $mapTypeIdRenderer; + } + + /** + * Gets the control position renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer The control position renderer. + */ + public function getControlPositionRenderer() + { + return $this->controlPositionRenderer; + } + + /** + * Sets the control position renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) + { + $this->controlPositionRenderer = $controlPositionRenderer; + } + + /** + * Gets the map type control style renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer The map type control style renderer. + */ + public function getMapTypeControlStyleRenderer() + { + return $this->mapTypeControlStyleRenderer; + } + + /** + * Sets the map type control style renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer $mapTypeControlStyleRenderer The map type control style renderer. + */ + public function setMapTypeControlStyleRenderer(MapTypeControlStyleRenderer $mapTypeControlStyleRenderer) + { + $this->mapTypeControlStyleRenderer = $mapTypeControlStyleRenderer; + } + + /** + * Renders a map type control. + * + * @param \Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl The map type control. + * + * @return string The rendered map type control. + */ + public function render(MapTypeControl $mapTypeControl) + { + $this->jsonBuilder->reset(); + + foreach ($mapTypeControl->getMapTypeIds() as $index => $mapTypeId) { + $this->jsonBuilder->setValue( + sprintf('[mapTypeIds][%d]', $index), + $this->mapTypeIdRenderer->render($mapTypeId), + false + ); + } + + return $this->jsonBuilder + ->setValue( + '[position]', + $this->controlPositionRenderer->render($mapTypeControl->getControlPosition()), + false + ) + ->setValue( + '[style]', + $this->mapTypeControlStyleRenderer->render($mapTypeControl->getMapTypeControlStyle()), + false + ) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/MapTypeControlStyleRenderer.php b/src/Helpers/Renderers/Controls/MapTypeControlStyleRenderer.php new file mode 100644 index 00000000..c573d17a --- /dev/null +++ b/src/Helpers/Renderers/Controls/MapTypeControlStyleRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +/** + * Map type control style renderer. + * + * @author GeLo + */ +class MapTypeControlStyleRenderer +{ + /** + * Renders a map type control style. + * + * @param string $mapTypeControlStyle The map type control style. + * + * @return string The rendered map type control style. + */ + public function render($mapTypeControlStyle) + { + return 'google.maps.MapTypeControlStyle.'.strtoupper($mapTypeControlStyle); + } +} diff --git a/src/Helper/Controls/OverviewMapControlHelper.php b/src/Helpers/Renderers/Controls/OverviewMapControlRenderer.php similarity index 73% rename from src/Helper/Controls/OverviewMapControlHelper.php rename to src/Helpers/Renderers/Controls/OverviewMapControlRenderer.php index 1923dd1b..b5fa282a 100644 --- a/src/Helper/Controls/OverviewMapControlHelper.php +++ b/src/Helpers/Renderers/Controls/OverviewMapControlRenderer.php @@ -9,24 +9,24 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Controls; +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; use Ivory\GoogleMap\Controls\OverviewMapControl; -use Ivory\GoogleMap\Helper\AbstractHelper; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Overview map control helper. + * Overview map control renderer. * * @author GeLo */ -class OverviewMapControlHelper extends AbstractHelper +class OverviewMapControlRenderer extends AbstractJsonRenderer { /** * Renders an overview map control. * * @param \Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl The overview map control. * - * @return string The JS output. + * @return string The rendered overview map control. */ public function render(OverviewMapControl $overviewMapControl) { diff --git a/src/Helpers/Renderers/Controls/PanControlRenderer.php b/src/Helpers/Renderers/Controls/PanControlRenderer.php new file mode 100644 index 00000000..f1b78c00 --- /dev/null +++ b/src/Helpers/Renderers/Controls/PanControlRenderer.php @@ -0,0 +1,77 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\PanControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Pan control renderer. + * + * @author GeLo + */ +class PanControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** + * Creates a pan control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|null $controlPositionRenderer The control position renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + ControlPositionRenderer $controlPositionRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setControlPositionRenderer($controlPositionRenderer ?: new ControlPositionRenderer()); + } + + /** + * Gets the control position renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer The control position renderer. + */ + public function getControlPositionRenderer() + { + return $this->controlPositionRenderer; + } + + /** + * Sets the control position renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) + { + $this->controlPositionRenderer = $controlPositionRenderer; + } + + /** + * Renders a pan control. + * + * @param \Ivory\GoogleMap\Controls\PanControl $panControl The pan control. + * + * @return string The rendered pan control. + */ + public function render(PanControl $panControl) + { + return $this->jsonBuilder + ->reset() + ->setValue('[position]', $this->controlPositionRenderer->render($panControl->getControlPosition()), false) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/RotateControlRenderer.php b/src/Helpers/Renderers/Controls/RotateControlRenderer.php new file mode 100644 index 00000000..88181110 --- /dev/null +++ b/src/Helpers/Renderers/Controls/RotateControlRenderer.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\RotateControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Rotate control renderer. + * + * @author GeLo + */ +class RotateControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** + * Creates a rotate control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|null $controlPositionRenderer The control position renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + ControlPositionRenderer $controlPositionRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setControlPositionRenderer($controlPositionRenderer ?: new ControlPositionRenderer()); + } + + /** + * Gets the control position renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer The control position renderer. + */ + public function getControlPositionRenderer() + { + return $this->controlPositionRenderer; + } + + /** + * Sets the control position renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) + { + $this->controlPositionRenderer = $controlPositionRenderer; + } + + /** + * Renders a rotate control. + * + * @param \Ivory\GoogleMap\Controls\RotateControl $rotateControl The rotate control. + * + * @return string The rendered rotate control. + */ + public function render(RotateControl $rotateControl) + { + return $this->jsonBuilder + ->reset() + ->setValue( + '[position]', + $this->controlPositionRenderer->render($rotateControl->getControlPosition()), + false + ) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/ScaleControlRenderer.php b/src/Helpers/Renderers/Controls/ScaleControlRenderer.php new file mode 100644 index 00000000..80526825 --- /dev/null +++ b/src/Helpers/Renderers/Controls/ScaleControlRenderer.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ScaleControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Scale control renderer. + * + * @author GeLo + */ +class ScaleControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControleStyleRenderer */ + protected $scaleControlStyleRenderer; + + /** + * Creates a scale control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControleStyleRenderer|null $scaleControlStyleRenderer The scale control style renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + ScaleControlStyleRenderer $scaleControlStyleRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setScaleControlStyleRenderer($scaleControlStyleRenderer ?: new ScaleControlStyleRenderer()); + } + + /** + * Gets the scale control style renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer The scale control style renderer. + */ + public function getScaleControlStyleRenderer() + { + return $this->scaleControlStyleRenderer; + } + + /** + * Sets the scale control style renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer $scaleControlStyleRenderer The scale control style renderer. + */ + public function setScaleControlStyleRenderer(ScaleControlStyleRenderer $scaleControlStyleRenderer) + { + $this->scaleControlStyleRenderer = $scaleControlStyleRenderer; + } + + /** + * Renders a scale control. + * + * @param \Ivory\GoogleMap\Controls\ScaleControl $scaleControl The scale control. + * + * @return string The rendered scale control. + */ + public function render(ScaleControl $scaleControl) + { + return $this->jsonBuilder + ->reset() + ->setValue( + '[style]', + $this->scaleControlStyleRenderer->render($scaleControl->getScaleControlStyle()), + false + ) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/ScaleControlStyleRenderer.php b/src/Helpers/Renderers/Controls/ScaleControlStyleRenderer.php new file mode 100644 index 00000000..3569fe7d --- /dev/null +++ b/src/Helpers/Renderers/Controls/ScaleControlStyleRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +/** + * Scale control style renderer. + * + * @author GeLo + */ +class ScaleControlStyleRenderer +{ + /** + * Renders a scale control style. + * + * @param string $scaleControlStyle The scale control style. + * + * @return string The rendered scale control style. + */ + public function render($scaleControlStyle) + { + return 'google.maps.ScaleControlStyle.'.strtoupper($scaleControlStyle); + } +} diff --git a/src/Helpers/Renderers/Controls/StreetViewControlRenderer.php b/src/Helpers/Renderers/Controls/StreetViewControlRenderer.php new file mode 100644 index 00000000..5b139716 --- /dev/null +++ b/src/Helpers/Renderers/Controls/StreetViewControlRenderer.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\StreetViewControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Street view control renderer. + * + * @author GeLo + */ +class StreetViewControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** + * Creates a street view control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|null $controlPositionRenderer The control position renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + ControlPositionRenderer $controlPositionRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setControlPositionRenderer($controlPositionRenderer ?: new ControlPositionRenderer()); + } + + /** + * Gets the control position renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer The control position renderer. + */ + public function getControlPositionRenderer() + { + return $this->controlPositionRenderer; + } + + /** + * Sets the control position renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) + { + $this->controlPositionRenderer = $controlPositionRenderer; + } + + /** + * Renders a street view control. + * + * @param \Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl The street view control. + * + * @return string The rendered street view control. + */ + public function render(StreetViewControl $streetViewControl) + { + return $this->jsonBuilder + ->reset() + ->setValue( + '[position]', + $this->controlPositionRenderer->render($streetViewControl->getControlPosition()), + false + ) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/ZoomControlRenderer.php b/src/Helpers/Renderers/Controls/ZoomControlRenderer.php new file mode 100644 index 00000000..5cd75086 --- /dev/null +++ b/src/Helpers/Renderers/Controls/ZoomControlRenderer.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ZoomControl; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Zoom control renderer. + * + * @author GeLo + */ +class ZoomControlRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** @var \vory\GoogleMap\Templating\Renderer\Controls\ZoomControlStyleRenderer */ + protected $zoomControlStyleRenderer; + + /** + * Create a zoom control renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|null $controlPositionRenderer The control position renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer|null $zoomControlStyleRenderer The zoom control style renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + ControlPositionRenderer $controlPositionRenderer = null, + ZoomControlStyleRenderer $zoomControlStyleRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setControlPositionRenderer($controlPositionRenderer ?: new ControlPositionRenderer()); + $this->setZoomControlStyleRenderer($zoomControlStyleRenderer ?: new ZoomControlStyleRenderer()); + } + + /** + * Gets the control position renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer The control position renderer. + */ + public function getControlPositionRenderer() + { + return $this->controlPositionRenderer; + } + + /** + * Sets the control position renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + public function setControlPositionRenderer(ControlPositionRenderer $controlPositionRenderer) + { + $this->controlPositionRenderer = $controlPositionRenderer; + } + + /** + * Gets the zoom control style renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer The zoom control style renderer. + */ + public function getZoomControlStyleRenderer() + { + return $this->zoomControlStyleRenderer; + } + + /** + * Sets the zoom control style renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer $zoomControlStyleRenderer The zoom control style renderer. + */ + public function setZoomControlStyleRenderer(ZoomControlStyleRenderer $zoomControlStyleRenderer) + { + $this->zoomControlStyleRenderer = $zoomControlStyleRenderer; + } + + /** + * Renders a zoom control. + * + * @param \Ivory\GoogleMap\Controls\ZoomControl $zoomControl The zoom control. + * + * @return string The rendered zoom control. + */ + public function render(ZoomControl $zoomControl) + { + return $this->jsonBuilder + ->reset() + ->setValue('[position]', $this->controlPositionRenderer->render($zoomControl->getControlPosition()), false) + ->setValue('[style]', $this->zoomControlStyleRenderer->render($zoomControl->getZoomControlStyle()), false) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Controls/ZoomControlStyleRenderer.php b/src/Helpers/Renderers/Controls/ZoomControlStyleRenderer.php new file mode 100644 index 00000000..f749ccfa --- /dev/null +++ b/src/Helpers/Renderers/Controls/ZoomControlStyleRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Controls; + +/** + * Zoom control style renderer. + * + * @author GeLo + */ +class ZoomControlStyleRenderer +{ + /** + * Renders a zoom control style. + * + * @param string $zoomControlStyle The zoom control style. + * + * @return string The rendered zoom control style. + */ + public function render($zoomControlStyle) + { + return 'google.maps.ZoomControlStyle.'.strtoupper($zoomControlStyle); + } +} diff --git a/src/Helpers/Renderers/Events/DomEventOnceRenderer.php b/src/Helpers/Renderers/Events/DomEventOnceRenderer.php new file mode 100644 index 00000000..035d803b --- /dev/null +++ b/src/Helpers/Renderers/Events/DomEventOnceRenderer.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\DomEvent; + +/** + * Dom event once renderer. + * + * @author GeLo + */ +class DomEventOnceRenderer +{ + /** + * Renders a dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event once. + * + * @return string The rendered dom event once. + */ + public function render(DomEvent $domEvent) + { + return sprintf( + 'google.maps.event.addDomListenerOnce(%s,"%s",%s,%s)', + $domEvent->getInstance(), + $domEvent->getEventName(), + $domEvent->getHandle(), + $domEvent->isCapture() ? 'true' : 'false' + ); + } +} diff --git a/src/Helpers/Renderers/Events/DomEventRenderer.php b/src/Helpers/Renderers/Events/DomEventRenderer.php new file mode 100644 index 00000000..5bf751ff --- /dev/null +++ b/src/Helpers/Renderers/Events/DomEventRenderer.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\Event; + +/** + * Dom event renderer. + * + * @author GeLo + */ +class DomEventRenderer +{ + /** + * Renders a dom event. + * + * @param \Ivory\GoogleMap\Events\Event $event The dom event. + * + * @return string The rendered dom event. + */ + public function render(Event $event) + { + return sprintf( + 'google.maps.event.addDomListener(%s,"%s",%s,%s)', + $event->getInstance(), + $event->getEventName(), + $event->getHandle(), + $event->isCapture() ? 'true' : 'false' + ); + } +} diff --git a/src/Helpers/Renderers/Events/EventOnceRenderer.php b/src/Helpers/Renderers/Events/EventOnceRenderer.php new file mode 100644 index 00000000..21b4247a --- /dev/null +++ b/src/Helpers/Renderers/Events/EventOnceRenderer.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\Event; + +/** + * Event once renderer. + * + * @author GeLo + */ +class EventOnceRenderer +{ + /** + * Renders an event once. + * + * @param \Ivory\GoogleMap\Events\Event $event The event once. + * + * @return string The rendered event once. + */ + public function render(Event $event) + { + return sprintf( + 'google.maps.event.addListenerOnce(%s,"%s",%s)', + $event->getInstance(), + $event->getEventName(), + $event->getHandle() + ); + } +} diff --git a/src/Helpers/Renderers/Events/EventRenderer.php b/src/Helpers/Renderers/Events/EventRenderer.php new file mode 100644 index 00000000..92043fda --- /dev/null +++ b/src/Helpers/Renderers/Events/EventRenderer.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\Event; + +/** + * Event renderer. + * + * @author GeLo + */ +class EventRenderer +{ + /** + * Renders an event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + * + * @return string The rendered event. + */ + public function render(Event $event) + { + return sprintf( + 'google.maps.event.addListener(%s,"%s",%s)', + $event->getInstance(), + $event->getEventName(), + $event->getHandle() + ); + } +} diff --git a/src/Helper/Geometry/EncodingHelper.php b/src/Helpers/Renderers/Geometry/EncodingRenderer.php similarity index 51% rename from src/Helper/Geometry/EncodingHelper.php rename to src/Helpers/Renderers/Geometry/EncodingRenderer.php index 5a02f2ef..f0ac9b15 100644 --- a/src/Helper/Geometry/EncodingHelper.php +++ b/src/Helpers/Renderers/Geometry/EncodingRenderer.php @@ -9,33 +9,25 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Geometry; - -use Ivory\GoogleMap\Exception\HelperException; +namespace Ivory\GoogleMap\Helpers\Renderers\Geometry; /** - * Encoding helper. + * Encoding renderer. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#encoding + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#encoding * @author GeLo */ -class EncodingHelper +class EncodingRenderer { /** - * Renders the decode path method. + * Renders a decode path. * * @param string $encodedPath The encoded path. * - * @throws \Ivory\GoogleMap\Exception\HelperException If the encoded path is not valid. - * - * @return string The JS output. + * @return string The rendered decode path. */ public function renderDecodePath($encodedPath) { - if (!is_string($encodedPath)) { - throw HelperException::invalidEncodedPath(); - } - return sprintf('google.maps.geometry.encoding.decodePath("%s")', addslashes($encodedPath)); } } diff --git a/src/Helpers/Renderers/Layers/KmlLayerRenderer.php b/src/Helpers/Renderers/Layers/KmlLayerRenderer.php new file mode 100644 index 00000000..75a1532c --- /dev/null +++ b/src/Helpers/Renderers/Layers/KmlLayerRenderer.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Layers; + +use Ivory\GoogleMap\Layers\KmlLayer; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; + +/** + * Kml layer renderer. + * + * @author GeLo + */ +class KmlLayerRenderer extends AbstractJsonRenderer +{ + /** + * Renders a kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered kml layer. + */ + public function render(KmlLayer $kmlLayer, Map $map) + { + $this->jsonBuilder + ->reset() + ->setValue('[map]', $map->getVariable(), false) + ->setValues($kmlLayer->getOptions()); + + return sprintf('new google.maps.KmlLayer("%s",%s)', $kmlLayer->getUrl(), $this->jsonBuilder->build()); + } +} diff --git a/src/Helpers/Renderers/LoaderRenderer.php b/src/Helpers/Renderers/LoaderRenderer.php new file mode 100644 index 00000000..0f69d6b2 --- /dev/null +++ b/src/Helpers/Renderers/LoaderRenderer.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +/** + * Loader renderer. + * + * @author GeLo + */ +class LoaderRenderer extends AbstractJsonRenderer +{ + /** + * Renders the loader. + * + * @param string $language The language + * @param array $libraries The libraries. + * @param string|null $callback The callback. + * @param boolean $sensor TRUE if the sensor is enabled else FALSE. + * + * @return string The rendered loader. + */ + public function render($language, array $libraries = array(), $callback = null, $sensor = false) + { + $parameters = array(); + + if (!empty($libraries)) { + $parameters['libraries'] = implode(',', $libraries); + } + + $parameters['language'] = $language; + $parameters['sensor'] = $sensor ? 'true' : 'false'; + + $this->jsonBuilder + ->reset() + ->setValue('[other_params]', urldecode(http_build_query($parameters))); + + if ($callback !== null) { + $this->jsonBuilder->setValue('[callback]', $callback, false); + } + + return sprintf('google.load("maps","3",%s)', $this->jsonBuilder->build()); + } + + /** + * Renders the source. + * + * @param string $callback The callback. + * + * @return string The rendered source. + */ + public function renderSource($callback) + { + return '//www.google.com/jsapi?callback='.$callback; + } +} diff --git a/src/Helpers/Renderers/MapBoundRenderer.php b/src/Helpers/Renderers/MapBoundRenderer.php new file mode 100644 index 00000000..6ca1acc9 --- /dev/null +++ b/src/Helpers/Renderers/MapBoundRenderer.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Map; + +/** + * Map bound renderer. + * + * @author GeLo + */ +class MapBoundRenderer +{ + /** + * Renders a map bound. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered map bound. + */ + public function render(Map $map) + { + return sprintf('%s.fitBounds(%s)', $map->getVariable(), $map->getBound()->getVariable()); + } +} diff --git a/src/Helpers/Renderers/MapCenterRenderer.php b/src/Helpers/Renderers/MapCenterRenderer.php new file mode 100644 index 00000000..314cdd51 --- /dev/null +++ b/src/Helpers/Renderers/MapCenterRenderer.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Map; + +/** + * Map center renderer. + * + * @author GeLo + */ +class MapCenterRenderer +{ + /** + * Renders a map center. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered map center. + */ + public function render(Map $map) + { + return sprintf('%s.setCenter(%s)', $map->getVariable(), $map->getCenter()->getVariable()); + } +} diff --git a/src/Helpers/Renderers/MapContainerRenderer.php b/src/Helpers/Renderers/MapContainerRenderer.php new file mode 100644 index 00000000..90c61171 --- /dev/null +++ b/src/Helpers/Renderers/MapContainerRenderer.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; + +/** + * Map container renderer. + * + * @author GeLo + */ +class MapContainerRenderer extends AbstractJsonRenderer +{ + /** + * Renders a map container. + * + * @param array $functions the functions. + * + * @return string The rendered map container. + */ + public function render(array $functions = array()) + { + $this->jsonBuilder + ->reset() + ->setValue('[base][coordinates]', array()) + ->setValue('[base][bounds]', array()) + ->setValue('[base][points]', array()) + ->setValue('[base][sizes]', array()) + ->setValue('[map]', null) + ->setValue('[overlays][circles]', array()) + ->setValue('[overlays][encoded_polylines]', array()) + ->setValue('[overlays][ground_overlays]', array()) + ->setValue('[overlays][polygons]', array()) + ->setValue('[overlays][polylines]', array()) + ->setValue('[overlays][rectangles]', array()) + ->setValue('[overlays][info_windows]', array()) + ->setValue('[overlays][info_boxes]', array()) + ->setValue('[overlays][icons]', array()) + ->setValue('[overlays][marker_shapes]', array()) + ->setValue('[overlays][markers]', array()) + ->setValue('[overlays][marker_cluster]', null) + ->setValue('[layers][kml_layers]', array()) + ->setValue('[events][dom_events]', array()) + ->setValue('[events][dom_events_once]', array()) + ->setValue('[events][events]', array()) + ->setValue('[events][events_once]', array()) + ->build(); + + foreach ($functions as $name => $function) { + $this->jsonBuilder->setValue('[functions]'.$name, $function, false); + } + + return $this->jsonBuilder->build(); + } +} diff --git a/src/Helpers/Renderers/MapRenderer.php b/src/Helpers/Renderers/MapRenderer.php new file mode 100644 index 00000000..d57dd3cd --- /dev/null +++ b/src/Helpers/Renderers/MapRenderer.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer; +use Ivory\GoogleMap\MapTypeId; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Map renderer. + * + * @author GeLo + */ +class MapRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer */ + protected $mapTypeIdRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer */ + protected $controlsRenderer; + + /** + * Creates a map renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer|null $mapTypeIdRenderer The map type id renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer|null $controlsRenderer The controls renderer. + */ + public function __construct( + JsonBuilder $jsonBuilder = null, + MapTypeIdRenderer $mapTypeIdRenderer = null, + ControlsRenderer $controlsRenderer = null + ) { + parent::__construct($jsonBuilder); + + $this->setMapTypeIdRenderer($mapTypeIdRenderer ?: new MapTypeIdRenderer()); + $this->setControlsRenderer($controlsRenderer ?: new ControlsRenderer()); + } + + /** + * Gets the map type id renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer The map type id renderer. + */ + public function getMapTypeIdRenderer() + { + return $this->mapTypeIdRenderer; + } + + /** + * Sets the map type id renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer $mapTypeIdRenderer The map type id renderer. + */ + public function setMapTypeIdRenderer(MapTypeIdRenderer $mapTypeIdRenderer) + { + $this->mapTypeIdRenderer = $mapTypeIdRenderer; + } + + /** + * Gets the controls renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer The controls renderer. + */ + public function getControlsRenderer() + { + return $this->controlsRenderer; + } + + /** + * Sets the controls renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer $controlsRenderer The controls renderer. + */ + public function setControlsRenderer(ControlsRenderer $controlsRenderer) + { + $this->controlsRenderer = $controlsRenderer; + } + + /** + * Renders a map. + * + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered map. + */ + public function render(Map $map) + { + $jsonBuilder = clone $this->jsonBuilder; + $jsonBuilder + ->reset() + ->setValues(array_merge(array('zoom' => 3), $map->getMapOptions())) + ->setValue( + '[mapTypeId]', + $this->mapTypeIdRenderer->render($map->getMapOption('mapTypeId') ?: MapTypeId::ROADMAP), + false + ); + + if ($map->getOverlays()->isAutoZoom()) { + $jsonBuilder->removeValue('[zoom]'); + } + + $this->controlsRenderer->render($map, $jsonBuilder); + + return sprintf( + 'new google.maps.Map(document.getElementById("%s"),%s)', + $map->getHtmlContainerId(), + $jsonBuilder->build() + ); + } +} diff --git a/src/Helpers/Renderers/MapTypeIdRenderer.php b/src/Helpers/Renderers/MapTypeIdRenderer.php new file mode 100644 index 00000000..38cdeb7c --- /dev/null +++ b/src/Helpers/Renderers/MapTypeIdRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers; + +/** + * Map type id renderer. + * + * @author GeLo + */ +class MapTypeIdRenderer +{ + /** + * Renders a map map type id. + * + * @param string $mapTypeId The map type id. + * + * @return string The rendered map type id. + */ + public function render($mapTypeId) + { + return 'google.maps.MapTypeId.'.strtoupper($mapTypeId); + } +} diff --git a/src/Helpers/Renderers/Overlays/AbstractInfoWindowRenderer.php b/src/Helpers/Renderers/Overlays/AbstractInfoWindowRenderer.php new file mode 100644 index 00000000..fa5a9e73 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/AbstractInfoWindowRenderer.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; + +/** + * Abstract info window renderer. + * + * @author GeLo + */ +abstract class AbstractInfoWindowRenderer extends AbstractJsonRenderer +{ + /** + * Renders an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + * + * @return string The rendered info window. + */ + public function render(InfoWindow $infoWindow) + { + $this->jsonBuilder->reset(); + + if ($infoWindow->hasPosition()) { + $this->jsonBuilder->setValue('[position]', $infoWindow->getPosition()->getVariable(), false); + } + + if ($infoWindow->hasPixelOffset()) { + $this->jsonBuilder->setValue( + '[pixelOffset]', + $infoWindow->getPixelOffset()->getVariable(), + false + ); + } + + $this->jsonBuilder + ->setValue('[content]', $infoWindow->getContent()) + ->setValues($infoWindow->getOptions()); + + return $this->doRender(); + } + + /** + * Does the rendering. + * + * @return string The rendered info window. + */ + abstract protected function doRender(); +} diff --git a/src/Helpers/Renderers/Overlays/AnimationRenderer.php b/src/Helpers/Renderers/Overlays/AnimationRenderer.php new file mode 100644 index 00000000..5b0255c7 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/AnimationRenderer.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +/** + * Animation renderer. + * + * @author GeLo + */ +class AnimationRenderer +{ + /** + * Renders an animation. + * + * @param string $animation The animation. + * + * @return string The rendered animation. + */ + public function render($animation) + { + return 'google.maps.Animation.'.strtoupper($animation); + } +} diff --git a/src/Helper/Overlays/CircleHelper.php b/src/Helpers/Renderers/Overlays/CircleRenderer.php similarity index 59% rename from src/Helper/Overlays/CircleHelper.php rename to src/Helpers/Renderers/Overlays/CircleRenderer.php index 8266503b..5c586347 100644 --- a/src/Helper/Overlays/CircleHelper.php +++ b/src/Helpers/Renderers/Overlays/CircleRenderer.php @@ -9,40 +9,36 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; -use Ivory\GoogleMap\Helper\AbstractHelper; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\Overlays\Circle; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Circle helper. + * Circle renderer. * * @author GeLo */ -class CircleHelper extends AbstractHelper +class CircleRenderer extends AbstractJsonRenderer { - /** + /** * Renders a circle. * * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. * @param \Ivory\GoogleMap\Map $map The map. * - * @return string The JS output. + * @return string The rendered circle. */ public function render(Circle $circle, Map $map) { $this->jsonBuilder ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValue('[center]', $circle->getCenter()->getJavascriptVariable(), false) + ->setValue('[map]', $map->getVariable(), false) + ->setValue('[center]', $circle->getCenter()->getVariable(), false) ->setValue('[radius]', $circle->getRadius()) ->setValues($circle->getOptions()); - return sprintf( - '%s = new google.maps.Circle(%s);'.PHP_EOL, - $circle->getJavascriptVariable(), - $this->jsonBuilder->build() - ); + return sprintf('new google.maps.Circle(%s)', $this->jsonBuilder->build()); } } diff --git a/src/Helpers/Renderers/Overlays/EncodedPolylineRenderer.php b/src/Helpers/Renderers/Overlays/EncodedPolylineRenderer.php new file mode 100644 index 00000000..bad1a2fc --- /dev/null +++ b/src/Helpers/Renderers/Overlays/EncodedPolylineRenderer.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\EncodedPolyline; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Encoded polyline renderer. + * + * @author GeLo + */ +class EncodedPolylineRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer */ + protected $encodingRenderer; + + /** + * Creates an encoded polyline renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer|null $encodingRenderer The encoding renderer. + */ + public function __construct(JsonBuilder $jsonBuilder = null, EncodingRenderer $encodingRenderer = null) + { + parent::__construct($jsonBuilder); + + $this->setEncodingRenderer($encodingRenderer ?: new EncodingRenderer()); + } + + /** + * Gets the encoding renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer The encoding renderer. + */ + public function getEncodingRenderer() + { + return $this->encodingRenderer; + } + + /** + * Sets the encoding renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer $encodingRenderer The encoding renderer. + */ + public function setEncodingRenderer(EncodingRenderer $encodingRenderer) + { + $this->encodingRenderer = $encodingRenderer; + } + + /** + * Renders an encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The rendered encoded polyline. + */ + public function render(EncodedPolyline $encodedPolyline, Map $map) + { + $this->jsonBuilder + ->reset() + ->setValue('[map]', $map->getVariable(), false) + ->setValue('[path]', $this->encodingRenderer->renderDecodePath($encodedPolyline->getValue()), false) + ->setValues($encodedPolyline->getOptions()); + + return sprintf('new google.maps.Polyline(%s)', $this->jsonBuilder->build()); + } +} diff --git a/src/Helpers/Renderers/Overlays/ExtendableRenderer.php b/src/Helpers/Renderers/Overlays/ExtendableRenderer.php new file mode 100644 index 00000000..568aa408 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/ExtendableRenderer.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Overlays\ExtendableInterface; + +/** + * Extendable renderer. + * + * @author GeLo + */ +class ExtendableRenderer +{ + /** + * Renders an extend. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The extend. + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. + * + * @return string The rendered extend. + */ + public function render(ExtendableInterface $extend, Bound $bound) + { + return $extend->renderExtend($bound); + } +} diff --git a/src/Helper/Overlays/GroundOverlayHelper.php b/src/Helpers/Renderers/Overlays/GroundOverlayRenderer.php similarity index 66% rename from src/Helper/Overlays/GroundOverlayHelper.php rename to src/Helpers/Renderers/Overlays/GroundOverlayRenderer.php index 889e33cc..0b41ee9f 100644 --- a/src/Helper/Overlays/GroundOverlayHelper.php +++ b/src/Helpers/Renderers/Overlays/GroundOverlayRenderer.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; -use Ivory\GoogleMap\Helper\AbstractHelper; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\Overlays\GroundOverlay; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Ground overlay helper. + * Ground overlay renderer. * * @author GeLo */ -class GroundOverlayHelper extends AbstractHelper +class GroundOverlayRenderer extends AbstractJsonRenderer { /** * Renders a ground overlay. @@ -28,20 +28,19 @@ class GroundOverlayHelper extends AbstractHelper * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. * @param \Ivory\GoogleMap\Map $map The map. * - * @return string The JS output. + * @return string The rendered ground overlay. */ public function render(GroundOverlay $groundOverlay, Map $map) { $this->jsonBuilder ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) + ->setValue('[map]', $map->getVariable(), false) ->setValues($groundOverlay->getOptions()); return sprintf( - '%s = new google.maps.GroundOverlay("%s", %s, %s);'.PHP_EOL, - $groundOverlay->getJavascriptVariable(), + 'new google.maps.GroundOverlay("%s",%s,%s)', $groundOverlay->getUrl(), - $groundOverlay->getBound()->getJavascriptVariable(), + $groundOverlay->getBound()->getVariable(), $this->jsonBuilder->build() ); } diff --git a/src/Helpers/Renderers/Overlays/IconRenderer.php b/src/Helpers/Renderers/Overlays/IconRenderer.php new file mode 100644 index 00000000..67f40c60 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/IconRenderer.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Overlays\Icon; + +/** + * Icon renderer. + * + * @author GeLo + */ +class IconRenderer extends AbstractJsonRenderer +{ + /** + * Renders an icon. + * + * @param \Ivory\GoogleMap\Overlays\Icon $icon The icon. + * + * @return string The rendered icon. + */ + public function render(Icon $icon) + { + $this->jsonBuilder + ->reset() + ->setValue('[url]', $icon->getUrl()); + + if ($icon->hasSize()) { + $this->jsonBuilder->setValue('[size]', $icon->getSize()->getVariable(), false); + } + + if ($icon->hasOrigin()) { + $this->jsonBuilder->setValue('[origin]', $icon->getOrigin()->getVariable(), false); + } + + if ($icon->hasAnchor()) { + $this->jsonBuilder->setValue('[anchor]', $icon->getAnchor()->getVariable(), false); + } + + if ($icon->hasScaledSize()) { + $this->jsonBuilder->setValue('[scaledSize]', $icon->getScaledSize()->getVariable(), false); + } + + return $this->jsonBuilder->build(); + } +} diff --git a/src/Helpers/Renderers/Overlays/InfoBoxRenderer.php b/src/Helpers/Renderers/Overlays/InfoBoxRenderer.php new file mode 100644 index 00000000..04f1ed71 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/InfoBoxRenderer.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +/** + * Info box renderer. + * + * @author GeLo + */ +class InfoBoxRenderer extends AbstractInfoWindowRenderer +{ + /** + * Renders an info box source. + * + * @return string The info box source. + */ + public function renderSource() + { + return '//google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js'; + } + + /** + * {@inheritdoc} + */ + protected function doRender() + { + return sprintf('new InfoBox(%s)', $this->jsonBuilder->build()); + } +} diff --git a/src/Helpers/Renderers/Overlays/InfoWindowCloseRenderer.php b/src/Helpers/Renderers/Overlays/InfoWindowCloseRenderer.php new file mode 100644 index 00000000..5a94381d --- /dev/null +++ b/src/Helpers/Renderers/Overlays/InfoWindowCloseRenderer.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Overlays\InfoWindow; + +/** + * Info window close renderer. + * + * @author GeLo + */ +class InfoWindowCloseRenderer +{ + /** + * Renders an info window close. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + * + * @return string The rendered info window close. + */ + public function render(InfoWindow $infoWindow) + { + return sprintf('%s.close()', $infoWindow->getVariable()); + } +} diff --git a/src/Helpers/Renderers/Overlays/InfoWindowOpenRenderer.php b/src/Helpers/Renderers/Overlays/InfoWindowOpenRenderer.php new file mode 100644 index 00000000..c920e381 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/InfoWindowOpenRenderer.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\GoogleMap\Overlays\Marker; + +/** + * Info window open renderer. + * + * @author GeLo + */ +class InfoWindowOpenRenderer +{ + /** + * Renders an info window open. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + * @param \Ivory\GoogleMap\Map $map The map. + * @param \Ivory\GoogleMap\Overlays\Marker|null $marker The marker. + * + * @return string The rendered info window open. + */ + public function render(InfoWindow $infoWindow, Map $map, Marker $marker = null) + { + $arguments = array($map->getVariable()); + + if ($marker !== null) { + $arguments[] = $marker->getVariable(); + } + + return sprintf('%s.open(%s)', $infoWindow->getVariable(), implode(',', $arguments)); + } +} diff --git a/src/Helpers/Renderers/Overlays/InfoWindowRenderer.php b/src/Helpers/Renderers/Overlays/InfoWindowRenderer.php new file mode 100644 index 00000000..7e3a8547 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/InfoWindowRenderer.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +/** + * Info window renderer. + * + * @author GeLo + */ +class InfoWindowRenderer extends AbstractInfoWindowRenderer +{ + /** + * {@inheritdoc} + */ + public function doRender() + { + return sprintf('new google.maps.InfoWindow(%s)', $this->jsonBuilder->build()); + } +} diff --git a/src/Helpers/Renderers/Overlays/MarkerClusterRenderer.php b/src/Helpers/Renderers/Overlays/MarkerClusterRenderer.php new file mode 100644 index 00000000..91df79c2 --- /dev/null +++ b/src/Helpers/Renderers/Overlays/MarkerClusterRenderer.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\MarkerCluster; + +/** + * Marker cluster renderer. + * + * @author GeLo + */ +class MarkerClusterRenderer extends AbstractJsonRenderer +{ + /** + * Renders a marker cluster. + * + * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. + * @param \Ivory\GoogleMap\Map $map The map. + * @param string $markers The markers. + * + * @return string The rendered marker cluster. + */ + public function render(MarkerCluster $markerCluster, Map $map, $markers) + { + $this->jsonBuilder + ->reset() + ->setValues($markerCluster->getOptions()); + + return sprintf('new MarkerClusterer(%s,%s,%s)', $map->getVariable(), $markers, $this->jsonBuilder->build()); + } + + /** + * Renders the marker cluster source. + * + * @return string The marker cluster source. + */ + public function renderSource() + { + return '//google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js'; + } +} diff --git a/src/Helpers/Renderers/Overlays/MarkerRenderer.php b/src/Helpers/Renderers/Overlays/MarkerRenderer.php new file mode 100644 index 00000000..187d75fd --- /dev/null +++ b/src/Helpers/Renderers/Overlays/MarkerRenderer.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\Marker; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer; +use Ivory\JsonBuilder\JsonBuilder; + +/** + * Marker renderer. + * + * @author GeLo + */ +class MarkerRenderer extends AbstractJsonRenderer +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer */ + protected $animationRenderer; + + /** + * Creates a marker renderer. + * + * @param \Ivory\JsonBuilder\JsonBuilder|null $jsonBuilder The json builder. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer|null $animationRenderer The animation renderer. + */ + public function __construct(JsonBuilder $jsonBuilder = null, AnimationRenderer $animationRenderer = null) + { + parent::__construct($jsonBuilder); + + $this->setAnimationRenderer($animationRenderer ?: new AnimationRenderer()); + } + + /** + * Gets the animation renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer The animation renderer. + */ + public function getAnimationRenderer() + { + return $this->animationRenderer; + } + + /** + * Sets the animation renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer $animationRenderer The animation renderer. + */ + public function setAnimationRenderer(AnimationRenderer $animationRenderer) + { + $this->animationRenderer = $animationRenderer; + } + + /** + * Renders a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + * @param \Ivory\GoogleMap\Map|null $map The map. + * + * @return string The rendered marker. + */ + public function render(Marker $marker, Map $map = null) + { + $this->jsonBuilder + ->reset() + ->setValue('[position]', $marker->getPosition()->getVariable(), false); + + if ($map !== null) { + $this->jsonBuilder->setValue('[map]', $map->getVariable(), false); + } + + if ($marker->hasAnimation()) { + $this->jsonBuilder->setValue( + '[animation]', + $this->animationRenderer->render($marker->getAnimation()), + false + ); + } + + if ($marker->hasIcon()) { + $this->jsonBuilder->setValue('[icon]', $marker->getIcon()->getVariable(), false); + } + + if ($marker->hasShadow()) { + $this->jsonBuilder->setValue('[shadow]', $marker->getShadow()->getVariable(), false); + } + + if ($marker->hasShape()) { + $this->jsonBuilder->setValue('[shape]', $marker->getShape()->getVariable(), false); + } + + $this->jsonBuilder->setValues($marker->getOptions()); + + return sprintf('new google.maps.Marker(%s)', $this->jsonBuilder->build()); + } +} diff --git a/src/Helper/Overlays/MarkerShapeHelper.php b/src/Helpers/Renderers/Overlays/MarkerShapeRenderer.php similarity index 55% rename from src/Helper/Overlays/MarkerShapeHelper.php rename to src/Helpers/Renderers/Overlays/MarkerShapeRenderer.php index 64dfb329..0f9e6d3d 100644 --- a/src/Helper/Overlays/MarkerShapeHelper.php +++ b/src/Helpers/Renderers/Overlays/MarkerShapeRenderer.php @@ -9,30 +9,31 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Marker shape helper. + * Marker shape renderer. * * @author GeLo */ -class MarkerShapeHelper +class MarkerShapeRenderer extends AbstractJsonRenderer { /** * Renders a marker shape. * * @param \Ivory\GoogleMap\Overlays\MarkerShape $markerShape The marker shape. * - * @return string The JS output. + * @return string The rendered marker shape. */ public function render(MarkerShape $markerShape) { - return sprintf( - '%s = new google.maps.MarkerShape(%s);'.PHP_EOL, - $markerShape->getJavascriptVariable(), - json_encode(array('type' => $markerShape->getType(), 'coords' => $markerShape->getCoordinates())) - ); + return $this->jsonBuilder + ->reset() + ->setValue('[type]', $markerShape->getType()) + ->setValue('[coords]', $markerShape->getCoordinates()) + ->build(); } } diff --git a/src/Helper/Overlays/PolygonHelper.php b/src/Helpers/Renderers/Overlays/PolygonRenderer.php similarity index 57% rename from src/Helper/Overlays/PolygonHelper.php rename to src/Helpers/Renderers/Overlays/PolygonRenderer.php index 682f993b..521346f5 100644 --- a/src/Helper/Overlays/PolygonHelper.php +++ b/src/Helpers/Renderers/Overlays/PolygonRenderer.php @@ -9,44 +9,39 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; -use Ivory\GoogleMap\Helper\AbstractHelper; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\Overlays\Polygon; /** - * Polygon helper. + * Polygon renderer. * * @author GeLo */ -class PolygonHelper extends AbstractHelper +class PolygonRenderer extends AbstractJsonRenderer { /** * Renders a polygon. * * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. - * @param \Ivory\GoogleMapl\Map $map The map. + * @param \Ivory\GoogleMap\Map $map The map. * - * @return string Ths JS output. + * @return string The rendered polygon. */ public function render(Polygon $polygon, Map $map) { $this->jsonBuilder ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValue('[paths]', array()); + ->setValue('[map]', $map->getVariable(), false); foreach ($polygon->getCoordinates() as $index => $coordinate) { - $this->jsonBuilder->setValue(sprintf('[paths][%d]', $index), $coordinate->getJavascriptVariable(), false); + $this->jsonBuilder->setValue(sprintf('[paths][%d]', $index), $coordinate->getVariable(), false); } $this->jsonBuilder->setValues($polygon->getOptions()); - return sprintf( - '%s = new google.maps.Polygon(%s);'.PHP_EOL, - $polygon->getJavascriptVariable(), - $this->jsonBuilder->build() - ); + return sprintf('new google.maps.Polygon(%s)', $this->jsonBuilder->build()); } } diff --git a/src/Helper/Overlays/PolylineHelper.php b/src/Helpers/Renderers/Overlays/PolylineRenderer.php similarity index 62% rename from src/Helper/Overlays/PolylineHelper.php rename to src/Helpers/Renderers/Overlays/PolylineRenderer.php index c9bdff2b..16620d3f 100644 --- a/src/Helper/Overlays/PolylineHelper.php +++ b/src/Helpers/Renderers/Overlays/PolylineRenderer.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; -use Ivory\GoogleMap\Helper\AbstractHelper; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\Overlays\Polyline; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Polyline helper. + * Polyline renderer. * * @author GeLo */ -class PolylineHelper extends AbstractHelper +class PolylineRenderer extends AbstractJsonRenderer { /** * Renders a polyline. @@ -28,25 +28,20 @@ class PolylineHelper extends AbstractHelper * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. * @param \Ivory\GoogleMap\Map $map The map. * - * @return string The JS output. + * @return string The rendered polyline. */ public function render(Polyline $polyline, Map $map) { $this->jsonBuilder ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValue('[path]', array()); + ->setValue('[map]', $map->getVariable(), false); foreach ($polyline->getCoordinates() as $index => $coordinate) { - $this->jsonBuilder->setValue(sprintf('[path][%d]', $index), $coordinate->getJavascriptVariable(), false); + $this->jsonBuilder->setValue(sprintf('[path][%d]', $index), $coordinate->getVariable(), false); } $this->jsonBuilder->setValues($polyline->getOptions()); - return sprintf( - '%s = new google.maps.Polyline(%s);'.PHP_EOL, - $polyline->getJavascriptVariable(), - $this->jsonBuilder->build() - ); + return sprintf('new google.maps.Polyline(%s)', $this->jsonBuilder->build()); } } diff --git a/src/Helper/Overlays/RectangleHelper.php b/src/Helpers/Renderers/Overlays/RectangleRenderer.php similarity index 58% rename from src/Helper/Overlays/RectangleHelper.php rename to src/Helpers/Renderers/Overlays/RectangleRenderer.php index f5d79382..5521987d 100644 --- a/src/Helper/Overlays/RectangleHelper.php +++ b/src/Helpers/Renderers/Overlays/RectangleRenderer.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Helper\Overlays; +namespace Ivory\GoogleMap\Helpers\Renderers\Overlays; -use Ivory\GoogleMap\Helper\AbstractHelper; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\Overlays\Rectangle; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; /** - * Rectangle helper. + * Rectangle renderer. * * @author GeLo */ -class RectangleHelper extends AbstractHelper +class RectangleRenderer extends AbstractJsonRenderer { /** * Renders a rectangle. @@ -28,20 +28,16 @@ class RectangleHelper extends AbstractHelper * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. * @param \Ivory\GoogleMap\Map $map The map. * - * @return string The JS output. + * @return string The rendered rectangle. */ public function render(Rectangle $rectangle, Map $map) { $this->jsonBuilder ->reset() - ->setValue('[map]', $map->getJavascriptVariable(), false) - ->setValue('[bounds]', $rectangle->getBound()->getJavascriptVariable(), false) + ->setValue('[map]', $map->getVariable(), false) + ->setValue('[bounds]', $rectangle->getBound()->getVariable(), false) ->setValues($rectangle->getOptions()); - return sprintf( - '%s = new google.maps.Rectangle(%s);'.PHP_EOL, - $rectangle->getJavascriptVariable(), - $this->jsonBuilder->build() - ); + return sprintf('new google.maps.Rectangle(%s)', $this->jsonBuilder->build()); } } diff --git a/src/Helpers/Renderers/Places/AutocompleteContainerRenderer.php b/src/Helpers/Renderers/Places/AutocompleteContainerRenderer.php new file mode 100644 index 00000000..8fd33cd0 --- /dev/null +++ b/src/Helpers/Renderers/Places/AutocompleteContainerRenderer.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Places; + +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; + +/** + * Autocomplete container renderer. + * + * @author GeLo + */ +class AutocompleteContainerRenderer extends AbstractJsonRenderer +{ + /** + * Renders an autocomplete container. + * + * @return string The rendered autocomplete container. + */ + public function render() + { + return $this->jsonBuilder + ->reset() + ->setValue('[base][coordinates]', array()) + ->setValue('[base][bounds]', array()) + ->setValue('[autocomplete]', null) + ->build(); + } +} diff --git a/src/Helpers/Renderers/Places/AutocompleteRenderer.php b/src/Helpers/Renderers/Places/AutocompleteRenderer.php new file mode 100644 index 00000000..26197843 --- /dev/null +++ b/src/Helpers/Renderers/Places/AutocompleteRenderer.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Renderers\Places; + +use Ivory\GoogleMap\Places\Autocomplete; +use Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer; + +/** + * Autocomplete renderer. + * + * @author GeLo + */ +class AutocompleteRenderer extends AbstractJsonRenderer +{ + /** + * Renders an autocomplete. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * + * @return string The rendered autocomplete. + */ + public function render(Autocomplete $autocomplete) + { + $this->jsonBuilder->reset(); + + if ($autocomplete->hasTypes()) { + $this->jsonBuilder->setValue('[types]', $autocomplete->getTypes()); + } + + if ($autocomplete->hasBound()) { + $this->jsonBuilder->setValue('[bounds]', $autocomplete->getBound()->getVariable(), false); + } + + if ($autocomplete->hasComponentRestrictions()) { + $this->jsonBuilder->setValue('[componentRestrictions]', $autocomplete->getComponentRestrictions()); + } + + if (!$this->jsonBuilder->hasValues()) { + $this->jsonBuilder->setJsonEncodeOptions(JSON_FORCE_OBJECT); + } + + return sprintf( + 'new google.maps.places.Autocomplete(document.getElementById(\'%s\'),%s)', + $autocomplete->getInputId(), + $this->jsonBuilder->build() + ); + } +} diff --git a/src/Helpers/Subscribers/AbstractFormatterSubscriber.php b/src/Helpers/Subscribers/AbstractFormatterSubscriber.php new file mode 100644 index 00000000..83f58a3a --- /dev/null +++ b/src/Helpers/Subscribers/AbstractFormatterSubscriber.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Abstract formatter. + * + * @author GeLo + */ +abstract class AbstractFormatterSubscriber implements EventSubscriberInterface +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Formatter */ + protected $formatter; + + /** + * Creates a formatter subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + */ + public function __construct(Formatter $formatter = null) + { + $this->setFormatter($formatter ?: new Formatter()); + } + + /** + * Gets the formatter. + * + * @return \Ivory\GoogleMap\Helpers\Subscribers\Formatter The formatter. + */ + function getFormatter() + { + return $this->formatter; + } + + /** + * Sets the formatter. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter $formatter The formatter. + */ + function setFormatter(Formatter $formatter) + { + $this->formatter = $formatter; + } +} diff --git a/src/Helpers/Subscribers/ApiJavascriptSubscriber.php b/src/Helpers/Subscribers/ApiJavascriptSubscriber.php new file mode 100644 index 00000000..69aa8918 --- /dev/null +++ b/src/Helpers/Subscribers/ApiJavascriptSubscriber.php @@ -0,0 +1,124 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Api javascript subscriber. + * + * @author GeLo + */ +class ApiJavascriptSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer */ + protected $loaderRenderer; + + /** + * Creates an api javascript subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer|null $loaderRenderer The loader renderer. + */ + public function __construct(Formatter $formatter = null, LoaderRenderer $loaderRenderer = null) + { + parent::__construct($formatter); + + $this->setLoaderRenderer($loaderRenderer ?: new LoaderRenderer()); + } + + /** + * Gets the loader renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer The loader renderer. + */ + public function getLoaderRenderer() + { + return $this->loaderRenderer; + } + + /** + * Sets the loader renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer $loaderRenderer The loader renderer. + */ + public function setLoaderRenderer(LoaderRenderer $loaderRenderer) + { + $this->loaderRenderer = $loaderRenderer; + } + + /** + * Renders the javascript api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + $apiEvent->getDispatcher()->dispatch(ApiEvents::JAVASCRIPT_MAP, $apiEvent); + $apiEvent->getDispatcher()->dispatch(ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE, $apiEvent); + + $token = str_replace('.', '', uniqid(null, true)); + + $loaderCallback = $this->formatter->formatCallback('ivory_google_map_loader_'.$token); + $apiCallback = $firstApiCallback = $lastApiCallback = $this->formatter->formatCallback( + 'ivory_google_map_api_'.$token + ); + + $sources = null; + foreach ($apiEvent->getSources() as $index => $source) { + $sources .= $this->formatter->formatFunction( + $this->formatter->formatSource( + $source, + $lastApiCallback = $apiCallback.($index + 2) + ), + array(), + $apiCallback.($index + 1) + ); + + if ($firstApiCallback === $apiCallback) { + $firstApiCallback = $apiCallback.($index + 1); + } + } + + $callbackCalls = null; + foreach ($apiEvent->getCallbacks() as $callback) { + $callbackCalls .= $this->formatter->formatFunctionCall($callback); + } + + $callbacks = $this->formatter->formatFunction($callbackCalls, array(), $lastApiCallback); + + $loader = $this->formatter->formatFunction( + $this->formatter->formatCode($this->loaderRenderer->render( + $apiEvent->getLanguage(), + $apiEvent->getLibraries(), + $firstApiCallback + )), + array(), + $loaderCallback + ); + + $apiEvent->addCode($this->formatter->formatJavascript($loader.$sources.$callbacks)); + $apiEvent->addCode($this->formatter->formatSource($this->loaderRenderer->renderSource($loaderCallback))); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(ApiEvents::JAVASCRIPT => 'onApi'); + } +} diff --git a/src/Helpers/Subscribers/Base/BaseSubscriber.php b/src/Helpers/Subscribers/Base/BaseSubscriber.php new file mode 100644 index 00000000..4a9c409c --- /dev/null +++ b/src/Helpers/Subscribers/Base/BaseSubscriber.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Base subscriber. + * + * @author GeLo + */ +class BaseSubscriber implements EventSubscriberInterface +{ + /** + * Renders the map javascript base. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_BASE_COORDINATE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_BASE_BOUND, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_BASE_POINT, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_BASE_SIZE, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_BASE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Base/BoundSubscriber.php b/src/Helpers/Subscribers/Base/BoundSubscriber.php new file mode 100644 index 00000000..5f726a5b --- /dev/null +++ b/src/Helpers/Subscribers/Base/BoundSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Bound subscriber. + * + * @author GeLo + */ +class BoundSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer */ + protected $boundRenderer; + + /** + * Creates a bound subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator|null $boundAggregator The bound aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer|null $boundRenderer The bound renderer. + */ + public function __construct( + Formatter $formatter = null, + BoundAggregator $boundAggregator = null, + BoundRenderer $boundRenderer = null + ) { + parent::__construct($formatter); + + $this->setBoundAggregator($boundAggregator ?: new BoundAggregator()); + $this->setBoundRenderer($boundRenderer ?: new BoundRenderer()); + } + + /** + * Gets the bound aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator The bound aggregator. + */ + public function getBoundAggregator() + { + return $this->boundAggregator; + } + + /** + * Sets the bound aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator $boundAggregator The bound aggregator. + */ + public function setBoundAggregator(BoundAggregator $boundAggregator) + { + $this->boundAggregator = $boundAggregator; + } + + /** + * Gets the bound renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer The bound renderer. + */ + public function getBoundRenderer() + { + return $this->boundRenderer; + } + + /** + * Sets the bound renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer $boundRenderer The bound renderer. + */ + public function setBoundRenderer(BoundRenderer $boundRenderer) + { + $this->boundRenderer = $boundRenderer; + } + + /** + * Renders the map javascript base bounds. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->boundAggregator->aggregate($map) as $bound) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->boundRenderer->render($bound), + 'base.bounds', + $bound + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_BASE_BOUND => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Base/CoordinateSubscriber.php b/src/Helpers/Subscribers/Base/CoordinateSubscriber.php new file mode 100644 index 00000000..3d037c38 --- /dev/null +++ b/src/Helpers/Subscribers/Base/CoordinateSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Coordinate subscriber. + * + * @author GeLo + */ +class CoordinateSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer */ + protected $coordinateRenderer; + + /** + * Creates a coordinate subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator|null $coordinateAggregator The coordinate aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer|null $coordinateRenderer The coordinate renderer. + */ + public function __construct( + Formatter $formatter = null, + CoordinateAggregator $coordinateAggregator = null, + CoordinateRenderer $coordinateRenderer = null + ) { + parent::__construct($formatter); + + $this->setCoordinateAggregator($coordinateAggregator ?: new CoordinateAggregator()); + $this->setCoordinateRenderer($coordinateRenderer ?: new CoordinateRenderer()); + } + + /** + * Gets the coordinate aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator The coordinate aggregator. + */ + public function getCoordinateAggregator() + { + return $this->coordinateAggregator; + } + + /** + * Sets the coordinate aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator $coordinateAggregator The coordinate aggregator. + */ + public function setCoordinateAggregator(CoordinateAggregator $coordinateAggregator) + { + $this->coordinateAggregator = $coordinateAggregator; + } + + /** + * Gets the coordinate renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer The coordinate renderer. + */ + public function getCoordinateRenderer() + { + return $this->coordinateRenderer; + } + + /** + * Sets the coordinate renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer $coordinateRenderer The coordinate renderer. + */ + public function setCoordinateRenderer(CoordinateRenderer $coordinateRenderer) + { + $this->coordinateRenderer = $coordinateRenderer; + } + + /** + * Renders the map javascript base coordinates. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->coordinateAggregator->aggregate($map) as $coordinate) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->coordinateRenderer->render($coordinate), + 'base.coordinates', + $coordinate + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_BASE_COORDINATE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Base/PointSubscriber.php b/src/Helpers/Subscribers/Base/PointSubscriber.php new file mode 100644 index 00000000..b1923c4c --- /dev/null +++ b/src/Helpers/Subscribers/Base/PointSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Point subscriber. + * + * @author GeLo + */ +class PointSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator */ + protected $pointAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer */ + protected $pointRenderer; + + /** + * Creates a point subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator|null $pointAggregator The point aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer|null $pointRenderer The point renderer. + */ + public function __construct( + Formatter $formatter = null, + PointAggregator $pointAggregator = null, + PointRenderer $pointRenderer = null + ) { + parent::__construct($formatter); + + $this->setPointAggregator($pointAggregator ?: new PointAggregator()); + $this->setPointRenderer($pointRenderer ?: new PointRenderer()); + } + + /** + * Gets the point aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator The point aggregator. + */ + public function getPointAggregator() + { + return $this->pointAggregator; + } + + /** + * Sets the point aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator $pointAggregator The point aggregator. + */ + public function setPointAggregator(PointAggregator $pointAggregator) + { + $this->pointAggregator = $pointAggregator; + } + + /** + * Gets the point renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer The point renderer. + */ + public function getPointRenderer() + { + return $this->pointRenderer; + } + + /** + * Sets the point renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer $pointRenderer The point renderer. + */ + public function setPointRenderer(PointRenderer $pointRenderer) + { + $this->pointRenderer = $pointRenderer; + } + + /** + * Renders the map javascript base points. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->pointAggregator->aggregate($map) as $point) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->pointRenderer->render($point), + 'base.points', + $point + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_BASE_POINT => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Base/SizeSubscriber.php b/src/Helpers/Subscribers/Base/SizeSubscriber.php new file mode 100644 index 00000000..bbb9c4f0 --- /dev/null +++ b/src/Helpers/Subscribers/Base/SizeSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Size subscriber. + * + * @author GeLo + */ +class SizeSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator */ + protected $sizeAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer */ + protected $sizeRenderer; + + /** + * Creates a size subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator|null $sizeAggregator The size aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer|null $sizeRenderer The size renderer. + */ + public function __construct( + Formatter $formatter = null, + SizeAggregator $sizeAggregator = null, + SizeRenderer $sizeRenderer = null + ) { + parent::__construct($formatter); + + $this->setSizeAggregator($sizeAggregator ?: new SizeAggregator()); + $this->setSizeRenderer($sizeRenderer ?: new SizeRenderer()); + } + + /** + * Gets the size aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator The size aggregator. + */ + public function getSizeAggregator() + { + return $this->sizeAggregator; + } + + /** + * Sets the size aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator $sizeAggregator The size aggregator. + */ + public function setSizeAggregator(SizeAggregator $sizeAggregator) + { + $this->sizeAggregator = $sizeAggregator; + } + + /** + * Gets the size renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer The size renderer. + */ + public function getSizeRenderer() + { + return $this->sizeRenderer; + } + + /** + * Sets the size renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer $sizeRenderer The size renderer. + */ + public function setSizeRenderer(SizeRenderer $sizeRenderer) + { + $this->sizeRenderer = $sizeRenderer; + } + + /** + * Renders the map javascript base sizes. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->sizeAggregator->aggregate($map) as $size) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->sizeRenderer->render($size), + 'base.sizes', + $size + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_BASE_SIZE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Events/DomEventOnceSubscriber.php b/src/Helpers/Subscribers/Events/DomEventOnceSubscriber.php new file mode 100644 index 00000000..1f5db5c2 --- /dev/null +++ b/src/Helpers/Subscribers/Events/DomEventOnceSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Dom event once subscriber. + * + * @author GeLo + */ +class DomEventOnceSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator */ + protected $domEventOnceAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer */ + protected $domEventOnceRenderer; + + /** + * Creates a dom event once subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator|null $domEventOnceAggregator The dom event once aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer|null $domEventOnceRenderer The dom event once renderer. + */ + public function __construct( + Formatter $formatter = null, + DomEventOnceAggregator $domEventOnceAggregator = null, + DomEventOnceRenderer $domEventOnceRenderer = null + ) { + parent::__construct($formatter); + + $this->setDomEventOnceAggregator($domEventOnceAggregator ?: new DomEventOnceAggregator()); + $this->setDomEventOnceRenderer($domEventOnceRenderer ?: new DomEventOnceRenderer()); + } + + /** + * Gets the dom event once aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator The dom event once aggregator. + */ + public function getDomEventOnceAggregator() + { + return $this->domEventOnceAggregator; + } + + /** + * Sets the dom event once aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator $domEventOnceAggregator The dom event once aggregator. + */ + public function setDomEventOnceAggregator(DomEventOnceAggregator $domEventOnceAggregator) + { + $this->domEventOnceAggregator = $domEventOnceAggregator; + } + + /** + * Gets the dom event once renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer The dom event once renderer. + */ + public function getDomEventOnceRenderer() + { + return $this->domEventOnceRenderer; + } + + /** + * Sets the dom event once renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer $domEventOnceRenderer The dom event once renderer. + */ + public function setDomEventOnceRenderer(DomEventOnceRenderer $domEventOnceRenderer) + { + $this->domEventOnceRenderer = $domEventOnceRenderer; + } + + /** + * Renders the map javascript events dom events once. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->domEventOnceAggregator->aggregate($map) as $domEventOnce) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->domEventOnceRenderer->render($domEventOnce), + 'events.dom_events_once', + $domEventOnce + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Events/DomEventSubscriber.php b/src/Helpers/Subscribers/Events/DomEventSubscriber.php new file mode 100644 index 00000000..c59553b4 --- /dev/null +++ b/src/Helpers/Subscribers/Events/DomEventSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Dom event subscriber. + * + * @author GeLo + */ +class DomEventSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator */ + protected $domEventAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer */ + protected $domEventRenderer; + + /** + * Creates a dom event subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator|null $domEventAggregator The dom event aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer|null $domEventRenderer The dom event renderer. + */ + public function __construct( + Formatter $formatter = null, + DomEventAggregator $domEventAggregator = null, + DomEventRenderer $domEventRenderer = null + ) { + parent::__construct($formatter); + + $this->setDomEventAggregator($domEventAggregator ?: new DomEventAggregator()); + $this->setDomEventRenderer($domEventRenderer ?: new DomEventRenderer()); + } + + /** + * Gets the dom event aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator The dom event aggregator. + */ + public function getDomEventAggregator() + { + return $this->domEventAggregator; + } + + /** + * Sets the dom event aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator $domEventAggregator The dom event aggregator. + */ + public function setDomEventAggregator(DomEventAggregator $domEventAggregator) + { + $this->domEventAggregator = $domEventAggregator; + } + + /** + * Gets the dom event renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer The dom event renderer. + */ + public function getDomEventRenderer() + { + return $this->domEventRenderer; + } + + /** + * Sets the dom event renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer $domEventRenderer The dom event renderer. + */ + public function setDomEventRenderer(DomEventRenderer $domEventRenderer) + { + $this->domEventRenderer = $domEventRenderer; + } + + /** + * Renders the map javascript events dom events. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->domEventAggregator->aggregate($map) as $domEvent) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->domEventRenderer->render($domEvent), + 'events.dom_events', + $domEvent + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Events/EventOnceSubscriber.php b/src/Helpers/Subscribers/Events/EventOnceSubscriber.php new file mode 100644 index 00000000..990ee4a7 --- /dev/null +++ b/src/Helpers/Subscribers/Events/EventOnceSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Event once subscriber. + * + * @author GeLo + */ +class EventOnceSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator */ + protected $eventOnceAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer */ + protected $eventOnceRenderer; + + /** + * Creates an event once subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator|null $eventOnceAggregator The event once aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer|null $eventOnceRenderer The event once renderer. + */ + public function __construct( + Formatter $formatter = null, + EventOnceAggregator $eventOnceAggregator = null, + EventOnceRenderer $eventOnceRenderer = null + ) { + parent::__construct($formatter); + + $this->setEventOnceAggregator($eventOnceAggregator ?: new EventOnceAggregator()); + $this->setEventOnceRenderer($eventOnceRenderer ?: new EventOnceRenderer()); + } + + /** + * Gets the event once aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator The event once aggregator. + */ + public function getEventOnceAggregator() + { + return $this->eventOnceAggregator; + } + + /** + * Sets the event once aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator $eventOnceAggregator The event once aggregator. + */ + public function setEventOnceAggregator(EventOnceAggregator $eventOnceAggregator) + { + $this->eventOnceAggregator = $eventOnceAggregator; + } + + /** + * Gets the event once renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer The event once renderer. + */ + public function getEventOnceRenderer() + { + return $this->eventOnceRenderer; + } + + /** + * Sets the event once renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer $eventOnceRenderer The event once renderer. + */ + public function setEventOnceRenderer(EventOnceRenderer $eventOnceRenderer) + { + $this->eventOnceRenderer = $eventOnceRenderer; + } + + /** + * Renders the map javascript events events once. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->eventOnceAggregator->aggregate($map) as $eventOnce) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->eventOnceRenderer->render($eventOnce), + 'events.events_once', + $eventOnce + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Events/EventSubscriber.php b/src/Helpers/Subscribers/Events/EventSubscriber.php new file mode 100644 index 00000000..145c2818 --- /dev/null +++ b/src/Helpers/Subscribers/Events/EventSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Event subscriber. + * + * @author GeLo + */ +class EventSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator */ + protected $eventAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer */ + protected $eventRenderer; + + /** + * Creates a event subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator|null $eventAggregator The event aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer|null $eventRenderer The event renderer. + */ + public function __construct( + Formatter $formatter = null, + EventAggregator $eventAggregator = null, + EventRenderer $eventRenderer = null + ) { + parent::__construct($formatter); + + $this->setEventAggregator($eventAggregator ?: new EventAggregator()); + $this->setEventRenderer($eventRenderer ?: new EventRenderer()); + } + + /** + * Gets the event aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator The event aggregator. + */ + public function getEventAggregator() + { + return $this->eventAggregator; + } + + /** + * Sets the event aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator $eventAggregator The event aggregator. + */ + public function setEventAggregator(EventAggregator $eventAggregator) + { + $this->eventAggregator = $eventAggregator; + } + + /** + * Gets the event renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer The event renderer. + */ + public function getEventRenderer() + { + return $this->eventRenderer; + } + + /** + * Sets the event renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer $eventRenderer The event renderer. + */ + public function setEventRenderer(EventRenderer $eventRenderer) + { + $this->eventRenderer = $eventRenderer; + } + + /** + * Renders the map javascript events events. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->eventAggregator->aggregate($map) as $event) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->eventRenderer->render($event), + 'events.events', + $event + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_EVENTS_EVENT => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Events/EventsSubscriber.php b/src/Helpers/Subscribers/Events/EventsSubscriber.php new file mode 100644 index 00000000..8da87b70 --- /dev/null +++ b/src/Helpers/Subscribers/Events/EventsSubscriber.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Events subscriber. + * + * @author GeLo + */ +class EventsSubscriber implements EventSubscriberInterface +{ + /** + * Renders the map javascript events. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_EVENTS_EVENT, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_EVENTS => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Formatter.php b/src/Helpers/Subscribers/Formatter.php new file mode 100644 index 00000000..e4299872 --- /dev/null +++ b/src/Helpers/Subscribers/Formatter.php @@ -0,0 +1,488 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Assets\AbstractVariableAsset; + +/** + * Formatter. + * + * @author GeLo + */ +class Formatter +{ + /** @var boolean */ + protected $debug; + + /** @var integer */ + protected $indentation; + + /** + * Creates a formatter. + * + * @param boolean $debug The debug flag. + * @param inteer $indentation The indentation. + */ + public function __construct($debug = false, $indentation = 4) + { + $this->setDebug($debug); + $this->setIndentation($indentation); + } + + /** + * Checks the debug flag. + * + * @return boolean The debug flag. + */ + public function isDebug() + { + return $this->debug; + } + + /** + * Sets the debug flag. + * + * @param boolean $debug The debug flag. + */ + public function setDebug($debug) + { + $this->debug = $debug; + } + + /** + * Gets the indentation. + * + * @return integer The indentation. + */ + public function getIndentation() + { + return $this->indentation; + } + + /** + * Sets the indentation. + * + * @param integer $indentation The indentation. + */ + public function setIndentation($indentation) + { + $this->indentation = $indentation; + } + + /** + * Formats a container assignment. + * + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset $container The container. + * @param string|null $code The code. + * @param string|null $level The level. + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset|null $asset The asset. + * @param boolean $append TRUE if the asset variable should be appended to the base variable. + * @param boolean $semicolon TRUE if the semicolon should be appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * + * @return string The formatted container assignment. + */ + public function formatContainerAssignment( + AbstractVariableAsset $container, + $code, + $level = null, + AbstractVariableAsset $asset = null, + $append = true, + $semicolon = true, + $format = true + ) { + return $this->formatAssignment( + $this->formatContainerVariable($container, $level, $append ? $asset : null), + $asset !== null ? $this->formatAssetAssignment($asset, $code, false, false) : $code, + $semicolon, + $format + ); + } + + /** + * Formats a container variable. + * + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset $container The base. + * @param string|null $level The level. + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset|null $asset The asset. + * + * @return string The formatted container variable. + */ + public function formatContainerVariable( + AbstractVariableAsset $container, + $level = null, + AbstractVariableAsset $asset = null + ) { + $variable = $container->getVariable().'_container'; + + if ($level !== null) { + $variable .= '.'.$level; + } + + if ($asset !== null) { + $variable .= '.'.$asset->getVariable(); + } + + return $variable; + } + + /** + * Formats an asset assignmment. + * + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset $variable The variable. + * @param string $code The code. + * @param boolean $semicolon TRUE if the semicolon should be appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * @param string $operator The operator. + * + * @return string The formatted asset assignment. + */ + public function formatAssetAssignment( + AbstractVariableAsset $variable, + $code, + $semicolon = true, + $format = true, + $operator = '=' + ) { + return $this->formatAssignment($variable->getVariable(), $code, $semicolon, $format, $operator); + } + + /** + * Formats an asset callback. + * + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset $variable The variable. + * + * @return string The formatted asset callback. + */ + public function formatAssetCallback(AbstractVariableAsset $variable) + { + return $this->formatCallback($variable->getVariable()); + } + + /** + * Formats a callback. + * + * @param string $variable The variable. + * + * @return string The formatted callback. + */ + public function formatCallback($variable) + { + return $variable.'_callback'; + } + + /** + * Formats an assignment. + * + * @param string $variable The variable. + * @param string $code The code. + * @param boolean $semicolon TRUE if the semicolon should be appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * @param string $operator The operator. + * + * @return string The formatted assignment. + */ + public function formatAssignment($variable, $code, $semicolon = true, $format = true, $operator = '=') + { + $separator = $this->formatSeparator(); + + return $this->formatCode($variable.$separator.$operator.$separator.$code, $semicolon, $format); + } + + /** + * Formats a function call. + * + * @param string $name The name. + * @param array $arguments The arguments. + * @param boolean $semicolon TRUE if the semicolon should be appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * + * @return string The formatted function call. + */ + public function formatFunctionCall($name, array $arguments = array(), $semicolon = true, $format = true) + { + return $this->formatCode( + $name.'('.implode(','.$this->formatSeparator(), $arguments).')', + $semicolon, + $format + ); + } + + /** + * Formats a function. + * + * @param string $code The code. + * @param array $arguments The arguments. + * @param string|null $name The name. + * + * @return string The formatted function. + */ + public function formatFunction( + $code, + array $arguments = array(), + $name = null, + $semicolon = true, + $formatStart = true, + $formatEnd = true + ) { + $separator = $this->formatSeparator(); + + $prototype = 'function'.($name !== null ? ' '.$name : $separator).'('.implode(','.$separator, $arguments).')'; + $prototype .= $separator.'{'; + + $function = $this->formatCode($prototype, false, $formatStart); + $function .= $formatStart ? $this->formatIndentation($code) : $code; + $function .= '}'; + + return $this->formatCode($function, $semicolon, $formatEnd); + } + + /** + * Formats a source. + * + * @param string $source The source. + * @param string|null $callback The callback. + * + * @return string The formatted source. + */ + public function formatSource($source, $callback = null) + { + if ($callback === null) { + return $this->formatJavascript(null, array('src' => $source)); + } + + $code = $this->formatAssignment( + 'var s', + $this->formatFunctionCall('document.createElement', array('"script"'), false, false) + ); + + $code .= $this->formatAssignment('s.type', '"text/javascript"'); + $code .= $this->formatAssignment('s.async', 'true'); + $code .= $this->formatAssignment('s.src', '"'.$source.'"'); + + if ($callback !== null) { + $attachEvent = 's.attachEvent'; + $addEventListener = 's.addEventListener'; + + $code .= $this->formatIf( + $attachEvent, + $this->formatFunctionCall( + $attachEvent, + array( + '"onreadystatechange"', + $this->formatFunction( + $this->formatIf( + $this->formatAssignment('s.readyState', '"complete"', false, false, '==='), + $this->formatFunctionCall($callback) + ), + array(), + null, + false, + true, + false + ), + ) + ), + array(), + $this->formatFunctionCall( + $addEventListener, + array('"load"', $callback, 'false') + ) + ); + } + + $code .= $this->formatFunctionCall( + $this->formatFunctionCall('document.getElementsByTagName', array('"head"'), false, false).'[0].appendChild', + array('s') + ); + + return $code; + } + + /** + * Formats a ternary. + * + * @param string $condition The condition. + * @param string $value1 The first value. + * @param string $value2 The second value. + * @param boolean $semicolon TRUE if the semicolon is appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * + * @return string The formatted ternary. + */ + public function formatTernary($condition, $value1, $value2, $semicolon = true, $format = true) + { + $separator = $this->formatSeparator(); + + return $this->formatCode( + $condition.$separator.'?'.$separator.$value1.$separator.':'.$separator.$value2, + $semicolon, + $format + ); + } + + /** + * Formats a if. + * + * @param string $ifCondition The if condition. + * @param string $ifCode The if code. + * @param array $elseIfs The else ifs. + * @param string|null $elseCode The else code. + * + * @return strig The formatted if. + */ + public function formatIf($ifCondition, $ifCode, array $elseIfs = array(), $elseCode = null) + { + $separator = $this->formatSeparator(); + + $code = $this->formatLine('if'.$separator.'('.$ifCondition.')'.$separator.'{'); + $code .= $this->formatIndentation($ifCode).'}'; + + foreach ($elseIfs as $elseIfCondition => $elseIfCode) { + $code .= $this->formatLine(sprintf($separator.'elseif'.$separator.'('.$elseIfCondition.')'.$separator.'{')); + $code .= $this->formatIndentation($elseIfCode).'}'; + } + + if ($elseCode !== null) { + $code .= $this->formatLine($separator.'else'.$separator.'{').$this->formatIndentation($elseCode).'}'; + } + + return $this->formatLine($code); + } + + /** + * Formats a code. + * + * @param string $code The code. + * @param boolean $semicolon TRUE if the semicolon is appended else FALSE. + * @param boolean $format TRUE if the code should be formatted else FALSE. + * + * @return string The formatted code. + */ + public function formatCode($code, $semicolon = true, $format = true) + { + if ($semicolon) { + $code .= ';'; + } + + return $format ? $this->formatLine($code) : $code; + } + + /** + * Formats a javascript. + * + * @param string $code The code. + * @param array $attributes The attributes. + * + * @return string The formatted javascript. + */ + public function formatJavascript($code, array $attributes = array()) + { + return $this->formatTag('script', $code, array_merge(array('type' => 'text/javascript'), $attributes)); + } + + /** + * Formats a stylesheet. + * + * @param string $name The node. + * @param array $items The items. + * + * @return string The formatted stylesheet. + */ + public function formatStylesheet($name, array $items) + { + $separator = $this->formatSeparator(); + + $stylesheet = null; + foreach ($items as $item => $value) { + $stylesheet .= $this->formatCode($item.':'.$separator.$value); + } + + $code = $this->formatLine($name.$separator.'{'); + $code .= $this->formatIndentation($stylesheet); + $code .= $this->formatLine('}'); + + return $this->formatTag('style', $code, array('type' => 'text/css')); + } + + /** + * Formats a tag. + * + * @param string $name The name. + * @param string|null $content The content. + * @param array $attributes The attributes. + * @param boolean $inline TRUE if the tag is inlined else FALSE. + * + * @return string The formatted tag. + */ + public function formatTag($name, $content = null, array $attributes = array(), $inline = false) + { + $tag = $name; + foreach ($attributes as $attribute => $value) { + $tag .= ' '.$attribute.'="'.$value.'"'; + } + + if ($content === null) { + if ($inline) { + return $this->formatLine('<'.$tag.' />'); + } + + return $this->formatLine('<'.$tag.'>'); + } + + return $this->formatLine('<'.$tag.'>').$this->formatIndentation($content).$this->formatLine(''); + } + + /** + * Formats an indentation. + * + * @param string $code The code. + * + * @return string The indented code. + */ + public function formatIndentation($code) + { + if (empty($code)) { + return $code; + } + + if ($this->debug) { + $indentation = str_repeat(' ', $this->indentation); + + return $indentation.preg_replace('/\n([^$])/', PHP_EOL.$indentation.'$1', $code); + } + + return $code; + } + + /** + * Formats a line. + * + * @param string $line The line. + * + * @return string The formatted line. + */ + public function formatLine($line) + { + return $this->debug ? $line.PHP_EOL : $line; + } + + /** + * Formats a separator. + * + * @return string The formatted separator. + */ + public function formatSeparator() + { + return $this->debug ? ' ' : ''; + } +} diff --git a/src/Helpers/Subscribers/Layers/KmlLayerSubscriber.php b/src/Helpers/Subscribers/Layers/KmlLayerSubscriber.php new file mode 100644 index 00000000..3f99df94 --- /dev/null +++ b/src/Helpers/Subscribers/Layers/KmlLayerSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Layers; + +use Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Kml layer subscriber. + * + * @author GeLo + */ +class KmlLayerSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator */ + protected $kmlLayerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer */ + protected $kmlLayerRenderer; + + /** + * Creates a kml layer subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator|null $kmlLayerAggregator The kml layer aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer|null $kmlLayerRenderer The kml layer renderer. + */ + public function __construct( + Formatter $formatter = null, + KmlLayerAggregator $kmlLayerAggregator = null, + KmlLayerRenderer $kmlLayerRenderer = null + ) { + parent::__construct($formatter); + + $this->setKmlLayerAggregator($kmlLayerAggregator ?: new KmlLayerAggregator()); + $this->setKmlLayerRenderer($kmlLayerRenderer ?: new KmlLayerRenderer()); + } + + /** + * Gets the kml layer aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator The kml layer aggregator. + */ + public function getKmlLayerAggregator() + { + return $this->kmlLayerAggregator; + } + + /** + * Sets the kml layer aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator $kmlLayerAggregator The kml layer aggregator. + */ + public function setKmlLayerAggregator(KmlLayerAggregator $kmlLayerAggregator) + { + $this->kmlLayerAggregator = $kmlLayerAggregator; + } + + /** + * Gets the kml layer renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer The kml layer renderer. + */ + public function getKmlLayerRenderer() + { + return $this->kmlLayerRenderer; + } + + /** + * Sets the kml layer renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer $kmlLayerRenderer The kml layer renderer. + */ + public function setKmlLayerRenderer(KmlLayerRenderer $kmlLayerRenderer) + { + $this->kmlLayerRenderer = $kmlLayerRenderer; + } + + /** + * Renders the map javascript layers kml layers. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->kmlLayerAggregator->aggregate($map) as $kmlLayer) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->kmlLayerRenderer->render($kmlLayer, $map), + 'layers.kml_layers', + $kmlLayer + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_LAYERS_KML_LAYER => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Layers/LayersSubscriber.php b/src/Helpers/Subscribers/Layers/LayersSubscriber.php new file mode 100644 index 00000000..fcdb1480 --- /dev/null +++ b/src/Helpers/Subscribers/Layers/LayersSubscriber.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Layers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Map layers subscriber. + * + * @author GeLo + */ +class LayersSubscriber implements EventSubscriberInterface +{ + /** + * Renders the map javascript layers. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_LAYERS_KML_LAYER, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_LAYERS => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapBoundSubscriber.php b/src/Helpers/Subscribers/MapBoundSubscriber.php new file mode 100644 index 00000000..afe75c4f --- /dev/null +++ b/src/Helpers/Subscribers/MapBoundSubscriber.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer; + +/** + * Map bound subscriber. + * + * @author GeLo + */ +class MapBoundSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer */ + protected $mapBoundRenderer; + + /** + * Creates a map bound subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer|null $mapBoundRenderer The map bound renderer. + */ + public function __construct(Formatter $formatter = null, MapBoundRenderer $mapBoundRenderer = null) + { + parent::__construct($formatter); + + $this->setMapBoundRenderer($mapBoundRenderer ?: new MapBoundRenderer()); + } + + /** + * Gets the map bound renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer The map bound renderer. + */ + public function getMapBoundRenderer() + { + return $this->mapBoundRenderer; + } + + /** + * Sets the map bound renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer $mapBoundRenderer The map bound renderer. + */ + public function setMapBoundRenderer(MapBoundRenderer $mapBoundRenderer) + { + $this->mapBoundRenderer = $mapBoundRenderer; + } + + /** + * Renders the map javascript bound. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + if ($map->getOverlays()->isAutoZoom()) { + $mapEvent->addCode($this->formatter->formatCode($this->mapBoundRenderer->render($map))); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH_MAP_BOUND => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapCenterSubscriber.php b/src/Helpers/Subscribers/MapCenterSubscriber.php new file mode 100644 index 00000000..0b0a261f --- /dev/null +++ b/src/Helpers/Subscribers/MapCenterSubscriber.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer; + +/** + * Map center subscriber. + * + * @author GeLo + */ +class MapCenterSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer */ + protected $mapCenterRenderer; + + /** + * Creates a map center subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer|null $mapCenterRenderer The map center renderer. + */ + public function __construct(Formatter $formatter = null, MapCenterRenderer $mapCenterRenderer = null) + { + parent::__construct($formatter); + + $this->setMapCenterRenderer($mapCenterRenderer ?: new MapCenterRenderer()); + } + + /** + * Gets the map center renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer The map center renderer. + */ + public function getMapCenterRenderer() + { + return $this->mapCenterRenderer; + } + + /** + * Sets the map center renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer $mapCenterRenderer The map center renderer. + */ + public function setMapCenterRenderer(MapCenterRenderer $mapCenterRenderer) + { + $this->mapCenterRenderer = $mapCenterRenderer; + } + + /** + * Renders the map javascript extra center. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + if (!$map->getOverlays()->isAutoZoom()) { + $mapEvent->addCode($this->formatter->formatCode($this->mapCenterRenderer->render($map))); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH_MAP_CENTER => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapContainerSubscriber.php b/src/Helpers/Subscribers/MapContainerSubscriber.php new file mode 100644 index 00000000..e182418b --- /dev/null +++ b/src/Helpers/Subscribers/MapContainerSubscriber.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer; + +/** + * Map container subscriber. + * + * @author GeLo + */ +class MapContainerSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer */ + protected $containerRenderer; + + /** + * Creates a container subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer|null $containerRenderer The container renderer. + */ + public function __construct( + Formatter $formatter = null, + MapContainerRenderer $containerRenderer = null + ) { + parent::__construct($formatter); + + $this->setContainerRenderer($containerRenderer ?: new MapContainerRenderer()); + } + + /** + * Gets the container renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer The container renderer. + */ + public function getContainerRenderer() + { + return $this->containerRenderer; + } + + /** + * Sets the container renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer $containerRenderer The container renderer. + */ + public function setContainerRenderer(MapContainerRenderer $containerRenderer) + { + $this->containerRenderer = $containerRenderer; + } + + /** + * Renders the map javascript container. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->containerRenderer->render(array( + '[info_windows][close]' => $this->formatter->formatFunction(null, array(), null, false, false, false), + '[to_array]' => $this->formatter->formatFunction( + 'var a=[];for(var k in o){a.push(o[k]);}return a;', + array('o'), + null, + false, + false, + false + ), + )) + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_INIT_CONTAINER => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapFinishSubscriber.php b/src/Helpers/Subscribers/MapFinishSubscriber.php new file mode 100644 index 00000000..d36e0b87 --- /dev/null +++ b/src/Helpers/Subscribers/MapFinishSubscriber.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Map finish subscriber. + * + * @author GeLo + */ +class MapFinishSubscriber implements EventSubscriberInterface +{ + /** + * Renders the map javascript finish. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH_EXTENDABLE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH_MAP_CENTER, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH_MAP_BOUND, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapHtmlSubscriber.php b/src/Helpers/Subscribers/MapHtmlSubscriber.php new file mode 100644 index 00000000..b7032034 --- /dev/null +++ b/src/Helpers/Subscribers/MapHtmlSubscriber.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; + +/** + * Map html subscriber. + * + * @author GeLo + */ +class MapHtmlSubscriber extends AbstractFormatterSubscriber +{ + /** + * Renders the map html. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + $mapEvent->addCode($this->formatter->formatTag( + 'div', + null, + array( + 'id' => $map->getHtmlContainerId(), + 'style' => sprintf( + 'width:%s;height:%s;', + $map->hasStylesheetOption('width') ? $map->getStylesheetOption('width') : '300px', + $map->hasStylesheetOption('height') ? $map->getStylesheetOption('height') : '300px' + ), + ) + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::HTML => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapInitSubscriber.php b/src/Helpers/Subscribers/MapInitSubscriber.php new file mode 100644 index 00000000..24351365 --- /dev/null +++ b/src/Helpers/Subscribers/MapInitSubscriber.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Map init subscriber. + * + * @author GeLo + */ +class MapInitSubscriber implements EventSubscriberInterface +{ + /** + * Initializes the map javascript. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_INIT_CONTAINER, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_INIT => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapJavascriptSubscriber.php b/src/Helpers/Subscribers/MapJavascriptSubscriber.php new file mode 100644 index 00000000..1692cb3b --- /dev/null +++ b/src/Helpers/Subscribers/MapJavascriptSubscriber.php @@ -0,0 +1,76 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; + +/** + * Map javascript subscriber. + * + * @author GeLo + */ +class MapJavascriptSubscriber extends AbstractFormatterSubscriber +{ + /** + * Configures the map javascript api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + $apiEvent->getDispatcher()->dispatch(ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE, $apiEvent); + $apiEvent->getDispatcher()->dispatch(ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW, $apiEvent); + $apiEvent->getDispatcher()->dispatch(ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER, $apiEvent); + + foreach ($apiEvent->getItems(ApiEvent::MAP) as $map) { + $apiEvent->addCallback($this->formatter->formatAssetCallback($map)); + $apiEvent->setLanguage($map->getLanguage()); + $apiEvent->addLibraries($map->getLibraries()); + } + } + + /** + * Renders the map javascript. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_INIT, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_BASE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_MAP, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_LAYERS, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_EVENTS, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_FINISH, $mapEvent); + + $mapEvent->setCode($this->formatter->formatJavascript($this->formatter->formatFunction( + $mapEvent->getCode(), + array(), + $this->formatter->formatAssetCallback($mapEvent->getMap()) + ))); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + ApiEvents::JAVASCRIPT_MAP => 'onApi', + MapEvents::JAVASCRIPT => 'onMap', + ); + } +} diff --git a/src/Helpers/Subscribers/MapStylesheetSubscriber.php b/src/Helpers/Subscribers/MapStylesheetSubscriber.php new file mode 100644 index 00000000..43c71ee0 --- /dev/null +++ b/src/Helpers/Subscribers/MapStylesheetSubscriber.php @@ -0,0 +1,49 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; + +/** + * Map stylesheet subscriber. + * + * @author GeLo + */ +class MapStylesheetSubscriber extends AbstractFormatterSubscriber +{ + /** + * Renders the map stylesheet. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + if ($map->hasStylesheetOptions()) { + $mapEvent->addCode($this->formatter->formatStylesheet( + '#'.$map->getHtmlContainerId(), + $map->getStylesheetOptions() + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::STYLESHEET => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/MapSubscriber.php b/src/Helpers/Subscribers/MapSubscriber.php new file mode 100644 index 00000000..828c9fa7 --- /dev/null +++ b/src/Helpers/Subscribers/MapSubscriber.php @@ -0,0 +1,86 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\MapRenderer; + +/** + * Map subscriber. + * + * @author GeLo + */ +class MapSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapRenderer */ + protected $mapRenderer; + + /** + * Creates a map subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\MapRenderer|null $mapRenderer The map renderer. + */ + public function __construct(Formatter $formatter = null, MapRenderer $mapRenderer = null) + { + parent::__construct($formatter); + + $this->setMapRenderer($mapRenderer ?: new MapRenderer()); + } + + /** + * Gets the map renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapRenderer The map renderer. + */ + public function getMapRenderer() + { + return $this->mapRenderer; + } + + /** + * Sets the map renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapRenderer $mapRenderer The map renderer. + */ + public function setMapRenderer(MapRenderer $mapRenderer) + { + $this->mapRenderer = $mapRenderer; + } + + /** + * Renders the javascript map. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->mapRenderer->render($map), + 'map', + $map, + false + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_MAP => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/CircleSubscriber.php b/src/Helpers/Subscribers/Overlays/CircleSubscriber.php new file mode 100644 index 00000000..3b63b909 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/CircleSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Circle subscriber. + * + * @author GeLo + */ +class CircleSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator */ + protected $circleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer */ + protected $circleRenderer; + + /** + * Creates a circle subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator|null $circleAggregator The circle aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer|null $circleRenderer The circle renderer. + */ + public function __construct( + Formatter $formatter = null, + CircleAggregator $circleAggregator = null, + CircleRenderer $circleRenderer = null + ) { + parent::__construct($formatter); + + $this->setCircleAggregator($circleAggregator ?: new CircleAggregator()); + $this->setCircleRenderer($circleRenderer ?: new CircleRenderer()); + } + + /** + * Gets the circle aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator The circle aggregator. + */ + public function getCircleAggregator() + { + return $this->circleAggregator; + } + + /** + * Sets the circle aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator $circleAggregator The circle aggregator. + */ + public function setCircleAggregator(CircleAggregator $circleAggregator) + { + $this->circleAggregator = $circleAggregator; + } + + /** + * Gets the circle renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer The circle renderer. + */ + public function getCircleRenderer() + { + return $this->circleRenderer; + } + + /** + * Sets the circle renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer $circleRenderer The circle renderer. + */ + public function setCircleRenderer(CircleRenderer $circleRenderer) + { + $this->circleRenderer = $circleRenderer; + } + + /** + * Renders the map javascript overlays circles. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->circleAggregator->aggregate($map) as $circle) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->circleRenderer->render($circle, $map), + 'overlays.circles', + $circle + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/EncodedPolylineSubscriber.php b/src/Helpers/Subscribers/Overlays/EncodedPolylineSubscriber.php new file mode 100644 index 00000000..a46cb3a9 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/EncodedPolylineSubscriber.php @@ -0,0 +1,139 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator; +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Encoded polyline subscriber. + * + * @author GeLo + */ +class EncodedPolylineSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator */ + protected $encodedPolylineAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer */ + protected $encodedPolylineRenderer; + + /** + * Creates an encoded polyline subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator|null $encodedPolylineAggregator The encoded polyline aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer|null $encodedPolylineRenderer The encoded polyline renderer. + */ + public function __construct( + Formatter $formatter = null, + EncodedPolylineAggregator $encodedPolylineAggregator = null, + EncodedPolylineRenderer $encodedPolylineRenderer = null + ) { + parent::__construct($formatter); + + $this->setEncodedPolylineAggregator($encodedPolylineAggregator ?: new EncodedPolylineAggregator()); + $this->setEncodedPolylineRenderer($encodedPolylineRenderer ?: new EncodedPolylineRenderer()); + } + + /** + * Gets the encoded polyline aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator The encoded polyline aggregator. + */ + public function getEncodedPolylineAggregator() + { + return $this->encodedPolylineAggregator; + } + + /** + * Sets the encoded polyline aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator $encodedPolylineAggregator The encoded polyline aggregator. + */ + public function setEncodedPolylineAggregator(EncodedPolylineAggregator $encodedPolylineAggregator) + { + $this->encodedPolylineAggregator = $encodedPolylineAggregator; + } + + /** + * Gets the encoded polyline renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer The encoded polyline renderer. + */ + public function getEncodedPolylineRenderer() + { + return $this->encodedPolylineRenderer; + } + + /** + * Sets the encoded polyline renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer $encodedPolylineRenderer The encoded polyline renderer. + */ + public function setEncodedPolylineRenderer(EncodedPolylineRenderer $encodedPolylineRenderer) + { + $this->encodedPolylineRenderer = $encodedPolylineRenderer; + } + + /** + * Configures the map javascript encoded polyline api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + foreach ($apiEvent->getItems(ApiEvent::MAP) as $map) { + $encodedPolylines = $this->encodedPolylineAggregator->aggregate($map); + + if (!empty($encodedPolylines)) { + $apiEvent->addLibrary('geometry'); + } + } + } + + /** + * Renders the map javascript overlays encoded polylines. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->encodedPolylineAggregator->aggregate($map) as $encodedPolyline) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->encodedPolylineRenderer->render($encodedPolyline, $map), + 'overlays.encoded_polylines', + $encodedPolyline + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE => 'onApi', + MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE => 'onMap', + ); + } +} diff --git a/src/Helpers/Subscribers/Overlays/ExtendableSubscriber.php b/src/Helpers/Subscribers/Overlays/ExtendableSubscriber.php new file mode 100644 index 00000000..aeb7d9ab --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/ExtendableSubscriber.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Extendable subscriber. + * + * @author GeLo + */ +class ExtendableSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator */ + protected $extendableAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer */ + protected $extendableRenderer; + + /** + * Creates an extendable subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator|null $extendableAggregator The extendable aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer|null $extendableRenderer The extendable renderer. + */ + public function __construct( + Formatter $formatter = null, + ExtendableAggregator $extendableAggregator = null, + ExtendableRenderer $extendableRenderer = null + ) { + parent::__construct($formatter); + + $this->setExtendableAggregator($extendableAggregator ?: new ExtendableAggregator()); + $this->setExtendableRenderer($extendableRenderer ?: new ExtendableRenderer()); + } + + /** + * Gets the extendable aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator The extendable aggregator. + */ + public function getExtendableAggregator() + { + return $this->extendableAggregator; + } + + /** + * Sets the extendable aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator $extendableAggregator The extendable aggregator. + */ + public function setExtendableAggregator(ExtendableAggregator $extendableAggregator) + { + $this->extendableAggregator = $extendableAggregator; + } + + /** + * Gets the extendable renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer The extendable renderer. + */ + public function getExtendableRenderer() + { + return $this->extendableRenderer; + } + + /** + * Sets the extendable renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer $extendableRenderer The extendable renderer. + */ + public function setExtendableRenderer(ExtendableRenderer $extendableRenderer) + { + $this->extendableRenderer = $extendableRenderer; + } + + /** + * Renders the map javascript extends. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->extendableAggregator->aggregate($map) as $extend) { + $mapEvent->addCode($this->formatter->formatCode( + $this->extendableRenderer->render($extend, $map->getBound()) + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH_EXTENDABLE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/GroundOverlaySubscriber.php b/src/Helpers/Subscribers/Overlays/GroundOverlaySubscriber.php new file mode 100644 index 00000000..d7f1c139 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/GroundOverlaySubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Ground overlay subscriber. + * + * @author GeLo + */ +class GroundOverlaySubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator */ + protected $groundOverlayAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer */ + protected $groundOverlayRenderer; + + /** + * Creates a ground overlay subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator|null $groundOverlayAggregator The ground overlay aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer|null $groundOverlayRenderer The ground overlay renderer. + */ + public function __construct( + Formatter $formatter = null, + GroundOverlayAggregator $groundOverlayAggregator = null, + GroundOverlayRenderer $groundOverlayRenderer = null + ) { + parent::__construct($formatter); + + $this->setGroundOverlayAggregator($groundOverlayAggregator ?: new GroundOverlayAggregator()); + $this->setGroundOverlayRenderer($groundOverlayRenderer ?: new GroundOverlayRenderer()); + } + + /** + * Gets the ground overlay aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator The ground overlay aggregator. + */ + public function getGroundOverlayAggregator() + { + return $this->groundOverlayAggregator; + } + + /** + * Sets the ground overlay aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator $groundOverlayAggregator The ground overlay aggregator. + */ + public function setGroundOverlayAggregator(GroundOverlayAggregator $groundOverlayAggregator) + { + $this->groundOverlayAggregator = $groundOverlayAggregator; + } + + /** + * Gets the ground overlay renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer The ground overlay renderer. + */ + public function getGroundOverlayRenderer() + { + return $this->groundOverlayRenderer; + } + + /** + * Sets the ground overlay renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer $groundOverlayRenderer The ground overlay renderer. + */ + public function setGroundOverlayRenderer(GroundOverlayRenderer $groundOverlayRenderer) + { + $this->groundOverlayRenderer = $groundOverlayRenderer; + } + + /** + * Renders the map javascript overlays ground overlays. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->groundOverlayAggregator->aggregate($map) as $groundOverlay) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->groundOverlayRenderer->render($groundOverlay, $map), + 'overlays.ground_overlays', + $groundOverlay + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/IconSubscriber.php b/src/Helpers/Subscribers/Overlays/IconSubscriber.php new file mode 100644 index 00000000..4df5b56c --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/IconSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Icon subscriber. + * + * @author GeLo + */ +class IconSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator */ + protected $iconAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer */ + protected $iconRenderer; + + /** + * Creates an icon subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator|null $iconAggregator The icon aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer|null $iconRenderer The icon renderer. + */ + public function __construct( + Formatter $formatter = null, + IconAggregator $iconAggregator = null, + IconRenderer $iconRenderer = null + ) { + parent::__construct($formatter); + + $this->setIconAggregator($iconAggregator ?: new IconAggregator()); + $this->setIconRenderer($iconRenderer ?: new IconRenderer()); + } + + /** + * Gets the icon aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator The icon aggregator. + */ + public function getIconAggregator() + { + return $this->iconAggregator; + } + + /** + * Sets the icon aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator $iconAggregator The icon aggregator. + */ + public function setIconAggregator(IconAggregator $iconAggregator) + { + $this->iconAggregator = $iconAggregator; + } + + /** + * Gets the icon renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer The icon renderer. + */ + public function getIconRenderer() + { + return $this->iconRenderer; + } + + /** + * Sets the icon renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer $iconRenderer The icon renderer. + */ + public function setIconRenderer(IconRenderer $iconRenderer) + { + $this->iconRenderer = $iconRenderer; + } + + /** + * Renders the map javascript overlays icons. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->iconAggregator->aggregate($map) as $icon) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->iconRenderer->render($icon), + 'overlays.icons', + $icon + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_ICON => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriber.php b/src/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriber.php new file mode 100644 index 00000000..d85a8c3d --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriber.php @@ -0,0 +1,126 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Info window close subscriber. + * + * @author GeLo + */ +class InfoWindowCloseSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer */ + protected $infoWindowCloseRenderer; + + /** + * Creates an info window close subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|null $infoWindowAggregator The info window aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer|null $infoWindowCloseRenderer The info window close renderer. + */ + public function __construct( + Formatter $formatter = null, + InfoWindowAggregator $infoWindowAggregator = null, + InfoWindowCloseRenderer $infoWindowCloseRenderer = null + ) { + parent::__construct($formatter); + + $this->setInfoWindowAggregator($infoWindowAggregator ?: new InfoWindowAggregator()); + $this->setInfoWindowCloseRenderer($infoWindowCloseRenderer ?: new InfoWindowCloseRenderer()); + } + + /** + * Gets the info window aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator The info window aggregator. + */ + public function getInfoWindowAggregator() + { + return $this->infoWindowAggregator; + } + + /** + * Sets the info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + public function setInfoWindowAggregator(InfoWindowAggregator $infoWindowAggregator) + { + $this->infoWindowAggregator = $infoWindowAggregator; + } + + /** + * Gets the info window close renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer The info window close renderer. + */ + public function getInfoWindowCloseRenderer() + { + return $this->infoWindowCloseRenderer; + } + + /** + * Sets the info window close renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer $infoWindowCloseRenderer The info window close renderer. + */ + public function setInfoWindowCloseRenderer(InfoWindowCloseRenderer $infoWindowCloseRenderer) + { + $this->infoWindowCloseRenderer = $infoWindowCloseRenderer; + } + + /** + * Renders the map javascript finish info window close. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + $code = null; + + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->isAutoClose()) { + $code .= $this->formatter->formatCode( + $this->infoWindowCloseRenderer->render($infoWindow) + ); + } + } + + if (!empty($code)) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->formatter->formatFunction($code, array(), null, false, true, false), + 'functions.info_windows.close' + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriber.php b/src/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriber.php new file mode 100644 index 00000000..02732589 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriber.php @@ -0,0 +1,117 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Info window open subscriber. + * + * @author GeLo + */ +class InfoWindowOpenSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer */ + protected $infoWindowOpenRenderer; + + /** + * Creates an info window open subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|null $infoWindowAggregator The info window aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer|null $infoWindowOpenRenderer The info window open renderer. + */ + public function __construct( + Formatter $formatter = null, + InfoWindowAggregator $infoWindowAggregator = null, + InfoWindowOpenRenderer $infoWindowOpenRenderer = null + ) { + parent::__construct($formatter); + + $this->setInfoWindowAggregator($infoWindowAggregator ?: new InfoWindowAggregator()); + $this->setInfoWindowOpenRenderer($infoWindowOpenRenderer ?: new InfoWindowOpenRenderer()); + } + + /** + * Gets the info window aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator The info window aggregator. + */ + public function getInfoWindowAggregator() + { + return $this->infoWindowAggregator; + } + + /** + * Sets the info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + public function setInfoWindowAggregator(InfoWindowAggregator $infoWindowAggregator) + { + $this->infoWindowAggregator = $infoWindowAggregator; + } + + /** + * Gets the info window open renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer The info window open renderer. + */ + public function getInfoWindowOpenRenderer() + { + return $this->infoWindowOpenRenderer; + } + + /** + * Sets the info window open renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer $infoWindowOpenRenderer The info window open renderer. + */ + public function setInfoWindowOpenRenderer(InfoWindowOpenRenderer $infoWindowOpenRenderer) + { + $this->infoWindowOpenRenderer = $infoWindowOpenRenderer; + } + + /** + * Renders the map javascript finish info window open. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->isOpen()) { + $mapEvent->addCode($this->formatter->formatCode( + $this->infoWindowOpenRenderer->render($infoWindow, $map) + )); + } + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/InfoWindowSubscriber.php b/src/Helpers/Subscribers/Overlays/InfoWindowSubscriber.php new file mode 100644 index 00000000..a93e57d8 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/InfoWindowSubscriber.php @@ -0,0 +1,176 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; +use Ivory\GoogleMap\Overlays\InfoWindowType; + +/** + * Info window subscriber. + * + * @author GeLo + */ +class InfoWindowSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer */ + protected $infoWindowRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer */ + protected $infoBoxRenderer; + + /** + * Creates a map info window subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|null $infoWindowAggregator The info window aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer|null $infoWindowRenderer The info window renderer. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer|null $infoBoxRenderer The info box renderer. + */ + public function __construct( + Formatter $formatter = null, + InfoWindowAggregator $infoWindowAggregator = null, + InfoWindowRenderer $infoWindowRenderer = null, + InfoBoxRenderer $infoBoxRenderer = null + ) { + parent::__construct($formatter); + + $this->setInfoWindowAggregator($infoWindowAggregator ?: new InfoWindowAggregator()); + $this->setInfoWindowRenderer($infoWindowRenderer ?: new InfoWindowRenderer()); + $this->setInfoBoxRenderer($infoBoxRenderer ?: new InfoBoxRenderer()); + } + + /** + * Gets the info window aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator The info window aggregator. + */ + public function getInfoWindowAggregator() + { + return $this->infoWindowAggregator; + } + + /** + * Sets the info window aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + public function setInfoWindowAggregator(InfoWindowAggregator $infoWindowAggregator) + { + $this->infoWindowAggregator = $infoWindowAggregator; + } + + /** + * Gets the info window renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer The info window renderer. + */ + public function getInfoWindowRenderer() + { + return $this->infoWindowRenderer; + } + + /** + * Sets the info window renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer $infoWindowRenderer The info window renderer. + */ + public function setInfoWindowRenderer(InfoWindowRenderer $infoWindowRenderer) + { + $this->infoWindowRenderer = $infoWindowRenderer; + } + + /** + * Gets the info box renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer The info box renderer. + */ + public function getInfoBoxRenderer() + { + return $this->infoBoxRenderer; + } + + /** + * Sets the info box renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer $infoBoxRenderer The info box renderer. + */ + public function setInfoBoxRenderer(InfoBoxRenderer $infoBoxRenderer) + { + $this->infoBoxRenderer = $infoBoxRenderer; + } + + /** + * Configures the map javascript info window api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + foreach ($apiEvent->getItems(ApiEvent::MAP) as $map) { + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->getType() === InfoWindowType::INFOBOX) { + $apiEvent->addSource($this->infoBoxRenderer->renderSource()); + } + } + } + } + + /** + * Renders the map javascript overlays info windows. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->infoWindowAggregator->aggregate($map) as $infoWindow) { + if ($infoWindow->getType() === InfoWindowType::INFOBOX) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->infoBoxRenderer->render($infoWindow), + 'overlays.info_boxes', + $infoWindow + )); + } else { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->infoWindowRenderer->render($infoWindow), + 'overlays.info_windows', + $infoWindow + )); + } + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW => 'onApi', + MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW => 'onMap', + ); + } +} diff --git a/src/Helpers/Subscribers/Overlays/MarkerClusterSubscriber.php b/src/Helpers/Subscribers/Overlays/MarkerClusterSubscriber.php new file mode 100644 index 00000000..7cb4af91 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/MarkerClusterSubscriber.php @@ -0,0 +1,120 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; +use Ivory\GoogleMap\Overlays\MarkerClusterType; + +/** + * Marker cluster subscriber. + * + * @author GeLo + */ +class MarkerClusterSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer */ + protected $markerClusterRenderer; + + /** + * Creates a marker cluster subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer|null $markerClusterRenderer The marker cluster renderer. + */ + public function __construct(Formatter $formatter = null, MarkerClusterRenderer $markerClusterRenderer = null) + { + parent::__construct($formatter); + + $this->setMarkerClusterRenderer($markerClusterRenderer ?: new MarkerClusterRenderer()); + } + + /** + * Gets the marker cluster renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer The marker cluster renderer. + */ + public function getMarkerClusterRenderer() + { + return $this->markerClusterRenderer; + } + + /** + * Sets the marker cluster renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer $markerClusterRenderer The marker cluster renderer. + */ + public function setMarkerClusterRenderer(MarkerClusterRenderer $markerClusterRenderer) + { + $this->markerClusterRenderer = $markerClusterRenderer; + } + + /** + * Configures the map javascript marker cluster api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + foreach ($apiEvent->getItems(ApiEvent::MAP) as $map) { + if ($map->getOverlays()->getMarkerCluster()->getType() === MarkerClusterType::MARKER_CLUSTER) { + $apiEvent->addSource($this->markerClusterRenderer->renderSource()); + } + } + } + + /** + * Renders the map javascript overlays marker cluster. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + $markerCluster = $map->getOverlays()->getMarkerCluster(); + + if ($markerCluster->getType() === MarkerClusterType::MARKER_CLUSTER) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->markerClusterRenderer->render( + $map->getOverlays()->getMarkerCluster(), + $map, + $this->formatter->formatFunctionCall( + $this->formatter->formatContainerVariable($map, 'functions.to_array'), + array($this->formatter->formatContainerVariable($map, 'overlays.markers')), + false, + false + ) + ), + 'overlays.marker_cluster', + $markerCluster, + false + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER => 'onApi', + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER => 'onMap', + ); + } +} diff --git a/src/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriber.php b/src/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriber.php new file mode 100644 index 00000000..89728c5e --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriber.php @@ -0,0 +1,144 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Events\Event; +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\Marker; + +/** + * Marker open event subscriber. + * + * @author GeLo + */ +class MarkerOpenEventSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer */ + protected $infoWindowOpenRenderer; + + /** + * Creates a marker open event subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer|null $infoWindowOpenRenderer The info window open renderer. + */ + public function __construct( + Formatter $formatter = null, + MarkerAggregator $markerAggregator = null, + InfoWindowOpenRenderer $infoWindowOpenRenderer = null + ) { + parent::__construct($formatter); + + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + $this->setInfoWindowOpenRenderer($infoWindowOpenRenderer ?: new InfoWindowOpenRenderer()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Gets the info window open renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer The info window open renderer. + */ + public function getInfoWindowOpenRenderer() + { + return $this->infoWindowOpenRenderer; + } + + /** + * Set the info window open renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer $infoWindowOpenRenderer The info window open renderer. + */ + public function setInfoWindowOpenRenderer(InfoWindowOpenRenderer $infoWindowOpenRenderer) + { + $this->infoWindowOpenRenderer = $infoWindowOpenRenderer; + } + + /** + * Initializes the map javascript marker open events. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->markerAggregator->aggregate($map) as $marker) { + if ($marker->hasInfoWindow() && $marker->getInfoWindow()->isAutoOpen()) { + $map->getEvents()->addEvent(new Event( + $marker->getVariable(), + $marker->getInfoWindow()->getOpenEvent(), + $this->createEventHandle($marker, $map) + )); + } + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT => 'onMap'); + } + + /** + * Creates the event handle. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + * @param \Ivory\GoogleMap\Map $map The map. + * + * @return string The event handle. + */ + protected function createEventHandle(Marker $marker, Map $map) + { + $code = $this->formatter->formatFunctionCall($this->formatter->formatContainerVariable( + $map, + 'functions.info_windows.close' + )); + + $code .= $this->formatter->formatCode( + $this->infoWindowOpenRenderer->render($marker->getInfoWindow(), $map, $marker) + ); + + return $this->formatter->formatFunction($code, array(), null, false, true, false); + } +} diff --git a/src/Helpers/Subscribers/Overlays/MarkerShapeSubscriber.php b/src/Helpers/Subscribers/Overlays/MarkerShapeSubscriber.php new file mode 100644 index 00000000..389d53f1 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/MarkerShapeSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Marker shape subscriber. + * + * @author GeLo + */ +class MarkerShapeSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator */ + protected $markerShapeAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer */ + protected $markerShapeRenderer; + + /** + * Creates a marker shape subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator|null $markerShapeAggregator The marker shape aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer|null $markerShapeRenderer The marker shape renderer. + */ + public function __construct( + Formatter $formatter = null, + MarkerShapeAggregator $markerShapeAggregator = null, + MarkerShapeRenderer $markerShapeRenderer = null + ) { + parent::__construct($formatter); + + $this->setMarkerShapeAggregator($markerShapeAggregator ?: new MarkerShapeAggregator()); + $this->setMarkerShapeRenderer($markerShapeRenderer ?: new MarkerShapeRenderer()); + } + + /** + * Gets the marker shape aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator The marker shape aggregator. + */ + public function getMarkerShapeAggregator() + { + return $this->markerShapeAggregator; + } + + /** + * Sets the marker shape aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator $markerShapeAggregator The marker shape aggregator. + */ + public function setMarkerShapeAggregator(MarkerShapeAggregator $markerShapeAggregator) + { + $this->markerShapeAggregator = $markerShapeAggregator; + } + + /** + * Gets the marker shape renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer The marker shape renderer. + */ + public function getMarkerShapeRenderer() + { + return $this->markerShapeRenderer; + } + + /** + * Sets the marker shape renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer $markerShapeRenderer The marker shape renderer. + */ + public function setMarkerShapeRenderer(MarkerShapeRenderer $markerShapeRenderer) + { + $this->markerShapeRenderer = $markerShapeRenderer; + } + + /** + * Renders the map javascript overlays marker shapes. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->markerShapeAggregator->aggregate($map) as $markerShape) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->markerShapeRenderer->render($markerShape), + 'overlays.marker_shapes', + $markerShape + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/MarkerSubscriber.php b/src/Helpers/Subscribers/Overlays/MarkerSubscriber.php new file mode 100644 index 00000000..6a5ba34c --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/MarkerSubscriber.php @@ -0,0 +1,122 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; +use Ivory\GoogleMap\Overlays\MarkerClusterType; + +/** + * Marker subscriber. + * + * @author GeLo + */ +class MarkerSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer */ + protected $markerRenderer; + + /** + * Creates a marker subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|null $markerAggregator The marker aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer|null $markerRenderer The marker renderer. + */ + public function __construct( + Formatter $formatter = null, + MarkerAggregator $markerAggregator = null, + MarkerRenderer $markerRenderer = null + ) { + parent::__construct($formatter); + + $this->setMarkerAggregator($markerAggregator ?: new MarkerAggregator()); + $this->setMarkerRenderer($markerRenderer ?: new MarkerRenderer()); + } + + /** + * Gets the marker aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator The marker aggregator. + */ + public function getMarkerAggregator() + { + return $this->markerAggregator; + } + + /** + * Sets the marker aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + public function setMarkerAggregator(MarkerAggregator $markerAggregator) + { + $this->markerAggregator = $markerAggregator; + } + + /** + * Gets the marker renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer The marker renderer. + */ + public function getMarkerRenderer() + { + return $this->markerRenderer; + } + + /** + * Sets the marker renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer $markerRenderer The marker renderer. + */ + public function setMarkerRenderer(MarkerRenderer $markerRenderer) + { + $this->markerRenderer = $markerRenderer; + } + + /** + * Renders the map javascript overlays markers. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->markerAggregator->aggregate($map) as $marker) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->markerRenderer->render( + $marker, + $map->getOverlays()->getMarkerCluster()->getType() === MarkerClusterType::DEFAULT_ ? $map : null + ), + 'overlays.markers', + $marker + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_MARKER => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/OverlaysSubscriber.php b/src/Helpers/Subscribers/Overlays/OverlaysSubscriber.php new file mode 100644 index 00000000..6fb76bb7 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/OverlaysSubscriber.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Overlays subscriber. + * + * @author GeLo + */ +class OverlaysSubscriber implements EventSubscriberInterface +{ + /** + * Renders the map javascript overlays. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_ICON, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_MARKER, $mapEvent); + $mapEvent->getDispatcher()->dispatch(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER, $mapEvent); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS => 'onMap'); + } + +} diff --git a/src/Helpers/Subscribers/Overlays/PolygonSubscriber.php b/src/Helpers/Subscribers/Overlays/PolygonSubscriber.php new file mode 100644 index 00000000..31788e41 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/PolygonSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Polygon subscriber. + * + * @author GeLo + */ +class PolygonSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator */ + protected $polygonAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer */ + protected $polygonRenderer; + + /** + * Creates a polygon subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator|null $polygonAggregator The polygon aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer|null $polygonRenderer The polygon renderer. + */ + public function __construct( + Formatter $formatter = null, + PolygonAggregator $polygonAggregator = null, + PolygonRenderer $polygonRenderer = null + ) { + parent::__construct($formatter); + + $this->setPolygonAggregator($polygonAggregator ?: new PolygonAggregator()); + $this->setPolygonRenderer($polygonRenderer ?: new PolygonRenderer()); + } + + /** + * Gets the polygon aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator The polygon aggregator. + */ + public function getPolygonAggregator() + { + return $this->polygonAggregator; + } + + /** + * Sets the polygon aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator $polygonAggregator The polygon aggregator. + */ + public function setPolygonAggregator(PolygonAggregator $polygonAggregator) + { + $this->polygonAggregator = $polygonAggregator; + } + + /** + * Gets the polygon renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer The polygon renderer. + */ + public function getPolygonRenderer() + { + return $this->polygonRenderer; + } + + /** + * Sets the polygon renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer $polygonRenderer The polygon renderer. + */ + public function setPolygonRenderer(PolygonRenderer $polygonRenderer) + { + $this->polygonRenderer = $polygonRenderer; + } + + /** + * Renders the map javascript overlays polygons. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->polygonAggregator->aggregate($map) as $polygon) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->polygonRenderer->render($polygon, $map), + 'overlays.polygons', + $polygon + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/PolylineSubscriber.php b/src/Helpers/Subscribers/Overlays/PolylineSubscriber.php new file mode 100644 index 00000000..c24f3839 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/PolylineSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Polyline subscriber. + * + * @author GeLo + */ +class PolylineSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator */ + protected $polylineAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer */ + protected $polylineRenderer; + + /** + * Creates a polyline subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator|null $polylineAggregator The polyline aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer|null $polylineRenderer The polyline renderer. + */ + public function __construct( + Formatter $formatter = null, + PolylineAggregator $polylineAggregator = null, + PolylineRenderer $polylineRenderer = null + ) { + parent::__construct($formatter); + + $this->setPolylineAggregator($polylineAggregator ?: new PolylineAggregator()); + $this->setPolylineRenderer($polylineRenderer ?: new PolylineRenderer()); + } + + /** + * Gets the polyline aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator The polyline aggregator. + */ + public function getPolylineAggregator() + { + return $this->polylineAggregator; + } + + /** + * Sets the polyline aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator $polylineAggregator The polyline aggregator. + */ + public function setPolylineAggregator(PolylineAggregator $polylineAggregator) + { + $this->polylineAggregator = $polylineAggregator; + } + + /** + * Gets the polyline renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer The polyline renderer. + */ + public function getPolylineRenderer() + { + return $this->polylineRenderer; + } + + /** + * Sets the polyline renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer $polylineRenderer The polyline renderer. + */ + public function setPolylineRenderer(PolylineRenderer $polylineRenderer) + { + $this->polylineRenderer = $polylineRenderer; + } + + /** + * Renders the map javascript overlays polylines. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->polylineAggregator->aggregate($map) as $polyline) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->polylineRenderer->render($polyline, $map), + 'overlays.polylines', + $polyline + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Overlays/RectangleSubscriber.php b/src/Helpers/Subscribers/Overlays/RectangleSubscriber.php new file mode 100644 index 00000000..2f855c37 --- /dev/null +++ b/src/Helpers/Subscribers/Overlays/RectangleSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator; +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Rectangle subscriber. + * + * @author GeLo + */ +class RectangleSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator */ + protected $rectangleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer */ + protected $rectangleRenderer; + + /** + * Creates a rectangle subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator|null $rectangleAggregator The rectangle aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer|null $rectangleRenderer The rectangle renderer. + */ + public function __construct( + Formatter $formatter = null, + RectangleAggregator $rectangleAggregator = null, + RectangleRenderer $rectangleRenderer = null + ) { + parent::__construct($formatter); + + $this->setRectangleAggregator($rectangleAggregator ?: new RectangleAggregator()); + $this->setRectangleRenderer($rectangleRenderer ?: new RectangleRenderer()); + } + + /** + * Gets the rectangle aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator The rectangle aggregator. + */ + public function getRectangleAggregator() + { + return $this->rectangleAggregator; + } + + /** + * Sets the rectangle aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator $rectangleAggregator The rectangle aggregator. + */ + public function setRectangleAggregator(RectangleAggregator $rectangleAggregator) + { + $this->rectangleAggregator = $rectangleAggregator; + } + + /** + * Gets the rectangle renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer The rectangle renderer. + */ + public function getRectangleRenderer() + { + return $this->rectangleRenderer; + } + + /** + * Sets the rectangle renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer $rectangleRenderer The rectangle renderer. + */ + public function setRectangleRenderer(RectangleRenderer $rectangleRenderer) + { + $this->rectangleRenderer = $rectangleRenderer; + } + + /** + * Renders the map javascript overlays rectangles. + * + * @param \Ivory\GoogleMap\Helpers\MapEvent $mapEvent The map event. + */ + public function onMap(MapEvent $mapEvent) + { + $map = $mapEvent->getMap(); + + foreach ($this->rectangleAggregator->aggregate($map) as $rectangle) { + $mapEvent->addCode($this->formatter->formatContainerAssignment( + $map, + $this->rectangleRenderer->render($rectangle, $map), + 'overlays.rectangles', + $rectangle + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE => 'onMap'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteBaseSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteBaseSubscriber.php new file mode 100644 index 00000000..63448b1b --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteBaseSubscriber.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Autocomplete base subscriber. + * + * @author GeLo + */ +class AutocompleteBaseSubscriber implements EventSubscriberInterface +{ + /** + * Renders the autocomplete javascript base. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE, + $placesAutocompleteEvent + ); + + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND, + $placesAutocompleteEvent + ); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_BASE => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteBoundSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteBoundSubscriber.php new file mode 100644 index 00000000..150127a2 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteBoundSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Autocomplete bound subscriber. + * + * @author GeLo + */ +class AutocompleteBoundSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer */ + protected $boundRenderer; + + /** + * Creates an autocomplete bound subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator|null $boundAggregator The bound aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer|null $boundRenderer The bound renderer. + */ + public function __construct( + Formatter $formatter = null, + AutocompleteBoundAggregator $boundAggregator = null, + BoundRenderer $boundRenderer = null + ) { + parent::__construct($formatter); + + $this->setBoundAggregator($boundAggregator ?: new AutocompleteBoundAggregator()); + $this->setBoundRenderer($boundRenderer ?: new BoundRenderer()); + } + + /** + * Gets the bound aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator The bound aggregator. + */ + public function getBoundAggregator() + { + return $this->boundAggregator; + } + + /** + * Sets the bound aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator $boundAggregator The bound aggregator. + */ + public function setBoundAggregator(AutocompleteBoundAggregator $boundAggregator) + { + $this->boundAggregator = $boundAggregator; + } + + /** + * Gets the bound renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer The bound renderer. + */ + public function getBoundRenderer() + { + return $this->boundRenderer; + } + + /** + * Sets the bound renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer $boundRenderer The bound renderer. + */ + public function setBoundRenderer(BoundRenderer $boundRenderer) + { + $this->boundRenderer = $boundRenderer; + } + + /** + * Renders the autocomplete javascript base bounds. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $autocomplete = $placesAutocompleteEvent->getAutocomplete(); + + foreach ($this->boundAggregator->aggregate($autocomplete) as $bound) { + $placesAutocompleteEvent->addCode($this->formatter->formatContainerAssignment( + $autocomplete, + $this->boundRenderer->render($bound), + 'base.bounds', + $bound + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteContainerSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteContainerSubscriber.php new file mode 100644 index 00000000..eda89a49 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteContainerSubscriber.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Autocomplete container subscriber. + * + * @author GeLo + */ +class AutocompleteContainerSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer */ + protected $containerRenderer; + + /** + * Creates an autocomplete container subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer|null $containerRenderer The container renderer. + */ + public function __construct( + Formatter $formatter = null, + AutocompleteContainerRenderer $containerRenderer = null + ) { + parent::__construct($formatter); + + $this->setContainerRenderer($containerRenderer ?: new AutocompleteContainerRenderer()); + } + + /** + * Gets the container renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer The container renderer. + */ + public function getContainerRenderer() + { + return $this->containerRenderer; + } + + /** + * Sets the container renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer $containerRenderer The container renderer. + */ + public function setContainerRenderer(AutocompleteContainerRenderer $containerRenderer) + { + $this->containerRenderer = $containerRenderer; + } + + /** + * Renders the autocomplete javascript container. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $autocomplete = $placesAutocompleteEvent->getAutocomplete(); + + $placesAutocompleteEvent->addCode($this->formatter->formatContainerAssignment( + $autocomplete, + $this->containerRenderer->render($autocomplete) + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriber.php new file mode 100644 index 00000000..e23be716 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriber.php @@ -0,0 +1,118 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Coordinate subscriber. + * + * @author GeLo + */ +class AutocompleteCoordinateSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer */ + protected $coordinateRenderer; + + /** + * Creates an autocomplete coordinate subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator|null $coordinateAggregator The coordinate aggregator. + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer|null $coordinateRenderer The coordinate renderer. + */ + public function __construct( + Formatter $formatter = null, + AutocompleteCoordinateAggregator $coordinateAggregator = null, + CoordinateRenderer $coordinateRenderer = null + ) { + parent::__construct($formatter); + + $this->setCoordinateAggregator($coordinateAggregator ?: new AutocompleteCoordinateAggregator()); + $this->setCoordinateRenderer($coordinateRenderer ?: new CoordinateRenderer()); + } + + /** + * Gets the coordinate aggregator. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator The coordinate aggregator. + */ + public function getCoordinateAggregator() + { + return $this->coordinateAggregator; + } + + /** + * Sets the coordinate aggregator. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator $coordinateAggregator The coordinate aggregator. + */ + public function setCoordinateAggregator(AutocompleteCoordinateAggregator $coordinateAggregator) + { + $this->coordinateAggregator = $coordinateAggregator; + } + + /** + * Gets the coordinate renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer The coordinate renderer. + */ + public function getCoordinateRenderer() + { + return $this->coordinateRenderer; + } + + /** + * Sets the coordinate renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer $coordinateRenderer The coordinate renderer. + */ + public function setCoordinateRenderer(CoordinateRenderer $coordinateRenderer) + { + $this->coordinateRenderer = $coordinateRenderer; + } + + /** + * Renders the autocomplete javascript base coordinates. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $autocomplete = $placesAutocompleteEvent->getAutocomplete(); + + foreach ($this->coordinateAggregator->aggregate($autocomplete) as $coordinate) { + $placesAutocompleteEvent->addCode($this->formatter->formatContainerAssignment( + $autocomplete, + $this->coordinateRenderer->render($coordinate), + 'base.coordinates', + $coordinate + )); + } + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteHtmlSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteHtmlSubscriber.php new file mode 100644 index 00000000..04e30723 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteHtmlSubscriber.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; + +/** + * Autocomplete html subscriber. + * + * @author GeLo + */ +class AutocompleteHtmlSubscriber extends AbstractFormatterSubscriber +{ + /** + * Renders the autocomplete html. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $autocomplete = $placesAutocompleteEvent->getAutocomplete(); + + $attributes = array( + 'id' => $autocomplete->getInputId(), + 'type' => 'text' + ); + + if ($autocomplete->hasValue()) { + $attributes['value'] = $autocomplete->getValue(); + } + + $placesAutocompleteEvent->addCode($this->formatter->formatTag( + 'input', + null, + array_merge($attributes, $autocomplete->getInputAttributes()), + true + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::HTML => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteInitSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteInitSubscriber.php new file mode 100644 index 00000000..6d94b45b --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteInitSubscriber.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Symfony\Component\EventDispatcher\EventSubscriberInterface; + +/** + * Autocomplete init subscriber. + * + * @author GeLo + */ +class AutocompleteInitSubscriber implements EventSubscriberInterface +{ + /** + * Renders the autocomplete javascript init. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER, + $placesAutocompleteEvent + ); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_INIT => 'onAutocomplete'); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriber.php new file mode 100644 index 00000000..b57003d1 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriber.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; + +/** + * Autocomplete javascript subscriber. + * + * @author GeLo + */ +class AutocompleteJavascriptSubscriber extends AbstractFormatterSubscriber +{ + /** + * Configures the autocomplete javascript api. + * + * @param \Ivory\GoogleMap\Helpers\ApiEvent $apiEvent The api event. + */ + public function onApi(ApiEvent $apiEvent) + { + foreach ($apiEvent->getItems(ApiEvent::PLACES_AUTOCOMPLETE) as $autocomplete) { + $apiEvent->addCallback($this->formatter->formatAssetCallback($autocomplete)); + $apiEvent->addLibrary('places'); + } + } + + /** + * Renders the autocomplete javascript. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_INIT, + $placesAutocompleteEvent + ); + + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_BASE, + $placesAutocompleteEvent + ); + + $placesAutocompleteEvent->getDispatcher()->dispatch( + PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE, + $placesAutocompleteEvent + ); + + $placesAutocompleteEvent->setCode($this->formatter->formatJavascript($this->formatter->formatFunction( + $placesAutocompleteEvent->getCode(), + array(), + $this->formatter->formatAssetCallback($placesAutocompleteEvent->getAutocomplete()) + ))); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array( + ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE => 'onApi', + PlacesAutocompleteEvents::JAVASCRIPT => 'onAutocomplete', + ); + } +} diff --git a/src/Helpers/Subscribers/Places/AutocompleteSubscriber.php b/src/Helpers/Subscribers/Places/AutocompleteSubscriber.php new file mode 100644 index 00000000..fda1c038 --- /dev/null +++ b/src/Helpers/Subscribers/Places/AutocompleteSubscriber.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer; +use Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Autocomplete subscriber. + * + * @author GeLo + */ +class AutocompleteSubscriber extends AbstractFormatterSubscriber +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer */ + protected $autocompleteRenderer; + + /** + * Creates an autocomplete subscriber. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter|null $formatter The formatter. + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer|null $autocompleteRenderer The autocomplete renderer. + */ + public function __construct(Formatter $formatter = null, AutocompleteRenderer $autocompleteRenderer = null) + { + parent::__construct($formatter); + + $this->setAutocompleteRenderer($autocompleteRenderer ?: new AutocompleteRenderer()); + } + + /** + * Gets the autocomplete renderer. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer The autocomplete renderer. + */ + public function getAutocompleteRenderer() + { + return $this->autocompleteRenderer; + } + + /** + * Sets the autocomplete renderer. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer $autocompleteRenderer The autocomplete renderer. + */ + public function setAutocompleteRenderer(AutocompleteRenderer $autocompleteRenderer) + { + $this->autocompleteRenderer = $autocompleteRenderer; + } + + /** + * Renders the places autocomplete javascript. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent $placesAutocompleteEvent The places autocomplete event. + */ + public function onAutocomplete(PlacesAutocompleteEvent $placesAutocompleteEvent) + { + $autocomplete = $placesAutocompleteEvent->getAutocomplete(); + + $placesAutocompleteEvent->addCode($this->formatter->formatContainerAssignment( + $autocomplete, + $this->autocompleteRenderer->render($autocomplete), + 'autocomplete', + $autocomplete, + false + )); + } + + /** + * {@inheritdoc} + */ + public static function getSubscribedEvents() + { + return array(PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE => 'onAutocomplete'); + } +} diff --git a/src/Layers/KMLLayer.php b/src/Layers/KMLLayer.php deleted file mode 100644 index 90742134..00000000 --- a/src/Layers/KMLLayer.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Layers; - -use Ivory\GoogleMap\Assets\AbstractOptionsAsset; -use Ivory\GoogleMap\Exception\LayerException; - -/** - * KML Layer which describes a google map KML layer. - * - * @author GeLo - */ -class KMLLayer extends AbstractOptionsAsset -{ - /** @var string */ - protected $url; - - /** - * Creates a KML Layer. - * - * @param string $url The KML layer url. - */ - public function __construct($url = null) - { - parent::__construct(); - - $this->setPrefixJavascriptVariable('kml_layer_'); - - if ($url !== null) { - $this->setUrl($url); - } - } - - /** - * Gets the KML Layer URL. - * - * @return string The KML Layer URL. - */ - public function getUrl() - { - return $this->url; - } - - /** - * Sets the KML Layer URL. - * - * @param string $url The KML layer URL. - * - * @throws \Ivory\GoogleMap\Exception\LayerException If the URL is not valid. - */ - public function setUrl($url) - { - if (!is_string($url)) { - throw LayerException::invalidKmlLayerUrl(); - } - - $this->url = $url; - } -} diff --git a/src/Layers/KmlLayer.php b/src/Layers/KmlLayer.php new file mode 100644 index 00000000..dce6ede7 --- /dev/null +++ b/src/Layers/KmlLayer.php @@ -0,0 +1,58 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Layers; + +use Ivory\GoogleMap\Assets\AbstractOptionsAsset; + +/** + * Kml layer. + * + * @link https://developers.google.com/maps/documentation/javascript/reference#KmlLayer + * @author GeLo + */ +class KmlLayer extends AbstractOptionsAsset +{ + /** @var string */ + protected $url; + + /** + * Creates a kml layer. + * + * @param string $url The url. + */ + public function __construct($url) + { + parent::__construct('kml_layer_'); + + $this->setUrl($url); + } + + /** + * Gets the url. + * + * @return string The url. + */ + public function getUrl() + { + return $this->url; + } + + /** + * Sets the url. + * + * @param string $url The url. + */ + public function setUrl($url) + { + $this->url = $url; + } +} diff --git a/src/Layers/Layers.php b/src/Layers/Layers.php new file mode 100644 index 00000000..8c21f7fa --- /dev/null +++ b/src/Layers/Layers.php @@ -0,0 +1,120 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Layers; + +/** + * Layers. + * + * @author GeLo + */ +class Layers +{ + /** @var array */ + protected $kmlLayers = array(); + + /** + * Resets the kml layers. + */ + public function resetKmlLayers() + { + $this->kmlLayers = array(); + } + + /** + * Checks if there are kml layers. + * + * @return boolean TRUE if the are kml layers else FALSE. + */ + public function hasKmlLayers() + { + return !empty($this->kmlLayers); + } + + /** + * Gets the kml layers. + * + * @return array The kml layers. + */ + public function getKmlLayers() + { + return $this->kmlLayers; + } + + /** + * Sets the kml layers. + * + * @param array $kmlLayers The kml layers. + */ + public function setKmlLayers(array $kmlLayers) + { + $this->resetKmlLayers(); + $this->addKmlLayers($kmlLayers); + } + + /** + * Adds the kml layers. + * + * @param array $kmlLayers The kml layers. + */ + public function addKmlLayers(array $kmlLayers) + { + foreach ($kmlLayers as $kmlLayer) { + $this->addKmlLayer($kmlLayer); + } + } + + /** + * Removes the kml layers. + * + * @param array $kmlLayers The kml layers. + */ + public function removeKmlLayers(array $kmlLayers) + { + foreach ($kmlLayers as $kmlLayer) { + $this->removeKmlLayer($kmlLayer); + } + } + + /** + * Checks if there is a kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + * + * @return boolean TRUE if there is the kml layer else FALSE. + */ + public function hasKmlLayer(KmlLayer $kmlLayer) + { + return in_array($kmlLayer, $this->kmlLayers, true); + } + + /** + * Adds a kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + */ + public function addKmlLayer(KmlLayer $kmlLayer) + { + if (!$this->hasKmlLayer($kmlLayer)) { + $this->kmlLayers[] = $kmlLayer; + } + } + + /** + * Removes a kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + */ + public function removeKmlLayer(KmlLayer $kmlLayer) + { + unset($this->kmlLayers[array_search($kmlLayer, $this->kmlLayers, true)]); + } +} diff --git a/src/Map.php b/src/Map.php index f93f29ef..2007b55d 100644 --- a/src/Map.php +++ b/src/Map.php @@ -11,159 +11,75 @@ namespace Ivory\GoogleMap; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMap\Controls\OverviewMapControl; -use Ivory\GoogleMap\Controls\PanControl; -use Ivory\GoogleMap\Controls\RotateControl; -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Controls\StreetViewControl; -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Events\EventManager; -use Ivory\GoogleMap\Exception\MapException; -use Ivory\GoogleMap\Layers\KMLLayer; -use Ivory\GoogleMap\Overlays\Circle; -use Ivory\GoogleMap\Overlays\EncodedPolyline; -use Ivory\GoogleMap\Overlays\GroundOverlay; -use Ivory\GoogleMap\Overlays\InfoWindow; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\MarkerCluster; -use Ivory\GoogleMap\Overlays\Polygon; -use Ivory\GoogleMap\Overlays\Polyline; -use Ivory\GoogleMap\Overlays\Rectangle; +use Ivory\GoogleMap\Controls\Controls; +use Ivory\GoogleMap\Events\Events; +use Ivory\GoogleMap\Layers\Layers; +use Ivory\GoogleMap\Overlays\Overlays; /** - * Map wich describes a google map. + * Map. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Map + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Map * @author GeLo */ -class Map extends AbstractJavascriptVariableAsset +class Map extends AbstractVariableAsset { /** @var string */ protected $htmlContainerId; - /** @var boolean */ - protected $async; - - /** @var boolean */ - protected $autoZoom; - - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|null */ protected $center; - /** @var \Ivory\GoogleMap\Base\Bound */ + /** @var \Ivory\GoogleMap\Base\Bound|null */ protected $bound; - /** @var array */ - protected $mapOptions; - - /** @var array */ - protected $stylesheetOptions; - - /** @var \Ivory\GoogleMap\Controls\MapTypeControl */ - protected $mapTypeControl; - - /** @var \Ivory\GoogleMap\Controls\OverviewMapControl */ - protected $overviewMapControl; - - /** @var \Ivory\GoogleMap\Controls\PanControl */ - protected $panControl; - - /** @var \Ivory\GoogleMap\Controls\RotateControl */ - protected $rotateControl; - - /** @var \Ivory\GoogleMap\Controls\ScaleControl */ - protected $scaleControl; - - /** @var \Ivory\GoogleMap\Controls\StreetViewControl */ - protected $streetViewControl; + /** @var \Ivory\GoogleMap\Controls\Controls */ + protected $controls; - /** @var \Ivory\GoogleMap\Controls\ZoomControl */ - protected $zoomControl; + /** @var \Ivory\GoogleMap\Events\Events */ + protected $events; - /** @var \Ivory\GoogleMap\Events\EventManager */ - protected $eventManager; + /** @var \Ivory\GoogleMap\Layers\Layers */ + protected $layers; - /** @var \Ivory\GoogleMap\Overlays\MarkerCluster */ - protected $markerCluster; - - /** @var array */ - protected $infoWindows; - - /** @var array */ - protected $polylines; - - /** @var array */ - protected $encodedPolylines; - - /** @var array */ - protected $polygons; - - /** @var array */ - protected $rectangles; + /** @var \Ivory\GoogleMap\Overlays\Overlays */ + protected $overlays; /** @var array */ - protected $circles; + protected $mapOptions = array(); /** @var array */ - protected $groundOverlays; + protected $stylesheetOptions = array(); - /** @var array */ - protected $kmlLayers; + /** @var string */ + protected $language = 'en'; /** @var array */ - protected $libraries; - - /** @var string */ - protected $language; + protected $libraries = array(); /** * Creates a map. */ public function __construct() { - $this->setPrefixJavascriptVariable('map_'); - - $this->htmlContainerId = 'map_canvas'; - $this->async = false; - $this->autoZoom = false; - - $this->center = new Coordinate(); - $this->bound = new Bound(); - $this->eventManager = new EventManager(); + parent::__construct('map_'); - $this->mapOptions = array( - 'mapTypeId' => MapTypeId::ROADMAP, - 'zoom' => 3, - ); - - $this->stylesheetOptions = array( - 'width' => '300px', - 'height' => '300px', - ); - - $this->markerCluster = new MarkerCluster(); - - $this->infoWindows = array(); - $this->polylines = array(); - $this->encodedPolylines = array(); - $this->polygons = array(); - $this->rectangles = array(); - $this->circles = array(); - $this->groundOverlays = array(); - $this->kmlLayers = array(); - - $this->libraries = array(); - $this->language = 'en'; + $this->setHtmlContainerId($this->variable); + $this->setCenter(new Coordinate(0, 0)); + $this->setBound(new Bound()); + $this->setControls(new Controls()); + $this->setEvents(new Events()); + $this->setLayers(new Layers()); + $this->setOverlays(new Overlays()); } /** - * Gets the map HTML container ID. + * Gets the html container id. * - * @return string The map HTML constainer ID. + * @return string The html constainer id. */ public function getHtmlContainerId() { @@ -171,77 +87,19 @@ public function getHtmlContainerId() } /** - * Sets the map HTML container ID. + * Sets the html container id. * - * @param string $htmlContainerId The map HTML container ID. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the HTML container ID is not a string. + * @param string $htmlContainerId The html container id. */ public function setHtmlContainerId($htmlContainerId) { - if (!is_string($htmlContainerId)) { - throw MapException::invalidHtmlContainerId(); - } - $this->htmlContainerId = $htmlContainerId; } /** - * Check if the map loading is asynchronous. - * - * @return boolean TRUE if the map loading is asynchronous else FALSE. - */ - public function isAsync() - { - return $this->async; - } - - /** - * Sets if the map loading is asynchronous. - * - * @param boolean $async TRUE if the map loading is asynchronous else FALSE. + * Gets the center. * - * @throws \Ivory\GoogleMap\Exception\MapException If the async flag is not a boolean. - */ - public function setAsync($async) - { - if (!is_bool($async)) { - throw MapException::invalidAsync(); - } - - $this->async = $async; - } - - /** - * Check if the map autozooms. - * - * @return boolean TRUE if the map autozooms else FALSE. - */ - public function isAutoZoom() - { - return $this->autoZoom; - } - - /** - * Sets if the map autozooms. - * - * @param boolean $autoZoom TRUE if the map autozooms else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the auto zoom flag is not a boolean. - */ - public function setAutoZoom($autoZoom) - { - if (!is_bool($autoZoom)) { - throw MapException::invalidAutoZoom(); - } - - $this->autoZoom = $autoZoom; - } - - /** - * Gets the map center. - * - * @return \Ivory\GoogleMap\Base\Coordinate The map center. + * @return \Ivory\GoogleMap\Base\Coordinate|null The center. */ public function getCenter() { @@ -249,36 +107,19 @@ public function getCenter() } /** - * Sets the map center. - * - * Available prototypes: - * - function setCenter(Ivory\GoogleMap\Base\Coordinate $center) - * - function setCenter(double $latitude, double $longitude, boolean $noWrap = true) + * Sets the center. * - * @throws \Ivory\GoogleMap\Exception\MapException If the center is not valid (prototypes). + * @param \Ivory\GoogleMap\Base\Coordinate $center The center. */ - public function setCenter() + public function setCenter(Coordinate $center) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->center = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $this->center->setLatitude($args[0]); - $this->center->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->center->setNoWrap($args[2]); - } - } else { - throw MapException::invalidCenter(); - } + $this->center = $center; } /** - * Gets the map bound. + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The map bound. + * @return \Ivory\GoogleMap\Base\Bound|null The bound. */ public function getBound() { @@ -286,925 +127,425 @@ public function getBound() } /** - * Sets the map bound. - * - * Available prototypes: - * - function setBound(Ivory\GoogleMap\Base\Bound $bound = null) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - * - * @throws \Ivory\GoogleMap\Exception\MapException If the bound is not valid (prototypes). - */ - public function setBound() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Bound)) { - $this->bound = $args[0]; - } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate)) - && (isset($args[1]) && ($args[1] instanceof Coordinate)) - ) { - $this->bound->setSouthWest($args[0]); - $this->bound->setNorthEast($args[1]); - } elseif ((isset($args[0]) && is_numeric($args[0])) - && (isset($args[1]) && is_numeric($args[1])) - && (isset($args[2]) && is_numeric($args[2])) - && (isset($args[3]) && is_numeric($args[3])) - ) { - $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); - $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); - - if (isset($args[4]) && is_bool($args[4])) { - $this->bound->getSouthWest()->setNoWrap($args[4]); - } - - if (isset($args[5]) && is_bool($args[5])) { - $this->bound->getNorthEast()->setNoWrap($args[5]); - } - } elseif (!isset($args[0])) { - $this->bound->setSouthWest(null); - $this->bound->setNorthEast(null); - } else { - throw MapException::invalidBound(); - } - } - - /** - * Checks if the map option exists. - * - * @param string $mapOption The map option. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the map option is not valid. - * - * @return boolean TRUE if the map option exists else FALSE. - */ - public function hasMapOption($mapOption) - { - if (!is_string($mapOption)) { - throw MapException::invalidMapOption(); - } - - return isset($this->mapOptions[$mapOption]); - } - - /** - * Gets the map options + * Sets the bound. * - * @return array The map options. + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function getMapOptions() + public function setBound(Bound $bound) { - return $this->mapOptions; + $this->bound = $bound; } /** - * Sets the map options. + * Gets the controls. * - * @param array $mapOptions The map options. + * @return \Ivory\GoogleMap\Controls\Controls The controls. */ - public function setMapOptions(array $mapOptions) + public function getControls() { - foreach ($mapOptions as $mapOption => $value) { - $this->setMapOption($mapOption, $value); - } + return $this->controls; } /** - * Gets a specific map option. - * - * @param string $mapOption The map option. + * Sets the controls. * - * @throws \Ivory\GoogleMap\Exception\MapException If the map option does not exist. - * - * @return mixed The map option value. + * @param \Ivory\GoogleMap\Controls\Controls $controls The controls. */ - public function getMapOption($mapOption) + public function setControls(Controls $controls) { - if (!$this->hasMapOption($mapOption)) { - throw MapException::mapOptionDoesNotExist($mapOption); - } - - return $this->mapOptions[$mapOption]; + $this->controls = $controls; } /** - * Sets a specific map option - * - * @param string $mapOption The map option. - * @param mixed $value The map option value. + * Gets the events. * - * @throws \Ivory\GoogleMap\Exception\MapException If the map option is not valid. + * @return \Ivory\GoogleMap\Events\Events The events. */ - public function setMapOption($mapOption, $value) + public function getEvents() { - if (!is_string($mapOption)) { - throw MapException::invalidMapOption(); - } - - $this->mapOptions[$mapOption] = $value; + return $this->events; } /** - * Removes a map option. + * Sets the events. * - * @param string $mapOption The map option. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the map option does not exist. + * @param \Ivory\GoogleMap\Events\Events $events The events. */ - public function removeMapOption($mapOption) + public function setEvents(Events $events) { - if (!$this->hasMapOption($mapOption)) { - throw MapException::mapOptionDoesNotExist($mapOption); - } - - unset($this->mapOptions[$mapOption]); + $this->events = $events; } /** - * Checks if the stylesheet option exists. + * Gets the layers. * - * @param string $stylesheetOption The stylesheet option. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the stylesheet option is not valid. - * - * @return boolean TRUE if the stylesheet option exists else FALSE. + * @return \Ivory\GoogleMap\Layers\Layers The layers. */ - public function hasStylesheetOption($stylesheetOption) + public function getLayers() { - if (!is_string($stylesheetOption)) { - throw MapException::invalidStylesheetOption(); - } - - return isset($this->stylesheetOptions[$stylesheetOption]); + return $this->layers; } /** - * Gets the stylesheet options. + * Sets the layers. * - * @return array The stylesheet options. + * @param \Ivory\GoogleMap\Layers\Layers $layers The layers. */ - public function getStylesheetOptions() + public function setLayers(Layers $layers) { - return $this->stylesheetOptions; + $this->layers = $layers; } /** - * Sets the stylesheet options. + * Gets the overlays. * - * @param array $stylesheetOptions The stylesheet options. + * @return \Ivory\GoogleMap\Overlays\Overlays The overlays. */ - public function setStylesheetOptions(array $stylesheetOptions) + public function getOverlays() { - foreach ($stylesheetOptions as $stylesheetOption => $value) { - $this->setStylesheetOption($stylesheetOption, $value); - } + return $this->overlays; } /** - * Gets a specific stylesheet option. - * - * @param string $stylesheetOption The stylesheet option. + * Sets the overlays. * - * @throws \Ivory\GoogleMap\Exception\MapException If the stylesheet option does not exist. - * - * @return mixed The stylesheet option value. + * @param \Ivory\GoogleMap\Overlays\Overlays $overlays The overlays. */ - public function getStylesheetOption($stylesheetOption) + public function setOverlays(Overlays $overlays) { - if (!$this->hasStylesheetOption($stylesheetOption)) { - throw MapException::stylesheetOptionDoesNotExist($stylesheetOption); - } - - return $this->stylesheetOptions[$stylesheetOption]; + $this->overlays = $overlays; } /** - * Sets a specific stylesheet option. - * - * @param string $stylesheetOption The stylesheet option. - * @param mixed $value The stylesheet option value. - * - * @throws \Ivory\GoogleMap\Exception\MapException If the stylesheet option is not valid. + * Resets the map options. */ - public function setStylesheetOption($stylesheetOption, $value) + public function resetMapOptions() { - if (!is_string($stylesheetOption)) { - throw MapException::invalidStylesheetOption(); - } - - $this->stylesheetOptions[$stylesheetOption] = $value; + $this->mapOptions = array(); } /** - * Removes a stylesheet option. - * - * @param string $stylesheetOption The stylesheet option. + * Checks if there are map options. * - * @throws \Ivory\GoogleMap\Exception\MapException If the stylesheet option does not exist. + * @return boolean TRUE if there are map options else FALSE. */ - public function removeStylesheetOption($stylesheetOption) + public function hasMapOptions() { - if (!$this->hasStylesheetOption($stylesheetOption)) { - throw MapException::stylesheetOptionDoesNotExist($stylesheetOption); - } - - unset($this->stylesheetOptions[$stylesheetOption]); + return !empty($this->mapOptions); } /** - * Checks if the map has a map type control. + * Gets the map options * - * @return boolean TRUE if the map has a map type control else FALSE. + * @return array The map options. */ - public function hasMapTypeControl() + public function getMapOptions() { - return $this->mapTypeControl !== null; + return $this->mapOptions; } /** - * Gets the map type control. + * Sets the map options. * - * @return \Ivory\GoogleMap\Controls\MapTypeControl The map type control. + * @param array $mapOptions The map options. */ - public function getMapTypeControl() + public function setMapOptions(array $mapOptions) { - return $this->mapTypeControl; + $this->resetMapOptions(); + $this->addMapOptions($mapOptions); } /** - * Sets the map type control. - * - * Available prototypes: - * - function setMapTypeControl(Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl = null) - * - function setMaptypeControl(array $mapTypeIds, string $controlPosition, string $mapTypeControlStyle) + * Adds the map options. * - * @throws \Ivory\GoogleMap\Exception\MapException If the map type control is not valid (prototypes). + * @param array $mapOptions The map options. */ - public function setMapTypeControl() + public function addMapOptions(array $mapOptions) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof MapTypeControl)) { - $this->mapTypeControl = $args[0]; - $this->mapOptions['mapTypeControl'] = true; - } elseif ((isset($args[0]) && is_array($args[0])) - && (isset($args[1]) && is_string($args[1])) - && (isset($args[2]) && is_string($args[2])) - ) { - if ($this->mapTypeControl === null) { - $this->mapTypeControl = new MapTypeControl(); - } - - $this->mapTypeControl->setMapTypeIds($args[0]); - $this->mapTypeControl->setControlPosition($args[1]); - $this->mapTypeControl->setMapTypeControlStyle($args[2]); - - $this->mapOptions['mapTypeControl'] = true; - } elseif (!isset($args[0])) { - $this->mapTypeControl = null; - - if (isset($this->mapOptions['mapTypeControl'])) { - unset($this->mapOptions['mapTypeControl']); - } - } else { - throw MapException::invalidMapTypeControl(); + foreach ($mapOptions as $name => $value) { + $this->setMapOption($name, $value); } } /** - * Checks if the map has an overview map control. - * - * @return boolean TRUE if the map has an overview map control else FALSE. - */ - public function hasOverviewMapControl() - { - return $this->overviewMapControl !== null; - } - - /** - * Gets the overview map control. - * - * @return \Ivory\GoogleMap\Controls\OverviewMapControl The overview map control. - */ - public function getOverviewMapControl() - { - return $this->overviewMapControl; - } - - /** - * Sets the overview map control. - * - * Available prototypes: - * - function setOverviewMapControl(Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl = null) - * - function setOverviewMapControl(boolean $opened) + * Removes the map options. * - * @throws \Ivory\GoogleMap\Exception\MapException If the overview map control is not valid (prototypes). + * @param array $names The map option names. */ - public function setOverviewMapControl() + public function removeMapOptions(array $names) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0]) instanceof OverviewMapControl) { - $this->overviewMapControl = $args[0]; - $this->mapOptions['overviewMapControl'] = true; - } elseif (isset($args[0]) && is_bool($args[0])) { - if ($this->overviewMapControl === null) { - $this->overviewMapControl = new OverviewMapControl(); - } - - $this->overviewMapControl->setOpened($args[0]); - $this->mapOptions['overviewMapControl'] = true; - } elseif (!isset($args[0])) { - $this->overviewMapControl = null; - - if (isset($this->mapOptions['overviewMapControl'])) { - unset($this->mapOptions['overviewMapControl']); - } - } else { - throw MapException::invalidOverviewMapControl(); + foreach ($names as $name) { + $this->removeMapOption($name); } } /** - * Checks if the map has a pan control. - * - * @return boolean TRUE if the map has a pan control else FALSE. - */ - public function hasPanControl() - { - return $this->panControl !== null; - } - - /** - * Gets the map pan control. + * Checks if there is a map option. * - * @return \Ivory\GoogleMap\Controls\PanControl The map pan control. - */ - public function getPanControl() - { - return $this->panControl; - } - - /** - * Sets the map pan control. + * @param string $name The map option name. * - * Available prototypes: - * - function setPanControl(Ivory\GoogleMap\Controls\PanControl $panControl = null) - * - function setPanControl(string $controlPosition) - * - * @throws \Ivory\GoogleMap\Exception\MapException If the pan control is not valid (prototypes). + * @return boolean TRUE if there is the map option else FALSE. */ - public function setPanControl() + public function hasMapOption($name) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof PanControl)) { - $this->panControl = $args[0]; - $this->mapOptions['panControl'] = true; - } elseif (isset($args[0]) && is_string($args[0])) { - if ($this->panControl === null) { - $this->panControl = new PanControl(); - } - - $this->panControl->setControlPosition($args[0]); - $this->mapOptions['panControl'] = true; - } elseif (!isset($args[0])) { - $this->panControl = null; - - if (isset($this->mapOptions['panControl'])) { - unset($this->mapOptions['panControl']); - } - } else { - throw MapException::invalidPanControl(); - } + return array_key_exists($name, $this->mapOptions); } /** - * Checks if the map has a rotate control. + * Gets a map option. * - * @return boolean TRUE if the map has a rotate control else FALSE. - */ - public function hasRotateControl() - { - return $this->rotateControl !== null; - } - - /** - * Gets the map rotate control. + * @param string $name The map option name. * - * @return \Ivory\GoogleMap\Controls\RotateControl The map rotate control. + * @return mixed The map option value. */ - public function getRotateControl() + public function getMapOption($name) { - return $this->rotateControl; + return $this->hasMapOption($name) ? $this->mapOptions[$name] : null; } /** - * Sets the map rotate control. - * - * Available prototypes: - * - function setRotateControl(Ivory\GoogleMap\Controls\RotateControl $rotateControl = null) - * - function setRotateControl(string $controlPosition) + * Sets a map option * - * @throws \Ivory\GoogleMap\Exception\MapException If the rotate control is not valid (prototypes). + * @param string $name The map option name. + * @param mixed $value The map option value. */ - public function setRotateControl() + public function setMapOption($name, $value) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof RotateControl)) { - $this->rotateControl = $args[0]; - $this->mapOptions['rotateControl'] = true; - } elseif (isset($args[0]) && is_string($args[0])) { - if ($this->rotateControl === null) { - $this->rotateControl = new RotateControl(); - } - - $this->rotateControl->setControlPosition($args[0]); - $this->mapOptions['rotateControl'] = true; - } elseif (!isset($args[0])) { - $this->rotateControl = null; - - if (isset($this->mapOptions['rotateControl'])) { - unset($this->mapOptions['rotateControl']); - } - } else { - throw MapException::invalidRotateControl(); - } + $this->mapOptions[$name] = $value; } /** - * Checks if the map has a scale control else FALSE. + * Removes a map option. * - * @return boolean TRUE if the map has a scale control else FALSE. + * @param string $name The map option name. */ - public function hasScaleControl() + public function removeMapOption($name) { - return $this->scaleControl !== null; + unset($this->mapOptions[$name]); } /** - * Gets the map scale control. - * - * @return \Ivory\GoogleMap\Controls\ScaleControl The map scale control. + * Resets the stylesheet options. */ - public function getScaleControl() + public function resetStylesheetOptions() { - return $this->scaleControl; + $this->stylesheetOptions = array(); } /** - * Sets the map scale control. + * Checks if there are stylesheet options. * - * Available prototypes: - * - function setScaleControl(Ivory\GoogleMap\Controls\ScaleControl $scaleControl = null) - * - function setScaleControl(string $controlPosition, string $scaleControlStyle) - * - * @throws \Ivory\GoogleMap\Exception\MapException If the scale control is not valid (prototypes). + * @return boolean TRUE if there are stylesheet options else FALSE. */ - public function setScaleControl() + public function hasStylesheetOptions() { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof ScaleControl)) { - $this->scaleControl = $args[0]; - $this->mapOptions['scaleControl'] = true; - } elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_string($args[1]))) { - if ($this->scaleControl === null) { - $this->scaleControl = new ScaleControl(); - } - - $this->scaleControl->setControlPosition($args[0]); - $this->scaleControl->setScaleControlStyle($args[1]); - - $this->mapOptions['scaleControl'] = true; - } elseif (!isset($args[0])) { - $this->scaleControl = null; - - if (isset($this->mapOptions['scaleControl'])) { - unset($this->mapOptions['scaleControl']); - } - } else { - throw MapException::invalidScaleControl(); - } + return !empty($this->stylesheetOptions); } /** - * Checks if the map has a street view control. + * Gets the stylesheet options. * - * @return boolean TRUE if the map has a street view control else FALSE. + * @return array The stylesheet options. */ - public function hasStreetViewControl() + public function getStylesheetOptions() { - return $this->streetViewControl !== null; + return $this->stylesheetOptions; } /** - * Gets the map street view control. + * Sets the stylesheet options. * - * @return \Ivory\GoogleMap\Controls\StreetViewControl The map street view control. + * @param array $stylesheetOptions The stylesheet options. */ - public function getStreetViewControl() + public function setStylesheetOptions(array $stylesheetOptions) { - return $this->streetViewControl; + $this->resetStylesheetOptions(); + $this->addStylesheetOptions($stylesheetOptions); } /** - * Sets the map street view control. + * Adds the stylesheet options. * - * Available prototypes: - * - function setStreetViewControl(Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl = null) - * - function setStreetViewControl(string $controlPosition) - * - * @throws \Ivory\GoogleMap\Exception\MapException If the street view control is not valid (prototypes). + * @param array $stylesheetOptions The stylesheet options. */ - public function setStreetViewControl() + public function addStylesheetOptions(array $stylesheetOptions) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof StreetViewControl)) { - $this->streetViewControl = $args[0]; - $this->mapOptions['streetViewControl'] = true; - } elseif (isset($args[0]) && is_string($args[0])) { - if ($this->streetViewControl === null) { - $this->streetViewControl = new StreetViewControl(); - } - - $this->streetViewControl->setControlPosition($args[0]); - $this->mapOptions['streetViewControl'] = true; - } elseif (!isset($args[0])) { - $this->streetViewControl = null; - - if (isset($this->mapOptions['streetViewControl'])) { - unset($this->mapOptions['streetViewControl']); - } - } else { - throw MapException::invalidStreetViewControl(); + foreach ($stylesheetOptions as $name => $value) { + $this->setStylesheetOption($name, $value); } } /** - * Checks if the map has a zoom control. + * Removes the stylesheet options. * - * @return boolean TRUE if the map has a zoom control else FALSE. + * @param array $names The stylesheet option names. */ - public function hasZoomControl() + public function removeStylesheetOptions(array $names) { - return $this->zoomControl !== null; - } - - /** - * Gets the map zoom control. - * - * @return \Ivory\GoogleMap\Controls\ZoomControl The map zoom control. - */ - public function getZoomControl() - { - return $this->zoomControl; - } - - /** - * Sets the map zoom control. - * - * Available prototypes: - * - function setZoomControl(Ivory\GoogleMap\Controls\ZoomControl $zoomControl = null) - * - function setZoomControl(string $controlPosition, string $zoomControlStyle) - * - * @throws \Ivory\GoogleMap\Exception\MapException If the zoom control is not valid (prototypes). - */ - public function setZoomControl() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof ZoomControl)) { - $this->zoomControl = $args[0]; - $this->mapOptions['zoomControl'] = true; - } elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_string($args[1]))) { - if ($this->zoomControl === null) { - $this->zoomControl = new ZoomControl(); - } - - $this->zoomControl->setControlPosition($args[0]); - $this->zoomControl->setZoomControlStyle($args[1]); - - $this->mapOptions['zoomControl'] = true; - } elseif (!isset($args[0])) { - $this->zoomControl = null; - - if (isset($this->mapOptions['zoomControl'])) { - unset($this->mapOptions['zoomControl']); - } - } else { - throw MapException::invalidZoomControl(); + foreach ($names as $name) { + $this->removeStylesheetOption($name); } } /** - * Gets the map event manager. + * Checks if there is a stylesheet option. * - * @return \Ivory\GoogleMap\Events\EventManager The map event manager. - */ - public function getEventManager() - { - return $this->eventManager; - } - - /** - * Sets the map event manager. - * - * @param \Ivory\GoogleMap\Events\EventManager $eventManager The map event manager. - */ - public function setEventManager(EventManager $eventManager) - { - $this->eventManager = $eventManager; - } - - /** - * Gets the marker cluster. + * @param string $name The stylesheet option name. * - * @return \Ivory\GoogleMap\Overlays\MarkerCluster The marker cluster. + * @return boolean TRUE if there is the stylesheet option else FALSE. */ - public function getMarkerCluster() + public function hasStylesheetOption($name) { - return $this->markerCluster; + return array_key_exists($name, $this->stylesheetOptions); } /** - * Sets the marker cluster. + * Gets a stylesheet option. * - * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. - */ - public function setMarkerCluster(MarkerCluster $markerCluster) - { - $this->markerCluster = $markerCluster; - } - - /** - * Gets the map markers. + * @param string $name The stylesheet option name. * - * @return array The map markers. + * @return mixed The stylesheet option value. */ - public function getMarkers() + public function getStylesheetOption($name) { - return $this->markerCluster->getMarkers(); + return $this->hasStylesheetOption($name) ? $this->stylesheetOptions[$name] : null; } /** - * Add a map marker. + * Sets a stylesheet option. * - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker to add. + * @param string $name The stylesheet option name. + * @param mixed $value The stylesheet option value. */ - public function addMarker(Marker $marker) + public function setStylesheetOption($name, $value) { - $this->markerCluster->addMarker($marker); - - if ($this->autoZoom) { - $this->bound->extend($marker); - } + $this->stylesheetOptions[$name] = $value; } /** - * Gets the map info windows. + * Removes a stylesheet option. * - * @return array The map info windows. + * @param string $name The stylesheet option name. */ - public function getInfoWindows() + public function removeStylesheetOption($name) { - return $this->infoWindows; + unset($this->stylesheetOptions[$name]); } /** - * Add a map info window. + * Gets the language. * - * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window to add. + * @return string The language. */ - public function addInfoWindow(InfoWindow $infoWindow) + public function getLanguage() { - $this->infoWindows[] = $infoWindow; - - if ($this->autoZoom) { - $this->bound->extend($infoWindow); - } + return $this->language; } /** - * Gets the map polylines. + * Sets the langauge. * - * @return array The map polylines. + * @param string $language The langauge. */ - public function getPolylines() + public function setLanguage($language) { - return $this->polylines; + $this->language = $language; } /** - * Add a map polyline. - * - * @param \Ivory\GoogleMap\Overlays\Polyline The polyline to add. + * Resets the libraries. */ - public function addPolyline(Polyline $polyline) + public function resetLibraries() { - $this->polylines[] = $polyline; - - if ($this->autoZoom) { - $this->bound->extend($polyline); - } + $this->libraries = array(); } /** - * Gets the map encoded polylines. + * Checks if there are libraries. * - * @return array The map encoded polylines. + * @return boolean TRUE if there are libraries else FALSE. */ - public function getEncodedPolylines() + public function hasLibraries() { - return $this->encodedPolylines; + return !empty($this->libraries); } /** - * Adds an encoded polyline to the map. + * Gets the libraries. * - * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline to add. + * @return array The libraries. */ - public function addEncodedPolyline(EncodedPolyline $encodedPolyline) + public function getLibraries() { - $this->encodedPolylines[] = $encodedPolyline; - - if ($this->autoZoom) { - $this->bound->extend($encodedPolyline); - } + return $this->libraries; } /** - * Gets the map polygons. + * Sets the libraries. * - * @return array The map polygons. + * @param array $libraries The libraries. */ - public function getPolygons() + public function setLibraries(array $libraries) { - return $this->polygons; + $this->resetLibraries(); + $this->addLibraries($libraries); } /** - * Add a map polygon. + * Adds the libraries. * - * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon to add. + * @param array $libraries The libraries. */ - public function addPolygon(Polygon $polygon) + public function addLibraries(array $libraries) { - $this->polygons[] = $polygon; - - if ($this->autoZoom) { - $this->bound->extend($polygon); + foreach ($libraries as $library) { + $this->addLibrary($library); } } /** - * Gets the map rectangles. - * - * @return array The map rectangles. - */ - public function getRectangles() - { - return $this->rectangles; - } - - /** - * Add a map rectangle to the map. + * Removes the libraries. * - * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle to add. + * @param array $libraries The libraries. */ - public function addRectangle(Rectangle $rectangle) + public function removeLibraries(array $libraries) { - $this->rectangles[] = $rectangle; - - if ($this->autoZoom) { - $this->bound->extend($rectangle); + foreach ($libraries as $library) { + $this->removeLibrary($library); } } /** - * Gets the map circles + * Checks if there is a library. * - * @return array The map circles. - */ - public function getCircles() - { - return $this->circles; - } - - /** - * Add a circle to the map. + * @param string $library The library. * - * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle to add. + * @return boolean TRUE if there is the library else FALSE. */ - public function addCircle(Circle $circle) + public function hasLibrary($library) { - $this->circles[] = $circle; - - if ($this->autoZoom) { - $this->bound->extend($circle); - } + return in_array($library, $this->libraries, true); } /** - * Gets the map ground overlays. + * Adds a library. * - * @return array The map ground overlays. + * @param string $library The library. */ - public function getGroundOverlays() + public function addLibrary($library) { - return $this->groundOverlays; - } - - /** - * Add a ground overlay to the map. - * - * @param \Ivory\GoogleMapBundle\Model\Overlays\GroupOverlay $groundOverlay The ground overlay to add. - */ - public function addGroundOverlay(GroundOverlay $groundOverlay) - { - $this->groundOverlays[] = $groundOverlay; - - if ($this->autoZoom) { - $this->bound->extend($groundOverlay); + if (!$this->hasLibrary($library)) { + $this->libraries[] = $library; } } /** - * Gets the KML layers. + * Removes a library. * - * @return array The KML layers. + * @param string $library The library. */ - public function getKMLLayers() + public function removeLibrary($library) { - return $this->kmlLayers; - } - - /** - * Adds a KML Layer to the map. - * - * @param \Ivory\GoogleMap\Layers\KMLLayer $kmlLayer The KML Layer to add. - */ - public function addKMLLayer(KMLLayer $kmlLayer) - { - $this->kmlLayers[] = $kmlLayer; - } - - /** - * Checks if the map has libraries. - * - * @return boolean TRUE if the map has libraries else FALSE. - */ - public function hasLibraries() - { - return !empty($this->libraries); - } - - /** - * Gets the map libraries. - * - * @return array The map libraries. - */ - public function getLibraries() - { - return $this->libraries; - } - - /** - * Sets the map libraries. - * - * @param array $libraries The map libraries. - */ - public function setLibraries(array $libraries) - { - $this->libraries = $libraries; - } - - /** - * Gets the map language. - * - * @return string The map language. - */ - public function getLanguage() - { - return $this->language; - } - - /** - * Sets the map langauge. - * - * @param string $language The map langauge. - */ - public function setLanguage($language) - { - $this->language = $language; + unset($this->libraries[array_search($library, $this->libraries, true)]); } } diff --git a/src/MapTypeId.php b/src/MapTypeId.php index b02ae434..805753a4 100644 --- a/src/MapTypeId.php +++ b/src/MapTypeId.php @@ -11,41 +11,18 @@ namespace Ivory\GoogleMap; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Map type ID which describes a google map type ID. + * Map type id. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MapTypeId + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MapTypeId * @author GeLo */ -class MapTypeId +class MapTypeId extends AbstractUninstantiableAsset { const HYBRID = 'hybrid'; const ROADMAP = 'roadmap'; const SATELLITE = 'satellite'; const TERRAIN = 'terrain'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available map type IDs. - * - * @return array The map type IDs. - */ - public static function getMapTypeIds() - { - return array( - self::HYBRID, - self::ROADMAP, - self::SATELLITE, - self::TERRAIN, - ); - } } diff --git a/src/Overlays/Animation.php b/src/Overlays/Animation.php index bcdfc508..bab2bf36 100644 --- a/src/Overlays/Animation.php +++ b/src/Overlays/Animation.php @@ -11,37 +11,16 @@ namespace Ivory\GoogleMap\Overlays; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Animation which describes a google map animation. + * Animation. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Animation + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Animation * @author GeLo */ -class Animation +class Animation extends AbstractUninstantiableAsset { const BOUNCE = 'bounce'; const DROP = 'drop'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available animations. - * - * @return array The animations. - */ - public static function getAnimations() - { - return array( - self::BOUNCE, - self::DROP, - ); - } } diff --git a/src/Overlays/Circle.php b/src/Overlays/Circle.php index c4610253..b4c8767d 100644 --- a/src/Overlays/Circle.php +++ b/src/Overlays/Circle.php @@ -12,13 +12,13 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; +use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Circle which describes a google map circle. + * Circle. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Circle + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Circle * @author GeLo */ class Circle extends AbstractOptionsAsset implements ExtendableInterface @@ -26,33 +26,27 @@ class Circle extends AbstractOptionsAsset implements ExtendableInterface /** @var \Ivory\GoogleMap\Base\Coordinate */ protected $center; - /** @var double */ + /** @var float */ protected $radius; /** - * Create a circle. + * Creates a circle. * - * @param \Ivory\GoogleMap\Base\Coordinate $center The circle center. - * @param double $radius The circle radius. + * @param \Ivory\GoogleMap\Base\Coordinate $center The center. + * @param float $radius The radius. */ - public function __construct(Coordinate $center = null, $radius = 1) + public function __construct(Coordinate $center, $radius) { - parent::__construct(); - - $this->setPrefixJavascriptVariable('circle_'); - - if ($center === null) { - $center = new Coordinate(); - } + parent::__construct('circle_'); $this->setCenter($center); $this->setRadius($radius); } /** - * Gets the circle center. + * Gets the center. * - * @return \Ivory\GoogleMap\Base\Coordinate The circle center. + * @return \Ivory\GoogleMap\Base\Coordinate The center. */ public function getCenter() { @@ -60,36 +54,19 @@ public function getCenter() } /** - * Sets the circle center. - * - * Available prototypes: - * - function setCenter(Ivory\GoogleMap\Base\Coordinate $center) - * - function setCenter(double $latitude, double $longitude, boolean $noWrap = true) + * Sets the center. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the center is not valid (prototypes). + * @param \Ivory\GoogleMap\Base\Coordinate $center The center. */ - public function setCenter() + public function setCenter(Coordinate $center) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->center = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $this->center->setLatitude($args[0]); - $this->center->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->center->setNoWrap($args[2]); - } - } else { - throw OverlayException::invalidCircleCenter(); - } + $this->center = $center; } /** - * Gets the circle radius. + * Gets the radius. * - * @return double The circle radius. + * @return float The radius. */ public function getRadius() { @@ -97,18 +74,20 @@ public function getRadius() } /** - * Sets the circle radius. - * - * @param double $radius The circle radius. + * Sets the radius. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the radius is not valid. + * @param float $radius The radius. */ public function setRadius($radius) { - if (!is_numeric($radius)) { - throw OverlayException::invalidCircleRadius(); - } - $this->radius = $radius; } + + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.union(%s.getBounds())', $bound->getVariable(), $this->variable); + } } diff --git a/src/Overlays/EncodedPolyline.php b/src/Overlays/EncodedPolyline.php index b74a4eea..89055c29 100644 --- a/src/Overlays/EncodedPolyline.php +++ b/src/Overlays/EncodedPolyline.php @@ -12,12 +12,12 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; -use Ivory\GoogleMap\Exception\OverlayException; +use Ivory\GoogleMap\Base\Bound; /** * Encoded polyline. * - * @see http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html + * @link http://code.google.com/apis/maps/documentation/utilities/polylinealgorithm.html * @author GeLo */ class EncodedPolyline extends AbstractOptionsAsset implements ExtendableInterface @@ -28,23 +28,19 @@ class EncodedPolyline extends AbstractOptionsAsset implements ExtendableInterfac /** * Creates an encoded polyline. * - * @param string $value The encoded polyline value. + * @param string $value The value. */ - public function __construct($value = null) + public function __construct($value) { - parent::__construct(); + parent::__construct('encoded_polyline_'); - $this->setPrefixJavascriptVariable('encoded_polyline_'); - - if ($value !== null) { - $this->setValue($value); - } + $this->setValue($value); } /** - * Gets the encoded polyline value. + * Gets the value. * - * @return string The encoded polyline value. + * @return string The value. */ public function getValue() { @@ -52,18 +48,20 @@ public function getValue() } /** - * Sets the encoded polyline value. - * - * @param string $value The encoded polyline value. + * Sets the value. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the encoded polyline value is not valid. + * @param string $value The value. */ public function setValue($value) { - if (!is_string($value)) { - throw OverlayException::invalidEncodedPolylineValue(); - } - $this->value = $value; } + + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.getPath().forEach(function(e){%s.extend(e);})', $this->variable, $bound->getVariable()); + } } diff --git a/src/Overlays/ExtendableInterface.php b/src/Overlays/ExtendableInterface.php index 89634ae1..8cc77482 100644 --- a/src/Overlays/ExtendableInterface.php +++ b/src/Overlays/ExtendableInterface.php @@ -11,11 +11,21 @@ namespace Ivory\GoogleMap\Overlays; +use Ivory\GoogleMap\Base\Bound; + /** - * Each class implements this interface can be extend by a bound. + * Extend. * * @author GeLo */ interface ExtendableInterface { + /** + * Renders an extend. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. + * + * @return string The rendered extend. + */ + public function renderExtend(Bound $bound); } diff --git a/src/Overlays/GroundOverlay.php b/src/Overlays/GroundOverlay.php index fdc8be97..c27931d4 100644 --- a/src/Overlays/GroundOverlay.php +++ b/src/Overlays/GroundOverlay.php @@ -12,14 +12,12 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; -use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Ground overlay which describes a google map ground overlay. + * Ground overlay. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GroundOverlay + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GroundOverlay * @author GeLo */ class GroundOverlay extends AbstractOptionsAsset implements ExtendableInterface @@ -33,30 +31,21 @@ class GroundOverlay extends AbstractOptionsAsset implements ExtendableInterface /** * Creates a ground overlay. * - * @param string $url The ground overlay url. - * @param \Ivory\GoogleMap\Base\Bound $bound The ground overlay bound. + * @param string $url The url. + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function __construct($url = null, Bound $bound = null) + public function __construct($url, Bound $bound) { - parent::__construct(); - - $this->setPrefixJavascriptVariable('ground_overlay_'); - - if ($url !== null) { - $this->setUrl($url); - } - - if ($bound === null) { - $bound = new Bound(new Coordinate(-1, -1), new Coordinate(1, 1)); - } + parent::__construct('ground_overlay_'); + $this->setUrl($url); $this->setBound($bound); } /** - * Gets the ground overlay image url. + * Gets the url. * - * @return string The ground overlay image url. + * @return string The url. */ public function getUrl() { @@ -64,23 +53,19 @@ public function getUrl() } /** - * Sets the ground overlay image url. + * Sets the url. * - * @param string $url The ground overlay image url. + * @param string $url The url. */ public function setUrl($url) { - if (!is_string($url)) { - throw OverlayException::invalidGroundOverlayUrl(); - } - $this->url = $url; } /** - * Gets the ground overlay bound. + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The ground overlay bound. + * @return \Ivory\GoogleMap\Base\Bound The bound. */ public function getBound() { @@ -88,54 +73,20 @@ public function getBound() } /** - * Sets the ground overlay bound. - * - * Available prototypes: - * - function setBound(Ivory\GoogleMap\Base\Bound $bound) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) + * Sets the bound. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the ground overlay bound is not valid (prototypes). + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function setBound() + public function setBound(Bound $bound) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Bound)) { - if ($args[0]->hasCoordinates()) { - $this->bound = $args[0]; - } else { - throw OverlayException::invalidGroundOverlayBoundCoordinates(); - } - } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate)) - && (isset($args[1]) && ($args[1] instanceof Coordinate)) - ) { - $this->bound->setSouthWest($args[0]); - $this->bound->setNorthEast($args[1]); - } elseif ((isset($args[0]) && is_numeric($args[0])) - && (isset($args[1]) && is_numeric($args[1])) - && (isset($args[2]) && is_numeric($args[2])) - && (isset($args[3]) && is_numeric($args[3])) - ) { - $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); - $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); - - if (isset($args[4]) && is_bool($args[4])) { - $this->bound->getSouthWest()->setNoWrap($args[4]); - } + $this->bound = $bound; + } - if (isset($args[5]) && is_bool($args[5])) { - $this->bound->getNorthEast()->setNoWrap($args[5]); - } - } else { - throw OverlayException::invalidGroundOverlayBound(); - } + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.union(%s)', $bound->getVariable(), $this->bound->getVariable()); } } diff --git a/src/Overlays/Icon.php b/src/Overlays/Icon.php new file mode 100644 index 00000000..db94ff26 --- /dev/null +++ b/src/Overlays/Icon.php @@ -0,0 +1,192 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Overlays; + +use Ivory\GoogleMap\Assets\AbstractVariableAsset; +use Ivory\GoogleMap\Base\Point; +use Ivory\GoogleMap\Base\Size; + +/** + * Icon. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Icon + * @author GeLo + */ +class Icon extends AbstractVariableAsset +{ + /** @var string */ + protected $url; + + /** @var \Ivory\GoogleMap\Base\Point|null */ + protected $anchor; + + /** @var \Ivory\GoogleMap\Base\Point|null */ + protected $origin; + + /** @var \Ivory\GoogleMap\Base\Size|null */ + protected $scaledSize; + + /** @var Ivory\GoogleMap\Base\Size|null */ + protected $size; + + /** + * Create an icon. + * + * @param string $url The url. + */ + public function __construct($url) + { + parent::__construct('icon_'); + + $this->setUrl($url); + } + + /** + * Gets the url. + * + * @return string The url. + */ + public function getUrl() + { + return $this->url; + } + + /** + * Sets the url. + * + * @param string $url The url. + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * Checks if there is an anchor. + * + * @return boolean TRUE if there is an anchor else FALSE. + */ + public function hasAnchor() + { + return $this->anchor !== null; + } + + /** + * Gets the anchor. + * + * @return \Ivory\GoogleMap\Base\Point|null The anchor. + */ + public function getAnchor() + { + return $this->anchor; + } + + /** + * Sets the anchor. + * + * @param \Ivory\GoogleMap\Base\Point|null $anchor The anchor. + */ + public function setAnchor(Point $anchor = null) + { + $this->anchor = $anchor; + } + + /** + * Checks if there is an origin. + * + * @return boolean TRUE if there is an origin else FALSE. + */ + public function hasOrigin() + { + return $this->origin !== null; + } + + /** + * Gets the origin. + * + * @return \Ivory\GoogleMap\Base\Point|null The origin. + */ + public function getOrigin() + { + return $this->origin; + } + + /** + * Sets the origin. + * + * @param \Ivory\GoogleMap\Base\Point|null $origin The origin. + */ + public function setOrigin(Point $origin = null) + { + $this->origin = $origin; + } + + /** + * Checks if there is a scaled size. + * + * @return boolean TRUE if there is a scaled size else FALSE. + */ + public function hasScaledSize() + { + return $this->scaledSize !== null; + } + + /** + * Gets the scaled size. + * + * @return \Ivory\GoogleMap\Base\Size|null The scaled size. + */ + public function getScaledSize() + { + return $this->scaledSize; + } + + /** + * Sets the scaled size. + * + * @param \Ivory\GoogleMap\Base\Size|null $scaledSize The scaled size. + */ + public function setScaledSize(Size $scaledSize = null) + { + $this->scaledSize = $scaledSize; + } + + /** + * Checks if there is a size. + * + * @return boolean TRUE if there is a size else FALSE. + */ + public function hasSize() + { + return $this->size !== null; + } + + /** + * Gets the size. + * + * @return \Ivory\GoogleMap\Base\Size|null The size. + */ + public function getSize() + { + return $this->size; + } + + /** + * Sets the size. + * + * @param \Ivory\GoogleMap\Base\Size|null $size The size. + */ + public function setSize(Size $size = null) + { + $this->size = $size; + } +} diff --git a/src/Overlays/InfoWindow.php b/src/Overlays/InfoWindow.php index d0768b73..73246fc6 100644 --- a/src/Overlays/InfoWindow.php +++ b/src/Overlays/InfoWindow.php @@ -13,14 +13,15 @@ use Ivory\GoogleMap\Assets\AbstractOptionsAsset; use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Size; use Ivory\GoogleMap\Events\MouseEvent; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Info window which describes a google map info window. + * Info window. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#InfoWindow + * @link http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html * @author GeLo */ class InfoWindow extends AbstractOptionsAsset implements ExtendableInterface @@ -28,69 +29,75 @@ class InfoWindow extends AbstractOptionsAsset implements ExtendableInterface /** @var string */ protected $content; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|null */ protected $position; - /** @var \Ivory\GoogleMap\Base\Size */ - protected $pixedOffset; + /** @var \Ivory\GoogleMap\Base\Size|null */ + protected $pixelOffset; /** @var boolean */ - protected $open; + protected $open = false; /** @var string */ - protected $openEvent; + protected $openEvent = MouseEvent::CLICK; /** @var boolean */ - protected $autoOpen; + protected $autoOpen = true; /** @var boolean */ - protected $autoClose; + protected $autoClose = true; + + /** @var string */ + protected $type = InfoWindowType::DEFAULT_; /** * Creates an info window. * - * @param string $content The info window content. - * @param \Ivory\GoogleMap\Base\Coordinate $position The info window position. - * @param \Ivory\GoogleMap\Base\Size $pixelOffset The info window pixel offset. - * @param boolean $open The info window open flag. - * @param string $openEvent The info window open event. - * @param boolean $autoOpen The info window auto open flag. - * @param boolean $autoClose The info window auto close flag + * @param string $content The content. + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. */ - public function __construct( - $content = '

Default content

', - Coordinate $position = null, - Size $pixelOffset = null, - $open = false, - $openEvent = MouseEvent::CLICK, - $autoOpen = true, - $autoClose = false - ) { - parent::__construct(); - - $this->setPrefixJavascriptVariable('info_window_'); + public function __construct($content, Coordinate $position = null) + { + parent::__construct('info_window_'); $this->setContent($content); + $this->setPosition($position); + } - if ($position !== null) { - $this->setPosition($position); - } - - if ($pixelOffset !== null) { - $this->setPixelOffset($pixelOffset); - } + /** + * Gets the content. + * + * @return string The content. + */ + public function getContent() + { + return $this->content; + } - $this->setOpen($open); - $this->setOpenEvent($openEvent); + /** + * Sets the content + * + * @param string $content The content. + */ + public function setContent($content) + { + $this->content = $content; + } - $this->setAutoOpen($autoOpen); - $this->setAutoClose($autoClose); + /** + * Checks if there is a position. + * + * @return boolean TRUE if there is a position else FALSE. + */ + public function hasPosition() + { + return $this->position !== null; } /** - * Gets the infow window position. + * Gets the position. * - * @return \Ivory\GoogleMap\Base\Coordinate The info window position. + * @return \Ivory\GoogleMap\Base\Coordinate|null The position. */ public function getPosition() { @@ -98,151 +105,89 @@ public function getPosition() } /** - * Sets the info window position - * - * Available prototypes: - * - function setPosition(Ivory\GoogleMap\Base\Coordinate $position = null) - * - function setPosition(double $latitude, double $longitude, boolean $noWrap = true) + * Sets the position. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the position is not valid. + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. */ - public function setPosition() + public function setPosition(Coordinate $position = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->position = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->position === null) { - $this->position = new Coordinate(); - } - - $this->position->setLatitude($args[0]); - $this->position->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->position->setNoWrap($args[2]); - } - } elseif (!isset($args[0])) { - $this->position = null; - } else { - throw OverlayException::invalidInfoWindowPosition(); - } + $this->position = $position; } /** - * Checks if the info window has a pixel offset. + * Checks if there is a pixel offset. * - * @return boolean TRUE if the info window has a pixel offset else FALSE. + * @return boolean TRUE if there is a pixel offset else FALSE. */ public function hasPixelOffset() { - return $this->pixedOffset !== null; + return $this->pixelOffset !== null; } /** * Gets the pixel offset. * - * @return \Ivory\GoogleMap\Base\Size The pixel offset. + * @return \Ivory\GoogleMap\Base\Size|null The pixel offset. */ public function getPixelOffset() { - return $this->pixedOffset; + return $this->pixelOffset; } /** * Sets the pixel offset. * - * Available prototypes: - * - function setPixelOffset(Ivory\GoogleMap\Base\Size $scaledSize) - * - function setPixelOffset(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the pixel offset is not valid (prototypes). + * @param \Ivory\GoogleMap\Base\Size|null $pixelOffset The pixel offset. */ - public function setPixelOffset() + public function setPixelOffset(Size $pixelOffset = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Size)) { - $this->pixedOffset = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->pixedOffset === null) { - $this->pixedOffset = new Size(); - } - - $this->pixedOffset->setWidth($args[0]); - $this->pixedOffset->setHeight($args[1]); - - if (isset($args[2]) && is_string($args[2])) { - $this->pixedOffset->setWidthUnit($args[2]); - } - - if (isset($args[3]) && is_string($args[3])) { - $this->pixedOffset->setHeightUnit($args[3]); - } - } elseif (!isset($args[0])) { - $this->pixedOffset = null; - } else { - throw OverlayException::invalidInfoWindowPixelOffset(); - } + $this->pixelOffset = $pixelOffset; } /** - * Gets the info window content. + * Checks if it is opened. * - * @return string The info window content. + * @return boolean TRUE if it is opened else FALSE. */ - public function getContent() + public function isOpen() { - return $this->content; + return $this->open; } /** - * Sets the info window content - * - * @param string $content The info window content. + * Sets the open flag. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the content is not valid. + * @param boolean $open TRUE if it is opened else FALSE. */ - public function setContent($content) + public function setOpen($open) { - if (!is_string($content)) { - throw OverlayException::invalidInfoWindowContent(); - } - - $this->content = $content; + $this->open = $open; } /** - * Checks if the info window is open. + * Gets the open event. * - * @return boolean TRUE if the info window is open else FALSE. + * @return string The open event. */ - public function isOpen() + public function getOpenEvent() { - return $this->open; + return $this->openEvent; } /** - * Sets if the info window is open. + * Sets the open event. * - * @param boolean $open TRUE if the info window is open else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the info window open flag is not valid. + * @param string $openEvent The open event. */ - public function setOpen($open) + public function setOpenEvent($openEvent) { - if (!is_bool($open)) { - throw OverlayException::invalidInfoWindowOpen(); - } - - $this->open = $open; + $this->openEvent = $openEvent; } /** - * Checks if the info window auto open. + * Checks if it opens automatically when the open event is triggered. * - * @return boolean TRUE if the info window auto open on event else FALSE. + * @return boolean TRUE if the it opens automatically when the open event is triggered else FALSE. */ public function isAutoOpen() { @@ -250,70 +195,60 @@ public function isAutoOpen() } /** - * Sets if the info window auto open. + * Sets the auto open flag. * - * @param boolean $autoOpen TRUE if the info window auto open on event else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the auto open flag is not valid. + * @param boolean $autoOpen TRUE if it opens automatically when the open event is triggered else FALSE. */ public function setAutoOpen($autoOpen) { - if (!is_bool($autoOpen)) { - throw OverlayException::invalidInfoWindowAutoOpen(); - } - $this->autoOpen = $autoOpen; } /** - * Gets the info window open event. + * Checks if it closes automatically when an open event is triggered. * - * @return string The info window open event. + * @return boolean TRUE if it closes automatically when an open event is triggered else FALSE. */ - public function getOpenEvent() + public function isAutoClose() { - return $this->openEvent; + return $this->autoClose; } /** - * Sets the info window open event. - * - * @param string $openEvent The info window open event. + * Sets the auto close flag. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the open event is not valid. + * @param boolean $autoClose TRUE if it closes automatically when an open event is triggered else FALSE. */ - public function setOpenEvent($openEvent) + public function setAutoClose($autoClose) { - if (!in_array($openEvent, MouseEvent::getMouseEvents())) { - throw OverlayException::invalidInfoWindowOpenEvent(); - } - - $this->openEvent = $openEvent; + $this->autoClose = $autoClose; } /** - * Gets the auto close flag. + * Gets the type. * - * @return boolean TRUE if all opened info windows close when one is opened else FALSE. + * @return string The type. */ - public function isAutoClose() + public function getType() { - return $this->autoClose; + return $this->type; } /** - * Sets the auto close flag. - * - * @param boolean $autoClose TRUE if all opened info windows close when one is opened else FALSE. + * Sets the type. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the auto close flag is not valid. + * @param string $type The type. */ - public function setAutoClose($autoClose) + public function setType($type) { - if (!is_bool($autoClose)) { - throw OverlayException::invalidInfoWindowAutoClose(); - } + $this->type = $type; + } - $this->autoClose = $autoClose; + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.extend(%s.getPosition())', $bound->getVariable(), $this->variable); } } diff --git a/src/Exception/Exception.php b/src/Overlays/InfoWindowType.php similarity index 56% rename from src/Exception/Exception.php rename to src/Overlays/InfoWindowType.php index 35c6c35b..37b0052b 100644 --- a/src/Exception/Exception.php +++ b/src/Overlays/InfoWindowType.php @@ -9,15 +9,17 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Exception; +namespace Ivory\GoogleMap\Overlays; -use Exception as BaseException; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; /** - * Ivory google map exception. + * Info window type. * * @author GeLo */ -class Exception extends BaseException +class InfoWindowType extends AbstractUninstantiableAsset { + const DEFAULT_ = 'default'; + const INFOBOX = 'infobox'; } diff --git a/src/Overlays/Marker.php b/src/Overlays/Marker.php index 63cbb451..f6073c6b 100644 --- a/src/Overlays/Marker.php +++ b/src/Overlays/Marker.php @@ -12,13 +12,13 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; +use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Marker which describes a google map marker. + * Marker. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Marker * @author GeLo */ class Marker extends AbstractOptionsAsset implements ExtendableInterface @@ -26,74 +26,37 @@ class Marker extends AbstractOptionsAsset implements ExtendableInterface /** @var \Ivory\GoogleMap\Base\Coordinate */ protected $position; - /** @var string */ + /** @var string|null */ protected $animation; - /** @var \Ivory\GoogleMap\Overlays\MarkerImage */ + /** @var \Ivory\GoogleMap\Overlays\Icon|null */ protected $icon; - /** @var \Ivory\GoogleMap\Overlays\MarkerImage */ + /** @var \Ivory\GoogleMap\Overlays\Icon|null */ protected $shadow; - /** @var \Ivory\GoogleMap\Overlays\MarkerShape */ + /** @var \Ivory\GoogleMap\Overlays\MarkerShape|null */ protected $shape; - /** @var \Ivory\GoogleMap\Overlays\InfoWindow */ + /** @var \Ivory\GoogleMap\Overlays\InfoWindow|null */ protected $infoWindow; /** * Creates a marker. * - * @param \Ivory\GoogleMap\Base\Coordinate $position The marker position. - * @param string $animation The marker animation. - * @param \Ivory\GoogleMap\Overlays\MarkerImage $icon The marker icon. - * @param \Ivory\GoogleMap\Overlays\MarkerImage $shadow The marker shadow. - * @param \Ivory\GoogleMap\Overlays\MarkerShape $shape The marker shape. - * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The marker info window. + * @param \Ivory\GoogleMap\Base\Coordinate $position The position. */ - public function __construct( - Coordinate $position = null, - $animation = null, - MarkerImage $icon = null, - MarkerImage $shadow = null, - MarkerShape $shape = null, - InfoWindow $infoWindow = null - ) { - parent::__construct(); - - $this->setPrefixJavascriptVariable('marker_'); - - if ($position === null) { - $position = new Coordinate(); - } + public function __construct(Coordinate $position) + { + parent::__construct('marker_'); $this->setPosition($position); - - if ($animation !== null) { - $this->setAnimation($animation); - } - - if ($icon !== null) { - $this->setIcon($icon); - } - - if ($shadow !== null) { - $this->setShadow($shadow); - } - - if ($shape !== null) { - $this->setShape($shape); - } - - if ($infoWindow !== null) { - $this->setInfoWindow($infoWindow); - } } /** - * Gets the marker position. + * Gets the position. * - * @return \Ivory\GoogleMap\Base\Coordinate The marker position. + * @return \Ivory\GoogleMap\Base\Coordinate The position. */ public function getPosition() { @@ -101,38 +64,19 @@ public function getPosition() } /** - * Sets the marker position. + * Sets the position. * - * Available prototypes: - * - function setPosition(Ivory\GoogleMap\Base\Coordinate $position = null) - * - function setPosition(double $latitude, double $longitude, boolean $noWrap = true) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the position is not valid. + * @param \Ivory\GoogleMap\Base\Coordinate $position The position. */ - public function setPosition() + public function setPosition(Coordinate $position) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->position = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $this->position->setLatitude($args[0]); - $this->position->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->position->setNoWrap($args[2]); - } - } elseif (!isset($args[0])) { - $this->position = null; - } else { - throw OverlayException::invalidMarkerPosition(); - } + $this->position = $position; } /** - * Checks if the marker has an animation. + * Checks if there is an animation. * - * @return boolean TRUE if the marker has an animation else FALSE. + * @return boolean TRUE if there is an animation else FALSE. */ public function hasAnimation() { @@ -140,9 +84,9 @@ public function hasAnimation() } /** - * Gets the marker animation. + * Gets the animation. * - * @return string The marker animation. + * @return string|null The animation. */ public function getAnimation() { @@ -150,25 +94,19 @@ public function getAnimation() } /** - * Sets the marker animation. - * - * @param string $animation The marker animation. + * Sets the animation. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the animation is not valid. + * @param string|null $animation The animation. */ public function setAnimation($animation = null) { - if (!in_array($animation, Animation::getAnimations()) && ($animation !== null)) { - throw OverlayException::invalidMarkerAnimation(); - } - $this->animation = $animation; } /** - * Checks if the marker has an icon. + * Checks if there is an icon. * - * @return boolean TRUE if the marker has an icon else FALSE. + * @return boolean TRUE if there is an icon else FALSE. */ public function hasIcon() { @@ -176,9 +114,9 @@ public function hasIcon() } /** - * Gets the marker icon. + * Gets the icon. * - * @return \Ivory\GoogleMap\Overlays\MarkerImage The marker image. + * @return \Ivory\GoogleMap\Overlays\Icon|null The icon. */ public function getIcon() { @@ -186,41 +124,19 @@ public function getIcon() } /** - * Sets the marker icon. - * - * Available prototypes: - * - function setIcon(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null) - * - function setIcon(string $url = null) + * Sets the icon. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the icon is not valid. + * @param \Ivory\GoogleMap\Overlays\Icon|null $icon The icon. */ - public function setIcon() + public function setIcon(Icon $icon = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof MarkerImage)) { - if ($args[0]->getUrl() === null) { - throw OverlayException::invalidMarkerIconUrl(); - } - - $this->icon = $args[0]; - } elseif (isset($args[0]) && is_string($args[0])) { - if ($this->icon === null) { - $this->icon = new MarkerImage(); - } - - $this->icon->setUrl($args[0]); - } elseif (!isset($args[0])) { - $this->icon = null; - } else { - throw OverlayException::invalidMarkerIcon(); - } + $this->icon = $icon; } /** - * Checks if the marker has a shadow. + * Checks if there is a shadow. * - * @return boolean TRUE if the marker has a shadow else FALSE. + * @return boolean TRUE if there is a shadow else FALSE. */ public function hasShadow() { @@ -228,9 +144,9 @@ public function hasShadow() } /** - * Gets the marker shadow. + * Gets the shadow. * - * @return \Ivory\GoogleMap\Overlays\MarkerImage The marker shadow. + * @return \Ivory\GoogleMap\Overlays\Icon|null The shadow. */ public function getShadow() { @@ -238,41 +154,19 @@ public function getShadow() } /** - * Sets the marker shadow. + * Sets the shadow. * - * Available prototypes: - * - function setShadow(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null) - * - function setShadow(string $url = null) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the marker shadow is not valid. + * @param \Ivory\GoogleMap\Overlays\Icon|null $shadow The shadow. */ - public function setShadow() + public function setShadow(Icon $shadow = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof MarkerImage)) { - if ($args[0]->getUrl() === null) { - throw OverlayException::invalidMarkerShadowUrl(); - } - - $this->shadow = $args[0]; - } elseif (isset($args[0]) && is_string($args[0])) { - if ($this->shadow === null) { - $this->shadow = new MarkerImage(); - } - - $this->shadow->setUrl($args[0]); - } elseif (!isset($args[0])) { - $this->shadow = null; - } else { - throw OverlayException::invalidMarkerShadow(); - } + $this->shadow = $shadow; } /** - * Checks if the marker has a shape. + * Checks if there is a shape. * - * @return boolean TRUE if the marker has a shape else FALSE. + * @return boolean TRUE if there is a shape else FALSE. */ public function hasShape() { @@ -280,9 +174,9 @@ public function hasShape() } /** - * Gets the marker shape. + * Gets the shape. * - * @return \Ivory\GoogleMap\Overlays\MarkerShape The marker shape. + * @return \Ivory\GoogleMap\Overlays\MarkerShape|null The shape. */ public function getShape() { @@ -290,42 +184,19 @@ public function getShape() } /** - * Sets the marker shape. + * Sets the shape. * - * Available prototypes: - * - function setShape(Ivory\GoogleMap\Overlays\MarkerShape $shape = null) - * - function setShape(string $type, array $coordinates) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the shape is not valid. + * @param \Ivory\GoogleMap\Overlays\MarkerShape|null $shape The shape. */ - public function setShape() + public function setShape(MarkerShape $shape = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof MarkerShape)) { - if (!$args[0]->hasCoordinates()) { - throw OverlayException::invalidMarkerShapeCoordinates(); - } - - $this->shape = $args[0]; - } elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_array($args[1]))) { - if ($this->shape === null) { - $this->shape = new MarkerShape(); - } - - $this->shape->setType($args[0]); - $this->shape->setCoordinates($args[1]); - } elseif (!isset($args[0])) { - $this->shape = null; - } else { - throw OverlayException::invalidMarkerShape(); - } + $this->shape = $shape; } /** - * Check if the marker has an info window. + * Check if there is an info window. * - * @return boolean TRUE if the marker has an info window else FALSE. + * @return boolean TRUE if there is an info window else FALSE. */ public function hasInfoWindow() { @@ -335,7 +206,7 @@ public function hasInfoWindow() /** * Gets the info window. * - * @return \Ivory\GoogleMap\Overlays\InfoWindow The info window. + * @return \Ivory\GoogleMap\Overlays\InfoWindow|null The info window. */ public function getInfoWindow() { @@ -345,10 +216,18 @@ public function getInfoWindow() /** * Sets the info window. * - * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + * @param \Ivory\GoogleMap\Overlays\InfoWindow|null $infoWindow The info window. */ - public function setInfoWindow(InfoWindow $infoWindow) + public function setInfoWindow(InfoWindow $infoWindow = null) { $this->infoWindow = $infoWindow; } + + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.extend(%s.getPosition())', $bound->getVariable(), $this->variable); + } } diff --git a/src/Overlays/MarkerCluster.php b/src/Overlays/MarkerCluster.php index eb3a01bc..baacec6b 100644 --- a/src/Overlays/MarkerCluster.php +++ b/src/Overlays/MarkerCluster.php @@ -14,97 +14,141 @@ use Ivory\GoogleMap\Assets\AbstractOptionsAsset; /** - * Marker Cluster. + * Marker cluster. * + * @link http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/docs/reference.html * @author GeLo */ class MarkerCluster extends AbstractOptionsAsset { - /** @const string The default marker cluster type */ - const _DEFAULT = 'default'; - - /** @const string The javascript marker cluster type */ - const MARKER_CLUSTER = 'marker_cluster'; + /** @var array */ + protected $markers = array(); /** @var string */ - protected $type; - - /** @var array */ - protected $markers; + protected $type = MarkerClusterType::DEFAULT_; /** * Creates a marker cluster. */ public function __construct() { - parent::__construct(); + parent::__construct('marker_cluster_'); + } - $this->setPrefixJavascriptVariable('marker_cluster_'); - $this->setType(self::_DEFAULT); + /** + * Resets the markers. + */ + public function resetMarkers() + { $this->markers = array(); } /** - * Gets the marker cluster type. + * Checks if there are markers. * - * @return string The marker cluster type. + * @return boolean TRUE if there are markers else FALSE. */ - public function getType() + public function hasMarkers() { - return $this->type; + return !empty($this->markers); } /** - * Sets the marker cluster type. + * Gets the markers. * - * @param string $type The marker cluster type. + * @return array The markers. */ - public function setType($type) + public function getMarkers() { - $this->type = $type; + return $this->markers; } /** - * Checks if the cluster has marker. + * Sets the markers. * - * @return boolean TRUE if the cluster has marker else FALSE. + * @param array $markers The markers. */ - public function hasMarkers() + public function setMarkers(array $markers) { - return !empty($this->markers); + $this->resetMarkers(); + $this->addMarkers($markers); } /** - * Gets the cluster markers. + * Adds the markers. * - * @return array The cluster markers. + * @param array $markers The markers. */ - public function getMarkers() + public function addMarkers(array $markers) { - return $this->markers; + foreach ($markers as $marker) { + $this->addMarker($marker); + } } /** - * Sets the cluster markers. + * Removes the markers. * - * @param array $markers The cluster markers. + * @param array $markers The markers. */ - public function setMarkers($markers) + public function removeMarkers(array $markers) { - $this->markers = array(); - foreach ($markers as $marker) { - $this->addMarker($marker); + $this->removeMarker($marker); } } /** - * Adds a marker to the cluster. + * Checks if there is a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + * + * @return boolean TRUE if there is the marker else FALSE. + */ + public function hasMarker(Marker $marker) + { + return in_array($marker, $this->markers, true); + } + + /** + * Adds a marker. * - * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker to add. + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. */ public function addMarker(Marker $marker) { - $this->markers[] = $marker; + if (!$this->hasMarker($marker)) { + $this->markers[] = $marker; + } + } + + /** + * Removes a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + public function removeMarker(Marker $marker) + { + unset($this->markers[array_search($marker, $this->markers, true)]); + } + + /** + * Gets the type. + * + * @return string The type. + */ + public function getType() + { + return $this->type; + } + + /** + * Sets the type. + * + * @param string $type The type. + */ + public function setType($type) + { + $this->type = $type; } } diff --git a/src/Overlays/MarkerClusterType.php b/src/Overlays/MarkerClusterType.php new file mode 100644 index 00000000..5374e944 --- /dev/null +++ b/src/Overlays/MarkerClusterType.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Overlays; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Marker cluster type. + * + * @author GeLo + */ +class MarkerClusterType extends AbstractUninstantiableAsset +{ + const DEFAULT_ = 'default'; + const MARKER_CLUSTER = 'marker_cluster'; +} diff --git a/src/Overlays/MarkerImage.php b/src/Overlays/MarkerImage.php deleted file mode 100644 index dba210e4..00000000 --- a/src/Overlays/MarkerImage.php +++ /dev/null @@ -1,309 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Overlays; - -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Base\Point; -use Ivory\GoogleMap\Base\Size; -use Ivory\GoogleMap\Exception\OverlayException; - -/** - * Marker image which describes a google map marker image. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerImage - * @author GeLo - */ -class MarkerImage extends AbstractJavascriptVariableAsset -{ - /** @var string */ - protected $url; - - /** @var \Ivory\GoogleMap\Base\Point */ - protected $anchor; - - /** @var \Ivory\GoogleMap\Base\Point */ - protected $origin; - - /** @var \Ivory\GoogleMap\Base\Size */ - protected $scaledSize; - - /** @var Ivory\GoogleMap\Base\Size */ - protected $size; - - /** - * Create a marker image. - */ - public function __construct( - $url = '//maps.gstatic.com/mapfiles/markers/marker.png', - Point $anchor = null, - Point $origin = null, - Size $scaledSize = null, - Size $size = null - ) { - $this->setPrefixJavascriptVariable('marker_image_'); - $this->setUrl($url); - - if ($anchor !== null) { - $this->setAnchor($anchor); - } - - if ($origin !== null) { - $this->setOrigin($origin); - } - - if ($scaledSize !== null) { - $this->setScaledSize($scaledSize); - } - - if ($size !== null) { - $this->setSize($size); - } - } - - /** - * Gets the url of the marker image. - * - * @return string The url of the marker image. - */ - public function getUrl() - { - return $this->url; - } - - /** - * Sets the url of the marker image. - * - * @param string $url The url of the marker image. - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the url is not valid. - */ - public function setUrl($url) - { - if (!is_string($url)) { - throw OverlayException::invalidMarkeImageUrl(); - } - - $this->url = $url; - } - - /** - * Checks if the marker image has an anchor. - * - * @return boolean TRUE if the marker image has an anchor else FALSE. - */ - public function hasAnchor() - { - return $this->anchor !== null; - } - - /** - * Gets the anchor of the marker image. - * - * @return \Ivory\GoogleMap\Base\Point The marker image anchor. - */ - public function getAnchor() - { - return $this->anchor; - } - - /** - * Sets the anchor of the marker image - * - * Available prototypes: - * - function setAnchor(Ivory\GoogleMap\Base\Point $anchor = null) - * - function setAnchor(double x, double y) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the anchor is not valid (prototypes). - */ - public function setAnchor() - { - $args = func_get_args(); - - if ($args[0] instanceof Point) { - $this->anchor = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->anchor === null) { - $this->anchor = new Point(); - } - - $this->anchor->setX($args[0]); - $this->anchor->setY($args[1]); - } elseif (!isset($args[0])) { - $this->anchor = null; - } else { - throw OverlayException::invalidMarkerImageAnchor(); - } - } - - /** - * Checks if the marker image has an origin. - * - * @return boolean TRUE if the marker image has an origin else FALSE. - */ - public function hasOrigin() - { - return $this->origin !== null; - } - - /** - * Gets the origin of the marker image. - * - * @return \Ivory\GoogleMap\Base\Point The marker image origin. - */ - public function getOrigin() - { - return $this->origin; - } - - /** - * Sets the origin of the marker image - * - * Available prototypes: - * - function setOrigin(Ivory\GoogleMap\Base\Point $origin = null) - * - function setOrigin(double x, double y) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the origin is not valid. - */ - public function setOrigin() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Point)) { - $this->origin = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->origin === null) { - $this->origin = new Point(); - } - - $this->origin->setX($args[0]); - $this->origin->setY($args[1]); - } elseif (!isset($args[0])) { - $this->origin = null; - } else { - throw OverlayException::invalidMarkerImageOrigin(); - } - } - - /** - * Checks if the marker image has a scaled size else FALSE. - * - * @return boolean TRUE if the marker image has a scaled size else FALSE. - */ - public function hasScaledSize() - { - return $this->scaledSize !== null; - } - - /** - * Gets the scaled size of the marker image. - * - * @return \Ivory\GoogleMap\Base\Size The marker image scaled size. - */ - public function getScaledSize() - { - return $this->scaledSize; - } - - /** - * Sets the scaled size of the marker image - * - * Available prototypes: - * - function setScaledSize(Ivory\GoogleMap\Base\Size $scaledSize = null) - * - function setScaledSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the scaled size is not valid. - */ - public function setScaledSize() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Size)) { - $this->scaledSize = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->scaledSize === null) { - $this->scaledSize = new Size(); - } - - $this->scaledSize->setWidth($args[0]); - $this->scaledSize->setHeight($args[1]); - - if (isset($args[2]) && is_string($args[2])) { - $this->scaledSize->setWidthUnit($args[2]); - } - - if (isset($args[3]) && is_string($args[3])) { - $this->scaledSize->setHeightUnit($args[3]); - } - } elseif (!isset($args[0])) { - $this->scaledSize = null; - } else { - throw OverlayException::invalidMarkerImageScaledSize(); - } - } - - /** - * Checks if the marker image has a size. - * - * @return boolean TRUE if the marker image has a size else FALSE. - */ - public function hasSize() - { - return $this->size !== null; - } - - /** - * Gets the size of the marker image. - * - * @return \Ivory\GoogleMap\Base\Size The marker image size. - */ - public function getSize() - { - return $this->size; - } - - /** - * Sets the size of the marker image. - * - * Available prototypes: - * - function setSize(Ivory\GoogleMap\Base\Size $size = null) - * - function setSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the size is not valid. - */ - public function setSize() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Size)) { - $this->size = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->size === null) { - $this->size = new Size($args[0], $args[1]); - } - - $this->size->setWidth($args[0]); - $this->size->setHeight($args[1]); - - if (isset($args[2]) && is_string($args[2])) { - $this->size->setWidthUnit($args[2]); - } - - if (isset($args[3]) && is_string($args[3])) { - $this->size->setHeightUnit($args[3]); - } - } elseif (!isset($args[0])) { - $this->size = null; - } else { - throw OverlayException::invalidMarkerImageSize(); - } - } -} diff --git a/src/Overlays/MarkerShape.php b/src/Overlays/MarkerShape.php index 1efbfbaa..fd90eb62 100644 --- a/src/Overlays/MarkerShape.php +++ b/src/Overlays/MarkerShape.php @@ -11,40 +11,40 @@ namespace Ivory\GoogleMap\Overlays; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; -use Ivory\GoogleMap\Exception\OverlayException; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; /** - * Marker shape which describes a google map marker shape. + * Marker shape. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerShape + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#MarkerShape * @author GeLo */ -class MarkerShape extends AbstractJavascriptVariableAsset +class MarkerShape extends AbstractVariableAsset { /** @var string */ protected $type; /** @var array */ - protected $coordinates; + protected $coordinates = array(); /** * Creates a marker shape. * - * @param string $type The marker shape type. - * @param array $coordinates The marker shape coordinates. + * @param string $type The type. + * @param array $coordinates The coordinates. */ - public function __construct($type = 'poly', array $coordinates = array(1, 1, 1, -1, -1, -1, -1, 1)) + public function __construct($type, array $coordinates) { - $this->setPrefixJavascriptVariable('marker_shape_'); + parent::__construct('marker_shape_'); + $this->setType($type); $this->setCoordinates($coordinates); } /** - * Gets the marker shape type. + * Gets the type. * - * @return string The marker sape type. + * @return string The type. */ public function getType() { @@ -52,29 +52,17 @@ public function getType() } /** - * Sets the marker shape type. - * - * The allowing marker shape type are : circle, poly & rect. - * - * @param string $type The marker schape type. + * Sets the type. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the type is not valid. + * @param string $type The type. */ public function setType($type) { - switch (strtolower($type)) { - case 'circle': - case 'poly': - case 'rect': - $this->type = $type; - break; - default: - throw OverlayException::invalidMarkerShapeType(); - } + $this->type = $type; } /** - * Resets the marker shape coordinates. + * Resets the coordinates. */ public function resetCoordinates() { @@ -82,9 +70,9 @@ public function resetCoordinates() } /** - * Cheks if the marker shape has coordinates + * Checks if there are coordinates. * - * @return boolean TRUE if the marker shape has coordinates else FALSE. + * @return boolean TRUE if there are coordinates else FALSE. */ public function hasCoordinates() { @@ -92,9 +80,9 @@ public function hasCoordinates() } /** - * Gets the marker shape coordinates. + * Gets the coordinates. * - * @return array The marker shape coordinates. + * @return array The coordinates. */ public function getCoordinates() { @@ -102,73 +90,58 @@ public function getCoordinates() } /** - * Sets the marker shape coordinates. + * Sets the coordinates. * - * @param array $coordinates The marker shape coordinates. - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the coordinates are not valid according to the type. + * @param array $coordinates The coordinates. */ public function setCoordinates(array $coordinates) { - switch (strtolower($this->type)) { - case 'circle': - if ((count($coordinates) === 3) - && is_numeric($coordinates[0]) - && is_numeric($coordinates[1]) - && is_numeric($coordinates[2]) - ) { - $this->coordinates = $coordinates; - } else { - throw OverlayException::invalidMarkerShapeCircleCoordinates(); - } - break; - case 'poly': - if ((count($coordinates) <= 0) || ((count($coordinates) % 2) !== 0)) { - throw OverlayException::invalidMarkerShapePolyCoordinates(); - } - - foreach ($coordinates as $coordinate) { - if (!is_numeric($coordinate)) { - throw OverlayException::invalidMarkerShapePolyCoordinates(); - } - } - - $this->coordinates = $coordinates; - break; - case 'rect': - if ((count($coordinates) === 4) - && is_numeric($coordinates[0]) - && is_numeric($coordinates[1]) - && is_numeric($coordinates[2]) - && is_numeric($coordinates[3]) - ) { - $this->coordinates = $coordinates; - } else { - throw OverlayException::invalidMarkerShapeRectCoordinates(); - } - break; - } + $this->coordinates = $coordinates; } /** - * Adds a coordinate to the marker shape if the type is poly. + * Sets the circle coordinates. * - * @param integer $x The X coordinate. - * @param integer $y The Y coordinate. + * @param float $x The X. + * @param float $y The Y. + * @param float $radius The radius. + */ + public function setCircleCoordinates($x, $y, $radius) + { + $this->coordinates = array($x, $y, $radius); + } + + /** + * Sets the rectangle coordinates. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the type is not poly or if the poly coordinate is not - * valid. + * @param float $x1 The X1. + * @param float $y1 The Y1. + * @param float $x2 The X2. + * @param float $y2 The Y2. */ - public function addPolyCoordinate($x, $y) + public function setRectangleCoordinates($x1, $y1, $x2, $y2) { - if ($this->type !== 'poly') { - throw OverlayException::invalidMarkerShapeAddPolyCoordinateCall(); - } + $this->coordinates = array($x1, $y1, $x2, $y2); + } - if (!is_numeric($x) || !is_numeric($y)) { - throw OverlayException::invalidMarkerShapePolyCoordinate(); - } + /** + * Sets the polygon coordinates. + * + * @param array $polygonCoordinates The polygon coordinates. + */ + public function setPolygonCoordinates(array $polygonCoordinates) + { + $this->setCoordinates($polygonCoordinates); + } + /** + * Adds a polygon coordinate. + * + * @param float $x The X. + * @param float $y The Y. + */ + public function addPolygonCoordinate($x, $y) + { $this->coordinates[] = $x; $this->coordinates[] = $y; } diff --git a/src/Overlays/MarkerShapeType.php b/src/Overlays/MarkerShapeType.php new file mode 100644 index 00000000..dff96765 --- /dev/null +++ b/src/Overlays/MarkerShapeType.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Overlays; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Marker shape type. + * + * @author GeLo + */ +class MarkerShapeType extends AbstractUninstantiableAsset +{ + const CIRCLE = 'circle'; + const POLYGON = 'poly'; + const RECTANGLE = 'rect'; +} diff --git a/src/Overlays/Overlays.php b/src/Overlays/Overlays.php new file mode 100644 index 00000000..7a47bed6 --- /dev/null +++ b/src/Overlays/Overlays.php @@ -0,0 +1,1027 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Overlays; + +/** + * Overlays. + * + * @author GeLo + */ +class Overlays +{ + /** @var \Ivory\GoogleMap\Overlays\MarkerCluster */ + protected $markerCluster; + + /** @var array */ + protected $circles = array(); + + /** @var array */ + protected $encodedPolylines = array(); + + /** @var array */ + protected $groundOverlays = array(); + + /** @var array */ + protected $infoWindows = array(); + + /** @var array */ + protected $polygons = array(); + + /** @var array */ + protected $polylines = array(); + + /** @var array */ + protected $rectangles = array(); + + /** @var array */ + protected $extends = array(); + + /** @var boolean */ + protected $autoZoom = false; + + /** + * Creates an overlays. + */ + public function __construct() + { + $this->setMarkerCluster(new MarkerCluster()); + } + + /** + * Gets the marker cluster. + * + * @return \Ivory\GoogleMap\Overlays\MarkerCluster The marker cluster. + */ + public function getMarkerCluster() + { + return $this->markerCluster; + } + + /** + * Sets the marker cluster. + * + * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. + */ + public function setMarkerCluster(MarkerCluster $markerCluster) + { + if ($this->markerCluster !== null) { + $this->removeExtends($this->markerCluster->getMarkers()); + } + + $this->markerCluster = $markerCluster; + $this->handleExtends($markerCluster->getMarkers()); + } + + /** + * Resets the markers. + */ + public function resetMarkers() + { + $this->removeExtends($this->markerCluster->getMarkers()); + $this->markerCluster->resetMarkers(); + } + + /** + * Checks if there are markers. + * + * @return boolean TRUE if there are markers else FALSE. + */ + public function hasMarkers() + { + return $this->markerCluster->hasMarkers(); + } + + /** + * Gets the markers. + * + * @return array The markers. + */ + public function getMarkers() + { + return $this->markerCluster->getMarkers(); + } + + /** + * Sets the markers. + * + * @param array $markers The markers. + */ + public function setMarkers(array $markers) + { + $this->resetMarkers(); + $this->addMarkers($markers); + } + + /** + * Adds the markers. + * + * @param array $markers The markers. + */ + public function addMarkers(array $markers) + { + $this->markerCluster->addMarkers($markers); + $this->handleExtends($markers); + } + + /** + * Removes the markers. + * + * @param array $markers The markers. + */ + public function removeMarkers(array $markers) + { + $this->markerCluster->removeMarkers($markers); + $this->removeExtends($markers); + } + + /** + * Checks if there is a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + * + * @return boolean TRUE if there is the marker else FALSE. + */ + public function hasMarker(Marker $marker) + { + return $this->markerCluster->hasMarker($marker); + } + + /** + * Adds a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + public function addMarker(Marker $marker) + { + $this->markerCluster->addMarker($marker); + $this->handleExtend($marker); + } + + /** + * Removes a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + public function removeMarker(Marker $marker) + { + $this->markerCluster->removeMarker($marker); + $this->removeExtend($marker); + } + + /** + * Resets the circles. + */ + public function resetCircles() + { + $this->removeExtends($this->circles); + $this->circles = array(); + } + + /** + * Checks if there are circles. + * + * @return boolean TRUE if there are circles else FALSE. + */ + public function hasCircles() + { + return !empty($this->circles); + } + + /** + * Gets the circles + * + * @return array The circles. + */ + public function getCircles() + { + return $this->circles; + } + + /** + * Sets the circles. + * + * @param array $circles The circles. + */ + public function setCircles(array $circles) + { + $this->resetCircles(); + $this->addCircles($circles); + } + + /** + * Adds the circles. + * + * @param array $circles The circles. + */ + public function addCircles(array $circles) + { + foreach ($circles as $circle) { + $this->addCircle($circle); + } + } + + /** + * Removes the circles. + * + * @param array $circles The circles. + */ + public function removeCircles(array $circles) + { + foreach ($circles as $circle) { + $this->removeCircle($circle); + } + } + + /** + * Checks if there is a circle. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + * + * @return boolean TRUE if there is the circle else FALSE. + */ + public function hasCircle(Circle $circle) + { + return in_array($circle, $this->circles, true); + } + + /** + * Adds a circle. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + */ + public function addCircle(Circle $circle) + { + if (!$this->hasCircle($circle)) { + $this->circles[] = $circle; + } + + $this->handleExtend($circle); + } + + /** + * Removes a circle. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + */ + public function removeCircle(Circle $circle) + { + unset($this->circles[array_search($circle, $this->circles, true)]); + $this->removeExtend($circle); + } + + /** + * Resets the encoded polylines. + */ + public function resetEncodedPolylines() + { + $this->removeExtends($this->encodedPolylines); + $this->encodedPolylines = array(); + } + + /** + * Checks if there are encoded polylines. + * + * @return boolean TRUE if there are encoded polylines else FALSE. + */ + public function hasEncodedPolylines() + { + return !empty($this->encodedPolylines); + } + + /** + * Gets the encoded polylines. + * + * @return array The encoded polylines. + */ + public function getEncodedPolylines() + { + return $this->encodedPolylines; + } + + /** + * Sets the encoded polylines. + * + * @param array $encodedPolylines The encoded polylines. + */ + public function setEncodedPolylines(array $encodedPolylines) + { + $this->resetEncodedPolylines(); + $this->addEncodedPolylines($encodedPolylines); + } + + /** + * Adds the encoded polylines. + * + * @param array $encodedPolylines The encoded polylines. + */ + public function addEncodedPolylines(array $encodedPolylines) + { + foreach ($encodedPolylines as $encodedPolyline) { + $this->addEncodedPolyline($encodedPolyline); + } + } + + /** + * Removes the encoded polylines. + * + * @param array $encodedPolylines The encoded polylines. + */ + public function removeEncocodedPolylines(array $encodedPolylines) + { + foreach ($encodedPolylines as $encodedPolyline) { + $this->removeEncodedPolyline($encodedPolyline); + } + } + + /** + * Checks if there is an encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + * + * @return boolean TRUE if there is the encoded polyline else FALSE. + */ + public function hasEncodedPolyline(EncodedPolyline $encodedPolyline) + { + return in_array($encodedPolyline, $this->encodedPolylines, true); + } + + /** + * Adds an encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + */ + public function addEncodedPolyline(EncodedPolyline $encodedPolyline) + { + if (!$this->hasEncodedPolyline($encodedPolyline)) { + $this->encodedPolylines[] = $encodedPolyline; + } + + $this->handleExtend($encodedPolyline); + } + + /** + * Removes an encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + */ + public function removeEncodedPolyline(EncodedPolyline $encodedPolyline) + { + unset($this->encodedPolylines[array_search($encodedPolyline, $this->encodedPolylines, true)]); + $this->removeExtend($encodedPolyline); + } + + /** + * Resets the ground overlays. + */ + public function resetGroundOverlays() + { + $this->removeExtends($this->groundOverlays); + $this->groundOverlays = array(); + } + + /** + * Checks if there are ground overlays. + * + * @return boolean TRUE if there are ground overlays else FALSE. + */ + public function hasGroundOverlays() + { + return !empty($this->groundOverlays); + } + + /** + * Gets the ground overlays. + * + * @return array The ground overlays. + */ + public function getGroundOverlays() + { + return $this->groundOverlays; + } + + /** + * Sets the ground overlays. + * + * @param array $groundOverlays The ground overlays. + */ + public function setGroundOverlays(array $groundOverlays) + { + $this->resetGroundOverlays(); + $this->addGroundOverlays($groundOverlays); + } + + /** + * Adds the ground overlays. + * + * @param array $groundOverlays The ground overlays. + */ + public function addGroundOverlays(array $groundOverlays) + { + foreach ($groundOverlays as $groundOverlay) { + $this->addGroundOverlay($groundOverlay); + } + } + + /** + * Removes the ground overlays. + * + * @param array $groundOverlays The ground overlays. + */ + public function removeGroundOverlays(array $groundOverlays) + { + foreach ($groundOverlays as $groundOverlay) { + $this->removeGroundOverlay($groundOverlay); + } + } + + /** + * Checks if there is a ground overlay. + * + * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. + * + * @return boolean TRUE if there is the ground overlay else FALSE. + */ + public function hasGroundOverlay(GroundOverlay $groundOverlay) + { + return in_array($groundOverlay, $this->groundOverlays, true); + } + + /** + * Adds a ground overlay. + * + * @param \Ivory\GoogleMapBundle\Model\Overlays\GroupOverlay $groundOverlay The ground overlay. + */ + public function addGroundOverlay(GroundOverlay $groundOverlay) + { + if (!$this->hasGroundOverlay($groundOverlay)) { + $this->groundOverlays[] = $groundOverlay; + } + + $this->handleExtend($groundOverlay); + } + + /** + * Removes a ground overlay. + * + * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. + */ + public function removeGroundOverlay(GroundOverlay $groundOverlay) + { + unset($this->groundOverlays[array_search($groundOverlay, $this->groundOverlays, true)]); + $this->removeExtend($groundOverlay); + } + + /** + * Resets the info windows. + */ + public function resetInfoWindows() + { + $this->removeExtends($this->infoWindows); + $this->infoWindows = array(); + } + + /** + * Checks if there are info windows. + * + * @return boolean TRUE if there are info windows else FALSE. + */ + public function hasInfoWindows() + { + return !empty($this->infoWindows); + } + + /** + * Gets the info windows. + * + * @return array The info windows. + */ + public function getInfoWindows() + { + return $this->infoWindows; + } + + /** + * Sets the info windows. + * + * @param array $infoWindows The info windows. + */ + public function setInfoWindows(array $infoWindows) + { + $this->resetInfoWindows(); + $this->addInfoWindows($infoWindows); + } + + /** + * Adds the info windows. + * + * @param array $infoWindows The info windows. + */ + public function addInfoWindows(array $infoWindows) + { + foreach ($infoWindows as $infoWindow) { + $this->addInfoWindow($infoWindow); + } + } + + /** + * Removes the info windows. + * + * @param array $infoWindows The info windows. + */ + public function removeInfoWindows(array $infoWindows) + { + foreach ($infoWindows as $infoWindow) { + $this->removeInfoWindow($infoWindow); + } + } + + /** + * Checks if there is an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + * + * @return boolean TRUE if there is the info window else FALSE. + */ + public function hasInfoWindow(InfoWindow $infoWindow) + { + return in_array($infoWindow, $this->infoWindows, true); + } + + /** + * Adds an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + public function addInfoWindow(InfoWindow $infoWindow) + { + if (!$this->hasInfoWindow($infoWindow)) { + $this->infoWindows[] = $infoWindow; + } + + $this->handleExtend($infoWindow); + } + + /** + * Removes an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + public function removeInfoWindow(InfoWindow $infoWindow) + { + unset($this->infoWindows[array_search($infoWindow, $this->infoWindows, true)]); + $this->removeExtend($infoWindow); + } + + /** + * Resets the polygons. + */ + public function resetPolygons() + { + $this->removeExtends($this->polygons); + $this->polygons = array(); + } + + /** + * Checks if there are polygons. + * + * @return boolean TRUE if there are polygons else FALSE. + */ + public function hasPolygons() + { + return !empty($this->polygons); + } + + /** + * Gets the polygons. + * + * @return array The polygons. + */ + public function getPolygons() + { + return $this->polygons; + } + + /** + * Sets the polygons. + * + * @param array $polygons The polygons. + */ + public function setPolygons(array $polygons) + { + $this->resetPolygons(); + $this->addPolygons($polygons); + } + + /** + * Adds the polygons. + * + * @param array $polygons The polygons. + */ + public function addPolygons(array $polygons) + { + foreach ($polygons as $polygon) { + $this->addPolygon($polygon); + } + } + + /** + * Removes the polygons. + * + * @param array $polygons The polygons. + */ + public function removePolygons(array $polygons) + { + foreach ($polygons as $polygon) { + $this->removePolygon($polygon); + } + } + + /** + * Checks if there is a polygon. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + * + * @return boolean TRUE if there is the polygon else FALSE. + */ + public function hasPolygon(Polygon $polygon) + { + return in_array($polygon, $this->polygons, true); + } + + /** + * Adds a polygon. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + */ + public function addPolygon(Polygon $polygon) + { + if (!$this->hasPolygon($polygon)) { + $this->polygons[] = $polygon; + } + + $this->handleExtend($polygon); + } + + /** + * Removes a polygon. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + */ + public function removePolygon(Polygon $polygon) + { + unset($this->polygons[array_search($polygon, $this->polygons, true)]); + $this->removeExtend($polygon); + } + + /** + * Resets the polylines. + */ + public function resetPolylines() + { + $this->removeExtends($this->polylines); + $this->polylines = array(); + } + + /** + * Checks if there are polylines. + * + * @return boolean TRUE if there are polylines else FALSE. + */ + public function hasPolylines() + { + return !empty($this->polylines); + } + + /** + * Gets the polylines. + * + * @return array The polylines. + */ + public function getPolylines() + { + return $this->polylines; + } + + /** + * Sets the polylines. + * + * @param array $polylines The polylines. + */ + public function setPolylines(array $polylines) + { + $this->resetPolylines(); + $this->addPolylines($polylines); + } + + /** + * Adds the polylines. + * + * @param array $polylines The polylines. + */ + public function addPolylines(array $polylines) + { + foreach ($polylines as $polyline) { + $this->addPolyline($polyline); + } + } + + /** + * Removes the polylines. + * + * @param array $polylines The polylines. + */ + public function removePolylines(array $polylines) + { + foreach ($polylines as $polyline) { + $this->removePolyline($polyline); + } + } + + /** + * Checks if there is a polyline. + * + * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. + * + * @return boolean TRUE if there is the polyline else FALSE. + */ + public function hasPolyline(Polyline $polyline) + { + return in_array($polyline, $this->polylines, true); + } + + /** + * Adds a polyline. + * + * @param \Ivory\GoogleMap\Overlays\Polyline The polyline. + */ + public function addPolyline(Polyline $polyline) + { + if (!$this->hasPolyline($polyline)) { + $this->polylines[] = $polyline; + } + + $this->handleExtend($polyline); + } + + /** + * Removes a polyline. + * + * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. + */ + public function removePolyline(Polyline $polyline) + { + unset($this->polylines[array_search($polyline, $this->polylines, true)]); + $this->removeExtend($polyline); + } + + /** + * Resets the rectangles. + */ + public function resetRectangles() + { + $this->removeExtends($this->rectangles); + $this->rectangles = array(); + } + + /** + * Checks if there are rectangles. + * + * @return boolean TRUE if there are rectangles else FALSE. + */ + public function hasRectangles() + { + return !empty($this->rectangles); + } + + /** + * Gets the rectangles. + * + * @return array The rectangles. + */ + public function getRectangles() + { + return $this->rectangles; + } + + /** + * Sets the rectangles. + * + * @param array $rectangles The rectangles. + */ + public function setRectangles(array $rectangles) + { + $this->resetRectangles(); + $this->addRectangles($rectangles); + } + + /** + * Adds the rectangles. + * + * @param array $rectangles The rectangles. + */ + public function addRectangles(array $rectangles) + { + foreach ($rectangles as $rectangle) { + $this->addRectangle($rectangle); + } + } + + /** + * Removes the rectangles. + * + * @param array $rectangles The rectangles. + */ + public function removeRectangles(array $rectangles) + { + foreach ($rectangles as $rectangle) { + $this->removeRectangle($rectangle); + } + } + + /** + * Checks if there is a rectangle. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. + * + * @return boolean TRUE if there is the rectangle else FALSE. + */ + public function hasRectangle(Rectangle $rectangle) + { + return in_array($rectangle, $this->rectangles, true); + } + + /** + * Adds a rectangle. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. + */ + public function addRectangle(Rectangle $rectangle) + { + if (!$this->hasRectangle($rectangle)) { + $this->rectangles[] = $rectangle; + } + + $this->handleExtend($rectangle); + } + + /** + * Removes a rectangle. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. + */ + public function removeRectangle(Rectangle $rectangle) + { + unset($this->rectangles[array_search($rectangle, $this->rectangles, true)]); + $this->removeExtend($rectangle); + } + + /** + * Resets the extends. + */ + public function resetExtends() + { + $this->extends = array(); + } + + /** + * Checks if there are extends. + * + * @return boolean TRUE if there are extends else FALSE. + */ + public function hasExtends() + { + return !empty($this->extends); + } + + /** + * Gets the extends. + * + * @return array The extends. + */ + public function getExtends() + { + return $this->extends; + } + + /** + * Sets the extends. + * + * @param array $extends The extends. + */ + public function setExtends(array $extends) + { + $this->resetExtends(); + $this->addExtends($extends); + } + + /** + * Adds the extends. + * + * @param array $extends The extends. + */ + public function addExtends(array $extends) + { + foreach ($extends as $extend) { + $this->addExtend($extend); + } + } + + /** + * Removes the extends. + * + * @param array $extends The extends. + */ + public function removeExtends(array $extends) + { + foreach ($extends as $extend) { + $this->removeExtend($extend); + } + } + + /** + * Checks if there is the extend. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The extend. + * + * @return boolean TRUE if there is the extend else FALSE. + */ + public function hasExtend(ExtendableInterface $extend) + { + return in_array($extend, $this->extends, true); + } + + /** + * Adds an extend. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The extend. + */ + public function addExtend(ExtendableInterface $extend) + { + if (!$this->hasExtend($extend)) { + $this->extends[] = $extend; + } + } + + /** + * Removes an extend. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The extend. + */ + public function removeExtend(ExtendableInterface $extend) + { + unset($this->extends[array_search($extend, $this->extends, true)]); + } + + /** + * Check if it zooms automatically on the overlays. + * + * @return boolean TRUE if it zooms automatically on the overlays else FALSE. + */ + public function isAutoZoom() + { + return $this->autoZoom; + } + + /** + * Sets if it zooms automatically on the overlays. + * + * @param boolean $autoZoom TRUE if it zooms automatically on the overlays else FALSE. + */ + public function setAutoZoom($autoZoom) + { + $this->autoZoom = $autoZoom; + } + + /** + * Handles the extends. + * + * @param array $extends The extends. + */ + protected function handleExtends(array $extends) + { + foreach ($extends as $extend) { + $this->handleExtend($extend); + } + } + + /** + * Handles an extend. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extend The extend. + */ + protected function handleExtend(ExtendableInterface $extend) + { + if ($this->autoZoom) { + $this->addExtend($extend); + } + } +} diff --git a/src/Overlays/Polygon.php b/src/Overlays/Polygon.php index da67fed6..75f19c29 100644 --- a/src/Overlays/Polygon.php +++ b/src/Overlays/Polygon.php @@ -12,37 +12,44 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; +use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Polygon which describes a google map polygon. + * Polygon. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Polygon + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Polygon * @author GeLo */ class Polygon extends AbstractOptionsAsset implements ExtendableInterface { /** @var array */ - protected $coordinates; + protected $coordinates = array(); /** * Creates a polygon. * - * @param array $coordinates The polygon coordinates. + * @param array $coordinates The coordinates. */ - public function __construct(array $coordinates = array()) + public function __construct(array $coordinates) { - parent::__construct(); + parent::__construct('polygon_'); - $this->setPrefixJavascriptVariable('polygon_'); - $this->setCoordinates($coordinates); + $this->addCoordinates($coordinates); } /** - * Checks if polygon has coordinates. + * Resets the coordinates. + */ + public function resetCoordinates() + { + $this->coordinates = array(); + } + + /** + * Checks if there are coordinates. * - * @return boolean TRUE if the polygon has coordinates else FALSE. + * @return boolean TRUE if there are coordinates else FALSE. */ public function hasCoordinates() { @@ -50,9 +57,9 @@ public function hasCoordinates() } /** - * Gets the polygon coordinates. + * Gets the coordinates. * - * @return array The polygon coordinates. + * @return array The coordinates. */ public function getCoordinates() { @@ -60,44 +67,79 @@ public function getCoordinates() } /** - * Sets the polygon coordinates. + * Sets the coordinates. * - * @param array $coordinates The polygon coordinates. + * @param array $coordinates The coordinates. */ - public function setCoordinates($coordinates) + public function setCoordinates(array $coordinates) { - $this->coordinates = array(); + $this->resetCoordinates(); + $this->addCoordinates($coordinates); + } + /** + * Adds the coordinates. + * + * @param array $coordinates The coordinates. + */ + public function addCoordinates(array $coordinates) + { foreach ($coordinates as $coordinate) { $this->addCoordinate($coordinate); } } /** - * Adds a coordinate to the polygon. - * - * Available prototypes: - * - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate) - * - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true) + * Removes the coordinates. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the coordinate is not valid. + * @param array $coordinates The coordinates. */ - public function addCoordinate() + public function removeCoordinates(array $coordinates) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->coordinates[] = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $coordinate = new Coordinate($args[0], $args[1]); + foreach ($coordinates as $coordinate) { + $this->removeCoordinate($coordinate); + } + } - if (isset($args[2]) && is_bool($args[2])) { - $coordinate->setNoWrap($args[2]); - } + /** + * Checks if there is a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + * + * @return boolean TRUE if there is the coordinate else FALSE. + */ + public function hasCoordinate(Coordinate $coordinate) + { + return in_array($coordinate, $this->coordinates, true); + } + /** + * Adds a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + public function addCoordinate(Coordinate $coordinate) + { + if (!$this->hasCoordinate($coordinate)) { $this->coordinates[] = $coordinate; - } else { - throw OverlayException::invalidPolygonCoordinate(); } } + + /** + * Removes a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + public function removeCoordinate(Coordinate $coordinate) + { + unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]); + } + + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.getPath().forEach(function(e){%s.extend(e);})', $this->variable, $bound->getVariable()); + } } diff --git a/src/Overlays/Polyline.php b/src/Overlays/Polyline.php index 265771fe..bc8c9c8d 100644 --- a/src/Overlays/Polyline.php +++ b/src/Overlays/Polyline.php @@ -12,37 +12,44 @@ namespace Ivory\GoogleMap\Overlays; use Ivory\GoogleMap\Assets\AbstractOptionsAsset; +use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Polyline which describes a google map polyline. + * Polyline. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Polyline + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Polyline * @author GeLo */ class Polyline extends AbstractOptionsAsset implements ExtendableInterface { /** @var array */ - protected $coordinates; + protected $coordinates = array(); /** * Creates a polyline. * - * @param array $coordinates The polyline coordinates. + * @param array $coordinates The coordinates. */ - public function __construct(array $coordinates = array()) + public function __construct(array $coordinates) { - parent::__construct(); + parent::__construct('polyline_'); - $this->setPrefixJavascriptVariable('polyline_'); - $this->setCoordinates($coordinates); + $this->addCoordinates($coordinates); } /** - * Checks if the polyline has coordinates. + * Resets the coordinates. + */ + public function resetCoordinates() + { + $this->coordinates = array(); + } + + /** + * Checks if there are coordinates. * - * @return boolean TRUE if the polyline has coordinates else FALSE. + * @return boolean TRUE if there are coordinates else FALSE. */ public function hasCoordinates() { @@ -50,9 +57,9 @@ public function hasCoordinates() } /** - * Gets the polyline coordinates. + * Gets the coordinates. * - * @return array The polyline coordinates. + * @return array The coordinates. */ public function getCoordinates() { @@ -60,44 +67,79 @@ public function getCoordinates() } /** - * Sets the polyline coordinates. + * Sets the coordinates. * - * @param array $coordinates The polyline coordinates. + * @param array $coordinates The coordinates. */ - public function setCoordinates($coordinates) + public function setCoordinates(array $coordinates) { - $this->coordinates = array(); + $this->resetCoordinates(); + $this->addCoordinates($coordinates); + } + /** + * Adds the coordinates. + * + * @param array $coordinates The coordinates. + */ + public function addCoordinates(array $coordinates) + { foreach ($coordinates as $coordinate) { $this->addCoordinate($coordinate); } } /** - * Add a coordinate to the polyline. - * - * Available prototypes: - * - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate) - * - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true) + * Removes the coordinates. * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the coordinate is not valid. + * @param array $coordinates The coordinates. */ - public function addCoordinate() + public function removeCoordinates(array $coordinates) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->coordinates[] = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $coordinate = new Coordinate($args[0], $args[1]); + foreach ($coordinates as $coordinate) { + $this->removeCoordinate($coordinate); + } + } - if (isset($args[2]) && is_bool($args[2])) { - $coordinate->setNoWrap($args[2]); - } + /** + * Checks if there is a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + * + * @return boolean TRUE if there is a coordinate else FALSE. + */ + public function hasCoordinate(Coordinate $coordinate) + { + return in_array($coordinate, $this->coordinates, true); + } + /** + * Adds a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + public function addCoordinate(Coordinate $coordinate) + { + if (!$this->hasCoordinate($coordinate)) { $this->coordinates[] = $coordinate; - } else { - throw OverlayException::invalidPolylineCoordinate(); } } + + /** + * Removes a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + public function removeCoordinate(Coordinate $coordinate) + { + unset($this->coordinates[array_search($coordinate, $this->coordinates, true)]); + } + + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.getPath().forEach(function(e){%s.extend(e);})', $this->variable, $bound->getVariable()); + } } diff --git a/src/Overlays/Rectangle.php b/src/Overlays/Rectangle.php index 478f83ef..6e75a9e1 100644 --- a/src/Overlays/Rectangle.php +++ b/src/Overlays/Rectangle.php @@ -13,12 +13,11 @@ use Ivory\GoogleMap\Assets\AbstractOptionsAsset; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\OverlayException; /** - * Rectangle which describes a google map rectangle. + * Rectangle. * + * @link https://developers.google.com/maps/documentation/javascript/reference#Rectangle * @author GeLo */ class Rectangle extends AbstractOptionsAsset implements ExtendableInterface @@ -28,24 +27,20 @@ class Rectangle extends AbstractOptionsAsset implements ExtendableInterface /** * Creates a rectangle. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function __construct(Bound $bound = null) + public function __construct(Bound $bound) { - parent::__construct(); - - $this->setPrefixJavascriptVariable('rectangle_'); - - if ($bound === null) { - $bound = new Bound(new Coordinate(-1, -1), new Coordinate(1, 1)); - } + parent::__construct('rectangle_'); $this->setBound($bound); } /** - * Gets the rectangle bound. + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The rectangle bound. + * @return \Ivory\GoogleMap\Base\Bound The bound. */ public function getBound() { @@ -53,54 +48,20 @@ public function getBound() } /** - * Sets the rectangle bound. + * Sets the bound. * - * Available prototypes: - * - function setBound(Ivory\GoogleMap\Base\Bound $bound) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - * - * @throws \Ivory\GoogleMap\Exception\OverlayException If the bound is not valid. + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function setBound() + public function setBound(Bound $bound) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Bound)) { - if (!$args[0]->hasCoordinates()) { - throw OverlayException::invalidRectangleBoundCoordinates(); - } - - $this->bound = $args[0]; - } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate)) - && (isset($args[1]) && ($args[1] instanceof Coordinate)) - ) { - $this->bound->setSouthWest($args[0]); - $this->bound->setNorthEast($args[1]); - } elseif ((isset($args[0]) && is_numeric($args[0])) - && (isset($args[1]) && is_numeric($args[1])) - && (isset($args[2]) && is_numeric($args[2])) - && (isset($args[3]) && is_numeric($args[3])) - ) { - $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); - $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); - - if (isset($args[4]) && is_bool($args[4])) { - $this->bound->getSouthWest()->setNoWrap($args[4]); - } + $this->bound = $bound; + } - if (isset($args[5]) && is_bool($args[5])) { - $this->bound->getNorthEast()->setNoWrap($args[5]); - } - } else { - throw OverlayException::invalidRectangleBound(); - } + /** + * {@inheritdoc} + */ + public function renderExtend(Bound $bound) + { + return sprintf('%s.union(%s)', $bound->getVariable(), $this->bound->getVariable()); } } diff --git a/src/Places/Autocomplete.php b/src/Places/Autocomplete.php index bb56613d..747b2ef6 100644 --- a/src/Places/Autocomplete.php +++ b/src/Places/Autocomplete.php @@ -11,66 +11,52 @@ namespace Ivory\GoogleMap\Places; -use Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset; +use Ivory\GoogleMap\Assets\AbstractVariableAsset; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\PlaceException; /** - * Places autocomplete. + * Autocomplete. * + * @link http://developers.google.com/maps/documentation/javascript/reference#Autocomplete * @author GeLo */ -class Autocomplete extends AbstractJavascriptVariableAsset +class Autocomplete extends AbstractVariableAsset { /** @var string */ protected $inputId; - /** @var \Ivory\GoogleMap\Base\Bound */ - protected $bound; - - /** @var array */ - protected $types; - /** @var array */ - protected $componentRestrictions; + protected $inputAttributes = array(); - /** @var string */ + /** @var string|null */ protected $value; + /** @var \Ivory\GoogleMap\Base\Bound|null */ + protected $bound; + /** @var array */ - protected $inputAttributes; + protected $types = array(); - /** @var boolean */ - protected $async; + /** @var array */ + protected $componentRestrictions = array(); /** @var string */ - protected $language; + protected $language = 'en'; /** - * Creates a place autocomplete. + * Creates an autocomplete. */ public function __construct() { - $this->setPrefixJavascriptVariable('place_autocomplete_'); - - $this->inputId = 'place_input'; - $this->inputAttributes = array( - 'type' => 'text', - 'placeholder' => 'off', - ); - - $this->types = array(); - $this->componentRestrictions = array(); + parent::__construct('places_autocomplete_'); - $this->async = false; - $this->language = 'en'; + $this->setInputId($this->variable); } /** - * Gets the autocomplete input ID. + * Gets the input id. * - * @return string The autocomplete input ID. + * @return string The input id. */ public function getInputId() { @@ -78,386 +64,392 @@ public function getInputId() } /** - * Sets the autocomplete input ID. + * Sets the input id. * - * @param string $inputId The autocomplete input ID. - * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the input ID is not a valid string. + * @param string $inputId The input id. */ public function setInputId($inputId) { - if (!is_string($inputId) || (strlen($inputId) === 0)) { - throw PlaceException::invalidAutocompleteInputId(); - } - $this->inputId = $inputId; } /** - * Checks if the autocomplete has a bound. + * Resets the input attributes. + */ + public function resetInputAttributes() + { + $this->inputAttributes = array(); + } + + /** + * Checks if there are input attributes. * - * @return boolean TRUE if the autocomplete has a bound else FALSE. + * @return boolean TRUE if there are input attributes else FALSE. */ - public function hasBound() + public function hasInputAttributes() { - return $this->bound !== null; + return !empty($this->inputAttributes); } /** - * Gets the autocomplete bound. + * Gets the input attributes. * - * @return \Ivory\GoogleMap\Base\Bound The autocomplete bound. + * @return array The input attributes. */ - public function getBound() + public function getInputAttributes() { - return $this->bound; + return $this->inputAttributes; + } + + /** + * Sets the input attributes. + * + * @param array $inputAttributes The input attributes. + */ + public function setInputAttributes(array $inputAttributes) + { + $this->resetInputAttributes(); + $this->addInputAttributes($inputAttributes); } /** - * Sets the autocomplete bound. - * - * Available prototypes: - * - function setBound(Ivory\GoogleMap\Base\Bound $bound = null) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the bound is not valid (prototypes). - */ - public function setBound() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Bound)) { - $this->bound = $args[0]; - } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate)) - && (isset($args[1]) && ($args[1] instanceof Coordinate)) - ) { - if ($this->bound === null) { - $this->bound = new Bound(); - } - - $this->bound->setSouthWest($args[0]); - $this->bound->setNorthEast($args[1]); - } elseif ((isset($args[0]) && is_numeric($args[0])) - && (isset($args[1]) && is_numeric($args[1])) - && (isset($args[2]) && is_numeric($args[2])) - && (isset($args[3]) && is_numeric($args[3])) - ) { - if ($this->bound === null) { - $this->bound = new Bound(); - } - - $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); - $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); - - if (isset($args[4]) && is_bool($args[4])) { - $this->bound->getSouthWest()->setNoWrap($args[4]); - } - - if (isset($args[5]) && is_bool($args[5])) { - $this->bound->getNorthEast()->setNoWrap($args[5]); - } - } elseif (!isset($args[0])) { - $this->bound = null; - } else { - throw PlaceException::invalidAutocompleteBound(); + * Adds the input attributes. + * + * @param array $inputAttributes The input attributes. + */ + public function addInputAttributes(array $inputAttributes) + { + foreach ($inputAttributes as $name => $value) { + $this->setInputAttribute($name, $value); } } /** - * Checks if the autocomplete has types. + * Removes the input attributes. * - * @return boolean TRUE if the autocomplete has types else FALSE. + * @param array $names The input attribute names. */ - public function hasTypes() + public function removeInputAttributes(array $names) { - return !empty($this->types); + foreach ($names as $name) { + $this->removeInputAttribute($name); + } } /** - * Checks if the autocomplete has a specific type. + * Checks if there is an input attribute. * - * @param string $type The type. + * @param string $name The input attribute name. * - * @return boolean TRUE if the autocomplete has te specific type else FALSE. + * @return boolean TRUE if there is the input attribute else FALSE. */ - public function hasType($type) + public function hasInputAttribute($name) { - return array_search($type, $this->types) !== false; + return array_key_exists($name, $this->inputAttributes); } /** - * Gets the autocomplete types. + * Gets an input attribute. + * + * @param string $name The input attribute name. * - * @return array The autocomplete types. + * @return mixed The input attribute value. */ - public function getTypes() + public function getInputAttribute($name) { - return $this->types; + return $this->hasInputAttribute($name) ? $this->inputAttributes[$name] : null; } /** - * Sets the autocomplete types. + * Sets an input attribute. * - * @param array $types The autocomplete types. + * @param string $name The input attribute name. + * @param mixed $value The input attribute value. */ - public function setTypes(array $types) + public function setInputAttribute($name, $value) { - $this->types = array(); + $this->inputAttributes[$name] = $value; + } - foreach ($types as $type) { - $this->addType($type); - } + /** + * Removes an input attribute. + * + * @param string $name The input attribute name. + */ + public function removeInputAttribute($name) + { + unset($this->inputAttributes[$name]); } /** - * Adds a type to the autocomplete. + * Checks if there is a value. * - * @param string $type The type to add. + * @return boolean TRUE if there is a value else FALSE. + */ + public function hasValue() + { + return $this->value !== null; + } + + /** + * Gets the value. * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the type is not valid. - * @throws \Ivory\GoogleMap\Exception\PlaceException If the type already exists. + * @return string|null The value. */ - public function addType($type) + public function getValue() { - if (!in_array($type, AutocompleteType::getAvailableAutocompleteTypes())) { - throw PlaceException::invalidAutocompleteType(); - } + return $this->value; + } - if ($this->hasType($type)) { - throw PlaceException::autocompleteTypeAlreadyExists($type); - } + /** + * Sets the value. + * + * @param string $value The value. + */ + public function setValue($value) + { + $this->value = $value; + } - $this->types[] = $type; + /** + * Checks if there is a bound. + * + * @return boolean TRUE if there is a bound else FALSE. + */ + public function hasBound() + { + return $this->bound !== null; } /** - * Removes a type from the autocomplete. + * Gets the bound. * - * @param string $type The type to remove. + * @return \Ivory\GoogleMap\Base\Bound|null The bound. + */ + public function getBound() + { + return $this->bound; + } + + /** + * Sets the bound. * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the type does not exist. + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. */ - public function removeType($type) + public function setBound(Bound $bound = null) { - if (!$this->hasType($type)) { - throw PlaceException::autocompleteTypeDoesNotExist($type); - } + $this->bound = $bound; + } - $index = array_search($type, $this->types); - unset($this->types[$index]); + /** + * Resets the types. + */ + public function resetTypes() + { + $this->types = array(); } /** - * Checks if the autocomplete has component restrictions. + * Checks if there are types. * - * @return boolean TRUE if the autocomplete has component restrictions else FALSE. + * @return boolean TRUE if there are types else FALSE. */ - public function hasComponentRestrictions() + public function hasTypes() { - return !empty($this->componentRestrictions); + return !empty($this->types); } /** - * Checks if the autocomplete has a specific component restriction type. - * - * @param string $type The component restriction type. + * Gets the types. * - * @return boolean TRUE if the autocomplete has the specific component restriction type else FALSE. + * @return array The types. */ - public function hasComponentRestriction($type) + public function getTypes() { - return isset($this->componentRestrictions[$type]); + return $this->types; } /** - * Gets the component restrictions. + * Sets the types. * - * @return array The component restrictions. + * @param array $types The types. */ - public function getComponentRestrictions() + public function setTypes(array $types) { - return $this->componentRestrictions; + $this->resetTypes(); + $this->addTypes($types); } /** - * Gets a specific component restriction. - * - * @param string $type The component restriction type. - * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the component restriction type does not exist. + * Adds the types. * - * @return mixed The component restriction. + * @param array $types The types. */ - public function getComponentRestriction($type) + public function addTypes(array $types) { - if (!$this->hasComponentRestriction($type)) { - throw PlaceException::autocompleteComponentRestrictionDoesNotExist($type); + foreach ($types as $type) { + $this->addType($type); } - - return $this->componentRestrictions[$type]; } /** - * Sets the component restrictions. + * Removes the types. * - * @param array $componentRestrictions The component restrictions. + * @param array $types The types. */ - public function setComponentRestrictions(array $componentRestrictions) + public function removeTypes(array $types) { - $this->componentRestrictions = array(); - - foreach ($componentRestrictions as $type => $value) { - $this->addComponentRestriction($type, $value); + foreach ($types as $type) { + $this->removeType($type); } } /** - * Adds a component restriction. + * Checks if there is a type. * - * @param string $type The component restriction type. - * @param mixed $value The component restriction value. + * @param string $type The type. * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the component restriction type is not supported. - * @throws \Ivory\GoogleMap\Exception\PlaceException If the component restriction type already exists. + * @return boolean TRUE if there is the type else FALSE. */ - public function addComponentRestriction($type, $value) + public function hasType($type) { - if (!in_array($type, AutocompleteComponentRestriction::getAvailableAutocompleteComponentRestrictions())) { - throw PlaceException::invalidAutocompleteComponentRestriction(); - } + return in_array($type, $this->types, true); + } - if ($this->hasComponentRestriction($type)) { - throw PlaceException::autocompleteComponentRestrictionAlreadyExists($type); + /** + * Adds a type. + * + * @param string $type The type. + */ + public function addType($type) + { + if (!$this->hasType($type)) { + $this->types[] = $type; } - - $this->componentRestrictions[$type] = $value; } /** - * Removes a component restriction. - * - * @param string $type The component restriction. + * Removes a type. * - * @throws \Ivory\GoogleMap\Exception\PlaceException If the component restriction type does not exists. + * @param string $type The type. */ - public function removeComponentRestriction($type) + public function removeType($type) { - if (!$this->hasComponentRestriction($type)) { - throw PlaceException::autocompleteComponentRestrictionDoesNotExist($type); - } + unset($this->types[array_search($type, $this->types, true)]); + } - unset($this->componentRestrictions[$type]); + /** + * Resets the component restrictions. + */ + public function resetComponentRestrictions() + { + $this->componentRestrictions = array(); } /** - * Checks if the autocomplete has a value. + * Checks if there are component restrictions. * - * @return boolean TRUE if the autocomplete has a value else FALSE. + * @return boolean TRUE if there are component restrictions else FALSE. */ - public function hasValue() + public function hasComponentRestrictions() { - return $this->value !== null; + return !empty($this->componentRestrictions); } /** - * Gets the autocomplete value. + * Gets the component restrictions. * - * @return string The autocomplete value. + * @return array The component restrictions. */ - public function getValue() + public function getComponentRestrictions() { - return $this->value; + return $this->componentRestrictions; } /** - * Sets the autocomplete value. + * Sets the component restrictions. * - * @param string $value The autocomplete value. + * @param array $componentRestrictions The component restrictions. */ - public function setValue($value) + public function setComponentRestrictions(array $componentRestrictions) { - $this->value = $value; + $this->resetComponentRestrictions(); + $this->addComponentRestrictions($componentRestrictions); } /** - * Gets the autocomplete input attributes. + * Adds the component restrictions. * - * @return array The autocomplete input attributes. + * @param array $componentRestrictions The component restrictions. */ - public function getInputAttributes() + public function addComponentRestrictions(array $componentRestrictions) { - return $this->inputAttributes; + foreach ($componentRestrictions as $name => $value) { + $this->setComponentRestriction($name, $value); + } } /** - * Sets the autocomplete input attributes. + * Removes the component restrictions. * - * @param array $inputAttributes The autocomplete input attributes. + * @param array $names The component restriction names. */ - public function setInputAttributes(array $inputAttributes) + public function removeComponentRestrictions(array $names) { - $this->inputAttributes = array(); - - foreach ($inputAttributes as $name => $value) { - $this->setInputAttribute($name, $value); + foreach ($names as $name) { + $this->removeComponentRestriction($name); } } /** - * Sets an autocomplete attribute. + * Checks if there is a component restriction. * - * You can remove an attribute by setting it to `null`. + * @param string $name The component restriction name. * - * @param string $name The attribute name. - * @param mixed $value The attribute value. + * @return boolean TRUE if there is the component restriction else FALSE. */ - public function setInputAttribute($name, $value) + public function hasComponentRestriction($name) { - if ($value === null) { - if (isset($this->inputAttributes[$name])) { - unset($this->inputAttributes[$name]); - } - } else { - $this->inputAttributes[$name] = $value; - } + return array_key_exists($name, $this->componentRestrictions); } /** - * Checks if the autocomplete is loaded asynchronously. + * Gets a component restriction. + * + * @param string $name The component restriction name. * - * @return boolean TRUE if the autocomplete is loaded asynchronounsly else FALSE. + * @return mixed The component restriction value. */ - public function isAsync() + public function getComponentRestriction($name) { - return $this->async; + return $this->hasComponentRestriction($name) ? $this->componentRestrictions[$name] : null; } /** - * Sets if the autocomplete is loaded asynchronously. + * Sets a component restriction. * - * @param boolean $async TRUE if the autocomplete is loaded asynchronously else FALSE. + * @param string $name The component restriction name. + * @param mixed $value The component restriction value. */ - public function setAsync($async) + public function setComponentRestriction($name, $value) { - if (!is_bool($async)) { - throw PlaceException::invalidAutocompleteAsync(); - } + $this->componentRestrictions[$name] = $value; + } - $this->async = $async; + /** + * Removes a component restriction. + * + * @param string $name The component restriction name. + */ + public function removeComponentRestriction($name) + { + unset($this->componentRestrictions[$name]); } /** - * Gets the autocomplete language + * Gets the language * - * @return string The autocomplete language + * @return string The language */ public function getLanguage() { @@ -465,9 +457,9 @@ public function getLanguage() } /** - * Sets the autocomplete language. + * Sets the language. * - * @param string $language The autocomplete language + * @param string $language The language */ public function setLanguage($language) { diff --git a/src/Places/AutocompleteComponentRestriction.php b/src/Places/AutocompleteComponentRestriction.php index 47e3b23d..3f6bfdfe 100644 --- a/src/Places/AutocompleteComponentRestriction.php +++ b/src/Places/AutocompleteComponentRestriction.php @@ -11,34 +11,16 @@ namespace Ivory\GoogleMap\Places; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Places autocomplete component restriction. + * Autocomplete component restriction. * + * @link http://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions * @author GeLo * @author Semyon Velichko */ -class AutocompleteComponentRestriction +class AutocompleteComponentRestriction extends AbstractUninstantiableAsset { const COUNTRY = 'country'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - } - - /** - * Gets the available component restrictions. - * - * @return array The available component restrictions. - */ - public static function getAvailableAutocompleteComponentRestrictions() - { - return array( - self::COUNTRY, - ); - } } \ No newline at end of file diff --git a/src/Places/AutocompleteType.php b/src/Places/AutocompleteType.php index b2ce866f..cfec3457 100644 --- a/src/Places/AutocompleteType.php +++ b/src/Places/AutocompleteType.php @@ -11,40 +11,18 @@ namespace Ivory\GoogleMap\Places; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * Place autocomplete type. + * Autocomplete type. * + * @link http://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions * @author GeLo */ -class AutocompleteType +class AutocompleteType extends AbstractUninstantiableAsset { const ESTABLISHMENT = 'establishment'; const GEOCODE = 'geocode'; const REGIONS = '(regions)'; const CITIES = '(cities)'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available autocomplete types. - * - * @return array The available autocomplete types. - */ - public static function getAvailableAutocompleteTypes() - { - return array( - self::ESTABLISHMENT, - self::GEOCODE, - self::REGIONS, - self::CITIES, - ); - } } diff --git a/src/Services/AbstractService.php b/src/Services/AbstractService.php index 0feac0b4..919afc2a 100644 --- a/src/Services/AbstractService.php +++ b/src/Services/AbstractService.php @@ -11,9 +11,7 @@ namespace Ivory\GoogleMap\Services; -use Ivory\GoogleMap\Exception\ServiceException; -use Ivory\GoogleMap\Services\Utils\XmlParser; -use Widop\HttpAdapter\HttpAdapterInterface; +use Ivory\HttpAdapter\HttpAdapterInterface; /** * Abstract class for accesing google API. @@ -22,7 +20,10 @@ */ abstract class AbstractService { - /** @var \Widop\HttpAdapter\HttpAdapterInterface */ + const FORMAT_JSON = 'json'; + const FORMAT_XML = 'xml'; + + /** @var \Ivory\HttpAdapter\HttpAdapterInterface */ protected $httpAdapter; /** @var string */ @@ -34,7 +35,7 @@ abstract class AbstractService /** @var string */ protected $format; - /** @var \Ivory\GoogleMap\Services\Utils\XmlParser */ + /** @var \Ivory\GoogleMap\Services\XmlParser */ protected $xmlParser; /** @var \Ivory\GoogleMap\Services\BusinessAccount */ @@ -43,37 +44,33 @@ abstract class AbstractService /** * Creates a service. * - * @param \Widop\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. - * @param string $url The service url. - * @param boolean $https TRUE if the service uses HTTPS else FALSE. - * @param string $format Format used by the service. - * @param \Ivory\GoogleMap\Services\Utils\XmlParser $xmlParser The xml parser. + * @param \Ivory\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. + * @param string $url The url. + * @param boolean $https TRUE if it uses https else FALSE. + * @param string $format The format. + * @param \Ivory\GoogleMap\Services\XmlParser $xmlParser The xml parser. * @param \Ivory\GoogleMap\Services\BusinessAccount $businessAccount The business account. */ public function __construct( HttpAdapterInterface $httpAdapter, $url, $https = false, - $format = 'json', + $format = self::FORMAT_JSON, XmlParser $xmlParser = null, BusinessAccount $businessAccount = null ) { - if ($xmlParser === null) { - $xmlParser = new XmlParser(); - } - $this->setHttpAdapter($httpAdapter); $this->setUrl($url); $this->setHttps($https); $this->setFormat($format); - $this->setXmlParser($xmlParser); + $this->setXmlParser($xmlParser ?: new XmlParser()); $this->setBusinessAccount($businessAccount); } /** * Gets the http adapter. * - * @return \Widop\HttpAdapter\HttpAdapterInterface The http adapter. + * @return \Ivory\HttpAdapter\HttpAdapterInterface The http adapter. */ public function getHttpAdapter() { @@ -83,7 +80,7 @@ public function getHttpAdapter() /** * Sets the http adapter. * - * @param \Widop\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. + * @param \Ivory\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. */ public function setHttpAdapter(HttpAdapterInterface $httpAdapter) { @@ -91,39 +88,29 @@ public function setHttpAdapter(HttpAdapterInterface $httpAdapter) } /** - * Gets the service API url according to the https flag. + * Gets the url. * - * @return string The service API url. + * @return string The url. */ public function getUrl() { - if ($this->isHttps()) { - return str_replace('http://', 'https://', $this->url); - } - - return $this->url; + return $this->isHttps() ? str_replace('http://', 'https://', $this->url) : $this->url; } /** - * Sets the service API url. + * Sets the url. * - * @param string $url The service API url. - * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the url is not valid. + * @param string $url The url. */ public function setUrl($url) { - if (!is_string($url)) { - throw ServiceException::invalidServiceUrl(); - } - $this->url = $url; } /** - * Checks if the service uses HTTPS. + * Checks if it uses https. * - * @return boolean TRUE if the service uses HTTPS else FALSE. + * @return boolean TRUE if it uses https else FALSE. */ public function isHttps() { @@ -131,25 +118,19 @@ public function isHttps() } /** - * Sets the service HTTPS flag. + * Sets if it uses https. * - * @param boolean $https TRUE if the service uses HTTPS else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the https flag is not valid. + * @param boolean $https TRUE if it uses https else FALSE. */ public function setHttps($https) { - if (!is_bool($https)) { - throw ServiceException::invalidServiceHttps(); - } - $this->https = $https; } /** - * Gets the service format. + * Gets the format. * - * @return string The service format. + * @return string The format. */ public function getFormat() { @@ -157,25 +138,19 @@ public function getFormat() } /** - * Sets the service format - * - * @param string $format The service format. + * Sets the format * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the format is not valid. + * @param string $format The format. */ public function setFormat($format) { - if (!in_array($format, array('json', 'xml'))) { - throw ServiceException::invalidServiceFormat(); - } - $this->format = $format; } /** * Gets the xml parser. * - * @return \Ivory\GoogleMap\Services\Utils\XmlParser The xml parser. + * @return \Ivory\GoogleMap\Services\XmlParser The xml parser. */ public function getXmlParser() { @@ -185,7 +160,7 @@ public function getXmlParser() /** * Sets the xml parser. * - * @param \Ivory\GoogleMap\Services\Geocoding\XmlParser $xmlParser The xml parser. + * @param \Ivory\GoogleMap\Services\XmlParser $xmlParser The xml parser. */ public function setXmlParser(XmlParser $xmlParser) { @@ -193,9 +168,9 @@ public function setXmlParser(XmlParser $xmlParser) } /** - * Checks if the service has a business account. + * Checks if it has a business account. * - * @return boolean TRUE if the service has a business account else FALSE. + * @return boolean TRUE if it has a business account else FALSE. */ public function hasBusinessAccount() { @@ -215,7 +190,7 @@ public function getBusinessAccount() /** * Sets the business account. * - * @param \Ivory\GoogleMap\Services\BusinessAccount $businessAccount The business account. + * @param \Ivory\GoogleMap\Services\BusinessAccount|null $businessAccount The business account. */ public function setBusinessAccount(BusinessAccount $businessAccount = null) { @@ -223,7 +198,7 @@ public function setBusinessAccount(BusinessAccount $businessAccount = null) } /** - * Sign an url for business account. + * Sign the url. * * @param string $url The url. * @@ -231,10 +206,6 @@ public function setBusinessAccount(BusinessAccount $businessAccount = null) */ protected function signUrl($url) { - if (!$this->hasBusinessAccount()) { - return $url; - } - - return $this->businessAccount->signUrl($url); + return $this->hasBusinessAccount() ? $this->businessAccount->signUrl($url) : $url; } } diff --git a/src/Services/Base/Distance.php b/src/Services/Base/Distance.php index e51bc527..510f00f5 100644 --- a/src/Services/Base/Distance.php +++ b/src/Services/Base/Distance.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Services\Base; -use Ivory\GoogleMap\Exception\ServiceException; - /** - * Distance which describes a google map distance. + * Distance. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Distance + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Distance * @author GeLo */ class Distance @@ -24,14 +22,14 @@ class Distance /** @var string */ protected $text; - /** @var double */ + /** @var float */ protected $value; /** * Creates a distance. * - * @param string $text The distance as text. - * @param double $value The distance in meters. + * @param string $text The text. + * @param float $value The value. */ public function __construct($text, $value) { @@ -40,9 +38,9 @@ public function __construct($text, $value) } /** - * Gets the string representation of the distance value. + * Gets the text. * - * @return string The distance as text. + * @return string The text. */ public function getText() { @@ -50,25 +48,19 @@ public function getText() } /** - * Sets the string representation of the distance value. - * - * @param string $text The distance as text. + * Sets the text. * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the text is not valid. + * @param string $text The text. */ public function setText($text) { - if (!is_string($text)) { - throw ServiceException::invalidDistanceText(); - } - $this->text = $text; } /** - * Gets the distance in meters. + * Gets the value. * - * @return double The distance in meters. + * @return float The value. */ public function getValue() { @@ -76,18 +68,12 @@ public function getValue() } /** - * Sets the distance in meters. + * Sets the value. * - * @param double $value The distance in meters. - * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the distance is not valid. + * @param float $value The value. */ public function setValue($value) { - if (!is_numeric($value)) { - throw ServiceException::invalidDistanceValue(); - } - $this->value = $value; } } diff --git a/src/Services/Base/Duration.php b/src/Services/Base/Duration.php index 55f76ec9..b0400ffa 100644 --- a/src/Services/Base/Duration.php +++ b/src/Services/Base/Duration.php @@ -11,12 +11,10 @@ namespace Ivory\GoogleMap\Services\Base; -use Ivory\GoogleMap\Exception\ServiceException; - /** - * A duration which describes a google map duration. + * Duration. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Duration + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Duration * @author GeLo */ class Duration @@ -24,14 +22,14 @@ class Duration /** @var string */ protected $text; - /** @var double */ + /** @var float */ protected $value; /** * Creates a duration. * - * @param string $text The duration as text. - * @param double $value The duration in minutes. + * @param string $text The text. + * @param float $value The value. */ public function __construct($text, $value) { @@ -40,9 +38,9 @@ public function __construct($text, $value) } /** - * Gets the string representation of the duration value. + * Gets the text. * - * @return string The duration as text. + * @return string The text. */ public function getText() { @@ -50,25 +48,19 @@ public function getText() } /** - * Sets the string representation of the duration value - * - * @param string $text The duration as text. + * Sets the text. * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the text is not valid. + * @param string $text The text. */ public function setText($text) { - if (!is_string($text)) { - throw ServiceException::invalidDurationText(); - } - $this->text = $text; } /** - * Gets the duration in minutes + * Gets the value. * - * @return double The duration in minutes. + * @return float The value. */ public function getValue() { @@ -76,18 +68,12 @@ public function getValue() } /** - * Sets the duration in minutes + * Sets the value. * - * @param double $value The duration in minutes. - * - * @throws \Ivory\GoogleMap\Exception\ServiceException If the value is not valid. + * @param float $value The value. */ public function setValue($value) { - if (!is_numeric($value)) { - throw ServiceException::invalidDurationValue(); - } - $this->value = $value; } } diff --git a/src/Services/Base/TravelMode.php b/src/Services/Base/TravelMode.php index 21ff4209..9951b415 100644 --- a/src/Services/Base/TravelMode.php +++ b/src/Services/Base/TravelMode.php @@ -11,41 +11,18 @@ namespace Ivory\GoogleMap\Services\Base; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * A travel mode which describes the google map travel mode. + * Travel mode. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#TravelMode + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#TravelMode * @author GeLo */ -class TravelMode +class TravelMode extends AbstractUninstantiableAsset { const BICYCLING = 'BICYCLING'; const DRIVING = 'DRIVING'; const WALKING = 'WALKING'; const TRANSIT = 'TRANSIT'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available travel modes. - * - * @return array The available travel modes. - */ - public static function getTravelModes() - { - return array( - self::BICYCLING, - self::DRIVING, - self::WALKING, - self::TRANSIT, - ); - } } diff --git a/src/Services/Base/UnitSystem.php b/src/Services/Base/UnitSystem.php index 51ba9d20..3b2b46f3 100644 --- a/src/Services/Base/UnitSystem.php +++ b/src/Services/Base/UnitSystem.php @@ -11,37 +11,16 @@ namespace Ivory\GoogleMap\Services\Base; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * A unit system which describes the google map unit system. + * Unit system. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#UnitSystem + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#UnitSystem * @author GeLo */ -class UnitSystem +class UnitSystem extends AbstractUninstantiableAsset { const IMPERIAL = 'IMPERIAL'; const METRIC = 'METRIC'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available unit systems. - * - * @return array The available unit systems. - */ - public static function getUnitSystems() - { - return array( - self::IMPERIAL, - self::METRIC, - ); - } } diff --git a/src/Services/BusinessAccount.php b/src/Services/BusinessAccount.php index 11297bcc..2654e86d 100644 --- a/src/Services/BusinessAccount.php +++ b/src/Services/BusinessAccount.php @@ -12,7 +12,7 @@ namespace Ivory\GoogleMap\Services; /** - * Google Map business account. + * Business account. * * @author GeLo */ @@ -82,9 +82,9 @@ public function setSecret($secret) } /** - * Checks if the business account has a channel. + * Checks if it has a channel. * - * @return boolean TRUE if the business account has a channel else FALSE. + * @return boolean TRUE if it has a channel else FALSE. */ public function hasChannel() { @@ -112,7 +112,7 @@ public function setChannel($channel) } /** - * Sign an url for business purpose. + * Sign the url. * * @param string $url The url. * @@ -120,19 +120,17 @@ public function setChannel($channel) */ public function signUrl($url) { - $url .= sprintf('&client=gme-%s', $this->clientId); + $url .= '&client=gme-'.$this->clientId; if ($this->hasChannel()) { - $url .= sprintf('&channel=%s', $this->channel); + $url .= '&channel='.$this->channel; } $urlParts = parse_url($url); - $data = sprintf('%s?%s', $urlParts['path'], $urlParts['query']); + $data = $urlParts['path'].'?'.$urlParts['query']; $key = base64_decode(str_replace(array('-', '_'), array('+', '/'), $this->secret)); $signature = base64_encode(hash_hmac('sha1', $data, $key, true)); - $url .= sprintf('&signature=%s', str_replace(array('+', '/'), array('-', '_'), $signature)); - - return $url; + return $url.'&signature='.str_replace(array('+', '/'), array('-', '_'), $signature); } } diff --git a/src/Services/Directions/Directions.php b/src/Services/Directions/Directions.php index 57250d29..579f59a9 100644 --- a/src/Services/Directions/Directions.php +++ b/src/Services/Directions/Directions.php @@ -13,12 +13,13 @@ use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DirectionsException; use Ivory\GoogleMap\Overlays\EncodedPolyline; use Ivory\GoogleMap\Services\AbstractService; use Ivory\GoogleMap\Services\Base\Distance; use Ivory\GoogleMap\Services\Base\Duration; -use Widop\HttpAdapter\HttpAdapterInterface; +use Ivory\GoogleMap\Services\BusinessAccount; +use Ivory\GoogleMap\Services\Utils\XmlParser; +use Ivory\HttpAdapter\HttpAdapterInterface; /** * Directions service. @@ -28,379 +29,278 @@ class Directions extends AbstractService { /** - * Creates a directions service. - * - * @param \Widop\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. + * {@inheritdoc} */ - public function __construct(HttpAdapterInterface $httpAdapter) - { - parent::__construct($httpAdapter, 'http://maps.googleapis.com/maps/api/directions'); + public function __construct( + HttpAdapterInterface $httpAdapter, + $url = 'http://maps.googleapis.com/maps/api/directions', + $https = false, + $format = self::FORMAT_JSON, + XmlParser $xmlParser = null, + BusinessAccount $businessAccount = null + ) { + parent::__construct($httpAdapter, $url, $https, $format, $xmlParser, $businessAccount); } /** - * Routes the given request. + * Routes a request. * - * Available prototypes: - * - function route(string $origin, string $destination) - * - function route(Ivory\GoogleMap\Services\Directions\DirectionsRequest $request) + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRequest $request The request. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the request is not valid (prototypes). + * @return \Ivory\GoogleMap\Services\Directions\DirectionsResponse The response. */ - public function route() + public function route(DirectionsRequest $request) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof DirectionsRequest)) { - $directionsRequest = $args[0]; - } elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_string($args[1]))) { - $directionsRequest = new DirectionsRequest(); - - $directionsRequest->setOrigin($args[0]); - $directionsRequest->setDestination($args[1]); - } else { - throw DirectionsException::invalidDirectionsRequestParameters(); - } - - if (!$directionsRequest->isValid()) { - throw DirectionsException::invalidDirectionsRequest(); - } - - $url = $this->generateUrl($directionsRequest); - $response = $this->httpAdapter->getContent($url); - - if ($response === null) { - throw DirectionsException::invalidServiceResult(); - } - - $directionsResponse = $this->buildDirectionsResponse($this->parse($response->getBody())); - - return $directionsResponse; + return $this->buildResponse($this->parse( + (string) $this->httpAdapter->get($this->generateUrl($request))->getBody() + )); } /** - * Generates directions URL API according to the request. + * Generates the url. * - * @param \Ivory\GoogleMap\Services\Directions\DirectionsRequest $directionsRequest The direction request. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRequest $request The request. * - * @return string The generated URL. + * @return string The generated url. */ - protected function generateUrl(DirectionsRequest $directionsRequest) + protected function generateUrl(DirectionsRequest $request) { $httpQuery = array(); - if (is_string($directionsRequest->getOrigin())) { - $httpQuery['origin'] = $directionsRequest->getOrigin(); - } else { - $httpQuery['origin'] = sprintf( - '%s,%s', - $directionsRequest->getOrigin()->getLatitude(), - $directionsRequest->getOrigin()->getLongitude() - ); - } + $httpQuery['origin'] = $request->getOrigin() instanceof Coordinate + ? $request->getOrigin()->getLatitude().','.$request->getOrigin()->getLongitude() + : $request->getOrigin(); - if (is_string($directionsRequest->getDestination())) { - $httpQuery['destination'] = $directionsRequest->getDestination(); - } else { - $httpQuery['destination'] = sprintf( - '%s,%s', - $directionsRequest->getDestination()->getLatitude(), - $directionsRequest->getDestination()->getLongitude() - ); - } + $httpQuery['destination'] = $request->getDestination() instanceof Coordinate + ? $request->getDestination()->getLatitude().','.$request->getDestination()->getLongitude() + : $request->getDestination(); - if ($directionsRequest->hasWaypoints()) { + if ($request->hasWaypoints()) { $waypoints = array(); - if ($directionsRequest->hasOptimizeWaypoints() && $directionsRequest->getOptimizeWaypoints()) { + if ($request->hasOptimizeWaypoints() && $request->getOptimizeWaypoints()) { $waypoints[] = 'optimize:true'; } - foreach ($directionsRequest->getWaypoints() as $waypoint) { + foreach ($request->getWaypoints() as $waypoint) { $stopover = $waypoint->getStopover() ? 'via:' : ''; - if (is_string($waypoint->getLocation())) { - $waypoints[] = $stopover.$waypoint->getLocation(); - } else { - $waypoints[] = sprintf( - '%s%s,%s', - $stopover, - $waypoint->getLocation()->getLatitude(), - $waypoint->getLocation()->getLongitude() - ); - } + $waypoints[] = $waypoint->getLocation() instanceof Coordinate + ? $stopover.$waypoint->getLocation()->getLatitude().','.$waypoint->getLocation()->getLongitude() + : $stopover.$waypoint->getLocation(); } $httpQuery['waypoints'] = implode('|', $waypoints); } - if ($directionsRequest->hasTravelMode()) { - $httpQuery['mode'] = strtolower($directionsRequest->getTravelMode()); + if ($request->hasTravelMode()) { + $httpQuery['mode'] = strtolower($request->getTravelMode()); } - if ($directionsRequest->hasProvideRouteAlternatives()) { - $httpQuery['alternatives'] = $directionsRequest->getProvideRouteAlternatives() ? 'true' : 'false'; + if ($request->hasProvideRouteAlternatives()) { + $httpQuery['alternatives'] = $request->getProvideRouteAlternatives() ? 'true' : 'false'; } - if ($directionsRequest->hasAvoidTolls() && $directionsRequest->getAvoidTolls()) { - $httpQuery['avoid'] = 'tolls'; - } elseif ($directionsRequest->hasAvoidHighways() && $directionsRequest->getAvoidHighways()) { - $httpQuery['avoid'] = 'highways'; - } + $httpQuery['avoid'] = $request->hasAvoidTolls() && $request->getAvoidTolls() ? 'tolls' : 'highways'; - if ($directionsRequest->hasUnitSystem()) { - $httpQuery['units'] = strtolower($directionsRequest->getUnitSystem()); + if ($request->hasUnitSystem()) { + $httpQuery['units'] = strtolower($request->getUnitSystem()); } - if ($directionsRequest->hasRegion()) { - $httpQuery['region'] = $directionsRequest->getRegion(); + if ($request->hasRegion()) { + $httpQuery['region'] = $request->getRegion(); } - if ($directionsRequest->hasLanguage()) { - $httpQuery['language'] = $directionsRequest->getLanguage(); + if ($request->hasLanguage()) { + $httpQuery['language'] = $request->getLanguage(); } - if ($directionsRequest->hasDepartureTime()) { - $httpQuery['departure_time'] = $directionsRequest->getDepartureTime()->getTimestamp(); + if ($request->hasDepartureTime()) { + $httpQuery['departure_time'] = $request->getDepartureTime()->getTimestamp(); } - if ($directionsRequest->hasArrivalTime()) { - $httpQuery['arrival_time'] = $directionsRequest->getArrivalTime()->getTimestamp(); + if ($request->hasArrivalTime()) { + $httpQuery['arrival_time'] = $request->getArrivalTime()->getTimestamp(); } - $httpQuery['sensor'] = $directionsRequest->hasSensor() ? 'true' : 'false'; + $httpQuery['sensor'] = $request->hasSensor() ? 'true' : 'false'; - $url = sprintf('%s/%s?%s', $this->getUrl(), $this->getFormat(), http_build_query($httpQuery)); - - return $this->signUrl($url); + return $this->signUrl($this->getUrl().'/'.$this->getFormat().'?'.http_build_query($httpQuery)); } /** - * Parses & normalizes the directions API result response. + * Parses a body. * - * @param string $response The directions API response. + * @param string $body The body. * - * @return \stdClass The parsed & normalized directions response. + * @return array The parsed body. */ - protected function parse($response) + protected function parse($body) { - if ($this->format === 'json') { - return $this->parseJSON($response); - } - - return $this->parseXML($response); + return $this->format === self::FORMAT_JSON ? $this->parseJson($body) : $this->parseXml($body); } /** - * Parses & normalizes a JSON directions API result response. + * Parses a json body. * - * @param string $response The directions API JSON response. + * @param string $body The json body. * - * @return \stdClass The parsed & normalized directions response. + * @return array The parsed json body. */ - protected function parseJSON($response) + protected function parseJson($body) { - return json_decode($response); + return json_decode($body, true); } /** - * Parses & normalizes an XML directions API result response. + * Parses an xml body. * - * @param string $response The directions API XML response. + * @param string $body The xml body. * - * @return \stdClass The parsed & normalized directions response. + * @return array The parsed xml body. */ - protected function parseXML($response) + protected function parseXml($body) { - $rules = array( - 'leg' => 'legs', - 'route' => 'routes', - 'step' => 'steps', + return $this->xmlParser->parse( + $body, + array( + 'leg' => 'legs', + 'route' => 'routes', + 'step' => 'steps', + ) ); - - return $this->xmlParser->parse($response, $rules); } /** - * Builds the directions response according to the normalized directions API results. + * Builds a response. * - * @param \stdClass $directionsResponse The normalied directions response. + * @param array $response The response. * - * @return \Ivory\GoogleMap\Services\Directions\DirectionsResponse The builded directions response. + * @return \Ivory\GoogleMap\Services\Directions\DirectionsResponse The built response. */ - protected function buildDirectionsResponse(\stdClass $directionsResponse) + protected function buildResponse(array $response) { - $routes = $this->buildDirectionsRoutes($directionsResponse->routes); - $status = $directionsResponse->status; - - return new DirectionsResponse($routes, $status); + return new DirectionsResponse($this->buildRoutes($response['routes']), $response['status']); } /** - * Builds the directions routes according to the normalized directions API routes. + * Builds the routes. * - * @param \stdClass $directionsRoutes The normalized directions routes. + * @param array $routes The routes. * - * @return array The builded directions routes. + * @return array The built routes. */ - protected function buildDirectionsRoutes(array $directionsRoutes) + protected function buildRoutes(array $routes) { - $results = array(); - foreach ($directionsRoutes as $directionsRoute) { - $results[] = $this->buildDirectionsRoute($directionsRoute); + $build = array(); + foreach ($routes as $route) { + $build[] = $this->buildRoute($route); } - return $results; + return $build; } /** - * Builds the directions route according to the normalized directions API route. + * Builds a route. * - * @param \stdClass $directionsRoute The normalized directions route. + * @param array $route The route. * - * @return \Ivory\GoogleMap\Services\Directions\DirectionsRoute The builded directions route. + * @return \Ivory\GoogleMap\Services\Directions\DirectionsRoute The built route. */ - protected function buildDirectionsRoute(\stdClass $directionsRoute) + protected function buildRoute(array $route) { - $bound = new Bound( - new Coordinate($directionsRoute->bounds->southwest->lat, $directionsRoute->bounds->southwest->lng), - new Coordinate($directionsRoute->bounds->northeast->lat, $directionsRoute->bounds->northeast->lng) - ); - - // @see https://github.com/egeloen/IvoryGoogleMapBundle/issues/72 - // @codeCoverageIgnoreStart - if (!isset($directionsRoute->copyrights)) { - $directionsRoute->copyrights = ''; - } - - if (!isset($directionsRoute->summary)) { - $directionsRoute->summary = ''; - } - // @codeCoverageIgnoreEnd - - $summary = $directionsRoute->summary; - $copyrights = $directionsRoute->copyrights; - - $directionsLegs = $this->buildDirectionsLegs($directionsRoute->legs); - $overviewPolyline = new EncodedPolyline($directionsRoute->overview_polyline->points); - - // The warnings & waypoint_order properties can not be defined in the xml format. - if (!isset($directionsRoute->warnings)) { - $directionsRoute->warnings = array(); - } - - if (!isset($directionsRoute->waypoint_order)) { - $directionsRoute->waypoint_order = array(); - } - - $warnings = $directionsRoute->warnings; - $waypointOrder = $directionsRoute->waypoint_order; - return new DirectionsRoute( - $bound, - $copyrights, - $directionsLegs, - $overviewPolyline, - $summary, - $warnings, - $waypointOrder + new Bound( + new Coordinate( + $route['bounds']['southwest']['lat'], + $route['bounds']['southwest']['lng'] + ), + new Coordinate( + $route['bounds']['northeast']['lat'], + $route['bounds']['northeast']['lng'] + ) + ), + isset($route['copyrights']) ? $route['copyrights'] : '', + $this->buildLegs($route['legs']), + new EncodedPolyline($route['overview_polyline']['points']), + isset($route['summary']) ? $route['summary'] : '', + isset($route['warnings']) ? $route['warnings'] : array(), + isset($route['waypoint_order']) ? $route['waypoint_order'] : array() ); } /** - * Builds the directions legs according to the normalized directions API legs. + * Builds the legs. * - * @param array $directionsLegs The normalized directions legs. + * @param array $legs The legs. * - * @return array The builded directions legs. + * @return array The built legs. */ - protected function buildDirectionsLegs(array $directionsLegs) + protected function buildLegs(array $legs) { - $results = array(); - foreach ($directionsLegs as $directionsLeg) { - $results[] = $this->buildDirectionsLeg($directionsLeg); + $build = array(); + foreach ($legs as $leg) { + $build[] = $this->buildLeg($leg); } - return $results; + return $build; } /** - * Buildd the directions leg according to the normalized directions API leg. + * Buildd a leg. * - * @param \stdClass $directionsLeg The normalized directions leg. + * @param array $leg The leg. * - * @return \Ivory\GoogleMap\Services\Directions\DirectionsLeg The builded directions leg. + * @return \Ivory\GoogleMap\Services\Directions\DirectionsLeg The leg. */ - protected function buildDirectionsLeg(\stdClass $directionsLeg) + protected function buildLeg(array $leg) { - $distance = new Distance($directionsLeg->distance->text, $directionsLeg->distance->value); - $duration = new Duration($directionsLeg->duration->text, $directionsLeg->duration->value); - $endAddress = $directionsLeg->end_address; - $endLocation = new Coordinate($directionsLeg->end_location->lat, $directionsLeg->end_location->lng); - $startAddress = $directionsLeg->start_address; - $startLocation = new Coordinate($directionsLeg->start_location->lat, $directionsLeg->start_location->lng); - $steps = $this->buildDirectionsSteps($directionsLeg->steps); - - // The via_waypoint property can not be defined in the xml format. - if (!isset($directionsLeg->via_waypoint)) { - $directionsLeg->via_waypoint = array(); - } - - $viaWaypoint = $directionsLeg->via_waypoint; - return new DirectionsLeg( - $distance, - $duration, - $endAddress, - $endLocation, - $startAddress, - $startLocation, - $steps, - $viaWaypoint + new Distance($leg['distance']['text'], $leg['distance']['value']), + new Duration($leg['duration']['text'], $leg['duration']['value']), + $leg['end_address'], + new Coordinate($leg['end_location']['lat'], $leg['end_location']['lng']), + $leg['start_address'], + new Coordinate($leg['start_location']['lat'], $leg['start_location']['lng']), + $this->buildSteps($leg['steps']), + isset($leg['via_waypoint']) ? $leg['via_waypoint'] : array() ); } /** - * Builds the directions steps according to the normalized directions API steps. + * Builds the steps. * - * @param array $directionsSteps The normalized directions steps. + * @param array $steps The steps. * - * @return array The builded directions steps. + * @return array The built steps. */ - protected function buildDirectionsSteps(array $directionsSteps) + protected function buildSteps(array $steps) { - $results = array(); - foreach ($directionsSteps as $directionsStep) { - $results[] = $this->buildDirectionsStep($directionsStep); + $build = array(); + foreach ($steps as $step) { + $build[] = $this->buildStep($step); } - return $results; + return $build; } /** - * Builds the directions step according to the normalized directions API step. + * Builds a step. * - * @param \stdClass $directionsStep The normalized directions step. + * @param array $step The step. * - * @return \Ivory\GoogleMap\Services\Directions\DirectionsStep The builded directions step. + * @return \Ivory\GoogleMap\Services\Directions\DirectionsStep The built step. */ - protected function buildDirectionsStep(\stdClass $directionsStep) + protected function buildStep(array $step) { - $distance = new Distance($directionsStep->distance->text, $directionsStep->distance->value); - $duration = new Duration($directionsStep->duration->text, $directionsStep->duration->value); - $endLocation = new Coordinate($directionsStep->end_location->lat, $directionsStep->end_location->lng); - $instructions = $directionsStep->html_instructions; - $encodedPolyline = new EncodedPolyline($directionsStep->polyline->points); - $startLocation = new Coordinate($directionsStep->start_location->lat, $directionsStep->start_location->lng); - $travelMode = $directionsStep->travel_mode; - return new DirectionsStep( - $distance, - $duration, - $endLocation, - $instructions, - $encodedPolyline, - $startLocation, - $travelMode + new Distance($step['distance']['text'], $step['distance']['value']), + new Duration($step['duration']['text'], $step['duration']['value']), + new Coordinate($step['end_location']['lat'], $step['end_location']['lng']), + $step['html_instructions'], + new EncodedPolyline($step['polyline']['points']), + new Coordinate($step['start_location']['lat'], $step['start_location']['lng']), + $step['travel_mode'] ); } } diff --git a/src/Services/Directions/DirectionsLeg.php b/src/Services/Directions/DirectionsLeg.php index 5f76777d..8de3b19d 100644 --- a/src/Services/Directions/DirectionsLeg.php +++ b/src/Services/Directions/DirectionsLeg.php @@ -12,14 +12,13 @@ namespace Ivory\GoogleMap\Services\Directions; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DirectionsException; use Ivory\GoogleMap\Services\Base\Distance; use Ivory\GoogleMap\Services\Base\Duration; /** - * A directions leg which describes a google map directions leg. + * Directions leg. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsLeg + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsLeg * @author GeLo */ class DirectionsLeg @@ -81,9 +80,9 @@ public function __construct( } /** - * Gets the leg distance. + * Gets the distance. * - * @return \Ivory\GoogleMap\Services\Base\Distance The leg distance. + * @return \Ivory\GoogleMap\Services\Base\Distance The distance. */ public function getDistance() { @@ -91,9 +90,9 @@ public function getDistance() } /** - * Sets the leg distance. + * Sets the distance. * - * @param \Ivory\GoogleMap\Services\Base\Distance $distance The leg distance. + * @param \Ivory\GoogleMap\Services\Base\Distance $distance The distance. */ public function setDistance(Distance $distance) { @@ -101,9 +100,9 @@ public function setDistance(Distance $distance) } /** - * Gets the leg duration. + * Gets the duration. * - * @return \Ivory\GoogleMap\Services\Base\Duration The leg duration. + * @return \Ivory\GoogleMap\Services\Base\Duration The duration. */ public function getDuration() { @@ -111,9 +110,9 @@ public function getDuration() } /** - * Sets the leg duration + * Sets the duration. * - * @param \Ivory\GoogleMap\Services\Base\Duration $duration The leg duration. + * @param \Ivory\GoogleMap\Services\Base\Duration $duration The duration. */ public function setDuration(Duration $duration) { @@ -121,9 +120,9 @@ public function setDuration(Duration $duration) } /** - * Gets the leg end address. + * Gets the end address. * - * @return string The leg end address. + * @return string The end address. */ public function getEndAddress() { @@ -131,25 +130,19 @@ public function getEndAddress() } /** - * Sets the leg end address. + * Sets the end address. * - * @param string The leg end address. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the and address is not valid. + * @param string The end address. */ public function setEndAddress($endAddress) { - if (!is_string($endAddress)) { - throw DirectionsException::invalidDirectionsLegEndAddress(); - } - $this->endAddress = $endAddress; } /** - * Gets the leg end location. + * Gets the end location. * - * @return \Ivory\GoogleMap\Base\Coordinate The leg end location. + * @return \Ivory\GoogleMap\Base\Coordinate The end location. */ public function getEndLocation() { @@ -157,9 +150,9 @@ public function getEndLocation() } /** - * Sets the leg end location. + * Sets the end location. * - * @param \Ivory\GoogleMap\Base\Coordinate $endLocation The leg end location. + * @param \Ivory\GoogleMap\Base\Coordinate $endLocation The end location. */ public function setEndLocation(Coordinate $endLocation) { @@ -167,9 +160,9 @@ public function setEndLocation(Coordinate $endLocation) } /** - * Gets the leg start address. + * Gets the start address. * - * @return string The leg start address. + * @return string The start address. */ public function getStartAddress() { @@ -177,25 +170,19 @@ public function getStartAddress() } /** - * Sets the leg start address. + * Sets the start address. * - * @param string $startAddress The leg start address. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the start address is not valid. + * @param string $startAddress The start address. */ public function setStartAddress($startAddress) { - if (!is_string($startAddress)) { - throw DirectionsException::invalidDirectionsLegStartAddress(); - } - $this->startAddress = $startAddress; } /** - * Gets the leg start location. + * Gets the start location. * - * @return \Ivory\GoogleMap\Base\Coordinate The leg start location. + * @return \Ivory\GoogleMap\Base\Coordinate The start location. */ public function getStartLocation() { @@ -203,9 +190,9 @@ public function getStartLocation() } /** - * Sets the leg start location. + * Sets the start location. * - * @param \Ivory\GoogleMap\Base\Coordinate $startLocation The leg start location. + * @param \Ivory\GoogleMap\Base\Coordinate $startLocation The start location. */ public function setStartLocation(Coordinate $startLocation) { @@ -213,9 +200,27 @@ public function setStartLocation(Coordinate $startLocation) } /** - * Gets the leg steps. + * Resets the steps. + */ + public function resetSteps() + { + $this->steps = array(); + } + + /** + * Checks if there are steps. * - * @return array The leg steps. + * @return boolean TRUE if there are steps else FALSE. + */ + public function hasSteps() + { + return !empty($this->steps); + } + + /** + * Gets the steps. + * + * @return array The steps. */ public function getSteps() { @@ -223,33 +228,96 @@ public function getSteps() } /** - * Sets the leg steps. + * Sets the steps. * - * @param array $steps The leg steps. + * @param array $steps The steps. */ public function setSteps(array $steps) { - $this->steps = array(); + $this->resetSteps(); + $this->addSteps($steps); + } + /** + * Adds the steps. + * + * @param array $steps The steps. + */ + public function addSteps(array $steps) + { foreach ($steps as $step) { $this->addStep($step); } } /** - * Add a step to the leg. + * Removes the staps. + * + * @param array $steps The steps. + */ + public function removeSteps(array $steps) + { + foreach ($steps as $step) { + $this->removeStep($step); + } + } + + /** + * Checks if there is a step. * - * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep The step to add. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep $step The step. + * + * @return boolean TRUE if there is the step else FALSE. + */ + public function hasStep(DirectionsStep $step) + { + return in_array($step, $this->steps, true); + } + + /** + * Adds a step. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep The step. */ public function addStep(DirectionsStep $step) { - $this->steps[] = $step; + if (!$this->hasStep($step)) { + $this->steps[] = $step; + } } /** - * Gets the via waypoint. + * Removes a step. * - * @return array The via waypoint. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep $step The step. + */ + public function removeStep(DirectionsStep $step) + { + unset($this->steps[array_search($step, $this->steps, true)]); + } + + /** + * Resets the via waypoints. + */ + public function resetViaWaypoints() + { + $this->viaWaypoints = array(); + } + + /** + * Checks if there are via waypoints. + * + * @return boolean TRUE if there are via waypoints else FALSE. + */ + public function hasViaWaypoints() + { + return !empty($this->viaWaypoints); + } + + /** + * Gets the via waypoints. + * + * @return array The via waypoints. */ public function getViaWaypoints() { @@ -257,12 +325,70 @@ public function getViaWaypoints() } /** - * Sets the via waypoint. + * Sets the via waypoints. * - * @param array $viaWaypoints The via waypoint. + * @param array $viaWaypoints The via waypoints. */ public function setViaWaypoints(array $viaWaypoints) { $this->viaWaypoints = $viaWaypoints; } + + /** + * Adds the via waypoints. + * + * @param array $viaWaypoints The via waypoints. + */ + public function addViaWaypoints(array $viaWaypoints) + { + foreach ($viaWaypoints as $viaWaypoint) { + $this->addViaWaypoint($viaWaypoint); + } + } + + /** + * Removes the via waypoints. + * + * @param array $viaWaypoints The via waypoints. + */ + public function removeViaWaypoints(array $viaWaypoints) + { + foreach ($viaWaypoints as $viaWaypoint) { + $this->removeViaWaypoint($viaWaypoint); + } + } + + /** + * Checks if there is a via waypoint. + * + * @param \Ivory\GoogleMap\Base\Coordinate $viaWaypoint The via waypoint. + * + * @return boolean TRUE if there is the via waypoint else FALSE. + */ + public function hasViaWaypoint(Coordinate $viaWaypoint) + { + return in_array($viaWaypoint, $this->viaWaypoints, true); + } + + /** + * Adds a via waypoint. + * + * @param \Ivory\GoogleMap\Base\Coordinate $viaWaypoint The via waypoint. + */ + public function addViaWaypoint(Coordinate $viaWaypoint) + { + if (!$this->hasViaWaypoint($viaWaypoint)) { + $this->viaWaypoints[] = $viaWaypoint; + } + } + + /** + * Removes a via waypoint. + * + * @param \Ivory\GoogleMap\Base\Coordinate $viaWaypoint The via waypoint. + */ + public function removeViaWaypoint(Coordinate $viaWaypoint) + { + unset($this->viaWaypoints[array_search($viaWaypoint, $this->viaWaypoints, true)]); + } } diff --git a/src/Services/Directions/DirectionsRequest.php b/src/Services/Directions/DirectionsRequest.php index 495dbee6..ae11601d 100644 --- a/src/Services/Directions/DirectionsRequest.php +++ b/src/Services/Directions/DirectionsRequest.php @@ -11,16 +11,10 @@ namespace Ivory\GoogleMap\Services\Directions; -use \DateTime; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DirectionsException; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - /** - * Directions request represents a google map directions request. + * Directions request. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRequest + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRequest * @author GeLo */ class DirectionsRequest @@ -31,19 +25,19 @@ class DirectionsRequest /** @var boolean */ protected $avoidTolls; - /** @var string | \Ivory\GoogleMap\Base\Coordinate */ + /** @var string|\Ivory\GoogleMap\Base\Coordinate */ protected $destination; /** @var boolean */ protected $optimizeWaypoints; - /** @var string | \Ivory\GoogleMap\Base\Coordinate */ + /** @var string|\Ivory\GoogleMap\Base\Coordinate */ protected $origin; /** @var \DateTime */ protected $departureTime; - /** @var \DateTime */ + /** @var \DateTime */ protected $arrivalTime; /** @var boolean */ @@ -62,24 +56,27 @@ class DirectionsRequest protected $unitSystem; /** @var array */ - protected $waypoints; + protected $waypoints = array(); /** @var boolean */ - protected $sensor; + protected $sensor = false; /** * Creates a directions request. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. */ - public function __construct() + public function __construct($origin, $destination) { - $this->waypoints = array(); - $this->sensor = false; + $this->setOrigin($origin); + $this->setDestination($destination); } /** - * Checks if the directions request has an avoid hightways flag. + * Checks if it has an avoid hightways. * - * @return boolean TRUE if the directions request has an avoid hightways flag else FALSE. + * @return boolean TRUE if it has an avoid hightways else FALSE. */ public function hasAvoidHighways() { @@ -87,9 +84,9 @@ public function hasAvoidHighways() } /** - * Checks if the directions request avoid hightways. + * Checks if it avoids hightways. * - * @return boolean TRUE if the directions request avoids hightways else FALSE. + * @return boolean TRUE if it avoids hightways else FALSE. */ public function getAvoidHighways() { @@ -97,25 +94,19 @@ public function getAvoidHighways() } /** - * Sets if the the directions request avoids hightways. - * - * @param boolean $avoidHighways TRUE if the directions request avoids hightways else FALSE. + * Sets if it avoids hightways. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the avoid highways flag is not valid. + * @param boolean $avoidHighways TRUE if it avoids hightways else FALSE. */ public function setAvoidHighways($avoidHighways = null) { - if (!is_bool($avoidHighways) && ($avoidHighways !== null)) { - throw DirectionsException::invalidDirectionsRequestAvoidHighways(); - } - $this->avoidHighways = $avoidHighways; } /** - * Checks if the directions request has an avoid tolls flag. + * Checks if it has an avoid tolls. * - * @return boolean TRUE if the directions request has an avoid tolls flag else FALSE. + * @return boolean TRUE if it has an avoid tolls else FALSE. */ public function hasAvoidTolls() { @@ -123,9 +114,9 @@ public function hasAvoidTolls() } /** - * Checks if the directions request avoid tolls. + * Checks if it avoid tolls. * - * @return boolean TRUE if the directions request avoids tolls else FALSE. + * @return boolean TRUE if it avoids tolls else FALSE. */ public function getAvoidTolls() { @@ -133,35 +124,29 @@ public function getAvoidTolls() } /** - * Sets if the the directions request avoids tolls. - * - * @param boolean $avoidTolls TRUE if the directions request avoids tolls else FALSE. + * Sets if it avoids tolls. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the avoid tolls flag is not valid. + * @param boolean $avoidTolls TRUE if it avoids tolls else FALSE. */ public function setAvoidTolls($avoidTolls = null) { - if (!is_bool($avoidTolls) && ($avoidTolls !== null)) { - throw DirectionsException::invalidDirectionsRequestAvoidTolls(); - } - $this->avoidTolls = $avoidTolls; } /** - * Checks if the directions request has a destination. + * Checks if it has a destination. * - * @return boolean TRUE if the directions request has a destination else FALSE. + * @return boolean TRUE if it has a destination else FALSE. */ public function hasDestination() { - return $this->destination !== null; + return !empty($this->destination); } /** - * Gets the directions request destination. + * Gets the destination. * - * @return string | \Ivory\GoogleMap\Base\Coordinate The directions request destination. + * @return string|\Ivory\GoogleMap\Base\Coordinate The destination. */ public function getDestination() { @@ -169,43 +154,19 @@ public function getDestination() } /** - * Sets the directions request destination. - * - * Available prototypes: - * - function setDestination(string $destination) - * - function setDestination(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setDestination(double $latitude, double $longitude, boolean $noWrap) + * Sets the destination. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the destination is not valid (prototypes). + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. */ - public function setDestination() + public function setDestination($destination) { - $args = func_get_args(); - - if (isset($args[0]) && is_string($args[0])) { - $this->destination = $args[0]; - } elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->destination = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->destination === null) { - $this->destination = new Coordinate(); - } - - $this->destination->setLatitude($args[0]); - $this->destination->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->destination->setNoWrap($args[2]); - } - } else { - throw DirectionsException::invalidDirectionsRequestDestination(); - } + $this->destination = $destination; } /** - * Checks if the directions request has the optimize waypoints flag. + * Checks if it has the optimize waypoints. * - * @return boolean TRUE if the directions request has the optimize waypoints flag else FALSE. + * @return boolean TRUE if it has the optimize waypoints else FALSE. */ public function hasOptimizeWaypoints() { @@ -213,9 +174,9 @@ public function hasOptimizeWaypoints() } /** - * Checks if the directions request optimizes waypoints. + * Checks if it optimizes waypoints. * - * @return boolean TRUE if the directions request optmizes waypoints else FALSE. + * @return boolean TRUE if it optmizes waypoints else FALSE. */ public function getOptimizeWaypoints() { @@ -223,35 +184,29 @@ public function getOptimizeWaypoints() } /** - * Sets if the directions request optimizes waypoints. - * - * @param boolean $optimizeWaypoints TRUE if the directions request optimizes waypoints else FALSE. + * Sets if it optimizes waypoints. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the optimize waypoints flag is not valid. + * @param boolean $optimizeWaypoints TRUE if it optimizes waypoints else FALSE. */ public function setOptimizeWaypoints($optimizeWaypoints = null) { - if (!is_bool($optimizeWaypoints) && ($optimizeWaypoints !== null)) { - throw DirectionsException::invalidDirectionsRequestOptimizeWaypoints(); - } - $this->optimizeWaypoints = $optimizeWaypoints; } /** - * Checks if the directions request has an origin. + * Checks if it has an origin. * - * @return boolean TRUE if the directions request has an origin else FALSE. + * @return boolean TRUE if the it has an origin else FALSE. */ public function hasOrigin() { - return $this->origin !== null; + return !empty($this->origin); } /** - * Gets the directions request origin. + * Gets the origin. * - * @return string | \Ivory\GoogleMap\Base\Coordinate The directions request origin. + * @return string|\Ivory\GoogleMap\Base\Coordinate The origin. */ public function getOrigin() { @@ -259,43 +214,19 @@ public function getOrigin() } /** - * Sets the directions request origin. - * - * Available prototypes: - * - function setOrigin(string $destination) - * - function setOrigin(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setOrigin(double $latitude, double $longitude, boolean $noWrap) + * Sets the origin. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the origin is not valid (prototypes). + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. */ - public function setOrigin() + public function setOrigin($origin) { - $args = func_get_args(); - - if (isset($args[0]) && is_string($args[0])) { - $this->origin = $args[0]; - } elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->origin = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->origin === null) { - $this->origin = new Coordinate(); - } - - $this->origin->setLatitude($args[0]); - $this->origin->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->origin->setNoWrap($args[2]); - } - } else { - throw DirectionsException::invalidDirectionsRequestOrigin(); - } + $this->origin = $origin; } /** - * Checks if the directions request has a departure time. + * Checks if it has a departure time. * - * @return boolean TRUE if the directions request has a departure time else FALSE. + * @return boolean TRUE if it has a departure time else FALSE. */ public function hasDepartureTime() { @@ -303,9 +234,9 @@ public function hasDepartureTime() } /** - * Gets the directions request departure time. + * Gets the departure time. * - * @return \DateTime The directions request departure time. + * @return \DateTime The departure time. */ public function getDepartureTime() { @@ -313,19 +244,19 @@ public function getDepartureTime() } /** - * Sets the directions departure time + * Sets the departure time * - * @param \DateTime $departureTime The directions departure time. + * @param \DateTime $departureTime The departure time. */ - public function setDepartureTime(DateTime $departureTime = null) + public function setDepartureTime(\DateTime $departureTime = null) { $this->departureTime = $departureTime; } /** - * Checks if the directions request has an arrival time. + * Checks if it has an arrival time. * - * @return boolean TRUE if the directions request has an arrival time else FALSE. + * @return boolean TRUE if it has an arrival time else FALSE. */ public function hasArrivalTime() { @@ -333,9 +264,9 @@ public function hasArrivalTime() } /** - * Gets the directions request arrival time. + * Gets the arrival time. * - * @return \DateTime The directions request arrival time. + * @return \DateTime The arrival time. */ public function getArrivalTime() { @@ -343,19 +274,19 @@ public function getArrivalTime() } /** - * Sets the directions arrival time + * Sets the arrival time * - * @param \DateTime $arrivalTime The directions arrival time. + * @param \DateTime $arrivalTime The arrival time. */ - public function setArrivalTime(DateTime $arrivalTime = null) + public function setArrivalTime(\DateTime $arrivalTime = null) { $this->arrivalTime = $arrivalTime; } /** - * Checks if the directions request has a provide route alternatives flag. + * Checks if it has a provide route alternatives. * - * @return boolean TRUE if the directions request has a provide route alternative flag else FALSE. + * @return boolean TRUE if the it has a provide route alternative else FALSE. */ public function hasProvideRouteAlternatives() { @@ -363,9 +294,9 @@ public function hasProvideRouteAlternatives() } /** - * Checks if the directions request provides route alternatives. + * Checks if it provides route alternatives. * - * @return boolean TRUE if the directions request provides route alternatives else FALSE. + * @return boolean TRUE if it provides route alternatives else FALSE. */ public function getProvideRouteAlternatives() { @@ -373,25 +304,19 @@ public function getProvideRouteAlternatives() } /** - * Sets if the directions request provides route alternatives. - * - * @param boolean $provideRouteAlternatives TRUE if the directions request provides route alternatives else FALSE. + * Sets if it provides route alternatives. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the provide route alternatives flag is not valid. + * @param boolean $provideRouteAlternatives TRUE if it provides route alternatives else FALSE. */ public function setProvideRouteAlternatives($provideRouteAlternatives = null) { - if (!is_bool($provideRouteAlternatives) && ($provideRouteAlternatives !== null)) { - throw DirectionsException::invalidDirectionsRequestProvideRouteAlternatives(); - } - $this->provideRouteAlternatives = $provideRouteAlternatives; } /** - * Checks if the directions request has a region. + * Checks if it has a region. * - * @return boolean TRUE if the directions request has a region else FALSE. + * @return boolean TRUE if it has a region else FALSE. */ public function hasRegion() { @@ -399,9 +324,9 @@ public function hasRegion() } /** - * Gets the directions request region. + * Gets the region. * - * @return string The direction request region. + * @return string The region. */ public function getRegion() { @@ -409,25 +334,19 @@ public function getRegion() } /** - * Sets the directions request region. - * - * @param string $region The directions request region. + * Sets the region. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the region is not valid. + * @param string $region The region. */ public function setRegion($region = null) { - if ((!is_string($region) || (strlen($region) !== 2)) && ($region !== null)) { - throw DirectionsException::invalidDirectionsRequestRegion(); - } - $this->region = $region; } /** - * Checks if the directions request has a language. + * Checks if it has a language. * - * @return boolean TRUE if the directions request has a language else FALSE. + * @return boolean TRUE if it has a language else FALSE. */ public function hasLanguage() { @@ -435,9 +354,9 @@ public function hasLanguage() } /** - * Gets the directions request language. + * Gets the language. * - * @return string The direction request language. + * @return string The language. */ public function getLanguage() { @@ -445,25 +364,19 @@ public function getLanguage() } /** - * Sets the directions request language. - * - * @param string $language The directions request language. + * Sets the language. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the language is not valid. + * @param string $language The language. */ public function setLanguage($language = null) { - if ((!is_string($language) || ((strlen($language) !== 2) && (strlen($language) !== 5))) && ($language !== null)) { - throw DirectionsException::invalidDirectionsRequestLanguage(); - } - $this->language = $language; } /** - * Checks if the directions request has a travel mode. + * Checks if it has a travel mode. * - * @return boolean TRUE if the directions request has a travel mode else FALSE. + * @return boolean TRUE if it has a travel mode else FALSE. */ public function hasTravelMode() { @@ -471,9 +384,9 @@ public function hasTravelMode() } /** - * Gets the directions request travel mode. + * Gets the travel mode. * - * @return string The directions request travel mode. + * @return string The travel mode. */ public function getTravelMode() { @@ -481,25 +394,19 @@ public function getTravelMode() } /** - * Sets the directions request travel mode. + * Sets the travel mode. * - * @param string $travelMode The directions request travel mode. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the travel mode is not valid. + * @param string $travelMode The travel mode. */ public function setTravelMode($travelMode = null) { - if (!in_array($travelMode, TravelMode::getTravelModes()) && ($travelMode !== null)) { - throw DirectionsException::invalidDirectionsRequestTravelMode(); - } - $this->travelMode = $travelMode; } /** - * Checks if the directions request has a unit system. + * Checks if it has a unit system. * - * @return boolean TRUE if the directions request has a unit system else FALSE. + * @return boolean TRUE if it has a unit system else FALSE. */ public function hasUnitSystem() { @@ -507,9 +414,9 @@ public function hasUnitSystem() } /** - * Gets the directions request unit system. + * Gets the unit system. * - * @return string The directions request unit system. + * @return string The unit system. */ public function getUnitSystem() { @@ -517,25 +424,27 @@ public function getUnitSystem() } /** - * Sets the directions request unit system. + * Sets the unit system. * - * @param string $unitSystem The directions request unit system. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the unit system is not valid. + * @param string $unitSystem The unit system. */ public function setUnitSystem($unitSystem = null) { - if (!in_array($unitSystem, UnitSystem::getUnitSystems()) && ($unitSystem !== null)) { - throw DirectionsException::invalidDirectionsRequestUnitSystem(); - } - $this->unitSystem = $unitSystem; } /** - * Checks if the directions request has waypoints. + * Resets the waypoints. + */ + public function resetWaypoints() + { + $this->waypoints = array(); + } + + /** + * Checks if it have waypoints. * - * @return boolean TRUE if the directions request has waypoints else FALSE. + * @return boolean TRUE if it have waypoints else FALSE. */ public function hasWaypoints() { @@ -543,9 +452,9 @@ public function hasWaypoints() } /** - * Gets the directions request waypoints. + * Gets the waypoints. * - * @return array The directions request waypoints. + * @return array The waypoints. */ public function getWaypoints() { @@ -553,98 +462,91 @@ public function getWaypoints() } /** - * Sets the directions request waypoints. + * Sets the waypoints. * - * @param array $waypoints The directions request waypoints. + * @param array $waypoints The waypoints. */ - public function setWaypoints(array $waypoints = array()) + public function setWaypoints(array $waypoints) { - $this->waypoints = array(); + $this->resetWaypoints(); + $this->addWaypoints($waypoints); + } + /** + * Adds the waypoints. + * + * @param array $waypoints The waypoints. + */ + public function addWaypoints(array $waypoints) + { foreach ($waypoints as $waypoint) { $this->addWaypoint($waypoint); } } /** - * Adds a waypoint to the directions request. - * - * Available prototypes: - * - function addWaypoint(Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint) - * - function addWaypoint(string $location) - * - function addWaypoint(double $latitude, double $longitude, boolean $noWrap) - * - function addWaypoint(Ivory\GoogleMap\Base\Coordinate $location) + * Removes the waypoints. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the waypoint is not valid (prototypes). + * @param array $waypoints The waypoints. */ - public function addWaypoint() + public function removeWaypoints(array $waypoints) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof DirectionsWaypoint)) { - $this->waypoints[] = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $waypoint = new DirectionsWaypoint(); - $waypoint->setLocation($args[0], $args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $waypoint->getLocation()->setNoWrap($args[2]); - } - - $this->waypoints[] = $waypoint; - } elseif (isset($args[0]) && (is_string($args[0]) || ($args[0] instanceof Coordinate))) { - $waypoint = new DirectionsWaypoint(); - $waypoint->setLocation($args[0]); - - $this->waypoints[] = $waypoint; - } else { - throw DirectionsException::invalidDirectionsRequestWaypoint(); + foreach ($waypoints as $waypoint) { + $this->removeWaypoint($waypoint); } } /** - * Checks if the directions request has a sensor. + * Checks if there is a waypoint. * - * @return boolean TRUE if the directions request has a sensor else FALSE. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The waypoint. + * + * @return boolean TRUE if there is the waypoint else FALSE. */ - public function hasSensor() + public function hasWaypoint(DirectionsWaypoint $waypoint) { - return $this->sensor; + return in_array($waypoint, $this->waypoints, true); } /** - * Sets the directions request sensor. + * Adds a waypoint. * - * @param boolean $sensor TRUE if the directions request has a sensor else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the sensor flag is not valid. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The waypoint. */ - public function setSensor($sensor) + public function addWaypoint(DirectionsWaypoint $waypoint) { - if (!is_bool($sensor)) { - throw DirectionsException::invalidDirectionsRequestSensor(); + if (!$this->hasWaypoint($waypoint)) { + $this->waypoints[] = $waypoint; } - - $this->sensor = $sensor; } /** - * Checks if the directions request is valid. + * Removes a waypoint. * - * @return boolean TRUE if the directions request is valid else FALSE. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The waypoint. */ - public function isValid() + public function removeWaypoint(DirectionsWaypoint $waypoint) { - $isValid = $this->hasDestination() && $this->hasOrigin(); - - for ($i = 0; $isValid && ($i < count($this->waypoints)); $i++) { - $isValid = $this->waypoints[$i]->isValid(); - } + unset($this->waypoints[array_search($waypoint, $this->waypoints, true)]); + } - if ($this->getTravelMode() === TravelMode::TRANSIT) { - $isValid = $this->hasArrivalTime() || $this->hasDepartureTime(); - } + /** + * Checks if it has a sensor. + * + * @return boolean TRUE if it has a sensor else FALSE. + */ + public function hasSensor() + { + return $this->sensor; + } - return $isValid; + /** + * Sets the sensor. + * + * @param boolean $sensor TRUE if it has a sensor else FALSE. + */ + public function setSensor($sensor) + { + $this->sensor = $sensor; } } diff --git a/src/Services/Directions/DirectionsResponse.php b/src/Services/Directions/DirectionsResponse.php index 24f9677b..1fce0153 100644 --- a/src/Services/Directions/DirectionsResponse.php +++ b/src/Services/Directions/DirectionsResponse.php @@ -11,10 +11,8 @@ namespace Ivory\GoogleMap\Services\Directions; -use Ivory\GoogleMap\Exception\DirectionsException; - /** - * A directions response wraps the directions results (routes) & the response status. + * Directions response. * * @author GeLo */ @@ -29,8 +27,8 @@ class DirectionsResponse /** * Create a directions response. * - * @param array $routes The response routes. - * @param string $status The response status. + * @param array $routes The routes. + * @param string $status The status. */ public function __construct(array $routes, $status) { @@ -39,9 +37,27 @@ public function __construct(array $routes, $status) } /** - * Gets the directions routes. + * Resets the routes. + */ + public function resetRoutes() + { + $this->routes = array(); + } + + /** + * Checks if there are routes. + * + * @return boolean TRUE if there are routes else FALSE. + */ + public function hasRoutes() + { + return !empty($this->routes); + } + + /** + * Gets the routes. * - * @return array The directions routes. + * @return array The routes. */ public function getRoutes() { @@ -49,33 +65,78 @@ public function getRoutes() } /** - * Sets the directions routes. + * Sets the routes. * - * @param array $routes The directions routes. + * @param array $routes The routes. */ public function setRoutes(array $routes) { - $this->routes = array(); + $this->resetRoutes(); + $this->addRoutes($routes); + } + /** + * Adds the routes. + * + * @param array $routes The routes. + */ + public function addRoutes(array $routes) + { foreach ($routes as $route) { $this->addRoute($route); } } /** - * Add a directions route. + * Removes the routes. + * + * @param array $routes The routes. + */ + public function removeRoutes(array $routes) + { + foreach ($routes as $route) { + $this->removeRoute($route); + } + } + + /** + * Checks if there is a route. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRoute $route The route. + * + * @return boolean TRUE if there is a route else FALSE. + */ + public function hasRoute(DirectionsRoute $route) + { + return in_array($route, $this->routes, true); + } + + /** + * Adds a route. * - * @param Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRoute $route The route to add. + * @param Ivory\GoogleMapBundle\Model\Services\Directions\DirectionsRoute $route The route. */ public function addRoute(DirectionsRoute $route) { - $this->routes[] = $route; + if (!$this->hasRoute($route)) { + $this->routes[] = $route; + } } /** - * Gets the directions response status. + * Removes a route. * - * @return string The directions response status. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRoute $route The route. + */ + public function removeRoute(DirectionsRoute $route) + { + unset($this->routes[array_search($route, $this->routes, true)]); + } + + /** + * Gets the status. + * + * @return string The status. */ public function getStatus() { @@ -83,18 +144,12 @@ public function getStatus() } /** - * Sets the directions response status. - * - * @param string $status The directions response status. + * Sets the status. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the status is not valid. + * @param string $status The status. */ public function setStatus($status) { - if (!in_array($status, DirectionsStatus::getDirectionsStatus())) { - throw DirectionsException::invalidDirectionsResponseStatus(); - } - $this->status = $status; } } diff --git a/src/Services/Directions/DirectionsRoute.php b/src/Services/Directions/DirectionsRoute.php index c66d9d87..c0256279 100644 --- a/src/Services/Directions/DirectionsRoute.php +++ b/src/Services/Directions/DirectionsRoute.php @@ -12,13 +12,12 @@ namespace Ivory\GoogleMap\Services\Directions; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Exception\DirectionsException; use Ivory\GoogleMap\Overlays\EncodedPolyline; /** - * A directions route which describes a google map route. + * Directions route. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRoute + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRoute * @author GeLo */ class DirectionsRoute @@ -42,7 +41,7 @@ class DirectionsRoute protected $warnings; /** @var array */ - protected $waypointOrder; + protected $waypointOrders; /** * Creates a directions route. @@ -53,7 +52,7 @@ class DirectionsRoute * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $overviewPolyline The encoded polyline. * @param string $summary The summary. * @param array $warnings The warnings. - * @param array $waypointOrder The waypoint order. + * @param array $waypointOrders The waypoint orders. */ public function __construct( Bound $bound, @@ -62,7 +61,7 @@ public function __construct( EncodedPolyline $overviewPolyline, $summary, array $warnings, - array $waypointOrder + array $waypointOrders ) { $this->setBound($bound); $this->setCopyrights($copyrights); @@ -70,13 +69,13 @@ public function __construct( $this->setOverviewPolyline($overviewPolyline); $this->setSummary($summary); $this->setWarnings($warnings); - $this->setWaypointOrder($waypointOrder); + $this->setWaypointOrders($waypointOrders); } /** - * Gets the route bound. + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The route bound. + * @return \Ivory\GoogleMap\Base\Bound The bound. */ public function getBound() { @@ -84,9 +83,9 @@ public function getBound() } /** - * Sets the route bound. + * Sets the bound. * - * @param \Ivory\GoogleMap\Base\Bound $bound The route bound. + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ public function setBound(Bound $bound) { @@ -94,9 +93,9 @@ public function setBound(Bound $bound) } /** - * Gets the route copyrights. + * Gets the copyrights. * - * @return string The route copyrights. + * @return string The copyrights. */ public function getCopyrights() { @@ -104,25 +103,37 @@ public function getCopyrights() } /** - * Sets the route copyrights. + * Sets the copyrights. * - * @param string $copyrights The route copyrights. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the copyrights is not valid. + * @param string $copyrights The copyrights. */ public function setCopyrights($copyrights) { - if (!is_string($copyrights)) { - throw DirectionsException::invalidDirectionsRouteCopyrights(); - } - $this->copyrights = $copyrights; } /** - * Gets the route legs + * Resets the legs. + */ + public function resetLegs() + { + $this->legs = array(); + } + + /** + * Checks if there are legs. + * + * @return boolean TRUE if there are legs else FALSE. + */ + public function hasLegs() + { + return !empty($this->legs); + } + + /** + * Gets the legs * - * @return array The route legs. + * @return array The legs. */ public function getLegs() { @@ -130,33 +141,78 @@ public function getLegs() } /** - * Sets the route legs + * Sets the legs * - * @param array $legs The route legs. + * @param array $legs The legs. */ public function setLegs(array $legs) { - $this->legs = array(); + $this->resetLegs(); + $this->addLegs($legs); + } + /** + * Adds the legs. + * + * @param array $legs The legs. + */ + public function addLegs(array $legs) + { foreach ($legs as $leg) { $this->addLeg($leg); } } /** - * Adds a leg to the route. + * Removes the legs. + * + * @param array $legs The legs. + */ + public function removeLegs(array $legs) + { + foreach ($legs as $leg) { + $this->removeLeg($leg); + } + } + + /** + * Checks if there is a leg. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg $leg The leg. * - * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg The leg to add. + * @return boolean TRUE if there is the leg else FALSE. + */ + public function hasLeg(DirectionsLeg $leg) + { + return in_array($leg, $this->legs, true); + } + + /** + * Adds a leg. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg The leg. */ public function addLeg(DirectionsLeg $leg) { - $this->legs[] = $leg; + if (!$this->hasLeg($leg)) { + $this->legs[] = $leg; + } } /** - * Gets the route overview polyline. + * Removes a leg. * - * @return \Ivory\GoogleMap\Overlays\EncodedPolyline The route overview polyline. + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg $leg The leg. + */ + public function removeLeg(DirectionsLeg $leg) + { + unset($this->legs[array_search($leg, $this->legs, true)]); + } + + /** + * Gets the overview polyline. + * + * @return \Ivory\GoogleMap\Overlays\EncodedPolyline The overview polyline. */ public function getOverviewPolyline() { @@ -164,9 +220,9 @@ public function getOverviewPolyline() } /** - * Sets the route overview polyline. + * Sets the overview polyline. * - * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $overviewPolyline The route overview polyline. + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $overviewPolyline The overview polyline. */ public function setOverviewPolyline(EncodedPolyline $overviewPolyline) { @@ -174,9 +230,9 @@ public function setOverviewPolyline(EncodedPolyline $overviewPolyline) } /** - * Gets the route summary. + * Gets the summary. * - * @return string The route summary. + * @return string The summary. */ public function getSummary() { @@ -184,25 +240,37 @@ public function getSummary() } /** - * Sets the route summary. - * - * @param string $summary The route summary. + * Sets the summary. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the summary is not valid. + * @param string $summary The summary. */ public function setSummary($summary) { - if (!is_string($summary)) { - throw DirectionsException::invalidDirectionsRouteSummary(); - } - $this->summary = $summary; } /** - * Gets the route warnings. + * Resets the warnings. + */ + public function resetWarnings() + { + $this->warnings = array(); + } + + /** + * Checks if there are warnings. * - * @return array The route warnings. + * @return boolean TRUE if there are warnings else FALSE. + */ + public function hasWarnings() + { + return !empty($this->warnings); + } + + /** + * Gets the warnings. + * + * @return array The warnings. */ public function getWarnings() { @@ -210,72 +278,168 @@ public function getWarnings() } /** - * Sets the route warnings. + * Sets the warnings. * - * @param array $warnings The route warnings. + * @param array $warnings The warnings. */ public function setWarnings(array $warnings) { - $this->warnings = array(); + $this->resetWarnings(); + $this->addWarnings($warnings); + } + /** + * Adds the warnings. + * + * @param array $warnings The warnings. + */ + public function addWarnings(array $warnings) + { foreach ($warnings as $warning) { $this->addWarning($warning); } } /** - * Adds a warning to the route. + * Removes the warnings. * - * @param string $warning The warning to add. + * @param array $warnings The warnings. + */ + public function removeWarnings(array $warnings) + { + foreach ($warnings as $warning) { + $this->removeWarning($warning); + } + } + + /** + * Checks if there is a warning. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the warning is not valid. + * @param string $warning The warning. + * + * @return boolean TRUE if there is a warning else FALSE. + */ + public function hasWarning($warning) + { + return in_array($warning, $this->warnings, true); + } + + /** + * Adds a warning. + * + * @param string $warning The warning. */ public function addWarning($warning) { - if (!is_string($warning)) { - throw DirectionsException::invalidDirectionsRouteWarning(); + if (!$this->hasWarning($warning)) { + $this->warnings[] = $warning; } + } + + /** + * Removes a warning. + * + * @param string $warning The warning. + */ + public function removeWarning($warning) + { + unset($this->warnings[array_search($warning, $this->warnings, true)]); + } + + /** + * Resets the warypoint orders. + */ + public function resetWaypointOrders() + { + $this->waypointOrders = array(); + } - $this->warnings[] = $warning; + /** + * Checks if there are waypoint orders. + * + * @return boolean TRUE if there are waypoint orders else FALSE. + */ + public function hasWaypointOrders() + { + return !empty($this->waypointOrders); } /** - * Gets the route waypoint order. + * Gets the waypoint orders. * - * @return array The route waypoint order. + * @return array The waypoint orders. */ - public function getWaypointOrder() + public function getWaypointOrders() { - return $this->waypointOrder; + return $this->waypointOrders; } /** - * Sets the routes waypoint order. + * Sets the waypoint orders. * - * @param array $waypointOrder The route waypoint order. + * @param array $waypointOrders The waypoint orders. */ - public function setWaypointOrder(array $waypointOrder) + public function setWaypointOrders(array $waypointOrders) { - $this->waypointOrder = array(); + $this->resetWaypointOrders(); + $this->addWaypointOrders($waypointOrders); + } - foreach ($waypointOrder as $waypointOrder) { + /** + * Adds the waypoint orders. + * + * @param array $waypointOrders The waypoint orders. + */ + public function addWaypointOrders(array $waypointOrders) + { + foreach ($waypointOrders as $waypointOrder) { $this->addWaypointOrder($waypointOrder); } } /** - * Adds a waypoint order to the route. + * Removes the waypoint orders. * - * @param integer $waypointOrder The waypoint to add. + * @param array $waypointOrders The waypoint orders. + */ + public function removeWaypointOrders(array $waypointOrders) + { + foreach ($waypointOrders as $waypointOrder) { + $this->removeWaypointOrder($waypointOrder); + } + } + + /** + * Checks if there is a waypoint order. + * + * @param integer $waypointOrder The waypoint order. + * + * @return boolean TRUE if there is the waypoint order else FALSE. + */ + public function hasWaypointOrder($waypointOrder) + { + return in_array($waypointOrder, $this->waypointOrders, true); + } + + /** + * Adds a waypoint order. * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the waypoint order is not valid. + * @param integer $waypointOrder The waypoint order. */ public function addWaypointOrder($waypointOrder) { - if (!is_int($waypointOrder)) { - throw DirectionsException::invalidDirectionsRouteWaypointOrder(); + if (!$this->hasWaypointOrder($waypointOrder)) { + $this->waypointOrders[] = $waypointOrder; } + } - $this->waypointOrder[] = $waypointOrder; + /** + * Removes a waypoint order. + * + * @param integer $waypointOrder The waypoint order. + */ + public function removeWaypointOrder($waypointOrder) + { + unset($this->waypointOrders[array_search($waypointOrder, $this->waypointOrders, true)]); } } diff --git a/src/Services/Directions/DirectionsStatus.php b/src/Services/Directions/DirectionsStatus.php index 72ce8dc2..4ea5ff14 100644 --- a/src/Services/Directions/DirectionsStatus.php +++ b/src/Services/Directions/DirectionsStatus.php @@ -11,13 +11,15 @@ namespace Ivory\GoogleMap\Services\Directions; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * A directions status which describes the google map direction status. + * Directions status. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsStatus + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsStatus * @author GeLo */ -class DirectionsStatus +class DirectionsStatus extends AbstractUninstantiableAsset { const INVALID_REQUEST = 'INVALID_REQUEST'; const MAX_WAYPOINTS_EXCEEDED = 'MAX_WAYPOINTS_EXCEEDED'; @@ -27,33 +29,4 @@ class DirectionsStatus const REQUEST_DENIED = 'REQUEST_DENIED'; const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; const ZERO_RESULTS = 'ZERO_RESULTS'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available directions status. - * - * @return array The available directions status. - */ - public static function getDirectionsStatus() - { - return array( - self::INVALID_REQUEST, - self::MAX_WAYPOINTS_EXCEEDED, - self::NOT_FOUND, - self::OK, - self::OVER_QUERY_LIMIT, - self::REQUEST_DENIED, - self::UNKNOWN_ERROR, - self::ZERO_RESULTS, - ); - } } diff --git a/src/Services/Directions/DirectionsStep.php b/src/Services/Directions/DirectionsStep.php index 7f333da4..e1ad2288 100644 --- a/src/Services/Directions/DirectionsStep.php +++ b/src/Services/Directions/DirectionsStep.php @@ -12,16 +12,14 @@ namespace Ivory\GoogleMap\Services\Directions; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DirectionsException; use Ivory\GoogleMap\Overlays\EncodedPolyline; use Ivory\GoogleMap\Services\Base\Distance; use Ivory\GoogleMap\Services\Base\Duration; -use Ivory\GoogleMap\Services\Base\TravelMode; /** - * A directions step which describes a google map directions step. + * Directions step. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsStep + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsStep * @author GeLo */ class DirectionsStep @@ -77,9 +75,9 @@ public function __construct( } /** - * Gets the step distance. + * Gets the distance. * - * @return \Ivory\GoogleMap\Services\Base\Distance The step distance. + * @return \Ivory\GoogleMap\Services\Base\Distance The distance. */ public function getDistance() { @@ -87,9 +85,9 @@ public function getDistance() } /** - * Sets the step distance. + * Sets the distance. * - * @param \Ivory\GoogleMap\Services\Base\Distance $distance The step distance. + * @param \Ivory\GoogleMap\Services\Base\Distance $distance The distance. */ public function setDistance(Distance $distance) { @@ -97,9 +95,9 @@ public function setDistance(Distance $distance) } /** - * Gets the step duration. + * Gets the duration. * - * @return \Ivory\GoogleMap\Services\Base\Duration The step duration. + * @return \Ivory\GoogleMap\Services\Base\Duration The duration. */ public function getDuration() { @@ -107,9 +105,9 @@ public function getDuration() } /** - * Sets the step duration + * Sets the duration * - * @param \Ivory\GoogleMap\Services\Base\Duration $duration The step duration. + * @param \Ivory\GoogleMap\Services\Base\Duration $duration The duration. */ public function setDuration(Duration $duration) { @@ -117,9 +115,9 @@ public function setDuration(Duration $duration) } /** - * Gets the step end location. + * Gets the end location. * - * @return \Ivory\GoogleMap\Base\Coordinate The step end location. + * @return \Ivory\GoogleMap\Base\Coordinate The end location. */ public function getEndLocation() { @@ -127,9 +125,9 @@ public function getEndLocation() } /** - * Sets the step end location. + * Sets the end location. * - * @param \Ivory\GoogleMap\Base\Coordinate $endLocation The step end location. + * @param \Ivory\GoogleMap\Base\Coordinate $endLocation The end location. */ public function setEndLocation(Coordinate $endLocation) { @@ -137,9 +135,9 @@ public function setEndLocation(Coordinate $endLocation) } /** - * Gets the step instructions. + * Gets the instructions. * - * @return string The step instructions. + * @return string The instructions. */ public function getInstructions() { @@ -147,23 +145,17 @@ public function getInstructions() } /** - * Sets the step instructions. + * Sets the instructions. * - * @param string $instructions The step instructions. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the instructions is not valid. + * @param string $instructions The instructions. */ public function setInstructions($instructions) { - if (!is_string($instructions)) { - throw DirectionsException::invalidDirectionsStepInstructions(); - } - $this->instructions = $instructions; } /** - * Gets the encoded polyline which describes the step. + * Gets the encoded polyline. * * @return \Ivory\GoogleMap\Overlays\EncodedPolyline The encoded polyline. */ @@ -173,7 +165,7 @@ public function getEncodedPolyline() } /** - * Sets the encoded polyline which describes the step. + * Sets the encoded polyline. * * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. */ @@ -183,9 +175,9 @@ public function setEncodedPolyline(EncodedPolyline $encodedPolyline) } /** - * Gets the step start location. + * Gets the start location. * - * @return \Ivory\GoogleMap\Base\Coordinate The step start location. + * @return \Ivory\GoogleMap\Base\Coordinate The start location. */ public function getStartLocation() { @@ -193,9 +185,9 @@ public function getStartLocation() } /** - * Sets the step start location. + * Sets the start location. * - * @param \Ivory\GoogleMap\Base\Coordinate $startLocation The step start position. + * @param \Ivory\GoogleMap\Base\Coordinate $startLocation The start position. */ public function setStartLocation(Coordinate $startLocation) { @@ -203,9 +195,9 @@ public function setStartLocation(Coordinate $startLocation) } /** - * Gets the step travel mode. + * Gets the travel mode. * - * @return string The step travel mode. + * @return string The travel mode. */ public function getTravelMode() { @@ -213,18 +205,12 @@ public function getTravelMode() } /** - * Sets the step travel mode. + * Sets the travel mode. * - * @param string $travelMode The step travel mode. - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the travel mode is not valid. + * @param string $travelMode The travel mode. */ public function setTravelMode($travelMode) { - if (!in_array($travelMode, TravelMode::getTravelModes())) { - throw DirectionsException::invalidDirectionsStepTravelMode(); - } - $this->travelMode = $travelMode; } } diff --git a/src/Services/Directions/DirectionsWaypoint.php b/src/Services/Directions/DirectionsWaypoint.php index 5d1033ab..a0589abf 100644 --- a/src/Services/Directions/DirectionsWaypoint.php +++ b/src/Services/Directions/DirectionsWaypoint.php @@ -11,37 +11,46 @@ namespace Ivory\GoogleMap\Services\Directions; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DirectionsException; - /** - * A directions waypoint which describes the google map directions waypoint. + * Directions waypoint. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsWaypoint + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsWaypoint * @author GeLo */ class DirectionsWaypoint { - /** @var string | \Ivory\GoogleMap\Base\Coordinate */ + /** @var string|\Ivory\GoogleMap\Base\Coordinate */ protected $location; /** @var boolean */ protected $stopover; /** - * Checks if the directions waypoint has a location. + * Creates a directions waypoint. * - * @return boolean TRUE if the directions waypoint has a location else FALSE. + * @param string|\Ivory\GoogleMap\Base\Coordinate $location The coordinate. + * @param boolean|null $stopover TRUE if it stopover else FALSE. + */ + public function __construct($location, $stopover = null) + { + $this->setLocation($location); + $this->setStopover($stopover); + } + + /** + * Checks if it has a location. + * + * @return boolean TRUE if it has a location else FALSE. */ public function hasLocation() { - return $this->location !== null; + return !empty($this->location); } /** - * Gets the directions waypoint location. + * Gets the location. * - * @return string | \Ivory\GoogleMap\Base\Coordinate The directions waypoint location. + * @return string|\Ivory\GoogleMap\Base\Coordinate The location. */ public function getLocation() { @@ -49,43 +58,19 @@ public function getLocation() } /** - * Sets the directions waypoint location. + * Sets the location. * - * Available prototypes: - * - function setLocation(string $destination) - * - function setLocation(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setLocation(double $latitude, double $longitude, boolean $noWrap) - * - * @throws \Ivory\GoogleMap\Exception\DirectionsException If the location is not valid (prototypes). + * @param string|\Ivory\GoogleMap\Base\Coordinate $location The location. */ - public function setLocation() + public function setLocation($location) { - $args = func_get_args(); - - if (isset($args[0]) && is_string($args[0])) { - $this->location = $args[0]; - } elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->location = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if ($this->location === null) { - $this->location = new Coordinate(); - } - - $this->location->setLatitude($args[0]); - $this->location->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->location->setNoWrap($args[2]); - } - } else { - throw DirectionsException::invalidDirectionsWaypointLocation(); - } + $this->location = $location; } /** - * Checks if the directions waypoint has a stopover flag. + * Checks if it has a stopover. * - * @return boolean TRUE if the directions waypoint has a stopover flag else FALSE. + * @return boolean TRUE if it has a stopover else FALSE. */ public function hasStopover() { @@ -93,9 +78,9 @@ public function hasStopover() } /** - * Gets the directions waypoint stopover flag. + * Gets the stopover. * - * @return boolean The directions waypoint stopover flag. + * @return boolean|null The stopover. */ public function getStopover() { @@ -103,26 +88,12 @@ public function getStopover() } /** - * Sets the directions waypoint stopover flag. + * Sets the stopover. * - * @param boolean $stopover The directions waypoint stopover flag. + * @param boolean|null $stopover The stopover. */ public function setStopover($stopover = null) { - if (!is_bool($stopover) && ($stopover !== null)) { - throw DirectionsException::invalidDirectionsWaypointStopover(); - } - $this->stopover = $stopover; } - - /** - * Checks if the directions waypoint is valid. - * - * @return boolean TRUE if the directions waypoint is valid else FALSE. - */ - public function isValid() - { - return $this->hasLocation(); - } } diff --git a/src/Services/DistanceMatrix/DistanceMatrix.php b/src/Services/DistanceMatrix/DistanceMatrix.php index c616959e..2cdcf7a6 100644 --- a/src/Services/DistanceMatrix/DistanceMatrix.php +++ b/src/Services/DistanceMatrix/DistanceMatrix.php @@ -11,110 +11,76 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; +use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Services\AbstractService; -use Ivory\GoogleMap\Exception\DistanceMatrixException; use Ivory\GoogleMap\Services\Base\Distance; use Ivory\GoogleMap\Services\Base\Duration; -use Widop\HttpAdapter\HttpAdapterInterface; +use Ivory\GoogleMap\Services\BusinessAccount; +use Ivory\GoogleMap\Services\Utils\XmlParser; +use Ivory\HttpAdapter\HttpAdapterInterface; /** - * DistanceMatrix service. + * Distance matrix service. * * @author GeLo - * @author Tyler Sommer */ class DistanceMatrix extends AbstractService { /** - * Creates a distance matrix service. - * - * @param \Widop\HttpAdapter\HttpAdapterInterface $httpAdapter The http adapter. + * {@inheritdoc} */ - public function __construct(HttpAdapterInterface $httpAdapter) - { - parent::__construct($httpAdapter, 'http://maps.googleapis.com/maps/api/distancematrix'); + public function __construct( + HttpAdapterInterface $httpAdapter, + $url = 'http://maps.googleapis.com/maps/api/distancematrix', + $https = false, + $format = self::FORMAT_JSON, + XmlParser $xmlParser = null, + BusinessAccount $businessAccount = null + ) { + parent::__construct($httpAdapter, $url, $https, $format, $xmlParser, $businessAccount); } /** - * Processes the given request. + * Processes the request. * - * Available prototypes: - * - function process(array $origins, array $destinations) - * - function process(Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $request) + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $request The request. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the request is not valid (prototypes). + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse The response. */ - public function process() + public function process(DistanceMatrixRequest $request) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof DistanceMatrixRequest)) { - $distanceMatrixRequest = $args[0]; - } elseif ((isset($args[0]) && is_array($args[0])) && (isset($args[1]) && is_array($args[1]))) { - $distanceMatrixRequest = new DistanceMatrixRequest(); - - $distanceMatrixRequest->setOrigins($args[0]); - $distanceMatrixRequest->setDestinations($args[1]); - } else { - throw DistanceMatrixException::invalidDistanceMatrixRequestParameters(); - } - - if (!$distanceMatrixRequest->isValid()) { - throw DistanceMatrixException::invalidDistanceMatrixRequest(); - } - - $url = $this->generateUrl($distanceMatrixRequest); - $response = $this->httpAdapter->getContent($url); - - if ($response === null) { - throw DistanceMatrixException::invalidServiceResult(); - } - - $distanceMatrixResponse = $this->buildDistanceMatrixResponse($this->parse($response->getBody())); - - return $distanceMatrixResponse; + return $this->buildResponse($this->parse( + (string) $this->httpAdapter->get($this->generateUrl($request))->getBody() + )); } /** - * Generates distance matrix URL API according to the request. + * Generates the url. * - * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $distanceMatrixRequest The distance matrix request. + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $distanceMatrixRequest The request. * - * @return string The generated URL. + * @return string The generated url. */ protected function generateUrl(DistanceMatrixRequest $distanceMatrixRequest) { - $httpQuery = array( - 'origins' => array(), - 'destinations' => array(), - ); - + $origins = array(); foreach ($distanceMatrixRequest->getOrigins() as $origin) { - if (is_string($origin)) { - $httpQuery['origins'][] = $origin; - } else { - $httpQuery['origins'][] = sprintf( - '%s,%s', - $origin->getLatitude(), - $origin->getLongitude() - ); - } + $origins[] = $origin instanceof Coordinate + ? $origin->getLatitude().','.$origin->getLongitude() + : $origin; } + $destinations = array(); foreach ($distanceMatrixRequest->getDestinations() as $destination) { - if (is_string($destination)) { - $httpQuery['destinations'][] = $destination; - } else { - $httpQuery['destinations'][] = sprintf( - '%s,%s', - $destination->getLatitude(), - $destination->getLongitude() - ); - } + $destinations[] = $destination instanceof Coordinate + ? $destination->getLatitude().','.$destination->getLongitude() + : $destination; } - $httpQuery['origins'] = implode('|', $httpQuery['origins']); - $httpQuery['destinations'] = implode('|', $httpQuery['destinations']); + $httpQuery = array( + 'origins' => implode('|', $origins), + 'destinations' => implode('|', $destinations), + ); if ($distanceMatrixRequest->hasTravelMode()) { $httpQuery['mode'] = strtolower($distanceMatrixRequest->getTravelMode()); @@ -142,47 +108,41 @@ protected function generateUrl(DistanceMatrixRequest $distanceMatrixRequest) $httpQuery['sensor'] = $distanceMatrixRequest->hasSensor() ? 'true' : 'false'; - $url = sprintf('%s/%s?%s', $this->getUrl(), $this->getFormat(), http_build_query($httpQuery)); - - return $this->signUrl($url); + return $this->signUrl($this->getUrl().'/'.$this->getFormat().'?'.http_build_query($httpQuery)); } /** - * Parses & normalizes the distance matrix API result response. + * Parses the body. * - * @param string $response The distance matrix API response. + * @param string $body The body. * - * @return \stdClass The parsed & normalized distance matrix response. + * @return array The parsed response. */ - protected function parse($response) + protected function parse($body) { - if ($this->format === 'json') { - return $this->parseJSON($response); - } - - return $this->parseXML($response); + return $this->format === self::FORMAT_JSON ? $this->parseJson($body) : $this->parseXml($body); } /** - * Parses & normalizes a JSON distance matrix API result response. + * Parses the json body. * - * @param string $response The distance matrix API JSON response. + * @param string $response The json body. * - * @return \stdClass The parsed & normalized distance matrix response. + * @return array The parsed json body. */ - protected function parseJSON($response) + protected function parseJson($response) { - return json_decode($response); + return json_decode($response, true); } /** - * Parses & normalizes an XML distance matrix API result response. + * Parses the xml body. * - * @param string $response The distance matrix API XML response. + * @param string $response The xml body. * - * @return \stdClass The parsed & normalized distance matrix response. + * @return array The parsed xml body. */ - protected function parseXML($response) + protected function parseXml($response) { $rules = array( 'destination_address' => 'destination_addresses', @@ -195,76 +155,73 @@ protected function parseXML($response) } /** - * Builds the distance matrix response according to the normalized distance matrix API results. + * Builds the response. * - * @param \stdClass $distanceMatrixResponse The normalized distance matrix response. + * @param array $response The response. * - * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse The built distance matrix response. + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse The built response. */ - protected function buildDistanceMatrixResponse(\stdClass $distanceMatrixResponse) + protected function buildResponse(array $response) { - $status = $distanceMatrixResponse->status; - $destinations = $distanceMatrixResponse->destination_addresses; - $origins = $distanceMatrixResponse->origin_addresses; - $rows = $this->buildDistanceMatrixRows($distanceMatrixResponse->rows); - - return new DistanceMatrixResponse($status, $destinations, $origins, $rows); + return new DistanceMatrixResponse( + $response['status'], + $response['destination_addresses'], + $response['origin_addresses'], + $this->buildRows($response['rows']) + ); } /** - * Builds the distance matrix response rows according to the normalized distance matrix API results. + * Builds the rows. * - * @param array $rows The normalized distance matrix response rows. + * @param array $rows The rows. * - * @return array The built distance matrix response rows. + * @return array The built rows. */ - protected function buildDistanceMatrixRows($rows) + protected function buildRows($rows) { $results = array(); foreach ($rows as $row) { - $results[] = $this->buildDistanceMatrixRow($row); + $results[] = $this->buildRow($row); } return $results; } /** - * Builds a distance matrix response row according to the normalized distance matrix API response row. + * Builds a row. * - * @param \stdClass $row The normalized distance matrix response row. + * @param array $row The row. * - * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow The built distance matrix response row. + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow The built row. */ - protected function buildDistanceMatrixRow($row) + protected function buildRow(array $row) { $elements = array(); - foreach ($row->elements as $element) { - $elements[] = $this->buildDistanceMatrixResponseElement($element); + foreach ($row['elements'] as $element) { + $elements[] = $this->buildResponseElement($element); } return new DistanceMatrixResponseRow($elements); } /** - * Builds a distance matrix response element according to the normalized distance matrix API response elements. + * Builds a response element. * - * @param \stdClass $element The normalized distance matrix response element. + * @param array $element The response element. * - * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement The built distance matrix response element. + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement The built response element. */ - protected function buildDistanceMatrixResponseElement($element) + protected function buildResponseElement(array $element) { - $status = $element->status; - $distance = null; - $duration = null; + $isStatusOk = $element['status'] === DistanceMatrixElementStatus::OK; - if ($element->status === DistanceMatrixElementStatus::OK) { - $distance = new Distance($element->distance->text, $element->distance->value); - $duration = new Duration($element->duration->text, $element->duration->value); - } - - return new DistanceMatrixResponseElement($status, $distance, $duration); + return new DistanceMatrixResponseElement( + $element['status'], + $isStatusOk ? new Distance($element['distance']['text'], $element['distance']['value']) : null, + $isStatusOk ? new Duration($element['duration']['text'], $element['duration']['value']) : null + ); } } diff --git a/src/Services/DistanceMatrix/DistanceMatrixElementStatus.php b/src/Services/DistanceMatrix/DistanceMatrixElementStatus.php index d4371a2f..6b2bc2bd 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixElementStatus.php +++ b/src/Services/DistanceMatrix/DistanceMatrixElementStatus.php @@ -11,40 +11,17 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * A distance matrix status which describes the google map distance matrix status. + * Distance matrix element status. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixElementStatus + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixElementStatus * @author GeLo - * @author Tyler Sommer */ -class DistanceMatrixElementStatus +class DistanceMatrixElementStatus extends AbstractUninstantiableAsset { const NOT_FOUND = 'NOT_FOUND'; const OK = 'OK'; const ZERO_RESULTS = 'ZERO_RESULTS'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available distance matrix status. - * - * @return array The available distance matrix status. - */ - public static function getDistanceMatrixElementStatus() - { - return array( - self::NOT_FOUND, - self::OK, - self::ZERO_RESULTS, - ); - } } diff --git a/src/Services/DistanceMatrix/DistanceMatrixRequest.php b/src/Services/DistanceMatrix/DistanceMatrixRequest.php index 3269d592..32f40693 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixRequest.php +++ b/src/Services/DistanceMatrix/DistanceMatrixRequest.php @@ -11,24 +11,18 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\DistanceMatrixException; -use Ivory\GoogleMap\Services\Base\TravelMode; -use Ivory\GoogleMap\Services\Base\UnitSystem; - /** - * DistanceMatrixRequest represents a google map distance matrix query. + * Distance matrix request. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixRequest + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixRequest * @author GeLo - * @author Tyler Sommer */ class DistanceMatrixRequest { - /** @var boolean */ + /** @var boolean|null */ protected $avoidHighways; - /** @var boolean */ + /** @var boolean|null */ protected $avoidTolls; /** @var array */ @@ -37,35 +31,37 @@ class DistanceMatrixRequest /** @var array */ protected $origins; - /** @var string */ + /** @var string|null */ protected $region; - /** @var string */ + /** @var string|null */ protected $language; - /** @var string */ + /** @var string|null */ protected $travelMode; - /** @var string */ + /** @var string|null */ protected $unitSystem; /** @var boolean */ - protected $sensor; + protected $sensor = false; /** * Creates a distance matrix request. + * + * @param array $origins The origins. + * @param array $destinations The destinations. */ - public function __construct() + public function __construct(array $origins, array $destinations) { - $this->origins = array(); - $this->destinations = array(); - $this->sensor = false; + $this->setOrigins($origins); + $this->setDestinations($destinations); } /** - * Checks if the distance matrix request has an avoid hightways flag. + * Checks if it has an avoid hightways. * - * @return boolean TRUE if the distance matrix request has an avoid hightways flag else FALSE. + * @return boolean TRUE if it has an avoid hightways else FALSE. */ public function hasAvoidHighways() { @@ -73,9 +69,9 @@ public function hasAvoidHighways() } /** - * Checks if the distance matrix request avoid hightways. + * Checks if it avoids hightways. * - * @return boolean TRUE if the distance matrix request avoids hightways else FALSE. + * @return boolean|null TRUE if it avoids hightways else FALSE. */ public function getAvoidHighways() { @@ -83,25 +79,19 @@ public function getAvoidHighways() } /** - * Sets if the the distance matrix request avoids hightways. - * - * @param boolean $avoidHighways TRUE if the distance matrix request avoids hightways else FALSE. + * Sets if it avoids hightways. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the avoid highways flag is not valid. + * @param boolean|null $avoidHighways TRUE if it avoids hightways else FALSE. */ public function setAvoidHighways($avoidHighways = null) { - if (!is_bool($avoidHighways) && ($avoidHighways !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestAvoidHighways(); - } - $this->avoidHighways = $avoidHighways; } /** - * Checks if the distance matrix request has an avoid tolls flag. + * Checks if it has an avoid tolls. * - * @return boolean TRUE if the distance matrix request has an avoid tolls flag else FALSE. + * @return boolean TRUE if it has an avoid tolls else FALSE. */ public function hasAvoidTolls() { @@ -109,9 +99,9 @@ public function hasAvoidTolls() } /** - * Checks if the distance matrix request avoid tolls. + * Checks if it avoids tolls. * - * @return boolean TRUE if the distance matrix request avoids tolls else FALSE. + * @return boolean|null TRUE if it avoids tolls else FALSE. */ public function getAvoidTolls() { @@ -119,25 +109,27 @@ public function getAvoidTolls() } /** - * Sets if the the distance matrix request avoids tolls. - * - * @param boolean $avoidTolls TRUE if the distance matrix request avoids tolls else FALSE. + * Sets if it avoids tolls. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the avoid tolls flag is not valid. + * @param boolean|null $avoidTolls TRUE if it avoids tolls else FALSE. */ public function setAvoidTolls($avoidTolls = null) { - if (!is_bool($avoidTolls) && ($avoidTolls !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestAvoidTolls(); - } - $this->avoidTolls = $avoidTolls; } /** - * Checks if the distance matrix request has destinations. + * Resets the destinations. + */ + public function resetDestinations() + { + $this->destinations = array(); + } + + /** + * Checks if it has destinations. * - * @return boolean TRUE if the distance matrix request has a destination else FALSE. + * @return boolean TRUE if it has a destination else FALSE. */ public function hasDestinations() { @@ -145,9 +137,9 @@ public function hasDestinations() } /** - * Gets the distance matrix request destinations + * Gets the destinations * - * @return array The distance matrix request destination. + * @return array The destinations. */ public function getDestinations() { @@ -155,56 +147,86 @@ public function getDestinations() } /** - * Sets the request destinations. + * Sets the destinations. * - * @param array $destinations The distance matrix request destinations. + * @param array $destinations The destinations. */ - public function setDestinations(array $destinations = array()) + public function setDestinations(array $destinations) { - $this->destinations = array(); + $this->resetDestinations(); + $this->addDestinations($destinations); + } + /** + * Adds the destinations. + * + * @param array $destinations The destinations. + */ + public function addDestinations(array $destinations) + { foreach ($destinations as $destination) { $this->addDestination($destination); } } /** - * Adds a destination to the request. - * - * Available prototypes: - * - function addDestination(string $destination) - * - function addDestination(Ivory\GoogleMap\Base\Coordinate $destination) - * - function addDestination(double $latitude, double $longitude, boolean $noWrap) + * Removes the destination. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the destination is not valid (prototypes). + * @param array $destinations The destinations. */ - public function addDestination() + public function removeDestinations(array $destinations) { - $args = func_get_args(); - - if (isset($args[0]) && is_string($args[0])) { - $this->destinations[] = $args[0]; - } elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->destinations[] = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $destination = new Coordinate(); - $destination->setLatitude($args[0]); - $destination->setLongitude($args[1]); + foreach ($destinations as $destination) { + $this->removeDestination($destination); + } + } - if (isset($args[2]) && is_bool($args[2])) { - $destination->setNoWrap($args[2]); - } + /** + * Check if there is a destination. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. + * + * @return boolean TRUE if there is the destination else FALSE. + */ + public function hasDestination($destination) + { + return in_array($destination, $this->destinations, true); + } + /** + * Adds a destination. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. + */ + public function addDestination($destination) + { + if (!$this->hasDestination($destination)) { $this->destinations[] = $destination; - } else { - throw DistanceMatrixException::invalidDistanceMatrixRequestDestination(); } } /** - * Checks if the distance matrix request has origins. + * Removes a destination. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $detination The destination. + */ + public function removeDestination($detination) + { + unset($this->destinations[array_search($detination, $this->destinations, true)]); + } + + /** + * Resets the origins. + */ + public function resetOrigins() + { + $this->origins = array(); + } + + /** + * Checks if there are origins. * - * @return boolean TRUE if the distance matrix request has origins else FALSE. + * @return boolean TRUE if there are origins else FALSE. */ public function hasOrigins() { @@ -212,9 +234,9 @@ public function hasOrigins() } /** - * Gets the distance matrix request origin. + * Gets the origins. * - * @return array The distance matrix request origin. + * @return array The origins. */ public function getOrigins() { @@ -222,56 +244,78 @@ public function getOrigins() } /** - * Sets the request origins. + * Sets the origins. * - * @param array $origins The distance matrix request origins. + * @param array $origins The origins. */ - public function setOrigins(array $origins = array()) + public function setOrigins(array $origins) { - $this->origins = array(); + $this->resetOrigins(); + $this->addOrigins($origins); + } + /** + * Adds the origins. + * + * @param array $origins The origins. + */ + public function addOrigins(array $origins) + { foreach ($origins as $origin) { $this->addOrigin($origin); } } /** - * Adds an origin to the request. + * Removes the origins. * - * Available prototypes: - * - function addOrigin(string $destination) - * - function addOrigin(Ivory\GoogleMap\Base\Coordinate $destination) - * - function addOrigin(double $latitude, double $longitude, boolean $noWrap) - * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the origin is not valid (prototypes). + * @param array $origins The origins. */ - public function addOrigin() + public function removeOrigins(array $origins) { - $args = func_get_args(); - - if (isset($args[0]) && is_string($args[0])) { - $this->origins[] = $args[0]; - } elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->origins[] = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - $origin = new Coordinate(); - $origin->setLatitude($args[0]); - $origin->setLongitude($args[1]); + foreach ($origins as $origin) { + $this->removeOrigin($origin); + } + } - if (isset($args[2]) && is_bool($args[2])) { - $origin->setNoWrap($args[2]); - } + /** + * Checks if there is an origin. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + * + * @return boolean TRUE if there is the origin else FALSE. + */ + public function hasOrigin($origin) + { + return in_array($origin, $this->origins, true); + } + /** + * Adds an origin. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + */ + public function addOrigin($origin) + { + if (!$this->hasOrigin($origin)) { $this->origins[] = $origin; - } else { - throw DistanceMatrixException::invalidDistanceMatrixRequestOrigin(); } } /** - * Checks if the distance matrix request has a region. + * Removes an origin. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + */ + public function removeOrigin($origin) + { + unset($this->origins[array_search($origin, $this->origins, true)]); + } + + /** + * Checks if there is a region. * - * @return boolean TRUE if the distance matrix request has a region else FALSE. + * @return boolean TRUE if there is a region else FALSE. */ public function hasRegion() { @@ -279,9 +323,9 @@ public function hasRegion() } /** - * Gets the distance matrix request region. + * Gets the region. * - * @return string The direction request region. + * @return string|null The region. */ public function getRegion() { @@ -289,25 +333,19 @@ public function getRegion() } /** - * Sets the distance matrix request region. - * - * @param string $region The distance matrix request region. + * Sets the region. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the region is not valid. + * @param string|null $region The region. */ public function setRegion($region = null) { - if ((!is_string($region) || (strlen($region) !== 2)) && ($region !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestRegion(); - } - $this->region = $region; } /** - * Checks if the distance matrix request has a language. + * Checks if there is a language. * - * @return boolean TRUE if the distance matrix request has a language else FALSE. + * @return boolean TRUE if there is a language else FALSE. */ public function hasLanguage() { @@ -315,9 +353,9 @@ public function hasLanguage() } /** - * Gets the distance matrix request language. + * Gets the language. * - * @return string The direction request language. + * @return string|null The language. */ public function getLanguage() { @@ -325,25 +363,19 @@ public function getLanguage() } /** - * Sets the distance matrix request language. - * - * @param string $language The distance matrix request language. + * Sets the language. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the language is not valid. + * @param string|null $language The language. */ public function setLanguage($language = null) { - if ((!is_string($language) || ((strlen($language) !== 2) && (strlen($language) !== 5))) && ($language !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestLanguage(); - } - $this->language = $language; } /** - * Checks if the distance matrix request has a travel mode. + * Checks if there is a travel mode. * - * @return boolean TRUE if the distance matrix request has a travel mode else FALSE. + * @return boolean TRUE if there is a travel mode else FALSE. */ public function hasTravelMode() { @@ -351,9 +383,9 @@ public function hasTravelMode() } /** - * Gets the distance matrix request travel mode. + * Gets the travel mode. * - * @return string The distance matrix request travel mode. + * @return string|null The travel mode. */ public function getTravelMode() { @@ -361,27 +393,19 @@ public function getTravelMode() } /** - * Sets the distance matrix request travel mode. - * - * @param string $travelMode The distance matrix request travel mode. + * Sets the travel mode. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the travel mode is not valid. + * @param string|null $travelMode The travel mode. */ public function setTravelMode($travelMode = null) { - $travelModes = array_diff(TravelMode::getTravelModes(), array(TravelMode::TRANSIT)); - - if (!in_array($travelMode, $travelModes) && ($travelMode !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestTravelMode(); - } - $this->travelMode = $travelMode; } /** - * Checks if the distance matrix request has a unit system. + * Checks if there is a unit system. * - * @return boolean TRUE if the distance matrix request has a unit system else FALSE. + * @return boolean TRUE if there is a unit system else FALSE. */ public function hasUnitSystem() { @@ -389,9 +413,9 @@ public function hasUnitSystem() } /** - * Gets the distance matrix request unit system. + * Gets the unit system. * - * @return string The distance matrix request unit system. + * @return string|null The unit system. */ public function getUnitSystem() { @@ -399,25 +423,19 @@ public function getUnitSystem() } /** - * Sets the distance matrix request unit system. + * Sets the unit system. * - * @param string $unitSystem The distance matrix request unit system. - * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the unit system is not valid. + * @param string|null $unitSystem The unit system. */ public function setUnitSystem($unitSystem = null) { - if (!in_array($unitSystem, UnitSystem::getUnitSystems()) && ($unitSystem !== null)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestUnitSystem(); - } - $this->unitSystem = $unitSystem; } /** - * Checks if the distance matrix request has a sensor. + * Checks if there is a sensor. * - * @return boolean TRUE if the distance matrix request has a sensor else FALSE. + * @return boolean TRUE if there is a sensor else FALSE. */ public function hasSensor() { @@ -425,28 +443,12 @@ public function hasSensor() } /** - * Sets the distance matrix request sensor. + * Sets the sensor. * - * @param boolean $sensor TRUE if the distance matrix request has a sensor else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the sensor flag is not valid. + * @param boolean $sensor TRUE if there is a sensor else FALSE. */ public function setSensor($sensor) { - if (!is_bool($sensor)) { - throw DistanceMatrixException::invalidDistanceMatrixRequestSensor(); - } - $this->sensor = $sensor; } - - /** - * Checks if the distance matrix request is valid. - * - * @return boolean TRUE if the distance matrix request is valid else FALSE. - */ - public function isValid() - { - return $this->hasDestinations() && $this->hasOrigins(); - } } diff --git a/src/Services/DistanceMatrix/DistanceMatrixResponse.php b/src/Services/DistanceMatrix/DistanceMatrixResponse.php index 6da34aec..2fd3de14 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixResponse.php +++ b/src/Services/DistanceMatrix/DistanceMatrixResponse.php @@ -11,14 +11,11 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; -use Ivory\GoogleMap\Exception\DistanceMatrixException; -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixStatus; - /** - * A distance matrix response wraps the distance results & the response status. + * Distance matrix response. * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixResponse * @author GeLo - * @author Tyler Sommer */ class DistanceMatrixResponse { @@ -37,10 +34,10 @@ class DistanceMatrixResponse /** * Create a distance matrix response. * - * @param string $status The response status. - * @param array $origins The normalized origins. - * @param array $destinations The normalized destinations. - * @param array $rows The rows of data returned. + * @param string $status The status. + * @param array $origins The origins. + * @param array $destinations The destinations. + * @param array $rows The rows. */ public function __construct($status, array $origins, array $destinations, array $rows) { @@ -51,9 +48,47 @@ public function __construct($status, array $origins, array $destinations, array } /** - * Gets the distance matrix routes. + * Gets the status. + * + * @return string The status. + */ + public function getStatus() + { + return $this->status; + } + + /** + * Sets the status. * - * @return array The distance matrix origins. + * @param string $status The tatus. + */ + public function setStatus($status) + { + $this->status = $status; + } + + /** + * Resets the origins. + */ + public function resetOrigins() + { + $this->origins = array(); + } + + /** + * Checks if there are origin. + * + * @return boolean TRUE if there are origins else FALSE. + */ + public function hasOrigins() + { + return !empty($this->origins); + } + + /** + * Gets the origins. + * + * @return array The origins. */ public function getOrigins() { @@ -61,33 +96,96 @@ public function getOrigins() } /** - * Sets the distance matrix routes. + * Sets the origins. * - * @param array $origins The distance matrix origins. + * @param array $origins The origins. */ public function setOrigins(array $origins) { - $this->origins = array(); + $this->resetOrigins(); + $this->addOrigins($origins); + } + /** + * Adds the origins. + * + * @param array $origins The origins. + */ + public function addOrigins(array $origins) + { foreach ($origins as $origin) { $this->addOrigin($origin); } } /** - * Add a distance matrix origin. + * Removes the origin. + * + * @param array $origins The origins. + */ + public function removeOrigins(array $origins) + { + foreach ($origins as $origin) { + $this->removeOrigin($origin); + } + } + + /** + * Checks if there is an origin. + * + * @param string $origin The origin. + * + * @return boolean TRUE if there is the origin else FALSE. + */ + public function hasOrigin($origin) + { + return in_array($origin, $this->origins, true); + } + + /** + * Adds an origin. * - * @param string $origin The origin to add. + * @param string $origin The origin. */ public function addOrigin($origin) { - $this->origins[] = $origin; + if (!$this->hasOrigin($origin)) { + $this->origins[] = $origin; + } + } + + /** + * Removes an origin. + * + * @param string $origin The origin. + */ + public function removeOrigin($origin) + { + unset($this->origins[array_search($origin, $this->origins, true)]); + } + + /** + * Resets the destinations. + */ + public function resetDestinations() + { + $this->destinations = array(); + } + + /** + * Checks if there are destinations. + * + * @return boolean TRUE if there are destinations else FALSE. + */ + public function hasDestinations() + { + return !empty($this->destinations); } /** - * Gets the distance matrix destinations. + * Gets the destinations. * - * @return array The distance matrix destinations. + * @return array The destinations. */ public function getDestinations() { @@ -95,33 +193,96 @@ public function getDestinations() } /** - * Sets the distance matrix destinations. + * Sets the destinations. * - * @param array $destinations The distance matrix routes. + * @param array $destinations The destinations. */ public function setDestinations(array $destinations) { - $this->destinations = array(); + $this->resetDestinations(); + $this->addDestinations($destinations); + } + /** + * Adds the destinations. + * + * @param array $destinations The destinations. + */ + public function addDestinations(array $destinations) + { foreach ($destinations as $destination) { $this->addDestination($destination); } } /** - * Add a distance matrix destination. + * Removes the destinations. * - * @param string $destination The destination to add. + * @param array $destinations The destinations. + */ + public function removeDestinations(array $destinations) + { + foreach ($destinations as $destination) { + $this->removeDestination($destination); + } + } + + /** + * Checks if there is a destination. + * + * @param string $destination The destination. + * + * @return boolean TRUE if there is a destination else FALSE. + */ + public function hasDestination($destination) + { + return in_array($destination, $this->destinations, true); + } + + /** + * Adds a destination. + * + * @param string $destination The destination. */ public function addDestination($destination) { - $this->destinations[] = $destination; + if (!$this->hasDestination($destination)) { + $this->destinations[] = $destination; + } } /** - * Gets the distance matrix routes. + * Removes a destination. * - * @return array The distance matrix rows. + * @param string $destination The destination. + */ + public function removeDestination($destination) + { + unset($this->destinations[array_search($destination, $this->destinations, true)]); + } + + /** + * Resets the rows. + */ + public function resetRows() + { + $this->rows = array(); + } + + /** + * Checks if there are rows. + * + * @return boolean TRUE if there are rows else FALSE. + */ + public function hasRows() + { + return !empty($this->rows); + } + + /** + * Gets the rows. + * + * @return array The rows. */ public function getRows() { @@ -129,52 +290,71 @@ public function getRows() } /** - * Sets the distance matrix routes. + * Sets the rows. * - * @param array $rows The distance matrix routes. + * @param array $rows The rows. */ public function setRows(array $rows) { - $this->rows = array(); + $this->resetRows(); + $this->addRows($rows); + } + /** + * Adds the rows. + * + * @param array $rows The rows. + */ + public function addRows(array $rows) + { foreach ($rows as $row) { $this->addRow($row); } } /** - * Add a distance matrix route. + * Removes the rows. * - * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row to add. + * @param array $rows The rows. */ - public function addRow(DistanceMatrixResponseRow $row) + public function removeRows(array $rows) { - $this->rows[] = $row; + foreach ($rows as $row) { + $this->removeRow($row); + } } /** - * Gets the distance matrix response status. + * Checks if there is a row. * - * @return string The distance matrix response status. + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row. + * + * @return boolean TRUE if there is the row else FALSE. */ - public function getStatus() + public function hasRow(DistanceMatrixResponseRow $row) { - return $this->status; + return in_array($row, $this->rows, true); } /** - * Sets the distance matrix response status. - * - * @param string $status The distance matrix status. + * Adds a row. * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the status is not valid. + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row. */ - public function setStatus($status) + public function addRow(DistanceMatrixResponseRow $row) { - if (!in_array($status, DistanceMatrixStatus::getDistanceMatrixStatus())) { - throw DistanceMatrixException::invalidDistanceMatrixResponseStatus(); + if (!$this->hasRow($row)) { + $this->rows[] = $row; } + } - $this->status = $status; + /** + * Removes a row. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row. + */ + public function removeRow(DistanceMatrixResponseRow $row) + { + unset($this->rows[array_search($row, $this->rows, true)]); } } diff --git a/src/Services/DistanceMatrix/DistanceMatrixResponseElement.php b/src/Services/DistanceMatrix/DistanceMatrixResponseElement.php index fd4ef801..b7d70cbd 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixResponseElement.php +++ b/src/Services/DistanceMatrix/DistanceMatrixResponseElement.php @@ -11,52 +11,44 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; -use Ivory\GoogleMap\Exception\DistanceMatrixException; use Ivory\GoogleMap\Services\Base\Distance; use Ivory\GoogleMap\Services\Base\Duration; -use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixElementStatus; /** - * A distance matrix response wraps the distance results & the response status. + * Distance matrix response element. * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixResponseElement * @author GeLo - * @author Tyler Sommer */ class DistanceMatrixResponseElement { /** @var string */ protected $status; - /** @var null|\Ivory\GoogleMap\Services\Base\Distance */ + /** @var \Ivory\GoogleMap\Services\Base\Distance|null */ protected $distance; - /** @var null|\Ivory\GoogleMap\Services\Base\Duration */ + /** @var \Ivory\GoogleMap\Services\Base\Duration|null */ protected $duration; /** * Create a distance matrix response element. * - * @param \Ivory\GoogleMap\Services\Base\Distance $distance The element distance. - * @param \Ivory\GoogleMap\Services\Base\Duration $duration The element duration. - * @param string $status The element status. + * @param string $status The status. + * @param \Ivory\GoogleMap\Services\Base\Distance $distance The distance. + * @param \Ivory\GoogleMap\Services\Base\Duration $duration The duration. */ public function __construct($status, Distance $distance = null, Duration $duration = null) { $this->setStatus($status); - - if ($distance !== null) { - $this->setDistance($distance); - } - - if ($duration !== null) { - $this->setDuration($duration); - } + $this->setDistance($distance); + $this->setDuration($duration); } /** - * Gets the distance matrix response status. + * Gets the status. * - * @return string The distance matrix response status. + * @return string The status. */ public function getStatus() { @@ -64,25 +56,29 @@ public function getStatus() } /** - * Sets the distance matrix response status. + * Sets the status. * - * @param string $status The distance matrix status. - * - * @throws \Ivory\GoogleMap\Exception\DistanceMatrixException If the status is not valid. + * @param string $status The status. */ public function setStatus($status) { - if (!in_array($status, DistanceMatrixElementStatus::getDistanceMatrixElementStatus())) { - throw DistanceMatrixException::invalidDistanceMatrixResponseElementStatus(); - } - $this->status = $status; } /** - * Gets the step distance. + * Checks if there is a distance. + * + * @return boolean TRUe if there is a distance else FALSE. + */ + public function hasDistance() + { + return $this->distance !== null; + } + + /** + * Gets the distance. * - * @return \Ivory\GoogleMap\Services\Base\Distance The step distance. + * @return \Ivory\GoogleMap\Services\Base\Distance|null The distance. */ public function getDistance() { @@ -90,19 +86,29 @@ public function getDistance() } /** - * Sets the step distance. + * Sets the distance. * - * @param \Ivory\GoogleMap\Services\Base\Distance $distance The step distance. + * @param \Ivory\GoogleMap\Services\Base\Distance|null $distance The distance. */ - public function setDistance(Distance $distance) + public function setDistance(Distance $distance = null) { $this->distance = $distance; } /** - * Gets the step duration. + * Checks if there is a duration. + * + * @return boolean TRUE if there is a duration else FALSE. + */ + public function hasDuration() + { + return $this->duration !== null; + } + + /** + * Gets the duration. * - * @return \Ivory\GoogleMap\Services\Base\Duration The step duration. + * @return \Ivory\GoogleMap\Services\Base\Duration|null The duration. */ public function getDuration() { @@ -110,11 +116,11 @@ public function getDuration() } /** - * Sets the step duration + * Sets the duration. * - * @param \Ivory\GoogleMap\Services\Base\Duration $duration The step duration. + * @param \Ivory\GoogleMap\Services\Base\Duration|null $duration The duration. */ - public function setDuration(Duration $duration) + public function setDuration(Duration $duration = null) { $this->duration = $duration; } diff --git a/src/Services/DistanceMatrix/DistanceMatrixResponseRow.php b/src/Services/DistanceMatrix/DistanceMatrixResponseRow.php index 1f813931..e479399f 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixResponseRow.php +++ b/src/Services/DistanceMatrix/DistanceMatrixResponseRow.php @@ -12,10 +12,10 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; /** - * A distance matrix response wraps the distance results & the response status. + * Distance matrix response row. * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixResponseRow * @author GeLo - * @author Tyler Sommer */ class DistanceMatrixResponseRow { @@ -23,9 +23,9 @@ class DistanceMatrixResponseRow protected $elements; /** - * Create a distance matrix response row. + * Creates a distance matrix response row. * - * @param array $elements The row elements. + * @param array $elements The elements. */ public function __construct(array $elements) { @@ -33,9 +33,27 @@ public function __construct(array $elements) } /** - * Gets the distance matrix row elements. + * Resets the elements. + */ + public function resetElements() + { + $this->elements = array(); + } + + /** + * Checks if there are elements. + * + * @return boolean TRUE if there are elements else FALSE. + */ + public function hasElements() + { + return !empty($this->elements); + } + + /** + * Gets the elements. * - * @return array The row elements. + * @return array The elements. */ public function getElements() { @@ -43,26 +61,71 @@ public function getElements() } /** - * Sets the distance matrix row elements. + * Sets the elements. * - * @param array $elements The row elements. + * @param array $elements The elements. */ public function setElements(array $elements) { - $this->elements = array(); + $this->resetElements(); + $this->addElements($elements); + } + /** + * Adds the elements. + * + * @param array $elements The elements. + */ + public function addElements(array $elements) + { foreach ($elements as $element) { $this->addElement($element); } } /** - * Add a distance matrix element. + * Removes the elements. + * + * @param array $elements The elements. + */ + public function removeElements(array $elements) + { + foreach ($elements as $element) { + $this->removeElement($element); + } + } + + /** + * Checks if there is an element. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element. + * + * @return boolean TRUE if there is the element else FALSE. + */ + public function hasElement(DistanceMatrixResponseElement $element) + { + return in_array($element, $this->elements, true); + } + + /** + * Adds an element. * - * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element to add. + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element. */ public function addElement(DistanceMatrixResponseElement $element) { - $this->elements[] = $element; + if (!$this->hasElement($element)) { + $this->elements[] = $element; + } + } + + /** + * Removes an element. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element. + */ + public function removeElement(DistanceMatrixResponseElement $element) + { + unset($this->elements[array_search($element, $this->elements, true)]); } } diff --git a/src/Services/DistanceMatrix/DistanceMatrixStatus.php b/src/Services/DistanceMatrix/DistanceMatrixStatus.php index fdb0fb27..f421dc0c 100644 --- a/src/Services/DistanceMatrix/DistanceMatrixStatus.php +++ b/src/Services/DistanceMatrix/DistanceMatrixStatus.php @@ -11,14 +11,15 @@ namespace Ivory\GoogleMap\Services\DistanceMatrix; +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + /** - * A distance matrix status which describes the google map distance matrix status. + * Distance matrix status. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixStatus + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#DistanceMatrixStatus * @author GeLo - * @author Tyler Sommer */ -class DistanceMatrixStatus +class DistanceMatrixStatus extends AbstractUninstantiableAsset { const INVALID_REQUEST = 'INVALID_REQUEST'; const MAX_DIMENSIONS_EXCEEDED = 'MAX_DIMENSIONS_EXCEEDED'; @@ -27,32 +28,4 @@ class DistanceMatrixStatus const OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; const REQUEST_DENIED = 'REQUEST_DENIED'; const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available distance matrix status. - * - * @return array The available distance matrix status. - */ - public static function getDistanceMatrixStatus() - { - return array( - self::INVALID_REQUEST, - self::MAX_DIMENSIONS_EXCEEDED, - self::MAX_ELEMENTS_EXCEEDED, - self::OK, - self::OVER_QUERY_LIMIT, - self::REQUEST_DENIED, - self::UNKNOWN_ERROR, - ); - } } diff --git a/src/Services/Geocoding/Geocoder.php b/src/Services/Geocoding/Geocoder.php index 87014aea..d894e3ed 100644 --- a/src/Services/Geocoding/Geocoder.php +++ b/src/Services/Geocoding/Geocoder.php @@ -14,9 +14,9 @@ use Geocoder\Geocoder as BaseGeocoder; /** - * Geocoder which describes a google map geocoder. + * Geocoder. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#Geocoder + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#Geocoder * @author GeLo */ class Geocoder extends BaseGeocoder diff --git a/src/Services/Geocoding/GeocoderAddressComponent.php b/src/Services/Geocoding/GeocoderAddressComponent.php new file mode 100644 index 00000000..85b28019 --- /dev/null +++ b/src/Services/Geocoding/GeocoderAddressComponent.php @@ -0,0 +1,181 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Services\Geocoding; + +/** + * Geocoder address component. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderAddressComponent + * @author GeLo + */ +class GeocoderAddressComponent +{ + /** @var string */ + protected $longName; + + /** @var string */ + protected $shortName; + + /** @var array */ + protected $types; + + /** + * Creates a geocoder address component. + * + * @param string $longName The long name. + * @param string $shortName The short name. + * @param array $types The types. + */ + public function __construct($longName, $shortName, array $types) + { + $this->setLongName($longName); + $this->setShortName($shortName); + $this->setTypes($types); + } + + /** + * Gets the long name. + * + * @return string The long name. + */ + public function getLongName() + { + return $this->longName; + } + + /** + * Sets the long name. + * + * @param string $longName The long name. + */ + public function setLongName($longName) + { + $this->longName = $longName; + } + + /** + * Gets the short name. + * + * @return string The short name. + */ + public function getShortName() + { + return $this->shortName; + } + + /** + * Sets the short name. + * + * @param string $shortName The short name. + */ + public function setShortName($shortName) + { + $this->shortName = $shortName; + } + + /** + * Resets the types. + */ + public function resetTypes() + { + $this->types = array(); + } + + /** + * Checks if there are types. + * + * @return boolean TRUE if there are types else FALSE. + */ + public function hasTypes() + { + return !empty($this->types); + } + + /** + * Gets the types. + * + * @return array The types. + */ + public function getTypes() + { + return $this->types; + } + + /** + * Sets the types. + * + * @param array $types The types. + */ + public function setTypes(array $types) + { + $this->resetTypes(); + $this->addTypes($types); + } + + /** + * Adds the types. + * + * @param array $types The types. + */ + public function addTypes(array $types) + { + foreach ($types as $type) { + $this->addType($type); + } + } + + /** + * Removes the types. + * + * @param array $types The types. + */ + public function removeTypes(array $types) + { + foreach ($types as $type) { + $this->removeType($type); + } + } + + /** + * Checks if there is a type. + * + * @param string $type The type. + * + * @return boolean TRUE if there is the type else FALSE. + */ + public function hasType($type) + { + return in_array($type, $this->types, true); + } + + /** + * Adds a type. + * + * @param string $type The type. + */ + public function addType($type) + { + if (!$this->hasType($type)) { + $this->types[] = $type; + } + } + + /** + * Removes a type. + * + * @param string $type The type. + */ + public function removeType($type) + { + unset($this->types[array_search($type, $this->types, true)]); + } +} diff --git a/src/Services/Geocoding/Result/GeocoderGeometry.php b/src/Services/Geocoding/GeocoderGeometry.php similarity index 56% rename from src/Services/Geocoding/Result/GeocoderGeometry.php rename to src/Services/Geocoding/GeocoderGeometry.php index 628f195d..ab08fc85 100644 --- a/src/Services/Geocoding/Result/GeocoderGeometry.php +++ b/src/Services/Geocoding/GeocoderGeometry.php @@ -9,16 +9,15 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Services\Geocoding\Result; +namespace Ivory\GoogleMap\Services\Geocoding; use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\GeocodingException; /** - * GeocoderGeometry which describes a google map geocoder geometry. + * Geocoder geometry. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderGeometry + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderGeometry * @author GeLo */ class GeocoderGeometry @@ -32,16 +31,16 @@ class GeocoderGeometry /** @var \Ivory\GoogleMap\Base\Bound */ protected $viewport; - /** @var \Ivory\GoogleMap\Base\Bound */ + /** @var \Ivory\GoogleMap\Base\Bound|null */ protected $bound; /** - * Create a geocoder geometry. + * Creates a geocoder geometry. * - * @param \Ivory\GoogleMap\Base\Coordinate $location The geometry location. - * @param string $locationType The geometry location type. - * @param \Ivory\GoogleMap\Base\Bound $viewport The geometry viewport. - * @param \Ivory\GoogleMap\Base\Bound $bound The geometry bound. + * @param \Ivory\GoogleMap\Base\Coordinate $location The location. + * @param string $locationType The location type. + * @param \Ivory\GoogleMap\Base\Bound $viewport The viewport. + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. */ public function __construct(Coordinate $location, $locationType, Bound $viewport, Bound $bound = null) { @@ -52,9 +51,9 @@ public function __construct(Coordinate $location, $locationType, Bound $viewport } /** - * Gets the geometry location. + * Gets the location. * - * @return \Ivory\GoogleMap\Base\Coordinate The geometry location. + * @return \Ivory\GoogleMap\Base\Coordinate The location. */ public function getLocation() { @@ -62,9 +61,9 @@ public function getLocation() } /** - * Sets the geometry location. + * Sets the location. * - * @param \Ivory\GoogleMap\Base\Coordinate $location The geometry location. + * @param \Ivory\GoogleMap\Base\Coordinate $location The location. */ public function setLocation(Coordinate $location) { @@ -72,9 +71,9 @@ public function setLocation(Coordinate $location) } /** - * Gets the geometry location type. + * Gets the location type. * - * @return string The geometry location type. + * @return string The location type. */ public function getLocationType() { @@ -82,25 +81,19 @@ public function getLocationType() } /** - * Sets the geometry location type. - * - * @param string $locationType The geometry location type. + * Sets the location type. * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the location type is not valid. + * @param string $locationType The location type. */ public function setLocationType($locationType) { - if (!in_array($locationType, GeocoderLocationType::getGeocoderLocationTypes())) { - throw GeocodingException::invalidGeocoderLocationType(); - } - $this->locationType = $locationType; } /** - * Gets the geometry viewport + * Gets the viewport. * - * @return \Ivory\GoogleMap\Base\Bound The geometry viewport. + * @return \Ivory\GoogleMap\Base\Bound The viewport. */ public function getViewport() { @@ -108,9 +101,9 @@ public function getViewport() } /** - * Sets the geometry viewport. + * Sets the viewport. * - * @param \Ivory\GoogleMap\Base\Bound $viewport The geometry viewport. + * @param \Ivory\GoogleMap\Base\Bound $viewport The viewport. */ public function setViewport(Bound $viewport) { @@ -118,9 +111,19 @@ public function setViewport(Bound $viewport) } /** - * Gets the geometry bound. + * Checks if there is a bound. + * + * @return boolean TRUE if there is a bound else FALSE. + */ + public function hasBound() + { + return $this->bound !== null; + } + + /** + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The geometry bound. + * @return \Ivory\GoogleMap\Base\Bound|null The bound. */ public function getBound() { @@ -128,9 +131,9 @@ public function getBound() } /** - * Sets the geometry bound. + * Sets the bound. * - * @param \Ivory\GoogleMap\Base\Bound $bound The geometry bound. + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. */ public function setBound(Bound $bound = null) { diff --git a/src/Services/Geocoding/GeocoderLocationType.php b/src/Services/Geocoding/GeocoderLocationType.php new file mode 100644 index 00000000..02dbdeb1 --- /dev/null +++ b/src/Services/Geocoding/GeocoderLocationType.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Geocoder location type. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderLocationType + * @author GeLo + */ +class GeocoderLocationType extends AbstractUninstantiableAsset +{ + const APPROXIMATE = 'APPROXIMATE'; + const GEOMETRIC_CENTER = 'GEOMETRIC_CENTER'; + const RANGE_INTERPOLATED = 'RANGE_INTERPOLATED'; + const ROOFTOP = 'ROOFTOP'; +} diff --git a/src/Services/Geocoding/GeocoderProvider.php b/src/Services/Geocoding/GeocoderProvider.php index 36e9b32b..ed9a6d00 100644 --- a/src/Services/Geocoding/GeocoderProvider.php +++ b/src/Services/Geocoding/GeocoderProvider.php @@ -11,216 +11,51 @@ namespace Ivory\GoogleMap\Services\Geocoding; -use Geocoder\HttpAdapter\HttpAdapterInterface; -use Geocoder\Provider\AbstractProvider; use Geocoder\Provider\ProviderInterface; use Ivory\GoogleMap\Base\Bound; use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\GeocodingException; +use Ivory\GoogleMap\Services\AbstractService; use Ivory\GoogleMap\Services\BusinessAccount; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult; use Ivory\GoogleMap\Services\Utils\XmlParser; +use Ivory\HttpAdapter\HttpAdapterInterface; /** * Geocoder provider. * * @author GeLo */ -class GeocoderProvider extends AbstractProvider implements ProviderInterface +class GeocoderProvider extends AbstractService implements ProviderInterface { - /** @var string */ - protected $url; - - /** @var boolean */ - protected $https; - - /** @var string */ - protected $format; - - /** @var \Ivory\GoogleMap\Services\Utils\XmlParser */ - protected $xmlParser; - - /** @var \Ivory\GoogleMap\Services\BusinessAccount */ - protected $businessAccount; - /** * {@inheritdoc} */ - public function __construct(HttpAdapterInterface $adapter, $locale = null) - { - parent::__construct($adapter, $locale); - - $this->setUrl('http://maps.googleapis.com/maps/api/geocode'); - $this->setHttps(false); - $this->setFormat('json'); - $this->setXmlParser(new XmlParser()); - } - - /** - * Gets the service url according to the https flag. - * - * @return string The service url. - */ - public function getUrl() - { - if ($this->isHttps()) { - return str_replace('http://', 'https://', $this->url); - } - - return $this->url; - } - - /** - * Sets the service url. - * - * @param string $url The service url. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the url is not valid. - */ - public function setUrl($url) - { - if (!is_string($url)) { - throw GeocodingException::invalidGeocoderProviderUrl(); - } - - $this->url = $url; - } - - /** - * Checks if the service uses HTTPS. - * - * @return boolean TRUE if the service uses HTTPS else FALSE. - */ - public function isHttps() - { - return $this->https; - } - - /** - * Sets the service HTTPS flag. - * - * @param boolean $https TRUE if the service uses HTTPS else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the https flag is not valid. - */ - public function setHttps($https) - { - if (!is_bool($https)) { - throw GeocodingException::invalidGeocoderProviderHttps(); - } - - $this->https = $https; - } - - /** - * Gets the service format. - * - * @return string The service format. - */ - public function getFormat() - { - return $this->format; - } - - /** - * Sets the service format. - * - * @param string $format The service format. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the format is not valid. - */ - public function setFormat($format) - { - if (($format !== 'json') && ($format !== 'xml')) { - throw GeocodingException::invalidGeocoderProviderFormat(); - } - - $this->format = $format; - } - - /** - * Gets the xml parser. - * - * @return \Ivory\GoogleMap\Services\Utils\XmlParser The xml parser. - */ - public function getXmlParser() - { - return $this->xmlParser; - } - - /** - * Sets the xml parser. - * - * @param \Ivory\GoogleMap\Services\Geocoding\XmlParser $xmlParser The xml parser. - */ - public function setXmlParser(XmlParser $xmlParser) - { - $this->xmlParser = $xmlParser; - } - - /** - * Checks if the geocoder provider has a business account. - * - * @return boolean TRUE if the geocoder provider has a business account else FALSE. - */ - public function hasBusinessAccount() - { - return $this->businessAccount !== null; - } - - /** - * Gets the business account. - * - * @return \Ivory\GoogleMap\Services\BusinessAccount The business account. - */ - public function getBusinessAccount() - { - return $this->businessAccount; + public function __construct( + HttpAdapterInterface $httpAdapter, + $url = 'http://maps.googleapis.com/maps/api/geocode', + $https = false, + $format = self::FORMAT_JSON, + XmlParser $xmlParser = null, + BusinessAccount $businessAccount = null + ) { + parent::__construct($httpAdapter, $url, $https, $format, $xmlParser, $businessAccount); } /** - * Sets the business account. - * - * @param \Ivory\GoogleMap\Services\BusinessAccount $businessAccount The business account. + * {@inheritdoc} */ - public function setBusinessAccount(BusinessAccount $businessAccount = null) + public function setMaxResults($maxResults) { - $this->businessAccount = $businessAccount; + return $this; } /** * {@inheritdoc} - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the request is not valid. */ - public function getGeocodedData($request) + public function getGeocodedData($geocoderRequest) { - if (is_string($request)) { - $geocoderRequest = new GeocoderRequest(); - $geocoderRequest->setAddress($request); - } elseif ($request instanceof GeocoderRequest) { - $geocoderRequest = $request; - } else { - throw GeocodingException::invalidGeocoderProviderRequestArguments(); - } - - if (!$geocoderRequest->isValid()) { - throw GeocodingException::invalidGeocoderProviderRequest(); - } - - $url = $this->generateUrl($geocoderRequest); - $response = $this->getAdapter()->getContent($url); - - if ($response === null) { - throw GeocodingException::invalidServiceResult(); - } - - $normalizedResponse = $this->parse($response); - - return $this->buildGeocoderResponse($normalizedResponse); + return $this->buildResponse($this->parse( + (string) $this->httpAdapter->get($this->generateUrl($geocoderRequest))->getBody() + )); } /** @@ -228,10 +63,7 @@ public function getGeocodedData($request) */ public function getReversedData(array $coordinates) { - $request = new GeocoderRequest(); - $request->setCoordinate($coordinates[0], $coordinates[1]); - - return $this->getGeocodedData($request); + return $this->getGeocodedData(new GeocoderRequest(new Coordinate($coordinates[0], $coordinates[1]))); } /** @@ -243,214 +75,190 @@ public function getName() } /** - * Generates geocoding URL according to the request. + * Generates the url. * - * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderRequest $geocoderRequest The geocoder request. + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderRequest $request The request. * - * @return string The generated URL. + * @return string The generated url. */ - protected function generateUrl(GeocoderRequest $geocoderRequest) + protected function generateUrl(GeocoderRequest $request) { $httpQuery = array(); - if ($geocoderRequest->hasAddress()) { - $httpQuery['address'] = $geocoderRequest->getAddress(); + $location = $request->getLocation(); + + if ($location instanceof Coordinate) { + $httpQuery['latlng'] = $location->getLatitude().','.$location->getLongitude(); } else { - $httpQuery['latlng'] = sprintf( - '%s,%s', - $geocoderRequest->getCoordinate()->getLatitude(), - $geocoderRequest->getCoordinate()->getLongitude() - ); + $httpQuery['address'] = $location; } - if ($geocoderRequest->hasBound()) { - $httpQuery['bound'] = sprintf( - '%s,%s|%s,%s', - $geocoderRequest->getBound()->getSouthWest()->getLatitude(), - $geocoderRequest->getBound()->getSouthWest()->getLongitude(), - $geocoderRequest->getBound()->getNorthEast()->getLatitude(), - $geocoderRequest->getBound()->getNorthEast()->getLongitude() - ); + if ($request->hasBound()) { + $httpQuery['bound'] = $request->getBound()->getSouthWest()->getLatitude().',' + .$request->getBound()->getSouthWest()->getLongitude().'|' + .$request->getBound()->getNorthEast()->getLatitude().',' + .$request->getBound()->getNorthEast()->getLongitude(); } - if ($geocoderRequest->hasRegion()) { - $httpQuery['region'] = $geocoderRequest->getRegion(); + if ($request->hasRegion()) { + $httpQuery['region'] = $request->getRegion(); } - if ($geocoderRequest->hasLanguage()) { - $httpQuery['language'] = $geocoderRequest->getLanguage(); + if ($request->hasLanguage()) { + $httpQuery['language'] = $request->getLanguage(); } - $httpQuery['sensor'] = $geocoderRequest->hasSensor() ? 'true' : 'false'; - - $url = sprintf('%s/%s?%s', $this->getUrl(), $this->getFormat(), http_build_query($httpQuery)); + $httpQuery['sensor'] = $request->hasSensor() ? 'true' : 'false'; - return $this->signUrl($url); + return $this->signUrl($this->getUrl().'/'.$this->getFormat().'?'.http_build_query($httpQuery)); } /** - * Sign an url for business account. + * Parses the body. * - * @param string $url The url. + * @param string $body The body. * - * @return string The signed url. + * @return array The parsed body. */ - protected function signUrl($url) + protected function parse($body) { - if (!$this->hasBusinessAccount()) { - return $url; - } - - return $this->businessAccount->signUrl($url); + return $this->format == self::FORMAT_JSON ? $this->parseJson($body) : $this->parseXml($body); } /** - * Parses & normalizes the geocoding result response. + * Parses a json body. * - * @param string $response The response. + * @param string $body The body. * - * @return \stdClass The parsed & normalized response. + * @return array The parsed body. */ - protected function parse($response) + protected function parseJson($body) { - if ($this->format == 'json') { - return $this->parseJSON($response); - } - - return $this->parseXML($response); + return json_decode($body, true); } /** - * Parses & normalizes a JSON geocoding result response. + * Parses an xml body. * - * @param string $response The response. + * @param string $body The body. * - * @return \stdClass The parsed & normalized response. + * @return array The parsed body. */ - protected function parseJSON($response) + protected function parseXml($body) { - return json_decode($response); + return $this->xmlParser->parse( + $body, + array( + 'address_component' => 'address_components', + 'type' => 'types', + 'result' => 'results', + ) + ); } /** - * Parses & normalizes an XML geocoding result response. + * Builds the response. * - * @param string $response The response. + * @param array $response The response. * - * @return \stdClass The parsed & normalized response. + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderResponse The built response. */ - protected function parseXML($response) + protected function buildResponse(array $response) { - $rules = array( - 'address_component' => 'address_components', - 'type' => 'types', - 'result' => 'results', - ); - - return $this->xmlParser->parse($response, $rules); + return new GeocoderResponse($this->buildResults($response['results']), $response['status']); } /** - * Builds the geocoder results accordint to a normalized geocoding results. + * Builds the results. * - * @param \stdClass $geocoderResponse The normalized geocder response. + * @param array $results The results. * - * @return \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse The builded geocoder response. + * @return array The buildt results. */ - protected function buildGeocoderResponse(\stdClass $geocoderResponse) + protected function buildResults(array $results) { - $results = array(); - foreach ($geocoderResponse->results as $geocoderResult) { - $results[] = $this->buildGeocoderResult($geocoderResult); + $build = array(); + foreach ($results as $result) { + $build[] = $this->buildResult($result); } - $status = $geocoderResponse->status; - - return new GeocoderResponse($results, $status); + return $build; } /** - * Builds a geocoder result according to a normalized geocoding result. + * Builds a result. * - * @param \stdClass $geocoderResult The normalized geocoder result. + * @param array $result The result. * - * @return \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult The builded geocoder result. + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderResult The built result. */ - protected function buildGeocoderResult(\stdClass $geocoderResult) + protected function buildResult(array $result) { - $addressComponents = $this->buildGeocoderAddressComponents($geocoderResult->address_components); - $formattedAddress = $geocoderResult->formatted_address; - $geometry = $this->buildGeocoderGeometry($geocoderResult->geometry); - $types = $geocoderResult->types; - $partialMatch = isset($geocoderResult->partial_match) ? $geocoderResult->partial_match : null; - - return new GeocoderResult($addressComponents, $formattedAddress, $geometry, $types, $partialMatch); + return new GeocoderResult( + $this->buildAddressComponents($result['address_components']), + $result['formatted_address'], + $this->buildGeometry($result['geometry']), + $result['types'], + isset($result['partial_match']) ? $result['partial_match'] : null + ); } /** - * Builds the gecoder address components according to a normalized geocoding address components. + * Builds the address components. * - * @param array $geocoderAddressComponents The normalized geocoder address components. + * @param array $addressComponents The address components. * - * @return array The builded geocoder address components. + * @return array The built address components. */ - protected function buildGeocoderAddressComponents(array $geocoderAddressComponents) + protected function buildAddressComponents(array $addressComponents) { - $results = array(); - - foreach ($geocoderAddressComponents as $geocoderAddressComponent) { - $results[] = $this->buildGeocoderAddressComponent($geocoderAddressComponent); + $build = array(); + foreach ($addressComponents as $addressComponent) { + $build[] = $this->buildAddressComponent($addressComponent); } - return $results; + return $build; } /** - * Builds a geocoder address component according to a normalized geocoding address component. + * Builds an address component. * - * @param \stdClass $geocoderAddressComponent The normalized geocoder address component. + * @param array $addressComponent The address component. * - * @return \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent The builded geocoder address - * component. + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent The built address component. */ - protected function buildGeocoderAddressComponent(\stdClass $geocoderAddressComponent) + protected function buildAddressComponent(array $addressComponent) { - $longName = $geocoderAddressComponent->long_name; - $shortName = $geocoderAddressComponent->short_name; - $types = $geocoderAddressComponent->types; - - return new GeocoderAddressComponent($longName, $shortName, $types); + return new GeocoderAddressComponent( + $addressComponent['long_name'], + $addressComponent['short_name'], + $addressComponent['types'] + ); } /** - * Builds a geocoder geometry according to a normalized geocoding geometry. + * Builds a geometry. * - * @param \stdClass $geocoderGeometry The normalized geocoder geomety. + * @param array $geometry The geomety. * - * @return \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry The builded geocoder geometry. + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry The built geometry. */ - protected function buildGeocoderGeometry(\stdClass $geocoderGeometry) + protected function buildGeometry(array $geometry) { - $location = new Coordinate( - $geocoderGeometry->location->lat, - $geocoderGeometry->location->lng - ); - - $locationType = $geocoderGeometry->location_type; - - $viewport = new Bound( - new Coordinate($geocoderGeometry->viewport->southwest->lat, $geocoderGeometry->viewport->southwest->lng), - new Coordinate($geocoderGeometry->viewport->northeast->lat, $geocoderGeometry->viewport->northeast->lng) + return new GeocoderGeometry( + new Coordinate( + $geometry['location']['lat'], + $geometry['location']['lng'] + ), + $geometry['location_type'], + new Bound( + new Coordinate($geometry['viewport']['southwest']['lat'], $geometry['viewport']['southwest']['lng']), + new Coordinate($geometry['viewport']['northeast']['lat'], $geometry['viewport']['northeast']['lng']) + ), + isset($geometry['bounds']) ? new Bound( + new Coordinate($geometry['bounds']['southwest']['lat'], $geometry['bounds']['southwest']['lng']), + new Coordinate($geometry['bounds']['northeast']['lat'], $geometry['bounds']['northeast']['lng']) + ) : null ); - - $bound = null; - if (isset($geocoderGeometry->bounds)) { - $bound = new Bound( - new Coordinate($geocoderGeometry->bounds->southwest->lat, $geocoderGeometry->bounds->southwest->lng), - new Coordinate($geocoderGeometry->bounds->northeast->lat, $geocoderGeometry->bounds->northeast->lng) - ); - } - - return new GeocoderGeometry($location, $locationType, $viewport, $bound); } } diff --git a/src/Services/Geocoding/GeocoderRequest.php b/src/Services/Geocoding/GeocoderRequest.php index 04587261..5258dda9 100644 --- a/src/Services/Geocoding/GeocoderRequest.php +++ b/src/Services/Geocoding/GeocoderRequest.php @@ -12,138 +12,64 @@ namespace Ivory\GoogleMap\Services\Geocoding; use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Exception\GeocodingException; /** - * Geocoder request which describes a google map geocoder request. + * Geocoder request. * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest * @author GeLo */ class GeocoderRequest { - /** @var string */ - protected $address; + /** @var string|\Ivory\GoogleMap\Base\Coordinate */ + protected $location; - /** @var \Ivory\GoogleMap\Base\Coordinate */ - protected $coordinate; - - /** @var \Ivory\GoogleMap\Base\Bound */ + /** @var \Ivory\GoogleMap\Base\Bound|null */ protected $bound; - /** @var string */ + /** @var string|null */ protected $region; - /** @var string */ + /** @var string|null */ protected $language; /** @var boolean */ - protected $sensor; + protected $sensor = false; /** * Creates a geocoder request. - */ - public function __construct() - { - $this->sensor = false; - } - - /** - * Checks if the geocoder request has an address. * - * @return boolean TRUE if the geocoder request has an address else FALSE. + * @param string|\Ivory\GoogleMap\Base\Coordinate $location The location. */ - public function hasAddress() + public function __construct($location) { - return $this->address !== null; + $this->setLocation($location); } /** - * Gets the geocoder request address. + * Gets the location. * - * @return string The geocoder request address. + * @return string|\Ivory\GoogleMap\Base\Coordinate The location. */ - public function getAddress() + public function getLocation() { - return $this->address; + return $this->location; } /** - * Sets the geocoder request address. - * - * @param string $address The geocoder request address. + * Sets the location. * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the address is not valid. + * @param string|\Ivory\GoogleMap\Base\Coordinate $location The location. */ - public function setAddress($address) + public function setLocation($location) { - if (!is_string($address) && ($address !== null)) { - throw GeocodingException::invalidGeocoderRequestAddress(); - } - - $this->address = $address; + $this->location = $location; } /** - * Checks if the geocoder request has a coordinate. + * Checks if it has a bound. * - * @return boolean TRUE if the geocoder request has a coordinate else FALSE. - */ - public function hasCoordinate() - { - return $this->coordinate !== null; - } - - /** - * Gets the geocoder request coordinate. - * - * @return \Ivory\GoogleMap\Base\Coordinate The geocoder request coordinate. - */ - public function getCoordinate() - { - return $this->coordinate; - } - - /** - * Sets the geocoder request coordinate - * - * Available prototypes: - * - function setCoordinate(\Ivory\GoogleMap\Base\Coordinate $coordinate = null) - * - function setCoordinate(double $latitude, double $longitude, boolean $noWrap = true) - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the coordinate is not valid (prototypes). - */ - public function setCoordinate() - { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Coordinate)) { - $this->coordinate = $args[0]; - } elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) { - if (!$this->hasCoordinate()) { - $this->coordinate = new Coordinate(); - } - - $this->coordinate->setLatitude($args[0]); - $this->coordinate->setLongitude($args[1]); - - if (isset($args[2]) && is_bool($args[2])) { - $this->coordinate->setNoWrap($args[2]); - } - } elseif (!isset($args[0])) { - $this->coordinate = null; - } else { - throw GeocodingException::invalidGeocoderRequestCoordinate(); - } - - return $this; - } - - /** - * Checks if the geocoder request has a bound. - * - * @return boolean TRUE if the geocoder request has a bound else FALSE. + * @return boolean TRUE if it has a bound else FALSE. */ public function hasBound() { @@ -151,9 +77,9 @@ public function hasBound() } /** - * Gets the geocoder request bound. + * Gets the bound. * - * @return \Ivory\GoogleMap\Base\Bound The geocoder request bound. + * @return \Ivory\GoogleMap\Base\Bound|null The bound. */ public function getBound() { @@ -161,67 +87,19 @@ public function getBound() } /** - * Sets the geocoder request bound. + * Sets the bound. * - * Available prototypes: - * - function setBound(Ivory\GoogleMap\Base\Bound $bound = null) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the bound is not valid. + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. */ - public function setBound() + public function setBound(Bound $bound = null) { - $args = func_get_args(); - - if (isset($args[0]) && ($args[0] instanceof Bound)) { - $this->bound = $args[0]; - } elseif ((isset($args[0]) && ($args[0] instanceof Coordinate)) - && (isset($args[1]) && ($args[1] instanceof Coordinate)) - ) { - if (!$this->hasBound()) { - $this->bound = new Bound(); - } - - $this->bound->setSouthWest($args[0]); - $this->bound->setNorthEast($args[1]); - } elseif ((isset($args[0]) && is_numeric($args[0])) - && (isset($args[1]) && is_numeric($args[1])) - && (isset($args[2]) && is_numeric($args[2])) - && (isset($args[3]) && is_numeric($args[3])) - ) { - if (!$this->hasBound()) { - $this->bound = new Bound(); - } - - $this->bound->setSouthWest(new Coordinate($args[0], $args[1])); - $this->bound->setNorthEast(new Coordinate($args[2], $args[3])); - - if (isset($args[4]) && is_bool($args[4])) { - $this->bound->getSouthWest()->setNoWrap($args[4]); - } - - if (isset($args[5]) && is_bool($args[5])) { - $this->bound->getNorthEast()->setNoWrap($args[5]); - } - } elseif (!isset($args[0])) { - $this->bound = null; - } else { - throw GeocodingException::invalidGeocoderRequestBound(); - } + $this->bound = $bound; } /** - * Checks if the geocoder request has a region. + * Checks if it has a region. * - * @return boolean TRUE if the geocoder request has a region else FALSE. + * @return boolean TRUE if it has a region else FALSE. */ public function hasRegion() { @@ -229,9 +107,9 @@ public function hasRegion() } /** - * Gets the geocoder request region + * Gets the region. * - * @return string + * @return string|null The region. */ public function getRegion() { @@ -239,25 +117,19 @@ public function getRegion() } /** - * Sets the geocoder request region. + * Sets the region. * - * @param string $region The geocoder request region. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the regin is not valid. + * @param string|null $region The region. */ public function setRegion($region = null) { - if ((!is_string($region) || (strlen($region) !== 2)) && ($region !== null)) { - throw GeocodingException::invalidGeocoderRequestRegion(); - } - $this->region = $region; } /** - * Checks if the geocoder request has a language. + * Checks if it has a language. * - * @return boolean TRUE if the geocoder request has a language else FALSE. + * @return boolean TRUE if it has a language else FALSE. */ public function hasLanguage() { @@ -265,9 +137,9 @@ public function hasLanguage() } /** - * Gets the geocoder request language. + * Gets the language. * - * @return string The geocoder request language. + * @return string|null The language. */ public function getLanguage() { @@ -275,25 +147,19 @@ public function getLanguage() } /** - * Sets the geocoder request language. - * - * @param string $language The geocoder request language. + * Sets the language. * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the language is not valid. + * @param string|null $language The language. */ public function setLanguage($language = null) { - if ((!is_string($language) || ((strlen($language) !== 2) && (strlen($language) !== 5))) && ($language !== null)) { - throw GeocodingException::invalidGeocoderRequestLanguage(); - } - $this->language = $language; } /** - * Checks if the geocoder request has a sensor. + * Checks if it has a sensor. * - * @return boolean TRUE if the geocoder request has a sensor else FALSE. + * @return boolean TRUE if it has a sensor else FALSE. */ public function hasSensor() { @@ -301,28 +167,12 @@ public function hasSensor() } /** - * Sets the geocoder request sensor. - * - * @param boolean $sensor TRUE if the geocoder request has a sensor else FALSE. + * Sets the sensor. * - * @throws \Ivory\GoogleMap\Exception\GeocodingRequest If the sensor flag is not valid. + * @param boolean $sensor TRUE if it has a sensor else FALSE. */ public function setSensor($sensor) { - if (!is_bool($sensor)) { - throw GeocodingException::invalidGeocoderRequestSensor(); - } - $this->sensor = $sensor; } - - /** - * Checks if the geocoder request is valid. - * - * @return boolean TRUE if the geocoder request is valid else FALSE. - */ - public function isValid() - { - return $this->hasAddress() || $this->hasCoordinate(); - } } diff --git a/src/Services/Geocoding/GeocoderResponse.php b/src/Services/Geocoding/GeocoderResponse.php new file mode 100644 index 00000000..89d5b7f7 --- /dev/null +++ b/src/Services/Geocoding/GeocoderResponse.php @@ -0,0 +1,155 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Services\Geocoding; + +/** + * Geocoder response. + * + * @author GeLo + */ +class GeocoderResponse +{ + /** @var array */ + protected $results; + + /** @var string */ + protected $status; + + /** + * Creates a geocoder results. + * + * @param array $results The results. + * @param string $status The status. + */ + public function __construct(array $results, $status) + { + $this->setResults($results); + $this->setStatus($status); + } + + /** + * Resets the results. + */ + public function resetResults() + { + $this->results = array(); + } + + /** + * Checks if there are results. + * + * @return boolean TRUE if there are results else FALSE. + */ + public function hasResults() + { + return !empty($this->results); + } + + /** + * Gets the results. + * + * @return array The results. + */ + public function getResults() + { + return $this->results; + } + + /** + * Sets the results + * + * @param array $results The results. + */ + public function setResults(array $results) + { + $this->resetResults(); + $this->addResults($results); + } + + /** + * Adds the results + * + * @param array $results The results. + */ + public function addResults(array $results) + { + foreach ($results as $result) { + $this->addResult($result); + } + } + + /** + * Removes the results. + * + * @param array $results The results. + */ + public function removeResults(array $results) + { + foreach ($results as $result) { + $this->removeResult($result); + } + } + + /** + * Checks if there is a result. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderResult $result The result. + * + * @return boolean TRUE if there is a result else FALSE. + */ + public function hasResult(GeocoderResult $result) + { + return in_array($result, $this->results, true); + } + + /** + * Adds a result. + * + * @param \Ivory\GoogleMap\Services\GeocoderResult $result The result. + */ + public function addResult(GeocoderResult $result) + { + if (!$this->hasResult($result)) { + $this->results[] = $result; + } + } + + /** + * Removes a result. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderResult $result The result. + */ + public function removeResult(GeocoderResult $result) + { + unset($this->results[array_search($result, $this->results, true)]); + } + + /** + * Gets the status. + * + * @return string The status. + */ + public function getStatus() + { + return $this->status; + } + + /** + * Sets the status. + * + * @param string $status The status. + */ + public function setStatus($status) + { + $this->status = $status; + } +} diff --git a/src/Services/Geocoding/GeocoderResult.php b/src/Services/Geocoding/GeocoderResult.php new file mode 100644 index 00000000..a10c7c78 --- /dev/null +++ b/src/Services/Geocoding/GeocoderResult.php @@ -0,0 +1,323 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Services\Geocoding; + +/** + * Geocoder result. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderResult + * @author GeLo + */ +class GeocoderResult +{ + /** @var array */ + protected $addressComponents; + + /** @var string */ + protected $formattedAddress; + + /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry */ + protected $geometry; + + /** @var boolean */ + protected $partialMatch; + + /** @var array */ + protected $types; + + /** + * Create a gecoder result. + * + * @param array $addressComponents The address components. + * @param string $formattedAddress The formatted address. + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry $geometry The geometry. + * @param array $types The types. + * @param boolean $partialMatch The partial match flag. + */ + public function __construct( + array $addressComponents, + $formattedAddress, + GeocoderGeometry $geometry, + array $types, + $partialMatch = null + ) { + $this->setAddressComponents($addressComponents); + $this->setFormattedAddress($formattedAddress); + $this->setGeometry($geometry); + $this->setTypes($types); + $this->setPartialMatch($partialMatch); + } + + /** + * Resets the address components. + */ + public function resetAddressComponents() + { + $this->addressComponents = array(); + } + + /** + * Checks if there are address components. + * + * @return boolean TRUE if there are address components else FALSE. + */ + public function hasAddressComponents() + { + return !empty($this->addressComponents); + } + + /** + * Gets the address components. + * + * @return array The address components. + */ + public function getAddressComponents() + { + return $this->addressComponents; + } + + /** + * Sets the address components. + * + * @param array $addressComponents The address components. + */ + public function setAddressComponents(array $addressComponents) + { + $this->resetAddressComponents(); + $this->addAddressComponents($addressComponents); + } + + /** + * Adds the address components. + * + * @param array $addressComponents The address components. + */ + public function addAddressComponents(array $addressComponents) + { + foreach ($addressComponents as $addressComponent) { + $this->addAddressComponent($addressComponent); + } + } + + /** + * Removes the address components. + * + * @param array $addressComponents The address components. + */ + public function removeAddressComponents(array $addressComponents) + { + foreach ($addressComponents as $addressComponent) { + $this->removeAddressComponent($addressComponent); + } + } + + /** + * Checks if there is an address component. + * + * @param \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent $addressComponent The address component. + * + * @return boolean TRUE if there is an address component else FALSE. + */ + public function hasAddressComponent(GeocoderAddressComponent $addressComponent) + { + return in_array($addressComponent, $this->addressComponents, true); + } + + /** + * Adds an address component. + * + * @param \Ivory\GoogleMapBundle\Model\Services\GeocoderAddressComponent $addressComponent The address component. + */ + public function addAddressComponent(GeocoderAddressComponent $addressComponent) + { + if (!$this->hasAddressComponent($addressComponent)) { + $this->addressComponents[] = $addressComponent; + } + } + + /** + * Removes an address component. + * + * @param \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent $addressComponent The address component. + */ + public function removeAddressComponent(GeocoderAddressComponent $addressComponent) + { + unset($this->addressComponents[array_search($addressComponent, $this->addressComponents, true)]); + } + + /** + * Gets the formatted address. + * + * @return string The formatted address. + */ + public function getFormattedAddress() + { + return $this->formattedAddress; + } + + /** + * Sets the formatted address. + * + * @param string $formattedAddress The formatted address. + */ + public function setFormattedAddress($formattedAddress) + { + $this->formattedAddress = $formattedAddress; + } + + /** + * Gets the geometry. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry The geometry. + */ + public function getGeometry() + { + return $this->geometry; + } + + /** + * Sets the geometry. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry $geometry The geometry. + */ + public function setGeometry(GeocoderGeometry $geometry) + { + $this->geometry = $geometry; + } + + /** + * Checks if there is a partial match. + * + * @return boolean TRUE if there is a partial match else FALSE. + */ + public function hasPartialMatch() + { + return $this->partialMatch !== null; + } + + /** + * Checks if it is a partial match. + * + * @return boolean TRUE if it is a partial match else FALSE. + */ + public function isPartialMatch() + { + return $this->partialMatch; + } + + /** + * Sets if it is a partial match. + * + * @param boolean|null $partialMatch TRUE if it is a partial match else FALSE. + */ + public function setPartialMatch($partialMatch = null) + { + $this->partialMatch = $partialMatch; + } + + /** + * Resets the types. + */ + public function resetTypes() + { + $this->types = array(); + } + + /** + * Checks if there are types. + * + * @return boolean TRUe if there are types else FALSE. + */ + public function hasTypes() + { + return !empty($this->types); + } + + /** + * Gets the types. + * + * @return array The types. + */ + public function getTypes() + { + return $this->types; + } + + /** + * Sets the types. + * + * @param array $types The types. + */ + public function setTypes(array $types) + { + $this->resetTypes(); + $this->addTypes($types); + } + + /** + * Adds the types. + * + * @param array $types The types. + */ + public function addTypes(array $types) + { + foreach ($types as $type) { + $this->addType($type); + } + } + + /** + * Removes the types. + * + * @param array $types The types. + */ + public function removeTypes(array $types) + { + foreach ($types as $type) { + $this->removeType($type); + } + } + + /** + * Checks if there is a type. + * + * @param string $type The type. + * + * @return boolean TRUE if there is the type else FALSE. + */ + public function hasType($type) + { + return in_array($type, $this->types, true); + } + + /** + * Adds a type. + * + * @param string $type The type. + */ + public function addType($type) + { + if (!$this->hasType($type)) { + $this->types[] = $type; + } + } + + /** + * Removes a type. + * + * @param string $type The type. + */ + public function removeType($type) + { + unset($this->types[array_search($type, $this->types, true)]); + } +} diff --git a/src/Services/Geocoding/GeocoderStatus.php b/src/Services/Geocoding/GeocoderStatus.php new file mode 100644 index 00000000..160b558b --- /dev/null +++ b/src/Services/Geocoding/GeocoderStatus.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Assets\AbstractUninstantiableAsset; + +/** + * Geocoder status. + * + * @link http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderStatus + * @author GeLo + */ +class GeocoderStatus extends AbstractUninstantiableAsset +{ + const ERROR = 'ERROR'; + const INVALID_REQUEST = 'INVALID_REQUEST'; + const OK = 'OK'; + const OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; + const REQUEST_DENIED = 'REQUEST_DENIED'; + const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; + const ZERO_RESULTS = 'ZERO_RESULTS'; +} diff --git a/src/Services/Geocoding/Result/GeocoderAddressComponent.php b/src/Services/Geocoding/Result/GeocoderAddressComponent.php deleted file mode 100644 index 24a836ed..00000000 --- a/src/Services/Geocoding/Result/GeocoderAddressComponent.php +++ /dev/null @@ -1,138 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Exception\GeocodingException; - -/** - * GeocoderAddressComponent which describes a google map geocoder address component. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderAddressComponent - * @author GeLo - */ -class GeocoderAddressComponent -{ - /** @var string */ - protected $longName; - - /** @var string */ - protected $shortName; - - /** @var array */ - protected $types; - - /** - * Creates a geocoder address component. - * - * @param string $longName The long name. - * @param string $shortName The short name. - * @param array $types The types. - */ - public function __construct($longName, $shortName, array $types) - { - $this->setLongName($longName); - $this->setShortName($shortName); - $this->setTypes($types); - } - - /** - * Gets the address component long name. - * - * @return string The address component long name. - */ - public function getLongName() - { - return $this->longName; - } - - /** - * Sets the address component long name. - * - * @param string $longName The address componenet long name. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the long name is not valid. - */ - public function setLongName($longName) - { - if (!is_string($longName)) { - throw GeocodingException::invalidGeocoderAddressComponentLongName(); - } - - $this->longName = $longName; - } - - /** - * Gets the address component short name. - * - * @return string The address component short name. - */ - public function getShortName() - { - return $this->shortName; - } - - /** - * Sets the address component short name. - * - * @param string $shortName The address component short name. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the short name is not valid. - */ - public function setShortName($shortName) - { - if (!is_string($shortName)) { - throw GeocodingException::invalidGeocoderAddressComponentShortName(); - } - - $this->shortName = $shortName; - } - - /** - * Gets the address component types. - * - * @return array The address component types. - */ - public function getTypes() - { - return $this->types; - } - - /** - * Sets the address component types. - * - * @param array $types The address component types. - */ - public function setTypes(array $types) - { - $this->types = array(); - - foreach ($types as $type) { - $this->addType($type); - } - } - - /** - * Add an address component type. - * - * @param string $type The type to add. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the type is not valid. - */ - public function addType($type) - { - if (!is_string($type)) { - throw GeocodingException::invalidGeocoderAddressComponentType(); - } - - $this->types[] = $type; - } -} diff --git a/src/Services/Geocoding/Result/GeocoderLocationType.php b/src/Services/Geocoding/Result/GeocoderLocationType.php deleted file mode 100644 index 4b3d63e7..00000000 --- a/src/Services/Geocoding/Result/GeocoderLocationType.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Services\Geocoding\Result; - -/** - * GeocoderLocationType which describes a google map geocoder location type. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderLocationType - * @author GeLo - */ -class GeocoderLocationType -{ - const APPROXIMATE = 'APPROXIMATE'; - const GEOMETRIC_CENTER = 'GEOMETRIC_CENTER'; - const RANGE_INTERPOLATED = 'RANGE_INTERPOLATED'; - const ROOFTOP = 'ROOFTOP'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available geocoder location types. - * - * @return array The availabel geocoder location types. - */ - public static function getGeocoderLocationTypes() - { - return array( - self::APPROXIMATE, - self::GEOMETRIC_CENTER, - self::RANGE_INTERPOLATED, - self::ROOFTOP, - ); - } -} diff --git a/src/Services/Geocoding/Result/GeocoderResponse.php b/src/Services/Geocoding/Result/GeocoderResponse.php deleted file mode 100644 index 3e7e5d1f..00000000 --- a/src/Services/Geocoding/Result/GeocoderResponse.php +++ /dev/null @@ -1,100 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Exception\GeocodingException; - -/** - * A geocoder response wraps the geocoder results & the response status. - * - * @author GeLo - */ -class GeocoderResponse -{ - /** @var array */ - protected $results; - - /** @var string */ - protected $status; - - /** - * Create a geocoder results. - * - * @param array $results The geocoder results. - * @param string $status The geocoder status. - */ - public function __construct(array $results, $status) - { - $this->setResults($results); - $this->setStatus($status); - } - - /** - * Gets the geocoder results. - * - * @return array The geocoder results. - */ - public function getResults() - { - return $this->results; - } - - /** - * Sets the geocoder results - * - * @param array $results The geocoder results. - */ - public function setResults(array $results) - { - $this->results = array(); - - foreach ($results as $result) { - $this->addResult($result); - } - } - - /** - * Adds a geocoder result. - * - * @param \Ivory\GoogleMap\Services\Result\GeocoderResult $result The geocoder result to add. - */ - public function addResult(GeocoderResult $result) - { - $this->results[] = $result; - } - - /** - * Gets the geocoder results status. - * - * @return string The geocoder results status. - */ - public function getStatus() - { - return $this->status; - } - - /** - * Sets the geocoder results status. - * - * @param string $status The geocoder result status. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the status is not valid. - */ - public function setStatus($status) - { - if (!in_array($status, GeocoderStatus::getGeocoderStatus())) { - throw GeocodingException::invalidGeocoderResponseStatus(); - } - - $this->status = $status; - } -} diff --git a/src/Services/Geocoding/Result/GeocoderResult.php b/src/Services/Geocoding/Result/GeocoderResult.php deleted file mode 100644 index a1a5b5dd..00000000 --- a/src/Services/Geocoding/Result/GeocoderResult.php +++ /dev/null @@ -1,222 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Exception\GeocodingException; - -/** - * Geocoder result which describes a google map geocoder result. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderResult - * @author GeLo - */ -class GeocoderResult -{ - /** @var array */ - protected $addressComponents; - - /** @var string */ - protected $formattedAddress; - - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry */ - protected $geometry; - - /** @var boolean */ - protected $partialMatch; - - /** @var array */ - protected $types; - - /** - * Create a gecoder result. - * - * @param array $addressComponents The address components. - * @param string $formattedAddress The formatted address. - * @param \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry $geometry The geometry. - * @param array $types The types. - * @param boolean $partialMatch The partial match flag. - */ - public function __construct( - array $addressComponents, - $formattedAddress, - GeocoderGeometry $geometry, - array $types, - $partialMatch = null - ) { - $this->setAddressComponents($addressComponents); - $this->setFormattedAddress($formattedAddress); - $this->setGeometry($geometry); - $this->setTypes($types); - $this->setPartialMatch($partialMatch); - } - - /** - * Gets the address components. - * - * @param string|null The type of the address components. - * - * @return array The address components. - */ - public function getAddressComponents($type = null) - { - if ($type === null) { - return $this->addressComponents; - } - - $addressComponents = array(); - - foreach ($this->addressComponents as $addressComponent) { - if (in_array($type, $addressComponent->getTypes())) { - $addressComponents[] = $addressComponent; - } - } - - return $addressComponents; - } - - /** - * Sets address components. - * - * @param array $addressComponents The address components. - */ - public function setAddressComponents(array $addressComponents) - { - $this->addressComponents = array(); - - foreach ($addressComponents as $addressComponent) { - $this->addAddressComponent($addressComponent); - } - } - - /** - * Adds an address component to the geocoder result. - * - * @param \Ivory\GoogleMapBundle\Model\Services\Result\GeocoderAddressComponent $addressComponent The address - * component to add. - */ - public function addAddressComponent(GeocoderAddressComponent $addressComponent) - { - $this->addressComponents[] = $addressComponent; - } - - /** - * Gets the formatted address. - * - * @return string The formatted address. - */ - public function getFormattedAddress() - { - return $this->formattedAddress; - } - - /** - * Sets the formatted address. - * - * @param string $formattedAddress The formatted address. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the formatted address is not valid. - */ - public function setFormattedAddress($formattedAddress) - { - if (!is_string($formattedAddress)) { - throw GeocodingException::invalidGeocoderResultFormattedAddress(); - } - - $this->formattedAddress = $formattedAddress; - } - - /** - * Gets the geocoder result geometry. - * - * @return \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry The geocoder result geometry. - */ - public function getGeometry() - { - return $this->geometry; - } - - /** - * Sets the geocoder result geometry. - * - * @param \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry $geometry The geocoder result geometry. - */ - public function setGeometry(GeocoderGeometry $geometry) - { - $this->geometry = $geometry; - } - - /** - * Checks if the geocoder result is a partial match. - * - * @return boolean TRUE if the geocoder result is a partial match else FALSE. - */ - public function isPartialMatch() - { - return $this->partialMatch; - } - - /** - * Sets the geocoder result partial match flag. - * - * @param boolean $partialMatch TRUE if the geocoder result is a partial match else FALSE. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the partial match flag is not valid. - */ - public function setPartialMatch($partialMatch = null) - { - if (!is_bool($partialMatch) && ($partialMatch !== null)) { - throw GeocodingException::invalidGeocoderResultPartialMatch(); - } - - $this->partialMatch = $partialMatch; - } - - /** - * Gets the geocoder result types. - * - * @return array The geocoder result types. - */ - public function getTypes() - { - return $this->types; - } - - /** - * Sets the geocoder result types. - * - * @param array $types The geocoder result types. - */ - public function setTypes(array $types) - { - $this->types = array(); - - foreach ($types as $type) { - $this->addType($type); - } - } - - /** - * Adds a type to the geocoder result. - * - * @param string $type The type to add. - * - * @throws \Ivory\GoogleMap\Exception\GeocodingException If the type is not valid. - */ - public function addType($type) - { - if (!is_string($type)) { - throw GeocodingException::invalidGeocoderResultType(); - } - - $this->types[] = $type; - } -} diff --git a/src/Services/Geocoding/Result/GeocoderStatus.php b/src/Services/Geocoding/Result/GeocoderStatus.php deleted file mode 100644 index e3a94e8d..00000000 --- a/src/Services/Geocoding/Result/GeocoderStatus.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\GoogleMap\Services\Geocoding\Result; - -/** - * Geocoder status which describes a google map geocoder status. - * - * @see http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderStatus - * @author GeLo - */ -class GeocoderStatus -{ - const ERROR = 'ERROR'; - const INVALID_REQUEST = 'INVALID_REQUEST'; - const OK = 'OK'; - const OVER_QUERY_LIMIT = 'OVER_QUERY_LIMIT'; - const REQUEST_DENIED = 'REQUEST_DENIED'; - const UNKNOWN_ERROR = 'UNKNOWN_ERROR'; - const ZERO_RESULTS = 'ZERO_RESULTS'; - - /** - * Disabled constructor. - * - * @codeCoverageIgnore - */ - final private function __construct() - { - - } - - /** - * Gets the available geocoder status. - * - * @return array The available geocoder status. - */ - public static function getGeocoderStatus() - { - return array( - self::ERROR, - self::INVALID_REQUEST, - self::OK, - self::OVER_QUERY_LIMIT, - self::REQUEST_DENIED, - self::UNKNOWN_ERROR, - self::ZERO_RESULTS, - ); - } -} diff --git a/src/Services/Utils/XmlParser.php b/src/Services/XmlParser.php similarity index 56% rename from src/Services/Utils/XmlParser.php rename to src/Services/XmlParser.php index 48e988b5..d989d4c1 100644 --- a/src/Services/Utils/XmlParser.php +++ b/src/Services/XmlParser.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Ivory\GoogleMap\Services\Utils; +namespace Ivory\GoogleMap\Services; /** * Xml parser. @@ -19,27 +19,37 @@ class XmlParser { /** - * Parses xml according to pluralization rules. + * Parses the xml. * - * @param string $xml The xml. - * @param array $pluralizationRules The pluralization rules. + * @param string $xml The xml. + * @param array $rules The rules. * - * @return \stdClass The parsed & pluralized xml. + * @return array The parsed xml. */ - public function parse($xml, array $pluralizationRules = array()) + public function parse($xml, array $rules = array()) { - $parsedXml = json_decode(json_encode(new \SimpleXMLElement($xml)), true); + return $this->pluralize($this->decode($xml), $rules); + } - return $this->pluralize($parsedXml, $pluralizationRules); + /** + * Decodes the xml. + * + * @param string $xml The xml. + * + * @return array The decoded xml. + */ + protected function decode($xml) + { + return json_decode(json_encode(new \SimpleXMLElement($xml)), true); } /** - * Pluralizes xml. + * Pluralizes the xml. * * @param array $xml The xml. - * @param array $rules The pluralization rules. + * @param array $rules The rules. * - * @return \stdClass The pluralized xml. + * @return array The pluralized xml. */ protected function pluralize(array $xml, array $rules) { @@ -60,22 +70,6 @@ protected function pluralize(array $xml, array $rules) } } - return $this->normalize($xml); - } - - /** - * Normalizes xml. - * - * @param array $xml The xml. - * - * @return array|\stdClass The normalized xml. - */ - protected function normalize(array $xml) - { - if (is_string(key($xml))) { - return (object) $xml; - } - return $xml; } } diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php new file mode 100644 index 00000000..0ebd756e --- /dev/null +++ b/tests/AbstractTestCase.php @@ -0,0 +1,452 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap; + +/** + * Abstract test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase +{ + /** + * Asserts a bound instance. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. + */ + protected function assertBoundInstance($bound) + { + $this->assertInstanceOf('Ivory\GoogleMap\Base\Bound', $bound); + } + + /** + * Asserts a controls instance. + * + * @param \Ivory\GoogleMap\Controls\Controls $controls The controls. + */ + protected function assertControlsInstance($controls) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\Controls', $controls); + } + + /** + * Asserts a controls renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer $controlsRenderer The controls renderer. + */ + protected function assertControlsRendererInstance($controlsRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer', $controlsRenderer); + } + + /** + * Asserts the coordinate instance. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + protected function assertCoordinateInstance($coordinate) + { + $this->assertInstanceOf('Ivory\GoogleMap\Base\Coordinate', $coordinate); + } + + /** + * Asserts an events instance. + * + * @param \Ivory\GoogleMap\Events\Events $events The events. + */ + protected function assertEventsInstance($events) + { + $this->assertInstanceOf('Ivory\GoogleMap\Events\Events', $events); + } + + /** + * Asserts a layers instance. + * + * @param \Ivory\GoogleMap\Layers\Layers $layers The layers. + */ + protected function assertLayersInstance($layers) + { + $this->assertInstanceOf('Ivory\GoogleMap\Layers\Layers', $layers); + } + + /** + * Asserts an options asset instance. + * + * @param \Ivory\GoogleMap\Assets\AbstractOptionsAsset $optionsAsset The options asset. + */ + protected function assertOptionsAssetInstance($optionsAsset) + { + $this->assertInstanceOf('Ivory\GoogleMap\Assets\AbstractOptionsAsset', $optionsAsset); + } + + /** + * Asserts an overlays instance. + * + * @param \Ivory\GoogleMap\Overlays\Overlays $overlays The overlays. + */ + protected function assertOverlaysInstance($overlays) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Overlays', $overlays); + } + + /** + * Asserts a size instance. + * + * @param \Ivory\GoogleMap\Base\Size $size The size. + */ + protected function assertSizeInstance($size) + { + $this->assertInstanceOf('Ivory\GoogleMap\Base\Size', $size); + } + + /** + * Asserts an uninstantiable asset instance. + * + * @param string $uninstantiableAsset The uninstantiable asset class. + */ + protected function assertUninstantiableAssetInstance($uninstantiableAsset) + { + $this->assertTrue(is_subclass_of($uninstantiableAsset, 'Ivory\GoogleMap\Assets\AbstractUninstantiableAsset')); + } + + /** + * Asserts a variable asset instance. + * + * @param \Ivory\GoogleMap\Assets\AbstractVariableAsset $variableAsset The varable asset. + */ + protected function assertVariableAssetInstance($variableAsset) + { + $this->assertInstanceOf('Ivory\GoogleMap\Assets\AbstractVariableAsset', $variableAsset); + } + + /** + * Creates a bound mock. + * + * @return \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject The bound mock. + */ + protected function createBoundMock() + { + return $this->getMock('Ivory\GoogleMap\Base\Bound'); + } + + /** + * Creates a circle mock. + * + * @return \Ivory\GoogleMap\Overlays\Circle|\PHPUnit_Framework_MockObject_MockObject The circle mock. + */ + protected function createCircleMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Circle')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a controls mock. + * + * @return \Ivory\GoogleMap\Controls\Controls|\PHPUnit_Framework_MockObject_MockObject The controls mock. + */ + protected function createControlsMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\Controls'); + } + + /** + * Creates a coordinate mock. + * + * @return \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject The coordinate mock. + */ + protected function createCoordinateMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Base\Coordinate')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a dom event mock. + * + * @return \Ivory\GoogleMap\Events\DomEvent|\PHPUnit_Framework_MockObject_MockObject The dom event mock. + */ + protected function createDomEventMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Events\DomEvent')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an encoded polyline mock. + * + * @return \Ivory\GoogleMap\Overlays\EncodedPolyline|\PHPUnit_Framework_MockObject_MockObject The encoded polyline mock. + */ + protected function createEncodedPolylineMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\EncodedPolyline') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates an event mock. + * + * @return \Ivory\GoogleMap\Events\Event|\PHPUnit_Framework_MockObject_MockObject The event mock. + */ + protected function createEventMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Events\Event')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an events mock. + * + * @return \Ivory\GoogleMap\Events\Events|\PHPUnit_Framework_MockObject_MockObject The events mock. + */ + protected function createEventsMock() + { + return $this->getMock('Ivory\GoogleMap\Events\Events'); + } + + /** + * Creates an extendable mock. + * + * @return \Ivory\GoogleMap\Overlays\ExtendableInterface|\PHPUnit_Framework_MockObject_MockObject The extendable mock. + */ + protected function createExtendableMock() + { + return $this->getMock('Ivory\GoogleMap\Overlays\ExtendableInterface'); + } + + /** + * Creates a ground overlay mock. + * + * @return \Ivory\GoogleMap\Overlays\GroundOverlay|\PHPUnit_Framework_MockObject_MockObject The ground overlay mock. + */ + protected function createGroundOverlayMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\GroundOverlay')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an icon mock. + * + * @return \Ivory\GoogleMap\Overlays\Icon|\PHPUnit_Framework_MockObject_MockObject The icon mock. + */ + protected function createIconMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Icon')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an info window mock. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\InfoWindow')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a kml layer mock. + * + * @return \Ivory\GoogleMap\Layers\KmlLayer|\PHPUnit_Framework_MockObject_MockObject The kml layer mock. + */ + protected function createKmlLayerMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Layers\KmlLayer')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a layers mock. + * + * @return \Ivory\GoogleMap\Layers\Layers|\PHPUnit_Framework_MockObject_MockObject The layers mock. + */ + protected function createLayersMock() + { + return $this->getMock('Ivory\GoogleMap\Layers\Layers'); + } + + /** + * Creates a map type control mock. + * + * @return \Ivory\GoogleMap\Controls\MapTypeControl|\PHPUnit_Framework_MockObject_MockObject The map type control mock. + */ + protected function createMapTypeControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\MapTypeControl'); + } + + /** + * Creates a marker cluster mock. + * + * @return \Ivory\GoogleMap\Overlays\MarkerCluster|\PHPUnit_Framework_MockObject_MockObject The marker cluster mock. + */ + protected function createMarkerClusterMock() + { + return $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); + } + + /** + * Creates a marker mock. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Marker')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a marker shape mock. + * + * @return \Ivory\GoogleMap\Overlays\MarkerShape|\PHPUnit_Framework_MockObject_MockObject The marker shape mock. + */ + protected function createMarkerShapeMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\MarkerShape')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an overlays mock. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock() + { + return $this->getMock('Ivory\GoogleMap\Overlays\Overlays'); + } + + /** + * Creates an overview map control mock. + * + * @return \Ivory\GoogleMap\Controls\OverviewMapControl|\PHPUnit_Framework_MockObject_MockObject The overview map control mock. + */ + protected function createOverviewMapControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\OverviewMapControl'); + } + + /** + * Creates a pan control mock. + * + * @return \Ivory\GoogleMap\Controls\PanControl|\PHPUnit_Framework_MockObject_MockObject The pan control mock. + */ + protected function createPanControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\PanControl'); + } + + /** + * Creates a point mock. + * + * @return \Ivory\GoogleMap\Base\Point|\PHPUnit_Framework_MockObject_MockObject The point mock. + */ + protected function createPointMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Base\Point')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a polygon mock. + * + * @return \Ivory\GoogleMap\Overlays\Polygon|\PHPUnit_Framework_MockObject_MockObject The polygon mock. + */ + protected function createPolygonMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Polygon')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a polyline mock. + * + * @return \Ivory\GoogleMap\Overlays\Polyline|\PHPUnit_Framework_MockObject_MockObject The polyline mock. + */ + protected function createPolylineMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Polyline')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a rectangle mock. + * + * @return \Ivory\GoogleMap\Overlays\Rectangle|\PHPUnit_Framework_MockObject_MockObject The rectangle mock. + */ + protected function createRectangleMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Overlays\Rectangle')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a rotate control mock. + * + * @return \Ivory\GoogleMap\Controls\RotateControl|\PHPUnit_Framework_MockObject_MockObject The rotate control mock. + */ + protected function createRotateControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\RotateControl'); + } + + /** + * Creates a scale control mock. + * + * @return \Ivory\GoogleMap\Controls\ScaleControl|\PHPUnit_Framework_MockObject_MockObject The scale control mock. + */ + protected function createScaleControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\ScaleControl'); + } + + /** + * Creates a size mock. + * + * @return \Ivory\GoogleMap\Base\Size|\PHPUnit_Framework_MockObject_MockObject The size mock. + */ + protected function createSizeMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Base\Size')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a street view control mock. + * + * @return \Ivory\GoogleMap\Controls\StreetViewControl|\PHPUnit_Framework_MockObject_MockObject The street view control mock. + */ + protected function createStreetViewControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\StreetViewControl'); + } + + /** + * Creates a variable asset mock. + * + * @return \Ivory\GoogleMap\Assets\AbstractVariableAsset|\PHPUnit_Framework_MockObject_MockObject The variable asset mock. + */ + protected function createVariableAssetMock() + { + return $this->createVariableAssetMockBuilder()->getMock(); + } + + /** + * Creates a variable asset mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The variable asset mock builder. + */ + protected function createVariableAssetMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Assets\AbstractVariableAsset'); + } + + /** + * Creates a zoom control mock. + * + * @return \Ivory\GoogleMap\Controls\ZoomControl|\PHPUnit_Framework_MockObject_MockObject The zoom control mock. + */ + protected function createZoomControlMock() + { + return $this->getMock('Ivory\GoogleMap\Controls\ZoomControl'); + } +} diff --git a/tests/Assets/AbstractTestCase.php b/tests/Assets/AbstractTestCase.php new file mode 100644 index 00000000..13c7e5c8 --- /dev/null +++ b/tests/Assets/AbstractTestCase.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Assets; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Assets test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Creates an options assets mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The options asset mock builder. + */ + protected function createOptionsAssetMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Assets\AbstractOptionsAsset'); + } +} diff --git a/tests/Assets/JavascriptVariableAssetTest.php b/tests/Assets/JavascriptVariableAssetTest.php deleted file mode 100644 index 65604611..00000000 --- a/tests/Assets/JavascriptVariableAssetTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Assets; - -/** - * Javascript variable asset test. - * - * @author GeLo - */ -class JavascriptVariableAssetTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset */ - protected $asset; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->asset = $this->getMockForAbstractClass('Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset'); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->asset); - } - - public function testDefaultState() - { - $this->assertInternalType('string', $this->asset->getJavascriptVariable()); - } - - public function testInitialState() - { - $this->asset = $this->getMockBuilder('Ivory\GoogleMap\Assets\AbstractJavascriptVariableAsset') - ->setConstructorArgs(array('foo')) - ->getMockForAbstractClass(); - - $this->assertSame('foo', $this->asset->getJavascriptVariable()); - } - - public function testjavascriptVariableWithValidVariable() - { - $this->asset->setJavascriptVariable('foo'); - - $this->assertSame('foo', $this->asset->getJavascriptVariable()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The javascript variable must be a string value. - */ - public function testJavascriptVariableWithInvalidVariable() - { - $this->asset->setJavascriptVariable(true); - } - - public function testPrefixJavascriptVariableWithValidPrefix() - { - $this->asset->setPrefixJavascriptVariable('foo'); - - $this->assertSame('foo', substr($this->asset->getJavascriptVariable(), 0, 3)); - $this->assertGreaterThan(3, strlen($this->asset->getJavascriptVariable())); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The prefix of a javascript variable must be a string value. - */ - public function testPrefixJavascriptVariableWithInvalidPrefix() - { - $this->asset->setPrefixJavascriptVariable(true); - } -} diff --git a/tests/Assets/OptionsAssetTest.php b/tests/Assets/OptionsAssetTest.php index 0c954dfb..3a36b9cf 100644 --- a/tests/Assets/OptionsAssetTest.php +++ b/tests/Assets/OptionsAssetTest.php @@ -16,17 +16,17 @@ * * @author GeLo */ -class OptionsAssetTest extends \PHPUnit_Framework_TestCase +class OptionsAssetTest extends AbstractTestCase { - /** @var \Ivory\GoogleMap\Assets\AbstractOptionsAsset */ - protected $asset; + /** @var \Ivory\GoogleMap\Assets\AbstractOptionsAsset|\PHPUnit_Framework_MockObject_MockObject */ + protected $optionsAssetMock; /** * {@inheritdoc} */ protected function setUp() { - $this->asset = $this->getMockForAbstractClass('Ivory\GoogleMap\Assets\AbstractOptionsAsset'); + $this->optionsAssetMock = $this->createOptionsAssetMockBuilder()->getMockForAbstractClass(); } /** @@ -34,73 +34,174 @@ protected function setUp() */ protected function tearDown() { - unset($this->asset); + unset($this->optionsAssetMock); + } + + public function testInheritance() + { + $this->assertVariableAssetInstance($this->optionsAssetMock); } public function testDefaultState() { - $this->assertInternalType('string', $this->asset->getJavascriptVariable()); - $this->assertEmpty($this->asset->getOptions()); + $this->assertNotEmpty($this->optionsAssetMock->getVariable()); + $this->assertNoOptions(); } public function testInitialState() { - $this->asset = $this->getMockBuilder('Ivory\GoogleMap\Assets\AbstractOptionsAsset') - ->setConstructorArgs(array('foo', array('foo' => 'bar'))) + $this->optionsAssetMock = $this->createOptionsAssetMockBuilder() + ->setConstructorArgs(array($prefix = 'foo', $options = array('bar' => 'baz'))) ->getMockForAbstractClass(); - $this->assertSame('foo', $this->asset->getJavascriptVariable()); - $this->assertSame(array('foo' => 'bar'), $this->asset->getOptions()); + $this->assertStringStartsWith($prefix, $this->optionsAssetMock->getVariable()); + $this->assertOptions($options); + } + + /** + * @dataProvider optionsProvider + */ + public function testSetOptions(array $options) + { + $this->optionsAssetMock->setOptions($options); + + $this->assertOptions($options); + } + + /** + * @dataProvider optionsProvider + */ + public function testAddOptions(array $options) + { + $this->optionsAssetMock->setOptions($options); + $this->optionsAssetMock->addOptions($newOptions = array('foo' => 'bar')); + + $this->assertOptions(array_merge($options, $newOptions)); + } + + /** + * @dataProvider optionsProvider + */ + public function testRemoveOptions(array $options) + { + $this->optionsAssetMock->setOptions($options); + $this->optionsAssetMock->removeOptions(array_keys($options)); + + $this->assertNoOptions(); + } + + /** + * @dataProvider optionsProvider + */ + public function testResetOptions(array $options) + { + $this->optionsAssetMock->setOptions($options); + $this->optionsAssetMock->resetOptions(); + + $this->assertNoOptions(); } - public function testOptions() + /** + * @dataProvider optionProvider + */ + public function testSetOption($name, $value) { - $this->asset->setOptions(array('foo' => 'bar')); + $this->optionsAssetMock->setOption($name, $value); - $this->assertTrue($this->asset->hasOptions()); - $this->assertSame(array('foo' => 'bar'), $this->asset->getOptions()); + $this->assertOption($name, $value); + } - $this->assertTrue($this->asset->hasOption('foo')); - $this->assertSame('bar', $this->asset->getOption('foo')); + /** + * @dataProvider optionProvider + */ + public function testRemoveOption($name, $value) + { + $this->optionsAssetMock->setOption($name, $value); + $this->optionsAssetMock->removeOption($name); - $this->asset->removeOption('foo'); + $this->assertNoOption($name); + } - $this->assertFalse($this->asset->hasOption('foo')); + /** + * Gets the option provider. + * + * @return array The option provider. + */ + public function optionProvider() + { + return array( + array('string', 'foo'), + array('boolean', true), + array('integer', 1), + array('float', 1.1), + array('array', array()), + array('object', new \stdClass()), + array('null', null), + ); } /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The option property must be a string value. + * Gets the options provider. + * + * @return array The options provider. */ - public function testHasOptionWithInvalidOption() + public function optionsProvider() { - $this->asset->hasOption(true); + $options = array(); + + foreach ($this->optionProvider() as $provider) { + $options[] = array($provider[0] => $provider[1]); + } + + return array($options); + } + + /** + * Asserts the are options. + * + * @param array $options The options. + */ + protected function assertOptions($options) + { + $this->assertInternalType('array', $options); + + $this->assertTrue($this->optionsAssetMock->hasOptions()); + $this->assertSame($options, $this->optionsAssetMock->getOptions()); + + foreach ($options as $name => $value) { + $this->assertOption($name, $value); + } } /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The option "foo" does not exist. + * Asserts there is an option. + * + * @param string $name The option name. + * @param mixed $value The option value. */ - public function testGetOptionWithInvalidOption() + protected function assertOption($name, $value) { - $this->asset->getOption('foo'); + $this->assertTrue($this->optionsAssetMock->hasOption($name)); + $this->assertSame($value, $this->optionsAssetMock->getOption($name)); } /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The option property must be a string value. + * Asserts there are no options. */ - public function testSetOptionWithInvalidOption() + protected function assertNoOptions() { - $this->asset->setOption(true, false); + $this->assertFalse($this->optionsAssetMock->hasOptions()); + $this->assertEmpty($this->optionsAssetMock->getOptions()); } /** - * @expectedException \Ivory\GoogleMap\Exception\AssetException - * @expectedExceptionMessage The option "foo" does not exist. + * Asserts there is no option. + * + * @param string $name The option name. */ - public function testRemoveOptionWithInvalidOption() + protected function assertNoOption($name) { - $this->asset->removeOption('foo'); + $this->assertFalse($this->optionsAssetMock->hasOption($name)); + $this->assertNull($this->optionsAssetMock->getOption($name)); } } diff --git a/tests/Assets/UninstantiableAssetTest.php b/tests/Assets/UninstantiableAssetTest.php new file mode 100644 index 00000000..c41c98a7 --- /dev/null +++ b/tests/Assets/UninstantiableAssetTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Assets; + +/** + * Uninstantiable asset test. + * + * @author GeLo + */ +class UninstantiableAssetTest extends AbstractTestCase +{ + public function testDisabledConstructor() + { + $reflectionMethod = new \ReflectionMethod('Ivory\GoogleMap\Assets\AbstractUninstantiableAsset', '__construct'); + + $this->assertTrue($reflectionMethod->isConstructor()); + $this->assertTrue($reflectionMethod->isFinal()); + $this->assertTrue($reflectionMethod->isPrivate()); + } +} diff --git a/tests/Assets/VariableAssetTest.php b/tests/Assets/VariableAssetTest.php new file mode 100644 index 00000000..230b0e0b --- /dev/null +++ b/tests/Assets/VariableAssetTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Assets; + +/** + * Variable asset test. + * + * @author GeLo + */ +class VariableAssetTest extends AbstractTestCase +{ + /** @var string */ + protected $variablePatternFormat = '/^%s[a-z0-9]{22}$/'; + + /** @var \Ivory\GoogleMap\Assets\AbstractVariableAsset|\PHPUnit_Framework_MockObject_MockObject */ + protected $variableAssetMock; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->variableAssetMock = $this->createVariableAssetMockBuilder()->getMockForAbstractClass(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->variableAssetMock); + } + + public function testDefaultState() + { + $this->assertRegExp(sprintf($this->variablePatternFormat, null), $this->variableAssetMock->getVariable()); + } + + public function testInitialState() + { + $this->variableAssetMock = $this->createVariableAssetMockBuilder() + ->setConstructorArgs(array($prefix = 'foo')) + ->getMockForAbstractClass(); + + $this->assertRegExp(sprintf($this->variablePatternFormat, $prefix), $this->variableAssetMock->getVariable()); + } + + public function testVariableUnicity() + { + $variableAssetMock = $this->createVariableAssetMockBuilder()->getMockForAbstractClass(); + + $this->assertNotSame($variableAssetMock->getVariable(), $this->variableAssetMock->getVariable()); + } + + public function testSetVariable() + { + $this->variableAssetMock->setVariable($variable = 'foo'); + + $this->assertSame($variable, $this->variableAssetMock->getVariable()); + } +} diff --git a/tests/Base/BoundTest.php b/tests/Base/BoundTest.php index f3b58b6b..c75deb25 100644 --- a/tests/Base/BoundTest.php +++ b/tests/Base/BoundTest.php @@ -12,13 +12,14 @@ namespace Ivory\Tests\GoogleMap\Base; use Ivory\GoogleMap\Base\Bound; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Bound test. * * @author GeLo */ -class BoundTest extends \PHPUnit_Framework_TestCase +class BoundTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Base\Bound */ protected $bound; @@ -39,114 +40,121 @@ protected function tearDown() unset($this->bound); } + public function testInheritance() + { + $this->assertVariableAssetInstance($this->bound); + } + public function testDefaultState() { - $this->assertSame('bound_', substr($this->bound->getJavascriptVariable(), 0, 6)); - $this->assertFalse($this->bound->hasCoordinates()); - $this->assertFalse($this->bound->hasExtends()); + $this->assertStringStartsWith('bound_', $this->bound->getVariable()); + $this->assertNoCoordinates(); } public function testInitialState() { - $southWest = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEast = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $extends = array($this->getMock('Ivory\GoogleMap\Overlays\ExtendableInterface')); + $this->bound = new Bound( + $southWest = $this->createCoordinateMock(), + $northEast = $this->createCoordinateMock() + ); - $this->bound = new Bound($southWest, $northEast, $extends); + $this->assertCoordinates($southWest, $northEast); + } - $this->assertTrue($this->bound->hasCoordinates()); - $this->assertSame($southWest, $this->bound->getSouthWest()); - $this->assertSame($northEast, $this->bound->getNorthEast()); + public function testSetSouthWest() + { + $this->bound->setSouthWest($southWest = $this->createCoordinateMock()); - $this->assertTrue($this->bound->hasExtends()); - $this->assertSame($extends, $this->bound->getExtends()); + $this->assertSouthWest($southWest); } - public function testSouthWestWithCoordinate() + public function testResetSouthWest() { - $southWest = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->bound->setSouthWest($southWest); + $this->bound->setSouthWest($this->createCoordinateMock()); + $this->bound->setSouthWest(null); - $this->assertSame($southWest, $this->bound->getSouthWest()); + $this->assertNoSouthWest(); } - public function testSouthWestWithLatitudeAndLongitude() + public function testSetNorthEast() { - $this->bound->setSouthWest(1, 2, false); + $this->bound->setNorthEast($northEast = $this->createCoordinateMock()); - $this->assertSame(1, $this->bound->getSouthWest()->getLatitude()); - $this->assertSame(2, $this->bound->getSouthWest()->getLongitude()); - $this->assertFalse($this->bound->getSouthWest()->isNoWrap()); + $this->assertNorthEast($northEast); } - public function testSouthWestWithNull() + public function testResetNorthEast() { - $this->bound->setSouthWest(1, 2, false); - $this->bound->setSouthWest(null); + $this->bound->setNorthEast($this->createCoordinateMock()); + $this->bound->setNorthEast(null); - $this->assertNull($this->bound->getSouthWest()); + $this->assertNoNorthEast(); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage - * The south west setter arguments is invalid. - * The available prototypes are : - * - function setSouthWest(Ivory\GoogleMap\Base\Coordinate $southWest) - * - function setSouthWest(double $latitude, double $longitude, boolean $noWrap = true) + * Asserts there are coordinates. + * + * @param \Ivory\GoogleMap\Base\Coordinate $southWest The south west coordinate. + * @param \Ivory\GoogleMap\Base\Coordinate $northEast The north east coordinate. */ - public function testSouthWestWithInvalidValue() + protected function assertCoordinates($southWest, $northEast) { - $this->bound->setSouthWest('foo'); + $this->assertTrue($this->bound->hasCoordinates()); + $this->assertSouthWest($southWest); + $this->assertNorthEast($northEast); } - public function testNorthEastWithCoordinate() + /** + * Asserts there is a south west coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $southWest The south west coordinate. + */ + protected function assertSouthWest($southWest) { - $northEast = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->bound->setNorthEast($northEast); + $this->assertCoordinateInstance($southWest); - $this->assertSame($northEast, $this->bound->getNorthEast()); + $this->assertTrue($this->bound->hasSouthWest()); + $this->assertSame($southWest, $this->bound->getSouthWest()); } - public function testNorthEastWithLatitudeAndLongitude() + /** + * Asserts there is a north east coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $northEast The north east coordinate. + */ + protected function assertNorthEast($northEast) { - $this->bound->setNorthEast(1, 2, false); + $this->assertCoordinateInstance($northEast); - $this->assertSame(1, $this->bound->getNorthEast()->getLatitude()); - $this->assertSame(2, $this->bound->getNorthEast()->getLongitude()); - $this->assertFalse($this->bound->getNorthEast()->isNoWrap()); + $this->assertTrue($this->bound->hasNorthEast()); + $this->assertSame($northEast, $this->bound->getNorthEast()); } - public function testNorthEastWithNull() + /** + * Asserts there are no coordinates. + */ + protected function assertNoCoordinates() { - $this->bound->setNorthEast(1, 2, false); - $this->bound->setNorthEast(null); - - $this->assertNull($this->bound->getNorthEast()); + $this->assertFalse($this->bound->hasCoordinates()); + $this->assertNoSouthWest(); + $this->assertNoNorthEast(); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage - * The north east setter arguments is invalid. - * The available prototypes are : - * - function setNorthEast(Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setNorthEast(double $latitude, double $longitude, boolean $noWrap = true) + * Asserts there is no south west coordinate. */ - public function testNorthEastWithInvalidValue() + protected function assertNoSouthWest() { - $this->bound->setNorthEast('foo'); + $this->assertFalse($this->bound->hasSouthWest()); + $this->assertNull($this->bound->getSouthWest()); } - public function testCenter() + /** + * Asserts there is no north east coordinate. + */ + protected function assertNoNorthEast() { - $this->bound->setSouthWest(-1, 0, false); - $this->bound->setNorthEast(1, 2, false); - - $center = $this->bound->getCenter(); - - $this->assertSame(0, $center->getLatitude()); - $this->assertSame(1, $center->getLongitude()); - $this->assertTrue($center->isNoWrap()); + $this->assertFalse($this->bound->hasNorthEast()); + $this->assertNull($this->bound->getNorthEast()); } } diff --git a/tests/Base/CoordinateTest.php b/tests/Base/CoordinateTest.php index 04b76bc8..08db6238 100644 --- a/tests/Base/CoordinateTest.php +++ b/tests/Base/CoordinateTest.php @@ -12,23 +12,30 @@ namespace Ivory\Tests\GoogleMap\Base; use Ivory\GoogleMap\Base\Coordinate; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Coordinate test. * * @author GeLo */ -class CoordinateTest extends \PHPUnit_Framework_TestCase +class CoordinateTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Base\Coordinate */ protected $coordinate; + /** @var float */ + protected $latitude; + + /** @var float */ + protected $longitude; + /** * {@inheritdoc} */ protected function setUp() { - $this->coordinate = new Coordinate(); + $this->coordinate = new Coordinate($this->latitude = 1, $this->longitude = -1); } /** @@ -37,79 +44,119 @@ protected function setUp() protected function tearDown() { unset($this->coordinate); + unset($this->latitude); + unset($this->longitude); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame('coordinate_', substr($this->coordinate->getJavascriptVariable(), 0, 11)); - $this->assertSame(0, $this->coordinate->getLatitude()); - $this->assertSame(0, $this->coordinate->getLongitude()); - $this->assertTrue($this->coordinate->isNoWrap()); + $this->assertVariableAssetInstance($this->coordinate); } public function testInitialState() { - $this->coordinate = new Coordinate(1, 2, false); + $this->assertStringStartsWith('coordinate_', $this->coordinate->getVariable()); - $this->assertSame(1, $this->coordinate->getLatitude()); - $this->assertSame(2, $this->coordinate->getLongitude()); - $this->assertFalse($this->coordinate->isNoWrap()); + $this->assertSame($this->latitude, $this->coordinate->getLatitude()); + $this->assertSame($this->longitude, $this->coordinate->getLongitude()); } - public function testLatitudeWithValidLatitude() + public function testSetLatitude() { - $this->coordinate->setLatitude(1); - $this->assertSame(1, $this->coordinate->getLatitude()); - } + $this->coordinate->setLatitude($latitude = 10); - public function testLatitudeWithNull() - { - $this->coordinate->setLatitude(null); - $this->assertNull($this->coordinate->getLatitude()); + $this->assertSame($latitude, $this->coordinate->getLatitude()); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The latitude of a coordinate must be a numeric value. + * @dataProvider latitudeNoWrapProvider */ - public function testLatitudeWithInvalidLatitude() + public function testIsLatitudeNoWrap($latitude, $noWrap) { - $this->coordinate->setLatitude(true); + $this->coordinate->setLatitude($latitude); + + $this->assertSame($noWrap, $this->coordinate->isLatitudeNoWrap()); } - public function testLongitudeWithValidLongitude() + public function testSetLongitude() { - $this->coordinate->setLongitude(1); - $this->assertSame(1, $this->coordinate->getLongitude()); + $this->coordinate->setLongitude($longitude = 10); + + $this->assertSame($longitude, $this->coordinate->getLongitude()); } - public function testLongitudeWithNull() + /** + * @dataProvider longitudeNoWrapProvider + */ + public function testIsLongitudeNoWrap($longitude, $noWrap) { - $this->coordinate->setLongitude(null); - $this->assertNull($this->coordinate->getLongitude()); + $this->coordinate->setLongitude($longitude); + + $this->assertSame($noWrap, $this->coordinate->isLongitudeNoWrap()); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The longitude of a coordinate must be a numeric value. + * @dataProvider noWrapProvider */ - public function testLongitudeWithInvalidLongitude() + public function testIsNoWrap($latitude, $longitude, $noWrap) { - $this->coordinate->setLongitude(true); + $this->coordinate->setLatitude($latitude); + $this->coordinate->setLongitude($longitude); + + $this->assertSame($noWrap, $this->coordinate->isNoWrap()); + } + + /** + * Gets the latitude no wrap provider. + * + * @return array The latitude no wrap provider. + */ + public function latitudeNoWrapProvider() + { + return array( + array(0, false), + array(90, false), + array(-90, false), + array(91, true), + array(-91, true), + ); } - public function testNoWrapWithValidNoWrap() + /** + * Gets the longitude no wrap provider. + * + * @return array The longitude no wrap provider. + */ + public function longitudeNoWrapProvider() { - $this->coordinate->setNoWrap(false); - $this->assertFalse($this->coordinate->isNoWrap()); + return array( + array(0, false), + array(180, false), + array(-180, false), + array(181, true), + array(-181, true), + ); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The no wrap coordinate property must be a boolean value. + * Gets the no wrap provider. + * + * @return array The no wrap provider. */ - public function testNoWrapWithInvalidNoWrap() + public function noWrapProvider() { - $this->coordinate->setNoWrap('foo'); + $noWraps = array(); + + foreach ($this->latitudeNoWrapProvider() as $latitudeProvider) { + foreach ($this->longitudeNoWrapProvider() as $longitudeProvider) { + $noWraps[] = array( + $latitudeProvider[0], + $longitudeProvider[0], + $latitudeProvider[1] || $longitudeProvider[1] + ); + } + } + + return $noWraps; } } diff --git a/tests/Base/PointTest.php b/tests/Base/PointTest.php index 53ff1b0c..74b5604b 100644 --- a/tests/Base/PointTest.php +++ b/tests/Base/PointTest.php @@ -12,23 +12,30 @@ namespace Ivory\Tests\GoogleMap\Base; use Ivory\GoogleMap\Base\Point; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Point test. * * @author GeLo */ -class PointTest extends \PHPUnit_Framework_TestCase +class PointTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Base\Point */ protected $point; + /** @var float */ + protected $x; + + /** @var float */ + protected $y; + /** * {@inheritdoc} */ protected function setUp() { - $this->point = new Point(); + $this->point = new Point($this->x = -1, $this->y = 1); } /** @@ -37,52 +44,33 @@ protected function setUp() protected function tearDown() { unset($this->point); + unset($this->x); + unset($this->y); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame('point_', substr($this->point->getJavascriptVariable(), 0, 6)); - $this->assertSame(0, $this->point->getX()); - $this->assertSame(0, $this->point->getY()); + $this->assertVariableAssetInstance($this->point); } public function testInitialState() { - $this->point = new Point(1, 2); - - $this->assertSame(1, $this->point->getX()); - $this->assertSame(2, $this->point->getY()); + $this->assertStringStartsWith('point_', $this->point->getVariable()); + $this->assertSame($this->x, $this->point->getX()); + $this->assertSame($this->y, $this->point->getY()); } - public function testXWithValidValue() + public function testSetX() { - $this->point->setX(1); + $this->point->setX($x = 10); - $this->assertSame(1, $this->point->getX()); + $this->assertSame($x, $this->point->getX()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The x coordinate of a point must be a numeric value. - */ - public function testXWithInvalidValue() + public function testSetY() { - $this->point->setX(true); - } + $this->point->setY($y = 10); - public function testYWithValidValue() - { - $this->point->setY(1); - - $this->assertSame(1, $this->point->getY()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The y coordinate of a point must be a numeric value. - */ - public function testYWithInvalidValue() - { - $this->point->setY(true); + $this->assertSame($y, $this->point->getY()); } } diff --git a/tests/Base/SizeTest.php b/tests/Base/SizeTest.php index cc669876..b4711f1f 100644 --- a/tests/Base/SizeTest.php +++ b/tests/Base/SizeTest.php @@ -12,23 +12,30 @@ namespace Ivory\Tests\GoogleMap\Base; use Ivory\GoogleMap\Base\Size; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Size test. * * @author GeLo */ -class SizeTest extends \PHPUnit_Framework_TestCase +class SizeTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Base\Size */ protected $size; + /** @var float */ + protected $width; + + /** @var float */ + protected $height; + /** * {@inheritdoc} */ protected function setUp() { - $this->size = new Size(); + $this->size = new Size($this->width = 1, $this->height = 2); } /** @@ -37,93 +44,164 @@ protected function setUp() protected function tearDown() { unset($this->size); + unset($this->width); + unset($this->height); + } + + public function testInheritance() + { + $this->assertVariableAssetInstance($this->size); } public function testDefaultState() { - $this->assertSame('size_', substr($this->size->getJavascriptVariable(), 0, 5)); + $this->assertStringStartsWith('size_', $this->size->getVariable()); + $this->assertSizes($this->width, $this->height); + $this->assertNoUnits(); + } - $this->assertSame(1, $this->size->getWidth()); - $this->assertSame(1, $this->size->getHeight()); + public function testInitialState() + { + $this->size = new Size($this->width, $this->height, $widthUnit = 'px', $heightUnit = '%'); - $this->assertFalse($this->size->hasUnits()); - $this->assertNull($this->size->getWidthUnit()); - $this->assertNull($this->size->getHeightUnit()); + $this->assertSizes($this->width, $this->height); + $this->assertUnits($widthUnit, $heightUnit); } - public function testInitialState() + public function testSetWidth() { - $this->size = new Size(2, 3, 'px', '%'); + $this->size->setWidth($width = 10); - $this->assertSame(2, $this->size->getWidth()); - $this->assertSame(3, $this->size->getHeight()); + $this->assertWidth($width); + } + + public function testSetHeight() + { + $this->size->setHeight($height = 10); + + $this->assertHeight($height); + } + + public function testSetWidthUnit() + { + $this->size->setWidthUnit($widthUnit = 'em'); + + $this->assertWidthUnit($widthUnit); + } + + public function testResetWidthUnit() + { + $this->size->setWidthUnit('em'); + $this->size->setWidthUnit(null); - $this->assertTrue($this->size->hasUnits()); - $this->assertSame('px', $this->size->getWidthUnit()); - $this->assertSame('%', $this->size->getHeightUnit()); + $this->assertNoWidthUnit(); } - public function testWidthWithValidValue() + public function testSetHeightUnit() { - $this->size->setWidth(2); + $this->size->setHeightUnit($heightUnit = 'em'); - $this->assertSame(2, $this->size->getWidth()); + $this->assertHeightUnit($heightUnit); + } + + public function testResetHeightUnit() + { + $this->size->setHeightUnit('em'); + $this->size->setHeightUnit(null); + + $this->assertNoHeightUnit(); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The width of a size must be a numeric value. + * Asserts the sizes. + * + * @param float $width The width. + * @param float $height The height. */ - public function testWidthWithInvalidValue() + protected function assertSizes($width, $height) { - $this->size->setWidth(true); + $this->assertWidth($width); + $this->assertHeight($height); } - public function testHeightWithValidValue() + /** + * Asserts the width. + * + * @param float $width The width. + */ + protected function assertWidth($width) { - $this->size->setHeight(2); - - $this->assertSame(2, $this->size->getHeight()); + $this->assertSame($width, $this->size->getWidth()); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The height of a size must be a numeric value. + * Asserts the height. + * + * @param float $height The height. */ - public function testHeightWithInvalidValue() + protected function assertHeight($height) { - $this->size->setHeight(true); + $this->assertSame($height, $this->size->getHeight()); } - public function testWidthUnitWithValidValue() + /** + * Asserts the units. + * + * @param string $widthUnit The width unit. + * @param string $heightUnit The height unit. + */ + protected function assertUnits($widthUnit, $heightUnit) { - $this->size->setWidthUnit('px'); + $this->assertWidthUnit($widthUnit); + $this->assertHeightUnit($heightUnit); + } - $this->assertSame('px', $this->size->getWidthUnit()); + /** + * Asserts the width unit. + * + * @param string $widthUnit The width unit. + */ + protected function assertWidthUnit($widthUnit) + { + $this->assertTrue($this->size->hasWidthUnit()); + $this->assertSame($widthUnit, $this->size->getWidthUnit()); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The width unit of a size must be a string value. + * Asserts the height unit. + * + * @param string $heightUnit The height unit. */ - public function testWidthUnitWithInvalidValue() + protected function assertHeightUnit($heightUnit) { - $this->size->setWidthUnit(true); + $this->assertTrue($this->size->hasHeightUnit()); + $this->assertSame($heightUnit, $this->size->getHeightUnit()); } - public function testHeightUnitWithValidValue() + /** + * Asserts there are no units. + */ + protected function assertNoUnits() { - $this->size->setHeightUnit('px'); + $this->assertNoWidthUnit(); + $this->assertNoHeightUnit(); + } - $this->assertSame('px', $this->size->getHeightUnit()); + /** + * Asserts there is no width unit. + */ + protected function assertNoWidthUnit() + { + $this->assertFalse($this->size->hasWidthUnit()); + $this->assertNull($this->size->getWidthUnit()); } /** - * @expectedException \Ivory\GoogleMap\Exception\BaseException - * @expectedExceptionMessage The height unit of a size must be a string value. + * Asserts there is no height unit. */ - public function testHeightUnitWithInvalidValue() + protected function assertNoHeightUnit() { - $this->size->setHeightUnit(true); + $this->assertFalse($this->size->hasHeightUnit()); + $this->assertNull($this->size->getHeightUnit()); } } diff --git a/tests/Controls/AbstractTestCase.php b/tests/Controls/AbstractTestCase.php new file mode 100644 index 00000000..ee609c09 --- /dev/null +++ b/tests/Controls/AbstractTestCase.php @@ -0,0 +1,92 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Controls; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Controls test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a map type control instance. + * + * @param \Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl The map type control. + */ + protected function assertMapTypeControlInstance($mapTypeControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\MapTypeControl', $mapTypeControl); + } + + /** + * Asserts an overview map control instance. + * + * @param \Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl The overview map control. + */ + protected function assertOverviewMapControlInstance($overviewMapControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\OverviewMapControl', $overviewMapControl); + } + + /** + * Asserts a pan control instance. + * + * @param \Ivory\GoogleMap\Controls\PanControl $panControl The pan control. + */ + protected function assertPanControlInstance($panControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\PanControl', $panControl); + } + + /** + * Asserts a rotate control instance. + * + * @param \Ivory\GoogleMap\Controls\RotateControl $rotateControl The rotate control. + */ + protected function assertRotateControlInstance($rotateControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\RotateControl', $rotateControl); + } + + /** + * Asserts a scale control instance. + * + * @param \Ivory\GoogleMap\Controls\ScaleControl $scaleControl The scale control. + */ + protected function assertScaleControlInstance($scaleControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\ScaleControl', $scaleControl); + } + + /** + * Asserts a street view control instance. + * + * @param \Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl The street view control. + */ + protected function assertStreetViewControlInstance($streetViewControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\StreetViewControl', $streetViewControl); + } + + /** + * Asserts a zoom control instance. + * + * @param \Ivory\GoogleMap\Controls\ZoomControl $zoomControl The zoom control. + */ + protected function assertZoomControlInstance($zoomControl) + { + $this->assertInstanceOf('Ivory\GoogleMap\Controls\ZoomControl', $zoomControl); + } +} diff --git a/tests/Controls/ControlPositionTest.php b/tests/Controls/ControlPositionTest.php index 502a530e..eb4b3313 100644 --- a/tests/Controls/ControlPositionTest.php +++ b/tests/Controls/ControlPositionTest.php @@ -18,25 +18,26 @@ * * @author GeLo */ -class ControlPositionTest extends \PHPUnit_Framework_TestCase +class ControlPositionTest extends AbstractTestCase { - public function testControlPositions() + public function testInheritance() { - $expected = array( - ControlPosition::BOTTOM_CENTER, - ControlPosition::BOTTOM_LEFT, - ControlPosition::BOTTOM_RIGHT, - ControlPosition::LEFT_BOTTOM, - ControlPosition::LEFT_CENTER, - ControlPosition::LEFT_TOP, - ControlPosition::RIGHT_BOTTOM, - ControlPosition::RIGHT_CENTER, - ControlPosition::RIGHT_TOP, - ControlPosition::TOP_CENTER, - ControlPosition::TOP_LEFT, - ControlPosition::TOP_RIGHT - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Controls\ControlPosition'); + } - $this->assertSame($expected, ControlPosition::getControlPositions()); + public function testConstants() + { + $this->assertSame('bottom_center', ControlPosition::BOTTOM_CENTER); + $this->assertSame('bottom_left', ControlPosition::BOTTOM_LEFT); + $this->assertSame('bottom_right', ControlPosition::BOTTOM_RIGHT); + $this->assertSame('left_bottom', ControlPosition::LEFT_BOTTOM); + $this->assertSame('left_center', ControlPosition::LEFT_CENTER); + $this->assertSame('left_top', ControlPosition::LEFT_TOP); + $this->assertSame('right_bottom', ControlPosition::RIGHT_BOTTOM); + $this->assertSame('right_center', ControlPosition::RIGHT_CENTER); + $this->assertSame('right_top', ControlPosition::RIGHT_TOP); + $this->assertSame('top_center', ControlPosition::TOP_CENTER); + $this->assertSame('top_left', ControlPosition::TOP_LEFT); + $this->assertSame('top_right', ControlPosition::TOP_RIGHT); } } diff --git a/tests/Controls/ControlsTest.php b/tests/Controls/ControlsTest.php new file mode 100644 index 00000000..50ef5abe --- /dev/null +++ b/tests/Controls/ControlsTest.php @@ -0,0 +1,311 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Controls; + +use Ivory\GoogleMap\Controls\Controls; + +/** + * Controls test. + * + * @author GeLo + */ +class ControlsTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Controls\Controls */ + protected $controls; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->controls = new Controls(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->controls); + } + + public function testDefaultState() + { + $this->assertNoMapTypeControl(); + $this->assertNoOverviewMapControl(); + $this->assertNoPanControl(); + $this->assertNoRotateControl(); + $this->assertNoScaleControl(); + $this->assertNoStreetViewControl(); + $this->assertNoZoomControl(); + } + + public function testSetMapTypeControl() + { + $this->controls->setMapTypeControl($mapTypeControl = $this->createMapTypeControlMock()); + + $this->assertMapTypeControl($mapTypeControl); + } + + public function testResetMapTypeControl() + { + $this->controls->setMapTypeControl($this->createMapTypeControlMock()); + $this->controls->setMapTypeControl(null); + + $this->assertNoMapTypeControl(); + } + + public function testSetOverviewMapControl() + { + $this->controls->setOverviewMapControl($overviewMapControl = $this->createOverviewMapControlMock()); + + $this->assertOverviewMapControl($overviewMapControl); + } + + public function testResetOverviewMapControl() + { + $this->controls->setOverviewMapControl($this->createOverviewMapControlMock()); + $this->controls->setOverviewMapControl(null); + + $this->assertNoOverviewMapControl(); + } + + public function testSetPanControl() + { + $this->controls->setPanControl($panControl = $this->createPanControlMock()); + + $this->assertPanControl($panControl); + } + + public function testResetPanControl() + { + $this->controls->setPanControl($this->createPanControlMock()); + $this->controls->setPanControl(null); + + $this->assertNoPanControl(); + } + + public function testSetRotateControl() + { + $this->controls->setRotateControl($rotateControl = $this->createRotateControlMock()); + + $this->assertRotateControl($rotateControl); + } + + public function testResetRotateControl() + { + $this->controls->setRotateControl($this->createRotateControlMock()); + $this->controls->setRotateControl(null); + + $this->assertNoRotateControl(); + } + + public function testSetScaleControl() + { + $this->controls->setScaleControl($scaleControl = $this->createScaleControlMock()); + + $this->assertScaleControl($scaleControl); + } + + public function testResetScaleControl() + { + $this->controls->setScaleControl($this->createScaleControlMock()); + $this->controls->setScaleControl(null); + + $this->assertNoScaleControl(); + } + + public function testSetStreetViewControl() + { + $this->controls->setStreetViewControl($streetViewControl = $this->createStreetViewControlMock()); + + $this->assertStreetViewControl($streetViewControl); + } + + public function testStreetViewControlWithNullValue() + { + $this->controls->setStreetViewControl($this->createStreetViewControlMock()); + $this->controls->setStreetViewControl(null); + + $this->assertNoStreetViewControl(); + } + + public function testSetZoomControl() + { + $this->controls->setZoomControl($zoomControl = $this->createZoomControlMock()); + + $this->assertZoomControl($zoomControl); + } + + public function testResetZoomControl() + { + $this->controls->setZoomControl($this->createZoomControlMock()); + $this->controls->setZoomControl(null); + + $this->assertNoZoomControl(); + } + + /** + * Asserts a map type control. + * + * @param \Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl The map type control. + */ + protected function assertMapTypeControl($mapTypeControl) + { + $this->assertMapTypeControlInstance($mapTypeControl); + + $this->assertTrue($this->controls->hasMapTypeControl()); + $this->assertSame($mapTypeControl, $this->controls->getMapTypeControl()); + } + + /** + * Asserts an overview map control. + * + * @param \Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl The overview map control. + */ + protected function assertOverviewMapControl($overviewMapControl) + { + $this->assertOverviewMapControlInstance($overviewMapControl); + + $this->assertTrue($this->controls->hasOverviewMapControl()); + $this->assertSame($overviewMapControl, $this->controls->getOverviewMapControl()); + } + + /** + * Asserts a pan control. + * + * @param \Ivory\GoogleMap\Controls\PanControl $panControl The pan control. + */ + protected function assertPanControl($panControl) + { + $this->assertPanControlInstance($panControl); + + $this->assertTrue($this->controls->hasPanControl()); + $this->assertSame($panControl, $this->controls->getPanControl()); + } + + /** + * Asserts a rotate control. + * + * @param \Ivory\GoogleMap\Controls\RotateControl $rotateControl The rotate control. + */ + protected function assertRotateControl($rotateControl) + { + $this->assertRotateControlInstance($rotateControl); + + $this->assertTrue($this->controls->hasRotateControl()); + $this->assertSame($rotateControl, $this->controls->getRotateControl()); + } + + /** + * Asserts a scale control. + * + * @param \Ivory\GoogleMap\Controls\ScaleControl $scaleControl The scale control. + */ + protected function assertScaleControl($scaleControl) + { + $this->assertScaleControlInstance($scaleControl); + + $this->assertTrue($this->controls->hasScaleControl()); + $this->assertSame($scaleControl, $this->controls->getScaleControl()); + } + + /** + * Asserts a street view control. + * + * @param \Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl The street view control. + */ + protected function assertStreetViewControl($streetViewControl) + { + $this->assertStreetViewControlInstance($streetViewControl); + + $this->assertTrue($this->controls->hasStreetViewControl()); + $this->assertSame($streetViewControl, $this->controls->getStreetViewControl()); + } + + /** + * Asserts a zoom control. + * + * @param \Ivory\GoogleMap\Controls\ZoomControl $zoomControl The zoom control. + */ + protected function assertZoomControl($zoomControl) + { + $this->assertZoomControlInstance($zoomControl); + + $this->assertTrue($this->controls->hasZoomControl()); + $this->assertSame($zoomControl, $this->controls->getZoomControl()); + } + + /** + * Asserts there is no map type control. + */ + protected function assertNoMapTypeControl() + { + $this->assertFalse($this->controls->hasMapTypeControl()); + $this->assertNull($this->controls->getMapTypeControl()); + } + + /** + * Asserts there is no overview map control. + */ + protected function assertNoOverviewMapControl() + { + $this->assertFalse($this->controls->hasOverviewMapControl()); + $this->assertNull($this->controls->getOverviewMapControl()); + } + + /** + * Asserts there is no pan control. + */ + protected function assertNoPanControl() + { + $this->assertFalse($this->controls->hasPanControl()); + $this->assertNull($this->controls->getPanControl()); + } + + /** + * Asserts there is no rotate control. + */ + protected function assertNoRotateControl() + { + $this->assertFalse($this->controls->hasRotateControl()); + $this->assertNull($this->controls->getRotateControl()); + } + + /** + * Asserts there is no scale control. + */ + protected function assertNoScaleControl() + { + $this->assertFalse($this->controls->hasScaleControl()); + $this->assertNull($this->controls->getScaleControl()); + } + + /** + * Asserts there is no street view control. + */ + protected function assertNoStreetViewControl() + { + $this->assertFalse($this->controls->hasStreetViewControl()); + $this->assertNull($this->controls->getStreetViewControl()); + } + + /** + * Asserts there is no zoom control. + */ + protected function assertNoZoomControl() + { + $this->assertFalse($this->controls->hasZoomControl()); + $this->assertNull($this->controls->getZoomControl()); + } +} diff --git a/tests/Controls/MapTypeControlStyleTest.php b/tests/Controls/MapTypeControlStyleTest.php index 5d86ede4..8ec9b506 100644 --- a/tests/Controls/MapTypeControlStyleTest.php +++ b/tests/Controls/MapTypeControlStyleTest.php @@ -18,16 +18,17 @@ * * @author GeLo */ -class MapTypeControlStyleTest extends \PHPUnit_Framework_TestCase +class MapTypeControlStyleTest extends AbstractTestCase { - public function testMapTypeControlStyles() + public function testInheritance() { - $expected = array( - MapTypeControlStyle::DEFAULT_, - MapTypeControlStyle::DROPDOWN_MENU, - MapTypeControlStyle::HORIZONTAL_BAR - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Controls\MapTypeControlStyle'); + } - $this->assertSame($expected, MapTypeControlStyle::getMapTypeControlStyles()); + public function testConstants() + { + $this->assertSame('default', MapTypeControlStyle::DEFAULT_); + $this->assertSame('dropdown_menu', MapTypeControlStyle::DROPDOWN_MENU); + $this->assertSame('horizontal_bar', MapTypeControlStyle::HORIZONTAL_BAR); } } diff --git a/tests/Controls/MapTypeControlTest.php b/tests/Controls/MapTypeControlTest.php index 5ba75bc6..0e979058 100644 --- a/tests/Controls/MapTypeControlTest.php +++ b/tests/Controls/MapTypeControlTest.php @@ -21,7 +21,7 @@ * * @author GeLo */ -class MapTypeControlTest extends \PHPUnit_Framework_TestCase +class MapTypeControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\MapTypeControl */ protected $mapTypeControl; @@ -44,49 +44,135 @@ protected function tearDown() public function testDefaultState() { - $this->assertSame(array(MapTypeId::ROADMAP, MapTypeId::SATELLITE), $this->mapTypeControl->getMapTypeIds()); + $this->assertMapTypeIds(array(MapTypeId::ROADMAP, MapTypeId::SATELLITE)); $this->assertSame(ControlPosition::TOP_RIGHT, $this->mapTypeControl->getControlPosition()); $this->assertSame(MapTypeControlStyle::DEFAULT_, $this->mapTypeControl->getMapTypeControlStyle()); } public function testInitialState() { - $mapTypeIds = array(MapTypeId::HYBRID); - $controlPosition = ControlPosition::LEFT_TOP; - $mapTypeControlStyle = MapTypeControlStyle::HORIZONTAL_BAR; + $this->mapTypeControl = new MapTypeControl( + $mapTypeIds = array(MapTypeId::TERRAIN, MapTypeId::HYBRID), + $controlPosition = ControlPosition::LEFT_TOP, + $mapTypeControlStyle = MapTypeControlStyle::HORIZONTAL_BAR + ); - $this->mapTypeControl = new MapTypeControl($mapTypeIds, $controlPosition, $mapTypeControlStyle); + $this->assertMapTypeIds($mapTypeIds); + $this->assertSame($controlPosition, $this->mapTypeControl->getControlPosition()); + $this->assertSame($mapTypeControlStyle, $this->mapTypeControl->getMapTypeControlStyle()); + } + + public function testSetMapTypeIds() + { + $this->mapTypeControl->setMapTypeIds($mapTypeIds = array(MapTypeId::TERRAIN, MapTypeId::HYBRID)); + + $this->assertMapTypeIds($mapTypeIds); + } + + public function testAddMapTypeIds() + { + $this->mapTypeControl->setMapTypeIds($mapTypeIds = array(MapTypeId::TERRAIN, MapTypeId::HYBRID)); + $this->mapTypeControl->addMapTypeIds($newMapTypeIds = array(MapTypeId::ROADMAP, MapTypeId::SATELLITE)); + + $this->assertMapTypeIds(array_merge($mapTypeIds, $newMapTypeIds)); + } + + public function testRemoveMapTypeIds() + { + $this->mapTypeControl->setMapTypeIds($mapTypeIds = array(MapTypeId::TERRAIN, MapTypeId::HYBRID)); + $this->mapTypeControl->removeMapTypeIds($mapTypeIds); + + $this->assertNoMapTypeIds(); + } + + public function testResetMapTypeIds() + { + $this->mapTypeControl->resetMapTypeIds(); + + $this->assertNoMapTypeIds(); + } + + public function testAddMapTypeId() + { + $this->mapTypeControl->addMapTypeId($mapTypeId = MapTypeId::HYBRID); + + $this->assertMapTypeId($mapTypeId); + } + + public function testAddMapTypeIdUnicity() + { + $this->mapTypeControl->resetMapTypeIds(); + $this->mapTypeControl->addMapTypeId($mapTypeId = MapTypeId::HYBRID); + $this->mapTypeControl->addMapTypeId($mapTypeId); + + $this->assertMapTypeIds(array($mapTypeId)); + } + + public function removeMapTypeId() + { + $this->mapTypeControl->addMapTypeId($mapTypeId = MapTypeId::HYBRID); + $this->mapTypeControl->removeMapTypeId($mapTypeId); + + $this->assertNoMapTypeId($mapTypeId); + } + + public function testSetControlPosition() + { + $this->mapTypeControl->setControlPosition($controlPosition = ControlPosition::LEFT_TOP); - $this->assertSame($mapTypeIds, $this->mapTypeControl->getMapTypeIds()); $this->assertSame($controlPosition, $this->mapTypeControl->getControlPosition()); + } + + public function testSetMapTypeControlStyle() + { + $this->mapTypeControl->setMapTypeControlStyle($mapTypeControlStyle = MapTypeControlStyle::HORIZONTAL_BAR); + $this->assertSame($mapTypeControlStyle, $this->mapTypeControl->getMapTypeControlStyle()); } /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The map type id can only be : hybrid, roadmap, satellite, terrain. + * Asserts the map type ids. + * + * @param array $mapTypeIds The map types ids. + */ + protected function assertMapTypeIds($mapTypeIds) + { + $this->assertInternalType('array', $mapTypeIds); + + $this->assertTrue($this->mapTypeControl->hasMapTypeIds()); + $this->assertSame($mapTypeIds, $this->mapTypeControl->getMapTypeIds()); + + foreach ($mapTypeIds as $mapTypeId) { + $this->assertMapTypeId($mapTypeId); + } + } + + /** + * Asserts a map type id. + * + * @param integer $mapTypeId The map type id. */ - public function testMapTypeIdWithInvalidValue() + protected function assertMapTypeId($mapTypeId) { - $this->mapTypeControl->addMapTypeId('foo'); + $this->assertTrue($this->mapTypeControl->hasMapTypeId($mapTypeId)); } /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The control position can only be : bottom_center, bottom_left, bottom_right, - * left_bottom, left_center, left_top, right_bottom, right_center, right_top, top_center, top_left, top_right. + * Asserts no map type ids. */ - public function testControlPositionWithInvalidValue() + protected function assertNoMapTypeIds() { - $this->mapTypeControl->setControlPosition('foo'); + $this->assertFalse($this->mapTypeControl->hasMapTypeIds()); + $this->assertEmpty($this->mapTypeControl->getMapTypeIds()); } /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The map type control style can only be : default, dropdown_menu, horizontal_bar. + * Asserts no map type id. + * + * @param integer $mapTypeId The map type id. */ - public function testMapTypeControlStyleWithInvalidValue() + protected function assertNoMapTypeId($mapTypeId) { - $this->mapTypeControl->setMapTypeControlStyle('foo'); + $this->assertFalse($this->mapTypeControl->hasMapTypeId($mapTypeId)); } } diff --git a/tests/Controls/OverviewMapControlTest.php b/tests/Controls/OverviewMapControlTest.php index bab1ef5e..6ada598b 100644 --- a/tests/Controls/OverviewMapControlTest.php +++ b/tests/Controls/OverviewMapControlTest.php @@ -18,7 +18,7 @@ * * @author GeLo */ -class OverviewMapControlTest extends \PHPUnit_Framework_TestCase +class OverviewMapControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\OverviewMapControl */ protected $overviewMapControl; @@ -51,12 +51,10 @@ public function testInitialState() $this->assertTrue($this->overviewMapControl->isOpened()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The opened property of an overview map control must be a boolean value. - */ - public function testOpenedWithInvalidValue() + public function testSetOpened() { - $this->overviewMapControl->setOpened('foo'); + $this->overviewMapControl->setOpened(true); + + $this->assertTrue($this->overviewMapControl->isOpened()); } } diff --git a/tests/Controls/PanControlTest.php b/tests/Controls/PanControlTest.php index bed10d3d..fd60f7e8 100644 --- a/tests/Controls/PanControlTest.php +++ b/tests/Controls/PanControlTest.php @@ -19,7 +19,7 @@ * * @author GeLo */ -class PanControlTest extends \PHPUnit_Framework_TestCase +class PanControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\PanControl */ protected $panControl; @@ -47,16 +47,15 @@ public function testDefaultState() public function testInitialState() { - $this->panControl = new PanControl(ControlPosition::LEFT_CENTER); + $this->panControl = new PanControl($controlPosition = ControlPosition::LEFT_CENTER); - $this->assertSame(ControlPosition::LEFT_CENTER, $this->panControl->getControlPosition()); + $this->assertSame($controlPosition, $this->panControl->getControlPosition()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - */ - public function testControlPositionWithInvalidValue() + public function testSetControlPosition() { - $this->panControl->setControlPosition('foo'); + $this->panControl->setControlPosition($controlPosition = ControlPosition::BOTTOM_CENTER); + + $this->assertSame($controlPosition, $this->panControl->getControlPosition()); } } diff --git a/tests/Controls/RotateControlTest.php b/tests/Controls/RotateControlTest.php index 77c3d677..819cac46 100644 --- a/tests/Controls/RotateControlTest.php +++ b/tests/Controls/RotateControlTest.php @@ -19,7 +19,7 @@ * * @author GeLo */ -class RotateControlTest extends \PHPUnit_Framework_TestCase +class RotateControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\RotateControl */ protected $rotateControl; @@ -47,16 +47,15 @@ public function testDefaultState() public function testInitialState() { - $this->rotateControl = new RotateControl(ControlPosition::LEFT_CENTER); + $this->rotateControl = new RotateControl($controlPosition = ControlPosition::LEFT_CENTER); - $this->assertSame(ControlPosition::LEFT_CENTER, $this->rotateControl->getControlPosition()); + $this->assertSame($controlPosition, $this->rotateControl->getControlPosition()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - */ - public function testControlPositionWithInvalidValue() + public function testSetControlPosition() { - $this->rotateControl->setControlPosition('foo'); + $this->rotateControl->setControlPosition($controlPosition = ControlPosition::BOTTOM_CENTER); + + $this->assertSame($controlPosition, $this->rotateControl->getControlPosition()); } } diff --git a/tests/Controls/ScaleControlStyleTest.php b/tests/Controls/ScaleControlStyleTest.php index 382da344..181df453 100644 --- a/tests/Controls/ScaleControlStyleTest.php +++ b/tests/Controls/ScaleControlStyleTest.php @@ -18,12 +18,15 @@ * * @author GeLo */ -class ScaleControlStyleTest extends \PHPUnit_Framework_TestCase +class ScaleControlStyleTest extends AbstractTestCase { - public function testScaleControlStyles() + public function testInheritance() { - $expected = array(ScaleControlStyle::DEFAULT_); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Controls\ScaleControlStyle'); + } - $this->assertSame($expected, ScaleControlStyle::getScaleControlStyles()); + public function testConstants() + { + $this->assertSame('default', ScaleControlStyle::DEFAULT_); } } diff --git a/tests/Controls/ScaleControlTest.php b/tests/Controls/ScaleControlTest.php index e81c1ad4..602f50c7 100644 --- a/tests/Controls/ScaleControlTest.php +++ b/tests/Controls/ScaleControlTest.php @@ -11,7 +11,6 @@ namespace Ivory\Tests\GoogleMap\Controls; -use Ivory\GoogleMap\Controls\ControlPosition; use Ivory\GoogleMap\Controls\ScaleControl; use Ivory\GoogleMap\Controls\ScaleControlStyle; @@ -20,7 +19,7 @@ * * @author GeLo */ -class ScaleControlTest extends \PHPUnit_Framework_TestCase +class ScaleControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\ScaleControl */ protected $scaleControl; @@ -43,32 +42,20 @@ protected function tearDown() public function testDefaultState() { - $this->assertSame(ControlPosition::BOTTOM_LEFT, $this->scaleControl->getControlPosition()); $this->assertSame(ScaleControlStyle::DEFAULT_, $this->scaleControl->getScaleControlStyle()); } public function testInitialState() { - $this->scaleControl = new ScaleControl(ControlPosition::BOTTOM_CENTER, ScaleControlStyle::DEFAULT_); + $this->scaleControl = new ScaleControl($scaleControlStyle = ScaleControlStyle::DEFAULT_); - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->scaleControl->getControlPosition()); - $this->assertSame(ScaleControlStyle::DEFAULT_, $this->scaleControl->getScaleControlStyle()); + $this->assertSame($scaleControlStyle, $this->scaleControl->getScaleControlStyle()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - */ - public function testControlPositionWithInvalidValue() + public function testSetScaleControlStyle() { - $this->scaleControl->setControlPosition('foo'); - } + $this->scaleControl->setScaleControlStyle($scaleControlStyle = ScaleControlStyle::DEFAULT_); - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The scale control style of a scale control can only be : default. - */ - public function testScaleControlStyleWithInvalidValue() - { - $this->scaleControl->setScaleControlStyle('foo'); + $this->assertSame($scaleControlStyle, $this->scaleControl->getScaleControlStyle()); } } diff --git a/tests/Controls/StreetViewControlTest.php b/tests/Controls/StreetViewControlTest.php index b2b244e4..cf3099f0 100644 --- a/tests/Controls/StreetViewControlTest.php +++ b/tests/Controls/StreetViewControlTest.php @@ -19,7 +19,7 @@ * * @author GeLo */ -class StreetViewControlTest extends \PHPUnit_Framework_TestCase +class StreetViewControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\StreetViewControl */ protected $streetViewControl; @@ -47,16 +47,15 @@ public function testDefaultState() public function testInitialState() { - $this->streetViewControl = new StreetViewControl(ControlPosition::BOTTOM_CENTER); + $this->streetViewControl = new StreetViewControl($controlPosition = ControlPosition::BOTTOM_CENTER); - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->streetViewControl->getControlPosition()); + $this->assertSame($controlPosition, $this->streetViewControl->getControlPosition()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - */ - public function testControlPositionWithInvalidValue() + public function testSetControlPosition() { - $this->streetViewControl->setControlPosition('foo'); + $this->streetViewControl->setControlPosition($controlPosition = ControlPosition::BOTTOM_CENTER); + + $this->assertSame($controlPosition, $this->streetViewControl->getControlPosition()); } } diff --git a/tests/Controls/ZoomControlStyleTest.php b/tests/Controls/ZoomControlStyleTest.php index 085ec748..c9e11502 100644 --- a/tests/Controls/ZoomControlStyleTest.php +++ b/tests/Controls/ZoomControlStyleTest.php @@ -18,16 +18,17 @@ * * @author GeLo */ -class ZoomControlStyleTest extends \PHPUnit_Framework_TestCase +class ZoomControlStyleTest extends AbstractTestCase { - public function testZoomControlStyles() + public function testInheritance() { - $expected = array( - ZoomControlStyle::DEFAULT_, - ZoomControlStyle::LARGE, - ZoomControlStyle::SMALL, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Controls\ZoomControlStyle'); + } - $this->assertSame($expected, ZoomControlStyle::getZoomControlStyles()); + public function testConstants() + { + $this->assertSame('default', ZoomControlStyle::DEFAULT_); + $this->assertSame('large', ZoomControlStyle::LARGE); + $this->assertSame('small', ZoomControlStyle::SMALL); } } diff --git a/tests/Controls/ZoomControlTest.php b/tests/Controls/ZoomControlTest.php index 7aa8dd55..b8e108c3 100644 --- a/tests/Controls/ZoomControlTest.php +++ b/tests/Controls/ZoomControlTest.php @@ -20,7 +20,7 @@ * * @author GeLo */ -class ZoomControlTest extends \PHPUnit_Framework_TestCase +class ZoomControlTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Controls\ZoomControl */ protected $zoomControl; @@ -49,26 +49,26 @@ public function testDefaultState() public function testInitialState() { - $this->zoomControl = new ZoomControl(ControlPosition::BOTTOM_CENTER, ZoomControlStyle::LARGE); + $this->zoomControl = new ZoomControl( + $controlPosition = ControlPosition::BOTTOM_CENTER, + $zoomControlStyle = ZoomControlStyle::LARGE + ); - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->zoomControl->getControlPosition()); - $this->assertSame(ZoomControlStyle::LARGE, $this->zoomControl->getZoomControlStyle()); + $this->assertSame($controlPosition, $this->zoomControl->getControlPosition()); + $this->assertSame($zoomControlStyle, $this->zoomControl->getZoomControlStyle()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - */ - public function testControlPositionWithInvalidValue() + public function testSetControlPosition() { - $this->zoomControl->setControlPosition('foo'); + $this->zoomControl->setControlPosition($controlPosition = ControlPosition::BOTTOM_CENTER); + + $this->assertSame($controlPosition, $this->zoomControl->getControlPosition()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ControlException - * @expectedExceptionMessage The zoom control style of a zoom control can only be : default, large, small. - */ - public function testZoomControlStyleWithInvalidValue() + public function testSetZoomControlStyle() { - $this->zoomControl->setZoomControlStyle('foo'); + $this->zoomControl->setZoomControlStyle($zoomControlStyle = ZoomControlStyle::LARGE); + + $this->assertSame($zoomControlStyle, $this->zoomControl->getZoomControlStyle()); } } diff --git a/tests/Events/AbstractTestCase.php b/tests/Events/AbstractTestCase.php new file mode 100644 index 00000000..c36fb7c7 --- /dev/null +++ b/tests/Events/AbstractTestCase.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Events; + +use Ivory\Tests\GoogleMap\Services\AbstractTestCase as TestCase; + +/** + * Events test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a dom event instance. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + */ + protected function assertDomEventInstance($domEvent) + { + $this->assertInstanceOf('Ivory\GoogleMap\Events\DomEvent', $domEvent); + } + + /** + * Asserts an event instance. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + */ + protected function assertEventInstance($event) + { + $this->assertInstanceOf('Ivory\GoogleMap\Events\Event', $event); + } +} diff --git a/tests/Events/DomEventTest.php b/tests/Events/DomEventTest.php new file mode 100644 index 00000000..0a770860 --- /dev/null +++ b/tests/Events/DomEventTest.php @@ -0,0 +1,90 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Events; + +use Ivory\GoogleMap\Events\DomEvent; + +/** + * Dom event test. + * + * @author GeLo + */ +class DomEventTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Events\DomEvent */ + protected $domEvent; + + /** @var string */ + protected $instance; + + /** @var string */ + protected $eventName; + + /** @var string */ + protected $handle; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->domEvent = new DomEvent( + $this->instance = 'instance', + $this->eventName = 'eventName', + $this->handle = 'handle' + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->handle); + unset($this->eventName); + unset($this->instance); + unset($this->event); + } + + public function testInheritance() + { + $this->assertEventInstance($this->domEvent); + } + + public function testDefaultState() + { + $this->assertStringStartsWith('event_', $this->domEvent->getVariable()); + $this->assertSame($this->instance, $this->domEvent->getInstance()); + $this->assertSame($this->eventName, $this->domEvent->getEventName()); + $this->assertSame($this->handle, $this->domEvent->getHandle()); + $this->assertFalse($this->domEvent->isCapture()); + } + + public function testInitialState() + { + $this->domEvent = new DomEvent( + $this->instance, + $this->eventName, + $this->handle, + true + ); + + $this->assertTrue($this->domEvent->isCapture()); + } + + public function testSetCapture() + { + $this->domEvent->setCapture(true); + + $this->assertTrue($this->domEvent->isCapture()); + } +} diff --git a/tests/Events/EventManagerTest.php b/tests/Events/EventManagerTest.php deleted file mode 100644 index a59a16fa..00000000 --- a/tests/Events/EventManagerTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Events; - -use Ivory\GoogleMap\Events\EventManager; - -/** - * Event manager test. - * - * @author GeLo - */ -class EventManagerTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Events\EventManager */ - protected $eventManager; - - /** @var \Ivory\GoogleMap\Events\Event */ - protected $eventMock; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->eventManager = new EventManager(); - $this->eventMock = $this->getMock('Ivory\GoogleMap\Events\Event'); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->eventManager); - unset($this->eventMock); - } - - public function testDefaultState() - { - $this->assertEmpty($this->eventManager->getDomEvents()); - $this->assertEmpty($this->eventManager->getDomEventsOnce()); - $this->assertEmpty($this->eventManager->getEvents()); - $this->assertEmpty($this->eventManager->getEventsOnce()); - } - - public function testInitialState() - { - $domEvents = array($this->getMock('Ivory\GoogleMap\Events\Event')); - $domEventsOnce = array($this->getMock('Ivory\GoogleMap\Events\Event')); - $events = array($this->getMock('Ivory\GoogleMap\Events\Event')); - $eventsOnce = array($this->getMock('Ivory\GoogleMap\Events\Event')); - - $this->eventManager = new EventManager($domEvents, $domEventsOnce, $events, $eventsOnce); - - $this->assertSame($domEvents, $this->eventManager->getDomEvents()); - $this->assertSame($domEventsOnce, $this->eventManager->getDomEventsOnce()); - $this->assertSame($events, $this->eventManager->getEvents()); - $this->assertSame($eventsOnce, $this->eventManager->getEventsOnce()); - } - - public function testDomEvent() - { - $this->eventManager->addDomEvent($this->eventMock); - - $this->assertSame(array($this->eventMock), $this->eventManager->getDomEvents()); - } - - public function testDomEventOnce() - { - $this->eventManager->addDomEventOnce($this->eventMock); - - $this->assertSame(array($this->eventMock), $this->eventManager->getDomEventsOnce()); - } - - public function testEvent() - { - $this->eventManager->addEvent($this->eventMock); - - $this->assertSame(array($this->eventMock), $this->eventManager->getEvents()); - } - - public function testEventOnce() - { - $this->eventManager->addEventOnce($this->eventMock); - - $this->assertSame(array($this->eventMock), $this->eventManager->getEventsOnce()); - } -} diff --git a/tests/Events/EventTest.php b/tests/Events/EventTest.php index da57662b..dd409f4c 100644 --- a/tests/Events/EventTest.php +++ b/tests/Events/EventTest.php @@ -18,17 +18,30 @@ * * @author GeLo */ -class EventTest extends \PHPUnit_Framework_TestCase +class EventTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Events\Event */ protected $event; + /** @var string */ + protected $instance; + + /** @var string */ + protected $eventName; + + /** @var string */ + protected $handle; + /** * {@inheritdoc} */ protected function setUp() { - $this->event = new Event(); + $this->event = new Event( + $this->instance = 'instance', + $this->eventName = 'eventName', + $this->handle = 'handle' + ); } /** @@ -36,88 +49,43 @@ protected function setUp() */ protected function tearDown() { + unset($this->handle); + unset($this->eventName); + unset($this->instance); unset($this->event); } - public function testDefaultState() + public function testInheritance() { - $this->assertNull($this->event->getInstance()); - $this->assertNull($this->event->getEventName()); - $this->assertNull($this->event->getHandle()); - $this->assertFalse($this->event->isCapture()); + $this->assertVariableAssetInstance($this->event); } public function testInitialState() { - $this->event = new Event('foo', 'bar', 'baz', true); - - $this->assertSame('foo', $this->event->getInstance()); - $this->assertSame('bar', $this->event->getEventName()); - $this->assertSame('baz', $this->event->getHandle()); - $this->assertTrue($this->event->isCapture()); - } - - public function testInstanceWithValidValue() - { - $this->event->setInstance('foo'); - - $this->assertSame('foo', $this->event->getInstance()); + $this->assertStringStartsWith('event_', $this->event->getVariable()); + $this->assertSame($this->instance, $this->event->getInstance()); + $this->assertSame($this->eventName, $this->event->getEventName()); + $this->assertSame($this->handle, $this->event->getHandle()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\EventException - * @expectedExceptionMessage The instance of an event must be a string value. - */ - public function testInstanceWithInvalidValue() + public function testSetInstance() { - $this->event->setInstance(true); - } - - public function testEventNameWithValidValue() - { - $this->event->setEventName('foo'); - - $this->assertSame('foo', $this->event->getEventName()); - } + $this->event->setInstance($instance = 'foo'); - /** - * @expectedException \Ivory\GoogleMap\Exception\EventException - * @expectedExceptionMessage The event name of an event must be a string value. - */ - public function testEventNameWithInvalidValue() - { - $this->event->setEventName(true); + $this->assertSame($instance, $this->event->getInstance()); } - public function testHandleWithValidValue() + public function testSetEventName() { - $this->event->setHandle('foo'); + $this->event->setEventName($eventName = 'foo'); - $this->assertSame('foo', $this->event->getHandle()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\EventException - * @expectedExceptionMessage The handle of an event must be a string value. - */ - public function testHandleWithInvalidValue() - { - $this->event->setHandle(true); + $this->assertSame($eventName, $this->event->getEventName()); } - public function testCaptureWithValidValue() + public function testSetHandle() { - $this->event->setCapture(true); - - $this->assertTrue($this->event->isCapture()); - } + $this->event->setHandle($handle = 'foo'); - /** - * @expectedException \Ivory\GoogleMap\Exception\EventException - * @expectedExceptionMessage The capture property of an event must be a boolean value. - */ - public function testCaptureWithInvalidValue() - { - $this->event->setCapture('foo'); + $this->assertSame($handle, $this->event->getHandle()); } } diff --git a/tests/Events/EventsTest.php b/tests/Events/EventsTest.php new file mode 100644 index 00000000..3afdfe27 --- /dev/null +++ b/tests/Events/EventsTest.php @@ -0,0 +1,461 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Events; + +use Ivory\GoogleMap\Events\Events; + +/** + * Events test. + * + * @author GeLo + */ +class EventsTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Events\Events */ + protected $events; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->events = new Events(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->events); + } + + public function testDefaultState() + { + $this->assertNoEvents(); + $this->assertNoEventsOnce(); + $this->assertNoDomEvents(); + $this->assertNoDomEventsOnce(); + } + + public function testSetEvents() + { + $this->events->setEvents($events = array($this->createEventMock())); + + $this->assertEvents($events); + } + + public function testAddEvents() + { + $this->events->setEvents($events = array($this->createEventMock())); + $this->events->addEvents($newEvents = array($this->createEventMock())); + + $this->assertEvents(array_merge($events, $newEvents)); + } + + public function testRemoveEvents() + { + $this->events->setEvents($events = array($this->createEventMock())); + $this->events->removeEvents($events); + + $this->assertNoEvents(); + } + + public function testResetEvents() + { + $this->events->setEvents(array($this->createEventMock())); + $this->events->resetEvents(); + + $this->assertNoEvents(); + } + + public function testAddEvent() + { + $this->events->addEvent($event = $this->createEventMock()); + + $this->assertEvent($event); + } + + public function testAddEventUnicity() + { + $this->events->resetEvents(); + $this->events->addEvent($event = $this->createEventMock()); + $this->events->addEvent($event); + + $this->assertEvents(array($event)); + } + + public function testRemoveEvent() + { + $this->events->addEvent($event = $this->createEventMock()); + $this->events->removeEvent($event); + + $this->assertNoEvent($event); + } + + public function testSetEventsOnce() + { + $this->events->setEventsOnce($eventsOnce = array($this->createEventMock())); + + $this->assertEventsOnce($eventsOnce); + } + + public function testAddEventsOnce() + { + $this->events->setEventsOnce($eventsOnce = array($this->createEventMock())); + $this->events->addEventsOnce($newEventsOnce = array($this->createEventMock())); + + $this->assertEventsOnce(array_merge($eventsOnce, $newEventsOnce)); + } + + public function testRemoveEventsOnce() + { + $this->events->setEventsOnce($eventsOnce = array($this->createEventMock())); + $this->events->removeEventsOnce($eventsOnce); + + $this->assertNoEventsOnce(); + } + + public function testResetEventsOnce() + { + $this->events->setEventsOnce(array($this->createEventMock())); + $this->events->resetEventsOnce(); + + $this->assertNoEventsOnce(); + } + + public function testAddEventOnce() + { + $this->events->addEventOnce($eventOnce = $this->createEventMock()); + + $this->assertEventOnce($eventOnce); + } + + public function testAddEventOnceUnicity() + { + $this->events->resetEventsOnce(); + $this->events->addEventOnce($eventOnce = $this->createEventMock()); + $this->events->addEventOnce($eventOnce); + + $this->assertEventsOnce(array($eventOnce)); + } + + public function testRemoveEventOnce() + { + $this->events->addEventOnce($eventOnce = $this->createEventMock()); + $this->events->removeEventOnce($eventOnce); + + $this->assertNoEventOnce($eventOnce); + } + + public function testSetDomEvents() + { + $this->events->setDomEvents($domEvents = array($this->createDomEventMock())); + + $this->assertDomEvents($domEvents); + } + + public function testAddDomEvents() + { + $this->events->setDomEvents($domEvents = array($this->createDomEventMock())); + $this->events->addDomEvents($newDomEvents = array($this->createDomEventMock())); + + $this->assertDomEvents(array_merge($domEvents, $newDomEvents)); + } + + public function testRemoveDomEvents() + { + $this->events->setDomEvents($domEvents = array($this->createDomEventMock())); + $this->events->removeDomEvents($domEvents); + + $this->assertNoDomEvents(); + } + + public function testResetDomEvents() + { + $this->events->setDomEvents(array($this->createDomEventMock())); + $this->events->resetDomEvents(); + + $this->assertNoDomEvents(); + } + + public function testAddDomEvent() + { + $this->events->addDomEvent($domEvent = $this->createDomEventMock()); + + $this->assertDomEvent($domEvent); + } + + public function testAddDomEventUnicity() + { + $this->events->resetDomEvents(); + $this->events->addDomEvent($domEvent = $this->createDomEventMock()); + $this->events->addDomEvent($domEvent); + + $this->assertDomEvents(array($domEvent)); + } + + public function testRemoveDomEvent() + { + $this->events->addDomEvent($domEvent = $this->createDomEventMock()); + $this->events->removeDomEvent($domEvent); + + $this->assertNoDomEvent($domEvent); + } + + public function testSetDomEventsOnce() + { + $this->events->setDomEventsOnce($domEventsOnce = array($this->createDomEventMock())); + + $this->assertDomEventsOnce($domEventsOnce); + } + + public function testAddDomEventsOnce() + { + $this->events->setDomEventsOnce($domEventsOnce = array($this->createDomEventMock())); + $this->events->addDomEventsOnce($newDomEventsOnce = array($this->createDomEventMock())); + + $this->assertDomEventsOnce(array_merge($domEventsOnce, $newDomEventsOnce)); + } + + public function testRemoveDomEventsOnce() + { + $this->events->setDomEventsOnce($domEventsOnce = array($this->createDomEventMock())); + $this->events->removeDomEventsOnce($domEventsOnce); + + $this->assertNoDomEventsOnce(); + } + + public function testResetDomEventsOnce() + { + $this->events->setDomEventsOnce(array($this->createDomEventMock())); + $this->events->resetDomEventsOnce(); + + $this->assertNoDomEventsOnce(); + } + + public function testAddDomEventOnce() + { + $this->events->addDomEventOnce($domEventOnce = $this->createDomEventMock()); + + $this->assertDomEventOnce($domEventOnce); + } + + public function testAddDomEventOnceUnicity() + { + $this->events->resetDomEventsOnce(); + $this->events->addDomEventOnce($domEventOnce = $this->createDomEventMock()); + $this->events->addDomEventOnce($domEventOnce); + + $this->assertDomEventsOnce(array($domEventOnce)); + } + + public function testRemoveDomEventOnce() + { + $this->events->addDomEventOnce($domEventOnce = $this->createDomEventMock()); + $this->events->removeDomEventOnce($domEventOnce); + + $this->assertNoDomEventOnce($domEventOnce); + } + + /** + * Asserts there are no events. + */ + protected function assertNoEvents() + { + $this->assertFalse($this->events->hasEvents()); + $this->assertEmpty($this->events->getEvents()); + } + + /** + * Asserts there is no event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + */ + protected function assertNoEvent($event) + { + $this->assertEventInstance($event); + $this->assertFalse($this->events->hasEvent($event)); + } + + /** + * Asserts there are no events once. + */ + protected function assertNoEventsOnce() + { + $this->assertFalse($this->events->hasEventsOnce()); + $this->assertEmpty($this->events->getEventsOnce()); + } + + /** + * Asserts there is no event once. + * + * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. + */ + protected function assertNoEventOnce($eventOnce) + { + $this->assertEventInstance($eventOnce); + $this->assertFalse($this->events->hasEventOnce($eventOnce)); + } + + /** + * Asserts there are no dom events. + */ + protected function assertNoDomEvents() + { + $this->assertFalse($this->events->hasDomEvents()); + $this->assertEmpty($this->events->getDomEvents()); + } + + /** + * Asserts there is no dom event. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + */ + protected function assertNoDomEvent($domEvent) + { + $this->assertDomEventInstance($domEvent); + $this->assertFalse($this->events->hasDomEvent($domEvent)); + } + + /** + * Asserts there are no dom events once. + */ + protected function assertNoDomEventsOnce() + { + $this->assertFalse($this->events->hasDomEventsOnce()); + $this->assertEmpty($this->events->getDomEventsOnce()); + } + + /** + * Asserts there is no dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEventOnce The dom event once. + */ + protected function assertNoDomEventOnce($domEventOnce) + { + $this->assertDomEventInstance($domEventOnce); + $this->assertFalse($this->events->hasDomEventOnce($domEventOnce)); + } + + /** + * Asserts there are events. + * + * @param array $events The events. + */ + protected function assertEvents($events) + { + $this->assertInternalType('array', $events); + + $this->assertTrue($this->events->hasEvents()); + $this->assertSame($events, $this->events->getEvents()); + + foreach ($events as $event) { + $this->assertEvent($event); + } + } + + /** + * Asserts there is an event. + * + * @param \Ivory\GoogleMap\Events\Event $event The event. + */ + protected function assertEvent($event) + { + $this->assertEventInstance($event); + $this->assertTrue($this->events->hasEvent($event)); + } + + /** + * Asserts there are dom events once. + * + * @param array $eventsOnce The events once. + */ + protected function assertEventsOnce($eventsOnce) + { + $this->assertInternalType('array', $eventsOnce); + + $this->assertTrue($this->events->hasEventsOnce()); + $this->assertSame($eventsOnce, $this->events->getEventsOnce()); + + foreach ($eventsOnce as $eventOnce) { + $this->assertEventOnce($eventOnce); + } + } + + /** + * Asserts there is an event once. + * + * @param \Ivory\GoogleMap\Events\Event $eventOnce The event once. + */ + protected function assertEventOnce($eventOnce) + { + $this->assertEventInstance($eventOnce); + $this->assertTrue($this->events->hasEventOnce($eventOnce)); + } + + /** + * Asserts there are dom events. + * + * @param array $domEvents The dom events. + */ + protected function assertDomEvents($domEvents) + { + $this->assertInternalType('array', $domEvents); + + $this->assertTrue($this->events->hasDomEvents()); + $this->assertSame($domEvents, $this->events->getDomEvents()); + + foreach ($domEvents as $domEvent) { + $this->assertDomEvent($domEvent); + } + } + + /** + * Asserts there is a dom event. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEvent The dom event. + */ + protected function assertDomEvent($domEvent) + { + $this->assertDomEventInstance($domEvent); + $this->assertTrue($this->events->hasDomEvent($domEvent)); + } + + /** + * Asserts there are dom events once. + * + * @param array $domEventsOnce The dom events once. + */ + protected function assertDomEventsOnce($domEventsOnce) + { + $this->assertInternalType('array', $domEventsOnce); + + $this->assertTrue($this->events->hasDomEventsOnce()); + $this->assertSame($domEventsOnce, $this->events->getDomEventsOnce()); + + foreach ($domEventsOnce as $domEventOnce) { + $this->assertDomEventOnce($domEventOnce); + } + } + + /** + * Asserts there is a dom event once. + * + * @param \Ivory\GoogleMap\Events\DomEvent $domEventOnce The dom event once. + */ + protected function assertDomEventOnce($domEventOnce) + { + $this->assertDomEventInstance($domEventOnce); + $this->assertTrue($this->events->hasDomEventOnce($domEventOnce)); + } +} diff --git a/tests/Events/MouseEventTest.php b/tests/Events/MouseEventTest.php index 53c49be0..97c5459b 100644 --- a/tests/Events/MouseEventTest.php +++ b/tests/Events/MouseEventTest.php @@ -18,19 +18,20 @@ * * @author GeLo */ -class MouseEventTest extends \PHPUnit_Framework_TestCase +class MouseEventTest extends AbstractTestCase { - public function testMouseEvents() + public function testInheritance() { - $expected = array( - MouseEvent::CLICK, - MouseEvent::DBLCLICK, - MouseEvent::MOUSEUP, - MouseEvent::MOUSEDOWN, - MouseEvent::MOUSEOVER, - MouseEvent::MOUSEOUT, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Events\MouseEvent'); + } - $this->assertSame($expected, MouseEvent::getMouseEvents()); + public function testConstants() + { + $this->assertSame('click', MouseEvent::CLICK); + $this->assertSame('dblclick', MouseEvent::DBLCLICK); + $this->assertSame('mouseup', MouseEvent::MOUSEUP); + $this->assertSame('mousedown', MouseEvent::MOUSEDOWN); + $this->assertSame('mouseover', MouseEvent::MOUSEOVER); + $this->assertSame('mouseout', MouseEvent::MOUSEOUT); } } diff --git a/tests/Helper/AbstractHelperTest.php b/tests/Helper/AbstractHelperTest.php deleted file mode 100644 index e319115a..00000000 --- a/tests/Helper/AbstractHelperTest.php +++ /dev/null @@ -1,58 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper; - -/** - * Abstract helper test. - * - * @author GeLo - */ -class AbstractHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\AbstractHelper */ - protected $helper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->helper = $this->getMockForAbstractClass('Ivory\GoogleMap\Helper\AbstractHelper'); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->helper); - } - - public function testInitialState() - { - $this->assertInstanceOf('Ivory\JsonBuilder\JsonBuilder', $this->helper->getJsonBuilder()); - } - - public function testJsContainerName() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('foo')); - - $method = new \ReflectionMethod($this->helper, 'getJsContainerName'); - $method->setAccessible(true); - - $this->assertSame('foo_container', $method->invoke($this->helper, $map)); - } -} diff --git a/tests/Helper/ApiHelperTest.php b/tests/Helper/ApiHelperTest.php deleted file mode 100644 index e49a9255..00000000 --- a/tests/Helper/ApiHelperTest.php +++ /dev/null @@ -1,135 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper; - -use Ivory\GoogleMap\Helper\ApiHelper; - -/** - * Api helper test. - * - * @author GeLo - */ -class ApiHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\ApiHelper */ - protected $apiHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->apiHelper = new ApiHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->apiHelper); - } - - public function testDefaultState() - { - $this->assertFalse($this->apiHelper->isLoaded()); - } - - public function testLoaded() - { - $this->apiHelper->render(); - - $this->assertTrue($this->apiHelper->isLoaded()); - - $this->apiHelper->isLoaded(false); - - $this->assertFalse($this->apiHelper->isLoaded()); - } - - public function testRenderWithDefaultValues() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render()); - } - - public function testRenderWithLanguage() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=fr&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render('fr')); - } - - public function testRenderWithoutLibraries() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render('en', array())); - } - - public function testRenderWithLibraries() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=geometry,places&language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render('en', array('geometry', 'places'))); - } - - public function testRenderWithCallback() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false","callback":callback}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render('en', array(), 'callback')); - } - - public function testRenderWithSensor() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=true"}); }; - - - -EOF; - - $this->assertSame($expected, $this->apiHelper->render('en', array(), null, true)); - } -} diff --git a/tests/Helper/Base/BoundHelperTest.php b/tests/Helper/Base/BoundHelperTest.php deleted file mode 100644 index 1f976edc..00000000 --- a/tests/Helper/Base/BoundHelperTest.php +++ /dev/null @@ -1,146 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Helper\Base\BoundHelper; - -/** - * Bound helper test - * - * @author GeLo - */ -class BoundHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Base\BoundHelper */ - protected $boundHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->boundHelper = new BoundHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->boundHelper); - } - - public function testRenderWithEmptyBound() - { - $bound = new Bound(); - $bound->setJavascriptVariable('foo'); - - $this->assertSame('foo = new google.maps.LatLngBounds();'.PHP_EOL, $this->boundHelper->render($bound)); - } - - public function testRenderWithBound() - { - $coordinate1 = new Coordinate(-1.1, -2.1, false); - $coordinate1->setJavascriptVariable('foo'); - - $coordinate2 = new Coordinate(1.1, 2.1, true); - $coordinate2->setJavascriptVariable('bar'); - - $bound = new Bound($coordinate1, $coordinate2); - $bound->setJavascriptVariable('baz'); - - $this->assertSame('baz = new google.maps.LatLngBounds(foo, bar);'.PHP_EOL, $this->boundHelper->render($bound)); - } - - public function testRenderExtends() - { - $bound = new Bound(); - $bound->setJavascriptVariable('bound'); - - $circle = $this->getMock('Ivory\GoogleMap\Overlays\Circle'); - $circle - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('circle')); - - $groundOverlayBound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $groundOverlayBound - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('groundOverlayBound')); - - $groundOverlay = $this->getMock('Ivory\GoogleMap\Overlays\GroundOverlay'); - $groundOverlay - ->expects($this->once()) - ->method('getBound') - ->will($this->returnValue($groundOverlayBound)); - - $infoWindow = $this->getMock('Ivory\GoogleMap\Overlays\InfoWindow'); - $infoWindow - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('infoWindow')); - - $marker = $this->getMock('Ivory\GoogleMap\Overlays\Marker'); - $marker - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('marker')); - - $polygon = $this->getMock('Ivory\GoogleMap\Overlays\Polygon'); - $polygon - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('polygon')); - - $polyline = $this->getMock('Ivory\GoogleMap\Overlays\Polyline'); - $polyline - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('polyline')); - - $rectangleBound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $rectangleBound - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('rectangleBound')); - - $rectangle = $this->getMock('Ivory\GoogleMap\Overlays\Rectangle'); - $rectangle - ->expects($this->once()) - ->method('getBound') - ->will($this->returnValue($rectangleBound)); - - $bound->extend($circle); - $bound->extend($groundOverlay); - $bound->extend($infoWindow); - $bound->extend($marker); - $bound->extend($polygon); - $bound->extend($polyline); - $bound->extend($rectangle); - - $expected = <<assertSame($expected, $this->boundHelper->renderExtends($bound)); - } -} diff --git a/tests/Helper/Base/CoordinateHelperTest.php b/tests/Helper/Base/CoordinateHelperTest.php deleted file mode 100644 index cd146cdc..00000000 --- a/tests/Helper/Base/CoordinateHelperTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Coordinate; -use Ivory\GoogleMap\Helper\Base\CoordinateHelper; - -/** - * Coordinate helper test - * - * @author GeLo - */ -class CoordinateHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Base\CoordinateHelper */ - protected $coordinateHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->coordinateHelper = new CoordinateHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->coordinateHelper); - } - - public function testRender() - { - $coordinate = new Coordinate(1.1, 2.1, true); - $coordinate->setJavascriptVariable('foo'); - - $this->assertSame( - 'foo = new google.maps.LatLng(1.1, 2.1, true);'.PHP_EOL, - $this->coordinateHelper->render($coordinate) - ); - } -} diff --git a/tests/Helper/Base/PointHelperTest.php b/tests/Helper/Base/PointHelperTest.php deleted file mode 100644 index 5311443d..00000000 --- a/tests/Helper/Base/PointHelperTest.php +++ /dev/null @@ -1,42 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Point; -use Ivory\GoogleMap\Helper\Base\PointHelper; - -/** - * Point helper test. - * - * @author GeLo - */ -class PointHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Base\PointHelper */ - protected $pointHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->pointHelper = new PointHelper(); - } - - public function testRender() - { - $point = new Point(1.1, 2.1); - $point->setJavascriptVariable('foo'); - - $this->assertSame('foo = new google.maps.Point(1.1, 2.1);'.PHP_EOL, $this->pointHelper->render($point)); - } -} diff --git a/tests/Helper/Base/SizeHelperTest.php b/tests/Helper/Base/SizeHelperTest.php deleted file mode 100644 index 9c1b7df8..00000000 --- a/tests/Helper/Base/SizeHelperTest.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Base; - -use Ivory\GoogleMap\Base\Size; -use Ivory\GoogleMap\Helper\Base\SizeHelper; - -/** - * Size helper test. - * - * @author GeLo - */ -class SizeHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Base\SizeHelper */ - protected $sizeHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->sizeHelper = new SizeHelper(); - } - - public function testRenderWithoutUnits() - { - $size = new Size(1.1, 2.1); - $size->setJavascriptVariable('foo'); - - $this->assertSame('foo = new google.maps.Size(1.1, 2.1);'.PHP_EOL, $this->sizeHelper->render($size)); - } - - public function testRenderWithUnits() - { - $size = new Size(1.1, 2.1, 'px', '%'); - $size->setJavascriptVariable('foo'); - - $this->assertSame('foo = new google.maps.Size(1.1, 2.1, "px", "%");'.PHP_EOL, $this->sizeHelper->render($size)); - } -} diff --git a/tests/Helper/Controls/ControlPositionHelperTest.php b/tests/Helper/Controls/ControlPositionHelperTest.php deleted file mode 100644 index ed4d7a8b..00000000 --- a/tests/Helper/Controls/ControlPositionHelperTest.php +++ /dev/null @@ -1,115 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Helper\Controls\ControlPositionHelper; - -/** - * Control position helper test. - * - * @author GeLo - */ -class ControlPositionHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ControlPositionHelper */ - protected $controlPositionHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->controlPositionHelper = new ControlPositionHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->controlPositionHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame( - 'google.maps.ControlPosition.BOTTOM_CENTER', - $this->controlPositionHelper->render(ControlPosition::BOTTOM_CENTER) - ); - - $this->assertSame( - 'google.maps.ControlPosition.BOTTOM_LEFT', - $this->controlPositionHelper->render(ControlPosition::BOTTOM_LEFT) - ); - - $this->assertSame( - 'google.maps.ControlPosition.BOTTOM_RIGHT', - $this->controlPositionHelper->render(ControlPosition::BOTTOM_RIGHT) - ); - - $this->assertSame( - 'google.maps.ControlPosition.LEFT_BOTTOM', - $this->controlPositionHelper->render(ControlPosition::LEFT_BOTTOM) - ); - - $this->assertSame( - 'google.maps.ControlPosition.LEFT_CENTER', - $this->controlPositionHelper->render(ControlPosition::LEFT_CENTER) - ); - - $this->assertSame( - 'google.maps.ControlPosition.LEFT_TOP', - $this->controlPositionHelper->render(ControlPosition::LEFT_TOP) - ); - - $this->assertSame( - 'google.maps.ControlPosition.RIGHT_BOTTOM', - $this->controlPositionHelper->render(ControlPosition::RIGHT_BOTTOM) - ); - - $this->assertSame( - 'google.maps.ControlPosition.RIGHT_CENTER', - $this->controlPositionHelper->render(ControlPosition::RIGHT_CENTER) - ); - - $this->assertSame( - 'google.maps.ControlPosition.RIGHT_TOP', - $this->controlPositionHelper->render(ControlPosition::RIGHT_TOP) - ); - - $this->assertSame( - 'google.maps.ControlPosition.TOP_CENTER', - $this->controlPositionHelper->render(ControlPosition::TOP_CENTER) - ); - - $this->assertSame( - 'google.maps.ControlPosition.TOP_LEFT', - $this->controlPositionHelper->render(ControlPosition::TOP_LEFT) - ); - - $this->assertSame( - 'google.maps.ControlPosition.TOP_RIGHT', - $this->controlPositionHelper->render(ControlPosition::TOP_RIGHT) - ); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The control position can only be : bottom_center, bottom_left, bottom_right, - * left_bottom, left_center, left_top, right_bottom, right_center, right_top, top_center, top_left, top_right. - */ - public function testRenderWithInvalidValue() - { - $this->controlPositionHelper->render('foo'); - } -} diff --git a/tests/Helper/Controls/MapTypeControlHelperTest.php b/tests/Helper/Controls/MapTypeControlHelperTest.php deleted file mode 100644 index 6161bf04..00000000 --- a/tests/Helper/Controls/MapTypeControlHelperTest.php +++ /dev/null @@ -1,97 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControl; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\MapTypeId; -use Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper; - -/** - * Map type control helper test. - * - * @author GeLo - */ -class MapTypeControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper */ - protected $mapTypeControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->mapTypeControlHelper = new MapTypeControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->mapTypeControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\MapTypeIdHelper', - $this->mapTypeControlHelper->getMapTypeIdHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->mapTypeControlHelper->getControlPositionHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper', - $this->mapTypeControlHelper->getMapTypeControlStyleHelper() - ); - } - - public function testInitialState() - { - $mapTypeIdHelper = $this->getMock('Ivory\GoogleMap\Helper\MapTypeIdHelper'); - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - $mapTypeControlStyleHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper'); - - $this->mapTypeControlHelper = new MapTypeControlHelper( - $mapTypeIdHelper, - $controlPositionHelper, - $mapTypeControlStyleHelper - ); - - $this->assertSame($mapTypeIdHelper, $this->mapTypeControlHelper->getMapTypeIdHelper()); - $this->assertSame($controlPositionHelper, $this->mapTypeControlHelper->getControlPositionHelper()); - $this->assertSame($mapTypeControlStyleHelper, $this->mapTypeControlHelper->getMapTypeControlStyleHelper()); - } - - public function testRender() - { - $mapTypeControl = new MapTypeControl( - array(MapTypeId::ROADMAP), - ControlPosition::BOTTOM_CENTER, - MapTypeControlStyle::DROPDOWN_MENU - ); - - $expected = '{'. - '"mapTypeIds":[google.maps.MapTypeId.ROADMAP],'. - '"position":google.maps.ControlPosition.BOTTOM_CENTER,'. - '"style":google.maps.MapTypeControlStyle.DROPDOWN_MENU'. - '}'; - - $this->assertSame($expected, $this->mapTypeControlHelper->render($mapTypeControl)); - } -} diff --git a/tests/Helper/Controls/MapTypeControlStyleHelperTest.php b/tests/Helper/Controls/MapTypeControlStyleHelperTest.php deleted file mode 100644 index dd5150a9..00000000 --- a/tests/Helper/Controls/MapTypeControlStyleHelperTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper; - -/** - * Map type control style helper test. - * - * @author GeLo - */ -class MapTypeControlStyleHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\MapTypeControlStyleHelper */ - protected $mapTypeControlStyleHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->mapTypeControlStyleHelper = new MapTypeControlStyleHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->mapTypeControlStyleHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame( - 'google.maps.MapTypeControlStyle.DEFAULT', - $this->mapTypeControlStyleHelper->render(MapTypeControlStyle::DEFAULT_) - ); - - $this->assertSame( - 'google.maps.MapTypeControlStyle.DROPDOWN_MENU', - $this->mapTypeControlStyleHelper->render(MapTypeControlStyle::DROPDOWN_MENU) - ); - - $this->assertSame( - 'google.maps.MapTypeControlStyle.HORIZONTAL_BAR', - $this->mapTypeControlStyleHelper->render(MapTypeControlStyle::HORIZONTAL_BAR) - ); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The map type control style can only be : default, dropdown_menu, horizontal_bar. - */ - public function testRenderWithInvalidValue() - { - $this->mapTypeControlStyleHelper->render('foo'); - } -} diff --git a/tests/Helper/Controls/OverviewMapControlHelperTest.php b/tests/Helper/Controls/OverviewMapControlHelperTest.php deleted file mode 100644 index 57080d23..00000000 --- a/tests/Helper/Controls/OverviewMapControlHelperTest.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\OverviewMapControl; -use Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper; - -/** - * Overview map control helper test. - * - * @author GeLo - */ -class OverviewMapControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper */ - protected $overviewMapControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->overviewMapControlHelper = new OverviewMapControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->overviewMapControlHelper); - } - - public function testRender() - { - $overviewMapControl = new OverviewMapControl(true); - - $this->assertSame('{"opened":true}', $this->overviewMapControlHelper->render($overviewMapControl)); - } -} diff --git a/tests/Helper/Controls/PanControlHelperTest.php b/tests/Helper/Controls/PanControlHelperTest.php deleted file mode 100644 index 13ccffc0..00000000 --- a/tests/Helper/Controls/PanControlHelperTest.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\PanControl; -use Ivory\GoogleMap\Helper\Controls\PanControlHelper; - -/** - * Overview map control helper test. - * - * @author GeLo - */ -class PanControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\PanControlHelper */ - protected $panControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->panControlHelper = new PanControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->panControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->panControlHelper->getControlPositionHelper() - ); - } - - public function testInitialState() - { - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - - $this->panControlHelper = new PanControlHelper($controlPositionHelper); - - $this->assertSame($controlPositionHelper, $this->panControlHelper->getControlPositionHelper()); - } - - public function testRender() - { - $panControl = new PanControl(ControlPosition::BOTTOM_CENTER); - - $this->assertSame( - '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', - $this->panControlHelper->render($panControl) - ); - } -} diff --git a/tests/Helper/Controls/RotateControlHelperTest.php b/tests/Helper/Controls/RotateControlHelperTest.php deleted file mode 100644 index 005e6da2..00000000 --- a/tests/Helper/Controls/RotateControlHelperTest.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\RotateControl; -use Ivory\GoogleMap\Helper\Controls\RotateControlHelper; - -/** - * Rotate control helper test. - * - * @author GeLo - */ -class RotateControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\RotateControlHelper */ - protected $rotateControlHelper; - - /**p - * {@inheritdoc} - */ - protected function setUp() - { - $this->rotateControlHelper = new RotateControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->rotateControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->rotateControlHelper->getControlPositionHelper() - ); - } - - public function testInitialState() - { - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - - $this->rotateControlHelper = new RotateControlHelper($controlPositionHelper); - - $this->assertSame($controlPositionHelper, $this->rotateControlHelper->getControlPositionHelper()); - } - - public function testRender() - { - $rotateControl = new RotateControl(ControlPosition::BOTTOM_CENTER); - - $this->assertSame( - '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', - $this->rotateControlHelper->render($rotateControl) - ); - } -} diff --git a/tests/Helper/Controls/ScaleControlHelperTest.php b/tests/Helper/Controls/ScaleControlHelperTest.php deleted file mode 100644 index f274538f..00000000 --- a/tests/Helper/Controls/ScaleControlHelperTest.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ScaleControl; -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Helper\Controls\ScaleControlHelper; - -/** - * Scale control helper test. - * - * @author GeLo - */ -class ScaleControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ScaleControlHelper */ - protected $scaleControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->scaleControlHelper = new ScaleControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->scaleControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->scaleControlHelper->getControlPositionHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper', - $this->scaleControlHelper->getScaleControlStyleHelper() - ); - } - - public function testInitialState() - { - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - $scaleControlStyleHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper'); - - $this->scaleControlHelper = new ScaleControlHelper($controlPositionHelper, $scaleControlStyleHelper); - - $this->assertSame($controlPositionHelper, $this->scaleControlHelper->getControlPositionHelper()); - $this->assertSame($scaleControlStyleHelper, $this->scaleControlHelper->getScaleControlStyleHelper()); - } - - public function testRender() - { - $scaleControl = new ScaleControl(ControlPosition::BOTTOM_CENTER, ScaleControlStyle::DEFAULT_); - - $this->assertSame( - '{"position":google.maps.ControlPosition.BOTTOM_CENTER,"style":google.maps.ScaleControlStyle.DEFAULT}', - $this->scaleControlHelper->render($scaleControl) - ); - } -} diff --git a/tests/Helper/Controls/ScaleControlStyleHelperTest.php b/tests/Helper/Controls/ScaleControlStyleHelperTest.php deleted file mode 100644 index 44e16c30..00000000 --- a/tests/Helper/Controls/ScaleControlStyleHelperTest.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper; - -/** - * Scale control style helper test. - * - * @author GeLo - */ -class ScaleControlStyleHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var Ivory\GoogleMap\Helper\Controls\ScaleControlStyleHelper */ - protected $scaleControlStyleHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->scaleControlStyleHelper = new ScaleControlStyleHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->scaleControlStyleHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame( - 'google.maps.ScaleControlStyle.DEFAULT', - $this->scaleControlStyleHelper->render(ScaleControlStyle::DEFAULT_) - ); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The scale control style can only be : default. - */ - public function testRenderWithInvalidValue() - { - $this->scaleControlStyleHelper->render('foo'); - } -} diff --git a/tests/Helper/Controls/StreetViewControlHelperTest.php b/tests/Helper/Controls/StreetViewControlHelperTest.php deleted file mode 100644 index ed5b08a2..00000000 --- a/tests/Helper/Controls/StreetViewControlHelperTest.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\StreetViewControl; -use Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper; - -/** - * Street view control helper test. - * - * @author GeLo - */ -class StreetViewControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper */ - protected $streetViewControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->streetViewControlHelper = new StreetViewControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->streetViewControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->streetViewControlHelper->getControlPositionHelper() - ); - } - - public function testInitialState() - { - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - - $this->streetViewControlHelper = new StreetViewControlHelper($controlPositionHelper); - - $this->assertSame($controlPositionHelper, $this->streetViewControlHelper->getControlPositionHelper()); - } - - public function testRender() - { - $streetViewControl = new StreetViewControl(ControlPosition::BOTTOM_CENTER); - - $this->assertSame( - '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', - $this->streetViewControlHelper->render($streetViewControl) - ); - } -} diff --git a/tests/Helper/Controls/ZoomControlHelperTest.php b/tests/Helper/Controls/ZoomControlHelperTest.php deleted file mode 100644 index b4f0bfd1..00000000 --- a/tests/Helper/Controls/ZoomControlHelperTest.php +++ /dev/null @@ -1,78 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\ZoomControl; -use Ivory\GoogleMap\Controls\ZoomControlStyle; -use Ivory\GoogleMap\Helper\Controls\ZoomControlHelper; - -/** - * Zoom control helper test. - * - * @author GeLo - */ -class ZoomControlHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ZoomControlHelper */ - protected $zoomControlHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->zoomControlHelper = new ZoomControlHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->zoomControlHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ControlPositionHelper', - $this->zoomControlHelper->getControlPositionHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper', - $this->zoomControlHelper->getZoomControlStyleHelper() - ); - } - - public function testInitialState() - { - $controlPositionHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ControlPositionHelper'); - $zoomControlStyleHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper'); - - $this->zoomControlHelper = new ZoomControlHelper($controlPositionHelper, $zoomControlStyleHelper); - - $this->assertSame($controlPositionHelper, $this->zoomControlHelper->getControlPositionHelper()); - $this->assertSame($zoomControlStyleHelper, $this->zoomControlHelper->getZoomControlStyleHelper()); - } - - public function testRender() - { - $zoomControlTest = new ZoomControl(ControlPosition::BOTTOM_CENTER, ZoomControlStyle::SMALL); - - $this->assertSame( - '{"position":google.maps.ControlPosition.BOTTOM_CENTER,"style":google.maps.ZoomControlStyle.SMALL}', - $this->zoomControlHelper->render($zoomControlTest) - ); - } -} diff --git a/tests/Helper/Controls/ZoomControlStyleHelperTest.php b/tests/Helper/Controls/ZoomControlStyleHelperTest.php deleted file mode 100644 index 4b8fb51b..00000000 --- a/tests/Helper/Controls/ZoomControlStyleHelperTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Controls\ZoomControlStyle; -use Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper; - -/** - * Zoom control style helper test. - * - * @author GeLo - */ -class ZoomControlStyleHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Controls\ZoomControlStyleHelper */ - protected $zoomControlStyleHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->zoomControlStyleHelper = new ZoomControlStyleHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->zoomControlStyleHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame( - 'google.maps.ZoomControlStyle.DEFAULT', - $this->zoomControlStyleHelper->render(ZoomControlStyle::DEFAULT_) - ); - - $this->assertSame( - 'google.maps.ZoomControlStyle.LARGE', - $this->zoomControlStyleHelper->render(ZoomControlStyle::LARGE) - ); - - $this->assertSame( - 'google.maps.ZoomControlStyle.SMALL', - $this->zoomControlStyleHelper->render(ZoomControlStyle::SMALL) - ); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The zoom control style can only be : default, large, small. - */ - public function testRenderWithInvalidValue() - { - $this->zoomControlStyleHelper->render('foo'); - } -} diff --git a/tests/Helper/Events/EventManagerHelperTest.php b/tests/Helper/Events/EventManagerHelperTest.php deleted file mode 100644 index 30953008..00000000 --- a/tests/Helper/Events/EventManagerHelperTest.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Controls; - -use Ivory\GoogleMap\Events\Event; -use Ivory\GoogleMap\Helper\Events\EventManagerHelper; - -/** - * Event manager helper test. - * - * @author GeLo - */ -class EventManagerHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Events\EventHelper */ - protected $eventManagerHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->eventManagerHelper = new EventManagerHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->eventManagerHelper); - } - - public function testRenderDomEvent() - { - $domEvent = new Event('instance', 'event_name', 'handle', true); - $domEvent->setJavascriptVariable('foo'); - - $this->assertSame( - 'foo = google.maps.event.addDomListener(instance, "event_name", handle, true);'.PHP_EOL, - $this->eventManagerHelper->renderDomEvent($domEvent) - ); - } - - public function testRenderDomEventOnce() - { - $domEventOnce = new Event('instance', 'event_name', 'handle', true); - $domEventOnce->setJavascriptVariable('foo'); - - $this->assertSame( - 'foo = google.maps.event.addDomListenerOnce(instance, "event_name", handle, true);'.PHP_EOL, - $this->eventManagerHelper->renderDomEventOnce($domEventOnce) - ); - } - - public function testRenderEvent() - { - $event = new Event('instance', 'event_name', 'handle', true); - $event->setJavascriptVariable('foo'); - - $this->assertSame( - 'foo = google.maps.event.addListener(instance, "event_name", handle);'.PHP_EOL, - $this->eventManagerHelper->renderEvent($event) - ); - } - - public function testRenderEventOnce() - { - $eventOnce = new Event('instance', 'event_name', 'handle'); - $eventOnce->setJavascriptVariable('foo'); - - $this->assertSame( - 'foo = google.maps.event.addListenerOnce(instance, "event_name", handle);'.PHP_EOL, - $this->eventManagerHelper->renderEventOnce($eventOnce) - ); - } -} diff --git a/tests/Helper/Extension/CoreExtensionHelperTest.php b/tests/Helper/Extension/CoreExtensionHelperTest.php deleted file mode 100644 index a5cc044f..00000000 --- a/tests/Helper/Extension/CoreExtensionHelperTest.php +++ /dev/null @@ -1,149 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Extension; - -use Ivory\GoogleMap\Helper\Extension\CoreExtensionHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\EncodedPolyline; - -/** - * Core extension helper test. - * - * @author GeLo - */ -class CoreExtensionHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Extension\CoreExtensionHelper */ - protected $coreExtensionHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->coreExtensionHelper = new CoreExtensionHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->coreExtensionHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf('Ivory\GoogleMap\Helper\ApiHelper', $this->coreExtensionHelper->getApiHelper()); - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper', - $this->coreExtensionHelper->getMarkerClusterHelper() - ); - } - - public function testInitialState() - { - $apiHelper = $this->getMock('Ivory\GoogleMap\Helper\ApiHelper'); - $markerClusterHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper'); - - $this->coreExtensionHelper = new CoreExtensionHelper($apiHelper, $markerClusterHelper); - - $this->assertSame($apiHelper, $this->coreExtensionHelper->getApiHelper()); - $this->assertSame($markerClusterHelper, $this->coreExtensionHelper->getMarkerClusterHelper()); - } - - public function testRenderLibrariesWithDefaultMap() - { - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->coreExtensionHelper->renderLibraries(new Map())); - } - - public function testRenderLibrariesWithAsyncMap() - { - $map = new Map(); - $map->setAsync(true); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false","callback":load_ivory_google_map}); }; - - - -EOF; - - $this->assertSame($expected, $this->coreExtensionHelper->renderLibraries($map)); - } - - public function testRenderLibrariesWithMapLibrariesAndEncodedPolylines() - { - $map = new Map(); - $map->setLibraries(array('places')); - $map->addEncodedPolyline(new EncodedPolyline('foo')); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places,geometry&language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected, $this->coreExtensionHelper->renderLibraries($map)); - } - - public function testRenderLibrariesWithMultipleMaps() - { - $expected1 = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - -EOF; - - $this->assertSame($expected1, $this->coreExtensionHelper->renderLibraries(new Map())); - $this->assertNull($this->coreExtensionHelper->renderLibraries(new Map())); - } - - public function testRenderBeforeWithDefaultMap() - { - $this->assertNull($this->coreExtensionHelper->renderBefore(new Map())); - } - - public function testRenderBeforeWithAsyncMap() - { - $map = new Map(); - $map->setAsync(true); - - $this->assertSame('function load_ivory_google_map() {'.PHP_EOL, $this->coreExtensionHelper->renderBefore($map)); - } - - public function testRenderAfterWithDefaultMap() - { - $this->assertNull($this->coreExtensionHelper->renderAfter(new Map())); - } - - public function testRenderAfterWithAsyncMap() - { - $map = new Map(); - $map->setAsync(true); - - $this->assertSame('}'.PHP_EOL, $this->coreExtensionHelper->renderAfter($map)); - } -} diff --git a/tests/Helper/Extension/InfoBoxExtensionHelperTest.php b/tests/Helper/Extension/InfoBoxExtensionHelperTest.php deleted file mode 100644 index 188b797d..00000000 --- a/tests/Helper/Extension/InfoBoxExtensionHelperTest.php +++ /dev/null @@ -1,134 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Extension; - -use Ivory\GoogleMap\Helper\Extension\InfoBoxExtensionHelper; - -/** - * InfoBox extension helper test. - * - * @author GeLo - */ -class InfoBoxExtensionHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Extension\InfoBoxExtensionHelper */ - protected $infoBoxExtensionHelper; - - /** - * {@ineritdoc} - */ - protected function setUp() - { - $this->infoBoxExtensionHelper = new InfoBoxExtensionHelper(); - } - - /** - * {@ineritdoc} - */ - protected function tearDown() - { - unset($this->infoBoxExtensionHelper); - } - - public function testDefaultState() - { - $this->assertSame( - '//google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js', - $this->infoBoxExtensionHelper->getSource() - ); - - $this->assertSame('load_ivory_google_map_info_box', $this->infoBoxExtensionHelper->getCallback()); - } - - public function testInitialState() - { - $this->infoBoxExtensionHelper = new InfoBoxExtensionHelper('foo', 'bar'); - - $this->assertSame('foo', $this->infoBoxExtensionHelper->getSource()); - $this->assertSame('bar', $this->infoBoxExtensionHelper->getCallback()); - } - - public function testRenderLibrariesWithSyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $expected = << - -EOF; - - $this->assertSame($expected, $this->infoBoxExtensionHelper->renderLibraries($map)); - } - - public function testRenderBeforeWithSyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $this->assertNull($this->infoBoxExtensionHelper->renderBefore($map)); - } - - public function testRenderAfterWithSyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $this->assertNull($this->infoBoxExtensionHelper->renderAfter($map)); - } - - public function testRenderLibrariesWithAsyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('isAsync') - ->will($this->returnValue(true)); - - $this->assertNull($this->infoBoxExtensionHelper->renderLibraries($map)); - } - - public function testRenderBeforeWithAsyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('isAsync') - ->will($this->returnValue(true)); - - $expected = <<assertSame($expected, $this->infoBoxExtensionHelper->renderBefore($map)); - } - - public function testRenderAfterWithAsyncMap() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('isAsync') - ->will($this->returnValue(true)); - - $expected = <<assertSame($expected, $this->infoBoxExtensionHelper->renderAfter($map)); - } -} diff --git a/tests/Helper/Geometry/EncodingHelperTest.php b/tests/Helper/Geometry/EncodingHelperTest.php deleted file mode 100644 index a0a3bf34..00000000 --- a/tests/Helper/Geometry/EncodingHelperTest.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Geometry; - -use Ivory\GoogleMap\Helper\Geometry\EncodingHelper; - -/** - * Encoding helper test. - * - * @author GeLo - */ -class EncodingHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Geometry\EncodingHelper */ - protected $encodingHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->encodingHelper = new EncodingHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->encodingHelper); - } - - public function testRenderDecodePathWithoutSpecialChars() - { - $this->assertSame( - 'google.maps.geometry.encoding.decodePath("foo")', - $this->encodingHelper->renderDecodePath('foo') - ); - } - - public function testRenderDecodePathWithSpecialChars() - { - $this->assertSame( - 'google.maps.geometry.encoding.decodePath("v\"a\\\\lu\\\'e")', - $this->encodingHelper->renderDecodePath('v"a\lu\'e') - ); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The encoded path must be a string value. - */ - public function testRenderDecodePathWithInvalidValue() - { - $this->encodingHelper->renderDecodePath(true); - } -} diff --git a/tests/Helper/Layers/KMLLayerHelperTest.php b/tests/Helper/Layers/KMLLayerHelperTest.php deleted file mode 100644 index 843bf5aa..00000000 --- a/tests/Helper/Layers/KMLLayerHelperTest.php +++ /dev/null @@ -1,79 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Layers; - -use Ivory\GoogleMap\Layers\KMLLayer; -use Ivory\GoogleMap\Helper\Layers\KMLLayerHelper; - -/** - * KML Layer helper test. - * - * @author GeLo - */ -class KMLLayerHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Layers\KMLLayerHelper */ - protected $kmlLayerHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->kmlLayerHelper = new KMLLayerHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->kmlLayerHelper); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $kmlLayer = new KMLLayer('url'); - $kmlLayer->setJavascriptVariable('kmlLayer'); - - $this->assertSame( - 'kmlLayer = new google.maps.KmlLayer("url", {"map":map});'.PHP_EOL, - $this->kmlLayerHelper->render($kmlLayer, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $kmlLayer = new KMLLayer('url'); - $kmlLayer->setJavascriptVariable('kmlLayer'); - $kmlLayer->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = 'kmlLayer = new google.maps.KmlLayer('. - '"url", '. - '{"map":map,"option1":"value1","option2":"value2"}'. - ');'.PHP_EOL; - - $this->assertSame($expected, $this->kmlLayerHelper->render($kmlLayer, $map)); - } -} diff --git a/tests/Helper/MapHelperTest.php b/tests/Helper/MapHelperTest.php deleted file mode 100644 index c1e56bd8..00000000 --- a/tests/Helper/MapHelperTest.php +++ /dev/null @@ -1,1280 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper; - -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Events\Event; -use Ivory\GoogleMap\Helper\Extension\InfoBoxExtensionHelper; -use Ivory\GoogleMap\Helper\Overlays\InfoBoxHelper; -use Ivory\GoogleMap\Layers\KMLLayer; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\MapTypeId; -use Ivory\GoogleMap\Overlays\Circle; -use Ivory\GoogleMap\Overlays\EncodedPolyline; -use Ivory\GoogleMap\Overlays\GroundOverlay; -use Ivory\GoogleMap\Overlays\InfoWindow; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Overlays\Polygon; -use Ivory\GoogleMap\Overlays\Polyline; -use Ivory\GoogleMap\Overlays\Rectangle; -use Ivory\GoogleMap\Helper\MapHelper; - -/** - * Map helper test. - * - * @author GeLo - */ -class MapHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\MapHelper */ - protected $mapHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->mapHelper = new MapHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->mapHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Base\CoordinateHelper', - $this->mapHelper->getCoordinateHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Base\BoundHelper', - $this->mapHelper->getBoundHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Base\PointHelper', - $this->mapHelper->getPointHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Base\SizeHelper', - $this->mapHelper->getSizeHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\MapTypeIdHelper', - $this->mapHelper->getMapTypeIdHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper', - $this->mapHelper->getMapTypeControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper', - $this->mapHelper->getOverviewMapControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\PanControlHelper', - $this->mapHelper->getPanControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\RotateControlHelper', - $this->mapHelper->getRotateControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ScaleControlHelper', - $this->mapHelper->getScaleControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper', - $this->mapHelper->getStreetViewControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Controls\ZoomControlHelper', - $this->mapHelper->getZoomControlHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper', - $this->mapHelper->getMarkerClusterHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper', - $this->mapHelper->getMarkerImageHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper', - $this->mapHelper->getMarkerShapeHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper', - $this->mapHelper->getInfoWindowHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\PolylineHelper', - $this->mapHelper->getPolylineHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper', - $this->mapHelper->getEncodedPolylineHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\PolygonHelper', - $this->mapHelper->getPolygonHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\RectangleHelper', - $this->mapHelper->getRectangleHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\CircleHelper', - $this->mapHelper->getCircleHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper', - $this->mapHelper->getGroundOverlayHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Layers\KMLLayerHelper', - $this->mapHelper->getKmlLayerHelper() - ); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Events\EventManagerHelper', - $this->mapHelper->getEventManagerHelper() - ); - - $this->assertTrue($this->mapHelper->hasExtensionHelpers()); - $this->assertCount(1, $this->mapHelper->getExtensionHelpers()); - - $this->assertTrue($this->mapHelper->hasExtensionHelper('core')); - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Extension\CoreExtensionHelper', - $this->mapHelper->getExtensionHelper('core') - ); - } - - public function testInitialState() - { - $coordinateHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\CoordinateHelper'); - $boundHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\BoundHelper'); - $pointHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\PointHelper'); - $sizeHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\SizeHelper'); - $mapTypeIdHelper = $this->getMock('Ivory\GoogleMap\Helper\MapTypeIdHelper'); - $mapTypeControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\MapTypeControlHelper'); - $overviewMapControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\OverviewMapControlHelper'); - $panControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\PanControlHelper'); - $rotateControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\RotateControlHelper'); - $scaleControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ScaleControlHelper'); - $streetViewControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\StreetViewControlHelper'); - $zoomControlHelper = $this->getMock('Ivory\GoogleMap\Helper\Controls\ZoomControlHelper'); - $markerClusterHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface'); - $markerImageHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper'); - $markerShapeHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper'); - $infoWindowHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper'); - $polylineHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\PolylineHelper'); - $encodedPolylineHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper'); - $polygonHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\PolygonHelper'); - $rectangleHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\RectangleHelper'); - $circleHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\CircleHelper'); - $groundOverlayHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper'); - $kmlLayerHelper = $this->getMock('Ivory\GoogleMap\Helper\Layers\KMLLayerHelper'); - $eventManagerHelper = $this->getMock('Ivory\GoogleMap\Helper\Events\EventManagerHelper'); - $extensionHelpers = array('foo' => $this->getMock('Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface')); - - $this->mapHelper = new MapHelper( - $coordinateHelper, - $boundHelper, - $pointHelper, - $sizeHelper, - $mapTypeIdHelper, - $mapTypeControlHelper, - $overviewMapControlHelper, - $panControlHelper, - $rotateControlHelper, - $scaleControlHelper, - $streetViewControlHelper, - $zoomControlHelper, - $markerClusterHelper, - $markerImageHelper, - $markerShapeHelper, - $infoWindowHelper, - $polylineHelper, - $encodedPolylineHelper, - $polygonHelper, - $rectangleHelper, - $circleHelper, - $groundOverlayHelper, - $kmlLayerHelper, - $eventManagerHelper, - $extensionHelpers - ); - - $this->assertSame($coordinateHelper, $this->mapHelper->getCoordinateHelper()); - $this->assertSame($boundHelper, $this->mapHelper->getBoundHelper()); - $this->assertSame($pointHelper, $this->mapHelper->getPointHelper()); - $this->assertSame($sizeHelper, $this->mapHelper->getSizeHelper()); - $this->assertSame($mapTypeIdHelper, $this->mapHelper->getMapTypeIdHelper()); - $this->assertSame($mapTypeControlHelper, $this->mapHelper->getMapTypeControlHelper()); - $this->assertSame($overviewMapControlHelper, $this->mapHelper->getOverviewMapControlHelper()); - $this->assertSame($panControlHelper, $this->mapHelper->getPanControlHelper()); - $this->assertSame($rotateControlHelper, $this->mapHelper->getRotateControlHelper()); - $this->assertSame($scaleControlHelper, $this->mapHelper->getScaleControlHelper()); - $this->assertSame($streetViewControlHelper, $this->mapHelper->getStreetViewControlHelper()); - $this->assertSame($zoomControlHelper, $this->mapHelper->getZoomControlHelper()); - $this->assertSame($markerClusterHelper, $this->mapHelper->getMarkerClusterHelper()); - $this->assertSame($markerImageHelper, $this->mapHelper->getMarkerImageHelper()); - $this->assertSame($markerShapeHelper, $this->mapHelper->getMarkerShapeHelper()); - $this->assertSame($infoWindowHelper, $this->mapHelper->getInfoWindowHelper()); - $this->assertSame($polylineHelper, $this->mapHelper->getPolylineHelper()); - $this->assertSame($encodedPolylineHelper, $this->mapHelper->getEncodedPolylineHelper()); - $this->assertSame($polygonHelper, $this->mapHelper->getPolygonHelper()); - $this->assertSame($rectangleHelper, $this->mapHelper->getRectangleHelper()); - $this->assertSame($circleHelper, $this->mapHelper->getCircleHelper()); - $this->assertSame($groundOverlayHelper, $this->mapHelper->getGroundOverlayHelper()); - $this->assertSame($kmlLayerHelper, $this->mapHelper->getKmlLayerHelper()); - $this->assertSame($eventManagerHelper, $this->mapHelper->getEventManagerHelper()); - $this->assertSame($extensionHelpers, $this->mapHelper->getExtensionHelpers()); - } - - public function testRemoveExtensionHelperWithValidValue() - { - $extensionHelper = $this->getMock('Ivory\GoogleMap\Helper\Extension\ExtensionHelperInterface'); - $this->mapHelper->setExtensionHelper('foo', $extensionHelper); - - $this->assertTrue($this->mapHelper->hasExtensionHelper('foo')); - - $this->mapHelper->removeExtensionHelper('foo'); - - $this->assertFalse($this->mapHelper->hasExtensionHelper('foo')); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The extension helper "foo" does not exist. - */ - public function testRemoveExtensionHelperWithInvalidValue() - { - $this->mapHelper->removeExtensionHelper('foo'); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The extension helper "foo" does not exist. - */ - public function testGetExtensionHelperWithInvalidValue() - { - $this->mapHelper->getExtensionHelper('foo'); - } - - public function testRenderHtmlContainer() - { - $map = new Map(); - $map->setHtmlContainerId('html_container_id'); - - $this->assertSame( - '
'.PHP_EOL, - $this->mapHelper->renderHtmlContainer($map) - ); - } - - public function testRenderStylesheets() - { - $map = new Map(); - $map->setHtmlContainerId('html_container_id'); - $map->setStylesheetOptions(array('width' => '200px','height' => '100px', 'option1' => 'value1')); - - $expected = << -#html_container_id{ -width:200px; -height:100px; -option1:value1; -} - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderStylesheets($map)); - } - - public function testRenderJsContainerInit() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $expected = 'map_container = {'. - '"map":null,'. - '"coordinates":{},'. - '"bounds":{},'. - '"points":{},'. - '"sizes":{},'. - '"circles":{},'. - '"encoded_polylines":{},'. - '"ground_overlays":{},'. - '"polygons":{},'. - '"polylines":{},'. - '"rectangles":{},'. - '"info_windows":{},'. - '"marker_images":{},'. - '"marker_shapes":{},'. - '"markers":{},'. - '"marker_cluster":null,'. - '"kml_layers":{},'. - '"event_manager":{"dom_events":{},"dom_events_once":{},"events":{},"events_once":{}},'. - '"closable_info_windows":{},'. - '"functions":{'. - '"to_array":function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }'. - '}};'.PHP_EOL; - - $this->assertSame($expected, $this->mapHelper->renderJsContainerInit($map)); - } - - public function testRenderJsContainerBounds() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getBound()->setJavascriptVariable('map_bound'); - - $map->addGroundOverlay($groundOverlay = new GroundOverlay()); - $groundOverlay->getBound()->setJavascriptVariable('ground_overlay_bound'); - $groundOverlay->getBound()->getSouthWest()->setJavascriptVariable('ground_overlay_coordinate_south_west'); - $groundOverlay->getBound()->getNorthEast()->setJavascriptVariable('ground_overlay_coordinate_north_east'); - - $map->addRectangle($rectangle = new Rectangle()); - $rectangle->getBound()->setJavascriptVariable('rectangle_bound'); - $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_coordinate_south_west'); - $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_coordinate_north_east'); - - $map->setAutoZoom(true); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerBounds($map)); - } - - public function testRenderJsContainerCoordinates() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $map->addRectangle($rectangle = new Rectangle()); - $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_south_west'); - $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_north_east'); - - $map->addCircle($circle = new Circle()); - $circle->getCenter()->setJavascriptVariable('circle_center'); - - $map->addInfoWindow($infoWindow = new InfoWindow()); - $infoWindow->setPosition(1, 2, true); - $infoWindow->getPosition()->setJavascriptVariable('info_window_position'); - - $map->addMarker($marker = new Marker()); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $map->addPolygon($polygon = new Polygon()); - $polygon->addCoordinate(1.1, 2.1); - $polygon->addCoordinate(3.1, 4.2); - - foreach ($polygon->getCoordinates() as $index => $polygonCoordinate) { - $polygonCoordinate->setJavascriptVariable('polygon_coordinate_'.$index); - } - - $map->addPolyline($polyline = new Polyline()); - $polyline->addCoordinate(1.2, 2.6); - $polyline->addCoordinate(3.2, 4.9); - - foreach ($polyline->getCoordinates() as $index => $polyline) { - $polyline->setJavascriptVariable('polyline_coordinate_'.$index); - } - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerCoordinates($map)); - } - - public function testRenderJsContainerPoints() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - - $marker->setIcon('url'); - - $marker->getIcon()->setAnchor(1, 2); - $marker->getIcon()->getAnchor()->setJavascriptVariable('marker_icon_anchor'); - - $marker->getIcon()->setOrigin(1, 2); - $marker->getIcon()->getOrigin()->setJavascriptVariable('marker_icon_origin'); - - $marker->setShadow('url'); - - $marker->getShadow()->setAnchor(1, 2); - $marker->getShadow()->getAnchor()->setJavascriptVariable('marker_shadow_anchor'); - - $marker->getShadow()->setOrigin(1, 2); - $marker->getShadow()->getOrigin()->setJavascriptVariable('marker_shadow_origin'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerPoints($map)); - } - - public function testRenderJsContainerSizes() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addInfoWindow($mapInfoWindow = new InfoWindow()); - $mapInfoWindow->setPixelOffset(1, 2); - $mapInfoWindow->getPixelOffset()->setJavascriptVariable('map_info_winfow_pixel_offset'); - - $map->addMarker($marker = new Marker()); - - $marker->setInfoWindow($markerInfoWindow = new InfoWindow()); - $markerInfoWindow->setPixelOffset(1, 2); - $markerInfoWindow->getPixelOffset()->setJavascriptVariable('marker_info_window_pixel_offset'); - - $marker->setIcon('url'); - - $marker->getIcon()->setSize(1, 2); - $marker->getIcon()->getSize()->setJavascriptVariable('marker_icon_size'); - - $marker->getIcon()->setScaledSize(1, 2); - $marker->getIcon()->getScaledSize()->setJavascriptVariable('marker_icon_scaled_size'); - - $marker->setShadow('url'); - - $marker->getShadow()->setSize(1, 2); - $marker->getShadow()->getSize()->setJavascriptVariable('marker_shadow_size'); - - $marker->getShadow()->setScaledSize(1, 2); - $marker->getShadow()->getScaledSize()->setJavascriptVariable('marker_shadow_scaled_size'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerSizes($map)); - } - - public function testRenderMapCenter() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getCenter()->setJavascriptVariable('map_center'); - - $this->assertSame('map.setCenter(map_center);'.PHP_EOL, $this->mapHelper->renderMapCenter($map)); - } - - public function testRenderMapBound() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getBound()->setJavascriptVariable('map_bound'); - - $this->assertSame('map.fitBounds(map_bound);'.PHP_EOL, $this->mapHelper->renderMapBound($map)); - } - - public function testRenderMap() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $expected = <<assertSame($expected, $this->mapHelper->renderMap($map)); - } - - public function testRenderMapWithEnabledMapControls() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->setMapTypeControl( - array(MapTypeId::TERRAIN), - ControlPosition::BOTTOM_CENTER, - MapTypeControlStyle::HORIZONTAL_BAR - ); - - // FIXME Add all map controls... - - $expected = 'map = new google.maps.Map('. - 'document.getElementById("map_canvas"), '. - '{'. - '"mapTypeId":google.maps.MapTypeId.ROADMAP,'. - '"mapTypeControl":true,'. - '"mapTypeControlOptions":'. - '{'. - '"mapTypeIds":[google.maps.MapTypeId.TERRAIN],'. - '"position":google.maps.ControlPosition.BOTTOM_CENTER,'. - '"style":google.maps.MapTypeControlStyle.HORIZONTAL_BAR'. - '},'. - '"zoom":3'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->mapHelper->renderMap($map)); - } - - public function testRenderMapWithDisabledMapControls() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->setMapOption('mapTypeControl', false); - - $expected = 'map = new google.maps.Map('. - 'document.getElementById("map_canvas"), '. - '{"mapTypeId":google.maps.MapTypeId.ROADMAP,"mapTypeControl":false,"zoom":3}'. - ');'.PHP_EOL; - - $this->assertSame($expected, $this->mapHelper->renderMap($map)); - } - - public function testRenderJsContainerMap() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerMap($map)); - } - - public function testRenderJsContainerCircles() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addCircle($circle = new Circle()); - $circle->setJavascriptVariable('circle'); - $circle->getCenter()->setJavascriptVariable('circle_center'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerCircles($map)); - } - - public function testRenderJsContainerEncodedPolylines() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addEncodedPolyline($encodedPolyline = new EncodedPolyline('foo')); - $encodedPolyline->setJavascriptVariable('encoded_polyline'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerEncodedPolylines($map)); - } - - public function testRenderJsContainerGroundOverlays() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addGroundOverlay($groundOverlay = new GroundOverlay('url')); - $groundOverlay->setJavascriptVariable('ground_overlay'); - $groundOverlay->getBound()->setJavascriptVariable('ground_overlay_bound'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerGroundOverlays($map)); - } - - public function testRenderJsContainerPolygons() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addPolygon($polygon = new Polygon()); - $polygon->setJavascriptVariable('polygon'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerPolygons($map)); - } - - public function testRenderJsContainerPolylines() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addPolyline($polyline = new Polyline()); - $polyline->setJavascriptVariable('polyline'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerPolylines($map)); - } - - public function testRenderJsContainerRectangles() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addRectangle($rectangle = new Rectangle()); - $rectangle->setJavascriptVariable('rectangle'); - $rectangle->getBound()->setJavascriptVariable('rectangle_bound'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerRectangles($map)); - } - - public function testRenderJsContainerInfoWindowsWithoutClosableOnes() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addInfoWindow($mapInfoWindow = new InfoWindow()); - $mapInfoWindow->setJavascriptVariable('map_info_window'); - $mapInfoWindow->setPosition(1, 2, true); - $mapInfoWindow->getPosition()->setJavascriptVariable('map_info_window_position'); - - $map->addMarker($marker = new Marker()); - $marker->setInfoWindow($markerInfoWindow = new InfoWindow()); - $markerInfoWindow->setJavascriptVariable('marker_info_window'); - $markerInfoWindow->setPosition(1, 2, true); - $markerInfoWindow->getPosition()->setJavascriptVariable('marker_info_window_position'); - - $expected = <<Default content<\/p>"}); -map_container.info_windows.marker_info_window = marker_info_window = new google.maps.InfoWindow({"content":"

Default content<\/p>"}); - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJsContainerInfoWindows($map)); - } - - public function testRenderJsContainerInfoWindowsWithClosableOnes() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addInfoWindow($mapInfoWindow = new InfoWindow()); - $mapInfoWindow->setJavascriptVariable('map_info_window'); - $mapInfoWindow->setPosition(1, 2, true); - $mapInfoWindow->getPosition()->setJavascriptVariable('map_info_window_position'); - - $map->addMarker($marker = new Marker()); - $marker->setInfoWindow($markerInfoWindow = new InfoWindow()); - $markerInfoWindow->setJavascriptVariable('marker_info_window'); - $markerInfoWindow->setPosition(1, 2, true); - $markerInfoWindow->getPosition()->setJavascriptVariable('marker_info_window_position'); - - $mapInfoWindow->setAutoClose(true); - $markerInfoWindow->setAutoClose(true); - - $expected = <<Default content<\/p>"}); -map_container.info_windows.marker_info_window = marker_info_window = new google.maps.InfoWindow({"content":"

Default content<\/p>"}); -map_container.closable_info_windows.map_info_window = map_info_window; -map_container.closable_info_windows.marker_info_window = marker_info_window; - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJsContainerInfoWindows($map)); - } - - public function testRenderJsContainerMarkerImages() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - - $marker->setIcon('url_icon'); - $marker->getIcon()->setJavascriptVariable('marker_icon'); - - $marker->setShadow('shadow_url'); - $marker->getShadow()->setJavascriptVariable('marker_shadow'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerMarkerImages($map)); - } - - public function testRenderJsContainerMarkerShapes() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - $marker->setShape('poly', array(1, 1, 1, -1, -1, -1, -1, 1)); - $marker->getShape()->setJavascriptVariable('marker_shape'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerMarkerShapes($map)); - } - - public function testRenderJsContainerMarkerCluster() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerMarkerCluster($map)); - } - - public function testRenderJsContainerKMLLayers() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addKMLLayer($kmlLayer = new KMLLayer('url')); - $kmlLayer->setJavascriptVariable('kml_layer'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerKMLLayers($map)); - } - - public function testRenderJsContainerEventManager() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $baseEvent = new Event('instance', 'click', 'function(){}', false); - - $map->getEventManager()->addDomEvent($domEvent = clone $baseEvent); - $domEvent->setJavascriptVariable('dom_event'); - - $map->getEventManager()->addDomEventOnce($domEventOnce = clone $baseEvent); - $domEventOnce->setJavascriptVariable('dom_event_once'); - - $map->getEventManager()->addEvent($event = clone $baseEvent); - $event->setJavascriptVariable('event'); - - $map->getEventManager()->addEventOnce($eventOnce = clone $baseEvent); - $eventOnce->setJavascriptVariable('event_once'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainerEventManager($map)); - } - - public function testRenderJsContainerWithDefaultMap() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = <<assertSame($expected, $this->mapHelper->renderJsContainer($map)); - } - - public function testRenderJsContainerWithComplexMap() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->setAutoZoom(true); - $map->getBound()->setJavascriptVariable('map_bound'); - - $map->addCircle($circle = new Circle()); - $circle->setJavascriptVariable('circle'); - $circle->getCenter()->setJavascriptVariable('circle_center'); - - $map->addEncodedPolyline($encodedPolyline = new EncodedPolyline('foo')); - $encodedPolyline->setJavascriptVariable('encoded_polyline'); - - $map->addGroundOverlay($groundOverlay = new GroundOverlay('url')); - $groundOverlay->setJavascriptVariable('ground_overlay'); - $groundOverlay->getBound()->setJavascriptVariable('ground_overlay_bound'); - $groundOverlay->getBound()->setSouthWest(1, 2, true); - $groundOverlay->getBound()->getSouthWest()->setJavascriptVariable('ground_overlay_bound_south_west'); - $groundOverlay->getBound()->setNorthEast(3, 4, true); - $groundOverlay->getBound()->getNorthEast()->setJavascriptVariable('ground_overlay_bound_north_east'); - - $map->addPolygon($polygon = new Polygon()); - $polygon->setJavascriptVariable('polygon'); - - $map->addPolyline($polyline = new Polyline()); - $polyline->setJavascriptVariable('polyline'); - - $map->addRectangle($rectangle = new Rectangle()); - $rectangle->setJavascriptVariable('rectangle'); - $rectangle->getBound()->setJavascriptVariable('rectangle_bound'); - $rectangle->getBound()->setSouthWest(1, 2, true); - $rectangle->getBound()->getSouthWest()->setJavascriptVariable('rectangle_bound_south_west'); - $rectangle->getBound()->setNorthEast(3, 4, true); - $rectangle->getBound()->getNorthEast()->setJavascriptVariable('rectangle_bound_north_east'); - - $map->addInfoWindow($mapInfoWindow = new InfoWindow()); - $mapInfoWindow->setJavascriptVariable('map_info_window'); - $mapInfoWindow->setPosition(1, 2, true); - $mapInfoWindow->getPosition()->setJavascriptVariable('map_info_window_position'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $marker->setInfoWindow($markerInfoWindow = new InfoWindow()); - $markerInfoWindow->setJavascriptVariable('marker_info_window'); - - $marker->setIcon('url'); - $marker->getIcon()->setJavascriptVariable('marker_icon'); - - $marker->setShadow('url'); - $marker->getShadow()->setJavascriptVariable('marker_shadow'); - - $map->addKMLLayer($kmlLayer = new KMLLayer('url')); - $kmlLayer->setJavascriptVariable('kml_layer'); - - $map->getEventManager()->addEvent($event = new Event('instance', 'click', 'function(){}', false)); - $event->setJavascriptVariable('event'); - - $expected = <<Default content<\/p>"}); -map_container.info_windows.marker_info_window = marker_info_window = new google.maps.InfoWindow({"content":"

Default content<\/p>"}); -map_container.marker_images.marker_icon = marker_icon = new google.maps.MarkerImage("url", null, null, null, null); -map_container.marker_images.marker_shadow = marker_shadow = new google.maps.MarkerImage("url", null, null, null, null); -map_container.markers.marker = marker = new google.maps.Marker({"position":marker_position,"map":map,"icon":marker_icon,"shadow":marker_shadow}); -map_container.kml_layers.kml_layer = kml_layer = new google.maps.KmlLayer("url", {"map":map}); -map_container.event_manager.events.event = event = google.maps.event.addListener(instance, "click", function(){}); -map_container.event_manager.events.marker_info_window_event = marker_info_window_event = google.maps.event.addListener(marker, "click", function () { - for (var info_window in map_container.closable_info_windows) { - map_container.closable_info_windows[info_window].close(); - } - marker_info_window.open(map, marker); - -}); -map_bound.union(circle.getBounds()); -encoded_polyline.getPath().forEach(function(element){map_bound.extend(element)}); -map_bound.union(ground_overlay_bound); -polygon.getPath().forEach(function(element){map_bound.extend(element)}); -polyline.getPath().forEach(function(element){map_bound.extend(element)}); -map_bound.union(rectangle_bound); -map_bound.extend(map_info_window.getPosition()); -map_bound.extend(marker.getPosition()); -map.fitBounds(map_bound); - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJsContainer($map)); - } - - public function testRenderJavascripts() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithEncodedPolyline() - { - $encodedPolyline = new EncodedPolyline('foo'); - $encodedPolyline->setJavascriptVariable('encoded_polyline'); - - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->addEncodedPolyline($encodedPolyline); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=geometry&language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithLibraries() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->setLibraries(array('places')); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places&language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithAsync() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->setAsync(true); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = << -function load_ivory_google_map() { -map_container = {"map":null,"coordinates":{},"bounds":{},"points":{},"sizes":{},"circles":{},"encoded_polylines":{},"ground_overlays":{},"polygons":{},"polylines":{},"rectangles":{},"info_windows":{},"marker_images":{},"marker_shapes":{},"markers":{},"marker_cluster":null,"kml_layers":{},"event_manager":{"dom_events":{},"dom_events_once":{},"events":{},"events_once":{}},"closable_info_windows":{},"functions":{"to_array":function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }}}; -map_container.coordinates.map_center = map_center = new google.maps.LatLng(0, 0, true); -map_container.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP,"zoom":3}); -map.setCenter(map_center); -} - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithMapInfoWindowOpened() - { - $infoWindow = new InfoWindow(); - $infoWindow->setJavascriptVariable('info_window'); - $infoWindow->setPosition(1.1, 2.2, true); - $infoWindow->getPosition()->setJavascriptVariable('info_window_position'); - $infoWindow->setContent('foo'); - $infoWindow->setAutoOpen(false); - $infoWindow->setOpen(true); - - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getCenter()->setJavascriptVariable('map_center'); - $map->addInfoWindow($infoWindow); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithMarkerInfoWindowOpened() - { - $infoWindow = new InfoWindow(); - $infoWindow->setJavascriptVariable('info_window'); - $infoWindow->setContent('foo'); - $infoWindow->setAutoOpen(false); - $infoWindow->setOpen(true); - - $marker = new Marker(); - $marker->setJavascriptVariable('marker'); - $marker->setPosition(1.2, 2.1, true); - $marker->getPosition()->setJavascriptVariable('marker_position'); - $marker->setInfoWindow($infoWindow); - - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getCenter()->setJavascriptVariable('map_center'); - $map->addMarker($marker); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRenderJavascriptsWithMultipleMaps() - { - $map1 = new Map(); - $map1->setJavascriptVariable('map1'); - $map1->getCenter()->setJavascriptVariable('map1_center'); - - $expected1 = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - - -EOF; - - $map2 = new Map(); - $map2->setJavascriptVariable('map2'); - $map2->getCenter()->setJavascriptVariable('map2_center'); - - $expected2 = << -map2_container = {"map":null,"coordinates":{},"bounds":{},"points":{},"sizes":{},"circles":{},"encoded_polylines":{},"ground_overlays":{},"polygons":{},"polylines":{},"rectangles":{},"info_windows":{},"marker_images":{},"marker_shapes":{},"markers":{},"marker_cluster":null,"kml_layers":{},"event_manager":{"dom_events":{},"dom_events_once":{},"events":{},"events_once":{}},"closable_info_windows":{},"functions":{"to_array":function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }}}; -map2_container.coordinates.map2_center = map2_center = new google.maps.LatLng(0, 0, true); -map2_container.map = map2 = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP,"zoom":3}); -map2.setCenter(map2_center); - - -EOF; - - $this->assertSame($expected1, $this->mapHelper->renderJavascripts($map1)); - $this->assertSame($expected2, $this->mapHelper->renderJavascripts($map2)); - } - - public function testRenderJavascriptsWithInfoBox() - { - $this->mapHelper->setInfoWindowHelper(new InfoBoxHelper()); - $this->mapHelper->setExtensionHelper('info_box', new InfoBoxExtensionHelper()); - - $map = new Map(); - $map->setJavascriptVariable('map'); - $map->getCenter()->setJavascriptVariable('map_center'); - - $map->addInfoWindow($infoBox = new InfoWindow()); - $infoBox->setJavascriptVariable('map_info_box'); - $infoBox->setPosition(1, 2, true); - $infoBox->getPosition()->setJavascriptVariable('map_info_box_position'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); }; - - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->renderJavascripts($map)); - } - - public function testRender() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getCenter()->setJavascriptVariable('map_center'); - - $expected = << - - - - - -EOF; - - $this->assertSame($expected, $this->mapHelper->render($map)); - } -} diff --git a/tests/Helper/MapTypeIdHelperTest.php b/tests/Helper/MapTypeIdHelperTest.php deleted file mode 100644 index 8c58434b..00000000 --- a/tests/Helper/MapTypeIdHelperTest.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper; - -use Ivory\GoogleMap\MapTypeId; -use Ivory\GoogleMap\Helper\MapTypeIdHelper; - -/** - * Map type ID helper test. - * - * @author GeLo - */ -class MapTypeIdHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\MapTypeIdHelper */ - protected $mapTypeIdHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->mapTypeIdHelper = new MapTypeIdHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->mapTypeIdHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame('google.maps.MapTypeId.HYBRID', $this->mapTypeIdHelper->render(MapTypeId::HYBRID)); - $this->assertSame('google.maps.MapTypeId.ROADMAP', $this->mapTypeIdHelper->render(MapTypeId::ROADMAP)); - $this->assertSame('google.maps.MapTypeId.SATELLITE', $this->mapTypeIdHelper->render(MapTypeId::SATELLITE)); - $this->assertSame('google.maps.MapTypeId.TERRAIN', $this->mapTypeIdHelper->render(MapTypeId::TERRAIN)); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The map type id can only be : hybrid, roadmap, satellite, terrain. - */ - public function testRenderWithInvalidValue() - { - $this->mapTypeIdHelper->render('foo'); - } -} diff --git a/tests/Helper/Overlays/AnimationHelperTest.php b/tests/Helper/Overlays/AnimationHelperTest.php deleted file mode 100644 index 29daafe7..00000000 --- a/tests/Helper/Overlays/AnimationHelperTest.php +++ /dev/null @@ -1,57 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\Animation; -use Ivory\GoogleMap\Helper\Overlays\AnimationHelper; - -/** - * Animation helper test. - * - * @author GeLo - */ -class AnimationHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\AnimationHelper */ - protected $animationHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->animationHelper = new AnimationHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->animationHelper); - } - - public function testRenderWithValidValue() - { - $this->assertSame('google.maps.Animation.BOUNCE', $this->animationHelper->render(Animation::BOUNCE)); - $this->assertSame('google.maps.Animation.DROP', $this->animationHelper->render(Animation::DROP)); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The animation can only be : bounce, drop. - */ - public function testRenderWithInvalidValue() - { - $this->animationHelper->render('foo'); - } -} diff --git a/tests/Helper/Overlays/CircleHelperTest.php b/tests/Helper/Overlays/CircleHelperTest.php deleted file mode 100644 index 8b07cd58..00000000 --- a/tests/Helper/Overlays/CircleHelperTest.php +++ /dev/null @@ -1,70 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\Circle; -use Ivory\GoogleMap\Helper\Overlays\CircleHelper; - -/** - * Circle helper test. - * - * @author GeLo - */ -class CircleHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\CircleHelper */ - protected $circleHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->circleHelper = new CircleHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->circleHelper); - } - - public function testRender() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $circle = new Circle(); - $circle->setJavascriptVariable('circle'); - - $circle->setCenter(1.1, 2.1, true); - $circle->getCenter()->setJavascriptVariable('center'); - - $circle->setRadius(2); - $circle->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = 'circle = new google.maps.Circle({'. - '"map":map,'. - '"center":center,'. - '"radius":2,'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->circleHelper->render($circle, $map)); - } -} diff --git a/tests/Helper/Overlays/EncodedPolylineHelperTest.php b/tests/Helper/Overlays/EncodedPolylineHelperTest.php deleted file mode 100644 index 59936de3..00000000 --- a/tests/Helper/Overlays/EncodedPolylineHelperTest.php +++ /dev/null @@ -1,98 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\EncodedPolyline; -use Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper; - -/** - * Encoded polyline helper test. - * - * @author GeLo - */ -class EncodedPolylineHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\EncodedPolylineHelper */ - protected $encodedPolylineHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->encodedPolylineHelper = new EncodedPolylineHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->encodedPolylineHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Geometry\EncodingHelper', - $this->encodedPolylineHelper->getEncodingHelper() - ); - } - - public function testInitialState() - { - $encodingHelper = $this->getMock('Ivory\GoogleMap\Helper\Geometry\EncodingHelper'); - - $this->encodedPolylineHelper = new EncodedPolylineHelper($encodingHelper); - - $this->assertSame($encodingHelper, $this->encodedPolylineHelper->getEncodingHelper()); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $encodedPolyline = new EncodedPolyline('foo'); - $encodedPolyline->setJavascriptVariable('encodedPolyline'); - - $this->assertSame( - 'encodedPolyline = new google.maps.Polyline('. - '{"map":map,"path":google.maps.geometry.encoding.decodePath("foo")}'. - ');'.PHP_EOL, - $this->encodedPolylineHelper->render($encodedPolyline, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $encodedPolyline = new EncodedPolyline('foo'); - $encodedPolyline->setJavascriptVariable('encodedPolyline'); - $encodedPolyline->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $this->assertSame( - 'encodedPolyline = new google.maps.Polyline('. - '{"map":map,"path":google.maps.geometry.encoding.decodePath("foo"),"option1":"value1","option2":"value2"}'. - ');'.PHP_EOL, - $this->encodedPolylineHelper->render($encodedPolyline, $map) - ); - } -} diff --git a/tests/Helper/Overlays/GroundOverlayHelperTest.php b/tests/Helper/Overlays/GroundOverlayHelperTest.php deleted file mode 100644 index 67702020..00000000 --- a/tests/Helper/Overlays/GroundOverlayHelperTest.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Overlays\GroundOverlay; -use Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper; - -/** - * Ground overlay helper test. - * - * @author GeLo - */ -class GroundOverlayHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\GroundOverlayHelper */ - protected $groundOverlayHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->groundOverlayHelper = new GroundOverlayHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->groundOverlayHelper); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $bound = new Bound(); - $bound->setJavascriptVariable('bound'); - $bound->setSouthWest(-1.1, -2.1, true); - $bound->setNorthEast(1.1, 2.1, true); - - $groundOverlay = new GroundOverlay('url', $bound); - $groundOverlay->setJavascriptVariable('groundOverlay'); - - $this->assertSame( - 'groundOverlay = new google.maps.GroundOverlay("url", bound, {"map":map});'.PHP_EOL, - $this->groundOverlayHelper->render($groundOverlay, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $bound = new Bound(); - $bound->setJavascriptVariable('bound'); - $bound->setSouthWest(-1.1, -2.1, true); - $bound->setNorthEast(1.1, 2.1, true); - - $groundOverlay = new GroundOverlay('url', $bound); - $groundOverlay->setJavascriptVariable('groundOverlay'); - $groundOverlay->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = <<assertSame($expected, $this->groundOverlayHelper->render($groundOverlay, $map)); - } -} diff --git a/tests/Helper/Overlays/InfoBoxHelperTest.php b/tests/Helper/Overlays/InfoBoxHelperTest.php deleted file mode 100644 index f2305315..00000000 --- a/tests/Helper/Overlays/InfoBoxHelperTest.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Helper\Overlays\InfoBoxHelper; -use Ivory\GoogleMap\Overlays\InfoWindow; - -/** - * InfoBox helper test. - * - * @author GeLo - */ -class InfoBoxHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\InfoBoxHelper */ - protected $infoBoxHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->infoBoxHelper = new InfoBoxHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->infoBoxHelper); - } - - public function testRender() - { - $infoWindow = new InfoWindow(); - - $infoWindow->setPosition(1.1, 2.1, true); - $infoWindow->getPosition()->setJavascriptVariable('position'); - - $infoWindow->setPixelOffset(3, 4, 'px', 'px'); - $infoWindow->getPixelOffset()->setJavascriptVariable('pixel_offset'); - - $infoWindow->setContent('content'); - $infoWindow->setOpen(true); - - $infoWindow->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = $infoWindow->getJavascriptVariable().' = new InfoBox({'. - '"position":position,'. - '"pixelOffset":pixel_offset,'. - '"content":"content",'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->infoBoxHelper->render($infoWindow, true)); - } -} diff --git a/tests/Helper/Overlays/InfoWindowHelperTest.php b/tests/Helper/Overlays/InfoWindowHelperTest.php deleted file mode 100644 index b195b4db..00000000 --- a/tests/Helper/Overlays/InfoWindowHelperTest.php +++ /dev/null @@ -1,134 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\InfoWindow; -use Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper; - -/** - * Info window helper test. - * - * @author GeLo - */ -class InfoWindowHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper */ - protected $infoWindowHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->infoWindowHelper = new InfoWindowHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->infoWindowHelper); - } - - public function testRenderWithoutPosition() - { - $infoWindow = new InfoWindow(); - - $infoWindow->setPosition(1.1, 2.1, true); - $infoWindow->getPosition()->setJavascriptVariable('position'); - - $infoWindow->setPixelOffset(3, 4, 'px', 'px'); - $infoWindow->getPixelOffset()->setJavascriptVariable('pixel_offset'); - - $infoWindow->setContent('content'); - $infoWindow->setOpen(true); - - $expected = $infoWindow->getJavascriptVariable().' = new google.maps.InfoWindow({'. - '"position":position,'. - '"pixelOffset":pixel_offset,'. - '"content":"content"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->infoWindowHelper->render($infoWindow, true)); - } - - public function testRenderWithPosition() - { - $infoWindow = new InfoWindow(); - - $infoWindow->setPosition(1.1, 2.1, true); - $infoWindow->getPosition()->setJavascriptVariable('position'); - - $infoWindow->setPixelOffset(3, 4, 'px', 'px'); - $infoWindow->getPixelOffset()->setJavascriptVariable('pixel_offset'); - - $infoWindow->setContent('content'); - $infoWindow->setOpen(true); - - $infoWindow->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = $infoWindow->getJavascriptVariable().' = new google.maps.InfoWindow({'. - '"pixelOffset":pixel_offset,'. - '"content":"content",'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->infoWindowHelper->render($infoWindow, false)); - } - - public function testRenderOpenWithoutMarker() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $infoWindow = new InfoWindow(); - $infoWindow->setJavascriptVariable('infoWindow'); - $infoWindow->setPosition(1.1, 2.1, true); - $infoWindow->setContent('content'); - $infoWindow->setOpen(true); - $infoWindow->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $this->assertSame('infoWindow.open(map);'.PHP_EOL, $this->infoWindowHelper->renderOpen($infoWindow, $map)); - } - - public function testRenderOpenWithMarker() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $infoWindow = new InfoWindow(); - $infoWindow->setJavascriptVariable('infoWindow'); - $infoWindow->setPosition(1.1, 2.1, true); - $infoWindow->setContent('content'); - $infoWindow->setOpen(true); - $infoWindow->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $marker = $this->getMock('Ivory\GoogleMap\Overlays\Marker'); - $marker - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('marker')); - - $this->assertSame( - 'infoWindow.open(map, marker);'.PHP_EOL, - $this->infoWindowHelper->renderOpen($infoWindow, $map, $marker) - ); - } -} diff --git a/tests/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelperTest.php b/tests/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelperTest.php deleted file mode 100644 index c82453f6..00000000 --- a/tests/Helper/Overlays/MarkerCluster/AbstractMarkerClusterHelperTest.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays\MarkerCluster; - -/** - * Abstract marker cluster helper test. - * - * @author GeLo - */ -class AbstractMarkerClusterHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\AbstractMarkerClusterHelper */ - protected $helper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->helper = $this->getMockForAbstractClass('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\AbstractMarkerClusterHelper'); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->helper); - } - - public function testDefaultState() - { - $this->assertInstanceOf('Ivory\GoogleMap\Helper\Overlays\MarkerHelper', $this->helper->getMarkerHelper()); - } - - public function testInitialState() - { - $markerHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerHelper'); - - $this->helper = $this->getMockBuilder('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\AbstractMarkerClusterHelper') - ->setConstructorArgs(array($markerHelper)) - ->getMockForAbstractClass(); - - $this->assertSame($markerHelper, $this->helper->getMarkerHelper()); - } -} diff --git a/tests/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelperTest.php b/tests/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelperTest.php deleted file mode 100644 index 98853587..00000000 --- a/tests/Helper/Overlays/MarkerCluster/DefaultMarkerClusterHelperTest.php +++ /dev/null @@ -1,112 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\DefaultMarkerClusterHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\InfoWindow; -use Ivory\GoogleMap\Overlays\Marker; - -/** - * Default marker cluster helper test. - * - * @author GeLo - */ -class DefaultMarkerClusterHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\DefaultMarkerClusterHelper */ - protected $helper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->helper = new DefaultMarkerClusterHelper(); - } - - /** - * {@inheritdoc} - */ - protected function setDown() - { - unset($this->helper); - } - - public function testDefaultState() - { - $this->assertInstanceOf('Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper', $this->helper->getInfoWindowHelper()); - } - - public function testInitialState() - { - $markerHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerHelper'); - $infoWindowHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\InfoWindowHelper'); - - $this->helper = new DefaultMarkerClusterHelper($markerHelper, $infoWindowHelper); - - $this->assertSame($markerHelper, $this->helper->getMarkerHelper()); - $this->assertSame($infoWindowHelper, $this->helper->getInfoWindowHelper()); - } - - public function testRender() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - - $this->assertNull($this->helper->render($markerCluster, $map)); - } - - public function testRenderLibraires() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - - $this->assertNull($this->helper->renderLibraries($markerCluster, $map)); - } - - public function testRenderMarkersWithoutAutoOpenInfoWindow() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $expected = <<assertSame($expected, $this->helper->renderMarkers($map->getMarkerCluster(), $map)); - } - - public function testRenderMarkersWithAutoOpenInfoWindow() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $marker->setInfoWindow($infoWindow = new InfoWindow()); - $infoWindow->setJavascriptVariable('marker_info_window'); - $infoWindow->setAutoOpen(true); - - $this->helper->renderMarkers($map->getMarkerCluster(), $map); - - $this->assertNotEmpty($map->getEventManager()->getEvents()); - } -} diff --git a/tests/Helper/Overlays/MarkerCluster/JsMarkerClusterHelperTest.php b/tests/Helper/Overlays/MarkerCluster/JsMarkerClusterHelperTest.php deleted file mode 100644 index d1b777a3..00000000 --- a/tests/Helper/Overlays/MarkerCluster/JsMarkerClusterHelperTest.php +++ /dev/null @@ -1,119 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\JsMarkerClusterHelper; -use Ivory\GoogleMap\Map; -use Ivory\GoogleMap\Overlays\Marker; - -/** - * Javscript marker cluster helper test. - * - * @author GeLo - */ -class JsMarkerClusterHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\JsMarkerClusterHelper */ - protected $helper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->helper = new JsMarkerClusterHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->helper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerCluster\DefaultMarkerClusterHelper', - $this->helper - ); - } - - public function testRenderWithoutOptions() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getMarkerCluster()->setJavascriptVariable('marker_cluster'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $expected = <<assertSame($expected, $this->helper->render($map->getMarkerCluster(), $map)); - } - - public function testRenderWithOptions() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->getMarkerCluster()->setJavascriptVariable('marker_cluster'); - $map->getMarkerCluster()->setOption('foo', 'bar'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $expected = <<assertSame($expected, $this->helper->render($map->getMarkerCluster(), $map)); - } - - public function testRenderLibraries() - { - $map = new Map(); - - $expected = << - -EOF; - - $this->assertSame($expected, $this->helper->renderLibraries($map->getMarkerCluster(), $map)); - } - - public function testRenderMarkers() - { - $map = new Map(); - $map->setJavascriptVariable('map'); - - $map->addMarker($marker = new Marker()); - $marker->setJavascriptVariable('marker'); - $marker->getPosition()->setJavascriptVariable('marker_position'); - - $expected = <<assertSame($expected, $this->helper->renderMarkers($map->getMarkerCluster(), $map)); - } -} diff --git a/tests/Helper/Overlays/MarkerCluster/MarkerClusterHelperTest.php b/tests/Helper/Overlays/MarkerCluster/MarkerClusterHelperTest.php deleted file mode 100644 index 970bf6eb..00000000 --- a/tests/Helper/Overlays/MarkerCluster/MarkerClusterHelperTest.php +++ /dev/null @@ -1,140 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays\MarkerCluster; - -use Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper; -use Ivory\GoogleMap\Overlays\MarkerCluster; - -/** - * Marker cluster helper test. - * - * @author GeLo - */ -class MarkerClusterHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelper */ - protected $helper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->helper = new MarkerClusterHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->helper); - } - - public function testDefaultState() - { - $this->assertTrue($this->helper->hasHelpers()); - - $this->assertTrue($this->helper->hasHelper(MarkerCluster::_DEFAULT)); - $this->assertTrue($this->helper->hasHelper(MarkerCluster::MARKER_CLUSTER)); - - $this->assertCount(2, $this->helper->getHelpers()); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\MarkerCluster\DefaultMarkerClusterHelper', - $this->helper->getHelper(MarkerCluster::_DEFAULT) - ); - } - - public function testInitialState() - { - $helper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface'); - $this->helper = new MarkerClusterHelper(array('foo' => $helper)); - - $this->assertSame(array('foo' => $helper), $this->helper->getHelpers()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The marker cluster helper can not be resolved. - */ - public function testHelperWithInvalidName() - { - $this->helper->getHelper('foo'); - } - - public function testRender() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - $markerCluster - ->expects($this->any()) - ->method('getType') - ->will($this->returnValue('foo')); - - $helperMock = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface'); - $helperMock - ->expects($this->once()) - ->method('render') - ->with($this->equalTo($markerCluster), $this->equalTo($map)) - ->will($this->returnValue('bar')); - - $this->helper->setHelper('foo', $helperMock); - - $this->assertSame('bar', $this->helper->render($markerCluster, $map)); - } - - public function testRenderMarkers() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - $markerCluster - ->expects($this->any()) - ->method('getType') - ->will($this->returnValue('foo')); - - $helperMock = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface'); - $helperMock - ->expects($this->once()) - ->method('renderMarkers') - ->with($this->equalTo($markerCluster), $this->equalTo($map)) - ->will($this->returnValue('bar')); - - $this->helper->setHelper('foo', $helperMock); - - $this->assertSame('bar', $this->helper->renderMarkers($markerCluster, $map)); - } - - public function testRenderLibraries() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - $markerCluster - ->expects($this->any()) - ->method('getType') - ->will($this->returnValue('foo')); - - $helperMock = $this->getMock('Ivory\GoogleMap\Helper\Overlays\MarkerCluster\MarkerClusterHelperInterface'); - $helperMock - ->expects($this->once()) - ->method('renderLibraries') - ->with($this->equalTo($markerCluster), $this->equalTo($map)) - ->will($this->returnValue('bar')); - - $this->helper->setHelper('foo', $helperMock); - - $this->assertSame('bar', $this->helper->renderLibraries($markerCluster, $map)); - } -} diff --git a/tests/Helper/Overlays/MarkerHelperTest.php b/tests/Helper/Overlays/MarkerHelperTest.php deleted file mode 100644 index 448700ad..00000000 --- a/tests/Helper/Overlays/MarkerHelperTest.php +++ /dev/null @@ -1,168 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\Animation; -use Ivory\GoogleMap\Overlays\Marker; -use Ivory\GoogleMap\Helper\Overlays\MarkerHelper; - -/** - * Marker helper test. - * - * @author GeLo - */ -class MarkerHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerHelper */ - protected $markerHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->markerHelper = new MarkerHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->markerHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Overlays\AnimationHelper', - $this->markerHelper->getAnimationHelper() - ); - } - - public function testInitialState() - { - $animationHelper = $this->getMock('Ivory\GoogleMap\Helper\Overlays\AnimationHelper'); - - $this->markerHelper = new MarkerHelper($animationHelper); - - $this->assertSame($animationHelper, $this->markerHelper->getAnimationHelper()); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $marker = new Marker(); - $marker->setJavascriptVariable('marker'); - - $marker->setAnimation(Animation::BOUNCE); - - $marker->setPosition(1.1, 2.1, true); - $marker->getPosition()->setJavascriptVariable('position'); - - $marker->setIcon('url'); - $marker->getIcon()->setJavascriptVariable('icon'); - - $marker->setShadow('url'); - $marker->getShadow()->setJavascriptVariable('shadow'); - - $marker->setShape('poly', array(1, 2, 3, 4)); - $marker->getShape()->setJavascriptVariable('shape'); - - $expected = 'marker = new google.maps.Marker({'. - '"position":position,'. - '"map":map,'. - '"animation":google.maps.Animation.BOUNCE,'. - '"icon":icon,'. - '"shadow":shadow,'. - '"shape":shape'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->markerHelper->render($marker, $map)); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->any()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $marker = new Marker(); - $marker->setJavascriptVariable('marker'); - - $marker->setAnimation(Animation::BOUNCE); - - $marker->setPosition(1.1, 2.1, true); - $marker->getPosition()->setJavascriptVariable('position'); - - $marker->setIcon('url'); - $marker->getIcon()->setJavascriptVariable('icon'); - - $marker->setShadow('url'); - $marker->getShadow()->setJavascriptVariable('shadow'); - - $marker->setShape('poly', array(1, 2, 3, 4)); - $marker->getShape()->setJavascriptVariable('shape'); - - $marker->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = 'marker = new google.maps.Marker({'. - '"position":position,'. - '"map":map,'. - '"animation":google.maps.Animation.BOUNCE,'. - '"icon":icon,'. - '"shadow":shadow,'. - '"shape":shape,'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->markerHelper->render($marker, $map)); - } - - public function testRenderWitoutMap() - { - $marker = new Marker(); - $marker->setJavascriptVariable('marker'); - - $marker->setAnimation(Animation::BOUNCE); - - $marker->setPosition(1.1, 2.1, true); - $marker->getPosition()->setJavascriptVariable('position'); - - $marker->setIcon('url'); - $marker->getIcon()->setJavascriptVariable('icon'); - - $marker->setShadow('url'); - $marker->getShadow()->setJavascriptVariable('shadow'); - - $marker->setShape('poly', array(1, 2, 3, 4)); - $marker->getShape()->setJavascriptVariable('shape'); - - $expected = 'marker = new google.maps.Marker({'. - '"position":position,'. - '"animation":google.maps.Animation.BOUNCE,'. - '"icon":icon,'. - '"shadow":shadow,'. - '"shape":shape'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->markerHelper->render($marker)); - } -} diff --git a/tests/Helper/Overlays/MarkerImageHelperTest.php b/tests/Helper/Overlays/MarkerImageHelperTest.php deleted file mode 100644 index 8ef8a6ed..00000000 --- a/tests/Helper/Overlays/MarkerImageHelperTest.php +++ /dev/null @@ -1,68 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\MarkerImage; -use Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper; - -/** - * Marker image helper test. - * - * @author GeLo - */ -class MarkerImageHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerImageHelper */ - protected $markerImageHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->markerImageHelper = new MarkerImageHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->markerImageHelper); - } - - public function testRender() - { - $markerImage = new MarkerImage(); - $markerImage->setJavascriptVariable('markerImage'); - $markerImage->setUrl('url'); - - $markerImage->setSize(1, 2); - $markerImage->getSize()->setJavascriptVariable('size'); - - $markerImage->setOrigin(3, 4); - $markerImage->getOrigin()->setJavascriptVariable('origin'); - - $markerImage->setAnchor(5, 6); - $markerImage->getAnchor()->setJavascriptVariable('anchor'); - - $markerImage->setScaledSize(7, 8); - $markerImage->getScaledSize()->setJavascriptVariable('scaled_size'); - - $expected = <<assertSame($expected, $this->markerImageHelper->render($markerImage)); - } -} diff --git a/tests/Helper/Overlays/MarkerShapeHelperTest.php b/tests/Helper/Overlays/MarkerShapeHelperTest.php deleted file mode 100644 index 8c88c60b..00000000 --- a/tests/Helper/Overlays/MarkerShapeHelperTest.php +++ /dev/null @@ -1,75 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\MarkerShape; -use Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper; - -/** - * Marker shape helper test. - * - * @author GeLo - */ -class MarkerShapeHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\MarkerShapeHelper */ - protected $markerShapeHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->markerShapeHelper = new MarkerShapeHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->markerShapeHelper); - } - - public function testRenderWithPolyType() - { - $markerShape = new MarkerShape('poly', array(1, 2, 3, 4, 5, 6)); - $markerShape->setJavascriptVariable('markerShape'); - - $this->assertSame( - 'markerShape = new google.maps.MarkerShape({"type":"poly","coords":[1,2,3,4,5,6]});'.PHP_EOL, - $this->markerShapeHelper->render($markerShape) - ); - } - - public function testRenderWithCircleType() - { - $markerShape = new MarkerShape('circle', array(1, 2, 3)); - $markerShape->setJavascriptVariable('markerShape'); - - $this->assertSame( - 'markerShape = new google.maps.MarkerShape({"type":"circle","coords":[1,2,3]});'.PHP_EOL, - $this->markerShapeHelper->render($markerShape) - ); - } - - public function testRenderWithRectangleType() - { - $markerShape = new MarkerShape('rect', array(-1, -1, 1, 1)); - $markerShape->setJavascriptVariable('markerShape'); - - $this->assertSame( - 'markerShape = new google.maps.MarkerShape({"type":"rect","coords":[-1,-1,1,1]});'.PHP_EOL, - $this->markerShapeHelper->render($markerShape) - ); - } -} diff --git a/tests/Helper/Overlays/PolygonHelperTest.php b/tests/Helper/Overlays/PolygonHelperTest.php deleted file mode 100644 index ef1e52a4..00000000 --- a/tests/Helper/Overlays/PolygonHelperTest.php +++ /dev/null @@ -1,102 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\Polygon; -use Ivory\GoogleMap\Helper\Overlays\PolygonHelper; - -/** - * Polygon helper test. - * - * @author GeLo - */ -class PolygonHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\PolygonHelper */ - protected $polygonHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->polygonHelper = new PolygonHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->polygonHelper); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $polygon = new Polygon(); - $polygon->setJavascriptVariable('polygon'); - - $polygon->addCoordinate(1.1, 2.1); - $polygon->addCoordinate(3.1, 4.2); - $polygon->addCoordinate(7.4, 12.6); - - foreach ($polygon->getCoordinates() as $index => $coordinate) { - $coordinate->setJavascriptVariable('coordinate'.$index); - } - - $this->assertSame( - 'polygon = new google.maps.Polygon({"map":map,"paths":[coordinate0,coordinate1,coordinate2]});'.PHP_EOL, - $this->polygonHelper->render($polygon, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $polygon = new Polygon(); - $polygon->setJavascriptVariable('polygon'); - - $polygon->addCoordinate(1.1, 2.1); - $polygon->addCoordinate(3.1, 4.2); - $polygon->addCoordinate(7.4, 12.6); - - foreach ($polygon->getCoordinates() as $index => $coordinate) { - $coordinate->setJavascriptVariable('coordinate'.$index); - } - - $polygon->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = 'polygon = new google.maps.Polygon({'. - '"map":map,'. - '"paths":['. - 'coordinate0,'. - 'coordinate1,'. - 'coordinate2'. - '],'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->polygonHelper->render($polygon, $map)); - } -} diff --git a/tests/Helper/Overlays/PolylineHelperTest.php b/tests/Helper/Overlays/PolylineHelperTest.php deleted file mode 100644 index f509e192..00000000 --- a/tests/Helper/Overlays/PolylineHelperTest.php +++ /dev/null @@ -1,102 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Overlays\Polyline; -use Ivory\GoogleMap\Helper\Overlays\PolylineHelper; - -/** - * Polyline helper test. - * - * @author GeLo - */ -class PolylineHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\PolylineHelper */ - protected $polylineHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->polylineHelper = new PolylineHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->polylineHelper); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $polyline = new Polyline(); - $polyline->setJavascriptVariable('polyline'); - - $polyline->addCoordinate(1.1, 2.1); - $polyline->addCoordinate(3.1, 4.2); - $polyline->addCoordinate(7.4, 12.6); - - foreach ($polyline->getCoordinates() as $index => $coordinate) { - $coordinate->setJavascriptVariable('coordinate'.$index); - } - - $this->assertSame( - 'polyline = new google.maps.Polyline({"map":map,"path":[coordinate0,coordinate1,coordinate2]});'.PHP_EOL, - $this->polylineHelper->render($polyline, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $polyline = new Polyline(); - $polyline->setJavascriptVariable('polyline'); - - $polyline->addCoordinate(1.1, 2.1); - $polyline->addCoordinate(3.1, 4.2); - $polyline->addCoordinate(7.4, 12.6); - - foreach ($polyline->getCoordinates() as $index => $coordinate) { - $coordinate->setJavascriptVariable('coordinate'.$index); - } - - $polyline->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = 'polyline = new google.maps.Polyline({'. - '"map":map,'. - '"path":['. - 'coordinate0,'. - 'coordinate1,'. - 'coordinate2'. - '],'. - '"option1":"value1",'. - '"option2":"value2"'. - '});'.PHP_EOL; - - $this->assertSame($expected, $this->polylineHelper->render($polyline, $map)); - } -} diff --git a/tests/Helper/Overlays/RectangleHelperTest.php b/tests/Helper/Overlays/RectangleHelperTest.php deleted file mode 100644 index 378d12b8..00000000 --- a/tests/Helper/Overlays/RectangleHelperTest.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Overlays; - -use Ivory\GoogleMap\Base\Bound; -use Ivory\GoogleMap\Overlays\Rectangle; -use Ivory\GoogleMap\Helper\Overlays\RectangleHelper; - -/** - * Rectangle helper test. - * - * @author GeLo - */ -class RectangleHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Overlays\RectangleHelper */ - protected $rectangleHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->rectangleHelper = new RectangleHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->rectangleHelper); - } - - public function testRenderWithoutOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $bound = new Bound(); - $bound->setJavascriptVariable('rectangleBound'); - $bound->setSouthWest(-1.1, -2.1); - $bound->setNorthEast(1.1, 2.1); - - $rectangle = new Rectangle($bound); - $rectangle->setJavascriptVariable('rectangle'); - - $this->assertSame( - 'rectangle = new google.maps.Rectangle({"map":map,"bounds":rectangleBound});'.PHP_EOL, - $this->rectangleHelper->render($rectangle, $map) - ); - } - - public function testRenderWithOptions() - { - $map = $this->getMock('Ivory\GoogleMap\Map'); - $map - ->expects($this->once()) - ->method('getJavascriptVariable') - ->will($this->returnValue('map')); - - $bound = new Bound(); - $bound->setJavascriptVariable('rectangleBound'); - $bound->setSouthWest(-1.1, -2.1); - $bound->setNorthEast(1.1, 2.1); - - $rectangle = new Rectangle($bound); - $rectangle->setJavascriptVariable('rectangle'); - $rectangle->setOptions(array('option1' => 'value1', 'option2' => 'value2')); - - $expected = <<assertSame($expected, $this->rectangleHelper->render($rectangle, $map)); - } -} diff --git a/tests/Helper/Places/AutocompleteHelperTest.php b/tests/Helper/Places/AutocompleteHelperTest.php deleted file mode 100644 index 99d6d5ca..00000000 --- a/tests/Helper/Places/AutocompleteHelperTest.php +++ /dev/null @@ -1,290 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Helper\Places; - -use Ivory\GoogleMap\Helper\Places\AutocompleteHelper; -use Ivory\GoogleMap\Places\Autocomplete; -use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; -use Ivory\GoogleMap\Places\AutocompleteType; - -/** - * Autocomplete helper test. - * - * @author GeLo - */ -class AutocompleteHelperTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Helper\Places\AutocompleteHelper */ - protected $autocompleteHelper; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->autocompleteHelper = new AutocompleteHelper(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->autocompleteHelper); - } - - public function testDefaultState() - { - $this->assertInstanceOf('Ivory\GoogleMap\Helper\ApiHelper', $this->autocompleteHelper->getApiHelper()); - - $this->assertInstanceOf( - 'Ivory\GoogleMap\Helper\Base\CoordinateHelper', - $this->autocompleteHelper->getCoordinateHelper() - ); - - $this->assertInstanceOf('ivory\GoogleMap\Helper\Base\BoundHelper', $this->autocompleteHelper->getBoundHelper()); - } - - public function testInitialState() - { - $apiHelper = $this->getMock('Ivory\GoogleMap\Helper\ApiHelper'); - $coordinateHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\CoordinateHelper'); - $boundHelper = $this->getMock('Ivory\GoogleMap\Helper\Base\BoundHelper'); - - $this->autocompleteHelper = new AutocompleteHelper($apiHelper, $coordinateHelper, $boundHelper); - - $this->assertSame($apiHelper, $this->autocompleteHelper->getApiHelper()); - $this->assertSame($coordinateHelper, $this->autocompleteHelper->getCoordinateHelper()); - $this->assertSame($boundHelper, $this->autocompleteHelper->getBoundHelper()); - } - - public function testRenderHtmlContainerWithoutValue() - { - $autocomplete = new Autocomplete(); - - $this->assertSame( - ''.PHP_EOL, - $this->autocompleteHelper->renderHtmlContainer($autocomplete) - ); - } - - public function testRenderHtmlContainerWithValue() - { - $autocomplete = new Autocomplete(); - $autocomplete->setValue('foo'); - - $this->assertSame( - ''.PHP_EOL, - $this->autocompleteHelper->renderHtmlContainer($autocomplete) - ); - } - - public function testRenderHtmlContainerWithoutCustomInputAttributes() - { - $autocomplete = new Autocomplete(); - $autocomplete->setInputAttribute('class', 'foo'); - - $this->assertSame( - ''.PHP_EOL, - $this->autocompleteHelper->renderHtmlContainer($autocomplete) - ); - } - - public function testRenderAutocomplete() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - - $expected = <<assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); - } - - public function testRenderAutocompleteWithTypes() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - $autocomplete->setTypes(array(AutocompleteType::ESTABLISHMENT, AutocompleteType::CITIES)); - - $expected = <<assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); - } - - public function testRenderAutocompleteWithComponentRestrictions() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - $autocomplete->setComponentRestrictions(array(AutocompleteComponentRestriction::COUNTRY => 'fr')); - - $expected = <<assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); - } - - public function testRenderAutocompleteWithBound() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - - $autocomplete->setBound(1, 2, 3, 4); - $autocomplete->getBound()->setJavascriptVariable('bound'); - - $expected = <<assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); - } - - public function testRenderAutocompleteWithTypesAndComponentRestrictionsAndBound() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - - $autocomplete->setTypes(array(AutocompleteType::ESTABLISHMENT, AutocompleteType::CITIES)); - $autocomplete->setComponentRestrictions(array(AutocompleteComponentRestriction::COUNTRY => 'fr')); - - $autocomplete->setBound(1, 2, 3, 4); - $autocomplete->getBound()->setJavascriptVariable('bound'); - - $expected = <<assertSame($expected, $this->autocompleteHelper->renderAutocomplete($autocomplete)); - } - - public function testRenderJavascriptsWithOneAutocomplete() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places&language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->autocompleteHelper->renderJavascripts($autocomplete)); - } - - public function testRenderJavascriptsWithMultipleAutocompletes() - { - $autocomplete1 = new Autocomplete(); - $autocomplete1->setJavascriptVariable('autocomplete1'); - - $autocomplete2 = new Autocomplete(); - $autocomplete2->setJavascriptVariable('autocomplete2'); - - $expected1 = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places&language=en&sensor=false"}); }; - - - - -EOF; - - $expected2 = << -autocomplete2 = new google.maps.places.Autocomplete(document.getElementById('place_input'), {}); - - -EOF; - - $this->assertSame($expected1, $this->autocompleteHelper->renderJavascripts($autocomplete1)); - $this->assertSame($expected2, $this->autocompleteHelper->renderJavascripts($autocomplete2)); - } - - public function testRenderJavascriptsWithBound() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - - $autocomplete->setBound(1, 2, 3, 4, true, false); - $autocomplete->getBound()->setJavascriptVariable('bound'); - $autocomplete->getBound()->getSouthWest()->setJavascriptVariable('bound_south_west'); - $autocomplete->getBound()->getNorthEast()->setJavascriptVariable('bound_north_east'); - - $expected = << -function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"libraries=places&language=en&sensor=false"}); }; - - - - -EOF; - - $this->assertSame($expected, $this->autocompleteHelper->renderJavascripts($autocomplete)); - } - - public function testRenderJavascriptsWithAsync() - { - $autocomplete = new Autocomplete(); - $autocomplete->setJavascriptVariable('autocomplete'); - $autocomplete->setAsync(true); - - $expected = << -function load_ivory_google_place () { -autocomplete = new google.maps.places.Autocomplete(document.getElementById('place_input'), {}); -} - - - - -EOF; - - $this->assertSame($expected, $this->autocompleteHelper->renderJavascripts($autocomplete)); - } - - /** - * @expectedException Ivory\GoogleMap\Exception\HelperException - * @expectedExceptionMessage The place autocomplete bound must have coordinates. - */ - public function testRenderJavascriptsWithInvalidBound() - { - $autocomplete = new Autocomplete(); - - $autocomplete->setBound(1, 2, 3, 4); - $autocomplete->getBound()->setSouthWest(null); - $autocomplete->getBound()->setNorthEast(null); - - $this->autocompleteHelper->renderJavascripts($autocomplete); - } -} diff --git a/tests/Helpers/AbstractHelperTest.php b/tests/Helpers/AbstractHelperTest.php new file mode 100644 index 00000000..7470c414 --- /dev/null +++ b/tests/Helpers/AbstractHelperTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +/** + * Abstract helper test. + * + * @author GeLo + */ +abstract class AbstractHelperTest extends AbstractTestCase +{ + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventDispatcher; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventDispatcher = $this->createSymfonyEventDispatcherMock(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventDispatcher); + } +} diff --git a/tests/Helpers/AbstractTestCase.php b/tests/Helpers/AbstractTestCase.php new file mode 100644 index 00000000..04491413 --- /dev/null +++ b/tests/Helpers/AbstractTestCase.php @@ -0,0 +1,1060 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Helpers test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts an api helper instance. + * + * @param \Ivory\GoogleMap\Helpers\ApiHelper $apiHelper The api helper. + */ + protected function assertApiHelperInstance($apiHelper) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\ApiHelper', $apiHelper); + } + + /** + * Asserts an autocomplete bound aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator $boundAggregator The bound aggregator. + */ + protected function assertAutocompleteBoundAggregatorInstance($boundAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator', + $boundAggregator + ); + } + + /** + * Asserts an autocomplete helper instance. + * + * @param \Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper $autocompleteHelper The autocomplete helper. + */ + protected function assertAutocompleteHelperInstance($autocompleteHelper) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper', $autocompleteHelper); + } + + /** + * Asserts a bound aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator $boundAggregator The bound aggregator. + */ + protected function assertBoundAggregatorInstance($boundAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator', $boundAggregator); + } + + /** + * Asserts a circle aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator $circleAggregator The circle aggregator. + */ + protected function assertCircleAggregatorInstance($circleAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator', $circleAggregator); + } + + /** + * Asserts a control position renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer $controlPositionRenderer The control position renderer. + */ + protected function assertControlPositionRendererInstance($controlPositionRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer', + $controlPositionRenderer + ); + } + + /** + * Asserts an event dispatcher instance. + * + * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $eventDispatcher The event dispatcher. + */ + protected function assertEventDispatcherInstance($eventDispatcher) + { + $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventDispatcherInterface', $eventDispatcher); + } + + /** + * Asserts a formatter instance. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\Formatter $formatter The formatter. + */ + protected function assertFormatterInstance($formatter) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Subscribers\Formatter', $formatter); + } + + /** + * Asserts a ground overlay aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator $groundOverlayAggregator The ground overlay aggregator. + */ + protected function assertGroundOverlayAggregatorInstance($groundOverlayAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator', + $groundOverlayAggregator + ); + } + + /** + * Asserts an helper event instance. + * + * @param \Ivory\GoogleMap\Helpers\AbstractEvent $event The helper event. + */ + protected function assertHelperEventInstance($event) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\AbstractEvent', $event); + } + + /** + * Asserts an helper instance. + * + * @param \Ivory\GoogleMap\Helpers\AbstractHelper $helper The helper. + */ + protected function assertHelperInstance($helper) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\AbstractHelper', $helper); + } + + /** + * Asserts an icon aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator $iconAggregator The icon aggregator. + */ + protected function assertIconAggregatorInstance($iconAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator', $iconAggregator); + } + + /** + * Asserts an info window aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator $infoWindowAggregator The info window aggregator. + */ + protected function assertInfoWindowAggregatorInstance($infoWindowAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator', + $infoWindowAggregator + ); + } + + /** + * Asserts an info window open renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer $infoWindowOpenRenderer The info window open renderer. + */ + protected function assertInfoWindowOpenRendererInstance($infoWindowOpenRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer', + $infoWindowOpenRenderer + ); + } + + /** + * Asserts a json builder instance. + * + * @param \Ivory\JsonBuilder\JsonBuilder $jsonBuilder The json builder. + */ + protected function assertJsonBuilderInstance($jsonBuilder) + { + $this->assertInstanceOf('Ivory\JsonBuilder\JsonBuilder', $jsonBuilder); + } + + /** + * Asserts a map helper instance. + * + * @param \Ivory\GoogleMap\Helpers\MapHelper $mapHelper The map helper. + */ + protected function assertMapHelperInstance($mapHelper) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\MapHelper', $mapHelper); + } + + /** + * Asserts a map type id renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer $mapTypeIdRenderer The map type id renderer. + */ + protected function assertMapTypeIdRendererInstance($mapTypeIdRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer', $mapTypeIdRenderer); + } + + /** + * Asserts a marker aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator $markerAggregator The marker aggregator. + */ + protected function assertMarkerAggregatorInstance($markerAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator', $markerAggregator); + } + + /** + * Asserts a polygon aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator $polygonAggregator The polygon aggregatir. + */ + protected function assertPolygonAggregatorInstance($polygonAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator', $polygonAggregator); + } + + /** + * Asserts a polyline aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator $polylineAggregator The polyline aggregator. + */ + protected function assertPolylineAggregatorInstance($polylineAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator', $polylineAggregator); + } + + /** + * Asserts a rectangle aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator $rectangleAggregator The rectangle aggregator. + */ + protected function assertRectangleAggregatorInstance($rectangleAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator', + $rectangleAggregator + ); + } + + /** + * Asserts a symfony dependency injection compiler pass instance. + * + * @param \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $compilerPass The symfony dependency injection compiler pass. + */ + protected function assertSymfonyCompilerPassInstance($compilerPass) + { + $this->assertInstanceOf('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface', $compilerPass); + } + + /** + * Asserts a symfony event instance. + * + * @param \Symfony\Component\EventDispatcher\Event $event The symfony event. + */ + protected function assertSymfonyEventInstance($event) + { + $this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', $event); + } + + /** + * Asserts a symfony dependency injection extension instance. + * + * @param \Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension The symfony dependency injection extension. + */ + protected function assertSymfonyExtensionInstance($extension) + { + $this->assertInstanceOf('Symfony\Component\DependencyInjection\Extension\ExtensionInterface', $extension); + } + + /** + * Creates an animation renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer|\PHPUnit_Framework_MockObject_MockObject The animation renderer mock. + */ + protected function createAnimationRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer'); + } + + /** + * Creates an autocomplete bound aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator|\PHPUnit_Framework_MockObject_MockObject The autocomplete bound aggregator mock. + */ + protected function createAutocompleteBoundAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator'); + } + + /** + * Creates an autocomplete container renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer|\PHPUnit_Framework_MockObject_MockObject The autocomplete container renderer mock. + */ + protected function createAutocompleteContainerRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer'); + } + + /** + * Creates an autocomplete coordinate aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator|\PHPUnit_Framework_MockObject_MockObject The autocomplete coordinate aggregator mock. + */ + protected function createAutocompleteCoordinateAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator'); + } + + /** + * Creates an autocomplete renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer|\PHPUnit_Framework_MockObject_MockObject The autocomplete renderer mock. + */ + protected function createAutocompleteRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer'); + } + + /** + * Creates an autocomplete mock. + * + * @return \Ivory\GoogleMap\Places\Autocomplete|\PHPUnit_Framework_MockObject_MockObject The autocomplete mock. + */ + protected function createAutocompleteMock() + { + return $this->getMock('Ivory\GoogleMap\Places\Autocomplete'); + } + + /** + * Creates a bound aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator|\PHPUnit_Framework_MockObject_MockObject The bound aggregator mock. + */ + protected function createBoundAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator'); + } + + /** + * Creates a bound renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer|\PHPUnit_Framework_MockObject_MockObject The bound renderer mock. + */ + protected function createBoundRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer'); + } + + /** + * Creates a circle aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator|\PHPUnit_Framework_MockObject_MockObject The circle aggregator mock. + */ + protected function createCircleAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator'); + } + + /** + * Creates a circle renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer|\PHPUnit_Framework_MockObject_MockObject The circle renderer mock. + */ + protected function createCircleRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer'); + } + + /** + * Creates a controls renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer|\PHPUnit_Framework_MockObject_MockObject The controls renderer mock. + */ + protected function createControlsRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer'); + } + + /** + * Creates a control position renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer|\PHPUnit_Framework_MockObject_MockObject The control position renderer mock. + */ + protected function createControlPositionRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer'); + } + + /** + * Creates a coordinate aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator|\PHPUnit_Framework_MockObject_MockObject The coordinate aggregator mock. + */ + protected function createCoordinateAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator'); + } + + /** + * Creates a coordinate renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer|\PHPUnit_Framework_MockObject_MockObject The coordinate renderer mock. + */ + protected function createCoordinateRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer'); + } + + /** + * Creates a dom event aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator|\PHPUnit_Framework_MockObject_MockObject The dom event aggregator mock. + */ + protected function createDomEventAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator'); + } + + /** + * Creates a dom event once aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator|\PHPUnit_Framework_MockObject_MockObject The dom event once aggregator mock. + */ + protected function createDomEventOnceAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator'); + } + + /** + * Creates a dom event once renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer|\PHPUnit_Framework_MockObject_MockObject The dom event once renderer mock. + */ + protected function createDomEventOnceRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer'); + } + + /** + * Creates a dom event renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer|\PHPUnit_Framework_MockObject_MockObject The dom event renderer mock. + */ + protected function createDomEventRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer'); + } + + /** + * Creates an encoded polyline aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator|\PHPUnit_Framework_MockObject_MockObject The encoded polyline aggregator mock. + */ + protected function createEncodedPolylineAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator'); + } + + /** + * Creates an encoded polyline renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer|\PHPUnit_Framework_MockObject_MockObject The encoded polyline renderer mock. + */ + protected function createEncodedPolylineRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer'); + } + + /** + * Creates an encoding renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer|\PHPUnit_Framework_MockObject_MockObject The encoding renderer mock. + */ + protected function createEncodingRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer'); + } + + /** + * Creates an event aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator|\PHPUnit_Framework_MockObject_MockObject The event aggregator mock. + */ + protected function createEventAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator'); + } + + /** + * Creates an event once aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator|\PHPUnit_Framework_MockObject_MockObject The event once aggregator mock. + */ + protected function createEventOnceAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator'); + } + + /** + * Creates an event once renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer|\PHPUnit_Framework_MockObject_MockObject The event once renderer mock. + */ + protected function createEventOnceRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer'); + } + + /** + * Creates an event renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer|\PHPUnit_Framework_MockObject_MockObject The event renderer mock. + */ + protected function createEventRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer'); + } + + /** + * Creates an extendable aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator|\PHPUnit_Framework_MockObject_MockObject The extendable aggregator mock. + */ + protected function createExtendableAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator'); + } + + /** + * Creates an extendable renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer|\PHPUnit_Framework_MockObject_MockObject The extendable renderer mock. + */ + protected function createExtendableRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer'); + } + + /** + * Creates a formatter mock. + * + * @return \Ivory\GoogleMap\Helpers\Subscribers\Formatter|\PHPUnit_Framework_MockObject_MockObject The formatter mock. + */ + protected function createFormatterMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Subscribers\Formatter'); + } + + /** + * Creates a ground overlay aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator|\PHPUnit_Framework_MockObject_MockObject The ground overlay aggregator mock. + */ + protected function createGroundOverlayAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator'); + } + + /** + * Creates a ground overlay renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer|\PHPUnit_Framework_MockObject_MockObject The ground overlay renderer mock. + */ + protected function createGroundOverlayRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer'); + } + + /** + * Creates an helper event mock. + * + * @return \Ivory\GoogleMap\Helpers\AbstractEvent|\PHPUnit_Framework_MockObject_MockObject The helper event mock. + */ + protected function createHelperEventMock() + { + return $this->getMockForAbstractClass('Ivory\GoogleMap\Helpers\AbstractEvent'); + } + + /** + * Creates an helper mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The helper mock builder. + */ + protected function createHelperMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\AbstractHelper'); + } + + /** + * Creates an icon aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator|\PHPUnit_Framework_MockObject_MockObject The icon aggregator mock. + */ + protected function createIconAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator'); + } + + /** + * Creates an icon renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer|\PHPUnit_Framework_MockObject_MockObject The icon renderer mock. + */ + protected function createIconRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer'); + } + + /** + * Creates an info box renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer|\PHPUnit_Framework_MockObject_MockObject The info box render mock. + */ + protected function createInfoBoxRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer'); + } + + /** + * Creates an info window aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject The info window aggregator mock. + */ + protected function createInfoWindowAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator'); + } + + /** + * Creates an info window close renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer|\PHPUnit_Framework_MockObject_MockObject The info window close renderer mock. + */ + protected function createInfoWindowCloseRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer'); + } + + /** + * Creates an info window open renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer|\PHPUnit_Framework_MockObject_MockObject The info window open renderer mock. + */ + protected function createInfoWindowOpenRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer'); + } + + /** + * Creates an info window renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer|\PHPUnit_Framework_MockObject_MockObject The info window render mock. + */ + protected function createInfoWindowRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer'); + } + + /** + * Creates a json builder mock. + * + * @return \Ivory\JsonBuilder\JsonBuilder|\PHPUnit_Framework_MockObject_MockObject The json renderer mock. + */ + protected function createJsonBuilderMock() + { + return $this->getMock('Ivory\JsonBuilder\JsonBuilder'); + } + + /** + * Creates a kml layer aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator|\PHPUnit_Framework_MockObject_MockObject The kml layer aggregator mock. + */ + protected function createKmlLayerAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator'); + } + + /** + * Creates a kml layer renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer|\PHPUnit_Framework_MockObject_MockObject The kml layer renderer mock. + */ + protected function createKmlLayerRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer'); + } + + /** + * Creates a loader renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer|\PHPUnit_Framework_MockObject_MockObject The loader renderer mock. + */ + protected function createLoaderRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer'); + } + + /** + * Creates a map bound renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer|\PHPUnit_Framework_MockObject_MockObject The map bound renderer mock. + */ + protected function createMapBoundRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer'); + } + + /** + * Creates a map center renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer|\PHPUnit_Framework_MockObject_MockObject The map center renderer mock. + */ + protected function createMapCenterRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer'); + } + + /** + * Creates a map container renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer|\PHPUnit_Framework_MockObject_MockObject The map container renderer mock. + */ + protected function createMapContainerRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer'); + } + + /** + * Creates a map mock. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock() + { + return $this->getMock('Ivory\GoogleMap\Map'); + } + + /** + * Creates a map renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapRenderer|\PHPUnit_Framework_MockObject_MockObject The map renderer mock. + */ + protected function createMapRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\MapRenderer'); + } + + /** + * Creates a map type control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer|\PHPUnit_Framework_MockObject_MockObject The map type control renderer mock. + */ + protected function createMapTypeControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer'); + } + + /** + * Creates a map type control style renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer|\PHPUnit_Framework_MockObject_MockObject The map type control style renderer mock. + */ + protected function createMapTypeControlStyleRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer'); + } + + /** + * Creates a map type id renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer|\PHPUnit_Framework_MockObject_MockObject The map type id renderer mock. + */ + protected function createMapTypeIdRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer'); + } + + /** + * Creates a marker aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject The marker aggregator mock. + */ + protected function createMarkerAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator'); + } + + /** + * Creates a marker cluster renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer|\PHPUnit_Framework_MockObject_MockObject The marker cluster renderer mock. + */ + protected function createMarkerClusterRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer'); + } + + /** + * Creates a marker renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer|\PHPUnit_Framework_MockObject_MockObject The marker renderer mock. + */ + protected function createMarkerRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer'); + } + + /** + * Creates a marker shape aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator|\PHPUnit_Framework_MockObject_MockObject The marker shape aggregator mock. + */ + protected function createMarkerShapeAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator'); + } + + /** + * Creates a marker shape renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer|\PHPUnit_Framework_MockObject_MockObject The marker shape renderer mock. + */ + protected function createMarkerShapeRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer'); + } + + /** + * Creates an overview map control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer|\PHPUnit_Framework_MockObject_MockObject The overview map control renderer mock. + */ + protected function createOverviewMapControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer'); + } + + /** + * Creates a pan control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer|\PHPUnit_Framework_MockObject_MockObject The pan control renderer mock. + */ + protected function createPanControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer'); + } + + /** + * Creates a point aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator|\PHPUnit_Framework_MockObject_MockObject The point aggregator mock. + */ + protected function createPointAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator'); + } + + /** + * Creates a point renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer|\PHPUnit_Framework_MockObject_MockObject The point renderer mock. + */ + protected function createPointRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer'); + } + + /** + * Creates a polygon aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator|\PHPUnit_Framework_MockObject_MockObject The polygon aggregator mock. + */ + protected function createPolygonAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator'); + } + + /** + * Creates a polygon renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer|\PHPUnit_Framework_MockObject_MockObject The polygon renderer mock. + */ + protected function createPolygonRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer'); + } + + /** + * Creates a polyline aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator|\PHPUnit_Framework_MockObject_MockObject The polyline aggregator mock. + */ + protected function createPolylineAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator'); + } + + /** + * Creates a polyline renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer|\PHPUnit_Framework_MockObject_MockObject The polyline renderer mock. + */ + protected function createPolylineRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer'); + } + + /** + * Creates a rectangle aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator|\PHPUnit_Framework_MockObject_MockObject The rectangle aggregator mock. + */ + protected function createRectangleAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator'); + } + + /** + * Creates a rectangle renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer|\PHPUnit_Framework_MockObject_MockObject The rectangle renderer mock. + */ + protected function createRectangleRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer'); + } + + /** + * Creates a rotate control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer|\PHPUnit_Framework_MockObject_MockObject The rotate control renderer mock. + */ + protected function createRotateControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer'); + } + + /** + * Creates a scale control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer|\PHPUnit_Framework_MockObject_MockObject The scale control renderer mock. + */ + protected function createScaleControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer'); + } + + /** + * Creates a scale control style renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer|\PHPUnit_Framework_MockObject_MockObject The scale control style renderer mock. + */ + protected function createScaleControlStyleRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer'); + } + + /** + * Creates a size aggregator mock. + * + * @return \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator|\PHPUnit_Framework_MockObject_MockObject The size aggregator mock. + */ + protected function createSizeAggregatorMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator'); + } + + /** + * Creates a size renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer|\PHPUnit_Framework_MockObject_MockObject The size renderer mock. + */ + protected function createSizeRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer'); + } + + /** + * Creates a street view control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer|\PHPUnit_Framework_MockObject_MockObject The street view control renderer mock. + */ + protected function createStreetViewControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer'); + } + + /** + * Creates a symfony compiler pass mock. + * + * @return \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface|\PHPUnit_Framework_MockObject_MockObject The symfony compiler pass mock. + */ + protected function createSymfonyCompilerPassMock() + { + return $this->getMock('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'); + } + + /** + * Creates a symfony dependency injection extension mock. + * + * @return \Symfony\Component\DependencyInjection\Extension\ExtensionInterface|\PHPUnit_Framework_MockObject_MockObject The symfony dependency injection extension mock. + */ + protected function createSymfonyExtensionMock() + { + return $this->getMock('Symfony\Component\DependencyInjection\Extension\ExtensionInterface'); + } + + /** + * Creates a symfony event dispatcher mock. + * + * @return \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject The symfony event dispatcher mock. + */ + protected function createSymfonyEventDispatcherMock() + { + return $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface'); + } + + /** + * Creates a symfony event subscriber mock. + * + * @return \Symfony\Component\EventDispatcher\EventSubscriberInterface|\PHPUnit_Framework_MockObject_MockObject The symfony event subscriber mock. + */ + protected function createSymfonyEventSubscriberMock() + { + return $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface'); + } + + /** + * Creates a zoom control renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer|\PHPUnit_Framework_MockObject_MockObject The zoom control renderer mock. + */ + protected function createZoomControlRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer'); + } + + /** + * Creates a zoom control style renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer|\PHPUnit_Framework_MockObject_MockObject The zoom control style renderer mock. + */ + protected function createZoomControlStyleRendererMock() + { + return $this->getMock('Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer'); + } +} diff --git a/tests/Helpers/Aggregators/Base/BoundAggregatorTest.php b/tests/Helpers/Aggregators/Base/BoundAggregatorTest.php new file mode 100644 index 00000000..34de4e1d --- /dev/null +++ b/tests/Helpers/Aggregators/Base/BoundAggregatorTest.php @@ -0,0 +1,306 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Bound aggregator test. + * + * @author GeLo + */ +class BoundAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $groundOverlayAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $rectangleAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->boundAggregator = new BoundAggregator( + $this->groundOverlayAggregator = $this->createGroundOverlayAggregatorMock(), + $this->rectangleAggregator = $this->createRectangleAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->groundOverlayAggregator); + unset($this->rectangleAggregator); + unset($this->boundAggregator); + } + + public function testDefaultState() + { + $this->boundAggregator = new BoundAggregator(); + + $this->assertGroundOverlayAggregatorInstance($this->boundAggregator->getGroundOverlayAggregator()); + $this->assertRectangleAggregatorInstance($this->boundAggregator->getRectangleAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->groundOverlayAggregator, $this->boundAggregator->getGroundOverlayAggregator()); + $this->assertSame($this->rectangleAggregator, $this->boundAggregator->getRectangleAggregator()); + } + + public function testSetGroundOverlayAggregator() + { + $this->boundAggregator->setGroundOverlayAggregator( + $groundOverlayAggregator = $this->createGroundOverlayAggregatorMock() + ); + + $this->assertSame($groundOverlayAggregator, $this->boundAggregator->getGroundOverlayAggregator()); + } + + public function testSetRectangleAggregator() + { + $this->boundAggregator->setRectangleAggregator($rectangleAggregator = $this->createRectangleAggregatorMock()); + + $this->assertSame($rectangleAggregator, $this->boundAggregator->getRectangleAggregator()); + } + + /** + * @dataProvider aggregateGroundOverlaysProvider + */ + public function testAggregateGroundOverlays( + array $expected, + array $groundOverlays = array(), + array $bounds = array() + ) { + $map = $this->createMapMock(); + + $this->groundOverlayAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($groundOverlays)); + + $this->assertEquals($expected, $this->boundAggregator->aggregateGroundOverlays($map, $bounds)); + } + + /** + * @dataProvider aggregateRectanglesProvider + */ + public function testAggregateRectangles(array $expected, array $rectangles = array(), array $bounds = array()) + { + $map = $this->createMapMock(); + + $this->rectangleAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($rectangles)); + + $this->assertEquals($expected, $this->boundAggregator->aggregateRectangles($map, $bounds)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate( + array $expected, + array $groundOverlays = array(), + array $rectangles = array(), + Bound $bound = null, + array $bounds = array() + ) { + $map = $this->createMapMock($bound); + + $this->groundOverlayAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($groundOverlays)); + + $this->rectangleAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($rectangles)); + + $this->assertEquals($expected, $this->boundAggregator->aggregate($map, $bounds)); + } + + /** + * Gets the aggregate ground overlays provider. + * + * @return array The aggregate ground overlays provider. + */ + public function aggregateGroundOverlaysProvider() + { + $groundOverlay1 = $this->createGroundOverlayMock($bound1 = $this->createBoundMock()); + $groundOverlay2 = $this->createGroundOverlayMock($bound2 = $this->createBoundMock()); + $groundOverlay3 = $this->createGroundOverlayMock($bound1); + + $simpleGroundOverlays = array($groundOverlay1); + $fullGroundOverlays = array($groundOverlay1, $groundOverlay2, $groundOverlay3); + + $simpleBounds = array($bound1); + $fullBounds = array($bound1, $bound2); + + return array( + array(array()), + array($simpleBounds, $simpleGroundOverlays), + array($fullBounds, $fullGroundOverlays), + array($fullBounds, $fullGroundOverlays, $simpleBounds), + ); + } + + /** + * Gets the aggregate rectangles provider. + * + * @return array The aggregate rectangles provider. + */ + public function aggregateRectanglesProvider() + { + $rectangle1 = $this->createRectangleMock($bound1 = $this->createBoundMock()); + $rectangle2 = $this->createRectangleMock($bound2 = $this->createBoundMock()); + $rectangle3 = $this->createRectangleMock($bound1); + + $simpleRectangles = array($rectangle1); + $fullRectangles = array($rectangle1, $rectangle2, $rectangle3); + + $simpleBounds = array($bound1); + $fullBounds = array($bound1, $bound2); + + return array( + array(array()), + array($simpleBounds, $simpleRectangles), + array($fullBounds, $fullRectangles), + array($fullBounds, $fullRectangles, $simpleBounds), + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $groundOverlay1 = $this->createGroundOverlayMock($bound1 = $this->createBoundMock()); + $groundOverlay2 = $this->createGroundOverlayMock($bound2 = $this->createBoundMock()); + $groundOverlay3 = $this->createGroundOverlayMock($bound1); + + $rectangle1 = $this->createRectangleMock($bound3 = $this->createBoundMock()); + $rectangle2 = $this->createRectangleMock($bound4 = $this->createBoundMock()); + $rectangle3 = $this->createRectangleMock($bound3); + + $simpleGroundOverlays = array($groundOverlay1); + $fullGroundOverlays = array($groundOverlay1, $groundOverlay2, $groundOverlay3); + + $simpleRectangles = array($rectangle1); + $fullRectangles = array($rectangle1, $rectangle2, $rectangle3); + + $simpleBounds = array($bound1, $bound3); + $fullBounds = array($bound1, $bound2, $bound3, $bound4); + + return array( + array(array()), + array($simpleBounds, $simpleGroundOverlays, $simpleRectangles), + array($fullBounds, $fullGroundOverlays, $fullRectangles), + array( + array_merge(array($mapBound = $this->createBoundMock()), $fullBounds), + $fullGroundOverlays, + $fullRectangles, + $mapBound, + ), + array( + array_merge(array($mapBound = $this->createBoundMock()), $fullBounds), + $fullGroundOverlays, + $fullRectangles, + $mapBound, + array($mapBound, $bound1), + ), + ); + } + + /** + * Creates a ground overlay mock. + * + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. + * + * @return \Ivory\GoogleMap\Overlays\GroundOverlay|\PHPUnit_Framework_MockObject_MockObject The ground overlay mock. + */ + protected function createGroundOverlayMock(Bound $bound = null) + { + $groundOverlay = parent::createGroundOverlayMock(); + $groundOverlay + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + + return $groundOverlay; + } + + /** + * Creates a map mock. + * + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(Bound $bound = null) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock())); + + if ($bound !== null) { + $overlays + ->expects($this->any()) + ->method('isAutoZoom') + ->will($this->returnValue(true)); + + $map + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + } + + return $map; + } + + /** + * Creates a rectangle mock. + * + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. + * + * @return \Ivory\GoogleMap\Overlays\Rectangle|\PHPUnit_Framework_MockObject_MockObject The rectangle mock. + */ + protected function createRectangleMock(Bound $bound = null) + { + $rectangle = parent::createRectangleMock(); + $rectangle + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + + return $rectangle; + } +} diff --git a/tests/Helpers/Aggregators/Base/CoordinateAggregatorTest.php b/tests/Helpers/Aggregators/Base/CoordinateAggregatorTest.php new file mode 100644 index 00000000..00e0b18f --- /dev/null +++ b/tests/Helpers/Aggregators/Base/CoordinateAggregatorTest.php @@ -0,0 +1,788 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Coordinate aggregator test. + * + * @author GeLo + */ +class CoordinateAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $circleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $polygonAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $polylineAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->coordinateAggregator = new CoordinateAggregator( + $this->boundAggregator = $this->createBoundAggregatorMock(), + $this->circleAggregator = $this->createCircleAggregatorMock(), + $this->infoWindowAggregator = $this->createInfoWindowAggregatorMock(), + $this->markerAggregator = $this->createMarkerAggregatorMock(), + $this->polygonAggregator = $this->createPolygonAggregatorMock(), + $this->polylineAggregator = $this->createPolylineAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->polylineAggregator); + unset($this->polygonAggregator); + unset($this->markerAggregator); + unset($this->infoWindowAggregator); + unset($this->circleAggregator); + unset($this->boundAggregator); + unset($this->coordinateAggregator); + } + + public function testDefaultState() + { + $this->coordinateAggregator = new CoordinateAggregator(); + + $this->assertBoundAggregatorInstance($this->coordinateAggregator->getBoundAggregator()); + $this->assertCircleAggregatorInstance($this->coordinateAggregator->getCircleAggregator()); + $this->assertInfoWindowAggregatorInstance($this->coordinateAggregator->getInfoWindowAggregator()); + $this->assertMarkerAggregatorInstance($this->coordinateAggregator->getMarkerAggregator()); + $this->assertPolygonAggregatorInstance($this->coordinateAggregator->getPolygonAggregator()); + $this->assertPolylineAggregatorInstance($this->coordinateAggregator->getPolylineAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->boundAggregator, $this->coordinateAggregator->getBoundAggregator()); + $this->assertSame($this->circleAggregator, $this->coordinateAggregator->getCircleAggregator()); + $this->assertSame($this->infoWindowAggregator, $this->coordinateAggregator->getInfoWindowAggregator()); + $this->assertSame($this->markerAggregator, $this->coordinateAggregator->getMarkerAggregator()); + $this->assertSame($this->polygonAggregator, $this->coordinateAggregator->getPolygonAggregator()); + $this->assertSame($this->polylineAggregator, $this->coordinateAggregator->getPolylineAggregator()); + } + + public function testSetBoundAggregator() + { + $this->coordinateAggregator->setBoundAggregator($boundAggregator = $this->createBoundAggregatorMock()); + + $this->assertSame($boundAggregator, $this->coordinateAggregator->getBoundAggregator()); + } + + public function testSetCircleAggregator() + { + $this->coordinateAggregator->setCircleAggregator($circleAggregator = $this->createCircleAggregatorMock()); + + $this->assertSame($circleAggregator, $this->coordinateAggregator->getCircleAggregator()); + } + + public function testSetInfoWindowAggregator() + { + $this->coordinateAggregator->setInfoWindowAggregator( + $infoWindowAggregator = $this->createInfoWindowAggregatorMock() + ); + + $this->assertSame($infoWindowAggregator, $this->coordinateAggregator->getInfoWindowAggregator()); + } + + public function testSetMarkerAggregator() + { + $this->coordinateAggregator->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->coordinateAggregator->getMarkerAggregator()); + } + + public function testSetPolygonAggregator() + { + $this->coordinateAggregator->setPolygonAggregator($polygonAggregator = $this->createPolygonAggregatorMock()); + + $this->assertSame($polygonAggregator, $this->coordinateAggregator->getPolygonAggregator()); + } + + public function testSetPolylineAggregator() + { + $this->coordinateAggregator->setPolylineAggregator($polylineAggregator = $this->createPolylineAggregatorMock()); + + $this->assertSame($polylineAggregator, $this->coordinateAggregator->getPolylineAggregator()); + } + + /** + * @dataProvider aggregateBoundsProvider + */ + public function testAggregateBounds(array $expected, array $bounds = array(), array $coordinates = array()) + { + $map = $this->createMapMock(); + + $this->boundAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($bounds)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregateBounds($map, $coordinates)); + } + + /** + * @dataProvider aggregateCirclesProvider + */ + public function testAggregateCircles(array $expected, array $circles = array(), array $coordinates = array()) + { + $map = $this->createMapMock(); + + $this->circleAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($circles)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregateCircles($map, $coordinates)); + } + + /** + * @dataProvider aggregateInfoWindowsProvider + */ + public function testAggregateInfoWindows( + array $expected, + array $infoWindows = array(), + array $coordinates = array() + ) { + $map = $this->createMapMock(); + + $this->infoWindowAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($infoWindows)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregateInfoWindows($map, $coordinates)); + } + + /** + * @dataProvider aggregateMarkersProvider + */ + public function testAggregateMarkers(array $expected, array $markers = array(), array $coordinates = array()) + { + $map = $this->createMapMock(); + + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregateMarkers($map, $coordinates)); + } + + /** + * @dataProvider aggregatePolygonsProvider + */ + public function testAggregatePolygons(array $expected, array $polygons = array(), array $coordinates = array()) + { + $map = $this->createMapMock(); + + $this->polygonAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($polygons)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregatePolygons($map, $coordinates)); + } + + /** + * @dataProvider aggregatePolylinesProvider + */ + public function testAggregatePolylines(array $expected, array $polylines = array(), array $coordinates = array()) + { + $map = $this->createMapMock(); + + $this->polylineAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($polylines)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregatePolylines($map, $coordinates)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate( + array $expected, + array $bounds = array(), + array $circles = array(), + array $infoWindows = array(), + array $markers = array(), + array $polygons = array(), + array $polylines = array(), + Coordinate $center = null, + array $coordinates = array() + ) { + $map = $this->createMapMock($center); + + $this->boundAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($bounds)); + + $this->circleAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($circles)); + + $this->infoWindowAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($infoWindows)); + + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($markers)); + + $this->polygonAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($polygons)); + + $this->polylineAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($polylines)); + + $this->assertEquals($expected, $this->coordinateAggregator->aggregate($map, $coordinates)); + } + + /** + * Gets the aggregate bounds provider. + * + * @return array The aggregate bounds provider. + */ + public function aggregateBoundsProvider() + { + $bound1 = $this->createBoundMock(); + + $bound2 = $this->createBoundMock( + $coordinate1 = $this->createCoordinateMock(), + $coordinate2 = $this->createCoordinateMock() + ); + + $bound3 = $this->createBoundMock( + $coordinate3 = $this->createCoordinateMock(), + $coordinate4 = $this->createCoordinateMock() + ); + + $bound4 = $this->createBoundMock($coordinate1, $coordinate4); + + $simpleBounds = array($bound1, $bound2); + $fullBounds = array($bound1, $bound2, $bound3, $bound4); + + $simpleCoordinates = array($coordinate1, $coordinate2); + $fullCoordinates = array($coordinate1, $coordinate2, $coordinate3, $coordinate4); + + return array( + array(array()), + array($simpleCoordinates, $simpleBounds), + array($fullCoordinates, $fullBounds), + array($fullCoordinates, $fullBounds, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate circles provider. + * + * @return array The aggregate circles provider. + */ + public function aggregateCirclesProvider() + { + $circle1 = $this->createCircleMock($coordinate1 = $this->createCoordinateMock()); + $circle2 = $this->createCircleMock($coordinate2 = $this->createCoordinateMock()); + $circle3 = $this->createCircleMock($coordinate1); + + $simpleCircles = array($circle1); + $fullCircles = array($circle1, $circle2, $circle3); + + $simpleCoordinates = array($coordinate1); + $fullCoordinates = array($coordinate1, $coordinate2); + + return array( + array(array()), + array($simpleCoordinates, $simpleCircles), + array($fullCoordinates, $fullCircles), + array($fullCoordinates, $fullCircles, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate info windows provider. + * + * @return array The aggregate info windows provider. + */ + public function aggregateInfoWindowsProvider() + { + $infoWindow1 = $this->createInfoWindowMock($coordinate1 = $this->createCoordinateMock()); + $infoWindow2 = $this->createInfoWindowMock($coordinate2 = $this->createCoordinateMock()); + $infoWindow3 = $this->createInfoWindowMock($coordinate1); + + $simpleInfoWindows = array($infoWindow1); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3); + + $simpleCoordinates = array($coordinate1); + $fullCoordinates = array($coordinate1, $coordinate2); + + return array( + array(array()), + array($simpleCoordinates, $simpleInfoWindows), + array($fullCoordinates, $fullInfoWindows), + array($fullCoordinates, $fullInfoWindows, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate markers provider. + * + * @return array The aggregate markers provider. + */ + public function aggregateMarkersProvider() + { + $marker1 = $this->createMarkerMock($coordinate1 = $this->createCoordinateMock()); + $marker2 = $this->createMarkerMock($coordinate2 = $this->createCoordinateMock()); + $marker3 = $this->createMarkerMock($coordinate1); + + $simpleMarkers = array($marker1); + $fullMarkers = array($marker1, $marker2, $marker3); + + $simpleCoordinates = array($coordinate1); + $fullCoordinates = array($coordinate1, $coordinate2); + + return array( + array(array()), + array($simpleCoordinates, $simpleMarkers), + array($fullCoordinates, $fullMarkers), + array($fullCoordinates, $fullMarkers, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate polygons provider. + * + * @return array The aggregate polygons provider. + */ + public function aggregatePolygonsProvider() + { + $polygon1 = $this->createPolygonMock($coordinates1 = array( + $coordinate1 = $this->createCoordinateMock(), + $this->createCoordinateMock(), + )); + + $polygon2 = $this->createPolygonMock($coordinates2 = array( + $this->createCoordinateMock(), + $this->createCoordinateMock(), + )); + + $polygon3 = $this->createPolygonMock(array($coordinate1, $coordinate5 = $this->createCoordinateMock())); + + $simplePolygons = array($polygon1); + $fullPolygons = array($polygon1, $polygon2, $polygon3); + + $simpleCoordinates = $coordinates1; + $fullCoordinates = array_merge($coordinates1, $coordinates2, array($coordinate5)); + + return array( + array(array()), + array($simpleCoordinates, $simplePolygons), + array($fullCoordinates, $fullPolygons), + array($fullCoordinates, $fullPolygons, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate polylines provider. + * + * @return array The aggregate polylines provider. + */ + public function aggregatePolylinesProvider() + { + $polyline1 = $this->createPolylineMock($coordinates1 = array( + $coordinate1 = $this->createCoordinateMock(), + $this->createCoordinateMock(), + )); + + $polyline2 = $this->createPolylineMock($coordinates2 = array( + $this->createCoordinateMock(), + $this->createCoordinateMock(), + )); + + $polyline3 = $this->createPolylineMock(array($coordinate1, $coordinate5 = $this->createCoordinateMock())); + + $simplePolylines = array($polyline1); + $fullPolylines = array($polyline1, $polyline2, $polyline3); + + $simpleCoordinates = $coordinates1; + $fullCoordinates = array_merge($coordinates1, $coordinates2, array($coordinate5)); + + return array( + array(array()), + array($simpleCoordinates, $simplePolylines), + array($fullCoordinates, $fullPolylines), + array($fullCoordinates, $fullPolylines, $simpleCoordinates), + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $bound1 = $this->createBoundMock(); + + $bound2 = $this->createBoundMock( + $coordinate1 = $this->createCoordinateMock(), + $coordinate2 = $this->createCoordinateMock() + ); + + $bound3 = $this->createBoundMock( + $coordinate3 = $this->createCoordinateMock(), + $coordinate4 = $this->createCoordinateMock() + ); + + $bound4 = $this->createBoundMock($coordinate1, $coordinate4); + + $circle1 = $this->createCircleMock($coordinate5 = $this->createCoordinateMock()); + $circle2 = $this->createCircleMock($coordinate6 = $this->createCoordinateMock()); + $circle3 = $this->createCircleMock($coordinate5); + + $infoWindow1 = $this->createInfoWindowMock($coordinate7 = $this->createCoordinateMock()); + $infoWindow2 = $this->createInfoWindowMock($coordinate8 = $this->createCoordinateMock()); + $infoWindow3 = $this->createInfoWindowMock($coordinate7); + + $marker1 = $this->createMarkerMock($coordinate9 = $this->createCoordinateMock()); + $marker2 = $this->createMarkerMock($coordinate10 = $this->createCoordinateMock()); + $marker3 = $this->createMarkerMock($coordinate9); + + $polygon1 = $this->createPolygonMock(array( + $coordinate11 = $this->createCoordinateMock(), + $coordinate12 = $this->createCoordinateMock(), + )); + + $polygon2 = $this->createPolygonMock($coordinates2 = array( + $coordinate13 = $this->createCoordinateMock(), + $coordinate14 = $this->createCoordinateMock(), + )); + + $polygon3 = $this->createPolygonMock(array($coordinate11, $coordinate15 = $this->createCoordinateMock())); + + $polyline1 = $this->createPolylineMock($coordinates1 = array( + $coordinate16 = $this->createCoordinateMock(), + $coordinate17 = $this->createCoordinateMock(), + )); + + $polyline2 = $this->createPolylineMock($coordinates2 = array( + $coordinate18 = $this->createCoordinateMock(), + $coordinate19 = $this->createCoordinateMock(), + )); + + $polyline3 = $this->createPolylineMock(array($coordinate16, $coordinate20 = $this->createCoordinateMock())); + + $mapCenter = $this->createCoordinateMock(); + + $simpleBounds = array($bound1, $bound2); + $fullBounds = array($bound1, $bound2, $bound3, $bound4); + + $simpleCircles = array($circle1); + $fullCircles = array($circle1, $circle2, $circle3); + + $simpleInfoWindows = array($infoWindow1); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3); + + $simpleMarkers = array($marker1); + $fullMarkers = array($marker1, $marker2, $marker3); + + $simplePolygons = array($polygon1); + $fullPolygons = array($polygon1, $polygon2, $polygon3); + + $simplePolylines = array($polyline1); + $fullPolylines = array($polyline1, $polyline2, $polyline3); + + $simpleCoordinates = array( + $coordinate1, + $coordinate2, + $coordinate5, + $coordinate7, + $coordinate9, + $coordinate11, + $coordinate12, + $coordinate16, + $coordinate17, + ); + + $fullCoordinates = array( + $coordinate1, + $coordinate2, + $coordinate3, + $coordinate4, + $coordinate5, + $coordinate6, + $coordinate7, + $coordinate8, + $coordinate9, + $coordinate10, + $coordinate11, + $coordinate12, + $coordinate13, + $coordinate14, + $coordinate15, + $coordinate16, + $coordinate17, + $coordinate18, + $coordinate19, + $coordinate20, + ); + + return array( + array(array()), + array( + $simpleCoordinates, + $simpleBounds, + $simpleCircles, + $simpleInfoWindows, + $simpleMarkers, + $simplePolygons, + $simplePolylines, + ), + array( + $fullCoordinates, + $fullBounds, + $fullCircles, + $fullInfoWindows, + $fullMarkers, + $fullPolygons, + $fullPolylines, + ), + array( + array_merge(array($mapCenter), $fullCoordinates), + $fullBounds, + $fullCircles, + $fullInfoWindows, + $fullMarkers, + $fullPolygons, + $fullPolylines, + $mapCenter, + $simpleCoordinates, + ), + array( + array_merge(array($mapCenter), $fullCoordinates), + $fullBounds, + $fullCircles, + $fullInfoWindows, + $fullMarkers, + $fullPolygons, + $fullPolylines, + $mapCenter, + $simpleCoordinates, + ), + ); + } + + /** + * Creates a bound mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $southWest The south west. + * @param \Ivory\GoogleMap\Base\Coordinate|null $northEast The north east. + * + * @return \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject The bound mock. + */ + protected function createBoundMock(Coordinate $southWest = null, Coordinate $northEast = null) + { + $bound = parent::createBoundMock(); + + if ($southWest !== null) { + $bound + ->expects($this->any()) + ->method('getSouthWest') + ->will($this->returnValue($southWest)); + } + + if ($northEast !== null) { + $bound + ->expects($this->any()) + ->method('getNorthEast') + ->will($this->returnValue($northEast)); + } + + if ($southWest !== null && $northEast !== null) { + $bound + ->expects($this->any()) + ->method('hasCoordinates') + ->will($this->returnValue(true)); + } + + return $bound; + } + + /** + * Creates an circle mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $center The center. + * + * @return \Ivory\GoogleMap\Overlays\Circle|\PHPUnit_Framework_MockObject_MockObject The circle mock. + */ + protected function createCircleMock(Coordinate $center = null) + { + $circle = parent::createCircleMock(); + $circle + ->expects($this->any()) + ->method('getCenter') + ->will($this->returnValue($center)); + + return $circle; + } + + /** + * Creates an info window mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock(Coordinate $position = null) + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('hasPosition') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue($position)); + + return $infoWindow; + } + + /** + * Creates a map mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $center The center. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(Coordinate $center = null) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock())); + + if ($center !== null) { + $map + ->expects($this->any()) + ->method('getCenter') + ->will($this->returnValue($center)); + } else { + $overlays + ->expects($this->any()) + ->method('isAutoZoom') + ->will($this->returnValue(true)); + } + + return $map; + } + + /** + * Creates a maker mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(Coordinate $position = null) + { + $marker = parent::createMarkerMock(); + $marker + ->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue($position)); + + return $marker; + } + + /** + * Creates a polygon mock. + * + * @param array $coordinates The coordinates. + * + * @return \Ivory\GoogleMap\Overlays\Polygon|\PHPUnit_Framework_MockObject_MockObject The polygon mock. + */ + protected function createPolygonMock(array $coordinates = array()) + { + $polygon = parent::createPolygonMock(); + $polygon + ->expects($this->any()) + ->method('getCoordinates') + ->will($this->returnValue($coordinates)); + + return $polygon; + } + + /** + * Creates a polyline mock. + * + * @param array $coordinates The coordinates. + * + * @return \Ivory\GoogleMap\Overlays\Polyline|\PHPUnit_Framework_MockObject_MockObject The polyline mock. + */ + protected function createPolylineMock(array $coordinates = array()) + { + $polyline = parent::createPolylineMock(); + $polyline + ->expects($this->any()) + ->method('getCoordinates') + ->will($this->returnValue($coordinates)); + + return $polyline; + } +} diff --git a/tests/Helpers/Aggregators/Base/PointAggregatorTest.php b/tests/Helpers/Aggregators/Base/PointAggregatorTest.php new file mode 100644 index 00000000..3994d0c3 --- /dev/null +++ b/tests/Helpers/Aggregators/Base/PointAggregatorTest.php @@ -0,0 +1,221 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Base\Point; +use Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator; +use Ivory\GoogleMap\Overlays\Icon; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Point aggregator test. + * + * @author GeLo + */ +class PointAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator */ + protected $pointAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->pointAggregator = new PointAggregator($this->markerAggregator = $this->createMarkerAggregatorMock()); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerAggregator); + unset($this->pointAggregator); + } + + public function testDefaultState() + { + $this->pointAggregator = new PointAggregator(); + + $this->assertMarkerAggregatorInstance($this->pointAggregator->getMarkerAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->markerAggregator, $this->pointAggregator->getMarkerAggregator()); + } + + public function testSetMarkerAggregator() + { + $this->pointAggregator->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->pointAggregator->getMarkerAggregator()); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregateMarkers(array $expected, array $markers = array(), array $points = array()) + { + $map = $this->createMapMock(); + + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->pointAggregator->aggregateMarkers($map, $points)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate($expected, $markers = array(), array $points = array()) + { + $map = $this->createMapMock(); + + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->pointAggregator->aggregate($map, $points)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $marker1 = $this->createMarkerMock(); + + $marker2 = $this->createMarkerMock($this->createIconMock( + $point1 = $this->createPointMock(), + $point2 = $this->createPointMock() + )); + + $marker3 = $this->createMarkerMock(null, $this->createIconMock( + $point3 = $this->createPointMock(), + $point4 = $this->createPointMock() + )); + + $marker4 = $this->createMarkerMock( + $this->createIconMock( + $point5 = $this->createPointMock(), + $point3 + ), + $this->createIconMock( + $point3, + $point2 + ) + ); + + $simpleMarkers = array($marker1, $marker2, $marker3); + $fullMarkers = array($marker1, $marker2, $marker3, $marker4); + + $simplePoints = array($point1, $point2, $point3, $point4); + $fullPoints = array($point1, $point2, $point3, $point4, $point5); + + return array( + array(array()), + array($simplePoints, $simpleMarkers), + array($fullPoints, $fullMarkers), + array($fullPoints, $fullMarkers, $simplePoints), + ); + } + + /** + * Creates an icon mock. + * + * @param \Ivory\GoogleMap\Base\Point|null $anchor The anchor. + * @param \Ivory\GoogleMap\Base\Point|null $origin The origin. + * + * @return \Ivory\GoogleMap\Overlays\Icon|\PHPUnit_Framework_MockObject_MockObject The icon mock. + */ + protected function createIconMock(Point $anchor = null, Point $origin = null) + { + $icon = parent::createIconMock(); + + if ($anchor !== null) { + $icon + ->expects($this->any()) + ->method('hasAnchor') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getAnchor') + ->will($this->returnValue($anchor)); + } + + if ($origin !== null) { + $icon + ->expects($this->any()) + ->method('hasOrigin') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getOrigin') + ->will($this->returnValue($origin)); + } + + return $icon; + } + + /** + * Creates a marker mock. + * + * @param \Ivory\GoogleMap\Overlays\Icon|null $icon The icon. + * @param \Ivory\GoogleMap\Overlays\Icon|null $shadow The shadow. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(Icon $icon = null, Icon $shadow = null) + { + $marker = parent::createMarkerMock(); + + if ($icon !== null) { + $marker + ->expects($this->any()) + ->method('hasIcon') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getIcon') + ->will($this->returnValue($icon)); + } + + if ($shadow !== null) { + $marker + ->expects($this->any()) + ->method('hasShadow') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getShadow') + ->will($this->returnValue($shadow)); + } + + return $marker; + } +} diff --git a/tests/Helpers/Aggregators/Base/SizeAggregatorTest.php b/tests/Helpers/Aggregators/Base/SizeAggregatorTest.php new file mode 100644 index 00000000..e2325972 --- /dev/null +++ b/tests/Helpers/Aggregators/Base/SizeAggregatorTest.php @@ -0,0 +1,291 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Base; + +use Ivory\GoogleMap\Base\Size; +use Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Size aggregator test. + * + * @author GeLo + */ +class SizeAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator */ + protected $sizeAggreator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $iconAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->sizeAggreator = new SizeAggregator( + $this->infoWindowAggregator = $this->createInfoWindowAggregatorMock(), + $this->iconAggregator = $this->createIconAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->iconAggregator); + unset($this->infoWindowAggregator); + unset($this->sizeAggreator); + } + + public function testDefaultState() + { + $this->sizeAggreator = new SizeAggregator(); + + $this->assertInfoWindowAggregatorInstance($this->sizeAggreator->getInfoWindowAggregator()); + $this->assertIconAggregatorInstance($this->sizeAggreator->getIconAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->infoWindowAggregator, $this->sizeAggreator->getInfoWindowAggregator()); + $this->assertSame($this->iconAggregator, $this->sizeAggreator->getIconAggregator()); + } + + public function testSetInfoWindowAggregator() + { + $this->sizeAggreator->setInfoWindowAggregator($infoWindowAggregator = $this->createInfoWindowAggregatorMock()); + + $this->assertSame($infoWindowAggregator, $this->sizeAggreator->getInfoWindowAggregator()); + } + + public function testSetIconAggregator() + { + $this->sizeAggreator->setIconAggregator($iconAggregator = $this->createIconAggregatorMock()); + + $this->assertSame($iconAggregator, $this->sizeAggreator->getIconAggregator()); + } + + /** + * @dataProvider aggregateInfoWindowsProvider + */ + public function testAggregateInfoWindows(array $expected, array $infoWindows = array(), array $sizes = array()) + { + $map = $this->createMapMock(); + + $this->infoWindowAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($infoWindows)); + + $this->assertEquals($expected, $this->sizeAggreator->aggregateInfoWindows($map, $sizes)); + } + + /** + * @dataProvider aggregateIconsProvider + */ + public function testAggregateIcons(array $expected, array $icons = array(), array $sizes = array()) + { + $map = $this->createMapMock(); + + $this->iconAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($icons)); + + $this->assertEquals($expected, $this->sizeAggreator->aggregateIcons($map, $sizes)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate( + array $expected, + array $infoWindows = array(), + array $icons = array(), + array $sizes = array() + ) { + $map = $this->createMapMock(); + + $this->infoWindowAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($infoWindows)); + + $this->iconAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue($icons)); + + $this->assertEquals($expected, $this->sizeAggreator->aggregate($map, $sizes)); + } + + /** + * Gets the aggregate info windows provider. + * + * @return array The aggregate info windows provider. + */ + public function aggregateInfoWindowsProvider() + { + $infoWindow1 = $this->createInfoWindowMock(); + $infoWindow2 = $this->createInfoWindowMock($size1 = $this->createSizeMock()); + $infoWindow3 = $this->createInfoWindowMock($size2 = $this->createSizeMock()); + $infoWindow4 = $this->createInfoWindowMock($size1); + + $simpleInfoWindows = array($infoWindow1, $infoWindow2); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3, $infoWindow4); + + $simpleSizes = array($size1); + $fullSizes = array($size1, $size2); + + return array( + array(array()), + array($simpleSizes, $simpleInfoWindows), + array($fullSizes, $fullInfoWindows), + array($fullSizes, $fullInfoWindows, $simpleSizes), + ); + } + + /** + * Gets the aggregate icons provider. + * + * @return array The aggregate icons provider. + */ + public function aggregateIconsProvider() + { + $icon1 = $this->createIconMock(); + $icon2 = $this->createIconMock($size1 = $this->createSizeMock()); + $icon3 = $this->createIconMock($size2 = $this->createSizeMock(), $size3 = $this->createSizeMock()); + $icon4 = $this->createIconMock($size1, $size4 = $this->createSizeMock()); + + $simpleIcons = array($icon1, $icon2, $icon3); + $fullIcons = array($icon1, $icon2, $icon3, $icon4); + + $simpleSizes = array($size1, $size2, $size3); + $fullSizes = array($size1, $size2, $size3, $size4); + + return array( + array(array()), + array($simpleSizes, $simpleIcons), + array($fullSizes, $fullIcons), + array($fullSizes, $fullIcons, $simpleSizes), + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $infoWindow1 = $this->createInfoWindowMock(); + $infoWindow2 = $this->createInfoWindowMock($size1 = $this->createSizeMock()); + $infoWindow3 = $this->createInfoWindowMock($size2 = $this->createSizeMock()); + $infoWindow4 = $this->createInfoWindowMock($size1); + + $icon1 = $this->createIconMock(); + $icon2 = $this->createIconMock($size3 = $this->createSizeMock()); + $icon3 = $this->createIconMock($size4 = $this->createSizeMock(), $size5 = $this->createSizeMock()); + $icon4 = $this->createIconMock($size3, $size6 = $this->createSizeMock()); + + $simpleInfoWindows = array($infoWindow1, $infoWindow2); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3, $infoWindow4); + + $simpleIcons = array($icon1, $icon2, $icon3); + $fullIcons = array($icon1, $icon2, $icon3, $icon4); + + $simpleSizes = array($size1, $size3, $size4, $size5); + $fullSizes = array($size1, $size2, $size3, $size4, $size5, $size6); + + return array( + array(array()), + array($simpleSizes, $simpleInfoWindows, $simpleIcons), + array($fullSizes, $fullInfoWindows, $fullIcons), + array($fullSizes, $fullInfoWindows, $fullIcons, $simpleSizes), + ); + } + + /** + * Creates an icon mock. + * + * @param \Ivory\GoogleMap\Base\Size|null $size The size. + * @param \Ivory\GoogleMap\Base\Size|null $scaledSize The scaled size. + * + * @return \Ivory\GoogleMap\Overlays\Icon|\PHPUnit_Framework_MockObject_MockObject The icon mock. + */ + protected function createIconMock(Size $size = null, Size $scaledSize = null) + { + $icon = parent::createIconMock(); + + if ($size !== null) { + $icon + ->expects($this->any()) + ->method('hasSize') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getSize') + ->will($this->returnValue($size)); + } + + if ($scaledSize !== null) { + $icon + ->expects($this->any()) + ->method('hasScaledSize') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getScaledSize') + ->will($this->returnValue($scaledSize)); + } + + return $icon; + } + + /** + * Creates an info window mock. + * + * @param \Ivory\GoogleMap\Base\Size|null $pixelOffset The pixel offset. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock(Size $pixelOffset = null) + { + $infoWindow = parent::createInfoWindowMock(); + + if ($pixelOffset !== null) { + $infoWindow + ->expects($this->any()) + ->method('hasPixelOffset') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPixelOffset') + ->will($this->returnValue($pixelOffset)); + } + + return $infoWindow; + } +} diff --git a/tests/Helpers/Aggregators/Events/DomEventAggregatorTest.php b/tests/Helpers/Aggregators/Events/DomEventAggregatorTest.php new file mode 100644 index 00000000..1b25462b --- /dev/null +++ b/tests/Helpers/Aggregators/Events/DomEventAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Dom event aggregator test. + * + * @author GeLo + */ +class DomEventAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator */ + protected $domEventAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->domEventAggregator = new DomEventAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->domEventAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $domEvents = array(), array $events = array()) + { + $this->assertEquals($expected, $this->domEventAggregator->aggregate($this->createMapMock($domEvents), $events)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $domEvent1 = $this->createDomEventMock(); + $domEvent2 = $this->createDomEventMock(); + + $simpleDomEvents = array($domEvent1, $domEvent2); + $fullDomEvents = array($domEvent1, $domEvent2, $domEvent1); + + return array( + array(array()), + array($simpleDomEvents, $simpleDomEvents), + array($simpleDomEvents, $fullDomEvents), + array($simpleDomEvents, $fullDomEvents), + array($simpleDomEvents, $fullDomEvents, array($domEvent1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $domEvents The dom events. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $domEvents = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($overlays = $this->createEventsMock($domEvents))); + + return $map; + } + + /** + * Creates an events mock. + * + * @param array $domEvents The dom events. + * + * @return \Ivory\GoogleMap\Events\Events|\PHPUnit_Framework_MockObject_MockObject The events mock. + */ + protected function createEventsMock(array $domEvents = array()) + { + $events = parent::createEventsMock(); + $events + ->expects($this->any()) + ->method('getDomEvents') + ->will($this->returnValue($domEvents)); + + return $events; + } +} diff --git a/tests/Helpers/Aggregators/Events/DomEventOnceAggregatorTest.php b/tests/Helpers/Aggregators/Events/DomEventOnceAggregatorTest.php new file mode 100644 index 00000000..663a3168 --- /dev/null +++ b/tests/Helpers/Aggregators/Events/DomEventOnceAggregatorTest.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Dom event aggregator test. + * + * @author GeLo + */ +class DomEventOnceOnceAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator */ + protected $domEventOnceAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->domEventOnceAggregator = new DomEventOnceAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->domEventOnceAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $domEventOnces = array(), array $events = array()) + { + $this->assertEquals( + $expected, + $this->domEventOnceAggregator->aggregate($this->createMapMock($domEventOnces), $events) + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $domEventOnce1 = $this->createDomEventMock(); + $domEventOnce2 = $this->createDomEventMock(); + + $simpleDomEventOnces = array($domEventOnce1, $domEventOnce2); + $fullDomEventOnces = array($domEventOnce1, $domEventOnce2, $domEventOnce1); + + return array( + array(array()), + array($simpleDomEventOnces, $simpleDomEventOnces), + array($simpleDomEventOnces, $fullDomEventOnces), + array($simpleDomEventOnces, $fullDomEventOnces), + array($simpleDomEventOnces, $fullDomEventOnces, array($domEventOnce1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $domEventOnces The dom events once. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $domEventOnces = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($overlays = $this->createEventsMock($domEventOnces))); + + return $map; + } + + /** + * Creates an events mock. + * + * @param array $domEventOnces The dom events once. + * + * @return \Ivory\GoogleMap\Events\Events|\PHPUnit_Framework_MockObject_MockObject The events mock. + */ + protected function createEventsMock(array $domEventOnces = array()) + { + $events = parent::createEventsMock(); + $events + ->expects($this->any()) + ->method('getDomEventsOnce') + ->will($this->returnValue($domEventOnces)); + + return $events; + } +} diff --git a/tests/Helpers/Aggregators/Events/EventAggregatorTest.php b/tests/Helpers/Aggregators/Events/EventAggregatorTest.php new file mode 100644 index 00000000..62ea5d84 --- /dev/null +++ b/tests/Helpers/Aggregators/Events/EventAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Events; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Event aggregator test. + * + * @author GeLo + */ +class EventAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator */ + protected $eventAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventAggregator = new EventAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $events = array(), array $base = array()) + { + $this->assertEquals($expected, $this->eventAggregator->aggregate($this->createMapMock($events), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $event1 = $this->createEventMock(); + $event2 = $this->createEventMock(); + + $simpleEvents = array($event1, $event2); + $fullEvents = array($event1, $event2, $event1); + + return array( + array(array()), + array($simpleEvents, $simpleEvents), + array($simpleEvents, $fullEvents), + array($simpleEvents, $fullEvents), + array($simpleEvents, $fullEvents, array($event1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $events The events. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $events = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($overlays = $this->createEventsMock($events))); + + return $map; + } + + /** + * Creates an events mock. + * + * @param array $events The events. + * + * @return \Ivory\GoogleMap\Events\Events|\PHPUnit_Framework_MockObject_MockObject The events mock. + */ + protected function createEventsMock(array $events = array()) + { + $mock = parent::createEventsMock(); + $mock + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($events)); + + return $mock; + } +} diff --git a/tests/Helpers/Aggregators/Events/EventOnceAggregatorTest.php b/tests/Helpers/Aggregators/Events/EventOnceAggregatorTest.php new file mode 100644 index 00000000..e8af40f9 --- /dev/null +++ b/tests/Helpers/Aggregators/Events/EventOnceAggregatorTest.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\EventOnces; + +use Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * EventOnce aggregator test. + * + * @author GeLo + */ +class EventOnceOnceAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\EventOnces\EventOnceAggregator */ + protected $eventOnceAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventOnceAggregator = new EventOnceAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventOnceAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $eventOnces = array(), array $events = array()) + { + $this->assertEquals( + $expected, + $this->eventOnceAggregator->aggregate($this->createMapMock($eventOnces), $events) + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $eventOnce1 = $this->createEventMock(); + $eventOnce2 = $this->createEventMock(); + + $simpleEventOnces = array($eventOnce1, $eventOnce2); + $fullEventOnces = array($eventOnce1, $eventOnce2, $eventOnce1); + + return array( + array(array()), + array($simpleEventOnces, $simpleEventOnces), + array($simpleEventOnces, $fullEventOnces), + array($simpleEventOnces, $fullEventOnces), + array($simpleEventOnces, $fullEventOnces, array($eventOnce1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $eventOnces The event onces. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $eventOnces = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($overlays = $this->createEventsMock($eventOnces))); + + return $map; + } + + /** + * Creates an events mock. + * + * @param array $eventOnces The event onces. + * + * @return \Ivory\GoogleMap\Events\Events|\PHPUnit_Framework_MockObject_MockObject The events mock. + */ + protected function createEventsMock(array $eventOnces = array()) + { + $events = parent::createEventsMock(); + $events + ->expects($this->any()) + ->method('getEventsOnce') + ->will($this->returnValue($eventOnces)); + + return $events; + } +} diff --git a/tests/Helpers/Aggregators/Layers/KmlLayerAggregatorTest.php b/tests/Helpers/Aggregators/Layers/KmlLayerAggregatorTest.php new file mode 100644 index 00000000..4382bf9c --- /dev/null +++ b/tests/Helpers/Aggregators/Layers/KmlLayerAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\KmlLayers; + +use Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Kml layer aggregator test. + * + * @author GeLo + */ +class KmlLayerAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator */ + protected $kmlLayerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->kmlLayerAggregator = new KmlLayerAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->kmlLayerAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $kmlLayers = array(), array $base = array()) + { + $this->assertEquals($expected, $this->kmlLayerAggregator->aggregate($this->createMapMock($kmlLayers), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $kmlLayer1 = $this->createKmlLayerMock(); + $kmlLayer2 = $this->createKmlLayerMock(); + + $simpleKmlLayers = array($kmlLayer1, $kmlLayer2); + $fullKmlLayers = array($kmlLayer1, $kmlLayer2, $kmlLayer1); + + return array( + array(array()), + array($simpleKmlLayers, $simpleKmlLayers), + array($simpleKmlLayers, $fullKmlLayers), + array($simpleKmlLayers, $fullKmlLayers), + array($simpleKmlLayers, $fullKmlLayers, array($kmlLayer1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $kmlLayers The kml layers. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $kmlLayers = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getLayers') + ->will($this->returnValue($overlays = $this->createLayersMock($kmlLayers))); + + return $map; + } + + /** + * Creates an layers mock. + * + * @param array $kmlLayers The kml layers. + * + * @return \Ivory\GoogleMap\Layers\Layers|\PHPUnit_Framework_MockObject_MockObject The layers mock. + */ + protected function createLayersMock(array $kmlLayers = array()) + { + $layers = parent::createLayersMock(); + $layers + ->expects($this->any()) + ->method('getKmlLayers') + ->will($this->returnValue($kmlLayers)); + + return $layers; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/CircleAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/CircleAggregatorTest.php new file mode 100644 index 00000000..5bc51d22 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/CircleAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Circles; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Circle aggregator test. + * + * @author GeLo + */ +class CircleAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator */ + protected $circleAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->circleAggregator = new CircleAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->circleAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $circles = array(), array $base = array()) + { + $this->assertEquals($expected, $this->circleAggregator->aggregate($this->createMapMock($circles), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $circle1 = $this->createCircleMock(); + $circle2 = $this->createCircleMock(); + + $simpleCircles = array($circle1, $circle2); + $fullCircles = array($circle1, $circle2, $circle1); + + return array( + array(array()), + array($simpleCircles, $simpleCircles), + array($simpleCircles, $fullCircles), + array($simpleCircles, $fullCircles), + array($simpleCircles, $fullCircles, array($circle1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $circles The circles. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $circles = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($circles))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $circles The circles. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $circles = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getCircles') + ->will($this->returnValue($circles)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/EncodedPolylineAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/EncodedPolylineAggregatorTest.php new file mode 100644 index 00000000..5beb081b --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/EncodedPolylineAggregatorTest.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\EncodedPolylines; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Encoded polyline aggregator test. + * + * @author GeLo + */ +class EncodedPolylineAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator */ + protected $encodedPolylineAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->encodedPolylineAggregator = new EncodedPolylineAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->encodedPolylineAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $encodedPolylines = array(), array $base = array()) + { + $this->assertEquals( + $expected, + $this->encodedPolylineAggregator->aggregate($this->createMapMock($encodedPolylines), $base) + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $encodedPolyline1 = $this->createEncodedPolylineMock(); + $encodedPolyline2 = $this->createEncodedPolylineMock(); + + $simpleEncodedPolylines = array($encodedPolyline1, $encodedPolyline2); + $fullEncodedPolylines = array($encodedPolyline1, $encodedPolyline2, $encodedPolyline1); + + return array( + array(array()), + array($simpleEncodedPolylines, $simpleEncodedPolylines), + array($simpleEncodedPolylines, $fullEncodedPolylines), + array($simpleEncodedPolylines, $fullEncodedPolylines), + array($simpleEncodedPolylines, $fullEncodedPolylines, array($encodedPolyline1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $encodedPolylines The encoded polylines. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $encodedPolylines = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($encodedPolylines))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $encodedPolylines The encoded polylines. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $encodedPolylines = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getEncodedPolylines') + ->will($this->returnValue($encodedPolylines)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/ExtendableAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/ExtendableAggregatorTest.php new file mode 100644 index 00000000..13747609 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/ExtendableAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Extendables; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Extendable aggregator test. + * + * @author GeLo + */ +class ExtendableAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator */ + protected $extendableAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->extendableAggregator = new ExtendableAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->extendableAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $extends = array(), array $base = array()) + { + $this->assertEquals($expected, $this->extendableAggregator->aggregate($this->createMapMock($extends), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $extendable1 = $this->createExtendableMock(); + $extendable2 = $this->createExtendableMock(); + + $simpleExtendables = array($extendable1, $extendable2); + $fullExtendables = array($extendable1, $extendable2, $extendable1); + + return array( + array(array()), + array($simpleExtendables, $simpleExtendables), + array($simpleExtendables, $fullExtendables), + array($simpleExtendables, $fullExtendables), + array($simpleExtendables, $fullExtendables, array($extendable1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $extends The extends. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $extends = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($extends))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $extends The extends. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $extends = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getExtends') + ->will($this->returnValue($extends)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/GroundOverlayAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/GroundOverlayAggregatorTest.php new file mode 100644 index 00000000..7021fcec --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/GroundOverlayAggregatorTest.php @@ -0,0 +1,111 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\GroundOverlays; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Ground overlay aggregator test. + * + * @author GeLo + */ +class GroundOverlayAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator */ + protected $groundOverlayAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->groundOverlayAggregator = new GroundOverlayAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->groundOverlayAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $groundOverlays = array(), array $base = array()) + { + $this->assertEquals( + $expected, + $this->groundOverlayAggregator->aggregate($this->createMapMock($groundOverlays), $base) + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $groundOverlay1 = $this->createGroundOverlayMock(); + $groundOverlay2 = $this->createGroundOverlayMock(); + + $simpleGroundOverlays = array($groundOverlay1, $groundOverlay2); + $fullGroundOverlays = array($groundOverlay1, $groundOverlay2, $groundOverlay1); + + return array( + array(array()), + array($simpleGroundOverlays, $simpleGroundOverlays), + array($simpleGroundOverlays, $fullGroundOverlays), + array($simpleGroundOverlays, $fullGroundOverlays), + array($simpleGroundOverlays, $fullGroundOverlays, array($groundOverlay1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $groundOverlays The ground overlays. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $groundOverlays = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($groundOverlays))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $groundOverlays The ground overlays. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $groundOverlays = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getGroundOverlays') + ->will($this->returnValue($groundOverlays)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/IconAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/IconAggregatorTest.php new file mode 100644 index 00000000..a86de631 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/IconAggregatorTest.php @@ -0,0 +1,160 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Icons; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator; +use Ivory\GoogleMap\Overlays\Icon; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Icon aggregator test. + * + * @author GeLo + */ +class IconAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator */ + protected $iconAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->iconAggregator = new IconAggregator($this->markerAggregator = $this->createMarkerAggregatorMock()); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerAggregator); + unset($this->iconAggregator); + } + + public function testDefaultState() + { + $this->iconAggregator = new IconAggregator(); + + $this->assertMarkerAggregatorInstance($this->iconAggregator->getMarkerAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->markerAggregator, $this->iconAggregator->getMarkerAggregator()); + } + + public function testSetMarkerAggregator() + { + $this->iconAggregator->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->iconAggregator->getMarkerAggregator()); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregateMarkers(array $expected, array $markers = array(), array $icons = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->iconAggregator->aggregateMarkers($map, $icons)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $markers = array(), array $icons = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->iconAggregator->aggregate($map, $icons)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $marker1 = $this->createMarkerMock(); + $marker2 = $this->createMarkerMock($icon1 = $this->createIconMock()); + $marker3 = $this->createMarkerMock(null, $icon2 = $this->createIconMock()); + $marker4 = $this->createMarkerMock(null, $icon3 = $this->createIconMock()); + $marker5 = $this->createMarkerMock($icon1, $icon3); + + $simpleMarkers = array($marker1, $marker2, $marker3); + $fullMarkers = array($marker1, $marker2, $marker3, $marker4, $marker5); + + $simpleIcons = array($icon1, $icon2); + $fullIcons = array($icon1, $icon2, $icon3); + + return array( + array(array()), + array($simpleIcons, $simpleMarkers), + array($fullIcons, $fullMarkers), + array($fullIcons, $fullMarkers, $simpleIcons), + ); + } + + /** + * Creates a maker mock. + * + * @param \Ivory\GoogleMap\Overlays\Icon|null $icon The icon. + * @param \Ivory\GoogleMap\Overlays\Icon|null $shadow The shadow. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(Icon $icon = null, Icon $shadow = null) + { + $marker = parent::createMarkerMock(); + + if ($icon !== null) { + $marker + ->expects($this->any()) + ->method('hasIcon') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getIcon') + ->will($this->returnValue($icon)); + } + + if ($shadow !== null) { + $marker + ->expects($this->any()) + ->method('hasShadow') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getShadow') + ->will($this->returnValue($shadow)); + } + + return $marker; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/InfoWindowAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/InfoWindowAggregatorTest.php new file mode 100644 index 00000000..b1388a08 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/InfoWindowAggregatorTest.php @@ -0,0 +1,241 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\InfoWindows; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator; +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Info window aggregator test. + * + * @author GeLo + */ +class InfoWindowAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->infoWindowAggregator = new InfoWindowAggregator( + $this->markerAggregator = $this->createMarkerAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerAggregator); + unset($this->infoWindowAggregator); + } + + public function testDefaultState() + { + $this->infoWindowAggregator = new InfoWindowAggregator(); + + $this->assertMarkerAggregatorInstance($this->infoWindowAggregator->getMarkerAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->markerAggregator, $this->infoWindowAggregator->getMarkerAggregator()); + } + + public function testSetMarkerAggregator() + { + $this->infoWindowAggregator->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->infoWindowAggregator->getMarkerAggregator()); + } + + /** + * @dataProvider aggregateInfoWindowsProvider + */ + public function testAggregateInfoWindows(array $expected, array $infoWindows = array(), array $base = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($infoWindows))) + ->will($this->returnValue(array())); + + $this->assertEquals($expected, $this->infoWindowAggregator->aggregateInfoWindows($map, $base)); + } + + /** + * @dataProvider aggregateMarkersProvider + */ + public function testAggregateMarkers(array $expected, array $markers = array(), array $infoWindows = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->infoWindowAggregator->aggregateMarkers($map, $infoWindows)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate( + array $expected, + array $infoWindows = array(), + array $markers = array(), + array $base = array() + ) { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($infoWindows))) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->infoWindowAggregator->aggregate($map, $base)); + } + + /** + * Gets the info windows aggregate provider. + * + * @return array The info windows aggregate provider. + */ + public function aggregateInfoWindowsProvider() + { + $infoWindow1 = $this->createInfoWindowMock(); + $infoWindow2 = $this->createInfoWindowMock(); + + $simpleInfoWindows = array($infoWindow1, $infoWindow2); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow1); + + return array( + array(array()), + array($simpleInfoWindows, $simpleInfoWindows), + array($simpleInfoWindows, $fullInfoWindows), + array($simpleInfoWindows, $fullInfoWindows, $simpleInfoWindows), + ); + } + + /** + * Gets the aggregate markers provider. + * + * @return array The aggregate markers provider. + */ + public function aggregateMarkersProvider() + { + $marker1 = $this->createMarkerMock(); + $marker2 = $this->createMarkerMock($infoWindow1 = $this->createInfoWindowMock()); + $marker3 = $this->createMarkerMock($infoWindow2 = $this->createInfoWindowMock()); + $marker4 = $this->createMarkerMock($infoWindow1); + + $simpleMarkers = array($marker1, $marker2); + $fullMarkers = array($marker1, $marker2, $marker3, $marker4); + + $simpleInfoWindows = array($infoWindow1); + $fullInfoWindows = array($infoWindow1, $infoWindow2); + + return array( + array(array()), + array($simpleInfoWindows, $simpleMarkers), + array($fullInfoWindows, $fullMarkers), + array($fullInfoWindows, $fullMarkers, $simpleInfoWindows), + ); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $infoWindow1 = $this->createInfoWindowMock(); + $infoWindow2 = $this->createInfoWindowMock(); + + $marker1 = $this->createMarkerMock(); + $marker2 = $this->createMarkerMock($infoWindow3 = $this->createInfoWindowMock()); + $marker3 = $this->createMarkerMock($infoWindow4 = $this->createInfoWindowMock()); + $marker4 = $this->createMarkerMock($infoWindow3); + + $simpleOverlaysInfoWindows = array($infoWindow1, $infoWindow2); + $fullOverlaysInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow1); + + $simpleMarkers = array($marker1, $marker2); + $fullMarkers = array($marker1, $marker2, $marker3, $marker4); + + $simpleInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3); + $fullInfoWindows = array($infoWindow1, $infoWindow2, $infoWindow3, $infoWindow4); + + return array( + array(array()), + array($simpleInfoWindows, $simpleOverlaysInfoWindows, $simpleMarkers), + array($fullInfoWindows, $fullOverlaysInfoWindows, $fullMarkers), + array($fullInfoWindows, $fullOverlaysInfoWindows, $fullMarkers, $simpleInfoWindows), + ); + } + + protected function createMapMock(array $infoWindows = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($infoWindows))); + + return $map; + } + + /** + * Creates a maker mock. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow|null $infoWindow The info window. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(InfoWindow $infoWindow = null) + { + $marker = parent::createMarkerMock(); + + if ($infoWindow !== null) { + $marker + ->expects($this->any()) + ->method('hasInfoWindow') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getInfoWindow') + ->will($this->returnValue($infoWindow)); + } + + return $marker; + } + + protected function createOverlaysMock(array $infoWindows = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getInfoWindows') + ->will($this->returnValue($infoWindows)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/MarkerAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/MarkerAggregatorTest.php new file mode 100644 index 00000000..45bb09fb --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/MarkerAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Markers; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Marker aggregator test. + * + * @author GeLo + */ +class MarkerAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator */ + protected $markerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->markerAggregator = new MarkerAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $markers = array(), array $base = array()) + { + $this->assertEquals($expected, $this->markerAggregator->aggregate($this->createMapMock($markers), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $marker1 = $this->createMarkerMock(); + $marker2 = $this->createMarkerMock(); + + $simpleMarkers = array($marker1, $marker2); + $fullMarkers = array($marker1, $marker2, $marker1); + + return array( + array(array()), + array($simpleMarkers, $simpleMarkers), + array($simpleMarkers, $fullMarkers), + array($simpleMarkers, $fullMarkers), + array($simpleMarkers, $fullMarkers, array($marker1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $markers The markers. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $markers = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($markers))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $markers The markers. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $markers = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getMarkers') + ->will($this->returnValue($markers)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/MarkerShapeAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/MarkerShapeAggregatorTest.php new file mode 100644 index 00000000..577cadeb --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/MarkerShapeAggregatorTest.php @@ -0,0 +1,148 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\MarkerShapes; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator; +use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Marker shape aggregator test. + * + * @author GeLo + */ +class MarkerShapeAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator */ + protected $markerShapeAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->markerShapeAggregator = new MarkerShapeAggregator( + $this->markerAggregator = $this->createMarkerAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerAggregator); + unset($this->markerShapeAggregator); + } + + public function testDefaultState() + { + $this->markerShapeAggregator = new MarkerShapeAggregator(); + + $this->assertMarkerAggregatorInstance($this->markerShapeAggregator->getMarkerAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->markerAggregator, $this->markerShapeAggregator->getMarkerAggregator()); + } + + public function testSetMarkerAggregator() + { + $this->markerShapeAggregator->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->markerShapeAggregator->getMarkerAggregator()); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregateMarkers(array $expected, array $markers = array(), array $markerShapes = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->markerShapeAggregator->aggregateMarkers($map, $markerShapes)); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $markers = array(), array $markerShapes = array()) + { + $this->markerAggregator + ->expects($this->any()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($markers)); + + $this->assertEquals($expected, $this->markerShapeAggregator->aggregate($map, $markerShapes)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $marker1 = $this->createMarkerMock(); + $marker2 = $this->createMarkerMock($markerShape1 = $this->createMarkerShapeMock()); + $marker3 = $this->createMarkerMock($markerShape2 = $this->createMarkerShapeMock()); + $marker4 = $this->createMarkerMock($markerShape1); + + $simpleMarkers = array($marker1, $marker2); + $fullMarkers = array($marker1, $marker2, $marker3, $marker4); + + $simpleMarkerShapes = array($markerShape1); + $fullMarkerShapes = array($markerShape1, $markerShape2); + + return array( + array(array()), + array($simpleMarkerShapes, $simpleMarkers), + array($fullMarkerShapes, $fullMarkers), + array($fullMarkerShapes, $fullMarkers, $simpleMarkerShapes), + ); + } + + /** + * Creates a maker mock. + * + * @param \Ivory\GoogleMap\Overlays\MarkerShape|null $markerShape The marker shape. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(MarkerShape $markerShape = null) + { + $marker = parent::createMarkerMock(); + + if ($markerShape !== null) { + $marker + ->expects($this->any()) + ->method('hasShape') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getShape') + ->will($this->returnValue($markerShape)); + } + + return $marker; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/PolygonAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/PolygonAggregatorTest.php new file mode 100644 index 00000000..2dcd6b40 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/PolygonAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Polygons; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Polygon aggregator test. + * + * @author GeLo + */ +class PolygonAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator */ + protected $polygonAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->polygonAggregator = new PolygonAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->polygonAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $polygons = array(), array $base = array()) + { + $this->assertEquals($expected, $this->polygonAggregator->aggregate($this->createMapMock($polygons), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $polygon1 = $this->createPolygonMock(); + $polygon2 = $this->createPolygonMock(); + + $simplePolygons = array($polygon1, $polygon2); + $fullPolygons = array($polygon1, $polygon2, $polygon1); + + return array( + array(array()), + array($simplePolygons, $simplePolygons), + array($simplePolygons, $fullPolygons), + array($simplePolygons, $fullPolygons), + array($simplePolygons, $fullPolygons, array($polygon1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $polygons The polygons. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $polygons = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($polygons))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $polygons The polygons. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $polygons = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getPolygons') + ->will($this->returnValue($polygons)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/PolylineAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/PolylineAggregatorTest.php new file mode 100644 index 00000000..f104830c --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/PolylineAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Polylines; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Polyline aggregator test. + * + * @author GeLo + */ +class PolylineAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator */ + protected $polylineAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->polylineAggregator = new PolylineAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->polylineAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $polylines = array(), array $base = array()) + { + $this->assertEquals($expected, $this->polylineAggregator->aggregate($this->createMapMock($polylines), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $polyline1 = $this->createPolylineMock(); + $polyline2 = $this->createPolylineMock(); + + $simplePolylines = array($polyline1, $polyline2); + $fullPolylines = array($polyline1, $polyline2, $polyline1); + + return array( + array(array()), + array($simplePolylines, $simplePolylines), + array($simplePolylines, $fullPolylines), + array($simplePolylines, $fullPolylines), + array($simplePolylines, $fullPolylines, array($polyline1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $polylines The polylines. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $polylines = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($polylines))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $polylines The polylines. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $polylines = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getPolylines') + ->will($this->returnValue($polylines)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Overlays/RectangleAggregatorTest.php b/tests/Helpers/Aggregators/Overlays/RectangleAggregatorTest.php new file mode 100644 index 00000000..270e1ab3 --- /dev/null +++ b/tests/Helpers/Aggregators/Overlays/RectangleAggregatorTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Rectangles; + +use Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Rectangle aggregator test. + * + * @author GeLo + */ +class RectangleAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator */ + protected $rectangleAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->rectangleAggregator = new RectangleAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->rectangleAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $rectangles = array(), array $base = array()) + { + $this->assertEquals($expected, $this->rectangleAggregator->aggregate($this->createMapMock($rectangles), $base)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $rectangle1 = $this->createRectangleMock(); + $rectangle2 = $this->createRectangleMock(); + + $simpleRectangles = array($rectangle1, $rectangle2); + $fullRectangles = array($rectangle1, $rectangle2, $rectangle1); + + return array( + array(array()), + array($simpleRectangles, $simpleRectangles), + array($simpleRectangles, $fullRectangles), + array($simpleRectangles, $fullRectangles), + array($simpleRectangles, $fullRectangles, array($rectangle1)), + ); + } + + /** + * Creates a map mock. + * + * @param array $rectangles The rectangles. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $rectangles = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($overlays = $this->createOverlaysMock($rectangles))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param array $rectangles The rectangles. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(array $rectangles = array()) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getRectangles') + ->will($this->returnValue($rectangles)); + + return $overlays; + } +} diff --git a/tests/Helpers/Aggregators/Places/AutocompleteBoundAggregatorTest.php b/tests/Helpers/Aggregators/Places/AutocompleteBoundAggregatorTest.php new file mode 100644 index 00000000..f420744e --- /dev/null +++ b/tests/Helpers/Aggregators/Places/AutocompleteBoundAggregatorTest.php @@ -0,0 +1,78 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Places; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Autocomplete bound aggregator test. + * + * @author GeLo + */ +class AutocompleteBoundAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator */ + protected $boundAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->boundAggregator = new AutocompleteBoundAggregator(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->boundAggregator); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, Bound $bound = null, array $bounds = array()) + { + $autocomplete = $this->createAutocompleteMock(); + $autocomplete + ->expects($this->any()) + ->method('hasBound') + ->will($this->returnValue($bound !== null)); + + $autocomplete + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + + $this->assertSame($expected, $this->boundAggregator->aggregate($autocomplete, $bounds)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $bound = $this->createBoundMock(); + + return array( + array(array()), + array(array($bound), $bound), + array(array($bound), $bound, array($bound)), + ); + } +} diff --git a/tests/Helpers/Aggregators/Places/AutocompleteCoordinateAggregatorTest.php b/tests/Helpers/Aggregators/Places/AutocompleteCoordinateAggregatorTest.php new file mode 100644 index 00000000..90c3c076 --- /dev/null +++ b/tests/Helpers/Aggregators/Places/AutocompleteCoordinateAggregatorTest.php @@ -0,0 +1,144 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Aggregators\Places; + +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Autocomplete coordinate aggregator test. + * + * @author GeLo + */ +class AutocompleteCoordinateAggregatorTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundAggregator; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->coordinateAggregator = new AutocompleteCoordinateAggregator( + $this->boundAggregator = $this->createAutocompleteBoundAggregatorMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->boundAggregator); + unset($this->coordinateAggregator); + } + + public function testDefaultState() + { + $this->coordinateAggregator = new AutocompleteCoordinateAggregator(); + + $this->assertAutocompleteBoundAggregatorInstance($this->coordinateAggregator->getBoundAggregator()); + } + + public function testInitialState() + { + $this->assertSame($this->boundAggregator, $this->coordinateAggregator->getBoundAggregator()); + } + + public function testSetBoundAggregator() + { + $this->coordinateAggregator->setBoundAggregator( + $boundAggregator = $this->createAutocompleteBoundAggregatorMock() + ); + + $this->assertSame($boundAggregator, $this->coordinateAggregator->getBoundAggregator()); + } + + /** + * @dataProvider aggregateProvider + */ + public function testAggregate(array $expected, array $bounds = array(), array $coordinates = array()) + { + $this->boundAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($autocomplete = $this->createAutocompleteMock())) + ->will($this->returnValue($bounds)); + + $this->assertSame($expected, $this->coordinateAggregator->aggregate($autocomplete, $coordinates)); + } + + /** + * Gets the aggregate provider. + * + * @return array The aggregate provider. + */ + public function aggregateProvider() + { + $emptyBound = $this->createBoundMock(); + $southWestBound = $this->createBoundMock($coordinate1 = $this->createCoordinateMock()); + $northEastBound = $this->createBoundMock(null, $coordinate2 = $this->createCoordinateMock()); + $fullBound = $this->createBoundMock($coordinate3 = $this->createCoordinateMock(), $coordinate1); + + $simpleBounds = array($emptyBound, $southWestBound, $northEastBound); + $fullBounds = array($emptyBound, $southWestBound, $northEastBound, $fullBound); + + $simpleCoordinates = array($coordinate1, $coordinate2); + $fullCoordinates = array($coordinate1, $coordinate2, $coordinate3); + + return array( + array(array()), + array($simpleCoordinates, $simpleBounds), + array($fullCoordinates, $fullBounds), + array($fullCoordinates, $fullBounds, $simpleCoordinates), + ); + } + + /** + * Creates a bound mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $southWest The south west. + * @param \Ivory\GoogleMap\Base\Coordinate|null $northEast The north east. + * + * @return \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject The bound mock. + */ + protected function createBoundMock(Coordinate $southWest = null, Coordinate $northEast = null) + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('hasSouthWest') + ->will($this->returnValue($southWest !== null)); + + $bound + ->expects($this->any()) + ->method('getSouthWest') + ->will($this->returnValue($southWest)); + + $bound + ->expects($this->any()) + ->method('hasNorthEast') + ->will($this->returnValue($northEast !== null)); + + $bound + ->expects($this->any()) + ->method('getNorthEast') + ->will($this->returnValue($northEast)); + + return $bound; + } +} diff --git a/tests/Helpers/ApiEventTest.php b/tests/Helpers/ApiEventTest.php new file mode 100644 index 00000000..a4679995 --- /dev/null +++ b/tests/Helpers/ApiEventTest.php @@ -0,0 +1,390 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\ApiEvent; + +/** + * Api event test. + * + * @author GeLo + */ +class ApiEventTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\ApiEvent */ + protected $apiEvent; + + /** @var \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject */ + protected $map; + + /** @var \Ivory\GoogleMap\Places\Autocomplete|\PHPUnit_Framework_MockObject_MockObject */ + protected $autocomplete; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->apiEvent = new ApiEvent(array( + $this->map = $this->createMapMock(), + $this->autocomplete = $this->createAutocompleteMock(), + )); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->autocomplete); + unset($this->map); + unset($this->apiEvent); + } + + public function testInheritance() + { + $this->assertSymfonyEventInstance($this->apiEvent); + } + + public function testDefaultState() + { + $this->assertTrue($this->apiEvent->hasItems()); + $this->assertSame(array($this->map, $this->autocomplete), $this->apiEvent->getItems()); + + $this->assertSame('en', $this->apiEvent->getLanguage()); + $this->assertFalse($this->apiEvent->hasSources()); + $this->assertFalse($this->apiEvent->hasLibraries()); + $this->assertFalse($this->apiEvent->hasCallbacks()); + } + + public function testGetItems() + { + $this->assertTrue($this->apiEvent->hasItems(ApiEvent::MAP)); + $this->assertSame(array($this->map), $this->apiEvent->getItems(ApiEvent::MAP)); + + $this->assertTrue($this->apiEvent->hasItems(ApiEvent::PLACES_AUTOCOMPLETE)); + $this->assertSame(array($this->autocomplete), $this->apiEvent->getItems(ApiEvent::PLACES_AUTOCOMPLETE)); + + $this->assertFalse($this->apiEvent->hasItems('foo')); + $this->assertEmpty($this->apiEvent->getItems('foo')); + } + + public function testSetLanguage() + { + $this->apiEvent->setLanguage($language = 'fr'); + + $this->assertSame($language, $this->apiEvent->getLanguage()); + } + + public function testSetSources() + { + $this->apiEvent->setSources($sources = array('foo')); + + $this->assertSources($sources); + } + + public function testAddSources() + { + $this->apiEvent->setSources($sources = array('foo')); + $this->apiEvent->addSources($newSources = array('bar')); + + $this->assertSources(array_merge($sources, $newSources)); + } + + public function testRemoveSources() + { + $this->apiEvent->setSources($sources = array('foo')); + $this->apiEvent->removeSources($sources); + + $this->assertNoSources(); + } + + public function testResetSources() + { + $this->apiEvent->setSources(array('foo')); + $this->apiEvent->resetSources(); + + $this->assertNoSources(); + } + + public function testAddSource() + { + $this->apiEvent->addSource($source = 'foo'); + + $this->assertSource($source); + } + + public function testAddSourceUnicity() + { + $this->apiEvent->resetSources(); + $this->apiEvent->addSource($source = 'foo'); + $this->apiEvent->addSource($source); + + $this->assertSources(array($source)); + } + + public function testRemoveSource() + { + $this->apiEvent->addSource($source = 'foo'); + $this->apiEvent->removeSource($source); + + $this->assertNoSource($source); + } + + public function testSetLibraries() + { + $this->apiEvent->setLibraries($libraries = array('foo')); + + $this->assertLibraries($libraries); + } + + public function testAddLibraries() + { + $this->apiEvent->setLibraries($libraries = array('foo')); + $this->apiEvent->addLibraries($newLibraries = array('bar')); + + $this->assertLibraries(array_merge($libraries, $newLibraries)); + } + + public function testRemoveLibraries() + { + $this->apiEvent->setLibraries($libraries = array('foo')); + $this->apiEvent->removeLibraries($libraries); + + $this->assertNoLibraries(); + } + + public function testResetLibraries() + { + $this->apiEvent->setLibraries(array('foo')); + $this->apiEvent->resetLibraries(); + + $this->assertNoLibraries(); + } + + public function testAddLibrary() + { + $this->apiEvent->addLibrary($library = 'foo'); + + $this->assertLibrary($library); + } + + public function testAddLibraryUnicity() + { + $this->apiEvent->resetLibraries(); + $this->apiEvent->addLibrary($library = 'foo'); + $this->apiEvent->addLibrary($library); + + $this->assertLibraries(array($library)); + } + + public function testRemoveLibrary() + { + $this->apiEvent->addLibrary($library = 'foo'); + $this->apiEvent->removeLibrary($library); + + $this->assertNoLibrary($library); + } + + public function testSetCallbacks() + { + $this->apiEvent->setCallbacks($callbacks = array('foo')); + + $this->assertCallbacks($callbacks); + } + + public function testAddCallbacks() + { + $this->apiEvent->setCallbacks($callbacks = array('foo')); + $this->apiEvent->addCallbacks($newCallbacks = array('bar')); + + $this->assertCallbacks(array_merge($callbacks, $newCallbacks)); + } + + public function testRemoveCallbacks() + { + $this->apiEvent->setCallbacks($callbacks = array('foo')); + $this->apiEvent->removeCallbacks($callbacks); + + $this->assertNoCallbacks(); + } + + public function testResetCallbacks() + { + $this->apiEvent->setCallbacks(array('foo')); + $this->apiEvent->resetCallbacks(); + + $this->assertNoCallbacks(); + } + + public function testAddCallback() + { + $this->apiEvent->addCallback($callback = 'foo'); + + $this->assertCallback($callback); + } + + public function testAddCallbackUnicity() + { + $this->apiEvent->resetCallbacks(); + $this->apiEvent->addCallback($callback = 'foo'); + $this->apiEvent->addCallback($callback); + + $this->assertCallbacks(array($callback)); + } + + public function testRemoveCallback() + { + $this->apiEvent->addCallback($callback = 'foo'); + $this->apiEvent->removeCallback($callback); + + $this->assertNoCallback($callback); + } + + /** + * Asserts there are sources. + * + * @param array $sources The sources. + */ + protected function assertSources($sources) + { + $this->assertInternalType('array', $sources); + + $this->assertTrue($this->apiEvent->hasSources()); + $this->assertSame($sources, $this->apiEvent->getSources()); + + foreach ($sources as $source) { + $this->assertSource($source); + } + } + + /** + * Asserts there is a source. + * + * @param string $source The source. + */ + protected function assertSource($source) + { + $this->assertTrue($this->apiEvent->hasSource($source)); + } + + /** + * Asserts there are no sources. + */ + protected function assertNoSources() + { + $this->assertFalse($this->apiEvent->hasSources()); + $this->assertEmpty($this->apiEvent->getSources()); + } + + /** + * Asserts there is no source. + * + * @param string $source The source. + */ + protected function assertNoSource($source) + { + $this->assertFalse($this->apiEvent->hasSource($source)); + } + + /** + * Asserts there are libraries. + * + * @param array $libraries The libraries. + */ + protected function assertLibraries($libraries) + { + $this->assertInternalType('array', $libraries); + + $this->assertTrue($this->apiEvent->hasLibraries()); + $this->assertSame($libraries, $this->apiEvent->getLibraries()); + + foreach ($libraries as $library) { + $this->assertLibrary($library); + } + } + + /** + * Asserts there is a library. + * + * @param string $library The library. + */ + protected function assertLibrary($library) + { + $this->assertTrue($this->apiEvent->hasLibrary($library)); + } + + /** + * Asserts there are no libraries. + */ + protected function assertNoLibraries() + { + $this->assertFalse($this->apiEvent->hasLibraries()); + $this->assertEmpty($this->apiEvent->getLibraries()); + } + + /** + * Asserts there is no library. + * + * @param string $library The library. + */ + protected function assertNoLibrary($library) + { + $this->assertFalse($this->apiEvent->hasLibrary($library)); + } + + /** + * Asserts there are callbacks. + * + * @param array $callbacks The callbacks. + */ + protected function assertCallbacks($callbacks) + { + $this->assertInternalType('array', $callbacks); + + $this->assertTrue($this->apiEvent->hasCallbacks()); + $this->assertSame($callbacks, $this->apiEvent->getCallbacks()); + + foreach ($callbacks as $callback) { + $this->assertCallback($callback); + } + } + + /** + * Asserts there is a callback. + * + * @param string $callback The callback. + */ + protected function assertCallback($callback) + { + $this->assertTrue($this->apiEvent->hasCallback($callback)); + } + + /** + * Asserts there are no callbacks. + */ + protected function assertNoCallbacks() + { + $this->assertFalse($this->apiEvent->hasCallbacks()); + $this->assertEmpty($this->apiEvent->getCallbacks()); + } + + /** + * Asserts there is no callback. + * + * @param string $callback The callback. + */ + protected function assertNoCallback($callback) + { + $this->assertFalse($this->apiEvent->hasCallback($callback)); + } +} diff --git a/tests/Helpers/ApiEventsTest.php b/tests/Helpers/ApiEventsTest.php new file mode 100644 index 00000000..6fe3fb01 --- /dev/null +++ b/tests/Helpers/ApiEventsTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\ApiEvents; + +/** + * Api events test. + * + * @author GeLo + */ +class ApiEventsTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Helpers\ApiEvents'); + } + + public function testConstants() + { + $this->assertSame('ivory.google_map.api.javascript', ApiEvents::JAVASCRIPT); + $this->assertSame('ivory.google_map.api.javascript.map', ApiEvents::JAVASCRIPT_MAP); + + $this->assertSame( + 'ivory.google_map.api.javascript.map.encoded_polyline', + ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE + ); + + $this->assertSame( + 'ivory.google_map.api.javascript.map.marker_cluster', + ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER + ); + + $this->assertSame('ivory.google_map.api.javascript.map.info_window', ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW); + + $this->assertSame( + 'ivory.google_map.api.javascript.places.autocomplete', + ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE + ); + } +} diff --git a/tests/Helpers/ApiHelperTest.php b/tests/Helpers/ApiHelperTest.php new file mode 100644 index 00000000..8f49e5b0 --- /dev/null +++ b/tests/Helpers/ApiHelperTest.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\ApiHelper; +use Ivory\Tests\GoogleMap\Helpers\AbstractHelperTest; + +/** + * Api helper test. + * + * @author GeLo + */ +class ApiHelperTest extends AbstractHelperTest +{ + /** @var \Ivory\GoogleMap\Helpers\ApiHelper */ + protected $apiHelper; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->apiHelper = new ApiHelper($this->eventDispatcher); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->apiHelper); + } + + public function testRender() + { + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with( + $this->identicalTo(ApiEvents::JAVASCRIPT), + $this->createApiEventCallbackConstraint( + $items = array($this->createMapMock(), $this->createAutocompleteMock()), + $code = 'code' + ) + ); + + $this->assertSame($code, $this->apiHelper->render($items)); + } + + /** + * Creates an api event callback constraint. + * + * @param array $items The items. + * @param string $code The code. + * + * @return \PHPUnit_Framework_Constraint_Callback The api event callback constraint. + */ + protected function createApiEventCallbackConstraint(array $items, $code) + { + return $this->callback(function ($apiEvent) use ($items, $code) { + $result = $apiEvent instanceof ApiEvent && $apiEvent->getItems() === $items; + + if ($result) { + $apiEvent->addCode($code); + } + + return $result; + }); + } +} diff --git a/tests/Helpers/EventTest.php b/tests/Helpers/EventTest.php new file mode 100644 index 00000000..5b9a6511 --- /dev/null +++ b/tests/Helpers/EventTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +/** + * Event test. + * + * @author GeLo + */ +class EventTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\AbstractEvent */ + protected $event; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->event = $this->createHelperEventMock(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->event); + } + + public function testInheritance() + { + $this->assertSymfonyEventInstance($this->event); + } + + public function testDefaultState() + { + $this->assertNull($this->event->getCode()); + } + + public function testAddCode() + { + $this->event->addCode($code1 = 'code1'); + $this->event->addCode($code2 = 'code2'); + + $this->assertSame($code1.$code2, $this->event->getCode()); + } + + public function testSetCode() + { + $this->event->addCode('code1'); + $this->event->setCode($code = 'code2'); + + $this->assertSame($code, $this->event->getCode()); + } +} diff --git a/tests/Helpers/Factories/AbstractHelperFactoryTest.php b/tests/Helpers/Factories/AbstractHelperFactoryTest.php new file mode 100644 index 00000000..9b766ffe --- /dev/null +++ b/tests/Helpers/Factories/AbstractHelperFactoryTest.php @@ -0,0 +1,652 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Factories; + +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase; + +/** + * Helper factory test. + * + * @author GeLo + */ +abstract class AbstractHelperFactoryTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Factories\HelperFactoryInterface */ + protected $helperFactory; + + /** @var array */ + protected $apiFormatterSubscribers; + + /** @var array */ + protected $mapFormatterSubscribers; + + /** @var array */ + protected $placesAutocompleteFormatterSubscribers; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->helperFactory = $this->createHelperFactory(); + $this->apiFormatterSubscribers = array( + ApiEvents::JAVASCRIPT, + ApiEvents::JAVASCRIPT_MAP, + ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE, + ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW, + ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER, + ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE, + ); + + $this->mapFormatterSubscribers = array( + MapEvents::JAVASCRIPT_BASE_BOUND, + MapEvents::JAVASCRIPT_BASE_COORDINATE, + MapEvents::JAVASCRIPT_BASE_POINT, + MapEvents::JAVASCRIPT_BASE_SIZE, + MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT, + MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE, + MapEvents::JAVASCRIPT_EVENTS_EVENT, + MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE, + MapEvents::JAVASCRIPT_LAYERS_KML_LAYER, + MapEvents::JAVASCRIPT_FINISH_MAP_BOUND, + MapEvents::JAVASCRIPT_FINISH_MAP_CENTER, + MapEvents::JAVASCRIPT_INIT_CONTAINER, + MapEvents::HTML, + MapEvents::JAVASCRIPT, + MapEvents::STYLESHEET, + MapEvents::JAVASCRIPT_MAP, + MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE, + MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE, + MapEvents::JAVASCRIPT_FINISH_EXTENDABLE, + MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY, + MapEvents::JAVASCRIPT_OVERLAYS_ICON, + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE, + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN, + MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW, + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER, + MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT, + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE, + MapEvents::JAVASCRIPT_OVERLAYS_MARKER, + MapEvents::JAVASCRIPT_OVERLAYS_POLYGON, + MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE, + MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE, + ); + + $this->placesAutocompleteFormatterSubscribers = array( + PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND, + PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER, + PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE, + PlacesAutocompleteEvents::HTML, + PlacesAutocompleteEvents::JAVASCRIPT, + PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE, + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->helperFactory); + } + + /** + * Creates the helper factory. + * + * @return \Ivory\GoogleMap\Helpers\Factories\HelperFactoryInterface The helper factory. + */ + abstract protected function createHelperFactory(); + + public function testCreateApiHelper() + { + $this->assertApiHelperInstance($apiHelper = $this->helperFactory->createApiHelper()); + $this->assertEventDispatcherInstance($eventDispatcher = $apiHelper->getEventDispatcher()); + $this->assertTrue($eventDispatcher->hasListeners()); + } + + public function testCreateMapHelper() + { + $this->assertMapHelperInstance($mapHelper = $this->helperFactory->createMapHelper()); + $this->assertEventDispatcherInstance($eventDispatcher = $mapHelper->getEventDispatcher()); + $this->assertTrue($eventDispatcher->hasListeners()); + } + + public function testCreatePlacesAutocompleteHelper() + { + $this->assertAutocompleteHelperInstance( + $autocompleteHelper = $this->helperFactory->createPlacesAutocompleteHelper() + ); + + $this->assertEventDispatcherInstance($eventDispatcher = $autocompleteHelper->getEventDispatcher()); + $this->assertTrue($eventDispatcher->hasListeners()); + } + + public function testSetDebug() + { + $this->helperFactory->setDebug(true); + + $this->assertTrue($this->helperFactory->isDebug()); + + foreach ($this->getFormatters() as $formatter) { + $this->assertTrue($formatter->isDebug()); + } + } + + public function testSetIndentation() + { + $this->helperFactory->setIndentation($indentation = 2); + + $this->assertSame($indentation, $this->helperFactory->getIndentation()); + + foreach ($this->getFormatters() as $formatter) { + $this->assertSame($indentation, $formatter->getIndentation()); + } + } + + public function testEventDispatcherInstances() + { + $apiHelper = $this->helperFactory->createApiHelper(); + $mapHelper = $this->helperFactory->createMapHelper(); + $placesAutocompleteHelper = $this->helperFactory->createPlacesAutocompleteHelper(); + + $this->assertNotSame($apiHelper->getEventDispatcher(), $mapHelper->getEventDispatcher()); + $this->assertNotSame($apiHelper->getEventDispatcher(), $placesAutocompleteHelper->getEventDispatcher()); + $this->assertNotSame($mapHelper->getEventDispatcher(), $placesAutocompleteHelper->getEventDispatcher()); + } + + public function testFormatterUnicity() + { + $formatters = $this->getFormatters(); + $formattersCount = count($formatters); + + for ($i = 1; $i < $formattersCount; $i++) { + $this->assertFormatterInstance($formatters[$i - 1]); + $this->assertFormatterInstance($formatters[$i]); + $this->assertSame($formatters[$i - 1], $formatters[$i]); + } + } + + public function testJsonBuilderUnicity() + { + $jsonBuilders = $this->getJsonBuilders(); + $jsonBuildersCount = count($jsonBuilders); + + for ($i = 1; $i < $jsonBuildersCount; $i++) { + $this->assertJsonBuilderInstance($jsonBuilders[$i - 1]); + $this->assertJsonBuilderInstance($jsonBuilders[$i]); + $this->assertSame($jsonBuilders[$i - 1], $jsonBuilders[$i]); + } + } + + public function testBoundAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $boundSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_BOUND); + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + + $boundAggregators = array( + $boundSubscribers[0][0]->getBoundAggregator(), + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getBoundAggregator(), + ); + + $boundAggregatorsCount = count($boundAggregators); + + for ($i = 1; $i < $boundAggregatorsCount; $i++) { + $this->assertBoundAggregatorInstance($boundAggregators[$i - 1]); + $this->assertBoundAggregatorInstance($boundAggregators[$i]); + $this->assertSame($boundAggregators[$i - 1], $boundAggregators[$i]); + } + } + + public function testGroundOverlayAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $boundSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_BOUND); + + $groundOverlaySubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY + ); + + $groundOverlayAggregators = array( + $boundSubscribers[0][0]->getBoundAggregator()->getGroundOverlayAggregator(), + $groundOverlaySubscribers[0][0]->getGroundOverlayAggregator(), + ); + + $groundOverlayAggregatorsCount = count($groundOverlayAggregators); + + for ($i = 1; $i < $groundOverlayAggregatorsCount; $i++) { + $this->assertGroundOverlayAggregatorInstance($groundOverlayAggregators[$i - 1]); + $this->assertGroundOverlayAggregatorInstance($groundOverlayAggregators[$i]); + $this->assertSame($groundOverlayAggregators[$i - 1], $groundOverlayAggregators[$i]); + } + } + + public function testRectangleAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $boundSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_BOUND); + + $rectangleSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE + ); + + $rectangleAggregators = array( + $boundSubscribers[0][0]->getBoundAggregator()->getRectangleAggregator(), + $rectangleSubscribers[0][0]->getRectangleAggregator(), + ); + + $rectangleAggregatorsCount = count($rectangleAggregators); + + for ($i = 1; $i < $rectangleAggregatorsCount; $i++) { + $this->assertRectangleAggregatorInstance($rectangleAggregators[$i - 1]); + $this->assertRectangleAggregatorInstance($rectangleAggregators[$i]); + $this->assertSame($rectangleAggregators[$i - 1], $rectangleAggregators[$i]); + } + } + + public function testCircleAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + $circleSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE); + + $circleAggregators = array( + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getCircleAggregator(), + $circleSubscribers[0][0]->getCircleAggregator(), + ); + + $circleAggregatorsCount = count($circleAggregators); + + for ($i = 1; $i < $circleAggregatorsCount; $i++) { + $this->assertCircleAggregatorInstance($circleAggregators[$i - 1]); + $this->assertCircleAggregatorInstance($circleAggregators[$i]); + $this->assertSame($circleAggregators[$i - 1], $circleAggregators[$i]); + } + } + + public function testInfoWindowAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + $sizeSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_SIZE); + + $infoWindowCloseSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE + ); + + $infoWindowOpenSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN + ); + + $infoWindowSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW + ); + + $infoWindowAggregators = array( + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getInfoWindowAggregator(), + $sizeSubscribers[0][0]->getSizeAggregator()->getInfoWindowAggregator(), + $infoWindowCloseSubscribers[0][0]->getInfoWindowAggregator(), + $infoWindowOpenSubscribers[0][0]->getInfoWindowAggregator(), + $infoWindowSubscribers[0][0]->getInfoWindowAggregator(), + ); + + $infoWindowAggregatorsCount = count($infoWindowAggregators); + + for ($i = 1; $i < $infoWindowAggregatorsCount; $i++) { + $this->assertInfoWindowAggregatorInstance($infoWindowAggregators[$i - 1]); + $this->assertInfoWindowAggregatorInstance($infoWindowAggregators[$i]); + $this->assertSame($infoWindowAggregators[$i - 1], $infoWindowAggregators[$i]); + } + } + + public function testMarkerAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + $pointSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_POINT); + + $markerOpenEventSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT + ); + + $markerSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_MARKER); + + $markerShapeSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE + ); + + $markerAggregators = array( + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getMarkerAggregator(), + $pointSubscribers[0][0]->getPointAggregator()->getMarkerAggregator(), + $markerOpenEventSubscribers[0][0]->getMarkerAggregator(), + $markerSubscribers[0][0]->getMarkerAggregator(), + $markerShapeSubscribers[0][0]->getMarkerShapeAggregator()->getMarkerAggregator(), + ); + + $markerAggregatorsCount = count($markerAggregators); + + for ($i = 1; $i < $markerAggregatorsCount; $i++) { + $this->assertMarkerAggregatorInstance($markerAggregators[$i - 1]); + $this->assertMarkerAggregatorInstance($markerAggregators[$i]); + $this->assertSame($markerAggregators[$i - 1], $markerAggregators[$i]); + } + } + + public function testPolygonAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + $polygonSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON); + + $polygonAggregators = array( + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getPolygonAggregator(), + $polygonSubscribers[0][0]->getPolygonAggregator(), + ); + + $polygonAggregatorsCount = count($polygonAggregators); + + for ($i = 1; $i < $polygonAggregatorsCount; $i++) { + $this->assertPolygonAggregatorInstance($polygonAggregators[$i - 1]); + $this->assertPolygonAggregatorInstance($polygonAggregators[$i]); + $this->assertSame($polygonAggregators[$i - 1], $polygonAggregators[$i]); + } + } + + public function testPolylineAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $coordinateSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_COORDINATE); + $polylineSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE); + + $polylineAggregators = array( + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getPolylineAggregator(), + $polylineSubscribers[0][0]->getPolylineAggregator(), + ); + + $polylineAggregatorsCount = count($polylineAggregators); + + for ($i = 1; $i < $polylineAggregatorsCount; $i++) { + $this->assertPolylineAggregatorInstance($polylineAggregators[$i - 1]); + $this->assertPolylineAggregatorInstance($polylineAggregators[$i]); + $this->assertSame($polylineAggregators[$i - 1], $polylineAggregators[$i]); + } + } + + public function testIconAggregatorUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $sizeSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_BASE_SIZE); + $iconSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_ICON); + + $iconAggregators = array( + $sizeSubscribers[0][0]->getSizeAggregator()->getIconAggregator(), + $iconSubscribers[0][0]->getIconAggregator(), + ); + + $iconAggregatorsCount = count($iconAggregators); + + for ($i = 1; $i < $iconAggregatorsCount; $i++) { + $this->assertIconAggregatorInstance($iconAggregators[$i - 1]); + $this->assertIconAggregatorInstance($iconAggregators[$i]); + $this->assertSame($iconAggregators[$i - 1], $iconAggregators[$i]); + } + } + + public function testAutocompleteBoundAggregatorUnicity() + { + $autocompleteHelper = $this->helperFactory->createPlacesAutocompleteHelper(); + + $boundSubscribers = $autocompleteHelper->getEventDispatcher()->getListeners( + PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND + ); + + $coordinateSubscribers = $autocompleteHelper->getEventDispatcher()->getListeners( + PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE + ); + + $boundAggregators = array( + $boundSubscribers[0][0]->getBoundAggregator(), + $coordinateSubscribers[0][0]->getCoordinateAggregator()->getBoundAggregator(), + ); + + $boundAggregatorsCount = count($boundAggregators); + + for ($i = 1; $i < $boundAggregatorsCount; $i++) { + $this->assertAutocompleteBoundAggregatorInstance($boundAggregators[$i - 1]); + $this->assertAutocompleteBoundAggregatorInstance($boundAggregators[$i]); + $this->assertSame($boundAggregators[$i - 1], $boundAggregators[$i]); + } + } + + public function testInfoWindowOpenRendererUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $infoWindowOpenSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN + ); + + $markerOpenEventSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT + ); + + $infoWindowOpenRenderers = array( + $infoWindowOpenSubscribers[0][0]->getInfoWindowOpenRenderer(), + $markerOpenEventSubscribers[0][0]->getInfoWindowOpenRenderer(), + ); + + $infoWindowOpenRenderersCount = count($infoWindowOpenRenderers); + + for ($i = 1; $i < $infoWindowOpenRenderersCount; $i++) { + $this->assertInfoWindowOpenRendererInstance($infoWindowOpenRenderers[$i - 1]); + $this->assertInfoWindowOpenRendererInstance($infoWindowOpenRenderers[$i]); + $this->assertSame($infoWindowOpenRenderers[$i - 1], $infoWindowOpenRenderers[$i]); + } + } + + public function testMapTypeIdRendererUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $mapSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_MAP); + $controlsRenderer = $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer(); + + $mapTypeIdRenderers = array( + $mapSubscribers[0][0]->getMapRenderer()->getMapTypeIdRenderer(), + $controlsRenderer->getMapTypeControlRenderer()->getMapTypeIdRenderer() + ); + + $mapTypeIdRenderersCount = count($mapTypeIdRenderers); + + for ($i = 1; $i < $mapTypeIdRenderersCount; $i++) { + $this->assertMapTypeIdRendererInstance($mapTypeIdRenderers[$i - 1]); + $this->assertMapTypeIdRendererInstance($mapTypeIdRenderers[$i]); + $this->assertSame($mapTypeIdRenderers[$i - 1], $mapTypeIdRenderers[$i]); + } + } + + public function testControlPositionRendererUnicity() + { + $mapHelper = $this->helperFactory->createMapHelper(); + + $mapSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_MAP); + $controlsRenderer = $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer(); + + $controlPositionRenderers = array( + $controlsRenderer->getMapTypeControlRenderer()->getControlPositionRenderer(), + $controlsRenderer->getPanControlRenderer()->getControlPositionRenderer(), + $controlsRenderer->getRotateControlRenderer()->getControlPositionRenderer(), + $controlsRenderer->getStreetViewControlRenderer()->getControlPositionRenderer(), + $controlsRenderer->getZoomControlRenderer()->getControlPositionRenderer(), + ); + + $controlPositionRenderersCount = count($controlPositionRenderers); + + for ($i = 1; $i < $controlPositionRenderersCount; $i++) { + $this->assertControlPositionRendererInstance($controlPositionRenderers[$i - 1]); + $this->assertControlPositionRendererInstance($controlPositionRenderers[$i]); + $this->assertSame($controlPositionRenderers[$i - 1], $controlPositionRenderers[$i]); + } + } + + /** + * Gets the formatters. + * + * @return array The formatters. + */ + protected function getFormatters() + { + $formatterSubscribers = array(); + + foreach ($this->apiFormatterSubscribers as $apiFormatterSubscribers) { + $formatterSubscribers = array_merge( + $formatterSubscribers, + $this->helperFactory->createApiHelper()->getEventDispatcher()->getListeners($apiFormatterSubscribers) + ); + } + + foreach ($this->mapFormatterSubscribers as $mapFormatterSubscribers) { + $formatterSubscribers = array_merge( + $formatterSubscribers, + $this->helperFactory->createMapHelper()->getEventDispatcher()->getListeners($mapFormatterSubscribers) + ); + } + + foreach ($this->placesAutocompleteFormatterSubscribers as $placesAutocompleteFormatterSubscribers) { + $formatterSubscribers = array_merge( + $formatterSubscribers, + $this->helperFactory->createPlacesAutocompleteHelper()->getEventDispatcher()->getListeners( + $placesAutocompleteFormatterSubscribers + ) + ); + } + + $formatters = array(); + + foreach ($formatterSubscribers as $formatterSubscriber) { + $formatters[] = $formatterSubscriber[0]->getFormatter(); + } + + return $formatters; + } + + /** + * Gets the json builders. + * + * @return array The json builders. + */ + protected function getJsonBuilders() + { + $apiHelper = $this->helperFactory->createApiHelper(); + $mapHelper = $this->helperFactory->createMapHelper(); + + $javascriptSubscribers = $apiHelper->getEventDispatcher()->getListeners(ApiEvents::JAVASCRIPT); + + $mapEncodedPolylineSubscribers = $apiHelper->getEventDispatcher()->getListeners( + ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE + ); + + $mapInfoWindowSubscribers = $apiHelper->getEventDispatcher()->getListeners( + ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW + ); + + $mapMarkerClusterSubscribers = $apiHelper->getEventDispatcher()->getListeners( + ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER + ); + + $containerSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_INIT_CONTAINER); + $kmlLayerSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_LAYERS_KML_LAYER); + $mapSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_MAP); + $circleSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE); + + $encodedPolylineSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE + ); + + $groundOverlaySubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY + ); + + $iconSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_ICON); + + $infoWindowSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW + ); + + $markerSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_MARKER); + + $markerClusterSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER + ); + + $markerShapeSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE + ); + + $polygonSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON); + $polylineSubscribers = $mapHelper->getEventDispatcher()->getListeners(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE); + + $rectangleSubscribers = $mapHelper->getEventDispatcher()->getListeners( + MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE + ); + + $jsonBuilderRenderers = array( + $javascriptSubscribers[0][0]->getLoaderRenderer(), + $mapEncodedPolylineSubscribers[0][0]->getEncodedPolylineRenderer(), + $mapInfoWindowSubscribers[0][0]->getInfoWindowRenderer(), + $mapInfoWindowSubscribers[0][0]->getInfoBoxRenderer(), + $mapMarkerClusterSubscribers[0][0]->getMarkerClusterRenderer(), + $containerSubscribers[0][0]->getContainerRenderer(), + $kmlLayerSubscribers[0][0]->getKmlLayerRenderer(), + $mapSubscribers[0][0]->getMapRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getMapTypeControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getOverviewMapControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getPanControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getRotateControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getScaleControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getStreetViewControlRenderer(), + $mapSubscribers[0][0]->getMapRenderer()->getControlsRenderer()->getZoomControlRenderer(), + $circleSubscribers[0][0]->getCircleRenderer(), + $encodedPolylineSubscribers[0][0]->getEncodedPolylineRenderer(), + $groundOverlaySubscribers[0][0]->getGroundOverlayRenderer(), + $iconSubscribers[0][0]->getIconRenderer(), + $infoWindowSubscribers[0][0]->getInfoWindowRenderer(), + $infoWindowSubscribers[0][0]->getInfoBoxRenderer(), + $markerSubscribers[0][0]->getMarkerRenderer(), + $markerClusterSubscribers[0][0]->getMarkerClusterRenderer(), + $markerShapeSubscribers[0][0]->getMarkerShapeRenderer(), + $polygonSubscribers[0][0]->getPolygonRenderer(), + $polylineSubscribers[0][0]->getPolylineRenderer(), + $rectangleSubscribers[0][0]->getRectangleRenderer(), + ); + + $jsonBuilders = array(); + + foreach ($jsonBuilderRenderers as $jsonBuilderRenderer) { + $jsonBuilders[] = $jsonBuilderRenderer->getJsonBuilder(); + } + + return $jsonBuilders; + } +} diff --git a/tests/Helpers/Factories/HelperFactoryTest.php b/tests/Helpers/Factories/HelperFactoryTest.php new file mode 100644 index 00000000..3cc3d6a4 --- /dev/null +++ b/tests/Helpers/Factories/HelperFactoryTest.php @@ -0,0 +1,1529 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Factories; + +use Ivory\GoogleMap\Helpers\Factories\HelperFactory; + +/** + * Helper factory test. + * + * @author GeLo + */ +class HelperFactoryTest extends AbstractHelperFactoryTest +{ + public function testDefaultState() + { + $this->assertFalse($this->helperFactory->isDebug()); + $this->assertSame(4, $this->helperFactory->getIndentation()); + $this->assertJsonBuilderInstance($this->helperFactory->getJsonBuilder()); + $this->assertFormatterInstance($this->helperFactory->getFormatter()); + $this->assertAggregators(); + $this->assertRenderers(); + $this->assertSubscribers(); + } + + public function testInitialState() + { + $this->helperFactory = new HelperFactory(false, $indentation = 2); + + $this->assertFalse($this->helperFactory->isDebug()); + $this->assertSame($indentation, $this->helperFactory->getIndentation()); + } + + public function testSetJsonBuilder() + { + $this->helperFactory->setJsonBuilder($jsonBuilder = $this->createJsonBuilderMock()); + + $this->assertSame($jsonBuilder, $this->helperFactory->getJsonBuilder()); + + foreach ($this->getJsonBuilders() as $item) { + $this->assertSame($item, $jsonBuilder); + } + } + + public function testSetFormatter() + { + $this->helperFactory->setFormatter($formatter = $this->createFormatterMock()); + + $this->assertSame($formatter, $this->helperFactory->getFormatter()); + + foreach ($this->getFormatters() as $item) { + $this->assertSame($item, $formatter); + } + } + + /** + * @dataProvider aggregatorsProvider + */ + public function testSetAggregators(array $aggregators, $assertion = null) + { + $this->helperFactory->setAggregators($aggregators); + + $this->assertAggregators($aggregators); + + if ($assertion !== null) { + foreach ($aggregators as $aggregator) { + call_user_func($assertion, $this, $aggregator); + } + } + } + + /** + * @dataProvider aggregatorsProvider + */ + public function testAddAggregators(array $aggregators, $assertion = null) + { + $this->helperFactory->addAggregators($aggregators); + + $this->assertAggregators($aggregators); + + if ($assertion !== null) { + foreach ($aggregators as $aggregator) { + call_user_func($assertion, $this, $aggregator); + } + } + } + + /** + * @dataProvider aggregatorsProvider + */ + public function testRemoveAggregators(array $aggregators) + { + $this->helperFactory->setAggregators($aggregators); + $this->helperFactory->removeAggregators(array_keys($aggregators)); + + $this->assertAggregators(); + } + + /** + * @dataProvider aggregatorsProvider + */ + public function testResetAggregators(array $aggregators) + { + $this->helperFactory->setAggregators($aggregators); + $this->helperFactory->resetAggregators(); + + $this->assertAggregators(); + } + + /** + * @dataProvider aggregatorProvider + */ + public function testSetAggregator($name, $aggregator, $assertion = null) + { + $this->helperFactory->setAggregator($name, $aggregator); + + $this->assertAggregator($name, $aggregator); + + if ($assertion !== null) { + call_user_func($assertion, $this, $aggregator); + } + } + + /** + * @dataProvider aggregatorProvider + */ + public function testRemoveAggregator($name, $aggregator) + { + $this->helperFactory->setAggregator($name, $aggregator); + $this->helperFactory->removeAggregator($name); + + $this->assertAggregators(); + } + + /** + * @dataProvider renderersProvider + */ + public function testSetRenderers(array $renderers, $assertion = null) + { + $this->helperFactory->setRenderers($renderers); + + $this->assertRenderers($renderers); + + if ($assertion !== null) { + foreach ($renderers as $renderer) { + call_user_func($assertion, $this, $renderer); + } + } + } + + /** + * @dataProvider renderersProvider + */ + public function testAddRenderers(array $renderers, $assertion = null) + { + $this->helperFactory->addRenderers($renderers); + + $this->assertRenderers($renderers); + + if ($assertion !== null) { + foreach ($renderers as $renderer) { + call_user_func($assertion, $this, $renderer); + } + } + } + + /** + * @dataProvider renderersProvider + */ + public function testRemoveRenderers(array $renderers) + { + $this->helperFactory->setRenderers($renderers); + $this->helperFactory->removeRenderers(array_keys($renderers)); + + $this->assertRenderers(); + } + + /** + * @dataProvider renderersProvider + */ + public function testResetRenderers(array $renderers) + { + $this->helperFactory->setRenderers($renderers); + $this->helperFactory->resetRenderers(); + + $this->assertRenderers(); + } + + /** + * @dataProvider rendererProvider + */ + public function testSetRenderer($name, $renderer, $assertion = null) + { + $this->helperFactory->setRenderer($name, $renderer); + + $this->assertRenderer($name, $renderer); + + if ($assertion !== null) { + call_user_func($assertion, $this, $renderer); + } + } + + /** + * @dataProvider rendererProvider + */ + public function testRemoveRenderer($name, $renderer) + { + $this->helperFactory->setRenderer($name, $renderer); + $this->helperFactory->removeRenderer($name); + + $this->assertRenderers(); + } + + /** + * @dataProvider subscribersProvider + */ + public function testSetSubscribers(array $subscribers) + { + $this->helperFactory->setSubscribers($subscribers); + + $this->assertSubscribers($subscribers); + } + + /** + * @dataProvider subscribersProvider + */ + public function testAddSubscribers(array $subscribers) + { + $this->helperFactory->addSubscribers($subscribers); + + $this->assertSubscribers($subscribers); + } + + /** + * @dataProvider subscribersProvider + */ + public function testRemoveSubscribers(array $subscribers) + { + $this->helperFactory->setSubscribers($subscribers); + $this->helperFactory->removeSubscribers($names = array_keys($subscribers)); + + foreach ($names as $name) { + $this->assertNoSubscriber($name); + } + } + + /** + * @dataProvider subscribersProvider + */ + public function testResetSubscribers(array $subscribers) + { + $this->helperFactory->setSubscribers($subscribers); + $this->helperFactory->resetSubscribers(); + + $this->assertSubscribers(); + } + + /** + * @dataProvider subscriberProvider + */ + public function testSetSubscriber($name) + { + $this->helperFactory->setSubscriber($name, $subscriber = $this->createSymfonyEventSubscriberMock()); + + $this->assertSubscriber($name, $subscriber); + } + + /** + * @dataProvider subscriberProvider + */ + public function testRemoveSubscriber($name) + { + $this->helperFactory->setSubscriber($name, $this->createSymfonyEventSubscriberMock()); + $this->helperFactory->removeSubscriber($name); + + $this->assertNoSubscriber($name); + } + + /** + * Gets the aggregator provider. + * + * @return array The aggregator provider. + */ + public function aggregatorProvider() + { + return array( + array( + 'bound', + $this->createBoundAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('bound'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('coordinate')->getBoundAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('bound')->getBoundAggregator(), + $aggregator + ); + }, + ), + array( + 'circle', + $this->createCircleAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('circle'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('coordinate')->getCircleAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('circle')->getCircleAggregator(), + $aggregator + ); + }, + ), + array( + 'coordinate', + $this->createCoordinateAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('coordinate'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('coordinate')->getCoordinateAggregator(), + $aggregator + ); + }, + ), + array( + 'dom_event', + $this->createDomEventAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('dom_event'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('dom_event')->getDomEventAggregator(), + $aggregator + ); + }, + ), + array( + 'dom_event_once', + $this->createDomEventOnceAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('dom_event_once'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('dom_event_once')->getDomEventOnceAggregator(), + $aggregator + ); + }, + ), + array( + 'encoded_polyline', + $this->createEncodedPolylineAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('encoded_polyline'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('encoded_polyline')->getEncodedPolylineAggregator(), + $aggregator + ); + }, + ), + array( + 'event', + $this->createEventAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('event'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('event')->getEventAggregator(), + $aggregator + ); + }, + ), + array( + 'event_once', + $this->createEventOnceAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('event_once'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('event_once')->getEventOnceAggregator(), + $aggregator + ); + }, + ), + array( + 'extendable', + $this->createExtendableAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('extendable'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('extendable')->getExtendableAggregator(), + $aggregator + ); + }, + ), + array( + 'ground_overlay', + $this->createGroundOverlayAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('ground_overlay'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('bound')->getGroundOverlayAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('ground_overlay')->getGroundOverlayAggregator(), + $aggregator + ); + }, + ), + array( + 'icon', + $this->createIconAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('icon'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('size')->getIconAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('icon')->getIconAggregator(), + $aggregator + ); + }, + ), + array( + 'info_window', + $this->createInfoWindowAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('info_window'), $aggregator); + + foreach (array('coordinate', 'size') as $value) { + $test->assertSame( + $test->getHelperFactory()->getAggregator($value)->getInfoWindowAggregator(), + $aggregator + ); + } + + foreach (array('info_window_close', 'info_window_open', 'info_window') as $value) { + $test->assertSame( + $test->getHelperFactory()->getSubscriber($value)->getInfoWindowAggregator(), + $aggregator + ); + } + }, + ), + array( + 'kml_layer', + $this->createKmlLayerAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('kml_layer'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('kml_layer')->getKmlLayerAggregator(), + $aggregator + ); + }, + ), + array( + 'marker', + $this->createMarkerAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('marker'), $aggregator); + + foreach (array('coordinate', 'icon', 'info_window', 'marker_shape', 'point') as $value) { + $test->assertSame( + $test->getHelperFactory()->getAggregator($value)->getMarkerAggregator(), + $aggregator + ); + } + + foreach (array('marker_open_event', 'marker') as $value) { + $test->assertSame( + $test->getHelperFactory()->getSubscriber($value)->getMarkerAggregator(), + $aggregator + ); + } + }, + ), + array( + 'marker_shape', + $this->createMarkerShapeAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('marker_shape'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('marker_shape')->getMarkerShapeAggregator(), + $aggregator + ); + }, + ), + array( + 'point', + $this->createPointAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('point'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('point')->getPointAggregator(), + $aggregator + ); + }, + ), + array( + 'size', + $this->createSizeAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('size'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('size')->getSizeAggregator(), + $aggregator + ); + }, + ), + array( + 'polygon', + $this->createPolygonAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('polygon'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('coordinate')->getPolygonAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('polygon')->getPolygonAggregator(), + $aggregator + ); + }, + ), + array( + 'polyline', + $this->createPolylineAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('polyline'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('coordinate')->getPolylineAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('polyline')->getPolylineAggregator(), + $aggregator + ); + }, + ), + array( + 'rectangle', + $this->createRectangleAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('rectangle'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('bound')->getRectangleAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('rectangle')->getRectangleAggregator(), + $aggregator + ); + }, + ), + array( + 'autocomplete_bound', + $this->createAutocompleteBoundAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('autocomplete_bound'), $aggregator); + + $test->assertSame( + $test->getHelperFactory()->getAggregator('autocomplete_coordinate')->getBoundAggregator(), + $aggregator + ); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('autocomplete_bound')->getBoundAggregator(), + $aggregator + ); + }, + ), + array( + 'autocomplete_coordinate', + $this->createAutocompleteCoordinateAggregatorMock(), + function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($test->getHelperFactory()->getAggregator('autocomplete_coordinate'), $aggregator); + }, + ), + array('custom', new \stdClass(), function (\PHPUnit_Framework_TestCase $test, $aggregator) { + $test->assertSame($aggregator, $test->getHelperFactory()->getAggregator('custom')); + }), + ); + } + + /** + * Gets the aggregators provider. + * + * @return array The aggregators provider. + */ + public function aggregatorsProvider() + { + $aggregators = array(); + + foreach ($this->aggregatorProvider() as $provider) { + $aggregators[] = array(array($provider[0] => $provider[1]), $provider[2]); + } + + return $aggregators; + } + + /** + * Gets the renderer provider. + * + * @return array The renderer provider. + */ + public function rendererProvider() + { + return array( + array( + 'animation', + $this->createAnimationRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('animation'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('marker')->getAnimationRenderer(), + $renderer + ); + }, + ), + array( + 'autocomplete', + $this->createAutocompleteRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('autocomplete'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('autocomplete')->getAutocompleteRenderer(), + $renderer + ); + }, + ), + array( + 'autocomplete_container', + $this->createAutocompleteContainerRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('autocomplete_container'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('autocomplete_container')->getContainerRenderer(), + $renderer + ); + }, + ), + array( + 'bound', + $this->createBoundRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('bound'), $renderer); + + foreach (array('bound', 'autocomplete_bound') as $value) { + $test->assertSame( + $test->getHelperFactory()->getSubscriber($value)->getBoundRenderer(), + $renderer + ); + } + }, + ), + array( + 'circle', + $this->createCircleRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('circle'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('circle')->getCircleRenderer(), + $renderer + ); + }, + ), + array( + 'coordinate', + $this->createCoordinateRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('coordinate'), $renderer); + + foreach (array('coordinate', 'autocomplete_coordinate') as $value) { + $test->assertSame( + $test->getHelperFactory()->getSubscriber($value)->getCoordinateRenderer(), + $renderer + ); + } + }, + ), + array( + 'controls', + $this->createControlsRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('controls'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('map')->getControlsRenderer(), + $renderer + ); + }, + ), + array( + 'control_position', + $this->createControlPositionRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('control_position'), $renderer); + + $values = array( + 'map_type_control', + 'pan_control', + 'rotate_control', + 'street_view_control', + 'zoom_control', + ); + + foreach ($values as $value) { + $test->assertSame( + $test->getHelperFactory()->getRenderer($value)->getControlPositionRenderer(), + $renderer + ); + } + }, + ), + array( + 'dom_event', + $this->createDomEventRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('dom_event'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('dom_event')->getDomEventRenderer(), + $renderer + ); + }, + ), + array( + 'dom_event_once', + $this->createDomEventOnceRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('dom_event_once'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('dom_event_once')->getDomEventOnceRenderer(), + $renderer + ); + }, + ), + array( + 'encoded_polyline', + $this->createEncodedPolylineRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('encoded_polyline'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('encoded_polyline')->getEncodedPolylineRenderer(), + $renderer + ); + }, + ), + array( + 'encoding', + $this->createEncodingRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('encoding'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('encoded_polyline')->getEncodingRenderer(), + $renderer + ); + }, + ), + array( + 'event', + $this->createEventRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('event'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('event')->getEventRenderer(), + $renderer + ); + }, + ), + array( + 'event_once', + $this->createEventOnceRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('event_once'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('event_once')->getEventOnceRenderer(), + $renderer + ); + }, + ), + array( + 'extendable', + $this->createExtendableRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('extendable'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('extendable')->getExtendableRenderer(), + $renderer + ); + }, + ), + array( + 'ground_overlay', + $this->createGroundOverlayRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('ground_overlay'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('ground_overlay')->getGroundOverlayRenderer(), + $renderer + ); + }, + ), + array( + 'icon', + $this->createIconRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('icon'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('icon')->getIconRenderer(), + $renderer + ); + }, + ), + array( + 'info_box', + $this->createInfoBoxRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('info_box'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('info_window')->getInfoBoxRenderer(), + $renderer + ); + }, + ), + array( + 'info_window', + $this->createInfoWindowRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('info_window'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('info_window')->getInfoWindowRenderer(), + $renderer + ); + }, + ), + array( + 'info_window_close', + $this->createInfoWindowCloseRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('info_window_close'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('info_window_close')->getInfoWindowCloseRenderer(), + $renderer + ); + }, + ), + array( + 'info_window_open', + $this->createInfoWindowOpenRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('info_window_open'), $renderer); + + foreach (array('info_window_open', 'marker_open_event') as $value) { + $test->assertSame( + $test->getHelperFactory()->getSubscriber($value)->getInfoWindowOpenRenderer(), + $renderer + ); + } + }, + ), + array( + 'kml_layer', + $this->createKmlLayerRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('kml_layer'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('kml_layer')->getKmlLayerRenderer(), + $renderer + ); + }, + ), + array( + 'loader', + $this->createLoaderRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('loader'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('api_javascript')->getLoaderRenderer(), + $renderer + ); + }, + ), + array( + 'map', + $this->createMapRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('map')->getMapRenderer(), + $renderer + ); + }, + ), + array( + 'map_bound', + $this->createMapBoundRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_bound'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('map_bound')->getMapBoundRenderer(), + $renderer + ); + }, + ), + array( + 'map_center', + $this->createMapCenterRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_center'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('map_center')->getMapCenterRenderer(), + $renderer + ); + }, + ), + array( + 'map_container', + $this->createMapContainerRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_container'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('map_container')->getContainerRenderer(), + $renderer + ); + }, + ), + array( + 'map_type_control', + $this->createMapTypeControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_type_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getMapTypeControlRenderer(), + $renderer + ); + }, + ), + array( + 'map_type_control_style', + $this->createMapTypeControlStyleRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_type_control_style'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('map_type_control')->getMapTypeControlStyleRenderer(), + $renderer + ); + }, + ), + array( + 'map_type_id', + $this->createMapTypeIdRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('map_type_id'), $renderer); + + foreach (array('map_type_control', 'map') as $value) { + $test->assertSame( + $test->getHelperFactory()->getRenderer($value)->getMapTypeIdRenderer(), + $renderer + ); + } + }, + ), + array( + 'marker', + $this->createMarkerRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('marker'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('marker')->getMarkerRenderer(), + $renderer + ); + }, + ), + array( + 'marker_cluster', + $this->createMarkerClusterRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('marker_cluster'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('marker_cluster')->getMarkerClusterRenderer(), + $renderer + ); + }, + ), + array( + 'marker_shape', + $this->createMarkerShapeRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('marker_shape'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('marker_shape')->getMarkerShapeRenderer(), + $renderer + ); + }, + ), + array( + 'overview_map_control', + $this->createOverviewMapControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('overview_map_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getOverviewMapControlRenderer(), + $renderer + ); + }, + ), + array( + 'pan_control', + $this->createPanControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('pan_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getPanControlRenderer(), + $renderer + ); + }, + ), + array( + 'point', + $this->createPointRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('point'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('point')->getPointRenderer(), + $renderer + ); + }, + ), + array( + 'polygon', + $this->createPolygonRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('polygon'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('polygon')->getPolygonRenderer(), + $renderer + ); + }, + ), + array( + 'polyline', + $this->createPolylineRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('polyline'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('polyline')->getPolylineRenderer(), + $renderer + ); + }, + ), + array( + 'rectangle', + $this->createRectangleRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('rectangle'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('rectangle')->getRectangleRenderer(), + $renderer + ); + }, + ), + array( + 'rotate_control', + $this->createRotateControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('rotate_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getRotateControlRenderer(), + $renderer + ); + }, + ), + array( + 'scale_control', + $this->createScaleControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('scale_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getScaleControlRenderer(), + $renderer + ); + }, + ), + array( + 'scale_control_style', + $this->createScaleControlStyleRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('scale_control_style'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('scale_control')->getScaleControlStyleRenderer(), + $renderer + ); + }, + ), + array( + 'size', + $this->createSizeRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('size'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getSubscriber('size')->getSizeRenderer(), + $renderer + ); + }, + ), + array( + 'street_view_control', + $this->createStreetViewControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('street_view_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getStreetViewControlRenderer(), + $renderer + ); + }, + ), + array( + 'zoom_control', + $this->createZoomControlRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('zoom_control'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('controls')->getZoomControlRenderer(), + $renderer + ); + }, + ), + array( + 'zoom_control_style', + $this->createZoomControlStyleRendererMock(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('zoom_control_style'), $renderer); + + $test->assertSame( + $test->getHelperFactory()->getRenderer('zoom_control')->getZoomControlStyleRenderer(), + $renderer + ); + }, + ), + array( + 'custom', + new \stdClass(), + function (\PHPUnit_Framework_TestCase $test, $renderer) { + $test->assertSame($test->getHelperFactory()->getRenderer('custom'), $renderer); + }, + ), + ); + } + + /** + * Gets the renderers provider. + * + * @return array The renderers provider. + */ + public function renderersProvider() + { + $renderers = array(); + + foreach ($this->rendererProvider() as $provider) { + $renderers[] = array(array($provider[0] => $provider[1]), $provider[2]); + } + + return $renderers; + } + + /** + * Gets the subscriber provider. + * + * @return array The subscriber provider. + */ + public function subscriberProvider() + { + return array( + array('base'), + array('events'), + array('layers'), + array('overlays'), + array('autocomplete_base'), + array('bound'), + array('coordinate'), + array('point'), + array('size'), + array('dom_event_once'), + array('dom_event'), + array('event_once'), + array('event'), + array('kml_layer'), + array('circle'), + array('encoded_polyline'), + array('extendable'), + array('ground_overlay'), + array('icon'), + array('info_window_close'), + array('info_window_open'), + array('info_window'), + array('marker_cluster'), + array('marker_open_event'), + array('marker_shape'), + array('marker'), + array('polygon'), + array('polyline'), + array('rectangle'), + array('autocomplete_bound'), + array('autocomplete_coordinate'), + array('autocomplete_container'), + array('autocomplete_html'), + array('autocomplete_init'), + array('autocomplete_javascript'), + array('autocomplete'), + array('api_javascript'), + array('map_bound'), + array('map_center'), + array('map_container'), + array('map_finish'), + array('map_html'), + array('map_init'), + array('map_javascript'), + array('map_stylesheet'), + array('map'), + array('custom'), + ); + } + + /** + * Gets the subscribers provider. + * + * @return array The subscribers provider. + */ + public function subscribersProvider() + { + $subscribers = array(); + + foreach ($this->subscriberProvider() as $provider) { + $subscribers[] = array(array($provider[0] => $this->createSymfonyEventSubscriberMock())); + } + + return $subscribers; + } + + /** + * Asserts the are aggregators. + * + * @param array $aggregators The aggregators. + */ + protected function assertAggregators($aggregators = array()) + { + $aggregators = array_merge( + array( + 'autocomplete_bound' => 'Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator', + 'autocomplete_coordinate' => 'Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator', + 'marker' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator', + 'circle' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator', + 'encoded_polyline' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator', + 'extendable' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator', + 'ground_overlay' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator', + 'icon' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator', + 'info_window' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator', + 'marker_shape' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator', + 'polygon' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator', + 'polyline' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator', + 'rectangle' => 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator', + 'kml_layer' => 'Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator', + 'dom_event_once' => 'Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator', + 'dom_event' => 'Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator', + 'event_once' => 'Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator', + 'event' => 'Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator', + 'bound' => 'Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator', + 'coordinate' => 'Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator', + 'point' => 'Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator', + 'size' => 'Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator' + ), + $aggregators + ); + + $this->assertInternalType('array', $aggregators); + + $this->assertTrue($this->helperFactory->hasAggregators()); + $this->assertNotEmpty($this->helperFactory->getAggregators()); + + foreach ($aggregators as $name => $aggregator) { + $this->assertAggregator($name, $aggregator); + } + } + + /** + * Asserts there is an aggregator. + * + * @param string $name The name. + * @param object $aggregator The aggregator. + */ + protected function assertAggregator($name, $aggregator) + { + $this->assertTrue($this->helperFactory->hasAggregator($name)); + + if (is_string($aggregator)) { + $this->assertInstanceOf($aggregator, $this->helperFactory->getAggregator($name)); + } else { + $this->assertSame($aggregator, $this->helperFactory->getAggregator($name)); + } + } + + /** + * Asserts the are renderers. + * + * @param array $renderers The renderers. + */ + protected function assertRenderers($renderers = array()) + { + $renderers = array_merge( + array( + 'bound' => 'Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer', + 'coordinate' => 'Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer', + 'point' => 'Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer', + 'size' => 'Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer', + 'dom_event_once' => 'Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer', + 'dom_event' => 'Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer', + 'event_once' => 'Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer', + 'event' => 'Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer', + 'encoding' => 'Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer', + 'kml_layer' => 'Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer', + 'animation' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer', + 'circle' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer', + 'encoded_polyline' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer', + 'extendable' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer', + 'ground_overlay' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer', + 'icon' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer', + 'info_window_close' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer', + 'info_window_open' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer', + 'info_window' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer', + 'info_box' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer', + 'marker_cluster' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer', + 'marker_shape' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer', + 'marker' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer', + 'polygon' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer', + 'polyline' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer', + 'rectangle' => 'Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer', + 'autocomplete_container' => 'Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer', + 'autocomplete' => 'Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer', + 'loader' => 'Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer', + 'map_bound' => 'Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer', + 'map_center' => 'Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer', + 'map_container' => 'Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer', + 'map_type_id' => 'Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer', + 'control_position' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer', + 'map_type_control_style' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer', + 'overview_map_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer', + 'pan_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer', + 'rotate_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer', + 'scale_control_style' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer', + 'scale_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer', + 'street_view_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer', + 'zoom_control_style' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer', + 'zoom_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer', + 'map_type_control' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer', + 'controls' => 'Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer', + 'map' => 'Ivory\GoogleMap\Helpers\Renderers\MapRenderer', + ), + $renderers + ); + + $this->assertInternalType('array', $renderers); + + $this->assertTrue($this->helperFactory->hasRenderers()); + $this->assertNotEmpty($this->helperFactory->getRenderers()); + + foreach ($renderers as $name => $renderer) { + $this->assertRenderer($name, $renderer); + } + } + + /** + * Asserts there is an renderer. + * + * @param string $name The name. + * @param object $renderer The renderer. + */ + protected function assertRenderer($name, $renderer) + { + $this->assertTrue($this->helperFactory->hasRenderer($name)); + + if (is_string($renderer)) { + $this->assertInstanceOf($renderer, $this->helperFactory->getRenderer($name)); + } else { + $this->assertSame($renderer, $this->helperFactory->getRenderer($name)); + } + } + + /** + * Asserts the are subscribers. + * + * @param array $subscribers The subscribers. + */ + protected function assertSubscribers($subscribers = array()) + { + $subscribers = array_merge( + array( + + ), + $subscribers + ); + + $this->assertInternalType('array', $subscribers); + + $this->assertTrue($this->helperFactory->hasSubscribers()); + $this->assertNotEmpty($this->helperFactory->getSubscribers()); + + foreach ($subscribers as $name => $subscriber) { + $this->assertSubscriber($name, $subscriber); + } + } + + /** + * Asserts there is an subscriber. + * + * @param string $name The name. + * @param object $subscriber The subscriber. + */ + protected function assertSubscriber($name, $subscriber) + { + $this->assertTrue($this->helperFactory->hasSubscriber($name)); + + if (is_string($subscriber)) { + $this->assertInstanceOf($subscriber, $this->helperFactory->getSubscriber($name)); + } else { + $this->assertSame($subscriber, $this->helperFactory->getSubscriber($name)); + } + } + + /** + * Asserts there is no subscriber. + * + * @param string $name The subscriber name. + */ + protected function assertNoSubscriber($name) + { + $this->assertFalse($this->helperFactory->hasSubscriber($name)); + $this->assertNull($this->helperFactory->getSubscriber($name)); + } + + /** + * Gets the helper factory. + * + * @return \Ivory\GoogleMap\Helpers\Factories\HelperFactoryInterface The helper factory. + */ + public function getHelperFactory() + { + return $this->helperFactory; + } + + /** + * {@inheritdoc} + */ + protected function createHelperFactory() + { + return new HelperFactory(); + } +} diff --git a/tests/Helpers/Factories/Symfony2HelperFactoryTest.php b/tests/Helpers/Factories/Symfony2HelperFactoryTest.php new file mode 100644 index 00000000..4fb8150f --- /dev/null +++ b/tests/Helpers/Factories/Symfony2HelperFactoryTest.php @@ -0,0 +1,358 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Factories; + +use Ivory\GoogleMap\Helpers\Factories\Symfony2HelperFactory; + +/** + * Symfony 2 helper factory test. + * + * @author GeLo + */ +class Symfony2HelperFactoryTest extends AbstractHelperFactoryTest +{ + /** @var string */ + protected $cachePath; + + /** + * {@inheritdo©} + */ + protected function setUp() + { + parent::setUp(); + + $this->cachePath = realpath(sys_get_temp_dir()); + } + + /** + * {@inheritdo©} + */ + protected function tearDown() + { + if ($this->helperFactory->hasCachePath()) { + $filename = $this->helperFactory->getCachePath().'/'.$this->helperFactory->getContainerName().'.php'; + + if (file_exists($filename)) { + unlink($filename); + } + } + + parent::tearDown(); + + unset($this->cachePath); + } + + public function testDefaultState() + { + $this->assertFalse($this->helperFactory->isDebug()); + $this->assertSame(4, $this->helperFactory->getIndentation()); + $this->assertFalse($this->helperFactory->hasCachePath()); + $this->assertSame('IvoryGoogleMapContainer', $this->helperFactory->getContainerName()); + $this->assertParameters(); + $this->assertExtensions(); + } + + public function testInitialState() + { + $this->helperFactory = new Symfony2HelperFactory( + true, + $indentation = 2, + $this->cachePath, + $containerName = 'foo' + ); + + $this->assertTrue($this->helperFactory->isDebug()); + $this->assertSame($indentation, $this->helperFactory->getIndentation()); + $this->assertTrue($this->helperFactory->hasCachePath()); + $this->assertSame($this->cachePath, $this->helperFactory->getCachePath()); + $this->assertSame($containerName, $this->helperFactory->getContainerName()); + } + + public function testSetCachePath() + { + $this->helperFactory->setCachePath($cachePath = $this->cachePath); + + $this->assertTrue($this->helperFactory->hasCachePath()); + $this->assertSame($cachePath, $this->helperFactory->getCachePath()); + } + + public function testSetContainerName() + { + $this->helperFactory->setContainerName($containerName = 'foo'); + + $this->assertSame($containerName, $this->helperFactory->getContainerName()); + } + + public function testSetParameters() + { + $this->helperFactory->setParameters($parameters = array( + 'ivory.google_map.debug' => true, + 'ivory.google_map.indentation' => 2, + 'foo' => 'bar', + )); + + $this->assertParameters($parameters); + } + + public function testAddParameters() + { + $this->helperFactory->addParameters($parameters = array( + 'ivory.google_map.debug' => true, + 'ivory.google_map.indentation' => 2, + 'foo' => 'bar', + )); + + $this->assertParameters($parameters); + } + + public function testRemoveParameters() + { + $this->helperFactory->setParameters($parameters = array( + 'ivory.google_map.debug' => false, + 'ivory.google_map.indentation' => 4, + 'foo' => 'bar', + )); + + $this->helperFactory->removeParameters(array_keys($parameters)); + + $this->assertParameters(); + } + + public function testSetParameter() + { + $this->helperFactory->setParameter($name = 'foo', $value = 'bar'); + + $this->assertParameter($name, $value); + } + + public function testRemoveParameter() + { + $this->helperFactory->setParameter($name = 'foo', 'bar'); + $this->helperFactory->removeParameter($name); + + $this->assertNoParameter($name); + } + + public function testSetExtensions() + { + $this->helperFactory->setExtensions( + $extensions = array($this->createSymfonyExtensionMock()) + ); + + $this->assertExtensions($extensions); + } + + public function testAddExtensions() + { + $this->helperFactory->addExtensions( + $extensions = array($this->createSymfonyExtensionMock()) + ); + + $this->assertExtensions($extensions); + } + + public function testRemoveExtensions() + { + $this->helperFactory->setExtensions( + $extensions = array($this->createSymfonyExtensionMock()) + ); + + $this->helperFactory->removeExtensions($extensions); + + $this->assertExtensions(); + } + + public function testAddExtension() + { + $this->helperFactory->addExtension($extension = $this->createSymfonyExtensionMock()); + + $this->assertExtensions(array($extension)); + } + + public function testRemoveExtension() + { + $this->helperFactory->addExtension($extension = $this->createSymfonyExtensionMock()); + $this->helperFactory->removeExtension($extension); + + $this->assertNoExtension($extension); + } + + public function testSetCompilerPasses() + { + $this->helperFactory->setCompilerPasses( + $compilerPasses = array($this->createSymfonyCompilerPassMock()) + ); + + $this->assertCompilerPasses($compilerPasses); + } + + public function testAddCompilerPasses() + { + $this->helperFactory->addCompilerPasses( + $compilerPasses = array($this->createSymfonyCompilerPassMock()) + ); + + $this->assertCompilerPasses($compilerPasses); + } + + public function testRemoveCompilerPasses() + { + $this->helperFactory->setCompilerPasses( + $compilerPasses = array($this->createSymfonyCompilerPassMock()) + ); + + $this->helperFactory->removeCompilerPasses($compilerPasses); + + $this->assertCompilerPasses(); + } + + public function testAddCompilerPass() + { + $this->helperFactory->addCompilerPass( + $compilerPass = $this->createSymfonyCompilerPassMock() + ); + + $this->assertCompilerPasses(array($compilerPass)); + } + + public function testRemoveCompilerPass() + { + $this->helperFactory->addCompilerPass( + $compilerPass = $this->createSymfonyCompilerPassMock() + ); + + $this->helperFactory->removeCompilerPass($compilerPass); + + $this->assertNoCompilerPass($compilerPass); + } + + public function testContainerCache() + { + $this->helperFactory->setCachePath($this->cachePath); + + $this->assertApiHelperInstance($this->helperFactory->createApiHelper()); + $this->assertMapHelperInstance($this->helperFactory->createMapHelper()); + $this->assertAutocompleteHelperInstance($this->helperFactory->createPlacesAutocompleteHelper()); + + $this->assertFileExists( + $this->helperFactory->getCachePath().'/'.$this->helperFactory->getContainerName().'.php' + ); + } + + /** + * Asserts the parameters. + * + * @param array $parameters The parameters. + */ + protected function assertParameters(array $parameters = array()) + { + $parameters = array_merge( + array( + 'ivory.google_map.debug' => false, + 'ivory.google_map.indentation' => 4, + ), + $parameters + ); + + $this->assertTrue($this->helperFactory->hasParameters()); + $this->assertSame($parameters, $this->helperFactory->getParameters()); + + foreach ($parameters as $name => $value) { + $this->assertParameter($name, $value); + } + } + + /** + * Asserts a parameters. + * + * @param string $name The name. + * @param mixed $value The value. + */ + protected function assertParameter($name, $value) + { + $this->assertTrue($this->helperFactory->hasParameter($name)); + $this->assertSame($value, $this->helperFactory->getParameter($name)); + } + + /** + * Asserts no parameter. + * + * @param string $name The name. + */ + protected function assertNoParameter($name) + { + $this->assertFalse($this->helperFactory->hasParameter($name)); + $this->assertNull($this->helperFactory->getParameter($name)); + } + + /** + * Asserts the extensions. + * + * @param array $extensions The extensions. + */ + protected function assertExtensions(array $extensions = array()) + { + $this->assertTrue($this->helperFactory->hasExtensions()); + $this->assertSame(count($extensions) + 1, count($this->helperFactory->getExtensions())); + + foreach ($extensions as $extension) { + $this->assertSymfonyExtensionInstance($extension); + $this->assertTrue($this->helperFactory->hasExtension($extension)); + } + } + + /** + * Asserts no extension. + * + * @param \Symfony\Component\DependencyInjection\Extension\ExtensionInterface $extension The extension. + */ + protected function assertNoExtension($extension) + { + $this->assertSymfonyExtensionInstance($extension); + $this->assertFalse($this->helperFactory->hasExtension($extension)); + } + + /** + * Asserts the compiler passes. + * + * @param array $compilerPasses The compiler passes. + */ + protected function assertCompilerPasses(array $compilerPasses = array()) + { + $this->assertTrue($this->helperFactory->hasCompilerPasses()); + $this->assertSame(count($compilerPasses) + 2, count($this->helperFactory->getCompilerPasses())); + + foreach ($compilerPasses as $compilerPass) { + $this->assertSymfonyCompilerPassInstance($compilerPass); + $this->assertTrue($this->helperFactory->hasCompilerPass($compilerPass)); + } + } + + /** + * Asserts no compiler pass. + * + * @param \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $compilerPass The compiler pass. + */ + protected function assertNoCompilerPass($compilerPass) + { + $this->assertSymfonyCompilerPassInstance($compilerPass); + $this->assertFalse($this->helperFactory->hasCompilerPass($compilerPass)); + } + + /** + * {@inheritdoc} + */ + protected function createHelperFactory() + { + return new Symfony2HelperFactory(); + } +} diff --git a/tests/Helpers/HelperTest.php b/tests/Helpers/HelperTest.php new file mode 100644 index 00000000..4c1ca960 --- /dev/null +++ b/tests/Helpers/HelperTest.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +/** + * Helper test. + * + * @author GeLo + */ +class HelperTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\AbstractHelper */ + protected $helper; + + /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventDispatcher; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->helper = $this->createHelperMockBuilder() + ->setConstructorArgs(array($this->eventDispatcher = $this->createSymfonyEventDispatcherMock())) + ->getMockForAbstractClass(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventDispatcher); + unset($this->helper); + } + + public function testDefaultState() + { + $this->assertSame($this->eventDispatcher, $this->helper->getEventDispatcher()); + } + + public function testSetEventDispatcher() + { + $this->helper->setEventDispatcher($eventDispatcher = $this->createSymfonyEventDispatcherMock()); + + $this->assertSame($eventDispatcher, $this->helper->getEventDispatcher()); + } +} diff --git a/tests/Helpers/MapEventTest.php b/tests/Helpers/MapEventTest.php new file mode 100644 index 00000000..1bd83606 --- /dev/null +++ b/tests/Helpers/MapEventTest.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\MapEvent; + +/** + * Map event test. + * + * @author GeLo + */ +class MapEventTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\MapEvent */ + protected $mapEvent; + + /** @var \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject */ + protected $map; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapEvent = new MapEvent($this->map = $this->createMapMock()); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->map); + unset($this->mapEvent); + } + + public function testInheritance() + { + $this->assertHelperEventInstance($this->mapEvent); + } + + public function testDefaultState() + { + $this->assertSame($this->map, $this->mapEvent->getMap()); + } +} diff --git a/tests/Helpers/MapEventsTest.php b/tests/Helpers/MapEventsTest.php new file mode 100644 index 00000000..a77e0238 --- /dev/null +++ b/tests/Helpers/MapEventsTest.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\MapEvents; + +/** + * Map events test. + * + * @author GeLo + */ +class MapEventsTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Helpers\MapEvents'); + } + + public function testConstants() + { + $this->assertSame('ivory.google_map.map.html', MapEvents::HTML); + $this->assertSame('ivory.google_map.map.stylesheet', MapEvents::STYLESHEET); + $this->assertSame('ivory.google_map.map.javascript', MapEvents::JAVASCRIPT); + $this->assertSame('ivory.google_map.map.javascript.init', MapEvents::JAVASCRIPT_INIT); + $this->assertSame( + 'ivory.google_map.map.javascript.init.marker_open_event', + MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT + ); + $this->assertSame('ivory.google_map.map.javascript.init.container', MapEvents::JAVASCRIPT_INIT_CONTAINER); + $this->assertSame('ivory.google_map.map.javascript.base', MapEvents::JAVASCRIPT_BASE); + $this->assertSame('ivory.google_map.map.javascript.base.coordinate', MapEvents::JAVASCRIPT_BASE_COORDINATE); + $this->assertSame('ivory.google_map.map.javascript.base.bound', MapEvents::JAVASCRIPT_BASE_BOUND); + $this->assertSame('ivory.google_map.map.javascript.base.point', MapEvents::JAVASCRIPT_BASE_POINT); + $this->assertSame('ivory.google_map.map.javascript.base.size', MapEvents::JAVASCRIPT_BASE_SIZE); + $this->assertSame('ivory.google_map.map.javascript.map', MapEvents::JAVASCRIPT_MAP); + $this->assertSame('ivory.google_map.map.javascript.overlays', MapEvents::JAVASCRIPT_OVERLAYS); + $this->assertSame('ivory.google_map.map.javascript.overlays.circle', MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.encoded_polyline', + MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE + ); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.ground_overlay', + MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY + ); + $this->assertSame('ivory.google_map.map.javascript.overlays.polygon', MapEvents::JAVASCRIPT_OVERLAYS_POLYGON); + $this->assertSame('ivory.google_map.map.javascript.overlays.polyline', MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.rectangle', + MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE + ); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.info_window', + MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW + ); + $this->assertSame('ivory.google_map.map.javascript.overlays.marker_image', MapEvents::JAVASCRIPT_OVERLAYS_ICON); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.marker_shape', + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE + ); + $this->assertSame('ivory.google_map.map.javascript.overlays.marker', MapEvents::JAVASCRIPT_OVERLAYS_MARKER); + $this->assertSame( + 'ivory.google_map.map.javascript.overlays.marker_cluster', + MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER + ); + $this->assertSame('ivory.google_map.map.javascript.layers', MapEvents::JAVASCRIPT_LAYERS); + $this->assertSame('ivory.google_map.map.javascript.layers.kml_layer', MapEvents::JAVASCRIPT_LAYERS_KML_LAYER); + $this->assertSame('ivory.google_map.map.javascript.events', MapEvents::JAVASCRIPT_EVENTS); + $this->assertSame('ivory.google_map.map.javascript.events.dom_event', MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT); + $this->assertSame( + 'ivory.google_map.map.javascript.events.dom_event_once', + MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE + ); + $this->assertSame('ivory.google_map.map.javascript.events.event', MapEvents::JAVASCRIPT_EVENTS_EVENT); + $this->assertSame('ivory.google_map.map.javascript.events.event_once', MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE); + $this->assertSame('ivory.google_map.map.javascript.finish', MapEvents::JAVASCRIPT_FINISH); + $this->assertSame( + 'ivory.google_map.map.javascript.finish.info_window_open', + MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN + ); + $this->assertSame('ivory.google_map.map.javascript.finish.extendable', MapEvents::JAVASCRIPT_FINISH_EXTENDABLE); + $this->assertSame('ivory.google_map.map.javascript.finish.map_center', MapEvents::JAVASCRIPT_FINISH_MAP_CENTER); + $this->assertSame('ivory.google_map.map.javascript.finish.map_bound', MapEvents::JAVASCRIPT_FINISH_MAP_BOUND); + } +} diff --git a/tests/Helpers/MapHelperTest.php b/tests/Helpers/MapHelperTest.php new file mode 100644 index 00000000..fe7bff14 --- /dev/null +++ b/tests/Helpers/MapHelperTest.php @@ -0,0 +1,132 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\MapEvent; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\MapHelper; +use Ivory\GoogleMap\Map; + +/** + * Map helper test. + * + * @author GeLo + */ +class MapHelperTest extends AbstractHelperTest +{ + /** @var \Ivory\GoogleMap\Helpers\MapHelper */ + protected $mapHelper; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapHelper = new MapHelper($this->eventDispatcher); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapHelper); + } + + public function testInheritance() + { + $this->assertHelperInstance($this->mapHelper); + } + + public function testRenderHtml() + { + $map = $this->createMapMock(); + $code = 'code'; + + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with($this->identicalTo(MapEvents::HTML), $this->createMapEventCallbackConstraint($map, $code)); + + $this->assertSame($code, $this->mapHelper->renderHtml($map)); + } + + public function testRenderStylesheet() + { + $map = $this->createMapMock(); + $code = 'code'; + + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with($this->identicalTo(MapEvents::STYLESHEET), $this->createMapEventCallbackConstraint($map, $code)); + + $this->assertSame($code, $this->mapHelper->renderStylesheet($map)); + } + + public function testRenderJavascript() + { + $map = $this->createMapMock(); + $code = 'code'; + + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with($this->identicalTo(MapEvents::JAVASCRIPT), $this->createMapEventCallbackConstraint($map, $code)); + + $this->assertSame($code, $this->mapHelper->renderJavascript($map)); + } + + public function testRender() + { + $map = $this->createMapMock(); + $code1 = 'code1'; + $code2 = 'code2'; + $code3 = 'code3'; + + $this->eventDispatcher + ->expects($this->exactly(3)) + ->method('dispatch') + ->withConsecutive( + array(MapEvents::STYLESHEET, $this->createMapEventCallbackConstraint($map, $code1)), + array(MapEvents::HTML, $this->createMapEventCallbackConstraint($map, $code2)), + array(MapEvents::JAVASCRIPT, $this->createMapEventCallbackConstraint($map, $code3)) + ); + + $this->assertSame($code1.$code2.$code3, $this->mapHelper->render($map)); + } + + /** + * Creates a map event callback constraint. + * + * @param \Ivory\GoogleMap\Map $map The map. + * @param string $code The code. + * + * @return \PHPUnit_Framework_Constraint_Callback The map event callback constraint. + */ + protected function createMapEventCallbackConstraint(Map $map, $code) + { + return $this->callback(function ($mapEvent) use ($map, $code) { + $result = $mapEvent instanceof MapEvent && $mapEvent->getMap() === $map; + + if ($result) { + $mapEvent->addCode($code); + } + + return $result; + }); + } +} diff --git a/tests/Helpers/PlacesAutocompleteEventTest.php b/tests/Helpers/PlacesAutocompleteEventTest.php new file mode 100644 index 00000000..916630a2 --- /dev/null +++ b/tests/Helpers/PlacesAutocompleteEventTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; + +/** + * Places autocomplete event test. + * + * @author GeLo + */ +class PlacesAutocompleteEventTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent */ + protected $placesAutocompleteEvent; + + /** @var \Ivory\GoogleMap\Places\Autocomplete|\PHPUnit_Framework_MockObject_MockObject */ + protected $autocomplete; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->placesAutocompleteEvent = new PlacesAutocompleteEvent($this->autocomplete = $this->createAutocompleteMock()); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->placesAutocompleteEvent); + } + + public function testInheritance() + { + $this->assertHelperEventInstance($this->placesAutocompleteEvent); + } + + public function testDefaultState() + { + $this->assertSame($this->autocomplete, $this->placesAutocompleteEvent->getAutocomplete()); + } +} diff --git a/tests/Helpers/PlacesAutocompleteEventsTest.php b/tests/Helpers/PlacesAutocompleteEventsTest.php new file mode 100644 index 00000000..13b3e967 --- /dev/null +++ b/tests/Helpers/PlacesAutocompleteEventsTest.php @@ -0,0 +1,63 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; + +/** + * Autocomplete events test. + * + * @author GeLo + */ +class PlacesAutocompleteEventsTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents'); + } + + public function testConstants() + { + $this->assertSame('ivory.google_map.places_autocomplete.html', PlacesAutocompleteEvents::HTML); + $this->assertSame('ivory.google_map.places_autocomplete.javascript', PlacesAutocompleteEvents::JAVASCRIPT); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.init', + PlacesAutocompleteEvents::JAVASCRIPT_INIT + ); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.init.container', + PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER + ); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.base', + PlacesAutocompleteEvents::JAVASCRIPT_BASE + ); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.base.coordinate', + PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE + ); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.base.bound', + PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND + ); + + $this->assertSame( + 'ivory.google_map.places_autocomplete.javascript.autocomplete', + PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE + ); + } +} diff --git a/tests/Helpers/PlacesAutocompleteHelperTest.php b/tests/Helpers/PlacesAutocompleteHelperTest.php new file mode 100644 index 00000000..2476404e --- /dev/null +++ b/tests/Helpers/PlacesAutocompleteHelperTest.php @@ -0,0 +1,128 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper; +use Ivory\GoogleMap\Places\Autocomplete; + +/** + * Autocomplete helper test. + * + * @author GeLo + */ +class PlacesAutocompleteHelperTest extends AbstractHelperTest +{ + /** @var \Ivory\GoogleMap\Helpers\PlacesAutocompleteHelper */ + protected $placesAutocompleteHelper; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->placesAutocompleteHelper = new PlacesAutocompleteHelper($this->eventDispatcher); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->placesAutocompleteHelper); + } + + public function testInheritance() + { + $this->assertHelperInstance($this->placesAutocompleteHelper); + } + + public function testRenderHtml() + { + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with( + $this->identicalTo(PlacesAutocompleteEvents::HTML), + $this->createAutocompleteEventCallbackConstraint( + $autocomplete = $this->createAutocompleteMock(), + $code = 'code' + ) + ); + + $this->assertSame($code, $this->placesAutocompleteHelper->renderHtml($autocomplete)); + } + + public function testRenderJavascript() + { + $this->eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with( + $this->identicalTo(PlacesAutocompleteEvents::JAVASCRIPT), + $this->createAutocompleteEventCallbackConstraint( + $autocomplete = $this->createAutocompleteMock(), + $code = 'code' + ) + ); + + $this->assertSame($code, $this->placesAutocompleteHelper->renderJavascript($autocomplete)); + } + + public function testRender() + { + $autocomplete = $this->createAutocompleteMock(); + + $this->eventDispatcher + ->expects($this->exactly(2)) + ->method('dispatch') + ->withConsecutive( + array( + PlacesAutocompleteEvents::HTML, + $this->createAutocompleteEventCallbackConstraint($autocomplete, $code1 = 'code1'), + ), + array( + PlacesAutocompleteEvents::JAVASCRIPT, + $this->createAutocompleteEventCallbackConstraint($autocomplete, $code2 = 'code2'), + ) + ); + + $this->assertSame($code1.$code2, $this->placesAutocompleteHelper->render($autocomplete)); + } + + /** + * Creates an autocomplete event callback constraint. + * + * @param \Ivory\GoogleMap\Places\Autocomplete $autocomplete The autocomplete. + * @param string $code The code. + * + * @return \PHPUnit_Framework_Constraint_Callback The autocomplete event callback constraint. + */ + protected function createAutocompleteEventCallbackConstraint(Autocomplete $autocomplete, $code) + { + return $this->callback(function ($autocompleteEvent) use ($autocomplete, $code) { + $result = $autocompleteEvent instanceof PlacesAutocompleteEvent + && $autocompleteEvent->getAutocomplete() === $autocomplete; + + if ($result) { + $autocompleteEvent->addCode($code); + } + + return $result; + }); + } +} diff --git a/tests/Helpers/Renderers/AbstractTestCase.php b/tests/Helpers/Renderers/AbstractTestCase.php new file mode 100644 index 00000000..948f2b55 --- /dev/null +++ b/tests/Helpers/Renderers/AbstractTestCase.php @@ -0,0 +1,196 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\Tests\GoogleMap\Helpers\AbstractTestCase as TestCase; + +/** + * Renderer test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts an animation renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer $animationRenderer The animation renderer. + */ + protected function assertAnimationRendererInstance($animationRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer', $animationRenderer); + } + + /** + * Asserts an encoding renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer $encodingRenderer The encoding renderer. + */ + protected function assertEncodingRendererInstance($encodingRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer', $encodingRenderer); + } + + /** + * Asserts a json renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer $jsonRenderer The json renderer. + */ + protected function assertJsonRendererInstance($jsonRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer', $jsonRenderer); + } + + /** + * Asserts a map type control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer $mapTypeControlRenderer The map type control renderer. + */ + protected function assertMapTypeControlRendererInstance($mapTypeControlRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer', + $mapTypeControlRenderer + ); + } + + /** + * Asserts a map type control style renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer $mapTypeControlStyleRenderer The map type control style renderer. + */ + protected function assertMapTypeControlStyleRendererInstance($mapTypeControlStyleRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer', + $mapTypeControlStyleRenderer + ); + } + + /** + * Asserts an overview map control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer $overviewMapControlRenderer The overview map control renderer. + */ + protected function assertOverviewMapControlRendererInstance($overviewMapControlRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer', + $overviewMapControlRenderer + ); + } + + /** + * Asserts a pan control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer $panControlRenderer The pan control renderer. + */ + protected function assertPanControlRendererInstance($panControlRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer', $panControlRenderer); + } + + /** + * Asserts a rotate control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer $rotateControlRenderer The rotate control renderer. + */ + protected function assertRotateControlRendererInstance($rotateControlRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer', + $rotateControlRenderer + ); + } + + /** + * Asserts a scale control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer $scaleControlRenderer The scale control renderer. + */ + protected function assertScaleControlRendererInstance($scaleControlRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer', + $scaleControlRenderer + ); + } + + /** + * Asserts a scale control style renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer $scaleControlStyleRenderer The scale control style renderer. + */ + protected function assertScaleControlStyleRendererInstance($scaleControlStyleRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer', + $scaleControlStyleRenderer + ); + } + + /** + * Asserts a street view control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer $streetViewControlRenderer The street view control renderer. + */ + protected function assertStreetViewControlRendererInstance($streetViewControlRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer', + $streetViewControlRenderer + ); + } + + /** + * Asserts a zoom control renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer $zoomControlRenderer The zoom control renderer. + */ + protected function assertZoomControlRendererInstance($zoomControlRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer', $zoomControlRenderer); + } + + /** + * Asserts a zoom control style renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer $zoomControlStyleRenderer The zoom control style renderer. + */ + protected function assertZoomControlStyleRendererInstance($zoomControlStyleRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer', + $zoomControlStyleRenderer + ); + } + + /** + * Creates a json renderer mock. + * + * @return \Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer|\PHPUnit_Framework_MockObject_MockObjectThe json renderer mock. + */ + protected function createJsonRendererMock() + { + return $this->createJsonRendererMockBuilder()->getMockForAbstractClass(); + } + + /** + * Creates a json renderer mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The json renderer mock builder. + */ + protected function createJsonRendererMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer'); + } +} diff --git a/tests/Helpers/Renderers/Base/BoundRendererTest.php b/tests/Helpers/Renderers/Base/BoundRendererTest.php new file mode 100644 index 00000000..c34c6856 --- /dev/null +++ b/tests/Helpers/Renderers/Base/BoundRendererTest.php @@ -0,0 +1,119 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Bound renderer test. + * + * @author GeLo + */ +class BoundRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer */ + protected $boundRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->boundRenderer = new BoundRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->boundRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Bound $bound) + { + $this->assertSame($expected, $this->boundRenderer->render($bound)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + $emptyBound = $this->createBoundMock(); + + $coordinateBound = $this->createBoundMock(); + + $coordinateBound + ->expects($this->any()) + ->method('hasCoordinates') + ->will($this->returnValue(true)); + + $coordinateBound + ->expects($this->any()) + ->method('getNorthEast') + ->will($this->returnValue($this->createCoordinateMock('north_east'))); + + $coordinateBound + ->expects($this->any()) + ->method('getSouthWest') + ->will($this->returnValue($this->createCoordinateMock('south_west'))); + + return array( + array('new google.maps.LatLngBounds()', $emptyBound), + array('new google.maps.LatLngBounds(south_west,north_east)', $coordinateBound), + ); + } + + /** + * Creates a bound mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject The bound mock. + */ + protected function createBoundMock($variable = 'bound') + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $bound; + } + + /** + * Creates a coordinate mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject The coordinate mock. + */ + protected function createCoordinateMock($variable = 'coordinate') + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $coordinate; + } +} diff --git a/tests/Helpers/Renderers/Base/CoordinateRendererTest.php b/tests/Helpers/Renderers/Base/CoordinateRendererTest.php new file mode 100644 index 00000000..6b11e0d9 --- /dev/null +++ b/tests/Helpers/Renderers/Base/CoordinateRendererTest.php @@ -0,0 +1,95 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Coordinate renderer test. + * + * @author GeLo + */ +class CoordinateRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer */ + protected $coordinateRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->coordinateRenderer = new CoordinateRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->coordinateRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Coordinate $coordinate) + { + $this->assertSame($expected, $this->coordinateRenderer->render($coordinate)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + $wrapCoordinate = $this->createCoordinateMock(false); + $noWrapCoordinate = $this->createCoordinateMock(true); + + return array( + array('new google.maps.LatLng(1.234,5.678,false)', $wrapCoordinate), + array('new google.maps.LatLng(1.234,5.678,true)', $noWrapCoordinate), + ); + } + + /** + * Creates a coordinate mock. + * + * @param boolean $noWrap The no wrap. + * + * @return \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject The coordinate mock. + */ + protected function createCoordinateMock($noWrap = true) + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getLatitude') + ->will($this->returnValue(1.234)); + + $coordinate + ->expects($this->any()) + ->method('getLongitude') + ->will($this->returnValue(5.678)); + + $coordinate + ->expects($this->any()) + ->method('isNoWrap') + ->will($this->returnValue($noWrap)); + + return $coordinate; + } +} diff --git a/tests/Helpers/Renderers/Base/PointRendererTest.php b/tests/Helpers/Renderers/Base/PointRendererTest.php new file mode 100644 index 00000000..1eed1b4e --- /dev/null +++ b/tests/Helpers/Renderers/Base/PointRendererTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Point renderer test. + * + * @author GeLo + */ +class PointRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer */ + protected $pointRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->pointRenderer = new PointRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->pointRenderer); + } + + public function testRender() + { + $this->assertSame( + 'new google.maps.Point(1.234,5.678)', + $this->pointRenderer->render($this->createPointMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createPointMock() + { + $point = parent::createPointMock(); + + $point + ->expects($this->any()) + ->method('getX') + ->will($this->returnValue(1.234)); + + $point + ->expects($this->any()) + ->method('getY') + ->will($this->returnValue(5.678)); + + return $point; + } +} diff --git a/tests/Helpers/Renderers/Base/SizeRendererTest.php b/tests/Helpers/Renderers/Base/SizeRendererTest.php new file mode 100644 index 00000000..c7772559 --- /dev/null +++ b/tests/Helpers/Renderers/Base/SizeRendererTest.php @@ -0,0 +1,120 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Base; + +use Ivory\GoogleMap\Base\Size; +use Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Size renderer test. + * + * @author GeLo + */ +class SizeRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer */ + protected $sizeRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->sizeRenderer = new SizeRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->sizeRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Size $size) + { + $this->assertSame($expected, $this->sizeRenderer->render($size)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + $emptySize = $this->createSizeMock(); + $widthUnitSize = $this->createSizeMock('px', null); + $heightUnitSize = $this->createSizeMock(null, 'px'); + $fullSize = $this->createSizeMock('px', 'pt'); + + return array( + array('new google.maps.Size(1.234,5.678,null,null)', $emptySize), + array('new google.maps.Size(1.234,5.678,"px",null)', $widthUnitSize), + array('new google.maps.Size(1.234,5.678,null,"px")', $heightUnitSize), + array('new google.maps.Size(1.234,5.678,"px","pt")', $fullSize), + ); + } + + /** + * Creates a size mock. + * + * @param string|null $widthUnit The width unit. + * @param string|null $heightUnit The height unit. + * + * @return \Ivory\GoogleMap\Base\Size|\PHPUnit_Framework_MockObject_MockObject The size mock. + */ + protected function createSizeMock($widthUnit = null, $heightUnit = null) + { + $size = parent::createSizeMock(); + + $size + ->expects($this->any()) + ->method('getWidth') + ->will($this->returnValue(1.234)); + + $size + ->expects($this->any()) + ->method('getHeight') + ->will($this->returnValue(5.678)); + + if ($widthUnit !== null) { + $size + ->expects($this->any()) + ->method('hasWidthUnit') + ->will($this->returnValue(true)); + + $size + ->expects($this->any()) + ->method('getWidthUnit') + ->will($this->returnValue($widthUnit)); + } + + if ($heightUnit !== null) { + $size + ->expects($this->any()) + ->method('hasHeightUnit') + ->will($this->returnValue(true)); + + $size + ->expects($this->any()) + ->method('getHeightUnit') + ->will($this->returnValue($heightUnit)); + } + + return $size; + } +} diff --git a/tests/Helpers/Renderers/Controls/ControlPositionRendererTest.php b/tests/Helpers/Renderers/Controls/ControlPositionRendererTest.php new file mode 100644 index 00000000..80491e46 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ControlPositionRendererTest.php @@ -0,0 +1,74 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Control position renderer test. + * + * @author GeLo + */ +class ControlPositionRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlPositionRenderer */ + protected $controlPositionRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->controlPositionRenderer = new ControlPositionRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->controlPositionRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, $controlPosition) + { + $this->assertSame($expected, $this->controlPositionRenderer->render($controlPosition)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.maps.ControlPosition.BOTTOM_CENTER', ControlPosition::BOTTOM_CENTER), + array('google.maps.ControlPosition.BOTTOM_LEFT', ControlPosition::BOTTOM_LEFT), + array('google.maps.ControlPosition.BOTTOM_RIGHT', ControlPosition::BOTTOM_RIGHT), + array('google.maps.ControlPosition.LEFT_BOTTOM', ControlPosition::LEFT_BOTTOM), + array('google.maps.ControlPosition.LEFT_CENTER', ControlPosition::LEFT_CENTER), + array('google.maps.ControlPosition.LEFT_TOP', ControlPosition::LEFT_TOP), + array('google.maps.ControlPosition.RIGHT_BOTTOM', ControlPosition::RIGHT_BOTTOM), + array('google.maps.ControlPosition.RIGHT_CENTER', ControlPosition::RIGHT_CENTER), + array('google.maps.ControlPosition.RIGHT_TOP', ControlPosition::RIGHT_TOP), + array('google.maps.ControlPosition.TOP_CENTER', ControlPosition::TOP_CENTER), + array('google.maps.ControlPosition.TOP_LEFT', ControlPosition::TOP_LEFT), + array('google.maps.ControlPosition.TOP_RIGHT', ControlPosition::TOP_RIGHT), + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/ControlsRendererTest.php b/tests/Helpers/Renderers/Controls/ControlsRendererTest.php new file mode 100644 index 00000000..a87f6f68 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ControlsRendererTest.php @@ -0,0 +1,512 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\MapTypeControl; +use Ivory\GoogleMap\Controls\OverviewMapControl; +use Ivory\GoogleMap\Controls\PanControl; +use Ivory\GoogleMap\Controls\RotateControl; +use Ivory\GoogleMap\Controls\ScaleControl; +use Ivory\GoogleMap\Controls\StreetViewControl; +use Ivory\GoogleMap\Controls\ZoomControl; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Controls renderer test. + * + * @author GeLo + */ +class ControlsRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ControlsRenderer */ + protected $controlsRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer */ + protected $mapTypeControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer */ + protected $overviewMapControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer */ + protected $panControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer */ + protected $rotateControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer */ + protected $scaleControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer */ + protected $streetViewControlRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer */ + protected $zoomControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->controlsRenderer = new ControlsRenderer( + $this->mapTypeControlRenderer = $this->createMapTypeControlRendererMock(), + $this->overviewMapControlRenderer = $this->createOverviewMapControlRendererMock(), + $this->panControlRenderer = $this->createPanControlRendererMock(), + $this->rotateControlRenderer = $this->createRotateControlRendererMock(), + $this->scaleControlRenderer = $this->createScaleControlRendererMock(), + $this->streetViewControlRenderer = $this->createStreetViewControlRendererMock(), + $this->zoomControlRenderer = $this->createZoomControlRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->controlsRenderer); + } + + public function testDefaultState() + { + $this->controlsRenderer = new ControlsRenderer(); + + $this->assertMapTypeControlRendererInstance($this->controlsRenderer->getMapTypeControlRenderer()); + $this->assertOverviewMapControlRendererInstance($this->controlsRenderer->getOverviewMapControlRenderer()); + $this->assertPanControlRendererInstance($this->controlsRenderer->getPanControlRenderer()); + $this->assertRotateControlRendererInstance($this->controlsRenderer->getRotateControlRenderer()); + $this->assertScaleControlRendererInstance($this->controlsRenderer->getScaleControlRenderer()); + $this->assertStreetViewControlRendererInstance($this->controlsRenderer->getStreetViewControlRenderer()); + $this->assertZoomControlRendererInstance($this->controlsRenderer->getZoomControlRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->mapTypeControlRenderer, $this->controlsRenderer->getMapTypeControlRenderer()); + $this->assertSame($this->overviewMapControlRenderer, $this->controlsRenderer->getOverviewMapControlRenderer()); + $this->assertSame($this->panControlRenderer, $this->controlsRenderer->getPanControlRenderer()); + $this->assertSame($this->rotateControlRenderer, $this->controlsRenderer->getRotateControlRenderer()); + $this->assertSame($this->scaleControlRenderer, $this->controlsRenderer->getScaleControlRenderer()); + $this->assertSame($this->streetViewControlRenderer, $this->controlsRenderer->getStreetViewControlRenderer()); + $this->assertSame($this->zoomControlRenderer, $this->controlsRenderer->getZoomControlRenderer()); + } + + public function testSetMapTypeControlRenderer() + { + $this->controlsRenderer->setMapTypeControlRenderer( + $mapTypeControlRenderer = $this->createMapTypeControlRendererMock() + ); + + $this->assertSame($mapTypeControlRenderer, $this->controlsRenderer->getMapTypeControlRenderer()); + } + + public function testSetOverviewMapControlRenderer() + { + $this->controlsRenderer->setOverviewMapControlRenderer( + $overviewMapControlRenderer = $this->createOverviewMapControlRendererMock() + ); + + $this->assertSame($overviewMapControlRenderer, $this->controlsRenderer->getOverviewMapControlRenderer()); + } + + public function testSetPanControlRenderer() + { + $this->controlsRenderer->setPanControlRenderer($panControlRenderer = $this->createPanControlRendererMock()); + + $this->assertSame($panControlRenderer, $this->controlsRenderer->getPanControlRenderer()); + } + + public function testSetRotateControlRenderer() + { + $this->controlsRenderer->setRotateControlRenderer( + $rotateControlRenderer = $this->createRotateControlRendererMock() + ); + + $this->assertSame($rotateControlRenderer, $this->controlsRenderer->getRotateControlRenderer()); + } + + public function testSetScaleControlRenderer() + { + $this->controlsRenderer->setScaleControlRenderer( + $scaleControlRenderer = $this->createScaleControlRendererMock() + ); + + $this->assertSame($scaleControlRenderer, $this->controlsRenderer->getScaleControlRenderer()); + } + + public function testSetStreetViewControlRenderer() + { + $this->controlsRenderer->setStreetViewControlRenderer( + $streetViewControlRenderer = $this->createStreetViewControlRendererMock() + ); + + $this->assertSame($streetViewControlRenderer, $this->controlsRenderer->getStreetViewControlRenderer()); + } + + public function testSetZoomControlRenderer() + { + $this->controlsRenderer->setZoomControlRenderer($zoomControlRenderer = $this->createZoomControlRendererMock()); + + $this->assertSame($zoomControlRenderer, $this->controlsRenderer->getZoomControlRenderer()); + } + + /** + * @dataProvider renderProvider + */ + public function testRender( + array $expected, + array $options = array(), + MapTypeControl $mapTypeControl = null, + OverviewMapControl $overviewMapControl = null, + PanControl $panControl = null, + RotateControl $rotateControl = null, + ScaleControl $scaleControl = null, + StreetViewControl $streetViewControl = null, + ZoomControl $zoomControl = null + ) { + $map = $this->createMapMock( + $options, + $mapTypeControl, + $overviewMapControl, + $panControl, + $rotateControl, + $scaleControl, + $streetViewControl, + $zoomControl + ); + + $jsonBuilder = $this->createJsonBuilderMock(); + $jsonBuilder + ->expects($this->exactly(count($expected))) + ->method('setValue') + ->will($this->returnValueMap($expected)); + + $this->controlsRenderer->render($map, $jsonBuilder); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + $mapTypeControl = $this->createMapTypeControlMock(); + $overviewMapControl = $this->createOverviewMapControlMock(); + $panControl = $this->createPanControlMock(); + $rotateControl = $this->createRotateControlMock(); + $scaleControl = $this->createScaleControlMock(); + $streetViewControl = $this->createStreetViewControlMock(); + $zoomControl = $this->createZoomControlMock(); + + return array( + array(array()), + array(array(array('[mapTypeControl]', true, true)), array('mapTypeControl' => true)), + array(array(array('[mapTypeControl]', false, true)), array('mapTypeControl' => false)), + array(array(array('[overviewMapControl]', true, true)), array('overviewMapControl' => true)), + array(array(array('[overviewMapControl]', false, true)), array('overviewMapControl' => false)), + array(array(array('[panControl]', true, true)), array('panControl' => true)), + array(array(array('[panControl]', false, true)), array('panControl' => false)), + array(array(array('[rotateControl]', true, true)), array('rotateControl' => true)), + array(array(array('[rotateControl]', false, true)), array('rotateControl' => false)), + array(array(array('[scaleControl]', true, true)), array('scaleControl' => true)), + array(array(array('[scaleControl]', false, true)), array('scaleControl' => false)), + array(array(array('[streetViewControl]', true, true)), array('streetViewControl' => true)), + array(array(array('[streetViewControl]', false, true)), array('streetViewControl' => false)), + array(array(array('[zoomControl]', true, true)), array('zoomControl' => true)), + array(array(array('[zoomControl]', false, true)), array('zoomControl' => false)), + array( + array( + array('[mapTypeControl]', true, true), + array('[overviewMapControl]', true, true), + array('[panControl]', true, true), + array('[rotateControl]', true, true), + array('[scaleControl]', true, true), + array('[streetViewControl]', true, true), + array('[zoomControl]', true, true), + ), + array( + 'mapTypeControl' => true, + 'overviewMapControl' => true, + 'panControl' => true, + 'rotateControl' => true, + 'scaleControl' => true, + 'streetViewControl' => true, + 'zoomControl' => true, + ), + ), + array( + array( + array('[mapTypeControl]', false, true), + array('[overviewMapControl]', false, true), + array('[panControl]', false, true), + array('[rotateControl]', false, true), + array('[scaleControl]', false, true), + array('[streetViewControl]', false, true), + array('[zoomControl]', false, true), + ), + array( + 'mapTypeControl' => false, + 'overviewMapControl' => false, + 'panControl' => false, + 'rotateControl' => false, + 'scaleControl' => false, + 'streetViewControl' => false, + 'zoomControl' => false, + ), + ), + array( + array( + array('[mapTypeControl]', true, true), + array('[mapTypeControlOptions]', 'map_type_control_options', true), + ), + array(), + $mapTypeControl, + ), + array( + array( + array('[overviewMapControl]', true, true), + array('[overviewMapControlOptions]', 'overview_map_control_options', true), + ), + array(), + null, + $overviewMapControl, + ), + array( + array( + array('[panControl]', true, true), + array('[panControlOptions]', 'pan_control_options', true), + ), + array(), + null, + null, + $panControl, + ), + array( + array( + array('[rotateControl]', true, true), + array('[rotateControlOptions]', 'rotate_control_options', true), + ), + array(), + null, + null, + null, + $rotateControl, + ), + array( + array( + array('[scaleControl]', true, true), + array('[scaleControlOptions]', 'scale_control_options', true), + ), + array(), + null, + null, + null, + null, + $scaleControl, + ), + array( + array( + array('[streetViewControl]', true, true), + array('[streetViewControlOptions]', 'street_view_control_options', true), + ), + array(), + null, + null, + null, + null, + null, + $streetViewControl, + ), + array( + array( + array('[zoomControl]', true, true), + array('[zoomControlOptions]', 'zoom_control_options', true), + ), + array(), + null, + null, + null, + null, + null, + null, + $zoomControl, + ), + ); + } + + /** + * Creates a controls mock. + * + * @param \Ivory\GoogleMap\Controls\MapTypeControl|null $mapTypeControl The map type control. + * @param \Ivory\GoogleMap\Controls\OverviewMapControl|null $overviewMapControl The overview map control. + * @param \Ivory\GoogleMap\Controls\PanControl|null $panControl The pan control. + * @param \Ivory\GoogleMap\Controls\RotateControl|null $rotateControl The rotate control. + * @param \Ivory\GoogleMap\Controls\ScaleControl|null $scaleControl The scale control. + * @param \Ivory\GoogleMap\Controls\StreetViewControl|null $streetViewControl The street view control. + * @param \Ivory\GoogleMap\Controls\ZoomControl|null $zoomControl The zoom control. + * + * @return \Ivory\GoogleMap\Controls\Controls|\PHPUnit_Framework_MockObject_MockObject The controls mock. + */ + protected function createControlsMock( + MapTypeControl $mapTypeControl = null, + OverviewMapControl $overviewMapControl = null, + PanControl $panControl = null, + RotateControl $rotateControl= null, + ScaleControl $scaleControl = null, + StreetViewControl $streetViewControl = null, + ZoomControl $zoomControl = null + ) { + $controls = parent::createControlsMock(); + + if ($mapTypeControl !== null) { + $controls + ->expects($this->any()) + ->method('hasMapTypeControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getMapTypeControl') + ->will($this->returnValue($mapTypeControl)); + } + + if ($overviewMapControl !== null) { + $controls + ->expects($this->any()) + ->method('hasOverviewMapControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getOverviewMapControl') + ->will($this->returnValue($overviewMapControl)); + } + + if ($panControl !== null) { + $controls + ->expects($this->any()) + ->method('hasPanControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getPanControl') + ->will($this->returnValue($panControl)); + } + + if ($rotateControl !== null) { + $controls + ->expects($this->any()) + ->method('hasRotateControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getRotateControl') + ->will($this->returnValue($rotateControl)); + } + + if ($scaleControl !== null) { + $controls + ->expects($this->any()) + ->method('hasScaleControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getScaleControl') + ->will($this->returnValue($scaleControl)); + } + + if ($streetViewControl !== null) { + $controls + ->expects($this->any()) + ->method('hasStreetViewControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getStreetViewControl') + ->will($this->returnValue($streetViewControl)); + } + + if ($zoomControl !== null) { + $controls + ->expects($this->any()) + ->method('hasZoomControl') + ->will($this->returnValue(true)); + + $controls + ->expects($this->any()) + ->method('getZoomControl') + ->will($this->returnValue($zoomControl)); + } + + return $controls; + } + + /** + * Creates a map mock. + * + * @param array $options The options. + * @param \Ivory\GoogleMap\Controls\MapTypeControl|null $mapTypeControl The map type control. + * @param \Ivory\GoogleMap\Controls\OverviewMapControl|null $overviewMapControl The overview map control. + * @param \Ivory\GoogleMap\Controls\PanControl|null $panControl The pan control. + * @param \Ivory\GoogleMap\Controls\RotateControl|null $rotateControl The rotate control. + * @param \Ivory\GoogleMap\Controls\ScaleControl|null $scaleControl The scale control. + * @param \Ivory\GoogleMap\Controls\StreetViewControl|null $streetViewControl The street view control. + * @param \Ivory\GoogleMap\Controls\ZoomControl|null $zoomControl The zoom control. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock( + array $options = array(), + MapTypeControl $mapTypeControl = null, + OverviewMapControl $overviewMapControl = null, + PanControl $panControl = null, + RotateControl $rotateControl= null, + ScaleControl $scaleControl = null, + StreetViewControl $streetViewControl = null, + ZoomControl $zoomControl = null + ){ + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getControls') + ->will($this->returnValue($this->createControlsMock( + $mapTypeControl, + $overviewMapControl, + $panControl, + $rotateControl, + $scaleControl, + $streetViewControl, + $zoomControl + ))); + + $map + ->expects($this->any()) + ->method('hasMapOption') + ->will($this->returnCallback(function ($name) use ($options) { + return isset($options[$name]); + })); + + $map + ->expects($this->any()) + ->method('getMapOption') + ->will($this->returnCallback(function ($name) use ($options) { + return $options[$name]; + })); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/Controls/MapTypeControlRendererTest.php b/tests/Helpers/Renderers/Controls/MapTypeControlRendererTest.php new file mode 100644 index 00000000..4360d8ad --- /dev/null +++ b/tests/Helpers/Renderers/Controls/MapTypeControlRendererTest.php @@ -0,0 +1,171 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Controls\MapTypeControl; +use Ivory\GoogleMap\Controls\MapTypeControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer; +use Ivory\GoogleMap\MapTypeId; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Map type control renderer test. + * + * @author GeLo + */ +class MapTypeControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlRenderer */ + protected $mapTypeControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapTypeControlRenderer = new MapTypeControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapTypeControlStyleRenderer); + unset($this->controlPositionRenderer); + unset($this->mapTypeIdRenderer); + unset($this->jsonBuilder); + unset($this->mapTypeControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->mapTypeControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->mapTypeControlRenderer->getJsonBuilder()); + $this->assertMapTypeIdRendererInstance($this->mapTypeControlRenderer->getMapTypeIdRenderer()); + $this->assertControlPositionRendererInstance($this->mapTypeControlRenderer->getControlPositionRenderer()); + + $this->assertMapTypeControlStyleRendererInstance( + $this->mapTypeControlRenderer->getMapTypeControlStyleRenderer() + ); + } + + public function testInitialState() + { + $this->mapTypeControlRenderer = new MapTypeControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $mapTypeIdRenderer = $this->createMapTypeIdRendererMock(), + $controlPositionRenderer = $this->createControlPositionRendererMock(), + $mapTypeControlStyleRenderer = $this->createMapTypeControlStyleRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->mapTypeControlRenderer->getJsonBuilder()); + $this->assertSame($mapTypeIdRenderer, $this->mapTypeControlRenderer->getMapTypeIdRenderer()); + $this->assertSame($controlPositionRenderer, $this->mapTypeControlRenderer->getControlPositionRenderer()); + + $this->assertSame( + $mapTypeControlStyleRenderer, + $this->mapTypeControlRenderer->getMapTypeControlStyleRenderer() + ); + } + + public function testSetMapTypeIdRenderer() + { + $this->mapTypeControlRenderer->setMapTypeIdRenderer($mapTypeIdRenderer = $this->createMapTypeIdRendererMock()); + + $this->assertSame($mapTypeIdRenderer, $this->mapTypeControlRenderer->getMapTypeIdRenderer()); + } + + public function testSetControlPositionRenderer() + { + $this->mapTypeControlRenderer->setControlPositionRenderer( + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($controlPositionRenderer, $this->mapTypeControlRenderer->getControlPositionRenderer()); + } + + public function testSetMapTypeControlStyleRenderer() + { + $this->mapTypeControlRenderer->setMapTypeControlStyleRenderer( + $mapTypeControlStyleRenderer = $this->createMapTypeControlStyleRendererMock() + ); + + $this->assertSame( + $mapTypeControlStyleRenderer, + $this->mapTypeControlRenderer->getMapTypeControlStyleRenderer() + ); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, MapTypeControl $mapTypeControl) + { + $this->assertSame($expected, $this->mapTypeControlRenderer->render($mapTypeControl)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + $emptyMapTypeControl = $this->createMapTypeControlMock(); + $fullMapTypeControl = $this->createMapTypeControlMock(array(MapTypeId::ROADMAP, MapTypeId::SATELLITE)); + + return array( + array( + '{"position":google.maps.ControlPosition.BOTTOM_CENTER,"style":google.maps.MapTypeControlStyle.DEFAULT}', + $emptyMapTypeControl, + ), + array( + '{"mapTypeIds":[google.maps.MapTypeId.ROADMAP,google.maps.MapTypeId.SATELLITE],"position":google.maps.ControlPosition.BOTTOM_CENTER,"style":google.maps.MapTypeControlStyle.DEFAULT}', + $fullMapTypeControl, + ), + ); + } + + /** + * Creates a map type control mock. + * + * @param array $mapTypeIds The map type ids. + * + * @return \Ivory\GoogleMap\Controls\MapTypeControl|\PHPUnit_Framework_MockObject_MockObject The map type control mock. + */ + protected function createMapTypeControlMock(array $mapTypeIds = array()) + { + $mapTypeControl = parent::createMapTypeControlMock(); + $mapTypeControl + ->expects($this->any()) + ->method('getMapTypeIds') + ->will($this->returnValue($mapTypeIds)); + + $mapTypeControl + ->expects($this->any()) + ->method('getControlPosition') + ->will($this->returnValue(ControlPosition::BOTTOM_CENTER)); + + $mapTypeControl + ->expects($this->any()) + ->method('getMapTypeControlStyle') + ->will($this->returnValue(MapTypeControlStyle::DEFAULT_)); + + return $mapTypeControl; + } +} diff --git a/tests/Helpers/Renderers/Controls/MapTypeControlStyleRendererTest.php b/tests/Helpers/Renderers/Controls/MapTypeControlStyleRendererTest.php new file mode 100644 index 00000000..ebb51928 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/MapTypeControlStyleRendererTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\MapTypeControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Map type control style renderer test. + * + * @author GeLo + */ +class MapTypeControlStyleRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\MapTypeControlStyleRenderer */ + protected $mapTypeControlStyleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapTypeControlStyleRenderer = new MapTypeControlStyleRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapTypeControlStyleRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, $mapTypeControlStyle) + { + $this->assertSame($expected, $this->mapTypeControlStyleRenderer->render($mapTypeControlStyle)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.maps.MapTypeControlStyle.DEFAULT', MapTypeControlStyle::DEFAULT_), + array('google.maps.MapTypeControlStyle.DROPDOWN_MENU', MapTypeControlStyle::DROPDOWN_MENU), + array('google.maps.MapTypeControlStyle.HORIZONTAL_BAR', MapTypeControlStyle::HORIZONTAL_BAR), + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/OverviewMapControlRendererTest.php b/tests/Helpers/Renderers/Controls/OverviewMapControlRendererTest.php new file mode 100644 index 00000000..048556ab --- /dev/null +++ b/tests/Helpers/Renderers/Controls/OverviewMapControlRendererTest.php @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\OverviewMapControl; +use Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Overview map control renderer test. + * + * @author GeLo + */ +class OverviewMapControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\OverviewMapControlRenderer */ + protected $overviewMapControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->overviewMapControlRenderer = new OverviewMapControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->overviewMapControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->overviewMapControlRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, OverviewMapControl $overviewMapControl) + { + $this->assertSame($expected, $this->overviewMapControlRenderer->render($overviewMapControl)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('{"opened":true}', $this->createOverviewMapControlMock()), + array('{"opened":false}', $this->createOverviewMapControlMock(false)), + ); + } + + protected function createOverviewMapControlMock($opened = true) + { + $overviewMapControl = parent::createOverviewMapControlMock(); + $overviewMapControl + ->expects($this->any()) + ->method('isOpened') + ->will($this->returnValue($opened)); + + return $overviewMapControl; + } +} diff --git a/tests/Helpers/Renderers/Controls/PanControlRendererTest.php b/tests/Helpers/Renderers/Controls/PanControlRendererTest.php new file mode 100644 index 00000000..33ad220e --- /dev/null +++ b/tests/Helpers/Renderers/Controls/PanControlRendererTest.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Pan control renderer test. + * + * @author GeLo + */ +class PanControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\PanControlRenderer */ + protected $panControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->panControlRenderer = new PanControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->panControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->panControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->panControlRenderer->getJsonBuilder()); + $this->assertControlPositionRendererInstance($this->panControlRenderer->getControlPositionRenderer()); + } + + public function testInitialState() + { + $this->panControlRenderer = new PanControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->panControlRenderer->getJsonBuilder()); + $this->assertSame($controlPositionRenderer, $this->panControlRenderer->getControlPositionRenderer()); + } + + public function testSetControlPositionRenderer() + { + $this->panControlRenderer->setControlPositionRenderer( + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($controlPositionRenderer, $this->panControlRenderer->getControlPositionRenderer()); + } + + public function testRender() + { + $panControl = $this->createPanControlMock(); + $panControl + ->expects($this->any()) + ->method('getControlPosition') + ->will($this->returnValue(ControlPosition::BOTTOM_CENTER)); + + $this->assertSame( + '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', + $this->panControlRenderer->render($panControl) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/RotateControlRendererTest.php b/tests/Helpers/Renderers/Controls/RotateControlRendererTest.php new file mode 100644 index 00000000..1431a9f5 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/RotateControlRendererTest.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Rotate control renderer test. + * + * @author GeLo + */ +class RotateControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\RotateControlRenderer */ + protected $rotateControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->rotateControlRenderer = new RotateControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->rotateControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->rotateControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->rotateControlRenderer->getJsonBuilder()); + $this->assertControlPositionRendererInstance($this->rotateControlRenderer->getControlPositionRenderer()); + } + + public function testInitialState() + { + $this->rotateControlRenderer = new RotateControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->rotateControlRenderer->getJsonBuilder()); + $this->assertSame($controlPositionRenderer, $this->rotateControlRenderer->getControlPositionRenderer()); + } + + public function testSetControlPositionRenderer() + { + $this->rotateControlRenderer->setControlPositionRenderer( + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($controlPositionRenderer, $this->rotateControlRenderer->getControlPositionRenderer()); + } + + public function testRender() + { + $rotateControl = $this->createRotateControlMock(); + $rotateControl + ->expects($this->any()) + ->method('getControlPosition') + ->will($this->returnValue(ControlPosition::BOTTOM_CENTER)); + + $this->assertSame( + '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', + $this->rotateControlRenderer->render($rotateControl) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/ScaleControlRendererTest.php b/tests/Helpers/Renderers/Controls/ScaleControlRendererTest.php new file mode 100644 index 00000000..9572f900 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ScaleControlRendererTest.php @@ -0,0 +1,89 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Controls\ScaleControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Scale control renderer test. + * + * @author GeLo + */ +class ScaleControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlRenderer */ + protected $scaleControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->scaleControlRenderer = new ScaleControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->scaleControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->scaleControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->scaleControlRenderer->getJsonBuilder()); + $this->assertScaleControlStyleRendererInstance($this->scaleControlRenderer->getScaleControlStyleRenderer()); + } + + public function testInitialState() + { + $this->scaleControlRenderer = new ScaleControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $scaleControlStyleRenderer = $this->createScaleControlStyleRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->scaleControlRenderer->getJsonBuilder()); + $this->assertSame($scaleControlStyleRenderer, $this->scaleControlRenderer->getScaleControlStyleRenderer()); + } + + public function testSetScaleControlStyleRenderer() + { + $this->scaleControlRenderer->setScaleControlStyleRenderer( + $scaleControlStyleRenderer = $this->createScaleControlStyleRendererMock() + ); + + $this->assertSame($scaleControlStyleRenderer, $this->scaleControlRenderer->getScaleControlStyleRenderer()); + } + + public function testRender() + { + $scaleControl = $this->createScaleControlMock(); + $scaleControl + ->expects($this->any()) + ->method('getScaleControlStyle') + ->will($this->returnValue(ScaleControlStyle::DEFAULT_)); + + $this->assertSame( + '{"style":google.maps.ScaleControlStyle.DEFAULT}', + $this->scaleControlRenderer->render($scaleControl) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/ScaleControlStyleRendererTest.php b/tests/Helpers/Renderers/Controls/ScaleControlStyleRendererTest.php new file mode 100644 index 00000000..ec2b6c4c --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ScaleControlStyleRendererTest.php @@ -0,0 +1,51 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ScaleControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Scale control style renderer test. + * + * @author GeLo + */ +class ScaleControlStyleRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ScaleControlStyleRenderer */ + protected $scaleControlStyleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->scaleControlStyleRenderer = new ScaleControlStyleRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->scaleControlStyleRenderer); + } + + public function testRender() + { + $this->assertSame( + 'google.maps.ScaleControlStyle.DEFAULT', + $this->scaleControlStyleRenderer->render(ScaleControlStyle::DEFAULT_) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/StreetViewControlRendererTest.php b/tests/Helpers/Renderers/Controls/StreetViewControlRendererTest.php new file mode 100644 index 00000000..d47de2eb --- /dev/null +++ b/tests/Helpers/Renderers/Controls/StreetViewControlRendererTest.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Street view control renderer test. + * + * @author GeLo + */ +class StreetViewControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\StreetViewControlRenderer */ + protected $streetViewControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->streetViewControlRenderer = new StreetViewControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->streetViewControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->streetViewControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->streetViewControlRenderer->getJsonBuilder()); + $this->assertControlPositionRendererInstance($this->streetViewControlRenderer->getControlPositionRenderer()); + } + + public function testInitialState() + { + $this->streetViewControlRenderer = new StreetViewControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->streetViewControlRenderer->getJsonBuilder()); + $this->assertSame($controlPositionRenderer, $this->streetViewControlRenderer->getControlPositionRenderer()); + } + + public function testSetControlPositionRenderer() + { + $this->streetViewControlRenderer->setControlPositionRenderer( + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($controlPositionRenderer, $this->streetViewControlRenderer->getControlPositionRenderer()); + } + + public function testRender() + { + $streetViewControl = $this->createStreetViewControlMock(); + $streetViewControl + ->expects($this->any()) + ->method('getControlPosition') + ->will($this->returnValue(ControlPosition::BOTTOM_CENTER)); + + $this->assertSame( + '{"position":google.maps.ControlPosition.BOTTOM_CENTER}', + $this->streetViewControlRenderer->render($streetViewControl) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/ZoomControlRendererTest.php b/tests/Helpers/Renderers/Controls/ZoomControlRendererTest.php new file mode 100644 index 00000000..2a855f83 --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ZoomControlRendererTest.php @@ -0,0 +1,106 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ControlPosition; +use Ivory\GoogleMap\Controls\ZoomControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Zoom control renderer test. + * + * @author GeLo + */ +class ZoomControlRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlRenderer */ + protected $zoomControlRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->zoomControlRenderer = new ZoomControlRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->zoomControlRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->zoomControlRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->zoomControlRenderer->getJsonBuilder()); + $this->assertControlPositionRendererInstance($this->zoomControlRenderer->getControlPositionRenderer()); + $this->assertZoomControlStyleRendererInstance($this->zoomControlRenderer->getZoomControlStyleRenderer()); + } + + public function testInitialState() + { + $this->zoomControlRenderer = new ZoomControlRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $controlPositionRenderer = $this->createControlPositionRendererMock(), + $zoomControlStyleRenderer = $this->createZoomControlStyleRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->zoomControlRenderer->getJsonBuilder()); + $this->assertSame($controlPositionRenderer, $this->zoomControlRenderer->getControlPositionRenderer()); + $this->assertSame($zoomControlStyleRenderer, $this->zoomControlRenderer->getZoomControlStyleRenderer()); + } + + public function testSetControlPositionRenderer() + { + $this->zoomControlRenderer->setControlPositionRenderer( + $controlPositionRenderer = $this->createControlPositionRendererMock() + ); + + $this->assertSame($controlPositionRenderer, $this->zoomControlRenderer->getControlPositionRenderer()); + } + + public function testSetZoomControlStyleRenderer() + { + $this->zoomControlRenderer->setZoomControlStyleRenderer( + $zoomControlStyleRenderer = $this->createZoomControlStyleRendererMock() + ); + + $this->assertSame($zoomControlStyleRenderer, $this->zoomControlRenderer->getZoomControlStyleRenderer()); + } + + public function testRender() + { + $zoomControl = $this->createZoomControlMock(); + $zoomControl + ->expects($this->any()) + ->method('getControlPosition') + ->will($this->returnValue(ControlPosition::BOTTOM_CENTER)); + + $zoomControl + ->expects($this->any()) + ->method('getZoomControlStyle') + ->will($this->returnValue(ZoomControlStyle::DEFAULT_)); + + $this->assertSame( + '{"position":google.maps.ControlPosition.BOTTOM_CENTER,"style":google.maps.ZoomControlStyle.DEFAULT}', + $this->zoomControlRenderer->render($zoomControl) + ); + } +} diff --git a/tests/Helpers/Renderers/Controls/ZoomControlStyleRendererTest.php b/tests/Helpers/Renderers/Controls/ZoomControlStyleRendererTest.php new file mode 100644 index 00000000..f049669b --- /dev/null +++ b/tests/Helpers/Renderers/Controls/ZoomControlStyleRendererTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Controls; + +use Ivory\GoogleMap\Controls\ZoomControlStyle; +use Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Zoom control style renderer test. + * + * @author GeLo + */ +class ZoomControlStyleRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Controls\ZoomControlStyleRenderer */ + protected $zoomControlStyleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->zoomControlStyleRenderer = new ZoomControlStyleRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->zoomControlStyleRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, $zoomControlStyle) + { + $this->assertSame($expected, $this->zoomControlStyleRenderer->render($zoomControlStyle)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.maps.ZoomControlStyle.DEFAULT', ZoomControlStyle::DEFAULT_), + array('google.maps.ZoomControlStyle.LARGE', ZoomControlStyle::LARGE), + array('google.maps.ZoomControlStyle.SMALL', ZoomControlStyle::SMALL), + ); + } +} diff --git a/tests/Helpers/Renderers/Events/DomEventOnceRendererTest.php b/tests/Helpers/Renderers/Events/DomEventOnceRendererTest.php new file mode 100644 index 00000000..e6104b1e --- /dev/null +++ b/tests/Helpers/Renderers/Events/DomEventOnceRendererTest.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\DomEvent; +use Ivory\GoogleMap\Events\MouseEvent; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Dom event once renderer test. + * + * @author GeLo + */ +class DomEventOnceRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer */ + protected $domEventOnceRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->domEventOnceRenderer = new DomEventOnceRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->domEventOnceRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, DomEvent $domEvent) + { + $this->assertSame($expected, $this->domEventOnceRenderer->render($domEvent)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array( + 'google.maps.event.addDomListenerOnce(instance,"click",handle,true)', + $this->createDomEventMock(), + ), + array( + 'google.maps.event.addDomListenerOnce(instance,"click",handle,false)', + $this->createDomEventMock(false), + ), + ); + } + + /** + * Creates a dom event mock. + * + * @param boolean $capture TRUE if it is captured else FALSE. + * + * @return \Ivory\GoogleMap\Events\DomEvent|\PHPUnit_Framework_MockObject_MockObject The dom event mock. + */ + protected function createDomEventMock($capture = true) + { + $domEvent = parent::createDomEventMock(); + $domEvent + ->expects($this->any()) + ->method('getInstance') + ->will($this->returnValue('instance')); + + $domEvent + ->expects($this->any()) + ->method('getEventName') + ->will($this->returnValue(MouseEvent::CLICK)); + + $domEvent + ->expects($this->any()) + ->method('getHandle') + ->will($this->returnValue('handle')); + + $domEvent + ->expects($this->any()) + ->method('isCapture') + ->will($this->returnValue($capture)); + + return $domEvent; + } +} diff --git a/tests/Helpers/Renderers/Events/DomEventRendererTest.php b/tests/Helpers/Renderers/Events/DomEventRendererTest.php new file mode 100644 index 00000000..018c008d --- /dev/null +++ b/tests/Helpers/Renderers/Events/DomEventRendererTest.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\DomEvent; +use Ivory\GoogleMap\Events\MouseEvent; +use Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Dom event renderer test. + * + * @author GeLo + */ +class DomEventRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer */ + protected $domEventRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->domEventRenderer = new DomEventRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->domEventRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, DomEvent $domEvent) + { + $this->assertSame($expected, $this->domEventRenderer->render($domEvent)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array( + 'google.maps.event.addDomListener(instance,"click",handle,true)', + $this->createDomEventMock(), + ), + array( + 'google.maps.event.addDomListener(instance,"click",handle,false)', + $this->createDomEventMock(false), + ), + ); + } + + /** + * Creates a dom event mock. + * + * @param boolean $capture TRUE if it is captured else FALSE. + * + * @return \Ivory\GoogleMap\Events\DomEvent|\PHPUnit_Framework_MockObject_MockObject The dom event mock. + */ + protected function createDomEventMock($capture = true) + { + $domEvent = parent::createDomEventMock(); + $domEvent + ->expects($this->any()) + ->method('getInstance') + ->will($this->returnValue('instance')); + + $domEvent + ->expects($this->any()) + ->method('getEventName') + ->will($this->returnValue(MouseEvent::CLICK)); + + $domEvent + ->expects($this->any()) + ->method('getHandle') + ->will($this->returnValue('handle')); + + $domEvent + ->expects($this->any()) + ->method('isCapture') + ->will($this->returnValue($capture)); + + return $domEvent; + } +} diff --git a/tests/Helpers/Renderers/Events/EventOnceRendererTest.php b/tests/Helpers/Renderers/Events/EventOnceRendererTest.php new file mode 100644 index 00000000..a789bf5d --- /dev/null +++ b/tests/Helpers/Renderers/Events/EventOnceRendererTest.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\MouseEvent; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Event once renderer test. + * + * @author GeLo + */ +class EventOnceRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer */ + protected $eventOnceRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventOnceRenderer = new EventOnceRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventOnceRenderer); + } + + public function testRender() + { + $this->assertSame( + 'google.maps.event.addListenerOnce(instance,"click",handle)', + $this->eventOnceRenderer->render($this->createEventMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createEventMock() + { + $event = parent::createEventMock(); + $event + ->expects($this->any()) + ->method('getInstance') + ->will($this->returnValue('instance')); + + $event + ->expects($this->any()) + ->method('getEventName') + ->will($this->returnValue(MouseEvent::CLICK)); + + $event + ->expects($this->any()) + ->method('getHandle') + ->will($this->returnValue('handle')); + + return $event; + } +} diff --git a/tests/Helpers/Renderers/Events/EventRendererTest.php b/tests/Helpers/Renderers/Events/EventRendererTest.php new file mode 100644 index 00000000..a699cb7d --- /dev/null +++ b/tests/Helpers/Renderers/Events/EventRendererTest.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Events; + +use Ivory\GoogleMap\Events\MouseEvent; +use Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Event once renderer test. + * + * @author GeLo + */ +class EventRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer */ + protected $eventRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventRenderer = new EventRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventRenderer); + } + + public function testRender() + { + $this->assertSame( + 'google.maps.event.addListener(instance,"click",handle)', + $this->eventRenderer->render($this->createEventMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createEventMock() + { + $event = parent::createEventMock(); + $event + ->expects($this->any()) + ->method('getInstance') + ->will($this->returnValue('instance')); + + $event + ->expects($this->any()) + ->method('getEventName') + ->will($this->returnValue(MouseEvent::CLICK)); + + $event + ->expects($this->any()) + ->method('getHandle') + ->will($this->returnValue('handle')); + + return $event; + } +} diff --git a/tests/Helpers/Renderers/Geometry/EncodingRendererTest.php b/tests/Helpers/Renderers/Geometry/EncodingRendererTest.php new file mode 100644 index 00000000..bee33df5 --- /dev/null +++ b/tests/Helpers/Renderers/Geometry/EncodingRendererTest.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Geometry; + +use Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Encoding renderer test. + * + * @author GeLo + */ +class EncodingRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Geometry\EncodingRenderer */ + protected $encodingRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->encodingRenderer = new EncodingRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->encodingRenderer); + } + + public function testRender() + { + $this->assertSame( + 'google.maps.geometry.encoding.decodePath("foo")', + $this->encodingRenderer->renderDecodePath('foo') + ); + } +} diff --git a/tests/Helpers/Renderers/JsonRendererTest.php b/tests/Helpers/Renderers/JsonRendererTest.php new file mode 100644 index 00000000..1e429322 --- /dev/null +++ b/tests/Helpers/Renderers/JsonRendererTest.php @@ -0,0 +1,60 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +/** + * Json renderer test. + * + * @author GeLo + */ +class JsonRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\AbstractJsonRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $jsonRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->jsonRenderer = $this->createJsonRendererMock(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->jsonRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->jsonRenderer->getJsonBuilder()); + } + + public function testInitialState() + { + $this->jsonRenderer = $this->createJsonRendererMockBuilder() + ->setConstructorArgs(array($jsonBuilder = $this->createJsonBuilderMock())) + ->getMockForAbstractClass(); + + $this->assertSame($jsonBuilder, $this->jsonRenderer->getJsonBuilder()); + } + + public function testSetJsonBuilder() + { + $this->jsonRenderer->setJsonBuilder($jsonBuilder = $this->createJsonBuilderMock()); + + $this->assertSame($jsonBuilder, $this->jsonRenderer->getJsonBuilder()); + } +} diff --git a/tests/Helpers/Renderers/Layers/KmlLayerRendererTest.php b/tests/Helpers/Renderers/Layers/KmlLayerRendererTest.php new file mode 100644 index 00000000..c788f55c --- /dev/null +++ b/tests/Helpers/Renderers/Layers/KmlLayerRendererTest.php @@ -0,0 +1,88 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Layers; + +use Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Kml layer renderer test. + * + * @author GeLo + */ +class KmlLayerRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer */ + protected $kmlLayerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->kmlLayerRenderer = new KmlLayerRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->kmlLayerRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->kmlLayerRenderer); + } + + public function testRender() + { + $this->assertSame( + 'new google.maps.KmlLayer("http://egeloen.fr",{"map":map,"foo":"bar"})', + $this->kmlLayerRenderer->render($this->createKmlLayerMock(), $this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createKmlLayerMock() + { + $kmlLayer = parent::createKmlLayerMock(); + $kmlLayer + ->expects($this->any()) + ->method('getUrl') + ->will($this->returnValue('http://egeloen.fr')); + + $kmlLayer + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $kmlLayer; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/LoaderRendererTest.php b/tests/Helpers/Renderers/LoaderRendererTest.php new file mode 100644 index 00000000..d121072f --- /dev/null +++ b/tests/Helpers/Renderers/LoaderRendererTest.php @@ -0,0 +1,85 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer; + +/** + * Loader renderer test. + * + * @author GeLo + */ +class LoaderRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer */ + protected $loaderRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->loaderRenderer = new LoaderRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->loaderRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, array $libraries = array(), $callback = null, $sensor = false) + { + $this->assertSame($expected, $this->loaderRenderer->render('fr', $libraries, $callback, $sensor)); + } + + public function testRenderSource() + { + $this->assertSame( + '//www.google.com/jsapi?callback=callback', + $this->loaderRenderer->renderSource('callback') + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.load("maps","3",{"other_params":"language=fr&sensor=false"})'), + array( + 'google.load("maps","3",{"other_params":"libraries=library&language=fr&sensor=false"})', + array('library'), + ), + array( + 'google.load("maps","3",{"other_params":"language=fr&sensor=false","callback":callback})', + array(), + 'callback', + ), + array('google.load("maps","3",{"other_params":"language=fr&sensor=true"})', array(), null, true), + array( + 'google.load("maps","3",{"other_params":"libraries=library&language=fr&sensor=true","callback":callback})', + array('library'), + 'callback', + true, + ), + ); + } +} diff --git a/tests/Helpers/Renderers/MapBoundRendererTest.php b/tests/Helpers/Renderers/MapBoundRendererTest.php new file mode 100644 index 00000000..07c7c8ad --- /dev/null +++ b/tests/Helpers/Renderers/MapBoundRendererTest.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer; + +/** + * Map bound renderer test. + * + * @author GeLo + */ +class MapBoundRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer */ + protected $mapBoundRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapBoundRenderer = new MapBoundRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapBoundRenderer); + } + + public function testRender() + { + $this->assertSame( + 'map.fitBounds(bound)', + $this->mapBoundRenderer->render($this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createBoundMock() + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('bound')); + + return $bound; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + $map + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($this->createBoundMock())); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/MapCenterRendererTest.php b/tests/Helpers/Renderers/MapCenterRendererTest.php new file mode 100644 index 00000000..1f90c8e9 --- /dev/null +++ b/tests/Helpers/Renderers/MapCenterRendererTest.php @@ -0,0 +1,82 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer; + +/** + * Map center renderer test. + * + * @author GeLo + */ +class MapCenterRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer */ + protected $mapCenterRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapCenterRenderer = new MapCenterRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapCenterRenderer); + } + + public function testRender() + { + $this->assertSame( + 'map.setCenter(coordinate)', + $this->mapCenterRenderer->render($this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createCoordinateMock() + { + $center = parent::createCoordinateMock(); + $center + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('coordinate')); + + return $center; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + $map + ->expects($this->any()) + ->method('getCenter') + ->will($this->returnValue($this->createCoordinateMock())); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/MapContainerRendererTest.php b/tests/Helpers/Renderers/MapContainerRendererTest.php new file mode 100644 index 00000000..cd529c63 --- /dev/null +++ b/tests/Helpers/Renderers/MapContainerRendererTest.php @@ -0,0 +1,87 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer; + +/** + * Map container renderer test. + * + * @author GeLo + */ +class MapContainerRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer */ + protected $mapContainerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapContainerRenderer = new MapContainerRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapContainerRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->mapContainerRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, array $functions = array()) + { + $this->assertSame( + $expected, + $this->mapContainerRenderer->render($functions) + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('{"base":{"coordinates":[],"bounds":[],"points":[],"sizes":[]},"map":null,"overlays":{"circles":[],"encoded_polylines":[],"ground_overlays":[],"polygons":[],"polylines":[],"rectangles":[],"info_windows":[],"info_boxes":[],"icons":[],"marker_shapes":[],"markers":[],"marker_cluster":null},"layers":{"kml_layers":[]},"events":{"dom_events":[],"dom_events_once":[],"events":[],"events_once":[]}}'), + array( + '{"base":{"coordinates":[],"bounds":[],"points":[],"sizes":[]},"map":null,"overlays":{"circles":[],"encoded_polylines":[],"ground_overlays":[],"polygons":[],"polylines":[],"rectangles":[],"info_windows":[],"info_boxes":[],"icons":[],"marker_shapes":[],"markers":[],"marker_cluster":null},"layers":{"kml_layers":[]},"events":{"dom_events":[],"dom_events_once":[],"events":[],"events_once":[]},"functions":{"foo":function(){return "foo";},"bar":function (){return "bar";}}}', + array('[foo]' => 'function(){return "foo";}', '[bar]' => 'function (){return "bar";}'), + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/MapRendererTest.php b/tests/Helpers/Renderers/MapRendererTest.php new file mode 100644 index 00000000..51678c9f --- /dev/null +++ b/tests/Helpers/Renderers/MapRendererTest.php @@ -0,0 +1,163 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\MapRenderer; + +/** + * Map renderer. + * + * @author GeLo + */ +class MapRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapRenderer */ + protected $mapRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapRenderer = new MapRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->mapRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->mapRenderer->getJsonBuilder()); + $this->assertMapTypeIdRendererInstance($this->mapRenderer->getMapTypeIdRenderer()); + $this->assertControlsRendererInstance($this->mapRenderer->getControlsRenderer()); + } + + public function testInitialState() + { + $this->mapRenderer = new MapRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $mapTypeIdRenderer = $this->createMapTypeIdRendererMock(), + $controlsRenderer = $this->createControlsRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->mapRenderer->getJsonBuilder()); + $this->assertSame($mapTypeIdRenderer, $this->mapRenderer->getMapTypeIdRenderer()); + $this->assertSame($controlsRenderer, $this->mapRenderer->getControlsRenderer()); + } + + public function testSetMapTypeIdRenderer() + { + $this->mapRenderer->setMapTypeIdRenderer($mapTypeIdRenderer = $this->createMapTypeIdRendererMock()); + + $this->assertSame($mapTypeIdRenderer, $this->mapRenderer->getMapTypeIdRenderer()); + } + + public function testSetControlsRenderer() + { + $this->mapRenderer->setControlsRenderer($controlsRenderer = $this->createControlsRendererMock()); + + $this->assertSame($controlsRenderer, $this->mapRenderer->getControlsRenderer()); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, array $options = array(), $autoZoom = false) + { + $this->assertSame($expected, $this->mapRenderer->render($this->createMapMock($options, $autoZoom))); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array( + 'new google.maps.Map(document.getElementById("id"),{"zoom":3,"mapTypeId":google.maps.MapTypeId.ROADMAP})', + ), + array( + 'new google.maps.Map(document.getElementById("id"),{"zoom":4,"mapTypeId":google.maps.MapTypeId.ROADMAP})', + array('zoom' => 4), + ), + array( + 'new google.maps.Map(document.getElementById("id"),{"mapTypeId":google.maps.MapTypeId.ROADMAP})', + array('zoom' => 4), + true, + ), + ); + } + + /** + * Creates a map mock. + * + * @param array $options The options. + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $options = array(), $autoZoom = false) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getHtmlContainerId') + ->will($this->returnValue('id')); + + $map + ->expects($this->any()) + ->method('getControls') + ->will($this->returnValue($this->createControlsMock())); + + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($autoZoom))); + + $map + ->expects($this->any()) + ->method('getMapOptions') + ->will($this->returnValue($options)); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock($autoZoom = false) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('isAutoZoom') + ->will($this->returnValue($autoZoom)); + + return $overlays; + } +} diff --git a/tests/Helpers/Renderers/MapTypeIdRendererTest.php b/tests/Helpers/Renderers/MapTypeIdRendererTest.php new file mode 100644 index 00000000..397e1bce --- /dev/null +++ b/tests/Helpers/Renderers/MapTypeIdRendererTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers; + +use Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer; +use Ivory\GoogleMap\MapTypeId; + +/** + * Map type id renderer test. + * + * @author GeLo + */ +class MapTypeIdRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapTypeIdRenderer */ + protected $mapTypeIdRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapTypeIdRenderer = new MapTypeIdRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapTypeIdRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, $mapTypeId) + { + $this->assertSame($expected, $this->mapTypeIdRenderer->render($mapTypeId)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.maps.MapTypeId.HYBRID', MapTypeId::HYBRID), + array('google.maps.MapTypeId.ROADMAP', MapTypeId::ROADMAP), + array('google.maps.MapTypeId.SATELLITE', MapTypeId::SATELLITE), + array('google.maps.MapTypeId.TERRAIN', MapTypeId::TERRAIN), + ); + } +} diff --git a/tests/Helpers/Renderers/Overlays/AnimationRendererTest.php b/tests/Helpers/Renderers/Overlays/AnimationRendererTest.php new file mode 100644 index 00000000..282319c7 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/AnimationRendererTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer; +use Ivory\GoogleMap\Overlays\Animation; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Animation renderer test. + * + * @author GeLo + */ +class AnimationRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\AnimationRenderer */ + protected $animationRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->animationRenderer = new AnimationRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->animationRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, $animation) + { + $this->assertSame($expected, $this->animationRenderer->render($animation)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('google.maps.Animation.BOUNCE', Animation::BOUNCE), + array('google.maps.Animation.DROP', Animation::DROP), + ); + } +} diff --git a/tests/Helpers/Renderers/Overlays/CircleRendererTest.php b/tests/Helpers/Renderers/Overlays/CircleRendererTest.php new file mode 100644 index 00000000..d017518f --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/CircleRendererTest.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Circle renderer test. + * + * @author GeLo + */ +class CircleRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer */ + protected $circleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->circleRenderer = new CircleRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->circleRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->circleRenderer); + } + + public function testRender() + { + $this->assertSame( + 'new google.maps.Circle({"map":map,"center":coordinate,"radius":1.234,"foo":"bar"})', + $this->circleRenderer->render($this->createCircleMock(), $this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createCircleMock() + { + $circle = parent::createCircleMock(); + $circle + ->expects($this->any()) + ->method('getCenter') + ->will($this->returnValue($this->createCoordinateMock())); + + $circle + ->expects($this->any()) + ->method('getRadius') + ->will($this->returnValue(1.234)); + + $circle + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $circle; + } + + /** + * {@inheritdoc} + */ + protected function createCoordinateMock() + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('coordinate')); + + return $coordinate; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/Overlays/EncodedPolylineRendererTest.php b/tests/Helpers/Renderers/Overlays/EncodedPolylineRendererTest.php new file mode 100644 index 00000000..497aa797 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/EncodedPolylineRendererTest.php @@ -0,0 +1,112 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Encoded polyline renderer test. + * + * @author GeLo + */ +class EncodedPolylineRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer */ + protected $encodedPolylineRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->encodedPolylineRenderer = new EncodedPolylineRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->encodedPolylineRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->encodedPolylineRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->encodedPolylineRenderer->getJsonBuilder()); + $this->assertEncodingRendererInstance($this->encodedPolylineRenderer->getEncodingRenderer()); + } + + public function testInitialState() + { + $this->encodedPolylineRenderer = new EncodedPolylineRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $encodingRenderer = $this->createEncodingRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->encodedPolylineRenderer->getJsonBuilder()); + $this->assertSame($encodingRenderer, $this->encodedPolylineRenderer->getEncodingRenderer()); + } + + public function testSetEncodingRenderer() + { + $this->encodedPolylineRenderer->setEncodingRenderer($encodingRenderer = $this->createEncodingRendererMock()); + + $this->assertSame($encodingRenderer, $this->encodedPolylineRenderer->getEncodingRenderer()); + } + + public function testRender() + { + $this->assertSame( + 'new google.maps.Polyline({"map":map,"path":google.maps.geometry.encoding.decodePath("value"),"foo":"bar"})', + $this->encodedPolylineRenderer->render($this->createEncodedPolylineMock(), $this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createEncodedPolylineMock() + { + $encodedPolyline = parent::createEncodedPolylineMock(); + $encodedPolyline + ->expects($this->any()) + ->method('getValue') + ->will($this->returnValue('value')); + + $encodedPolyline + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $encodedPolyline; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/Overlays/ExtendableRendererTest.php b/tests/Helpers/Renderers/Overlays/ExtendableRendererTest.php new file mode 100644 index 00000000..5a461f58 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/ExtendableRendererTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Extendable renderer test. + * + * @author GeLo + */ +class ExtendableRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer */ + protected $extendableRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->extendableRenderer = new ExtendableRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->extendableRenderer); + } + + public function testRender() + { + $extend = $this->createExtendableMock(); + $extend + ->expects($this->any()) + ->method('renderExtend') + ->with($this->identicalTo($bound = $this->createBoundMock())) + ->will($this->returnValue($render = 'render')); + + $this->assertSame($render, $this->extendableRenderer->render($extend, $bound)); + } +} diff --git a/tests/Helpers/Renderers/Overlays/GroundOverlayRendererTest.php b/tests/Helpers/Renderers/Overlays/GroundOverlayRendererTest.php new file mode 100644 index 00000000..3e824d27 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/GroundOverlayRendererTest.php @@ -0,0 +1,107 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Ground overlay renderer test. + * + * @author GeLo + */ +class GroundOverlayRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer */ + protected $groundOverlayRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->groundOverlayRenderer = new GroundOverlayRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->groundOverlayRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->groundOverlayRenderer); + } + + public function testRender() + { + $this->assertSame( + 'new google.maps.GroundOverlay("http://egeloen.fr",bound,{"map":map,"foo":"bar"})', + $this->groundOverlayRenderer->render($this->createGroundOverlayMock(), $this->createMapMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createGroundOverlayMock() + { + $groundOverlay = parent::createGroundOverlayMock(); + $groundOverlay + ->expects($this->any()) + ->method('getUrl') + ->will($this->returnValue('http://egeloen.fr')); + + $groundOverlay + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($this->createBoundMock())); + + $groundOverlay + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $groundOverlay; + } + + /** + * {@inheritdoc} + */ + protected function createBoundMock() + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('bound')); + + return $bound; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } +} diff --git a/tests/Helpers/Renderers/Overlays/IconRendererTest.php b/tests/Helpers/Renderers/Overlays/IconRendererTest.php new file mode 100644 index 00000000..6e6ad1b1 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/IconRendererTest.php @@ -0,0 +1,192 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Base\Point; +use Ivory\GoogleMap\Base\Size; +use Ivory\GoogleMap\Overlays\Icon; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Icon renderer test. + * + * @author GeLo + */ +class IconRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer */ + protected $iconRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->iconRenderer = new IconRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->iconRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Icon $icon) + { + $this->assertSame($expected, $this->iconRenderer->render($icon)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('{"url":"http:\/\/egeloen.fr"}', $this->createIconMock()), + array('{"url":"http:\/\/egeloen.fr","size":size}', $this->createIconMock($this->createSizeMock())), + array( + '{"url":"http:\/\/egeloen.fr","origin":origin}', + $this->createIconMock(null, $this->createPointMock('origin')), + ), + array( + '{"url":"http:\/\/egeloen.fr","anchor":anchor}', + $this->createIconMock(null, null, $this->createPointMock('anchor')), + ), + array( + '{"url":"http:\/\/egeloen.fr","scaledSize":scaled_size}', + $this->createIconMock(null, null, null, $this->createSizeMock('scaled_size')), + ), + array( + '{"url":"http:\/\/egeloen.fr","size":size,"origin":origin,"anchor":anchor,"scaledSize":scaled_size}', + $this->createIconMock( + $this->createSizeMock(), + $this->createPointMock('origin'), + $this->createPointMock('anchor'), + $this->createSizeMock('scaled_size') + ), + ), + ); + } + + /** + * Creates an icon mock. + * + * @param \Ivory\GoogleMap\Base\Size|null $size The size. + * @param \Ivory\GoogleMap\Base\Point|null $origin The origin. + * @param \Ivory\GoogleMap\Base\Point|null $anchor The anchor. + * @param \Ivory\GoogleMap\Base\Size|null $scaledSize The scaled size. + * + * @return \Ivory\GoogleMap\Overlays\Icon|\PHPUnit_Framework_MockObject_MockObject The icon mock. + */ + protected function createIconMock(Size $size = null, Point $origin = null, Point $anchor = null, Size $scaledSize = null) + { + $icon = parent::createIconMock(); + $icon + ->expects($this->any()) + ->method('getUrl') + ->will($this->returnValue('http://egeloen.fr')); + + if ($size !== null) { + $icon + ->expects($this->any()) + ->method('hasSize') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getSize') + ->will($this->returnValue($size)); + } + + if ($origin !== null) { + $icon + ->expects($this->any()) + ->method('hasOrigin') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getOrigin') + ->will($this->returnValue($origin)); + } + + if ($anchor !== null) { + $icon + ->expects($this->any()) + ->method('hasAnchor') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getAnchor') + ->will($this->returnValue($anchor)); + } + + if ($scaledSize !== null) { + $icon + ->expects($this->any()) + ->method('hasScaledSize') + ->will($this->returnValue(true)); + + $icon + ->expects($this->any()) + ->method('getScaledSize') + ->will($this->returnValue($scaledSize)); + } + + return $icon; + } + + /** + * Creates a point mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Point|\PHPUnit_Framework_MockObject_MockObject The point mock. + */ + protected function createPointMock($variable = 'point') + { + $point = parent::createPointMock(); + $point + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $point; + } + + /** + * Creates a size mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Size|\PHPUnit_Framework_MockObject_MockObject The size mock. + */ + protected function createSizeMock($variable = 'size') + { + $size = parent::createSizeMock(); + $size + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $size; + } +} diff --git a/tests/Helpers/Renderers/Overlays/InfoBoxRendererTest.php b/tests/Helpers/Renderers/Overlays/InfoBoxRendererTest.php new file mode 100644 index 00000000..ead3860b --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/InfoBoxRendererTest.php @@ -0,0 +1,173 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Base\Size; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer; +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Info box renderer test. + * + * @author GeLo + */ +class InfoBoxRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer */ + protected $infoBoxRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->infoBoxRenderer = new InfoBoxRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->infoBoxRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, InfoWindow $infoWindow) + { + $this->assertSame($expected, $this->infoBoxRenderer->render($infoWindow)); + } + + public function testRenderSource() + { + $this->assertSame( + '//google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox_packed.js', + $this->infoBoxRenderer->renderSource() + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('new InfoBox({"content":"content"})', $this->createInfoWindowMock()), + array( + 'new InfoBox({"position":coordinate,"content":"content"})', + $this->createInfoWindowMock($this->createCoordinateMock()), + ), + array( + 'new InfoBox({"pixelOffset":size,"content":"content"})', + $this->createInfoWindowMock(null, $this->createSizeMock()), + ), + array( + 'new InfoBox({"position":coordinate,"pixelOffset":size,"content":"content"})', + $this->createInfoWindowMock($this->createCoordinateMock(), $this->createSizeMock()), + ), + array( + 'new InfoBox({"position":coordinate,"pixelOffset":size,"content":"content","foo":"bar"})', + $this->createInfoWindowMock( + $this->createCoordinateMock(), + $this->createSizeMock(), + array('foo' => 'bar') + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function createCoordinateMock() + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('coordinate')); + + return $coordinate; + } + + /** + * Creates an info window mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. + * @param \Ivory\GoogleMap\Base\Size|null $pixelOffset The pixel offset. + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock( + Coordinate $position = null, + Size $pixelOffset = null, + array $options = array() + ) { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getContent') + ->will($this->returnValue('content')); + + $infoWindow + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + if ($position !== null) { + $infoWindow + ->expects($this->any()) + ->method('hasPosition') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue($position)); + } + + if ($pixelOffset !== null) { + $infoWindow + ->expects($this->any()) + ->method('hasPixelOffset') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPixelOffset') + ->will($this->returnValue($pixelOffset)); + } + + return $infoWindow; + } + + /** + * {@inheritdoc} + */ + protected function createSizeMock() + { + $size = parent::createSizeMock(); + $size + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('size')); + + return $size; + } +} diff --git a/tests/Helpers/Renderers/Overlays/InfoWindowCloseRendererTest.php b/tests/Helpers/Renderers/Overlays/InfoWindowCloseRendererTest.php new file mode 100644 index 00000000..be1e1943 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/InfoWindowCloseRendererTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Info window close renderer test. + * + * @author GeLo + */ +class InfoWindowCloseRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer */ + protected $infoWindowCloseRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->infoWindowCloseRenderer = new InfoWindowCloseRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->infoWindowCloseRenderer); + } + + public function testRender() + { + $this->assertSame( + 'info_window.close()', + $this->infoWindowCloseRenderer->render($this->createInfoWindowMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createInfoWindowMock() + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('info_window')); + + return $infoWindow; + } +} diff --git a/tests/Helpers/Renderers/Overlays/InfoWindowOpenRendererTest.php b/tests/Helpers/Renderers/Overlays/InfoWindowOpenRendererTest.php new file mode 100644 index 00000000..0205440c --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/InfoWindowOpenRendererTest.php @@ -0,0 +1,109 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer; +use Ivory\GoogleMap\Overlays\Marker; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Info window open renderer test. + * + * @author GeLo + */ +class InfoWindowOpenRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer */ + protected $infoWindowOpenRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->infoWindowOpenRenderer = new InfoWindowOpenRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->infoWindowOpenRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Marker $marker = null) + { + $this->assertSame( + $expected, + $this->infoWindowOpenRenderer->render($this->createInfoWindowMock(), $this->createMapMock(), $marker) + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('info_window.open(map)'), + array('info_window.open(map,marker)', $this->createMarkerMock()), + ); + } + + /** + * {@inheritdoc} + */ + protected function createInfoWindowMock() + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('info_window')); + + return $infoWindow; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * {@inheritdoc} + */ + protected function createMarkerMock() + { + $marker = parent::createMarkerMock(); + $marker + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('marker')); + + return $marker; + } +} diff --git a/tests/Helpers/Renderers/Overlays/InfoWindowRendererTest.php b/tests/Helpers/Renderers/Overlays/InfoWindowRendererTest.php new file mode 100644 index 00000000..4dbd3c6e --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/InfoWindowRendererTest.php @@ -0,0 +1,165 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Base\Coordinate; +use Ivory\GoogleMap\Base\Size; +use Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer; +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Info window renderer test. + * + * @author GeLo + */ +class InfoWindowRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer */ + protected $infoWindowRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->infoWindowRenderer = new InfoWindowRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->infoWindowRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, InfoWindow $infoWindow) + { + $this->assertSame($expected, $this->infoWindowRenderer->render($infoWindow)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('new google.maps.InfoWindow({"content":"content"})', $this->createInfoWindowMock()), + array( + 'new google.maps.InfoWindow({"position":coordinate,"content":"content"})', + $this->createInfoWindowMock($this->createCoordinateMock()), + ), + array( + 'new google.maps.InfoWindow({"pixelOffset":size,"content":"content"})', + $this->createInfoWindowMock(null, $this->createSizeMock()), + ), + array( + 'new google.maps.InfoWindow({"position":coordinate,"pixelOffset":size,"content":"content"})', + $this->createInfoWindowMock($this->createCoordinateMock(), $this->createSizeMock()), + ), + array( + 'new google.maps.InfoWindow({"position":coordinate,"pixelOffset":size,"content":"content","foo":"bar"})', + $this->createInfoWindowMock( + $this->createCoordinateMock(), + $this->createSizeMock(), + array('foo' => 'bar') + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function createCoordinateMock() + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('coordinate')); + + return $coordinate; + } + + /** + * Creates an info window mock. + * + * @param \Ivory\GoogleMap\Base\Coordinate|null $position The position. + * @param \Ivory\GoogleMap\Base\Size|null $pixelOffset The pixel offset. + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock( + Coordinate $position = null, + Size $pixelOffset = null, + array $options = array() + ) { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getContent') + ->will($this->returnValue('content')); + + $infoWindow + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + if ($position !== null) { + $infoWindow + ->expects($this->any()) + ->method('hasPosition') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue($position)); + } + + if ($pixelOffset !== null) { + $infoWindow + ->expects($this->any()) + ->method('hasPixelOffset') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getPixelOffset') + ->will($this->returnValue($pixelOffset)); + } + + return $infoWindow; + } + + /** + * {@inheritdoc} + */ + protected function createSizeMock() + { + $size = parent::createSizeMock(); + $size + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('size')); + + return $size; + } +} diff --git a/tests/Helpers/Renderers/Overlays/MarkerClusterRendererTest.php b/tests/Helpers/Renderers/Overlays/MarkerClusterRendererTest.php new file mode 100644 index 00000000..8ac373ed --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/MarkerClusterRendererTest.php @@ -0,0 +1,94 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Marker cluster renderer test. + * + * @author GeLo + */ +class MarkerClusterRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer */ + protected $markerClusterRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->markerClusterRenderer = new MarkerClusterRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerClusterRenderer); + } + + public function testRender() + { + $map = $this->createMapMock(); + $markerCluster = $this->createMarkerClusterMock(); + + $this->assertSame( + 'new MarkerClusterer(map,markers,{"foo":"bar"})', + $this->markerClusterRenderer->render($markerCluster, $map, 'markers') + ); + } + + public function testRenderSource() + { + $this->assertSame( + '//google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer_compiled.js', + $this->markerClusterRenderer->renderSource() + ); + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * {@inheritdoc} + */ + protected function createMarkerClusterMock() + { + $markerCluster = parent::createMarkerClusterMock(); + $markerCluster + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('marker_cluster')); + + $markerCluster + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $markerCluster; + } +} diff --git a/tests/Helpers/Renderers/Overlays/MarkerRendererTest.php b/tests/Helpers/Renderers/Overlays/MarkerRendererTest.php new file mode 100644 index 00000000..305e59a3 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/MarkerRendererTest.php @@ -0,0 +1,271 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer; +use Ivory\GoogleMap\Map; +use Ivory\GoogleMap\Overlays\Animation; +use Ivory\GoogleMap\Overlays\Icon; +use Ivory\GoogleMap\Overlays\Marker; +use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Marker renderer test. + * + * @author GeLo + */ +class MarkerRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer */ + protected $markerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->markerRenderer = new MarkerRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->markerRenderer); + } + + public function testDefaultState() + { + $this->assertJsonBuilderInstance($this->markerRenderer->getJsonBuilder()); + $this->assertAnimationRendererInstance($this->markerRenderer->getAnimationRenderer()); + } + + public function testInitialState() + { + $this->markerRenderer = new MarkerRenderer( + $jsonBuilder = $this->createJsonBuilderMock(), + $animationRenderer = $this->createAnimationRendererMock() + ); + + $this->assertSame($jsonBuilder, $this->markerRenderer->getJsonBuilder()); + $this->assertSame($animationRenderer, $this->markerRenderer->getAnimationRenderer()); + } + + public function testSetAnimationRenderer() + { + $this->markerRenderer->setAnimationRenderer($animationRenderer = $this->createAnimationRendererMock()); + + $this->assertSame($animationRenderer, $this->markerRenderer->getAnimationRenderer()); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Marker $marker, Map $map = null) + { + $this->assertSame($expected, $this->markerRenderer->render($marker, $map)); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('new google.maps.Marker({"position":coordinate})', $this->createMarkerMock()), + array( + 'new google.maps.Marker({"position":coordinate,"map":map})', + $this->createMarkerMock(), + $this->createMapMock(), + ), + array( + 'new google.maps.Marker({"position":coordinate,"animation":google.maps.Animation.BOUNCE})', + $this->createMarkerMock(Animation::BOUNCE), + ), + array( + 'new google.maps.Marker({"position":coordinate,"icon":icon})', + $this->createMarkerMock(null, $this->createIconMock()), + ), + array( + 'new google.maps.Marker({"position":coordinate,"shadow":shadow})', + $this->createMarkerMock(null, null, $this->createIconMock('shadow')), + ), + array( + 'new google.maps.Marker({"position":coordinate,"shape":marker_shape})', + $this->createMarkerMock(null, null, null, $this->createMarkerShapeMock()), + ), + array( + 'new google.maps.Marker({"position":coordinate,"foo":"bar"})', + $this->createMarkerMock(null, null, null, null, array('foo' => 'bar')), + ), + array( + 'new google.maps.Marker({"position":coordinate,"animation":google.maps.Animation.BOUNCE,"icon":icon,"shadow":shadow,"shape":marker_shape,"foo":"bar"})', + $this->createMarkerMock( + Animation::BOUNCE, + $this->createIconMock(), + $this->createIconMock('shadow'), + $this->createMarkerShapeMock(), + array('foo' => 'bar') + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function createCoordinateMock() + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('coordinate')); + + return $coordinate; + } + + /** + * Creates an icon mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Overlays\Icon|\PHPUnit_Framework_MockObject_MockObject The icon mock. + */ + protected function createIconMock($variable = 'icon') + { + $icon = parent::createIconMock(); + $icon + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $icon; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * Creates a marker mock. + * + * @param string|null $animation The animation. + * @param \Ivory\GoogleMap\Overlays\Icon|null $icon The icon. + * @param \Ivory\GoogleMap\Overlays\Icon|null $shadow The shadow. + * @param \Ivory\GoogleMap\Overlays\MarkerShape|null $markerShape The marker shape. + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock( + $animation = null, + Icon $icon = null, + Icon $shadow = null, + MarkerShape $markerShape = null, + array $options = array() + ) { + $marker = parent::createMarkerMock(); + $marker + ->expects($this->any()) + ->method('getPosition') + ->will($this->returnValue($this->createCoordinateMock())); + + if ($animation !== null) { + $marker + ->expects($this->any()) + ->method('hasAnimation') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getAnimation') + ->will($this->returnValue($animation)); + } + + if ($icon !== null) { + $marker + ->expects($this->any()) + ->method('hasIcon') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getIcon') + ->will($this->returnValue($icon)); + } + + if ($shadow !== null) { + $marker + ->expects($this->any()) + ->method('hasShadow') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getShadow') + ->will($this->returnValue($shadow)); + } + + if ($markerShape !== null) { + $marker + ->expects($this->any()) + ->method('hasShape') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getShape') + ->will($this->returnValue($markerShape)); + } + + $marker + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + return $marker; + } + + /** + * {@inheritdoc} + */ + protected function createMarkerShapeMock() + { + $markerShape = parent::createMarkerShapeMock(); + $markerShape + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('marker_shape')); + + return $markerShape; + } +} diff --git a/tests/Helpers/Renderers/Overlays/MarkerShapeRendererTest.php b/tests/Helpers/Renderers/Overlays/MarkerShapeRendererTest.php new file mode 100644 index 00000000..887fe46d --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/MarkerShapeRendererTest.php @@ -0,0 +1,75 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer; +use Ivory\GoogleMap\Overlays\MarkerShapeType; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Marker shape renderer test. + * + * @author GeLo + */ +class MarkerShapeRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer */ + protected $markerShapeRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->markerShapeRenderer = new MarkerShapeRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->markerShapeRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->markerShapeRenderer); + } + + public function testRender() + { + $this->assertSame( + '{"type":"circle","coords":[1.2,3.4,4.5]}', + $this->markerShapeRenderer->render($this->createMarkerShapeMock()) + ); + } + + /** + * {@inheritdoc} + */ + protected function createMarkerShapeMock() + { + $markerShape = parent::createMarkerShapeMock(); + $markerShape + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue(MarkerShapeType::CIRCLE)); + + $markerShape + ->expects($this->any()) + ->method('getCoordinates') + ->will($this->returnValue(array(1.2, 3.4, 4.5))); + + return $markerShape; + } +} diff --git a/tests/Helpers/Renderers/Overlays/PolygonRendererTest.php b/tests/Helpers/Renderers/Overlays/PolygonRendererTest.php new file mode 100644 index 00000000..974bfb11 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/PolygonRendererTest.php @@ -0,0 +1,137 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer; +use Ivory\GoogleMap\Overlays\Polygon; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Polygon renderer test. + * + * @author GeLo + */ +class PolygonRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer */ + protected $polygonRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->polygonRenderer = new PolygonRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->polygonRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->polygonRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Polygon $polygon) + { + $this->assertSame( + $expected, + $this->polygonRenderer->render($polygon, $this->createMapMock()) + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array( + 'new google.maps.Polygon({"map":map,"paths":[coordinate1,coordinate2]})', + $this->createPolygonMock(array( + $this->createCoordinateMock('coordinate1'), + $this->createCoordinateMock('coordinate2') + )), + ), + array( + 'new google.maps.Polygon({"map":map,"paths":[coordinate],"foo":"bar"})', + $this->createPolygonMock(array($this->createCoordinateMock()), array('foo' => 'bar')), + ), + ); + } + + /** + * Creates a coordinate mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject The coordinate mock. + */ + protected function createCoordinateMock($variable = 'coordinate') + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $coordinate; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * Creates a polygon mock. + * + * @param array $coordinates The coordinates. + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\Polygon|\PHPUnit_Framework_MockObject_MockObject The polygon mock. + */ + protected function createPolygonMock(array $coordinates = array(), array $options = array()) + { + $polygon = parent::createPolygonMock(); + $polygon + ->expects($this->any()) + ->method('getCoordinates') + ->will($this->returnValue($coordinates)); + + $polygon + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + return $polygon; + } +} diff --git a/tests/Helpers/Renderers/Overlays/PolylineRendererTest.php b/tests/Helpers/Renderers/Overlays/PolylineRendererTest.php new file mode 100644 index 00000000..78db0940 --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/PolylineRendererTest.php @@ -0,0 +1,137 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer; +use Ivory\GoogleMap\Overlays\Polyline; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Polyline renderer test. + * + * @author GeLo + */ +class PolylineRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer */ + protected $polylineRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->polylineRenderer = new PolylineRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->polylineRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->polylineRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Polyline $polyline) + { + $this->assertSame( + $expected, + $this->polylineRenderer->render($polyline, $this->createMapMock()) + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array( + 'new google.maps.Polyline({"map":map,"path":[coordinate1,coordinate2]})', + $this->createPolylineMock(array( + $this->createCoordinateMock('coordinate1'), + $this->createCoordinateMock('coordinate2') + )), + ), + array( + 'new google.maps.Polyline({"map":map,"path":[coordinate],"foo":"bar"})', + $this->createPolylineMock(array($this->createCoordinateMock()), array('foo' => 'bar')), + ), + ); + } + + /** + * Creates a coordinate mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject The coordinate mock. + */ + protected function createCoordinateMock($variable = 'coordinate') + { + $coordinate = parent::createCoordinateMock(); + $coordinate + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $coordinate; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * Creates a polyline mock. + * + * @param array $coordinates The coordinates. + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\Polyline|\PHPUnit_Framework_MockObject_MockObject The polyline mock. + */ + protected function createPolylineMock(array $coordinates = array(), array $options = array()) + { + $polyline = parent::createPolylineMock(); + $polyline + ->expects($this->any()) + ->method('getCoordinates') + ->will($this->returnValue($coordinates)); + + $polyline + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + return $polyline; + } +} diff --git a/tests/Helpers/Renderers/Overlays/RectangleRendererTest.php b/tests/Helpers/Renderers/Overlays/RectangleRendererTest.php new file mode 100644 index 00000000..4695e73d --- /dev/null +++ b/tests/Helpers/Renderers/Overlays/RectangleRendererTest.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Overlays; + +use Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer; +use Ivory\GoogleMap\Overlays\Rectangle; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Rectangle renderer test. + * + * @author GeLo + */ +class RectangleRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer */ + protected $rectangleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->rectangleRenderer = new RectangleRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->rectangleRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->rectangleRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender($expected, Rectangle $rectangle) + { + $this->assertSame($expected, $this->rectangleRenderer->render($rectangle, $this->createMapMock())); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('new google.maps.Rectangle({"map":map,"bounds":bound})', $this->createRectangleMock()), + array( + 'new google.maps.Rectangle({"map":map,"bounds":bound,"foo":"bar"})', + $this->createRectangleMock(array('foo' => 'bar')), + ), + ); + } + + /** + * {@inheritdoc} + */ + protected function createBoundMock() + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('bound')); + + return $bound; + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + return $map; + } + + /** + * Creates a rectangle mock. + * + * @param array $options The options. + * + * @return \Ivory\GoogleMap\Overlays\Rectangle|\PHPUnit_Framework_MockObject_MockObject The rectangle mock. + */ + protected function createRectangleMock(array $options = array()) + { + $rectangle = parent::createRectangleMock(); + $rectangle + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($this->createBoundMock())); + + $rectangle + ->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue($options)); + + return $rectangle; + } +} diff --git a/tests/Helpers/Renderers/Places/AutocompleteContainerRendererTest.php b/tests/Helpers/Renderers/Places/AutocompleteContainerRendererTest.php new file mode 100644 index 00000000..5df3af8e --- /dev/null +++ b/tests/Helpers/Renderers/Places/AutocompleteContainerRendererTest.php @@ -0,0 +1,55 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Places; + +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Autocomplete container renderer test. + * + * @author GeLo + */ +class AutocompleteContainerRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer */ + protected $containerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->containerRenderer = new AutocompleteContainerRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->containerRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->containerRenderer); + } + + public function testRender() + { + $this->assertSame( + '{"base":{"coordinates":[],"bounds":[]},"autocomplete":null}', + $this->containerRenderer->render() + ); + } +} diff --git a/tests/Helpers/Renderers/Places/AutocompleteRendererTest.php b/tests/Helpers/Renderers/Places/AutocompleteRendererTest.php new file mode 100644 index 00000000..f0ac3391 --- /dev/null +++ b/tests/Helpers/Renderers/Places/AutocompleteRendererTest.php @@ -0,0 +1,165 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Renderers\Places; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; +use Ivory\GoogleMap\Places\AutocompleteType; +use Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer; +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase; + +/** + * Autocomplete renderer test. + * + * @author GeLo + */ +class AutocompleteRendererTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer */ + protected $autocompleteRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->autocompleteRenderer= new AutocompleteRenderer(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->autocompleteRenderer); + } + + public function testInheritance() + { + $this->assertJsonRendererInstance($this->autocompleteRenderer); + } + + /** + * @dataProvider renderProvider + */ + public function testRender( + $expected, + array $types = array(), + Bound $bound = null, + array $componentRestrictions = array() + ) { + $this->assertSame( + $expected, + $this->autocompleteRenderer->render($this->createAutocompleteMock($types, $bound, $componentRestrictions)) + ); + } + + /** + * Gets the render provider. + * + * @return array The render provider. + */ + public function renderProvider() + { + return array( + array('new google.maps.places.Autocomplete(document.getElementById(\'input_id\'),{})'), + array( + 'new google.maps.places.Autocomplete(document.getElementById(\'input_id\'),{"types":["(regions)"]})', + array(AutocompleteType::REGIONS), + ), + array( + 'new google.maps.places.Autocomplete(document.getElementById(\'input_id\'),{"bounds":bound})', + array(), + $this->createBoundMock(), + ), + array( + 'new google.maps.places.Autocomplete(document.getElementById(\'input_id\'),{"componentRestrictions":["country"]})', + array(), + null, + array(AutocompleteComponentRestriction::COUNTRY), + ), + array( + 'new google.maps.places.Autocomplete(document.getElementById(\'input_id\'),{"types":["(regions)"],"bounds":bound,"componentRestrictions":["country"]})', + array(AutocompleteType::REGIONS), + $this->createBoundMock(), + array(AutocompleteComponentRestriction::COUNTRY), + ), + ); + } + + /** + * Creates an autocomplete mock. + * + * @param array $types The types. + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. + * @param array $componentRestrictions The component restrictions. + * + * @return \Ivory\GoogleMap\Places\Autocomplete|\PHPUnit_Framework_MockObject_MockObject The autocomplete mock. + */ + protected function createAutocompleteMock( + array $types = array(), + Bound $bound = null, + array $componentRestrictions = array() + ) { + $autocomplete = parent::createAutocompleteMock(); + $autocomplete + ->expects($this->any()) + ->method('getInputId') + ->will($this->returnValue('input_id')); + + $autocomplete + ->expects($this->any()) + ->method('hasTypes') + ->will($this->returnValue(!empty($types))); + + $autocomplete + ->expects($this->any()) + ->method('getTypes') + ->will($this->returnValue($types)); + + $autocomplete + ->expects($this->any()) + ->method('hasBound') + ->will($this->returnValue($bound !== null)); + + $autocomplete + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + + $autocomplete + ->expects($this->any()) + ->method('hasComponentRestrictions') + ->will($this->returnValue(!empty($componentRestrictions))); + + $autocomplete + ->expects($this->any()) + ->method('getComponentRestrictions') + ->will($this->returnValue($componentRestrictions)); + + return $autocomplete; + } + + /** + * {@inheritdoc} + */ + protected function createBoundMock() + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('bound')); + + return $bound; + } +} diff --git a/tests/Helpers/Subscribers/AbstractFormatterSubscriberTest.php b/tests/Helpers/Subscribers/AbstractFormatterSubscriberTest.php new file mode 100644 index 00000000..5aadcc68 --- /dev/null +++ b/tests/Helpers/Subscribers/AbstractFormatterSubscriberTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +/** + * Abstract container formatter subscriber test. + * + * @author GeLo + */ +abstract class AbstractFormatterSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Formatters\ContainerFormatter|\PHPUnit_Framework_MockObject_MockObject */ + protected $formatter; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->formatter = $this->createFormatterMock(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->formatter); + } +} diff --git a/tests/Helpers/Subscribers/AbstractTestCase.php b/tests/Helpers/Subscribers/AbstractTestCase.php new file mode 100644 index 00000000..60586862 --- /dev/null +++ b/tests/Helpers/Subscribers/AbstractTestCase.php @@ -0,0 +1,540 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\Tests\GoogleMap\Helpers\Renderers\AbstractTestCase as TestCase; + +/** + * Subscriber test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts an autocomplete container renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer $containerRenderer The container renderer. + */ + protected function assertAutocompleteContainerRendererInstance($containerRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer', + $containerRenderer + ); + } + + /** + * Asserts an autocomplete coordinate aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator $coordinateAggregator The coordinate aggregator. + */ + protected function assertAutocompleteCoordinateAggregatorInstance($coordinateAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteCoordinateAggregator', + $coordinateAggregator + ); + } + + /** + * Asserts an autocomplete renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer $autocompleteRenderer The autocomplete renderer. + */ + protected function assertAutocompleteRendererInstance($autocompleteRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer', + $autocompleteRenderer + ); + } + + /** + * Asserts a bound renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer $boundRenderer The bound renderer. + */ + protected function assertBoundRendererInstance($boundRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer', $boundRenderer); + } + + /** + * Asserts a circle renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer $circleRenderer The circle renderer. + */ + protected function assertCircleRendererInstance($circleRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer', $circleRenderer); + } + + /** + * Asserts the coordinate aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator $coordinateAggregator The coordinate aggregator. + */ + protected function assertCoordinateAggregatorInstance($coordinateAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator', $coordinateAggregator); + } + + /** + * Asserts the coordinate renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer $coordinateRenderer The coordinate renderer. + */ + protected function assertCoordinateRendererInstance($coordinateRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer', $coordinateRenderer); + } + + /** + * Asserts a dom event aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator $domEventAggregator The dom event aggregator. + */ + protected function assertDomEventAggregatorInstance($domEventAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator', $domEventAggregator); + } + + /** + * Asserts a dom event renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer $domEventRenderer The dom event renderer. + */ + protected function assertDomEventRendererInstance($domEventRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer', $domEventRenderer); + } + + /** + * Asserts a dom event once aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator $domEventOnceAggregator The dom event once aggregator. + */ + protected function assertDomEventOnceAggregatorInstance($domEventOnceAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator', + $domEventOnceAggregator + ); + } + + /** + * Asserts a dom event once renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer $domEventOnceRenderer The dom event once renderer. + */ + protected function assertDomEventOnceRendererInstance($domEventOnceRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer', $domEventOnceRenderer); + } + + /** + * Asserts a encoded polyline aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator $encodedPolylineAggregator The encoded polyline aggregator. + */ + protected function assertEncodedPolylineAggregatorInstance($encodedPolylineAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator', + $encodedPolylineAggregator + ); + } + + /** + * Asserts a encoded polyline renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer $encodedPolylineRenderer The encoded polyline renderer. + */ + protected function assertEncodedPolylineRendererInstance($encodedPolylineRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer', + $encodedPolylineRenderer + ); + } + + /** + * Asserts an event aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator $eventAggregator The event aggregator. + */ + protected function assertEventAggregatorInstance($eventAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator', $eventAggregator); + } + + /** + * Asserts an event once aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator $eventOnceAggregator The event once aggregator. + */ + protected function assertEventOnceAggregatorInstance($eventOnceAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Events\EventOnceAggregator', $eventOnceAggregator); + } + + /** + * Asserts an event once renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer $eventOnceRenderer The event once renderer. + */ + protected function assertEventOnceRendererInstance($eventOnceRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Events\EventOnceRenderer', $eventOnceRenderer); + } + + /** + * Asserts an event renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer $eventRenderer The event renderer. + */ + protected function assertEventRendererInstance($eventRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer', $eventRenderer); + } + + /** + * Asserts an extendable aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator $extendableAggregator The extendable aggregator. + */ + protected function assertExtendableAggregatorInstance($extendableAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator', + $extendableAggregator + ); + } + + /** + * Asserts an extendable renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer $extendableRenderer The extendable renderer. + */ + protected function assertExtendableRendererInstance($extendableRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer', $extendableRenderer); + } + + /** + * Asserts a formatter subscriber instance. + * + * @param \Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber $formatterSubscriber The formatter subscriber. + */ + protected function assertFormatterSubscriberInstance($formatterSubscriber) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber', + $formatterSubscriber + ); + } + + /** + * Asserts a ground overlay renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer $groundOverlayRenderer The ground overlay renderer. + */ + protected function assertGroundOverlayRendererInstance($groundOverlayRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer', + $groundOverlayRenderer + ); + } + + /** + * Asserts an icon renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer $iconRenderer The icon renderer. + */ + protected function assertIconRendererInstance($iconRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer', $iconRenderer); + } + + /** + * Asserts an info box renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer $infoBoxRenderer The info box renderer. + */ + protected function assertInfoBoxRendererInstance($infoBoxRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer', $infoBoxRenderer); + } + + /** + * Asserts an info window close renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer $infoWindowCloseRenderer The info window close renderer. + */ + protected function assertInfoWindowCloseRendererInstance($infoWindowCloseRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer', + $infoWindowCloseRenderer + ); + } + + /** + * Asserts an info window renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer $infoWindowRenderer The info window renderer. + */ + protected function assertInfoWindowRendererInstance($infoWindowRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer', $infoWindowRenderer); + } + + /** + * Asserts a kml layer aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator $kmlLayerAggregator The kml layer aggregator. + */ + protected function assertKmlLayerAggregatorInstance($kmlLayerAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator', $kmlLayerAggregator); + } + + /** + * Asserts a kml layer renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer $kmlLayerRenderer The kml layer renderer. + */ + protected function assertKmlLayerRendererInstance($kmlLayerRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer', $kmlLayerRenderer); + } + + /** + * Asserts a loader renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer $loaderRenderer The loader renderer. + */ + protected function assertLoaderRendererInstance($loaderRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer', $loaderRenderer); + } + + /** + * Asserts a map bound renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer $mapBoundRenderer The map bound renderer. + */ + protected function assertMapBoundRendererInstance($mapBoundRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer', $mapBoundRenderer); + } + + /** + * Asserts a map center renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer $mapCenterRenderer The map center renderer. + */ + protected function assertMapCenterRendererInstance($mapCenterRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer', $mapCenterRenderer); + } + + /** + * Asserts a map container renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer $mapContainerRenderer The map container renderer. + */ + protected function assertMapContainerRendererInstance($mapContainerRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer', $mapContainerRenderer); + } + + /** + * Asserts a map renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\MapRenderer $mapRenderer The map renderer. + */ + protected function assertMapRendererInstance($mapRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\MapRenderer', $mapRenderer); + } + + /** + * Asserts a marker cluster renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer $markerClusterRenderer The marker cluster renderer. + */ + protected function assertMarkerClusterRendererInstance($markerClusterRenderer) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer', + $markerClusterRenderer + ); + } + + /** + * Asserts a marker renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer $markerRenderer The marker renderer. + */ + protected function assertMarkerRendererInstance($markerRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer', $markerRenderer); + } + + /** + * Asserts a marker shape aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator $markerShapeAggregator The marker shape aggregator. + */ + protected function assertMarkerShapeAggregatorInstance($markerShapeAggregator) + { + $this->assertInstanceOf( + 'Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator', + $markerShapeAggregator + ); + } + + /** + * Asserts a marker shape renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer $markerShapeRenderer The marker shape renderer. + */ + protected function assertMarkerShapeRendererInstance($markerShapeRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer', $markerShapeRenderer); + } + + /** + * Asserts a point aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator $pointAggregator The point aggregator. + */ + protected function assertPointAggregatorInstance($pointAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator', $pointAggregator); + } + + /** + * Asserts a point renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer $pointRenderer The point renderer. + */ + protected function assertPointRendererInstance($pointRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer', $pointRenderer); + } + + /** + * Asserts a polygon renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer $polygonRenderer The polygon renderer. + */ + protected function assertPolygonRendererInstance($polygonRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer', $polygonRenderer); + } + + /** + * Asserts a polyline renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer $polylineRenderer The polyline renderer. + */ + protected function assertPolylineRendererInstance($polylineRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer', $polylineRenderer); + } + + /** + * Asserts a rectangle renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer $rectangleRenderer The rectangle renderer. + */ + protected function assertRectangleRendererInstance($rectangleRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer', $rectangleRenderer); + } + + /** + * Asserts a size aggregator instance. + * + * @param \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator $sizeAggregator The size aggregator. + */ + protected function assertSizeAggregatorInstance($sizeAggregator) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator', $sizeAggregator); + } + + /** + * Asserts a size renderer instance. + * + * @param \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer $sizeRenderer The size renderer. + */ + protected function assertSizeRendererInstance($sizeRenderer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer', $sizeRenderer); + } + + /** + * Creates an api event mock. + * + * @return \Ivory\GoogleMap\Helpers\ApiEvent|\PHPUnit_Framework_MockObject_MockObject The api event mock. + */ + protected function createApiEventMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\ApiEvent')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a formatter subscriber mock. + * + * @return \Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber|\PHPUnit_Framework_MockObject_MockObject The formatter subscriber mock. + */ + protected function createFormatterSubscriberMock() + { + return $this->createFormatterSubscriberMockBuilder()->getMockForAbstractClass(); + } + + /** + * Creates a formatter subscriber mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The formatter subscriber mock builder. + */ + protected function createFormatterSubscriberMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber'); + } + + /** + * Creates a map event mock. + * + * @return \Ivory\GoogleMap\Helpers\MapEvent|\PHPUnit_Framework_MockObject_MockObject The map event mock. + */ + protected function createMapEventMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\MapEvent')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an autocomplete event mock. + * + * @return \Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent|\PHPUnit_Framework_MockObject_MockObject The autocomplete event mock. + */ + protected function createPlacesAutocompleteEventMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent') + ->disableOriginalConstructor() + ->getMock(); + } +} diff --git a/tests/Helpers/Subscribers/ApiJavascriptSubscriberTest.php b/tests/Helpers/Subscribers/ApiJavascriptSubscriberTest.php new file mode 100644 index 00000000..911ddc51 --- /dev/null +++ b/tests/Helpers/Subscribers/ApiJavascriptSubscriberTest.php @@ -0,0 +1,220 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\Subscribers\ApiJavascriptSubscriber; + +/** + * Api javascript subscriber test. + * + * @author GeLo + */ +class ApiJavascriptSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\ApiJavascriptSubscriber */ + protected $apiJavascriptSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\LoaderRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $loaderRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->apiJavascriptSubscriber = new ApiJavascriptSubscriber( + $this->formatter, + $this->loaderRenderer = $this->createLoaderRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->loaderRenderer); + unset($this->apiJavascriptSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->apiJavascriptSubscriber); + } + + public function testDefaultState() + { + $this->apiJavascriptSubscriber = new ApiJavascriptSubscriber(); + + $this->assertFormatterInstance($this->apiJavascriptSubscriber->getFormatter()); + $this->assertLoaderRendererInstance($this->apiJavascriptSubscriber->getLoaderRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->apiJavascriptSubscriber->getFormatter()); + $this->assertSame($this->loaderRenderer, $this->apiJavascriptSubscriber->getLoaderRenderer()); + } + + public function testSetLoaderRenderer() + { + $this->apiJavascriptSubscriber->setLoaderRenderer($loaderRenderer = $this->createLoaderRendererMock()); + + $this->assertSame($loaderRenderer, $this->apiJavascriptSubscriber->getLoaderRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = ApiJavascriptSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT]); + } + + public function testOnApi() + { + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(2)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(ApiEvents::JAVASCRIPT_MAP, $apiEvent), + array(ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE, $apiEvent), + ))); + + $apiEvent + ->expects($this->any()) + ->method('getSources') + ->will($this->returnValue(array($source = 'source'))); + + $apiEvent + ->expects($this->any()) + ->method('getCallbacks') + ->will($this->returnValue(array($callback = 'callback'))); + + $apiEvent + ->expects($this->any()) + ->method('getLibraries') + ->will($this->returnValue($libraries = array('geometry'))); + + $apiEvent + ->expects($this->any()) + ->method('getLanguage') + ->will($this->returnValue($language = 'en')); + + $loaderCallback = 'loader_callback'; + $apiCallback = 'api_callback'; + + $this->formatter + ->expects($this->exactly(2)) + ->method('formatCallback') + ->will($this->returnCallback(function ($name) use ($loaderCallback, $apiCallback) { + if (strpos($name, 'ivory_google_map_loader') === 0) { + return $loaderCallback; + } + + if (strpos($name, 'ivory_google_map_api') === 0) { + return $apiCallback; + } + })); + + $this->loaderRenderer + ->expects($this->once()) + ->method('renderSource') + ->with($this->identicalTo($loaderCallback)) + ->will($this->returnValue($renderSource = 'render_source')); + + $this->formatter + ->expects($this->any(2)) + ->method('formatSource') + ->will($this->returnValueMap(array( + array($source, $apiCallback.'2', $apiSource = 'api_source'), + array($renderSource, null, $javascriptSource = 'javascript_source'), + ))); + + $this->formatter + ->expects($this->any(1)) + ->method('formatFunctionCall') + ->will($this->returnValueMap(array( + array($callback, array(), true, true, $callbackFunctionCall = 'callback_function_call'), + ))); + + $this->loaderRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($language), + $this->identicalTo($libraries), + $this->identicalTo($apiCallback.'1') + ) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->any(1)) + ->method('formatCode') + ->will($this->returnValueMap(array( + array($render, true, true, $loader = 'loader'), + ))); + + $this->formatter + ->expects($this->any(3)) + ->method('formatFunction') + ->will($this->returnValueMap(array( + array($apiSource, array(), $apiCallback.'1', true, true, true, $sourceFunction = 'api_function'), + array( + $callbackFunctionCall, + array(), + $apiCallback.'2', + true, + true, + true, + $callbackFunction = 'callback_function', + ), + array( + $loader, + array(), + $loaderCallback, + true, + true, + true, + $loaderFunction = 'loader_function', + ), + ))); + + $this->formatter + ->expects($this->any(1)) + ->method('formatJavascript') + ->will($this->returnValueMap(array( + array($loaderFunction.$sourceFunction.$callbackFunction, array(), $javascript = 'javascript'), + ))); + + $apiEvent + ->expects($this->exactly(2)) + ->method('addCode') + ->withConsecutive( + array($this->identicalTo($javascript)), + array($this->identicalTo($javascriptSource)) + ); + + $this->apiJavascriptSubscriber->onApi($apiEvent); + } +} diff --git a/tests/Helpers/Subscribers/Base/BaseSubscriberTest.php b/tests/Helpers/Subscribers/Base/BaseSubscriberTest.php new file mode 100644 index 00000000..fc08e1d1 --- /dev/null +++ b/tests/Helpers/Subscribers/Base/BaseSubscriberTest.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Base\BaseSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Base subscriber test. + * + * @author GeLo + */ +class BaseSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Base\BaseSubscriber */ + protected $baseSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->baseSubscriber = new BaseSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->baseSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = BaseSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_BASE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_BASE]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(4)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_BASE_COORDINATE, $mapEvent), + array(MapEvents::JAVASCRIPT_BASE_BOUND, $mapEvent), + array(MapEvents::JAVASCRIPT_BASE_POINT, $mapEvent), + array(MapEvents::JAVASCRIPT_BASE_SIZE, $mapEvent), + ))); + + $this->baseSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Base/BoundSubscriberTest.php b/tests/Helpers/Subscribers/Base/BoundSubscriberTest.php new file mode 100644 index 00000000..f02b97df --- /dev/null +++ b/tests/Helpers/Subscribers/Base/BoundSubscriberTest.php @@ -0,0 +1,141 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Base\BoundSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Bound subscriber test. + * + * @author GeLo + */ +class BoundSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Base\BoundSubscriber */ + protected $boundSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\BoundAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->boundSubscriber = new BoundSubscriber( + $this->formatter, + $this->boundAggregator = $this->createBoundAggregatorMock(), + $this->boundRenderer = $this->createBoundRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->boundRenderer); + unset($this->boundAggregator); + unset($this->boundSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->boundSubscriber); + } + + public function testDefaultState() + { + $this->boundSubscriber = new BoundSubscriber(); + + $this->assertFormatterInstance($this->boundSubscriber->getFormatter()); + $this->assertBoundAggregatorInstance($this->boundSubscriber->getBoundAggregator()); + $this->assertBoundRendererInstance($this->boundSubscriber->getBoundRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->boundSubscriber->getFormatter()); + $this->assertSame($this->boundAggregator, $this->boundSubscriber->getBoundAggregator()); + $this->assertSame($this->boundRenderer, $this->boundSubscriber->getBoundRenderer()); + } + + public function testSetBoundAggregator() + { + $this->boundSubscriber->setBoundAggregator($boundAggregator = $this->createBoundAggregatorMock()); + + $this->assertSame($boundAggregator, $this->boundSubscriber->getBoundAggregator()); + } + + public function testSetBoundRenderer() + { + $this->boundSubscriber->setBoundRenderer($boundRenderer = $this->createBoundRendererMock()); + + $this->assertSame($boundRenderer, $this->boundSubscriber->getBoundRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = BoundSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_BASE_BOUND, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_BASE_BOUND]); + } + + public function testOnMap() + { + $this->boundAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($bound = $this->createBoundMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.bounds'), + $this->identicalTo($bound) + ) + ->will($this->returnValue($code = 'code')); + + $this->boundRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($bound)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->boundSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Base/CoordinateSubscriberTest.php b/tests/Helpers/Subscribers/Base/CoordinateSubscriberTest.php new file mode 100644 index 00000000..80fb4ddb --- /dev/null +++ b/tests/Helpers/Subscribers/Base/CoordinateSubscriberTest.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Base\CoordinateSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Coordinate subscriber test. + * + * @author GeLo + */ +class CoordinateSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Base\CoordinateSubscriber */ + protected $coordinateSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\CoordinateAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $coordinateRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->coordinateSubscriber = new CoordinateSubscriber( + $this->formatter, + $this->coordinateAggregator = $this->createCoordinateAggregatorMock(), + $this->coordinateRenderer = $this->createCoordinateRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->coordinateRenderer); + unset($this->coordinateAggregator); + unset($this->coordinateSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->coordinateSubscriber); + } + + public function testDefaultState() + { + $this->coordinateSubscriber = new CoordinateSubscriber(); + + $this->assertFormatterInstance($this->coordinateSubscriber->getFormatter()); + $this->assertCoordinateAggregatorInstance($this->coordinateSubscriber->getCoordinateAggregator()); + $this->assertCoordinateRendererInstance($this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->coordinateSubscriber->getFormatter()); + $this->assertSame($this->coordinateAggregator, $this->coordinateSubscriber->getCoordinateAggregator()); + $this->assertSame($this->coordinateRenderer, $this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testSetCoordinateAggregator() + { + $this->coordinateSubscriber->setCoordinateAggregator( + $coordinateAggregator = $this->createCoordinateAggregatorMock() + ); + + $this->assertSame($coordinateAggregator, $this->coordinateSubscriber->getCoordinateAggregator()); + } + + public function testSetCoordinateRenderer() + { + $this->coordinateSubscriber->setCoordinateRenderer( + $coordinateRenderer = $this->createCoordinateRendererMock() + ); + + $this->assertSame($coordinateRenderer, $this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = CoordinateSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_BASE_COORDINATE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_BASE_COORDINATE]); + } + + public function testOnMap() + { + $this->coordinateAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($coordinate = $this->createCoordinateMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.coordinates'), + $this->identicalTo($coordinate) + ) + ->will($this->returnValue($code = 'code')); + + $this->coordinateRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($coordinate)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->coordinateSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Base/PointSubscriberTest.php b/tests/Helpers/Subscribers/Base/PointSubscriberTest.php new file mode 100644 index 00000000..ca65e3c9 --- /dev/null +++ b/tests/Helpers/Subscribers/Base/PointSubscriberTest.php @@ -0,0 +1,141 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Base\PointSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Point subscriber test. + * + * @author GeLo + */ +class PointSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Base\PointSubscriber */ + protected $pointSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\PointAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $pointAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\PointRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $pointRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->pointSubscriber = new PointSubscriber( + $this->formatter, + $this->pointAggregator = $this->createPointAggregatorMock(), + $this->pointRenderer = $this->createPointRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->pointRenderer); + unset($this->pointAggregator); + unset($this->pointSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->pointSubscriber); + } + + public function testDefaultState() + { + $this->pointSubscriber = new PointSubscriber(); + + $this->assertFormatterInstance($this->pointSubscriber->getFormatter()); + $this->assertPointAggregatorInstance($this->pointSubscriber->getPointAggregator()); + $this->assertPointRendererInstance($this->pointSubscriber->getPointRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->pointSubscriber->getFormatter()); + $this->assertSame($this->pointAggregator, $this->pointSubscriber->getPointAggregator()); + $this->assertSame($this->pointRenderer, $this->pointSubscriber->getPointRenderer()); + } + + public function testSetPointAggregator() + { + $this->pointSubscriber->setPointAggregator($pointAggregator = $this->createPointAggregatorMock()); + + $this->assertSame($pointAggregator, $this->pointSubscriber->getPointAggregator()); + } + + public function testSetPointRenderer() + { + $this->pointSubscriber->setPointRenderer($pointRenderer = $this->createPointRendererMock()); + + $this->assertSame($pointRenderer, $this->pointSubscriber->getPointRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = PointSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_BASE_POINT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_BASE_POINT]); + } + + public function testOnMap() + { + $this->pointAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($point = $this->createPointMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.points'), + $this->identicalTo($point) + ) + ->will($this->returnValue($code = 'code')); + + $this->pointRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($point)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->pointSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Base/SizeSubscriberTest.php b/tests/Helpers/Subscribers/Base/SizeSubscriberTest.php new file mode 100644 index 00000000..eb943cb5 --- /dev/null +++ b/tests/Helpers/Subscribers/Base/SizeSubscriberTest.php @@ -0,0 +1,139 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Base\SizeSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Size subscriber test. + * + * @author GeLo + */ +class SizeSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Base\SizeSubscriber */ + protected $sizeSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Base\SizeAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $sizeAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\SizeRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $sizeRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->sizeSubscriber = new SizeSubscriber( + $this->formatter, + $this->sizeAggregator = $this->createSizeAggregatorMock(), + $this->sizeRenderer = $this->createSizeRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->sizeRenderer); + unset($this->sizeAggregator); + unset($this->sizeSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->sizeSubscriber); + } + + public function testDefaultState() + { + $this->sizeSubscriber = new SizeSubscriber(); + + $this->assertSizeAggregatorInstance($this->sizeSubscriber->getSizeAggregator()); + $this->assertSizeRendererInstance($this->sizeSubscriber->getSizeRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->sizeAggregator, $this->sizeSubscriber->getSizeAggregator()); + $this->assertSame($this->sizeRenderer, $this->sizeSubscriber->getSizeRenderer()); + } + + public function testSetSizeAggregator() + { + $this->sizeSubscriber->setSizeAggregator($sizeAggregator = $this->createSizeAggregatorMock()); + + $this->assertSame($sizeAggregator, $this->sizeSubscriber->getSizeAggregator()); + } + + public function testSetSizeRenderer() + { + $this->sizeSubscriber->setSizeRenderer($sizeRenderer = $this->createSizeRendererMock()); + + $this->assertSame($sizeRenderer, $this->sizeSubscriber->getSizeRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = SizeSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_BASE_SIZE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_BASE_SIZE]); + } + + public function testOnMap() + { + $this->sizeAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($size = $this->createSizeMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.sizes'), + $this->identicalTo($size) + ) + ->will($this->returnValue($code = 'code')); + + $this->sizeRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($size)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->sizeSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Events/DomEventOnceSubscriberTest.php b/tests/Helpers/Subscribers/Events/DomEventOnceSubscriberTest.php new file mode 100644 index 00000000..014b7fbe --- /dev/null +++ b/tests/Helpers/Subscribers/Events/DomEventOnceSubscriberTest.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventOnceSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Dom event once subscriber test. + * + * @author GeLo + */ +class DomEventOnceSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventOnceSubscriber */ + protected $domEventOnceSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventOnceAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $domEventOnceAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventOnceRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $domEventOnceRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->domEventOnceSubscriber = new DomEventOnceSubscriber( + $this->formatter, + $this->domEventOnceAggregator = $this->createDomEventOnceAggregatorMock(), + $this->domEventOnceRenderer = $this->createDomEventOnceRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->domEventOnceRenderer); + unset($this->domEventOnceAggregator); + unset($this->domEventOnceSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->domEventOnceSubscriber); + } + + public function testDefaultState() + { + $this->domEventOnceSubscriber = new DomEventOnceSubscriber(); + + $this->assertFormatterInstance($this->domEventOnceSubscriber->getFormatter()); + $this->assertDomEventOnceAggregatorInstance($this->domEventOnceSubscriber->getDomEventOnceAggregator()); + $this->assertDomEventOnceRendererInstance($this->domEventOnceSubscriber->getDomEventOnceRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->domEventOnceSubscriber->getFormatter()); + $this->assertSame($this->domEventOnceAggregator, $this->domEventOnceSubscriber->getDomEventOnceAggregator()); + $this->assertSame($this->domEventOnceRenderer, $this->domEventOnceSubscriber->getDomEventOnceRenderer()); + } + + public function testSetDomEventOnceAggregator() + { + $this->domEventOnceSubscriber->setDomEventOnceAggregator( + $domEventOnceAggregator = $this->createDomEventOnceAggregatorMock() + ); + + $this->assertSame($domEventOnceAggregator, $this->domEventOnceSubscriber->getDomEventOnceAggregator()); + } + + public function testSetDomEventOnceRenderer() + { + $this->domEventOnceSubscriber->setDomEventOnceRenderer( + $domEventOnceRenderer = $this->createDomEventOnceRendererMock() + ); + + $this->assertSame($domEventOnceRenderer, $this->domEventOnceSubscriber->getDomEventOnceRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = DomEventOnceSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE]); + } + + public function testOnMap() + { + $this->domEventOnceAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($domEventOnce = $this->createDomEventMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('events.dom_events_once'), + $this->identicalTo($domEventOnce) + ) + ->will($this->returnValue($code = 'code')); + + $this->domEventOnceRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($domEventOnce)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->domEventOnceSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Events/DomEventSubscriberTest.php b/tests/Helpers/Subscribers/Events/DomEventSubscriberTest.php new file mode 100644 index 00000000..0b24d9fb --- /dev/null +++ b/tests/Helpers/Subscribers/Events/DomEventSubscriberTest.php @@ -0,0 +1,141 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Dom event subscriber test. + * + * @author GeLo + */ +class DomEventSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Events\DomEventSubscriber */ + protected $domEventSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\DomEventAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $domEventAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\DomEventRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $domEventRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->domEventSubscriber = new DomEventSubscriber( + $this->formatter, + $this->domEventAggregator = $this->createDomEventAggregatorMock(), + $this->domEventRenderer = $this->createDomEventRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->domEventRenderer); + unset($this->domEventAggregator); + unset($this->domEventSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->domEventSubscriber); + } + + public function testDefaultState() + { + $this->domEventSubscriber = new DomEventSubscriber(); + + $this->assertFormatterInstance($this->domEventSubscriber->getFormatter()); + $this->assertDomEventAggregatorInstance($this->domEventSubscriber->getDomEventAggregator()); + $this->assertDomEventRendererInstance($this->domEventSubscriber->getDomEventRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->domEventSubscriber->getFormatter()); + $this->assertSame($this->domEventAggregator, $this->domEventSubscriber->getDomEventAggregator()); + $this->assertSame($this->domEventRenderer, $this->domEventSubscriber->getDomEventRenderer()); + } + + public function testSetDomEventAggregator() + { + $this->domEventSubscriber->setDomEventAggregator($domEventAggregator = $this->createDomEventAggregatorMock()); + + $this->assertSame($domEventAggregator, $this->domEventSubscriber->getDomEventAggregator()); + } + + public function testSetDomEventRenderer() + { + $this->domEventSubscriber->setDomEventRenderer($domEventRenderer = $this->createDomEventRendererMock()); + + $this->assertSame($domEventRenderer, $this->domEventSubscriber->getDomEventRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = DomEventSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT]); + } + + public function testOnMap() + { + $this->domEventAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($domEvent = $this->createDomEventMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('events.dom_events'), + $this->identicalTo($domEvent) + ) + ->will($this->returnValue($code = 'code')); + + $this->domEventRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($domEvent)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->domEventSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Events/EventOnceSubscriberTest.php b/tests/Helpers/Subscribers/Events/EventOnceSubscriberTest.php new file mode 100644 index 00000000..4c048657 --- /dev/null +++ b/tests/Helpers/Subscribers/Events/EventOnceSubscriberTest.php @@ -0,0 +1,143 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\EventOnces; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventOnceSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Event once subscriber test. + * + * @author GeLo + */ +class EventOnceSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\EventOnces\EventOnceSubscriber */ + protected $eventOnceSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\EventOnces\EventOnceAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventOnceAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\EventOnces\EventOnceRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventOnceRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->eventOnceSubscriber = new EventOnceSubscriber( + $this->formatter, + $this->eventOnceAggregator = $this->createEventOnceAggregatorMock(), + $this->eventOnceRenderer = $this->createEventOnceRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->eventOnceRenderer); + unset($this->eventOnceAggregator); + unset($this->eventOnceSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->eventOnceSubscriber); + } + + public function testDefaultState() + { + $this->eventOnceSubscriber = new EventOnceSubscriber(); + + $this->assertFormatterInstance($this->eventOnceSubscriber->getFormatter()); + $this->assertEventOnceAggregatorInstance($this->eventOnceSubscriber->getEventOnceAggregator()); + $this->assertEventOnceRendererInstance($this->eventOnceSubscriber->getEventOnceRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->eventOnceSubscriber->getFormatter()); + $this->assertSame($this->eventOnceAggregator, $this->eventOnceSubscriber->getEventOnceAggregator()); + $this->assertSame($this->eventOnceRenderer, $this->eventOnceSubscriber->getEventOnceRenderer()); + } + + public function testSetEventOnceAggregator() + { + $this->eventOnceSubscriber->setEventOnceAggregator( + $eventOnceAggregator = $this->createEventOnceAggregatorMock() + ); + + $this->assertSame($eventOnceAggregator, $this->eventOnceSubscriber->getEventOnceAggregator()); + } + + public function testSetEventOnceRenderer() + { + $this->eventOnceSubscriber->setEventOnceRenderer($eventOnceRenderer = $this->createEventOnceRendererMock()); + + $this->assertSame($eventOnceRenderer, $this->eventOnceSubscriber->getEventOnceRenderer()); + } + + public function testSubscribedEventOnces() + { + $subscribedEvents = EventOnceSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE]); + } + + public function testOnMap() + { + $this->eventOnceAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($eventOnce = $this->createEventMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('events.events_once'), + $this->identicalTo($eventOnce) + ) + ->will($this->returnValue($code = 'code')); + + $this->eventOnceRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($eventOnce)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->eventOnceSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Events/EventSubscriberTest.php b/tests/Helpers/Subscribers/Events/EventSubscriberTest.php new file mode 100644 index 00000000..e90373fe --- /dev/null +++ b/tests/Helpers/Subscribers/Events/EventSubscriberTest.php @@ -0,0 +1,141 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Event subscriber test. + * + * @author GeLo + */ +class EventSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Events\EventSubscriber */ + protected $eventSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Events\EventAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Events\EventRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $eventRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->eventSubscriber = new EventSubscriber( + $this->formatter, + $this->eventAggregator = $this->createEventAggregatorMock(), + $this->eventRenderer = $this->createEventRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->eventRenderer); + unset($this->eventAggregator); + unset($this->eventSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->eventSubscriber); + } + + public function testDefaultState() + { + $this->eventSubscriber = new EventSubscriber(); + + $this->assertFormatterInstance($this->eventSubscriber->getFormatter()); + $this->assertEventAggregatorInstance($this->eventSubscriber->getEventAggregator()); + $this->assertEventRendererInstance($this->eventSubscriber->getEventRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->eventSubscriber->getFormatter()); + $this->assertSame($this->eventAggregator, $this->eventSubscriber->getEventAggregator()); + $this->assertSame($this->eventRenderer, $this->eventSubscriber->getEventRenderer()); + } + + public function testSetEventAggregator() + { + $this->eventSubscriber->setEventAggregator($eventAggregator = $this->createEventAggregatorMock()); + + $this->assertSame($eventAggregator, $this->eventSubscriber->getEventAggregator()); + } + + public function testSetEventRenderer() + { + $this->eventSubscriber->setEventRenderer($eventRenderer = $this->createEventRendererMock()); + + $this->assertSame($eventRenderer, $this->eventSubscriber->getEventRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = EventSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_EVENTS_EVENT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_EVENTS_EVENT]); + } + + public function testOnMap() + { + $this->eventAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($event = $this->createEventMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('events.events'), + $this->identicalTo($event) + ) + ->will($this->returnValue($code = 'code')); + + $this->eventRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($event)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->eventSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Events/EventsSubscriberTest.php b/tests/Helpers/Subscribers/Events/EventsSubscriberTest.php new file mode 100644 index 00000000..4bdca0cf --- /dev/null +++ b/tests/Helpers/Subscribers/Events/EventsSubscriberTest.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Events; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Events\EventsSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Events subscriber test. + * + * @author GeLo + */ +class EventsSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Events\EventsSubscriber */ + protected $eventsSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->eventsSubscriber = new EventsSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->eventsSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = EventsSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_EVENTS, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_EVENTS]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(4)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT, $mapEvent), + array(MapEvents::JAVASCRIPT_EVENTS_DOM_EVENT_ONCE, $mapEvent), + array(MapEvents::JAVASCRIPT_EVENTS_EVENT, $mapEvent), + array(MapEvents::JAVASCRIPT_EVENTS_EVENT_ONCE, $mapEvent), + ))); + + $this->eventsSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/FormatterSubscriberTest.php b/tests/Helpers/Subscribers/FormatterSubscriberTest.php new file mode 100644 index 00000000..3ff9a85f --- /dev/null +++ b/tests/Helpers/Subscribers/FormatterSubscriberTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +/** + * Formatter subscriber test. + * + * @author GeLo + */ +class FormatterSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriber|\PHPUnit_Framework_MockObject_MockObject */ + protected $formatterSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->formatterSubscriber = $this->createFormatterSubscriberMockBuilder() + ->setConstructorArgs(array($this->formatter)) + ->getMockForAbstractClass(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->formatterSubscriber); + } + + public function testDefaultState() + { + $this->formatterSubscriber = $this->createFormatterSubscriberMock(); + + $this->assertFormatterInstance($this->formatterSubscriber->getFormatter()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->formatterSubscriber->getFormatter()); + } + + public function testSetContainerFormatter() + { + $this->formatterSubscriber->setFormatter($formatter = $this->createFormatterMock()); + + $this->assertSame($formatter, $this->formatterSubscriber->getFormatter()); + } +} diff --git a/tests/Helpers/Subscribers/FormatterTest.php b/tests/Helpers/Subscribers/FormatterTest.php new file mode 100644 index 00000000..45a7796d --- /dev/null +++ b/tests/Helpers/Subscribers/FormatterTest.php @@ -0,0 +1,994 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Assets\AbstractVariableAsset; +use Ivory\GoogleMap\Helpers\Subscribers\Formatter; + +/** + * Formatter test. + * + * @author GeLo + */ +class FormatterTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Formatter */ + protected $formatter; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->formatter = new Formatter(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->formatter); + } + + public function testDefaultState() + { + $this->assertFalse($this->formatter->isDebug()); + $this->assertSame(4, $this->formatter->getIndentation()); + } + + public function testInitialState() + { + $this->formatter = new Formatter(true, $indentation = 2); + + $this->assertTrue($this->formatter->isDebug()); + $this->assertSame($indentation, $this->formatter->getIndentation()); + } + + public function testSetDebug() + { + $this->formatter->setDebug(true); + + $this->assertTrue($this->formatter->isDebug()); + } + + public function testSetIndentation() + { + $this->formatter->setIndentation($indentation = 2); + + $this->assertSame($indentation, $this->formatter->getIndentation()); + } + + /** + * @dataProvider formatSeparatorProvider + */ + public function testFormatSeparator($expected, $debug) + { + $this->formatter->setDebug($debug); + + $this->assertSame($expected, $this->formatter->formatSeparator()); + } + + /** + * @dataProvider formatLineProvider + */ + public function testFormatLine($expected, $debug) + { + $this->formatter->setDebug($debug); + + $this->assertSame($expected, $this->formatter->formatLine('line')); + } + + /** + * @dataProvider formatIndentationProvider + */ + public function testFormatIndentation($expected, $code, $debug, $indentation = 4) + { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatIndentation($code)); + } + + /** + * @dataProvider formatTagProvider + */ + public function testFormatTag( + $expected, + $debug, + $indentation = 4, + $content = null, + array $attributes = array(), + $inline = false + ) { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatTag('name', $content, $attributes, $inline)); + } + + /** + * @dataProvider formatStylesheetProvider + */ + public function testFormatStylesheet($expected, $debug, $indentation = 4) + { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatStylesheet('#id', array('foo' => 'bar', 'baz' => 'bat'))); + } + + /** + * @dataProvider formatJavascriptProvider + */ + public function testFormatJavascript($expected, $debug, $indentation = 4) + { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatJavascript('code')); + } + + /** + * @dataProvider formatCodeProvider + */ + public function testFormatCode($expected, $debug, $semicolon = true, $format = true) + { + $this->formatter->setDebug($debug); + + $this->assertSame($expected, $this->formatter->formatCode('code', $semicolon, $format)); + } + + /** + * @dataProvider formatTernaryProvider + */ + public function testFormatTernary($expected, $debug, $semicolon = true, $format = true) + { + $this->formatter->setDebug($debug); + + $this->assertSame( + $expected, + $this->formatter->formatTernary('condition', 'value1', 'value2', $semicolon, $format) + ); + } + + /** + * @dataProvider formatIfProvider + */ + public function testFormatIf($expected, $debug, $indentation = 4, array $elseIfs = array(), $elseCode = null) + { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatIf('condition', 'code', $elseIfs, $elseCode)); + } + + /** + * @dataProvider formatSourceProvider + */ + public function testFormatSource($expected, $debug, $indentation = 4, $callback = null) + { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame($expected, $this->formatter->formatSource('source', $callback)); + } + + /** + * @dataProvider formatFunctionProvider + */ + public function testFormatFunction( + $expected, + $debug, + $indentation = 4, + array $arguments = array(), + $name = null, + $semicolon = true, + $formatStart = true, + $formatEnd = true + ) { + $this->formatter->setDebug($debug); + $this->formatter->setIndentation($indentation); + + $this->assertSame( + $expected, + $this->formatter->formatFunction('code', $arguments, $name, $semicolon, $formatStart, $formatEnd) + ); + } + + /** + * @dataProvider formatFunctionCallProvider + */ + public function testFormatFunctionCall( + $expected, + $debug, + array $arguments = array(), + $semicolon = true, + $format = true + ) { + $this->formatter->setDebug($debug); + + $this->assertSame($expected, $this->formatter->formatFunctionCall('name', $arguments, $semicolon, $format)); + } + + /** + * @dataProvider formatAssignmentProvider + */ + public function testFormatAssignment($expected, $debug, $semicolon = true, $format = true, $operator = '=') + { + $this->formatter->setDebug($debug); + + $this->assertSame( + $expected, + $this->formatter->formatAssignment('variable', 'code', $semicolon, $format, $operator) + ); + } + + public function testFormatCallback() + { + $this->assertSame('variable_callback', $this->formatter->formatCallback('variable')); + } + + public function testFormatAssetCallback() + { + $this->assertSame('variable_callback', $this->formatter->formatAssetCallback($this->createVariableAssetMock())); + } + + /** + * @dataProvider formatAssetAssignmentProvider + */ + public function testFormatAssetAssignment($expected, $debug, $semicolon = true, $format = true, $operator = '=') + { + $this->formatter->setDebug($debug); + + $this->assertSame( + $expected, + $this->formatter->formatAssetAssignment( + $this->createVariableAssetMock(), + 'code', + $semicolon, + $format, + $operator + ) + ); + } + + /** + * @dataProvider formatContainerVariableProvider + */ + public function testFormatVariableAssignment($expected, $level = null, AbstractVariableAsset $asset = null) + { + $this->assertSame( + $expected, + $this->formatter->formatContainerVariable($this->createVariableAssetMock('base'), $level, $asset) + ); + } + + /** + * @dataProvider formatContainerAssignmentProvider + */ + public function testFormatContainerAssignment( + $expected, + $debug = false, + AbstractVariableAsset $asset = null, + $level = null, + $append = true, + $semicolon = true, + $format = true + ) { + $this->formatter->setDebug($debug); + + $this->assertSame( + $expected, + $this->formatter->formatContainerAssignment( + $this->createVariableAssetMock('base'), + 'code', + $level, + $asset, + $append, + $semicolon, + $format + ) + ); + } + + /** + * Gets the format seperator provider. + * + * @return array The format separator provider. + */ + public function formatSeparatorProvider() + { + return array( + array('', false), + array(' ', true), + ); + } + + /** + * Gets the format line provider. + * + * @return array The format line provider. + */ + public function formatLineProvider() + { + return array( + array('line', false), + array( + 'line +', + true, + ), + ); + } + + /** + * Gets the format indentation provider. + * + * @return array The format indentation provider. + */ + public function formatIndentationProvider() + { + return array( + array('', '', false), + array('', '', true), + array('', '', false, 2), + array('', '', true, 2), + array('code', 'code', false), + array(' code', 'code', true), + array('code', 'code', false, 2), + array(' code', 'code', true, 2), + array('code'.PHP_EOL, 'code'.PHP_EOL, false), + array(' code'.PHP_EOL, 'code'.PHP_EOL, true), + array('code'.PHP_EOL, 'code'.PHP_EOL, false, 2), + array(' code'.PHP_EOL, 'code'.PHP_EOL, true, 2), + array('code1'.PHP_EOL.'code2', 'code1'.PHP_EOL.'code2', false), + array(' code1'.PHP_EOL.' code2', 'code1'.PHP_EOL.'code2', true), + array('code1'.PHP_EOL.'code2', 'code1'.PHP_EOL.'code2', false, 2), + array(' code1'.PHP_EOL.' code2', 'code1'.PHP_EOL.'code2', true, 2), + ); + } + + /** + * Gets the format tag provider. + * + * @return array The format tag provider. + */ + public function formatTagProvider() + { + return array( + array('', false), + array( + ' +', + true, + ), + array('content', false, 4, 'content'), + array( + ' + content +', + true, + 4, + 'content', + ), + array( + ' + content +', + true, + 2, + 'content', + ), + array('content', false, 4, 'content', array('foo' => 'bar')), + array( + ' + content +', + true, + 4, + 'content', + array('foo' => 'bar'), + ), + array( + ' + content +', + true, + 2, + 'content', + array('foo' => 'bar'), + ), + array('', false, 4, null, array('foo' => 'bar'), true), + array( + ' +', + true, + 4, + null, + array('foo' => 'bar'), + true, + ), + array('content', false, 4, 'content', array('foo' => 'bar'), true), + array( + ' + content +', + true, + 4, + 'content', + array('foo' => 'bar'), + true, + ), + array( + ' + content +', + true, + 2, + 'content', + array('foo' => 'bar'), + true, + ), + ); + } + + /** + * Gets the format stylesheet provider. + * + * @return array The format stylesheet provider. + */ + public function formatStylesheetProvider() + { + return array( + array('', false), + array( + ' +', + true, + ), + array( + ' +', + true, + 2 + ), + ); + } + + /** + * Gets the format javascript provider. + * + * @return array The format javascript provider. + */ + public function formatJavascriptProvider() + { + return array( + array('', false), + array( + ' +', + true, + ), + array( + ' +', + true, + 2 + ), + ); + } + + /** + * Gets the format code provider. + * + * @return array The format code provider. + */ + public function formatCodeProvider() + { + return array( + array('code;', false), + array( + 'code; +', + true, + ), + array('code', false, false), + array( + 'code +', + true, + false, + ), + array('code;', false, true, false), + array('code;', true, true, false), + ); + } + + /** + * Gets the format ternary provider. + * + * @return array The format ternary provider. + */ + public function formatTernaryProvider() + { + return array( + array('condition?value1:value2;', false), + array( + 'condition ? value1 : value2; +', + true, + ), + array('condition?value1:value2', false, false), + array( + 'condition ? value1 : value2 +', + true, + false, + ), + array('condition?value1:value2', false, false, false), + array('condition ? value1 : value2', true, false, false), + ); + } + + /** + * Gets the if provider. + * + * @return array The if provider. + */ + public function formatIfProvider() + { + return array( + array('if(condition){code}', false), + array( + 'if (condition) { + code} +', + true, + ), + array('if(condition){code}', false, 2), + array( + 'if (condition) { + code} +', + true, + 2 + ), + array('if(condition){code}elseif(foo){bar}', false, 4, array('foo' => 'bar')), + array( + 'if (condition) { + code} elseif (foo) { + bar} +', + true, + 4, + array('foo' => 'bar') + ), + array( + 'if (condition) { + code} elseif (foo) { + bar} +', + true, + 2, + array('foo' => 'bar') + ), + array('if(condition){code}elseif(foo){bar}else{baz}', false, 4, array('foo' => 'bar'), 'baz'), + array( + 'if (condition) { + code} elseif (foo) { + bar} else { + baz} +', + true, + 4, + array('foo' => 'bar'), + 'baz' + ), + array( + 'if (condition) { + code} elseif (foo) { + bar} else { + baz} +', + true, + 2, + array('foo' => 'bar'), + 'baz' + ), + ); + } + + /** + * Gets the format source provider. + * + * @return array The format source provider. + */ + public function formatSourceProvider() + { + return array( + array('', false), + array( + ' +', + true, + ), + array( + 'var s=document.createElement("script");s.type="text/javascript";s.async=true;s.src="source";if(s.attachEvent){s.attachEvent("onreadystatechange",function(){if(s.readyState==="complete"){callback();}});}else{s.addEventListener("load",callback,false);}document.getElementsByTagName("head")[0].appendChild(s);', + false, + 4, + 'callback', + ), + array( + 'var s = document.createElement("script"); +s.type = "text/javascript"; +s.async = true; +s.src = "source"; +if (s.attachEvent) { + s.attachEvent("onreadystatechange", function () { + if (s.readyState === "complete") { + callback(); + } + }); +} else { + s.addEventListener("load", callback, false); +} +document.getElementsByTagName("head")[0].appendChild(s); +', + true, + 4, + 'callback' + ), + array( + 'var s = document.createElement("script"); +s.type = "text/javascript"; +s.async = true; +s.src = "source"; +if (s.attachEvent) { + s.attachEvent("onreadystatechange", function () { + if (s.readyState === "complete") { + callback(); + } + }); +} else { + s.addEventListener("load", callback, false); +} +document.getElementsByTagName("head")[0].appendChild(s); +', + true, + 2, + 'callback' + ), + ); + } + + /** + * Gets the format function provider. + * + * @return array The format function provider. + */ + public function formatFunctionProvider() + { + return array( + array('function(){code};', false), + array( + 'function () { + code}; +', + true, + ), + array('function(foo,bar){code};', false, 4, array('foo', 'bar')), + array( + 'function (foo, bar) { + code}; +', + true, + 4, + array('foo', 'bar'), + ), + array( + 'function (foo, bar) { + code}; +', + true, + 2, + array('foo', 'bar'), + ), + array('function baz(foo,bar){code};', false, 4, array('foo', 'bar'), 'baz'), + array( + 'function baz(foo, bar) { + code}; +', + true, + 4, + array('foo', 'bar'), + 'baz', + ), + array( + 'function baz(foo, bar) { + code}; +', + true, + 2, + array('foo', 'bar'), + 'baz', + ), + array('function baz(foo,bar){code}', false, 4, array('foo', 'bar'), 'baz', false), + array( + 'function baz(foo, bar) { + code} +', + true, + 4, + array('foo', 'bar'), + 'baz', + false, + ), + array( + 'function baz(foo, bar) { + code} +', + true, + 2, + array('foo', 'bar'), + 'baz', + false, + ), + array('function baz(foo,bar){code}', false, 4, array('foo', 'bar'), 'baz', false, false), + array( + 'function baz(foo, bar) {code} +', + true, + 4, + array('foo', 'bar'), + 'baz', + false, + false, + ), + array('function baz(foo,bar){code}', false, 4, array('foo', 'bar'), 'baz', false, false, false), + array('function baz(foo, bar) {code}', true, 4, array('foo', 'bar'), 'baz', false, false, false), + ); + } + + /** + * Gets the format function call provider. + * + * @return array The format function call provider. + */ + public function formatFunctionCallProvider() + { + return array( + array('name();', false), + array( + 'name(); +', + true, + ), + array('name(argument);', false, array('argument')), + array( + 'name(argument); +', + true, + array('argument'), + ), + array('name(argument1,argument2)', false, array('argument1', 'argument2'), false), + array( + 'name(argument1, argument2) +', + true, + array('argument1', 'argument2'), + false, + ), + array('name(argument1,argument2)', false, array('argument1', 'argument2'), false, false), + array('name(argument1, argument2)', true, array('argument1', 'argument2'), false, false), + ); + } + + /** + * Gets the format assignment provider. + * + * @return array The format assignment provider. + */ + public function formatAssignmentProvider() + { + return array( + array('variable=code;', false), + array( + 'variable = code; +', + true, + ), + array('variable=code', false, false), + array( + 'variable = code +', + true, + false, + ), + array('variable=code;', false, true, false), + array('variable = code;', true, true, false), + array('variable:code;', false, true, true, ':'), + array( + 'variable : code; +', + true, + true, + true, + ':', + ), + ); + } + + /** + * Gets the format asset assignment provider. + * + * @return array The format asset assignment provider. + */ + public function formatAssetAssignmentProvider() + { + return array( + array('variable=code;', false), + array( + 'variable = code; +', + true, + ), + array('variable=code', false, false), + array( + 'variable = code +', + true, + false, + ), + array('variable=code;', false, true, false), + array('variable = code;', true, true, false), + array('variable:code;', false, true, true, ':'), + array( + 'variable : code; +', + true, + true, + true, + ':', + ), + ); + } + + /** + * Gets the format container variable provider. + * + * @return array The format container variable provider. + */ + public function formatContainerVariableProvider() + { + return array( + array('base_container'), + array('base_container.level', 'level'), + array('base_container.variable', null, $this->createVariableAssetMock()), + array('base_container.level.variable', 'level', $this->createVariableAssetMock()), + ); + } + + /** + * Gets the format container assignment provider. + * + * @return array The format container assignment provider. + */ + public function formatContainerAssignmentProvider() + { + return array( + array('base_container=code;'), + array( + 'base_container = code; +', + true, + ), + array('base_container.variable=variable=code;', false, $this->createVariableAssetMock()), + array( + 'base_container.variable = variable = code; +', + true, + $this->createVariableAssetMock(), + ), + array('base_container.level=code;', false, null, 'level'), + array( + 'base_container.level = code; +', + true, + null, + 'level', + ), + array('base_container.level.variable=variable=code;', false, $this->createVariableAssetMock(), 'level'), + array( + 'base_container.level.variable = variable = code; +', + true, + $this->createVariableAssetMock(), + 'level', + ), + array('base_container=variable=code;', false, $this->createVariableAssetMock(), null, false), + array( + 'base_container = variable = code; +', + true, + $this->createVariableAssetMock(), + null, + false, + ), + array('base_container.level=variable=code;', false, $this->createVariableAssetMock(), 'level', false), + array( + 'base_container.level = variable = code; +', + true, + $this->createVariableAssetMock(), + 'level', + false, + ), + array( + 'base_container.level.variable=variable=code', + false, + $this->createVariableAssetMock(), + 'level', + true, + false, + ), + array( + 'base_container.level.variable = variable = code +', + true, + $this->createVariableAssetMock(), + 'level', + true, + false, + ), + array( + 'base_container.level.variable = variable = code;', + true, + $this->createVariableAssetMock(), + 'level', + true, + true, + false + ), + ); + } + + /** + * Creates a variable asset mock. + * + * @param string $variable The variable. + * + * @return \Ivory\GoogleMap\Assets\AbstractVariableAsset|\PHPUnit_Framework_MockObject_MockObject The variable asset mock. + */ + protected function createVariableAssetMock($variable = 'variable') + { + $variableAsset = parent::createVariableAssetMock(); + $variableAsset + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $variableAsset; + } +} diff --git a/tests/Helpers/Subscribers/Layers/KmlLayerSubscriberTest.php b/tests/Helpers/Subscribers/Layers/KmlLayerSubscriberTest.php new file mode 100644 index 00000000..af1461cd --- /dev/null +++ b/tests/Helpers/Subscribers/Layers/KmlLayerSubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Layers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Layers\KmlLayerSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Kml layer subscriber test. + * + * @author GeLo + */ +class KmlLayerSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Layers\KmlLayerSubscriber */ + protected $kmlLayerSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Layers\KmlLayerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $kmlLayerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Layers\KmlLayerRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $kmlLayerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->kmlLayerSubscriber = new KmlLayerSubscriber( + $this->formatter, + $this->kmlLayerAggregator = $this->createKmlLayerAggregatorMock(), + $this->kmlLayerRenderer = $this->createKmlLayerRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->kmlLayerRenderer); + unset($this->kmlLayerAggregator); + unset($this->kmlLayerSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->kmlLayerSubscriber); + } + + public function testDefaultState() + { + $this->kmlLayerSubscriber = new KmlLayerSubscriber(); + + $this->assertKmlLayerAggregatorInstance($this->kmlLayerSubscriber->getKmlLayerAggregator()); + $this->assertKmlLayerRendererInstance($this->kmlLayerSubscriber->getKmlLayerRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->kmlLayerAggregator, $this->kmlLayerSubscriber->getKmlLayerAggregator()); + $this->assertSame($this->kmlLayerRenderer, $this->kmlLayerSubscriber->getKmlLayerRenderer()); + } + + public function testSetKmlLayerAggregator() + { + $this->kmlLayerSubscriber->setKmlLayerAggregator($kmlLayerAggregator = $this->createKmlLayerAggregatorMock()); + + $this->assertSame($kmlLayerAggregator, $this->kmlLayerSubscriber->getKmlLayerAggregator()); + } + + public function testSetKmlLayerRenderer() + { + $this->kmlLayerSubscriber->setKmlLayerRenderer($kmlLayerRenderer = $this->createKmlLayerRendererMock()); + + $this->assertSame($kmlLayerRenderer, $this->kmlLayerSubscriber->getKmlLayerRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = KmlLayerSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_LAYERS_KML_LAYER, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_LAYERS_KML_LAYER]); + } + + public function testOnMap() + { + $this->kmlLayerAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($kmlLayer = $this->createKmlLayerMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('layers.kml_layers'), + $this->identicalTo($kmlLayer) + ) + ->will($this->returnValue($code = 'code')); + + $this->kmlLayerRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($kmlLayer), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->kmlLayerSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Layers/LayersSubscriberTest.php b/tests/Helpers/Subscribers/Layers/LayersSubscriberTest.php new file mode 100644 index 00000000..0aa26d36 --- /dev/null +++ b/tests/Helpers/Subscribers/Layers/LayersSubscriberTest.php @@ -0,0 +1,67 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Layers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Layers\LayersSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Layers subscriber test. + * + * @author GeLo + */ +class LayersSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Layers\LayersSubscriber */ + protected $layersSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->layersSubscriber = new LayersSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->layersSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = LayersSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_LAYERS, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_LAYERS]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(1)) + ->method('dispatch') + ->will($this->returnValueMap(array(array(MapEvents::JAVASCRIPT_LAYERS_KML_LAYER, $mapEvent)))); + + $this->layersSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/MapBoundSubscriberTest.php b/tests/Helpers/Subscribers/MapBoundSubscriberTest.php new file mode 100644 index 00000000..b409bcb0 --- /dev/null +++ b/tests/Helpers/Subscribers/MapBoundSubscriberTest.php @@ -0,0 +1,173 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapBoundSubscriber; + +/** + * Map bound subscriber test. + * + * @author GeLo + */ +class MapBoundSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapBoundSubscriber */ + protected $mapBoundSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapBoundRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $mapBoundRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapBoundSubscriber = new MapBoundSubscriber( + $this->formatter, + $this->mapBoundRenderer = $this->createMapBoundRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapBoundRenderer); + unset($this->mapBoundSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->mapBoundSubscriber); + } + + public function testDefaultState() + { + $this->mapBoundSubscriber = new MapBoundSubscriber(); + + $this->assertFormatterInstance($this->mapBoundSubscriber->getFormatter()); + $this->assertMapBoundRendererInstance($this->mapBoundSubscriber->getMapBoundRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->mapBoundSubscriber->getFormatter()); + $this->assertSame($this->mapBoundRenderer, $this->mapBoundSubscriber->getMapBoundRenderer()); + } + + public function testSetMapBoundRenderer() + { + $this->mapBoundSubscriber->setMapBoundRenderer($mapBoundRenderer = $this->createMapBoundRendererMock()); + + $this->assertSame($mapBoundRenderer, $this->mapBoundSubscriber->getMapBoundRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapBoundSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH_MAP_BOUND, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH_MAP_BOUND]); + } + + /** + * @dataProvider onMapProvider + */ + public function testOnMap($autoZoom = false) + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map = $this->createMapMock($autoZoom))); + + if ($autoZoom) { + $this->mapBoundRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($map)) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render)) + ->will($this->returnValue($code = 'code')); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + } else { + $mapEvent + ->expects($this->never()) + ->method('addCode'); + } + + $this->mapBoundSubscriber->onMap($mapEvent); + } + + /** + * Gets the on map provider. + * + * @return array The on map provider. + */ + public function onMapProvider() + { + return array( + array(), + array(true), + ); + } + + /** + * Creates a map mock. + * + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock($autoZoom = false) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($autoZoom))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock($autoZoom = false) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('isAutoZoom') + ->will($this->returnValue($autoZoom)); + + return $overlays; + } +} diff --git a/tests/Helpers/Subscribers/MapCenterSubscriberTest.php b/tests/Helpers/Subscribers/MapCenterSubscriberTest.php new file mode 100644 index 00000000..b809bd20 --- /dev/null +++ b/tests/Helpers/Subscribers/MapCenterSubscriberTest.php @@ -0,0 +1,173 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapCenterSubscriber; + +/** + * Map center subscriber test. + * + * @author GeLo + */ +class MapCenterSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapCenterSubscriber */ + protected $mapCenterSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapCenterRenderer */ + protected $mapCenterRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapCenterSubscriber = new MapCenterSubscriber( + $this->formatter, + $this->mapCenterRenderer = $this->createMapCenterRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapCenterRenderer); + unset($this->mapCenterSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->mapCenterSubscriber); + } + + public function testDefaultState() + { + $this->mapCenterSubscriber = new MapCenterSubscriber(); + + $this->assertFormatterInstance($this->mapCenterSubscriber->getFormatter()); + $this->assertMapCenterRendererInstance($this->mapCenterSubscriber->getMapCenterRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->mapCenterSubscriber->getFormatter()); + $this->assertSame($this->mapCenterRenderer, $this->mapCenterSubscriber->getMapCenterRenderer()); + } + + public function testSetMapCenterRenderer() + { + $this->mapCenterSubscriber->setMapCenterRenderer($mapCenterRenderer = $this->createMapCenterRendererMock()); + + $this->assertSame($mapCenterRenderer, $this->mapCenterSubscriber->getMapCenterRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapCenterSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH_MAP_CENTER, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH_MAP_CENTER]); + } + + /** + * @dataProvider onMapProvider + */ + public function testOnMap($autoZoom = false) + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map = $this->createMapMock($autoZoom))); + + if (!$autoZoom) { + $this->mapCenterRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($map)) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render)) + ->will($this->returnValue($code = 'code')); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + } else { + $mapEvent + ->expects($this->never()) + ->method('addCode'); + } + + $this->mapCenterSubscriber->onMap($mapEvent); + } + + /** + * Gets the on map provider. + * + * @return array The on map provider. + */ + public function onMapProvider() + { + return array( + array(), + array(true), + ); + } + + /** + * Creates a map mock. + * + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock($autoZoom = false) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($autoZoom))); + + return $map; + } + + /** + * Creates an overlays mock. + * + * @param boolean $autoZoom The auto zoom. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock($autoZoom = false) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('isAutoZoom') + ->will($this->returnValue($autoZoom)); + + return $overlays; + } +} diff --git a/tests/Helpers/Subscribers/MapContainerSubscriberTest.php b/tests/Helpers/Subscribers/MapContainerSubscriberTest.php new file mode 100644 index 00000000..cd016c8e --- /dev/null +++ b/tests/Helpers/Subscribers/MapContainerSubscriberTest.php @@ -0,0 +1,114 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapContainerSubscriber; + +/** + * Map container subscriber test. + * + * @author GeLo + */ +class MapContainerSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapContainerSubscriber */ + protected $mapContainerSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapContainerRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $mapContainerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapContainerSubscriber = new MapContainerSubscriber( + $this->formatter, + $this->mapContainerRenderer = $this->createMapContainerRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapContainerRenderer); + unset($this->mapContainerSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->mapContainerSubscriber); + } + + public function testDefaultState() + { + $this->assertFormatterInstance($this->mapContainerSubscriber->getFormatter()); + $this->assertMapContainerRendererInstance($this->mapContainerSubscriber->getContainerRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->mapContainerSubscriber->getFormatter()); + $this->assertSame($this->mapContainerRenderer, $this->mapContainerSubscriber->getContainerRenderer()); + } + + public function testSetContainerRenderer() + { + $this->mapContainerSubscriber->setContainerRenderer( + $containerRenderer = $this->createMapContainerRendererMock() + ); + + $this->assertSame($containerRenderer, $this->mapContainerSubscriber->getContainerRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapContainerSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_INIT_CONTAINER, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_INIT_CONTAINER]); + } + + public function testOnMap() + { + $this->mapContainerRenderer + ->expects($this->once()) + ->method('render') + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with($this->identicalTo($map = $this->createMapMock()), $this->identicalTo($render)) + ->will($this->returnValue($code = 'code')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->mapContainerSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/MapFinishSubscriberTest.php b/tests/Helpers/Subscribers/MapFinishSubscriberTest.php new file mode 100644 index 00000000..222a1661 --- /dev/null +++ b/tests/Helpers/Subscribers/MapFinishSubscriberTest.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapFinishSubscriber; + +/** + * Map finish subscriber test. + * + * @author GeLo + */ +class MapFinishSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapFinishSubscriber */ + protected $mapFinishSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapFinishSubscriber = new MapFinishSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapFinishSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapFinishSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(5)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE, $mapEvent), + array(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN, $mapEvent), + array(MapEvents::JAVASCRIPT_FINISH_EXTENDABLE, $mapEvent), + array(MapEvents::JAVASCRIPT_FINISH_MAP_BOUND, $mapEvent), + array(MapEvents::JAVASCRIPT_FINISH_MAP_CENTER, $mapEvent), + ))); + + $this->mapFinishSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/MapHtmlSubscriberTest.php b/tests/Helpers/Subscribers/MapHtmlSubscriberTest.php new file mode 100644 index 00000000..1cced021 --- /dev/null +++ b/tests/Helpers/Subscribers/MapHtmlSubscriberTest.php @@ -0,0 +1,159 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapHtmlSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Map html subscriber test. + * + * @author GeLo + */ +class MapHtmlSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapHtmlSubscriber */ + protected $mapHtmlSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapHtmlSubscriber = new MapHtmlSubscriber($this->formatter); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapHtmlSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->mapHtmlSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapHtmlSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::HTML, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::HTML]); + } + + /** + * @dataProvider onMapProvider + */ + public function testOnMap($style, $width = null, $height = null) + { + $this->formatter + ->expects($this->once()) + ->method('formatTag') + ->with( + $this->identicalTo('div'), + $this->identicalTo(null), + $this->identicalTo(array( + 'id' => 'id', + 'style' => $style, + )) + ) + ->will($this->returnValue($code = 'code')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($this->createMapMock($width, $height))); + + $mapEvent + ->expects($this->any()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->mapHtmlSubscriber->onMap($mapEvent); + } + + /** + * Gets the on map provider. + * + * @return array The on map provider. + */ + public function onMapProvider() + { + $format = 'width:%s;height:%s;'; + + $defaultWidth = '300px'; + $defaultHeight = '300px'; + + $customWidth = '100px'; + $customHeight = '200px'; + + return array( + array(sprintf($format, $defaultWidth, $defaultHeight)), + array(sprintf($format, $customWidth, $defaultHeight), $customWidth), + array(sprintf($format, $defaultWidth, $customHeight), null, $customHeight), + array(sprintf($format, $customWidth, $customHeight), $customWidth, $customHeight), + ); + } + + /** + * Creates a map mock. + * + * @param string $width The width. + * @param string $height The height. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock($width = null, $height = null) + { + $map = parent::createMapMock(); + + if ($width === null) { + $width = '300px'; + } + + if ($height === null) { + $height = '300px'; + } + + $map + ->expects($this->any()) + ->method('getHtmlContainerId') + ->will($this->returnValue('id')); + + $map + ->expects($this->exactly(2)) + ->method('hasStylesheetOption') + ->will($this->returnValueMap(array( + array('width', $width !== null), + array('height', $height !== null), + ))); + + $map + ->expects($this->exactly(2)) + ->method('getStylesheetOption') + ->will($this->returnValueMap(array( + array('width', $width), + array('height', $height), + ))); + + return $map; + } +} diff --git a/tests/Helpers/Subscribers/MapInitSubscriberTest.php b/tests/Helpers/Subscribers/MapInitSubscriberTest.php new file mode 100644 index 00000000..78e1cbda --- /dev/null +++ b/tests/Helpers/Subscribers/MapInitSubscriberTest.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapInitSubscriber; + +/** + * Map init subscriber test. + * + * @author GeLo + */ +class MapInitSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapInitSubscriber */ + protected $mapInitSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->mapInitSubscriber = new MapInitSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->mapInitSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapInitSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_INIT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_INIT]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(2)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT, $mapEvent), + array(MapEvents::JAVASCRIPT_INIT_CONTAINER, $mapEvent), + ))); + + $this->mapInitSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/MapJavascriptSubscriberTest.php b/tests/Helpers/Subscribers/MapJavascriptSubscriberTest.php new file mode 100644 index 00000000..a39f8e2e --- /dev/null +++ b/tests/Helpers/Subscribers/MapJavascriptSubscriberTest.php @@ -0,0 +1,190 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapJavascriptSubscriber; + +/** + * Map javascript subscriber test. + * + * @author GeLo + */ +class MapJavascriptSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapJavascriptSubscriber */ + protected $mapJavascriptSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapJavascriptSubscriber = new MapJavascriptSubscriber($this->formatter); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapJavascriptSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapJavascriptSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT_MAP, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT_MAP]); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT]); + } + + public function testOnApi() + { + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(3)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE, $apiEvent), + array(ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW, $apiEvent), + array(ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER, $apiEvent), + ))); + + $apiEvent + ->expects($this->once()) + ->method('getItems') + ->with($this->identicalTo(ApiEvent::MAP)) + ->will($this->returnValue(array($map = $this->createMapMock($libraries = array('foo'))))); + + $this->formatter + ->expects($this->once()) + ->method('formatAssetCallback') + ->with($this->identicalTo($map)) + ->will($this->returnValue($callback = 'callback')); + + $apiEvent + ->expects($this->once()) + ->method('addCallback') + ->with($this->identicalTo($callback)); + + $apiEvent + ->expects($this->once()) + ->method('setLanguage') + ->with($this->identicalTo('fr')); + + $apiEvent + ->expects($this->once()) + ->method('addLibraries') + ->with($this->identicalTo($libraries)); + + $this->mapJavascriptSubscriber->onApi($apiEvent); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(7)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_INIT, $mapEvent), + array(MapEvents::JAVASCRIPT_BASE, $mapEvent), + array(MapEvents::JAVASCRIPT_MAP, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS, $mapEvent), + array(MapEvents::JAVASCRIPT_LAYERS, $mapEvent), + array(MapEvents::JAVASCRIPT_EVENTS, $mapEvent), + array(MapEvents::JAVASCRIPT_FINISH, $mapEvent), + ))); + + $mapEvent + ->expects($this->any()) + ->method('getCode') + ->will($this->returnValue($code = 'code')); + + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map = $this->createMapMock())); + + $this->formatter + ->expects($this->once()) + ->method('formatAssetCallback') + ->with($this->identicalTo($map)) + ->will($this->returnValue($callback = 'callback')); + + $this->formatter + ->expects($this->once()) + ->method('formatFunction') + ->with( + $this->identicalTo($code), + $this->identicalTo(array()), + $this->identicalTo($callback) + ) + ->will($this->returnValue($function = 'function')); + + $this->formatter + ->expects($this->once()) + ->method('formatJavascript') + ->with($this->identicalTo($function)) + ->will($this->returnValue($javascript = 'javascript')); + + $mapEvent + ->expects($this->once()) + ->method('setCode') + ->will($this->returnValue($javascript)); + + $this->mapJavascriptSubscriber->onMap($mapEvent); + } + + /** + * Creates a map mock. + * + * @param array $libraries The libraries. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(array $libraries = array()) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getLibraries') + ->will($this->returnValue($libraries)); + + $map + ->expects($this->any()) + ->method('getLanguage') + ->will($this->returnValue('fr')); + + return $map; + } +} diff --git a/tests/Helpers/Subscribers/MapStylesheetSubscriberTest.php b/tests/Helpers/Subscribers/MapStylesheetSubscriberTest.php new file mode 100644 index 00000000..0ea54ba9 --- /dev/null +++ b/tests/Helpers/Subscribers/MapStylesheetSubscriberTest.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapStylesheetSubscriber; + +/** + * Map stylesheet subscriber test. + * + * @author GeLo + */ +class MapStylesheetSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapStylesheetSubscriber */ + protected $mapStylesheetSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapStylesheetSubscriber = new MapStylesheetSubscriber($this->formatter); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapStylesheetSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->mapStylesheetSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapStylesheetSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::STYLESHEET, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::STYLESHEET]); + } + + public function testOnMap() + { + $this->formatter + ->expects($this->once()) + ->method('formatStylesheet') + ->with($this->identicalTo('#map', array('foo' => 'bar'))) + ->will($this->returnValue($code = 'code')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map = $this->createMapMock())); + + $mapEvent + ->expects($this->any()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->mapStylesheetSubscriber->onMap($mapEvent); + } + + /** + * {@inheritdoc} + */ + protected function createMapMock() + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getHtmlContainerId') + ->will($this->returnValue('map')); + + $map + ->expects($this->any()) + ->method('hasStylesheetOptions') + ->will($this->returnValue(true)); + + $map + ->expects($this->any()) + ->method('getStylesheetOptions') + ->will($this->returnValue(array('foo' => 'bar'))); + + return $map; + } +} diff --git a/tests/Helpers/Subscribers/MapSubscriberTest.php b/tests/Helpers/Subscribers/MapSubscriberTest.php new file mode 100644 index 00000000..66b3ea80 --- /dev/null +++ b/tests/Helpers/Subscribers/MapSubscriberTest.php @@ -0,0 +1,121 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\MapSubscriber; + +/** + * Map subscriber test. + * + * @author GeLo + */ +class MapSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\MapSubscriber */ + protected $mapSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\MapRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $mapRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->mapSubscriber = new MapSubscriber( + $this->formatter, + $this->mapRenderer = $this->createMapRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->mapRenderer); + unset($this->mapSubscriber); + } + + public function testUnheritance() + { + $this->assertFormatterSubscriberInstance($this->mapSubscriber); + } + + public function testDefaultState() + { + $this->mapSubscriber = new MapSubscriber(); + + $this->assertFormatterInstance($this->mapSubscriber->getFormatter()); + $this->assertMapRendererInstance($this->mapSubscriber->getMapRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->mapSubscriber->getFormatter()); + $this->assertSame($this->mapRenderer, $this->mapSubscriber->getMapRenderer()); + } + + public function testSetMapRenderer() + { + $this->mapSubscriber->setMapRenderer($mapRenderer = $this->createMapRendererMock()); + + $this->assertSame($mapRenderer, $this->mapSubscriber->getMapRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MapSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_MAP, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_MAP]); + } + + public function testOnMap() + { + $this->mapRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render), + $this->identicalTo('map'), + $this->identicalTo($map), + $this->identicalTo(false) + ) + ->will($this->returnValue($code = 'code')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->any()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->mapSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/CircleSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/CircleSubscriberTest.php new file mode 100644 index 00000000..9b891259 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/CircleSubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\CircleSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Circle subscriber test. + * + * @author GeLo + */ +class CircleSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\CircleSubscriber */ + protected $circleSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\CircleAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $circleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\CircleRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $circleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->circleSubscriber = new CircleSubscriber( + $this->formatter, + $this->circleAggregator = $this->createCircleAggregatorMock(), + $this->circleRenderer = $this->createCircleRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->circleRenderer); + unset($this->circleAggregator); + unset($this->circleSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->circleSubscriber); + } + + public function testDefaultState() + { + $this->circleSubscriber = new CircleSubscriber(); + + $this->assertCircleAggregatorInstance($this->circleSubscriber->getCircleAggregator()); + $this->assertCircleRendererInstance($this->circleSubscriber->getCircleRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->circleAggregator, $this->circleSubscriber->getCircleAggregator()); + $this->assertSame($this->circleRenderer, $this->circleSubscriber->getCircleRenderer()); + } + + public function testSetCircleAggregator() + { + $this->circleSubscriber->setCircleAggregator($circleAggregator = $this->createCircleAggregatorMock()); + + $this->assertSame($circleAggregator, $this->circleSubscriber->getCircleAggregator()); + } + + public function testSetCircleRenderer() + { + $this->circleSubscriber->setCircleRenderer($circleRenderer = $this->createCircleRendererMock()); + + $this->assertSame($circleRenderer, $this->circleSubscriber->getCircleRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = CircleSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE]); + } + + public function testOnMap() + { + $this->circleAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($circle = $this->createCircleMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.circles'), + $this->identicalTo($circle) + ) + ->will($this->returnValue($code = 'code')); + + $this->circleRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($circle), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->circleSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/EncodedPolylineSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/EncodedPolylineSubscriberTest.php new file mode 100644 index 00000000..93e63e76 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/EncodedPolylineSubscriberTest.php @@ -0,0 +1,184 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\EncodedPolylineSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Encoded polyline subscriber test. + * + * @author GeLo + */ +class EncodedPolylineSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\EncodedPolylineSubscriber */ + protected $encodedPolylineSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\EncodedPolylineAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $encodedPolylineAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\EncodedPolylineRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $encodedPolylineRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->encodedPolylineSubscriber = new EncodedPolylineSubscriber( + $this->formatter, + $this->encodedPolylineAggregator = $this->createEncodedPolylineAggregatorMock(), + $this->encodedPolylineRenderer = $this->createEncodedPolylineRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->encodedPolylineRenderer); + unset($this->encodedPolylineAggregator); + unset($this->encodedPolylineSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->encodedPolylineSubscriber); + } + + public function testDefaultState() + { + $this->encodedPolylineSubscriber = new EncodedPolylineSubscriber(); + + $this->assertEncodedPolylineAggregatorInstance( + $this->encodedPolylineSubscriber->getEncodedPolylineAggregator() + ); + + $this->assertEncodedPolylineRendererInstance($this->encodedPolylineSubscriber->getEncodedPolylineRenderer()); + } + + public function testInitialState() + { + $this->assertSame( + $this->encodedPolylineAggregator, + $this->encodedPolylineSubscriber->getEncodedPolylineAggregator() + ); + + $this->assertSame( + $this->encodedPolylineRenderer, + $this->encodedPolylineSubscriber->getEncodedPolylineRenderer() + ); + } + + public function testSetEncodedPolylineAggregator() + { + $this->encodedPolylineSubscriber->setEncodedPolylineAggregator( + $encodedPolylineAggregator = $this->createEncodedPolylineAggregatorMock() + ); + + $this->assertSame($encodedPolylineAggregator, $this->encodedPolylineSubscriber->getEncodedPolylineAggregator()); + } + + public function testSetEncodedPolylineRenderer() + { + $this->encodedPolylineSubscriber->setEncodedPolylineRenderer( + $encodedPolylineRenderer = $this->createEncodedPolylineRendererMock() + ); + + $this->assertSame($encodedPolylineRenderer, $this->encodedPolylineSubscriber->getEncodedPolylineRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = EncodedPolylineSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT_MAP_ENCODED_POLYLINE]); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE]); + } + + public function testOnApi() + { + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->once()) + ->method('getItems') + ->with($this->identicalTo(ApiEvent::MAP)) + ->will($this->returnValue(array($map = $this->createMapMock()))); + + $this->encodedPolylineAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map)) + ->will($this->returnValue(array($encodedPolyline = $this->createEncodedPolylineMock()))); + + $apiEvent + ->expects($this->once()) + ->method('addLibrary') + ->with($this->identicalTo('geometry')); + + $this->encodedPolylineSubscriber->onApi($apiEvent); + } + + public function testOnMap() + { + $this->encodedPolylineAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($encodedPolyline = $this->createEncodedPolylineMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.encoded_polylines'), + $this->identicalTo($encodedPolyline) + ) + ->will($this->returnValue($code = 'code')); + + $this->encodedPolylineRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($encodedPolyline), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->encodedPolylineSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/ExtendableSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/ExtendableSubscriberTest.php new file mode 100644 index 00000000..1790b316 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/ExtendableSubscriberTest.php @@ -0,0 +1,167 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\ExtendableSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Map extendable subscriber test. + * + * @author GeLo + */ +class ExtendableSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\ExtendableSubscriber */ + protected $extendableSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\ExtendableAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $extendableAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\ExtendableRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $extendableRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->extendableSubscriber = new ExtendableSubscriber( + $this->formatter, + $this->extendableAggregator = $this->createExtendableAggregatorMock(), + $this->extendableRenderer = $this->createExtendableRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->extendableRenderer); + unset($this->extendableAggregator); + unset($this->extendableSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->extendableSubscriber); + } + + public function testDefaultState() + { + $this->extendableSubscriber = new ExtendableSubscriber(); + + $this->assertFormatterInstance($this->extendableSubscriber->getFormatter()); + $this->assertExtendableAggregatorInstance($this->extendableSubscriber->getExtendableAggregator()); + $this->assertExtendableRendererInstance($this->extendableSubscriber->getExtendableRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->extendableSubscriber->getFormatter()); + $this->assertSame($this->extendableAggregator, $this->extendableSubscriber->getExtendableAggregator()); + $this->assertSame($this->extendableRenderer, $this->extendableSubscriber->getExtendableRenderer()); + } + + public function testSetFormatter() + { + $this->extendableSubscriber->setFormatter($formatter = $this->createFormatterMock()); + + $this->assertSame($formatter, $this->extendableSubscriber->getFormatter()); + } + + public function testSetExtendableAggregator() + { + $this->extendableSubscriber->setExtendableAggregator( + $extendableAggregator = $this->createExtendableAggregatorMock() + ); + + $this->assertSame($extendableAggregator, $this->extendableSubscriber->getExtendableAggregator()); + } + + public function testSetExtendableRenderer() + { + $this->extendableSubscriber->setExtendableRenderer($extendableRenderer = $this->createExtendableRendererMock()); + + $this->assertSame($extendableRenderer, $this->extendableSubscriber->getExtendableRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = ExtendableSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH_EXTENDABLE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH_EXTENDABLE]); + } + + public function testOnMap() + { + $this->extendableAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($bound = $this->createBoundMock()))) + ->will($this->returnValue(array($extendable = $this->createExtendableMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render = 'render')) + ->will($this->returnValue($code = 'code')); + + $this->extendableRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($extendable), + $this->identicalTo($bound) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->extendableSubscriber->onMap($mapEvent); + } + + /** + * Creates a map mock. + * + * @param \Ivory\GoogleMap\Base\Bound|null $bound The bound. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(Bound $bound = null) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getBound') + ->will($this->returnValue($bound)); + + return $map; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/GroundOverlaySubscriberTest.php b/tests/Helpers/Subscribers/Overlays/GroundOverlaySubscriberTest.php new file mode 100644 index 00000000..b9e69df3 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/GroundOverlaySubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\GroundOverlaySubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Ground overlay subscriber test. + * + * @author GeLo + */ +class GroundOverlaySubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\GroundOverlaySubscriber */ + protected $groundOverlaySubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\GroundOverlayAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $groundOverlayAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\GroundOverlayRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $groundOverlayRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->groundOverlaySubscriber = new GroundOverlaySubscriber( + $this->formatter, + $this->groundOverlayAggregator = $this->createGroundOverlayAggregatorMock(), + $this->groundOverlayRenderer = $this->createGroundOverlayRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->groundOverlayRenderer); + unset($this->groundOverlayAggregator); + unset($this->groundOverlaySubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->groundOverlaySubscriber); + } + + public function testDefaultState() + { + $this->groundOverlaySubscriber = new GroundOverlaySubscriber(); + + $this->assertGroundOverlayAggregatorInstance($this->groundOverlaySubscriber->getGroundOverlayAggregator()); + $this->assertGroundOverlayRendererInstance($this->groundOverlaySubscriber->getGroundOverlayRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->groundOverlayAggregator, $this->groundOverlaySubscriber->getGroundOverlayAggregator()); + $this->assertSame($this->groundOverlayRenderer, $this->groundOverlaySubscriber->getGroundOverlayRenderer()); + } + + public function testSetGroundOverlayAggregator() + { + $this->groundOverlaySubscriber->setGroundOverlayAggregator($groundOverlayAggregator = $this->createGroundOverlayAggregatorMock()); + + $this->assertSame($groundOverlayAggregator, $this->groundOverlaySubscriber->getGroundOverlayAggregator()); + } + + public function testSetGroundOverlayRenderer() + { + $this->groundOverlaySubscriber->setGroundOverlayRenderer($groundOverlayRenderer = $this->createGroundOverlayRendererMock()); + + $this->assertSame($groundOverlayRenderer, $this->groundOverlaySubscriber->getGroundOverlayRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = GroundOverlaySubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY]); + } + + public function testOnMap() + { + $this->groundOverlayAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($groundOverlay = $this->createGroundOverlayMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.ground_overlays'), + $this->identicalTo($groundOverlay) + ) + ->will($this->returnValue($code = 'code')); + + $this->groundOverlayRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($groundOverlay), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->groundOverlaySubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/IconSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/IconSubscriberTest.php new file mode 100644 index 00000000..48bedb45 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/IconSubscriberTest.php @@ -0,0 +1,139 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\IconSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Icon subscriber test. + * + * @author GeLo + */ +class IconSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\IconSubscriber */ + protected $iconSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\IconAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $iconAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\IconRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $iconRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->iconSubscriber = new IconSubscriber( + $this->formatter, + $this->iconAggregator = $this->createIconAggregatorMock(), + $this->iconRenderer = $this->createIconRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->iconRenderer); + unset($this->iconAggregator); + unset($this->iconSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->iconSubscriber); + } + + public function testDefaultState() + { + $this->iconSubscriber = new IconSubscriber(); + + $this->assertIconAggregatorInstance($this->iconSubscriber->getIconAggregator()); + $this->assertIconRendererInstance($this->iconSubscriber->getIconRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->iconAggregator, $this->iconSubscriber->getIconAggregator()); + $this->assertSame($this->iconRenderer, $this->iconSubscriber->getIconRenderer()); + } + + public function testSetIconAggregator() + { + $this->iconSubscriber->setIconAggregator($iconAggregator = $this->createIconAggregatorMock()); + + $this->assertSame($iconAggregator, $this->iconSubscriber->getIconAggregator()); + } + + public function testSetIconRenderer() + { + $this->iconSubscriber->setIconRenderer($iconRenderer = $this->createIconRendererMock()); + + $this->assertSame($iconRenderer, $this->iconSubscriber->getIconRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = IconSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_ICON, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_ICON]); + } + + public function testOnMap() + { + $this->iconAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($icon = $this->createIconMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.icons'), + $this->identicalTo($icon) + ) + ->will($this->returnValue($code = 'code')); + + $this->iconRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($icon)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->iconSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/InfoWIndowSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/InfoWIndowSubscriberTest.php new file mode 100644 index 00000000..63a55ed7 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/InfoWIndowSubscriberTest.php @@ -0,0 +1,232 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowSubscriber; +use Ivory\GoogleMap\Overlays\InfoWindowType; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Info window subscriber test. + * + * @author GeLo + */ +class InfoWIndowSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowSubscriber */ + protected $infoWindowSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowRenderer; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoBoxRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoBoxRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->infoWindowSubscriber = new InfoWindowSubscriber( + $this->formatter, + $this->infoWindowAggregator = $this->createInfoWindowAggregatorMock(), + $this->infoWindowRenderer = $this->createInfoWindowRendererMock(), + $this->infoBoxRenderer = $this->createInfoBoxRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->infoBoxRenderer); + unset($this->infoWindowRenderer); + unset($this->infoWindowAggregator); + unset($this->infoWindowSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->infoWindowSubscriber); + } + + public function testDefaultState() + { + $this->infoWindowSubscriber = new InfoWindowSubscriber(); + + $this->assertInfoWindowAggregatorInstance($this->infoWindowSubscriber->getInfoWindowAggregator()); + $this->assertInfoWindowRendererInstance($this->infoWindowSubscriber->getInfoWindowRenderer()); + $this->assertInfoBoxRendererInstance($this->infoWindowSubscriber->getInfoBoxRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->infoWindowAggregator, $this->infoWindowSubscriber->getInfoWindowAggregator()); + $this->assertSame($this->infoWindowRenderer, $this->infoWindowSubscriber->getInfoWindowRenderer()); + $this->assertSame($this->infoBoxRenderer, $this->infoWindowSubscriber->getInfoBoxRenderer()); + } + + public function testSetInfoWindowAggregator() + { + $this->infoWindowSubscriber->setInfoWindowAggregator($infoWindowAggregator = $this->createInfoWindowAggregatorMock()); + + $this->assertSame($infoWindowAggregator, $this->infoWindowSubscriber->getInfoWindowAggregator()); + } + + public function testSetInfoWindowRenderer() + { + $this->infoWindowSubscriber->setInfoWindowRenderer($infoWindowRenderer = $this->createInfoWindowRendererMock()); + + $this->assertSame($infoWindowRenderer, $this->infoWindowSubscriber->getInfoWindowRenderer()); + } + + public function testSetInfoBoxRenderer() + { + $this->infoWindowSubscriber->setInfoBoxRenderer($infoBoxRenderer = $this->createInfoBoxRendererMock()); + + $this->assertSame($infoBoxRenderer, $this->infoWindowSubscriber->getInfoBoxRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = InfoWindowSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT_MAP_INFO_WINDOW]); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW]); + } + + public function testOnApi() + { + $this->infoWindowAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($this->createMarkerClusterMock()))) + ->will($this->returnValue(array($this->createInfoWindowMock(InfoWindowType::INFOBOX)))); + + $this->infoBoxRenderer + ->expects($this->once()) + ->method('renderSource') + ->will($this->returnValue($source = 'source')); + + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->once()) + ->method('getItems') + ->with($this->identicalTo(ApiEvent::MAP)) + ->will($this->returnValue(array($map))); + + $apiEvent + ->expects($this->once()) + ->method('addSource') + ->with($this->identicalTo($source)); + + $this->infoWindowSubscriber->onApi($apiEvent); + } + + public function testOnMap() + { + $this->infoWindowAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array( + $infoWindow = $this->createInfoWindowMock(), + $infoBox = $this->createInfoWindowMock(InfoWindowType::INFOBOX), + ))); + + $this->formatter + ->expects($this->exactly(2)) + ->method('formatContainerAssignment') + ->will($this->returnValueMap(array( + array( + $map, + $renderInfoWindow = 'renderInfoWindow', + 'overlays.info_windows', + $infoWindow, + true, + true, + true, + $codeInfoWindow = 'codeInfoWindow', + ), + array( + $map, + $renderInfoBox = 'renderInfoBox', + 'overlays.info_boxes', + $infoBox, + true, + true, + true, + $codeInfoBox = 'codeInfoBox', + ), + ))); + + $this->infoWindowRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($infoWindow)) + ->will($this->returnValue($renderInfoWindow)); + + $this->infoBoxRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($infoBox)) + ->will($this->returnValue($renderInfoBox)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->exactly(2)) + ->method('addCode') + ->withConsecutive( + array($this->identicalTo($codeInfoWindow)), + array($this->identicalTo($codeInfoBox)) + ); + + $this->infoWindowSubscriber->onMap($mapEvent); + } + + /** + * Creates an info window mock. + * + * @param string $type The type. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock($type = InfoWindowType::DEFAULT_) + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue($type)); + + return $infoWindow; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriberTest.php new file mode 100644 index 00000000..87be0c04 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/InfoWindowCloseSubscriberTest.php @@ -0,0 +1,188 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowCloseSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Info window close subscriber test. + * + * @author GeLo + */ +class InfoWindowCloseSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Extra\MapInfoWindowCloseSubscriber */ + protected $infoWindowCloseSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowCloseRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowCloseRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->infoWindowCloseSubscriber = new InfoWindowCloseSubscriber( + $this->formatter, + $this->infoWindowAggregator = $this->createInfoWindowAggregatorMock(), + $this->infoWindowCloseRenderer = $this->createInfoWindowCloseRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->infoWindowCloseRenderer); + unset($this->infoWindowAggregator); + unset($this->infoWindowCloseSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->infoWindowCloseSubscriber); + } + + public function testDefaultState() + { + $this->infoWindowCloseSubscriber = new InfoWindowCloseSubscriber(); + + $this->assertFormatterInstance($this->infoWindowCloseSubscriber->getFormatter()); + $this->assertInfoWindowAggregatorInstance($this->infoWindowCloseSubscriber->getInfoWindowAggregator()); + $this->assertInfoWindowCloseRendererInstance($this->infoWindowCloseSubscriber->getInfoWindowCloseRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->infoWindowCloseSubscriber->getFormatter()); + $this->assertSame($this->infoWindowAggregator, $this->infoWindowCloseSubscriber->getInfoWindowAggregator()); + + $this->assertSame( + $this->infoWindowCloseRenderer, + $this->infoWindowCloseSubscriber->getInfoWindowCloseRenderer() + ); + } + + public function testSetInfoWindowAggregator() + { + $this->infoWindowCloseSubscriber->setInfoWindowAggregator( + $infoWindowAggregator = $this->createInfoWindowAggregatorMock() + ); + + $this->assertSame($infoWindowAggregator, $this->infoWindowCloseSubscriber->getInfoWindowAggregator()); + } + + public function testSetInfoWindwoCloseRenderer() + { + $this->infoWindowCloseSubscriber->setInfoWindowCloseRenderer( + $infoWindowCloseRenderer = $this->createInfoWindowCloseRendererMock() + ); + + $this->assertSame($infoWindowCloseRenderer, $this->infoWindowCloseSubscriber->getInfoWindowCloseRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = InfoWindowCloseSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_CLOSE]); + } + + public function testOnMap() + { + $this->infoWindowAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array( + $autoCloseInfoWindow = $this->createInfoWindowMock(), + $this->createInfoWindowMock(false), + ))); + + $this->infoWindowCloseRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($autoCloseInfoWindow)) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render)) + ->will($this->returnValue($code = 'code')); + + $this->formatter + ->expects($this->once()) + ->method('formatFunction') + ->with( + $this->identicalTo($code), + $this->identicalTo(array()), + $this->identicalTo(null), + $this->identicalTo(false), + $this->identicalTo(true), + $this->identicalTo(false) + ) + ->will($this->returnValue($function = 'function')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($function), + $this->identicalTo('functions.info_windows.close') + ) + ->will($this->returnValue($container = 'container')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($container)); + + $this->infoWindowCloseSubscriber->onMap($mapEvent); + } + + /** + * Creates an info window mock. + * + * @param boolean $autoClose TRUE if it is auto closed else FALSE. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock($autoClose = true) + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('isAutoClose') + ->will($this->returnValue($autoClose)); + + return $infoWindow; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriberTest.php new file mode 100644 index 00000000..43d5f4b7 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/InfoWindowOpenSubscriberTest.php @@ -0,0 +1,168 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\InfoWindowOpenSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Info window open subscriber test. + * + * @author GeLo + */ +class InfoWindowOpenSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Extra\MapInfoWindowOpenSubscriber */ + protected $infoWindowOpenSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\InfoWindowAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowOpenRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->infoWindowOpenSubscriber = new InfoWindowOpenSubscriber( + $this->formatter, + $this->infoWindowAggregator = $this->createInfoWindowAggregatorMock(), + $this->infoWindowOpenRenderer = $this->createInfoWindowOpenRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->infoWindowOpenRenderer); + unset($this->infoWindowAggregator); + unset($this->infoWindowOpenSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->infoWindowOpenSubscriber); + } + + public function testDefaultState() + { + $this->infoWindowOpenSubscriber = new InfoWindowOpenSubscriber(); + + $this->assertFormatterInstance($this->infoWindowOpenSubscriber->getFormatter()); + $this->assertInfoWindowAggregatorInstance($this->infoWindowOpenSubscriber->getInfoWindowAggregator()); + $this->assertInfoWindowOpenRendererInstance($this->infoWindowOpenSubscriber->getInfoWindowOpenRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->infoWindowOpenSubscriber->getFormatter()); + $this->assertSame($this->infoWindowAggregator, $this->infoWindowOpenSubscriber->getInfoWindowAggregator()); + + $this->assertSame( + $this->infoWindowOpenRenderer, + $this->infoWindowOpenSubscriber->getInfoWindowOpenRenderer() + ); + } + + public function testSetInfoWindowAggregator() + { + $this->infoWindowOpenSubscriber->setInfoWindowAggregator( + $infoWindowAggregator = $this->createInfoWindowAggregatorMock() + ); + + $this->assertSame($infoWindowAggregator, $this->infoWindowOpenSubscriber->getInfoWindowAggregator()); + } + + public function testSetInfoWindwoOpenRenderer() + { + $this->infoWindowOpenSubscriber->setInfoWindowOpenRenderer( + $infoWindowOpenRenderer = $this->createInfoWindowOpenRendererMock() + ); + + $this->assertSame($infoWindowOpenRenderer, $this->infoWindowOpenSubscriber->getInfoWindowOpenRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = InfoWindowOpenSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_FINISH_INFO_WINDOW_OPEN]); + } + + public function testOnMap() + { + $this->infoWindowAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array( + $openInfoWindow = $this->createInfoWindowMock(), + $this->createInfoWindowMock(false), + ))); + + $this->infoWindowOpenRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($openInfoWindow), + $this->identicalTo($map) + ) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render)) + ->will($this->returnValue($code = 'code')); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->infoWindowOpenSubscriber->onMap($mapEvent); + } + + /** + * Creates an info window mock. + * + * @param boolean $open TRUE if it is opened else FALSE. + * + * @return \Ivory\GoogleMap\Overlays\InfoWindow|\PHPUnit_Framework_MockObject_MockObject The info window mock. + */ + protected function createInfoWindowMock($open = true) + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('isOpen') + ->will($this->returnValue($open)); + + return $infoWindow; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/MarkerClusterSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/MarkerClusterSubscriberTest.php new file mode 100644 index 00000000..68c205c2 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/MarkerClusterSubscriberTest.php @@ -0,0 +1,232 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerClusterSubscriber; +use Ivory\GoogleMap\Overlays\MarkerCluster; +use Ivory\GoogleMap\Overlays\MarkerClusterType; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Marker cluster subscriber test. + * + * @author GeLo + */ +class MarkerClusterSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerClusterSubscriber */ + protected $markerClusterSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerClusterRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerClusterRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->markerClusterSubscriber = new MarkerClusterSubscriber( + $this->formatter, + $this->markerClusterRenderer = $this->createMarkerClusterRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->markerClusterRenderer); + unset($this->markerClusterSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->markerClusterSubscriber); + } + + public function testDefaultState() + { + $this->markerClusterSubscriber = new MarkerClusterSubscriber(); + + $this->assertMarkerClusterRendererInstance($this->markerClusterSubscriber->getMarkerClusterRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->markerClusterRenderer, $this->markerClusterSubscriber->getMarkerClusterRenderer()); + } + + public function testSetMarkerClusterRenderer() + { + $this->markerClusterSubscriber->setMarkerClusterRenderer($markerClusterRenderer = $this->createMarkerClusterRendererMock()); + + $this->assertSame($markerClusterRenderer, $this->markerClusterSubscriber->getMarkerClusterRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MarkerClusterSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT_MAP_MARKER_CLUSTER]); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER]); + } + + public function testOnApi() + { + $this->markerClusterRenderer + ->expects($this->once()) + ->method('renderSource') + ->will($this->returnValue($source = 'source')); + + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->once()) + ->method('getItems') + ->with($this->identicalTo(ApiEvent::MAP)) + ->will($this->returnValue(array($map = $this->createMapMock($this->createMarkerClusterMock())))); + + $apiEvent + ->expects($this->once()) + ->method('addSource') + ->with($this->identicalTo($source)); + + $this->markerClusterSubscriber->onApi($apiEvent); + } + + public function testOnMap() + { + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map = $this->createMapMock($markerCluster = $this->createMarkerClusterMock())), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.marker_cluster'), + $this->identicalTo($markerCluster), + $this->identicalTo(false) + ) + ->will($this->returnValue($code = 'code')); + + $this->formatter + ->expects($this->exactly(2)) + ->method('formatContainerVariable') + ->will($this->returnValueMap(array( + array( + $map, + 'functions.to_array', + null, + $functionCallName = 'map.functions.to_array', + ), + array( + $map, + 'overlays.markers', + null, + $functionCallArgument = 'map.overlays.markers', + ), + ))); + + $this->formatter + ->expects($this->once()) + ->method('formatFunctionCall') + ->with( + $this->identicalTo($functionCallName), + $this->identicalTo(array($functionCallArgument)), + $this->identicalTo(false), + $this->identicalTo(false) + ) + ->will($this->returnValue($functionCall = 'map.functions.to_array(map.overlays.markers)')); + + $this->markerClusterRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($markerCluster), + $this->identicalTo($map), + $this->identicalTo($functionCall) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->markerClusterSubscriber->onMap($mapEvent); + } + + /** + * Creates a map mock. + * + * @param \Ivory\GoogleMap\Overlays\MarkerCluster|null $markerCluster The marker cluster. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(MarkerCluster $markerCluster = null) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($markerCluster))); + + return $map; + } + + /** + * {@inheritdoc} + */ + protected function createMarkerClusterMock() + { + $markerCluster = parent::createMarkerClusterMock(); + $markerCluster + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue(MarkerClusterType::MARKER_CLUSTER)); + + return $markerCluster; + } + + /** + * Creates an overlays mock. + * + * @param \Ivory\GoogleMap\Overlays\MarkerCluster|null $markerCluster The marker cluster. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock(MarkerCluster $markerCluster = null) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getMarkerCluster') + ->will($this->returnValue($markerCluster)); + + return $overlays; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriberTest.php new file mode 100644 index 00000000..6989c916 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/MarkerOpenEventSubscriberTest.php @@ -0,0 +1,257 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Events\Event; +use Ivory\GoogleMap\Events\Events; +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerOpenEventSubscriber; +use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Marker open event subscriber test. + * + * @author GeLo + */ +class MarkerOpenEventSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerOpenEventSubscriber */ + protected $markerOpenEventSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\InfoWindowOpenRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $infoWindowOpenRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->markerOpenEventSubscriber = new MarkerOpenEventSubscriber( + $this->formatter, + $this->markerAggregator = $this->createMarkerAggregatorMock(), + $this->infoWindowOpenRenderer = $this->createInfoWindowOpenRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->infoWindowOpenRenderer); + unset($this->markerAggregator); + unset($this->markerOpenEventSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->markerOpenEventSubscriber); + } + + public function testDefaultState() + { + $this->markerOpenEventSubscriber = new MarkerOpenEventSubscriber(); + + $this->assertFormatterInstance($this->markerOpenEventSubscriber->getFormatter()); + $this->assertMarkerAggregatorInstance($this->markerOpenEventSubscriber->getMarkerAggregator()); + $this->assertInfoWindowOpenRendererInstance($this->markerOpenEventSubscriber->getInfoWindowOpenRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->markerOpenEventSubscriber->getFormatter()); + $this->assertSame($this->markerAggregator, $this->markerOpenEventSubscriber->getMarkerAggregator()); + + $this->assertSame( + $this->infoWindowOpenRenderer, + $this->markerOpenEventSubscriber->getInfoWindowOpenRenderer() + ); + } + + public function testSetMarkerAggregator() + { + $this->markerOpenEventSubscriber->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->markerOpenEventSubscriber->getMarkerAggregator()); + } + + public function testSetInfoWindowOpenRenderer() + { + $this->markerOpenEventSubscriber->setInfoWindowOpenRenderer( + $infoWindowOpenRenderer = $this->createInfoWindowOpenRendererMock() + ); + + $this->assertSame($infoWindowOpenRenderer, $this->markerOpenEventSubscriber->getInfoWindowOpenRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MarkerOpenEventSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_INIT_MARKER_OPEN_EVENT]); + } + + public function testOnMap() + { + $this->markerAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($events = $this->createEventsMock()))) + ->will($this->returnValue(array( + $marker = $this->createMarkerMock($infoWindow = $this->createInfoWindowMock()), + ))); + + $this->infoWindowOpenRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($infoWindow), + $this->identicalTo($map), + $this->identicalTo($marker) + ) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerVariable') + ->with( + $this->identicalTo($map), + $this->identicalTo('functions.info_windows.close') + ) + ->will($this->returnValue($closeInfoWindow = 'map.functions.info_windows.close')); + + $this->formatter + ->expects($this->once()) + ->method('formatFunctionCall') + ->with($this->identicalTo($closeInfoWindow)) + ->will($this->returnValue($closeInfoWindowCode = 'map.functions.info_windows.close();')); + + $this->formatter + ->expects($this->once()) + ->method('formatCode') + ->with($this->identicalTo($render)) + ->will($this->returnValue($openInfoWindowCode = 'info_window.open();')); + + $this->formatter + ->expects($this->once()) + ->method('formatFunction') + ->with( + $this->identicalTo($closeInfoWindowCode.$openInfoWindowCode), + $this->identicalTo(array()), + $this->identicalTo(null), + $this->identicalTo(false) + ) + ->will($this->returnValue($handle = 'function () {'.$closeInfoWindowCode.$openInfoWindowCode.'}')); + + $events + ->expects($this->once()) + ->method('addEvent') + ->with($this->callback(function ($event) use ($handle) { + return $event instanceof Event + && $event->getInstance() === 'marker' + && $event->getEventName() === 'open_event' + && $event->getHandle() === $handle; + })); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $this->markerOpenEventSubscriber->onMap($mapEvent); + } + + /** + * {@inheritdoc} + */ + protected function createInfoWindowMock() + { + $infoWindow = parent::createInfoWindowMock(); + $infoWindow + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('info_window')); + + $infoWindow + ->expects($this->any()) + ->method('isAutoOpen') + ->will($this->returnValue(true)); + + $infoWindow + ->expects($this->any()) + ->method('getOpenEvent') + ->will($this->returnValue('open_event')); + + return $infoWindow; + } + + /** + * Creates a map mock. + * + * @param \Ivory\HttpAdapter\Event\Events $events The events. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock(Events $events = null) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('map')); + + $map + ->expects($this->any()) + ->method('getEvents') + ->will($this->returnValue($events)); + + return $map; + } + + /** + * Creates a marker mock. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow|null $infoWindow The info window. + * + * @return \Ivory\GoogleMap\Overlays\Marker|\PHPUnit_Framework_MockObject_MockObject The marker mock. + */ + protected function createMarkerMock(InfoWindow $infoWindow = null) + { + $marker = parent::createMarkerMock(); + $marker + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue('marker')); + + $marker + ->expects($this->any()) + ->method('hasInfoWindow') + ->will($this->returnValue(true)); + + $marker + ->expects($this->any()) + ->method('getInfoWindow') + ->will($this->returnValue($infoWindow)); + + return $marker; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/MarkerShapeSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/MarkerShapeSubscriberTest.php new file mode 100644 index 00000000..c96fd3d3 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/MarkerShapeSubscriberTest.php @@ -0,0 +1,143 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerShapeSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Marker shape subscriber test. + * + * @author GeLo + */ +class MarkerShapeSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerShapeSubscriber */ + protected $markerShapeSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerShapeAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerShapeAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerShapeRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerShapeRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->markerShapeSubscriber = new MarkerShapeSubscriber( + $this->formatter, + $this->markerShapeAggregator = $this->createMarkerShapeAggregatorMock(), + $this->markerShapeRenderer = $this->createMarkerShapeRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->markerShapeRenderer); + unset($this->markerShapeAggregator); + unset($this->markerShapeSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->markerShapeSubscriber); + } + + public function testDefaultState() + { + $this->markerShapeSubscriber = new MarkerShapeSubscriber(); + + $this->assertMarkerShapeAggregatorInstance($this->markerShapeSubscriber->getMarkerShapeAggregator()); + $this->assertMarkerShapeRendererInstance($this->markerShapeSubscriber->getMarkerShapeRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->markerShapeAggregator, $this->markerShapeSubscriber->getMarkerShapeAggregator()); + $this->assertSame($this->markerShapeRenderer, $this->markerShapeSubscriber->getMarkerShapeRenderer()); + } + + public function testSetMarkerShapeAggregator() + { + $this->markerShapeSubscriber->setMarkerShapeAggregator( + $markerShapeAggregator = $this->createMarkerShapeAggregatorMock() + ); + + $this->assertSame($markerShapeAggregator, $this->markerShapeSubscriber->getMarkerShapeAggregator()); + } + + public function testSetMarkerShapeRenderer() + { + $this->markerShapeSubscriber->setMarkerShapeRenderer( + $markerShapeRenderer = $this->createMarkerShapeRendererMock() + ); + + $this->assertSame($markerShapeRenderer, $this->markerShapeSubscriber->getMarkerShapeRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MarkerShapeSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE]); + } + + public function testOnMap() + { + $this->markerShapeAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($markerShape = $this->createMarkerShapeMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.marker_shapes'), + $this->identicalTo($markerShape) + ) + ->will($this->returnValue($code = 'code')); + + $this->markerShapeRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($markerShape)) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->markerShapeSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/MarkerSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/MarkerSubscriberTest.php new file mode 100644 index 00000000..27484239 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/MarkerSubscriberTest.php @@ -0,0 +1,213 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerSubscriber; +use Ivory\GoogleMap\Overlays\MarkerClusterType; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Marker subscriber test. + * + * @author GeLo + */ +class MarkerSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\MarkerSubscriber */ + protected $markerSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\MarkerAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\MarkerRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $markerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->markerSubscriber = new MarkerSubscriber( + $this->formatter, + $this->markerAggregator = $this->createMarkerAggregatorMock(), + $this->markerRenderer = $this->createMarkerRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->markerRenderer); + unset($this->markerAggregator); + unset($this->markerSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->markerSubscriber); + } + + public function testDefaultState() + { + $this->markerSubscriber = new MarkerSubscriber(); + + $this->assertMarkerAggregatorInstance($this->markerSubscriber->getMarkerAggregator()); + $this->assertMarkerRendererInstance($this->markerSubscriber->getMarkerRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->markerAggregator, $this->markerSubscriber->getMarkerAggregator()); + $this->assertSame($this->markerRenderer, $this->markerSubscriber->getMarkerRenderer()); + } + + public function testSetMarkerAggregator() + { + $this->markerSubscriber->setMarkerAggregator($markerAggregator = $this->createMarkerAggregatorMock()); + + $this->assertSame($markerAggregator, $this->markerSubscriber->getMarkerAggregator()); + } + + public function testSetMarkerRenderer() + { + $this->markerSubscriber->setMarkerRenderer($markerRenderer = $this->createMarkerRendererMock()); + + $this->assertSame($markerRenderer, $this->markerSubscriber->getMarkerRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = MarkerSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_MARKER, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_MARKER]); + } + + /** + * @dataProvider onMapProvider + */ + public function testOnMap($markerClusterType, $useMap) + { + $this->markerAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock($markerClusterType))) + ->will($this->returnValue(array($marker = $this->createMarkerMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.markers'), + $this->identicalTo($marker) + ) + ->will($this->returnValue($code = 'code')); + + $this->markerRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($marker), + $this->identicalTo($useMap ? $map : null) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->markerSubscriber->onMap($mapEvent); + } + + /** + * Gets the on map provider. + * + * @return array The on map provider. + */ + public function onMapProvider() + { + return array( + array(MarkerClusterType::DEFAULT_, true), + array(MarkerClusterType::MARKER_CLUSTER, false), + ); + } + + /** + * Creates a map mock. + * + * @param string $markerClusterType The marker cluster type. + * + * @return \Ivory\GoogleMap\Map|\PHPUnit_Framework_MockObject_MockObject The map mock. + */ + protected function createMapMock($markerClusterType = MarkerClusterType::DEFAULT_) + { + $map = parent::createMapMock(); + $map + ->expects($this->any()) + ->method('getOverlays') + ->will($this->returnValue($this->createOverlaysMock($markerClusterType))); + + return $map; + } + + /** + * Creates a marker cluster mock. + * + * @param string $type The type. + * + * @return \Ivory\GoogleMap\Overlays\MarkerCluster|\PHPUnit_Framework_MockObject_MockObject The marker cluster mock. + */ + protected function createMarkerClusterMock($type = MarkerClusterType::DEFAULT_) + { + $markerCluster = parent::createMarkerClusterMock(); + $markerCluster + ->expects($this->any()) + ->method('getType') + ->will($this->returnValue($type)); + + return $markerCluster; + } + + /** + * Creates an overlays mock. + * + * @param string $markerClusterType The marker cluster type. + * + * @return \Ivory\GoogleMap\Overlays\Overlays|\PHPUnit_Framework_MockObject_MockObject The overlays mock. + */ + protected function createOverlaysMock($markerClusterType = MarkerClusterType::DEFAULT_) + { + $overlays = parent::createOverlaysMock(); + $overlays + ->expects($this->any()) + ->method('getMarkerCluster') + ->will($this->returnValue($this->createMarkerClusterMock($markerClusterType))); + + return $overlays; + } +} diff --git a/tests/Helpers/Subscribers/Overlays/OverlaysSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/OverlaysSubscriberTest.php new file mode 100644 index 00000000..b1183483 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/OverlaysSubscriberTest.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\OverlaysSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Overlays subscriber test. + * + * @author GeLo + */ +class OverlaysSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\OverlaysSubscriber */ + protected $overlaysSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->overlaysSubscriber = new OverlaysSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->overlaysSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = OverlaysSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS]); + } + + public function testOnMap() + { + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(11)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(MapEvents::JAVASCRIPT_OVERLAYS_CIRCLE, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_ENCODED_POLYLINE, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_GROUND_OVERLAY, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_INFO_WINDOW, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_ICON, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_SHAPE, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_MARKER, $mapEvent), + array(MapEvents::JAVASCRIPT_OVERLAYS_MARKER_CLUSTER, $mapEvent), + ))); + + $this->overlaysSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/PolygonSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/PolygonSubscriberTest.php new file mode 100644 index 00000000..4053dde8 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/PolygonSubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolygonSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Polygon subscriber test. + * + * @author GeLo + */ +class PolygonSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolygonSubscriber */ + protected $polygonSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolygonAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $polygonAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolygonRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $polygonRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->polygonSubscriber = new PolygonSubscriber( + $this->formatter, + $this->polygonAggregator = $this->createPolygonAggregatorMock(), + $this->polygonRenderer = $this->createPolygonRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->polygonRenderer); + unset($this->polygonAggregator); + unset($this->polygonSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->polygonSubscriber); + } + + public function testDefaultState() + { + $this->polygonSubscriber = new PolygonSubscriber(); + + $this->assertPolygonAggregatorInstance($this->polygonSubscriber->getPolygonAggregator()); + $this->assertPolygonRendererInstance($this->polygonSubscriber->getPolygonRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->polygonAggregator, $this->polygonSubscriber->getPolygonAggregator()); + $this->assertSame($this->polygonRenderer, $this->polygonSubscriber->getPolygonRenderer()); + } + + public function testSetPolygonAggregator() + { + $this->polygonSubscriber->setPolygonAggregator($polygonAggregator = $this->createPolygonAggregatorMock()); + + $this->assertSame($polygonAggregator, $this->polygonSubscriber->getPolygonAggregator()); + } + + public function testSetPolygonRenderer() + { + $this->polygonSubscriber->setPolygonRenderer($polygonRenderer = $this->createPolygonRendererMock()); + + $this->assertSame($polygonRenderer, $this->polygonSubscriber->getPolygonRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = PolygonSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_POLYGON, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_POLYGON]); + } + + public function testOnMap() + { + $this->polygonAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($polygon = $this->createPolygonMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.polygons'), + $this->identicalTo($polygon) + ) + ->will($this->returnValue($code = 'code')); + + $this->polygonRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($polygon), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->polygonSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/PolylineSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/PolylineSubscriberTest.php new file mode 100644 index 00000000..e8dd0bf9 --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/PolylineSubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolylineSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Polyline subscriber test. + * + * @author GeLo + */ +class PolylineSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\PolylineSubscriber */ + protected $polylineSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\PolylineAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $polylineAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\PolylineRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $polylineRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->polylineSubscriber = new PolylineSubscriber( + $this->formatter, + $this->polylineAggregator = $this->createPolylineAggregatorMock(), + $this->polylineRenderer = $this->createPolylineRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->polylineRenderer); + unset($this->polylineAggregator); + unset($this->polylineSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->polylineSubscriber); + } + + public function testDefaultState() + { + $this->polylineSubscriber = new PolylineSubscriber(); + + $this->assertPolylineAggregatorInstance($this->polylineSubscriber->getPolylineAggregator()); + $this->assertPolylineRendererInstance($this->polylineSubscriber->getPolylineRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->polylineAggregator, $this->polylineSubscriber->getPolylineAggregator()); + $this->assertSame($this->polylineRenderer, $this->polylineSubscriber->getPolylineRenderer()); + } + + public function testSetPolylineAggregator() + { + $this->polylineSubscriber->setPolylineAggregator($polylineAggregator = $this->createPolylineAggregatorMock()); + + $this->assertSame($polylineAggregator, $this->polylineSubscriber->getPolylineAggregator()); + } + + public function testSetPolylineRenderer() + { + $this->polylineSubscriber->setPolylineRenderer($polylineRenderer = $this->createPolylineRendererMock()); + + $this->assertSame($polylineRenderer, $this->polylineSubscriber->getPolylineRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = PolylineSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_POLYLINE]); + } + + public function testOnMap() + { + $this->polylineAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($polyline = $this->createPolylineMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.polylines'), + $this->identicalTo($polyline) + ) + ->will($this->returnValue($code = 'code')); + + $this->polylineRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($polyline), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->polylineSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Overlays/RectangleSubscriberTest.php b/tests/Helpers/Subscribers/Overlays/RectangleSubscriberTest.php new file mode 100644 index 00000000..c9b7670b --- /dev/null +++ b/tests/Helpers/Subscribers/Overlays/RectangleSubscriberTest.php @@ -0,0 +1,142 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Overlays; + +use Ivory\GoogleMap\Helpers\MapEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Overlays\RectangleSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Rectangle subscriber test. + * + * @author GeLo + */ +class RectangleSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Overlays\RectangleSubscriber */ + protected $rectangleSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Overlays\RectangleAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $rectangleAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Overlays\RectangleRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $rectangleRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->rectangleSubscriber = new RectangleSubscriber( + $this->formatter, + $this->rectangleAggregator = $this->createRectangleAggregatorMock(), + $this->rectangleRenderer = $this->createRectangleRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->rectangleRenderer); + unset($this->rectangleAggregator); + unset($this->rectangleSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->rectangleSubscriber); + } + + public function testDefaultState() + { + $this->rectangleSubscriber = new RectangleSubscriber(); + + $this->assertRectangleAggregatorInstance($this->rectangleSubscriber->getRectangleAggregator()); + $this->assertRectangleRendererInstance($this->rectangleSubscriber->getRectangleRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->rectangleAggregator, $this->rectangleSubscriber->getRectangleAggregator()); + $this->assertSame($this->rectangleRenderer, $this->rectangleSubscriber->getRectangleRenderer()); + } + + public function testSetRectangleAggregator() + { + $this->rectangleSubscriber->setRectangleAggregator($rectangleAggregator = $this->createRectangleAggregatorMock()); + + $this->assertSame($rectangleAggregator, $this->rectangleSubscriber->getRectangleAggregator()); + } + + public function testSetRectangleRenderer() + { + $this->rectangleSubscriber->setRectangleRenderer($rectangleRenderer = $this->createRectangleRendererMock()); + + $this->assertSame($rectangleRenderer, $this->rectangleSubscriber->getRectangleRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = RectangleSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE, $subscribedEvents); + $this->assertSame('onMap', $subscribedEvents[MapEvents::JAVASCRIPT_OVERLAYS_RECTANGLE]); + } + + public function testOnMap() + { + $this->rectangleAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($map = $this->createMapMock())) + ->will($this->returnValue(array($rectangle = $this->createRectangleMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($map), + $this->identicalTo($render = 'render'), + $this->identicalTo('overlays.rectangles'), + $this->identicalTo($rectangle) + ) + ->will($this->returnValue($code = 'code')); + + $this->rectangleRenderer + ->expects($this->once()) + ->method('render') + ->with( + $this->identicalTo($rectangle), + $this->identicalTo($map) + ) + ->will($this->returnValue($render)); + + $mapEvent = $this->createMapEventMock(); + $mapEvent + ->expects($this->any()) + ->method('getMap') + ->will($this->returnValue($map)); + + $mapEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->rectangleSubscriber->onMap($mapEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteBaseSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteBaseSubscriberTest.php new file mode 100644 index 00000000..bdc486f5 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteBaseSubscriberTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBaseSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Autocomplete base subscriber test. + * + * @author GeLo + */ +class AutocompleteBaseSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBaseSubscriber */ + protected $autocompleteBaseSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->autocompleteBaseSubscriber = new AutocompleteBaseSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->autocompleteBaseSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteBaseSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_BASE, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_BASE]); + } + + public function testOnAutocomplete() + { + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(2)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE, $placesAutocompleteEvent), + array(PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND, $placesAutocompleteEvent), + ))); + + $this->autocompleteBaseSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteBoundSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteBoundSubscriberTest.php new file mode 100644 index 00000000..68122111 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteBoundSubscriberTest.php @@ -0,0 +1,141 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBoundSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete bound subscriber test. + * + * @author GeLo + */ +class AutocompleteBoundSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteBoundSubscriber */ + protected $boundSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\AutocompleteBoundAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\BoundRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $boundRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->boundSubscriber = new AutocompleteBoundSubscriber( + $this->formatter, + $this->boundAggregator = $this->createAutocompleteBoundAggregatorMock(), + $this->boundRenderer = $this->createBoundRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->boundRenderer); + unset($this->boundAggregator); + unset($this->boundSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->boundSubscriber); + } + + public function testDefaultState() + { + $this->boundSubscriber = new AutocompleteBoundSubscriber(); + + $this->assertFormatterInstance($this->boundSubscriber->getFormatter()); + $this->assertAutocompleteBoundAggregatorInstance($this->boundSubscriber->getBoundAggregator()); + $this->assertBoundRendererInstance($this->boundSubscriber->getBoundRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->boundSubscriber->getFormatter()); + $this->assertSame($this->boundAggregator, $this->boundSubscriber->getBoundAggregator()); + $this->assertSame($this->boundRenderer, $this->boundSubscriber->getBoundRenderer()); + } + + public function testSetBoundAggregator() + { + $this->boundSubscriber->setBoundAggregator($boundAggregator = $this->createAutocompleteBoundAggregatorMock()); + + $this->assertSame($boundAggregator, $this->boundSubscriber->getBoundAggregator()); + } + + public function testSetBoundRenderer() + { + $this->boundSubscriber->setBoundRenderer($boundRenderer = $this->createBoundRendererMock()); + + $this->assertSame($boundRenderer, $this->boundSubscriber->getBoundRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteBoundSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_BASE_BOUND]); + } + + public function testOnAutocomplete() + { + $this->boundAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($autocomplete = $this->createAutocompleteMock())) + ->will($this->returnValue(array($bound = $this->createBoundMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($autocomplete), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.bounds'), + $this->identicalTo($bound) + ) + ->will($this->returnValue($code = 'code')); + + $this->boundRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($bound)) + ->will($this->returnValue($render)); + + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($autocomplete)); + + $placesAutocompleteEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->boundSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteContainerSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteContainerSubscriberTest.php new file mode 100644 index 00000000..661fde23 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteContainerSubscriberTest.php @@ -0,0 +1,120 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteContainerSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete container subscriber test. + * + * @author GeLo + */ +class AutocompleteContainerSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteContainerSubscriber */ + protected $containerSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteContainerRenderer */ + protected $containerRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->containerSubscriber = new AutocompleteContainerSubscriber( + $this->formatter, + $this->containerRenderer = $this->createAutocompleteContainerRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->containerRenderer); + unset($this->containerSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->containerSubscriber); + } + + public function testDefaultState() + { + $this->containerSubscriber = new AutocompleteContainerSubscriber(); + + $this->assertFormatterInstance($this->containerSubscriber->getFormatter()); + $this->assertAutocompleteContainerRendererInstance($this->containerSubscriber->getContainerRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->containerSubscriber->getFormatter()); + $this->assertSame($this->containerRenderer, $this->containerSubscriber->getContainerRenderer()); + } + + public function testSetContainerRenderer() + { + $this->containerSubscriber->setContainerRenderer( + $containerRenderer = $this->createAutocompleteContainerRendererMock() + ); + + $this->assertSame($containerRenderer, $this->containerSubscriber->getContainerRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteContainerSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER]); + } + + public function testOnAutocomplete() + { + $this->containerRenderer + ->expects($this->once()) + ->method('render') + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($autocomplete = $this->createAutocompleteMock()), + $this->identicalTo($render) + ) + ->will($this->returnValue($code = 'code')); + + $autocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $autocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($autocomplete)); + + $autocompleteEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->containerSubscriber->onAutocomplete($autocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriberTest.php new file mode 100644 index 00000000..d580f554 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteCoordinateSubscriberTest.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Base; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteCoordinateSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete coordinate subscriber test. + * + * @author GeLo + */ +class AutocompleteCoordinateSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteCoordinateSubscriber */ + protected $coordinateSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Aggregators\Places\CoordinateAggregator|\PHPUnit_Framework_MockObject_MockObject */ + protected $coordinateAggregator; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Base\CoordinateRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $coordinateRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->coordinateSubscriber = new AutocompleteCoordinateSubscriber( + $this->formatter, + $this->coordinateAggregator = $this->createAutocompleteCoordinateAggregatorMock(), + $this->coordinateRenderer = $this->createCoordinateRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->coordinateRenderer); + unset($this->coordinateAggregator); + unset($this->coordinateSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->coordinateSubscriber); + } + + public function testDefaultState() + { + $this->coordinateSubscriber = new AutocompleteCoordinateSubscriber(); + + $this->assertFormatterInstance($this->coordinateSubscriber->getFormatter()); + $this->assertAutocompleteCoordinateAggregatorInstance($this->coordinateSubscriber->getCoordinateAggregator()); + $this->assertCoordinateRendererInstance($this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->coordinateSubscriber->getFormatter()); + $this->assertSame($this->coordinateAggregator, $this->coordinateSubscriber->getCoordinateAggregator()); + $this->assertSame($this->coordinateRenderer, $this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testSetCoordinateAggregator() + { + $this->coordinateSubscriber->setCoordinateAggregator( + $coordinateAggregator = $this->createAutocompleteCoordinateAggregatorMock() + ); + + $this->assertSame($coordinateAggregator, $this->coordinateSubscriber->getCoordinateAggregator()); + } + + public function testSetCoordinateRenderer() + { + $this->coordinateSubscriber->setCoordinateRenderer( + $coordinateRenderer = $this->createCoordinateRendererMock() + ); + + $this->assertSame($coordinateRenderer, $this->coordinateSubscriber->getCoordinateRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteCoordinateSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_BASE_COORDINATE]); + } + + public function testOnMap() + { + $this->coordinateAggregator + ->expects($this->once()) + ->method('aggregate') + ->with($this->identicalTo($autocomplete = $this->createAutocompleteMock())) + ->will($this->returnValue(array($coordinate = $this->createCoordinateMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($autocomplete), + $this->identicalTo($render = 'render'), + $this->identicalTo('base.coordinates'), + $this->identicalTo($coordinate) + ) + ->will($this->returnValue($code = 'code')); + + $this->coordinateRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($coordinate)) + ->will($this->returnValue($render)); + + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($autocomplete)); + + $placesAutocompleteEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->coordinateSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteHtmlSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteHtmlSubscriberTest.php new file mode 100644 index 00000000..0d2c3d07 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteHtmlSubscriberTest.php @@ -0,0 +1,140 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvent; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteHtmlSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete html subscriber test. + * + * @author GeLo + */ +class AutocompleteHtmlSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteHtmlSubscriber */ + protected $autocompleteHtml; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->autocompleteHtml = new AutocompleteHtmlSubscriber($this->formatter); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->autocompleteHtml); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->autocompleteHtml); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteHtmlSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::HTML, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::HTML]); + } + + /** + * @dataProvider onAutocompleteProvider + */ + public function testOnAutocomplete($value = null , array $inputAttributes = array()) + { + $attributes = array( + 'id' => 'input_id', + 'type' => 'text' + ); + + if ($value !== null) { + $attributes['value'] = $value; + } + + $this->formatter + ->expects($this->once()) + ->method('formatTag') + ->with( + $this->identicalTo('input'), + $this->identicalTo(null), + $this->identicalTo(array_merge($attributes, $inputAttributes)), + $this->identicalTo(true) + ) + ->will($this->returnValue($code = 'code')); + + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($this->createAutocompleteMock($value, $inputAttributes))); + + $placesAutocompleteEvent + ->expects($this->any()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->autocompleteHtml->onAutocomplete($placesAutocompleteEvent); + } + + /** + * Gets the on autocomplete provider. + * + * @return array The on autocomplete provicer. + */ + public function onAutocompleteProvider() + { + return array( + array(), + array('value'), + array('value', array('foo' => 'bar')), + ); + } + + protected function createAutocompleteMock($value = null, array $inputAttributes = array()) + { + $autocomplete = parent::createAutocompleteMock(); + $autocomplete + ->expects($this->any()) + ->method('getInputId') + ->will($this->returnValue('input_id')); + + $autocomplete + ->expects($this->any()) + ->method('hasValue') + ->will($this->returnValue($value !== null)); + + $autocomplete + ->expects($this->any()) + ->method('getValue') + ->will($this->returnValue($value)); + + $autocomplete + ->expects($this->any()) + ->method('getInputAttributes') + ->will($this->returnValue($inputAttributes)); + + return $autocomplete; + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteInitSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteInitSubscriberTest.php new file mode 100644 index 00000000..a4a19529 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteInitSubscriberTest.php @@ -0,0 +1,70 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteInitSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractTestCase; + +/** + * Autocomplete init subscriber test. + * + * @author GeLo + */ +class AutocompleteInitSubscriberTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteInitSubscriber */ + protected $autocompleteInitSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->autocompleteInitSubscriber = new AutocompleteInitSubscriber(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->autocompleteInitSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteInitSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_INIT, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_INIT]); + } + + public function testOnAutocomplete() + { + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->once()) + ->method('dispatch') + ->with( + $this->identicalTo(PlacesAutocompleteEvents::JAVASCRIPT_INIT_CONTAINER), + $this->identicalTo($placesAutocompleteEvent) + ); + + $this->autocompleteInitSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriberTest.php new file mode 100644 index 00000000..ca24f5f1 --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteJavascriptSubscriberTest.php @@ -0,0 +1,150 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\ApiEvent; +use Ivory\GoogleMap\Helpers\ApiEvents; +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteJavascriptSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete javascript subscriber test. + * + * @author GeLo + */ +class AutocompleteJavascriptSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteJavascriptSubscriber */ + protected $autocompleteJavascriptSubscriber; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->autocompleteJavascriptSubscriber = new AutocompleteJavascriptSubscriber($this->formatter); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->autocompleteJavascriptSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->autocompleteJavascriptSubscriber); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteJavascriptSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE, $subscribedEvents); + $this->assertSame('onApi', $subscribedEvents[ApiEvents::JAVASCRIPT_PLACES_AUTOCOMPLETE]); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT]); + } + + public function testOnApi() + { + $apiEvent = $this->createApiEventMock(); + $apiEvent + ->expects($this->once()) + ->method('getItems') + ->with($this->identicalTo(ApiEvent::PLACES_AUTOCOMPLETE)) + ->will($this->returnValue(array($autocomplete = $this->createAutocompleteMock()))); + + $this->formatter + ->expects($this->once()) + ->method('formatAssetCallback') + ->with($this->identicalTo($autocomplete)) + ->will($this->returnValue($callback = 'callback')); + + $apiEvent + ->expects($this->once()) + ->method('addCallback') + ->with($this->identicalTo($callback)); + + $apiEvent + ->expects($this->once()) + ->method('addLibrary') + ->with($this->identicalTo('places')); + + $this->autocompleteJavascriptSubscriber->onApi($apiEvent); + } + + public function testOnAutocomplete() + { + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getDispatcher') + ->will($this->returnValue($eventDispatcher = $this->createSymfonyEventDispatcherMock())); + + $eventDispatcher + ->expects($this->exactly(3)) + ->method('dispatch') + ->will($this->returnValueMap(array( + array(PlacesAutocompleteEvents::JAVASCRIPT_INIT, $placesAutocompleteEvent), + array(PlacesAutocompleteEvents::JAVASCRIPT_BASE, $placesAutocompleteEvent), + array(PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE, $placesAutocompleteEvent), + ))); + + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getCode') + ->will($this->returnValue($code = 'code')); + + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($autocomplete = $this->createAutocompleteMock())); + + $this->formatter + ->expects($this->once()) + ->method('formatAssetCallback') + ->with($this->identicalTo($autocomplete)) + ->will($this->returnValue($callback = 'callback')); + + $this->formatter + ->expects($this->once()) + ->method('formatFunction') + ->with( + $this->identicalTo($code), + $this->identicalTo(array()), + $this->identicalTo($callback) + ) + ->will($this->returnValue($function = 'function')); + + $this->formatter + ->expects($this->once()) + ->method('formatJavascript') + ->with($this->identicalTo($function)) + ->will($this->returnValue($javascript = 'javascript')); + + $placesAutocompleteEvent + ->expects($this->once()) + ->method('setCode') + ->will($this->returnValue($javascript)); + + $this->autocompleteJavascriptSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Helpers/Subscribers/Places/AutocompleteSubscriberTest.php b/tests/Helpers/Subscribers/Places/AutocompleteSubscriberTest.php new file mode 100644 index 00000000..a4a0bb2c --- /dev/null +++ b/tests/Helpers/Subscribers/Places/AutocompleteSubscriberTest.php @@ -0,0 +1,124 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Helpers\Subscribers\Places; + +use Ivory\GoogleMap\Helpers\PlacesAutocompleteEvents; +use Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteSubscriber; +use Ivory\Tests\GoogleMap\Helpers\Subscribers\AbstractFormatterSubscriberTest; + +/** + * Autocomplete subscriber test. + * + * @author GeLo + */ +class AutocompleteSubscriberTest extends AbstractFormatterSubscriberTest +{ + /** @var \Ivory\GoogleMap\Helpers\Subscribers\Places\AutocompleteSubscriber */ + protected $autocompleteSubscriber; + + /** @var \Ivory\GoogleMap\Helpers\Renderers\Places\AutocompleteRenderer|\PHPUnit_Framework_MockObject_MockObject */ + protected $autocompleteRenderer; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + parent::setUp(); + + $this->autocompleteSubscriber = new AutocompleteSubscriber( + $this->formatter, + $this->autocompleteRenderer = $this->createAutocompleteRendererMock() + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + parent::tearDown(); + + unset($this->autocompleteRenderer); + unset($this->autocompleteSubscriber); + } + + public function testInheritance() + { + $this->assertFormatterSubscriberInstance($this->autocompleteSubscriber); + } + + public function testDefaultState() + { + $this->autocompleteSubscriber = new AutocompleteSubscriber(); + + $this->assertFormatterInstance($this->autocompleteSubscriber->getFormatter()); + $this->assertAutocompleteRendererInstance($this->autocompleteSubscriber->getAutocompleteRenderer()); + } + + public function testInitialState() + { + $this->assertSame($this->formatter, $this->autocompleteSubscriber->getFormatter()); + $this->assertSame($this->autocompleteRenderer, $this->autocompleteSubscriber->getAutocompleteRenderer()); + } + + public function testSetAutocompleteRenderer() + { + $this->autocompleteSubscriber->setAutocompleteRenderer( + $autocompleteRenderer = $this->createAutocompleteRendererMock() + ); + + $this->assertSame($autocompleteRenderer, $this->autocompleteSubscriber->getAutocompleteRenderer()); + } + + public function testSubscribedEvents() + { + $subscribedEvents = AutocompleteSubscriber::getSubscribedEvents(); + + $this->assertArrayHasKey(PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE, $subscribedEvents); + $this->assertSame('onAutocomplete', $subscribedEvents[PlacesAutocompleteEvents::JAVASCRIPT_AUTOCOMPLETE]); + } + + public function testOnAutocomplete() + { + $this->autocompleteRenderer + ->expects($this->once()) + ->method('render') + ->with($this->identicalTo($autocomplete = $this->createAutocompleteMock())) + ->will($this->returnValue($render = 'render')); + + $this->formatter + ->expects($this->once()) + ->method('formatContainerAssignment') + ->with( + $this->identicalTo($autocomplete), + $this->identicalTo($render), + $this->identicalTo('autocomplete'), + $this->identicalTo($autocomplete), + $this->identicalTo(false) + ) + ->will($this->returnValue($code = 'code')); + + $placesAutocompleteEvent = $this->createPlacesAutocompleteEventMock(); + $placesAutocompleteEvent + ->expects($this->any()) + ->method('getAutocomplete') + ->will($this->returnValue($autocomplete)); + + $placesAutocompleteEvent + ->expects($this->once()) + ->method('addCode') + ->with($this->identicalTo($code)); + + $this->autocompleteSubscriber->onAutocomplete($placesAutocompleteEvent); + } +} diff --git a/tests/Layers/AbstractTestCase.php b/tests/Layers/AbstractTestCase.php new file mode 100644 index 00000000..cf994d9b --- /dev/null +++ b/tests/Layers/AbstractTestCase.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Layers; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Layers test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a kml layer instance. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + */ + protected function assertKmlLayerInstance($kmlLayer) + { + $this->assertInstanceOf('Ivory\GoogleMap\Layers\KmlLayer', $kmlLayer); + } +} diff --git a/tests/Layers/KMLLayerTest.php b/tests/Layers/KMLLayerTest.php deleted file mode 100644 index c97c015f..00000000 --- a/tests/Layers/KMLLayerTest.php +++ /dev/null @@ -1,69 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Events; - -use Ivory\GoogleMap\Layers\KMLLayer; - -/** - * KML layer test. - * - * @author GeLo - */ -class KMLLayerTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Layers\KMLLayer */ - protected $kmlLayer; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->kmlLayer = new KMLLayer(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->kmlLayer); - } - - public function testDefaultState() - { - $this->assertNull($this->kmlLayer->getUrl()); - } - - public function testInitialState() - { - $this->kmlLayer = new KMLLayer('foo'); - - $this->assertSame('foo', $this->kmlLayer->getUrl()); - } - - public function testUrlWithValidValue() - { - $this->kmlLayer->setUrl('foo'); - - $this->assertSame('foo', $this->kmlLayer->getUrl()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\LayerException - * @expectedExceptionMessage The kml layer url must be a string value. - */ - public function testUrlWithInvalidValue() - { - $this->kmlLayer->setUrl(true); - } -} diff --git a/tests/Layers/KmlLayerTest.php b/tests/Layers/KmlLayerTest.php new file mode 100644 index 00000000..779670d6 --- /dev/null +++ b/tests/Layers/KmlLayerTest.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Layers; + +use Ivory\GoogleMap\Layers\KmlLayer; + +/** + * Kml layer test. + * + * @author GeLo + */ +class KmlLayerTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Layers\KmlLayer */ + protected $kmlLayer; + + /** @var string */ + protected $url; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->kmlLayer = new KmlLayer($this->url = 'url'); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->url); + unset($this->kmlLayer); + } + + public function testInheritance() + { + $this->assertOptionsAssetInstance($this->kmlLayer); + } + + public function testDefaultState() + { + $this->assertStringStartsWith('kml_layer_', $this->kmlLayer->getVariable()); + $this->assertSame($this->url, $this->kmlLayer->getUrl()); + $this->assertFalse($this->kmlLayer->hasOptions()); + } + + public function testSetUrl() + { + $this->kmlLayer->setUrl($url = 'foo'); + + $this->assertSame($url, $this->kmlLayer->getUrl()); + } +} diff --git a/tests/Layers/LayersTest.php b/tests/Layers/LayersTest.php new file mode 100644 index 00000000..3560615f --- /dev/null +++ b/tests/Layers/LayersTest.php @@ -0,0 +1,149 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Layers; + +use Ivory\GoogleMap\Layers\Layers; + +/** + * Layers test. + * + * @author GeLo + */ +class LayersTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Layers\Layers */ + protected $layers; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->layers = new Layers(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->layers); + } + + public function testDefaultState() + { + $this->assertNoKmlLayers(); + } + + public function testSetKmlLayers() + { + $this->layers->setKmlLayers($kmlLayers = array($this->createKmlLayerMock())); + + $this->assertKmlLayers($kmlLayers); + } + + public function testAddKmlLayers() + { + $this->layers->setKmlLayers($kmlLayers = array($this->createKmlLayerMock())); + $this->layers->addKmlLayers($newKmlLayers = array($this->createKmlLayerMock())); + + $this->assertKmlLayers(array_merge($kmlLayers, $newKmlLayers)); + } + + public function testRemoveKmlLayers() + { + $this->layers->setKmlLayers($kmlLayers = array($this->createKmlLayerMock())); + $this->layers->removeKmlLayers($kmlLayers); + + $this->assertNoKmlLayers(); + } + + public function testResetKmlLayers() + { + $this->layers->setKmlLayers(array($this->createKmlLayerMock())); + $this->layers->resetKmlLayers(); + + $this->assertNoKmlLayers(); + } + + public function testAddKmlLayer() + { + $this->layers->addKmlLayer($kmlLayer = $this->createKmlLayerMock()); + + $this->assertKmlLayer($kmlLayer); + } + + public function testAddKmlLayerUnicity() + { + $this->layers->resetKmlLayers(); + $this->layers->addKmlLayer($kmlLayer = $this->createKmlLayerMock()); + $this->layers->addKmlLayer($kmlLayer); + + $this->assertKmlLayers(array($kmlLayer)); + } + + public function testRemoveKmlLayer() + { + $this->layers->addKmlLayer($kmlLayer = $this->createKmlLayerMock()); + $this->layers->removeKmlLayer($kmlLayer); + + $this->assertNoKmlLayer($kmlLayer); + } + + /** + * Asserts there are kml layers. + * + * @param array $kmlLayers The kml layers. + */ + protected function assertKmlLayers($kmlLayers) + { + $this->assertInternalType('array', $kmlLayers); + + $this->assertTrue($this->layers->hasKmlLayers()); + $this->assertSame($kmlLayers, $this->layers->getKmlLayers()); + + foreach ($kmlLayers as $kmlLayer) { + $this->assertKmlLayer($kmlLayer); + } + } + + /** + * Asserts there is a kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + */ + protected function assertKmlLayer($kmlLayer) + { + $this->assertKmlLayerInstance($kmlLayer); + $this->assertTrue($this->layers->hasKmlLayer($kmlLayer)); + } + + /** + * Asserts there are no kml layers. + */ + protected function assertNoKmlLayers() + { + $this->assertFalse($this->layers->hasKmlLayers()); + $this->assertEmpty($this->layers->getKmlLayers()); + } + + /** + * Asserts there is no kml layer. + * + * @param \Ivory\GoogleMap\Layers\KmlLayer $kmlLayer The kml layer. + */ + protected function assertNoKmlLayer($kmlLayer) + { + $this->assertKmlLayerInstance($kmlLayer); + $this->assertFalse($this->layers->hasKmlLayer($kmlLayer)); + } +} diff --git a/tests/MapTest.php b/tests/MapTest.php index 0f4aad43..2b81c4fd 100644 --- a/tests/MapTest.php +++ b/tests/MapTest.php @@ -11,10 +11,6 @@ namespace Ivory\Tests\GoogleMap; -use Ivory\GoogleMap\Controls\ControlPosition; -use Ivory\GoogleMap\Controls\MapTypeControlStyle; -use Ivory\GoogleMap\Controls\ScaleControlStyle; -use Ivory\GoogleMap\Controls\ZoomControlStyle; use Ivory\GoogleMap\Map; use Ivory\GoogleMap\MapTypeId; @@ -23,7 +19,7 @@ * * @author GeLo */ -class MapTest extends \PHPUnit_Framework_TestCase +class MapTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Map */ protected $map; @@ -36,20 +32,6 @@ protected function setUp() $this->map = new Map(); } - /** - * Set up the map bound. - */ - protected function setUpBound() - { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->any()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->map->setBound($bound); - } - /** * {@inheritdoc} */ @@ -58,853 +40,414 @@ protected function tearDown() unset($this->map); } + public function testInheritance() + { + $this->assertVariableAssetInstance($this->map); + } + public function testDefaultState() { - $this->assertSame('map_canvas', $this->map->getHtmlContainerId()); - $this->assertFalse($this->map->isAsync()); - $this->assertFalse($this->map->isAutoZoom()); + $this->assertStringStartsWith('map_', $this->map->getVariable()); + $this->assertSame($this->map->getVariable(), $this->map->getHtmlContainerId()); + $this->assertCoordinateInstance($this->map->getCenter()); $this->assertSame($this->map->getCenter()->getLatitude(), 0); $this->assertSame($this->map->getCenter()->getLongitude(), 0); - $this->assertTrue($this->map->getCenter()->isNoWrap()); - - $this->assertNull($this->map->getBound()->getNorthEast()); - $this->assertNull($this->map->getBound()->getSouthWest()); - $this->assertEmpty($this->map->getBound()->getExtends()); - - $this->assertSame(array('mapTypeId' => 'roadmap','zoom' => 3), $this->map->getMapOptions()); - $this->assertSame(array('width' => '300px', 'height' => '300px'), $this->map->getStylesheetOptions()); - - $this->assertFalse($this->map->hasMapTypeControl()); - $this->assertFalse($this->map->hasOverviewMapControl()); - $this->assertFalse($this->map->hasPanControl()); - $this->assertFalse($this->map->hasRotateControl()); - $this->assertFalse($this->map->hasScaleControl()); - $this->assertFalse($this->map->hasStreetViewControl()); - $this->assertFalse($this->map->hasZoomControl()); - $this->assertInstanceOf('Ivory\GoogleMap\Events\EventManager', $this->map->getEventManager()); - $this->assertInstanceOf('Ivory\GoogleMap\Overlays\MarkerCluster', $this->map->getMarkerCluster()); + $this->assertBoundInstance($this->map->getBound()); - $this->assertEmpty($this->map->getMarkers()); - $this->assertEmpty($this->map->getInfoWindows()); - $this->assertEmpty($this->map->getPolylines()); - $this->assertEmpty($this->map->getPolygons()); - $this->assertEmpty($this->map->getEncodedPolylines()); - $this->assertEmpty($this->map->getRectangles()); - $this->assertEmpty($this->map->getCircles()); - $this->assertEmpty($this->map->getGroundOverlays()); + $this->assertControlsInstance($this->map->getControls()); + $this->assertEventsInstance($this->map->getEvents()); + $this->assertLayersInstance($this->map->getLayers()); + $this->assertOverlaysInstance($this->map->getOverlays()); - $this->assertEmpty($this->map->getKMLLayers()); - - $this->assertFalse($this->map->hasLibraries()); + $this->assertNoMapOptions(); + $this->assertNoStylesheetOptions(); $this->assertSame('en', $this->map->getLanguage()); + $this->assertNoLibraries(); } - public function testHtmlContainerIdWithValidValue() + public function testSetHtmlContainerId() { - $this->map->setHtmlContainerId('html_container_id'); + $this->map->setHtmlContainerId($htmlContainerId = 'foo'); - $this->assertSame('html_container_id', $this->map->getHtmlContainerId()); + $this->assertSame($htmlContainerId, $this->map->getHtmlContainerId()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The html container id of a map must be a string value. - */ - public function testHtmlContainerWithInvalidValue() + public function testSetCenter() { - $this->map->setHtmlContainerId(true); - } - - public function testAsyncWithValidValue() - { - $this->map->setAsync(true); - - $this->assertTrue($this->map->isAsync()); - } + $this->map->setCenter($center = $this->createCoordinateMock()); - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The asynchronous load of a map must be a boolean value. - */ - public function testAsyncWithInvalidValue() - { - $this->map->setAsync('foo'); + $this->assertCenter($center); } - public function testAutoZoomWithValidValue() + public function testSetBound() { - $this->map->setAutoZoom(true); + $this->map->setBound($bound = $this->createBoundMock()); - $this->assertTrue($this->map->isAutoZoom()); + $this->assertBound($bound); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The auto zoom of a map must be a boolean value. - */ - public function testAutoZoomWithInvalidValue() + public function testSetControls() { - $this->map->setAutoZoom('foo'); - } + $this->map->setControls($controls = $this->createControlsMock()); - public function testCenterWithCoordinate() - { - $coordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->map->setCenter($coordinate); - - $this->assertSame($coordinate, $this->map->getCenter()); + $this->assertSame($controls, $this->map->getControls()); } - public function testCenterWithLatitueAndLongitude() + public function testSetEvents() { - $this->map->setCenter(1, 2, false); + $this->map->setEvents($events = $this->createEventsMock()); - $this->assertEquals(1, $this->map->getCenter()->getLatitude()); - $this->assertEquals(2, $this->map->getCenter()->getLongitude()); - $this->assertFalse($this->map->getCenter()->isNoWrap()); + $this->assertSame($events, $this->map->getEvents()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The center setter arguments is invalid. - * The available prototypes are : - * - function setCenter(Ivory\GoogleMap\Base\Coordinate $center) - * - function setCenter(double $latitude, double $longitude, boolean $noWrap = true) - */ - public function testCenterWithInvalidValue() + public function testSetLayers() { - $this->map->setCenter('foo'); - } - - public function testBoundWithBound() - { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->map->setBound($bound); + $this->map->setLayers($layers = $this->createLayersMock()); - $this->assertSame($bound, $this->map->getBound()); + $this->assertSame($layers, $this->map->getLayers()); } - public function testBoundWithCoordinates() + public function testSetOverlays() { - $southWestCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEastCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); + $this->map->setOverlays($overlays = $this->createOverlaysMock()); - $this->map->setBound($southWestCoordinate, $northEastCoordinate); - - $this->assertSame($southWestCoordinate, $this->map->getBound()->getSouthWest()); - $this->assertSame($northEastCoordinate, $this->map->getBound()->getNorthEast()); + $this->assertSame($overlays, $this->map->getOverlays()); } - public function testBoundWithLatitudesAndLongitudes() + public function testSetMapOptions() { - $this->map->setBound(1, 2, 3, 4, true, false); - - $this->assertSame(1, $this->map->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(2, $this->map->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->map->getBound()->getSouthWest()->isNoWrap()); + $this->map->setMapOptions($mapOptions = array('foo' => 'bar')); - $this->assertEquals(3, $this->map->getBound()->getNorthEast()->getLatitude()); - $this->assertEquals(4, $this->map->getBound()->getNorthEast()->getLongitude()); - $this->assertFalse($this->map->getBound()->getNorthEast()->isNoWrap()); + $this->assertMapOptions($mapOptions); } - public function testBoundWithNullValue() + public function testAddMapOptions() { - $this->map->setBound(1, 2, 3, 4); - $this->map->setBound(null); + $this->map->setMapOptions($mapOptions = array('foo' => 'bar')); + $this->map->addMapOptions($newMapOptions = array('baz' => 'bat')); - $this->assertNull($this->map->getBound()->getSouthWest()); - $this->assertNull($this->map->getBound()->getNorthEast()); + $this->assertMapOptions(array_merge($mapOptions, $newMapOptions)); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The bound setter arguments is invalid. - * The available prototypes are : - * - function setBound(Ivory\GoogleMap\Base\Bound $bound) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - */ - public function testBoundWithInvalidValue() + public function testRemoveMapOptions() { - $this->map->setBound('foo'); - } - - public function testHasMapOptionWithValidValue() - { - $this->assertTrue($this->map->hasMapOption('zoom')); - $this->assertFalse($this->map->hasMapOption('foo')); - } + $this->map->setMapOptions($mapOptions = array('foo' => 'bar')); + $this->map->removeMapOptions(array_keys($mapOptions)); - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The map option property of a map must be a string value. - */ - public function testHasMapOptionWithInvalidValue() - { - $this->map->hasMapOption(true); + $this->assertNoMapOptions(); } - public function testSetMapOptionsWithValidValue() + public function testResetMapOptions() { $this->map->setMapOptions(array('foo' => 'bar')); + $this->map->resetMapOptions(); - $this->assertSame('bar', $this->map->getMapOption('foo')); + $this->assertNoMapOptions(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - */ - public function testSetMapOptionWithInvalidValue() + public function testSetMapOption() { - $this->map->setMapOption(true, false); - } + $this->map->setMapOption($name = 'foo', $value = 'bar'); - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - */ - public function testGetMapOptionWithInvalidValue() - { - $this->map->getMapOption('foo'); + $this->assertMapOption($name, $value); } - public function testRemoveMapOptionWithValidValue() + public function testRemoveMapOption() { - $this->map->removeMapOption('zoom'); + $this->map->setMapOption($name = 'foo', 'bar'); + $this->map->removeMapOption($name); - $this->assertFalse($this->map->hasMapOption('zoom')); + $this->assertNoMapOption($name); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The map option "foo" does not exist. - */ - public function testRemoveMapOptionWithInvalidValue() + public function testSetStylesheetOptions() { - $this->map->removeMapOption('foo'); - } + $this->map->setStylesheetOptions($stylesheetOptions = array('foo' => 'bar')); - public function testHasStylesheetOptionWithValidValue() - { - $this->assertTrue($this->map->hasStylesheetOption('width')); - $this->assertFalse($this->map->hasStylesheetOption('foo')); + $this->assertStylesheetOptions($stylesheetOptions); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The stylesheet option property of a map must be a string value. - */ - public function testHasStylesheetOptionWithInvalidValue() + public function testAddStylesheetOptions() { - $this->map->hasStylesheetOption(true); - } + $this->map->setStylesheetOptions($stylesheetOptions = array('foo' => 'bar')); + $this->map->addStylesheetOptions($newStylesheetOptions = array('baz' => 'bat')); - public function testSetStylesheetOptionsWithValidValue() - { - $this->map->setStylesheetOptions(array('foo' => 'bar')); - - $this->assertSame('bar', $this->map->getStylesheetOption('foo')); + $this->assertStylesheetOptions( + array_merge($stylesheetOptions, $newStylesheetOptions) + ); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - */ - public function testSetStylesheetOptionWithInvalidValue() + public function testRemoveStylesheetOptions() { - $this->map->setStylesheetOption(true, false); - } + $this->map->setStylesheetOptions($stylesheetOptions = array('foo' => 'bar')); + $this->map->removeStylesheetOptions(array_keys($stylesheetOptions)); - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - */ - public function testGetStylesheetOptionWithInvalidValue() - { - $this->map->getStylesheetOption('foo'); + $this->assertNoStylesheetOptions(); } - public function testRemoveStylesheetOptionWithValidValue() + public function testResetStylesheetOptions() { - $this->map->removeStylesheetOption('width'); - - $this->assertFalse($this->map->hasStylesheetOption('width')); - } + $this->map->setStylesheetOptions(array('foo' => 'bar')); + $this->map->resetStylesheetOptions(); - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The stylesheet option "foo" does not exist. - */ - public function testRemoveStylesheetOptionWithInvalidValue() - { - $this->map->removeStylesheetOption('foo'); + $this->assertNoStylesheetOptions(); } - public function testMapTypeControlWithMapTypeControl() + public function testSetStylesheetOption() { - $mapTypeControl = $this->getMock('Ivory\GoogleMap\Controls\MapTypeControl'); - $this->map->setMapTypeControl($mapTypeControl); + $this->map->setStylesheetOption($name = 'foo', $value = 'bar'); - $this->assertSame($mapTypeControl, $this->map->getMapTypeControl()); - $this->assertTrue($this->map->getMapOption('mapTypeControl')); + $this->assertStylesheetOption($name, $value); } - public function testMapTypeControlWithMapTypeControlParameters() + public function testRemoveStylesheetOption() { - $mapTypeIds = array(MapTypeId::TERRAIN); - $controlPosition = ControlPosition::BOTTOM_CENTER; - $mapTypeControlStyle = MapTypeControlStyle::HORIZONTAL_BAR; - - $this->map->setMapTypeControl($mapTypeIds, $controlPosition, $mapTypeControlStyle); - - $this->assertSame($mapTypeIds, $this->map->getMapTypeControl()->getMapTypeIds()); - $this->assertSame($controlPosition, $this->map->getMapTypeControl()->getControlPosition()); - $this->assertSame($mapTypeControlStyle, $this->map->getMapTypeControl()->getMapTypeControlStyle()); + $this->map->setStylesheetOption($name = 'foo', 'bar'); + $this->map->removeStylesheetOption($name); - $this->assertTrue($this->map->getMapOption('mapTypeControl')); + $this->assertNoStylesheetOption($name); } - public function testMapTypeControlWithNullValue() + public function testSetLanguage() { - $this->map->setMapTypeControl($this->getMock('Ivory\GoogleMap\Controls\MapTypeControl')); - $this->map->setMapTypeControl(null); + $this->map->setLanguage($language = 'fr'); - $this->assertNull($this->map->getMapTypeControl()); - $this->assertFalse($this->map->hasMapOption('mapTypeControl')); + $this->assertSame($language, $this->map->getLanguage()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The map type control setter arguments is invalid. - * The available prototypes are : - * - function setMapTypeControl(Ivory\GoogleMap\Controls\MapTypeControl $mapTypeControl = null) - * - function setMaptypeControl(array $mapTypeIds, string $controlPosition, string $mapTypeControlStyle) - */ - public function testMapTypeControlWithInvalidValue() - { - $this->map->setMapTypeControl('foo'); - } - - public function testOverviewMapControlWithOverviewMapControl() + public function testSetLibraries() { - $overviewMapControl = $this->getMock('Ivory\GoogleMap\Controls\OverviewMapControl'); - $this->map->setOverviewMapControl($overviewMapControl); + $this->map->setLibraries($libraries = array('foo')); - $this->assertSame($overviewMapControl, $this->map->getOverviewMapControl()); - $this->assertTrue($this->map->getMapOption('overviewMapControl')); + $this->assertLibraries($libraries); } - public function testOverviewMapControlWithOverviewMapControlParameters() + public function testAddLibraries() { - $this->map->setOverviewMapControl(true); + $this->map->setLibraries($libraries = array('foo')); + $this->map->addLibraries($newLibraries = array('bar')); - $this->assertTrue($this->map->getOverviewMapControl()->isOpened()); - $this->assertTrue($this->map->getMapOption('overviewMapControl')); + $this->assertLibraries(array_merge($libraries, $newLibraries)); } - public function testOverviewMapControlWithNullValue() + public function testRemoveLibraries() { - $this->map->setOverviewMapControl($this->getMock('Ivory\GoogleMap\Controls\OverviewMapControl')); - $this->map->setOverviewMapControl(null); + $this->map->setLibraries($libraries = array('foo')); + $this->map->removeLibraries($libraries); - $this->assertNull($this->map->getOverviewMapControl()); - $this->assertFalse($this->map->hasMapOption('overviewMapControl')); + $this->assertNoLibraries(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The overview map control setter arguments is invalid. - * The available prototypes are : - * - function setOverviewMapControl(Ivory\GoogleMap\Controls\OverviewMapControl $overviewMapControl = null) - * - function setOverviewMapControl(boolean $opened) - */ - public function testOverviewMapControlWithInvalidValue() + public function testResetLibraries() { - $this->map->setOverviewMapControl('foo'); - } - - public function testPanControlWithPanControl() - { - $panControl = $this->getMock('Ivory\GoogleMap\Controls\PanControl'); - $this->map->setPanControl($panControl); + $this->map->setLibraries(array('foo')); + $this->map->resetLibraries(); - $this->assertSame($panControl, $this->map->getPanControl()); - $this->assertTrue($this->map->getMapOption('panControl')); + $this->assertNoLibraries(); } - public function testPanControlWithPanControlParameters() + public function testAddLibrary() { - $this->map->setPanControl(ControlPosition::BOTTOM_CENTER); + $this->map->addLibrary($library = 'foo'); - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->map->getPanControl()->getControlPosition()); - $this->assertTrue($this->map->getMapOption('panControl')); + $this->assertLibrary($library); } - public function testPanControlWithNullValue() + public function testRemoveLibrary() { - $this->map->setPanControl($this->getMock('Ivory\GoogleMap\Controls\PanControl')); - $this->map->setPanControl(null); + $this->map->addLibrary($library = 'foo'); + $this->map->removeLibrary($library); - $this->assertNull($this->map->getPanControl()); - $this->assertFalse($this->map->hasMapOption('panControl')); + $this->assertNoLibrary($library); } /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The pan control setter arguments is invalid. - * The available prototypes are : - * - function setPanControl(Ivory\GoogleMap\Controls\PanControl $panControl = null) - * - function setPanControl(string $controlPosition) + * Asserts there is a center. + * + * @param \Ivory\GoogleMap\Base\Coordinate $center The center. */ - public function testPanControlWithInvalidValue() - { - $this->map->setPanControl(true); - } - - public function testRotateControlWithRotateControl() - { - $rotateControl = $this->getMock('Ivory\GoogleMap\Controls\RotateControl'); - $this->map->setRotateControl($rotateControl); - - $this->assertSame($rotateControl, $this->map->getRotateControl()); - $this->assertTrue($this->map->getMapOption('rotateControl')); - } - - public function testRotateControlWithRotateControlParameters() - { - $this->map->setRotateControl(ControlPosition::BOTTOM_CENTER); - - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->map->getRotateControl()->getControlPosition()); - $this->assertTrue($this->map->getMapOption('rotateControl')); - } - - public function testRotateControlWithNullValue() + protected function assertCenter($center) { - $this->map->setRotateControl($this->getMock('Ivory\GoogleMap\Controls\RotateControl')); - $this->map->setRotateControl(null); + $this->assertCoordinateInstance($center); - $this->assertNull($this->map->getRotateControl()); - $this->assertFalse($this->map->hasMapOption('rotateControl')); + $this->assertSame($center, $this->map->getCenter()); } /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The rotate control setter arguments is invalid. - * The available prototypes are : - * - function setRotateControl(Ivory\GoogleMap\Controls\RotateControl $rotateControl = null) - * - function setRotateControl(string $controlPosition) + * Asserts there is a bound. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function testRotateControlWithInvalidValue() - { - $this->map->setRotateControl(true); - } - - public function testScaleControlWithScaleControl() - { - $scaleControl = $this->getMock('Ivory\GoogleMap\Controls\ScaleControl'); - $this->map->setScaleControl($scaleControl); - - $this->assertSame($scaleControl, $this->map->getScaleControl()); - $this->assertTrue($this->map->getMapOption('scaleControl')); - } - - public function testScaleControlWithScaleControlParameters() - { - $controlPosition = ControlPosition::BOTTOM_CENTER; - $scaleControlStyle = ScaleControlStyle::DEFAULT_; - - $this->map->setScaleControl($controlPosition, $scaleControlStyle); - - $this->assertSame($controlPosition, $this->map->getScaleControl()->getControlPosition()); - $this->assertSame($scaleControlStyle, $this->map->getScaleControl()->getScaleControlStyle()); - - $this->assertTrue($this->map->getMapOption('scaleControl')); - } - - public function testScaleControlWithNullValue() + protected function assertBound($bound) { - $this->map->setScaleControl($this->getMock('Ivory\GoogleMap\Controls\ScaleControl')); - $this->map->setScaleControl(null); - - $this->assertNull($this->map->getScaleControl()); - $this->assertFalse($this->map->hasMapOption('scaleControl')); + $this->assertBoundInstance($bound); +; + $this->assertSame($bound, $this->map->getBound()); } /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The scale control setter arguments is invalid. - * The available prototypes are : - * - function setScaleControl(Ivory\GoogleMap\Controls\ScaleControl $scaleControl = null) - * - function setScaleControl(string $controlPosition, string $scaleControlStyle) + * Asserts there are map options. + * + * @param array $mapOptions The map options. */ - public function testScaleControlWithInvalidValue() + protected function assertMapOptions($mapOptions) { - $this->map->setScaleControl(true); - } + $this->assertInternalType('array', $mapOptions); - public function testStreetViewControlWithStreetViewControl() - { - $streetViewControl = $this->getMock('Ivory\GoogleMap\Controls\StreetViewControl'); - $this->map->setStreetViewControl($streetViewControl); + $this->assertTrue($this->map->hasMapOptions()); + $this->assertSame($mapOptions, $this->map->getMapOptions()); - $this->assertSame($streetViewControl, $this->map->getStreetViewControl()); - $this->assertTrue($this->map->getMapOption('streetViewControl')); - } - - public function testStreetViewControlWithStreetViewControlParameters() - { - $this->map->setStreetViewControl(ControlPosition::BOTTOM_CENTER); - - $this->assertSame(ControlPosition::BOTTOM_CENTER, $this->map->getStreetViewControl()->getControlPosition()); - $this->assertTrue($this->map->getMapOption('streetViewControl')); - } - - public function testStreetViewControlWithNullValue() - { - $this->map->setStreetViewControl($this->getMock('Ivory\GoogleMap\Controls\StreetViewControl')); - $this->map->setStreetViewControl(null); - - $this->assertNull($this->map->getStreetViewControl()); - $this->assertFalse($this->map->hasMapOption('streetViewControl')); + foreach ($mapOptions as $name => $value) { + $this->assertMapOption($name, $value); + } } /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The street view control setter arguments is invalid. - * The available prototypes are : - * - function setStreetViewControl(Ivory\GoogleMap\Controls\StreetViewControl $streetViewControl = null) - * - function setStreetViewControl(string $controlPosition) + * Asserts there is a map option. + * + * @param string $name The map option name. + * @param mixed $value The map option value. */ - public function testStreetViewControlWithInvalidValue() - { - $this->map->setStreetViewControl(true); - } - - public function testZoomControlWithZoomControl() + protected function assertMapOption($name, $value) { - $zoomControl = $this->getMock('Ivory\GoogleMap\Controls\ZoomControl'); - $this->map->setZoomControl($zoomControl); - - $this->assertSame($zoomControl, $this->map->getZoomControl()); - $this->assertTrue($this->map->getMapOption('zoomControl')); - } - - public function testZoomControlWithZoomControlParameters() - { - $controlPosition = ControlPosition::BOTTOM_CENTER; - $zoomControlStyle = ZoomControlStyle::LARGE; - - $this->map->setZoomControl($controlPosition, $zoomControlStyle); - - $this->assertSame($controlPosition, $this->map->getZoomControl()->getControlPosition()); - $this->assertSame($zoomControlStyle, $this->map->getZoomControl()->getZoomControlStyle()); - $this->assertTrue($this->map->getMapOption('zoomControl')); - } - - public function testZoomControlWithNullValue() - { - $this->map->setZoomControl($this->getMock('Ivory\GoogleMap\Controls\ZoomControl')); - $this->map->setZoomControl(null); - - $this->assertNull($this->map->getZoomControl()); - $this->assertFalse($this->map->hasMapOption('zoomControl')); + $this->assertTrue($this->map->hasMapOption($name)); + $this->assertSame($value, $this->map->getMapOption($name)); } /** - * @expectedException \Ivory\GoogleMap\Exception\MapException - * @expectedExceptionMessage The zoom control setter arguments is invalid. - * The available prototypes are : - * - function setZoomControl(Ivory\GoogleMap\Controls\ZoomControl $zoomControl = null) - * - function setZoomControl(string $controlPosition, string $zoomControlStyle) + * Asserts there are stylesheet options. + * + * @param array $stylesheetOptions The stylesheet options. */ - public function testZoomControlWithInvalidValue() - { - $this->map->setZoomControl(true); - } - - public function testEventManager() - { - $eventManager = $this->getMock('Ivory\GoogleMap\Events\EventManager'); - $this->map->setEventManager($eventManager); - - $this->assertSame($eventManager, $this->map->getEventManager()); - } - - public function testMarkerCluster() - { - $markerCluster = $this->getMock('Ivory\GoogleMap\Overlays\MarkerCluster'); - $this->map->setMarkerCluster($markerCluster); - - $this->assertSame($markerCluster, $this->map->getMarkerCluster()); - } - - public function testMarkerWithAutoZoom() - { - $marker = $this->getMock('Ivory\GoogleMap\Overlays\Marker'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($marker)); - - $this->map->addMarker($marker); - - $this->assertSame(array($marker), $this->map->getMarkers()); - } - - public function testMarkerWithoutAutoZoom() - { - $marker = $this->getMock('Ivory\GoogleMap\Overlays\Marker'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addMarker($marker); - - $this->assertSame(array($marker), $this->map->getMarkers()); - } - - public function testInfoWindowWithAutoZoom() - { - $infoWindow = $this->getMock('Ivory\GoogleMap\Overlays\InfoWindow'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($infoWindow)); - - $this->map->addInfoWindow($infoWindow); - - $this->assertSame(array($infoWindow), $this->map->getInfoWindows()); - } - - public function testInfoWindowWithoutAutoZoom() - { - $infoWindow = $this->getMock('Ivory\GoogleMap\Overlays\InfoWindow'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addInfoWindow($infoWindow); - - $this->assertSame(array($infoWindow), $this->map->getInfoWindows()); - } - - public function testPolylineWithAutoZoom() - { - $polyline = $this->getMock('Ivory\GoogleMap\Overlays\Polyline'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($polyline)); - - $this->map->addPolyline($polyline); - - $this->assertSame(array($polyline), $this->map->getPolylines()); - } - - public function testPolylineWithoutAutoZoom() - { - $polyline = $this->getMock('Ivory\GoogleMap\Overlays\Polyline'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addPolyline($polyline); - - $this->assertSame(array($polyline), $this->map->getPolylines()); - } - - public function testEncodedPolylineWithAutoZoom() + protected function assertStylesheetOptions($stylesheetOptions) { - $encodedPolyline = $this->getMock('Ivory\GoogleMap\Overlays\EncodedPolyline'); - $this->map->setAutoZoom(true); + $this->assertInternalType('array', $stylesheetOptions); - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($encodedPolyline)); + $this->assertTrue($this->map->hasStylesheetOptions()); + $this->assertSame($stylesheetOptions, $this->map->getStylesheetOptions()); - $this->map->addEncodedPolyline($encodedPolyline); - - $this->assertSame(array($encodedPolyline), $this->map->getEncodedPolylines()); + foreach ($stylesheetOptions as $name => $value) { + $this->assertStylesheetOption($name, $value); + } } - public function testEncodedPolylineWithoutAutoZoom() - { - $encodedPolyline = $this->getMock('Ivory\GoogleMap\Overlays\EncodedPolyline'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addEncodedPolyline($encodedPolyline); - - $this->assertSame(array($encodedPolyline), $this->map->getEncodedPolylines()); - } - - public function testPolygonWithAutoZoom() + /** + * Asserts there is a stylesheet option. + * + * @param string $name The stylesheet option name. + * @param mixed $value The stylesheet option value. + */ + protected function assertStylesheetOption($name, $value) { - $polygon = $this->getMock('Ivory\GoogleMap\Overlays\Polygon'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($polygon)); - - $this->map->addPolygon($polygon); - - $this->assertSame(array($polygon), $this->map->getPolygons()); + $this->assertTrue($this->map->hasStylesheetOption($name)); + $this->assertSame($value, $this->map->getStylesheetOption($name)); } - public function testPolygonWithoutAutoZoom() + /** + * Asserts there are libraries. + * + * @param array $libraries The libraries. + */ + protected function assertLibraries($libraries) { - $polygon = $this->getMock('Ivory\GoogleMap\Overlays\Polygon'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); + $this->assertInternalType('array', $libraries); - $this->map->addPolygon($polygon); + $this->assertTrue($this->map->hasLibraries()); + $this->assertSame($libraries, $this->map->getLibraries()); - $this->assertSame(array($polygon), $this->map->getPolygons()); + foreach ($libraries as $library) { + $this->assertLibrary($library); + } } - public function testRectangleWithAutoZoom() + /** + * Asserts there is a library. + * + * @param string $library The library. + */ + protected function assertLibrary($library) { - $rectangle = $this->getMock('Ivory\GoogleMap\Overlays\Rectangle'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($rectangle)); - - $this->map->addRectangle($rectangle); - - $this->assertSame(array($rectangle), $this->map->getRectangles()); + $this->assertTrue($this->map->hasLibrary($library)); } - public function testRectangleWithoutAutoZoom() + /** + * Asserts there are no map options. + */ + protected function assertNoMapOptions() { - $rectangle = $this->getMock('Ivory\GoogleMap\Overlays\Rectangle'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addRectangle($rectangle); - - $this->assertSame(array($rectangle), $this->map->getRectangles()); + $this->assertFalse($this->map->hasMapOptions()); + $this->assertEmpty($this->map->getMapOptions()); } - public function testCircleWithAutoZoom() + /** + * Asserts there is no map option. + * + * @param string $name The map option name. + */ + protected function assertNoMapOption($name) { - $circle = $this->getMock('Ivory\GoogleMap\Overlays\Circle'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($circle)); - - $this->map->addCircle($circle); - - $this->assertSame(array($circle), $this->map->getCircles()); + $this->assertFalse($this->map->hasMapOption($name)); + $this->assertNull($this->map->getMapOption($name)); } - public function testCircleWithoutAutoZoom() + /** + * Asserts there are no stylesheet options. + */ + protected function assertNoStylesheetOptions() { - $circle = $this->getMock('Ivory\GoogleMap\Overlays\Circle'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addCircle($circle); - - $this->assertSame(array($circle), $this->map->getCircles()); + $this->assertFalse($this->map->hasStylesheetOptions()); + $this->assertEmpty($this->map->getStylesheetOptions()); } - public function testGroundOverlayWithAutoZoom() + /** + * Asserts there is no stylesheet option. + * + * @param string $name The stylesheet option name. + */ + protected function assertNoStylesheetOption($name) { - $groundOverlay = $this->getMock('Ivory\GoogleMap\Overlays\GroundOverlay'); - $this->map->setAutoZoom(true); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->once()) - ->method('extend') - ->with($this->equalTo($groundOverlay)); - - $this->map->addGroundOverlay($groundOverlay); - - $this->assertSame(array($groundOverlay), $this->map->getGroundOverlays()); + $this->assertFalse($this->map->hasStylesheetOption($name)); + $this->assertNull($this->map->getStylesheetOption($name)); } - public function testGroundOverlayWithoutAutoZoom() + /** + * Asserts there are no libraries. + */ + protected function assertNoLibraries() { - $groundOverlay = $this->getMock('Ivory\GoogleMap\Overlays\GroundOverlay'); - - $this->setUpBound(); - $this->map->getBound() - ->expects($this->never()) - ->method('extend'); - - $this->map->addGroundOverlay($groundOverlay); - - $this->assertSame(array($groundOverlay), $this->map->getGroundOverlays()); + $this->assertFalse($this->map->hasLibraries()); + $this->assertEmpty($this->map->getLibraries()); } - public function testKmlLayer() + /** + * Asserts there is no library. + * + * @param string $library The library. + */ + protected function assertNoLibrary($library) { - $kmlLayer = $this->getMock('Ivory\GoogleMap\Layers\KMLLayer'); - $this->map->addKMLLayer($kmlLayer); - - $this->assertSame(array($kmlLayer), $this->map->getKMLLayers()); + $this->assertFalse($this->map->hasLibrary($library)); } - public function testLibraries() + /** + * Asserts a coordinate instance. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + protected function assertCoordinateInstance($coordinate) { - $this->map->setLibraries(array('foo')); - - $this->assertTrue($this->map->hasLibraries()); - $this->assertSame(array('foo'), $this->map->getLibraries()); + $this->assertInstanceOf('Ivory\GoogleMap\Base\Coordinate', $coordinate); } - public function testLanguage() + /** + * Asserts a bound instance. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. + */ + protected function assertBoundInstance($bound) { - $this->map->setLanguage('fr'); - - $this->assertSame('fr', $this->map->getLanguage()); + $this->assertInstanceOf('Ivory\GoogleMap\Base\Bound', $bound); } } diff --git a/tests/MapTypeIdTest.php b/tests/MapTypeIdTest.php index d92b723e..34a0d9ac 100644 --- a/tests/MapTypeIdTest.php +++ b/tests/MapTypeIdTest.php @@ -14,21 +14,22 @@ use Ivory\GoogleMap\MapTypeId; /** - * Map type ID test. + * Map type id test. * * @author GeLo */ -class MapTypeIdTest extends \PHPUnit_Framework_TestCase +class MapTypeIdTest extends AbstractTestCase { - public function testMapTypeIds() + public function testInheritance() { - $expected = array( - MapTypeId::HYBRID, - MapTypeId::ROADMAP, - MapTypeId::SATELLITE, - MapTypeId::TERRAIN - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\MapTypeId'); + } - $this->assertSame($expected, MapTypeId::getMapTypeIds()); + public function testConstants() + { + $this->assertSame('hybrid', MapTypeId::HYBRID); + $this->assertSame('roadmap', MapTypeId::ROADMAP); + $this->assertSame('satellite', MapTypeId::SATELLITE); + $this->assertSame('terrain', MapTypeId::TERRAIN); } } diff --git a/tests/Overlays/AbstractExtendableTest.php b/tests/Overlays/AbstractExtendableTest.php new file mode 100644 index 00000000..c3e96ad7 --- /dev/null +++ b/tests/Overlays/AbstractExtendableTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +/** + * Abstract extendable test. + * + * @author GeLo + */ +abstract class AbstractExtendableTest extends AbstractTestCase +{ + abstract public function testRenderExtend(); + + /** + * Creates a bound mock. + * + * @param string|null $variable The variable. + * + * @return \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject The bound. + */ + protected function createBoundMock($variable = 'bound') + { + $bound = parent::createBoundMock(); + $bound + ->expects($this->any()) + ->method('getVariable') + ->will($this->returnValue($variable)); + + return $bound; + } +} diff --git a/tests/Overlays/AbstractTestCase.php b/tests/Overlays/AbstractTestCase.php new file mode 100644 index 00000000..b9c3dd19 --- /dev/null +++ b/tests/Overlays/AbstractTestCase.php @@ -0,0 +1,152 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Overlays test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a circle instance. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + */ + protected function assertCircleInstance($circle) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Circle', $circle); + } + + /** + * Asserts an encoded polyline instance. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + */ + protected function assertEncodedPolylineInstance($encodedPolyline) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\EncodedPolyline', $encodedPolyline); + } + + /** + * Asserts an extendable instance. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extendable The extendable. + */ + protected function assertExtendableInstance($extendable) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\ExtendableInterface', $extendable); + } + + /** + * Asserts a ground overlay instance. + * + * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. + */ + protected function assertGroundOverlayInstance($groundOverlay) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\GroundOverlay', $groundOverlay); + } + + /** + * Asserts an icon instance. + * + * @param \Ivory\GoogleMap\Overlays\Icon $icon The icon. + */ + protected function assertIconInstance($icon) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Icon', $icon); + } + + /** + * Asserts an info window instance. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + protected function assertInfoWindowInstance($infoWindow) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\InfoWindow', $infoWindow); + } + + /** + * Asserts a marker cluster instance. + * + * @param \Ivory\GoogleMap\Overlays\MarkerCluster $markerCluster The marker cluster. + */ + protected function assertMarkerClusterInstance($markerCluster) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\MarkerCluster', $markerCluster); + } + + /** + * Asserts a marker instance. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + protected function assertMarkerInstance($marker) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Marker', $marker); + } + + /** + * Asserts a marker shape instance. + * + * @param \Ivory\GoogleMap\Overlays\MarkerShape $markerShape The marker shape. + */ + protected function assertMarkerShapeInstance($markerShape) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\MarkerShape', $markerShape); + } + + /** + * Asserts a point instance. + * + * @param \Ivory\GoogleMap\Base\Point $point The point. + */ + protected function assertPointInstance($point) + { + $this->assertInstanceOf('Ivory\GoogleMap\Base\Point', $point); + } + + /** + * Asserts a polygon instance. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + */ + protected function assertPolygonInstance($polygon) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Polygon', $polygon); + } + + /** + * Asserts a polyline instance. + * + * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. + */ + protected function assertPolylineInstance($polyline) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Polyline', $polyline); + } + + /** + * Asserts a rectangle instance. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. + */ + protected function assertRectangleInstance($rectangle) + { + $this->assertInstanceOf('Ivory\GoogleMap\Overlays\Rectangle', $rectangle); + } +} diff --git a/tests/Overlays/AnimationTest.php b/tests/Overlays/AnimationTest.php index 20e049ee..4d38ce68 100644 --- a/tests/Overlays/AnimationTest.php +++ b/tests/Overlays/AnimationTest.php @@ -18,15 +18,16 @@ * * @author GeLo */ -class AnimationTest extends \PHPUnit_Framework_TestCase +class AnimationTest extends AbstractTestCase { - public function testMapTypeControlStyles() + public function testInheritance() { - $expected = array( - Animation::BOUNCE, - Animation::DROP, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Overlays\Animation'); + } - $this->assertSame($expected, Animation::getAnimations()); + public function testConstants() + { + $this->assertSame('bounce', Animation::BOUNCE); + $this->assertSame('drop', Animation::DROP); } } diff --git a/tests/Overlays/CircleTest.php b/tests/Overlays/CircleTest.php index 4beb4af9..6d2d05b0 100644 --- a/tests/Overlays/CircleTest.php +++ b/tests/Overlays/CircleTest.php @@ -18,17 +18,23 @@ * * @author GeLo */ -class CircleTest extends \PHPUnit_Framework_TestCase +class CircleTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\Circle */ protected $circle; + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ + protected $center; + + /** @var float */ + protected $radius; + /** * {@inheritdoc} */ protected function setUp() { - $this->circle = new Circle(); + $this->circle = new Circle($this->center = $this->createCoordinateMock(), $this->radius = 1); } /** @@ -36,72 +42,43 @@ protected function setUp() */ protected function tearDown() { + unset($this->radius); + unset($this->center); unset($this->circle); } - public function testDefaultState() + public function testInheritance() { - $this->assertInstanceOf('Ivory\GoogleMap\Base\Coordinate', $this->circle->getCenter()); - $this->assertSame(1, $this->circle->getRadius()); + $this->assertOptionsAssetInstance($this->circle); + $this->assertExtendableInstance($this->circle); } - public function testInitialState() + public function testDefaultState() { - $center = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $radius = 2; - - $this->circle = new Circle($center, $radius); - - $this->assertSame($center, $this->circle->getCenter()); - $this->assertSame($radius, $this->circle->getRadius()); + $this->assertStringStartsWith('circle_', $this->circle->getVariable()); + $this->assertSame($this->center, $this->circle->getCenter()); + $this->assertSame($this->radius, $this->circle->getRadius()); + $this->assertFalse($this->circle->hasOptions()); } - public function testCenterWithCoordinate() + public function testSetCenter() { - $center = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->circle->setCenter($center); + $this->circle->setCenter($center = $this->createCoordinateMock()); $this->assertSame($center, $this->circle->getCenter()); } - public function testCenterWithLatitudeAndLongitude() + public function testSetRadius() { - $latitude = 1; - $longitude = 2; - - $this->circle->setCenter($latitude, $longitude, true); - - $this->assertSame($latitude, $this->circle->getCenter()->getLatitude()); - $this->assertSame($longitude, $this->circle->getCenter()->getLongitude()); - $this->assertTrue($this->circle->getCenter()->isNoWrap()); - } + $this->circle->setRadius($radius = 10); - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage - * The center setter arguments is invalid. - * The available prototypes are : - * - function setCenter(Ivory\GoogleMap\Base\Coordinate $center) - * - function setCenter(double $latitude, double $longitude, boolean $noWrap = true) - */ - public function testCenterWithInvalidValue() - { - $this->circle->setCenter('foo'); + $this->assertSame($radius, $this->circle->getRadius()); } - public function testRadiusWithValidValue() + public function testRenderExtend() { - $this->circle->setRadius(3); + $this->circle->setVariable('circle'); - $this->assertSame(3, $this->circle->getRadius()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The radius of a circle must be a numeric value. - */ - public function testRadiusWithInvalidValue() - { - $this->circle->setRadius(true); + $this->assertSame('bound.union(circle.getBounds())', $this->circle->renderExtend($this->createBoundMock())); } } diff --git a/tests/Overlays/EncodedPolylineTest.php b/tests/Overlays/EncodedPolylineTest.php index dc789ea2..7be99496 100644 --- a/tests/Overlays/EncodedPolylineTest.php +++ b/tests/Overlays/EncodedPolylineTest.php @@ -18,17 +18,20 @@ * * @author GeLo */ -class EncodedPolylineTest extends \PHPUnit_Framework_TestCase +class EncodedPolylineTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\EncodedPolyline */ protected $encodedPolyline; + /** @var string */ + protected $value; + /** * {@inheritdoc} */ protected function setUp() { - $this->encodedPolyline = new EncodedPolyline(); + $this->encodedPolyline = new EncodedPolyline($this->value = 'value'); } /** @@ -36,27 +39,37 @@ protected function setUp() */ protected function tearDown() { + unset($this->value); unset($this->encodedPolyline); } + public function testInheritance() + { + $this->assertOptionsAssetInstance($this->encodedPolyline); + $this->assertExtendableInstance($this->encodedPolyline); + } + public function testDefaultState() { - $this->assertNull($this->encodedPolyline->getValue()); + $this->assertStringStartsWith('encoded_polyline_', $this->encodedPolyline->getVariable()); + $this->assertSame($this->value, $this->encodedPolyline->getValue()); + $this->assertFalse($this->encodedPolyline->hasOptions()); } - public function testInitialState() + public function testSetValue() { - $this->encodedPolyline = new EncodedPolyline('foo'); + $this->encodedPolyline->setValue($value = 'foo'); - $this->assertSame('foo', $this->encodedPolyline->getValue()); + $this->assertSame($value, $this->encodedPolyline->getValue()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The encoded polyline value must be a string value. - */ - public function testValueWithInvalidValue() + public function testRenderExtend() { - $this->encodedPolyline->setValue(true); + $this->encodedPolyline->setVariable('encoded_polyline'); + + $this->assertSame( + 'encoded_polyline.getPath().forEach(function(e){bound.extend(e);})', + $this->encodedPolyline->renderExtend($this->createBoundMock()) + ); } } diff --git a/tests/Overlays/GroundOverlayTest.php b/tests/Overlays/GroundOverlayTest.php index 36bd0563..35e7c904 100644 --- a/tests/Overlays/GroundOverlayTest.php +++ b/tests/Overlays/GroundOverlayTest.php @@ -18,17 +18,26 @@ * * @author GeLo */ -class GroundOverlayTest extends \PHPUnit_Framework_TestCase +class GroundOverlayTest extends AbstractExtendableTest { /** @vra \Ivory\GoogleMap\Overlays\GroundOverlay */ protected $groundOverlay; + /** @var string */ + protected $url; + + /** @var \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject */ + protected $bound; + /** * {@inheritdoc} */ protected function setUp() { - $this->groundOverlay = new GroundOverlay(); + $this->groundOverlay = new GroundOverlay( + $this->url = 'url', + $this->bound = $this->createBoundMock('ground_overlay_bound') + ); } /** @@ -36,109 +45,44 @@ protected function setUp() */ protected function tearDown() { + unset($this->bound); + unset($this->url); unset($this->groundOverlay); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame(-1, $this->groundOverlay->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(-1, $this->groundOverlay->getBound()->getSouthWest()->getLongitude()); - - $this->assertSame(1, $this->groundOverlay->getBound()->getNorthEast()->getLatitude()); - $this->assertSame(1, $this->groundOverlay->getBound()->getNorthEast()->getLongitude()); - - $this->assertNull($this->groundOverlay->getUrl()); + $this->assertOptionsAssetInstance($this->groundOverlay); + $this->assertExtendableInstance($this->groundOverlay); } - public function testInitialState() + public function testDefaultState() { - $url = 'foo'; - - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->once()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->groundOverlay = new GroundOverlay($url, $bound); - - $this->assertSame($url, $this->groundOverlay->getUrl()); - $this->assertSame($bound, $this->groundOverlay->getBound()); + $this->assertStringStartsWith('ground_overlay_', $this->groundOverlay->getVariable()); + $this->assertSame($this->url, $this->groundOverlay->getUrl()); + $this->assertSame($this->bound, $this->groundOverlay->getBound()); + $this->assertFalse($this->groundOverlay->hasOptions()); } - public function testUrlWithValidValue() + public function testSetUrl() { - $this->groundOverlay->setUrl('foo'); + $this->groundOverlay->setUrl($url = 'foo'); - $this->assertSame('foo', $this->groundOverlay->getUrl()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The url of a ground overlay must be a string value. - */ - public function testUrlWithInvalidValue() - { - $this->groundOverlay->setUrl(true); + $this->assertSame($url, $this->groundOverlay->getUrl()); } - public function testBoundWithValidBound() + public function testSetBound() { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->any()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->groundOverlay->setBound($bound); + $this->groundOverlay->setBound($bound = $this->createBoundMock()); $this->assertSame($bound, $this->groundOverlay->getBound()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage A ground overlay bound must have a south west & a north east coordinate. - */ - public function testBoundWithInvalidBound() - { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->any()) - ->method('hasCoordinates') - ->will($this->returnValue(false)); - - $this->groundOverlay->setBound($bound); - } - - public function testBoundWithSouthWestAndNorthEast() - { - $southWest = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEast = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->groundOverlay->setBound($southWest, $northEast); - - $this->assertSame($southWest, $this->groundOverlay->getBound()->getSouthWest()); - $this->assertSame($northEast, $this->groundOverlay->getBound()->getNorthEast()); - } - - public function testBoundWithLatitudesAndLongitudes() - { - $this->groundOverlay->setBound(-1, -2, 1, 2, true, false); - - $this->assertSame(-1, $this->groundOverlay->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(-2, $this->groundOverlay->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->groundOverlay->getBound()->getSouthWest()->isNoWrap()); - - $this->assertSame(1, $this->groundOverlay->getBound()->getNorthEast()->getLatitude()); - $this->assertSame(2, $this->groundOverlay->getBound()->getNorthEast()->getLongitude()); - $this->assertFalse($this->groundOverlay->getBound()->getNorthEast()->isNoWrap()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - */ - public function testBoundWithInvalidValue() + public function testRenderExtend() { - $this->groundOverlay->setBound('foo'); + $this->assertSame( + 'bound.union(ground_overlay_bound)', + $this->groundOverlay->renderExtend($this->createBoundMock()) + ); } } diff --git a/tests/Overlays/IconTest.php b/tests/Overlays/IconTest.php new file mode 100644 index 00000000..c3f28855 --- /dev/null +++ b/tests/Overlays/IconTest.php @@ -0,0 +1,215 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\GoogleMap\Overlays\Icon; + +/** + * Icon test. + * + * @author GeLo + */ +class IconTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Overlays\Icon */ + protected $icon; + + /** @var string */ + protected $url; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->icon = new Icon($this->url = 'url'); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->url); + unset($this->icon); + } + + public function testInheritance() + { + $this->assertVariableAssetInstance($this->icon); + } + + public function testDefaultState() + { + $this->assertStringStartsWith('icon_', $this->icon->getVariable()); + $this->assertSame($this->url, $this->icon->getUrl()); + $this->assertNoAnchor(); + $this->assertNoOrigin(); + $this->assertNoScaledSize(); + $this->assertNoSize(); + } + + public function testSetUrl() + { + $this->icon->setUrl($url = 'foo'); + + $this->assertSame($url, $this->icon->getUrl()); + } + + public function testSetAnchor() + { + $this->icon->setAnchor($point = $this->createPointMock()); + + $this->assertSame($point, $this->icon->getAnchor()); + } + + public function testResetAnchor() + { + $this->icon->setAnchor($this->createPointMock()); + $this->icon->setAnchor(null); + + $this->assertNoAnchor(); + } + + public function testSetOrigin() + { + $this->icon->setOrigin($point = $this->createPointMock()); + + $this->assertSame($point, $this->icon->getOrigin()); + } + + public function testResetOrigin() + { + $this->icon->setOrigin($this->createPointMock()); + $this->icon->setOrigin(null); + + $this->assertNoOrigin(); + } + + public function testSetScaledSize() + { + $this->icon->setScaledSize($size = $this->createSizeMock()); + + $this->assertSame($size, $this->icon->getScaledSize()); + } + + public function testResetScaledSize() + { + $this->icon->setScaledSize($this->createSizeMock()); + $this->icon->setScaledSize(null); + + $this->assertNoScaledSize(); + } + + public function testSetSize() + { + $this->icon->setSize($size = $this->createSizeMock()); + + $this->assertSame($size, $this->icon->getSize()); + } + + public function testResetSize() + { + $this->icon->setSize($this->createSizeMock()); + $this->icon->setSize(null); + + $this->assertNoSize(); + } + + /** + * Asserts there is an anchor. + * + * @param \Ivory\GoogleMap\Base\Point $anchor The anchor. + */ + protected function assertAnchor($anchor) + { + $this->assertPointInstance($anchor); + + $this->assertTrue($this->icon->hasAnchor()); + $this->assertSame($anchor, $this->icon->getAnchor()); + } + + /** + * Asserts there is an origin. + * + * @param \Ivory\GoogleMap\Base\Point $origin The origin. + */ + protected function assertOrigin($origin) + { + $this->assertPointInstance($origin); + + $this->assertTrue($this->icon->hasOrigin()); + $this->assertSame($origin, $this->icon->getOrigin()); + } + + /** + * Asserts there is a scaled size. + * + * @param \Ivory\GoogleMap\Base\Size $scaledSize The scaled size. + */ + protected function assertScaledSize($scaledSize) + { + $this->assertSizeInstance($scaledSize); + + $this->assertTrue($this->icon->hasScaledSize()); + $this->assertSame($scaledSize, $this->icon->getScaledSize()); + } + + /** + * Asserts there is a size. + * + * @param \Ivory\GoogleMap\Base\Size $size The size. + */ + protected function assertSize($size) + { + $this->assertSizeInstance($size); + + $this->assertTrue($this->icon->hasSize()); + $this->assertSame($size, $this->icon->getSize()); + } + + /** + * Asserts there is no anchor. + */ + protected function assertNoAnchor() + { + $this->assertFalse($this->icon->hasAnchor()); + $this->assertNull($this->icon->getAnchor()); + } + + /** + * Asserts there is no origin. + */ + protected function assertNoOrigin() + { + $this->assertFalse($this->icon->hasOrigin()); + $this->assertNull($this->icon->getOrigin()); + } + + /** + * Asserts there is no scaled size. + */ + protected function assertNoScaledSize() + { + $this->assertFalse($this->icon->hasScaledSize()); + $this->assertNull($this->icon->getScaledSize()); + } + + /** + * Asserts there is no size. + */ + protected function assertNoSize() + { + $this->assertFalse($this->icon->hasSize()); + $this->assertNull($this->icon->getSize()); + } +} diff --git a/tests/Overlays/InfoWindowTest.php b/tests/Overlays/InfoWindowTest.php index 5ce9c5cb..19da74a3 100644 --- a/tests/Overlays/InfoWindowTest.php +++ b/tests/Overlays/InfoWindowTest.php @@ -13,23 +13,27 @@ use Ivory\GoogleMap\Events\MouseEvent; use Ivory\GoogleMap\Overlays\InfoWindow; +use Ivory\GoogleMap\Overlays\InfoWindowType; /** * Info window test. * * @author GeLo */ -class InfoWindowTest extends \PHPUnit_Framework_TestCase +class InfoWindowTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\InfoWindow */ protected $infoWindow; + /** @var string */ + protected $content; + /** * {@inheritdoc} */ protected function setUp() { - $this->infoWindow = new InfoWindow(); + $this->infoWindow = new InfoWindow($this->content = 'content'); } /** @@ -37,199 +41,153 @@ protected function setUp() */ protected function tearDown() { + unset($this->content); unset($this->infoWindow); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame('

Default content

', $this->infoWindow->getContent()); - $this->assertNull($this->infoWindow->getPosition()); - $this->assertFalse($this->infoWindow->hasPixelOffset()); - $this->assertFalse($this->infoWindow->isOpen()); - $this->assertTrue($this->infoWindow->isAutoOpen()); - $this->assertSame(MouseEvent::CLICK, $this->infoWindow->getOpenEvent()); - $this->assertFalse($this->infoWindow->isAutoClose()); + $this->assertOptionsAssetInstance($this->infoWindow); + $this->assertExtendableInstance($this->infoWindow); } - public function testInitialState() + public function testDefaultState() { - $content = 'foo'; - $position = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $pixelOffset = $this->getMock('Ivory\GoogleMap\Base\Size'); - $opentEvent = MouseEvent::DBLCLICK; - - $this->infoWindow = new InfoWindow($content, $position, $pixelOffset, true, $opentEvent, false, true); - - $this->assertSame($content, $this->infoWindow->getContent()); - $this->assertSame($position, $this->infoWindow->getPosition()); - $this->assertSame($pixelOffset, $this->infoWindow->getPixelOffset()); - $this->assertTrue($this->infoWindow->isOpen()); - $this->assertFalse($this->infoWindow->isAutoOpen()); - $this->assertSame($opentEvent, $this->infoWindow->getOpenEvent()); + $this->assertStringStartsWith('info_window_', $this->infoWindow->getVariable()); + $this->assertSame($this->content, $this->infoWindow->getContent()); + $this->assertNoPosition(); + $this->assertNoPixelOffset(); + $this->assertFalse($this->infoWindow->isOpen()); + $this->assertSame(MouseEvent::CLICK, $this->infoWindow->getOpenEvent()); + $this->assertTrue($this->infoWindow->isAutoOpen()); $this->assertTrue($this->infoWindow->isAutoClose()); + $this->assertSame(InfoWindowType::DEFAULT_, $this->infoWindow->getType()); + $this->assertFalse($this->infoWindow->hasOptions()); } - public function testPositionWithCoordinate() + public function testSetContent() { - $position = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->infoWindow->setPosition($position); + $this->infoWindow->setContent($content = 'foo'); - $this->assertSame($position, $this->infoWindow->getPosition()); + $this->assertSame($content, $this->infoWindow->getContent()); } - public function testPositionWithLatitudeAndLongitude() + public function testSetPosition() { - $latitude = 2; - $longitude = 3; - - $this->infoWindow->setPosition($latitude, $longitude, true); + $this->infoWindow->setPosition($position = $this->createCoordinateMock()); - $this->assertSame($latitude, $this->infoWindow->getPosition()->getLatitude()); - $this->assertSame($longitude, $this->infoWindow->getPosition()->getLongitude()); - $this->assertTrue($this->infoWindow->getPosition()->isNoWrap()); + $this->assertPosition($position); } - public function testPositionWithNullValue() + public function testResetPosition() { - $this->infoWindow->setPosition($this->getMock('Ivory\GoogleMap\Base\Coordinate')); + $this->infoWindow->setPosition($this->createCoordinateMock()); $this->infoWindow->setPosition(null); - $this->assertNull($this->infoWindow->getPosition()); + $this->assertNoPosition(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The position setter arguments is invalid. - * The available prototypes are : - * - function setPosition(Ivory\GoogleMap\Base\Coordinate $position) - * - function setPosition(double $latitude, double $longitude, boolean $noWrap = true) - */ - public function testPositionWithInvalidValue() + public function testSetPixedOffset() { - $this->infoWindow->setPosition('foo'); + $this->infoWindow->setPixelOffset($pixelOffset = $this->createSizeMock()); + + $this->assertPixelOffset($pixelOffset); } - public function testPixedOffsetWithSize() + public function testResetPixelOffset() { - $size = $this->getMock('Ivory\GoogleMap\Base\Size'); - $this->infoWindow->setPixelOffset($size); + $this->infoWindow->setPixelOffset($this->createSizeMock()); + $this->infoWindow->setPixelOffset(null); - $this->assertSame($size, $this->infoWindow->getPixelOffset()); + $this->assertNoPixelOffset(); } - public function testPixedOffsetWithWidthAndHeight() + public function testSetOpen() { - $width = 2; - $widthUnit = 'px'; - $height = 3; - $heightUnit = '%'; - - $this->infoWindow->setPixelOffset($width, $height, $widthUnit, $heightUnit); + $this->infoWindow->setOpen(true); - $this->assertSame($width, $this->infoWindow->getPixelOffset()->getWidth()); - $this->assertSame($widthUnit, $this->infoWindow->getPixelOffset()->getWidthUnit()); - $this->assertSame($height, $this->infoWindow->getPixelOffset()->getHeight()); - $this->assertSame($heightUnit, $this->infoWindow->getPixelOffset()->getHeightUnit()); + $this->assertTrue($this->infoWindow->isOpen()); } - public function testPixelOffsetWithNullValue() + public function testSetOpenEvent() { - $this->infoWindow->setPixelOffset($this->getMock('Ivory\GoogleMap\Base\Size')); - $this->infoWindow->setPixelOffset(null); + $this->infoWindow->setOpenEvent($openEvent = MouseEvent::DBLCLICK); - $this->assertNull($this->infoWindow->getPixelOffset()); + $this->assertSame($openEvent, $this->infoWindow->getOpenEvent()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The pixel offset setter arguments is invalid. - * The available prototypes are : - * - function setPixelOffset(Ivory\GoogleMap\Base\Size $scaledSize) - * - function setPixelOffset(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - */ - public function testPixedOffsetWithInvalidValue() + public function testSetAutoOpen() { - $this->infoWindow->setPixelOffset('foo'); + $this->infoWindow->setAutoOpen(true); + + $this->assertTrue($this->infoWindow->isAutoOpen()); } - public function testContentWithValidValue() + public function testSetAutoClose() { - $this->infoWindow->setContent('foo'); + $this->infoWindow->setAutoClose(true); - $this->assertSame('foo', $this->infoWindow->getContent()); + $this->assertTrue($this->infoWindow->isAutoClose()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The content of an info window must be a string value. - */ - public function testContentWithInvalidValue() + public function testSetType() { - $this->infoWindow->setContent(true); + $this->infoWindow->setType($type = InfoWindowType::INFOBOX); + + $this->assertSame($type, $this->infoWindow->getType()); } - public function testOpenWithValidValue() + public function testRenderExtend() { - $this->infoWindow->setOpen(true); + $this->infoWindow->setVariable('info_window'); - $this->assertTrue($this->infoWindow->isOpen()); + $this->assertSame( + 'bound.extend(info_window.getPosition())', + $this->infoWindow->renderExtend($this->createBoundMock()) + ); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The open property of an info window must be a boolean value. + * Asserts there is a position. + * + * @param \Ivory\GoogleMap\Base\Coordinate $position The position. */ - public function testOpenWithInvalidValue() + protected function assertPosition($position) { - $this->infoWindow->setOpen('foo'); - } - - public function testAutoOpenWithValidValue() - { - $this->infoWindow->setAutoOpen(true); + $this->assertCoordinateInstance($position); - $this->assertTrue($this->infoWindow->isAutoOpen()); + $this->assertTrue($this->infoWindow->hasPosition()); + $this->assertSame($position, $this->infoWindow->getPosition()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The auto open property of an info window must be a boolean value. + * Asserts there is a pixel offset. + * + * @param \Ivory\GoogleMap\Base\Size $pixelOffset The pixel offset. */ - public function testAutoOpenWithInvalidValue() - { - $this->infoWindow->setAutoOpen('foo'); - } - - public function testOpenEventWithValidValue() + protected function assertPixelOffset($pixelOffset) { - $this->infoWindow->setOpenEvent(MouseEvent::MOUSEDOWN); + $this->assertSizeInstance($pixelOffset); - $this->assertSame(MouseEvent::MOUSEDOWN, $this->infoWindow->getOpenEvent()); + $this->assertTrue($this->infoWindow->hasPixelOffset()); + $this->assertSame($pixelOffset, $this->infoWindow->getPixelOffset()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The only available open event are : click, dblclick, mouseup, mousedown, mouseover, - * mouseout. + * Asserts there is no position. */ - public function testOpenEventWithInvalidValue() + protected function assertNoPosition() { - $this->infoWindow->setOpenEvent('foo'); - } - - public function testAutoCloseWithValidValue() - { - $this->infoWindow->setAutoClose(true); - - $this->assertTrue($this->infoWindow->isAutoClose()); + $this->assertFalse($this->infoWindow->hasPosition()); + $this->assertNull($this->infoWindow->getPosition()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The info window auto close flag must be a boolean value. + * Asserts there is no pixel offset. */ - public function testAutoCloseWithInvalidValue() + protected function assertNoPixelOffset() { - $this->infoWindow->setAutoClose('foo'); + $this->assertFalse($this->infoWindow->hasPixelOffset()); + $this->assertNull($this->infoWindow->getPixelOffset()); } } diff --git a/tests/Overlays/InfoWindowTypeTest.php b/tests/Overlays/InfoWindowTypeTest.php new file mode 100644 index 00000000..378fb3fb --- /dev/null +++ b/tests/Overlays/InfoWindowTypeTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\GoogleMap\Overlays\InfoWindowType; + +/** + * Info window type test. + * + * @author GeLo + */ +class InfoWindowTypeTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Overlays\InfoWindowType'); + } + + public function testConstants() + { + $this->assertSame('default', InfoWindowType::DEFAULT_); + $this->assertSame('infobox', InfoWindowType::INFOBOX); + } +} diff --git a/tests/Overlays/MarkerClusterTest.php b/tests/Overlays/MarkerClusterTest.php index 905ba7ea..a742136e 100644 --- a/tests/Overlays/MarkerClusterTest.php +++ b/tests/Overlays/MarkerClusterTest.php @@ -12,13 +12,14 @@ namespace Ivory\Tests\GoogleMap\Overlays; use Ivory\GoogleMap\Overlays\MarkerCluster; +use Ivory\GoogleMap\Overlays\MarkerClusterType; /** * Marker cluster test. * * @author GeLo */ -class MarkerClusterTest extends \PHPUnit_Framework_TestCase +class MarkerClusterTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Overlays\MarkerCluster */ protected $markerCluster; @@ -39,27 +40,126 @@ protected function tearDown() unset($this->markerCluster); } + public function testInheritance() + { + $this->assertOptionsAssetInstance($this->markerCluster); + } + public function testDefaultState() { - $this->assertSame('marker_cluster_', substr($this->markerCluster->getJavascriptVariable(), 0, 15)); - $this->assertSame(MarkerCluster::_DEFAULT, $this->markerCluster->getType()); - $this->assertFalse($this->markerCluster->hasMarkers()); - $this->assertEmpty($this->markerCluster->getMarkers()); + $this->assertStringStartsWith('marker_cluster_', $this->markerCluster->getVariable()); + $this->assertNoMarkers(); + $this->assertSame(MarkerClusterType::DEFAULT_, $this->markerCluster->getType()); + $this->assertFalse($this->markerCluster->hasOptions()); + } + + public function testSetMarkers() + { + $this->markerCluster->setMarkers($markers = array($this->createMarkerMock())); + + $this->assertMarkers($markers); } - public function testType() + public function testAddMarkers() { - $this->markerCluster->setType(MarkerCluster::MARKER_CLUSTER); + $this->markerCluster->setMarkers($markers = array($this->createMarkerMock())); + $this->markerCluster->addMarkers($newMarkers = array($this->createMarkerMock())); - $this->assertSame(MarkerCluster::MARKER_CLUSTER, $this->markerCluster->getType()); + $this->assertMarkers(array_merge($markers, $newMarkers)); } - public function testMarker() + public function testRemoveMarkers() { - $marker = $this->getMock('Ivory\GoogleMap\Overlays\Marker'); - $this->markerCluster->setMarkers(array($marker)); + $this->markerCluster->setMarkers($markers = array($this->createMarkerMock())); + $this->markerCluster->removeMarkers($markers); + + $this->assertNoMarkers(); + } + + public function testResetMarkers() + { + $this->markerCluster->setMarkers(array($this->createMarkerMock())); + $this->markerCluster->resetMarkers(); + + $this->assertNoMarkers(); + } + + public function testAddMarker() + { + $this->markerCluster->addMarker($marker = $this->createMarkerMock()); + + $this->assertMarker($marker); + } + + public function testAddMarkerUnicity() + { + $this->markerCluster->resetMarkers(); + $this->markerCluster->addMarker($marker = $this->createMarkerMock()); + $this->markerCluster->addMarker($marker); + + $this->assertMarkers(array($marker)); + } + + public function testRemoveMarker() + { + $this->markerCluster->addMarker($marker = $this->createMarkerMock()); + $this->markerCluster->removeMarker($marker); + + $this->assertNoMarker($marker); + } + + public function testSetType() + { + $this->markerCluster->setType($type = MarkerClusterType::MARKER_CLUSTER); + + $this->assertSame($type, $this->markerCluster->getType()); + } + + /** + * Asserts there are markers. + * + * @param array $markers The markers. + */ + protected function assertMarkers($markers) + { + $this->assertInternalType('array', $markers); $this->assertTrue($this->markerCluster->hasMarkers()); - $this->assertSame(array($marker), $this->markerCluster->getMarkers()); + $this->assertSame($markers, $this->markerCluster->getMarkers()); + + foreach ($markers as $marker) { + $this->assertMarker($marker); + } + } + + /** + * Asserts there is a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + protected function assertMarker($marker) + { + $this->assertMarkerInstance($marker); + $this->assertTrue($this->markerCluster->hasMarker($marker)); + } + + /** + * Asserts there are no markers. + */ + protected function assertNoMarkers() + { + $this->assertFalse($this->markerCluster->hasMarkers()); + $this->assertEmpty($this->markerCluster->getMarkers()); + } + + /** + * Asserts there is no marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + protected function assertNoMarker($marker) + { + $this->assertMarkerInstance($marker); + $this->assertFalse($this->markerCluster->hasMarker($marker)); } } diff --git a/tests/Overlays/MarkerClusterTypeTest.php b/tests/Overlays/MarkerClusterTypeTest.php new file mode 100644 index 00000000..679e0d22 --- /dev/null +++ b/tests/Overlays/MarkerClusterTypeTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\GoogleMap\Overlays\MarkerClusterType; + +/** + * Marker cluster type test. + * + * @author GeLo + */ +class MarkerClusterTypeTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Overlays\MarkerClusterType'); + } + + public function testConstants() + { + $this->assertSame('default', MarkerClusterType::DEFAULT_); + $this->assertSame('marker_cluster', MarkerClusterType::MARKER_CLUSTER); + } +} diff --git a/tests/Overlays/MarkerImageTest.php b/tests/Overlays/MarkerImageTest.php deleted file mode 100644 index e68f73a2..00000000 --- a/tests/Overlays/MarkerImageTest.php +++ /dev/null @@ -1,249 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Overlays; - -use Ivory\GoogleMap\Overlays\MarkerImage; - -/** - * Marker image test. - * - * @author GeLo - */ -class MarkerImageTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Overlays\MarkerImage */ - protected $markerImage; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->markerImage = new MarkerImage(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->markerImage); - } - - public function testDefaultState() - { - $this->assertSame('//maps.gstatic.com/mapfiles/markers/marker.png', $this->markerImage->getUrl()); - $this->assertFalse($this->markerImage->hasAnchor()); - $this->assertFalse($this->markerImage->hasOrigin()); - $this->assertFalse($this->markerImage->hasScaledSize()); - $this->assertFalse($this->markerImage->hasSize()); - } - - public function testInitialState() - { - $url = 'foo'; - $anchor = $this->getMock('Ivory\GoogleMap\Base\Point'); - $origin = $this->getMock('Ivory\GoogleMap\Base\Point'); - $scaledSize = $this->getMock('Ivory\GoogleMap\Base\Size'); - $size = $this->getMock('Ivory\GoogleMap\Base\Size'); - - $this->markerImage = new MarkerImage($url, $anchor, $origin, $scaledSize, $size); - - $this->assertSame($url, $this->markerImage->getUrl()); - $this->assertSame($anchor, $this->markerImage->getAnchor()); - $this->assertSame($origin, $this->markerImage->getOrigin()); - $this->assertSame($scaledSize, $this->markerImage->getScaledSize()); - $this->assertSame($size, $this->markerImage->getSize()); - } - - public function testUrlWithValidValue() - { - $this->markerImage->setUrl('foo'); - - $this->assertSame('foo', $this->markerImage->getUrl()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The url of a maker image must be a string value. - */ - public function testUrlWithInvalidValue() - { - $this->markerImage->setUrl(true); - } - - public function testAnchorWithPoint() - { - $point = $this->getMock('Ivory\GoogleMap\Base\Point'); - $this->markerImage->setAnchor($point); - - $this->assertSame($point, $this->markerImage->getAnchor()); - } - - public function testAnchorWithXAndY() - { - $x = 2; - $y = 3; - - $this->markerImage->setAnchor($x, $y); - - $this->assertSame($x, $this->markerImage->getAnchor()->getX()); - $this->assertSame($y, $this->markerImage->getAnchor()->getY()); - } - - public function testAnchorWithNullValue() - { - $this->markerImage->setAnchor($this->getMock('Ivory\GoogleMap\Base\Point')); - $this->markerImage->setAnchor(null); - - $this->assertNull($this->markerImage->getAnchor()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The anchor setter arguments is invalid. - * The available prototypes are : - * - function setAnchor(Ivory\GoogleMap\Base\Point $anchor) - * - function setAnchor(double x, double y) - */ - public function testAnchorWithInvalidValue() - { - $this->markerImage->setAnchor(true); - } - - public function testOriginWithPoint() - { - $point = $this->getMock('Ivory\GoogleMap\Base\Point'); - $this->markerImage->setOrigin($point); - - $this->assertSame($point, $this->markerImage->getOrigin()); - } - - public function testOriginWithXAndY() - { - $x = 2; - $y = 3; - - $this->markerImage->setOrigin($x, $y); - - $this->assertSame($x, $this->markerImage->getOrigin()->getX()); - $this->assertSame($y, $this->markerImage->getOrigin()->getY()); - } - - public function testOriginWithNullValue() - { - $this->markerImage->setOrigin($this->getMock('Ivory\GoogleMap\Base\Point')); - $this->markerImage->setOrigin(null); - - $this->assertNull($this->markerImage->getOrigin()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The origin setter arguments is invalid. - * The available prototypes are : - * - function setOrigin(Ivory\GoogleMap\Base\Point $anchor) - * - function setOrigin(double x, double y) - */ - public function testOriginWithInvalidValue() - { - $this->markerImage->setOrigin(true); - } - - public function testScaledSizeWithSize() - { - $size = $this->getMock('Ivory\GoogleMap\Base\Size'); - $this->markerImage->setScaledSize($size); - - $this->assertSame($size, $this->markerImage->getScaledSize()); - } - - public function testScaledSizeWithWidthAndHeight() - { - $width = 2; - $widthUnit = 'px'; - - $height = 3; - $heightUnit = '%'; - - $this->markerImage->setScaledSize($width, $height, $widthUnit, $heightUnit); - - $this->assertSame($width, $this->markerImage->getScaledSize()->getWidth()); - $this->assertSame($height, $this->markerImage->getScaledSize()->getHeight()); - $this->assertSame($widthUnit, $this->markerImage->getScaledSize()->getWidthUnit()); - $this->assertSame($heightUnit, $this->markerImage->getScaledSize()->getHeightUnit()); - } - - public function testScaledSizeWithNullValue() - { - $this->markerImage->setScaledSize($this->getMock('Ivory\GoogleMap\Base\Size')); - $this->markerImage->setScaledSize(null); - - $this->assertNull($this->markerImage->getScaledSize()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The scaled size setter arguments is invalid. - * The available prototypes are : - * - function setScaledSize(Ivory\GoogleMap\Base\Size $scaledSize = null) - * - function setScaledSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - */ - public function testScaledSizeWithInvalidValue() - { - $this->markerImage->setScaledSize('foo'); - } - - public function testSizeWithSize() - { - $size = $this->getMock('Ivory\GoogleMap\Base\Size'); - $this->markerImage->setSize($size); - - $this->assertSame($size, $this->markerImage->getSize()); - } - - public function testSizeWithWidthAndHeight() - { - $width = 2; - $widthUnit = 'px'; - - $height = 3; - $heightUnit = '%'; - - $this->markerImage->setSize($width, $height, $widthUnit, $heightUnit); - - $this->assertSame($width, $this->markerImage->getSize()->getWidth()); - $this->assertSame($height, $this->markerImage->getSize()->getHeight()); - $this->assertSame($widthUnit, $this->markerImage->getSize()->getWidthUnit()); - $this->assertSame($heightUnit, $this->markerImage->getSize()->getHeightUnit()); - } - - public function testSizeWithNullValue() - { - $this->markerImage->setSize($this->getMock('Ivory\GoogleMap\Base\Size')); - $this->markerImage->setSize(null); - - $this->assertNull($this->markerImage->getSize()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The size setter arguments is invalid. - * The available prototypes are : - * - function setSize(Ivory\GoogleMap\Base\Size $scaledSize = null) - * - function setSize(double $width, double $height, string $widthUnit = null, string $heightUnit = null) - */ - public function testSizeWithInvalidValue() - { - $this->markerImage->setSize('foo'); - } -} diff --git a/tests/Overlays/MarkerShapeTest.php b/tests/Overlays/MarkerShapeTest.php index 8de2bfba..13f365dc 100644 --- a/tests/Overlays/MarkerShapeTest.php +++ b/tests/Overlays/MarkerShapeTest.php @@ -12,23 +12,33 @@ namespace Ivory\Tests\GoogleMap\Overlays; use Ivory\GoogleMap\Overlays\MarkerShape; +use Ivory\GoogleMap\Overlays\MarkerShapeType; /** * Marker shape test. * * @author GeLo */ -class MarkerShapeTest extends \PHPUnit_Framework_TestCase +class MarkerShapeTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Overlays\MarkerShape */ protected $markerShape; + /** @var string */ + protected $type; + + /** @var array */ + protected $coordinates; + /** * {@inheritdoc} */ protected function setUp() { - $this->markerShape = new MarkerShape(); + $this->markerShape = new MarkerShape( + $this->type = MarkerShapeType::CIRCLE, + $this->coordinates = array(0, 0, 1) + ); } /** @@ -39,137 +49,88 @@ protected function tearDown() unset($this->markerShape); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame('poly', $this->markerShape->getType()); - $this->assertTrue($this->markerShape->hasCoordinates()); - $this->assertSame(array(1, 1, 1, -1, -1, -1, -1, 1), $this->markerShape->getCoordinates()); + $this->assertVariableAssetInstance($this->markerShape); } public function testInitialState() { - $type = 'rect'; - $coordinates = array(1, 1, -1, -1); - - $this->markerShape = new MarkerShape($type, $coordinates); - - $this->assertSame($type, $this->markerShape->getType()); - $this->assertSame($coordinates, $this->markerShape->getCoordinates()); + $this->assertStringStartsWith('marker_shape_', $this->markerShape->getVariable()); + $this->assertSame($this->type, $this->markerShape->getType()); + $this->assertCoordinates($this->coordinates); } - public function testTypeWithValidValue() + public function testSetType() { - $this->markerShape->setType('rect'); - - $this->assertSame('rect', $this->markerShape->getType()); - } + $this->markerShape->setType($type = MarkerShapeType::RECTANGLE); - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The type of a marker shape can only be : circle, poly, rect. - */ - public function testTypeWithInvalidValue() - { - $this->markerShape->setType('foo'); + $this->assertSame($type, $this->markerShape->getType()); } - public function testCircleCoordinatesWithValidValue() + public function testResetCoordinates() { - $this->markerShape->setType('circle'); - $this->markerShape->setCoordinates(array(1, 2, 3)); - - $this->assertSame(array(1, 2, 3), $this->markerShape->getCoordinates()); - } + $this->markerShape->resetCoordinates(); - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinates setter arguments is invalid if the marker shape type is circle. - * The available prototype is : function setCoordinates(array(double $x, double $y, double $r)) - */ - public function testCircleCoordinatesWithInvalidValue() - { - $this->markerShape->setType('circle'); - $this->markerShape->setCoordinates(array(true)); + $this->assertNoCoordinates(); } - public function testPolyCoordinatesWithValidValue() + public function testSetCoordinates() { - $this->markerShape->setType('poly'); - $this->markerShape->setCoordinates(array(1, 2, 3, 4, 5, 6)); + $this->markerShape->setCoordinates($coordinates = array(1, 2, 3, 4)); - $this->assertSame(array(1, 2, 3, 4, 5, 6), $this->markerShape->getCoordinates()); + $this->assertCoordinates($coordinates); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinates setter arguments is invalid if the marker shape type is poly. - * The available prototype is : function setCoordinates(array(double $x1, double $y1, ..., double $xn, double $yn)) - */ - public function testPolyCoordinatesWithInvalidParametersCount() + public function testSetCircleCoordinates() { - $this->markerShape->setType('poly'); - $this->markerShape->setCoordinates(array(1)); - } + $this->markerShape->setCircleCoordinates($x = 1, $y = 2, $radius = 3); - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinates setter arguments is invalid if the marker shape type is poly. - * The available prototype is : function setCoordinates(array(double $x1, double $y1, ..., double $xn, double $yn)) - */ - public function testPolyCoordinatesWithInvalidValue() - { - $this->markerShape->setType('poly'); - $this->markerShape->setCoordinates(array(1, true)); + $this->assertCoordinates(array($x, $y, $radius)); } - public function testRectCoordinatesWithValidValue() + public function testSetRectangleCoordinates() { - $this->markerShape->setType('rect'); - $this->markerShape->setCoordinates(array(1, 2, 3, 4)); + $this->markerShape->setRectangleCoordinates($x1 = 1, $y1 = 2, $x2 = 3, $y2 = 4); - $this->assertSame(array(1, 2, 3, 4), $this->markerShape->getCoordinates()); + $this->assertCoordinates(array($x1, $y1, $x2, $y2)); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinates setter arguments is invalid if the marker shape type is rect. - * The available prototype is : function setCoordinates(array(double $x1, double $y1, double $x2, double $y2)) - */ - public function testRectCoordinatesWithInvalidValue() + public function testSetPolygonCoordinates() { - $this->markerShape->setType('rect'); - $this->markerShape->setCoordinates(array(true)); + $this->markerShape->setPolygonCoordinates($polygonCoordinates = array(1, 2, 3, 4)); + + $this->assertCoordinates($polygonCoordinates); } - public function testAddPolyCoordinateWithValidValue() + public function testAddPolygonCoordinate() { $this->markerShape->resetCoordinates(); - $this->markerShape->setType('poly'); + $this->markerShape->addPolygonCoordinate($x1 = 1, $y1 = 2); + $this->markerShape->addPolygonCoordinate($x2 = 3, $y2 = 4); - $this->markerShape->addPolyCoordinate(1, 2); - $this->markerShape->addPolyCoordinate(3, 4); - - $this->assertSame(array(1, 2, 3, 4), $this->markerShape->getCoordinates()); + $this->assertCoordinates(array($x1, $y1, $x2, $y2)); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The MarkerShape::addPolyCoordinate($x, $y) method can only be use with a marker - * shape which has type poly. + * Asserts there are coordinates. + * + * @param array $coordinates The coordinates. */ - public function testAddPolyCoordinateWithInvalidType() + protected function assertCoordinates($coordinates) { - $this->markerShape->setType('rect'); - $this->markerShape->addPolyCoordinate(1, 2); + $this->assertInternalType('array', $coordinates); + + $this->assertTrue($this->markerShape->hasCoordinates()); + $this->assertSame($coordinates, $this->markerShape->getCoordinates()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The x & y coordinates of a poly marker shape must be numeric values. + * Asserts there are no coordinates. */ - public function testAddPolyCoordinateWithInvalidValue() + protected function assertNoCoordinates() { - $this->markerShape->setType('poly'); - $this->markerShape->addPolyCoordinate(true, false); + $this->assertFalse($this->markerShape->hasCoordinates()); + $this->assertEmpty($this->markerShape->getCoordinates()); } } diff --git a/tests/Overlays/MarkerShapeTypeTest.php b/tests/Overlays/MarkerShapeTypeTest.php new file mode 100644 index 00000000..73e4a8e4 --- /dev/null +++ b/tests/Overlays/MarkerShapeTypeTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\GoogleMap\Overlays\MarkerShapeType; + +/** + * Marker shape type test. + * + * @author GeLo + */ +class MarkerShapeTypeTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Overlays\MarkerShapeType'); + } + + public function testConstants() + { + $this->assertSame('circle', MarkerShapeType::CIRCLE); + $this->assertSame('poly', MarkerShapeType::POLYGON); + $this->assertSame('rect', MarkerShapeType::RECTANGLE); + } +} diff --git a/tests/Overlays/MarkerTest.php b/tests/Overlays/MarkerTest.php index 8058b56f..d15bdcc1 100644 --- a/tests/Overlays/MarkerTest.php +++ b/tests/Overlays/MarkerTest.php @@ -19,17 +19,20 @@ * * @author GeLo */ -class MarkerTest extends \PHPUnit_Framework_TestCase +class MarkerTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\Marker */ protected $marker; + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ + protected $position; + /** * {@inheritdoc} */ protected function setUp() { - $this->marker = new Marker(); + $this->marker = new Marker($this->position = $this->createCoordinateMock()); } /** @@ -37,269 +40,225 @@ protected function setUp() */ protected function tearDown() { + unset($this->position); unset($this->marker); } - public function testDefaultState() + public function testInheritance() { - $this->assertInstanceOf('Ivory\GoogleMap\Base\Coordinate', $this->marker->getPosition()); - $this->assertFalse($this->marker->hasAnimation()); - $this->assertFalse($this->marker->hasIcon()); - $this->assertFalse($this->marker->hasShadow()); - $this->assertFalse($this->marker->hasShape()); - $this->assertFalse($this->marker->hasInfoWindow()); + $this->assertOptionsAssetInstance($this->marker); + $this->assertExtendableInstance($this->marker); } - public function testInitialState() + public function testDefaultState() { - $position = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $animation = Animation::DROP; - - $icon = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $icon - ->expects($this->once()) - ->method('getUrl') - ->will($this->returnValue('foo')); - - $shadow = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $shadow - ->expects($this->once()) - ->method('getUrl') - ->will($this->returnValue('foo')); - - $shape = $this->getMock('Ivory\GoogleMap\Overlays\MarkerShape'); - $shape - ->expects($this->once()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $infoWindow = $this->getMock('Ivory\GoogleMap\Overlays\InfoWindow'); - - $this->marker = new Marker($position, $animation, $icon, $shadow, $shape, $infoWindow); - - $this->assertSame($position, $this->marker->getPosition()); - $this->assertSame($animation, $this->marker->getAnimation()); - $this->assertSame($icon, $this->marker->getIcon()); - $this->assertSame($shadow, $this->marker->getShadow()); - $this->assertSame($shape, $this->marker->getShape()); - $this->assertSame($infoWindow, $this->marker->getInfoWindow()); + $this->assertStringStartsWith('marker_', $this->marker->getVariable()); + $this->assertSame($this->position, $this->marker->getPosition()); + $this->assertNoAnimation(); + $this->assertNoIcon(); + $this->assertNoShadow(); + $this->assertNoShape(); + $this->assertNoInfoWindow(); + $this->assertFalse($this->marker->hasOptions()); } - public function testPositionWithCoordinate() + public function testSetPosition() { - $coordinate = $this->getMock('ivory\GoogleMap\Base\Coordinate'); - $this->marker->setPosition($coordinate); + $this->marker->setPosition($position = $this->createCoordinateMock()); - $this->assertSame($coordinate, $this->marker->getPosition()); + $this->assertSame($position, $this->marker->getPosition()); } - public function testPositionWithLatitudeAndLongitude() + public function testSetAnimation() { - $latitude = 1; - $longitude = 2; - - $this->marker->setPosition($latitude, $longitude, true); + $this->marker->setAnimation($animation = Animation::BOUNCE); - $this->assertSame($latitude, $this->marker->getPosition()->getLatitude()); - $this->assertSame($longitude, $this->marker->getPosition()->getLongitude()); - $this->assertTrue($this->marker->getPosition()->isNoWrap()); + $this->assertAnimation($animation); } - public function testPositionWithNullValue() + public function testResetAnimation() { - $this->marker->setPosition($this->getMock('ivory\GoogleMap\Base\Coordinate')); - $this->marker->setPosition(null); + $this->marker->setAnimation(Animation::BOUNCE); + $this->marker->setAnimation(null); - $this->assertNull($this->marker->getPosition()); + $this->assertNoAnimation(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The position setter arguments is invalid. - * The available prototypes are : - * - function setPosition(Ivory\GoogleMap\Base\Coordinate $position) - * - function setPosition(double $latitude, double $longitude, boolean $noWrap = true) - */ - public function testPositionWithInvalidValue() + public function testSetIcon() { - $this->marker->setPosition('foo'); + $this->marker->setIcon($icon = $this->createIconMock()); + + $this->assertSame($icon, $this->marker->getIcon()); } - public function testAnimationWithValidValue() + public function testResetIcon() { - $this->marker->setAnimation(Animation::DROP); + $this->marker->setIcon($this->createIconMock()); + $this->marker->setIcon(null); - $this->assertSame(Animation::DROP, $this->marker->getAnimation()); + $this->assertNoIcon(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The animation of a marker can only be : bounce, drop. - */ - public function testAnimationWithInvalidValue() + public function testSetShadow() { - $this->marker->setAnimation('foo'); + $this->marker->setShadow($shadow = $this->createIconMock()); + + $this->assertShadow($shadow); } - public function testIconWithValidMarkerImage() + public function testResetShadow() { - $markerImage = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $markerImage - ->expects($this->once()) - ->method('getUrl') - ->will($this->returnValue('foo')); - - $this->marker->setIcon($markerImage); + $this->marker->setShadow($this->createIconMock()); + $this->marker->setShadow(null); - $this->assertSame($markerImage, $this->marker->getIcon()); + $this->assertNoShadow(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage A marker image icon must have an url. - */ - public function testIconWithInvalidMarkerImage() + public function testSetShape() { - $markerImage = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $this->marker->setIcon($markerImage); + $this->marker->setShape($shape = $this->createMarkerShapeMock()); + + $this->assertShape($shape); } - public function testIconWithUrl() + public function testResetShape() { - $this->marker->setIcon('foo'); + $this->marker->setShape($this->createMarkerShapeMock()); + $this->marker->setShape(null); - $this->assertSame('foo', $this->marker->getIcon()->getUrl()); + $this->assertNoShape(); } - public function testIconWithNullValue() + public function testSetInfoWindow() { - $this->marker->setIcon('foo'); - $this->marker->setIcon(null); + $this->marker->setInfoWindow($infoWindow = $this->createInfoWindowMock()); - $this->assertNull($this->marker->getIcon()); + $this->assertInfoWindow($infoWindow); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The icon setter arguments is invalid. - * The available prototypes are : - * - function setIcon(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null) - * - function setIcon(string $url = null) - */ - public function testIconWithInvalidValue() + public function testResetInfoWindow() { - $this->marker->setIcon(true); + $this->marker->setInfoWindow($this->createInfoWindowMock()); + $this->marker->setInfoWindow(null); + + $this->assertNoInfoWindow(); } - public function testShadowWithValidMarkerImage() + public function testRenderExtend() { - $markerImage = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $markerImage - ->expects($this->once()) - ->method('getUrl') - ->will($this->returnValue('foo')); - - $this->marker->setShadow($markerImage); + $this->marker->setVariable('marker'); - $this->assertSame($markerImage, $this->marker->getShadow()); + $this->assertSame( + 'bound.extend(marker.getPosition())', + $this->marker->renderExtend($this->createBoundMock()) + ); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage A marker image shadow must have an url. + * Asserts there is an animation. + * + * @param string $animation The animation. */ - public function testShadowWithInvalidMarkerImage() + protected function assertAnimation($animation) { - $markerImage = $this->getMock('Ivory\GoogleMap\Overlays\MarkerImage'); - $this->marker->setShadow($markerImage); + $this->assertTrue($this->marker->hasAnimation()); + $this->assertSame($animation, $this->marker->getAnimation()); } - public function testShadowWithUrl() + /** + * Asserts there is an icon. + * + * @param \Ivory\GoogleMap\Overlays\Icon $icon The icon. + */ + protected function assertIcon($icon) { - $this->marker->setShadow('foo'); + $this->assertIconInstance($icon); - $this->assertSame('foo', $this->marker->getShadow()->getUrl()); + $this->assertTrue($this->marker->hasIcon()); + $this->assertSame($icon, $this->marker->getIcon()); } - public function testShadowWithNullValue() + /** + * Asserts there is a shadow. + * + * @param \Ivory\GoogleMap\Overlays\Icon $shadow The shadow. + */ + protected function assertShadow($shadow) { - $this->marker->setShadow('foo'); - $this->marker->setShadow(null); + $this->assertIconInstance($shadow); - $this->assertNull($this->marker->getShadow()); + $this->assertTrue($this->marker->hasShadow()); + $this->assertSame($shadow, $this->marker->getShadow()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The shadow setter arguments is invalid. - * The available prototypes are : - * - function setShadow(Ivory\GoogleMap\Overlays\MarkerImage $markerImage = null) - * - function setShadow(string $url = null) + * Asserts there is a shape. + * + * @param \Ivory\GoogleMap\Overlays\MarkerShape $shape The shape. */ - public function testShadowWithInvalidValue() + protected function assertShape($shape) { - $this->marker->setShadow(true); + $this->assertMarkerShapeInstance($shape); + + $this->assertTrue($this->marker->hasShape()); + $this->assertSame($shape, $this->marker->getShape()); } - public function testShapeWithValidMarkerShape() + /** + * Asserts there is an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + protected function assertInfoWindow($infoWindow) { - $markerShape = $this->getMock('Ivory\GoogleMap\Overlays\MarkerShape'); - $markerShape - ->expects($this->once()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->marker->setShape($markerShape); + $this->assertInfoWindowInstance($infoWindow); - $this->assertSame($markerShape, $this->marker->getShape()); + $this->assertTrue($this->marker->hasInfoWindow()); + $this->assertSame($infoWindow, $this->marker->getInfoWindow()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage A marker shape must have coordinates. + * Asserts there is no animation. */ - public function testShapeWithInvalidMarkerShape() + protected function assertNoAnimation() { - $markerShape = $this->getMock('Ivory\GoogleMap\Overlays\MarkerShape'); - $this->marker->setShape($markerShape); + $this->assertFalse($this->marker->hasAnimation()); + $this->assertNull($this->marker->getAnimation()); } - public function testShapeWithTypeAndCoordinates() + /** + * Asserts there is no icon. + */ + protected function assertNoIcon() { - $type = 'poly'; - $coordinates = array(1, 2, 3, 4); - - $this->marker->setShape($type, $coordinates); - - $this->assertSame($type, $this->marker->getShape()->getType()); - $this->assertSame($coordinates, $this->marker->getShape()->getCoordinates()); + $this->assertFalse($this->marker->hasIcon()); + $this->assertNull($this->marker->getIcon()); } - public function testShapeWithNullValue() + /** + * Asserts there is no shadow. + */ + protected function assertNoShadow() { - $this->marker->setShape('poly', array(1, 2, 3, 4)); - $this->marker->setShape(null); - - $this->assertNull($this->marker->getShape()); + $this->assertFalse($this->marker->hasShadow()); + $this->assertNull($this->marker->getShadow()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The shape setter arguments is invalid. - * The available prototypes are : - * - function setShape(Ivory\GoogleMap\Overlays\MarkerShape $shape = null) - * - function setShape(string $type, array $coordinates) + * Asserts there is no shape. */ - public function testShapeWithInvalidValue() + protected function assertNoShape() { - $this->marker->setShape(true); + $this->assertFalse($this->marker->hasShape()); + $this->assertNull($this->marker->getShape()); } - public function testInfoWindow() + /** + * Asserts there is no info window. + */ + protected function assertNoInfoWindow() { - $infoWindow = $this->getMock('Ivory\GoogleMap\Overlays\InfoWindow'); - $this->marker->setInfoWindow($infoWindow); - - $this->assertSame($infoWindow, $this->marker->getInfoWindow()); + $this->assertFalse($this->marker->hasInfoWindow()); + $this->assertNull($this->marker->getInfoWindow()); } } diff --git a/tests/Overlays/OverlaysTest.php b/tests/Overlays/OverlaysTest.php new file mode 100644 index 00000000..7e15e7e3 --- /dev/null +++ b/tests/Overlays/OverlaysTest.php @@ -0,0 +1,1546 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Overlays; + +use Ivory\GoogleMap\Overlays\Overlays; + +/** + * Overlays test. + * + * @author GeLo + */ +class OverlaysTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Overlays\Overlays */ + protected $overlays; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->overlays = new Overlays(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->overlays); + } + + public function testDefaultState() + { + $this->assertMarkerClusterInstance($this->overlays->getMarkerCluster()); + $this->assertNoCircles(); + $this->assertNoEncodedPolylines(); + $this->assertNoGroundOverlays(); + $this->assertNoInfoWindows(); + $this->assertNoPolygons(); + $this->assertNoPolylines(); + $this->assertNoRectangles(); + $this->assertNoExtendables(); + $this->assertFalse($this->overlays->isAutoZoom()); + } + + public function testSetMarkerClusterWithoutAutoZoom() + { + $this->overlays->setMarkerCluster($this->createMarkerClusterMock($markers = array($this->createMarkerMock()))); + + $this->assertMarkers($markers); + $this->assertNoExtendables(); + } + + public function testSetMarkerClusterWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setMarkerCluster($this->createMarkerClusterMock($markers = array($this->createMarkerMock()))); + + $this->assertMarkers($markers); + $this->assertExtendables($markers); + } + + public function testSetMarkersWithoutAutoZoom() + { + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + + $this->assertMarkers($markers); + $this->assertNoExtendables(); + } + + public function testSetMarkersWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + + $this->assertMarkers($markers); + $this->assertExtendables($markers); + } + + public function testAddMarkersWithoutAutoZoom() + { + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + $this->overlays->addMarkers($newMarkers = array($this->createMarkerMock())); + + $this->assertMarkers(array_merge($markers, $newMarkers)); + $this->assertNoExtendables(); + } + + public function testAddMarkersWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + $this->overlays->addMarkers($newMarkers = array($this->createMarkerMock())); + + $this->assertMarkers($expected = array_merge($markers, $newMarkers)); + $this->assertExtendables($expected); + } + + public function testRemoveMarkersWithoutAutoZoom() + { + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + $this->overlays->removeMarkers($markers); + + $this->assertNoMarkers(); + $this->assertNoExtendables(); + } + + public function testRemoveMarkersWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setMarkers($markers = array($this->createMarkerMock())); + $this->overlays->removeMarkers($markers); + + $this->assertNoMarkers(); + $this->assertNoExtendables(); + } + + public function testResetMarkersWithoutAutoZoom() + { + $this->overlays->setMarkers(array($this->createMarkerMock())); + $this->overlays->resetMarkers(); + + $this->assertNoMarkers(); + $this->assertNoExtendables(); + } + + public function testResetMarkersWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setMarkers(array($this->createMarkerMock())); + $this->overlays->resetMarkers(); + + $this->assertNoMarkers(); + $this->assertNoExtendables(); + } + + public function testAddMarkerWithoutAutoZoom() + { + $this->overlays->addMarker($marker = $this->createMarkerMock()); + + $this->assertMarker($marker); + $this->assertNoExtendable($marker); + } + + public function testAddMarkerWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addMarker($marker = $this->createMarkerMock()); + + $this->assertMarker($marker); + $this->assertExtendable($marker); + } + + public function testAddMarkerUnicity() + { + $this->overlays->resetMarkers(); + $this->overlays->addMarker($marker = $this->createMarkerMock()); + $this->overlays->addMarker($marker); + + $this->assertMarkers(array($marker)); + } + + public function testRemoveMarkerWithoutAutoZoom() + { + $this->overlays->addMarker($marker = $this->createMarkerMock()); + $this->overlays->removeMarker($marker); + + $this->assertNoMarker($marker); + $this->assertNoExtendable($marker); + } + + public function testRemoveMarkerWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addMarker($marker = $this->createMarkerMock()); + $this->overlays->removeMarker($marker); + + $this->assertNoMarker($marker); + $this->assertNoExtendable($marker); + } + + public function testSetCirclesWithoutAutoZoom() + { + $this->overlays->setCircles($circles = array($this->createCircleMock())); + + $this->assertCircles($circles); + $this->assertNoExtendables(); + } + + public function testSetCirclesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setCircles($circles = array($this->createCircleMock())); + + $this->assertCircles($circles); + $this->assertExtendables($circles); + } + + public function testAddCirclesWithoutAutoZoom() + { + $this->overlays->setCircles($circles = array($this->createCircleMock())); + $this->overlays->addCircles($newCircles = array($this->createCircleMock())); + + $this->assertCircles(array_merge($circles, $newCircles)); + $this->assertNoExtendables(); + } + + public function testAddCirclesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setCircles($circles = array($this->createCircleMock())); + $this->overlays->addCircles($newCircles = array($this->createCircleMock())); + + $this->assertCircles($expected = array_merge($circles, $newCircles)); + $this->assertExtendables($expected); + } + + public function testRemoveCirclesWithoutAutoZoom() + { + $this->overlays->setCircles($circles = array($this->createCircleMock())); + $this->overlays->removeCircles($circles); + + $this->assertNoCircles(); + $this->assertNoExtendables(); + } + + public function testRemoveCirclesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setCircles($circles = array($this->createCircleMock())); + $this->overlays->removeCircles($circles); + + $this->assertNoCircles(); + $this->assertNoExtendables(); + } + + public function testResetCirclesWithoutAutoZoom() + { + $this->overlays->setCircles(array($this->createCircleMock())); + $this->overlays->resetCircles(); + + $this->assertNoCircles(); + $this->assertNoExtendables(); + } + + public function testResetCirclesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setCircles(array($this->createCircleMock())); + $this->overlays->resetCircles(); + + $this->assertNoCircles(); + $this->assertNoExtendables(); + } + + public function testAddCircleWithoutAutoZoom() + { + $this->overlays->addCircle($circle = $this->createCircleMock()); + + $this->assertCircle($circle); + $this->assertNoExtendable($circle); + } + + public function testAddCircleWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addCircle($circle = $this->createCircleMock()); + + $this->assertCircle($circle); + $this->assertExtendable($circle); + } + + public function testAddCircleUnicity() + { + $this->overlays->resetCircles(); + $this->overlays->addCircle($circle = $this->createCircleMock()); + $this->overlays->addCircle($circle); + + $this->assertCircles(array($circle)); + } + + public function testRemoveCircleWithoutAutoZoom() + { + $this->overlays->addCircle($circle = $this->createCircleMock()); + $this->overlays->removeCircle($circle); + + $this->assertNoCircle($circle); + $this->assertNoExtendable($circle); + } + + public function testRemoveCircleWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addCircle($circle = $this->createCircleMock()); + $this->overlays->removeCircle($circle); + + $this->assertNoCircle($circle); + $this->assertNoExtendable($circle); + } + + public function testSetEncodedPolylinesWithoutAutoZoom() + { + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + + $this->assertEncodedPolylines($encodedPolylines); + $this->assertNoExtendables(); + } + + public function testSetEncodedPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + + $this->assertEncodedPolylines($encodedPolylines); + $this->assertExtendables($encodedPolylines); + } + + public function testAddEncodedPolylinesWithoutAutoZoom() + { + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + $this->overlays->addEncodedPolylines($newEncodedPolylines = array($this->createEncodedPolylineMock())); + + $this->assertEncodedPolylines(array_merge($encodedPolylines, $newEncodedPolylines)); + $this->assertNoExtendables(); + } + + public function testAddEncodedPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + $this->overlays->addEncodedPolylines($newEncodedPolylines = array($this->createEncodedPolylineMock())); + + $this->assertEncodedPolylines($expected = array_merge($encodedPolylines, $newEncodedPolylines)); + $this->assertExtendables($expected); + } + + public function testRemoveEncodedPolylinesWithoutAutoZoom() + { + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + $this->overlays->removeEncocodedPolylines($encodedPolylines); + + $this->assertNoEncodedPolylines(); + $this->assertNoExtendables(); + } + + public function testRemoveEncodedPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setEncodedPolylines($encodedPolylines = array($this->createEncodedPolylineMock())); + $this->overlays->removeEncocodedPolylines($encodedPolylines); + + $this->assertNoEncodedPolylines(); + $this->assertNoExtendables(); + } + + public function testResetEncodedPolylinesWithoutAutoZoom() + { + $this->overlays->setEncodedPolylines(array($this->createEncodedPolylineMock())); + $this->overlays->resetEncodedPolylines(); + + $this->assertNoEncodedPolylines(); + $this->assertNoExtendables(); + } + + public function testResetEncodedPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setEncodedPolylines(array($this->createEncodedPolylineMock())); + $this->overlays->resetEncodedPolylines(); + + $this->assertNoEncodedPolylines(); + $this->assertNoExtendables(); + } + + public function testAddEncodedPolylineWithoutAutoZoom() + { + $this->overlays->addEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + + $this->assertEncodedPolyline($encodedPolyline); + $this->assertNoExtendable($encodedPolyline); + } + + public function testAddEncodedPolylineWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + + $this->assertEncodedPolyline($encodedPolyline); + $this->assertExtendable($encodedPolyline); + } + + public function testAddEncodedPolylineUnicity() + { + $this->overlays->resetEncodedPolylines(); + $this->overlays->addEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + $this->overlays->addEncodedPolyline($encodedPolyline); + + $this->assertEncodedPolylines(array($encodedPolyline)); + } + + public function testRemoveEncodedPolylineWithoutAutoZoom() + { + $this->overlays->addEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + $this->overlays->removeEncodedPolyline($encodedPolyline); + + $this->assertNoEncodedPolyline($encodedPolyline); + $this->assertNoExtendable($encodedPolyline); + } + + public function testRemoveEncodedPolylineWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + $this->overlays->removeEncodedPolyline($encodedPolyline); + + $this->assertNoEncodedPolyline($encodedPolyline); + $this->assertNoExtendable($encodedPolyline); + } + + public function testSetGroundOverlaysWithoutAutoZoom() + { + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + + $this->assertGroundOverlays($groundOverlays); + $this->assertNoExtendables(); + } + + public function testSetGroundOverlaysWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + + $this->assertGroundOverlays($groundOverlays); + $this->assertExtendables($groundOverlays); + } + + public function testAddGroundOverlaysWithoutAutoZoom() + { + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + $this->overlays->addGroundOverlays($newGroundOverlays = array($this->createGroundOverlayMock())); + + $this->assertGroundOverlays(array_merge($groundOverlays, $newGroundOverlays)); + $this->assertNoExtendables(); + } + + public function testAddGroundOverlaysWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + $this->overlays->addGroundOverlays($newGroundOverlays = array($this->createGroundOverlayMock())); + + $this->assertGroundOverlays($expected = array_merge($groundOverlays, $newGroundOverlays)); + $this->assertExtendables($expected); + } + + public function testRemoveGroundOverlaysWithoutAutoZoom() + { + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + $this->overlays->removeGroundOverlays($groundOverlays); + + $this->assertNoGroundOverlays(); + $this->assertNoExtendables(); + } + + public function testRemoveGroundOverlaysWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setGroundOverlays($groundOverlays = array($this->createGroundOverlayMock())); + $this->overlays->removeGroundOverlays($groundOverlays); + + $this->assertNoGroundOverlays(); + $this->assertNoExtendables(); + } + + public function testResetGroundOverlaysWithoutAutoZoom() + { + $this->overlays->setGroundOverlays(array($this->createGroundOverlayMock())); + $this->overlays->resetGroundOverlays(); + + $this->assertNoGroundOverlays(); + $this->assertNoExtendables(); + } + + public function testResetGroundOverlaysWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setGroundOverlays(array($this->createGroundOverlayMock())); + $this->overlays->resetGroundOverlays(); + + $this->assertNoGroundOverlays(); + $this->assertNoExtendables(); + } + + public function testAddGroundOverlayWithoutAutoZoom() + { + $this->overlays->addGroundOverlay($groundOverlay = $this->createGroundOverlayMock()); + + $this->assertGroundOverlay($groundOverlay); + $this->assertNoExtendable($groundOverlay); + } + + public function testAddGroundOverlayWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addGroundOverlay($groundOverlay = $this->createGroundOverlayMock()); + + $this->assertGroundOverlay($groundOverlay); + $this->assertExtendable($groundOverlay); + } + + public function testAddGroundOverlayUnicity() + { + $this->overlays->resetGroundOverlays(); + $this->overlays->addGroundOverlay($groundOverlay = $this->createGroundOverlayMock()); + $this->overlays->addGroundOverlay($groundOverlay); + + $this->assertGroundOverlays(array($groundOverlay)); + } + + public function testRemoveGroundOverlayWithoutAutoZoom() + { + $this->overlays->addGroundOverlay($groundOverlay = $this->createGroundOverlayMock()); + $this->overlays->removeGroundOverlay($groundOverlay); + + $this->assertNoGroundOverlay($groundOverlay); + $this->assertNoExtendable($groundOverlay); + } + + public function testRemoveGroundOverlayWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addGroundOverlay($groundOverlay = $this->createGroundOverlayMock()); + $this->overlays->removeGroundOverlay($groundOverlay); + + $this->assertNoGroundOverlay($groundOverlay); + $this->assertNoExtendable($groundOverlay); + } + + public function testSetInfoWindowsWithoutAutoZoom() + { + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + + $this->assertInfoWindows($infoWindows); + $this->assertNoExtendables(); + } + + public function testSetInfoWindowsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + + $this->assertInfoWindows($infoWindows); + $this->assertExtendables($infoWindows); + } + + public function testAddInfoWindowsWithoutAutoZoom() + { + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + $this->overlays->addInfoWindows($newInfoWindows = array($this->createInfoWindowMock())); + + $this->assertInfoWindows(array_merge($infoWindows, $newInfoWindows)); + $this->assertNoExtendables(); + } + + public function testAddInfoWindowsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + $this->overlays->addInfoWindows($newInfoWindows = array($this->createInfoWindowMock())); + + $this->assertInfoWindows($expected = array_merge($infoWindows, $newInfoWindows)); + $this->assertExtendables($expected); + } + + public function testRemoveInfoWindowsWithoutAutoZoom() + { + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + $this->overlays->removeInfoWindows($infoWindows); + + $this->assertNoInfoWindows(); + $this->assertNoExtendables(); + } + + public function testRemoveInfoWindowsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setInfoWindows($infoWindows = array($this->createInfoWindowMock())); + $this->overlays->removeInfoWindows($infoWindows); + + $this->assertNoInfoWindows(); + $this->assertNoExtendables(); + } + + public function testResetInfoWindowsWithoutAutoZoom() + { + $this->overlays->setInfoWindows(array($this->createInfoWindowMock())); + $this->overlays->resetInfoWindows(); + + $this->assertNoInfoWindows(); + $this->assertNoExtendables(); + } + + public function testResetInfoWindowsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setInfoWindows(array($this->createInfoWindowMock())); + $this->overlays->resetInfoWindows(); + + $this->assertNoInfoWindows(); + $this->assertNoExtendables(); + } + + public function testAddInfoWindowWithoutAutoZoom() + { + $this->overlays->addInfoWindow($infoWindow = $this->createInfoWindowMock()); + + $this->assertInfoWindow($infoWindow); + $this->assertNoExtendable($infoWindow); + } + + public function testAddInfoWindowWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addInfoWindow($infoWindow = $this->createInfoWindowMock()); + + $this->assertInfoWindow($infoWindow); + $this->assertExtendable($infoWindow); + } + + public function testAddInfoWindowUnicity() + { + $this->overlays->resetInfoWindows(); + $this->overlays->addInfoWindow($infoWindow = $this->createInfoWindowMock()); + $this->overlays->addInfoWindow($infoWindow); + + $this->assertInfoWindows(array($infoWindow)); + } + + public function testRemoveInfoWindowWithoutAutoZoom() + { + $this->overlays->addInfoWindow($infoWindow = $this->createInfoWindowMock()); + $this->overlays->removeInfoWindow($infoWindow); + + $this->assertNoInfoWindow($infoWindow); + $this->assertNoExtendable($infoWindow); + } + + public function testRemoveInfoWindowWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addInfoWindow($infoWindow = $this->createInfoWindowMock()); + $this->overlays->removeInfoWindow($infoWindow); + + $this->assertNoInfoWindow($infoWindow); + $this->assertNoExtendable($infoWindow); + } + + public function testSetPolygonsWithoutAutoZoom() + { + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + + $this->assertPolygons($polygons); + $this->assertNoExtendables(); + } + + public function testSetPolygonsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + + $this->assertPolygons($polygons); + $this->assertExtendables($polygons); + } + + public function testAddPolygonsWithoutAutoZoom() + { + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + $this->overlays->addPolygons($newPolygons = array($this->createPolygonMock())); + + $this->assertPolygons(array_merge($polygons, $newPolygons)); + $this->assertNoExtendables(); + } + + public function testAddPolygonsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + $this->overlays->addPolygons($newPolygons = array($this->createPolygonMock())); + + $this->assertPolygons($expected = array_merge($polygons, $newPolygons)); + $this->assertExtendables($expected); + } + + public function testRemovePolygonsWithoutAutoZoom() + { + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + $this->overlays->removePolygons($polygons); + + $this->assertNoPolygons(); + $this->assertNoExtendables(); + } + + public function testRemovePolygonsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolygons($polygons = array($this->createPolygonMock())); + $this->overlays->removePolygons($polygons); + + $this->assertNoPolygons(); + $this->assertNoExtendables(); + } + + public function testResetPolygonsWithoutAutoZoom() + { + $this->overlays->setPolygons(array($this->createPolygonMock())); + $this->overlays->resetPolygons(); + + $this->assertNoPolygons(); + $this->assertNoExtendables(); + } + + public function testResetPolygonsWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolygons(array($this->createPolygonMock())); + $this->overlays->resetPolygons(); + + $this->assertNoPolygons(); + $this->assertNoExtendables(); + } + + public function testAddPolygonWithoutAutoZoom() + { + $this->overlays->addPolygon($polygon = $this->createPolygonMock()); + + $this->assertPolygon($polygon); + $this->assertNoExtendable($polygon); + } + + public function testAddPolygonWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addPolygon($polygon = $this->createPolygonMock()); + + $this->assertPolygon($polygon); + $this->assertExtendable($polygon); + } + + public function testAddPolygonUnicity() + { + $this->overlays->resetPolygons(); + $this->overlays->addPolygon($polygon = $this->createPolygonMock()); + $this->overlays->addPolygon($polygon); + + $this->assertPolygons(array($polygon)); + } + + public function testRemovePolygonWithoutAutoZoom() + { + $this->overlays->addPolygon($polygon = $this->createPolygonMock()); + $this->overlays->removePolygon($polygon); + + $this->assertNoPolygon($polygon); + $this->assertNoExtendable($polygon); + } + + public function testRemovePolygonWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addPolygon($polygon = $this->createPolygonMock()); + $this->overlays->removePolygon($polygon); + + $this->assertNoPolygon($polygon); + $this->assertNoExtendable($polygon); + } + + public function testSetPolylinesWithoutAutoZoom() + { + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + + $this->assertPolylines($polylines); + $this->assertNoExtendables(); + } + + public function testSetPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + + $this->assertPolylines($polylines); + $this->assertExtendables($polylines); + } + + public function testAddPolylinesWithoutAutoZoom() + { + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + $this->overlays->addPolylines($newPolylines = array($this->createPolylineMock())); + + $this->assertPolylines(array_merge($polylines, $newPolylines)); + $this->assertNoExtendables(); + } + + public function testAddPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + $this->overlays->addPolylines($newPolylines = array($this->createPolylineMock())); + + $this->assertPolylines($expected = array_merge($polylines, $newPolylines)); + $this->assertExtendables($expected); + } + + public function testRemovePolylinesWithoutAutoZoom() + { + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + $this->overlays->removePolylines($polylines); + + $this->assertNoPolylines(); + $this->assertNoExtendables(); + } + + public function testRemovePolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolylines($polylines = array($this->createPolylineMock())); + $this->overlays->removePolylines($polylines); + + $this->assertNoPolylines(); + $this->assertNoExtendables(); + } + + public function testResetPolylinesWithoutAutoZoom() + { + $this->overlays->setPolylines(array($this->createPolylineMock())); + $this->overlays->resetPolylines(); + + $this->assertNoPolylines(); + $this->assertNoExtendables(); + } + + public function testResetPolylinesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setPolylines(array($this->createPolylineMock())); + $this->overlays->resetPolylines(); + + $this->assertNoPolylines(); + $this->assertNoExtendables(); + } + + public function testAddPolylineWithoutAutoZoom() + { + $this->overlays->addPolyline($polyline = $this->createPolylineMock()); + + $this->assertPolyline($polyline); + $this->assertNoExtendable($polyline); + } + + public function testAddPolylineWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addPolyline($polyline = $this->createPolylineMock()); + + $this->assertPolyline($polyline); + $this->assertExtendable($polyline); + } + + public function testAddPolylineUnicity() + { + $this->overlays->resetPolylines(); + $this->overlays->addPolyline($polyline = $this->createPolylineMock()); + $this->overlays->addPolyline($polyline); + + $this->assertPolylines(array($polyline)); + } + + public function testRemovePolylineWithoutAutoZoom() + { + $this->overlays->addPolyline($polyline = $this->createPolylineMock()); + $this->overlays->removePolyline($polyline); + + $this->assertNoPolyline($polyline); + $this->assertNoExtendable($polyline); + } + + public function testRemovePolylineWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addPolyline($polyline = $this->createPolylineMock()); + $this->overlays->removePolyline($polyline); + + $this->assertNoPolyline($polyline); + $this->assertNoExtendable($polyline); + } + + public function testSetRectanglesWithoutAutoZoom() + { + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + + $this->assertRectangles($rectangles); + $this->assertNoExtendables(); + } + + public function testSetRectanglesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + + $this->assertRectangles($rectangles); + $this->assertExtendables($rectangles); + } + + public function testAddRectanglesWithoutAutoZoom() + { + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + $this->overlays->addRectangles($newRectangles = array($this->createRectangleMock())); + + $this->assertRectangles(array_merge($rectangles, $newRectangles)); + $this->assertNoExtendables(); + } + + public function testAddRectanglesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + $this->overlays->addRectangles($newRectangles = array($this->createRectangleMock())); + + $this->assertRectangles($expected = array_merge($rectangles, $newRectangles)); + $this->assertExtendables($expected); + } + + public function testRemoveRectanglesWithoutAutoZoom() + { + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + $this->overlays->removeRectangles($rectangles); + + $this->assertNoRectangles(); + $this->assertNoExtendables(); + } + + public function testRemoveRectanglesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setRectangles($rectangles = array($this->createRectangleMock())); + $this->overlays->removeRectangles($rectangles); + + $this->assertNoRectangles(); + $this->assertNoExtendables(); + } + + public function testResetRectanglesWithoutAutoZoom() + { + $this->overlays->setRectangles(array($this->createRectangleMock())); + $this->overlays->resetRectangles(); + + $this->assertNoRectangles(); + $this->assertNoExtendables(); + } + + public function testResetRectanglesWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->setRectangles(array($this->createRectangleMock())); + $this->overlays->resetRectangles(); + + $this->assertNoRectangles(); + $this->assertNoExtendables(); + } + + public function testAddRectangleWithoutAutoZoom() + { + $this->overlays->addRectangle($rectangle = $this->createRectangleMock()); + + $this->assertRectangle($rectangle); + $this->assertNoExtendable($rectangle); + } + + public function testAddRectangleWithoAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addRectangle($rectangle = $this->createRectangleMock()); + + $this->assertRectangle($rectangle); + $this->assertExtendable($rectangle); + } + + public function testAddRectangleUnicity() + { + $this->overlays->resetRectangles(); + $this->overlays->addRectangle($rectangle = $this->createRectangleMock()); + $this->overlays->addRectangle($rectangle); + + $this->assertRectangles(array($rectangle)); + } + + public function testRemoveRectangleWithoutAutoZoom() + { + $this->overlays->addRectangle($rectangle = $this->createRectangleMock()); + $this->overlays->removeRectangle($rectangle); + + $this->assertNoRectangle($rectangle); + $this->assertNoExtendable($rectangle); + } + + public function testRemoveRectangleWithAutoZoom() + { + $this->overlays->setAutoZoom(true); + $this->overlays->addRectangle($rectangle = $this->createRectangleMock()); + $this->overlays->removeRectangle($rectangle); + + $this->assertNoRectangle($rectangle); + $this->assertNoExtendable($rectangle); + } + + public function testSetExtends() + { + $this->overlays->setExtends($extends = array($this->createExtendableMock())); + + $this->assertExtendables($extends); + } + + public function testAddExtends() + { + $this->overlays->setExtends($extends = array($this->createExtendableMock())); + $this->overlays->addExtends($newExtends = array($this->createExtendableMock())); + + $this->assertExtendables(array_merge($extends, $newExtends)); + } + + public function testRemoveExtends() + { + $this->overlays->setExtends($extends = array($this->createExtendableMock())); + $this->overlays->removeExtends($extends); + + $this->assertNoExtendables(); + } + + public function testResetExtends() + { + $this->overlays->setExtends(array($this->createExtendableMock())); + $this->overlays->resetExtends(); + + $this->assertNoExtendables(); + } + + public function testAddExtend() + { + $this->overlays->addExtend($extend = $this->createExtendableMock()); + + $this->assertExtendable($extend); + } + + public function testAddExtendUnicity() + { + $this->overlays->resetExtends(); + $this->overlays->addExtend($extend = $this->createExtendableMock()); + $this->overlays->addExtend($extend); + + $this->assertExtendables(array($extend)); + } + + public function testRemoveExtend() + { + $this->overlays->addExtend($extend = $this->createExtendableMock()); + $this->overlays->removeExtend($extend); + + $this->assertNoExtendable($extend); + } + + public function testSetAutoZoom() + { + $this->overlays->setAutoZoom(true); + + $this->assertTrue($this->overlays->isAutoZoom()); + } + + /** + * Asserts there are markers. + * + * @param array $markers The markers. + */ + protected function assertMarkers($markers) + { + $this->assertInternalType('array', $markers); + + $this->assertTrue($this->overlays->hasMarkers()); + $this->assertSame($markers, $this->overlays->getMarkers()); + + foreach ($markers as $marker) { + $this->assertMarker($marker); + } + } + + /** + * Asserts there is a marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + protected function assertMarker($marker) + { + $this->assertMarkerInstance($marker); + $this->assertTrue($this->overlays->hasMarker($marker)); + } + + /** + * Asserts there are circles. + * + * @param array $circles The circles. + */ + protected function assertCircles($circles) + { + $this->assertInternalType('array', $circles); + + $this->assertTrue($this->overlays->hasCircles()); + $this->assertSame($circles, $this->overlays->getCircles()); + + foreach ($circles as $circle) { + $this->assertCircle($circle); + } + } + + /** + * Asserts there is a circle. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + */ + protected function assertCircle($circle) + { + $this->assertCircleInstance($circle); + $this->assertTrue($this->overlays->hasCircle($circle)); + } + + /** + * Asserts there are encoded polylines. + * + * @param array $encodedPolylines The encoded polylines. + */ + protected function assertEncodedPolylines($encodedPolylines) + { + $this->assertInternalType('array', $encodedPolylines); + + $this->assertTrue($this->overlays->hasEncodedPolylines()); + $this->assertSame($encodedPolylines, $this->overlays->getEncodedPolylines()); + } + + /** + * Asserts there is an encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + */ + protected function assertEncodedPolyline($encodedPolyline) + { + $this->assertEncodedPolylineInstance($encodedPolyline); + $this->assertTrue($this->overlays->hasEncodedPolyline($encodedPolyline)); + } + + /** + * Asserts there are ground overlays. + * + * @param array $groundOverlays The ground overlays. + */ + protected function assertGroundOverlays($groundOverlays) + { + $this->assertInternalType('array', $groundOverlays); + + $this->assertTrue($this->overlays->hasGroundOverlays()); + $this->assertSame($groundOverlays, $this->overlays->getGroundOverlays()); + + foreach ($groundOverlays as $groundOverlay) { + $this->assertGroundOverlay($groundOverlay); + } + } + + /** + * Asserts there is a ground overlay. + * + * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. + */ + protected function assertGroundOverlay($groundOverlay) + { + $this->assertGroundOverlayInstance($groundOverlay); + $this->assertTrue($this->overlays->hasGroundOverlay($groundOverlay)); + } + + /** + * Asserts there are info windows. + * + * @param array $infoWindows The info windows. + */ + protected function assertInfoWindows($infoWindows) + { + $this->assertInternalType('array', $infoWindows); + + $this->assertTrue($this->overlays->hasInfoWindows()); + $this->assertSame($infoWindows, $this->overlays->getInfoWindows()); + + foreach ($infoWindows as $infoWindow) { + $this->assertInfoWindow($infoWindow); + } + } + + /** + * Asserts there is an info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + protected function assertInfoWindow($infoWindow) + { + $this->assertInfoWindowInstance($infoWindow); + $this->assertTrue($this->overlays->hasInfoWindow($infoWindow)); + } + + /** + * Asserts there are polygons. + * + * @param array $polygons The polygons. + */ + protected function assertPolygons($polygons) + { + $this->assertInternalType('array', $polygons); + + $this->assertTrue($this->overlays->hasPolygons()); + $this->assertSame($polygons, $this->overlays->getPolygons()); + + foreach ($polygons as $polygon) { + $this->assertPolygon($polygon); + } + } + + /** + * Asserts there is a polygon. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + */ + protected function assertPolygon($polygon) + { + $this->assertPolygonInstance($polygon); + $this->assertTrue($this->overlays->hasPolygon($polygon)); + } + + /** + * Asserts there are polylines. + * + * @param array $polylines The polylines. + */ + protected function assertPolylines($polylines) + { + $this->assertInternalType('array', $polylines); + + $this->assertTrue($this->overlays->hasPolylines()); + $this->assertSame($polylines, $this->overlays->getPolylines()); + + foreach ($polylines as $polyline) { + $this->assertPolyline($polyline); + } + } + + /** + * Asserts there is a polyline. + * + * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. + */ + protected function assertPolyline($polyline) + { + $this->assertPolylineInstance($polyline); + $this->assertTrue($this->overlays->hasPolyline($polyline)); + } + + /** + * Asserts there are rectangles. + * + * @param array $rectangles The rectangles. + */ + protected function assertRectangles($rectangles) + { + $this->assertInternalType('array', $rectangles); + + $this->assertTrue($this->overlays->hasRectangles()); + $this->assertSame($rectangles, $this->overlays->getRectangles()); + + foreach ($rectangles as $rectangle) { + $this->assertRectangle($rectangle); + } + } + + /** + * Asserts there is a rectangle. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle the rectangle. + */ + protected function assertRectangle($rectangle) + { + $this->assertRectangleInstance($rectangle); + $this->assertTrue($this->overlays->hasRectangle($rectangle)); + } + + /** + * Asserts there are extendables. + * + * @param array $extendables The extendables. + */ + protected function assertExtendables($extendables) + { + $this->assertInternalType('array', $extendables); + + $this->assertTrue($this->overlays->hasExtends()); + $this->assertSame($extendables, $this->overlays->getExtends()); + + foreach ($extendables as $extendable) { + $this->assertExtendable($extendable); + } + } + + /** + * Asserts there is an extendable. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extendable The extendable. + */ + protected function assertExtendable($extendable) + { + $this->assertExtendableInstance($extendable); + $this->assertTrue($this->overlays->hasExtend($extendable)); + } + + /** + * Asserts there are no markers. + */ + protected function assertNoMarkers() + { + $this->assertFalse($this->overlays->hasMarkers()); + $this->assertEmpty($this->overlays->getMarkers()); + } + + /** + * Asserts there is no marker. + * + * @param \Ivory\GoogleMap\Overlays\Marker $marker The marker. + */ + protected function assertNoMarker($marker) + { + $this->assertMarkerInstance($marker); + $this->assertFalse($this->overlays->hasMarker($marker)); + } + + /** + * Asserts there are no circles. + */ + protected function assertNoCircles() + { + $this->assertFalse($this->overlays->hasCircles()); + $this->assertEmpty($this->overlays->getCircles()); + } + + /** + * Asserts there is no circle. + * + * @param \Ivory\GoogleMap\Overlays\Circle $circle The circle. + */ + protected function assertNoCircle($circle) + { + $this->assertCircleInstance($circle); + $this->assertFalse($this->overlays->hasCircle($circle)); + } + + /** + * Asserts there are no encoded polylines. + */ + protected function assertNoEncodedPolylines() + { + $this->assertFalse($this->overlays->hasEncodedPolylines()); + $this->assertEmpty($this->overlays->getEncodedPolylines()); + } + + /** + * Asserts there is no encoded polyline. + * + * @param \Ivory\GoogleMap\Overlays\EncodedPolyline $encodedPolyline The encoded polyline. + */ + protected function assertNoEncodedPolyline($encodedPolyline) + { + $this->assertEncodedPolylineInstance($encodedPolyline); + $this->assertFalse($this->overlays->hasEncodedPolyline($encodedPolyline)); + } + + /** + * Asserts there are no ground overlays. + */ + protected function assertNoGroundOverlays() + { + $this->assertFalse($this->overlays->hasGroundOverlays()); + $this->assertEmpty($this->overlays->getGroundOverlays()); + } + + /** + * Asserts there is no ground overlay. + * + * @param \Ivory\GoogleMap\Overlays\GroundOverlay $groundOverlay The ground overlay. + */ + protected function assertNoGroundOverlay($groundOverlay) + { + $this->assertGroundOverlayInstance($groundOverlay); + $this->assertFalse($this->overlays->hasGroundOverlay($groundOverlay)); + } + + /** + * Asserts there are no info windows. + */ + protected function assertNoInfoWindows() + { + $this->assertFalse($this->overlays->hasInfoWindows()); + $this->assertEmpty($this->overlays->getInfoWindows()); + } + + /** + * Asserts there is no info window. + * + * @param \Ivory\GoogleMap\Overlays\InfoWindow $infoWindow The info window. + */ + protected function assertNoInfoWindow($infoWindow) + { + $this->assertInfoWindowInstance($infoWindow); + $this->assertFalse($this->overlays->hasInfoWindow($infoWindow)); + } + + /** + * Asserts there are no polygons. + */ + protected function assertNoPolygons() + { + $this->assertFalse($this->overlays->hasPolygons()); + $this->assertEmpty($this->overlays->getPolygons()); + } + + /** + * Asserts there is no polygon. + * + * @param \Ivory\GoogleMap\Overlays\Polygon $polygon The polygon. + */ + protected function assertNoPolygon($polygon) + { + $this->assertPolygonInstance($polygon); + $this->assertFalse($this->overlays->hasPolygon($polygon)); + } + + /** + * Asserts there are no polylines. + */ + protected function assertNoPolylines() + { + $this->assertFalse($this->overlays->hasPolylines()); + $this->assertEmpty($this->overlays->getPolylines()); + } + + /** + * Asserts there is no polyline. + * + * @param \Ivory\GoogleMap\Overlays\Polyline $polyline The polyline. + */ + protected function assertNoPolyline($polyline) + { + $this->assertPolylineInstance($polyline); + $this->assertFalse($this->overlays->hasPolyline($polyline)); + } + + /** + * Asserts there are no rectangles. + */ + protected function assertNoRectangles() + { + $this->assertFalse($this->overlays->hasRectangles()); + $this->assertEmpty($this->overlays->getRectangles()); + } + + /** + * Asserts there is no rectangle. + * + * @param \Ivory\GoogleMap\Overlays\Rectangle $rectangle The rectangle. + */ + protected function assertNoRectangle($rectangle) + { + $this->assertRectangleInstance($rectangle); + $this->assertFalse($this->overlays->hasRectangle($rectangle)); + } + + /** + * Asserts there are no extends. + */ + protected function assertNoExtendables() + { + $this->assertFalse($this->overlays->hasExtends()); + $this->assertEmpty($this->overlays->getExtends()); + } + + /** + * Asserts there is no extendable. + * + * @param \Ivory\GoogleMap\Overlays\ExtendableInterface $extendable The extendable. + */ + protected function assertNoExtendable($extendable) + { + $this->assertExtendableInstance($extendable); + $this->assertFalse($this->overlays->hasExtend($extendable)); + } + + /** + * Creates a marker cluster mock. + * + * @param array $markers The markers. + * + * @return \Ivory\GoogleMap\Overlays\MarkerCluster|\PHPUnit_Framework_MockObject_MockObject The marker cluster mock. + */ + protected function createMarkerClusterMock(array $markers = array()) + { + $markerCluster = parent::createMarkerClusterMock(); + + $markerCluster + ->expects($this->any()) + ->method('hasMarkers') + ->will($this->returnValue(!empty($markers))); + + $markerCluster + ->expects($this->any()) + ->method('getMarkers') + ->will($this->returnValue($markers)); + + foreach ($markers as $marker) { + $markerCluster + ->expects($this->any()) + ->method('hasMarker') + ->with($this->identicalTo($marker)) + ->will($this->returnValue(true)); + } + + return $markerCluster; + } +} diff --git a/tests/Overlays/PolygonTest.php b/tests/Overlays/PolygonTest.php index 62ea9283..cadca587 100644 --- a/tests/Overlays/PolygonTest.php +++ b/tests/Overlays/PolygonTest.php @@ -18,69 +18,154 @@ * * @author GeLo */ -class PolygonTest extends \PHPUnit_Framework_TestCase +class PolygonTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\Polygon */ protected $polygon; + /** @var array */ + protected $coordinates; + /** * {@inheritdoc} */ protected function setUp() { - $this->polygon = new Polygon(); + $this->polygon = new Polygon($this->coordinates = array($this->createCoordinateMock())); } /** - * {@in1, 2, 3, 4heritdoc} + * {@inheritdoc} */ protected function tearDown() { + unset($this->coordinates); unset($this->polygon); } + public function testInheritance() + { + $this->assertOptionsAssetInstance($this->polygon); + $this->assertExtendableInstance($this->polygon); + } + public function testDefaultState() { - $this->assertFalse($this->polygon->hasCoordinates()); + $this->assertStringStartsWith('polygon_', $this->polygon->getVariable()); + $this->assertCoordinates($this->coordinates); + $this->assertFalse($this->polygon->hasOptions()); } - public function testInitialState() + public function testSetCoordinates() { - $coordinates = array( - $this->getMock('Ivory\GoogleMap\Base\Coordinate'), - $this->getMock('Ivory\GoogleMap\Base\Coordinate'), + $this->polygon->setCoordinates($coordinates = array($this->createCoordinateMock())); + + $this->assertCoordinates($coordinates); + } + + public function testAddCoordinates() + { + $this->polygon->setCoordinates($coordinates = array($this->createCoordinateMock())); + $this->polygon->addCoordinates($newCoordinate = array($this->createCoordinateMock())); + + $this->assertCoordinates(array_merge($coordinates, $newCoordinate)); + } + + public function testRemoveCoordinates() + { + $this->polygon->setCoordinates($coordinates = array($this->createCoordinateMock())); + $this->polygon->removeCoordinates($coordinates); + + $this->assertNoCoordinates(); + } + + public function testResetCoordinates() + { + $this->polygon->setCoordinates(array($this->createCoordinateMock())); + $this->polygon->resetCoordinates(); + + $this->assertNoCoordinates(); + } + + public function testAddCoordinate() + { + $this->polygon->addCoordinate($coordinate = $this->createCoordinateMock()); + + $this->assertCoordinate($coordinate); + } + + public function testAddCoordinateUnicity() + { + $this->polygon->resetCoordinates(); + $this->polygon->addCoordinate($coordinate = $this->createCoordinateMock()); + $this->polygon->addCoordinate($coordinate); + + $this->assertCoordinates(array($coordinate)); + } + + public function testRemoveCoordinate() + { + $this->polygon->addCoordinate($coordinate = $this->createCoordinateMock()); + $this->polygon->removeCoordinate($coordinate); + + $this->assertNoCoordinate($coordinate); + } + + public function testRenderExtend() + { + $this->polygon->setVariable('polygon'); + + $this->assertSame( + 'polygon.getPath().forEach(function(e){bound.extend(e);})', + $this->polygon->renderExtend($this->createBoundMock()) ); + } - $this->polygon = new Polygon($coordinates); + /** + * Asserts there are coordinates. + * + * @param array $coordinates The coordinates. + */ + protected function assertCoordinates($coordinates) + { + $this->assertInternalType('array', $coordinates); $this->assertTrue($this->polygon->hasCoordinates()); $this->assertSame($coordinates, $this->polygon->getCoordinates()); + + foreach ($coordinates as $coordinate) { + $this->assertCoordinate($coordinate); + } } - public function testCoordinateWithLatitudeAndLongitude() + /** + * Asserts there is a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + protected function assertCoordinate($coordinate) { - $latitude = 1; - $longitude = 2; - - $this->polygon->addCoordinate($latitude, $longitude, true); - - $coordinates = $this->polygon->getCoordinates(); + $this->assertCoordinateInstance($coordinate); + $this->assertTrue($this->polygon->hasCoordinate($coordinate)); + } - $this->assertArrayHasKey(0, $coordinates); - $this->assertSame($latitude, $coordinates[0]->getLatitude()); - $this->assertSame($longitude, $coordinates[0]->getLongitude()); - $this->assertTrue($coordinates[0]->isNoWrap()); + /** + * Asserts there are no coordinates. + */ + protected function assertNoCoordinates() + { + $this->assertFalse($this->polygon->hasCoordinates()); + $this->assertEmpty($this->polygon->getCoordinates()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinate adder arguments is invalid. - * The available prototypes are : - * - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate) - * - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true) + * Asserts there is no coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. */ - public function testCoordinateWithInvalidValue() + protected function assertNoCoordinate($coordinate) { - $this->polygon->addCoordinate('foo'); + $this->assertCoordinateInstance($coordinate); + $this->assertFalse($this->polygon->hasCoordinate($coordinate)); } } diff --git a/tests/Overlays/PolylineTest.php b/tests/Overlays/PolylineTest.php index d7480451..1f214219 100644 --- a/tests/Overlays/PolylineTest.php +++ b/tests/Overlays/PolylineTest.php @@ -18,69 +18,154 @@ * * @author GeLo */ -class PolylineTest extends \PHPUnit_Framework_TestCase +class PolylineTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\Polyline */ protected $polyline; + /** @var array */ + protected $coordinates; + /** * {@inheritdoc} */ protected function setUp() { - $this->polyline = new Polyline(); + $this->polyline = new Polyline($this->coordinates = array($this->createCoordinateMock())); } /** - * {@in1, 2, 3, 4heritdoc} + * {@inheritdoc} */ protected function tearDown() { + unset($this->coordinates); unset($this->polyline); } + public function testInheritance() + { + $this->assertOptionsAssetInstance($this->polyline); + $this->assertExtendableInstance($this->polyline); + } + public function testDefaultState() { - $this->assertFalse($this->polyline->hasCoordinates()); + $this->assertStringStartsWith('polyline_', $this->polyline->getVariable()); + $this->assertCoordinates($this->coordinates); + $this->assertFalse($this->polyline->hasOptions()); } - public function testInitialState() + public function testSetCoordinates() { - $coordinates = array( - $this->getMock('Ivory\GoogleMap\Base\Coordinate'), - $this->getMock('Ivory\GoogleMap\Base\Coordinate'), + $this->polyline->setCoordinates($coordinates = array($this->createCoordinateMock())); + + $this->assertCoordinates($coordinates); + } + + public function testAddCoordinates() + { + $this->polyline->setCoordinates($coordinates = array($this->createCoordinateMock())); + $this->polyline->addCoordinates($newCoordinates = array($this->createCoordinateMock())); + + $this->assertCoordinates(array_merge($coordinates, $newCoordinates)); + } + + public function testRemoveCoordinates() + { + $this->polyline->setCoordinates($coordinates = array($this->createCoordinateMock())); + $this->polyline->removeCoordinates($coordinates); + + $this->assertNoCoordinates(); + } + + public function testResetCoordinates() + { + $this->polyline->setCoordinates(array($this->createCoordinateMock())); + $this->polyline->resetCoordinates(); + + $this->assertNoCoordinates(); + } + + public function testAddCoordinate() + { + $this->polyline->addCoordinate($coordinate = $this->createCoordinateMock()); + + $this->assertCoordinate($coordinate); + } + + public function testAddCoordinateUnicity() + { + $this->polyline->resetCoordinates(); + $this->polyline->addCoordinate($coordinate = $this->createCoordinateMock()); + $this->polyline->addCoordinate($coordinate); + + $this->assertCoordinates(array($coordinate)); + } + + public function testRemoveCoordinate() + { + $this->polyline->addCoordinate($coordinate = $this->createCoordinateMock()); + $this->polyline->removeCoordinate($coordinate); + + $this->assertNoCoordinate($coordinate); + } + + public function testRenderExtend() + { + $this->polyline->setVariable('polyline'); + + $this->assertSame( + 'polyline.getPath().forEach(function(e){bound.extend(e);})', + $this->polyline->renderExtend($this->createBoundMock()) ); + } - $this->polyline = new Polyline($coordinates); + /** + * Asserts there are coordinates. + * + * @param array $coordinates The coordinates. + */ + protected function assertCoordinates($coordinates) + { + $this->assertInternalType('array', $coordinates); $this->assertTrue($this->polyline->hasCoordinates()); $this->assertSame($coordinates, $this->polyline->getCoordinates()); + + foreach ($coordinates as $coordinate) { + $this->assertCoordinate($coordinate); + } } - public function testCoordinateWithLatitudeAndLongitude() + /** + * Asserts there is a coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. + */ + protected function assertCoordinate($coordinate) { - $latitude = 1; - $longitude = 2; - - $this->polyline->addCoordinate($latitude, $longitude, true); - - $coordinates = $this->polyline->getCoordinates(); + $this->assertCoordinateInstance($coordinate); + $this->assertTrue($this->polyline->hasCoordinate($coordinate)); + } - $this->assertArrayHasKey(0, $coordinates); - $this->assertSame($latitude, $coordinates[0]->getLatitude()); - $this->assertSame($longitude, $coordinates[0]->getLongitude()); - $this->assertTrue($coordinates[0]->isNoWrap()); + /** + * Asserts there are no coordinates. + */ + protected function assertNoCoordinates() + { + $this->assertFalse($this->polyline->hasCoordinates()); + $this->assertEmpty($this->polyline->getCoordinates()); } /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The coordinate adder arguments is invalid. - * The available prototypes are : - * - function addCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate) - * - function addCoordinate(double $latitude, double $longitude, boolean $noWrap = true) + * Asserts there is no coordinate. + * + * @param \Ivory\GoogleMap\Base\Coordinate $coordinate The coordinate. */ - public function testCoordinateWithInvalidValue() + protected function assertNoCoordinate($coordinate) { - $this->polyline->addCoordinate('foo'); + $this->assertCoordinateInstance($coordinate); + $this->assertFalse($this->polyline->hasCoordinate($coordinate)); } } diff --git a/tests/Overlays/RectangleTest.php b/tests/Overlays/RectangleTest.php index 2372d4e1..a91c8fcb 100644 --- a/tests/Overlays/RectangleTest.php +++ b/tests/Overlays/RectangleTest.php @@ -18,17 +18,20 @@ * * @author GeLo */ -class RectangleTest extends \PHPUnit_Framework_TestCase +class RectangleTest extends AbstractExtendableTest { /** @var \Ivory\GoogleMap\Overlays\Rectangle */ protected $rectangle; + /** @var \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject */ + protected $bound; + /** * {@inheritdoc} */ protected function setUp() { - $this->rectangle = new Rectangle(); + $this->rectangle = new Rectangle($this->bound = $this->createBoundMock('rectangle_bound')); } /** @@ -36,109 +39,32 @@ protected function setUp() */ protected function tearDown() { + unset($this->bound); unset($this->rectangle); } - public function testDefaultState() + public function testInheritance() { - $this->assertSame(1, $this->rectangle->getBound()->getNorthEast()->getLatitude()); - $this->assertSame(1, $this->rectangle->getBound()->getNorthEast()->getLongitude()); - $this->assertTrue($this->rectangle->getBound()->getNorthEast()->isNoWrap()); - - $this->assertSame(-1, $this->rectangle->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(-1, $this->rectangle->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->rectangle->getBound()->getSouthWest()->isNoWrap()); + $this->assertOptionsAssetInstance($this->rectangle); + $this->assertExtendableInstance($this->rectangle); } - public function testInitialState() + public function testDefaultState() { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->once()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->rectangle = new Rectangle($bound); - - $this->assertSame($bound, $this->rectangle->getBound()); + $this->assertStringStartsWith('rectangle_', $this->rectangle->getVariable()); + $this->assertSame($this->bound, $this->rectangle->getBound()); + $this->assertFalse($this->rectangle->hasOptions()); } - public function testBoundWithValidBound() + public function testSetBound() { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $bound - ->expects($this->once()) - ->method('hasCoordinates') - ->will($this->returnValue(true)); - - $this->rectangle->setBound($bound); + $this->rectangle->setBound($bound = $this->createBoundMock()); $this->assertSame($bound, $this->rectangle->getBound()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage A rectangle bound must have a south west & a north east coordinate. - */ - public function testBoundWithInvalidBound() - { - $this->rectangle->setBound($this->getMock('Ivory\GoogleMap\Base\Bound')); - } - - public function testBoundWithCoordinates() - { - $southWeestCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEastCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->rectangle->setBound($southWeestCoordinate, $northEastCoordinate); - - $this->assertSame($southWeestCoordinate, $this->rectangle->getBound()->getSouthWest()); - $this->assertSame($northEastCoordinate, $this->rectangle->getBound()->getNorthEast()); - } - - public function testBoundWithLatitudesAndLongitudes() - { - $southWestLatitude = 1; - $southWestLongitue = 2; - - $northEastLatitude = -1; - $northEastLongitude = -2; - - $this->rectangle->setBound( - $southWestLatitude, - $southWestLongitue, - $northEastLatitude, - $northEastLongitude, - true, - false - ); - - $this->assertSame($southWestLatitude, $this->rectangle->getBound()->getSouthWest()->getLatitude()); - $this->assertSame($southWestLongitue, $this->rectangle->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->rectangle->getBound()->getSouthWest()->isNoWrap()); - - $this->assertSame($northEastLatitude, $this->rectangle->getBound()->getNorthEast()->getLatitude()); - $this->assertSame($northEastLongitude, $this->rectangle->getBound()->getNorthEast()->getLongitude()); - $this->assertFalse($this->rectangle->getBound()->getNorthEast()->isNoWrap()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\OverlayException - * @expectedExceptionMessage The bound setter arguments is invalid. - * The available prototypes are : - * - function setBound(Ivory\GoogleMap\Base\Bound $bound) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - */ - public function testBoundWithInvalidValue() + public function testRenderExtend() { - $this->rectangle->setBound('foo'); + $this->assertSame('bound.union(rectangle_bound)', $this->rectangle->renderExtend($this->createBoundMock())); } } diff --git a/tests/Places/AutocompleteComponentRestrictionTest.php b/tests/Places/AutocompleteComponentRestrictionTest.php index 324dcf10..1ceae27a 100644 --- a/tests/Places/AutocompleteComponentRestrictionTest.php +++ b/tests/Places/AutocompleteComponentRestrictionTest.php @@ -12,19 +12,22 @@ namespace Ivory\Tests\GoogleMap\Places; use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Autocomplete component restriction test. * * @author GeLo */ -class AutocompleteComponentRestrictionTest extends \PHPUnit_Framework_TestCase +class AutocompleteComponentRestrictionTest extends AbstractTestCase { - public function testAutocompleteComponentRestrictions() + public function testInheritance() { - $this->assertSame( - array(AutocompleteComponentRestriction::COUNTRY), - AutocompleteComponentRestriction::getAvailableAutocompleteComponentRestrictions() - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Places\AutocompleteComponentRestriction'); + } + + public function testConstants() + { + $this->assertSame('country', AutocompleteComponentRestriction::COUNTRY); } } diff --git a/tests/Places/AutocompleteTest.php b/tests/Places/AutocompleteTest.php index bc912408..85569053 100644 --- a/tests/Places/AutocompleteTest.php +++ b/tests/Places/AutocompleteTest.php @@ -14,13 +14,14 @@ use Ivory\GoogleMap\Places\Autocomplete; use Ivory\GoogleMap\Places\AutocompleteComponentRestriction; use Ivory\GoogleMap\Places\AutocompleteType; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Autocomplete test. * * @author GeLo */ -class AutocompleteTest extends \PHPUnit_Framework_TestCase +class AutocompleteTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Places\Autocomplete */ protected $autocomplete; @@ -41,241 +42,405 @@ protected function tearDown() unset($this->autocomplete); } + public function testInheritance() + { + $this->assertVariableAssetInstance($this->autocomplete); + } + public function testDefaultState() { - $this->assertSame('place_input', $this->autocomplete->getInputId()); - $this->assertFalse($this->autocomplete->hasBound()); - $this->assertFalse($this->autocomplete->hasTypes()); - $this->assertFalse($this->autocomplete->hasComponentRestrictions()); - $this->assertFalse($this->autocomplete->hasValue()); - $this->assertSame(array('type' => 'text', 'placeholder' => 'off'), $this->autocomplete->getInputAttributes()); - $this->assertFalse($this->autocomplete->isAsync()); + $this->assertStringStartsWith('places_autocomplete_', $this->autocomplete->getVariable()); + $this->assertSame($this->autocomplete->getVariable(), $this->autocomplete->getInputId()); + $this->assertNoInputAttributes(); + $this->assertNoValue(); + $this->assertNoBound(); + $this->assertNoTypes(); + $this->assertNoComponentRestrictions(); $this->assertSame('en', $this->autocomplete->getLanguage()); } - public function testInputIdWithValidValue() + public function testSetInputId() { - $this->autocomplete->setInputId('input'); + $this->autocomplete->setInputId($inputId = 'foo'); - $this->assertSame('input', $this->autocomplete->getInputId()); + $this->assertSame($inputId, $this->autocomplete->getInputId()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete input ID must be a string value. - */ - public function testInputIdWithInvalidValue() + public function testSetInputAttributes() { - $this->autocomplete->setInputId(true); + $this->autocomplete->setInputAttributes($inputAttributes = array('foo' => 'bar')); + + $this->assertInputAttributes($inputAttributes); } - public function testBoundWithBound() + public function testAddInputAttributes() { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->autocomplete->setBound($bound); + $this->autocomplete->setInputAttributes($inputAttributes = array('foo' => 'bar')); + $this->autocomplete->addInputAttributes($newInputAttributes = array('baz' => 'bat')); - $this->assertSame($bound, $this->autocomplete->getBound()); + $this->assertInputAttributes(array_merge($inputAttributes, $newInputAttributes)); } - public function testBoundWithCoordinates() + public function testRemoveInputAttributes() { - $southWestCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEastCoordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); + $this->autocomplete->setInputAttributes($inputAttributes = array('foo' => 'bar')); + $this->autocomplete->removeInputAttributes(array_keys($inputAttributes)); + + $this->assertNoInputAttributes(); + } - $this->autocomplete->setBound($southWestCoordinate, $northEastCoordinate); + public function testResetInputAttributes() + { + $this->autocomplete->setInputAttributes(array('foo' => 'bar')); + $this->autocomplete->resetInputAttributes(); - $this->assertSame($southWestCoordinate, $this->autocomplete->getBound()->getSouthWest()); - $this->assertSame($northEastCoordinate, $this->autocomplete->getBound()->getNorthEast()); + $this->assertNoInputAttributes(); } - public function testBoundWithLatitudesAndLongitudes() + public function testSetInputAttribute() { - $this->autocomplete->setBound(1, 2, 3, 4, true, false); + $this->autocomplete->setInputAttribute($name = 'foo', $value = 'bar'); - $this->assertSame(1, $this->autocomplete->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(2, $this->autocomplete->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->autocomplete->getBound()->getSouthWest()->isNoWrap()); + $this->assertInputAttribute($name, $value); + } - $this->assertEquals(3, $this->autocomplete->getBound()->getNorthEast()->getLatitude()); - $this->assertEquals(4, $this->autocomplete->getBound()->getNorthEast()->getLongitude()); - $this->assertFalse($this->autocomplete->getBound()->getNorthEast()->isNoWrap()); + public function testRemoveInputAttribute() + { + $this->autocomplete->setInputAttribute($name = 'foo', 'bar'); + $this->autocomplete->removeInputAttribute($name); + + $this->assertNoInputAttribute($name); + } + + public function testValue() + { + $this->autocomplete->setValue($value = 'value'); + + $this->assertValue($value); + } + + public function testResetValue() + { + $this->autocomplete->setValue('value'); + $this->autocomplete->setValue(null); + + $this->assertNoValue(); + } + + public function testSetBound() + { + $this->autocomplete->setBound($bound = $this->createBoundMock()); + + $this->assertBound($bound); } - public function testBoundWithNullValue() + public function testResetBound() { - $this->autocomplete->setBound(1, 2, 3, 4); + $this->autocomplete->setBound($this->createBoundMock()); $this->autocomplete->setBound(null); - $this->assertNull($this->autocomplete->getBound()); + $this->assertNoBound(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The bound setter arguments is invalid. - * The available prototypes are : - * - function setBound(Ivory\GoogleMap\Base\Bound $bound) - * - function setBount(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - */ - public function testBoundWithInvalidValue() + public function testSetTypes() { - $this->autocomplete->setBound('foo'); + $this->autocomplete->setTypes($types = array(AutocompleteType::CITIES)); + + $this->assertTypes($types); } - public function testTypesWithValidTypes() + public function testAddTypes() { - $types = array(AutocompleteType::ESTABLISHMENT, AutocompleteType::GEOCODE); - $this->autocomplete->setTypes($types); + $this->autocomplete->setTypes($types = array(AutocompleteType::CITIES)); + $this->autocomplete->addTypes($newTypes = array(AutocompleteType::ESTABLISHMENT)); - $this->assertSame($types, $this->autocomplete->getTypes()); + $this->assertTypes(array_merge($types, $newTypes)); + } - $this->assertTrue($this->autocomplete->hasTypes()); - $this->assertTrue($this->autocomplete->hasType(AutocompleteType::ESTABLISHMENT)); + public function testRemoveTypes() + { + $this->autocomplete->setTypes($types = array(AutocompleteType::CITIES)); + $this->autocomplete->removeTypes($types); + + $this->assertNoTypes(); } - /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete type can only be: establishment, geocode, (regions), (cities). - */ - public function testAddTypeWithInvalidType() + public function testResetTypes() { - $this->autocomplete->addType('foo'); + $this->autocomplete->setTypes(array(AutocompleteType::CITIES)); + $this->autocomplete->resetTypes(); + + $this->assertNoTypes(); } - /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete type "establishment" already exists. - */ - public function testAddTypeWithExistingType() + public function testAddType() { - $this->autocomplete->addType(AutocompleteType::ESTABLISHMENT); - $this->autocomplete->addType(AutocompleteType::ESTABLISHMENT); + $this->autocomplete->addType($type = AutocompleteType::CITIES); + + $this->assertType($type); } - public function testRemoveTypeWithValidType() + public function testAddTypeUnicity() { - $this->autocomplete->addType(AutocompleteType::ESTABLISHMENT); - $this->autocomplete->removeType(AutocompleteType::ESTABLISHMENT); + $this->autocomplete->resetTypes(); + $this->autocomplete->addType($type = AutocompleteType::CITIES); + $this->autocomplete->addType($type); - $this->assertFalse($this->autocomplete->hasType(AutocompleteType::ESTABLISHMENT)); + $this->assertTypes(array($type)); } - /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete type "establishment" does not exist. - */ - public function testRemoveTypeWithNonExistingType() + public function testRemoveType() + { + $this->autocomplete->addType($type = AutocompleteType::CITIES); + $this->autocomplete->removeType($type); + + $this->assertNoType($type); + } + + public function testSetComponentRestrictions() { - $this->autocomplete->removeType(AutocompleteType::ESTABLISHMENT); + $this->autocomplete->setComponentRestrictions( + $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'france') + ); + + $this->assertComponentRestrictions($componentRestrictions); } - public function testComponentRestrictionsWithValidComponentRestrictions() + public function testAddComponentRestrictions() { - $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'fr'); - $this->autocomplete->setComponentRestrictions($componentRestrictions); + $this->autocomplete->setComponentRestrictions( + $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'france') + ); - $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); + $this->autocomplete->addComponentRestrictions($newComponentRestrictions = array('bar' => 'baz')); - $this->assertTrue($this->autocomplete->hasComponentRestrictions()); - $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); + $this->assertComponentRestrictions(array_merge($componentRestrictions, $newComponentRestrictions)); + } - $this->assertTrue($this->autocomplete->hasComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); - $this->assertSame( - $componentRestrictions[AutocompleteComponentRestriction::COUNTRY], - $this->autocomplete->getComponentRestriction(AutocompleteComponentRestriction::COUNTRY) + public function testRemoveComponentRestrictions() + { + $this->autocomplete->setComponentRestrictions( + $componentRestrictions = array(AutocompleteComponentRestriction::COUNTRY => 'france') ); + + $this->autocomplete->removeComponentRestrictions(array_keys($componentRestrictions)); + + $this->assertNoComponentRestrictions(); + } + + public function testResetComponentRestrictions() + { + $this->autocomplete->setComponentRestrictions(array(AutocompleteComponentRestriction::COUNTRY => 'france')); + $this->autocomplete->resetComponentRestrictions(); + + $this->assertNoComponentRestrictions(); + } + + public function testSetComponentRestriction() + { + $this->autocomplete->setComponentRestriction($name = AutocompleteComponentRestriction::COUNTRY, $value = 'france'); + + $this->assertComponentRestriction($name, $value); + } + + public function testRemoveComponentRestriction() + { + $this->autocomplete->setComponentRestriction($name = AutocompleteComponentRestriction::COUNTRY, 'france'); + $this->autocomplete->removeComponentRestriction($name); + + $this->assertNoComponentRestriction($name); + } + + public function testSetLanguage() + { + $this->autocomplete->setLanguage($language = 'fr'); + + $this->assertSame($language, $this->autocomplete->getLanguage()); + } + + /** + * Asserts there are input attributes. + * + * @param array $inputAttributes The input attributes. + */ + protected function assertInputAttributes($inputAttributes) + { + $this->assertInternalType('array', $inputAttributes); + + $this->assertTrue($this->autocomplete->hasInputAttributes()); + $this->assertSame($inputAttributes, $this->autocomplete->getInputAttributes()); + + foreach ($inputAttributes as $name => $value) { + $this->assertInputAttribute($name, $value); + } } /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete component restriction type "country" does not exist. + * Asserts there is an input attribute. + * + * @param string $name The input attribute name. + * @param string $value The input attribute value. */ - public function testComponentRestrictionsWithInvalidComponentRestrictions() + protected function assertInputAttribute($name, $value) { - $this->autocomplete->getComponentRestriction(AutocompleteComponentRestriction::COUNTRY); + $this->assertTrue($this->autocomplete->hasInputAttribute($name)); + $this->assertSame($value, $this->autocomplete->getInputAttribute($name)); } /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete component restriction can only be: country. + * Asserts there is a value. + * + * @param string $value The value. */ - public function testAddComponentRestrictionWithInvalidComponentRestrictions() + protected function assertValue($value) { - $this->autocomplete->addComponentRestriction('foo', 'bar'); + $this->assertTrue($this->autocomplete->hasValue()); + $this->assertSame($value, $this->autocomplete->getValue()); } /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete component restriction type "country" already exists. + * Asserts there is a bound. + * + * @param \Ivory\GoogleMap\Base\Bound $bound The bound. */ - public function testAddComponentRestrictionWithExistingComponentRestriction() + protected function assertBound($bound) { - $this->autocomplete->addComponentRestriction(AutocompleteComponentRestriction::COUNTRY, 'foo'); - $this->autocomplete->addComponentRestriction(AutocompleteComponentRestriction::COUNTRY, 'bar'); + $this->assertBoundInstance($bound); + + $this->assertTrue($this->autocomplete->hasBound()); + $this->assertSame($bound, $this->autocomplete->getBound()); } - public function testRemoveComponentRestrictionWithValidComponentRestriction() + /** + * Asserts there are types. + * + * @param array $types The types. + */ + protected function assertTypes($types) { - $this->autocomplete->addComponentRestriction(AutocompleteComponentRestriction::COUNTRY, 'foo'); - $this->autocomplete->removeComponentRestriction(AutocompleteComponentRestriction::COUNTRY); + $this->assertInternalType('array', $types); + + $this->assertTrue($this->autocomplete->hasTypes()); + $this->assertSame($types, $this->autocomplete->getTypes()); - $this->assertFalse($this->autocomplete->hasComponentRestriction(AutocompleteComponentRestriction::COUNTRY)); + foreach ($types as $type) { + $this->assertType($type); + } } /** - * @expectedException Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The place autocomplete component restriction type "country" does not exist. + * Asserts there is a type. + * + * @param string $type The type. */ - public function testRemoveComponentRestrictionWithNonExistingComponentRestriction() + protected function assertType($type) { - $this->autocomplete->removeComponentRestriction(AutocompleteComponentRestriction::COUNTRY); + $this->assertTrue($this->autocomplete->hasType($type)); } - public function testInputAttributesWithValidValue() + /** + * Asserts there are component restrictions. + * + * @param array $componentRestrictions The component restrictions. + */ + protected function assertComponentRestrictions($componentRestrictions) { - $this->autocomplete->setInputAttributes(array('foo' => 'bar')); + $this->assertInternalType('array', $componentRestrictions); + + $this->assertTrue($this->autocomplete->hasComponentRestrictions()); + $this->assertSame($componentRestrictions, $this->autocomplete->getComponentRestrictions()); - $inputAttributes = $this->autocomplete->getInputAttributes(); + foreach ($componentRestrictions as $name => $value) { + $this->assertComponentRestriction($name, $value); + } + } + + /** + * Asserts there is a component restriction. + * + * @param string $name The component restriction name. + * @param string $value The component restriction value. + */ + protected function assertComponentRestriction($name, $value) + { + $this->assertTrue($this->autocomplete->hasComponentRestriction($name)); + $this->assertSame($value, $this->autocomplete->getComponentRestriction($name)); + } - $this->assertArrayHasKey('foo', $inputAttributes); - $this->assertSame('bar', $inputAttributes['foo']); + /** + * Asserts there are no input attributes. + */ + protected function assertNoInputAttributes() + { + $this->assertFalse($this->autocomplete->hasInputAttributes()); + $this->assertEmpty($this->autocomplete->getInputAttributes()); } - public function testInputAttributesWithNullValue() + /** + * Asserts there is no input attribute. + * + * @param string $name The input attribute name. + */ + protected function assertNoInputAttribute($name) { - $this->autocomplete->setInputAttribute('foo', 'bar'); - $this->autocomplete->setInputAttribute('foo', null); + $this->assertFalse($this->autocomplete->hasInputAttribute($name)); + $this->assertNull($this->autocomplete->getInputAttribute($name)); + } - $this->assertArrayNotHasKey('foo', $this->autocomplete->getInputAttributes()); + /** + * Asserts there is no value. + */ + protected function assertNoValue() + { + $this->assertFalse($this->autocomplete->hasValue()); + $this->assertNull($this->autocomplete->getValue()); } - public function testAsyncWithValidValue() + /** + * Asserts there is no bound. + */ + protected function assertNoBound() { - $this->autocomplete->setAsync(true); + $this->assertFalse($this->autocomplete->hasBound()); + $this->assertNull($this->autocomplete->getBound()); + } - $this->assertTrue($this->autocomplete->isAsync()); + /** + * Asserts there are no types. + */ + protected function assertNoTypes() + { + $this->assertFalse($this->autocomplete->hasTypes()); + $this->assertEmpty($this->autocomplete->getTypes()); } /** - * @expectedException \Ivory\GoogleMap\Exception\PlaceException - * @expectedExceptionMessage The asynchronous load of a place autocomplete must be a boolean value. + * Asserts there is no type. + * + * @param string $type The type. */ - public function testAsyncWithInvalidValue() + protected function assertNoType($type) { - $this->autocomplete->setAsync('foo'); + $this->assertFalse($this->autocomplete->hasType($type)); } - public function testLanguage() + /** + * Asserts there are no component restrictions. + */ + protected function assertNoComponentRestrictions() { - $this->autocomplete->setLanguage('fr'); + $this->assertFalse($this->autocomplete->hasComponentRestrictions()); + $this->assertEmpty($this->autocomplete->getComponentRestrictions()); + } - $this->assertSame('fr', $this->autocomplete->getLanguage()); + /** + * Asserts there is no component restriction. + * + * @param string $name The component restriction name. + */ + protected function assertNoComponentRestriction($name) + { + $this->assertFalse($this->autocomplete->hasComponentRestriction($name)); + $this->assertNull($this->autocomplete->getComponentRestriction($name)); } } diff --git a/tests/Places/AutocompleteTypeTest.php b/tests/Places/AutocompleteTypeTest.php index cd0f7710..832dcfd0 100644 --- a/tests/Places/AutocompleteTypeTest.php +++ b/tests/Places/AutocompleteTypeTest.php @@ -12,24 +12,25 @@ namespace Ivory\Tests\GoogleMap\Places; use Ivory\GoogleMap\Places\AutocompleteType; +use Ivory\Tests\GoogleMap\AbstractTestCase; /** * Autocomplete type test. * * @author GeLo */ -class AutocompleteTypeTest extends \PHPUnit_Framework_TestCase +class AutocompleteTypeTest extends AbstractTestCase { - public function testAutocompleteTypes() + public function testInheritance() { - $this->assertSame( - array( - AutocompleteType::ESTABLISHMENT, - AutocompleteType::GEOCODE, - AutocompleteType::REGIONS, - AutocompleteType::CITIES, - ), - AutocompleteType::getAvailableAutocompleteTypes() - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Places\AutocompleteType'); + } + + public function testConstants() + { + $this->assertSame('(cities)', AutocompleteType::CITIES); + $this->assertSame('establishment', AutocompleteType::ESTABLISHMENT); + $this->assertSame('geocode', AutocompleteType::GEOCODE); + $this->assertSame('(regions)', AutocompleteType::REGIONS); } } diff --git a/tests/Services/AbstractServiceTest.php b/tests/Services/AbstractServiceTest.php deleted file mode 100644 index c864c2c3..00000000 --- a/tests/Services/AbstractServiceTest.php +++ /dev/null @@ -1,195 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services; - -use Ivory\GoogleMap\Services\BusinessAccount; - -/** - * Abstract service test. - * - * @author GeLo - */ -class AbstractServiceTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\AbstractService */ - protected $service; - - /** @var \Widop\HttpAdapter\HttpAdapterInterface */ - protected $httpAdapter; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->httpAdapter = $this->getMock('Widop\HttpAdapter\HttpAdapterInterface'); - - $this->service = $this->getMockBuilder('Ivory\GoogleMap\Services\AbstractService') - ->setConstructorArgs(array($this->httpAdapter, 'http://foo')) - ->getMockForAbstractClass(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->httpAdapter); - unset($this->service); - } - - public function testDefaultState() - { - $this->assertSame($this->httpAdapter, $this->service->getHttpAdapter()); - $this->assertSame('http://foo', $this->service->getUrl()); - $this->assertFalse($this->service->isHttps()); - $this->assertSame('json', $this->service->getFormat()); - $this->assertInstanceOf('Ivory\GoogleMap\Services\Utils\XmlParser', $this->service->getXmlParser()); - $this->assertFalse($this->service->hasBusinessAccount()); - $this->assertNull($this->service->getBusinessAccount()); - } - - public function testInitialState() - { - $xmlParser = $this->getMock('Ivory\GoogleMap\Services\Utils\XmlParser'); - - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $this->service = $this->getMockBuilder('Ivory\GoogleMap\Services\AbstractService') - ->setConstructorArgs(array($this->httpAdapter, 'http://bar', true, 'xml', $xmlParser, $businessAccount)) - ->getMockForAbstractClass(); - - $this->assertSame($this->httpAdapter, $this->service->getHttpAdapter()); - $this->assertSame('https://bar', $this->service->getUrl()); - $this->assertTrue($this->service->isHttps()); - $this->assertSame('xml', $this->service->getFormat()); - $this->assertSame($xmlParser, $this->service->getXmlParser()); - $this->assertTrue($this->service->hasBusinessAccount()); - $this->assertSame($businessAccount, $this->service->getBusinessAccount()); - } - - public function testHttpAdapter() - { - $httpAdapter = $this->getMock('Widop\HttpAdapter\HttpAdapterInterface'); - $this->service->setHttpAdapter($httpAdapter); - - $this->assertSame($httpAdapter, $this->service->getHttpAdapter()); - } - - public function testHttps() - { - $this->service->setHttps(true); - - $this->assertTrue($this->service->isHttps()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The service https flag must be a boolean value. - */ - public function testHttpsWithInvalidValue() - { - $this->service->setHttps('foo'); - } - - public function testUrlWithHttps() - { - $this->service->setHttps(true); - $this->assertSame('https://foo', $this->service->getUrl()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The service url must be a string value. - */ - public function testUrlWithInvalidValue() - { - $this->service->setUrl(true); - } - - public function testFormatWithJsonAndXml() - { - $this->service->setFormat('xml'); - $this->assertSame('xml', $this->service->getFormat()); - - $this->service->setFormat('json'); - $this->assertSame('json', $this->service->getFormat()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The service format can only be : json, xml. - */ - public function testFormatWithInvalidValue() - { - $this->service->setFormat('foo'); - } - - public function testXmlParser() - { - $xmlParser = $this->getMock('Ivory\GoogleMap\Services\Utils\XmlParser'); - $this->service->setXmlParser($xmlParser); - - $this->assertSame($xmlParser, $this->service->getXmlParser()); - } - - public function testBusinessAccount() - { - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $this->service->setBusinessAccount($businessAccount); - - $this->assertTrue($this->service->hasBusinessAccount()); - $this->assertSame($businessAccount, $this->service->getBusinessAccount()); - - $this->service->setBusinessAccount(); - - $this->assertFalse($this->service->hasBusinessAccount()); - $this->assertNull($this->service->getBusinessAccount()); - } - - public function testSignUrlWithoutBusinessAccount() - { - $method = new \ReflectionMethod($this->service, 'signUrl'); - $method->setAccessible(true); - - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $this->assertSame($url, $method->invoke($this->service, $url)); - } - - public function testSignUrlWithBusinessAccount() - { - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $businessAccount - ->expects($this->once()) - ->method('signUrl') - ->with($this->equalTo($url)) - ->will($this->returnValue('url')); - - $this->service->setBusinessAccount($businessAccount); - - $method = new \ReflectionMethod($this->service, 'signUrl'); - $method->setAccessible(true); - - $this->assertSame('url', $method->invoke($this->service, $url)); - } -} diff --git a/tests/Services/AbstractTestCase.php b/tests/Services/AbstractTestCase.php new file mode 100644 index 00000000..698bb036 --- /dev/null +++ b/tests/Services/AbstractTestCase.php @@ -0,0 +1,104 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services; + +use Ivory\Tests\GoogleMap\AbstractTestCase as TestCase; + +/** + * Services test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a service instance. + * + * @param \Ivory\GoogleMap\Services\AbstractService $service The service. + */ + protected function assertServiceInstance($service) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\AbstractService', $service); + } + + /** + * Asserts an xml parser instance. + * + * @param \Ivory\GoogleMap\Services\XmlParser $xmlParser The xml parser. + */ + protected function assertXmlParserInstance($xmlParser) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\XmlParser', $xmlParser); + } + + /** + * Creates a business account mock. + * + * @return \Ivory\GoogleMap\Services\BusinessAccount|\PHPUnit_Framework_MockObject_MockObject The business account mock. + */ + protected function createBusinessAccountMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a distance mock. + * + * @return \Ivory\GoogleMap\Services\Base\Distance|\PHPUnit_Framework_MockObject_MockObject The distance mock. + */ + protected function createDistanceMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Distance')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates a duration mock. + * + * @return \Ivory\GoogleMap\Services\Base\Duration|\PHPUnit_Framework_MockObject_MockObject The duration mock. + */ + protected function createDurationMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Duration')->disableOriginalConstructor()->getMock(); + } + + /** + * Creates an http adapter mock. + * + * @return \Ivory\HttpAdapter\HttpAdapterInterface|\PHPUnit_Framework_MockObject_MockObject The http adapter mock. + */ + protected function createHttpAdapterMock() + { + return $this->getMock('Ivory\HttpAdapter\HttpAdapterInterface'); + } + + /** + * Creates a service mock builder. + * + * @return \PHPUnit_Framework_MockObject_MockBuilder The service mock builder. + */ + protected function createServiceMockBuilder() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\AbstractService'); + } + + /** + * Creates an xml parser mock. + * + * @return \Ivory\GoogleMap\Services\XmlParser|\PHPUnit_Framework_MockObject_MockBuilder The xml parser mock. + */ + protected function createXmlParserMock() + { + return $this->getMock('Ivory\GoogleMap\Services\XmlParser'); + } +} diff --git a/tests/Services/Base/DistanceTest.php b/tests/Services/Base/DistanceTest.php index 335604e7..450e559e 100644 --- a/tests/Services/Base/DistanceTest.php +++ b/tests/Services/Base/DistanceTest.php @@ -12,23 +12,30 @@ namespace Ivory\Tests\GoogleMap\Services\Service; use Ivory\GoogleMap\Services\Base\Distance; +use Ivory\Tests\GoogleMap\Services\AbstractTestCase; /** * Distance test. * * @author GeLo */ -class DistanceTest extends \PHPUnit_Framework_TestCase +class DistanceTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Base\Distance */ protected $distance; + /** @var string */ + protected $text; + + /** @var float */ + protected $value; + /** * {@inheritdoc} */ protected function setUp() { - $this->distance = new Distance('foo', 2.2); + $this->distance = new Distance($this->text = 'foo', $this->value = 2.2); } /** @@ -36,30 +43,28 @@ protected function setUp() */ protected function tearDown() { + unset($this->value); + unset($this->text); unset($this->distance); } public function testInitialState() { - $this->assertSame('foo', $this->distance->getText()); - $this->assertSame(2.2, $this->distance->getValue()); + $this->assertSame($this->text, $this->distance->getText()); + $this->assertSame($this->value, $this->distance->getValue()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The distance text must be a string value. - */ - public function testTextWithInvalidValue() + public function testSetText() { - $this->distance->setText(true); + $this->distance->setText($text = 'bar'); + + $this->assertSame($text, $this->distance->getText()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The distance value must be a numeric value. - */ - public function testValueWithInvalidValue() + public function testSetValue() { - $this->distance->setValue('foo'); + $this->distance->setValue($value = 1.1); + + $this->assertSame($value, $this->distance->getValue()); } } diff --git a/tests/Services/Base/DurationTest.php b/tests/Services/Base/DurationTest.php index 828d6643..46441b84 100644 --- a/tests/Services/Base/DurationTest.php +++ b/tests/Services/Base/DurationTest.php @@ -12,23 +12,30 @@ namespace Ivory\Tests\GoogleMap\Services\Base; use Ivory\GoogleMap\Services\Base\Duration; +use Ivory\Tests\GoogleMap\Services\AbstractTestCase; /** * Duration test. * * @author GeLo */ -class DurationTest extends \PHPUnit_Framework_TestCase +class DurationTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Base\Duration */ protected $duration; + /** @var string */ + protected $text; + + /** @var float */ + protected $value; + /** * {@inheritdoc} */ protected function setUp() { - $this->duration = new Duration('foo', 2.2); + $this->duration = new Duration($this->text = 'foo', $this->value = 2.2); } /** @@ -36,30 +43,28 @@ protected function setUp() */ protected function tearDown() { + unset($this->value); + unset($this->text); unset($this->duration); } public function testInitialState() { - $this->assertSame('foo', $this->duration->getText()); - $this->assertSame(2.2, $this->duration->getValue()); + $this->assertSame($this->text, $this->duration->getText()); + $this->assertSame($this->value, $this->duration->getValue()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The duration text must be a string value. - */ - public function testTextWithInvalidValue() + public function testSetText() { - $this->duration->setText(true); + $this->duration->setText($text = 'bar'); + + $this->assertSame($text, $this->duration->getText()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\ServiceException - * @expectedExceptionMessage The duration value must be a numeric value. - */ - public function testValueWithInvalidValue() + public function testSetValue() { - $this->duration->setValue('foo'); + $this->duration->setValue($value = 1.1); + + $this->assertSame($value, $this->duration->getValue()); } } diff --git a/tests/Services/Base/TravelModeTest.php b/tests/Services/Base/TravelModeTest.php index a37ebcfc..37f2411f 100644 --- a/tests/Services/Base/TravelModeTest.php +++ b/tests/Services/Base/TravelModeTest.php @@ -12,23 +12,28 @@ namespace Ivory\Tests\GoogleMap\Services\Base; use Ivory\GoogleMap\Services\Base\TravelMode; +use Ivory\Tests\GoogleMap\Services\AbstractTestCase; /** * Travel mode test. * * @author GeLo */ -class TravelModeTest extends \PHPUnit_Framework_TestCase +class TravelModeTest extends AbstractTestCase { - public function testTravelModes() + public function testInheritance() { - $expected = array( - TravelMode::BICYCLING, - TravelMode::DRIVING, - TravelMode::WALKING, - TravelMode::TRANSIT, - ); + $this->assertTrue(is_subclass_of( + 'Ivory\GoogleMap\Services\Base\TravelMode', + 'Ivory\GoogleMap\Assets\AbstractUninstantiableAsset' + )); + } - $this->assertSame($expected, TravelMode::getTravelModes()); + public function testConstants() + { + $this->assertSame('BICYCLING', TravelMode::BICYCLING); + $this->assertSame('DRIVING', TravelMode::DRIVING); + $this->assertSame('WALKING', TravelMode::WALKING); + $this->assertSame('TRANSIT', TravelMode::TRANSIT); } } diff --git a/tests/Services/Base/UnitSystemTest.php b/tests/Services/Base/UnitSystemTest.php index 5613bd35..083e6783 100644 --- a/tests/Services/Base/UnitSystemTest.php +++ b/tests/Services/Base/UnitSystemTest.php @@ -12,21 +12,26 @@ namespace Ivory\Tests\GoogleMap\Services\Base; use Ivory\GoogleMap\Services\Base\UnitSystem; +use Ivory\Tests\GoogleMap\Services\AbstractTestCase; /** * Unit system test. * * @author GeLo */ -class UnitSystemTest extends \PHPUnit_Framework_TestCase +class UnitSystemTest extends AbstractTestCase { - public function testUnitSystems() + public function testInheritance() { - $expected = array( - UnitSystem::IMPERIAL, - UnitSystem::METRIC, - ); + $this->assertTrue(is_subclass_of( + 'Ivory\GoogleMap\Services\Base\UnitSystem', + 'Ivory\GoogleMap\Assets\AbstractUninstantiableAsset' + )); + } - $this->assertSame($expected, UnitSystem::getUnitSystems()); + public function testConstants() + { + $this->assertSame('IMPERIAL', UnitSystem::IMPERIAL); + $this->assertSame('METRIC', UnitSystem::METRIC); } } diff --git a/tests/Services/BusinessAccountTest.php b/tests/Services/BusinessAccountTest.php index 48f87027..77a76d8e 100644 --- a/tests/Services/BusinessAccountTest.php +++ b/tests/Services/BusinessAccountTest.php @@ -18,17 +18,23 @@ * * @author GeLo */ -class BusinessAccountTest extends \PHPUnit_Framework_TestCase +class BusinessAccountTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\BusinessAccount */ protected $businessAccount; + /** @var string */ + protected $clientId; + + /** @var string */ + protected $secret; + /** * {@inheritdoc} */ protected function setUp() { - $this->businessAccount = new BusinessAccount('client_id', 'secret'); + $this->businessAccount = new BusinessAccount($this->clientId = 'client_id', $this->secret = 'secret'); } /** @@ -36,61 +42,76 @@ protected function setUp() */ protected function tearDown() { + unset($this->secret); + unset($this->clientId); unset($this->businessAccount); } public function testDefaultState() { - $this->assertSame('client_id', $this->businessAccount->getClientId()); - $this->assertSame('secret', $this->businessAccount->getSecret()); + $this->assertSame($this->clientId, $this->businessAccount->getClientId()); + $this->assertSame($this->secret, $this->businessAccount->getSecret()); $this->assertFalse($this->businessAccount->hasChannel()); $this->assertNull($this->businessAccount->getChannel()); } public function testInitialState() { - $this->businessAccount = new BusinessAccount('client_id', 'secret', 'channel'); + $this->businessAccount = new BusinessAccount($this->clientId, $this->secret, $channel = 'channel'); $this->assertTrue($this->businessAccount->hasChannel()); - $this->assertSame('channel', $this->businessAccount->getChannel()); + $this->assertSame($channel, $this->businessAccount->getChannel()); } - public function testClientId() + public function testSetClientId() { - $this->businessAccount->setClientId('foo'); + $this->businessAccount->setClientId($clientId = 'foo'); - $this->assertSame('foo', $this->businessAccount->getClientId()); + $this->assertSame($clientId, $this->businessAccount->getClientId()); } - public function testSecret() + public function testSetSecret() { - $this->businessAccount->setSecret('foo'); + $this->businessAccount->setSecret($secret = 'foo'); - $this->assertSame('foo', $this->businessAccount->getSecret()); + $this->assertSame($secret, $this->businessAccount->getSecret()); } - public function testChannel() + public function testSetChannel() { - $this->businessAccount->setChannel('foo'); + $this->businessAccount->setChannel($channel = 'foo'); - $this->assertSame('foo', $this->businessAccount->getChannel()); + $this->assertSame($channel, $this->businessAccount->getChannel()); } - public function testSignUrlWithoutChannel() + /** + * @dataProvider signUrlProvider + */ + public function testSignUrl($url, $channel, $signature) { - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - $expected = $url.'&client=gme-client_id&signature=EO4W2ipM4YzwEIOM1pRZ5xbrl8k='; + $this->businessAccount->setChannel($channel); - $this->assertSame($expected, $this->businessAccount->signUrl($url)); + $this->assertSame($url.$signature, $this->businessAccount->signUrl($url)); } - public function testSignUrlWithChannel() + /** + * Gets the sign url provider. + * + * @return array The sign url provider. + */ + public function signUrlProvider() { - $this->businessAccount->setChannel('channel'); - - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - $expected = $url.'&client=gme-client_id&channel=channel&signature=e9BFlnQaKg-t3NIxKbilkQeTU1Y='; - - $this->assertSame($expected, $this->businessAccount->signUrl($url)); + return array( + array( + 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false', + null, + '&client=gme-client_id&signature=EO4W2ipM4YzwEIOM1pRZ5xbrl8k=', + ), + array( + 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false', + 'channel', + '&client=gme-client_id&channel=channel&signature=e9BFlnQaKg-t3NIxKbilkQeTU1Y=', + ), + ); } } diff --git a/tests/Services/Directions/AbstractTestCase.php b/tests/Services/Directions/AbstractTestCase.php new file mode 100644 index 00000000..fa42778d --- /dev/null +++ b/tests/Services/Directions/AbstractTestCase.php @@ -0,0 +1,110 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Directions; + +use Ivory\Tests\GoogleMap\Services\AbstractTestCase as TestCase; + +/** + * Directions test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a directions leg instance. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg $leg The direction leg. + */ + protected function assertDirectionsLegInstance($leg) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Directions\DirectionsLeg', $leg); + } + + /** + * Asserts a directions route instance. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRoute $route The directions route. + */ + protected function assertDirectionsRouteInstance($route) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Directions\DirectionsRoute', $route); + } + + /** + * Asserts a directions step instance. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep $step The directions step. + */ + protected function assertDirectionsStepInstance($step) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Directions\DirectionsStep', $step); + } + + /** + * Asserts a directions waypoint instance. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The directions waypoint. + */ + protected function assertDirectionsWaypointInstance($waypoint) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Directions\DirectionsWaypoint', $waypoint); + } + + /** + * Creates a directions leg mock. + * + * @return \Ivory\GoogleMap\Services\Directions\DirectionsLeg|\PHPUnit_Framework_MockObject_MockObject The directions leg mock. + */ + protected function createDirectionsLegMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsLeg') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a directions route mock. + * + * @return \Ivory\GoogleMap\Services\Directions\DirectionsRoute|\PHPUnit_Framework_MockObject_MockObject The directions route mock. + */ + protected function createDirectionsRouteMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsRoute') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a directions step mock. + * + * @return \Ivory\GoogleMap\Services\Directions\DirectionsStep|\PHPUnit_Framework_MockObject_MockObject The directions step mock. + */ + protected function createDirectionsStepMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsStep') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a directions waypoint mock. + * + * @return \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint|\PHPUnit_Framework_MockObject_MockObject The directions waypoint mock. + */ + protected function createDirectionsWaypointMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsWaypoint') + ->disableOriginalConstructor() + ->getMock(); + } +} diff --git a/tests/Services/Directions/DirectionsLegTest.php b/tests/Services/Directions/DirectionsLegTest.php index 3d18c3ad..b8c13f02 100644 --- a/tests/Services/Directions/DirectionsLegTest.php +++ b/tests/Services/Directions/DirectionsLegTest.php @@ -18,27 +18,27 @@ * * @author GeLo */ -class DirectionsLegTest extends \PHPUnit_Framework_TestCase +class DirectionsLegTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsLeg */ protected $directionsLeg; - /** @var \Ivory\GoogleMap\Services\Base\Distance */ + /** @var \Ivory\GoogleMap\Services\Base\Distance|\PHPUnit_Framework_MockObject_MockObject */ protected $distance; - /** @var \Ivory\GoogleMap\Services\Base\Duration */ + /** @var \Ivory\GoogleMap\Services\Base\Duration|\PHPUnit_Framework_MockObject_MockObject */ protected $duration; /** @var string */ protected $endAddress; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ protected $endLocation; /** @var string */ protected $startAddress; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ protected $startLocation; /** @var array */ @@ -52,35 +52,15 @@ class DirectionsLegTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->distance = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Distance') - ->disableOriginalConstructor() - ->getMock(); - - $this->duration = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Duration') - ->disableOriginalConstructor() - ->getMock(); - - $this->endAddress = 'foo'; - $this->endLocation = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->startAddress = 'bar'; - $this->startLocation = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $step = $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsStep') - ->disableOriginalConstructor() - ->getMock(); - - $this->steps = array($step); - $this->viaWaypoint = array('foo'); - $this->directionsLeg = new DirectionsLeg( - $this->distance, - $this->duration, - $this->endAddress, - $this->endLocation, - $this->startAddress, - $this->startLocation, - $this->steps, - $this->viaWaypoint + $this->distance = $this->createDistanceMock(), + $this->duration = $this->createDurationMock(), + $this->endAddress = 'end_address', + $this->endLocation = $this->createCoordinateMock(), + $this->startAddress = 'start_address', + $this->startLocation = $this->createCoordinateMock(), + $this->steps = array($this->createDirectionsStepMock()), + $this->viaWaypoint = array('waypoint') ); } @@ -112,21 +92,251 @@ public function testInitialState() $this->assertSame($this->viaWaypoint, $this->directionsLeg->getViaWaypoints()); } + public function testSetDistance() + { + $this->directionsLeg->setDistance($distance = $this->createDistanceMock()); + + $this->assertSame($distance, $this->directionsLeg->getDistance()); + } + + public function testSetDuration() + { + $this->directionsLeg->setDuration($duration = $this->createDurationMock()); + + $this->assertSame($duration, $this->directionsLeg->getDuration()); + } + + public function testSetEndAddress() + { + $this->directionsLeg->setEndAddress($endAddress = 'foo'); + + $this->assertSame($endAddress, $this->directionsLeg->getEndAddress()); + } + + public function testSetEndLocation() + { + $this->directionsLeg->setEndLocation($endLocation = $this->createCoordinateMock()); + + $this->assertSame($endLocation, $this->directionsLeg->getEndLocation()); + } + + public function testSetStartAddress() + { + $this->directionsLeg->setStartAddress($startAddress = 'foo'); + + $this->assertSame($startAddress, $this->directionsLeg->getStartAddress()); + } + + public function testSetStartLocation() + { + $this->directionsLeg->setStartLocation($startLocation = $this->createCoordinateMock()); + + $this->assertSame($startLocation, $this->directionsLeg->getStartLocation()); + } + + public function testSetSteps() + { + $this->directionsLeg->setSteps($steps = array($this->createDirectionsStepMock())); + + $this->assertSteps($steps); + } + + public function testAddSteps() + { + $this->directionsLeg->setSteps($steps = array($this->createDirectionsStepMock())); + $this->directionsLeg->addSteps($newSteps = array($this->createDirectionsStepMock())); + + $this->assertSteps(array_merge($steps, $newSteps)); + } + + public function testRemoveSteps() + { + $this->directionsLeg->setSteps($steps = array($this->createDirectionsStepMock())); + $this->directionsLeg->removeSteps($steps); + + $this->assertNoSteps(); + } + + public function testResetSteps() + { + $this->directionsLeg->setSteps(array($this->createDirectionsStepMock())); + $this->directionsLeg->resetSteps(); + + $this->assertNoSteps(); + } + + public function testAddStep() + { + $this->directionsLeg->addStep($step = $this->createDirectionsStepMock()); + + $this->assertStep($step); + } + + public function testAddStepUnicity() + { + $this->directionsLeg->resetSteps(); + $this->directionsLeg->addStep($step = $this->createDirectionsStepMock()); + $this->directionsLeg->addStep($step); + + $this->assertSteps(array($step)); + } + + public function testRemoveStep() + { + $this->directionsLeg->addStep($step = $this->createDirectionsStepMock()); + $this->directionsLeg->removeStep($step); + + $this->assertNoStep($step); + } + + public function testSetViaWaypoints() + { + $this->directionsLeg->setViaWaypoints($viaWaypoints = array($this->createCoordinateMock())); + + $this->assertViaWaypoints($viaWaypoints); + } + + public function testAddViaWaypoints() + { + $this->directionsLeg->setViaWaypoints($viaWaypoints = array($this->createCoordinateMock())); + $this->directionsLeg->addViaWaypoints($newViaWaypoints = array($this->createCoordinateMock())); + + $this->assertViaWaypoints(array_merge($viaWaypoints, $newViaWaypoints)); + } + + public function testRemoveViaWaypoints() + { + $this->directionsLeg->setViaWaypoints($viaWaypoints = array($this->createCoordinateMock())); + $this->directionsLeg->removeViaWaypoints($viaWaypoints); + + $this->assertNoViaWaypoints(); + } + + public function testResetViaWaypoints() + { + $this->directionsLeg->setViaWaypoints(array($this->createCoordinateMock())); + $this->directionsLeg->resetViaWaypoints(); + + $this->assertNoViaWaypoints(); + } + + public function testAddViaWaypoint() + { + $this->directionsLeg->addViaWaypoint($viaWaypoint = $this->createCoordinateMock()); + + $this->assertViaWaypoint($viaWaypoint); + } + + public function testAddViaWaypointUnicity() + { + $this->directionsLeg->resetViaWaypoints(); + $this->directionsLeg->addViaWaypoint($viaWaypoint = $this->createCoordinateMock()); + $this->directionsLeg->addViaWaypoint($viaWaypoint); + + $this->assertViaWaypoints(array($viaWaypoint)); + } + + public function testRemoveViaWaypoint() + { + $this->directionsLeg->addViaWaypoint($viaWaypoint = $this->createCoordinateMock()); + $this->directionsLeg->removeViaWaypoint($viaWaypoint); + + $this->assertNoViaWaypoint($viaWaypoint); + } + + /** + * Asserts there are steps. + * + * @param array $steps The steps. + */ + protected function assertSteps($steps) + { + $this->assertInternalType('array', $steps); + + $this->assertTrue($this->directionsLeg->hasSteps()); + $this->assertSame($steps, $this->directionsLeg->getSteps()); + + foreach ($steps as $step) { + $this->assertStep($step); + } + } + + /** + * Asserts there is a step. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep $step The step. + */ + protected function assertStep($step) + { + $this->assertDirectionsStepInstance($step); + $this->assertTrue($this->directionsLeg->hasStep($step)); + } + + /** + * Asserts there are no steps. + */ + protected function assertNoSteps() + { + $this->assertFalse($this->directionsLeg->hasSteps()); + $this->assertEmpty($this->directionsLeg->getSteps()); + } + + /** + * Asserts there is no step. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsStep $step The step. + */ + protected function assertNoStep($step) + { + $this->assertDirectionsStepInstance($step); + $this->assertFalse($this->directionsLeg->hasStep($step)); + } + + /** + * Asserts there are via waypoints. + * + * @param array $viaWaypoints The via waypoints. + */ + protected function assertViaWaypoints($viaWaypoints) + { + $this->assertInternalType('array', $viaWaypoints); + + $this->assertTrue($this->directionsLeg->hasViaWaypoints()); + $this->assertSame($viaWaypoints, $this->directionsLeg->getViaWaypoints()); + + foreach ($viaWaypoints as $viaWaypoint) { + $this->assertViaWaypoint($viaWaypoint); + } + } + + /** + * Asserts there is a via waypoint. + * + * @param \Ivory\GoogleMap\Base\Coordinate $viaWaypoint The via waypoint. + */ + protected function assertViaWaypoint($viaWaypoint) + { + $this->assertCoordinateInstance($viaWaypoint); + $this->assertTrue($this->directionsLeg->hasViaWaypoint($viaWaypoint)); + } + /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The leg end address must be a string value. + * Asserts there are no via waypoints. */ - public function testEndAddressWithInvalidValue() + protected function assertNoViaWaypoints() { - $this->directionsLeg->setEndAddress(true); + $this->assertFalse($this->directionsLeg->hasViaWaypoints()); + $this->assertEmpty($this->directionsLeg->getViaWaypoints()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The leg start address must be a string value. + * Asserts there is no via waypoint. + * + * @param \Ivory\GoogleMap\Base\Coordinate $viaWaypoint The via waypoint. */ - public function testStartAddressWithInvalidValue() + protected function assertNoViaWaypoint($viaWaypoint) { - $this->directionsLeg->setStartAddress(true); + $this->assertCoordinateInstance($viaWaypoint); + $this->assertFalse($this->directionsLeg->hasViaWaypoint($viaWaypoint)); } } diff --git a/tests/Services/Directions/DirectionsRequestTest.php b/tests/Services/Directions/DirectionsRequestTest.php index ff6a8af7..8266dbc1 100644 --- a/tests/Services/Directions/DirectionsRequestTest.php +++ b/tests/Services/Directions/DirectionsRequestTest.php @@ -11,7 +11,6 @@ namespace Ivory\Tests\GoogleMap\Services\Directions; -use \DateTime; use Ivory\GoogleMap\Services\Directions\DirectionsRequest; use Ivory\GoogleMap\Services\Base\TravelMode; use Ivory\GoogleMap\Services\Base\UnitSystem; @@ -21,17 +20,23 @@ * * @author GeLo */ -class DirectionsRequestTest extends \PHPUnit_Framework_TestCase +class DirectionsRequestTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsRequest */ protected $directionsRequest; + /** @var string */ + protected $origin; + + /** @var string */ + protected $destination; + /** * {@inheritdoc} */ protected function setUp() { - $this->directionsRequest = new DirectionsRequest(); + $this->directionsRequest = new DirectionsRequest($this->origin = 'origin', $this->destination = 'destination'); } /** @@ -39,16 +44,22 @@ protected function setUp() */ protected function tearDown() { + unset($this->destination); + unset($this->origin); unset($this->directionsRequest); } public function testDefaultState() { + $this->assertTrue($this->directionsRequest->hasOrigin()); + $this->assertSame($this->origin, $this->directionsRequest->getOrigin()); + + $this->assertTrue($this->directionsRequest->hasDestination()); + $this->assertSame($this->destination, $this->directionsRequest->getDestination()); + $this->assertFalse($this->directionsRequest->hasAvoidHighways()); $this->assertFalse($this->directionsRequest->hasAvoidTolls()); - $this->assertFalse($this->directionsRequest->hasDestination()); $this->assertFalse($this->directionsRequest->hasOptimizeWaypoints()); - $this->assertFalse($this->directionsRequest->hasOrigin()); $this->assertFalse($this->directionsRequest->hasDepartureTime()); $this->assertFalse($this->directionsRequest->hasArrivalTime()); $this->assertFalse($this->directionsRequest->hasProvideRouteAlternatives()); @@ -59,7 +70,7 @@ public function testDefaultState() $this->assertFalse($this->directionsRequest->hasWaypoints()); } - public function testAvoidHightwaysWithValidValue() + public function testSetAvoidHightways() { $this->directionsRequest->setAvoidHighways(true); @@ -67,24 +78,16 @@ public function testAvoidHightwaysWithValidValue() $this->assertTrue($this->directionsRequest->getAvoidHighways()); } - public function testAvoidHighwaysWithNullValue() + public function testResetAvoidHighways() { $this->directionsRequest->setAvoidHighways(true); $this->directionsRequest->setAvoidHighways(null); + $this->assertFalse($this->directionsRequest->hasAvoidHighways()); $this->assertNull($this->directionsRequest->getAvoidHighways()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request avoid hightways flag must be a boolean value. - */ - public function testAvoidHighwaysWithInvalidValue() - { - $this->directionsRequest->setAvoidHighways('foo'); - } - - public function testAvoidTollsWithValidValue() + public function testSetAvoidTolls() { $this->directionsRequest->setAvoidTolls(true); @@ -92,63 +95,27 @@ public function testAvoidTollsWithValidValue() $this->assertTrue($this->directionsRequest->getAvoidTolls()); } - public function testAvoidTollsWithNullValue() + public function testResetAvoidTolls() { $this->directionsRequest->setAvoidTolls(true); $this->directionsRequest->setAvoidTolls(null); + $this->assertFalse($this->directionsRequest->hasAvoidTolls()); $this->assertNull($this->directionsRequest->getAvoidTolls()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request avoid tolls flag must be a boolean value. + * @dataProvider locationProvider */ - public function testAvoidTollsWithInvalidValue() + public function testSetDestination($destination) { - $this->directionsRequest->setAvoidTolls('foo'); - } - - public function testDestinationWithString() - { - $this->directionsRequest->setDestination('foo'); + $this->directionsRequest->setDestination($destination); $this->assertTrue($this->directionsRequest->hasDestination()); - $this->assertEquals($this->directionsRequest->getDestination(), 'foo'); + $this->assertSame($destination, $this->directionsRequest->getDestination()); } - public function testDestinationWithCoordinate() - { - $location = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->directionsRequest->setDestination($location); - - $this->assertSame($location, $this->directionsRequest->getDestination()); - } - - public function testDestinationWithLatitudeAndLongitude() - { - $this->directionsRequest->setDestination(1.1, 2.1, false); - - $this->assertSame(1.1, $this->directionsRequest->getDestination()->getLatitude()); - $this->assertSame(2.1, $this->directionsRequest->getDestination()->getLongitude()); - $this->assertFalse($this->directionsRequest->getDestination()->isNoWrap()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The destination setter arguments are invalid. - * The available prototypes are : - * - function setDestination(string $destination) - * - function setDestination(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setDestination(double $latitude, double $longitude, boolean $noWrap) - */ - public function testDestinationWithInvalidValue() - { - $this->directionsRequest->setDestination(true); - } - - public function testOptimizeWaypointsWithValidValue() + public function testSetOptimizeWaypoints() { $this->directionsRequest->setOptimizeWaypoints(true); @@ -156,96 +123,61 @@ public function testOptimizeWaypointsWithValidValue() $this->assertTrue($this->directionsRequest->getOptimizeWaypoints()); } - public function testOptimizeWaypointsWithNullValue() + public function testResetOptimizeWaypoints() { $this->directionsRequest->setOptimizeWaypoints(true); $this->directionsRequest->setOptimizeWaypoints(null); + $this->assertFalse($this->directionsRequest->hasOptimizeWaypoints()); $this->assertNull($this->directionsRequest->getOptimizeWaypoints()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request optimize waypoints flag must be a boolean value. + * @dataProvider locationProvider */ - public function testOptimizeWaypointsWithInvalidValue() + public function testSetOrigin($origin) { - $this->directionsRequest->setOptimizeWaypoints('foo'); - } - - public function testOriginWithString() - { - $this->directionsRequest->setOrigin('foo'); - - $this->assertTrue($this->directionsRequest->hasOrigin()); - $this->assertSame('foo', $this->directionsRequest->getOrigin()); - } - - public function testOriginWithCoordinate() - { - $origin = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); $this->directionsRequest->setOrigin($origin); + $this->assertTrue($this->directionsRequest->hasOrigin()); $this->assertSame($origin, $this->directionsRequest->getOrigin()); } - public function testOriginWithLatitudeAndLongitude() - { - $this->directionsRequest->setOrigin(1.1, 2.1, false); - - $this->assertSame(1.1, $this->directionsRequest->getOrigin()->getLatitude()); - $this->assertSame(2.1, $this->directionsRequest->getOrigin()->getLongitude()); - $this->assertFalse($this->directionsRequest->getOrigin()->isNoWrap()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The origin setter arguments are invalid. - * The available prototypes are : - * - function setOrigin(string $destination) - * - function setOrigin(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setOrigin(double $latitude, double $longitude, boolean $noWrap) - */ - public function testOriginWithInvalidValue() - { - $this->directionsRequest->setOrigin(true); - } - - public function testDepartureTimeWithValidValue() + public function testSetDepartureTime() { - $now = new DateTime(); - $this->directionsRequest->setDepartureTime($now); + $this->directionsRequest->setDepartureTime($departureTime = new \DateTime()); $this->assertTrue($this->directionsRequest->hasDepartureTime()); - $this->assertSame($now, $this->directionsRequest->getDepartureTime()); + $this->assertSame($departureTime, $this->directionsRequest->getDepartureTime()); } - public function testDepartureTimeWithNullValue() + public function testResetDepartureTime() { - $this->directionsRequest->setDepartureTime(new DateTime()); + $this->directionsRequest->setDepartureTime(new \DateTime()); $this->directionsRequest->setDepartureTime(null); + $this->assertFalse($this->directionsRequest->hasDepartureTime()); $this->assertNull($this->directionsRequest->getDepartureTime()); } - public function testArrivalTimeWithValidValue() + public function testSetArrivalTime() { - $now = new DateTime(); - $this->directionsRequest->setArrivalTime($now); + $this->directionsRequest->setArrivalTime($arrivalTime = new \DateTime()); $this->assertTrue($this->directionsRequest->hasArrivalTime()); - $this->assertSame($now, $this->directionsRequest->getArrivalTime()); + $this->assertSame($arrivalTime, $this->directionsRequest->getArrivalTime()); } - public function testArrivalTimeWithNullValue() + public function testResetArrivalTime() { - $this->directionsRequest->setArrivalTime(new DateTime()); + $this->directionsRequest->setArrivalTime(new \DateTime()); $this->directionsRequest->setArrivalTime(null); + $this->assertFalse($this->directionsRequest->hasArrivalTime()); $this->assertNull($this->directionsRequest->getArrivalTime()); } - public function testProvideRouteAlternativesWithValidValue() + public function testSetProvideRouteAlternatives() { $this->directionsRequest->setProvideRouteAlternatives(true); @@ -253,283 +185,203 @@ public function testProvideRouteAlternativesWithValidValue() $this->assertTrue($this->directionsRequest->getProvideRouteAlternatives()); } - public function testProvideRouteAlternativesWithNullValue() + public function testResetProvideRouteAlternatives() { $this->directionsRequest->setProvideRouteAlternatives(true); $this->directionsRequest->setProvideRouteAlternatives(null); + $this->assertFalse($this->directionsRequest->hasProvideRouteAlternatives()); $this->assertNull($this->directionsRequest->getProvideRouteAlternatives()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request provide route alternatives flag must be a boolean value. - */ - public function testProvideRouteAlternativesWithInvalidValue() - { - $this->directionsRequest->setProvideRouteAlternatives('foo'); - } - - public function testRegionWithValidValue() + public function testSetRegion() { - $this->directionsRequest->setRegion('fr'); + $this->directionsRequest->setRegion($region = 'fr'); $this->assertTrue($this->directionsRequest->hasRegion()); - $this->assertSame('fr', $this->directionsRequest->getRegion()); + $this->assertSame($region, $this->directionsRequest->getRegion()); } - public function testRegionWithNullValue() + public function testResetRegion() { $this->directionsRequest->setRegion('fr'); $this->directionsRequest->setRegion(null); + $this->assertFalse($this->directionsRequest->hasRegion()); $this->assertNull($this->directionsRequest->getRegion()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request region must be a string with two characters. - */ - public function testRegionWithInvalidValue() - { - $this->directionsRequest->setRegion('foo'); - } - - public function testLanguageWithValidValue() + public function testSetLanguage() { - $this->directionsRequest->setLanguage('fr'); + $this->directionsRequest->setLanguage($language = 'fr'); $this->assertTrue($this->directionsRequest->hasLanguage()); - $this->assertSame('fr', $this->directionsRequest->getLanguage()); + $this->assertSame($language, $this->directionsRequest->getLanguage()); } - public function testLanguageWithNullValue() + public function testResetLanguage() { $this->directionsRequest->setLanguage('fr'); $this->directionsRequest->setLanguage(null); + $this->assertFalse($this->directionsRequest->hasLanguage()); $this->assertNull($this->directionsRequest->getLanguage()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request language must be a string with two or five characters. - */ - public function testLanguageWithInvalidValue() - { - $this->directionsRequest->setLanguage('foo'); - } - - public function testTravelModeWithValidValue() + public function testSetTravelMode() { - $this->directionsRequest->setTravelMode(TravelMode::WALKING); + $this->directionsRequest->setTravelMode($travelMode = TravelMode::WALKING); $this->assertTrue($this->directionsRequest->hasTravelMode()); - $this->assertSame(TravelMode::WALKING, $this->directionsRequest->getTravelMode()); + $this->assertSame($travelMode, $this->directionsRequest->getTravelMode()); } - public function testTravelModeWithNullValue() + public function testResetTravelMode() { $this->directionsRequest->setTravelMode(TravelMode::WALKING); $this->directionsRequest->setTravelMode(null); + $this->assertFalse($this->directionsRequest->hasTravelMode()); $this->assertNull($this->directionsRequest->getTravelMode()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request travel mode can only be : BICYCLING, DRIVING, WALKING, TRANSIT. - */ - public function testTravelModeWithInvalidValue() - { - $this->directionsRequest->setTravelMode('foo'); - } - - public function testUnitSystemWithValidValue() + public function testSetUnitSystem() { - $this->directionsRequest->setUnitSystem(UnitSystem::IMPERIAL); + $this->directionsRequest->setUnitSystem($unitSystem = UnitSystem::IMPERIAL); $this->assertTrue($this->directionsRequest->hasUnitSystem()); - $this->assertSame(UnitSystem::IMPERIAL, $this->directionsRequest->getUnitSystem()); + $this->assertSame($unitSystem, $this->directionsRequest->getUnitSystem()); } - public function testUnitSystemWithNullValue() + public function testResetUnitSystem() { $this->directionsRequest->setUnitSystem(UnitSystem::IMPERIAL); $this->directionsRequest->setUnitSystem(null); + $this->assertFalse($this->directionsRequest->hasUnitSystem()); $this->assertNull($this->directionsRequest->getUnitSystem()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request unit system can only be : IMPERIAL, METRIC. - */ - public function testUnitSystemWithInvalidValue() - { - $this->directionsRequest->setUnitSystem('foo'); - } - - public function testWaypointWithWaypoint() - { - $waypoint = $this->getMock('Ivory\GoogleMap\Services\Directions\DirectionsWaypoint'); - $this->directionsRequest->setWaypoints(array($waypoint)); - - $this->assertTrue($this->directionsRequest->hasWaypoints()); - $this->assertSame(array($waypoint), $this->directionsRequest->getWaypoints()); - } - - public function testWaypointWithCoordinate() + public function testSetWaypoints() { - $coordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->directionsRequest->setWaypoints(array($coordinate)); - - $waypoints = $this->directionsRequest->getWaypoints(); + $this->directionsRequest->setWaypoints($waypoints = array($this->createDirectionsWaypointMock())); - $this->assertArrayHasKey(0, $waypoints); - $this->assertSame($coordinate, $waypoints[0]->getLocation()); + $this->assertWaypoints($waypoints); } - public function testWaypointWithLatitudeAndLongitude() + public function testAddWaypoints() { - $this->directionsRequest->addWaypoint(1.1, 2.2, false); - - $waypoints = $this->directionsRequest->getWaypoints(); - - $this->assertArrayHasKey(0, $waypoints); - $this->assertSame(1.1, $waypoints[0]->getLocation()->getLatitude()); - $this->assertSame(2.2, $waypoints[0]->getLocation()->getLongitude()); - $this->assertFalse($waypoints[0]->getLocation()->isNoWrap()); - } + $this->directionsRequest->setWaypoints($waypoints = array($this->createDirectionsWaypointMock())); + $this->directionsRequest->addWaypoints($newWaypoints = array($this->createDirectionsWaypointMock())); - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The waypoint adder arguments are invalid. - * The available prototypes are : - * - function addWaypoint(Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint) - * - function addWaypoint(string $location) - * - function addWaypoint(Ivory\GoogleMap\Base\Coordinate $location) - * - function addWaypoint(double $latitude, double $longitude, boolean $noWrap) - */ - public function testWaypointWithInvalidValue() - { - $this->directionsRequest->addWaypoint(true); + $this->assertWaypoints(array_merge($waypoints, $newWaypoints)); } - public function testSensorWithValidValue() + public function testRemoveWaypoints() { - $this->directionsRequest->setSensor(true); + $this->directionsRequest->setWaypoints($waypoints = array($this->createDirectionsWaypointMock())); + $this->directionsRequest->removeWaypoints($waypoints); - $this->assertTrue($this->directionsRequest->hasSensor()); + $this->assertNoWaypoints(); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request sensor flag must be a boolean value. - */ - public function testSensorWithInvalidValue() + public function testResetWaypoints() { - $this->directionsRequest->setSensor('foo'); - } + $this->directionsRequest->setWaypoints(array($this->createDirectionsWaypointMock())); + $this->directionsRequest->resetWaypoints(); - public function testIsValid() - { - $this->assertFalse($this->directionsRequest->isValid()); + $this->assertNoWaypoints(); } - public function testIsValidWithOrigin() + public function testAddWaypoint() { - $this->directionsRequest->setOrigin('foo'); + $this->directionsRequest->addWaypoint($waypoint = $this->createDirectionsWaypointMock()); - $this->assertFalse($this->directionsRequest->isValid()); + $this->assertWaypoint($waypoint); } - public function testIsValidWithDestination() + public function testAddWaypointUnicity() { - $this->directionsRequest->setDestination('foo'); + $this->directionsRequest->resetWaypoints(); + $this->directionsRequest->addWaypoint($waypoint = $this->createDirectionsWaypointMock()); + $this->directionsRequest->addWaypoint($waypoint); - $this->assertFalse($this->directionsRequest->isValid()); + $this->assertWaypoints(array($waypoint)); } - public function testIsValidWithOriginAndDestination() + public function testRemoveWaypoint() { - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); + $this->directionsRequest->addWaypoint($waypoint = $this->createDirectionsWaypointMock()); + $this->directionsRequest->removeWaypoint($waypoint); - $this->assertTrue($this->directionsRequest->isValid()); + $this->assertNoWaypoint($waypoint); } - public function testIsValidWithValidWaypoint() + public function testSetSensor() { - $waypoint = $this->getMock('Ivory\GoogleMap\Services\Directions\DirectionsWaypoint'); - $waypoint - ->expects($this->once()) - ->method('isValid') - ->will($this->returnValue(true)); - - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); - $this->directionsRequest->addWaypoint($waypoint); + $this->directionsRequest->setSensor(true); - $this->assertTrue($this->directionsRequest->isValid()); + $this->assertTrue($this->directionsRequest->hasSensor()); } - public function testIsValidWithInvalidWaypoint() + /** + * Gets the location provider. + * + * @return array The location provider. + */ + public function locationProvider() { - $waypoint = $this->getMock('Ivory\GoogleMap\Services\Directions\DirectionsWaypoint'); - $waypoint - ->expects($this->once()) - ->method('isValid') - ->will($this->returnValue(false)); - - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); - $this->directionsRequest->addWaypoint($waypoint); - - $this->assertFalse($this->directionsRequest->isValid()); + return array( + array('foo'), + array($this->createCoordinateMock()), + ); } - public function testIsValidWithInvalidTransit() + /** + * Asserts there are waypoints. + * + * @param array $waypoints The waypoints. + */ + protected function assertWaypoints($waypoints) { - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); + $this->assertInternalType('array', $waypoints); - $this->directionsRequest->setTravelMode(TravelMode::TRANSIT); + $this->assertTrue($this->directionsRequest->hasWaypoints()); + $this->assertSame($waypoints, $this->directionsRequest->getWaypoints()); - $this->assertFalse($this->directionsRequest->isValid()); + foreach ($waypoints as $waypoint) { + $this->assertWaypoint($waypoint); + } } - public function testIsValidWithValidTransitDepartureTime() + /** + * Asserts there is a waypoint. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The waypoint. + */ + protected function assertWaypoint($waypoint) { - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); - - $this->directionsRequest->setTravelMode(TravelMode::TRANSIT); - $this->directionsRequest->setDepartureTime(new DateTime()); - - $this->assertTrue($this->directionsRequest->isValid()); + $this->assertDirectionsWaypointInstance($waypoint); + $this->assertTrue($this->directionsRequest->hasWaypoint($waypoint)); } - public function testIsValidWithTransitArrivalTime() + /** + * Asserts there are no waypoints. + */ + protected function assertNoWaypoints() { - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); - - $this->directionsRequest->setTravelMode(TravelMode::TRANSIT); - $this->directionsRequest->setArrivalTime(new DateTime()); - - $this->assertTrue($this->directionsRequest->isValid()); + $this->assertFalse($this->directionsRequest->hasWaypoints()); + $this->assertEmpty($this->directionsRequest->getWaypoints()); } - public function testIsValidWithValidTransitDepartureTimeAndArrivalTime() + /** + * Asserts there is no waypoint. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint $waypoint The waypoint. + */ + protected function assertNoWaypoint($waypoint) { - $this->directionsRequest->setDestination('foo'); - $this->directionsRequest->setOrigin('bar'); - - $this->directionsRequest->setTravelMode(TravelMode::TRANSIT); - $this->directionsRequest->setArrivalTime(new DateTime()); - $this->directionsRequest->setDepartureTime(new DateTime()); - - $this->assertTrue($this->directionsRequest->isValid()); + $this->assertDirectionsWaypointInstance($waypoint); + $this->assertFalse($this->directionsRequest->hasWaypoint($waypoint)); } } diff --git a/tests/Services/Directions/DirectionsResponseTest.php b/tests/Services/Directions/DirectionsResponseTest.php index 36e7dc0d..165fae76 100644 --- a/tests/Services/Directions/DirectionsResponseTest.php +++ b/tests/Services/Directions/DirectionsResponseTest.php @@ -19,7 +19,7 @@ * * @author GeLo */ -class DirectionsResponseTest extends \PHPUnit_Framework_TestCase +class DirectionsResponseTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsResponse */ protected $directionsResponse; @@ -35,14 +35,10 @@ class DirectionsResponseTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $route = $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsRoute') - ->disableOriginalConstructor() - ->getMock(); - - $this->routes = array($route); - $this->status = DirectionsStatus::NOT_FOUND; - - $this->directionsResponse = new DirectionsResponse($this->routes, $this->status); + $this->directionsResponse = new DirectionsResponse( + $this->routes = array($this->createDirectionsRouteMock()), + $this->status = DirectionsStatus::NOT_FOUND + ); } /** @@ -61,13 +57,113 @@ public function testDefaultState() $this->assertSame($this->status, $this->directionsResponse->getStatus()); } + public function testSetRoutes() + { + $this->directionsResponse->setRoutes($routes = array($this->createDirectionsRouteMock())); + + $this->assertRoutes($routes); + } + + public function testAddRoutes() + { + $this->directionsResponse->setRoutes($routes = array($this->createDirectionsRouteMock())); + $this->directionsResponse->addRoutes($newRoutes = array($this->createDirectionsRouteMock())); + + $this->assertRoutes(array_merge($routes, $newRoutes)); + } + + public function testRemoveRoutes() + { + $this->directionsResponse->setRoutes($routes = array($this->createDirectionsRouteMock())); + $this->directionsResponse->removeRoutes($routes); + + $this->assertNoRoutes(); + } + + public function testResetRoutes() + { + $this->directionsResponse->setRoutes(array($this->createDirectionsRouteMock())); + $this->directionsResponse->resetRoutes(); + + $this->assertNoRoutes(); + } + + public function testAddRoute() + { + $this->directionsResponse->addRoute($route = $this->createDirectionsRouteMock()); + + $this->assertRoute($route); + } + + public function testAddRouteUnicity() + { + $this->directionsResponse->resetRoutes(); + $this->directionsResponse->addRoute($route = $this->createDirectionsRouteMock()); + $this->directionsResponse->addRoute($route); + + $this->assertRoutes(array($route)); + } + + public function testRemoveRoute() + { + $this->directionsResponse->addRoute($route = $this->createDirectionsRouteMock()); + $this->directionsResponse->removeRoute($route); + + $this->assertNoRoute($route); + } + + public function testSetStatus() + { + $this->directionsResponse->setStatus($status = DirectionsStatus::OK); + + $this->assertSame($status, $this->directionsResponse->getStatus()); + } + + /** + * Asserts there are routes. + * + * @param array $routes The routes. + */ + protected function assertRoutes($routes) + { + $this->assertInternalType('array', $routes); + + $this->assertTrue($this->directionsResponse->hasRoutes()); + $this->assertSame($routes, $this->directionsResponse->getRoutes()); + + foreach ($routes as $route) { + $this->assertRoute($route); + } + } + + /** + * Asserts there is a route. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRoute $route The route. + */ + protected function assertRoute($route) + { + $this->assertDirectionsRouteInstance($route); + $this->assertTrue($this->directionsResponse->hasRoute($route)); + } + + /** + * Asserts there are no routes. + */ + protected function assertNoRoutes() + { + $this->assertFalse($this->directionsResponse->hasRoutes()); + $this->assertEmpty($this->directionsResponse->getRoutes()); + } + /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions response status can only be : INVALID_REQUEST, - * MAX_WAYPOINTS_EXCEEDED, NOT_FOUND, OK, OVER_QUERY_LIMIT, REQUEST_DENIED, UNKNOWN_ERROR, ZERO_RESULTS. + * Asserts there is no route. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsRoute $route The route. */ - public function testStatusWithInvalidValue() + protected function assertNoRoute($route) { - $this->directionsResponse->setStatus('foo'); + $this->assertDirectionsRouteInstance($route); + $this->assertFalse($this->directionsResponse->hasRoute($route)); } } diff --git a/tests/Services/Directions/DirectionsRouteTest.php b/tests/Services/Directions/DirectionsRouteTest.php index 2cd30deb..2568acbf 100644 --- a/tests/Services/Directions/DirectionsRouteTest.php +++ b/tests/Services/Directions/DirectionsRouteTest.php @@ -18,12 +18,12 @@ * * @author GeLo */ -class DirectionsRouteTest extends \PHPUnit_Framework_TestCase +class DirectionsRouteTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsRoute */ protected $directionsRoute; - /** @var \Ivory\GoogleMap\Base\Bound */ + /** @var \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject */ protected $bound; /** @var string */ @@ -32,7 +32,7 @@ class DirectionsRouteTest extends \PHPUnit_Framework_TestCase /** @var array */ protected $legs; - /** @var \Ivory\GoogleMap\Overlays\EncodedPolyline */ + /** @var \Ivory\GoogleMap\Overlays\EncodedPolyline|\PHPUnit_Framework_MockObject_MockObject */ protected $encodedPolyline; /** @var string */ @@ -42,35 +42,21 @@ class DirectionsRouteTest extends \PHPUnit_Framework_TestCase protected $warnings; /** @var array */ - protected $waypointOrder; + protected $waypointOrders; /** * {@inheritdoc} */ protected function setUp() { - $this->bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->copyrights = 'foo'; - - $leg = $this->getMockBuilder('Ivory\GoogleMap\Services\Directions\DirectionsLeg') - ->disableOriginalConstructor() - ->getMock(); - - $this->legs = array($leg); - - $this->encodedPolyline = $this->getMock('Ivory\GoogleMap\Overlays\EncodedPolyline'); - $this->summary = 'bar'; - $this->warnings = array('foo', 'baz'); - $this->waypointOrder = array(3, 2, 1); - $this->directionsRoute = new DirectionsRoute( - $this->bound, - $this->copyrights, - $this->legs, - $this->encodedPolyline, - $this->summary, - $this->warnings, - $this->waypointOrder + $this->bound = $this->createBoundMock(), + $this->copyrights = 'copyrights', + $this->legs = array($leg = $this->createDirectionsLegMock()), + $this->encodedPolyline = $this->createEncodedPolylineMock(), + $this->summary = 'summary', + $this->warnings = array('waypoint'), + $this->waypointOrders = array(1) ); } @@ -86,7 +72,7 @@ protected function tearDown() unset($this->encodedPolyline); unset($this->summary); unset($this->warnings); - unset($this->waypointOrder); + unset($this->waypointOrders); } public function testInitialState() @@ -97,42 +83,339 @@ public function testInitialState() $this->assertSame($this->encodedPolyline, $this->directionsRoute->getOverviewPolyline()); $this->assertSame($this->summary, $this->directionsRoute->getSummary()); $this->assertSame($this->warnings, $this->directionsRoute->getWarnings()); - $this->assertSame($this->waypointOrder, $this->directionsRoute->getWaypointOrder()); + $this->assertSame($this->waypointOrders, $this->directionsRoute->getWaypointOrders()); + } + + public function testSetBound() + { + $this->directionsRoute->setBound($bound = $this->createBoundMock()); + + $this->assertSame($bound, $this->directionsRoute->getBound()); + } + + public function testSetCopyrights() + { + $this->directionsRoute->setCopyrights($copyrights = 'foo'); + + $this->assertSame($copyrights, $this->directionsRoute->getCopyrights()); + } + + public function testSetLegs() + { + $this->directionsRoute->setLegs($legs = array($this->createDirectionsLegMock())); + + $this->assertLegs($legs); + } + + public function testAddLegs() + { + $this->directionsRoute->setLegs($legs = array($this->createDirectionsLegMock())); + $this->directionsRoute->addLegs($newLegs = array($this->createDirectionsLegMock())); + + $this->assertLegs(array_merge($legs, $newLegs)); + } + + public function testRemoveLegs() + { + $this->directionsRoute->setLegs($legs = array($this->createDirectionsLegMock())); + $this->directionsRoute->removeLegs($legs); + + $this->assertNoLegs(); + } + + public function testResetLegs() + { + $this->directionsRoute->setLegs(array($this->createDirectionsLegMock())); + $this->directionsRoute->resetLegs(); + + $this->assertNoLegs(); + } + + public function testAddLeg() + { + $this->directionsRoute->addLeg($leg = $this->createDirectionsLegMock()); + + $this->assertLeg($leg); + } + + public function testAddLegUnicity() + { + $this->directionsRoute->resetLegs(); + $this->directionsRoute->addLeg($leg = $this->createDirectionsLegMock()); + $this->directionsRoute->addLeg($leg); + + $this->assertLegs(array($leg)); + } + + public function testRemoveLeg() + { + $this->directionsRoute->addLeg($leg = $this->createDirectionsLegMock()); + $this->directionsRoute->removeLeg($leg); + + $this->assertNoLeg($leg); + } + + public function testSetOverviewPolyline() + { + $this->directionsRoute->setOverviewPolyline($overviewPolyline = $this->createEncodedPolylineMock()); + + $this->assertSame($overviewPolyline, $this->directionsRoute->getOverviewPolyline()); + } + + public function testSetSummary() + { + $this->directionsRoute->setSummary($summary = 'foo'); + + $this->assertSame($summary, $this->directionsRoute->getSummary()); + } + + public function testSetWarnings() + { + $this->directionsRoute->setWarnings($warnings = array('foo')); + + $this->assertWarnings($warnings); + } + + public function testAddWarnings() + { + $this->directionsRoute->setWarnings($warnings = array('foo')); + $this->directionsRoute->addWarnings($newWarnings = array('bar')); + + $this->assertWarnings(array_merge($warnings, $newWarnings)); + } + + public function testRemoveWarnings() + { + $this->directionsRoute->setWarnings($warnings = array('foo')); + $this->directionsRoute->removeWarnings($warnings); + + $this->assertNoWarnings(); + } + + public function testResetWarnings() + { + $this->directionsRoute->setWarnings(array('foo')); + $this->directionsRoute->resetWarnings(); + + $this->assertNoWarnings(); + } + + public function testAddWarning() + { + $this->directionsRoute->addWarning($warning = 'foo'); + + $this->assertWarning($warning); + } + + public function testAddWarningUnicity() + { + $this->directionsRoute->resetWarnings(); + $this->directionsRoute->addWarning($warning = 'foo'); + $this->directionsRoute->addWarning($warning); + + $this->assertWarnings(array($warning)); + } + + public function testRemoveWarning() + { + $this->directionsRoute->addWarning($warning = 'foo'); + $this->directionsRoute->removeWarning($warning); + + $this->assertNoWarning($warning); + } + + public function testSetWaypointOrders() + { + $this->directionsRoute->setWaypointOrders($waypointOrders = array(1)); + + $this->assertWaypointOrders($waypointOrders); + } + + public function testAddWaypointOrders() + { + $this->directionsRoute->setWaypointOrders($waypointOrders = array('foo')); + $this->directionsRoute->addWaypointOrders($newWaypointOrders = array('bar')); + + $this->assertWaypointOrders(array_merge($waypointOrders, $newWaypointOrders)); + } + + public function testRemoveWaypointOrders() + { + $this->directionsRoute->setWaypointOrders($waypointOrders = array('foo')); + $this->directionsRoute->removeWaypointOrders($waypointOrders); + + $this->assertNoWaypointOrders(); + } + + public function testResetWaypointOrders() + { + $this->directionsRoute->setWaypointOrders(array(1)); + $this->directionsRoute->resetWaypointOrders(); + + $this->assertNoWaypointOrders(); + } + + public function testAddWaypointOrder() + { + $this->directionsRoute->addWaypointOrder($waypointOrder = 1); + + $this->assertWaypointOrder($waypointOrder); + } + + public function testAddWaypointOrderUnicity() + { + $this->directionsRoute->resetWaypointOrders(); + $this->directionsRoute->addWaypointOrder($waypointOrder = 'foo'); + $this->directionsRoute->addWaypointOrder($waypointOrder); + + $this->assertWaypointOrders(array($waypointOrder)); + } + + public function testRemoveWaypointOrder() + { + $this->directionsRoute->addWaypointOrder($waypointOrder = 1); + $this->directionsRoute->removeWaypointOrder($waypointOrder); + + $this->assertNoWaypointOrder($waypointOrder); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions route copyrights must be a string value. + * Asserts there are legs. + * + * @param array $legs The legs. */ - public function testCopyrightsWithInvalidValue() + protected function assertLegs($legs) { - $this->directionsRoute->setCopyrights(true); + $this->assertInternalType('array', $legs); + + $this->assertTrue($this->directionsRoute->hasLegs()); + $this->assertSame($legs, $this->directionsRoute->getLegs()); + + foreach ($legs as $leg) { + $this->assertLeg($leg); + } + } + + /** + * Asserts there is a leg. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg $leg The direction leg. + */ + protected function assertLeg($leg) + { + $this->assertDirectionsLegInstance($leg); + $this->assertTrue($this->directionsRoute->hasLeg($leg)); + } + + /** + * Asserts there are no legs. + */ + protected function assertNoLegs() + { + $this->assertFalse($this->directionsRoute->hasLegs()); + $this->assertEmpty($this->directionsRoute->getLegs()); + } + + /** + * Asserts there is no leg. + * + * @param \Ivory\GoogleMap\Services\Directions\DirectionsLeg $leg The leg. + */ + protected function assertNoLeg($leg) + { + $this->assertDirectionsLegInstance($leg); + $this->assertFalse($this->directionsRoute->hasLeg($leg)); + } + + /** + * Asserts there are warnings. + * + * @param array $warnings The warnings. + */ + protected function assertWarnings($warnings) + { + $this->assertInternalType('array', $warnings); + + $this->assertTrue($this->directionsRoute->hasWarnings()); + $this->assertSame($warnings, $this->directionsRoute->getWarnings()); + + foreach ($warnings as $warning) { + $this->assertWarning($warning); + } + } + + /** + * Asserts there is a warning. + * + * @param string $warning The warning. + */ + protected function assertWarning($warning) + { + $this->assertTrue($this->directionsRoute->hasWarning($warning)); + } + + /** + * Asserts there are no warnings. + */ + protected function assertNoWarnings() + { + $this->assertFalse($this->directionsRoute->hasWarnings()); + $this->assertEmpty($this->directionsRoute->getWarnings()); + } + + /** + * Asserts there is no warning. + * + * @param string $warning The warning. + */ + protected function assertNoWarning($warning) + { + $this->assertFalse($this->directionsRoute->hasWarning($warning)); + } + + /** + * Asserts there are waypoint orders. + * + * @param array $waypointOrders The waypoint orders. + */ + protected function assertWaypointOrders($waypointOrders) + { + $this->assertInternalType('array', $waypointOrders); + + $this->assertTrue($this->directionsRoute->hasWaypointOrders()); + $this->assertSame($waypointOrders, $this->directionsRoute->getWaypointOrders()); + + foreach ($waypointOrders as $waypointOrder) { + $this->assertWaypointOrder($waypointOrder); + } } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions route summary must be a string value. + * Asserts there is a waypoint order. + * + * @param integer $waypointOrder The waypoint order. */ - public function testSummaryWithInvalidValue() + protected function assertWaypointOrder($waypointOrder) { - $this->directionsRoute->setSummary(true); + $this->assertTrue($this->directionsRoute->hasWaypointOrder($waypointOrder)); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions route warning must be a string value. + * Asserts there are no waypoint orders. */ - public function testWarningsWithInvalidValue() + protected function assertNoWaypointOrders() { - $this->directionsRoute->addWarning(true); + $this->assertFalse($this->directionsRoute->hasWaypointOrders()); + $this->assertEmpty($this->directionsRoute->getWaypointOrders()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions route waypoint order must be an integer value. + * Asserts there is no waypoint order. + * + * @param integer $waypointOrder The waypoint order. */ - public function testWaypointOrderWithInvalidValue() + protected function assertNoWaypointOrder($waypointOrder) { - $this->directionsRoute->addWaypointOrder(true); + $this->assertFalse($this->directionsRoute->hasWaypointOrder($waypointOrder)); } } diff --git a/tests/Services/Directions/DirectionsStatusTest.php b/tests/Services/Directions/DirectionsStatusTest.php index 9df965f7..5c4a5a82 100644 --- a/tests/Services/Directions/DirectionsStatusTest.php +++ b/tests/Services/Directions/DirectionsStatusTest.php @@ -18,21 +18,22 @@ * * @author GeLo */ -class DirectionsStatusTest extends \PHPUnit_Framework_TestCase +class DirectionsStatusTest extends AbstractTestCase { - public function testDirectionsStatus() + public function testInheritance() { - $expected = array( - DirectionsStatus::INVALID_REQUEST, - DirectionsStatus::MAX_WAYPOINTS_EXCEEDED, - DirectionsStatus::NOT_FOUND, - DirectionsStatus::OK, - DirectionsStatus::OVER_QUERY_LIMIT, - DirectionsStatus::REQUEST_DENIED, - DirectionsStatus::UNKNOWN_ERROR, - DirectionsStatus::ZERO_RESULTS, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Services\Directions\DirectionsStatus'); + } - $this->assertSame($expected, DirectionsStatus::getDirectionsStatus()); + public function testConstants() + { + $this->assertSame('INVALID_REQUEST', DirectionsStatus::INVALID_REQUEST); + $this->assertSame('MAX_WAYPOINTS_EXCEEDED', DirectionsStatus::MAX_WAYPOINTS_EXCEEDED); + $this->assertSame('NOT_FOUND', DirectionsStatus::NOT_FOUND); + $this->assertSame('OK', DirectionsStatus::OK); + $this->assertSame('OVER_QUERY_LIMIT', DirectionsStatus::OVER_QUERY_LIMIT); + $this->assertSame('REQUEST_DENIED', DirectionsStatus::REQUEST_DENIED); + $this->assertSame('UNKNOWN_ERROR', DirectionsStatus::UNKNOWN_ERROR); + $this->assertSame('ZERO_RESULTS', DirectionsStatus::ZERO_RESULTS); } } diff --git a/tests/Services/Directions/DirectionsStepTest.php b/tests/Services/Directions/DirectionsStepTest.php index 7727097f..792e90e5 100644 --- a/tests/Services/Directions/DirectionsStepTest.php +++ b/tests/Services/Directions/DirectionsStepTest.php @@ -19,27 +19,27 @@ * * @author GeLo */ -class DirectionsStepTest extends \PHPUnit_Framework_TestCase +class DirectionsStepTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsStep */ protected $directionsStep; - /** @var \Ivory\GoogleMap\Services\Base\Distance */ + /** @var \Ivory\GoogleMap\Services\Base\Distance|\PHPUnit_Framework_MockObject_MockObject */ protected $distance; - /** @var \Ivory\GoogleMap\Services\Base\Duration */ + /** @var \Ivory\GoogleMap\Services\Base\Duration|\PHPUnit_Framework_MockObject_MockObject */ protected $duration; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ protected $endLocation; /** @var string */ protected $instructions; - /** @var \Ivory\GoogleMap\Overlays\EncodedPolyline */ + /** @var \Ivory\GoogleMap\Overlays\EncodedPolyline|\PHPUnit_Framework_MockObject_MockObject */ protected $encodedPolyline; - /** @var \Ivory\GoogleMap\Base\Coordinate */ + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ protected $startLocation; /** @var string */ @@ -50,28 +50,14 @@ class DirectionsStepTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->distance = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Distance') - ->disableOriginalConstructor() - ->getMock(); - - $this->duration = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Duration') - ->disableOriginalConstructor() - ->getMock(); - - $this->endLocation = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->instructions = 'instructions'; - $this->encodedPolyline = $this->getMock('Ivory\GoogleMap\Overlays\EncodedPolyline'); - $this->startLocation = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->travelMode = TravelMode::DRIVING; - $this->directionsStep = new DirectionsStep( - $this->distance, - $this->duration, - $this->endLocation, - $this->instructions, - $this->encodedPolyline, - $this->startLocation, - $this->travelMode + $this->distance = $this->createDistanceMock(), + $this->duration = $this->createDurationMock(), + $this->endLocation = $this->createCoordinateMock(), + $this->instructions = 'instructions', + $this->encodedPolyline = $this->createEncodedPolylineMock(), + $this->startLocation = $this->createCoordinateMock(), + $this->travelMode = TravelMode::DRIVING ); } @@ -101,21 +87,52 @@ public function testInitialState() $this->assertSame($this->travelMode, $this->directionsStep->getTravelMode()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The step instructions must be a string value. - */ - public function testInstructionsWithInvalidValue() + public function testSetDistance() { - $this->directionsStep->setInstructions(true); + $this->directionsStep->setDistance($distance = $this->createDistanceMock()); + + $this->assertSame($distance, $this->directionsStep->getDistance()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions step travel mode can only be : BICYCLING, DRIVING, WALKING, TRANSIT. - */ - public function testTravelModeWithInvalidValue() + public function testSetDuration() { - $this->directionsStep->setTravelMode('foo'); + $this->directionsStep->setDuration($duration = $this->createDurationMock()); + + $this->assertSame($duration, $this->directionsStep->getDuration()); + } + + public function testSetEndLocation() + { + $this->directionsStep->setEndLocation($endLocation = $this->createCoordinateMock()); + + $this->assertSame($endLocation, $this->directionsStep->getEndLocation()); + } + + public function setSetInstructions() + { + $this->directionsStep->setInstructions($instructions = 'foo'); + + $this->assertSame($instructions, $this->directionsStep->getInstructions()); + } + + public function testSetEncodedPolyline() + { + $this->directionsStep->setEncodedPolyline($encodedPolyline = $this->createEncodedPolylineMock()); + + $this->assertSame($encodedPolyline, $this->directionsStep->getEncodedPolyline()); + } + + public function testSetStartLocation() + { + $this->directionsStep->setStartLocation($startLocation = $this->createCoordinateMock()); + + $this->assertSame($startLocation, $this->directionsStep->getStartLocation()); + } + + public function testSetTravelMode() + { + $this->directionsStep->setTravelMode($travelMode = TravelMode::BICYCLING); + + $this->assertSame($travelMode, $this->directionsStep->getTravelMode()); } } diff --git a/tests/Services/Directions/DirectionsTest.php b/tests/Services/Directions/DirectionsTest.php index 5f39510c..5d407c62 100644 --- a/tests/Services/Directions/DirectionsTest.php +++ b/tests/Services/Directions/DirectionsTest.php @@ -11,21 +11,20 @@ namespace Ivory\Tests\GoogleMap\Services\Directions; -use \DateTime; use Ivory\GoogleMap\Services\Directions\Directions; use Ivory\GoogleMap\Services\Directions\DirectionsRequest; use Ivory\GoogleMap\Services\Directions\DirectionsStatus; use Ivory\GoogleMap\Services\Directions\DirectionsWaypoint; use Ivory\GoogleMap\Services\Base\TravelMode; use Ivory\GoogleMap\Services\Base\UnitSystem; -use Widop\HttpAdapter\CurlHttpAdapter; +use Ivory\HttpAdapter\SocketHttpAdapter; /** * Directions test. * * @author GeLo */ -class DirectionsServiceTest extends \PHPUnit_Framework_TestCase +class DirectionsTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\Directions */ protected $directions; @@ -37,7 +36,7 @@ protected function setUp() { sleep(5); - $this->directions = new Directions(new CurlHttpAdapter()); + $this->directions = new Directions(new SocketHttpAdapter()); } /** @@ -48,238 +47,102 @@ protected function tearDown() unset($this->directions); } - public function testRouteWithOriginAndDestination() + public function testInheritance() { - $response = $this->directions->route('Lille', 'Paris'); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequest() - { - $request = new DirectionsRequest(); - $request->setOrigin(50.629381, 3.057268); - $request->setDestination(48.856633, 2.352254); - $request->setTravelMode(TravelMode::DRIVING); - $request->setProvideRouteAlternatives(true); - $request->setUnitSystem(UnitSystem::METRIC); - $request->setRegion('fr'); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndStringWaypointAndOptimizeWaypoint() - { - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->addWaypoint('Compiègne'); - $request->setDestination('Paris'); - - $request->setOptimizeWaypoints(true); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndCoordinateWaypoint() - { - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->addWaypoint(49.418079, 2.826190); - $request->setDestination('Paris'); - - $request->setOptimizeWaypoints(true); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndStopoverWaypoint() - { - $waypoint = new DirectionsWaypoint(); - $waypoint->setLocation('Compiègne'); - $waypoint->setStopover(true); - - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->addWaypoint($waypoint); - $request->setDestination('Paris'); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndAvoidTolls() - { - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->setDestination('Paris'); - $request->setAvoidTolls(true); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndAvoidHighways() - { - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->setDestination('Paris'); - $request->setAvoidHighways(true); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); + $this->assertServiceInstance($this->directions); } - public function testRouteWithDirectionsRequestAndLanguage() - { - $request = new DirectionsRequest(); - $request->setOrigin('Lille'); - $request->setDestination('Paris'); - $request->setLanguage('fr'); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndTransitModeAndDepartureTime() - { - $request = new DirectionsRequest(); - $request->setOrigin('601-625 Ashbury Street, San Francisco'); - $request->setDestination('Bike Route 95, San Francisco'); - - $request->setTravelMode(TravelMode::TRANSIT); - $request->setDepartureTime(new DateTime()); - - $response = $this->directions->route($request); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testRouteWithDirectionsRequestAndTransitModeAndArrivalTime() + /** + * @dataProvider requestProvider + */ + public function testRouteWithJsonFormat(DirectionsRequest $request) { - $request = new DirectionsRequest(); - $request->setOrigin('601-625 Ashbury Street, San Francisco'); - $request->setDestination('Bike Route 95, San Francisco'); - - $request->setTravelMode(TravelMode::TRANSIT); - $request->setArrivalTime(new DateTime('+2 hours')); - $response = $this->directions->route($request); $this->assertSame(DirectionsStatus::OK, $response->getStatus()); $this->assertNotEmpty($response->getRoutes()); } - public function testRouteWithDirectionsRequestAndTransitModeAndDepartureTimeAndArrivalTime() + /** + * @dataProvider requestProvider + */ + public function testRouteWithXmlFormat(DirectionsRequest $request) { - $request = new DirectionsRequest(); - $request->setOrigin('601-625 Ashbury Street, San Francisco'); - $request->setDestination('Bike Route 95, San Francisco'); - - $request->setTravelMode(TravelMode::TRANSIT); - $request->setArrivalTime(new DateTime()); - $request->setArrivalTime(new DateTime('+2 hours')); - + $this->directions->setFormat(Directions::FORMAT_XML); $response = $this->directions->route($request); $this->assertSame(DirectionsStatus::OK, $response->getStatus()); $this->assertNotEmpty($response->getRoutes()); } - public function testRouteWithXmlFormat() - { - $this->directions->setFormat('xml'); - $response = $this->directions->route('Lille', 'Paris'); - - $this->assertSame(DirectionsStatus::OK, $response->getStatus()); - $this->assertNotEmpty($response->getRoutes()); - } - - public function testSignUrlWithoutBusinessAccount() - { - $method = new \ReflectionMethod($this->directions, 'signUrl'); - $method->setAccessible(true); - - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $this->assertSame($url, $method->invoke($this->directions, $url)); - } - - public function testSignUrlWithBusinessAccount() - { - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $businessAccount - ->expects($this->once()) - ->method('signUrl') - ->with($this->equalTo($url)) - ->will($this->returnValue('url')); - - $this->directions->setBusinessAccount($businessAccount); - - $method = new \ReflectionMethod($this->directions, 'signUrl'); - $method->setAccessible(true); - - $this->assertSame('url', $method->invoke($this->directions, $url)); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The route arguments are invalid. - * The available prototypes are: - * - function route(string $origin, string $destination) - * - function route(Ivory\GoogleMap\Services\Directions\DirectionsRequest $request) - */ - public function testRouteWithInvalidRequestParameters() - { - $this->directions->route(true); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions request is not valid. It needs at least an origin and a destination. - * If you add waypoint to the directions request, it needs at least a location. - */ public function testRouteWithInvalidRequest() { - $this->directions->route(new DirectionsRequest()); + $response = $this->directions->route(new DirectionsRequest(null, null)); + + $this->assertSame(DirectionsStatus::INVALID_REQUEST, $response->getStatus()); + $this->assertEmpty($response->getRoutes()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The service result is not valid. + * Gets the request provider. + * + * @return array The request provider. */ - public function testRouteWithInvalidResult() - { - $httpAdapterMock = $this->getMock('Widop\HttpAdapter\HttpAdapterInterface'); - $httpAdapterMock - ->expects($this->once()) - ->method('getContent') - ->will($this->returnValue(null)); - - $this->directions = new Directions($httpAdapterMock); - $this->directions->route('Lille', 'Paris'); + public function requestProvider() + { + $fullRequest = new DirectionsRequest('50.629381, 3.057268', '48.856633, 2.352254'); + $fullRequest->setTravelMode(TravelMode::DRIVING); + $fullRequest->setProvideRouteAlternatives(true); + $fullRequest->setUnitSystem(UnitSystem::METRIC); + $fullRequest->setRegion('fr'); + + $stringWaypointRequest = new DirectionsRequest('Lille', 'Paris'); + $stringWaypointRequest->addWaypoint(new DirectionsWaypoint('Compiègne')); + + $coordinateWaypointRequest = new DirectionsRequest('Lille', 'Paris'); + $coordinateWaypointRequest->addWaypoint(new DirectionsWaypoint('49.418079, 2.826190')); + + $optimizeWaypointRequest = new DirectionsRequest('Lille', 'Paris'); + $optimizeWaypointRequest->addWaypoint(new DirectionsWaypoint('Compiègne')); + $optimizeWaypointRequest->setOptimizeWaypoints(true); + + $stopoverWaypointRequest = new DirectionsRequest('Lille', 'Paris'); + $stopoverWaypointRequest->addWaypoint(new DirectionsWaypoint('Compiègne', true)); + + $avoidTollsRequest = new DirectionsRequest('Lille', 'Paris'); + $avoidTollsRequest->setAvoidTolls(true); + + $avoidHighwaysRequest = new DirectionsRequest('Lille', 'Paris'); + $avoidHighwaysRequest->setAvoidHighways(true); + + $languageRequest = new DirectionsRequest('Lille', 'Paris'); + $languageRequest->setLanguage('fr'); + + $transitDepartureRequest = new DirectionsRequest('601-625 Ashbury Street, San Francisco', 'Bike Route 95, San Francisco'); + $transitDepartureRequest->setTravelMode(TravelMode::TRANSIT); + $transitDepartureRequest->setDepartureTime(new \DateTime()); + + $transitArrivalRequest = new DirectionsRequest('601-625 Ashbury Street, San Francisco', 'Bike Route 95, San Francisco'); + $transitArrivalRequest->setTravelMode(TravelMode::TRANSIT); + $transitArrivalRequest->setArrivalTime(new \DateTime('+2 hours')); + + $transitDepartureArrivalRequest = new DirectionsRequest('601-625 Ashbury Street, San Francisco', 'Bike Route 95, San Francisco'); + $transitDepartureArrivalRequest->setTravelMode(TravelMode::TRANSIT); + $transitDepartureArrivalRequest->setArrivalTime(new \DateTime()); + $transitDepartureArrivalRequest->setArrivalTime(new \DateTime('+2 hours')); + + return array( + array($fullRequest), + array($stringWaypointRequest), + array($coordinateWaypointRequest), + array($optimizeWaypointRequest), + array($stopoverWaypointRequest), + array($avoidTollsRequest), + array($avoidHighwaysRequest), + array($languageRequest), + array($transitDepartureRequest), + array($transitArrivalRequest), + array($transitDepartureArrivalRequest), + ); } } diff --git a/tests/Services/Directions/DirectionsWaypointTest.php b/tests/Services/Directions/DirectionsWaypointTest.php index 68770823..7b254afd 100644 --- a/tests/Services/Directions/DirectionsWaypointTest.php +++ b/tests/Services/Directions/DirectionsWaypointTest.php @@ -18,17 +18,20 @@ * * @author GeLo */ -class DirectionsWaypointTest extends \PHPUnit_Framework_TestCase +class DirectionsWaypointTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Directions\DirectionsWaypoint */ protected $directionsWaypoint; + /** @var string */ + protected $location; + /** * {@inheritdoc} */ protected function setUp() { - $this->directionsWaypoint = new DirectionsWaypoint(); + $this->directionsWaypoint = new DirectionsWaypoint($this->location = 'foo'); } /** @@ -36,54 +39,39 @@ protected function setUp() */ protected function tearDown() { + unset($this->location); unset($this->directionsWaypoint); } public function testDefaultState() { - $this->assertFalse($this->directionsWaypoint->hasLocation()); - $this->assertFalse($this->directionsWaypoint->hasStopover()); - } - - public function testLocationWithString() - { - $this->directionsWaypoint->setLocation('address'); $this->assertTrue($this->directionsWaypoint->hasLocation()); - $this->assertEquals($this->directionsWaypoint->getLocation(), 'address'); - } + $this->assertSame($this->location, $this->directionsWaypoint->getLocation()); - public function testLocationWithCoordinate() - { - $location = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->directionsWaypoint->setLocation($location); - - $this->assertSame($location, $this->directionsWaypoint->getLocation()); + $this->assertFalse($this->directionsWaypoint->hasStopover()); + $this->assertNull($this->directionsWaypoint->getStopover()); } - public function testLocationWithLatitudeAndLongitude() + public function testInitialState() { - $this->directionsWaypoint->setLocation(1.1, 2.1, false); + $this->directionsWaypoint = new DirectionsWaypoint($this->location, $stopover = false); - $this->assertSame(1.1, $this->directionsWaypoint->getLocation()->getLatitude()); - $this->assertSame(2.1, $this->directionsWaypoint->getLocation()->getLongitude()); - $this->assertFalse($this->directionsWaypoint->getLocation()->isNoWrap()); + $this->assertTrue($this->directionsWaypoint->hasStopover()); + $this->assertFalse($this->directionsWaypoint->getStopover()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The location setter arguments are invalid. - * The available prototypes are : - * - function setLocation(string $destination) - * - function setLocation(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setLocation(double $latitude, double $longitude, boolean $noWrap) + * @dataProvider locationProvider */ - public function testLocationWithInvalidValue() + public function testSetLocation($location) { - $this->directionsWaypoint->setLocation(true); + $this->directionsWaypoint->setLocation($location); + + $this->assertTrue($this->directionsWaypoint->hasLocation()); + $this->assertSame($location, $this->directionsWaypoint->getLocation()); } - public function testStopoverWithValieValue() + public function testSetStopover() { $this->directionsWaypoint->setStopover(true); @@ -91,32 +79,24 @@ public function testStopoverWithValieValue() $this->assertTrue($this->directionsWaypoint->getStopover()); } - public function testStopoverWithNullValue() + public function testResetStopover() { - $this->directionsWaypoint->setStopover(true); $this->directionsWaypoint->setStopover(null); $this->assertFalse($this->directionsWaypoint->hasStopover()); + $this->assertNull($this->directionsWaypoint->getStopover()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DirectionsException - * @expectedExceptionMessage The directions waypoint stopover flag must be a boolean value. + * Gets the location provider. + * + * @return array The location provider. */ - public function testStopoverWithInvalidValue() - { - $this->directionsWaypoint->setStopover('foo'); - } - - public function testIsValidWithoutLocation() - { - $this->assertFalse($this->directionsWaypoint->isValid()); - } - - public function testIsValidWithLocation() + public function locationProvider() { - $this->directionsWaypoint->setLocation('foo'); - - $this->assertTrue($this->directionsWaypoint->isValid()); + return array( + array('location'), + array($this->createCoordinateMock()), + ); } } diff --git a/tests/Services/DistanceMatrix/AbstractTestCase.php b/tests/Services/DistanceMatrix/AbstractTestCase.php new file mode 100644 index 00000000..ad5386d7 --- /dev/null +++ b/tests/Services/DistanceMatrix/AbstractTestCase.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\DistanceMatrix; + +use Ivory\Tests\GoogleMap\Services\AbstractTestCase as TestCase; + +/** + * Distance matrix test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a distance matrix response element intance. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The distance matrix response element. + */ + protected function assertDistanceMatrixResponseElementInstance($element) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement', $element); + } + + /** + * Asserts a distance matrix response row intance. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The distance matrix response row. + */ + protected function assertDistanceMatrixResponseRowInstance($row) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow', $row); + } + + /** + * Creates a distance matrix response element mock. + * + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement|\PHPUnit_Framework_MockObject_MockObject The distance matrix response element mock. + */ + protected function createDistanceMatrixResponseElementMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a distance matrix response row mock. + * + * @return \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow|\PHPUnit_Framework_MockObject_MockObject The distance matrix response row mock. + */ + protected function createDistanceMatrixResponseRowMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow') + ->disableOriginalConstructor() + ->getMock(); + } +} diff --git a/tests/Services/DistanceMatrix/DistanceMatrixElementStatusTest.php b/tests/Services/DistanceMatrix/DistanceMatrixElementStatusTest.php index d6386a97..37011390 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixElementStatusTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixElementStatusTest.php @@ -18,16 +18,17 @@ * * @author GeLo */ -class DirectionsMatrixElementStatusTest extends \PHPUnit_Framework_TestCase +class DirectionsMatrixElementStatusTest extends AbstractTestCase { - public function testDistanceMatrixElementStatus() + public function testInheritance() { - $expected = array( - DistanceMatrixElementStatus::NOT_FOUND, - DistanceMatrixElementStatus::OK, - DistanceMatrixElementStatus::ZERO_RESULTS, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixElementStatus'); + } - $this->assertSame($expected, DistanceMatrixElementStatus::getDistanceMatrixElementStatus()); + public function testConstants() + { + $this->assertSame('NOT_FOUND', DistanceMatrixElementStatus::NOT_FOUND); + $this->assertSame('OK', DistanceMatrixElementStatus::OK); + $this->assertSame('ZERO_RESULTS', DistanceMatrixElementStatus::ZERO_RESULTS); } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixRequestTest.php b/tests/Services/DistanceMatrix/DistanceMatrixRequestTest.php index df22eb57..59c49df6 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixRequestTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixRequestTest.php @@ -16,22 +16,30 @@ use Ivory\GoogleMap\Services\Base\UnitSystem; /** - * DistanceMatrix request test. + * Distance matrix request test. * * @author GeLo - * @author Tyler Sommer */ -class DistanceMatrixRequestTest extends \PHPUnit_Framework_TestCase +class DistanceMatrixRequestTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest */ protected $distanceMatrixRequest; + /** @var array */ + protected $origins; + + /** @var array */ + protected $destinations; + /** * {@inheritdoc} */ protected function setUp() { - $this->distanceMatrixRequest = new DistanceMatrixRequest(); + $this->distanceMatrixRequest = new DistanceMatrixRequest( + $this->origins = array('origin'), + $this->destinations = array('destination') + ); } /** @@ -39,15 +47,21 @@ protected function setUp() */ protected function tearDown() { + unset($this->destinations); + unset($this->origins); unset($this->distanceMatrixRequest); } public function testDefaultState() { + $this->assertTrue($this->distanceMatrixRequest->hasOrigins()); + $this->assertSame($this->origins, $this->distanceMatrixRequest->getOrigins()); + + $this->assertTrue($this->distanceMatrixRequest->hasDestinations()); + $this->assertSame($this->destinations, $this->distanceMatrixRequest->getDestinations()); + $this->assertFalse($this->distanceMatrixRequest->hasAvoidHighways()); $this->assertFalse($this->distanceMatrixRequest->hasAvoidTolls()); - $this->assertFalse($this->distanceMatrixRequest->hasDestinations()); - $this->assertFalse($this->distanceMatrixRequest->hasOrigins()); $this->assertFalse($this->distanceMatrixRequest->hasRegion()); $this->assertFalse($this->distanceMatrixRequest->hasLanguage()); $this->assertFalse($this->distanceMatrixRequest->hasTravelMode()); @@ -55,7 +69,7 @@ public function testDefaultState() $this->assertFalse($this->distanceMatrixRequest->hasSensor()); } - public function testAvoidHightwaysWithValidValue() + public function testSetAvoidHightways() { $this->distanceMatrixRequest->setAvoidHighways(true); @@ -63,24 +77,16 @@ public function testAvoidHightwaysWithValidValue() $this->assertTrue($this->distanceMatrixRequest->getAvoidHighways()); } - public function testAvoidHighwaysWithNullValue() + public function testResetAvoidHighways() { $this->distanceMatrixRequest->setAvoidHighways(true); $this->distanceMatrixRequest->setAvoidHighways(null); + $this->assertFalse($this->distanceMatrixRequest->hasAvoidHighways()); $this->assertNull($this->distanceMatrixRequest->getAvoidHighways()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request avoid hightways flag must be a boolean value. - */ - public function testAvoidHighwaysWithInvalidValue() - { - $this->distanceMatrixRequest->setAvoidHighways('foo'); - } - - public function testAvoidTollsWithValidValue() + public function testSetAvoidTolls() { $this->distanceMatrixRequest->setAvoidTolls(true); @@ -88,264 +94,360 @@ public function testAvoidTollsWithValidValue() $this->assertTrue($this->distanceMatrixRequest->getAvoidTolls()); } - public function testAvoidTollsWithNullValue() + public function testResetAvoidTolls() { $this->distanceMatrixRequest->setAvoidTolls(true); $this->distanceMatrixRequest->setAvoidTolls(null); + $this->assertFalse($this->distanceMatrixRequest->hasAvoidTolls()); $this->assertNull($this->distanceMatrixRequest->getAvoidTolls()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request avoid tolls flag must be a boolean value. + * @dataProvider locationProvider */ - public function testAvoidTollsWithInvalidValue() + public function testSetDestinations($destination) { - $this->distanceMatrixRequest->setAvoidTolls('foo'); + $this->distanceMatrixRequest->setDestinations($destinations = array($destination)); + + $this->assertDestinations($destinations); } - public function testDestinationWithString() + /** + * @dataProvider locationProvider + */ + public function testAddDestinations($destination) { - $this->distanceMatrixRequest->setDestinations(array('foo')); + $this->distanceMatrixRequest->setDestinations($destinations = array($destination)); + $this->distanceMatrixRequest->addDestinations($newDestinations = array('bar')); - $this->assertTrue($this->distanceMatrixRequest->hasDestinations()); - $this->assertEquals($this->distanceMatrixRequest->getDestinations(), array('foo')); + $this->assertDestinations(array_merge($destinations, $newDestinations)); } - public function testDestinationWithCoordinate() + /** + * @dataProvider locationProvider + */ + public function testRemoveDestinations($destination) { - $location = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); + $this->distanceMatrixRequest->setDestinations($destinations = array($destination)); + $this->distanceMatrixRequest->removeDestinations($destinations); - $this->distanceMatrixRequest->setDestinations(array($location)); + $this->assertNoDestinations(); + } - $destinations = $this->distanceMatrixRequest->getDestinations(); + /** + * @dataProvider locationProvider + */ + public function testResetDestinations($destination) + { + $this->distanceMatrixRequest->setDestinations(array($destination)); + $this->distanceMatrixRequest->resetDestinations(); - $this->assertArrayHasKey(0, $destinations); - $this->assertCount(1, $destinations); - $this->assertSame($location, $destinations[0]); + $this->assertNoDestinations(); } - public function testDestinationWithLatitudeAndLongitude() + /** + * @dataProvider locationProvider + */ + public function testAddDestination($destination) { - $this->distanceMatrixRequest->addDestination(1.1, 2.1, false); + $this->distanceMatrixRequest->addDestination($destination); - $destinations = $this->distanceMatrixRequest->getDestinations(); + $this->assertDestination($destination); + } - $this->assertArrayHasKey(0, $destinations); - $this->assertCount(1, $destinations); - $this->assertSame(1.1, $destinations[0]->getLatitude()); - $this->assertSame(2.1, $destinations[0]->getLongitude()); - $this->assertFalse($destinations[0]->isNoWrap()); + /** + * @dataProvider locationProvider + */ + public function testAddDestinationUnicity($destination) + { + $this->distanceMatrixRequest->resetDestinations(); + $this->distanceMatrixRequest->addDestination($destination); + $this->distanceMatrixRequest->addDestination($destination); + + $this->assertDestinations(array($destination)); } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The destination adder arguments are invalid. - * The available prototypes are : - * - function setDestination(string $destination) - * - function setDestination(Ivory\GoogleMap\Base\Coordinate $destination) - * - function setDestination(double $latitude, double $longitude, boolean $noWrap) + * @dataProvider locationProvider */ - public function testDestinationWithInvalidValue() + public function testRemoveDestination($destination) { - $this->distanceMatrixRequest->addDestination(true); + $this->distanceMatrixRequest->addDestination($destination); + $this->distanceMatrixRequest->removeDestination($destination); + + $this->assertNoDestination($destination); } - public function testOriginWithString() + /** + * @dataProvider locationProvider + */ + public function testSetOrigins($destination) { - $this->distanceMatrixRequest->setOrigins(array('foo')); + $this->distanceMatrixRequest->setOrigins($origins = array($destination)); - $this->assertTrue($this->distanceMatrixRequest->hasOrigins()); - $this->assertSame(array('foo'), $this->distanceMatrixRequest->getOrigins()); + $this->assertOrigins($origins); } - public function testOriginWithCoordinate() + /** + * @dataProvider locationProvider + */ + public function testAddOrigins($destination) { - $origin = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->distanceMatrixRequest->setOrigins(array($origin)); + $this->distanceMatrixRequest->setOrigins($origins = array($destination)); + $this->distanceMatrixRequest->addOrigins($newOrigins = array('bar')); + + $this->assertOrigins(array_merge($origins, $newOrigins)); + } + + /** + * @dataProvider locationProvider + */ + public function testRemoveOrigins($destination) + { + $this->distanceMatrixRequest->setOrigins($origins = array($destination)); + $this->distanceMatrixRequest->removeOrigins($origins); + + $this->assertNoOrigins(); + } - $origins = $this->distanceMatrixRequest->getOrigins(); + /** + * @dataProvider locationProvider + */ + public function testResetOrigins($origin) + { + $this->distanceMatrixRequest->setOrigins(array($origin)); + $this->distanceMatrixRequest->resetOrigins(); - $this->assertArrayHasKey(0, $origins); - $this->assertSame($origin, $origins[0]); + $this->assertNoOrigins(); } - public function testOriginWithLatitudeAndLongitude() + /** + * @dataProvider locationProvider + */ + public function testAddOrigin($origin) { - $this->distanceMatrixRequest->addOrigin(1.1, 2.1, false); + $this->distanceMatrixRequest->addOrigin($origin); - $origins = $this->distanceMatrixRequest->getOrigins(); + $this->assertOrigin($origin); + } - $this->assertArrayHasKey(0, $origins); - $this->assertCount(1, $origins); - $this->assertSame(1.1, $origins[0]->getLatitude()); - $this->assertSame(2.1, $origins[0]->getLongitude()); - $this->assertFalse($origins[0]->isNoWrap()); + /** + * @dataProvider locationProvider + */ + public function testAddOriginUnicity($origin) + { + $this->distanceMatrixRequest->resetOrigins(); + $this->distanceMatrixRequest->addOrigin($origin); + $this->distanceMatrixRequest->addOrigin($origin); + + $this->assertOrigins(array($origin)); } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The origin adder arguments are invalid. - * The available prototypes are : - * - function setOrigin(string $origin) - * - function setOrigin(Ivory\GoogleMap\Base\Coordinate $origin) - * - function setOrigin(double $latitude, double $longitude, boolean $noWrap) + * @dataProvider locationProvider */ - public function testOriginWithInvalidValue() + public function testRemoveOrigin($origin) { - $this->distanceMatrixRequest->addOrigin(true); + $this->distanceMatrixRequest->addOrigin($origin); + $this->distanceMatrixRequest->removeOrigin($origin); + + $this->assertNoOrigin($origin); } - public function testRegionWithValidValue() + public function testSetRegion() { - $this->distanceMatrixRequest->setRegion('fr'); + $this->distanceMatrixRequest->setRegion($region = 'fr'); $this->assertTrue($this->distanceMatrixRequest->hasRegion()); - $this->assertSame('fr', $this->distanceMatrixRequest->getRegion()); + $this->assertSame($region, $this->distanceMatrixRequest->getRegion()); } - public function testRegionWithNullValue() + public function testResetRegion() { $this->distanceMatrixRequest->setRegion('fr'); $this->distanceMatrixRequest->setRegion(null); + $this->assertFalse($this->distanceMatrixRequest->hasRegion()); $this->assertNull($this->distanceMatrixRequest->getRegion()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request region must be a string with two characters. - */ - public function testRegionWithInvalidValue() - { - $this->distanceMatrixRequest->setRegion('foo'); - } - - public function testLanguageWithValidValue() + public function testSetLanguage() { - $this->distanceMatrixRequest->setLanguage('fr'); + $this->distanceMatrixRequest->setLanguage($language = 'fr'); $this->assertTrue($this->distanceMatrixRequest->hasLanguage()); - $this->assertSame('fr', $this->distanceMatrixRequest->getLanguage()); + $this->assertSame($language, $this->distanceMatrixRequest->getLanguage()); } - public function testLanguageWithNullValue() + public function testResetLanguage() { $this->distanceMatrixRequest->setLanguage('fr'); $this->distanceMatrixRequest->setLanguage(null); + $this->assertFalse($this->distanceMatrixRequest->hasLanguage()); $this->assertNull($this->distanceMatrixRequest->getLanguage()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request language must be a string with two or five characters. - */ - public function testLanguageWithInvalidValue() + public function testSetTravelMode() { - $this->distanceMatrixRequest->setLanguage('foo'); - } - - public function testTravelModeWithValidValue() - { - $this->distanceMatrixRequest->setTravelMode(TravelMode::WALKING); + $this->distanceMatrixRequest->setTravelMode($travelMode = TravelMode::WALKING); $this->assertTrue($this->distanceMatrixRequest->hasTravelMode()); - $this->assertSame(TravelMode::WALKING, $this->distanceMatrixRequest->getTravelMode()); + $this->assertSame($travelMode, $this->distanceMatrixRequest->getTravelMode()); } - public function testTravelModeWithNullValue() + public function testResetTravelMode() { $this->distanceMatrixRequest->setTravelMode(TravelMode::WALKING); $this->distanceMatrixRequest->setTravelMode(null); + $this->assertFalse($this->distanceMatrixRequest->hasTravelMode()); $this->assertNull($this->distanceMatrixRequest->getTravelMode()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request travel mode can only be : BICYCLING, DRIVING, WALKING. - */ - public function testTravelModeWithTransitValue() + public function testSetUnitSystem() { - $this->distanceMatrixRequest->setTravelMode(TravelMode::TRANSIT); - } + $this->distanceMatrixRequest->setUnitSystem($unitSystem = UnitSystem::IMPERIAL); - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request travel mode can only be : BICYCLING, DRIVING, WALKING. - */ - public function testTravelModeWithInvalidValue() - { - $this->distanceMatrixRequest->setTravelMode('foo'); + $this->assertTrue($this->distanceMatrixRequest->hasUnitSystem()); + $this->assertSame($unitSystem, $this->distanceMatrixRequest->getUnitSystem()); } - public function testUnitSystemWithValidValue() + public function testResetUnitSystem() { $this->distanceMatrixRequest->setUnitSystem(UnitSystem::IMPERIAL); + $this->distanceMatrixRequest->setUnitSystem(null); - $this->assertTrue($this->distanceMatrixRequest->hasUnitSystem()); - $this->assertSame(UnitSystem::IMPERIAL, $this->distanceMatrixRequest->getUnitSystem()); + $this->assertFalse($this->distanceMatrixRequest->hasUnitSystem()); + $this->assertNull($this->distanceMatrixRequest->getUnitSystem()); } - public function testUnitSystemWithNullValue() + public function testSetSensor() { - $this->distanceMatrixRequest->setUnitSystem(UnitSystem::IMPERIAL); - $this->distanceMatrixRequest->setUnitSystem(null); + $this->distanceMatrixRequest->setSensor(true); - $this->assertNull($this->distanceMatrixRequest->getUnitSystem()); + $this->assertTrue($this->distanceMatrixRequest->hasSensor()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request unit system can only be : IMPERIAL, METRIC. + * Gets the location provider. + * + * @return array The location provider. */ - public function testUnitSystemWithInvalidValue() + public function locationProvider() { - $this->distanceMatrixRequest->setUnitSystem('foo'); + return array( + array('foo'), + array($this->createCoordinateMock()), + ); } - public function testSensorWithValidValue() + /** + * Asserts there are destinations. + * + * @param array $destinations The destinations. + */ + protected function assertDestinations($destinations) { - $this->distanceMatrixRequest->setSensor(true); + $this->assertInternalType('array', $destinations); - $this->assertTrue($this->distanceMatrixRequest->hasSensor()); + $this->assertTrue($this->distanceMatrixRequest->hasDestinations()); + $this->assertSame($destinations, $this->distanceMatrixRequest->getDestinations()); + + foreach ($destinations as $destination) { + $this->assertDestination($destination); + } } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix request sensor flag must be a boolean value. + * Asserts there is a destination. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. */ - public function testSensorWithInvalidValue() + protected function assertDestination($destination) { - $this->distanceMatrixRequest->setSensor('foo'); + if (!is_string($destination)) { + $this->assertCoordinateInstance($destination); + } + + $this->assertTrue($this->distanceMatrixRequest->hasDestination($destination)); } - public function testIsValid() + /** + * Asserts there are no destinations. + */ + protected function assertNoDestinations() + { + $this->assertFalse($this->distanceMatrixRequest->hasDestinations()); + $this->assertEmpty($this->distanceMatrixRequest->getDestinations()); + } + + /** + * Asserts there is no destination. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $destination The destination. + */ + protected function assertNoDestination($destination) { - $this->assertFalse($this->distanceMatrixRequest->isValid()); + if (!is_string($destination)) { + $this->assertCoordinateInstance($destination); + } + + $this->assertFalse($this->distanceMatrixRequest->hasDestination($destination)); } - public function testIsValidWithOrigin() + /** + * Asserts there are origins. + * + * @param array $origins The origins. + */ + protected function assertOrigins($origins) { - $this->distanceMatrixRequest->addOrigin('foo'); + $this->assertInternalType('array', $origins); + + $this->assertTrue($this->distanceMatrixRequest->hasOrigins()); + $this->assertSame($origins, $this->distanceMatrixRequest->getOrigins()); - $this->assertFalse($this->distanceMatrixRequest->isValid()); + foreach ($origins as $origin) { + $this->assertOrigin($origin); + } } - public function testIsValidWithDestination() + /** + * Asserts there is a origin. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + */ + protected function assertOrigin($origin) { - $this->distanceMatrixRequest->addDestination('foo'); + if (!is_string($origin)) { + $this->assertCoordinateInstance($origin); + } - $this->assertFalse($this->distanceMatrixRequest->isValid()); + $this->assertTrue($this->distanceMatrixRequest->hasOrigin($origin)); } - public function testIsValidWithOriginAndDestination() + /** + * Asserts there are no origins. + */ + protected function assertNoOrigins() + { + $this->assertFalse($this->distanceMatrixRequest->hasOrigins()); + $this->assertEmpty($this->distanceMatrixRequest->getOrigins()); + } + + /** + * Asserts there is no origin. + * + * @param string|\Ivory\GoogleMap\Base\Coordinate $origin The origin. + */ + protected function assertNoOrigin($origin) { - $this->distanceMatrixRequest->addDestination('foo'); - $this->distanceMatrixRequest->addOrigin('bar'); + if (!is_string($origin)) { + $this->assertCoordinateInstance($origin); + } - $this->assertTrue($this->distanceMatrixRequest->isValid()); + $this->assertFalse($this->distanceMatrixRequest->hasOrigin($origin)); } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixResponseElementTest.php b/tests/Services/DistanceMatrix/DistanceMatrixResponseElementTest.php index e140a5c1..ada34e5e 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixResponseElementTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixResponseElementTest.php @@ -19,18 +19,18 @@ * * @author GeLo */ -class DirectionsResponseElementTest extends \PHPUnit_Framework_TestCase +class DirectionsResponseElementTest extends AbstractTestCase { - /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse */ + /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement */ protected $distanceMatrixResponseElement; /** @var string */ protected $status; - /** @var \Ivory\GoogleMap\Services\Base\Distance */ + /** @var \Ivory\GoogleMap\Services\Base\Distance|\PHPUnit_Framework_MockObject_MockObject */ protected $distance; - /** @var \Ivory\GoogleMap\Services\Base\Duration */ + /** @var \Ivory\GoogleMap\Services\Base\Duration|\PHPUnit_Framework_MockObject_MockObject */ protected $duration; /** @@ -38,20 +38,10 @@ class DirectionsResponseElementTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->status = DistanceMatrixElementStatus::ZERO_RESULTS; - - $this->distance = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Distance') - ->disableOriginalConstructor() - ->getMock(); - - $this->duration = $this->getMockBuilder('Ivory\GoogleMap\Services\Base\Duration') - ->disableOriginalConstructor() - ->getMock(); - $this->distanceMatrixResponseElement = new DistanceMatrixResponseElement( - $this->status, - $this->distance, - $this->duration + $this->status = DistanceMatrixElementStatus::ZERO_RESULTS, + $this->distance = $this->createDistanceMock(), + $this->duration = $this->createDurationMock() ); } @@ -69,16 +59,50 @@ protected function tearDown() public function testDefaultState() { $this->assertSame($this->status, $this->distanceMatrixResponseElement->getStatus()); + + $this->assertTrue($this->distanceMatrixResponseElement->hasDistance()); $this->assertSame($this->distance, $this->distanceMatrixResponseElement->getDistance()); + + $this->assertTrue($this->distanceMatrixResponseElement->hasDuration()); $this->assertSame($this->duration, $this->distanceMatrixResponseElement->getDuration()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix response element status can only be : NOT_FOUND, OK, ZERO_RESULTS. - */ - public function testStatusWithInvalidValue() + public function testSetStatus() + { + $this->distanceMatrixResponseElement->setStatus($status = DistanceMatrixElementStatus::OK); + + $this->assertSame($status, $this->distanceMatrixResponseElement->getStatus()); + } + + public function testSetDistance() + { + $this->distanceMatrixResponseElement->setDistance($distance = $this->createDistanceMock()); + + $this->assertTrue($this->distanceMatrixResponseElement->hasDistance()); + $this->assertSame($distance, $this->distanceMatrixResponseElement->getDistance()); + } + + public function testResetDistance() + { + $this->distanceMatrixResponseElement->setDistance(null); + + $this->assertFalse($this->distanceMatrixResponseElement->hasDistance()); + $this->assertNull($this->distanceMatrixResponseElement->getDistance()); + } + + public function testSetDuration() + { + $this->distanceMatrixResponseElement->setDuration($duration = $this->createDurationMock()); + + $this->assertTrue($this->distanceMatrixResponseElement->hasDuration()); + $this->assertSame($duration, $this->distanceMatrixResponseElement->getDuration()); + } + + public function testResetDuration() { - $this->distanceMatrixResponseElement->setStatus('foo'); + $this->distanceMatrixResponseElement->setDuration(null); + + $this->assertFalse($this->distanceMatrixResponseElement->hasDuration()); + $this->assertNull($this->distanceMatrixResponseElement->getDuration()); } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixResponseRowTest.php b/tests/Services/DistanceMatrix/DistanceMatrixResponseRowTest.php index 68e3f668..326783ac 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixResponseRowTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixResponseRowTest.php @@ -18,7 +18,7 @@ * * @author GeLo */ -class DirectionsResponseRowTest extends \PHPUnit_Framework_TestCase +class DirectionsResponseRowTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse */ protected $distanceMatrixResponseRow; @@ -31,13 +31,9 @@ class DirectionsResponseRowTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $element = $this->getMockBuilder('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement') - ->disableOriginalConstructor() - ->getMock(); - - $this->elements = array($element); - - $this->distanceMatrixResponseRow = new DistanceMatrixResponseRow($this->elements); + $this->distanceMatrixResponseRow = new DistanceMatrixResponseRow( + $this->elements = array($this->createDistanceMatrixResponseElementMock()) + ); } /** @@ -53,4 +49,107 @@ public function testDefaultState() { $this->assertSame($this->elements, $this->distanceMatrixResponseRow->getElements()); } + + public function testSetElements() + { + $this->distanceMatrixResponseRow->setElements($elements = array($this->createDistanceMatrixResponseElementMock())); + + $this->assertElements($elements); + } + + public function testAddElements() + { + $this->distanceMatrixResponseRow->setElements($elements = array($this->createDistanceMatrixResponseElementMock())); + $this->distanceMatrixResponseRow->addElements($newElements = array($this->createDistanceMatrixResponseElementMock())); + + $this->assertElements(array_merge($elements, $newElements)); + } + + public function testRemoveElements() + { + $this->distanceMatrixResponseRow->setElements($elements = array($this->createDistanceMatrixResponseElementMock())); + $this->distanceMatrixResponseRow->removeElements($elements); + + $this->assertNoElements(); + } + + public function testResetElements() + { + $this->distanceMatrixResponseRow->setElements(array($this->createDistanceMatrixResponseElementMock())); + $this->distanceMatrixResponseRow->resetElements(); + + $this->assertNoElements(); + } + + public function testAddElement() + { + $this->distanceMatrixResponseRow->addElement($element = $this->createDistanceMatrixResponseElementMock()); + + $this->assertElement($element); + } + + public function testAddElementUnicity() + { + $this->distanceMatrixResponseRow->resetElements(); + $this->distanceMatrixResponseRow->addElement($element = $this->createDistanceMatrixResponseElementMock()); + $this->distanceMatrixResponseRow->addElement($element); + + $this->assertElements(array($element)); + } + + public function testRemoveElement() + { + $this->distanceMatrixResponseRow->addElement($element = $this->createDistanceMatrixResponseElementMock()); + $this->distanceMatrixResponseRow->removeElement($element); + + $this->assertNoElement($element); + } + + /** + * Asserts there are elements. + * + * @param array $elements The elements. + */ + protected function assertElements($elements) + { + $this->assertInternalType('array', $elements); + + $this->assertTrue($this->distanceMatrixResponseRow->hasElements()); + $this->assertSame($elements, $this->distanceMatrixResponseRow->getElements()); + + foreach ($elements as $element) { + $this->assertElement($element); + } + } + + /** + * Asserts there is an element; + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element. + */ + protected function assertElement($element) + { + $this->assertDistanceMatrixResponseElementInstance($element); + $this->assertTrue($this->distanceMatrixResponseRow->hasElement($element)); + } + + /** + * Asserts there are no elements. + */ + protected function assertNoElements() + { + $this->assertFalse($this->distanceMatrixResponseRow->hasElements()); + $this->assertEmpty($this->distanceMatrixResponseRow->getElements()); + } + + /** + * Asserts there is no element. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseElement $element The element. + */ + protected function assertNoElement($element) + { + $this->assertDistanceMatrixResponseElementInstance($element); + $this->assertFalse($this->distanceMatrixResponseRow->hasElement($element)); + } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixResponseTest.php b/tests/Services/DistanceMatrix/DistanceMatrixResponseTest.php index ecdb79b4..6bc54238 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixResponseTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixResponseTest.php @@ -19,7 +19,7 @@ * * @author GeLo */ -class DirectionsResponseTest extends \PHPUnit_Framework_TestCase +class DirectionsResponseTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponse */ protected $distanceMatrixResponse; @@ -41,20 +41,11 @@ class DirectionsResponseTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $row = $this->getMockBuilder('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow') - ->disableOriginalConstructor() - ->getMock(); - - $this->status = DistanceMatrixStatus::REQUEST_DENIED; - $this->origins = array('foo'); - $this->destinations = array('bar'); - $this->rows = array($row); - $this->distanceMatrixResponse = new DistanceMatrixResponse( - $this->status, - $this->origins, - $this->destinations, - $this->rows + $this->status = DistanceMatrixStatus::REQUEST_DENIED, + $this->origins = array('origin'), + $this->destinations = array('destination'), + $this->rows = array($this->createDistanceMatrixResponseRowMock()) ); } @@ -78,13 +69,315 @@ public function testDefaultState() $this->assertSame($this->rows, $this->distanceMatrixResponse->getRows()); } + public function testSetStatus() + { + $this->distanceMatrixResponse->setStatus($status = DistanceMatrixStatus::OK); + + $this->assertSame($status, $this->distanceMatrixResponse->getStatus()); + } + + public function testSetOrigins() + { + $this->distanceMatrixResponse->setOrigins($origins = array('foo')); + + $this->assertOrigins($origins); + } + + public function testAddOrigins() + { + $this->distanceMatrixResponse->setOrigins($origins = array('foo')); + $this->distanceMatrixResponse->addOrigins($newOrigins = array('bar')); + + $this->assertOrigins(array_merge($origins, $newOrigins)); + } + + public function testRemoveOrigins() + { + $this->distanceMatrixResponse->setOrigins($origins = array('foo')); + $this->distanceMatrixResponse->removeOrigins($origins); + + $this->assertNoOrigins(); + } + + public function testResetOrigins() + { + $this->distanceMatrixResponse->setOrigins(array('foo')); + $this->distanceMatrixResponse->resetOrigins(); + + $this->assertNoOrigins(); + } + + public function testAddOrigin() + { + $this->distanceMatrixResponse->addOrigin($origin = 'foo'); + + $this->assertOrigin($origin); + } + + public function testAddOriginUnicity() + { + $this->distanceMatrixResponse->resetOrigins(); + $this->distanceMatrixResponse->addOrigin($origin = 'foo'); + $this->distanceMatrixResponse->addOrigin($origin); + + $this->assertOrigins(array($origin)); + } + + public function testRemoveOrigin() + { + $this->distanceMatrixResponse->addOrigin($origin = 'foo'); + $this->distanceMatrixResponse->removeOrigin($origin); + + $this->assertNoOrigin($origin); + } + + public function testSetDestinations() + { + $this->distanceMatrixResponse->setDestinations($destinations = array('foo')); + + $this->assertDestinations($destinations); + } + + public function testAddDestinations() + { + $this->distanceMatrixResponse->setDestinations($destinations = array('foo')); + $this->distanceMatrixResponse->addDestinations($newDestinations = array('bar')); + + $this->assertDestinations(array_merge($destinations, $newDestinations)); + } + + public function testRemoveDestinations() + { + $this->distanceMatrixResponse->setDestinations($destinations = array('foo')); + $this->distanceMatrixResponse->removeDestinations($destinations); + + $this->assertNoDestinations(); + } + + public function testResetDestinations() + { + $this->distanceMatrixResponse->setDestinations(array('foo')); + $this->distanceMatrixResponse->resetDestinations(); + + $this->assertNoDestinations(); + } + + public function testAddDestination() + { + $this->distanceMatrixResponse->addDestination($destination = 'foo'); + + $this->assertDestination($destination); + } + + public function testAddDestinationUnicity() + { + $this->distanceMatrixResponse->resetDestinations(); + $this->distanceMatrixResponse->addDestination($destination = 'foo'); + $this->distanceMatrixResponse->addDestination($destination); + + $this->assertDestinations(array($destination)); + } + + public function testRemoveDestination() + { + $this->distanceMatrixResponse->addDestination($destination = 'foo'); + $this->distanceMatrixResponse->removeDestination($destination); + + $this->assertNoDestination($destination); + } + + public function testSetRows() + { + $this->distanceMatrixResponse->setRows($rows = array($this->createDistanceMatrixResponseRowMock())); + + $this->assertRows($rows); + } + + public function testAddRows() + { + $this->distanceMatrixResponse->setRows($rows = array($this->createDistanceMatrixResponseRowMock())); + $this->distanceMatrixResponse->addRows($newRows = array($this->createDistanceMatrixResponseRowMock())); + + $this->assertRows(array_merge($rows, $newRows)); + } + + public function testRemoveRows() + { + $this->distanceMatrixResponse->setRows($rows = array($this->createDistanceMatrixResponseRowMock())); + $this->distanceMatrixResponse->removeRows($rows); + + $this->assertNoRows(); + } + + public function testResetRows() + { + $this->distanceMatrixResponse->setRows(array($this->createDistanceMatrixResponseRowMock())); + $this->distanceMatrixResponse->resetRows(); + + $this->assertNoRows(); + } + + public function testAddRow() + { + $this->distanceMatrixResponse->addRow($row = $this->createDistanceMatrixResponseRowMock()); + + $this->assertRow($row); + } + + public function testAddRowUnicity() + { + $this->distanceMatrixResponse->resetRows(); + $this->distanceMatrixResponse->addRow($row = $this->createDistanceMatrixResponseRowMock()); + $this->distanceMatrixResponse->addRow($row); + + $this->assertRows(array($row)); + } + + public function testRemoveRow() + { + $this->distanceMatrixResponse->addRow($row = $this->createDistanceMatrixResponseRowMock()); + $this->distanceMatrixResponse->removeRow($row); + + $this->assertNoRow($row); + } + + /** + * Asserts there are origins. + * + * @param array $origins The origins. + */ + protected function assertOrigins($origins) + { + $this->assertInternalType('array', $origins); + + $this->assertTrue($this->distanceMatrixResponse->hasOrigins()); + $this->assertSame($origins, $this->distanceMatrixResponse->getOrigins()); + + foreach ($origins as $origin) { + $this->assertOrigin($origin); + } + } + + /** + * Asserts there is a origin. + * + * @param string $origin The origin. + */ + protected function assertOrigin($origin) + { + $this->assertTrue($this->distanceMatrixResponse->hasOrigin($origin)); + } + + /** + * Asserts there are no origins. + */ + protected function assertNoOrigins() + { + $this->assertFalse($this->distanceMatrixResponse->hasOrigins()); + $this->assertEmpty($this->distanceMatrixResponse->getOrigins()); + } + + /** + * Asserts there is no origin. + * + * @param string $origin The origin. + */ + protected function assertNoOrigin($origin) + { + $this->assertFalse($this->distanceMatrixResponse->hasOrigin($origin)); + } + + /** + * Asserts there are destinations. + * + * @param array $destinations The destinations. + */ + protected function assertDestinations($destinations) + { + $this->assertInternalType('array', $destinations); + + $this->assertTrue($this->distanceMatrixResponse->hasDestinations()); + $this->assertSame($destinations, $this->distanceMatrixResponse->getDestinations()); + + foreach ($destinations as $destination) { + $this->assertDestination($destination); + } + } + + /** + * Asserts there is a destination. + * + * @param string $destination The destination. + */ + protected function assertDestination($destination) + { + $this->assertTrue($this->distanceMatrixResponse->hasDestination($destination)); + } + + /** + * Asserts there are no destinations. + */ + protected function assertNoDestinations() + { + $this->assertFalse($this->distanceMatrixResponse->hasDestinations()); + $this->assertEmpty($this->distanceMatrixResponse->getDestinations()); + } + + /** + * Asserts there is no destination. + * + * @param string $destination The destination. + */ + protected function assertNoDestination($destination) + { + $this->assertFalse($this->distanceMatrixResponse->hasDestination($destination)); + } + + /** + * Asserts there are rows. + * + * @param array $rows The rows. + */ + protected function assertRows($rows) + { + $this->assertInternalType('array', $rows); + + $this->assertTrue($this->distanceMatrixResponse->hasRows()); + $this->assertSame($rows, $this->distanceMatrixResponse->getRows()); + + foreach ($rows as $row) { + $this->assertRow($row); + } + } + + /** + * Asserts there is a row. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row. + */ + protected function assertRow($row) + { + $this->assertDistanceMatrixResponseRowInstance($row); + $this->assertTrue($this->distanceMatrixResponse->hasRow($row)); + } + + /** + * Asserts there are no rows. + */ + protected function assertNoRows() + { + $this->assertFalse($this->distanceMatrixResponse->hasRows()); + $this->assertEmpty($this->distanceMatrixResponse->getRows()); + } + /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The distance matrix response status can only be : INVALID_REQUEST, - * MAX_DIMENSIONS_EXCEEDED, MAX_ELEMENTS_EXCEEDED, OK, OVER_QUERY_LIMIT, REQUEST_DENIED, UNKNOWN_ERROR. + * Asserts there is no row. + * + * @param \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixResponseRow $row The row. */ - public function testStatusWithInvalidValue() + protected function assertNoRow($row) { - $this->distanceMatrixResponse->setStatus('foo'); + $this->assertDistanceMatrixResponseRowInstance($row); + $this->assertFalse($this->distanceMatrixResponse->hasRow($row)); } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixStatusTest.php b/tests/Services/DistanceMatrix/DistanceMatrixStatusTest.php index 91d24cf0..da3c8e83 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixStatusTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixStatusTest.php @@ -18,20 +18,21 @@ * * @author GeLo */ -class DirectionsMatrixStatusTest extends \PHPUnit_Framework_TestCase +class DirectionsMatrixStatusTest extends AbstractTestCase { - public function testDistanceMatrixStatus() + public function testInheritance() { - $expected = array( - DistanceMatrixStatus::INVALID_REQUEST, - DistanceMatrixStatus::MAX_DIMENSIONS_EXCEEDED, - DistanceMatrixStatus::MAX_ELEMENTS_EXCEEDED, - DistanceMatrixStatus::OK, - DistanceMatrixStatus::OVER_QUERY_LIMIT, - DistanceMatrixStatus::REQUEST_DENIED, - DistanceMatrixStatus::UNKNOWN_ERROR, - ); + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixStatus'); + } - $this->assertSame($expected, DistanceMatrixStatus::getDistanceMatrixStatus()); + public function testConstants() + { + $this->assertSame('INVALID_REQUEST', DistanceMatrixStatus::INVALID_REQUEST); + $this->assertSame('MAX_DIMENSIONS_EXCEEDED', DistanceMatrixStatus::MAX_DIMENSIONS_EXCEEDED); + $this->assertSame('MAX_ELEMENTS_EXCEEDED', DistanceMatrixStatus::MAX_ELEMENTS_EXCEEDED); + $this->assertSame('OK', DistanceMatrixStatus::OK); + $this->assertSame('OVER_QUERY_LIMIT', DistanceMatrixStatus::OVER_QUERY_LIMIT); + $this->assertSame('REQUEST_DENIED', DistanceMatrixStatus::REQUEST_DENIED); + $this->assertSame('UNKNOWN_ERROR', DistanceMatrixStatus::UNKNOWN_ERROR); } } diff --git a/tests/Services/DistanceMatrix/DistanceMatrixTest.php b/tests/Services/DistanceMatrix/DistanceMatrixTest.php index 0496ab07..705cb3b8 100644 --- a/tests/Services/DistanceMatrix/DistanceMatrixTest.php +++ b/tests/Services/DistanceMatrix/DistanceMatrixTest.php @@ -18,24 +18,24 @@ use Ivory\GoogleMap\Services\Base\TravelMode; use Ivory\GoogleMap\Services\Base\UnitSystem; use Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrix; -use Widop\HttpAdapter\CurlHttpAdapter; +use Ivory\HttpAdapter\SocketHttpAdapter; /** * Distance matrix test. * * @author GeLo */ -class DistanceMatrixTest extends \PHPUnit_Framework_TestCase +class DistanceMatrixTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrix */ - protected $service; + protected $distanceMatrix; /** * {@inheritdoc} */ protected function setUp() { - $this->service = new DistanceMatrix(new CurlHttpAdapter()); + $this->distanceMatrix = new DistanceMatrix(new SocketHttpAdapter()); } /** @@ -43,205 +43,95 @@ protected function setUp() */ protected function tearDown() { - unset($this->service); + unset($this->distanceMatrix); } - public function testProcessWithOriginAndDestinationStrings() + public function testInheritance() { - $response = $this->service->process(array('Vancouver BC'), array('San Francisco')); - - $this->assertSame(DistanceMatrixStatus::OK, $response->getStatus()); - $this->assertCount(1, $response->getOrigins()); - $this->assertCount(1, $response->getDestinations()); - - $rows = $response->getRows(); - $this->assertCount(1, $rows); - - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); - $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); + $this->assertServiceInstance($this->distanceMatrix); } - public function testProcessWithOriginAndDestinationCoordinates() + /** + * @dataProvider requestProvider + */ + public function testProcessWithJsonFormat(DistanceMatrixRequest $request) { - $vancouver = new Coordinate(49.262428, -123.113136); - $sanFrancisco = new Coordinate(37.775328, -122.418938); - - $response = $this->service->process(array($vancouver), array($sanFrancisco)); + $response = $this->distanceMatrix->process($request); $this->assertSame(DistanceMatrixStatus::OK, $response->getStatus()); - $this->assertCount(1, $response->getOrigins()); - $this->assertCount(1, $response->getDestinations()); - - $rows = $response->getRows(); - $this->assertCount(1, $rows); - - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); - $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); - } - - public function testProcessWithMinimalDistanceMatrixRequest() - { - $request = new DistanceMatrixRequest(); - $request->addOrigin('Vancouver BC'); - $request->addDestination('San Francisco'); - - $response = $this->service->process($request); - $this->assertCount(1, $response->getOrigins()); - $this->assertCount(1, $response->getDestinations()); - - $rows = $response->getRows(); - $this->assertCount(1, $rows); - - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); - $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); - } - - public function testProcessWithDistanceMatrixRequest() - { - $request = new DistanceMatrixRequest(); - $request->addOrigin('Vancouver BC'); - $request->addDestination('San Francisco'); - $request->setTravelMode(TravelMode::BICYCLING); - $request->setUnitSystem(UnitSystem::METRIC); - $request->setRegion('en'); - $request->setLanguage('fr'); - - $response = $this->service->process($request); - $this->assertCount(1, $response->getOrigins()); - $this->assertCount(1, $response->getDestinations()); - - $rows = $response->getRows(); - $this->assertCount(1, $rows); - - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); - $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); - } - - public function testProcessWithDistanceMatrixRequestAndAvoidTolls() - { - $request = new DistanceMatrixRequest(); - $request->addOrigin('Vancouver BC'); - $request->addDestination('San Francisco'); - $request->setAvoidTolls(true); - $response = $this->service->process($request); $this->assertCount(1, $response->getOrigins()); $this->assertCount(1, $response->getDestinations()); + $this->assertCount(1, $rows = $response->getRows()); - $rows = $response->getRows(); - $this->assertCount(1, $rows); + $this->assertArrayHasKey(0, $rows); + $this->assertCount(1, $elements = $rows[0]->getElements()); - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); + $this->assertArrayHasKey(0, $elements); $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); } - public function testProcessWithDistanceMatrixRequestAndAvoidHighways() - { - $request = new DistanceMatrixRequest(); - $request->addOrigin('Vancouver BC'); - $request->addDestination('San Francisco'); - $request->setAvoidHighways(true); - - $response = $this->service->process($request); - $this->assertCount(1, $response->getOrigins()); - $this->assertCount(1, $response->getDestinations()); - - $rows = $response->getRows(); - $this->assertCount(1, $rows); - - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); - $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); - } - - public function testProcessWithXmlFormat() + /** + * @dataProvider requestProvider + */ + public function testProcessWithXmlFormat(DistanceMatrixRequest $request) { - $this->service->setFormat('xml'); - $response = $this->service->process(array('Vancouver BC'), array('San Francisco')); + $this->distanceMatrix->setFormat(DistanceMatrix::FORMAT_XML); + $response = $this->distanceMatrix->process($request); - $this->assertSame(DistanceMatrixStatus::OK, $response->getStatus()); $this->assertCount(1, $response->getOrigins()); $this->assertCount(1, $response->getDestinations()); + $this->assertCount(1, $rows = $response->getRows()); - $rows = $response->getRows(); - $this->assertCount(1, $rows); + $this->assertArrayHasKey(0, $rows); + $this->assertCount(1, $elements = $rows[0]->getElements()); - $elements = $rows[0]->getElements(); - $this->assertCount(1, $elements); + $this->assertArrayHasKey(0, $elements); $this->assertSame(DistanceMatrixElementStatus::OK, $elements[0]->getStatus()); } - public function testSignUrlWithoutBusinessAccount() - { - $method = new \ReflectionMethod($this->service, 'signUrl'); - $method->setAccessible(true); - - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $this->assertSame($url, $method->invoke($this->service, $url)); - } - - public function testSignUrlWithBusinessAccount() - { - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $businessAccount - ->expects($this->once()) - ->method('signUrl') - ->with($this->equalTo($url)) - ->will($this->returnValue('url')); - - $this->service->setBusinessAccount($businessAccount); - - $method = new \ReflectionMethod($this->service, 'signUrl'); - $method->setAccessible(true); - - $this->assertSame('url', $method->invoke($this->service, $url)); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The process arguments are invalid. - * The available prototypes are: - * - function route(array $origins, array $destinations) - * - function route(Ivory\GoogleMap\Services\DistanceMatrix\DistanceMatrixRequest $request) - */ - public function testProcessWithInvalidRequestParameters() - { - $this->service->process(true); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The directions request is not valid. It needs at least one origin and one destination. - */ public function testProcessWithInvalidRequest() { - $this->service->process(new DistanceMatrixRequest()); + $response = $this->distanceMatrix->process(new DistanceMatrixRequest(array(), array())); + + $this->assertSame(DistanceMatrixStatus::INVALID_REQUEST, $response->getStatus()); + $this->assertEmpty($response->getOrigins()); + $this->assertEmpty($response->getDestinations()); + $this->assertEmpty($response->getRows()); } /** - * @expectedException \Ivory\GoogleMap\Exception\DistanceMatrixException - * @expectedExceptionMessage The service result is not valid. + * Gets the request provider. + * + * @return array The request provider. */ - public function testProcessWithInvalidResult() + public function requestProvider() { - $httpAdapterMock = $this->getMock('Widop\HttpAdapter\HttpAdapterInterface'); - $httpAdapterMock - ->expects($this->once()) - ->method('getContent') - ->will($this->returnValue(null)); - - $this->service = new DistanceMatrix($httpAdapterMock); - $this->service->process(array('Vancouver BC'), array('San Francisco')); + $stringRequest = new DistanceMatrixRequest(array('Vancouver BC'), array('San Francisco')); + + $coordinateRequest = new DistanceMatrixRequest( + array(new Coordinate(49.262428, -123.113136)), + array(new Coordinate(37.775328, -122.418938)) + ); + + $fullRequest = new DistanceMatrixRequest(array('Vancouver BC'), array('San Francisco')); + $fullRequest->setTravelMode(TravelMode::BICYCLING); + $fullRequest->setUnitSystem(UnitSystem::METRIC); + $fullRequest->setRegion('en'); + $fullRequest->setLanguage('fr'); + + $avoidTollsRequest = new DistanceMatrixRequest(array('Vancouver BC'), array('San Francisco')); + $avoidTollsRequest->setAvoidTolls(true); + + $avoidHighwaysRequest = new DistanceMatrixRequest(array('Vancouver BC'), array('San Francisco')); + $avoidHighwaysRequest->setAvoidHighways(true); + + return array( + array($stringRequest), + array($coordinateRequest), + array($fullRequest), + array($avoidTollsRequest), + array($avoidHighwaysRequest), + ); } } diff --git a/tests/Services/Geocoding/AbstractTestCase.php b/tests/Services/Geocoding/AbstractTestCase.php new file mode 100644 index 00000000..c7e9b77d --- /dev/null +++ b/tests/Services/Geocoding/AbstractTestCase.php @@ -0,0 +1,102 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\Tests\GoogleMap\Services\AbstractTestCase as TestCase; + +/** + * Geocoding test case. + * + * @author GeLo + */ +abstract class AbstractTestCase extends TestCase +{ + /** + * Asserts a geocoder address component instance. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent $addressComponent The geocoder address component. + */ + protected function assertGeocoderAddressComponentInstance($addressComponent) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent', $addressComponent); + } + + /** + * Asserts a geocoder result instance. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderResult $result The geocoder result. + */ + protected function assertGeocoderResultInstance($result) + { + $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\GeocoderResult', $result); + } + + /** + * Creates a geocoder address component mock. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent|\PHPUnit_Framework_MockObject_MockObject The geocoder address component mock. + */ + protected function createGeocoderAddressComponentMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a geocoder geometry mock. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry|\PHPUnit_Framework_MockObject_MockObject The geocoder geometry mock. + */ + protected function createGeocoderGeometryMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a geocoder provider mock. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderProvider|\PHPUnit_Framework_MockObject_MockObject The geocoder provider mock. + */ + protected function createGeocoderProviderMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\GeocoderProvider') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Creates a geocoder request mock. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderRequest|\PHPUnit_Framework_MockObject_MockObject The geocoder request mock. + */ + protected function createGeocoderRequestMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\GeocoderRequest') + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + } + + /** + * Creates a geocoder result mock. + * + * @return \Ivory\GoogleMap\Services\Geocoding\GeocoderResult|\PHPUnit_Framework_MockObject_MockObject The geocoder result mock. + */ + protected function createGeocoderResultMock() + { + return $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\GeocoderResult') + ->disableOriginalConstructor() + ->getMock(); + } +} diff --git a/tests/Services/Geocoding/GeocoderAddressComponentTest.php b/tests/Services/Geocoding/GeocoderAddressComponentTest.php new file mode 100644 index 00000000..79d32dfd --- /dev/null +++ b/tests/Services/Geocoding/GeocoderAddressComponentTest.php @@ -0,0 +1,179 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent; + +/** + * Geocoder address component test. + * + * @author GeLo + */ +class GeocoderAddressComponentTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent */ + protected $geocoderAddressComponent; + + /** @var string */ + protected $longName; + + /** @var string */ + protected $shortName; + + /** @var array */ + protected $types; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->geocoderAddressComponent = new GeocoderAddressComponent( + $this->longName = 'long_name', + $this->shortName = 'short_name', + $this->types = array('type') + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->geocoderAddressComponent); + unset($this->longName); + unset($this->shortName); + unset($this->types); + } + + public function testInitialState() + { + $this->assertSame($this->longName, $this->geocoderAddressComponent->getLongName()); + $this->assertSame($this->shortName, $this->geocoderAddressComponent->getShortName()); + $this->assertSame($this->types, $this->geocoderAddressComponent->getTypes()); + } + + public function testSetLongName() + { + $this->geocoderAddressComponent->setLongName($longName = 'foo'); + + $this->assertSame($longName, $this->geocoderAddressComponent->getLongName()); + } + + public function testSetShortName() + { + $this->geocoderAddressComponent->setShortName($shortName = 'foo'); + + $this->assertSame($shortName, $this->geocoderAddressComponent->getShortName()); + } + + public function testSetTypes() + { + $this->geocoderAddressComponent->setTypes($types = array('foo')); + + $this->assertTypes($types); + } + + public function testAddTypes() + { + $this->geocoderAddressComponent->setTypes($types = array('foo')); + $this->geocoderAddressComponent->addTypes($newTypes = array('bar')); + + $this->assertTypes(array_merge($types, $newTypes)); + } + + public function testRemoveTypes() + { + $this->geocoderAddressComponent->setTypes($types = array('foo')); + $this->geocoderAddressComponent->removeTypes($types); + + $this->assertNoTypes(); + } + + public function testResetTypes() + { + $this->geocoderAddressComponent->setTypes(array('foo')); + $this->geocoderAddressComponent->resetTypes(); + + $this->assertNoTypes(); + } + + public function testAddType() + { + $this->geocoderAddressComponent->addType($type = 'foo'); + + $this->assertType($type); + } + + public function testAddTypeUnicity() + { + $this->geocoderAddressComponent->resetTypes(); + $this->geocoderAddressComponent->addType($type = 'foo'); + $this->geocoderAddressComponent->addType($type); + + $this->assertTypes(array($type)); + } + + public function testRemoveType() + { + $this->geocoderAddressComponent->addType($type = 'foo'); + $this->geocoderAddressComponent->removeType($type); + + $this->assertNoType($type); + } + + /** + * Asserts there are types. + * + * @param array $types The types. + */ + protected function assertTypes($types) + { + $this->assertInternalType('array', $types); + + $this->assertTrue($this->geocoderAddressComponent->hasTypes()); + $this->assertSame($types, $this->geocoderAddressComponent->getTypes()); + + foreach ($types as $type) { + $this->assertType($type); + } + } + + /** + * Asserts there is a type. + * + * @param string $type The type. + */ + protected function assertType($type) + { + $this->assertTrue($this->geocoderAddressComponent->hasType($type)); + } + + /** + * Asserts there are no types. + */ + protected function assertNoTypes() + { + $this->assertFalse($this->geocoderAddressComponent->hasTypes()); + $this->assertEmpty($this->geocoderAddressComponent->getTypes()); + } + + /** + * Asserts there is no type. + * + * @param string $type The type. + */ + protected function assertNoType($type) + { + $this->assertFalse($this->geocoderAddressComponent->hasType($type)); + } +} diff --git a/tests/Services/Geocoding/GeocoderGeometryTest.php b/tests/Services/Geocoding/GeocoderGeometryTest.php new file mode 100644 index 00000000..48737f47 --- /dev/null +++ b/tests/Services/Geocoding/GeocoderGeometryTest.php @@ -0,0 +1,108 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderLocationType; +use Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry; + +/** + * Geocoder geometry test. + * + * @author GeLo + */ +class GeocoderGeometryTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry */ + protected $geocoderGeometry; + + /** @var \Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ + protected $location; + + /** @var string */ + protected $locationType; + + /** @var \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject */ + protected $viewport; + + /** @var \Ivory\GoogleMap\Base\Bound|\PHPUnit_Framework_MockObject_MockObject */ + protected $bound; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->geocoderGeometry = new GeocoderGeometry( + $this->location = $this->createCoordinateMock(), + $this->locationType = GeocoderLocationType::RANGE_INTERPOLATED, + $this->viewport = $this->createBoundMock(), + $this->bound = $this->createBoundMock() + ); + } + + protected function tearDown() + { + unset($this->geocoderGeometry); + unset($this->location); + unset($this->locationType); + unset($this->viewport); + unset($this->bound); + } + + public function testInitialState() + { + $this->assertSame($this->location, $this->geocoderGeometry->getLocation()); + $this->assertSame($this->locationType, $this->geocoderGeometry->getLocationType()); + $this->assertSame($this->viewport, $this->geocoderGeometry->getViewport()); + + $this->assertTrue($this->geocoderGeometry->hasBound()); + $this->assertSame($this->bound, $this->geocoderGeometry->getBound()); + } + + public function testSetLocation() + { + $this->geocoderGeometry->setLocation($location = $this->createCoordinateMock()); + + $this->assertSame($location, $this->geocoderGeometry->getLocation()); + } + + public function testSetLocationType() + { + $this->geocoderGeometry->setLocationType($locationType = GeocoderLocationType::GEOMETRIC_CENTER); + + $this->assertSame($locationType, $this->geocoderGeometry->getLocationType()); + } + + public function testSetViewport() + { + $this->geocoderGeometry->setViewport($viewport = $this->createBoundMock()); + + $this->assertSame($viewport, $this->geocoderGeometry->getViewport()); + } + + public function testSetBound() + { + $this->geocoderGeometry->setBound($bound = $this->createBoundMock()); + + $this->assertTrue($this->geocoderGeometry->hasBound()); + $this->assertSame($bound, $this->geocoderGeometry->getBound()); + } + + public function testResetBound() + { + $this->geocoderGeometry->setBound($this->createBoundMock()); + $this->geocoderGeometry->setBound(null); + + $this->assertFalse($this->geocoderGeometry->hasBound()); + $this->assertNull($this->geocoderGeometry->getBound()); + } +} diff --git a/tests/Services/Geocoding/GeocoderLocationTypeTest.php b/tests/Services/Geocoding/GeocoderLocationTypeTest.php new file mode 100644 index 00000000..8486070c --- /dev/null +++ b/tests/Services/Geocoding/GeocoderLocationTypeTest.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderLocationType; + +/** + * Geocoder location type test. + * + * @author GeLo + */ +class GeocoderLocationTypeTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Services\Geocoding\GeocoderLocationType'); + } + + public function testConstants() + { + $this->assertSame('APPROXIMATE', GeocoderLocationType::APPROXIMATE); + $this->assertSame('GEOMETRIC_CENTER', GeocoderLocationType::GEOMETRIC_CENTER); + $this->assertSame('RANGE_INTERPOLATED', GeocoderLocationType::RANGE_INTERPOLATED); + $this->assertSame('ROOFTOP', GeocoderLocationType::ROOFTOP); + } +} diff --git a/tests/Services/Geocoding/GeocoderProviderTest.php b/tests/Services/Geocoding/GeocoderProviderTest.php index f4990ad7..a9f0c8f4 100644 --- a/tests/Services/Geocoding/GeocoderProviderTest.php +++ b/tests/Services/Geocoding/GeocoderProviderTest.php @@ -11,17 +11,19 @@ namespace Ivory\Tests\GoogleMap\Services\Geocoding; -use Geocoder\HttpAdapter\CurlHttpAdapter; +use Ivory\GoogleMap\Base\Bound; +use Ivory\GoogleMap\Base\Coordinate; use Ivory\GoogleMap\Services\Geocoding\GeocoderProvider; use Ivory\GoogleMap\Services\Geocoding\GeocoderRequest; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderStatus; +use Ivory\GoogleMap\Services\Geocoding\GeocoderStatus; +use Ivory\HttpAdapter\SocketHttpAdapter; /** * Geocoder provider test. * * @author GeLo */ -class GeocoderProviderTest extends \PHPUnit_Framework_TestCase +class GeocoderProviderTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderProvider */ protected $geocoderProvider; @@ -31,7 +33,7 @@ class GeocoderProviderTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->geocoderProvider = new GeocoderProvider(new CurlHttpAdapter()); + $this->geocoderProvider = new GeocoderProvider(new SocketHttpAdapter()); } /** @@ -42,234 +44,110 @@ protected function tearDown() unset($this->geocoderProvider); } - public function testInitialState() + public function testInheritance() { - $this->assertSame('http://maps.googleapis.com/maps/api/geocode', $this->geocoderProvider->getUrl()); - $this->assertFalse($this->geocoderProvider->isHttps()); - $this->assertSame('json', $this->geocoderProvider->getFormat()); - $this->assertInstanceOf('Ivory\GoogleMap\Services\Utils\XmlParser', $this->geocoderProvider->getXmlParser()); - $this->assertFalse($this->geocoderProvider->hasBusinessAccount()); - $this->assertNull($this->geocoderProvider->getBusinessAccount()); + $this->assertServiceInstance($this->geocoderProvider); } - public function testUrlWithValieValue() + public function testSetMaxResults() { - $this->geocoderProvider->setUrl('http://foo'); - - $this->assertSame('http://foo', $this->geocoderProvider->getUrl()); + $this->assertSame($this->geocoderProvider, $this->geocoderProvider->setMaxResults(10)); } /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder provider url must be a string value. + * @dataProvider geocodedDataProvider */ - public function testUrlWithInvalidValue() + public function testGeocodedDataWithJsonFormat($request) { - $this->geocoderProvider->setUrl(true); - } - - public function testHttpsWithValidValue() - { - $this->geocoderProvider->setHttps(true); + $response = $this->geocoderProvider->getGeocodedData($request); - $this->assertTrue($this->geocoderProvider->isHttps()); + $this->assertSame(GeocoderStatus::OK, $response->getStatus()); + $this->assertNotEmpty($response->getResults()); } /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder provider https flag must be a boolean value. + * @dataProvider geocodedDataProvider */ - public function testHttpsWithInvalidValue() - { - $this->geocoderProvider->setHttps('foo'); - } - - public function testUrlWithHttps() + public function testGeocodedDataWithXmlFormat($request) { - $this->geocoderProvider->setUrl('http://foo'); - $this->geocoderProvider->setHttps(true); - - $this->assertSame('https://foo', $this->geocoderProvider->getUrl()); - } - - public function testFormatWithJsonValue() - { - $this->geocoderProvider->setFormat('json'); + $this->geocoderProvider->setFormat(GeocoderProvider::FORMAT_XML); + $response = $this->geocoderProvider->getGeocodedData($request); - $this->assertSame('json', $this->geocoderProvider->getFormat()); + $this->assertSame(GeocoderStatus::OK, $response->getStatus()); + $this->assertNotEmpty($response->getResults()); } - public function testFormatWithXmlFormat() + public function testGeocodedDataWithInvalidRequest() { - $this->geocoderProvider->setFormat('xml'); + $response = $this->geocoderProvider->getGeocodedData(new GeocoderRequest('')); - $this->assertSame('xml', $this->geocoderProvider->getFormat()); + $this->assertSame(GeocoderStatus::ZERO_RESULTS, $response->getStatus()); + $this->assertEmpty($response->getResults()); } /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder provider format can only be : json, xml. + * @dataProvider reversedDataProvider */ - public function testFormatWithInvalidValue() - { - $this->geocoderProvider->setFormat('foo'); - } - - public function testXmlParser() + public function testReversedData($longitude, $latitude) { - $xmlParser = $this->getMock('Ivory\GoogleMap\Services\Utils\XmlParser'); - $this->geocoderProvider->setXmlParser($xmlParser); + $response = $this->geocoderProvider->getReversedData(array($longitude, $latitude)); - $this->assertSame($xmlParser, $this->geocoderProvider->getXmlParser()); - } - - public function testBusinessAccount() - { - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $this->geocoderProvider->setBusinessAccount($businessAccount); - - $this->assertTrue($this->geocoderProvider->hasBusinessAccount()); - $this->assertSame($businessAccount, $this->geocoderProvider->getBusinessAccount()); - - $this->geocoderProvider->setBusinessAccount(); - - $this->assertFalse($this->geocoderProvider->hasBusinessAccount()); - $this->assertNull($this->geocoderProvider->getBusinessAccount()); - } - - public function testGeocodedDataWithAddress() - { - $response = $this->geocoderProvider->getGeocodedData('Paris'); - - $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', $response); - - $this->assertNotEmpty($response->getResults()); - $this->assertSame(GeocoderStatus::OK, $response->getStatus()); - } - - public function testGeocdedDataWithIp() - { - $response = $this->geocoderProvider->getGeocodedData('111.111.111.111'); - - $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', $response); - - $this->assertNotEmpty($response->getResults()); $this->assertSame(GeocoderStatus::OK, $response->getStatus()); - } - - public function testGeocodedDataWithGeocoderRequest() - { - $request = new GeocoderRequest(); - $request->setAddress('Paris'); - $request->setBound(48.815573, 2.224199, 48.9021449, 2.4699208); - $request->setRegion('FR'); - $request->setLanguage('PL'); - - $response = $this->geocoderProvider->getGeocodedData($request); - - $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', $response); - $this->assertNotEmpty($response->getResults()); - $this->assertSame(GeocoderStatus::OK, $response->getStatus()); } - public function testGeocodedDataWithXmlFormat() + public function testReversedDataWithInvalidRequest() { - $this->geocoderProvider->setFormat('xml'); - $response = $this->geocoderProvider->getGeocodedData('Paris'); - - $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', $response); - - $this->assertNotEmpty($response->getResults()); - $this->assertSame(GeocoderStatus::OK, $response->getStatus()); - } + $response = $this->geocoderProvider->getReversedData(array('foo', 'bar')); - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geolocate argument is invalid. - * The available prototypes are : - * - function geocode(string $address) - * - function geocode(Ivory\GoogleMap\Services\Geocoding\GeocoderRequest $request) - */ - public function testGeocodedDataWithInvalidValue() - { - $this->geocoderProvider->getGeocodedData(true); + $this->assertSame(GeocoderStatus::ZERO_RESULTS, $response->getStatus()); + $this->assertEmpty($response->getResults()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder request is not valid. It needs at least an address or a coordinate. - */ - public function testGeocodedDataWithInvalidGeocoderRequest() + public function testGetName() { - $request = new GeocoderRequest(); - - $this->geocoderProvider->getGeocodedData($request); + $this->assertSame('ivory_google_map', $this->geocoderProvider->getName()); } /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The service result is not valid. + * Gets the geocoded data provider. + * + * @return array The geocoded data provider. */ - public function testGeocodedDataWithInvalidResult() + public function geocodedDataProvider() { - $httpAdapterMock = $this->getMock('Geocoder\HttpAdapter\HttpAdapterInterface'); - $httpAdapterMock - ->expects($this->once()) - ->method('getContent') - ->will($this->returnValue(null)); + $addressRequest = new GeocoderRequest('Paris'); + $coordinateRequest = new GeocoderRequest(new Coordinate(48.815573, 2.224199)); + $ipRequest = new GeocoderRequest('111.111.111.111'); - $this->geocoderProvider = new GeocoderProvider($httpAdapterMock); - $this->geocoderProvider->getGeocodedData('Paris'); - } - - public function testReversedData() - { - $response = $this->geocoderProvider->getReversedData(array(48.856633, 2.352254)); - - $this->assertInstanceOf('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', $response); - - $this->assertNotEmpty($response->getResults()); - $this->assertSame(GeocoderStatus::OK, $response->getStatus()); - } - - public function testSignUrlWithoutBusinessAccount() - { - $method = new \ReflectionMethod($this->geocoderProvider, 'signUrl'); - $method->setAccessible(true); + $boundRequest = new GeocoderRequest('Paris'); + $boundRequest->setBound(new Bound(new Coordinate(48.815573, 2.224199), new Coordinate(48.9021449, 2.4699208))); - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; + $regionRequest = new GeocoderRequest('Paris'); + $regionRequest->setRegion('FR'); - $this->assertSame($url, $method->invoke($this->geocoderProvider, $url)); - } - - public function testSignUrlWithBusinessAccount() - { - $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; - - $businessAccount = $this->getMockBuilder('Ivory\GoogleMap\Services\BusinessAccount') - ->disableOriginalConstructor() - ->getMock(); - - $businessAccount - ->expects($this->once()) - ->method('signUrl') - ->with($this->equalTo($url)) - ->will($this->returnValue('url')); + $languageRequest = new GeocoderRequest('Paris'); + $languageRequest->setLanguage('PL'); - $this->geocoderProvider->setBusinessAccount($businessAccount); - - $method = new \ReflectionMethod($this->geocoderProvider, 'signUrl'); - $method->setAccessible(true); - - $this->assertSame('url', $method->invoke($this->geocoderProvider, $url)); + return array( + array($addressRequest), + array($coordinateRequest), + array($ipRequest), + array($boundRequest), + array($regionRequest), + array($languageRequest), + ); } - public function testName() + /** + * Gets the reversed data provider. + * + * @return array The reversed data provider. + */ + public function reversedDataProvider() { - $this->assertSame('ivory_google_map', $this->geocoderProvider->getName()); + return array( + array(48.856633, 2.352254) + ); } } diff --git a/tests/Services/Geocoding/GeocoderRequestTest.php b/tests/Services/Geocoding/GeocoderRequestTest.php index c80a4547..c89f6afd 100644 --- a/tests/Services/Geocoding/GeocoderRequestTest.php +++ b/tests/Services/Geocoding/GeocoderRequestTest.php @@ -18,17 +18,20 @@ * * @author GeLo */ -class GeocoderRequestTest extends \PHPUnit_Framework_TestCase +class GeocoderRequestTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderRequest */ protected $geocoderRequest; + /** @var string|\Ivory\GoogleMap\Base\Coordinate|\PHPUnit_Framework_MockObject_MockObject */ + protected $location; + /** * {@inheritdoc} */ protected function setUp() { - $this->geocoderRequest = new GeocoderRequest(); + $this->geocoderRequest = new GeocoderRequest($this->location = 'foo'); } /** @@ -36,226 +39,81 @@ protected function setUp() */ protected function tearDown() { + unset($this->location); unset($this->geocoderRequest); } public function testDefaultState() { - $this->assertFalse($this->geocoderRequest->hasAddress()); - $this->assertFalse($this->geocoderRequest->hasCoordinate()); + $this->assertSame($this->location, $this->geocoderRequest->getLocation()); $this->assertFalse($this->geocoderRequest->hasBound()); $this->assertFalse($this->geocoderRequest->hasRegion()); $this->assertFalse($this->geocoderRequest->hasLanguage()); $this->assertFalse($this->geocoderRequest->hasSensor()); } - public function testAddressWithValidValue() - { - $this->geocoderRequest->setAddress('foo'); - - $this->assertTrue($this->geocoderRequest->hasAddress()); - $this->assertSame('foo', $this->geocoderRequest->getAddress()); - } - - public function testAddressWithNullValue() - { - $this->geocoderRequest->setAddress('foo'); - $this->geocoderRequest->setAddress(null); - - $this->assertNull($this->geocoderRequest->getAddress()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder request address must be a string value. - */ - public function testAddressWithInvalidValue() - { - $this->geocoderRequest->setAddress(true); - } - - public function testCoordinateWithCoordinate() - { - $coordinate = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->geocoderRequest->setCoordinate($coordinate); - - $this->assertTrue($this->geocoderRequest->hasCoordinate()); - $this->assertSame($coordinate, $this->geocoderRequest->getCoordinate()); - } - - public function testCoordinateWithLatitudeAndLongitude() + public function testSetLocation() { - $this->geocoderRequest->setCoordinate(1.1, -2.1, false); + $this->geocoderRequest->setLocation($location = $this->createCoordinateMock()); - $this->assertSame(1.1, $this->geocoderRequest->getCoordinate()->getLatitude()); - $this->assertSame(-2.1, $this->geocoderRequest->getCoordinate()->getLongitude()); - $this->assertFalse($this->geocoderRequest->getCoordinate()->isNoWrap()); + $this->assertSame($location, $this->geocoderRequest->getLocation()); } - public function testCoordinateWithNullValue() + public function testSetBound() { - $this->geocoderRequest->setCoordinate(1.1, -2.1); - $this->geocoderRequest->setCoordinate(null); - - $this->assertNull($this->geocoderRequest->getCoordinate()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The coordinate setter arguments is invalid. - * The available prototypes are : - * - function setCoordinate(Ivory\GoogleMap\Base\Coordinate $coordinate = null) - * - function setCoordinate(double $latitude, double $longitude, boolean $noWrap = true) - */ - public function testCoordinateWithInvalidValue() - { - $this->geocoderRequest->setCoordinate('foo'); - } - - public function testBoundWithBound() - { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->geocoderRequest->setBound($bound); + $this->geocoderRequest->setBound($bound = $this->createBoundMock()); $this->assertTrue($this->geocoderRequest->hasBound()); $this->assertSame($bound, $this->geocoderRequest->getBound()); } - public function testBoundWithCoordinates() - { - $southWest = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $northEast = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - - $this->geocoderRequest->setBound($southWest, $northEast); - - $this->assertSame($southWest, $this->geocoderRequest->getBound()->getSouthWest()); - $this->assertSame($northEast, $this->geocoderRequest->getBound()->getNorthEast()); - } - - public function testBoundWithLatitudesAndLongitudes() - { - $this->geocoderRequest->setBound(-2, -2, 2, 2, true, false); - - $this->assertSame(-2, $this->geocoderRequest->getBound()->getSouthWest()->getLatitude()); - $this->assertSame(-2, $this->geocoderRequest->getBound()->getSouthWest()->getLongitude()); - $this->assertTrue($this->geocoderRequest->getBound()->getSouthWest()->isNoWrap()); - - $this->assertSame(2, $this->geocoderRequest->getBound()->getNorthEast()->getLatitude()); - $this->assertSame(2, $this->geocoderRequest->getBound()->getNorthEast()->getLongitude()); - $this->assertFalse($this->geocoderRequest->getBound()->getNorthEast()->isNoWrap()); - } - - public function testBoundWithNullValue() + public function testResetBound() { - $this->geocoderRequest->setBound(-2, -2, 2, 2); + $this->geocoderRequest->setBound($this->createBoundMock()); $this->geocoderRequest->setBound(null); + $this->assertFalse($this->geocoderRequest->hasBound()); $this->assertNull($this->geocoderRequest->getBound()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The bound setter arguments are invalid. - * The available prototypes are : - * - function setBound(Ivory\GoogleMap\Base\Bound $bound = null) - * - function setBound(Ivory\GoogleMap\Base\Coordinate $southWest, Ivory\GoogleMap\Base\Coordinate $northEast) - * - function setBound( - * double $southWestLatitude, - * double $southWestLongitude, - * double $northEastLatitude, - * double $northEastLongitude, - * boolean southWestNoWrap = true, - * boolean $northEastNoWrap = true - * ) - */ - public function testBoundWithInvalidValue() - { - $this->geocoderRequest->setBound('foo'); - } - - public function testRegionWithValidValue() + public function testSetRegion() { - $this->geocoderRequest->setRegion('fr'); + $this->geocoderRequest->setRegion($region = 'fr'); $this->assertTrue($this->geocoderRequest->hasRegion()); - $this->assertSame('fr', $this->geocoderRequest->getRegion()); + $this->assertSame($region, $this->geocoderRequest->getRegion()); } - public function testRegionWithNullValue() + public function testResetRegion() { $this->geocoderRequest->setRegion('fr'); $this->geocoderRequest->setRegion(null); + $this->assertFalse($this->geocoderRequest->hasRegion()); $this->assertNull($this->geocoderRequest->getRegion()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder request region must be a string with two characters. - */ - public function testRegionWithInvalidValue() + public function testSetLanguage() { - $this->geocoderRequest->setRegion('foo'); - } - - public function testLanguageWithValidValue() - { - $this->geocoderRequest->setLanguage('pl'); + $this->geocoderRequest->setLanguage($language = 'pl'); $this->assertTrue($this->geocoderRequest->hasLanguage()); - $this->assertSame('pl', $this->geocoderRequest->getLanguage()); + $this->assertSame($language, $this->geocoderRequest->getLanguage()); } - public function testLanguageWithNullValue() + public function testResetLanguage() { $this->geocoderRequest->setLanguage('pl'); $this->geocoderRequest->setLanguage(null); + $this->assertFalse($this->geocoderRequest->hasLanguage()); $this->assertNull($this->geocoderRequest->getLanguage()); } - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder request language must be a string with two or five characters. - */ - public function testLanguageWithInvalidValue() - { - $this->geocoderRequest->setLanguage('foo'); - } - - public function testSensorWithValidValue() + public function testSetSensor() { $this->geocoderRequest->setSensor(true); $this->assertTrue($this->geocoderRequest->hasSensor()); } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder request sensor flag must be a boolean value. - */ - public function testSensorWithInvalidValue() - { - $this->geocoderRequest->setSensor('foo'); - } - - public function testIsValidWithoutAddressAndCoordinate() - { - $this->assertFalse($this->geocoderRequest->isValid()); - } - - public function testIsValidWithAddress() - { - $this->geocoderRequest->setAddress('address'); - - $this->assertTrue($this->geocoderRequest->isValid()); - } - - public function testIsValidWithCoordinate() - { - $this->geocoderRequest->setCoordinate(1, 1); - - $this->assertTrue($this->geocoderRequest->isValid()); - } } diff --git a/tests/Services/Geocoding/GeocoderResponseTest.php b/tests/Services/Geocoding/GeocoderResponseTest.php new file mode 100644 index 00000000..a130e812 --- /dev/null +++ b/tests/Services/Geocoding/GeocoderResponseTest.php @@ -0,0 +1,170 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderResponse; +use Ivory\GoogleMap\Services\Geocoding\GeocoderStatus; + +/** + * Geocoder response test. + * + * @author GeLo + */ +class GeocoderResponseTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderResponse */ + protected $geocoderResponse; + + /** @var array */ + protected $results; + + /** @var string */ + protected $status; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->geocoderResponse = new GeocoderResponse( + $this->results = array($this->createGeocoderResultMock()), + $this->status = GeocoderStatus::REQUEST_DENIED + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->geocoderResponse); + unset($this->results); + unset($this->status); + } + + public function testInitialState() + { + $this->assertTrue($this->geocoderResponse->hasResults()); + $this->assertSame($this->results, $this->geocoderResponse->getResults()); + $this->assertSame($this->status, $this->geocoderResponse->getStatus()); + } + + public function testSetResults() + { + $this->geocoderResponse->setResults($results = array($this->createGeocoderResultMock())); + + $this->assertResults($results); + } + + public function testAddResults() + { + $this->geocoderResponse->setResults($results = array($this->createGeocoderResultMock())); + $this->geocoderResponse->addResults($newResults = array($this->createGeocoderResultMock())); + + $this->assertResults(array_merge($results, $newResults)); + } + + public function testRemoveResults() + { + $this->geocoderResponse->setResults($results = array($this->createGeocoderResultMock())); + $this->geocoderResponse->removeResults($results); + + $this->assertNoResults(); + } + + public function testResetResults() + { + $this->geocoderResponse->setResults(array($this->createGeocoderResultMock())); + $this->geocoderResponse->resetResults(); + + $this->assertNoResults(); + } + + public function testAddResult() + { + $this->geocoderResponse->addResult($result = $this->createGeocoderResultMock()); + + $this->assertResult($result); + } + + public function testAddResultUnicity() + { + $this->geocoderResponse->resetResults(); + $this->geocoderResponse->addResult($result = $this->createGeocoderResultMock()); + $this->geocoderResponse->addResult($result); + + $this->assertResults(array($result)); + } + + public function testRemoveResult() + { + $this->geocoderResponse->addResult($result = $this->createGeocoderResultMock()); + $this->geocoderResponse->removeResult($result); + + $this->assertNoResult($result); + } + + public function testSetStatus() + { + $this->geocoderResponse->setStatus($status = GeocoderStatus::ERROR); + + $this->assertSame($status, $this->geocoderResponse->getStatus()); + } + + /** + * Asserts there are results. + * + * @param array $results The results. + */ + protected function assertResults($results) + { + $this->assertInternalType('array', $results); + + $this->assertTrue($this->geocoderResponse->hasResults()); + $this->assertSame($results, $this->geocoderResponse->getResults()); + + foreach ($results as $result) { + $this->assertResult($result); + } + } + + /** + * Asserts there is a result. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderResult $result The result. + */ + protected function assertResult($result) + { + $this->assertGeocoderResultInstance($result); + $this->assertTrue($this->geocoderResponse->hasResult($result)); + } + + /** + * Asserts there are no results. + */ + protected function assertNoResults() + { + $this->assertFalse($this->geocoderResponse->hasResults()); + $this->assertEmpty($this->geocoderResponse->getResults()); + } + + /** + * Asserts there is no result. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderResult $result The result. + */ + protected function assertNoResult($result) + { + $this->assertGeocoderResultInstance($result); + $this->assertFalse($this->geocoderResponse->hasResult($result)); + } +} diff --git a/tests/Services/Geocoding/GeocoderResultTest.php b/tests/Services/Geocoding/GeocoderResultTest.php new file mode 100644 index 00000000..6fcacf5b --- /dev/null +++ b/tests/Services/Geocoding/GeocoderResultTest.php @@ -0,0 +1,316 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderResult; + +/** + * Geocoder result test. + * + * @author GeLo + */ +class GeocoderResultTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderResult */ + protected $geocoderResult; + + /** @var array */ + protected $addressComponents; + + /** @var string */ + protected $formattedAddress; + + /** @var \Ivory\GoogleMap\Services\Geocoding\GeocoderGeometry|\PHPUnit_Framework_MockObject_MockObject */ + protected $geometry; + + /** @var boolean */ + protected $partialMatch; + + /** @var array */ + protected $types; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->geocoderResult = new GeocoderResult( + $this->addressComponents = array($this->createGeocoderAddressComponentMock()), + $this->formattedAddress = 'formattedAddress', + $this->geometry = $this->createGeocoderGeometryMock(), + $this->types = array('type'), + $this->partialMatch = true + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->geocoderResult); + unset($this->addressComponents); + unset($this->geometry); + unset($this->types); + unset($this->partialMatch); + } + + public function testInitialState() + { + $this->assertTrue($this->geocoderResult->hasAddressComponents()); + $this->assertSame($this->addressComponents, $this->geocoderResult->getAddressComponents()); + + $this->assertSame($this->formattedAddress, $this->geocoderResult->getFormattedAddress()); + $this->assertSame($this->geometry, $this->geocoderResult->getGeometry()); + + $this->assertTrue($this->geocoderResult->hasTypes()); + $this->assertSame($this->types, $this->geocoderResult->getTypes()); + + $this->assertTrue($this->geocoderResult->hasPartialMatch()); + $this->assertSame($this->partialMatch, $this->geocoderResult->isPartialMatch()); + } + + public function testSetAddressComponents() + { + $this->geocoderResult->setAddressComponents($addressComponents = array($this->createGeocoderAddressComponentMock())); + + $this->assertAddressComponents($addressComponents); + } + + public function testAddAddressComponents() + { + $this->geocoderResult->setAddressComponents($addressComponents = array($this->createGeocoderAddressComponentMock())); + $this->geocoderResult->addAddressComponents($newAddressComponents = array($this->createGeocoderAddressComponentMock())); + + $this->assertAddressComponents(array_merge($addressComponents, $newAddressComponents)); + } + + public function testRemoveAddressComponents() + { + $this->geocoderResult->setAddressComponents($addressComponents = array($this->createGeocoderAddressComponentMock())); + $this->geocoderResult->removeAddressComponents($addressComponents); + + $this->assertNoAddressComponents(); + } + + public function testResetAddressComponents() + { + $this->geocoderResult->setAddressComponents(array($this->createGeocoderAddressComponentMock())); + $this->geocoderResult->resetAddressComponents(); + + $this->assertNoAddressComponents(); + } + + public function testAddAddressComponent() + { + $this->geocoderResult->addAddressComponent($addressComponent = $this->createGeocoderAddressComponentMock()); + + $this->assertAddressComponent($addressComponent); + } + + public function testAddAddressComponentUnicity() + { + $this->geocoderResult->resetAddressComponents(); + $this->geocoderResult->addAddressComponent($addressComponent = $this->createGeocoderAddressComponentMock()); + $this->geocoderResult->addAddressComponent($addressComponent); + + $this->assertAddressComponents(array($addressComponent)); + } + + public function testRemoveAddressComponent() + { + $this->geocoderResult->addAddressComponent($addressComponent = $this->createGeocoderAddressComponentMock()); + $this->geocoderResult->removeAddressComponent($addressComponent); + + $this->assertNoAddressComponent($addressComponent); + } + + public function testSetFormattedAddress() + { + $this->geocoderResult->setFormattedAddress($formattedAddress = 'foo'); + + $this->assertSame($formattedAddress, $this->geocoderResult->getFormattedAddress()); + } + + public function testSetGeometry() + { + $this->geocoderResult->setGeometry($geometry = $this->createGeocoderGeometryMock()); + + $this->assertSame($geometry, $this->geocoderResult->getGeometry()); + } + + public function testSetPartialMatch() + { + $this->geocoderResult->setPartialMatch(false); + + $this->assertTrue($this->geocoderResult->hasPartialMatch()); + $this->assertFalse($this->geocoderResult->isPartialMatch()); + } + + public function testResetPartialMatch() + { + $this->geocoderResult->setPartialMatch(false); + $this->geocoderResult->setPartialMatch(null); + + $this->assertFalse($this->geocoderResult->hasPartialMatch()); + $this->assertNull($this->geocoderResult->isPartialMatch()); + } + + public function testSetTypes() + { + $this->geocoderResult->setTypes($types = array('foo')); + + $this->assertTypes($types); + } + + public function testAddTypes() + { + $this->geocoderResult->setTypes($types = array('foo')); + $this->geocoderResult->addTypes($newTypes = array('bar')); + + $this->assertTypes(array_merge($types, $newTypes)); + } + + public function testRemoveTypes() + { + $this->geocoderResult->setTypes($types = array('foo')); + $this->geocoderResult->removeTypes($types); + + $this->assertNoTypes(); + } + + public function testResetTypes() + { + $this->geocoderResult->setTypes(array('foo')); + $this->geocoderResult->resetTypes(); + + $this->assertNoTypes(); + } + + public function testAddType() + { + $this->geocoderResult->addType($type = 'foo'); + + $this->assertType($type); + } + + public function testAddTypeUnicity() + { + $this->geocoderResult->resetTypes(); + $this->geocoderResult->addType($type = 'foo'); + $this->geocoderResult->addType($type); + + $this->assertTypes(array($type)); + } + + public function testRemoveType() + { + $this->geocoderResult->addType($type = 'foo'); + $this->geocoderResult->removeType($type); + + $this->assertNoType($type); + } + + /** + * Asserts there are address components. + * + * @param array $addressComponents The address components. + */ + protected function assertAddressComponents($addressComponents) + { + $this->assertInternalType('array', $addressComponents); + + $this->assertTrue($this->geocoderResult->hasAddressComponents()); + $this->assertSame($addressComponents, $this->geocoderResult->getAddressComponents()); + + foreach ($addressComponents as $addressComponent) { + $this->assertAddressComponent($addressComponent); + } + } + + /** + * Asserts there is a address component. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent $addressComponent The address component. + */ + protected function assertAddressComponent($addressComponent) + { + $this->assertGeocoderAddressComponentInstance($addressComponent); + $this->assertTrue($this->geocoderResult->hasAddressComponent($addressComponent)); + } + + /** + * Asserts there are no address components. + */ + protected function assertNoAddressComponents() + { + $this->assertFalse($this->geocoderResult->hasAddressComponents()); + $this->assertEmpty($this->geocoderResult->getAddressComponents()); + } + + /** + * Asserts there is no address component. + * + * @param \Ivory\GoogleMap\Services\Geocoding\GeocoderAddressComponent $addressComponent The address component. + */ + protected function assertNoAddressComponent($addressComponent) + { + $this->assertGeocoderAddressComponentInstance($addressComponent); + $this->assertFalse($this->geocoderResult->hasAddressComponent($addressComponent)); + } + + /** + * Asserts there are types. + * + * @param array $types The types. + */ + protected function assertTypes($types) + { + $this->assertInternalType('array', $types); + + $this->assertTrue($this->geocoderResult->hasTypes()); + $this->assertSame($types, $this->geocoderResult->getTypes()); + + foreach ($types as $type) { + $this->assertType($type); + } + } + + /** + * Asserts there is a type. + * + * @param string $type The type. + */ + protected function assertType($type) + { + $this->assertTrue($this->geocoderResult->hasType($type)); + } + + /** + * Asserts there are no types. + */ + protected function assertNoTypes() + { + $this->assertFalse($this->geocoderResult->hasTypes()); + $this->assertEmpty($this->geocoderResult->getTypes()); + } + + /** + * Asserts there is no type. + * + * @param string $type The type. + */ + protected function assertNoType($type) + { + $this->assertFalse($this->geocoderResult->hasType($type)); + } +} diff --git a/tests/Services/Geocoding/GeocoderStatusTest.php b/tests/Services/Geocoding/GeocoderStatusTest.php new file mode 100644 index 00000000..107fb5df --- /dev/null +++ b/tests/Services/Geocoding/GeocoderStatusTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services\Geocoding; + +use Ivory\GoogleMap\Services\Geocoding\GeocoderStatus; + +/** + * Geocoder status test. + * + * @author GeLo + */ +class GeocoderStatusTest extends AbstractTestCase +{ + public function testInheritance() + { + $this->assertUninstantiableAssetInstance('Ivory\GoogleMap\Services\Geocoding\GeocoderStatus'); + } + + public function testConstants() + { + $this->assertSame('ERROR', GeocoderStatus::ERROR); + $this->assertSame('INVALID_REQUEST', GeocoderStatus::INVALID_REQUEST); + $this->assertSame('OK', GeocoderStatus::OK); + $this->assertSame('OVER_QUERY_LIMIT', GeocoderStatus::OVER_QUERY_LIMIT); + $this->assertSame('REQUEST_DENIED', GeocoderStatus::REQUEST_DENIED); + $this->assertSame('UNKNOWN_ERROR', GeocoderStatus::UNKNOWN_ERROR); + $this->assertSame('ZERO_RESULTS', GeocoderStatus::ZERO_RESULTS); + } +} diff --git a/tests/Services/Geocoding/GeocoderTest.php b/tests/Services/Geocoding/GeocoderTest.php index 34122b1c..9c7f868b 100644 --- a/tests/Services/Geocoding/GeocoderTest.php +++ b/tests/Services/Geocoding/GeocoderTest.php @@ -11,17 +11,14 @@ namespace Ivory\Tests\GoogleMap\Services\Geocoding; -use Geocoder\HttpAdapter\CurlHttpAdapter; -use Geocoder\Provider\GoogleMapsProvider; use Ivory\GoogleMap\Services\Geocoding\Geocoder; -use Ivory\GoogleMap\Services\Geocoding\GeocoderProvider; /** * Geocoder test. * * @author GeLo */ -class GeocoderTest extends \PHPUnit_Framework_TestCase +class GeocoderTest extends AbstractTestCase { /** @var \Ivory\GoogleMap\Services\Geocoding\Geocoder */ protected $geocoder; @@ -34,22 +31,6 @@ protected function setUp() $this->geocoder = new Geocoder(); } - /** - * Set up a geocoder provider. - */ - protected function setUpGeocoderProvider() - { - $this->geocoder->registerProvider(new GoogleMapsProvider(new CurlHttpAdapter())); - } - - /** - * Set up the Ivory provider. - */ - protected function setUpIvoryProvider() - { - $this->geocoder->registerProvider(new GeocoderProvider(new CurlHttpAdapter())); - } - /** * {@inheritdoc} */ @@ -60,35 +41,95 @@ protected function tearDown() public function testGeocodeWithGeocoderProvider() { - $this->setUpGeocoderProvider(); + $this->geocoder->registerProvider($provider = $this->createGoogleMapsProviderMock()); + + $provider + ->expects($this->any()) + ->method('getGeocodedData') + ->with($this->identicalTo($request = 'foo')) + ->will($this->returnValue(array(array('bar')))); - $this->assertInstanceOf('Geocoder\Result\Geocoded', $this->geocoder->geocode('Paris')); + $this->assertGeocodedInstance($this->geocoder->geocode($request)); } public function testGeocodeWithIvoryProvider() { - $this->setUpIvoryProvider(); + $this->geocoder->registerProvider($provider = $this->createGeocoderProviderMock()); + + $provider + ->expects($this->any()) + ->method('getGeocodedData') + ->with($this->identicalTo($request = $this->createGeocoderRequestMock())) + ->will($this->returnValue($response = 'foo')); - $this->assertInstanceOf( - 'Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', - $this->geocoder->geocode('Paris') - ); + $this->assertSame($response, $this->geocoder->geocode($request)); } public function testReverseWithGeocoderProvider() { - $this->setUpGeocoderProvider(); + $this->geocoder->registerProvider($provider = $this->createGoogleMapsProviderMock()); - $this->assertInstanceOf('Geocoder\Result\Geocoded', $this->geocoder->reverse(48.856633, 2.352254)); + $provider + ->expects($this->any()) + ->method('getReversedData') + ->with($this->identicalTo(array($longitude = 48.856633, $latitude = 2.352254))) + ->will($this->returnValue(array(array('foo')))); + + $this->assertGeocodedInstance($this->geocoder->reverse($longitude, $latitude)); } public function testReverseWithIvoryProvider() { - $this->setUpIvoryProvider(); + $this->geocoder->registerProvider($provider = $this->createGeocoderProviderMock()); + + $provider + ->expects($this->any()) + ->method('getReversedData') + ->with($this->identicalTo(array($longitude = 48.856633, $latitude = 2.352254))) + ->will($this->returnValue($response = 'foo')); + + $this->assertSame($response, $this->geocoder->reverse($longitude, $latitude)); + } - $this->assertInstanceOf( - 'Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse', - $this->geocoder->reverse(48.856633, 2.352254) - ); + protected function assertGeocodedInstance($geocoded) + { + $this->assertInstanceOf('Geocoder\Result\Geocoded', $geocoded); + } + + protected function createGoogleMapsProviderMock() + { + $provider = $this->getMockBuilder('Geocoder\Provider\GoogleMapsProvider') + ->disableOriginalConstructor() + ->getMock(); + + $provider + ->expects($this->any()) + ->method('setMaxResults') + ->with($this->anything()) + ->will($this->returnSelf()); + + $provider + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue('geocoder')); + + return $provider; + } + + protected function createGeocoderProviderMock() + { + $provider = parent::createGeocoderProviderMock(); + $provider + ->expects($this->any()) + ->method('setMaxResults') + ->with($this->anything()) + ->will($this->returnSelf()); + + $provider + ->expects($this->any()) + ->method('getName') + ->will($this->returnValue('ivory')); + + return $provider; } } diff --git a/tests/Services/Geocoding/Result/GeocoderAddressComponentTest.php b/tests/Services/Geocoding/Result/GeocoderAddressComponentTest.php deleted file mode 100644 index 057eac30..00000000 --- a/tests/Services/Geocoding/Result/GeocoderAddressComponentTest.php +++ /dev/null @@ -1,117 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent; - -/** - * Geocoder address component test. - * - * @author GeLo - */ -class GeocoderAddressComponentTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent */ - protected $geocoderAddressComponent; - - /** @var string */ - protected $longName; - - /** @var string */ - protected $shortName; - - /** @var array */ - protected $types; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->longName = 'long_name'; - $this->shortName = 'short_name'; - $this->types = array('foo', 'bar'); - - $this->geocoderAddressComponent = new GeocoderAddressComponent( - $this->longName, - $this->shortName, - $this->types - ); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->geocoderAddressComponent); - unset($this->longName); - unset($this->shortName); - unset($this->types); - } - - public function testInitialState() - { - $this->assertSame($this->longName, $this->geocoderAddressComponent->getLongName()); - $this->assertSame($this->shortName, $this->geocoderAddressComponent->getShortName()); - $this->assertSame($this->types, $this->geocoderAddressComponent->getTypes()); - } - - public function testLongNameWithValidValue() - { - $this->geocoderAddressComponent->setLongName('longname'); - - $this->assertSame('longname', $this->geocoderAddressComponent->getLongName()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder address component long name must be a string value. - */ - public function testLongNameWithInvalidValue() - { - $this->geocoderAddressComponent->setLongName(true); - } - - public function testShortNameWithValidValue() - { - $this->geocoderAddressComponent->setShortName('shortname'); - - $this->assertSame('shortname', $this->geocoderAddressComponent->getShortName()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder address component short name must be a string value. - */ - public function testShortNameWithInvalidValue() - { - $this->geocoderAddressComponent->setShortName(true); - } - - public function testTypesWithValidValue() - { - $types = array('type1', 'type2'); - $this->geocoderAddressComponent->setTypes($types); - - $this->assertSame($types, $this->geocoderAddressComponent->getTypes()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder address component type must be a string value. - */ - public function testTypesWithInvalidValue() - { - $this->geocoderAddressComponent->addType(true); - } -} diff --git a/tests/Services/Geocoding/Result/GeocoderGeometryTest.php b/tests/Services/Geocoding/Result/GeocoderGeometryTest.php deleted file mode 100644 index 3995a3ad..00000000 --- a/tests/Services/Geocoding/Result/GeocoderGeometryTest.php +++ /dev/null @@ -1,114 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderLocationType; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry; - -/** - * Geocoder geometry test. - * - * @author GeLo - */ -class GeocoderGeometryTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry */ - protected $geocoderGeometry; - - /** @var \Ivory\GoogleMap\Base\Coordinate */ - protected $location; - - /** @var string */ - protected $locationType; - - /** @var \Ivory\GoogleMap\Base\Bound */ - protected $viewport; - - /** @var \Ivory\GoogleMap\Base\Bound */ - protected $bound; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->location = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->locationType = GeocoderLocationType::RANGE_INTERPOLATED; - $this->viewport = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - - $this->geocoderGeometry = new GeocoderGeometry( - $this->location, - $this->locationType, - $this->viewport, - $this->bound - ); - } - - protected function tearDown() - { - unset($this->geocoderGeometry); - unset($this->location); - unset($this->locationType); - unset($this->viewport); - unset($this->bound); - } - - public function testInitialState() - { - $this->assertSame($this->location, $this->geocoderGeometry->getLocation()); - $this->assertSame($this->locationType, $this->geocoderGeometry->getLocationType()); - $this->assertSame($this->viewport, $this->geocoderGeometry->getViewport()); - $this->assertSame($this->bound, $this->geocoderGeometry->getBound()); - } - - public function testLocation() - { - $location = $this->getMock('Ivory\GoogleMap\Base\Coordinate'); - $this->geocoderGeometry->setLocation($location); - - $this->assertSame($location, $this->geocoderGeometry->getLocation()); - } - - public function testLocationTypeWithValidValue() - { - $this->geocoderGeometry->setLocationType(GeocoderLocationType::GEOMETRIC_CENTER); - - $this->assertSame(GeocoderLocationType::GEOMETRIC_CENTER, $this->geocoderGeometry->getLocationType()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder geometry location type can only be : APPROXIMATE, GEOMETRIC_CENTER, - * RANGE_INTERPOLATED, ROOFTOP. - */ - public function testLocationTypeWithInvalidValue() - { - $this->geocoderGeometry->setLocationType('foo'); - } - - public function testViewport() - { - $viewport = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->geocoderGeometry->setViewport($viewport); - - $this->assertSame($viewport, $this->geocoderGeometry->getViewport()); - } - - public function testBound() - { - $bound = $this->getMock('Ivory\GoogleMap\Base\Bound'); - $this->geocoderGeometry->setBound($bound); - - $this->assertSame($bound, $this->geocoderGeometry->getBound()); - } -} diff --git a/tests/Services/Geocoding/Result/GeocoderLocationTypeTest.php b/tests/Services/Geocoding/Result/GeocoderLocationTypeTest.php deleted file mode 100644 index 8f4c8f68..00000000 --- a/tests/Services/Geocoding/Result/GeocoderLocationTypeTest.php +++ /dev/null @@ -1,34 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderLocationType; - -/** - * Geocoder location type test. - * - * @author GeLo - */ -class GeocoderLocationTypeTest extends \PHPUnit_Framework_TestCase -{ - public function testGeocoderLocationtypes() - { - $expected = array( - GeocoderLocationType::APPROXIMATE, - GeocoderLocationType::GEOMETRIC_CENTER, - GeocoderLocationType::RANGE_INTERPOLATED, - GeocoderLocationType::ROOFTOP, - ); - - $this->assertSame($expected, GeocoderLocationType::getGeocoderLocationTypes()); - } -} diff --git a/tests/Services/Geocoding/Result/GeocoderResponseTest.php b/tests/Services/Geocoding/Result/GeocoderResponseTest.php deleted file mode 100644 index 0af94168..00000000 --- a/tests/Services/Geocoding/Result/GeocoderResponseTest.php +++ /dev/null @@ -1,93 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse; -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderStatus; - -/** - * Geocoder response test. - * - * @author GeLo - */ -class GeocoderResponseTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResponse */ - protected $geocoderResponse; - - /** @var array */ - protected $results; - - /** @var string */ - protected $status; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $geocoderResult = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult') - ->disableOriginalConstructor() - ->getMock(); - - $this->results = array($geocoderResult); - $this->status = GeocoderStatus::REQUEST_DENIED; - - $this->geocoderResponse = new GeocoderResponse($this->results, $this->status); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->geocoderResponse); - unset($this->results); - unset($this->status); - } - - public function testInitialState() - { - $this->assertSame($this->results, $this->geocoderResponse->getResults()); - $this->assertSame($this->status, $this->geocoderResponse->getStatus()); - } - - public function testResults() - { - $geocoderResult = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult') - ->disableOriginalConstructor() - ->getMock(); - - $results = array($geocoderResult); - - $this->geocoderResponse->setResults($results); - - $this->assertSame($results, $this->geocoderResponse->getResults()); - } - - public function testStatusWithValidValue() - { - $this->geocoderResponse->setStatus(GeocoderStatus::ERROR); - - $this->assertSame(GeocoderStatus::ERROR, $this->geocoderResponse->getStatus()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder response status can only be : ERROR, INVALID_REQUEST, OK, - * OVER_QUERY_LIMIT, REQUEST_DENIED, UNKNOWN_ERROR, ZERO_RESULTS. - */ - public function testStatusWithInvalidValue() - { - $this->geocoderResponse->setStatus('foo'); - } -} diff --git a/tests/Services/Geocoding/Result/GeocoderResultTest.php b/tests/Services/Geocoding/Result/GeocoderResultTest.php deleted file mode 100644 index ef3945e8..00000000 --- a/tests/Services/Geocoding/Result/GeocoderResultTest.php +++ /dev/null @@ -1,181 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult; - -/** - * Geocoder result test. - * - * @author GeLo - */ -class GeocoderResultTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderResult */ - protected $geocoderResult; - - /** @var array */ - protected $addressComponents; - - /** @var string */ - protected $formattedAddress; - - /** @var \Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry */ - protected $geometry; - - /** @var boolean */ - protected $partialMatch; - - /** @var array */ - protected $types; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $addressComponent = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent') - ->disableOriginalConstructor() - ->getMock(); - - $this->addressComponents = array($addressComponent); - $this->formattedAddress = 'formattedAddress'; - - $this->geometry = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry') - ->disableOriginalConstructor() - ->getMock(); - - $this->partialMatch = true; - $this->types = array('foo', 'bar'); - - $this->geocoderResult = new GeocoderResult( - $this->addressComponents, - $this->formattedAddress, - $this->geometry, - $this->types, - $this->partialMatch - ); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->geocoderResult); - unset($this->addressComponents); - unset($this->geometry); - unset($this->types); - unset($this->partialMatch); - } - - public function testInitialState() - { - $this->assertSame($this->addressComponents, $this->geocoderResult->getAddressComponents()); - $this->assertSame($this->formattedAddress, $this->geocoderResult->getFormattedAddress()); - $this->assertSame($this->geometry, $this->geocoderResult->getGeometry()); - $this->assertSame($this->types, $this->geocoderResult->getTypes()); - $this->assertSame($this->partialMatch, $this->geocoderResult->isPartialMatch()); - } - - public function testAddressComponentsWithoutType() - { - $addressComponent = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent') - ->disableOriginalConstructor() - ->getMock(); - - $addressComponents = array($addressComponent); - - $this->geocoderResult->setAddressComponents($addressComponents); - - $this->assertSame($addressComponents, $this->geocoderResult->getAddressComponents()); - } - - public function testAddressComponentsWithType() - { - $addressComponent = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderAddressComponent') - ->disableOriginalConstructor() - ->getMock(); - - $addressComponent - ->expects($this->any()) - ->method('getTypes') - ->will($this->returnValue(array('foo'))); - - $addressComponents = array($addressComponent); - - $this->geocoderResult->setAddressComponents($addressComponents); - - $this->assertSame($addressComponents, $this->geocoderResult->getAddressComponents('foo')); - $this->assertEmpty($this->geocoderResult->getAddressComponents('bar')); - } - - public function testFormattedAddressWithValidValue() - { - $this->geocoderResult->setFormattedAddress('formatted_address'); - - $this->assertSame('formatted_address', $this->geocoderResult->getFormattedAddress()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder result formatted address must be a string value. - */ - public function testFormattedAddressWithInvalidValue() - { - $this->geocoderResult->setFormattedAddress(true); - } - - public function testGeometry() - { - $geometry = $this->getMockBuilder('Ivory\GoogleMap\Services\Geocoding\Result\GeocoderGeometry') - ->disableOriginalConstructor() - ->getMock(); - - $this->geocoderResult->setGeometry($geometry); - - $this->assertSame($geometry, $this->geocoderResult->getGeometry()); - } - - public function testPartialMatchWithValidValue() - { - $this->geocoderResult->setPartialMatch(false); - - $this->assertFalse($this->geocoderResult->isPartialMatch()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder result partial match flag must be a boolean value. - */ - public function testPartialMatchWithInvalidValue() - { - $this->geocoderResult->setPartialMatch('foo'); - } - - public function testTypeWithValidValue() - { - $types = array('type_1', 'type_2'); - $this->geocoderResult->setTypes($types); - - $this->assertSame($types, $this->geocoderResult->getTypes()); - } - - /** - * @expectedException \Ivory\GoogleMap\Exception\GeocodingException - * @expectedExceptionMessage The geocoder result type must be a string value. - */ - public function testTypeWithInvalidValue() - { - $this->geocoderResult->addType(true); - } -} diff --git a/tests/Services/Geocoding/Result/GeocoderStatusTest.php b/tests/Services/Geocoding/Result/GeocoderStatusTest.php deleted file mode 100644 index b140b9c1..00000000 --- a/tests/Services/Geocoding/Result/GeocoderStatusTest.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Geocoding\Result; - -use Ivory\GoogleMap\Services\Geocoding\Result\GeocoderStatus; - -/** - * Geocoder status test. - * - * @author GeLo - */ -class GeocoderStatusTest extends \PHPUnit_Framework_TestCase -{ - public function testGeocoderStatus() - { - $expected = array( - GeocoderStatus::ERROR, - GeocoderStatus::INVALID_REQUEST, - GeocoderStatus::OK, - GeocoderStatus::OVER_QUERY_LIMIT, - GeocoderStatus::REQUEST_DENIED, - GeocoderStatus::UNKNOWN_ERROR, - GeocoderStatus::ZERO_RESULTS - ); - - $this->assertSame($expected, GeocoderStatus::getGeocoderStatus()); - } -} diff --git a/tests/Services/ServiceTest.php b/tests/Services/ServiceTest.php new file mode 100644 index 00000000..e64d55fa --- /dev/null +++ b/tests/Services/ServiceTest.php @@ -0,0 +1,157 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services; + +use Ivory\GoogleMap\Services\AbstractService; + +/** + * Service test. + * + * @author GeLo + */ +class ServiceTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\AbstractService */ + protected $service; + + /** @var \Ivory\HttpAdapter\HttpAdapterInterface|\PHPUnit_Framework_MockObject_MockObject */ + protected $httpAdapter; + + /** @var string */ + protected $url; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->service = $this->createServiceMockBuilder() + ->setConstructorArgs(array($this->httpAdapter = $this->createHttpAdapterMock(), $this->url = 'http://foo')) + ->getMockForAbstractClass(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->url); + unset($this->httpAdapter); + unset($this->service); + } + + public function testDefaultState() + { + $this->assertSame($this->httpAdapter, $this->service->getHttpAdapter()); + $this->assertSame($this->url, $this->service->getUrl()); + $this->assertFalse($this->service->isHttps()); + $this->assertSame(AbstractService::FORMAT_JSON, $this->service->getFormat()); + $this->assertXmlParserInstance($this->service->getXmlParser()); + $this->assertFalse($this->service->hasBusinessAccount()); + $this->assertNull($this->service->getBusinessAccount()); + } + + public function testInitialState() + { + $this->service = $this->createServiceMockBuilder() + ->setConstructorArgs(array( + $this->httpAdapter, + $this->url, + true, + $format = AbstractService::FORMAT_XML, + $xmlParser = $this->createXmlParserMock(), + $businessAccount = $this->createBusinessAccountMock() + )) + ->getMockForAbstractClass(); + + $this->assertTrue($this->service->isHttps()); + $this->assertSame($format, $this->service->getFormat()); + $this->assertSame($xmlParser, $this->service->getXmlParser()); + $this->assertTrue($this->service->hasBusinessAccount()); + $this->assertSame($businessAccount, $this->service->getBusinessAccount()); + } + + public function testSetHttpAdapter() + { + $this->service->setHttpAdapter($httpAdapter = $this->createHttpAdapterMock()); + + $this->assertSame($httpAdapter, $this->service->getHttpAdapter()); + } + + public function testSetHttps() + { + $this->service->setHttps(true); + + $this->assertTrue($this->service->isHttps()); + $this->assertSame('https://foo', $this->service->getUrl()); + } + + public function testSetFormat() + { + $this->service->setFormat($format = AbstractService::FORMAT_XML); + + $this->assertSame($format, $this->service->getFormat()); + } + + public function testSetXmlParser() + { + $this->service->setXmlParser($xmlParser = $this->createXmlParserMock()); + + $this->assertSame($xmlParser, $this->service->getXmlParser()); + } + + public function testSetBusinessAccount() + { + $this->service->setBusinessAccount($businessAccount = $this->createBusinessAccountMock()); + + $this->assertTrue($this->service->hasBusinessAccount()); + $this->assertSame($businessAccount, $this->service->getBusinessAccount()); + } + + public function testResetBusinessAccount() + { + $this->service->setBusinessAccount($this->createBusinessAccountMock()); + $this->service->setBusinessAccount(null); + + $this->assertFalse($this->service->hasBusinessAccount()); + $this->assertNull($this->service->getBusinessAccount()); + } + + public function testSignUrlWithoutBusinessAccount() + { + $method = new \ReflectionMethod($this->service, 'signUrl'); + $method->setAccessible(true); + + $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; + + $this->assertSame($url, $method->invoke($this->service, $url)); + } + + public function testSignUrlWithBusinessAccount() + { + $url = 'http://maps.googleapis.com/maps/api/staticmap?center=%E4%B8%8A%E6%B5%B7+%E4%B8%AD%E5%9C%8B&size=640x640&zoom=10&sensor=false'; + + $businessAccount = $this->createBusinessAccountMock(); + $businessAccount + ->expects($this->once()) + ->method('signUrl') + ->with($this->equalTo($url)) + ->will($this->returnValue($signedUrl = 'url')); + + $this->service->setBusinessAccount($businessAccount); + + $method = new \ReflectionMethod($this->service, 'signUrl'); + $method->setAccessible(true); + + $this->assertSame($signedUrl, $method->invoke($this->service, $url)); + } +} diff --git a/tests/Services/Utils/XmlParserTest.php b/tests/Services/Utils/XmlParserTest.php deleted file mode 100644 index e0c2aa2c..00000000 --- a/tests/Services/Utils/XmlParserTest.php +++ /dev/null @@ -1,62 +0,0 @@ - - * - * For the full copyright and license information, please read the LICENSE - * file that was distributed with this source code. - */ - -namespace Ivory\Tests\GoogleMap\Services\Utils; - -use Ivory\GoogleMap\Services\Utils\XmlParser; - -/** - * Xml parser test. - * - * @author GeLo - */ -class XmlParserTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Ivory\GoogleMap\Services\Utils\XmlParser */ - protected $xmlParser; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->xmlParser = new XmlParser(); - } - - /** - * {@inheritdoc} - */ - protected function tearDown() - { - unset($this->xmlParser); - } - - public function testParse() - { - $xml = 'bar'; - - $expected = new \stdClass(); - $expected->foo = 'bar'; - - $this->assertEquals($expected, $this->xmlParser->parse($xml)); - } - - public function testParsePluralized() - { - $xml = 'bar'; - $rules = array('foo' => 'foos'); - - $expected = new \stdClass(); - $expected->foos = array('bar'); - - $this->assertEquals($expected, $this->xmlParser->parse($xml, $rules)); - } -} diff --git a/tests/Services/XmlParserTest.php b/tests/Services/XmlParserTest.php new file mode 100644 index 00000000..79b2571e --- /dev/null +++ b/tests/Services/XmlParserTest.php @@ -0,0 +1,68 @@ + + * + * For the full copyright and license information, please read the LICENSE + * file that was distributed with this source code. + */ + +namespace Ivory\Tests\GoogleMap\Services; + +use Ivory\GoogleMap\Services\XmlParser; + +/** + * Xml parser test. + * + * @author GeLo + */ +class XmlParserTest extends AbstractTestCase +{ + /** @var \Ivory\GoogleMap\Services\XmlParser */ + protected $xmlParser; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->xmlParser = new XmlParser(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + unset($this->xmlParser); + } + + /** + * @dataProvider parseProvider + */ + public function testParse($xml, $pluralizationRules, $expected) + { + $this->assertSame($expected, $this->xmlParser->parse($xml, $pluralizationRules)); + } + + /** + * Gets the parse provider. + * + * @return array The parse provider. + */ + public function parseProvider() + { + return array( + array('bar', array(), array('foo' => 'bar')), + array('barbaz', array(), array('foo' => array('bar', 'baz'))), + array('bar', array('foo' => 'foos'), array('foos' => array('bar'))), + array( + 'barbaz', + array('foo' => 'foos'), + array('foos' => array('bar', 'baz')), + ), + ); + } +}