Skip to content

Commit

Permalink
Fix issue that popup methods are rendered twice (See #4).
Browse files Browse the repository at this point in the history
  • Loading branch information
dmolineus committed Jan 2, 2019
1 parent 3b979da commit 6492f6b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Netzmacht/LeafletPHP/Encoder/UIEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public function encodePopup(Popup $popup, Encoder $encoder)
$source ? (', ' . $encoder->encodeReference($source)) : ''
);

$buffer .= $this->encodeMethodCalls($popup->getMethodCalls(), $encoder);

return $buffer;
}
}
25 changes: 25 additions & 0 deletions tests/Encoder/UIEncoderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Netzmacht\LeafletPHP\Test\Encoder;

use Netzmacht\JavascriptBuilder\Type\AnonymousFunction;
use Netzmacht\LeafletPHP\Definition\UI\Popup;
use Netzmacht\LeafletPHP\Test\TestCase;

class UIEncoderTest extends TestCase
{
public function testPopupMethodsAreRendered()
{
$leaflet = $this->getBuilder();

$popup = new Popup('popup');
$popup->on('add', (new AnonymousFunction())->addLine('console.log("add");'));

$this->assertSame(
'layers.popup = L.popup([]);'
. "\n"
. 'layers.popup.on("add", function() { console.log("add"); });',
$leaflet->encode($popup)
);
}
}

0 comments on commit 6492f6b

Please sign in to comment.