This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Integration\Activate\Permissions\Tab;
use Magento\Integration\Controller\Adminhtml\Integration as IntegrationController;
use Magento\Integration\Model\Integration;
/**
* @magentoDataFixture Magento/Integration/_files/integration_all_permissions.php
*/
class WebapiTest extends \PHPUnit\Framework\TestCase
{
/** @var \Magento\Framework\Registry */
protected $registry;
protected function setUp(): void
{
parent::setUp();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->registry = $objectManager->get(\Magento\Framework\Registry::class);
}
protected function tearDown(): void
{
$this->registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
parent::tearDown();
}
public function testGetSelectedResourcesJsonEmpty()
{
$expectedResult = '[]';
$this->assertEquals($expectedResult, $this->createApiTabBlock()->getSelectedResourcesJson());
}
public function testGetSelectedResourcesJson()
{
$expectedResult = '["Magento_Backend::dashboard",';
$this->registry->register(
IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION,
$this->getFixtureIntegration()->getData()
);
$this->assertStringContainsString($expectedResult, $this->createApiTabBlock()->getSelectedResourcesJson());
}
public function testGetResourcesTreeJson()
{
$expectedResult = '[{"id":"Magento_Backend::dashboard","li_attr":{"data-id":"Magento_Backend::dashboard"},' .
'"text":"Dashboard","children":[],"state":';
$this->registry->register(
IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION,
$this->getFixtureIntegration()->getData()
);
$this->assertStringContainsString($expectedResult, $this->createApiTabBlock()->getResourcesTreeJson());
}
public function testCanShowTabNegative()
{
$this->assertFalse($this->createApiTabBlock()->canShowTab());
}
public function testCanShowTabPositive()
{
$integrationData = $this->getFixtureIntegration()->getData();
$integrationData[Integration::SETUP_TYPE] = Integration::TYPE_CONFIG;
$this->registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
$this->assertTrue($this->createApiTabBlock()->canShowTab());
}
/**
* @return \Magento\Integration\Block\Adminhtml\Integration\Activate\Permissions\Tab\Webapi
*/
protected function createApiTabBlock()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
return $objectManager->create(
\Magento\Integration\Block\Adminhtml\Integration\Activate\Permissions\Tab\Webapi::class
);
}
/**
* @return Integration
*/
protected function getFixtureIntegration()
{
/** @var $integration Integration */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$integration = $objectManager->create(\Magento\Integration\Model\Integration::class);
return $integration->load('Fixture Integration', 'name');
}
}
@@ -0,0 +1,69 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Integration\Block\Adminhtml\Integration\Edit;
use Magento\Integration\Controller\Adminhtml\Integration;
use Magento\Integration\Model\Integration as IntegrationModel;
/**
* Test for \Magento\Integration\Block\Adminhtml\Integration\Edit\Form
*/
class FormTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Integration\Edit\Form
*/
private $block;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $layout \Magento\Framework\View\Layout */
$layout = $this->objectManager->create(\Magento\Framework\View\LayoutInterface::class);
$this->block = $layout->createBlock(\Magento\Integration\Block\Adminhtml\Integration\Edit\Form::class);
}
/**
* @magentoAppArea adminhtml
*/
public function testToHtmlNoExistingIntegrationData()
{
$this->assertStringContainsString(
'<form id="edit_form" action="" method="post">',
$this->block->toHtml()
);
}
/**
* @magentoAppArea adminhtml
* @magentoAppIsolation enabled
*/
public function testToHtmlWithIntegrationData()
{
/** @var \Magento\Framework\Registry $coreRegistry */
$coreRegistry = $this->objectManager->get(\Magento\Framework\Registry::class);
$coreRegistry->unregister(Integration::REGISTRY_KEY_CURRENT_INTEGRATION);
$id = 'idValue';
$integrationData = [
\Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info::DATA_ID => $id,
];
$coreRegistry->register(Integration::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
$html = $this->block->toHtml();
$this->assertMatchesRegularExpression(
"/<input id=\"integration_id\" name=\"id\".*value=\"$id\".*type=\"hidden\".*>/",
$html
);
}
}
@@ -0,0 +1,118 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Integration\Block\Adminhtml\Integration\Edit\Tab;
use Magento\Integration\Controller\Adminhtml\Integration;
use Magento\Integration\Model\Integration as IntegrationModel;
/**
* Test for \Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info
*/
class InfoTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info
*/
private $block;
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var $layout \Magento\Framework\View\Layout */
$layout = $this->objectManager->create(\Magento\Framework\View\LayoutInterface::class);
$this->block = $layout->createBlock(\Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info::class);
$this->block->addChild('integration_tokens', \Magento\Integration\Block\Adminhtml\Integration\Tokens::class);
}
/**
* @magentoAppArea adminhtml
*/
public function testToHtmlNoExistingIntegrationData()
{
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_name" name="name".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_email" name="email".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_endpoint" name="endpoint".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_identity_link_url" name="identity_link_url".*type="text".*>/',
$this->block->toHtml()
);
}
/**
* @magentoAppArea adminhtml
*/
public function testToHtmlWithIntegrationData()
{
/** @var \Magento\Framework\Registry $coreRegistry */
$coreRegistry = $this->objectManager->get(\Magento\Framework\Registry::class);
$coreRegistry->unregister(Integration::REGISTRY_KEY_CURRENT_INTEGRATION);
$name = 'nameExample';
$email = 'admin@example.com';
$endpoint = 'exampleEndpoint';
$identityLinkUrl = 'identityLinkUrl';
$integrationData = [
Info::DATA_ID => '1',
Info::DATA_NAME => $name,
Info::DATA_EMAIL => 'admin@example.com',
Info::DATA_ENDPOINT => 'exampleEndpoint',
Info::DATA_IDENTITY_LINK_URL => 'identityLinkUrl',
Info::DATA_SETUP_TYPE => IntegrationModel::TYPE_MANUAL,
];
$coreRegistry->register(Integration::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
$html = $this->block->toHtml();
$this->assertMatchesRegularExpression(
"/<input id=\"integration_properties_name\" name=\"name\".*value=\"$name\".*type=\"text\".*>/",
$html
);
$this->assertMatchesRegularExpression(
"/<input id=\"integration_properties_email\" name=\"email\".*value=\"$email\".*type=\"text\".*>/",
$html
);
$this->assertMatchesRegularExpression(
"/<input id=\"integration_properties_endpoint\" name=\"endpoint\".*value=\"$endpoint\".*type=\"text\".*>/",
$html
);
$this->assertMatchesRegularExpression(
"/<input id=\"integration_properties_identity_link_url\" name=\"identity_link_url\".*"
. "value=\"$identityLinkUrl\".*type=\"text\".*>/",
$html
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_consumer_key" name="consumer_key".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_consumer_secret" name="consumer_secret".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_token" name="token".*type="text".*>/',
$this->block->toHtml()
);
$this->assertMatchesRegularExpression(
'/<input id="integration_properties_token_secret" name="token_secret".*type="text".*>/',
$this->block->toHtml()
);
}
}
@@ -0,0 +1,122 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Integration;
use Magento\Integration\Controller\Adminhtml\Integration as IntegrationController;
use Magento\Integration\Model\Integration;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test class for \Magento\Integration\Block\Adminhtml\Integration\Edit
*
* @magentoAppArea adminhtml
*/
class EditTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Integration\Edit
*/
protected $editBlock;
protected function setUp(): void
{
$this->editBlock = Bootstrap::getObjectManager()
->create(\Magento\Integration\Block\Adminhtml\Integration\Edit::class);
}
public function testGetHeaderTextNewIntegration()
{
$this->assertEquals('New Integration', $this->editBlock->getHeaderText()->getText());
$buttonList = Bootstrap::getObjectManager()
->get(\Magento\Backend\Block\Widget\Context::class)
->getButtonList()
->getItems();
// Assert that there is a 'save' and 'activate' button when creating a new integration
$haveSaveButton = false;
foreach ($buttonList as $button) {
foreach ($button as $key => $value) {
if ($key === 'save') {
$haveSaveButton = true;
$this->assertNotNull($value->getDataByKey('options'));
$this->assertEquals(
'activate',
$value->getDataByKey('options')['save_activate']['id'],
"'Activate' button is expected when creating a new integration."
);
}
}
}
$this->assertTrue($haveSaveButton, "'Save' button is expected when creating a new integration.");
}
public function testGetHeaderTextEditIntegration()
{
$integrationId = 1;
$integrationName = 'Test Name';
$integrationData = [
Integration::ID => $integrationId,
Integration::NAME => $integrationName,
];
/** @var \Magento\Framework\Registry $registry */
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
$registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
$headerText = $this->editBlock->getHeaderText();
$this->assertEquals("Edit Integration '%1'", $headerText->getText());
$this->assertEquals($integrationName, $headerText->getArguments()[0]);
// Tear down
$registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
}
public function testGetHeaderTextEditIntegrationConfigType()
{
$integrationId = 2;
$integrationName = 'Test Name 2';
$integrationData = [
Integration::ID => $integrationId,
Integration::NAME => $integrationName,
Integration::SETUP_TYPE => Integration::TYPE_CONFIG
];
/** @var \Magento\Framework\Registry $registry */
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
$registry->register(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
/** @var \Magento\Integration\Block\Adminhtml\Integration\Edit $editBlock */
$editBlock = Bootstrap::getObjectManager()
->create(\Magento\Integration\Block\Adminhtml\Integration\Edit::class);
$headerText = $editBlock->getHeaderText();
$this->assertEquals("Edit Integration '%1'", $headerText->getText());
$this->assertEquals($integrationName, $headerText->getArguments()[0]);
$buttonList = Bootstrap::getObjectManager()
->get(\Magento\Backend\Block\Widget\Context::class)
->getButtonList()
->getItems();
// Assert that 'save' button is removed for integration of config type
foreach ($buttonList as $button) {
$this->assertArrayNotHasKey('save', $button);
}
// Tear down
$registry->unregister(IntegrationController::REGISTRY_KEY_CURRENT_INTEGRATION);
}
public function testGetFormActionUrl()
{
$baseUrl = Bootstrap::getObjectManager()->get(\Magento\Framework\Url::class)->getBaseUrl();
$this->assertStringContainsString($baseUrl, $this->editBlock->getFormActionUrl());
}
}
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Integration;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test class for \Magento\Integration\Block\Adminhtml\Integration\Grid
*
* @magentoAppArea adminhtml
*/
class GridTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Integration\Grid
*/
protected $gridBlock;
protected function setUp(): void
{
$this->gridBlock = Bootstrap::getObjectManager()
->create(\Magento\Integration\Block\Adminhtml\Integration\Grid::class);
}
public function testGetRowClickCallback()
{
$this->assertEquals('', $this->gridBlock->getRowClickCallback());
}
public function testGetRowInitCallback()
{
$this->assertEquals('', $this->gridBlock->getRowInitCallback());
}
}
@@ -0,0 +1,102 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Integration;
use Magento\TestFramework\Helper\Bootstrap;
/**
* Test class for \Magento\Integration\Block\Adminhtml\Integration\Tokens
*
* @magentoAppArea adminhtml
*/
class TokensTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Integration\Tokens
*/
protected $tokensBlock;
protected function setUp(): void
{
$this->tokensBlock = Bootstrap::getObjectManager()
->create(\Magento\Integration\Block\Adminhtml\Integration\Tokens::class);
}
public function testGetFormFields()
{
$expectedData = [
[
'name' => Tokens::DATA_CONSUMER_KEY,
'type' => 'text',
'metadata' => [
'label' => __('Consumer Key'),
'name' => Tokens::DATA_CONSUMER_KEY,
'readonly' => true,
],
],
[
'name' => Tokens::DATA_CONSUMER_SECRET,
'type' => 'text',
'metadata' => [
'label' => __('Consumer Secret'),
'name' => Tokens::DATA_CONSUMER_SECRET,
'readonly' => true,
]
],
[
'name' => Tokens::DATA_TOKEN,
'type' => 'text',
'metadata' => ['label' => __('Access Token'), 'name' => Tokens::DATA_TOKEN, 'readonly' => true]
],
[
'name' => Tokens::DATA_TOKEN_SECRET,
'type' => 'text',
'metadata' => [
'label' => __('Access Token Secret'),
'name' => Tokens::DATA_TOKEN_SECRET,
'readonly' => true,
]
]
];
$this->assertEquals($expectedData, $this->tokensBlock->getFormFields());
}
public function testToHtml()
{
$this->tokensBlock->setNameInLayout('test_block_name');
$htmlContent = $this->tokensBlock->toHtml();
$this->assertStringContainsString('name="consumer_key"', $htmlContent);
$this->assertStringContainsString(
'<span>Consumer Key</span>',
$htmlContent,
"HTML content of token block should contain information about 'Consumer Key'."
);
$this->assertStringContainsString('name="consumer_secret"', $htmlContent);
$this->assertStringContainsString(
'<span>Consumer Secret</span>',
$htmlContent,
"HTML content of token block should contain information about 'Consumer Secret'."
);
$this->assertStringContainsString('name="token"', $htmlContent);
$this->assertStringContainsString(
'<span>Access Token</span>',
$htmlContent,
"HTML content of token block should contain information about 'Access Token'."
);
$this->assertStringContainsString('name="token_secret"', $htmlContent);
$this->assertStringContainsString(
'<span>Access Token Secret</span>',
$htmlContent,
"HTML content of token block should contain information about 'Access Token Secret'."
);
}
}
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Integration\Block\Adminhtml\System\Config;
/**
* Testing Oauth section in configs.
*
* @magentoAppArea adminhtml
*/
class OauthSectionTest extends \Magento\TestFramework\TestCase\AbstractBackendController
{
/**
* Checks that OAuth Section in the system config is loaded
*/
public function testOAuthSection()
{
$this->dispatch('backend/admin/system_config/edit/section/oauth/');
$body = $this->getResponse()->getBody();
$this->assertStringContainsString('id="oauth_access_token_lifetime-head"', $body);
$this->assertStringContainsString('id="oauth_cleanup-head"', $body);
$this->assertStringContainsString('id="oauth_consumer-head"', $body);
$this->assertStringContainsString('id="oauth_authentication_lock-head"', $body);
}
}
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button;
use Magento\Integration\Model\Integration;
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Integration/_files/integration_all_permissions.php
*/
class DeleteTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button\Delete
*/
protected $deleteButtonBlock;
protected function setUp(): void
{
parent::setUp();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\App\Request\Http $request */
$request = $objectManager->get(\Magento\Framework\App\Request\Http::class);
$request->setRouteName('adminhtml')->setControllerName('integration');
$this->deleteButtonBlock = $objectManager->create(
\Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button\Delete::class
);
$column = $objectManager->create(\Magento\Backend\Block\Widget\Grid\Column::class);
$this->deleteButtonBlock->setColumn($column);
}
public function testRender()
{
$integration = $this->getFixtureIntegration();
$buttonHtml = $this->deleteButtonBlock->render($integration);
self::assertStringContainsString('title="Remove"', $buttonHtml);
self::assertStringContainsString(
'this.setAttribute(\'data-url\', '
. '\'http://localhost/index.php/backend/admin/integration/delete/id/'
. $integration->getId(),
$buttonHtml
);
$this->assertStringNotContainsString('disabled', $buttonHtml);
}
public function testRenderDisabled()
{
$integration = $this->getFixtureIntegration();
$integration->setSetupType(Integration::TYPE_CONFIG);
$buttonHtml = $this->deleteButtonBlock->render($integration);
self::assertStringContainsString(
'title="' .$this->deleteButtonBlock->escapeHtmlAttr('Uninstall the extension to remove this integration')
.'"',
$buttonHtml
);
self::assertStringContainsString(
'this.setAttribute(\'data-url\', '
. '\'http://localhost/index.php/backend/admin/integration/delete/id/'
. $integration->getId(),
$buttonHtml
);
self::assertStringContainsString('disabled="disabled"', $buttonHtml);
}
/**
* @return Integration
*/
protected function getFixtureIntegration()
{
/** @var $integration Integration */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$integration = $objectManager->create(\Magento\Integration\Model\Integration::class);
return $integration->load('Fixture Integration', 'name');
}
}
@@ -0,0 +1,68 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button;
use Magento\Integration\Model\Integration;
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Integration/_files/integration_all_permissions.php
*/
class EditTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button\Edit
*/
protected $editButtonBlock;
protected function setUp(): void
{
parent::setUp();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\App\Request\Http $request */
$request = $objectManager->get(\Magento\Framework\App\Request\Http::class);
$request->setRouteName('adminhtml')->setControllerName('integration');
$this->editButtonBlock = $objectManager->create(
\Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Button\Edit::class
);
$column = $objectManager->create(\Magento\Backend\Block\Widget\Grid\Column::class);
$this->editButtonBlock->setColumn($column);
}
public function testRenderEdit()
{
$integration = $this->getFixtureIntegration();
$buttonHtml = $this->editButtonBlock->render($integration);
$this->assertStringContainsString('title="Edit"', $buttonHtml);
$this->assertStringContainsString('class="' .$this->editButtonBlock->escapeHtmlAttr('action edit') .'"', $buttonHtml);
$this->assertStringContainsString(
'window.location.href=\'http://localhost/index.php/backend/admin/integration/edit/id/'
. $integration->getId(),
$buttonHtml
);
}
public function testRenderView()
{
$integration = $this->getFixtureIntegration();
$integration->setSetupType(Integration::TYPE_CONFIG);
$buttonHtml = $this->editButtonBlock->render($integration);
$this->assertStringContainsString('title="View"', $buttonHtml);
$this->assertStringContainsString('class="' .$this->editButtonBlock->escapeHtmlAttr('action info') .'"', $buttonHtml);
}
/**
* @return Integration
*/
protected function getFixtureIntegration()
{
/** @var $integration Integration */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$integration = $objectManager->create(\Magento\Integration\Model\Integration::class);
return $integration->load('Fixture Integration', 'name');
}
}
@@ -0,0 +1,105 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Link;
use Magento\Integration\Model\Integration;
/**
* @magentoAppArea adminhtml
* @magentoDataFixture Magento/Integration/_files/integration_all_permissions.php
*/
class ActivateTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Link\Activate
*/
protected $activateLinkBlock;
protected function setUp(): void
{
parent::setUp();
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->activateLinkBlock = $objectManager->create(
\Magento\Integration\Block\Adminhtml\Widget\Grid\Column\Renderer\Link\Activate::class
);
$column = $objectManager->create(\Magento\Backend\Block\Widget\Grid\Column::class);
$this->activateLinkBlock->setColumn($column);
}
public function testRenderActivate()
{
$integration = $this->getFixtureIntegration();
$buttonHtml = $this->activateLinkBlock->render($integration);
$this->assertStringContainsString('href="javascript:void(0);"', $buttonHtml);
$this->assertStringContainsString('title="Activate"', $buttonHtml);
$this->assertStringContainsString('data-row-id="' . $integration->getId() . '"', $buttonHtml);
$this->assertStringContainsString('data-row-dialog="permissions"', $buttonHtml);
$this->assertStringContainsString('data-row-is-reauthorize="0"', $buttonHtml);
$this->assertStringContainsString('data-row-is-token-exchange="0"', $buttonHtml);
$this->assertStringContainsString('onclick="integration.popup.show(this);', $buttonHtml);
$this->assertStringContainsString('>Activate</a>', $buttonHtml);
}
public function testRenderReauthorize()
{
$integration = $this->getFixtureIntegration();
$integration->setStatus(Integration::STATUS_ACTIVE);
$buttonHtml = $this->activateLinkBlock->render($integration);
$this->assertStringContainsString('href="javascript:void(0);"', $buttonHtml);
$this->assertStringContainsString('title="Reauthorize"', $buttonHtml);
$this->assertStringContainsString('data-row-id="' . $integration->getId() . '"', $buttonHtml);
$this->assertStringContainsString('data-row-dialog="permissions"', $buttonHtml);
$this->assertStringContainsString('data-row-is-reauthorize="1"', $buttonHtml);
$this->assertStringContainsString('data-row-is-token-exchange="0"', $buttonHtml);
$this->assertStringContainsString('onclick="integration.popup.show(this);', $buttonHtml);
$this->assertStringContainsString('>Reauthorize</a>', $buttonHtml);
}
/**
* @param string $endpoint
* @param string $identityLinkUrl
* @param int $expectedResult
* @dataProvider renderTokenExchangeProvider
*/
public function testRenderTokenExchange($endpoint, $identityLinkUrl, $expectedResult)
{
$integration = $this->getFixtureIntegration();
$integration->setStatus(Integration::STATUS_ACTIVE);
$integration->setEndpoint($endpoint);
$integration->setIdentityLinkUrl($identityLinkUrl);
$buttonHtml = $this->activateLinkBlock->render($integration);
$this->assertStringContainsString('href="javascript:void(0);"', $buttonHtml);
$this->assertStringContainsString('title="Reauthorize"', $buttonHtml);
$this->assertStringContainsString('data-row-id="' . $integration->getId() . '"', $buttonHtml);
$this->assertStringContainsString('data-row-dialog="permissions"', $buttonHtml);
$this->assertStringContainsString('data-row-is-reauthorize="1"', $buttonHtml);
$this->assertStringContainsString('data-row-is-token-exchange="' . $expectedResult . '"', $buttonHtml);
$this->assertStringContainsString('onclick="integration.popup.show(this);', $buttonHtml);
$this->assertStringContainsString('>Reauthorize</a>', $buttonHtml);
}
public function renderTokenExchangeProvider()
{
return [
['http://example.com/endpoint', 'http://example.com/identity', 1],
['', null, 0],
['http://example.com/endpoint', '', 0],
[null, 'http://example.com/identity', 0],
];
}
/**
* @return Integration
*/
protected function getFixtureIntegration()
{
/** @var $integration Integration */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$integration = $objectManager->create(\Magento\Integration\Model\Integration::class);
return $integration->load('Fixture Integration', 'name');
}
}