php Magento-TestFramework-Helper-Bootstrap类(方法)实例源码

下面列出了php Magento-TestFramework-Helper-Bootstrap 类(方法)源码代码实例,从而了解它的用法。

作者:kidaa3    项目:magento2-platforms   
/**
  * @magentoDataFixture Magento/Sales/_files/quote.php
  */
 protected function setUp()
 {
     $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $quote = $this->_objectManager->create('Magento\\Quote\\Model\\Quote')->load(1);
     $sessionQuoteMock = $this->getMockBuilder('Magento\\Backend\\Model\\Session\\Quote')->disableOriginalConstructor()->setMethods(['getCustomerId', 'getStore', 'getStoreId', 'getQuote'])->getMock();
     $sessionQuoteMock->expects($this->any())->method('getCustomerId')->will($this->returnValue(1));
     $sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quote));
     /** @var \Magento\Framework\View\LayoutInterface $layout */
     $layout = $this->_objectManager->get('Magento\\Framework\\View\\LayoutInterface');
     $this->_accountBlock = $layout->createBlock('Magento\\Sales\\Block\\Adminhtml\\Order\\Create\\Form\\Account', 'address_block' . rand(), ['sessionQuote' => $sessionQuoteMock]);
     parent::setUp();
 }

作者:andrewhowdenco    项目:m2onk8   
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');
 }

作者:aies    项目:magento   
/**
  * {@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);
 }

作者:andrewhowdenco    项目:m2onk8   
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');
 }

作者:koliaG    项目:magento   
/**
  * @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());
     }
 }

作者:shabbirvividad    项目:magento   
/**
  * @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());
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @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());
 }

作者:Doabilit    项目:magento2de   
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]);
 }

作者:vasiljo    项目:magento   
/**
  * Test getCollection None images
  * 1) Check that image attributes were not loaded
  * 2) Check no images were loaded
  * 3) Check thumbnails when no thumbnail selected
  *
  * @magentoConfigFixture default_store sitemap/product/image_include base
  */
 public function testGetCollectionBase()
 {
     $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Sitemap\\Model\\Resource\\Catalog\\Product');
     $products = $model->getCollection(\Magento\Store\Model\Store::DISTRO_STORE_ID);
     $this->_checkProductCollection($products, 3, [1, 4, 5]);
     // Check name attribute was loaded
     foreach ($products as $product) {
         $this->assertNotEmpty($product->getName(), 'name attribute was not loaded');
     }
     // Check thumbnail attribute
     $this->assertEmpty($products[1]->getImage(), 'image attribute was loaded');
     $this->assertEmpty($products[4]->getThumbnail(), 'thumbnail attribute was loaded');
     $this->assertEquals('/s/e/second_image.png', $products[4]->getImage(), 'Incorrect image attribute');
     // Check images loading
     $this->assertEmpty($products[1]->getImages(), 'Images were loaded');
     $this->assertNotEmpty($products[4]->getImages(), 'Images were not loaded');
     $this->assertEquals('Simple Images', $products[4]->getImages()->getTitle(), 'Incorrect title');
     $this->assertEquals('catalog/product/s/e/second_image.png', $products[4]->getImages()->getThumbnail(), 'Incorrect thumbnail');
     $this->assertCount(1, $products[4]->getImages()->getCollection(), 'Number of loaded images is incorrect');
     $imagesCollection = $products[4]->getImages()->getCollection();
     $this->assertEquals('catalog/product/s/e/second_image.png', $imagesCollection[0]->getUrl(), 'Incorrect image url');
     $this->assertEmpty($imagesCollection[0]->getCaption(), 'Caption not empty');
     // Check no selection
     $this->assertEmpty($products[5]->getThumbnail(), 'thumbnail is not empty');
     $this->assertEquals('no_selection', $products[5]->getImage(), 'image is incorrect');
     $this->assertEmpty($products[5]->getImages(), 'Product images were loaded');
 }

作者:andrewhowdenco    项目:m2onk8   
/**
  * @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);
 }

作者:andrewhowdenco    项目:m2onk8   
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');
 }

作者:aies    项目:magento   
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);
 }

作者:pradeep-wagent    项目:magento   
/**
  * @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());
 }

作者:nja7    项目:magento   
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]);
 }

作者:andrewhowdenco    项目:m2onk8   
/**
  * 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');
 }

作者:Doabilit    项目:magento2de   
/**
  * {@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');
 }

作者:andrewhowdenco    项目:m2onk8   
/**
  * @return Integration
  */
 protected function getFixtureIntegration()
 {
     /** @var $integration Integration */
     $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $integration = $objectManager->create('Magento\\Integration\\Model\\Integration');
     return $integration->load('Fixture Integration', 'name');
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * Test verify that theme contains available containers for widget
  */
 public function testAvailableContainers()
 {
     $themeToTest = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('\\Magento\\Theme\\Model\\Theme');
     $themeId = $themeToTest->load('Magento/blank', 'code')->getId();
     $this->block->setTheme($themeId);
     $this->assertContains('<option value="before.body.end" >', $this->block->toHtml());
 }

作者:andrewhowdenco    项目:m2onk8   
protected function setUp()
 {
     $this->_config = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Framework\\App\\Config\\MutableScopeConfigInterface');
     $data = ['access_list' => 'localhost', 'backend_host' => 'localhost', 'backend_port' => 8080, 'ttl' => 120];
     $this->_config->setValue('system/full_page_cache/default', $data);
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\PageCache\\Model\\System\\Config\\Backend\\Varnish');
 }

作者:Atli    项目:docker-magento   
protected function setUp()
 {
     $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
     $this->builder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetailsBuilder');
     $this->itemBuilder = $this->objectManager->create('Magento\\Tax\\Service\\V1\\Data\\QuoteDetails\\ItemBuilder');
     $this->addressBuilder = $this->objectManager->create('\\Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
 }


问题


面经


文章

微信
公众号

扫码关注公众号