├── .github
└── workflows
│ └── main.yml
├── .gitignore
├── .styleci.yml
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── composer.json
├── composer.lock
├── config
└── config.php
├── phpunit.xml
├── resources
└── views
│ ├── components
│ ├── google.blade.php
│ └── leaflet.blade.php
│ └── tests
│ └── views
│ ├── basic-leaflet.blade.php
│ ├── with-a-centerpoint-set-leaflet.blade.php
│ └── with-zoom-set-leaflet.blade.php
├── src
├── Components
│ ├── Google.php
│ └── Leaflet.php
├── LaravelMaps.php
├── LaravelMapsFacade.php
└── LaravelMapsServiceProvider.php
└── tests
├── TestCase.php
├── TestView.php
└── Unit
├── ExampleTest.php
├── GoogleMapsTest.php
└── LeafletTest.php
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: run-tests
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 | pull_request:
8 | branches:
9 | - master
10 |
11 | jobs:
12 | test:
13 | runs-on: ${{ matrix.os }}
14 |
15 | strategy:
16 | fail-fast: true
17 | matrix:
18 | os: [ubuntu-latest]
19 | php: [8.1, 8.2, 8.3]
20 | laravel: ['9.*', '10.*', '11.*', '12.*']
21 | stability: [prefer-stable]
22 | include:
23 | - laravel: 9.*
24 | testbench: ^7.0
25 | - laravel: 10.*
26 | testbench: ^8.0
27 | - laravel: 11.*
28 | testbench: ^9.0
29 | - laravel: 12.*
30 | testbench: ^10.0
31 | exclude:
32 | - laravel: 11.*
33 | php: 8.1
34 | - laravel: 10.*
35 | php: 8.0
36 | - laravel: 9.*
37 | php: 7.4
38 | - laravel: 12.*
39 | php: 8.1
40 |
41 | name: PHP${{ matrix.php }} - LARAVEL${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
42 |
43 | steps:
44 | - name: Checkout code
45 | uses: actions/checkout@v3
46 |
47 | - name: Setup PHP
48 | uses: shivammathur/setup-php@v2
49 | with:
50 | php-version: ${{ matrix.php }}
51 | extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
52 | coverage: none
53 |
54 | - name: Setup problem matchers
55 | run: |
56 | echo "::add-matcher::${{ runner.tool_cache }}/php.json"
57 | echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
58 |
59 | - name: Install dependencies
60 | run: |
61 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
62 | composer update --${{ matrix.stability }} --prefer-dist --no-interaction
63 |
64 | - name: Execute tests
65 | run: vendor/bin/phpunit
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | vendor/*
3 | .phpunit.result.cache
4 | node_modules
5 |
--------------------------------------------------------------------------------
/.styleci.yml:
--------------------------------------------------------------------------------
1 | preset: laravel
2 |
3 | disabled:
4 | - single_class_element_per_statement
5 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to `laravel-maps` will be documented in this file
4 |
5 | ## 1.0.0 - 201X-XX-XX
6 |
7 | - initial release
8 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are **welcome** and will be fully **credited**.
4 |
5 | Please read and understand the contribution guide before creating an issue or pull request.
6 |
7 | ## Etiquette
8 |
9 | This project is open source, and as such, the maintainers give their free time to build and maintain the source code
10 | held within. They make the code freely available in the hope that it will be of use to other developers. It would be
11 | extremely unfair for them to suffer abuse or anger for their hard work.
12 |
13 | Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
14 | world that developers are civilized and selfless people.
15 |
16 | It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
17 | quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
18 |
19 | ## Viability
20 |
21 | When requesting or submitting new features, first consider whether it might be useful to others. Open
22 | source projects are used by many developers, who may have entirely different needs to your own. Think about
23 | whether or not your feature is likely to be used by other users of the project.
24 |
25 | ## Procedure
26 |
27 | Before filing an issue:
28 |
29 | - Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
30 | - Check to make sure your feature suggestion isn't already present within the project.
31 | - Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
32 | - Check the pull requests tab to ensure that the feature isn't already in progress.
33 |
34 | Before submitting a pull request:
35 |
36 | - Check the codebase to ensure that your feature doesn't already exist.
37 | - Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
38 |
39 | ## Requirements
40 |
41 | If the project maintainer has any additional requirements, you will find them listed here.
42 |
43 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
44 |
45 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests.
46 |
47 | - **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
48 |
49 | - **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
50 |
51 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
52 |
53 | - **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
54 |
55 | **Happy coding**!
56 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Lars Wiegers
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Laravel maps
2 |
3 | [](https://packagist.org/packages/larswiegers/laravel-maps)
4 | [](https://packagist.org/packages/larswiegers/laravel-maps)
5 | 
6 |
7 | 
8 |
9 | This package allows you to easily use leaflet.js or google maps to create a map in your laravel project.
10 |
11 | ## Installation
12 |
13 | You can install the package via composer:
14 |
15 | ```bash
16 | composer require larswiegers/laravel-maps
17 | ```
18 |
19 | If you want to customize the map views more then you can publish the views:
20 |
21 | ```bash
22 | php artisan vendor:publish --provider="Larswiegers\LaravelMaps\LaravelMapsServiceProvider"
23 | ```
24 |
25 | ## Supported map types
26 | | What | Basic map | Different map types | Centerpoint | Basic markers | Use bounds | Zoomlevel | Can use different tiles | Can be used multiple times on the same page |
27 | | ----------- | :-------: | :-----------------: | :---------: | :-----------: | :--------: | :-------: | :---------------------: | :------------------------------------------ |
28 | | Leaflet | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
29 | | Google maps | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
30 |
31 | #### Tilehosts
32 | ##### Openstreetmap
33 | Openstreetmap is a creative commence tile library created by volunteers.
34 | No configuration has to be set to use as it is the default tilehost for this library.
35 | More information can be found here: [openstreetmap.org](https://www.openstreetmap.org)
36 |
37 | ##### Mapbox
38 | Mapbox is a for profit company that also offers free keys.
39 | Their map can be more accurate / precise.
40 | To get your free key go to [mapbox.com](https://account.mapbox.com/auth/signup/)
41 | Once logged in you can get your free key and use it by placing it in the env file like this ``MAPS_MAPBOX_ACCESS_TOKEN``.
42 |
43 | ##### Attribution
44 | Mapbox requires you to have attribution when you use their tilehost. More information on that here: https://docs.mapbox.com/help/getting-started/attribution/
45 | We provide a default value if you use mapbox. But if you want to customize it you can pass in the te text via the attribution attribute. Like this:
46 | ```
47 | OpenStreetMap contributors, Imagery © Mapbox">
49 |
50 | ```
51 | ## Usage
52 | ### Leaflet
53 |
54 | ```blade
55 | // Leaflet
56 | // A basic map is as easy as using the x blade component.
57 |
58 |
59 |
60 | // Set the centerpoint of the map:
61 |
62 |
63 | // Set a zoomlevel:
64 |
65 |
66 | // Set markers on the map:
67 |
68 | ```
69 | Do note that if you want to use multiple maps on the same page that you need to specify an id per map.
70 |
71 | #### Leaflet Version
72 | By default we use the latest version of leaflet, but if you want to use a different version just pass it in via a parameter:
73 | ```blade
74 | // Set leafletVersion to desired version:
75 |
76 | ```
77 | ### Google Maps
78 | ``` blade
79 | // Google Maps
80 |
81 | // Set the centerpoint of the map:
82 |
83 |
84 | // Set a zoomlevel:
85 |
86 |
87 | // Set type of the map (roadmap, satellite, hybrid, terrain):
88 |
89 |
90 | // Set markers on the map:
91 |
92 |
93 | // You can customize the title for each markers:
94 |
95 |
96 | // Automatically adjust the map's view during initialization to encompass all markers:
97 |
104 |
105 | // Position the map's center at the geometric midpoint of all markers:
106 |
114 | ```
115 | #### Google maps api key
116 | You can get an api key here:
117 | 
118 | Create an api key and enable the Maps Javascript API in the console aswell.
119 | Place the api key in the env file like this ``MAPS_GOOGLE_MAPS_ACCESS_TOKEN``
120 |
121 | ### Good to know
122 | Double quotes need to be escaped, i.e. add a backslash followed by double quotes (/")
123 |
124 | ### Usage in livewire
125 | This library does not support livewire out of the box, but some users have found a workaround to work.
126 | Please see this issue for more information: https://github.com/LarsWiegers/laravel-maps/issues/34
127 |
128 | Feel free to PR a livewire component if you have the time.
129 | ### Testing
130 | To run the tests just use the following component:
131 | ```bash
132 | composer test
133 | ```
134 |
135 | Testing is done through rendering the blade components and making assertions on the html outputted.
136 | While this is great for initial testing it does lack some more certainty. In the future an browser test may be needed to further make sure that the code works as intended.
137 |
138 | ### Changelog
139 |
140 | Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
141 |
142 | ## Contributing
143 |
144 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
145 |
146 | ### Security
147 |
148 | If you discover any security related issues, please email larswiegers@live.nl instead of using the issue tracker.
149 |
150 | ## Credits
151 |
152 | - [Lars Wiegers](https://github.com/larswiegers)
153 | - [All Contributors](../../contributors)
154 |
155 | ## License
156 |
157 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
158 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "larswiegers/laravel-maps",
3 | "description": "A new way to handle maps in your laravel applications.",
4 | "keywords": [
5 | "larswiegers",
6 | "laravel-maps"
7 | ],
8 | "homepage": "https://github.com/larswiegers/laravel-maps",
9 | "license": "MIT",
10 | "type": "library",
11 | "authors": [
12 | {
13 | "name": "Lars Wiegers",
14 | "email": "larswiegers@live.nl",
15 | "role": "Developer"
16 | }
17 | ],
18 | "require": {
19 | "php": "^8.1|^8.2",
20 | "gajus/dindent": "^2.0.2",
21 | "illuminate/support": "^9.43|^v10.0.0|^11.0|^12.0",
22 | "nesbot/carbon": "^2.63|^3.0",
23 | "ramsey/collection": "^1.2.2|^2.0"
24 | },
25 | "require-dev": {
26 | "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
27 | "phpunit/phpunit": "^9.0|^10.0|^11.0"
28 | },
29 | "autoload": {
30 | "psr-4": {
31 | "Larswiegers\\LaravelMaps\\": "src"
32 | }
33 | },
34 | "autoload-dev": {
35 | "psr-4": {
36 | "Larswiegers\\LaravelMaps\\Tests\\": "tests"
37 | },
38 | "classmap": [
39 | "tests"
40 | ]
41 | },
42 | "scripts": {
43 | "test": "vendor/bin/phpunit",
44 | "test-coverage": "vendor/bin/phpunit --coverage-html coverage"
45 | },
46 | "config": {
47 | "sort-packages": true
48 | },
49 | "minimum-stability": "dev",
50 | "prefer-stable": true,
51 | "extra": {
52 | "laravel": {
53 | "providers": [
54 | "Larswiegers\\LaravelMaps\\LaravelMapsServiceProvider"
55 | ],
56 | "aliases": {
57 | "LaravelMaps": "Larswiegers\\LaravelMaps\\LaravelMapsFacade"
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/config/config.php:
--------------------------------------------------------------------------------
1 | resource_path('views'),
8 | 'mapbox' => [
9 | 'access_token' => env('MAPS_MAPBOX_ACCESS_TOKEN', null),
10 | ],
11 | 'google_maps' => [
12 | 'access_token' => env('MAPS_GOOGLE_MAPS_ACCESS_TOKEN', null)
13 | ]
14 | ];
15 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ./tests/Unit
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | src/
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/resources/views/components/google.blade.php:
--------------------------------------------------------------------------------
1 |
6 |
15 |
16 |
20 |
24 |
25 |
81 |
--------------------------------------------------------------------------------
/resources/views/components/leaflet.blade.php:
--------------------------------------------------------------------------------
1 |
4 |
5 |
14 |
15 |
19 |
20 |
21 |
23 |
59 |
--------------------------------------------------------------------------------
/resources/views/tests/views/basic-leaflet.blade.php:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/resources/views/tests/views/with-a-centerpoint-set-leaflet.blade.php:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/resources/views/tests/views/with-zoom-set-leaflet.blade.php:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/src/Components/Google.php:
--------------------------------------------------------------------------------
1 | centerPoint = $centerPoint;
36 | $this->zoomLevel = $zoomLevel;
37 | $this->maxZoomLevel = $maxZoomLevel;
38 | $this->fitToBounds = $fitToBounds;
39 | $this->centerToBoundsCenter = $centerToBoundsCenter;
40 | $this->mapType = strtolower($mapType);
41 | $this->markers = $markers;
42 | $this->tileHost = $tileHost;
43 | $this->mapId = $this->mapId = $id === self::DEFAULTMAPID ? Str::random() : $id;
44 | }
45 |
46 | public function render(): View
47 | {
48 | $markerArray = [];
49 |
50 | foreach($this->markers as $marker) {
51 | $markerArray[] = [implode(",", $marker)];
52 | }
53 |
54 | $shouldIncludeMapJS = !self::$mapHasBeenLoadedBefore;
55 | self::$mapHasBeenLoadedBefore = true;
56 |
57 |
58 | if (!empty($this->mapType) && !in_array($this->mapType, ['roadmap', 'satellite', 'hybrid', 'terrain'], true)) {
59 | $this->mapType = 'roadmap';
60 | }
61 |
62 | return view('maps::components.google', [
63 | 'centerPoint' => $this->centerPoint,
64 | 'zoomLevel' => $this->zoomLevel,
65 | 'maxZoomLevel' => $this->maxZoomLevel,
66 | 'fitToBounds' => $this->fitToBounds,
67 | 'centerToBoundsCenter' => $this->centerToBoundsCenter,
68 | 'mapType' => $this->mapType,
69 | 'markers' => $this->markers,
70 | 'markerArray' => $markerArray,
71 | 'tileHost' => $this->tileHost,
72 | 'mapId' => $this->mapId,
73 | 'mapHasBeenLoadedBefore' => $shouldIncludeMapJS,
74 | ]);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Components/Leaflet.php:
--------------------------------------------------------------------------------
1 | OpenStreetMap contributors, Imagery © Mapbox.com',
38 | $leafletVersion = "latest",
39 | )
40 | {
41 | $this->centerPoint = $centerPoint;
42 | $this->zoomLevel = $zoomLevel;
43 | $this->maxZoomLevel = $maxZoomLevel;
44 | $this->markers = $markers;
45 | $this->tileHost = $tileHost;
46 | $this->mapId = $id;
47 | $this->attribution = $attribution;
48 | $this->leafletVersion = $leafletVersion;
49 | }
50 |
51 | public function render() : View
52 | {
53 | $markerArray = [];
54 |
55 | foreach($this->markers as $marker) {
56 | $markerArray[] = [implode(",", $marker)];
57 | }
58 |
59 | return view('maps::components.leaflet', [
60 | 'centerPoint' => $this->centerPoint,
61 | 'zoomLevel' => $this->zoomLevel,
62 | 'maxZoomLevel' => $this->maxZoomLevel,
63 | 'markers' => $this->markers,
64 | 'markerArray' => $markerArray,
65 | 'tileHost' => $this->tileHost,
66 | 'mapId' => $this->mapId === self::DEFAULTMAPID ? Str::random() : $this->mapId,
67 | 'attribution' => $this->attribution,
68 | 'leafletVersion' => $this->leafletVersion ?? "1.7.1"
69 | ]);
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/LaravelMaps.php:
--------------------------------------------------------------------------------
1 | loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-maps');
20 | // $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-maps');
21 | // $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
22 | // $this->loadRoutesFrom(__DIR__.'/routes.php');
23 |
24 | if ($this->app->runningInConsole()) {
25 | $this->publishes([
26 | __DIR__.'/../config/config.php' => config_path('laravel-maps.php'),
27 | ], 'config');
28 |
29 | // Publishing the views.
30 | $this->publishes([
31 | __DIR__.'/../resources/views/components' => resource_path('views/vendor/maps/components'),
32 | ], 'views');
33 |
34 | // Publishing assets.
35 | /*$this->publishes([
36 | __DIR__.'/../resources/assets' => public_path('vendor/laravel-maps'),
37 | ], 'assets');*/
38 |
39 | // Publishing the translation files.
40 | /*$this->publishes([
41 | __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-maps'),
42 | ], 'lang');*/
43 |
44 | // Registering package commands.
45 | // $this->commands([]);
46 | }
47 |
48 | $this->loadViewComponentsAs('maps', [
49 | Leaflet::class,
50 | Google::class,
51 | ]);
52 |
53 | $this->loadViewsFrom(__DIR__.'/../resources/views', 'maps');
54 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'maps');
55 | }
56 |
57 | /**
58 | * Register the application services.
59 | */
60 | public function register()
61 | {
62 | // Automatically apply the package configuration
63 | $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'laravel-maps');
64 |
65 | // Register the main class to use with the facade
66 | $this->app->singleton('laravel-maps', function () {
67 | return new LaravelMaps;
68 | });
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/tests/TestCase.php:
--------------------------------------------------------------------------------
1 | setElementType('h1', Indenter::ELEMENT_TYPE_INLINE);
34 | $indenter->setElementType('del', Indenter::ELEMENT_TYPE_INLINE);
35 |
36 | $blade = (string) $this->blade($template, $data);
37 | $indented = $indenter->indent($blade);
38 | $cleaned = str_replace(
39 | [' >', "\n/>", ' ', '> ', "\n>"],
40 | ['>', ' />', "\n", ">\n ", '>'],
41 | $indented,
42 | );
43 |
44 | $this->assertSame($expected, $cleaned);
45 | }
46 |
47 | public function getComponentRenderedContent(string $template, array $data = []): string
48 | {
49 | $indenter = new Indenter();
50 | $indenter->setElementType('h1', Indenter::ELEMENT_TYPE_INLINE);
51 | $indenter->setElementType('del', Indenter::ELEMENT_TYPE_INLINE);
52 |
53 | $blade = (string) $this->blade($template, $data);
54 | $indented = $indenter->indent($blade);
55 | $cleaned = str_replace(
56 | [' >', "\n/>", ' ', '> ', "\n>"],
57 | ['>', ' />', "\n", ">\n ", '>'],
58 | $indented,
59 | );
60 |
61 | return $cleaned;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tests/TestView.php:
--------------------------------------------------------------------------------
1 | view = $view;
35 | $this->rendered = $view->render();
36 | }
37 |
38 | /**
39 | * Assert that the given string is contained within the view.
40 | *
41 | * @param string $value
42 | * @param bool $escaped
43 | * @return $this
44 | */
45 | public function assertSee($value, $escaped = true)
46 | {
47 | $value = $escaped ? e($value) : $value;
48 |
49 | PHPUnit::assertStringContainsString((string) $value, $this->rendered);
50 |
51 | return $this;
52 | }
53 |
54 | /**
55 | * Assert that the given strings are contained in order within the view.
56 | *
57 | * @param array $values
58 | * @param bool $escape
59 | * @return $this
60 | */
61 | public function assertSeeInOrder(array $values, $escape = true)
62 | {
63 | $values = $escape ? array_map('e', ($values)) : $values;
64 |
65 | PHPUnit::assertThat($values, new SeeInOrder($this->rendered));
66 |
67 | return $this;
68 | }
69 |
70 | /**
71 | * Assert that the given string is contained within the view text.
72 | *
73 | * @param string $value
74 | * @param bool $escape
75 | * @return $this
76 | */
77 | public function assertSeeText($value, $escape = true)
78 | {
79 | $value = $escape ? e($value) : $value;
80 |
81 | PHPUnit::assertStringContainsString((string) $value, strip_tags($this->rendered));
82 |
83 | return $this;
84 | }
85 |
86 | /**
87 | * Assert that the given strings are contained in order within the view text.
88 | *
89 | * @param array $values
90 | * @param bool $escape
91 | * @return $this
92 | */
93 | public function assertSeeTextInOrder(array $values, $escape = true)
94 | {
95 | $values = $escape ? array_map('e', ($values)) : $values;
96 |
97 | PHPUnit::assertThat($values, new SeeInOrder(strip_tags($this->rendered)));
98 |
99 | return $this;
100 | }
101 |
102 | /**
103 | * Assert that the given string is not contained within the view.
104 | *
105 | * @param string $value
106 | * @param bool $escape
107 | * @return $this
108 | */
109 | public function assertDontSee($value, $escape = true)
110 | {
111 | $value = $escape ? e($value) : $value;
112 |
113 | PHPUnit::assertStringNotContainsString((string) $value, $this->rendered);
114 |
115 | return $this;
116 | }
117 |
118 | /**
119 | * Assert that the given string is not contained within the view text.
120 | *
121 | * @param string $value
122 | * @param bool $escape
123 | * @return $this
124 | */
125 | public function assertDontSeeText($value, $escape = true)
126 | {
127 | $value = $escape ? e($value) : $value;
128 |
129 | PHPUnit::assertStringNotContainsString((string) $value, strip_tags($this->rendered));
130 |
131 | return $this;
132 | }
133 |
134 | /**
135 | * Get the string contents of the rendered view.
136 | *
137 | * @return string
138 | */
139 | public function __toString()
140 | {
141 | return $this->rendered;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/tests/Unit/ExampleTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/Unit/GoogleMapsTest.php:
--------------------------------------------------------------------------------
1 | getComponentRenderedContent('');
17 | $this->assertStringContainsString('', $content);
18 | }
19 |
20 | public function test_it_can_render_with_a_centre_point()
21 | {
22 | $content = $this->getComponentRenderedContent(" 52, 'long' => 5]\">");
23 | $this->assertStringContainsString('center: { lat: 52, lng: 5 },', $content);
24 | }
25 |
26 | public function test_we_can_set_the_zoom_level()
27 | {
28 | $content = $this->getComponentRenderedContent("");
29 |
30 | $this->assertStringContainsString('zoom: 6', $content);
31 | }
32 |
33 | public function test_it_has_default_styles()
34 | {
35 | $content = $this->getComponentRenderedContent("");
36 | $this->assertStringContainsString('height: 100vh', $content);
37 | }
38 |
39 | public function test_it_has_can_take_styles_as_attribute()
40 | {
41 | $content = $this->getComponentRenderedContent("");
42 | $this->assertStringContainsString('height: 50vh', $content);
43 | }
44 |
45 | public function test_it_can_take_classes_as_attribute()
46 | {
47 | $content = $this->getComponentRenderedContent("");
48 | $this->assertStringContainsString("class='h-16'", $content);
49 | }
50 |
51 | public function test_it_can_take_custom_icon_on_marker()
52 | {
53 | $content = $this->getComponentRenderedContent(" 38.716450, 'long' => 0.055684, 'icon' => 'icon.png']]\">");
54 | $this->assertStringContainsString('icon: "icon.png"', $content);
55 | }
56 |
57 | public function test_it_can_take_custom_infowindow_on_marker()
58 | {
59 | $content = $this->getComponentRenderedContent(" 38.716450, 'long' => 0.055684, 'info' => 'MarkerInfo']]\">");
60 | $this->assertStringContainsString('addInfoWindow(marker1, "MarkerInfo");', $content);
61 | }
62 |
63 | public function test_we_can_set_fit_to_bounds()
64 | {
65 | $content = $this->getComponentRenderedContent(" 38.716450, 'long' => 0.055684]]\" :fitToBounds=\"true\">");
66 | $this->assertStringContainsString('let bounds = new google.maps.LatLngBounds();', $content);
67 | $this->assertStringContainsString('.fitBounds(bounds)', $content);
68 | }
69 |
70 | public function test_we_can_set_center_to_bounds_center()
71 | {
72 | $content = $this->getComponentRenderedContent(" 38.716450, 'long' => 0.055684]]\" :centerToBoundsCenter=\"true\">");
73 | $this->assertStringContainsString('let bounds = new google.maps.LatLngBounds();', $content);
74 | $this->assertStringContainsString('.setCenter(bounds.getCenter())', $content);
75 | }
76 |
77 | public function test_we_can_set_map_type()
78 | {
79 | $content = $this->getComponentRenderedContent("");
80 | $this->assertStringContainsString("mapTypeId: 'hybrid'", $content);
81 | }
82 |
83 | public function test_that_invalid_map_type_fallbacks_to_default_map_type()
84 | {
85 | $content = $this->getComponentRenderedContent("");
86 | $this->assertStringContainsString("mapTypeId: 'roadmap'", $content);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/tests/Unit/LeafletTest.php:
--------------------------------------------------------------------------------
1 | getComponentRenderedContent('');
17 | $this->assertStringContainsString('', $content);
18 | }
19 |
20 | public function test_it_can_render_with_a_centre_point()
21 | {
22 | $content = $this->getComponentRenderedContent(" 52, 'long' => 5]\">");
23 | $this->assertStringContainsString('setView([52, 5]', $content);
24 | }
25 |
26 | public function test_we_can_set_the_zoom_level()
27 | {
28 | $content = $this->getComponentRenderedContent("");
29 | $this->assertStringContainsString('setView([0, 0], 6);', $content);
30 | }
31 |
32 | public function test_it_has_default_styles()
33 | {
34 | $content = $this->getComponentRenderedContent("");
35 | $this->assertStringContainsString('height: 100vh', $content);
36 | }
37 |
38 | public function test_it_has_can_take_styles_as_attribute()
39 | {
40 | $content = $this->getComponentRenderedContent("");
41 | $this->assertStringContainsString('height: 50vh', $content);
42 | }
43 |
44 | public function test_it_can_take_classes_as_attribute()
45 | {
46 | $content = $this->getComponentRenderedContent("");
47 | $this->assertStringContainsString("class='h-16'", $content);
48 | }
49 |
50 | public function test_it_can_take_custom_infowindow_on_marker()
51 | {
52 | $content = $this->getComponentRenderedContent(" 38.716450, 'long' => 0.055684, 'info' => 'MarkerInfo']]\">");
53 | $this->assertStringContainsString('marker.bindPopup("MarkerInfo");', $content);
54 | }
55 |
56 | public function test_it_shows_the_attribution()
57 | {
58 | $content = $this->getComponentRenderedContent("");
59 | $this->assertStringContainsString('test', $content);
60 | }
61 |
62 | public function test_it_shows_the_default_attribution()
63 | {
64 | $content = $this->getComponentRenderedContent("");
65 | $this->assertStringContainsString('Map data © OpenStreetMap contributors, Imagery © Mapbox.com', $content);
66 | }
67 |
68 | public function test_uses_latest_as_default_version()
69 | {
70 | $content = $this->getComponentRenderedContent("");
71 | $this->assertStringContainsString('https://unpkg.com/leaflet@latest/dist/leaflet.js', $content);
72 | }
73 |
74 | public function test_can_pass_in_version_and_it_uses_that()
75 | {
76 | $content = $this->getComponentRenderedContent("");
77 | $this->assertStringContainsString('https://unpkg.com/leaflet@1.9.4/dist/leaflet.js', $content);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------