diff --git a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php
index 2daaf39d58d14d2e5bf11f38880529a01e3fb85a..dda3940cd9ba512a0303b429beb4ef0516c3b134 100644
--- a/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php
+++ b/app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php
@@ -35,7 +35,7 @@ class OnInsert extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
     public function execute()
     {
         $helper = $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
-        $storeId = $this->getRequest()->getParam('store');
+        $storeId = (int)$this->getRequest()->getParam('store');
 
         $filename = $this->getRequest()->getParam('filename');
         $filename = $helper->idDecode($filename);
diff --git a/dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsertTest.php b/dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsertTest.php
new file mode 100644
index 0000000000000000000000000000000000000000..fe7788e12d12307446a42eb541bbec55e1e63422
--- /dev/null
+++ b/dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsertTest.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Copyright © Magento, Inc. All rights reserved.
+ * See COPYING.txt for license details.
+ */
+
+namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
+
+use Magento\Cms\Helper\Wysiwyg\Images;
+use Magento\Framework\Data\Form\FormKey;
+use Magento\TestFramework\Helper\Bootstrap;
+use Magento\TestFramework\TestCase\AbstractBackendController;
+
+/**
+ * Provide tests for OnInsert controller.
+ * @magentoAppArea adminhtml
+ */
+class OnInsertTest extends AbstractBackendController
+{
+    /**
+     * Test OnIsert with turned on static urls in catalog.
+     *
+     * @magentoConfigFixture admin_store cms/wysiwyg/use_static_urls_in_catalog 1
+     * @return void
+     */
+    public function testExecuteWhithStaticUrls()
+    {
+        $this->prepareRequest();
+        $this->dispatch('backend/cms/wysiwyg_images/onInsert');
+        $this->assertRegExp('/pub\/media\/wysiwyg\/testFilename/', $this->getResponse()->getBody());
+    }
+
+    /**
+     * Test OnIsert with turned off static urls in catalog.
+     *
+     * @magentoConfigFixture admin_store cms/wysiwyg/use_static_urls_in_catalog 0
+     * @return void
+     */
+    public function testExecuteWhithoutStaticUrls()
+    {
+        $this->prepareRequest();
+        $this->dispatch('backend/cms/wysiwyg_images/onInsert');
+        $this->assertRegExp('/cms\/wysiwyg\/directive\/___directive/', $this->getResponse()->getBody());
+    }
+
+    /**
+     * Set necessary post data into request.
+     *
+     * @return void
+     */
+    private function prepareRequest()
+    {
+        $this->getRequest()->setParams(
+            [
+                'key' => 'testKey',
+                'isAjax' => 'true',
+                'filename' => Bootstrap::getObjectManager()->get(Images::class)->idEncode('testFilename'),
+                'node' => 'root',
+                'store' => '',
+                'as_is' => '0',
+                'form_key' => Bootstrap::getObjectManager()->get(FormKey::class)->getFormKey(),
+            ]
+        );
+    }
+}