本文整理汇总了PHP中Magento\Framework\Math\Random::expects方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::expects方法的具体用法?PHP Random::expects怎么用?PHP Random::expects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Math\Random
的用法示例。
在下文中一共展示了Random::expects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testPrepareElementHtml
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
* @param string $elementValue
* @param integer|null $modelBlockId
*
* @dataProvider prepareElementHtmlDataProvider
*/
public function testPrepareElementHtml($elementValue, $modelBlockId)
{
$elementId = 1;
$uniqId = '126hj4h3j73hk7b347jhkl37gb34';
$sourceUrl = 'cms/block_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
$config = ['key1' => 'value1'];
$fieldsetId = 2;
$html = 'some html';
$title = 'some title';
$this->this->setConfig($config);
$this->this->setFieldsetId($fieldsetId);
$this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
$this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
$this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/block_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
$this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
$this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
$this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
$this->blockFactoryMock->expects($this->any())->method('create')->willReturn($this->modelBlockMock);
$this->modelBlockMock->expects($this->any())->method('load')->with($elementValue)->willReturnSelf();
$this->modelBlockMock->expects($this->any())->method('getId')->willReturn($modelBlockId);
$this->modelBlockMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->chooserMock->expects($this->any())->method('setLabel')->with($title)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
$this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
$this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
}
示例2: testGetFormKeyExists
public function testGetFormKeyExists()
{
$this->sessionMock->expects($this->exactly(2))->method('getData')->with(FormKey::FORM_KEY)->will($this->returnValue('random_string'));
$this->mathRandomMock->expects($this->never())->method('getRandomString');
$this->sessionMock->expects($this->never())->method('setData');
$this->assertEquals('random_string', $this->formKey->getFormKey());
}
示例3: testGetWidgetOptions
public function testGetWidgetOptions()
{
$rand = rand();
$this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
$saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
$saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
$this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl);
$value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand];
$this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
$this->block->getWidgetOptions();
}
示例4: testAfterLoad
/**
* @dataProvider afterLoadDataProvider
*/
public function testAfterLoad($value, $hashData, $expected)
{
$this->model->setValue($value);
$index = 0;
foreach ($hashData as $hash) {
$this->mathRandomMock->expects($this->at($index))->method('getUniqueHash')->willReturn($hash);
$index++;
}
$this->model->afterLoad();
$this->assertEquals($expected, $this->model->getValue());
}
示例5: setUp
public function setUp()
{
$this->setUpMock = $this->getMock('Magento\\Setup\\Module\\Setup', [], [], '', false);
$this->dbAdapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
$this->setUpMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->dbAdapterMock));
$this->setUpMock->expects($this->any())->method('getTable')->will($this->returnCallback(function ($table) {
return $table;
}));
$this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random');
$this->randomMock->expects($this->any())->method('getRandomString')->will($this->returnValue('salt'));
$data = [AdminAccount::KEY_FIRST_NAME => 'John', AdminAccount::KEY_LAST_NAME => 'Doe', AdminAccount::KEY_EMAIL => 'john.doe@test.com', AdminAccount::KEY_PASSWORD => '123123q', AdminAccount::KEY_USERNAME => 'admin'];
$this->adminAccount = new AdminAccount($this->setUpMock, $this->randomMock, $data);
}
示例6: testRequestToken
public function testRequestToken()
{
$request = new Object();
$secureTokenID = 'Sdj46hDokds09c8k2klaGJdKLl032ekR';
$this->transparent->expects($this->once())->method('buildBasicRequest')->willReturn($request);
$this->transparent->expects($this->once())->method('fillCustomerContacts');
$this->transparent->expects($this->once())->method('getConfig')->willReturn($this->getMock('Magento\\Paypal\\Model\\PayflowConfig', [], [], '', false));
$this->transparent->expects($this->once())->method('postRequest')->willReturn(new Object());
$this->mathRandom->expects($this->once())->method('getUniqueHash')->willReturn($secureTokenID);
$this->url->expects($this->exactly(3))->method('getUrl');
$quote = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
$this->model->requestToken($quote);
$this->assertEquals($secureTokenID, $request->getSecuretokenid());
}
示例7: prepareInitiatePasswordReset
/**
* @param string $email
* @param string $templateIdentifier
* @param string $sender
* @param int $storeId
* @param int $customerId
* @param string $hash
*/
protected function prepareInitiatePasswordReset($email, $templateIdentifier, $sender, $storeId, $customerId, $hash)
{
$websiteId = 1;
$dateTime = date(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
$customerData = ['key' => 'value'];
$customerName = 'Customer Name';
$this->store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
$this->store->expects($this->any())->method('getId')->willReturn($storeId);
$this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
$customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
$customer->expects($this->any())->method('getEmail')->willReturn($email);
$customer->expects($this->any())->method('getId')->willReturn($customerId);
$customer->expects($this->any())->method('getStoreId')->willReturn($storeId);
$this->customerRepository->expects($this->once())->method('get')->with($email, $websiteId)->willReturn($customer);
$this->customerRepository->expects($this->once())->method('save')->with($customer)->willReturnSelf();
$this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash);
$this->customerViewHelper->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName);
$this->customerSecure->expects($this->any())->method('setRpToken')->with($hash)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('setRpTokenCreatedAt')->with($dateTime)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('addData')->with($customerData)->willReturnSelf();
$this->customerSecure->expects($this->any())->method('setData')->with('name', $customerName)->willReturnSelf();
$this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecure);
$this->dataObjectProcessor->expects($this->any())->method('buildOutputDataArray')->with($customer, '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn($customerData);
$this->prepareEmailSend($email, $templateIdentifier, $sender, $storeId, $customerName);
}
示例8: testToHtmlMethodSetBmlData
public function testToHtmlMethodSetBmlData()
{
$isInCatalog = true;
$paymentMethodCode = '';
$bmlMethodCode = '';
$hash = 'hash';
$this->shortcut->setIsInCatalogProduct($isInCatalog);
$expressMethod = $this->getMockBuilder('Magento\\Paypal\\Model\\Express')->disableOriginalConstructor()->setMethods([])->getMock();
$expectedData = ['is_in_catalog_product' => $isInCatalog, 'shortcut_html_id' => $hash, 'checkout_url' => null, 'image_url' => 'https://www.paypalobjects.com/webstatic/en_US/i/buttons/ppcredit-logo-medium.png', 'additional_link_image' => ['href' => 'https://www.securecheckout.billmelater.com/paycapture-content/' . 'fetch?hash=AU826TU8&content=/bmlweb/ppwpsiw.html', 'src' => 'https://www.paypalobjects.com/webstatic/en_US/btn/btn_bml_text.png']];
$this->paypalShortcutHelperMock->expects($this->once())->method('validate')->with($paymentMethodCode, $isInCatalog)->will($this->returnValue(true));
$this->paymentHelperMock->expects($this->once())->method('getMethodInstance')->with($bmlMethodCode)->will($this->returnValue($expressMethod));
$expressMethod->expects($this->once())->method('isAvailable')->will($this->returnValue(true));
$this->randomMock->expects($this->once())->method('getUniqueHash')->with('ec_shortcut_bml_')->will($this->returnValue($hash));
$this->assertEmpty($this->shortcut->toHtml());
$this->assertContains($expectedData, $this->shortcut->getData());
}
示例9: testCreateAccountWithPasswordHashWithCustomerAddresses
public function testCreateAccountWithPasswordHashWithCustomerAddresses()
{
$websiteId = 1;
$addressId = 2;
$customerId = null;
$storeId = 1;
$hash = '4nj54lkj5jfi03j49f8bgujfgsd';
//Handle store
$store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
$store->expects($this->any())->method('getWebsiteId')->willReturn($websiteId);
//Handle address - existing and non-existing. Non-Existing should return null when call getId method
$existingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
$nonExistingAddress = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AddressInterface')->disableOriginalConstructor()->getMock();
//Ensure that existing address is not in use
$this->addressRepository->expects($this->atLeastOnce())->method("save")->withConsecutive(array($this->logicalNot($this->identicalTo($existingAddress))), array($this->identicalTo($nonExistingAddress)));
$existingAddress->expects($this->any())->method("getId")->willReturn($addressId);
//Expects that id for existing address should be unset
$existingAddress->expects($this->once())->method("setId")->with(null);
//Handle Customer calls
$customer = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
$customer->expects($this->atLeastOnce())->method('getWebsiteId')->willReturn($websiteId);
$customer->expects($this->atLeastOnce())->method('getStoreId')->willReturn($storeId);
$customer->expects($this->any())->method("getId")->willReturn($customerId);
//Return Customer from customer repositoryå
$this->customerRepository->expects($this->atLeastOnce())->method('save')->willReturn($customer);
$this->customerRepository->expects($this->once())->method('getById')->with($customerId)->willReturn($customer);
$customerSecure = $this->getMockBuilder('Magento\\Customer\\Model\\Data\\CustomerSecure')->setMethods(['setRpToken', 'setRpTokenCreatedAt', 'getPasswordHash'])->disableOriginalConstructor()->getMock();
$customerSecure->expects($this->once())->method('setRpToken')->with($hash);
$customerSecure->expects($this->any())->method('getPasswordHash')->willReturn($hash);
$this->customerRegistry->expects($this->any())->method('retrieveSecureData')->with($customerId)->willReturn($customerSecure);
$this->random->expects($this->once())->method('getUniqueHash')->willReturn($hash);
$customer->expects($this->atLeastOnce())->method('getAddresses')->willReturn([$existingAddress, $nonExistingAddress]);
$this->storeManager->expects($this->atLeastOnce())->method('getStore')->willReturn($store);
$this->assertSame($customer, $this->accountManagement->createAccountWithPasswordHash($customer, $hash));
}
示例10: testGetHtmlElementIdsShoppingCart
public function testGetHtmlElementIdsShoppingCart()
{
$random = '_shopping_cart';
$this->mathRandomMock->expects($this->any())->method('getRandomString')->willReturn($random);
$block = $this->objectManagerHelper->getObject('Magento\\Braintree\\Block\\PayPal\\Shortcut', ['mathRandom' => $this->mathRandomMock, 'data' => ['container' => new \Magento\Framework\Object(['module_name' => 'Magento_Checkout'])]]);
$this->assertEquals('braintree_paypal_container_shopping_cart', $block->getContainerId());
$this->assertEquals('braintree_paypal_submit_form_shopping_cart', $block->getSubmitFormId());
$this->assertEquals('braintree_paypal_payment_method_nonce_shopping_cart', $block->getPaymentMethodNonceId());
$this->assertEquals('braintree_paypal_payment_details_shopping_cart', $block->getPaymentDetailsId());
}
示例11: testGetHtmlSuccessfulTimestamp
public function testGetHtmlSuccessfulTimestamp()
{
$uniqueHash = 'H@$H';
$id = 3;
$format = 'mm/dd/yyyy';
$yesterday = new \DateTime();
$yesterday->add(\DateInterval::createFromDateString('yesterday'));
$tomorrow = new \DateTime();
$tomorrow->add(\DateInterval::createFromDateString('tomorrow'));
$value = ['locale' => 'en_US', 'from' => $yesterday->getTimestamp(), 'to' => $tomorrow->getTimestamp()];
$this->mathRandomMock->expects($this->any())->method('getUniqueHash')->willReturn($uniqueHash);
$this->columnMock->expects($this->once())->method('getHtmlId')->willReturn($id);
$this->localeDateMock->expects($this->any())->method('getDateFormat')->willReturn($format);
$this->columnMock->expects($this->any())->method('getTimezone')->willReturn(false);
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn('en_US');
$this->model->setColumn($this->columnMock);
$this->model->setValue($value);
$output = $this->model->getHtml();
$this->assertContains('id="' . $uniqueHash . '_from" value="' . $yesterday->getTimestamp(), $output);
$this->assertContains('id="' . $uniqueHash . '_to" value="' . $tomorrow->getTimestamp(), $output);
}
示例12: testExecute
public function testExecute()
{
$selectedCategories = '1';
$isAnchorOnly = true;
$hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb';
$content = 'block_content';
$this->request->expects($this->any())->method('getParam')->willReturnMap(
[
['selected', '', $selectedCategories],
['is_anchor_only', 0, $isAnchorOnly]
]
);
$this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash);
$this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf();
$this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf();
$this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf();
$this->chooser->expects($this->once())
->method('setSelectedCategories')
->with(explode(',', $selectedCategories))
->willReturnSelf();
$this->chooser->expects($this->once())->method('toHtml')->willReturn($content);
$this->layout->expects($this->once())
->method('createBlock')
->with($this->blockClass)
->willReturn($this->chooser);
$this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf();
$this->resultFactory->expects($this->once())
->method('create')
->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW)
->willReturn($this->resultRaw);
$this->context->expects($this->once())->method('getRequest')->willReturn($this->request);
$this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory);
/** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */
$this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
->getObject(
'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories',
[
'context' => $this->context,
'mathRandom' => $this->mathRandom,
'layout' => $this->layout
]
);
$this->assertSame($this->resultRaw, $this->controller->executeInternal());
}
示例13: testLoadByCustomerId
public function testLoadByCustomerId()
{
$customerId = 1;
$customerIdFieldName = 'customer_id';
$sharingCode = 'expected_sharing_code';
$this->eventDispatcher->expects($this->any())->method('dispatch');
$this->resource->expects($this->any())->method('getCustomerIdFieldName');
$this->resource->expects($this->once())->method('load')->with($this->logicalOr($this->wishlist, $customerId, $customerIdFieldName));
$this->mathRandom->expects($this->once())->method('getUniqueHash')->will($this->returnValue($sharingCode));
$this->assertInstanceOf('Magento\\Wishlist\\Model\\Wishlist', $this->wishlist->loadByCustomerId($customerId, true));
$this->assertEquals($customerId, $this->wishlist->getCustomerId());
$this->assertEquals($sharingCode, $this->wishlist->getSharingCode());
}
示例14: testPrepareElementHtml
/**
* @covers \Magento\Cms\Block\Adminhtml\Block\Widget\Chooser::prepareElementHtml
*
* @param string $elementValue
* @param integer|null $cmsPageId
*
* @dataProvider prepareElementHtmlDataProvider
*/
public function testPrepareElementHtml($elementValue, $cmsPageId)
{
//$elementValue = 12345;
//$cmsPageId = 1;
$elementId = 1;
$uniqId = '126hj4h3j73hk7b347jhkl37gb34';
$sourceUrl = 'cms/page_widget/chooser/126hj4h3j73hk7b347jhkl37gb34';
$config = ['key1' => 'value1'];
$fieldsetId = 2;
$html = 'some html';
$title = 'some "><img src=y onerror=prompt(document.domain)>; title';
$titleEscaped = 'some "><img src=y onerror=prompt(document.domain)>; title';
$this->this->setConfig($config);
$this->this->setFieldsetId($fieldsetId);
$this->elementMock->expects($this->atLeastOnce())->method('getId')->willReturn($elementId);
$this->mathRandomMock->expects($this->atLeastOnce())->method('getUniqueHash')->with($elementId)->willReturn($uniqId);
$this->urlBuilderMock->expects($this->atLeastOnce())->method('getUrl')->with('cms/page_widget/chooser', ['uniq_id' => $uniqId])->willReturn($sourceUrl);
$this->layoutMock->expects($this->atLeastOnce())->method('createBlock')->with('Magento\\Widget\\Block\\Adminhtml\\Widget\\Chooser')->willReturn($this->chooserMock);
$this->chooserMock->expects($this->atLeastOnce())->method('setElement')->with($this->elementMock)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setConfig')->with($config)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setFieldsetId')->with($fieldsetId)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setSourceUrl')->with($sourceUrl)->willReturnSelf();
$this->chooserMock->expects($this->atLeastOnce())->method('setUniqId')->with($uniqId)->willReturnSelf();
$this->elementMock->expects($this->atLeastOnce())->method('getValue')->willReturn($elementValue);
$this->pageFactoryMock->expects($this->any())->method('create')->willReturn($this->cmsPageMock);
$this->cmsPageMock->expects($this->any())->method('load')->with((int) $elementValue)->willReturnSelf();
$this->cmsPageMock->expects($this->any())->method('getId')->willReturn($cmsPageId);
$this->cmsPageMock->expects($this->any())->method('getTitle')->willReturn($title);
$this->chooserMock->expects($this->atLeastOnce())->method('toHtml')->willReturn($html);
if (!empty($elementValue) && !empty($cmsPageId)) {
$this->escaper->expects($this->atLeastOnce())->method('escapeHtml')->willReturn($titleEscaped);
$this->chooserMock->expects($this->atLeastOnce())->method('setLabel')->with($titleEscaped)->willReturnSelf();
}
$this->elementMock->expects($this->atLeastOnce())->method('setData')->with('after_element_html', $html)->willReturnSelf();
$this->assertEquals($this->elementMock, $this->this->prepareElementHtml($this->elementMock));
}
示例15: testChangeEncryptionKeyAutogenerate
public function testChangeEncryptionKeyAutogenerate()
{
$this->setUpChangeEncryptionKey();
$this->randomMock->expects($this->once())->method('getRandomString')->willReturn('abc');
$this->assertEquals(md5('abc'), $this->model->changeEncryptionKey());
}