Skip to content

Commit bc53649

Browse files
committed
Fix #30296 - fix retrieving send count by ip, add verification of ip conversion into int to integration test
1 parent ccc83b2 commit bc53649

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

app/code/Magento/SendFriend/Model/ResourceModel/SendFriend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getSendCount($object, $ip, $startTime, $websiteId = null)
4343
AND time>=:time
4444
AND website_id=:website_id'
4545
);
46-
$bind = ['ip' => ip2long($ip), 'time' => $startTime, 'website_id' => (int)$websiteId];
46+
$bind = ['ip' => $ip, 'time' => $startTime, 'website_id' => (int)$websiteId];
4747

4848
$row = $connection->fetchRow($select, $bind);
4949
return $row['count'];

dev/tests/integration/testsuite/Magento/SendFriend/Model/SendFriendTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class SendFriendTest extends TestCase
2828
/** @var SendFriend */
2929
private $sendFriend;
3030

31+
/** @var ResourceModel\SendFriend */
32+
private $sendFriendResource;
33+
3134
/** @var CookieManagerInterface */
3235
private $cookieManager;
3336

@@ -43,6 +46,7 @@ protected function setUp(): void
4346

4447
$this->objectManager = Bootstrap::getObjectManager();
4548
$this->sendFriend = $this->objectManager->get(SendFriendFactory::class)->create();
49+
$this->sendFriendResource = $this->objectManager->get(ResourceModel\SendFriend::class);
4650
$this->cookieManager = $this->objectManager->get(CookieManagerInterface::class);
4751
$this->request = $this->objectManager->get(RequestInterface::class);
4852
}
@@ -191,10 +195,21 @@ public function testisExceedLimitByCookies(): void
191195
*/
192196
public function testisExceedLimitByIp(): void
193197
{
198+
$remoteAddr = '127.0.0.1';
194199
$parameters = $this->objectManager->create(Parameters::class);
195-
$parameters->set('REMOTE_ADDR', '127.0.0.1');
200+
$parameters->set('REMOTE_ADDR', $remoteAddr);
196201
$this->request->setServer($parameters);
197202
$this->assertTrue($this->sendFriend->isExceedLimit());
203+
// Verify that ip is saved correctly as integer value
204+
$this->assertEquals(
205+
1,
206+
(int)$this->sendFriendResource->getSendCount(
207+
null,
208+
ip2long($remoteAddr),
209+
time() - (60 * 60 * 24 * 365),
210+
1
211+
)
212+
);
198213
}
199214

200215
/**

0 commit comments

Comments
 (0)