|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images; |
| 8 | + |
| 9 | +use Magento\Cms\Helper\Wysiwyg\Images; |
| 10 | +use Magento\Framework\Data\Form\FormKey; |
| 11 | +use Magento\TestFramework\Helper\Bootstrap; |
| 12 | +use Magento\TestFramework\TestCase\AbstractBackendController; |
| 13 | + |
| 14 | +/** |
| 15 | + * Provide tests for OnInsert controller. |
| 16 | + * @magentoAppArea adminhtml |
| 17 | + */ |
| 18 | +class OnInsertTest extends AbstractBackendController |
| 19 | +{ |
| 20 | + /** |
| 21 | + * Test OnIsert with turned on static urls in catalog. |
| 22 | + * |
| 23 | + * @magentoConfigFixture admin_store cms/wysiwyg/use_static_urls_in_catalog 1 |
| 24 | + * @return void |
| 25 | + */ |
| 26 | + public function testExecuteWhithStaticUrls() |
| 27 | + { |
| 28 | + $this->prepareRequest(); |
| 29 | + $this->dispatch('backend/cms/wysiwyg_images/onInsert'); |
| 30 | + $this->assertRegExp('/pub\/media\/wysiwyg\/testFilename/', $this->getResponse()->getBody()); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Test OnIsert with turned off static urls in catalog. |
| 35 | + * |
| 36 | + * @magentoConfigFixture admin_store cms/wysiwyg/use_static_urls_in_catalog 0 |
| 37 | + * @return void |
| 38 | + */ |
| 39 | + public function testExecuteWhithoutStaticUrls() |
| 40 | + { |
| 41 | + $this->prepareRequest(); |
| 42 | + $this->dispatch('backend/cms/wysiwyg_images/onInsert'); |
| 43 | + $this->assertRegExp('/cms\/wysiwyg\/directive\/___directive/', $this->getResponse()->getBody()); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Set necessary post data into request. |
| 48 | + * |
| 49 | + * @return void |
| 50 | + */ |
| 51 | + private function prepareRequest() |
| 52 | + { |
| 53 | + $this->getRequest()->setParams( |
| 54 | + [ |
| 55 | + 'key' => 'testKey', |
| 56 | + 'isAjax' => 'true', |
| 57 | + 'filename' => Bootstrap::getObjectManager()->get(Images::class)->idEncode('testFilename'), |
| 58 | + 'node' => 'root', |
| 59 | + 'store' => '', |
| 60 | + 'as_is' => '0', |
| 61 | + 'form_key' => Bootstrap::getObjectManager()->get(FormKey::class)->getFormKey(), |
| 62 | + ] |
| 63 | + ); |
| 64 | + } |
| 65 | +} |
0 commit comments