本文整理匯總了PHP中Magento\TestFramework\Helper\Bootstrap::getObjectManager方法的典型用法代碼示例。如果您正苦於以下問題:PHP Bootstrap::getObjectManager方法的具體用法?PHP Bootstrap::getObjectManager怎麽用?PHP Bootstrap::getObjectManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\TestFramework\Helper\Bootstrap
的用法示例。
在下文中一共展示了Bootstrap::getObjectManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testGetRelatedOrders
/**
* Test getting orders associated with specified billing agreement.
*
* Create two identical orders, associate one of them with billing agreement and invoke testGetRelatedOrders()
*
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Paypal/_files/billing_agreement.php
* @magentoDataFixture Magento/Sales/_files/order.php
* @magentoDbIsolation enabled
* @magentoAppIsolation enabled
*/
public function testGetRelatedOrders()
{
/** Customer ID declared in the fixture */
$customerId = 1;
/** Assign first order to the active customer */
/** @var \Magento\Sales\Model\Order $orderA */
$orderA = Bootstrap::getObjectManager()->create('Magento\\Sales\\Model\\Order');
$orderA->loadByIncrementId('100000001');
$orderA->setCustomerIsGuest(false)->setCustomerId($customerId)->save();
/** @var \Magento\Customer\Model\Session $customerSession */
$customerSession = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Session');
$customerSession->setCustomerId($customerId);
/** Assign second order to the active customer */
$orderB = clone $orderA;
$orderB->setId(null)->setIncrementId('100000002')->setCustomerIsGuest(false)->setCustomerId($customerId)->save();
/** @var \Magento\Customer\Model\Session $customerSession */
$customerSession = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Session');
$customerSession->setCustomerId($customerId);
/** @var \Magento\Paypal\Model\ResourceModel\Billing\Agreement\Collection $billingAgreementCollection */
$billingAgreementCollection = Bootstrap::getObjectManager()->create('Magento\\Paypal\\Model\\ResourceModel\\Billing\\Agreement\\Collection');
/** @var \Magento\Paypal\Model\Billing\Agreement $billingAgreement */
$billingAgreement = $billingAgreementCollection->getFirstItem();
$billingAgreement->addOrderRelation($orderA->getId())->save();
$registry = Bootstrap::getObjectManager()->get('Magento\\Framework\\Registry');
$registry->register('current_billing_agreement', $billingAgreement);
$relatedOrders = $this->_block->getRelatedOrders();
$this->assertEquals(1, $relatedOrders->count(), "Only one order must be returned.");
$this->assertEquals($orderA->getId(), $relatedOrders->getFirstItem()->getId(), "Invalid order returned as associated with billing agreement.");
}
示例2: setUp
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->filterBuilder = $this->objectManager->create('Magento\\Framework\\Api\\FilterBuilder');
$this->sortOrderBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SortOrderBuilder');
$this->searchCriteriaBuilder = $this->objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
}
示例3: get
/**
* {@inheritdoc}
*/
public function get($filename, $scope)
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$readDirectory = $objectManager->create('Magento\\Framework\\Filesystem\\Directory\\Read', ['config' => ['path' => realpath(__DIR__ . '/../../_files/etc')], 'driver' => $objectManager->create('Magento\\Framework\\Filesystem\\Driver\\File')]);
$paths = ['data_object.xml'];
return new \Magento\Framework\Config\FileIterator($readDirectory, $paths);
}
示例4: testToHtml
/**
* @covers \Magento\Framework\View\Element\AbstractBlock::toHtml
* @see testAssign()
*/
public function testToHtml()
{
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\App\\State')->setAreaCode('any area');
$this->assertEmpty($this->_block->toHtml());
$this->_block->setTemplate(uniqid('invalid_filename.phtml'));
$this->assertEmpty($this->_block->toHtml());
}
示例5: testUpdateProduct
/**
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*/
public function testUpdateProduct()
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attr **/
$attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Eav\\Model\\Config')->getAttribute('catalog_product', 'weight');
$attr->setIsFilterable(1)->save();
$this->assertTrue($attr->isIndexable());
$repository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\ProductRepository');
$product = $repository->get('simple');
$product->setWeight(11);
$product->save();
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Model\\CategoryFactory');
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Catalog\\Block\\Product\\ListProduct');
$category = $categoryFactory->create()->load(2);
$layer = $listProduct->getLayer();
$layer->setCurrentCategory($category);
$productCollection = $layer->getProductCollection();
$productCollection->addAttributeToSelect('weight');
$this->assertCount(1, $productCollection);
/** @var $product \Magento\Catalog\Model\Product */
foreach ($productCollection as $product) {
$this->assertEquals('Simple Product', $product->getName());
$this->assertEquals('Short description', $product->getShortDescription());
$this->assertEquals(11, $product->getWeight());
}
}
示例6: setUp
protected function setUp()
{
parent::setUp();
$productMetadataMock = $this->getMockBuilder('Magento\\Framework\\App\\ProductMetadata')->setMethods(['getVersion'])->disableOriginalConstructor()->getMock();
$productMetadataMock->expects($this->once())->method('getVersion')->willReturn($this::TEST_PRODUCT_VERSION);
$this->block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Backend\\Block\\Page\\Footer', '', ['productMetadata' => $productMetadataMock]);
}
示例7: testSaveFailure
/**
* @magentoDataFixture Magento/Bundle/_files/product.php
* @magentoDbIsolation enabled
*/
public function testSaveFailure()
{
$this->markTestSkipped("When MAGETWO-36510 is fixed, need to change Dbisolation to disabled");
$bundleProductSku = 'bundle-product';
$product = $this->productRepository->get($bundleProductSku);
$bundleExtensionAttributes = $product->getExtensionAttributes()->getBundleProductOptions();
$bundleOption = $bundleExtensionAttributes[0];
$this->assertEquals(true, $bundleOption->getRequired());
$bundleOption->setRequired(false);
//set an incorrect option id to trigger exception
$bundleOption->setOptionId(-1);
$description = "hello";
$product->setDescription($description);
$product->getExtensionAttributes()->setBundleProductOptions([$bundleOption]);
$caughtException = false;
try {
$this->productRepository->save($product);
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
$caughtException = true;
}
$this->assertTrue($caughtException);
/** @var \Magento\Catalog\Model\Product $product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product')->load($product->getId());
$this->assertEquals(null, $product->getDescription());
}
示例8: setUp
protected function setUp()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->storeManager = $objectManager->get('Magento\\Store\\Model\\StoreManagerInterface');
$this->storeManager->reinitStores();
$this->pathProcessor = $objectManager->get('Magento\\Webapi\\Controller\\PathProcessor');
}
示例9: testGetResultingIds
/**
* @magentoDataFixture Magento/Review/_files/different_reviews.php
*/
public function testGetResultingIds()
{
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Review\\Model\\ResourceModel\\Review\\Product\\Collection');
$collection->addStatusFilter(\Magento\Review\Model\Review::STATUS_APPROVED);
$actual = $collection->getResultingIds();
$this->assertCount(2, $actual);
}
示例10: testPrepareForm
/**
* @magentoAppIsolation enabled
*/
public function testPrepareForm()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$objectManager->get('Magento\\Framework\\View\\DesignInterface')->setArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)->setDefaultDesignTheme();
$objectManager->get('Magento\\Framework\\Registry')->register('current_promo_quote_rule', $objectManager->create('Magento\\SalesRule\\Model\\Rule'));
$layout = $objectManager->create('Magento\\Framework\\View\\Layout');
$block = $layout->createBlock('Magento\\SalesRule\\Block\\Adminhtml\\Promo\\Quote\\Edit\\Tab\\Main');
$prepareFormMethod = new \ReflectionMethod('Magento\\SalesRule\\Block\\Adminhtml\\Promo\\Quote\\Edit\\Tab\\Main', '_prepareForm');
$prepareFormMethod->setAccessible(true);
$prepareFormMethod->invoke($block);
$form = $block->getForm();
foreach (['from_date', 'to_date'] as $id) {
$element = $form->getElement($id);
$this->assertNotNull($element);
$this->assertNotEmpty($element->getDateFormat());
}
// assert Customer Groups field
$customerGroupsField = $form->getElement('customer_group_ids');
/** @var \Magento\Customer\Api\GroupRepositoryInterface $groupRepository */
$groupRepository = $objectManager->create('Magento\\Customer\\Api\\GroupRepositoryInterface');
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
$searchCriteria = $objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
$objectConverter = $objectManager->get('Magento\\Framework\\Convert\\DataObject');
$groups = $groups = $groupRepository->getList($searchCriteria->create())->getItems();
$expected = $objectConverter->toOptionArray($groups, 'id', 'code');
$this->assertEquals($expected, $customerGroupsField->getValues());
}
示例11: tearDown
protected function tearDown()
{
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Customer\Model\AddressRegistry $addressRegistry */
$customerRegistry = $objectManager->get('Magento\\Customer\\Model\\CustomerRegistry');
$customerRegistry->remove(1);
}
示例12: setUp
public function setUp()
{
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->_customerRepository = $this->_objectManager->get('Magento\\Customer\\Api\\CustomerRepositoryInterface');
$storeManager = $this->_objectManager->get('Magento\\Store\\Model\\StoreManager');
$this->_context = $this->_objectManager->get('Magento\\Backend\\Block\\Template\\Context', ['storeManager' => $storeManager]);
}
示例13: setUp
/**
* Execute per test initialization.
*/
public function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$objectManager->get('Magento\\Framework\\App\\State')->setAreaCode('adminhtml');
$this->coreRegistry = $objectManager->get('Magento\\Framework\\Registry');
$this->block = $objectManager->get('Magento\\Framework\\View\\LayoutInterface')->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\Newsletter', '', ['registry' => $this->coreRegistry])->setTemplate('tab/newsletter.phtml');
}
示例14: setUp
protected function setUp()
{
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Theme\\Model\\Design\\Backend\\Exceptions');
$this->_model->setScope('default');
$this->_model->setScopeId(0);
$this->_model->setPath('design/theme/ua_regexp');
}
示例15: setUp
/**
* {@inheritDoc}
*/
protected function setUp()
{
parent::setUp();
$objectManager = Bootstrap::getObjectManager();
$this->dataProvider = $objectManager->create(DataProvider::class, ['name' => 'category_form_data_source', 'primaryFieldName' => 'entity_id', 'requestFieldName' => 'id']);
$this->entityType = $objectManager->create(EavConfig::class)->getEntityType('catalog_category');
}