From d895f13504f7ba9804ab89f5e92e903221a2b2d4 Mon Sep 17 00:00:00 2001 From: mage2-team Date: Fri, 6 Jun 2014 12:16:28 -0700 Subject: [PATCH] 2.0.0.0-dev81 * Framework improvements: * Covered the following Magento application components with unit tests: * `SalesRule/Model/Observer` * `SalesRule/Helper/*` * `SalesRule/Model/Plugin/*` * `SalesRule/Model/System/Config*` * `Sales/Model/Config.php` * `Sales/Model/Download.php` * `Sales/Model/Quote.php` * Covered the following Magento lib form elements with unit tests: * `lib/Magento/Framework/Flag.php` * `lib/Magento/Framework/Escaper` * `lib/Magento/Framework/Event` * `lib/Magento/Framework/Logger` * `lib/Magento/Framework/Util` * `lib/Magento/Framework/Registry.php` * `lib/Magento/Framework/Backup/Media` * `lib/Magento/Framework/Backup/NoMedia` * `lib/Magento/Framework/Archive` * `lib/Magento/Framework/Translate.php` * Created Service API for Magento_Catalog module: * AttributeSet service * AttributeSetGroup service * ProductLinks service * ProductType service * Payments Improvements: * Resolved a performance issue with Merchant Country selector under Payment Methods settings * Removed the PayPal Payments Pro Payflow Edition payment solution * Removed the Saved Credit Card payment method * Added the following functional tests: * Delete Admin User * Delete Backend Customer * Delete Product UrlRewrite * Downloadable Product Creation * Update Simple Product * Update Tax Rule * Update Tax Rate * Suggest Searching Result * Fixed bugs: * Fixed an issue where the Create Order page title was not correct when scrolling down was performed * Fixed the concurrent test running in MTF * Fixed an issue where product custom options were merged incorrectly * Fixed an issue where customer group discount was not applied for bundle products * Fixed an issue where it was impossible to create a refund for the PayPal Exprecch Checkout Payflow Edition if captured from the PayPal admin * Fixed an issue where adding customer review caused an error in system.log * Fixed an issue where the Manage Stock option was automatically reset to No after changing the Stock Availability option * Fixed an issue where the recurring profile attributes where displayed for a product when they were not included in the product attribute set. * Fixed an issue where a fatal error appeared in some cases on attempt to add a product to cart when FPT was enabled * Fixed an issue where back in stock product alert emails showed HTML markup * Fixed an issue where the Refresh Statistics link on the Sales Report page redirected to the frontend after setting Add Store Code to Urls to Yes * Fixed an issue where the selected bundle options price was included to the price displayed in the MAP popup * Fixed an issue where the wrong allowed countries list was used in Checkout * Fixed an issue where configurable products with out of stock associated simple products were displayed in layered navigation * Fixed an issue where configurable products lost options after being duplicated using the Save and Duplicate button * Fixed issues with simple product custom options where it was impossible to import them from a product page and they were not duplicated correctly using the Save and Duplicate button * Fixed an issue where it was impossible to create a customer on the backend in a single store mode * Fixed an issue where reviews created on the backend appeared with the Guest status * Fixed an issue where it was impossible to add an image for a configurable product variation during editing * Processed GitHub requests: * [#539] (https://github.com/magento/magento2/issues/539) The "{config.xml,*/config.xml}" pattern cannot be processed * [#564] (https://github.com/magento/magento2/issues/564) Catalog product images - Do not removing from file system * [#256] (https://github.com/magento/magento2/issues/256) Unused file app\code\core\Mage\Backend\view\adminhtml\store\switcher\enhanced.phtml * [#561] (https://github.com/magento/magento2/pull/561) Bugfix Magento\Framework\DB\Adapter\Pdo\Mysql::getForeignKeys() * [#576] (https://github.com/magento/magento2/pull/576) Change Request for InvokerDefault::_callObserverMethod() --- CHANGELOG.md | 71 +- .../Block/System/Config/Form/Fieldset.php | 2 +- app/code/Magento/Backend/Model/Url.php | 8 +- app/code/Magento/Backend/etc/di.xml | 3 +- app/code/Magento/Backend/etc/events.xml | 3 - app/code/Magento/Backend/etc/system.xsd | 3 +- app/code/Magento/Backend/etc/system_file.xsd | 1 - .../templates/store/switcher/enhanced.phtml | 119 - .../Bundle/Pricing/Price/BasePrice.php | 67 - .../Pricing/Price/BundleOptionPrice.php | 3 +- .../Pricing/Price/BundleSelectionPrice.php | 27 +- .../Bundle/Pricing/Price/ConfiguredPrice.php | 12 +- .../Pricing/Price/DiscountCalculator.php | 55 + ...face.php => DiscountProviderInterface.php} | 9 +- .../Bundle/Pricing/Price/FinalPrice.php | 41 +- .../Bundle/Pricing/Price/GroupPrice.php | 41 +- .../Bundle/Pricing/Price/SpecialPrice.php | 37 +- .../Bundle/Pricing/Price/TierPrice.php | 59 +- app/code/Magento/Bundle/etc/di.xml | 6 +- .../frontend/templates/js/components.phtml | 1 + .../Bundle/view/frontend/web/bundle.js | 3 + .../Block/Adminhtml/Product/Options/Ajax.php | 6 +- .../Catalog/Controller/Adminhtml/Product.php | 6 +- .../Product/Initialization/Helper.php | 24 +- app/code/Magento/Catalog/Model/Product.php | 7 +- .../Model/Product/Attribute/Backend/Media.php | 30 +- .../Attribute/Source/Countryofmanufacture.php | 2 +- .../Initialization/Helper/ProductLinks.php | 37 +- .../Catalog/Model/Resource/Product.php | 23 + .../Resource/Product/Indexer/Eav/Source.php | 8 + .../Catalog/Pricing/Price/BasePrice.php | 6 +- .../Catalog/Pricing/Price/TierPrice.php | 1 + .../Catalog/Service/V1/Data/Eav/Attribute.php | 98 + .../Service/V1/Data/Eav/AttributeBuilder.php | 95 + .../Service/V1/Data/Eav/AttributeGroup.php | 36 +- .../V1/Data/Eav/AttributeGroupBuilder.php | 52 + .../Service/V1/Data/Eav/AttributeSet.php | 75 + .../V1/Data/Eav/AttributeSet/Attribute.php | 72 + .../Eav/AttributeSet/AttributeBuilder.php} | 38 +- .../V1/Data/Eav/AttributeSetBuilder.php | 63 + .../Catalog/Service/V1/Data/ProductType.php | 54 + .../Service/V1/Data/ProductTypeBuilder.php | 53 + .../V1/Product/AttributeGroup/ReadService.php | 77 + .../AttributeGroup/ReadServiceInterface.php | 36 + .../Product/AttributeGroup/WriteService.php | 113 + .../AttributeGroup/WriteServiceInterface.php | 59 + .../Product/AttributeSet/AttributeService.php | 156 + .../AttributeServiceInterface.php | 46 + .../V1/Product/AttributeSet/ReadService.php | 153 + .../AttributeSet/ReadServiceInterface.php | 50 + .../V1/Product/AttributeSet/WriteService.php | 143 + .../AttributeSet/WriteServiceInterface.php | 64 + .../V1/Product/Link/Data/LinkAttribute.php | 57 + .../Link/Data/LinkAttributeBuilder.php | 32 +- .../Service/V1/Product/Link/Data/LinkType.php | 57 + .../V1/Product/Link/Data/LinkTypeBuilder.php | 55 + .../V1/Product/Link/Data/ProductLink.php | 69 + .../Data/ProductLink/CollectionProvider.php | 74 + .../CollectionProvider/Crosssell.php | 36 + .../CollectionProvider/Related.php | 18 +- .../ProductLink/CollectionProvider/Upsell.php | 36 + .../CollectionProviderInterface.php | 36 + .../Data/ProductLink/DataMapper/Composite.php | 54 + .../Data/ProductLink/DataMapperInterface.php} | 12 +- .../ProductEntity/ConverterInterface.php | 36 + .../ProductEntity/ConverterPool.php | 59 + .../ProductEntity/DefaultConverter.php | 42 + .../Product/Link/Data/ProductLinkBuilder.php | 97 + .../V1/Product/Link/LinkTypeResolver.php | 60 + .../Service/V1/Product/Link/ProductLoader.php | 63 + .../Service/V1/Product/Link/ReadService.php | 157 + .../V1/Product/Link/ReadServiceInterface.php | 54 + .../Service/V1/Product/Link/WriteService.php | 181 ++ .../V1/Product/Link/WriteServiceInterface.php | 64 + .../Catalog/Service/V1/ProductTypeService.php | 68 + .../V1/ProductTypeServiceInterface.php | 36 + app/code/Magento/Catalog/etc/di.xml | 31 +- app/code/Magento/Catalog/etc/webapi.xml | 142 + .../templates/catalog/product/edit.phtml | 18 +- .../view/adminhtml/web/product/product.css | 1 + .../frontend/layout/catalog_product_view.xml | 5 +- .../Block/Adminhtml/Form/Field/Stock.php | 67 +- .../Model/Product/Type/Configurable.php | 20 +- .../catalog/product/edit/super/config.phtml | 9 +- .../catalog/product/edit/super/matrix.phtml | 2 +- app/code/Magento/Core/App/Router/Base.php | 10 +- .../Edit/Renderer/Attribute/Sendemail.php | 73 + .../Block/Adminhtml/Edit/Tab/Account.php | 285 +- .../Service/V1/Data/AddressBuilder.php | 6 +- .../Service/V1/Data/CustomerBuilder.php | 6 +- .../V1/Data/CustomerDetailsBuilder.php | 10 +- .../V1/Data/Eav/AttributeMetadataBuilder.php | 10 +- .../tab/account/form/renderer/sendemail.phtml | 52 + .../DesignEditor/Model/Url/NavigationMode.php | 4 +- .../Eav/Model/Entity/AbstractEntity.php | 2 +- .../Eav/Model/Validator/Attribute/Backend.php | 2 +- .../Magento/Email/Model/Template/Filter.php | 6 +- .../Helper/ProductLinks/Plugin/Grouped.php | 47 + .../CollectionProvider/Grouped.php | 38 + .../ProductLink/DataMapper/GroupedProduct.php | 43 + .../ProductLink/ProductEntity/Converter.php | 47 + .../GroupedProduct/etc/adminhtml/di.xml | 3 - app/code/Magento/GroupedProduct/etc/di.xml | 31 + .../templates/product/grouped/list.phtml | 6 +- .../Model/Export/Entity/Product.php | 12 +- .../Magento/ImportExport/Model/Import.php | 6 +- .../Model/Import/Entity/Product.php | 18 +- .../ImportExport/Model/Import/Uploader.php | 5 +- .../Index/Model/Indexer/AbstractIndexer.php | 2 +- .../Magento/Index/Model/Resource/Setup.php | 2 +- .../OfflinePayments/Block/Info/Ccsave.php | 59 - .../OfflinePayments/etc/adminhtml/system.xml | 64 - .../Magento/OfflinePayments/etc/config.xml | 9 - .../Magento/OfflinePayments/etc/module.xml | 1 - .../Magento/OfflinePayments/etc/payment.xml | 4 - .../adminhtml/templates/form/ccsave.phtml | 128 - .../view/frontend/templates/form/ccsave.phtml | 137 - app/code/Magento/Ogone/Model/Config.php | 8 +- app/code/Magento/Payment/Block/Info.php | 2 +- .../Payment/Model/Checks/CanUseCheckout.php | 2 +- .../Payment/Model/Checks/CanUseForCountry.php | 2 +- .../Model/Checks/SpecificationFactory.php | 19 +- .../Payment/Model/Checks/TotalMinMax.php | 14 +- app/code/Magento/Payment/Model/Config.php | 108 +- .../Payment/Model/Config/SchemaLocator.php | 15 +- .../Model/Config/Source/Allmethods.php | 2 +- app/code/Magento/Payment/Model/Info.php | 27 +- .../Payment/Model/Method/AbstractMethod.php | 1 + app/code/Magento/Payment/Model/Observer.php | 5 +- .../Block/Adminhtml/Store/SwitcherPlugin.php | 48 + .../Adminhtml/System/Config/Field/Country.php | 156 + .../System/Config/Fieldset/Group.php | 3 +- .../System/Config/Fieldset/Location.php | 4 +- .../System/Config/Fieldset/Payment.php | 14 +- .../System/Config/Fieldset/Store.php | 89 - .../Magento/Paypal/Block/Express/Shortcut.php | 2 +- app/code/Magento/Paypal/Helper/Backend.php | 74 + app/code/Magento/Paypal/Model/AbstractIpn.php | 4 +- .../Magento/Paypal/Model/Api/AbstractApi.php | 12 +- app/code/Magento/Paypal/Model/Api/Nvp.php | 4 +- .../Magento/Paypal/Model/Api/PayflowNvp.php | 7 +- app/code/Magento/Paypal/Model/Config.php | 130 +- .../Config/Structure/Element/FieldPlugin.php} | 37 +- .../Paypal/Model/Config/StructurePlugin.php | 122 + app/code/Magento/Paypal/Model/Direct.php | 29 +- app/code/Magento/Paypal/Model/Express.php | 25 +- .../Magento/Paypal/Model/Express/Checkout.php | 21 +- app/code/Magento/Paypal/Model/Hostedpro.php | 6 +- app/code/Magento/Paypal/Model/Info.php | 389 +-- app/code/Magento/Paypal/Model/Ipn.php | 2 +- .../Magento/Paypal/Model/Method/Agreement.php | 10 +- .../Magento/Paypal/Model/PayflowDirect.php | 102 - .../Magento/Paypal/Model/PayflowExpress.php | 56 +- app/code/Magento/Paypal/Model/Standard.php | 8 +- app/code/Magento/Paypal/etc/adminhtml/di.xml | 9 + .../Magento/Paypal/etc/adminhtml/system.xml | 2690 +++++++++-------- app/code/Magento/Paypal/etc/config.xml | 9 - app/code/Magento/Paypal/etc/di.xml | 10 + app/code/Magento/Paypal/etc/payment.xml | 4 - .../system/config/fieldset/store.phtml | 99 - .../Block/Email/AbstractEmail.php | 30 + .../ProductAlert/Block/Email/Stock.php | 4 +- .../view/frontend/templates/email/price.phtml | 2 +- .../view/frontend/templates/email/stock.phtml | 2 +- .../install-1.0.0.0.php | 1 + .../Review/Controller/Adminhtml/Product.php | 57 +- .../Block/Adminhtml/Order/Create/Sidebar.php | 2 +- app/code/Magento/Sales/Block/Order/Link.php | 7 +- app/code/Magento/Sales/Block/Order/Totals.php | 2 +- .../Sales/Helper/Quote/Item/Compare.php | 89 + .../Magento/Sales/Model/AdminOrder/Create.php | 6 +- .../Sales/Model/Payment/Method/Converter.php | 106 - app/code/Magento/Sales/Model/Quote/Item.php | 48 +- .../Sales/Model/Resource/AbstractResource.php | 67 - .../Sales/Model/Resource/Order/Payment.php | 11 +- .../Resource/Order/Payment/Collection.php | 16 - .../Sales/Model/Resource/Quote/Payment.php | 11 +- .../Resource/Quote/Payment/Collection.php | 16 - .../data-upgrade-1.6.0.8-1.6.0.9.php | 91 - .../adminhtml/web/order/create/scripts.js | 15 +- app/code/Magento/SalesRule/Helper/Data.php | 68 - app/code/Magento/SalesRule/Model/Observer.php | 3 +- app/code/Magento/Shipping/Model/Shipping.php | 2 +- .../Magento/Store/App/Response/Redirect.php | 13 +- .../Tax/sql/tax_setup/install-1.6.0.0.php | 1 + .../user_setup/upgrade-1.6.1.3-1.6.1.4.php | 1 + app/code/Magento/Weee/Helper/Data.php | 37 + .../Magento/Weee/Model/Total/Quote/Weee.php | 208 +- .../Weee/sql/weee_setup/install-1.6.0.0.php | 1 + .../layout/default_head_blocks.xml | 2 +- .../functional/lib/Mtf/App/State/State1.php | 21 +- .../Selenium/Element/DatepickerElement.php | 4 +- .../lib/Mtf/Util/Generate/testcase.xml | 30 + .../Test/Block/System/Config/PageActions.php | 22 +- .../Backend/Test/Block/Widget/FormTabs.php | 7 +- .../Backend/Test/Block/Widget/Grid.php | 1 + .../Backend/Test/Handler/Extractor.php | 87 + .../Test/Page/Adminhtml/SystemConfig.php | 80 + .../Test/Page/Adminhtml/SystemConfig.xml | 45 + .../Backend/Test/Page/System/Config.php | 102 - .../Magento/Backend/Test/etc/global/page.xml | 32 + .../Test/Block/Adminhtml/Product/Form.php | 39 +- .../Test/Block/Adminhtml/Product/Form.xml | 7 + .../Test/Block/Adminhtml/Product/Grid.php | 26 +- .../Block/Product/ProductList/Toolbar.php | 2 +- .../Catalog/Test/Block/Product/View.php | 5 +- .../app/Magento/Catalog/Test/Block/Search.php | 46 +- .../AssertAddToCartButtonAbsent.php | 4 +- .../AssertAddToCartButtonPresent.php | 6 +- .../AssertCustomOptionsOnProductPage.php | 56 +- .../AssertGroupedPriceOnProductPage.php | 8 +- .../Test/Constraint/AssertProductForm.php | 7 +- .../Test/Constraint/AssertProductInCart.php | 2 +- .../Constraint/AssertProductInCategory.php | 2 +- .../Test/Constraint/AssertProductInGrid.php | 2 +- .../Test/Constraint/AssertProductInStock.php | 2 +- ...AssertProductIsNotDisplayingOnFrontend.php | 8 +- .../Constraint/AssertProductOutOfStock.php | 4 +- .../Test/Constraint/AssertProductPage.php | 2 +- .../AssertProductSearchableBySku.php | 8 +- .../AssertProductSkuAutoGenerated.php | 4 +- .../AssertProductVisibleInCategory.php | 6 +- .../AssertSpecialPriceOnProductPage.php | 10 +- .../AssertTierPriceOnProductPage.php | 4 +- .../Test/Fixture/CatalogProductSimple.php | 4 +- .../CatalogProductSimple/CustomOptions.php | 56 + .../GroupPriceOptions.php | 7 + .../Handler/CatalogProductSimple/Curl.php | 104 +- .../Page/Category/CatalogCategoryView.php | 2 +- .../Test/Page/Product/CatalogProductView.php | 26 +- .../Test/Repository/CatalogProductSimple.php | 14 +- ....php => UpdateSimpleProductEntityTest.php} | 40 +- .../testUpdate.csv | 0 .../Catalog/Test/etc/global/constraint.xml | 6 +- .../AssertSuggestSearchingResult.php | 80 + .../Test/Fixture/CatalogSearchQuery.php | 193 ++ .../Test/Fixture/CatalogSearchQuery.xml | 113 + .../Fixture/CatalogSearchQuery/SearchData.php | 92 + .../SuggestSearchingResultEntityTest.php | 63 + .../testSearch.csv | 3 + .../Test/etc/global/constraint.xml | 34 + .../CatalogSearch/Test/etc/global/fixture.xml | 32 + .../Constraint/AssertCustomerNotInGrid.php | 72 + .../AssertCustomerSuccessDeleteMessage.php | 71 + .../DeleteCustomerBackendEntityTest.php | 93 + .../testDeleteCustomerBackendEntity.csv | 2 + .../Customer/Test/etc/global/constraint.xml | 22 +- .../Catalog/Product/Edit/Tab/Downloadable.php | 66 +- .../Product/Edit/Tab/Downloadable/LinkRow.php | 48 +- .../Product/Edit/Tab/Downloadable/LinkRow.xml | 85 + .../Product/Edit/Tab/Downloadable/Links.php | 127 + .../Product/Edit/Tab/Downloadable/Links.xml | 38 + .../Edit/Tab/Downloadable/SampleRow.php | 57 + .../Edit/Tab/Downloadable/SampleRow.xml | 51 + .../Product/Edit/Tab/Downloadable/Samples.php | 123 + .../Product/Edit/Tab/Downloadable/Samples.xml | 33 + .../Product/Form.xml} | 0 .../Test/Block/Catalog/Product/View.php | 79 + .../Test/Block/Catalog/Product/View/Links.php | 128 + .../Block/Catalog/Product/View/Samples.php | 72 + .../Constraint/AssertDownloadableLinks.php | 128 + .../AssertDownloadableProductForm.php | 123 + .../AssertDownloadableSamplesData.php | 107 + .../Fixture/CatalogProductDownloadable.php | 939 ++++++ .../Fixture/CatalogProductDownloadable.xml | 479 +++ .../CatalogProductDownloadable/Links.php | 177 ++ .../CatalogProductDownloadable/Samples.php | 140 + .../Test/Fixture/DownloadableProduct.php | 13 +- .../LinksNotPurchasedSeparately.php | 6 +- .../LinksPurchasedSeparately.php | 45 +- .../Test/Handler/Curl/CreateDownloadable.php | 2 + .../Test/Page/Product/CatalogProductView.php | 61 + .../Test/Page/Product/CatalogProductView.xml | 33 + .../Create/LinksPurchasedSeparatelyTest.php | 38 +- .../CreateDownloadableProductEntityTest.php | 116 + .../testCreateDownloadableProduct.csv | 15 + .../Test/etc/global/constraint.xml | 36 + .../Test/Block/Adminhtml/Rate/Edit/Form.php | 36 + .../Test/Block/Adminhtml/Rate/Edit/Form.xml | 43 + .../Adminhtml/Rate/Edit/FormPageActions.php | 41 + .../Tax/Test/Block/Adminhtml/Rate/Grid.php | 59 + .../Tax/Test/Constraint/AssertTaxRateForm.php | 130 + .../Test/Constraint/AssertTaxRateInGrid.php | 83 + .../AssertTaxRateIsInCorrectRange.php | 33 +- .../AssertTaxRateSuccessSaveMessage.php | 71 + .../Constraint/AssertTaxRuleIsApplied.php | 125 + .../Constraint/AssertTaxRuleIsNotApplied.php | 125 + .../app/Magento/Tax/Test/Fixture/TaxRate.php | 2 +- .../Tax/Test/Page/Adminhtml/TaxRateIndex.php | 80 + .../Tax/Test/Page/Adminhtml/TaxRateIndex.xml | 45 + .../Tax/Test/Page/Adminhtml/TaxRateNew.php | 80 + .../Tax/Test/Page/Adminhtml/TaxRateNew.xml | 45 + .../Magento/Tax/Test/Repository/TaxRate.php | 18 +- .../Test/TestCase/UpdateTaxRateEntityTest.php | 105 + .../testUpdateTaxRate.csv | 7 + .../Test/TestCase/UpdateTaxRuleEntityTest.php | 130 + .../testUpdateTaxRule.csv | 5 + .../Tax/Test/etc/global/constraint.xml | 33 + .../app/Magento/Tax/Test/etc/global/page.xml | 10 + .../AssertPageByUrlRewriteIsNotFound.php | 80 + .../AssertUrlRewriteDeletedMessage.php | 75 + .../Constraint/AssertUrlRewriteNotInGrid.php | 70 + .../UrlRewrite/Test/Fixture/UrlRewrite.php | 20 + .../UrlRewrite/Test/Fixture/UrlRewrite.xml | 6 + .../Test/Handler/UrlRewrite/Curl.php | 97 + .../UrlRewrite/UrlRewriteInterface.php | 35 + .../UrlRewrite/Test/Repository/UrlRewrite.php | 47 + .../DeleteProductUrlRewritesEntityTest.php | 113 + .../testDeleteProductUrlRewrites.csv | 2 + .../Magento/UrlRewrite/Test/etc/curl/di.xml | 28 + .../UrlRewrite/Test/etc/global/constraint.xml | 21 + .../Block/{ => Adminhtml}/User/Edit/Form.php | 20 +- .../{ => Adminhtml}/User/Edit/Tab/Roles.php | 26 +- .../User/Test/Block/Adminhtml/UserGrid.php | 55 + .../User/Test/Block/Backend/UserGrid.php | 78 - .../AssertImpossibleDeleteYourOwnAccount.php | 71 + .../User/Test/Constraint/AssertUserInGrid.php | 71 + .../Test/Constraint/AssertUserNotInGrid.php | 71 + .../AssertUserSuccessDeleteMessage.php | 71 + .../User/Test/Fixture/AdminUserInjectable.php | 5 +- .../User/Test/Handler/AdminUser/Curl.php | 6 +- .../User/Test/Handler/AdminUserRole/Curl.php | 8 +- .../User/Test/Page/Adminhtml/UserEdit.php | 80 + .../User/Test/Page/Adminhtml/UserEdit.xml | 45 + .../User/Test/Page/Adminhtml/UserIndex.php | 80 + .../User/Test/Page/Adminhtml/UserIndex.xml | 45 + .../User/Test/Page/Backend/UserEdit.php | 124 - .../User/Test/Page/Backend/UserIndex.php | 105 - .../Test/Repository/AdminUserInjectable.php | 15 +- .../User/Test/Repository/AdminUserRole.php | 1 + .../TestCase/DeleteAdminUserEntityTest.php | 153 + .../testDeleteAdminUserEntity.csv | 3 + .../app/Magento/User/Test/etc/curl/di.xml | 8 +- .../User/Test/etc/global/constraint.xml | 41 +- .../Magento/User/Test/etc/global/fixture.xml | 5 - .../app/Magento/User/Test/etc/global/page.xml | 14 +- .../Workaround/Cleanup/TestCaseProperties.php | 2 +- .../Product/Indexer/Eav/SourceTest.php | 95 + .../_files/product_simple_rollback.php} | 21 +- .../_files/product_virtual_rollback.php | 39 + .../_files/products_crosssell_rollback.php | 46 + .../Catalog/_files/products_new_rollback.php | 38 + .../_files/products_related_rollback.php | 46 + .../Catalog/_files/products_upsell.php | 72 + .../_files/products_upsell_rollback.php | 45 + .../Magento/Centinel/CreateOrderTest.php | 6 + .../Model/Product/Type/ConfigurableTest.php | 7 +- .../Block/Adminhtml/Group/Edit/FormTest.php | 3 +- .../Block/Adminhtml/Group/EditTest.php | 3 +- .../Service/V1/CustomerAccountServiceTest.php | 18 +- .../Service/V1/CustomerAddressServiceTest.php | 3 +- .../Service/V1/CustomerGroupServiceTest.php | 23 +- .../Customer/_files/customer_group.php | 9 +- .../_files/_inline_page_original.html | 3 - .../_files/product_grouped_rollback.php | 54 + .../_files/product_with_custom_options.csv | 2 +- ...oducts_to_import_invalid_attribute_set.csv | 2 +- .../Order/Create/Form/AbstractTest.php | 14 +- .../Block/Adminhtml/Order/Create/FormTest.php | 7 +- .../Sales/Model/AdminOrder/CreateTest.php | 27 - .../Magento/Sales/Model/Service/QuoteTest.php | 5 +- .../Sales/_files/order_paid_with_saved_cc.php | 64 - .../Tax/Model/Sales/Total/Quote/SetupUtil.php | 2 +- .../Tax/Model/TaxClass/Type/CustomerTest.php | 3 +- .../_files/design-abstraction_select.html | 3 - .../Chooser/_files/page_types_select.html | 3 - .../Test/Performance/_files/scenario.jmx | 3 - .../Test/Performance/_files/scenario.jtl | 3 - .../Performance/_files/scenario_error.jmx | 3 - .../Performance/_files/scenario_error.jtl | 3 - .../Performance/_files/scenario_failure.jmx | 3 - .../Performance/_files/scenario_failure.jtl | 3 - .../_files/scenario_without_report.jmx | 3 - .../CodingStandard/Tool/CodeSniffer.php | 2 +- .../CodingStandard/Tool/CodeSnifferTest.php | 2 +- .../Test/Legacy/_files/obsolete_classes.php | 12 + .../Test/Legacy/_files/obsolete_methods.php | 6 + .../Test/Php/_files/whitelist/common.txt | 2 + .../TestFramework/Helper/ObjectManager.php | 35 + .../Config/_files/invalidSystemXmlArray.php | 11 +- .../Model/Config/_files/valid_system.xml | 1 - .../Product/View/Type/Bundle/OptionTest.php | 2 +- .../Pricing/Adjustment/CalculatorTest.php | 2 +- .../Bundle/Pricing/Price/BasePriceTest.php | 123 - .../Price/BundleSelectionPriceTest.php | 362 +-- .../Pricing/Price/DiscountCalculatorTest.php | 152 + .../Bundle/Pricing/Price/FinalPriceTest.php | 17 +- .../Bundle/Pricing/Price/GroupPriceTest.php | 37 +- .../Bundle/Pricing/Price/SpecialPriceTest.php | 33 +- .../Bundle/Pricing/Price/TierPriceTest.php | 2 +- .../Pricing/Render/FinalPriceBoxTest.php | 2 +- .../Product/Helper/Form/CategoryTest.php | 3 - .../Adminhtml/Product/Options/AjaxTest.php | 138 + .../Product/Initialization/HelperTest.php | 13 +- .../Controller/Adminhtml/ProductTest.php | 154 +- .../Product/Attribute/Backend/MediaTest.php | 215 +- .../Source/CountryofmanufactureTest.php | 95 + .../Magento/Catalog/Model/ProductTest.php | 82 +- .../Product/Indexer/Eav/SourceTest.php | 132 + .../Catalog/Pricing/Price/BasePriceTest.php | 2 +- .../Pricing/Price/ConfiguredPriceTest.php | 2 +- .../Catalog/Pricing/Price/GroupPriceTest.php | 2 +- .../Catalog/Pricing/Price/TierPriceTest.php | 2 +- .../AttributeGroup/ReadServiceTest.php | 73 + .../AttributeGroup/WriteServiceTest.php | 163 + .../AttributeSet/AttributeServiceTest.php | 379 +++ .../Product/AttributeSet/ReadServiceTest.php | 340 +++ .../Product/AttributeSet/WriteServiceTest.php | 379 +++ .../CollectionProvider/CrosssellTest.php | 37 + .../CollectionProvider/RelatedTest.php | 37 + .../CollectionProvider/UpsellTest.php | 37 + .../ProductLink/CollectionProviderTest.php | 115 + .../ProductLink/DataMapper/CompositeTest.php | 56 + .../ProductEntity/ConverterPoolTests.php | 56 + .../ProductEntity/DefaultConverterTest.php | 68 + .../V1/Product/Link/LinkTypeResolverTest.php | 62 + .../V1/Product/Link/ProductLoaderTest.php | 84 + .../V1/Product/Link/ReadServiceTest.php | 229 ++ .../V1/Product/Link/WriteServiceTest.php | 317 ++ .../Service/V1/ProductTypeServiceTest.php | 92 + .../Pricing/Price/CatalogRulePriceTest.php | 2 +- .../Model/Product/Type/ConfigurableTest.php | 92 +- .../Pricing/Price/AttributePriceTest.php | 2 +- .../Magento/Core/Model/View/DesignTest.php | 3 - .../Edit/Renderer/Attribute/SendemailTest.php | 83 + .../Block/Adminhtml/Edit/Tab/AccountTest.php | 234 ++ .../Customer/Block/Widget/GenderTest.php | 10 +- .../Controller/Adminhtml/IndexTest.php | 14 +- .../Model/Metadata/Form/MultiselectTest.php | 8 +- .../Model/Metadata/Form/SelectTest.php | 10 +- .../Customer/Model/Metadata/Form/TextTest.php | 7 +- .../Group/Grid/ServiceCollectionTest.php | 5 +- .../Service/V1/CustomerAccountServiceTest.php | 7 +- .../Service/V1/CustomerAddressServiceTest.php | 32 +- .../V1/CustomerMetadataServiceTest.php | 84 +- .../Service/V1/Data/AddressConverterTest.php | 5 +- .../Customer/Service/V1/Data/AddressTest.php | 15 +- .../Service/V1/Data/CustomerBuilderTest.php | 2 +- .../V1/Data/CustomerDetailsBuilderTest.php | 28 +- .../V1/Data/Eav/AttributeMetadataTest.php | 8 +- .../Service/V1/Data/Eav/OptionTest.php | 4 +- .../Customer/Service/V1/Data/RegionTest.php | 5 +- .../Block/Catalog/Product/LinksTest.php | 2 +- .../Framework/App/Action/ActionTest.php | 212 ++ .../Framework/App/Cache/TypeListTest.php | 198 ++ .../App/Config/Initial/ReaderTest.php | 22 - .../Magento/Framework/ArchiveTest.php | 219 ++ .../Magento/Framework/Backup/MediaTest.php | 20 +- .../Magento/Framework/Backup/NomediaTest.php | 5 +- .../Framework/Backup/_files/data/.gitignore | 1 + .../Magento/Framework/Code/ValidatorTest.php | 3 - .../Framework/DB/Adapter/Pdo/MysqlTest.php | 95 +- .../Magento/Framework/EscaperTest.php | 39 +- .../testsuite/Magento/Framework/EventTest.php | 114 + .../testsuite/Magento/Framework/FlagTest.php | 153 + .../PreProcessor/Instruction/ImportTest.php | 2 +- .../Magento/Framework/LoggerTest.php | 112 +- .../Pricing/Adjustment/CalculatorTest.php | 6 +- .../Pricing/Price/AbstractPriceTest.php | 2 +- .../Pricing/PriceInfo/FactoryTest.php | 2 +- .../Framework/Pricing/Render/PriceBoxTest.php | 2 +- .../Magento/Framework/RegistryTest.php | 92 + .../Service/Data/Eav/AttributeValueTest.php | 3 +- .../Service/DataObjectConverterTest.php | 15 +- .../Magento/Framework/TranslateTest.php | 94 +- .../testsuite/Magento/Framework/UtilTest.php | 36 + .../_files/Archive/archives/.gitignore | 1 + .../Framework/_files/Archive/source.txt | 1 + .../ProductLinks/Plugin/GroupedTest.php | 66 +- .../CollectionProvider/GroupedTest.php | 44 + .../DataMapper/GroupedProductTest.php | 51 + .../ProductEntity/ConverterTest.php | 60 + .../_files/product_with_custom_options.csv | 4 +- .../testsuite/Magento/Ogone/Model/ApiTest.php | 5 - .../Model/Checks/CanUseCheckoutTest.php | 64 + .../Model/Checks/CanUseForCountryTest.php | 78 + .../Model/Checks/CanUseForCurrencyTest.php | 78 + .../Model/Checks/CanUseInternalTest.php | 64 + .../Payment/Model/Checks/CompositeTest.php | 59 + .../Model/Checks/SpecificationFactoryTest.php | 63 + .../Payment/Model/Checks/TotalMinMaxTest.php | 72 + .../Payment/Model/Checks/ZeroTotalTest.php | 67 + .../Model/Config/SchemaLocatorTest.php | 62 + .../Model/Config/Source/AllmethodsTest.php | 58 + .../Source/AllspecificcountriesTest.php | 38 + .../Model/Config/Source/CctypeTest.php | 59 + .../Magento/Payment/Model/ConfigTest.php | 204 ++ .../Magento/Payment/Model/InfoTest.php | 242 ++ .../Magento/Payment/Model/ObserverTest.php | 277 ++ .../Payment/Model/Source/CctypeTest.php | 96 + .../Payment/Model/Source/InvoiceTest.php | 51 + .../Adminhtml/Store/SwitcherPluginTest.php | 65 + .../System/Config/Field/CountryTest.php | 147 + .../System/Config/Fieldset/GroupTest.php | 121 + .../System/Config/Fieldset/PaymentTest.php | 144 + .../Magento/Paypal/Helper/BackendTest.php | 150 + .../Structure/Element/FieldPluginTest.php | 100 + .../Model/Config/StructurePluginTest.php | 222 ++ .../Magento/Paypal/Model/ConfigTest.php | 76 + .../Magento/Paypal/Model/InfoTest.php | 278 ++ .../Magento/Paypal/Model/IpnTest.php | 164 +- .../Paypal/Model/Method/AgreementTest.php | 2 +- .../Paypal/Model/PayflowExpressTest.php | 117 + .../Model/_files/additional_info_data.php | 183 ++ .../ProductAlert/Block/Email/StockTest.php | 76 + .../RequireJs/Block/Html/Head/ConfigTest.php | 3 - .../Controller/Adminhtml/ProductTest.php | 235 ++ .../Sales/Helper/Quote/Item/CompareTest.php | 206 ++ .../Magento/Sales/Model/ConfigTest.php | 108 + .../Magento/Sales/Model/DownloadTest.php | 247 ++ .../Model/Payment/Method/ConverterTest.php | 173 -- .../Magento/Sales/Model/Quote/ItemTest.php | 32 + .../Magento/Sales/Model/QuoteTest.php | 523 +++- .../Magento/SalesRule/Helper/CouponTest.php | 168 + .../Magento/SalesRule/Model/ObserverTest.php | 486 ++- .../QuoteConfigProductAttributesTest.php | 70 + .../Config/Source/Coupon/FormatTest.php | 75 + .../Store/App/Response/RedirectTest.php | 133 + .../Service/Entity/DataFromArrayTest.php | 2 +- .../Service/Entity/WebapiObjectManager.php | 17 +- .../Magento/Weee/Helper/DataTest.php | 78 + .../Weee/Model/Total/Quote/WeeeTest.php | 433 +++ .../Magento/Framework/Connect/Converter.php | 14 +- .../lib/Magento/Framework/Connect/Package.php | 2 +- .../Framework/App/Config/Initial/Reader.php | 2 +- .../Magento/Framework/AppInterface.php | 2 +- lib/internal/Magento/Framework/Archive.php | 18 +- .../Magento/Framework/Connect/Command.php | 2 +- .../Magento/Framework/Connect/Converter.php | 14 +- .../Magento/Framework/Connect/Package.php | 2 +- .../Framework/DB/Adapter/Pdo/Mysql.php | 12 +- .../Event/Invoker/InvokerDefault.php | 2 +- .../Exception/CouldNotSaveException.php | 30 + .../Magento/Framework/File/Uploader.php | 5 +- .../Magento/Framework/Filter/Template.php | 8 +- .../Framework/Gdata/Gshopping/Content.php | 2 +- .../Magento/Framework/Model/AbstractModel.php | 4 +- .../ObjectManager/Factory/Factory.php | 2 +- lib/internal/Magento/Framework/Registry.php | 5 +- .../Framework/Service/Data/AbstractObject.php | 11 +- .../Service/Data/AbstractObjectBuilder.php | 12 +- .../Data/Eav/AbstractObjectBuilder.php | 9 +- .../Framework/Service/Data/ObjectFactory.php | 26 +- .../V1/Data/Search/FilterGroupBuilder.php | 11 +- .../Service/V1/Data/SearchCriteriaBuilder.php | 11 +- 545 files changed, 26958 insertions(+), 5623 deletions(-) delete mode 100644 app/code/Magento/Backend/view/adminhtml/templates/store/switcher/enhanced.phtml delete mode 100644 app/code/Magento/Bundle/Pricing/Price/BasePrice.php create mode 100644 app/code/Magento/Bundle/Pricing/Price/DiscountCalculator.php rename app/code/Magento/Bundle/Pricing/Price/{BasePriceInterface.php => DiscountProviderInterface.php} (83%) rename app/code/Magento/Catalog/{Controller/Adminhtml => Model}/Product/Initialization/Helper/ProductLinks.php (57%) create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/Attribute.php create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeBuilder.php rename dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/Links.php => app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroup.php (63%) create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroupBuilder.php create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/Attribute.php rename app/code/Magento/{Payment/Model/Config/Source/Allowedmethods.php => Catalog/Service/V1/Data/Eav/AttributeSet/AttributeBuilder.php} (57%) create mode 100644 app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSetBuilder.php create mode 100644 app/code/Magento/Catalog/Service/V1/Data/ProductType.php create mode 100644 app/code/Magento/Catalog/Service/V1/Data/ProductTypeBuilder.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttribute.php rename dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Tar.php => app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttributeBuilder.php (62%) create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkTypeBuilder.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Crosssell.php rename dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Gz.php => app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Related.php (73%) create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Upsell.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapper/Composite.php rename app/code/Magento/{OfflinePayments/Block/Form/Ccsave.php => Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapperInterface.php} (81%) create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterPool.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverter.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLinkBuilder.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolver.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/ProductLoader.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/WriteService.php create mode 100644 app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php create mode 100644 app/code/Magento/Catalog/Service/V1/ProductTypeService.php create mode 100644 app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php create mode 100644 app/code/Magento/Catalog/etc/webapi.xml create mode 100644 app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php create mode 100644 app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml create mode 100644 app/code/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php create mode 100644 app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Grouped.php create mode 100644 app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProduct.php create mode 100644 app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/ProductEntity/Converter.php delete mode 100644 app/code/Magento/OfflinePayments/Block/Info/Ccsave.php delete mode 100644 app/code/Magento/OfflinePayments/view/adminhtml/templates/form/ccsave.phtml delete mode 100644 app/code/Magento/OfflinePayments/view/frontend/templates/form/ccsave.phtml create mode 100644 app/code/Magento/Paypal/Block/Adminhtml/Store/SwitcherPlugin.php create mode 100644 app/code/Magento/Paypal/Block/Adminhtml/System/Config/Field/Country.php delete mode 100644 app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php create mode 100644 app/code/Magento/Paypal/Helper/Backend.php rename app/code/Magento/{GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php => Paypal/Model/Config/Structure/Element/FieldPlugin.php} (57%) create mode 100644 app/code/Magento/Paypal/Model/Config/StructurePlugin.php delete mode 100644 app/code/Magento/Paypal/Model/PayflowDirect.php delete mode 100644 app/code/Magento/Paypal/view/adminhtml/templates/system/config/fieldset/store.phtml create mode 100644 app/code/Magento/Sales/Helper/Quote/Item/Compare.php delete mode 100644 app/code/Magento/Sales/Model/Payment/Method/Converter.php delete mode 100644 app/code/Magento/Sales/data/sales_setup/data-upgrade-1.6.0.8-1.6.0.9.php delete mode 100644 app/code/Magento/SalesRule/Helper/Data.php create mode 100644 dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Extractor.php create mode 100644 dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.php create mode 100644 dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.xml delete mode 100644 dev/tests/functional/tests/app/Magento/Backend/Test/Page/System/Config.php create mode 100644 dev/tests/functional/tests/app/Magento/Backend/Test/etc/global/page.xml rename dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/{UpdateProductSimpleEntityTest.php => UpdateSimpleProductEntityTest.php} (90%) rename dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/{UpdateProductSimpleEntityTest => UpdateSimpleProductEntityTest}/testUpdate.csv (100%) create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Constraint/AssertSuggestSearchingResult.php create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.php create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.xml create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/SearchData.php create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest/testSearch.csv create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/constraint.xml create mode 100644 dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/fixture.xml create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerNotInGrid.php create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerSuccessDeleteMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest/testDeleteCustomerBackendEntity.csv create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.xml create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.xml create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.xml create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.xml rename dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/{Backend/ProductForm.xml => Adminhtml/Product/Form.xml} (100%) create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Links.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Samples.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableLinks.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableProductForm.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableSamplesData.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.xml create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Links.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Samples.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.xml create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest/testCreateDownloadableProduct.csv create mode 100644 dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/global/constraint.xml create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/Form.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/Form.xml create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/FormPageActions.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Grid.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateForm.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateInGrid.php rename app/code/Magento/OfflinePayments/Model/Ccsave.php => dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateIsInCorrectRange.php (70%) create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateSuccessSaveMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsApplied.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsNotApplied.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.xml create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.xml create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest/testUpdateTaxRate.csv create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest/testUpdateTaxRule.csv create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertPageByUrlRewriteIsNotFound.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteDeletedMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteNotInGrid.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/UrlRewriteInterface.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Repository/UrlRewrite.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest/testDeleteProductUrlRewrites.csv create mode 100644 dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/curl/di.xml rename dev/tests/functional/tests/app/Magento/User/Test/Block/{ => Adminhtml}/User/Edit/Form.php (74%) rename dev/tests/functional/tests/app/Magento/User/Test/Block/{ => Adminhtml}/User/Edit/Tab/Roles.php (82%) create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/UserGrid.php delete mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Block/Backend/UserGrid.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertImpossibleDeleteYourOwnAccount.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInGrid.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserNotInGrid.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserSuccessDeleteMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.xml create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.xml delete mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserEdit.php delete mode 100644 dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserIndex.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest.php create mode 100644 dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest/testDeleteAdminUserEntity.csv create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php rename dev/tests/integration/testsuite/Magento/{Checkout/_files/quote_with_ccsave_payment.php => Catalog/_files/product_simple_rollback.php} (62%) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/products_crosssell_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/products_new_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/products_related_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell.php create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell_rollback.php create mode 100644 dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_rollback.php delete mode 100644 dev/tests/integration/testsuite/Magento/Sales/_files/order_paid_with_saved_cc.php delete mode 100644 dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BasePriceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/DiscountCalculatorTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Options/AjaxTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Source/CountryofmanufactureTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/CrosssellTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/RelatedTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/UpsellTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapper/CompositeTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterPoolTests.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverterTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolverTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ProductLoaderTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ReadServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/WriteServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Catalog/Service/V1/ProductTypeServiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/App/Action/ActionTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/App/Cache/TypeListTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/ArchiveTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/Backup/_files/data/.gitignore create mode 100644 dev/tests/unit/testsuite/Magento/Framework/EventTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/FlagTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/RegistryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/UtilTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Framework/_files/Archive/archives/.gitignore create mode 100644 dev/tests/unit/testsuite/Magento/Framework/_files/Archive/source.txt rename dev/tests/unit/testsuite/Magento/GroupedProduct/{Controller/Adminhtml => Model}/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php (53%) create mode 100644 dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/GroupedTest.php create mode 100644 dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProductTest.php create mode 100644 dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseCheckoutTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCountryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCurrencyTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseInternalTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CompositeTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/SpecificationFactoryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/TotalMinMaxTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Checks/ZeroTotalTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Config/SchemaLocatorTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllmethodsTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllspecificcountriesTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/CctypeTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/ConfigTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/InfoTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/ObserverTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Source/CctypeTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Payment/Model/Source/InvoiceTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/Store/SwitcherPluginTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Field/CountryTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/GroupTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/PaymentTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Helper/BackendTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/Config/Structure/Element/FieldPluginTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/Config/StructurePluginTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/ConfigTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/InfoTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/PayflowExpressTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Paypal/Model/_files/additional_info_data.php create mode 100644 dev/tests/unit/testsuite/Magento/ProductAlert/Block/Email/StockTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Review/Controller/Adminhtml/ProductTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Sales/Helper/Quote/Item/CompareTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Sales/Model/ConfigTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Sales/Model/DownloadTest.php delete mode 100644 dev/tests/unit/testsuite/Magento/Sales/Model/Payment/Method/ConverterTest.php create mode 100644 dev/tests/unit/testsuite/Magento/SalesRule/Helper/CouponTest.php create mode 100644 dev/tests/unit/testsuite/Magento/SalesRule/Model/Plugin/QuoteConfigProductAttributesTest.php create mode 100644 dev/tests/unit/testsuite/Magento/SalesRule/Model/System/Config/Source/Coupon/FormatTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Store/App/Response/RedirectTest.php create mode 100644 dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php create mode 100644 lib/internal/Magento/Framework/Exception/CouldNotSaveException.php rename app/code/Magento/Paypal/Model/Method/ProTypeFactory.php => lib/internal/Magento/Framework/Service/Data/ObjectFactory.php (70%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24f9cc16de182..f81444dc9b1ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,70 @@ +2.0.0.0-dev81 +============= +* Framework improvements: + * Covered the following Magento application components with unit tests: + * `SalesRule/Model/Observer` + * `SalesRule/Helper/*` + * `SalesRule/Model/Plugin/*` + * `SalesRule/Model/System/Config*` + * `Sales/Model/Config.php` + * `Sales/Model/Download.php` + * `Sales/Model/Quote.php` + * Covered the following Magento lib form elements with unit tests: + * `lib/Magento/Framework/Flag.php` + * `lib/Magento/Framework/Escaper` + * `lib/Magento/Framework/Event` + * `lib/Magento/Framework/Logger` + * `lib/Magento/Framework/Util` + * `lib/Magento/Framework/Registry.php` + * `lib/Magento/Framework/Backup/Media` + * `lib/Magento/Framework/Backup/NoMedia` + * `lib/Magento/Framework/Archive` + * `lib/Magento/Framework/Translate.php` + * Created Service API for Magento_Catalog module: + * AttributeSet service + * AttributeSetGroup service + * ProductLinks service + * ProductType service +* Payments Improvements: + * Resolved a performance issue with Merchant Country selector under Payment Methods settings + * Removed the PayPal Payments Pro Payflow Edition payment solution + * Removed the Saved Credit Card payment method +* Added the following functional tests: + * Delete Admin User + * Delete Backend Customer + * Delete Product UrlRewrite + * Downloadable Product Creation + * Update Simple Product + * Update Tax Rule + * Update Tax Rate + * Suggest Searching Result +* Fixed bugs: + * Fixed an issue where the Create Order page title was not correct when scrolling down was performed + * Fixed the concurrent test running in MTF + * Fixed an issue where product custom options were merged incorrectly + * Fixed an issue where customer group discount was not applied for bundle products + * Fixed an issue where it was impossible to create a refund for the PayPal Exprecch Checkout Payflow Edition if captured from the PayPal admin + * Fixed an issue where adding customer review caused an error in system.log + * Fixed an issue where the Manage Stock option was automatically reset to No after changing the Stock Availability option + * Fixed an issue where the recurring profile attributes where displayed for a product when they were not included in the product attribute set. + * Fixed an issue where a fatal error appeared in some cases on attempt to add a product to cart when FPT was enabled + * Fixed an issue where back in stock product alert emails showed HTML markup + * Fixed an issue where the Refresh Statistics link on the Sales Report page redirected to the frontend after setting Add Store Code to Urls to Yes + * Fixed an issue where the selected bundle options price was included to the price displayed in the MAP popup + * Fixed an issue where the wrong allowed countries list was used in Checkout + * Fixed an issue where configurable products with out of stock associated simple products were displayed in layered navigation + * Fixed an issue where configurable products lost options after being duplicated using the Save and Duplicate button + * Fixed issues with simple product custom options where it was impossible to import them from a product page and they were not duplicated correctly using the Save and Duplicate button + * Fixed an issue where it was impossible to create a customer on the backend in a single store mode + * Fixed an issue where reviews created on the backend appeared with the Guest status + * Fixed an issue where it was impossible to add an image for a configurable product variation during editing +* Processed GitHub requests: + * [#539] (https://github.com/magento/magento2/issues/539) The "{config.xml,*/config.xml}" pattern cannot be processed + * [#564] (https://github.com/magento/magento2/issues/564) Catalog product images - Do not removing from file system + * [#256] (https://github.com/magento/magento2/issues/256) Unused file app\code\core\Mage\Backend\view\adminhtml\store\switcher\enhanced.phtml + * [#561] (https://github.com/magento/magento2/pull/561) Bugfix Magento\Framework\DB\Adapter\Pdo\Mysql::getForeignKeys() + * [#576] (https://github.com/magento/magento2/pull/576) Change Request for InvokerDefault::_callObserverMethod() + 2.0.0.0-dev80 ============= * Framework improvements: @@ -104,7 +171,7 @@ * Fixed an issue where the Links section was absent while editing downloadable products from the Wishlist * Fixed an issue where specified details for composite products were lost after adding to Gift Card and Downloadable products to the Wishlist * Fixed and issue where the Date widget was set to incorrect date when creating a new customer - * Fixed an issue where a customer was redirected to Dashboard if the Redirect user to dashboard after login option was set to ‘No’ + * Fixed an issue where a customer was redirected to Dashboard if the Redirect user to dashboard after login option was set to "No" * Fixed an issue where a customer was not able to register during checkout if Guest Checkout was not allowed * Fixed an issue where System logs were not generated properly in integration tests * Fixed benchmarking script @@ -122,7 +189,7 @@ * Catalog Price Rule Creation * Category Url Rewrite Creation * Admin User Role Deletion -* Update composer.json.dist in order to download and install MTF from Public GitHub (MAGETWO-24698) +* Update composer.json.dist in order to download and install MTF from Public GitHub * GitHub requests: * [#542] (https://github.com/magento/magento2/pull/542) Fix ImportExport bug which occurs while importing multiple rows per entity * [#507] (https://github.com/magento/magento2/issues/507) "Insert Image" window is overlapped on menu diff --git a/app/code/Magento/Backend/Block/System/Config/Form/Fieldset.php b/app/code/Magento/Backend/Block/System/Config/Form/Fieldset.php index 588687e731b56..df38a6839a450 100644 --- a/app/code/Magento/Backend/Block/System/Config/Form/Fieldset.php +++ b/app/code/Magento/Backend/Block/System/Config/Form/Fieldset.php @@ -92,7 +92,7 @@ protected function _getHeaderHtml($element) if ($element->getIsNested()) { $html = '
'; } else { - $html = '
'; + $html = '
'; } $html .= '
' . diff --git a/app/code/Magento/Backend/Model/Url.php b/app/code/Magento/Backend/Model/Url.php index 71e887d201544..ca5f3dff77ff2 100644 --- a/app/code/Magento/Backend/Model/Url.php +++ b/app/code/Magento/Backend/Model/Url.php @@ -93,12 +93,13 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn * @param \Magento\Framework\App\Route\ConfigInterface $routeConfig * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo - * @param \Magento\Backend\Model\Url\ScopeResolver $scopeResolver + * @param \Magento\Framework\Url\ScopeResolverInterface $scopeResolver * @param \Magento\Framework\Session\Generic $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver * @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param string $scopeType * @param \Magento\Backend\Helper\Data $backendHelper * @param Menu\Config $menuConfig * @param \Magento\Framework\App\CacheInterface $cache @@ -106,7 +107,6 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor * @param \Magento\Store\Model\StoreFactory $storeFactory * @param \Magento\Framework\Data\Form\FormKey $formKey - * @param string $scopeType * @param array $data * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -115,12 +115,13 @@ public function __construct( \Magento\Framework\App\Route\ConfigInterface $routeConfig, \Magento\Framework\App\RequestInterface $request, \Magento\Framework\Url\SecurityInfoInterface $urlSecurityInfo, - \Magento\Backend\Model\Url\ScopeResolver $scopeResolver, + \Magento\Framework\Url\ScopeResolverInterface $scopeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + $scopeType, \Magento\Backend\Helper\Data $backendHelper, \Magento\Backend\Model\Menu\Config $menuConfig, \Magento\Framework\App\CacheInterface $cache, @@ -128,7 +129,6 @@ public function __construct( \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Store\Model\StoreFactory $storeFactory, \Magento\Framework\Data\Form\FormKey $formKey, - $scopeType, array $data = array() ) { $this->_encryptor = $encryptor; diff --git a/app/code/Magento/Backend/etc/di.xml b/app/code/Magento/Backend/etc/di.xml index b37ec543458cf..331df7123659f 100644 --- a/app/code/Magento/Backend/etc/di.xml +++ b/app/code/Magento/Backend/etc/di.xml @@ -97,6 +97,7 @@ + Magento\Backend\Model\Url\ScopeResolver Magento\Backend\Model\Auth\Session\Proxy Magento\Framework\Data\Form\FormKey\Proxy Magento\Store\Model\ScopeInterface::SCOPE_STORE @@ -186,7 +187,7 @@ - + Magento\Backend\Model\Config\Structure\Search\Proxy diff --git a/app/code/Magento/Backend/etc/events.xml b/app/code/Magento/Backend/etc/events.xml index 57598dd668cf0..2fe0fd68510e5 100644 --- a/app/code/Magento/Backend/etc/events.xml +++ b/app/code/Magento/Backend/etc/events.xml @@ -24,9 +24,6 @@ */ --> - - - diff --git a/app/code/Magento/Backend/etc/system.xsd b/app/code/Magento/Backend/etc/system.xsd index 48e99fb830902..3c7db2918d895 100644 --- a/app/code/Magento/Backend/etc/system.xsd +++ b/app/code/Magento/Backend/etc/system.xsd @@ -106,7 +106,7 @@ - + @@ -144,7 +144,6 @@ - diff --git a/app/code/Magento/Backend/etc/system_file.xsd b/app/code/Magento/Backend/etc/system_file.xsd index 0479c648b79d1..e9836a2eda2cb 100644 --- a/app/code/Magento/Backend/etc/system_file.xsd +++ b/app/code/Magento/Backend/etc/system_file.xsd @@ -145,7 +145,6 @@ - diff --git a/app/code/Magento/Backend/view/adminhtml/templates/store/switcher/enhanced.phtml b/app/code/Magento/Backend/view/adminhtml/templates/store/switcher/enhanced.phtml deleted file mode 100644 index 9402a98fd51be..0000000000000 --- a/app/code/Magento/Backend/view/adminhtml/templates/store/switcher/enhanced.phtml +++ /dev/null @@ -1,119 +0,0 @@ - -getWebsiteCollection() ?> -getSize()): ?> -
-
- -
- -
- getHintHtml() ?> -
-
- - diff --git a/app/code/Magento/Bundle/Pricing/Price/BasePrice.php b/app/code/Magento/Bundle/Pricing/Price/BasePrice.php deleted file mode 100644 index 28df06a393d01..0000000000000 --- a/app/code/Magento/Bundle/Pricing/Price/BasePrice.php +++ /dev/null @@ -1,67 +0,0 @@ -value === null) { - $this->value = $this->calculateBaseValue(parent::getValue()); - } - return $this->value; - } - - /** - * Calculate base price for passed regular one - * - * @param float $price - * @return float - */ - public function calculateBaseValue($price) - { - $discount = [ - 0, - $this->priceInfo->getPrice(CatalogPrice\TierPrice::PRICE_CODE, $this->quantity)->getValue(), - $this->priceInfo->getPrice(CatalogPrice\GroupPrice::PRICE_CODE, $this->quantity)->getValue(), - $this->priceInfo->getPrice(CatalogPrice\SpecialPrice::PRICE_CODE, $this->quantity)->getValue() - ]; - $discount = max($discount); - if ($discount) { - $price = $price - $price * ($discount / 100); - } - return $price; - } -} diff --git a/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php b/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php index 5cecd761e8c9a..871a2cdbd8369 100644 --- a/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/BundleOptionPrice.php @@ -125,7 +125,8 @@ public function getOptions() */ public function getOptionSelectionAmount($selection) { - $selectionPrice = $this->selectionFactory->create($this->product, $selection, $selection->getSelectionQty()); + $selectionPrice = $this->selectionFactory + ->create($this->product, $selection, $selection->getSelectionQty()); return $selectionPrice->getAmount(); } diff --git a/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php b/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php index b7cf63a490f38..8f773a152263a 100644 --- a/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/BundleSelectionPrice.php @@ -46,11 +46,6 @@ class BundleSelectionPrice extends AbstractPrice */ protected $bundleProduct; - /** - * @var BasePrice - */ - protected $bundleBasePrice; - /** * Event manager * @@ -58,25 +53,31 @@ class BundleSelectionPrice extends AbstractPrice */ protected $eventManager; + /** + * @var DiscountCalculator + */ + protected $discountCalculator; + /** * @param Product $saleableItem * @param float $quantity * @param CalculatorInterface $calculator * @param SaleableInterface $bundleProduct * @param ManagerInterface $eventManager + * @param DiscountCalculator $discountCalculator */ public function __construct( Product $saleableItem, $quantity, CalculatorInterface $calculator, SaleableInterface $bundleProduct, - ManagerInterface $eventManager + ManagerInterface $eventManager, + DiscountCalculator $discountCalculator ) { parent::__construct($saleableItem, $quantity, $calculator); $this->bundleProduct = $bundleProduct; - $this->bundleBasePrice = $this->bundleProduct->getPriceInfo() - ->getPrice(CatalogPrice\BasePrice::PRICE_CODE, $this->quantity); $this->eventManager = $eventManager; + $this->discountCalculator = $discountCalculator; } /** @@ -92,15 +93,15 @@ public function getValue() if ($this->bundleProduct->getPriceType() == Price::PRICE_TYPE_DYNAMIC) { $value = $this->priceInfo - ->getPrice(FinalPrice::PRICE_CODE, $this->quantity) + ->getPrice(FinalPrice::PRICE_CODE) ->getValue(); } else { if ($this->product->getSelectionPriceType()) { // calculate price for selection type percent - $product = clone $this->bundleProduct; - $price = $product->getPriceInfo() - ->getPrice(CatalogPrice\RegularPrice::PRICE_CODE, $this->quantity) + $price = $this->bundleProduct->getPriceInfo() + ->getPrice(CatalogPrice\RegularPrice::PRICE_CODE) ->getValue(); + $product = clone $this->bundleProduct; $product->setFinalPrice($price); $this->eventManager->dispatch( 'catalog_product_get_final_price', @@ -112,7 +113,7 @@ public function getValue() $value = $this->product->getSelectionPriceValue() * $this->quantity; } } - $this->value = $this->bundleBasePrice->calculateBaseValue($value); + $this->value = $this->discountCalculator->calculateDiscount($this->bundleProduct, $value); return $this->value; } } diff --git a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php index c5ccf76c17a29..fee3a136a41e7 100644 --- a/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/ConfiguredPrice.php @@ -45,6 +45,11 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice */ protected $calculator; + /** + * @var DiscountCalculator + */ + protected $discountCalculator; + /** * @var null|ItemInterface */ @@ -54,12 +59,14 @@ class ConfiguredPrice extends CatalogPrice\FinalPrice implements ConfiguredPrice * @param Product $saleableItem * @param float $quantity * @param BundleCalculatorInterface $calculator + * @param DiscountCalculator $discountCalculator * @param ItemInterface $item */ public function __construct( Product $saleableItem, $quantity, BundleCalculatorInterface $calculator, + DiscountCalculator $discountCalculator, ItemInterface $item = null ) { $this->item = $item; @@ -136,7 +143,10 @@ public function getValue() { if ($this->item) { $configuredOptionsAmount = $this->getConfiguredAmount()->getBaseAmount(); - return parent::getValue() + $this->basePrice->calculateBaseValue($configuredOptionsAmount); + return parent::getValue() + + $this->priceInfo + ->getPrice(BundleDiscountPrice::PRICE_CODE) + ->calculateDiscount($configuredOptionsAmount); } else { return parent::getValue(); } diff --git a/app/code/Magento/Bundle/Pricing/Price/DiscountCalculator.php b/app/code/Magento/Bundle/Pricing/Price/DiscountCalculator.php new file mode 100644 index 0000000000000..0578caaf9f782 --- /dev/null +++ b/app/code/Magento/Bundle/Pricing/Price/DiscountCalculator.php @@ -0,0 +1,55 @@ +getPriceInfo()->getPrice(FinalPrice::PRICE_CODE)->getValue(); + } + + $discount = null; + foreach ($product->getPriceInfo()->getPrices() as $price) { + if ($price instanceof DiscountProviderInterface && $price->getDiscountPercent()) { + $discount = min($price->getDiscountPercent(), $discount ?: $price->getDiscountPercent()); + } + } + return (null !== $discount) ? $discount/100 * $value : $value; + } +} diff --git a/app/code/Magento/Bundle/Pricing/Price/BasePriceInterface.php b/app/code/Magento/Bundle/Pricing/Price/DiscountProviderInterface.php similarity index 83% rename from app/code/Magento/Bundle/Pricing/Price/BasePriceInterface.php rename to app/code/Magento/Bundle/Pricing/Price/DiscountProviderInterface.php index 0ba4fa0f70bcc..9290d970457be 100644 --- a/app/code/Magento/Bundle/Pricing/Price/BasePriceInterface.php +++ b/app/code/Magento/Bundle/Pricing/Price/DiscountProviderInterface.php @@ -25,15 +25,12 @@ namespace Magento\Bundle\Pricing\Price; /** - * Bundle base price interface + * Interface DiscountProviderInterface */ -interface BasePriceInterface +interface DiscountProviderInterface { /** - * Calculate base price for passed regular one - * - * @param float $price * @return float */ - public function calculateBaseValue($price); + public function getDiscountPercent(); } diff --git a/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php b/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php index 9cee50e6073ae..20b476821d730 100644 --- a/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/FinalPrice.php @@ -24,8 +24,9 @@ namespace Magento\Bundle\Pricing\Price; +use Magento\Framework\Pricing\Adjustment\CalculatorInterface; use Magento\Catalog\Model\Product; -use Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface; +use Magento\Catalog\Pricing\Price\BasePrice; /** * Final price model @@ -33,29 +34,33 @@ class FinalPrice extends \Magento\Catalog\Pricing\Price\FinalPrice { /** - * Price type final + * @param Product $saleableItem + * @param float $quantity + * @param CalculatorInterface $calculator */ - const PRICE_CODE = 'final_price'; - - /** - * @var BundleCalculatorInterface - */ - protected $calculator; - - /** - * @var BasePrice - */ - protected $basePrice; + public function __construct( + Product $saleableItem, + $quantity, + CalculatorInterface $calculator + ) { + parent::__construct($saleableItem, $quantity, $calculator); + $this->basePrice = $this->priceInfo->getPrice(BasePrice::PRICE_CODE); + } /** + * Returns price value + * * @return float */ public function getValue() { - return parent::getValue() + $this->basePrice->calculateBaseValue($this->getBundleOptionPrice()->getValue()); + return parent::getValue() + + $this->getBundleOptionPrice()->getValue(); } /** + * Returns max price + * * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getMaximalPrice() @@ -64,6 +69,8 @@ public function getMaximalPrice() } /** + * Returns min price + * * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getMinimalPrice() @@ -72,6 +79,8 @@ public function getMinimalPrice() } /** + * Returns price amount + * * @return \Magento\Framework\Pricing\Amount\AmountInterface */ public function getAmount() @@ -80,10 +89,12 @@ public function getAmount() } /** + * Returns option price + * * @return \Magento\Bundle\Pricing\Price\BundleOptionPrice */ protected function getBundleOptionPrice() { - return $this->priceInfo->getPrice(BundleOptionPrice::PRICE_CODE, $this->quantity); + return $this->priceInfo->getPrice(BundleOptionPrice::PRICE_CODE); } } diff --git a/app/code/Magento/Bundle/Pricing/Price/GroupPrice.php b/app/code/Magento/Bundle/Pricing/Price/GroupPrice.php index 4395eecc3970d..03769bb671116 100644 --- a/app/code/Magento/Bundle/Pricing/Price/GroupPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/GroupPrice.php @@ -24,19 +24,35 @@ namespace Magento\Bundle\Pricing\Price; -use Magento\Customer\Model\Session; +use Magento\Catalog\Pricing\Price\RegularPrice; /** - * Bundle droup price model + * Bundle group price model */ -class GroupPrice extends \Magento\Catalog\Pricing\Price\GroupPrice +class GroupPrice extends \Magento\Catalog\Pricing\Price\GroupPrice implements DiscountProviderInterface { /** - * Price type group + * @var float|false */ - const PRICE_CODE = 'group_price'; + protected $percent; /** + * Returns percent discount value + * + * @return bool|float + */ + public function getDiscountPercent() + { + if ($this->percent === null) { + $percent = parent::getValue(); + $this->percent = ($percent) ? max(0, min(100, 100 - $percent)) : null; + } + return $this->percent; + } + + /** + * Returns pice value + * * @return float|bool */ public function getValue() @@ -45,10 +61,10 @@ public function getValue() return $this->value; } - $groupPrice = parent::getValue(); + $groupPrice = $this->getDiscountPercent(); if ($groupPrice) { - $basePrice = $this->getBasePrice(); - $this->value = $basePrice - $basePrice * ($groupPrice / 100); + $regularPrice = $this->getRegularPrice(); + $this->value = $regularPrice * ($groupPrice / 100); } else { $this->value = false; } @@ -56,13 +72,12 @@ public function getValue() } /** - * @param null|float $qty + * Returns regular price + * * @return bool|float */ - protected function getBasePrice($qty = null) + protected function getRegularPrice() { - return $this->priceInfo - ->getPrice(\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE) - ->getValue(); + return $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getValue(); } } diff --git a/app/code/Magento/Bundle/Pricing/Price/SpecialPrice.php b/app/code/Magento/Bundle/Pricing/Price/SpecialPrice.php index a77e9116b499e..79d70ef4f0711 100644 --- a/app/code/Magento/Bundle/Pricing/Price/SpecialPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/SpecialPrice.php @@ -24,19 +24,34 @@ namespace Magento\Bundle\Pricing\Price; -use Magento\Catalog\Pricing\Price\BasePrice as CatalogBasePrice; +use Magento\Catalog\Pricing\Price\RegularPrice; /** * Special price model */ -class SpecialPrice extends \Magento\Catalog\Pricing\Price\SpecialPrice +class SpecialPrice extends \Magento\Catalog\Pricing\Price\SpecialPrice implements DiscountProviderInterface { /** - * Price type special + * @var float|false */ - const PRICE_CODE = 'special_price'; + protected $percent; /** + * Returns discount percent + * + * @return bool|float + */ + public function getDiscountPercent() + { + if ($this->percent === null) { + $this->percent = parent::getValue(); + } + return $this->percent; + } + + /** + * Returns price value + * * @return bool|float */ public function getValue() @@ -45,10 +60,10 @@ public function getValue() return $this->value; } - $specialPrice = parent::getValue(); + $specialPrice = $this->getDiscountPercent(); if ($specialPrice) { - $basePrice = $this->getBasePrice(); - $this->value = $basePrice - $basePrice * ($specialPrice / 100); + $regularPrice = $this->getRegularPrice(); + $this->value = $regularPrice * ($specialPrice / 100); } else { $this->value = false; } @@ -56,12 +71,12 @@ public function getValue() } /** + * Returns regular price + * * @return bool|float */ - protected function getBasePrice() + protected function getRegularPrice() { - return $this->priceInfo - ->getPrice(CatalogBasePrice::PRICE_CODE) - ->getValue(); + return $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getValue(); } } diff --git a/app/code/Magento/Bundle/Pricing/Price/TierPrice.php b/app/code/Magento/Bundle/Pricing/Price/TierPrice.php index da2b8654b4000..9797f4fb57686 100644 --- a/app/code/Magento/Bundle/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Bundle/Pricing/Price/TierPrice.php @@ -24,20 +24,67 @@ namespace Magento\Bundle\Pricing\Price; +use Magento\Catalog\Pricing\Price\RegularPrice; + /** - * Bundle tire prices model + * Bundle tier prices model */ -class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice +class TierPrice extends \Magento\Catalog\Pricing\Price\TierPrice implements DiscountProviderInterface { /** - * Price type tier + * @var bool */ - const PRICE_CODE = 'tier_price'; + protected $filterByBasePrice = false; /** - * @var bool + * @var float|false */ - protected $filterByBasePrice = false; + protected $percent; + + /** + * Returns percent discount + * + * @return bool|float + */ + public function getDiscountPercent() + { + if ($this->percent === null) { + $percent = parent::getValue(); + $this->percent = ($percent) ? max(0, min(100, 100 - $percent)) : null; + } + return $this->percent; + } + + /** + * Returns pricing value + * + * @return bool|float + */ + public function getValue() + { + if ($this->value !== null) { + return $this->value; + } + + $tierPrice = $this->getDiscountPercent(); + if ($tierPrice) { + $regularPrice = $this->getRegularPrice(); + $this->value = $regularPrice * ($tierPrice / 100); + } else { + $this->value = false; + } + return $this->value; + } + + /** + * Returns regular price + * + * @return bool|float + */ + protected function getRegularPrice() + { + return $this->priceInfo->getPrice(RegularPrice::PRICE_CODE)->getValue(); + } /** * Returns true if first price is better diff --git a/app/code/Magento/Bundle/etc/di.xml b/app/code/Magento/Bundle/etc/di.xml index ecdb2efc91120..9db37f542c836 100644 --- a/app/code/Magento/Bundle/etc/di.xml +++ b/app/code/Magento/Bundle/etc/di.xml @@ -68,10 +68,10 @@ Magento\Catalog\Pricing\Price\RegularPrice Magento\Bundle\Pricing\Price\FinalPrice Magento\Bundle\Pricing\Price\TierPrice - Magento\Catalog\Pricing\Price\GroupPrice - Magento\Catalog\Pricing\Price\SpecialPrice + Magento\Bundle\Pricing\Price\GroupPrice + Magento\Bundle\Pricing\Price\SpecialPrice Magento\Catalog\Pricing\Price\MsrpPrice - Magento\Bundle\Pricing\Price\BasePrice + Magento\Catalog\Pricing\Price\BasePrice Magento\Bundle\Pricing\Price\ConfiguredPrice Magento\Bundle\Pricing\Price\BundleOptionPrice diff --git a/app/code/Magento/Bundle/view/frontend/templates/js/components.phtml b/app/code/Magento/Bundle/view/frontend/templates/js/components.phtml index a5ce58abec93f..231b8c0bc5d6c 100644 --- a/app/code/Magento/Bundle/view/frontend/templates/js/components.phtml +++ b/app/code/Magento/Bundle/view/frontend/templates/js/components.phtml @@ -33,6 +33,7 @@ 'getViewFileUrl('mage/sticky.js') ?>' ], bundleOption: [ + 'getViewFileUrl('Magento_Catalog::js/price-option.js') ?>', 'getViewFileUrl('Magento_Bundle::bundle.js') ?>' ], slide: [ diff --git a/app/code/Magento/Bundle/view/frontend/web/bundle.js b/app/code/Magento/Bundle/view/frontend/web/bundle.js index e5b6ae3ccd629..4ac75e5ae6083 100644 --- a/app/code/Magento/Bundle/view/frontend/web/bundle.js +++ b/app/code/Magento/Bundle/view/frontend/web/bundle.js @@ -60,6 +60,9 @@ } }, _create: function() { + this.element.on('reloadPrice', $.proxy(function() { + this.reloadPrice(); + }, this)); $(this.options.productBundleSelector).each( $.proxy(function(key, value) { var element = $(value), diff --git a/app/code/Magento/Catalog/Block/Adminhtml/Product/Options/Ajax.php b/app/code/Magento/Catalog/Block/Adminhtml/Product/Options/Ajax.php index 3c03cf2539e59..9b3806ed2a112 100644 --- a/app/code/Magento/Catalog/Block/Adminhtml/Product/Options/Ajax.php +++ b/app/code/Magento/Catalog/Block/Adminhtml/Product/Options/Ajax.php @@ -29,6 +29,8 @@ */ namespace Magento\Catalog\Block\Adminhtml\Product\Options; +use \Magento\Store\Model\Store; + class Ajax extends \Magento\Backend\Block\AbstractBlock { /** @@ -96,7 +98,9 @@ protected function _toHtml() $products = $this->_coreRegistry->registry('import_option_products'); if (is_array($products)) { foreach ($products as $productId) { - $product = $this->_productFactory->create()->load((int)$productId); + $product = $this->_productFactory->create(); + $product->setStoreId($this->getRequest()->getParam('store', Store::DEFAULT_STORE_ID)); + $product->load((int)$productId); if (!$product->getId()) { continue; } diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product.php index ccacef68d5b49..590abfe64646b 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product.php @@ -196,7 +196,11 @@ public function newAction() $this->_eventManager->dispatch('catalog_product_new_action', array('product' => $product)); if ($this->getRequest()->getParam('popup')) { - $this->_view->loadLayout('popup'); + $this->_view->loadLayout(array( + 'popup', + strtolower($this->_request->getFullActionName()), + 'catalog_product_' . $product->getTypeId() + )); } else { $this->_view->loadLayout( array( diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index ac0cfcd7a40bb..e16c7a36c3bd5 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -41,26 +41,34 @@ class Helper protected $stockFilter; /** - * @var Helper\ProductLinks + * @var \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks */ protected $productLinks; + /** + * @var \Magento\Backend\Helper\Js + */ + protected $jsHelper; + /** * @param \Magento\Framework\App\RequestInterface $request * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param StockDataFilter $stockFilter - * @param Helper\ProductLinks $productLinks + * @param \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks + * @param \Magento\Backend\Helper\Js $jsHelper */ public function __construct( \Magento\Framework\App\RequestInterface $request, \Magento\Store\Model\StoreManagerInterface $storeManager, StockDataFilter $stockFilter, - Helper\ProductLinks $productLinks + \Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks, + \Magento\Backend\Helper\Js $jsHelper ) { $this->request = $request; $this->storeManager = $storeManager; $this->stockFilter = $stockFilter; $this->productLinks = $productLinks; + $this->jsHelper = $jsHelper; } /** @@ -117,7 +125,15 @@ public function initialize(\Magento\Catalog\Model\Product $product) } } - $product = $this->productLinks->initializeLinks($product); + $links = $this->request->getPost('links'); + $links = is_array($links) ? $links : array(); + $linkTypes = array('related', 'upsell', 'crosssell'); + foreach ($linkTypes as $type) { + if (isset($links[$type])) { + $links[$type] = $this->jsHelper->decodeGridSerializedInput($links[$type]); + } + } + $product = $this->productLinks->initializeLinks($product, $links); /** * Initialize product options diff --git a/app/code/Magento/Catalog/Model/Product.php b/app/code/Magento/Catalog/Model/Product.php index 7db9c80726f68..ff187dc790845 100644 --- a/app/code/Magento/Catalog/Model/Product.php +++ b/app/code/Magento/Catalog/Model/Product.php @@ -36,6 +36,7 @@ * @method array getAssociatedProductIds() * @method \Magento\Catalog\Model\Product setNewVariationsAttributeSetId(int $value) * @method int getNewVariationsAttributeSetId() + * @method int getPriceType * @method \Magento\Catalog\Model\Resource\Product\Collection getCollection() * * @SuppressWarnings(PHPMD.LongVariable) @@ -735,7 +736,9 @@ protected function _afterSave() /** * Product Options */ - $this->getOptionInstance()->setProduct($this)->saveOptions(); + if (!$this->getIsDuplicate()) { + $this->getOptionInstance()->setProduct($this)->saveOptions(); + } $result = parent::_afterSave(); @@ -1945,7 +1948,7 @@ protected function _clearReferences() protected function _clearData() { foreach ($this->_data as $data) { - if (is_object($data) && method_exists($data, 'reset')) { + if (is_object($data) && method_exists($data, 'reset') && is_callable([$data, 'reset'])) { $data->reset(); } } diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php index f71b38cdd269a..a6b2cd70383d9 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Backend/Media.php @@ -311,12 +311,13 @@ public function afterSave($object) $picturesInOtherStores[$image['filepath']] = true; } - $toDelete = array(); - $filesToValueIds = array(); + $recordsToDelete = array(); + $filesToDelete = array(); foreach ($value['images'] as &$image) { if (!empty($image['removed'])) { if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) { - $toDelete[] = $image['value_id']; + $recordsToDelete[] = $image['value_id']; + $filesToDelete[] = ltrim($image['file'], '/'); } continue; } @@ -343,18 +344,31 @@ public function afterSave($object) $this->_getResource()->insertGalleryValueInStore($data); } - $this->_getResource()->deleteGallery($toDelete); + $this->_getResource()->deleteGallery($recordsToDelete); + $this->removeDeletedImages($filesToDelete); + } + + /** + * @param array $files + * @return null + */ + protected function removeDeletedImages(array $files) + { + $catalogPath = $this->_mediaConfig->getBaseMediaPath(); + foreach ($files as $filePath) { + $this->_mediaDirectory->delete($catalogPath . '/' . $filePath); + } } /** * Add image to media gallery and return new filename * * @param \Magento\Catalog\Model\Product $product - * @param string $file file path of image in file system - * @param string|string[] $mediaAttribute code of attribute with type 'media_image', + * @param string $file file path of image in file system + * @param string|string[] $mediaAttribute code of attribute with type 'media_image', * leave blank if image should be only in gallery - * @param boolean $move if true, it will move source file - * @param boolean $exclude mark image as disabled in product page view + * @param boolean $move if true, it will move source file + * @param boolean $exclude mark image as disabled in product page view * @return string * @throws Exception */ diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php index 4ba00a2019e31..c32408dcee690 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php @@ -74,7 +74,7 @@ public function __construct( */ public function getAllOptions() { - $cacheKey = 'DIRECTORY_COUNTRY_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); + $cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode(); if ($cache = $this->_configCacheType->load($cacheKey)) { $options = unserialize($cache); } else { diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks.php b/app/code/Magento/Catalog/Model/Product/Initialization/Helper/ProductLinks.php similarity index 57% rename from app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks.php rename to app/code/Magento/Catalog/Model/Product/Initialization/Helper/ProductLinks.php index b5e7c7277e48b..0059bcddf8f2d 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks.php +++ b/app/code/Magento/Catalog/Model/Product/Initialization/Helper/ProductLinks.php @@ -21,50 +21,29 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper; +namespace Magento\Catalog\Model\Product\Initialization\Helper; class ProductLinks { - /** - * @var \Magento\Framework\App\RequestInterface - */ - protected $request; - - /** - * @var \Magento\Backend\Helper\Js - */ - protected $jsHelper; - - /** - * @param \Magento\Framework\App\RequestInterface $request - * @param \Magento\Backend\Helper\Js $jsHelper - */ - public function __construct(\Magento\Framework\App\RequestInterface $request, \Magento\Backend\Helper\Js $jsHelper) - { - $this->request = $request; - $this->jsHelper = $jsHelper; - } - - /** - * Init product links data (related, upsell, crosssel) + /** + * Init product links data (related, upsell, cross sell) * * @param \Magento\Catalog\Model\Product $product + * @param array $links link data * @return \Magento\Catalog\Model\Product */ - public function initializeLinks(\Magento\Catalog\Model\Product $product) + public function initializeLinks(\Magento\Catalog\Model\Product $product, array $links) { - $links = $this->request->getPost('links'); - if (isset($links['related']) && !$product->getRelatedReadonly()) { - $product->setRelatedLinkData($this->jsHelper->decodeGridSerializedInput($links['related'])); + $product->setRelatedLinkData($links['related']); } if (isset($links['upsell']) && !$product->getUpsellReadonly()) { - $product->setUpSellLinkData($this->jsHelper->decodeGridSerializedInput($links['upsell'])); + $product->setUpSellLinkData($links['upsell']); } if (isset($links['crosssell']) && !$product->getCrosssellReadonly()) { - $product->setCrossSellLinkData($this->jsHelper->decodeGridSerializedInput($links['crosssell'])); + $product->setCrossSellLinkData($links['crosssell']); } return $product; diff --git a/app/code/Magento/Catalog/Model/Resource/Product.php b/app/code/Magento/Catalog/Model/Resource/Product.php index a85a27dac44c3..c7b0aaefd0e45 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product.php +++ b/app/code/Magento/Catalog/Model/Resource/Product.php @@ -504,6 +504,29 @@ public function getProductsSku(array $productIds) return $this->_getReadAdapter()->fetchAll($select); } + /** + * Get product ids by their sku + * + * @param array $productSkuList + * @return array + */ + public function getProductsIdsBySkus(array $productSkuList) + { + $select = $this->_getReadAdapter()->select()->from( + $this->getTable('catalog_product_entity'), + array('sku', 'entity_id') + )->where( + 'sku IN (?)', + $productSkuList + ); + + $result = array(); + foreach ($this->_getReadAdapter()->fetchAll($select) as $row) { + $result[$row['sku']] = $row['entity_id']; + } + return $result; + } + /** * Retrieve product entities info * diff --git a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Eav/Source.php b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Eav/Source.php index 74586a3810703..fea812a89549c 100644 --- a/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Eav/Source.php +++ b/app/code/Magento/Catalog/Model/Resource/Product/Indexer/Eav/Source.php @@ -140,6 +140,14 @@ protected function _prepareSelectIndex($entityIds = null, $attributeId = null) array('d' => $this->getTable('catalog_product_entity_int')), '1 = 1 AND d.store_id = 0', array('entity_id', 'attribute_id', 'value') + )->joinInner( + array('d2' => $this->getTable('catalog_product_entity_int')), + sprintf( + 'd.entity_id = d2.entity_id AND d2.attribute_id = %s AND d2.value = %s AND d.store_id = 0', + $this->_eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'status')->getId(), + ProductStatus::STATUS_ENABLED + ), + array() )->where( 's.store_id != 0' ); diff --git a/app/code/Magento/Catalog/Pricing/Price/BasePrice.php b/app/code/Magento/Catalog/Pricing/Price/BasePrice.php index 8323a941037c2..ec2c1790c750a 100644 --- a/app/code/Magento/Catalog/Pricing/Price/BasePrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/BasePrice.php @@ -25,6 +25,7 @@ namespace Magento\Catalog\Pricing\Price; use Magento\Framework\Pricing\Price\AbstractPrice; +use Magento\Framework\Pricing\Price\BasePriceProviderInterface; /** * Class BasePrice @@ -45,9 +46,8 @@ public function getValue() { if ($this->value === null) { $this->value = false; - foreach ($this->priceInfo->getPrices() as $code => $price) { - if ($price instanceof \Magento\Framework\Pricing\Price\BasePriceProviderInterface && $price->getValue() - ) { + foreach ($this->priceInfo->getPrices() as $price) { + if ($price instanceof BasePriceProviderInterface && $price->getValue()) { $this->value = min($price->getValue(), $this->value ? : $price->getValue()); } } diff --git a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php index 8a34bf7b83453..8d0f92769d46b 100644 --- a/app/code/Magento/Catalog/Pricing/Price/TierPrice.php +++ b/app/code/Magento/Catalog/Pricing/Price/TierPrice.php @@ -86,6 +86,7 @@ public function __construct( CalculatorInterface $calculator, Session $customerSession ) { + $quantity = $quantity ?: 1; parent::__construct($saleableItem, $quantity, $calculator); $this->customerSession = $customerSession; if ($saleableItem->hasCustomerGroupId()) { diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/Attribute.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/Attribute.php new file mode 100644 index 0000000000000..33c971db73b9b --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/Attribute.php @@ -0,0 +1,98 @@ +_get(self::ID); + } + + /** + * Get attribute code + * + * @return string + */ + public function getCode() + { + return $this->_get(self::CODE); + } + + /** + * Get attribute frontend label + * + * @return string|null + */ + public function getFrontendLabel() + { + return $this->_get(self::LABEL); + } + + /** + * Get attribute default value + * + * @return string|null + */ + public function getDefaultValue() + { + return $this->_get(self::DEFAULT_VALUE); + } + + /** + * Get attribute is_required flag + * + * @return boolean + * @SuppressWarnings(PHPMD.BooleanGetMethodName) + */ + public function getIsRequired() + { + return $this->_get(self::IS_REQUIRED); + } + + /** + * Get attribute is_user_defined flag + * + * @return boolean + * @SuppressWarnings(PHPMD.BooleanGetMethodName) + */ + public function getIsUserDefined() + { + return $this->_get(self::IS_USER_DEFINED); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeBuilder.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeBuilder.php new file mode 100644 index 0000000000000..55cbfbabcc41a --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeBuilder.php @@ -0,0 +1,95 @@ +_set(Attribute::ID, $attributeId); + } + + /** + * Set attribute code + * + * @param string $code + * @return $this + */ + public function setCode($code) + { + return $this->_set(Attribute::CODE, $code); + } + + /** + * Set attribute frontend label + * + * @param string|null $frontendLabel + * @return $this + */ + public function setFrontendLabel($frontendLabel) + { + return $this->_set(Attribute::LABEL, $frontendLabel); + } + + /** + * Set attribute default value + * + * @param string|null $defaultValue + * @return $this + */ + public function setDefaultValue($defaultValue) + { + return $this->_set(Attribute::DEFAULT_VALUE, $defaultValue); + } + + /** + * Set attribute is_required flag + * + * @param boolean $isRequired + * @return $this + */ + public function setIsRequired($isRequired) + { + return $this->_set(Attribute::IS_REQUIRED, $isRequired); + } + + /** + * Set attribute is_user_defined flag + * + * @param boolean $isUserDefined + * @return $this + */ + public function setIsUserDefined($isUserDefined) + { + return $this->_set(Attribute::IS_USER_DEFINED, $isUserDefined); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/Links.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroup.php similarity index 63% rename from dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/Links.php rename to app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroup.php index b5277047efe22..6c171121b0930 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/Links.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroup.php @@ -1,5 +1,6 @@ _get(self::KEY_ID); + } /** - * @param array $links + * Retrieve name + * + * @return string */ - public function check($links) + public function getName() { - foreach ($links as $link) { - $xpath = sprintf($this->labelByTitleSelectorTemplate, $link['title']); - $this->_rootElement->find($xpath, Locator::SELECTOR_XPATH)->click(); - } + return $this->_get(self::KEY_NAME); } } diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroupBuilder.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroupBuilder.php new file mode 100644 index 0000000000000..84b2a10e7033a --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeGroupBuilder.php @@ -0,0 +1,52 @@ +_set(AttributeGroup::KEY_ID, $id); + return $this; + } + + /** + * Set name + * + * @param string $name + * @return $this + */ + public function setName($name) + { + $this->_set(AttributeGroup::KEY_NAME, $name); + return $this; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php new file mode 100644 index 0000000000000..5252a88c30ce9 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet.php @@ -0,0 +1,75 @@ +_get(self::ID); + } + + /** + * Get attribute set name + * + * @return string + */ + public function getName() + { + return $this->_get(self::NAME); + } + + /** + * Get attribute set sort order index + * + * @return int + */ + public function getSortOrder() + { + return $this->_get(self::ORDER); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/Attribute.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/Attribute.php new file mode 100644 index 0000000000000..09162ff996916 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/Attribute.php @@ -0,0 +1,72 @@ +_get(self::ATTRIBUTE_ID); + } + + /** + * Get attribute id + * + * @return string + */ + public function getAttributeGroupId() + { + return $this->_get(self::ATTRIBUTE_GROUP_ID); + } + + /** + * Get attribute set sort order index + * + * @return int + */ + public function getSortOrder() + { + return $this->_get(self::SORT_ORDER); + } +} diff --git a/app/code/Magento/Payment/Model/Config/Source/Allowedmethods.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/AttributeBuilder.php similarity index 57% rename from app/code/Magento/Payment/Model/Config/Source/Allowedmethods.php rename to app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/AttributeBuilder.php index cf670020111a6..e7d5faf8f021f 100644 --- a/app/code/Magento/Payment/Model/Config/Source/Allowedmethods.php +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSet/AttributeBuilder.php @@ -21,38 +21,40 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\Payment\Model\Config\Source; +namespace Magento\Catalog\Service\V1\Data\Eav\AttributeSet; -class Allowedmethods extends \Magento\Payment\Model\Config\Source\Allmethods +class AttributeBuilder extends \Magento\Framework\Service\Data\AbstractObjectBuilder { /** - * Payment config model + * Set attribute group id * - * @var \Magento\Payment\Model\Config + * @param string $id + * @return $this */ - protected $_paymentConfig; + public function setAttributeGroupId($id) + { + return $this->_set(Attribute::ATTRIBUTE_GROUP_ID, $id); + } /** - * Construct + * Get attribute id * - * @param \Magento\Payment\Helper\Data $paymentData - * @param \Magento\Payment\Model\Config $paymentConfig + * @param string $id + * @return $this */ - public function __construct( - \Magento\Payment\Helper\Data $paymentData, - \Magento\Payment\Model\Config $paymentConfig - ) { - parent::__construct($paymentData); - $this->_paymentConfig = $paymentConfig; + public function setAttributeId($id) + { + return $this->_set(Attribute::ATTRIBUTE_ID, $id); } /** - * Get payment methods + * Set attribute set sort order index * - * @return array + * @param int $index + * @return $this */ - protected function _getPaymentMethods() + public function setSortOrder($index) { - return $this->_paymentConfig->getActiveMethods(); + return $this->_set(Attribute::SORT_ORDER, $index); } } diff --git a/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSetBuilder.php b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSetBuilder.php new file mode 100644 index 0000000000000..cf90d2ce147d4 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/Eav/AttributeSetBuilder.php @@ -0,0 +1,63 @@ +_set(AttributeSet::ID, $id); + } + + /** + * Set attribute set name + * + * @param string $name + * @return $this + */ + public function setName($name) + { + return $this->_set(AttributeSet::NAME, $name); + } + + /** + * Set attribute set sort order index + * + * @param int $index + * @return $this + */ + public function setSortOrder($index) + { + return $this->_set(AttributeSet::ORDER, $index); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Data/ProductType.php b/app/code/Magento/Catalog/Service/V1/Data/ProductType.php new file mode 100644 index 0000000000000..b7a4a49e5ecb1 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/ProductType.php @@ -0,0 +1,54 @@ +_get(self::NAME); + } + + /** + * Retrieve product type label + * + * @return string + */ + public function getLabel() + { + return $this->_get(self::LABEL); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Data/ProductTypeBuilder.php b/app/code/Magento/Catalog/Service/V1/Data/ProductTypeBuilder.php new file mode 100644 index 0000000000000..df36d34454c5e --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Data/ProductTypeBuilder.php @@ -0,0 +1,53 @@ +_set(ProductType::NAME, $name); + } + + /** + * Set product type label + * + * @param string $label + * @return $this + */ + public function setLabel($label) + { + return $this->_set(ProductType::LABEL, $label); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadService.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadService.php new file mode 100644 index 0000000000000..3307a26979be8 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadService.php @@ -0,0 +1,77 @@ +groupListFactory = $groupListFactory; + $this->groupBuilder = $groupBuilder; + } + + /** + * {@inheritdoc} + */ + public function getList($attributeSetId) + { + $collection = $this->groupListFactory->create(); + $collection->setAttributeSetFilter($attributeSetId); + $collection->setSortOrder(); + + $groups = array(); + + /** @var $group \Magento\Eav\Model\Entity\Attribute\Group */ + foreach ($collection->getItems() as $group) { + $this->groupBuilder->setId( + $group->getId() + )->setName( + $group->getAttributeGroupName() + ); + $groups[] = $this->groupBuilder->create(); + } + return $groups; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php new file mode 100644 index 0000000000000..ae4eaba782b57 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceInterface.php @@ -0,0 +1,36 @@ +groupFactory = $groupFactory; + $this->groupBuilder = $groupBuilder; + } + + /** + * {inheritdoc} + */ + public function create($attributeSetId, \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup $groupData) + { + try { + /** @var Group $attributeGroup */ + $attributeGroup = $this->groupFactory->create(); + $attributeGroup->setAttributeGroupName($groupData->getName()); + $attributeGroup->setAttributeSetId($attributeSetId); + $attributeGroup->save(); + return $this->groupBuilder->setId( + $attributeGroup->getId() + )->setName( + $attributeGroup->getAttributeGroupName() + )->create(); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not create attribute group'); + } + } + + /** + * {@inheritdoc} + */ + public function update($groupId, \Magento\Catalog\Service\V1\Data\Eav\AttributeGroup $groupData) + { + /** @var Group $attributeGroup */ + $attributeGroup = $this->groupFactory->create(); + $attributeGroup->load($groupId); + if (!$attributeGroup->getId()) { + throw new NoSuchEntityException(); + } + try { + $attributeGroup->setId($groupData->getId()); + $attributeGroup->setAttributeGroupName($groupData->getName()); + $attributeGroup->save(); + } catch (\Exception $e) { + throw new CouldNotSaveException('Could not update attribute group'); + } + } + + /** + * {@inheritdoc} + */ + public function delete($groupId) + { + /** @var Group $attributeGroup */ + $attributeGroup = $this->groupFactory->create(); + $attributeGroup->load($groupId); + if ($attributeGroup->hasSystemAttributes()) { + throw new StateException('Attribute group that contains system attributes can not be deleted'); + } + if (!$attributeGroup->getId()) { + throw new NoSuchEntityException(); + } + $attributeGroup->delete(); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php new file mode 100644 index 0000000000000..3d3c396539eed --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceInterface.php @@ -0,0 +1,59 @@ +attributeFactory = $attributeFactory; + $this->groupFactory = $groupFactory; + $this->setFactory = $setFactory; + $this->attributeResource = $attributeResource; + $this->entityTypeFactory = $entityTypeFactory; + } + + /** + * Add attribute to attribute set and group + * + * @param int $attributeSetId + * @param Data\Eav\AttributeSet\Attribute $data + * @return int + * @throws \Magento\Framework\Exception\InputException + */ + public function addAttribute($attributeSetId, \Magento\Catalog\Service\V1\Data\Eav\AttributeSet\Attribute $data) + { + $attributeSet = $this->setFactory->create()->load($attributeSetId); + if (!$attributeSet->getId()) { + throw new InputException('Attribute set does not exist'); + } + + $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); + if ($setEntityType->getEntityTypeCode() != \Magento\Catalog\Model\Product::ENTITY) { + throw new InputException('Wrong attribute set id provided'); + } + + if (!$this->groupFactory->create()->load($data->getAttributeGroupId())->getId()) { + throw new InputException('Attribute group does not exist'); + } + + $attribute = $this->attributeFactory->create(); + if (!$attribute->load($data->getAttributeId())->getId()) { + throw new InputException('Attribute does not exist'); + } + + $attribute->setId($data->getAttributeId()); + $attribute->setEntityTypeId($setEntityType->getId()); + $attribute->setAttributeSetId($attributeSetId); + $attribute->setAttributeGroupId($data->getAttributeGroupId()); + $attribute->setSortOrder($data->getSortOrder()); + + $this->attributeResource->saveInSetIncluding($attribute); + return $attribute->loadEntityAttributeIdBySet()->getData('entity_attribute_id'); + } + + /** + * @param string $attributeSetId + * @param string $attributeId + * @return bool + * @throws \Magento\Framework\Exception\InputException + * @throws \Magento\Framework\Exception\StateException + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function deleteAttribute($attributeSetId, $attributeId) + { + $attributeSet = $this->setFactory->create()->load($attributeSetId); + if (!$attributeSet->getId()) { + // Attribute set does not exist + throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); + } + // check that attribute set has type catalog_product + $setEntityType = $this->entityTypeFactory->create()->getEntityType($attributeSet->getEntityTypeId()); + if ($setEntityType->getEntityTypeCode() != \Magento\Catalog\Model\Product::ENTITY) { + throw new InputException('Attribute with wrong attribute type is provided'); + } + + // check if attribute with requested id exists + $attribute = $this->attributeFactory->create()->load($attributeId); + if (!$attribute->getId()) { + // Attribute set does not exist + throw NoSuchEntityException::singleField('attributeId', $attributeId); + } + // check if attribute is in set + $attribute->setAttributeSetId($attributeSet->getId())->loadEntityAttributeIdBySet(); + if (!$attribute->getEntityAttributeId()) { + throw new InputException('Requested attribute is not in requested attribute set.'); + } + if (!$attribute->getIsUserDefined()) { + throw new StateException('System attribute can not be deleted'); + } + $attribute->deleteEntity(); + return true; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php new file mode 100644 index 0000000000000..0e6d39281ba0e --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceInterface.php @@ -0,0 +1,46 @@ +setFactory = $setFactory; + $this->setCollectionFactory = $setCollectionFactory; + $this->eavConfig = $eavConfig; + $this->attributeSetBuilder = $attributeSetBuilder; + $this->attributeCollection = $attributeCollection; + $this->attributeBuilder = $attributeBuilder; + } + + /** + * {@inheritdoc} + */ + public function getList() + { + $sets = array(); + + $attributeSetsCollection = $this->setCollectionFactory->create() + ->setEntityTypeFilter($this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId()) + ->load(); + + /** @var $attributeSet \Magento\Eav\Model\Resource\Entity\Attribute\Set */ + foreach ($attributeSetsCollection as $attributeSet) { + $this->attributeSetBuilder->setId($attributeSet->getId()); + $this->attributeSetBuilder->setName($attributeSet->getAttributeSetName()); + $this->attributeSetBuilder->setSortOrder($attributeSet->getSortOrder()); + $sets[] = $this->attributeSetBuilder->create(); + } + + return $sets; + } + + /** + * {@inheritdoc} + */ + public function getInfo($attributeSetId) + { + $attributeSet = $this->setFactory->create()->load($attributeSetId); + $requiredEntityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if (!$attributeSet->getId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) { + // Attribute set does not exist + throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); + } + $attrSetDataObject = $this->attributeSetBuilder->setId($attributeSet->getId()) + ->setName($attributeSet->getAttributeSetName()) + ->setSortOrder($attributeSet->getSortOrder()) + ->create(); + return $attrSetDataObject; + } + + /** + * {@inheritdoc} + */ + public function getAttributeList($attributeSetId) + { + /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */ + $attributeSet = $this->setFactory->create()->load($attributeSetId); + $requiredEntityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if (!$attributeSet->getId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) { + // Attribute set does not exist + throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId); + } + $attributeCollection = $this->attributeCollection->setAttributeSetFilter($attributeSet->getId())->load(); + + $attributes = array(); + /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ + foreach ($attributeCollection as $attribute) { + $attributes[] = $this->attributeBuilder->setId($attribute->getAttributeId()) + ->setCode($attribute->getAttributeCode()) + ->setFrontendLabel($attribute->getData('frontend_label')) + ->setDefaultValue($attribute->getDefaultValue()) + ->setIsRequired((boolean)$attribute->getData('is_required')) + ->setIsUserDefined((boolean)$attribute->getData('is_user_defined')) + ->create(); + } + return $attributes; + + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php new file mode 100644 index 0000000000000..dc9e766fbab2d --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceInterface.php @@ -0,0 +1,50 @@ +setFactory = $setFactory; + $this->eavConfig = $eavConfig; + } + + /** + * {@inheritdoc} + */ + public function create(AttributeSet $setData, $skeletonId) + { + if ($setData->getId()) { + throw InputException::invalidFieldValue('id', $setData->getId()); + } + + $basicData = array( + 'attribute_set_name' => $setData->getName(), + 'sort_order' => $setData->getSortOrder(), + 'entity_type_id' => $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(), + ); + + /** @var \Magento\Eav\Model\Entity\Attribute\Set $set */ + $set = $this->setFactory->create(); + foreach ($basicData as $key => $value) { + $set->setData($key, $value); + } + $set->validate(); + $set->save(); + //process skeleton data + $skeletonId = intval($skeletonId); + if (0 == $skeletonId) { + throw InputException::invalidFieldValue('skeletonId', $skeletonId); + } + + $skeletonSet = $this->setFactory->create()->load($skeletonId); + $skeletonData = $skeletonSet->getData(); + if (empty($skeletonData)) { + throw NoSuchEntityException::singleField('id', $skeletonId); + } + $set->initFromSkeleton($skeletonId); + $set->save(); + + return $set->getId(); + } + + /** + * {@inheritdoc} + */ + public function update(AttributeSet $attributeSetData) + { + if (!$attributeSetData->getId()) { + throw InputException::requiredField('id'); + } + + $attributeSetModel = $this->setFactory->create()->load($attributeSetData->getId()); + $requiredEntityTypeId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if (!$attributeSetModel->getId() || $attributeSetModel->getEntityTypeId() != $requiredEntityTypeId) { + throw NoSuchEntityException::singleField('id', $attributeSetData->getId()); + } + + $attributeSetModel->setAttributeSetName($attributeSetData->getName()); + $attributeSetModel->setSortOrder($attributeSetData->getSortOrder()); + $attributeSetModel->save(); + return $attributeSetModel->getId(); + } + + /** + * {@inheritdoc} + */ + public function remove($attributeSetId) + { + $id = intval($attributeSetId); + if (0 == $id) { + throw InputException::invalidFieldValue('id', $id); + } + + /** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */ + $attributeSet = $this->setFactory->create()->load($id); + $defaultAttributeSetId = + $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getDefaultAttributeSetId(); + $loadedData = $attributeSet->getData(); + if (empty($loadedData)) { + throw NoSuchEntityException::singleField('id', $attributeSetId); + } + $productEntityId = $this->eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId(); + if ($attributeSet->getEntityTypeId() != $productEntityId) { + throw InputException::invalidFieldValue('id', $attributeSetId); + } + + if ($attributeSetId == $defaultAttributeSetId) { + throw new StateException('Default attribute set can not be deleted'); + } + $attributeSet->delete(); + return true; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php new file mode 100644 index 0000000000000..39fb14686afce --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceInterface.php @@ -0,0 +1,64 @@ +_get(self::CODE); + } + + /** + * Get attribute type + * + * @return string + */ + public function getType() + { + return $this->_get(self::TYPE); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Tar.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttributeBuilder.php similarity index 62% rename from dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Tar.php rename to app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttributeBuilder.php index 6d496cefe1c38..24da159e9b569 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Tar.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkAttributeBuilder.php @@ -22,36 +22,34 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ +namespace Magento\Catalog\Service\V1\Product\Link\Data; + /** - * Mock class to work with tar archives + * Builder for the LinkAttribute Service Data Object + * + * @method LinkAttribute create() */ -namespace Magento\Framework\Backup\Archive; - -class Tar +class LinkAttributeBuilder extends \Magento\Framework\Service\Data\AbstractObjectBuilder { /** - * Mock set files that shouldn't be added to tarball + * Set attribute code * - * @param array $skipFiles + * @param string $code * @return $this - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function setSkipFiles(array $skipFiles) + public function setCode($code) { - return $this; + return $this->_set(LinkAttribute::CODE, $code); } /** - * Mock pack file to TAR (Tape Archiver). + * Set type * - * @param $source - * @param $destination - * @param bool $skipRoot - * @return string - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param string $type + * @return $this */ - public function pack($source, $destination, $skipRoot = false) + public function setType($type) { - return '\unexistingpath'; + return $this->_set(LinkAttribute::TYPE, $type); } } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php new file mode 100644 index 0000000000000..94269b810145e --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkType.php @@ -0,0 +1,57 @@ +_get(self::TYPE); + } + + /** + * Get code + * + * @return int + */ + public function getCode() + { + return $this->_get(self::CODE); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkTypeBuilder.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkTypeBuilder.php new file mode 100644 index 0000000000000..3abf3bfb8d268 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/LinkTypeBuilder.php @@ -0,0 +1,55 @@ +_set(LinkType::TYPE, $type); + } + + /** + * Set code + * + * @param int $code + * @return $this + */ + public function setCode($code) + { + return $this->_set(LinkType::CODE, $code); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php new file mode 100644 index 0000000000000..f809e6c5e1ad3 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink.php @@ -0,0 +1,69 @@ +_get(self::TYPE); + } + + /** + * Get product sku + * + * @return string + */ + public function getSku() + { + return $this->_get(self::SKU); + } + + /** + * Get product position + * + * @return int + */ + public function getPosition() + { + return $this->_get(self::POSITION); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider.php new file mode 100644 index 0000000000000..52a5629b1da4f --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider.php @@ -0,0 +1,74 @@ +converterPool = $converterPool; + $this->providers = $providers; + } + + /** + * Get product collection by link type + * + * @param \Magento\Catalog\Model\Product $product + * @param string $type + * @return array + * @throws NoSuchEntityException + */ + public function getCollection(\Magento\Catalog\Model\Product $product, $type) + { + if (!isset($this->providers[$type])) { + throw new NoSuchEntityException('Collection provider is not registered'); + } + + $products = $this->providers[$type]->getLinkedProducts($product); + $converter = $this->converterPool->getConverter($type); + $output = []; + foreach ($products as $item) { + $output[$item->getId()] = $converter->convert($item); + } + return $output; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Crosssell.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Crosssell.php new file mode 100644 index 0000000000000..972af9db72c9a --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Crosssell.php @@ -0,0 +1,36 @@ +getCrossSellProducts(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Gz.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Related.php similarity index 73% rename from dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Gz.php rename to app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Related.php index 209451d994ea6..49afce1801402 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/Gz.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Related.php @@ -22,23 +22,15 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -/** - * Mock class to work with gz archives - */ -namespace Magento\Framework\Archive; +namespace Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider; -class Gz +class Related implements \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProviderInterface { /** - * Mock pack file by GZ compressor. - * - * @param $source - * @param $destination - * @return string - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * {@inheritdoc} */ - public function pack($source, $destination) + public function getLinkedProducts(\Magento\Catalog\Model\Product $product) { - return '\unexistingpath'; + return $product->getRelatedProducts(); } } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Upsell.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Upsell.php new file mode 100644 index 0000000000000..f564dbd16561a --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Upsell.php @@ -0,0 +1,36 @@ +getUpSellProducts(); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderInterface.php new file mode 100644 index 0000000000000..2223cfe80a364 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderInterface.php @@ -0,0 +1,36 @@ +mappers = $mappers; + } + + /** + * {@inheritdoc} + */ + public function map(array $data) + { + foreach ($this->mappers as $mapper) { + $data = $mapper->map($data); + } + return $data; + } +} diff --git a/app/code/Magento/OfflinePayments/Block/Form/Ccsave.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapperInterface.php similarity index 81% rename from app/code/Magento/OfflinePayments/Block/Form/Ccsave.php rename to app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapperInterface.php index 804d8fa707920..cbf50c17d587c 100644 --- a/app/code/Magento/OfflinePayments/Block/Form/Ccsave.php +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapperInterface.php @@ -21,14 +21,16 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\OfflinePayments\Block\Form; -class Ccsave extends \Magento\Payment\Block\Form\Cc +namespace Magento\Catalog\Service\V1\Product\Link\Data\ProductLink; + +interface DataMapperInterface { /** - * Cc save template + * Map data object * - * @var string + * @param array $data + * @return array */ - protected $_template = 'Magento_OfflinePayments::form/ccsave.phtml'; + public function map(array $data); } diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterInterface.php new file mode 100644 index 0000000000000..9c64d526eb13e --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterInterface.php @@ -0,0 +1,36 @@ +converters = $converters; + } + + /** + * Get converter by link type + * + * @param string $linkType + * @return ConverterInterface + */ + public function getConverter($linkType) + { + return isset($this->converters[$linkType]) + ? $this->converters[$linkType] + : $this->converters[$this->defaultConverterCode]; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverter.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverter.php new file mode 100644 index 0000000000000..25e27b7ee2026 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverter.php @@ -0,0 +1,42 @@ + $product->getTypeId(), + ProductLink::SKU => $product->getSku(), + ProductLink::POSITION => $product->getPosition() + ]; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLinkBuilder.php b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLinkBuilder.php new file mode 100644 index 0000000000000..2355b2838ac53 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/Data/ProductLinkBuilder.php @@ -0,0 +1,97 @@ +customAttributes = $customAttributesCodes; + parent::__construct($objectFactory, $valueBuilder); + } + + /** + * Set type + * + * @param string $type + * @return $this + */ + public function setType($type) + { + return $this->_set(ProductLink::TYPE, $type); + } + + /** + * Set product sku + * + * @param string $sku + * @return $this + */ + public function setSku($sku) + { + return $this->_set(ProductLink::SKU, $sku); + } + + /** + * Set product position + * + * @param int $position + * @return $this + */ + public function setPosition($position) + { + return $this->_set(ProductLink::POSITION, $position); + } + + /** + * Get custom attributes codes + * + * @return string[] + */ + public function getCustomAttributesCodes() + { + return array_merge(parent::getCustomAttributesCodes(), $this->customAttributes); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolver.php b/app/code/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolver.php new file mode 100644 index 0000000000000..1bc89fe85ceaa --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolver.php @@ -0,0 +1,60 @@ +linkTypeProvider = $linkTypeProvider; + } + + /** + * Get link type id by code + * + * @param string $code + * @throws NoSuchEntityException + * @return int + */ + public function getTypeIdByCode($code) + { + $types = $this->linkTypeProvider->getLinkTypes(); + if (isset($types[$code])) { + return $types[$code]; + } + throw new NoSuchEntityException('Unknown link type code is provided'); + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/ProductLoader.php b/app/code/Magento/Catalog/Service/V1/Product/Link/ProductLoader.php new file mode 100644 index 0000000000000..8ebbe959f1cef --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/ProductLoader.php @@ -0,0 +1,63 @@ +productFactory = $productFactory; + } + + /** + * Load product by SKU + * + * @param string $productSku + * @return \Magento\Catalog\Model\Product + * @throws NoSuchEntityException + */ + public function load($productSku) + { + /** @var \Magento\Catalog\Model\Product $product */ + $product = $this->productFactory->create(); + $productId = $product->getIdBySku($productSku); + + if (!$productId) { + throw new NoSuchEntityException('There is no product with provided SKU'); + } + $product->load($productId); + return $product; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php new file mode 100644 index 0000000000000..5e2a652a8e64a --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadService.php @@ -0,0 +1,157 @@ +linkTypeProvider = $linkTypeProvider; + $this->builder = $builder; + $this->productLoader = $productLoader; + $this->productEntityBuilder = $productEntityBuilder; + $this->entityCollectionProvider = $entityCollectionProvider; + $this->linkFactory = $linkFactory; + $this->linkAttributeBuilder = $linkAttributeBuilder; + $this->linkTypeResolver = $linkTypeResolver; + } + + /** + * {@inheritdoc} + */ + public function getProductLinkTypes() + { + $output = []; + foreach ($this->linkTypeProvider->getLinkTypes() as $type => $typeCode) { + $data = [LinkType::TYPE => $type, LinkType::CODE => $typeCode]; + $output[] = $this->builder + ->populateWithArray($data) + ->create(); + } + return $output; + } + + /** + * {@inheritdoc} + */ + public function getLinkedProducts($productSku, $type) + { + $output = []; + $product = $this->productLoader->load($productSku); + $collection = $this->entityCollectionProvider->getCollection($product, $type); + foreach ($collection as $item) { + $output[] = $this->productEntityBuilder->populateWithArray($item)->create(); + } + return $output; + } + + /** + * {@inheritdoc} + */ + public function getLinkAttributes($type) + { + $output = []; + $typeId = $this->linkTypeResolver->getTypeIdByCode($type); + + /** @var \Magento\Catalog\Model\Product\Link $link */ + $link = $this->linkFactory->create(['data' => ['link_type_id' => $typeId]]); + $attributes = $link->getAttributes(); + foreach ($attributes as $item) { + $data = [ + Data\LinkAttribute::CODE => $item['code'], + Data\LinkAttribute::TYPE => $item['type'], + ]; + $output[] = $this->linkAttributeBuilder->populateWithArray($data)->create(); + } + return $output; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php new file mode 100644 index 0000000000000..9a063cc52100d --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/ReadServiceInterface.php @@ -0,0 +1,54 @@ +linkInitializer = $linkInitializer; + $this->entityCollectionProvider = $entityCollectionProvider; + $this->productLoader = $productLoader; + $this->productResource = $productResource; + $this->dataMapper = $dataMapper; + } + + /** + * Save product links + * + * @param \Magento\Catalog\Model\Product $product + * @param array $links + * @throws CouldNotSaveException + * @return void + */ + protected function saveLinks($product, array $links) + { + foreach ($links as $type => $linksData) { + $links[$type] = $this->dataMapper->map($linksData); + } + $this->linkInitializer->initializeLinks($product, $links); + try { + $product->save(); + } catch (\Exception $exception) { + throw new CouldNotSaveException('Invalid data provided for linked products'); + } + } + + /** + * {@inheritdoc} + */ + public function assign($productSku, array $assignedProducts, $type) + { + $product = $this->productLoader->load($productSku); + $assignedSkuList = array_map( + function ($item) { + return $item->getSku(); + }, + $assignedProducts + ); + $linkedProductIds = $this->productResource->getProductsIdsBySkus($assignedSkuList); + + $links = []; + /** @var Data\ProductLink[] $assignedProducts*/ + foreach ($assignedProducts as $linkedProduct) { + $data = $linkedProduct->__toArray(); + if (!isset($linkedProductIds[$linkedProduct->getSku()])) { + throw new NoSuchEntityException( + sprintf("Product with SKU \"%s\" does not exist", $linkedProduct->getSku()) + ); + } + $data['product_id'] = $linkedProductIds[$linkedProduct->getSku()]; + $links[$linkedProductIds[$linkedProduct->getSku()]] = $data; + } + $this->saveLinks($product, [$type => $links]); + return true; + } + + /** + * {@inheritdoc} + */ + public function update($productSku, Data\ProductLink $linkedProduct, $type) + { + $product = $this->productLoader->load($productSku); + $linkedProductEntity = $this->productLoader->load($linkedProduct->getSku()); + $links = $this->entityCollectionProvider->getCollection($product, $type); + + if (!isset($links[$linkedProductEntity->getId()])) { + throw new NoSuchEntityException( + sprintf( + "Product with SKU \"%s\" is not linked to product with SKU %s", + $linkedProduct->getSku(), + $productSku + ) + ); + } + + $data = $linkedProduct->__toArray(); + $data['product_id'] = $linkedProductEntity->getId(); + $links[$linkedProductEntity->getId()] = $data; + $this->saveLinks($product, [$type => $links]); + return true; + } + + /** + * {@inheritdoc} + */ + public function remove($productSku, $linkedProductSku, $type) + { + $linkedProduct = $this->productLoader->load($linkedProductSku); + $product = $this->productLoader->load($productSku); + $links = $this->entityCollectionProvider->getCollection($product, $type); + + if (!isset($links[$linkedProduct->getId()])) { + throw new NoSuchEntityException( + sprintf('Product with SKU %s is not linked to product with SKU %s', $linkedProductSku, $productSku) + ); + } + + //Remove product from the linked product list + unset($links[$linkedProduct->getId()]); + + $this->saveLinks($product, [$type => $links]); + + return true; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php new file mode 100644 index 0000000000000..f4a4569616120 --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/Product/Link/WriteServiceInterface.php @@ -0,0 +1,64 @@ +productTypeConfig = $productTypeConfig; + $this->productTypeBuilder = $productTypeBuilder; + } + + /** + * {@inheritdoc} + */ + public function getProductTypes() + { + $productTypes = array(); + foreach ($this->productTypeConfig->getAll() as $productTypeData) { + $productTypes[] = $this->productTypeBuilder->setName($productTypeData['name']) + ->setLabel($productTypeData['label']) + ->create(); + } + return $productTypes; + } +} diff --git a/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php b/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php new file mode 100644 index 0000000000000..9ad7a4011b5ea --- /dev/null +++ b/app/code/Magento/Catalog/Service/V1/ProductTypeServiceInterface.php @@ -0,0 +1,36 @@ + + + + + + + + + + @@ -237,9 +246,9 @@ - Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED - Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL - Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL + Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED + Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL + Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL @@ -371,4 +380,20 @@
+ + + + Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Crosssell + Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Upsell + Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Related + + + + + + + \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\ProductEntity\DefaultConverter + + + diff --git a/app/code/Magento/Catalog/etc/webapi.xml b/app/code/Magento/Catalog/etc/webapi.xml new file mode 100644 index 0000000000000..480a7f47bf1c9 --- /dev/null +++ b/app/code/Magento/Catalog/etc/webapi.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml index f118c406b4345..ef4da6dd5d884 100644 --- a/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml +++ b/app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit.phtml @@ -291,7 +291,7 @@ jQuery(function($) { .removeClass('ignore-validate') .removeClass(removedElementClass) .each(function(i, fieldSet) { - $newPage.find('#product_info_tabs .fieldset').each(function(j, newFieldSet) { + var updateFieldsetElements = function(index, newFieldSet) { if ($(fieldSet).attr('id') != $(newFieldSet).attr('id')) { return } @@ -332,7 +332,21 @@ jQuery(function($) { $elementToMove.removeClass(removedElementClass).removeClass('.ignore-validate'); $elements = $(fieldSet).find('>.field:not(.' + removedElementClass + ')'); }); - }); + }; + + $newPage.find('#product_info_tabs .fieldset').each(updateFieldsetElements); + + fieldsetContainer = $(fieldSet).parents('[data-ui-id*=-tab-content-]').first(); + var newFieldsetContainer = $newPage.find('[data-ui-id='+$(fieldsetContainer).data('uiId')+']'); + if (newFieldsetContainer.length == 0) { + $(fieldsetContainer).find('fieldset .field') + .addClass('ignore-validate') + .addClass(removedElementClass); + $(fieldsetContainer).addClass(removedElementClass); + } else { + $(newFieldsetContainer).find('fieldset').each(updateFieldsetElements); + $(fieldsetContainer).removeClass(removedElementClass); + } }); $('#product_info_tabs').tabs('refresh'); if (!$('#' + activeTabId).closest('li').hasClass(removedElementClass)) { diff --git a/app/code/Magento/Catalog/view/adminhtml/web/product/product.css b/app/code/Magento/Catalog/view/adminhtml/web/product/product.css index 583795a4f7cd0..804841ffe42de 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/product/product.css +++ b/app/code/Magento/Catalog/view/adminhtml/web/product/product.css @@ -520,6 +520,7 @@ /* Change Attribute Set */ #product_info_tabs li.removed, +div.removed, .field.removed { display: none !important; } diff --git a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml index 5b6d8a6fbce64..db01776bfedfc 100644 --- a/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml +++ b/app/code/Magento/Catalog/view/frontend/layout/catalog_product_view.xml @@ -65,8 +65,7 @@
- - + product.price.render.default final_price @@ -82,7 +81,7 @@ item_view - + diff --git a/app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php b/app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php index e846f08a09386..2df9e468fc5f1 100644 --- a/app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php +++ b/app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php @@ -182,8 +182,69 @@ protected function _disableFields() */ protected function _getJs($quantityFieldId, $inStockFieldId) { - // @codingStandardsIgnoreStart - return "\n \n "; - // @codingStandardsIgnoreEnd + return " + + "; } } diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php index 3b7a81088c645..a8be0223e6a67 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php @@ -550,13 +550,15 @@ public function save($product) foreach ($data as $attributeData) { /** @var $configurableAttribute \Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute */ $configurableAttribute = $this->_configurableAttributeFactory->create(); - if (!empty($attributeData['id'])) { - $configurableAttribute->load($attributeData['id']); - } else { - $configurableAttribute->loadByProductAndAttribute( - $product, - $this->getAttributeById($attributeData['attribute_id'], $product) - ); + if (!$product->getIsDuplicate()) { + if (!empty($attributeData['id'])) { + $configurableAttribute->load($attributeData['id']); + } else { + $configurableAttribute->loadByProductAndAttribute( + $product, + $this->getAttributeById($attributeData['attribute_id'], $product) + ); + } } unset($attributeData['id']); $configurableAttribute->addData( @@ -1159,6 +1161,10 @@ protected function _fillSimpleProductData( $postData['stock_data'] = $parentProduct->getStockData(); $postData['stock_data']['manage_stock'] = $postData['quantity_and_stock_status']['qty'] === '' ? 0 : 1; + if (!isset($postData['stock_data']['is_in_stock'])) { + $stockStatus = $parentProduct->getQuantityAndStockStatus(); + $postData['stock_data']['is_in_stock'] = $stockStatus['is_in_stock']; + } $configDefaultValue = $this->_scopeConfig->getValue( \Magento\CatalogInventory\Model\Stock\Item::XML_PATH_MANAGE_STOCK, \Magento\Store\Model\ScopeInterface::SCOPE_STORE diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/config.phtml b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/config.phtml index 0d209003ba4fc..4a0c3cb129201 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/config.phtml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/config.phtml @@ -157,8 +157,12 @@ jQuery(function($) { $(this).html(''); }) .on('click', '[data-column=entity_id]', function() { - $(this).closest('tr').find('input[type!=checkbox],button') - .prop('disabled', !$(this).is(':checked')); + var entityCheckBox = $(this); + entityCheckBox.closest('tr').find('input[type!=checkbox],button').each(function () { + if (!isLocked($(this))) { + $(this).prop('disabled', !entityCheckBox.is(':checked')); + } + }); }) .on('click', '[data-action=choose]', function(event) { event.preventDefault(); @@ -216,6 +220,7 @@ jQuery(function($) { $matrixRow.find('[name=image]') .attr('src', $gridRow.find('[data-role=image-url]').val()) + .attr('data-locked', '1') .trigger('click') .prop({disabled: true}); diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/matrix.phtml b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/matrix.phtml index 31517d3f52aea..249759260aef7 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/matrix.phtml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/matrix.phtml @@ -105,7 +105,7 @@ $productByUsedAttributes = $this->getAssociatedProducts(); getImage(); if ($image == 'no_selection'): $image = ''; endif; ;?>
- getControllerClassName($currentModuleName, 'index'); - if (!$controllerClassName || !method_exists($controllerClassName, 'norouteAction')) { + if (!$controllerClassName + || !method_exists($controllerClassName, 'norouteAction') + || !is_callable([$controllerClassName, 'norouteAction']) + ) { return null; } @@ -294,7 +297,10 @@ protected function _matchController(\Magento\Framework\App\RequestInterface $req $currentModuleName = $moduleName; $controllerClassName = $this->getControllerClassName($moduleName, $controller); - if (!$controllerClassName || false === method_exists($controllerClassName, $action . 'Action')) { + if (!$controllerClassName + || !method_exists($controllerClassName, $action . 'Action') + || !is_callable([$controllerClassName, $action . 'Action']) + ) { continue; } diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php new file mode 100644 index 0000000000000..6ea74406b8f8a --- /dev/null +++ b/app/code/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/Sendemail.php @@ -0,0 +1,73 @@ +_storeManager = $context->getStoreManager(); + parent::__construct($context, $data); + } + + /** + * Check if Single Store Mode is enabled + * + * @return bool + */ + public function isSingleStoreMode() + { + return $this->_storeManager->isSingleStoreMode(); + } + + /** + * Get form HTML ID + * @return string + */ + public function getFormHtmlId() + { + return $this->getForm()->getHtmlIdPrefix(); + } +} diff --git a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php index af4db846c1266..f7ffe9e1333bd 100644 --- a/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php +++ b/app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Account.php @@ -24,6 +24,7 @@ namespace Magento\Customer\Block\Adminhtml\Edit\Tab; use Magento\Customer\Service\V1\CustomerAccountServiceInterface; +use \Magento\Framework\Service\DataObjectConverter; /** * Customer account form block @@ -73,6 +74,16 @@ class Account extends GenericMetadata */ protected $_customerBuilder; + /** + * @var \Magento\Customer\Model\Metadata\Form + */ + protected $_customerForm; + + /** + * @var \Magento\Customer\Service\V1\Data\Customer + */ + protected $_customerDataObject; + /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Framework\Registry $registry @@ -126,84 +137,111 @@ public function initForm() $form->setHtmlIdPrefix('_account'); $form->setFieldNameSuffix('account'); + /** @var \Magento\Framework\Data\Form\Element\Fieldset $fieldset */ $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('Account Information'))); + $accountData = $this->_customizeFieldset($fieldset); - $customerData = $this->_backendSession->getCustomerData(); - $customerId = isset($customerData['customer_id']) ? $customerData['customer_id'] : false; - $accountData = isset($customerData['account']) ? $customerData['account'] : array(); - $customerDataObject = $this->_customerBuilder->populateWithArray($accountData)->create(); + $form->setValues($accountData); + $this->setForm($form); + return $this; + } - $customerForm = $this->_initCustomerForm($customerDataObject); - $attributes = $this->_initCustomerAttributes($customerForm); + /** + * Customize fieldset elements + * + * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset + * @return array + */ + protected function _customizeFieldset($fieldset) + { + $attributes = $this->_initCustomerAttributes(); $this->_setFieldset($attributes, $fieldset, array(self::DISABLE_ATTRIBUTE_NAME)); - - $form->getElement( + $form = $fieldset->getForm(); + $groupElement = $form->getElement( 'group_id' - )->setRenderer( + ); + $groupElement->setRenderer( $this->getLayout()->createBlock( 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group' )->setDisableAutoGroupChangeAttribute( - $customerForm->getAttribute(self::DISABLE_ATTRIBUTE_NAME) + $this->_getCustomerForm()->getAttribute(self::DISABLE_ATTRIBUTE_NAME) )->setDisableAutoGroupChangeAttributeValue( - $customerDataObject->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME) ? - $customerDataObject->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME)->getValue() : null + $this->_getCustomerDataObject()->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME) ? + $this->_getCustomerDataObject()->getCustomAttribute(self::DISABLE_ATTRIBUTE_NAME)->getValue() : null ) ); - $customerStoreId = $customerDataObject->getStoreId(); + $this->_checkElementType('prefix', $fieldset); + $this->_checkElementType('suffix', $fieldset); - $prefixElement = $form->getElement('prefix'); - if ($prefixElement) { - $prefixOptions = $this->_customerHelper->getNamePrefixOptions($customerStoreId); - if (!empty($prefixOptions)) { - $fieldset->removeField($prefixElement->getId()); - $prefixField = $fieldset->addField( - $prefixElement->getId(), - 'select', - $prefixElement->getData(), - $form->getElement('group_id')->getId() - ); - $prefixField->setValues($prefixOptions); - if ($customerId) { - $prefixField->addElementValues($customerDataObject->getPrefix()); - } - } + $fieldset->getForm()->getElement('website_id')->addClass('validate-website-has-store'); + $renderer = $this->getLayout()->createBlock( + 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' + ); + $form->getElement('website_id')->setRenderer($renderer); + + $accountData = DataObjectConverter::toFlatArray($this->_getCustomerDataObject()); + if ($this->_getCustomerDataObject()->getId()) { + $customerFormFields = $this->_addEditCustomerFormFields($fieldset); + } else { + $customerFormFields = $this->_addNewCustomerFormFields($fieldset); } - $suffixElement = $form->getElement('suffix'); - if ($suffixElement) { - $suffixOptions = $this->_customerHelper->getNameSuffixOptions($customerStoreId); - if (!empty($suffixOptions)) { - $fieldset->removeField($suffixElement->getId()); - $suffixField = $fieldset->addField( - $suffixElement->getId(), + $this->_handleReadOnlyCustomer($form, $this->_getCustomerDataObject()->getId(), $attributes); + + return array_merge($customerFormFields, $accountData); + } + + /** + * Check if type of Prefix and Suffix elements should be changed from text to select and change it if need. + * + * @param string $elementName + * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset + * @return null + */ + protected function _checkElementType($elementName, $fieldset) + { + $possibleElements = ['prefix', 'suffix']; + if (!in_array($elementName, $possibleElements)) { + return; + } + $element = $fieldset->getForm()->getElement($elementName); + if ($element) { + if ($elementName == 'prefix') { + $options = $this->_customerHelper->getNamePrefixOptions($this->_getCustomerDataObject()->getStoreId()); + $prevSibling = $fieldset->getForm()->getElement('group_id')->getId(); + } + if ($elementName == 'suffix') { + $options = $this->_customerHelper->getNameSuffixOptions($this->_getCustomerDataObject()->getStoreId()); + $prevSibling = $fieldset->getForm()->getElement('lastname')->getId(); + } + + if (!empty($options)) { + $fieldset->removeField($element->getId()); + $elementField = $fieldset->addField( + $element->getId(), 'select', - $suffixElement->getData(), - $form->getElement('lastname')->getId() + $element->getData(), + $prevSibling ); - $suffixField->setValues($suffixOptions); - if ($customerId) { - $suffixField->addElementValues($customerDataObject->getSuffix()); - } + $elementField->setValues($options); } } + } - if ($customerId) { - $accountData = array_merge( - $this->_addEditCustomerFormFields($form, $fieldset, $customerDataObject), - $accountData - ); - } else { - $this->_addNewCustomerFormFields($form, $fieldset); - $accountData['sendemail'] = '1'; + /** + * Obtain customer data from session and create customer object + * + * @return \Magento\Customer\Service\V1\Data\Customer + */ + protected function _getCustomerDataObject() + { + if (is_null($this->_customerDataObject)) { + $customerData = $this->_backendSession->getCustomerData(); + $accountData = isset($customerData['account']) ? $customerData['account'] : array(); + $this->_customerDataObject = $this->_customerBuilder->populateWithArray($accountData)->create(); } - - $this->_disableSendEmailStoreForEmptyWebsite($form); - $this->_handleReadOnlyCustomer($form, $customerId, $attributes); - - $form->setValues($accountData); - $this->setForm($form); - return $this; + return $this->_customerDataObject; } /** @@ -223,13 +261,11 @@ protected function _getAdditionalElementTypes() /** * Initialize attribute set. * - * @param \Magento\Customer\Model\Metadata\Form $customerForm * @return \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] */ - protected function _initCustomerAttributes(\Magento\Customer\Model\Metadata\Form $customerForm) + protected function _initCustomerAttributes() { - $attributes = $customerForm->getAttributes(); - + $attributes = $this->_getCustomerForm()->getAttributes(); foreach ($attributes as $key => $attribute) { if ($attribute->getAttributeCode() == 'created_at') { unset($attributes[$key]); @@ -241,16 +277,18 @@ protected function _initCustomerAttributes(\Magento\Customer\Model\Metadata\Form /** * Initialize customer form * - * @param \Magento\Customer\Service\V1\Data\Customer $customer * @return \Magento\Customer\Model\Metadata\Form $customerForm */ - protected function _initCustomerForm(\Magento\Customer\Service\V1\Data\Customer $customer) + protected function _getCustomerForm() { - return $this->_customerFormFactory->create( - 'customer', - 'adminhtml_customer', - \Magento\Framework\Service\EavDataObjectConverter::toFlatArray($customer) - ); + if (is_null($this->_customerForm)) { + $this->_customerForm = $this->_customerFormFactory->create( + 'customer', + 'adminhtml_customer', + DataObjectConverter::toFlatArray($this->_getCustomerDataObject()) + ); + } + return $this->_customerForm; } /** @@ -273,47 +311,13 @@ protected function _handleReadOnlyCustomer($form, $customerId, $attributes) } } - /** - * Make sendemail or sendmail_store_id disabled if website_id has an empty value - * - * @param \Magento\Framework\Data\Form $form - * @return void - */ - protected function _disableSendEmailStoreForEmptyWebsite(\Magento\Framework\Data\Form $form) - { - $sendEmailId = $this->_storeManager->isSingleStoreMode() ? 'sendemail' : 'sendemail_store_id'; - $sendEmail = $form->getElement($sendEmailId); - - $prefix = $form->getHtmlIdPrefix(); - if ($sendEmail) { - $_disableStoreField = ''; - if (!$this->_storeManager->isSingleStoreMode()) { - $_disableStoreField = "\$('{$prefix}sendemail_store_id').disabled=(''==this.value || '0'==this.value);"; - } - $sendEmail->setAfterElementHtml( - '' - ); - } - } - /** * Create New Customer form fields * - * @param \Magento\Framework\Data\Form $form * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset - * @return void + * @return array */ - protected function _addNewCustomerFormFields($form, $fieldset) + protected function _addNewCustomerFormFields($fieldset) { $fieldset->removeField('created_in'); @@ -323,39 +327,13 @@ protected function _addNewCustomerFormFields($form, $fieldset) 'checkbox', array('label' => __('Send Welcome Email'), 'name' => 'sendemail', 'id' => 'sendemail') ); - if (!$this->_storeManager->isSingleStoreMode()) { - $form->getElement('website_id')->addClass('validate-website-has-store'); - - $websites = array(); - foreach ($this->_storeManager->getWebsites(true) as $website) { - $websites[$website->getId()] = !is_null($website->getDefaultStore()); - } - $prefix = $form->getHtmlIdPrefix(); - - $note = __('Please select a website which contains store view'); - $form->getElement( - 'website_id' - )->setAfterElementJs( - '' - ); - $renderer = $this->getLayout()->createBlock( - 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' - ); - $form->getElement('website_id')->setRenderer($renderer); + $renderer = $this->getLayout()->createBlock( + 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail' + ); + $renderer->setForm($fieldset->getForm()); + $fieldset->getForm()->getElement('sendemail')->setRenderer($renderer); + if (!$this->_storeManager->isSingleStoreMode()) { $fieldset->addField( 'sendemail_store_id', 'select', @@ -365,45 +343,36 @@ protected function _addNewCustomerFormFields($form, $fieldset) 'values' => $this->_systemStore->getStoreValuesForForm() ) ); - } else { - $fieldset->removeField('website_id'); - $fieldset->addField('website_id', 'hidden', array('name' => 'website_id')); } + + return array('sendemail' => '1'); } /** * Edit/View Existing Customer form fields * - * @param \Magento\Framework\Data\Form $form * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset - * @param \Magento\Customer\Service\V1\Data\Customer $customerDataObject * @return string[] Values to set on the form */ - protected function _addEditCustomerFormFields($form, $fieldset, $customerDataObject) + protected function _addEditCustomerFormFields($fieldset) { - $form->getElement('created_in')->setDisabled('disabled'); - if (!$this->_storeManager->isSingleStoreMode()) { - $form->getElement('website_id')->setDisabled('disabled'); - $renderer = $this->getLayout()->createBlock( - 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' - ); - $form->getElement('website_id')->setRenderer($renderer); - } else { - $fieldset->removeField('website_id'); - } - - if ($customerDataObject->getId() && !$this->_customerAccountService->canModify($customerDataObject->getId())) { + $fieldset->getForm()->getElement('created_in')->setDisabled('disabled'); + $fieldset->getForm()->getElement('website_id')->setDisabled('disabled'); + $customerData = $this->_getCustomerDataObject(); + if ($customerData->getId() && + !$this->_customerAccountService->canModify($customerData->getId()) + ) { return array(); } // Prepare customer confirmation control (only for existing customers) - $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customerDataObject->getId()); - $confirmationKey = $customerDataObject->getConfirmation(); + $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customerData->getId()); + $confirmationKey = $customerData->getConfirmation(); if ($confirmationStatus != CustomerAccountServiceInterface::ACCOUNT_CONFIRMED) { $confirmationAttr = $this->_customerMetadataService->getCustomerAttributeMetadata('confirmation'); if (!$confirmationKey) { - $confirmationKey = $this->getRandomConfirmationKey(); + $confirmationKey = $this->_getRandomConfirmationKey(); } $element = $fieldset->addField( @@ -416,7 +385,7 @@ protected function _addEditCustomerFormFields($form, $fieldset, $customerDataObj // Prepare send welcome email checkbox if customer is not confirmed // no need to add it, if website ID is empty - if ($customerDataObject->getConfirmation() && $customerDataObject->getWebsiteId()) { + if ($customerData->getConfirmation() && $customerData->getWebsiteId()) { $fieldset->addField( 'sendemail', 'checkbox', diff --git a/app/code/Magento/Customer/Service/V1/Data/AddressBuilder.php b/app/code/Magento/Customer/Service/V1/Data/AddressBuilder.php index e6258b1c96a8c..126fc2ec40caf 100644 --- a/app/code/Magento/Customer/Service/V1/Data/AddressBuilder.php +++ b/app/code/Magento/Customer/Service/V1/Data/AddressBuilder.php @@ -48,18 +48,18 @@ class AddressBuilder extends AbstractObjectBuilder protected $_metadataService; /** - * Initialize dependencies. - * + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory * @param AttributeValueBuilder $valueBuilder * @param RegionBuilder $regionBuilder * @param CustomerMetadataServiceInterface $metadataService */ public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, AttributeValueBuilder $valueBuilder, RegionBuilder $regionBuilder, CustomerMetadataServiceInterface $metadataService ) { - parent::__construct($valueBuilder); + parent::__construct($objectFactory, $valueBuilder); $this->_metadataService = $metadataService; $this->_regionBuilder = $regionBuilder; $this->_data[Address::KEY_REGION] = $regionBuilder->create(); diff --git a/app/code/Magento/Customer/Service/V1/Data/CustomerBuilder.php b/app/code/Magento/Customer/Service/V1/Data/CustomerBuilder.php index 99e2edd8e7187..ffc2549adf8fc 100644 --- a/app/code/Magento/Customer/Service/V1/Data/CustomerBuilder.php +++ b/app/code/Magento/Customer/Service/V1/Data/CustomerBuilder.php @@ -43,16 +43,16 @@ class CustomerBuilder extends AbstractObjectBuilder protected $_metadataService; /** - * Initialize dependencies. - * + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory * @param AttributeValueBuilder $valueBuilder * @param CustomerMetadataServiceInterface $metadataService */ public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, AttributeValueBuilder $valueBuilder, CustomerMetadataServiceInterface $metadataService ) { - parent::__construct($valueBuilder); + parent::__construct($objectFactory, $valueBuilder); $this->_metadataService = $metadataService; } diff --git a/app/code/Magento/Customer/Service/V1/Data/CustomerDetailsBuilder.php b/app/code/Magento/Customer/Service/V1/Data/CustomerDetailsBuilder.php index 83125377c90ed..36db9eccb1763 100644 --- a/app/code/Magento/Customer/Service/V1/Data/CustomerDetailsBuilder.php +++ b/app/code/Magento/Customer/Service/V1/Data/CustomerDetailsBuilder.php @@ -47,16 +47,16 @@ class CustomerDetailsBuilder extends AbstractObjectBuilder protected $_addressBuilder; /** - * Constructor - * - * @param \Magento\Customer\Service\V1\Data\CustomerBuilder $customerBuilder - * @param \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory + * @param CustomerBuilder $customerBuilder + * @param AddressBuilder $addressBuilder */ public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, \Magento\Customer\Service\V1\Data\CustomerBuilder $customerBuilder, \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder ) { - parent::__construct(); + parent::__construct($objectFactory); $this->_customerBuilder = $customerBuilder; $this->_addressBuilder = $addressBuilder; } diff --git a/app/code/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataBuilder.php b/app/code/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataBuilder.php index 99581be76ee5f..e45d018fad67e 100644 --- a/app/code/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataBuilder.php +++ b/app/code/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataBuilder.php @@ -43,16 +43,16 @@ class AttributeMetadataBuilder extends \Magento\Framework\Service\Data\AbstractO protected $_validationRuleBuilder; /** - * Initializes builder. - * - * @param \Magento\Customer\Service\V1\Data\Eav\OptionBuilder $optionBuilder - * @param \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder $validationRuleBuilder + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory + * @param OptionBuilder $optionBuilder + * @param ValidationRuleBuilder $validationRuleBuilder */ public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, \Magento\Customer\Service\V1\Data\Eav\OptionBuilder $optionBuilder, \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder $validationRuleBuilder ) { - parent::__construct(); + parent::__construct($objectFactory); $this->_optionBuilder = $optionBuilder; $this->_validationRuleBuilder = $validationRuleBuilder; $this->_data[AttributeMetadata::OPTIONS] = array(); diff --git a/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml b/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml new file mode 100644 index 0000000000000..c3982a964baf6 --- /dev/null +++ b/app/code/Magento/Customer/view/adminhtml/templates/edit/tab/account/form/renderer/sendemail.phtml @@ -0,0 +1,52 @@ + +getElement(); +?> + +
+ getLabelHtml(); ?> +
+ getElementHtml(); ?> +
+
+ + diff --git a/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php b/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php index 048f556e09154..2555754fdfb84 100644 --- a/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php +++ b/app/code/Magento/DesignEditor/Model/Url/NavigationMode.php @@ -58,9 +58,9 @@ class NavigationMode extends \Magento\Framework\Url * @param \Magento\Framework\Session\SidResolverInterface $sidResolver * @param \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver * @param \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver - * @param \Magento\DesignEditor\Helper\Data $helper * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $scopeType + * @param \Magento\DesignEditor\Helper\Data $helper * @param array $data */ public function __construct( @@ -72,9 +72,9 @@ public function __construct( \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Url\RouteParamsResolverFactory $routeParamsResolver, \Magento\Framework\Url\QueryParamsResolverInterface $queryParamsResolver, - \Magento\DesignEditor\Helper\Data $helper, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, $scopeType, + \Magento\DesignEditor\Helper\Data $helper, array $data = array() ) { $this->_helper = $helper; diff --git a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php index f3337ae5bf533..11ea1a7832db5 100644 --- a/app/code/Magento/Eav/Model/Entity/AbstractEntity.php +++ b/app/code/Magento/Eav/Model/Entity/AbstractEntity.php @@ -781,7 +781,7 @@ public function walkAttributes($partMethod, array $args = array(), $collectExcep */ protected function _isCallableAttributeInstance($instance, $method, $args) { - if (!is_object($instance) || !method_exists($instance, $method)) { + if (!is_object($instance) || !method_exists($instance, $method) || !is_callable([$instance, $method])) { return false; } diff --git a/app/code/Magento/Eav/Model/Validator/Attribute/Backend.php b/app/code/Magento/Eav/Model/Validator/Attribute/Backend.php index 065fbcf673ccf..8a15b7f0b42fc 100644 --- a/app/code/Magento/Eav/Model/Validator/Attribute/Backend.php +++ b/app/code/Magento/Eav/Model/Validator/Attribute/Backend.php @@ -55,7 +55,7 @@ public function isValid($entity) /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ foreach ($attributes as $attribute) { $backend = $attribute->getBackend(); - if (!method_exists($backend, 'validate')) { + if (!method_exists($backend, 'validate') || !is_callable([$backend, 'validate'])) { continue; } try { diff --git a/app/code/Magento/Email/Model/Template/Filter.php b/app/code/Magento/Email/Model/Template/Filter.php index 9a183ff687bed..f9ad16c0141e3 100644 --- a/app/code/Magento/Email/Model/Template/Filter.php +++ b/app/code/Magento/Email/Model/Template/Filter.php @@ -273,7 +273,11 @@ public function blockDirective($construction) if (isset($blockParameters['output'])) { $method = $blockParameters['output']; } - if (!isset($method) || !is_string($method) || !method_exists($block, $method)) { + if (!isset($method) + || !is_string($method) + || !method_exists($block, $method) + || !is_callable([$block, $method]) + ) { $method = 'toHtml'; } return $block->{$method}(); diff --git a/app/code/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php b/app/code/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php new file mode 100644 index 0000000000000..3baa7a795bb8c --- /dev/null +++ b/app/code/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php @@ -0,0 +1,47 @@ +getGroupedReadonly()) { + $product->setGroupedLinkData((array)$links['associated']); + } + } +} diff --git a/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Grouped.php b/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Grouped.php new file mode 100644 index 0000000000000..4979b68474b14 --- /dev/null +++ b/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/Grouped.php @@ -0,0 +1,38 @@ +getTypeInstance()->getAssociatedProducts($product); + } +} diff --git a/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProduct.php b/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProduct.php new file mode 100644 index 0000000000000..9417a61c230f7 --- /dev/null +++ b/app/code/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProduct.php @@ -0,0 +1,43 @@ + $product->getTypeId(), + ProductLink::SKU => $product->getSku(), + ProductLink::POSITION => $product->getPosition(), + ProductLink::CUSTOM_ATTRIBUTES_KEY => [ + [AttributeValue::ATTRIBUTE_CODE => 'qty', AttributeValue::VALUE => $product->getQty()], + ] + ]; + } +} diff --git a/app/code/Magento/GroupedProduct/etc/adminhtml/di.xml b/app/code/Magento/GroupedProduct/etc/adminhtml/di.xml index dbc58b6bf1e90..0c7439cae967a 100644 --- a/app/code/Magento/GroupedProduct/etc/adminhtml/di.xml +++ b/app/code/Magento/GroupedProduct/etc/adminhtml/di.xml @@ -25,9 +25,6 @@ --> - - - diff --git a/app/code/Magento/GroupedProduct/etc/di.xml b/app/code/Magento/GroupedProduct/etc/di.xml index f708f1943bfaa..a10ad5a509daa 100644 --- a/app/code/Magento/GroupedProduct/etc/di.xml +++ b/app/code/Magento/GroupedProduct/etc/di.xml @@ -91,4 +91,35 @@ + + + + Magento\GroupedProduct\Service\V1\Product\Link\Data\ProductLink\CollectionProvider\Grouped + + + + + + + + + + qty + + + + + + + \Magento\GroupedProduct\Service\V1\Product\Link\Data\ProductLink\DataMapper\GroupedProduct + + + + + + + \Magento\GroupedProduct\Service\V1\Product\Link\Data\ProductLink\ProductEntity\Converter + + + diff --git a/app/code/Magento/GroupedProduct/view/adminhtml/templates/product/grouped/list.phtml b/app/code/Magento/GroupedProduct/view/adminhtml/templates/product/grouped/list.phtml index dd55b34c8552c..dd402007256ea 100644 --- a/app/code/Magento/GroupedProduct/view/adminhtml/templates/product/grouped/list.phtml +++ b/app/code/Magento/GroupedProduct/view/adminhtml/templates/product/grouped/list.phtml @@ -27,8 +27,8 @@ - - + + ${name} @@ -40,7 +40,7 @@ ${price} - + diff --git a/app/code/Magento/ImportExport/Model/Export/Entity/Product.php b/app/code/Magento/ImportExport/Model/Export/Entity/Product.php index dfe75b41ffd01..e42ee802051ee 100644 --- a/app/code/Magento/ImportExport/Model/Export/Entity/Product.php +++ b/app/code/Magento/ImportExport/Model/Export/Entity/Product.php @@ -651,12 +651,12 @@ protected function _setHeaderColumns($customOptionsData, $stockItemRows) reset($stockItemRows) ? array_keys(end($stockItemRows)) : array(), array(), array( - '_links_related_sku', - '_links_related_position', - '_links_crosssell_sku', - '_links_crosssell_position', - '_links_upsell_sku', - '_links_upsell_position', + '_related_sku', + '_related_position', + '_crosssell_sku', + '_crosssell_position', + '_upsell_sku', + '_upsell_position', '_associated_sku', '_associated_default_qty', '_associated_position' diff --git a/app/code/Magento/ImportExport/Model/Import.php b/app/code/Magento/ImportExport/Model/Import.php index 0d9c373b44029..9e2c52e676021 100644 --- a/app/code/Magento/ImportExport/Model/Import.php +++ b/app/code/Magento/ImportExport/Model/Import.php @@ -489,9 +489,9 @@ public function expandSource() 'meta_title' => 'last', 'meta_keyword' => 'last', 'meta_description' => 'last', - '_links_related_sku' => 'last', - '_links_crosssell_sku' => 'last', - '_links_upsell_sku' => 'last', + '_related_sku' => 'last', + '_crosssell_sku' => 'last', + '_upsell_sku' => 'last', '_custom_option_sku' => 'middle', '_custom_option_row_sku' => 'middle', '_super_products_sku' => 'last', diff --git a/app/code/Magento/ImportExport/Model/Import/Entity/Product.php b/app/code/Magento/ImportExport/Model/Import/Entity/Product.php index 06e176661e99e..41d7fb2ba0129 100644 --- a/app/code/Magento/ImportExport/Model/Import/Entity/Product.php +++ b/app/code/Magento/ImportExport/Model/Import/Entity/Product.php @@ -178,9 +178,9 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity * @var array */ protected $_linkNameToId = array( - '_links_related_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, - '_links_crosssell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL, - '_links_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL + '_related_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_RELATED, + '_crosssell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_CROSSSELL, + '_upsell_' => \Magento\Catalog\Model\Product\Link::LINK_TYPE_UPSELL ); /** @@ -258,15 +258,15 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity '_tier_price_customer_group', '_tier_price_qty', '_tier_price_price', - '_links_related_sku', + '_related_sku', '_group_price_website', '_group_price_customer_group', '_group_price_price', - '_links_related_position', - '_links_crosssell_sku', - '_links_crosssell_position', - '_links_upsell_sku', - '_links_upsell_position', + '_related_position', + '_crosssell_sku', + '_crosssell_position', + '_upsell_sku', + '_upsell_position', '_custom_option_store', '_custom_option_type', '_custom_option_title', diff --git a/app/code/Magento/ImportExport/Model/Import/Uploader.php b/app/code/Magento/ImportExport/Model/Import/Uploader.php index 6b5eca673a1e0..e7ce134a3cd96 100644 --- a/app/code/Magento/ImportExport/Model/Import/Uploader.php +++ b/app/code/Magento/ImportExport/Model/Import/Uploader.php @@ -175,7 +175,10 @@ protected function _validateFile() } //run validate callbacks foreach ($this->_validateCallbacks as $params) { - if (is_object($params['object']) && method_exists($params['object'], $params['method'])) { + if (is_object($params['object']) + && method_exists($params['object'], $params['method']) + && is_callable([$params['object'], $params['method']]) + ) { $params['object']->{$params['method']}($filePath); } } diff --git a/app/code/Magento/Index/Model/Indexer/AbstractIndexer.php b/app/code/Magento/Index/Model/Indexer/AbstractIndexer.php index 9011de56e6ce4..e3156dca525b7 100644 --- a/app/code/Magento/Index/Model/Indexer/AbstractIndexer.php +++ b/app/code/Magento/Index/Model/Indexer/AbstractIndexer.php @@ -147,7 +147,7 @@ public function reindexAll() } /** - * Try dynamicly detect and call event hanler from resource model. + * Try dynamicly detect and call event handler from resource model. * Handler name will be generated from event entity and type code * * @param Event $event diff --git a/app/code/Magento/Index/Model/Resource/Setup.php b/app/code/Magento/Index/Model/Resource/Setup.php index 0c858883b69d8..f752418b17e76 100644 --- a/app/code/Magento/Index/Model/Resource/Setup.php +++ b/app/code/Magento/Index/Model/Resource/Setup.php @@ -98,7 +98,7 @@ protected function _syncIndexes() 'status' => \Magento\Index\Model\Process::STATUS_REQUIRE_REINDEX ); } - if (method_exists($connection, 'insertArray')) { + if (method_exists($connection, 'insertArray') && is_callable([$connection, 'insertArray'])) { $connection->insertArray($table, array('indexer_code', 'status'), $insertData); } } diff --git a/app/code/Magento/OfflinePayments/Block/Info/Ccsave.php b/app/code/Magento/OfflinePayments/Block/Info/Ccsave.php deleted file mode 100644 index 2247bddf5301b..0000000000000 --- a/app/code/Magento/OfflinePayments/Block/Info/Ccsave.php +++ /dev/null @@ -1,59 +0,0 @@ -_paymentSpecificInformation) { - return $this->_paymentSpecificInformation; - } - $info = $this->getInfo(); - $transport = new \Magento\Framework\Object(array((string)__('Name on the Card') => $info->getCcOwner())); - $transport = parent::_prepareSpecificInformation($transport); - if (!$this->getIsSecureMode()) { - $transport->addData( - array( - (string)__( - 'Expiration Date' - ) => $this->_formatCardDate( - $info->getCcExpYear(), - $this->getCcExpMonth() - ), - (string)__('Credit Card Number') => $info->getCcNumber() - ) - ); - } - return $transport; - } -} diff --git a/app/code/Magento/OfflinePayments/etc/adminhtml/system.xml b/app/code/Magento/OfflinePayments/etc/adminhtml/system.xml index f377052c10897..8c8b26642800b 100644 --- a/app/code/Magento/OfflinePayments/etc/adminhtml/system.xml +++ b/app/code/Magento/OfflinePayments/etc/adminhtml/system.xml @@ -26,70 +26,6 @@
- - - - - Enabling this method will store credit card information in the database, which may increase your security or compliance requirements. - Magento\Backend\Model\Config\Source\Yesno - - - - Magento\Payment\Model\Config\Source\Cctype - 1 - - - - Magento\Sales\Model\Config\Source\Order\Status\NewStatus - - - - validate-number - - - - - - - Magento\Backend\Model\Config\Source\Yesno - - - - Magento\Backend\Model\Config\Source\Yesno - - - - Severe validation removes chargeback liability on merchant. - Magento\Backend\Model\Config\Source\Yesno - - 1 - - - - - A value is required for live mode. Refer to your CardinalCommerce agreement. - Magento\Backend\Model\Config\Source\Yesno - - 1 - - - - - Magento\Payment\Model\Config\Source\Allspecificcountries - - - - Magento\Directory\Model\Config\Source\Country - 1 - - - - - - - - - diff --git a/app/code/Magento/OfflinePayments/etc/config.xml b/app/code/Magento/OfflinePayments/etc/config.xml index 4bddc0ad7c370..1075acf376dde 100644 --- a/app/code/Magento/OfflinePayments/etc/config.xml +++ b/app/code/Magento/OfflinePayments/etc/config.xml @@ -26,15 +26,6 @@ - - 0 - AE,VI,MC,DI - Magento\OfflinePayments\Model\Ccsave - pending - Credit Card (saved) - 0 - offline - 1 Magento\OfflinePayments\Model\Checkmo diff --git a/app/code/Magento/OfflinePayments/etc/module.xml b/app/code/Magento/OfflinePayments/etc/module.xml index 6e1c51754de2c..cecfda746ac1b 100644 --- a/app/code/Magento/OfflinePayments/etc/module.xml +++ b/app/code/Magento/OfflinePayments/etc/module.xml @@ -32,7 +32,6 @@ - diff --git a/app/code/Magento/OfflinePayments/etc/payment.xml b/app/code/Magento/OfflinePayments/etc/payment.xml index 642e8e8f9637f..cbd2c76df8928 100644 --- a/app/code/Magento/OfflinePayments/etc/payment.xml +++ b/app/code/Magento/OfflinePayments/etc/payment.xml @@ -39,10 +39,6 @@ 1 1 - - 1 - 1 - 1 1 diff --git a/app/code/Magento/OfflinePayments/view/adminhtml/templates/form/ccsave.phtml b/app/code/Magento/OfflinePayments/view/adminhtml/templates/form/ccsave.phtml deleted file mode 100644 index ad7b26916558a..0000000000000 --- a/app/code/Magento/OfflinePayments/view/adminhtml/templates/form/ccsave.phtml +++ /dev/null @@ -1,128 +0,0 @@ - -getMethodCode() ?> - diff --git a/app/code/Magento/OfflinePayments/view/frontend/templates/form/ccsave.phtml b/app/code/Magento/OfflinePayments/view/frontend/templates/form/ccsave.phtml deleted file mode 100644 index a2270efa5676e..0000000000000 --- a/app/code/Magento/OfflinePayments/view/frontend/templates/form/ccsave.phtml +++ /dev/null @@ -1,137 +0,0 @@ - -getMethodCode() ?> - diff --git a/app/code/Magento/Ogone/Model/Config.php b/app/code/Magento/Ogone/Model/Config.php index 3454c8269656e..1da9203599023 100644 --- a/app/code/Magento/Ogone/Model/Config.php +++ b/app/code/Magento/Ogone/Model/Config.php @@ -23,6 +23,8 @@ */ namespace Magento\Ogone\Model; +use Magento\Store\Model\ScopeInterface; + /** * Config model */ @@ -45,6 +47,7 @@ class Config extends \Magento\Payment\Model\Config * @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory * @param \Magento\Framework\Locale\ListsInterface $localeLists * @param \Magento\Framework\Config\DataInterface $dataStorage + * @param \Magento\Framework\Stdlib\DateTime\DateTime $date * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor */ @@ -53,10 +56,11 @@ public function __construct( \Magento\Payment\Model\Method\Factory $paymentMethodFactory, \Magento\Framework\Locale\ListsInterface $localeLists, \Magento\Framework\Config\DataInterface $dataStorage, + \Magento\Framework\Stdlib\DateTime\DateTime $date, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\Encryption\EncryptorInterface $encryptor ) { - parent::__construct($scopeConfig, $paymentMethodFactory, $localeLists, $dataStorage); + parent::__construct($scopeConfig, $paymentMethodFactory, $localeLists, $dataStorage, $date); $this->_urlBuilder = $urlBuilder; $this->_encryptor = $encryptor; } @@ -73,7 +77,7 @@ public function getConfigData($path, $storeId = null) if (!empty($path)) { return $this->_scopeConfig->getValue( self::OGONE_PAYMENT_PATH . $path, - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + ScopeInterface::SCOPE_STORE, $storeId ); } diff --git a/app/code/Magento/Payment/Block/Info.php b/app/code/Magento/Payment/Block/Info.php index a62eb2f72564a..bab83b56527bf 100644 --- a/app/code/Magento/Payment/Block/Info.php +++ b/app/code/Magento/Payment/Block/Info.php @@ -86,7 +86,7 @@ public function getChildPdfAsArray() { $result = array(); foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $child) { - if (method_exists($child, 'toPdf')) { + if (method_exists($child, 'toPdf') && is_callable([$child, 'toPdf'])) { $result[] = $child->toPdf(); } } diff --git a/app/code/Magento/Payment/Model/Checks/CanUseCheckout.php b/app/code/Magento/Payment/Model/Checks/CanUseCheckout.php index 11f29a4935deb..08f4ab261d9bf 100644 --- a/app/code/Magento/Payment/Model/Checks/CanUseCheckout.php +++ b/app/code/Magento/Payment/Model/Checks/CanUseCheckout.php @@ -31,7 +31,7 @@ class CanUseCheckout implements SpecificationInterface * Check whether payment method is applicable to quote * * @param PaymentMethodChecksInterface $paymentMethod - * @param \Magento\Sales\Model\Quote $quote + * @param Quote $quote * @return bool */ public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote) diff --git a/app/code/Magento/Payment/Model/Checks/CanUseForCountry.php b/app/code/Magento/Payment/Model/Checks/CanUseForCountry.php index debf20993b1e0..7310e289b8b36 100644 --- a/app/code/Magento/Payment/Model/Checks/CanUseForCountry.php +++ b/app/code/Magento/Payment/Model/Checks/CanUseForCountry.php @@ -30,7 +30,7 @@ class CanUseForCountry implements SpecificationInterface /** * Check whether payment method is applicable to quote * @param PaymentMethodChecksInterface $paymentMethod - * @param \Magento\Sales\Model\Quote $quote + * @param Quote $quote * @return bool */ public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote) diff --git a/app/code/Magento/Payment/Model/Checks/SpecificationFactory.php b/app/code/Magento/Payment/Model/Checks/SpecificationFactory.php index 26295db8efe85..a04ef799205a0 100644 --- a/app/code/Magento/Payment/Model/Checks/SpecificationFactory.php +++ b/app/code/Magento/Payment/Model/Checks/SpecificationFactory.php @@ -29,11 +29,11 @@ class SpecificationFactory { /** - * Object manager + * Composite Factory * - * @var \Magento\Framework\ObjectManager + * @var \Magento\Payment\Model\Checks\CompositeFactory */ - protected $objectManager; + protected $compositeFactory; /** @var array mapping */ protected $mapping; @@ -41,12 +41,12 @@ class SpecificationFactory /** * Construct * - * @param \Magento\Framework\ObjectManager $objectManager + * @param \Magento\Payment\Model\Checks\CompositeFactory $compositeFactory * @param array $mapping */ - public function __construct(\Magento\Framework\ObjectManager $objectManager, array $mapping) + public function __construct(\Magento\Payment\Model\Checks\CompositeFactory $compositeFactory, array $mapping) { - $this->objectManager = $objectManager; + $this->compositeFactory = $compositeFactory; $this->mapping = $mapping; } @@ -54,15 +54,12 @@ public function __construct(\Magento\Framework\ObjectManager $objectManager, arr * Creates new instances of payment method models * * @param array $data - * @return SpecificationInterface + * @return Composite * @throws \Magento\Framework\Model\Exception */ public function create($data) { $specifications = array_intersect_key($this->mapping, array_flip((array)$data)); - return $this->objectManager->create( - 'Magento\Payment\Model\Checks\Composite', - array('list' => $specifications) - ); + return $this->compositeFactory->create(array('list' => $specifications)); } } diff --git a/app/code/Magento/Payment/Model/Checks/TotalMinMax.php b/app/code/Magento/Payment/Model/Checks/TotalMinMax.php index 3a0f6427dd4b3..d58afce684461 100644 --- a/app/code/Magento/Payment/Model/Checks/TotalMinMax.php +++ b/app/code/Magento/Payment/Model/Checks/TotalMinMax.php @@ -27,6 +27,16 @@ class TotalMinMax implements SpecificationInterface { + /** + * Config value key for min order total + */ + const MIN_ORDER_TOTAL = 'min_order_total'; + + /** + * Config value key for max order total + */ + const MAX_ORDER_TOTAL = 'max_order_total'; + /** * Check whether payment method is applicable to quote * @@ -37,8 +47,8 @@ class TotalMinMax implements SpecificationInterface public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote) { $total = $quote->getBaseGrandTotal(); - $minTotal = $paymentMethod->getConfigData('min_order_total'); - $maxTotal = $paymentMethod->getConfigData('max_order_total'); + $minTotal = $paymentMethod->getConfigData(self::MIN_ORDER_TOTAL); + $maxTotal = $paymentMethod->getConfigData(self::MAX_ORDER_TOTAL); if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) { return false; } diff --git a/app/code/Magento/Payment/Model/Config.php b/app/code/Magento/Payment/Model/Config.php index d1fe2bda8defb..ad399c1448b6e 100644 --- a/app/code/Magento/Payment/Model/Config.php +++ b/app/code/Magento/Payment/Model/Config.php @@ -23,7 +23,7 @@ */ namespace Magento\Payment\Model; -use Magento\Store\Model\Store; +use Magento\Store\Model\ScopeInterface; use Magento\Payment\Model\Method\AbstractMethod; /** @@ -33,6 +33,11 @@ */ class Config { + /** + * Years range + */ + const YEARS_RANGE = 10; + /** * @var array */ @@ -62,7 +67,14 @@ class Config * * @var \Magento\Payment\Model\Method\Factory */ - protected $_methodFactory; + protected $_paymentMethodFactory; + + /** + * DateTime + * + * @var \Magento\Framework\Stdlib\DateTime\DateTime + */ + protected $_date; /** * Construct @@ -71,41 +83,37 @@ class Config * @param \Magento\Payment\Model\Method\Factory $paymentMethodFactory * @param \Magento\Framework\Locale\ListsInterface $localeLists * @param \Magento\Framework\Config\DataInterface $dataStorage + * @param \Magento\Framework\Stdlib\DateTime\DateTime $date */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Factory $paymentMethodFactory, \Magento\Framework\Locale\ListsInterface $localeLists, - \Magento\Framework\Config\DataInterface $dataStorage + \Magento\Framework\Config\DataInterface $dataStorage, + \Magento\Framework\Stdlib\DateTime\DateTime $date ) { $this->_scopeConfig = $scopeConfig; $this->_dataStorage = $dataStorage; - $this->_methodFactory = $paymentMethodFactory; + $this->_paymentMethodFactory = $paymentMethodFactory; $this->_localeLists = $localeLists; + $this->_date = $date; } /** * Retrieve active system payments * - * @param null|string|bool|int|Store $store * @return array */ - public function getActiveMethods($store = null) + public function getActiveMethods() { - $methods = array(); - $config = $this->_scopeConfig->getValue('payment', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); - foreach ($config as $code => $methodConfig) { - if ($this->_scopeConfig->isSetFlag( - 'payment/' . $code . '/active', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, - $store - ) - ) { - if (array_key_exists('model', $methodConfig)) { - $methodModel = $this->_methodFactory->create($methodConfig['model']); - if ($methodModel && $methodModel->getConfigData('active', $store)) { - $methods[$code] = $this->_getMethod($code, $methodConfig); - } + $methods = []; + foreach ($this->_scopeConfig->getValue('payment', ScopeInterface::SCOPE_STORE, null) as $code => $data) { + if (isset($data['active']) && (bool)$data['active'] && isset($data['model'])) { + /** @var AbstractMethod|null $methodModel Actually it's wrong interface */ + $methodModel = $this->_paymentMethodFactory->create($data['model']); + $methodModel->setId($code)->setStore(null); + if ($methodModel->getConfigData('active', null)) { + $methods[$code] = $methodModel; } } } @@ -113,53 +121,7 @@ public function getActiveMethods($store = null) } /** - * Retrieve all system payments - * - * @param null|string|bool|int|Store $store - * @return array - */ - public function getAllMethods($store = null) - { - $methods = array(); - $config = $this->_scopeConfig->getValue('payment', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store); - foreach ($config as $code => $methodConfig) { - $data = $this->_getMethod($code, $methodConfig); - if (false !== $data) { - $methods[$code] = $data; - } - } - return $methods; - } - - /** - * @param string $code - * @param string $config - * @param null|string|bool|int|Store $store - * @return \Magento\Payment\Model\MethodInterface - */ - protected function _getMethod($code, $config, $store = null) - { - if (isset($this->_methods[$code])) { - return $this->_methods[$code]; - } - if (empty($config['model'])) { - return false; - } - $modelName = $config['model']; - - if (!class_exists($modelName)) { - return false; - } - - /** @var AbstractMethod $method */ - $method = $this->_methodFactory->create($modelName); - $method->setId($code)->setStore($store); - $this->_methods[$code] = $method; - return $this->_methods[$code]; - } - - /** - * Retrieve array of credit card types + * Get list of credit card types * * @return array */ @@ -185,12 +147,7 @@ public function getMethodsInfo() */ public function getGroups() { - $groups = $this->_dataStorage->get('groups'); - $result = array(); - foreach ($groups as $code => $title) { - $result[$code] = $title; - } - return $result; + return $this->_dataStorage->get('groups'); } /** @@ -216,9 +173,8 @@ public function getMonths() public function getYears() { $years = array(); - $first = date("Y"); - - for ($index = 0; $index <= 10; $index++) { + $first = (int)$this->_date->date('Y'); + for ($index = 0; $index <= self::YEARS_RANGE; $index++) { $year = $first + $index; $years[$year] = $year; } diff --git a/app/code/Magento/Payment/Model/Config/SchemaLocator.php b/app/code/Magento/Payment/Model/Config/SchemaLocator.php index a86cffd42e00e..42e63e7f4223e 100644 --- a/app/code/Magento/Payment/Model/Config/SchemaLocator.php +++ b/app/code/Magento/Payment/Model/Config/SchemaLocator.php @@ -27,6 +27,16 @@ class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface { + /** + * Merged config schema file name + */ + const MERGED_CONFIG_SCHEMA = 'payment.xsd'; + + /** + * Per file validation schema file name + */ + const PER_FILE_VALIDATION_SCHEMA = 'payment_file.xsd'; + /** * Path to corresponding XSD file with validation rules for merged config * @@ -46,8 +56,9 @@ class SchemaLocator implements \Magento\Framework\Config\SchemaLocatorInterface */ public function __construct(\Magento\Framework\Module\Dir\Reader $moduleReader) { - $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Payment') . '/payment.xsd'; - $this->_perFileSchema = $moduleReader->getModuleDir('etc', 'Magento_Payment') . '/payment_file.xsd'; + $this->_schema = $moduleReader->getModuleDir('etc', 'Magento_Payment') . '/' . self::MERGED_CONFIG_SCHEMA; + $this->_perFileSchema = $moduleReader->getModuleDir('etc', 'Magento_Payment') + . '/' . self::PER_FILE_VALIDATION_SCHEMA; } /** diff --git a/app/code/Magento/Payment/Model/Config/Source/Allmethods.php b/app/code/Magento/Payment/Model/Config/Source/Allmethods.php index bdd8a1dbdfe8a..fb4df03b0f250 100644 --- a/app/code/Magento/Payment/Model/Config/Source/Allmethods.php +++ b/app/code/Magento/Payment/Model/Config/Source/Allmethods.php @@ -30,7 +30,7 @@ class Allmethods implements \Magento\Framework\Option\ArrayInterface * * @var \Magento\Payment\Helper\Data */ - protected $_paymentData = null; + protected $_paymentData; /** * @param \Magento\Payment\Helper\Data $paymentData diff --git a/app/code/Magento/Payment/Model/Info.php b/app/code/Magento/Payment/Model/Info.php index 12a02e71eacc0..b2989c643e473 100644 --- a/app/code/Magento/Payment/Model/Info.php +++ b/app/code/Magento/Payment/Model/Info.php @@ -33,14 +33,14 @@ class Info extends \Magento\Framework\Model\AbstractModel * * @var array */ - protected $_additionalInformation = -1; + protected $_additionalInformation = array(); /** * Payment data * * @var \Magento\Payment\Helper\Data */ - protected $_paymentData = null; + protected $_paymentData; /** * @var \Magento\Framework\Encryption\EncryptorInterface @@ -95,7 +95,7 @@ public function getData($key = '', $index = null) /** * Retrieve payment method model object * - * @return \Magento\Payment\Model\MethodInterface + * @return MethodInterface * @throws \Magento\Framework\Model\Exception */ public function getMethodInstance() @@ -105,7 +105,7 @@ public function getMethodInstance() $instance = $this->_paymentData->getMethodInstance($this->getMethod()); if (!$instance) { $instance = $this->_paymentData->getMethodInstance( - \Magento\Payment\Model\Method\Substitution::CODE + Method\Substitution::CODE ); } $instance->setInfoInstance($this); @@ -126,10 +126,7 @@ public function getMethodInstance() */ public function encrypt($data) { - if ($data) { - return $this->_encryptor->encrypt($data); - } - return $data; + return $this->_encryptor->encrypt($data); } /** @@ -140,10 +137,7 @@ public function encrypt($data) */ public function decrypt($data) { - if ($data) { - return $this->_encryptor->decrypt($data); - } - return $data; + return $this->_encryptor->decrypt($data); } /** @@ -197,7 +191,7 @@ public function unsAdditionalInformation($key = null) unset($this->_additionalInformation[$key]); return $this->setData('additional_information', $this->_additionalInformation); } - $this->_additionalInformation = -1; + $this->_additionalInformation = array(); return $this->unsetData('additional_information'); } @@ -217,17 +211,14 @@ public function hasAdditionalInformation($key = null) } /** - * Make sure _additionalInformation is an array + * Initialize _additionalInformation with $this->_data['additional_information'] if empty * * @return void */ protected function _initAdditionalInformation() { - if (-1 === $this->_additionalInformation) { + if (empty($this->_additionalInformation) && $this->_getData('additional_information')) { $this->_additionalInformation = $this->_getData('additional_information'); } - if (null === $this->_additionalInformation) { - $this->_additionalInformation = array(); - } } } diff --git a/app/code/Magento/Payment/Model/Method/AbstractMethod.php b/app/code/Magento/Payment/Model/Method/AbstractMethod.php index e775c0846bb6f..720776229f0fe 100644 --- a/app/code/Magento/Payment/Model/Method/AbstractMethod.php +++ b/app/code/Magento/Payment/Model/Method/AbstractMethod.php @@ -30,6 +30,7 @@ /** * Payment method abstract model + * @method AbstractMethod setStore() */ abstract class AbstractMethod extends \Magento\Framework\Object implements MethodInterface, PaymentMethodChecksInterface { diff --git a/app/code/Magento/Payment/Model/Observer.php b/app/code/Magento/Payment/Model/Observer.php index 0bec83e0d782e..f734264e32283 100644 --- a/app/code/Magento/Payment/Model/Observer.php +++ b/app/code/Magento/Payment/Model/Observer.php @@ -68,6 +68,7 @@ public function __construct( */ public function salesOrderBeforeSave($observer) { + /** @var \Magento\Sales\Model\Order $order */ $order = $observer->getEvent()->getOrder(); if ($order->getPayment()->getMethodInstance()->getCode() != 'free') { @@ -78,7 +79,7 @@ public function salesOrderBeforeSave($observer) return $this; } - if ($order->isCanceled() || $order->getState() === \Magento\Sales\Model\Order::STATE_CLOSED) { + if ($order->isCanceled() || $order->getState() == \Magento\Sales\Model\Order::STATE_CLOSED) { return $this; } /** @@ -96,7 +97,7 @@ public function salesOrderBeforeSave($observer) */ public function updateOrderStatusForPaymentMethods(\Magento\Framework\Event\Observer $observer) { - if ($observer->getEvent()->getState() !== \Magento\Sales\Model\Order::STATE_NEW) { + if ($observer->getEvent()->getState() != \Magento\Sales\Model\Order::STATE_NEW) { return; } $status = $observer->getEvent()->getStatus(); diff --git a/app/code/Magento/Paypal/Block/Adminhtml/Store/SwitcherPlugin.php b/app/code/Magento/Paypal/Block/Adminhtml/Store/SwitcherPlugin.php new file mode 100644 index 0000000000000..67ee9b9dc5347 --- /dev/null +++ b/app/code/Magento/Paypal/Block/Adminhtml/Store/SwitcherPlugin.php @@ -0,0 +1,48 @@ +getRequest()->getParam(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY)) { + $params[\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY] = null; + } + return $proceed($route, $params); + } +} diff --git a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Field/Country.php b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Field/Country.php new file mode 100644 index 0000000000000..b6759b378742b --- /dev/null +++ b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Field/Country.php @@ -0,0 +1,156 @@ +_url = $url; + $this->_jsHelper = $jsHelper; + $this->_coreHelper = $coreHelper; + } + + /** + * Render country field considering request parameter + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + $country = $this->getRequest()->getParam(StructurePlugin::REQUEST_PARAM_COUNTRY); + if ($country) { + $element->setValue($country); + } + + if ($element->getCanUseDefaultValue()) { + $this->_defaultCountry = $this->_scopeConfig->getValue(self::FIELD_CONFIG_PATH); + if (!$this->_defaultCountry) { + $this->_defaultCountry = $this->_coreHelper->getDefaultCountry(); + } + if ($country) { + $shouldInherit = $country == $this->_defaultCountry + && $this->getRequest()->getParam(self::REQUEST_PARAM_DEFAULT_COUNTRY); + $element->setInherit($shouldInherit); + } + if ($element->getInherit()) { + $this->_defaultCountry = null; + } + } + + return parent::render($element); + } + + /** + * Get country selector html + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + $urlParams = [ + 'section' => $this->getRequest()->getParam('section'), + 'website' => $this->getRequest()->getParam('website'), + 'store' => $this->getRequest()->getParam('store'), + StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__' + ]; + $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); + $jsString = ' + $("' . $element->getHtmlId() . '").observe("change", function () { + location.href = \'' . $urlString . '\'.replace("__country__", this.value); + }); + '; + + if ($this->_defaultCountry) { + $urlParams[self::REQUEST_PARAM_DEFAULT_COUNTRY] = '__default__'; + $urlString = $this->_escaper->escapeJsQuote($this->_url->getUrl('*/*/*', $urlParams)); + $jsParentCountry = $this->_escaper->escapeJsQuote($this->_defaultCountry); + $jsString .= ' + $("' . $element->getHtmlId() . '_inherit").observe("click", function () { + if (this.checked) { + location.href = \'' . $urlString . '\'.replace("__country__", \'' . $jsParentCountry . '\') + .replace("__default__", "1"); + } + }); + '; + } + + return parent::_getElementHtml($element) . $this->_jsHelper->getScript( + 'document.observe("dom:loaded", function() {' . $jsString . '});' + ); + } +} diff --git a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php index 4c0f1a5a55d7f..d943cb66b96ec 100644 --- a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php +++ b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Group.php @@ -83,7 +83,8 @@ protected function _isCollapseState($element) return $extra['configState'][$element->getId()]; } - if ($element->getExpanded() !== null) { + $groupConfig = $element->getGroup(); + if (!empty($groupConfig['expanded'])) { return true; } diff --git a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Location.php b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Location.php index 2b47358433f81..03f52d5de07e8 100644 --- a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Location.php +++ b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Location.php @@ -29,7 +29,7 @@ */ namespace Magento\Paypal\Block\Adminhtml\System\Config\Fieldset; -class Location extends \Magento\Backend\Block\System\Config\Form\Fieldset +class Location extends \Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded { /** * Render fieldset html @@ -373,6 +373,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele }); }); '; - return $this->toHtml() . $this->_jsHelper->getScript($js); + return parent::render($element) . $this->_jsHelper->getScript($js); } } diff --git a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Payment.php b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Payment.php index b09e265347eba..2d983add86fde 100644 --- a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Payment.php +++ b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Payment.php @@ -72,15 +72,19 @@ protected function _getFrontendClass($element) protected function _isPaymentEnabled($element) { $groupConfig = $element->getGroup(); - $activityPath = isset($groupConfig['activity_path']) ? $groupConfig['activity_path'] : ''; + $activityPaths = isset($groupConfig['activity_path']) ? $groupConfig['activity_path'] : []; - if (empty($activityPath)) { - return false; + if (!is_array($activityPaths)) { + $activityPaths = [$activityPaths]; } - $isPaymentEnabled = (string)$this->_backendConfig->getConfigDataValue($activityPath); + $isPaymentEnabled = false; + foreach ($activityPaths as $activityPath) { + $isPaymentEnabled = $isPaymentEnabled + || (bool)(string)$this->_backendConfig->getConfigDataValue($activityPath); + } - return (bool)$isPaymentEnabled; + return $isPaymentEnabled; } /** diff --git a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php b/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php deleted file mode 100644 index 21dfd95a60f7c..0000000000000 --- a/app/code/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/Store.php +++ /dev/null @@ -1,89 +0,0 @@ - - */ -class Store extends \Magento\Backend\Block\Template implements \Magento\Framework\Data\Form\Element\Renderer\RendererInterface -{ - /** - * Path to template file - * - * @var string - */ - protected $_template = 'Magento_Paypal::system/config/fieldset/store.phtml'; - - /** - * @param \Magento\Backend\Block\Template\Context $context - * @param array $data - */ - public function __construct( - \Magento\Backend\Block\Template\Context $context, - array $data = array() - ) { - parent::__construct($context, $data); - } - - /** - * Render service JavaScript code - * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element - * @return string - */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - $html = $this->_storeManager->isSingleStoreMode() ? '' : $this->toHtml(); - return $html; - } - - /** - * Returns list of disabled (in the Default or the Website Scope) paypal methods - * - * @return array - */ - protected function getPaypalDisabledMethods() - { - // Assoc array that contains info about paypal methods (their IDs and corresponding Config Paths) - $methods = array( - 'express' => 'payment/paypal_express/active', - 'wps' => 'payment/paypal_standard/active', - 'wpp' => 'payment/paypal_direct/active', - 'wpppe' => 'payment/payflow_direct/active', - 'payflowpro' => 'payment/payflowpro/active', - 'expresspe' => 'payment/payflow_express/active' - ); - // Retrieve a code of the current website - $website = $this->getRequest()->getParam('website'); - $disabledMethods = array(); - foreach ($methods as $methodId => $methodPath) { - $isEnabled = (int)$this->_scopeConfig->getValue($methodPath, 'website', $website); - if ($isEnabled === 0) { - $disabledMethods[$methodId] = $isEnabled; - } - } - return $disabledMethods; - } -} diff --git a/app/code/Magento/Paypal/Block/Express/Shortcut.php b/app/code/Magento/Paypal/Block/Express/Shortcut.php index 8f014d3bbee07..8f508fad6dea1 100644 --- a/app/code/Magento/Paypal/Block/Express/Shortcut.php +++ b/app/code/Magento/Paypal/Block/Express/Shortcut.php @@ -177,7 +177,7 @@ protected function _beforeToHtml() // check visibility on cart or product page $context = $isInCatalog ? 'visible_on_product' : 'visible_on_cart'; - if (!$config->{$context}) { + if (!$config->getConfigValue($context)) { $this->_shouldRender = false; return $result; } diff --git a/app/code/Magento/Paypal/Helper/Backend.php b/app/code/Magento/Paypal/Helper/Backend.php new file mode 100644 index 0000000000000..10ba896db84f0 --- /dev/null +++ b/app/code/Magento/Paypal/Helper/Backend.php @@ -0,0 +1,74 @@ +_coreHelper = $coreHelper; + $this->_backendConfig = $backendConfig; + } + + /** + * Get selected merchant country code in system configuration + * + * @return string + */ + public function getConfigurationCountryCode() + { + $countryCode = $this->_request->getParam(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY); + if (is_null($countryCode) || preg_match('/^[a-zA-Z]{2}$/', $countryCode) == 0) { + $countryCode = $this->_backendConfig->getConfigDataValue( + \Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH + ); + } + if (empty($countryCode)) { + $countryCode = $this->_coreHelper->getDefaultCountry(); + } + return $countryCode; + } +} diff --git a/app/code/Magento/Paypal/Model/AbstractIpn.php b/app/code/Magento/Paypal/Model/AbstractIpn.php index 891581276d25e..03fee1cce9f37 100644 --- a/app/code/Magento/Paypal/Model/AbstractIpn.php +++ b/app/code/Magento/Paypal/Model/AbstractIpn.php @@ -104,7 +104,7 @@ protected function _postBack() $postbackUrl = $this->_config->getPaypalUrl(); $this->_addDebugData('postback_to', $postbackUrl); - $httpAdapter->setConfig(array('verifypeer' => $this->_config->verifyPeer)); + $httpAdapter->setConfig(array('verifypeer' => $this->_config->getConfigValue('verifyPeer'))); $httpAdapter->write(\Zend_Http_Client::POST, $postbackUrl, '1.1', array('Connection: close'), $postbackQuery); try { $postbackResult = $httpAdapter->read(); @@ -169,7 +169,7 @@ protected function _filterPaymentStatus($ipnPaymentStatus) */ protected function _debug() { - if ($this->_config && $this->_config->debug) { + if ($this->_config && $this->_config->getConfigValue('debug')) { $file = $this->_config ->getMethodCode() ? "payment_{$this ->_config diff --git a/app/code/Magento/Paypal/Model/Api/AbstractApi.php b/app/code/Magento/Paypal/Model/Api/AbstractApi.php index 12a59392568a3..5f7c6e3f77742 100644 --- a/app/code/Magento/Paypal/Model/Api/AbstractApi.php +++ b/app/code/Magento/Paypal/Model/Api/AbstractApi.php @@ -156,7 +156,7 @@ public function __construct( */ public function getApiUsername() { - return $this->_config->apiUsername; + return $this->_config->getConfigValue('apiUsername'); } /** @@ -166,7 +166,7 @@ public function getApiUsername() */ public function getApiPassword() { - return $this->_config->apiPassword; + return $this->_config->getConfigValue('apiPassword'); } /** @@ -176,7 +176,7 @@ public function getApiPassword() */ public function getApiSignature() { - return $this->_config->apiSignature; + return $this->_config->getConfigValue('apiSignature'); } /** @@ -542,7 +542,7 @@ protected function _getDataOrConfig($key, $default = null) if ($this->hasData($key)) { return $this->getData($key); } - return $this->_config->{$key} ? $this->_config->{$key} : $default; + return $this->_config->getConfigValue($key) ? $this->_config->getConfigValue($key) : $default; } /** @@ -639,7 +639,7 @@ protected function _debug($debugData) */ public function getDebugFlag() { - return $this->_config->debug; + return $this->_config->getConfigValue('debug'); } /** @@ -649,6 +649,6 @@ public function getDebugFlag() */ public function getUseCertAuthentication() { - return (bool)$this->_config->apiAuthentication; + return (bool)$this->_config->getConfigValue('apiAuthentication'); } } diff --git a/app/code/Magento/Paypal/Model/Api/Nvp.php b/app/code/Magento/Paypal/Model/Api/Nvp.php index e100aa87b2688..585541edfaeac 100644 --- a/app/code/Magento/Paypal/Model/Api/Nvp.php +++ b/app/code/Magento/Paypal/Model/Api/Nvp.php @@ -783,7 +783,7 @@ public function __construct( public function getApiEndpoint() { $url = $this->getUseCertAuthentication() ? 'https://api%s.paypal.com/nvp' : 'https://api-3t%s.paypal.com/nvp'; - return sprintf($url, $this->_config->sandboxFlag ? '.sandbox' : ''); + return sprintf($url, $this->_config->getConfigValue('sandboxFlag') ? '.sandbox' : ''); } /** @@ -1174,7 +1174,7 @@ public function call($methodName, array $request) try { $http = new \Magento\Framework\HTTP\Adapter\Curl(); - $config = array('timeout' => 60, 'verifypeer' => $this->_config->verifyPeer); + $config = array('timeout' => 60, 'verifypeer' => $this->_config->getConfigValue('verifyPeer')); if ($this->getUseProxy()) { $config['proxy'] = $this->getProxyHost() . ':' . $this->getProxyPort(); } diff --git a/app/code/Magento/Paypal/Model/Api/PayflowNvp.php b/app/code/Magento/Paypal/Model/Api/PayflowNvp.php index d4933ed247baf..6450d5b29f491 100644 --- a/app/code/Magento/Paypal/Model/Api/PayflowNvp.php +++ b/app/code/Magento/Paypal/Model/Api/PayflowNvp.php @@ -480,7 +480,10 @@ public function __construct( */ public function getApiEndpoint() { - return sprintf('https://%spayflowpro.paypal.com/transaction', $this->_config->sandboxFlag ? 'pilot-' : ''); + return sprintf( + 'https://%spayflowpro.paypal.com/transaction', + $this->_config->getConfigValue('sandboxFlag') ? 'pilot-' : '' + ); } /** @@ -597,7 +600,7 @@ protected function _mapPaypalMethodName($methodName) case \Magento\Paypal\Model\Api\Nvp::GET_EXPRESS_CHECKOUT_DETAILS: case \Magento\Paypal\Model\Api\Nvp::SET_EXPRESS_CHECKOUT: case \Magento\Paypal\Model\Api\Nvp::DO_DIRECT_PAYMENT: - return $this->_config->payment_action == + return $this->_config->getConfigValue('payment_action') == \Magento\Paypal\Model\Config::PAYMENT_ACTION_AUTH ? self::TRXTYPE_AUTH_ONLY : self::TRXTYPE_SALE; case \Magento\Paypal\Model\Api\Nvp::DO_CAPTURE: return self::TRXTYPE_DELAYED_CAPTURE; diff --git a/app/code/Magento/Paypal/Model/Config.php b/app/code/Magento/Paypal/Model/Config.php index 81aa7428da980..9d62ad04439e7 100644 --- a/app/code/Magento/Paypal/Model/Config.php +++ b/app/code/Magento/Paypal/Model/Config.php @@ -44,11 +44,6 @@ class Config */ const METHOD_WPP_DIRECT = 'paypal_direct'; - /** - * Direct Payments (Payflow Edition) - */ - const METHOD_WPP_PE_DIRECT = 'payflow_direct'; - /** * Express Checkout (Payflow Edition) */ @@ -203,8 +198,7 @@ class Config 'paypal_standard' => 'WPS', 'paypal_express' => 'EC', 'paypal_direct' => 'DP', - 'payflow_express' => 'EC', - 'payflow_direct' => 'DP' + 'payflow_express' => 'EC' ); /** @@ -732,41 +726,26 @@ public function isMethodAvailable($methodCode = null) switch ($methodCode) { case self::METHOD_WPS: - if (!$this->businessAccount) { + if (!$this->getConfigValue('businessAccount')) { $result = false; break; } // check for direct payments dependence - if ($this->isMethodActive(self::METHOD_WPP_DIRECT) || $this->isMethodActive(self::METHOD_WPP_PE_DIRECT) - ) { + if ($this->isMethodActive(self::METHOD_WPP_DIRECT)) { $result = false; } break; case self::METHOD_WPP_EXPRESS: - // check for direct payments dependence - if ($this->isMethodActive(self::METHOD_WPP_PE_DIRECT)) { - $result = false; - } elseif ($this->isMethodActive(self::METHOD_WPP_DIRECT)) { + if ($this->isMethodActive(self::METHOD_WPP_DIRECT)) { $result = true; } break; case self::METHOD_WPP_PE_EXPRESS: // check for direct payments dependence - if ($this->isMethodActive( - self::METHOD_WPP_PE_DIRECT - ) || $this->isMethodActive( - self::METHOD_PAYFLOWLINK - ) || $this->isMethodActive( - self::METHOD_PAYFLOWADVANCED - ) - ) { + if ($this->isMethodActive(self::METHOD_PAYFLOWLINK) + || $this->isMethodActive(self::METHOD_PAYFLOWADVANCED)) { $result = true; - } elseif (!$this->isMethodActive( - self::METHOD_WPP_PE_DIRECT - ) && !$this->isMethodActive( - self::METHOD_PAYFLOWPRO - ) - ) { + } elseif (!$this->isMethodActive(self::METHOD_PAYFLOWPRO)) { $result = false; } break; @@ -774,7 +753,6 @@ public function isMethodAvailable($methodCode = null) $result = $this->isWppApiAvailabe(); break; case self::METHOD_WPP_DIRECT: - case self::METHOD_WPP_PE_DIRECT: break; } return $result; @@ -789,7 +767,7 @@ public function isMethodAvailable($methodCode = null) * @param string $key * @return string|null */ - public function __get($key) + public function getConfigValue($key) { $underscored = strtolower(preg_replace('/(.)([A-Z])/', "$1_$2", $key)); $path = $this->_getSpecificConfigPath($underscored); @@ -894,9 +872,9 @@ public function isMethodSupportedForCountry($method = null, $countryCode = null) */ public function getCountryMethods($countryCode = null) { - $countryMethods = array( - 'other' => array(self::METHOD_WPS, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT), - 'US' => array( + $countryMethods = [ + 'other' => [self::METHOD_WPS, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT], + 'US' => [ self::METHOD_PAYFLOWADVANCED, self::METHOD_WPP_DIRECT, self::METHOD_WPS, @@ -905,68 +883,71 @@ public function getCountryMethods($countryCode = null) self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT, self::METHOD_WPP_PE_EXPRESS - ), - 'CA' => array( + ], + 'CA' => [ self::METHOD_WPP_DIRECT, self::METHOD_WPS, self::METHOD_PAYFLOWPRO, self::METHOD_PAYFLOWLINK, self::METHOD_WPP_EXPRESS, - self::METHOD_BILLING_AGREEMENT - ), - 'GB' => array( + self::METHOD_BILLING_AGREEMENT, + self::METHOD_WPP_PE_EXPRESS + ], + 'GB' => [ self::METHOD_WPP_DIRECT, self::METHOD_WPS, - self::METHOD_WPP_PE_DIRECT, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, - self::METHOD_BILLING_AGREEMENT, - self::METHOD_WPP_PE_EXPRESS - ), - 'AU' => array( + self::METHOD_BILLING_AGREEMENT + ], + 'AU' => [ self::METHOD_WPS, self::METHOD_PAYFLOWPRO, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'NZ' => array( + ], + 'NZ' => [ self::METHOD_WPS, self::METHOD_PAYFLOWPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'JP' => array( + ], + 'JP' => [ self::METHOD_WPS, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'FR' => array( + ], + 'FR' => [ self::METHOD_WPS, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'IT' => array( + ], + 'IT' => [ self::METHOD_WPS, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'ES' => array( + ], + 'ES' => [ self::METHOD_WPS, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ), - 'HK' => array( + ], + 'HK' => [ self::METHOD_WPS, self::METHOD_HOSTEDPRO, self::METHOD_WPP_EXPRESS, self::METHOD_BILLING_AGREEMENT - ) - ); + ], + 'DE' => [ + self::METHOD_WPP_EXPRESS, + self::METHOD_BILLING_AGREEMENT + ] + ]; if ($countryCode === null) { return $countryMethods; } @@ -1028,7 +1009,7 @@ public function getPaypalUrl(array $params = array()) { return sprintf( 'https://www.%spaypal.com/cgi-bin/webscr%s', - $this->sandboxFlag ? 'sandbox.' : '', + $this->getConfigValue('sandboxFlag') ? 'sandbox.' : '', $params ? '?' . http_build_query($params) : '' ); } @@ -1040,7 +1021,7 @@ public function getPaypalUrl(array $params = array()) */ public function areButtonsDynamic() { - return $this->buttonFlavor === self::EC_FLAVOR_DYNAMIC; + return $this->getConfigValue('buttonFlavor') === self::EC_FLAVOR_DYNAMIC; } /** @@ -1058,7 +1039,7 @@ public function getExpressCheckoutShortcutImageUrl($localeCode, $orderTotal = nu if ($this->areButtonsDynamic()) { return $this->_getDynamicImageUrl(self::EC_BUTTON_TYPE_SHORTCUT, $localeCode, $orderTotal, $pal); } - if ($this->buttonType === self::EC_BUTTON_TYPE_MARK) { + if ($this->getConfigValue('buttonType') === self::EC_BUTTON_TYPE_MARK) { return $this->getPaymentMarkImageUrl($localeCode); } return sprintf( @@ -1085,7 +1066,7 @@ public function getPaymentMarkImageUrl($localeCode, $orderTotal = null, $pal = n } if (null === $staticSize) { - $staticSize = $this->paymentMarkSize; + $staticSize = $this->getConfigValue('paymentMarkSize'); } switch ($staticSize) { case self::PAYMENT_MARK_37X23: @@ -1317,7 +1298,7 @@ public function getRequireBillingAddressOptions() */ public function getPaymentAction() { - switch ($this->paymentAction) { + switch ($this->getConfigValue('paymentAction')) { case self::PAYMENT_ACTION_AUTH: return \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE; case self::PAYMENT_ACTION_SALE: @@ -1372,7 +1353,8 @@ public function getExpressCheckoutBASignupOptions() */ public function shouldAskToCreateBillingAgreement() { - return $this->allow_ba_signup === self::EC_BA_SIGNUP_ASK && !$this->shouldUseUnilateralPayments(); + return $this->getConfigValue('allow_ba_signup') === self::EC_BA_SIGNUP_ASK + && !$this->shouldUseUnilateralPayments(); } /** @@ -1382,7 +1364,7 @@ public function shouldAskToCreateBillingAgreement() */ public function shouldUseUnilateralPayments() { - return $this->business_account && !$this->isWppApiAvailabe(); + return $this->getConfigValue('business_account') && !$this->isWppApiAvailabe(); } /** @@ -1392,7 +1374,10 @@ public function shouldUseUnilateralPayments() */ public function isWppApiAvailabe() { - return $this->api_username && $this->api_password && ($this->api_signature || $this->api_cert); + return $this->getConfigValue('api_username') + && $this->getConfigValue('api_password') + && ($this->getConfigValue('api_signature') + || $this->getConfigValue('api_cert')); } /** @@ -1449,7 +1434,6 @@ public static function getIsCreditCardMethod($code) { switch ($code) { case self::METHOD_WPP_DIRECT: - case self::METHOD_WPP_PE_DIRECT: case self::METHOD_PAYFLOWPRO: case self::METHOD_PAYFLOWLINK: case self::METHOD_PAYFLOWADVANCED: @@ -1491,8 +1475,9 @@ public function isCurrencyCodeSupported($code) public function exportExpressCheckoutStyleSettings(\Magento\Framework\Object $to) { foreach ($this->_ecStyleConfigMap as $key => $exportKey) { - if ($this->{$key}) { - $to->setData($exportKey, $this->{$key}); + $configValue = $this->getConfigValue($key); + if ($configValue) { + $to->setData($exportKey, $configValue); } } } @@ -1522,7 +1507,7 @@ protected function _getDynamicImageUrl($type, $localeCode, $orderTotal, $pal) } return sprintf( 'https://fpdbs%s.paypal.com/dynamicimageweb?%s', - $this->sandboxFlag ? '.sandbox' : '', + $this->getConfigValue('sandboxFlag') ? '.sandbox' : '', http_build_query($params) ); } @@ -1559,7 +1544,6 @@ protected function _getSpecificConfigPath($fieldName) $path = $this->_mapExpressFieldset($fieldName); break; case self::METHOD_WPP_DIRECT: - case self::METHOD_WPP_PE_DIRECT: $path = $this->_mapDirectFieldset($fieldName); break; case self::METHOD_BILLING_AGREEMENT: @@ -1577,7 +1561,6 @@ protected function _getSpecificConfigPath($fieldName) $path = $this->_mapWppFieldset($fieldName); break; case self::METHOD_WPP_PE_EXPRESS: - case self::METHOD_WPP_PE_DIRECT: case self::METHOD_PAYFLOWADVANCED: case self::METHOD_PAYFLOWLINK: $path = $this->_mapWpukFieldset($fieldName); @@ -1731,10 +1714,7 @@ protected function _mapWpukFieldset($fieldName) ) ) { $pathPrefix = 'payment/payflow_advanced'; - } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS && !$this->isMethodAvailable( - self::METHOD_WPP_PE_DIRECT - ) - ) { + } elseif ($this->_methodCode == self::METHOD_WPP_PE_EXPRESS) { $pathPrefix = 'payment/payflowpro'; } elseif ($this->_methodCode == self::METHOD_PAYFLOWADVANCED || $this->_methodCode == self::METHOD_PAYFLOWLINK ) { diff --git a/app/code/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php b/app/code/Magento/Paypal/Model/Config/Structure/Element/FieldPlugin.php similarity index 57% rename from app/code/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php rename to app/code/Magento/Paypal/Model/Config/Structure/Element/FieldPlugin.php index fb2995df05543..015deadeae4c2 100644 --- a/app/code/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/Grouped.php +++ b/app/code/Magento/Paypal/Model/Config/Structure/Element/FieldPlugin.php @@ -21,42 +21,41 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\GroupedProduct\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks\Plugin; +namespace Magento\Paypal\Model\Config\Structure\Element; -class Grouped +class FieldPlugin { /** * @var \Magento\Framework\App\RequestInterface */ - protected $request; + protected $_request; /** * @param \Magento\Framework\App\RequestInterface $request */ public function __construct(\Magento\Framework\App\RequestInterface $request) { - $this->request = $request; + $this->_request = $request; } /** - * Initialize grouped product links + * Get original configPath (not changed by PayPal configuration inheritance) * - * @param \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks $subject - * @param \Magento\Catalog\Model\Product $product - * - * @return \Magento\Catalog\Model\Product - * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @param \Magento\Backend\Model\Config\Structure\Element\Field $subject + * @param \Closure $proceed + * @return string|null */ - public function afterInitializeLinks( - \Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks $subject, - \Magento\Catalog\Model\Product $product + public function aroundGetConfigPath( + \Magento\Backend\Model\Config\Structure\Element\Field $subject, + \Closure $proceed ) { - $links = $this->request->getPost('links'); - - if (isset($links['grouped']) && !$product->getGroupedReadonly()) { - $product->setGroupedLinkData((array)$links['grouped']); + $configPath = $proceed(); + if (!isset($configPath) && $this->_request->getParam('section') == 'payment') { + $configPath = preg_replace('@^(' . implode( + '|', + \Magento\Paypal\Model\Config\StructurePlugin::getPaypalConfigCountries(true) + ) . ')/@', 'payment/', $subject->getPath()); } - - return $product; + return $configPath; } } diff --git a/app/code/Magento/Paypal/Model/Config/StructurePlugin.php b/app/code/Magento/Paypal/Model/Config/StructurePlugin.php new file mode 100644 index 0000000000000..b69557e61914e --- /dev/null +++ b/app/code/Magento/Paypal/Model/Config/StructurePlugin.php @@ -0,0 +1,122 @@ +_scopeDefiner = $scopeDefiner; + $this->_helper = $helper; + } + + /** + * Get paypal configuration countries + * + * @param bool $addOther + * @return string[] + */ + public static function getPaypalConfigCountries($addOther = false) + { + $countries = self::$_paypalConfigCountries; + if ($addOther) { + $countries[] = 'payment_other'; + } + return $countries; + } + + /** + * Substitute payment section with PayPal configs + * + * @param \Magento\Backend\Model\Config\Structure $subject + * @param \Closure $proceed + * @param array $pathParts + * @return \Magento\Backend\Model\Config\Structure\ElementInterface + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundGetElementByPathParts( + \Magento\Backend\Model\Config\Structure $subject, + \Closure $proceed, + array $pathParts + ) { + $isSectionChanged = $pathParts[0] == 'payment'; + if ($isSectionChanged) { + $requestedCountrySection = 'payment_' . strtolower($this->_helper->getConfigurationCountryCode()); + if (in_array($requestedCountrySection, self::getPaypalConfigCountries())) { + $pathParts[0] = $requestedCountrySection; + } else { + $pathParts[0] = 'payment_other'; + } + } + /** @var \Magento\Backend\Model\Config\Structure\ElementInterface $result */ + $result = $proceed($pathParts); + if ($isSectionChanged && isset($result)) { + if ($result instanceof \Magento\Backend\Model\Config\Structure\Element\Section) { + $result->setData(array_merge( + $result->getData(), + ['showInDefault' => true, 'showInWebsite' => true, 'showInStore' => true] + ), $this->_scopeDefiner->getScope()); + } + } + return $result; + } +} diff --git a/app/code/Magento/Paypal/Model/Direct.php b/app/code/Magento/Paypal/Model/Direct.php index f16a3aee13a94..392c2b8eb9213 100644 --- a/app/code/Magento/Paypal/Model/Direct.php +++ b/app/code/Magento/Paypal/Model/Direct.php @@ -129,18 +129,6 @@ class Direct extends \Magento\Payment\Model\Method\Cc */ protected $_pro; - /** - * Website Payments Pro instance type - * - * @var $_proType string - */ - protected $_proType = 'Magento\Paypal\Model\Pro'; - - /** - * @var \Magento\Paypal\Model\Method\ProTypeFactory - */ - protected $_proTypeFactory; - /** * @var \Magento\Store\Model\StoreManagerInterface */ @@ -170,7 +158,7 @@ class Direct extends \Magento\Payment\Model\Method\Cc * @param \Magento\Framework\Module\ModuleListInterface $moduleList * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Centinel\Model\Service $centinelService - * @param \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory + * @param \Magento\Paypal\Model\ProFactory $proFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Framework\App\RequestInterface $requestHttp @@ -188,7 +176,7 @@ public function __construct( \Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Centinel\Model\Service $centinelService, - \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory, + \Magento\Paypal\Model\ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\App\RequestInterface $requestHttp, @@ -206,7 +194,6 @@ public function __construct( $centinelService, $data ); - $this->_proTypeFactory = $proTypeFactory; $this->_storeManager = $storeManager; $this->_urlBuilder = $urlBuilder; $this->_requestHttp = $requestHttp; @@ -216,7 +203,7 @@ public function __construct( if ($proInstance && $proInstance instanceof \Magento\Paypal\Model\Pro) { $this->_pro = $proInstance; } else { - $this->_pro = $this->_proTypeFactory->create($this->_proType); + $this->_pro = $proFactory->create(); } $this->_pro->setMethod($this->_code); } @@ -267,7 +254,7 @@ public function getConfigPaymentAction() */ public function getAllowedCcTypes() { - $ccTypes = explode(',', $this->_pro->getConfig()->cctypes); + $ccTypes = explode(',', $this->_pro->getConfig()->getConfigValue('cctypes')); $country = $this->_pro->getConfig()->getMerchantCountry(); if ($country == 'GB') { @@ -307,7 +294,7 @@ public function getConfigData($field, $storeId = null) $value = $this->getAllowedCcTypes(); break; default: - $value = $this->_pro->getConfig()->{$field}; + $value = $this->_pro->getConfig()->getConfigValue($field); } return $value; } @@ -421,7 +408,7 @@ public function getCentinelValidator() { $validator = parent::getCentinelValidator(); if (!$validator->getCustomApiEndpointUrl()) { - $validator->setCustomApiEndpointUrl($this->_pro->getConfig()->centinelDefaultApiUrl); + $validator->setCustomApiEndpointUrl($this->_pro->getConfig()->getConfigValue('centinelDefaultApiUrl')); } return $validator; } @@ -449,7 +436,7 @@ protected function _placeOrder(Payment $payment, $amount) { $order = $payment->getOrder(); $api = $this->_pro->getApi()->setPaymentAction( - $this->_pro->getConfig()->paymentAction + $this->_pro->getConfig()->getConfigValue('paymentAction') )->setIpAddress( $this->_requestHttp->getClientIp(false) )->setAmount( @@ -493,7 +480,7 @@ protected function _placeOrder(Payment $payment, $amount) // add line items $cart = $this->_cartFactory->create(array('salesModel' => $order)); - $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_pro->getConfig()->lineItemsEnabled); + $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_pro->getConfig()->getConfigValue('lineItemsEnabled')); // call api and import transaction and other payment information $api->callDoDirectPayment(); diff --git a/app/code/Magento/Paypal/Model/Express.php b/app/code/Magento/Paypal/Model/Express.php index c954207a604c2..6a48cd19f66ba 100644 --- a/app/code/Magento/Paypal/Model/Express.php +++ b/app/code/Magento/Paypal/Model/Express.php @@ -49,13 +49,6 @@ class Express extends \Magento\Payment\Model\Method\AbstractMethod */ protected $_infoBlockType = 'Magento\Paypal\Block\Payment\Info'; - /** - * Website Payments Pro instance type - * - * @var $_proType string - */ - protected $_proType = 'Magento\Paypal\Model\Pro'; - /** * Availability option * @@ -161,11 +154,6 @@ class Express extends \Magento\Payment\Model\Method\AbstractMethod */ protected $_authorizationCountKey = 'authorization_count'; - /** - * @var \Magento\Paypal\Model\Method\ProTypeFactory - */ - protected $_proTypeFactory; - /** * @var \Magento\Store\Model\StoreManagerInterface */ @@ -186,7 +174,7 @@ class Express extends \Magento\Payment\Model\Method\AbstractMethod * @param \Magento\Payment\Helper\Data $paymentData * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Logger\AdapterFactory $logAdapterFactory - * @param \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory + * @param ProFactory $proFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Paypal\Model\CartFactory $cartFactory @@ -197,14 +185,13 @@ public function __construct( \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Logger\AdapterFactory $logAdapterFactory, - \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory, + ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Paypal\Model\CartFactory $cartFactory, array $data = array() ) { parent::__construct($eventManager, $paymentData, $scopeConfig, $logAdapterFactory, $data); - $this->_proTypeFactory = $proTypeFactory; $this->_storeManager = $storeManager; $this->_urlBuilder = $urlBuilder; $this->_cartFactory = $cartFactory; @@ -213,7 +200,7 @@ public function __construct( if ($proInstance && $proInstance instanceof \Magento\Paypal\Model\Pro) { $this->_pro = $proInstance; } else { - $this->_pro = $this->_proTypeFactory->create($this->_proType); + $this->_pro = $proFactory->create(); } $this->_pro->setMethod($this->_code); } @@ -299,7 +286,7 @@ public function isAvailable($quote = null) */ public function getConfigData($field, $storeId = null) { - return $this->_pro->getConfig()->{$field}; + return $this->_pro->getConfig()->getConfigValue($field); } /** @@ -622,7 +609,7 @@ protected function _placeOrder(Payment $payment, $amount) )->setAmount( $amount )->setPaymentAction( - $this->_pro->getConfig()->paymentAction + $this->_pro->getConfig()->getConfigValue('paymentAction') )->setNotifyUrl( $this->_urlBuilder->getUrl('paypal/ipn/') )->setInvNum( @@ -632,7 +619,7 @@ protected function _placeOrder(Payment $payment, $amount) )->setPaypalCart( $cart )->setIsLineItemsEnabled( - $this->_pro->getConfig()->lineItemsEnabled + $this->_pro->getConfig()->getConfigValue('lineItemsEnabled') ); if ($order->getIsVirtual()) { $api->setAddress($order->getBillingAddress())->setSuppressShipping(true); diff --git a/app/code/Magento/Paypal/Model/Express/Checkout.php b/app/code/Magento/Paypal/Model/Express/Checkout.php index 926dce9ac3865..e014d89c4d517 100644 --- a/app/code/Magento/Paypal/Model/Express/Checkout.php +++ b/app/code/Magento/Paypal/Model/Express/Checkout.php @@ -483,8 +483,8 @@ public function start($returnUrl, $cancelUrl) ->setInvNum($this->_quote->getReservedOrderId()) ->setReturnUrl($returnUrl) ->setCancelUrl($cancelUrl) - ->setSolutionType($this->_config->solutionType) - ->setPaymentAction($this->_config->paymentAction) + ->setSolutionType($this->_config->getConfigValue('solutionType')) + ->setPaymentAction($this->_config->getConfigValue('paymentAction')) ; if ($this->_giropayUrls) { list($successUrl, $cancelUrl, $pendingUrl) = $this->_giropayUrls; @@ -499,13 +499,13 @@ public function start($returnUrl, $cancelUrl) $this->_setBillingAgreementRequest(); - if ($this->_config->requireBillingAddress == PaypalConfig::REQUIRE_BILLING_ADDRESS_ALL) { + if ($this->_config->getConfigValue('requireBillingAddress') == PaypalConfig::REQUIRE_BILLING_ADDRESS_ALL) { $this->_api->setRequireBillingAddress(1); } // suppress or export shipping address if ($this->_quote->getIsVirtual()) { - if ($this->_config->requireBillingAddress == PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL) { + if ($this->_config->getConfigValue('requireBillingAddress') == PaypalConfig::REQUIRE_BILLING_ADDRESS_VIRTUAL) { $this->_api->setRequireBillingAddress(1); } $this->_api->setSuppressShipping(true); @@ -527,11 +527,14 @@ public function start($returnUrl, $cancelUrl) /** @var $cart \Magento\Payment\Model\Cart */ $cart = $this->_cartFactory->create(array('salesModel' => $this->_quote)); $this->_api->setPaypalCart($cart) - ->setIsLineItemsEnabled($this->_config->lineItemsEnabled); + ->setIsLineItemsEnabled($this->_config->getConfigValue('lineItemsEnabled')); // add shipping options if needed and line items are available $cartItems = $cart->getAllItems(); - if ($this->_config->lineItemsEnabled && $this->_config->transferShippingOptions && !empty($cartItems)) { + if ($this->_config->getConfigValue('lineItemsEnabled') + && $this->_config->getConfigValue('transferShippingOptions') + && !empty($cartItems) + ) { if (!$this->_quote->getIsVirtual() && !$this->_quote->hasNominalItems()) { $options = $this->_prepareShippingOptions($address, true); if ($options) { @@ -816,7 +819,9 @@ private function _ignoreAddressValidation() $this->_quote->getBillingAddress()->setShouldIgnoreValidation(true); if (!$this->_quote->getIsVirtual()) { $this->_quote->getShippingAddress()->setShouldIgnoreValidation(true); - if (!$this->_config->requireBillingAddress && !$this->_quote->getBillingAddress()->getEmail()) { + if (!$this->_config->getConfigValue('requireBillingAddress') + && !$this->_quote->getBillingAddress()->getEmail() + ) { $this->_quote->getBillingAddress()->setSameAsBilling(1); } } @@ -913,7 +918,7 @@ protected function _setBillingAgreementRequest() $isRequested = $this->_isBARequested || $this->_quote->getPayment() ->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_BILLING_AGREEMENT); - if (!($this->_config->allow_ba_signup == PaypalConfig::EC_BA_SIGNUP_AUTO + if (!($this->_config->getConfigValue('allow_ba_signup') == PaypalConfig::EC_BA_SIGNUP_AUTO || $isRequested && $this->_config->shouldAskToCreateBillingAgreement()) ) { return $this; diff --git a/app/code/Magento/Paypal/Model/Hostedpro.php b/app/code/Magento/Paypal/Model/Hostedpro.php index afcd305a69a87..c887fde91d128 100644 --- a/app/code/Magento/Paypal/Model/Hostedpro.php +++ b/app/code/Magento/Paypal/Model/Hostedpro.php @@ -95,7 +95,7 @@ class Hostedpro extends \Magento\Paypal\Model\Direct * @param \Magento\Framework\Module\ModuleListInterface $moduleList * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Centinel\Model\Service $centinelService - * @param \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory + * @param \Magento\Paypal\Model\ProFactory $proFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Framework\App\RequestInterface $requestHttp @@ -114,7 +114,7 @@ public function __construct( \Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Centinel\Model\Service $centinelService, - \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory, + \Magento\Paypal\Model\ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Framework\App\RequestInterface $requestHttp, @@ -132,7 +132,7 @@ public function __construct( $moduleList, $localeDate, $centinelService, - $proTypeFactory, + $proFactory, $storeManager, $urlBuilder, $requestHttp, diff --git a/app/code/Magento/Paypal/Model/Info.php b/app/code/Magento/Paypal/Model/Info.php index 2d1b90150b9ad..2b6874fca2d1e 100644 --- a/app/code/Magento/Paypal/Model/Info.php +++ b/app/code/Magento/Paypal/Model/Info.php @@ -91,16 +91,16 @@ class Info * @var array */ protected $_paymentMap = array( - self::PAYER_ID => 'paypal_payer_id', - self::PAYER_EMAIL => 'paypal_payer_email', - self::PAYER_STATUS => 'paypal_payer_status', - self::ADDRESS_ID => 'paypal_address_id', - self::ADDRESS_STATUS => 'paypal_address_status', - self::PROTECTION_EL => 'paypal_protection_eligibility', - self::FRAUD_FILTERS => 'paypal_fraud_filters', - self::CORRELATION_ID => 'paypal_correlation_id', - self::AVS_CODE => 'paypal_avs_code', - self::CVV2_MATCH => 'paypal_cvv2_match', + self::PAYER_ID => self::PAYPAL_PAYER_ID, + self::PAYER_EMAIL => self::PAYPAL_PAYER_EMAIL, + self::PAYER_STATUS => self::PAYPAL_PAYER_STATUS, + self::ADDRESS_ID => self::PAYPAL_ADDRESS_ID, + self::ADDRESS_STATUS => self::PAYPAL_ADDRESS_STATUS, + self::PROTECTION_EL => self::PAYPAL_PROTECTION_ELIGIBILITY, + self::FRAUD_FILTERS => self::PAYPAL_FRAUD_FILTERS, + self::CORRELATION_ID => self::PAYPAL_CORRELATION_ID, + self::AVS_CODE => self::PAYPAL_AVS_CODE, + self::CVV2_MATCH => self::PAYPAL_CVV2_MATCH, self::CENTINEL_VPAS => self::CENTINEL_VPAS, self::CENTINEL_ECI => self::CENTINEL_ECI, self::BUYER_TAX_ID => self::BUYER_TAX_ID, @@ -187,6 +187,68 @@ class Info */ protected $_paymentMapFull = array(); + /** + * Cache for storing label translations + * + * @var array + */ + protected $_labelCodesCache = []; + + /** + * Paypal payer id code key + */ + const PAYPAL_PAYER_ID = 'paypal_payer_id'; + + /** + * Paypal payer email code key + */ + const PAYPAL_PAYER_EMAIL = 'paypal_payer_email'; + + /** + * Paypal payer status code key + */ + const PAYPAL_PAYER_STATUS = 'paypal_payer_status'; + + /** + * Paypal address id code key + */ + const PAYPAL_ADDRESS_ID = 'paypal_address_id'; + + /** + * Paypal address status code key + */ + const PAYPAL_ADDRESS_STATUS = 'paypal_address_status'; + + /** + * Paypal protection eligibility code key + */ + const PAYPAL_PROTECTION_ELIGIBILITY = 'paypal_protection_eligibility'; + + /** + * Paypal fraud filters code key + */ + const PAYPAL_FRAUD_FILTERS = 'paypal_fraud_filters'; + + /** + * Paypal correlation id code key + */ + const PAYPAL_CORRELATION_ID = 'paypal_correlation_id'; + + /** + * Paypal avs code key + */ + const PAYPAL_AVS_CODE = 'paypal_avs_code'; + + /** + * Paypal cvv2 code key + */ + const PAYPAL_CVV2_MATCH = 'paypal_cvv2_match'; + + /** + * Item labels key for label codes cache + */ + const ITEM_LABELS = 'item labels'; + /** * All available payment info getter * @@ -409,7 +471,7 @@ public static function explainPendingReason($code) */ public static function explainReasonCode($code) { - $comments = array( + $comments = [ 'chargeback' => __('A reversal has occurred on this transaction due to a chargeback by your customer.'), 'guarantee' => __( 'A reversal has occurred on this transaction due to your customer triggering a money-back guarantee.' @@ -439,14 +501,10 @@ public static function explainReasonCode($code) 'adjustment_reimburse' => __('A case that has been resolved and close requires a reimbursement.'), 'duplicate' => __('Buyer claims that a possible duplicate payment was made to the merchant.'), 'merchandise' => __('Buyer claims that the received merchandise is unsatisfactory, defective, or damaged.') - ); - $value = array_key_exists( - $code, - $comments - ) && !empty($comments[$code]) ? $comments[$code] : __( - 'Unknown reason. Please contact PayPal customer service.' - ); - return $value; + ]; + return isset($comments[$code]) + ? $comments[$code] + : __('Unknown reason. Please contact PayPal customer service.'); } /** @@ -457,21 +515,18 @@ public static function explainReasonCode($code) */ public static function isReversalDisputable($code) { - switch ($code) { - case 'none': - case 'other': - case 'chargeback': - case 'buyer-complaint': - case 'buyer_complaint': - case 'adjustment_reversal': - return true; - case 'guarantee': - case 'refund': - case 'chargeback_reimbursement': - case 'chargeback_settlement': - default: - return false; - } + $listOfDisputeCodes = [ + 'none' => true, + 'other' => true, + 'chargeback' => true, + 'buyer-complaint' => true, + 'adjustment_reversal' => true, + 'guarantee' => false, + 'refund' => false, + 'chargeback_reimbursement' => false, + 'chargeback_settlement' => false, + ]; + return isset($listOfDisputeCodes[$code]) ? $listOfDisputeCodes[$code] : false; } /** @@ -518,37 +573,27 @@ protected function _getFullInfo(array $keys, \Magento\Payment\Model\Info $paymen */ protected function _getLabel($key) { - switch ($key) { - case 'paypal_payer_id': - return __('Payer ID'); - case 'paypal_payer_email': - return __('Payer Email'); - case 'paypal_payer_status': - return __('Payer Status'); - case 'paypal_address_id': - return __('Payer Address ID'); - case 'paypal_address_status': - return __('Payer Address Status'); - case 'paypal_protection_eligibility': - return __('Merchant Protection Eligibility'); - case 'paypal_fraud_filters': - return __('Triggered Fraud Filters'); - case 'paypal_correlation_id': - return __('Last Correlation ID'); - case 'paypal_avs_code': - return __('Address Verification System Response'); - case 'paypal_cvv2_match': - return __('CVV2 Check Result by PayPal'); - case self::BUYER_TAX_ID: - return __('Buyer\'s Tax ID'); - case self::BUYER_TAX_ID_TYPE: - return __('Buyer\'s Tax ID Type'); - case self::CENTINEL_VPAS: - return __('PayPal/Centinel Visa Payer Authentication Service Result'); - case self::CENTINEL_ECI: - return __('PayPal/Centinel Electronic Commerce Indicator'); + if (!isset($this->_labelCodesCache[self::ITEM_LABELS])) { + $this->_labelCodesCache[self::ITEM_LABELS] = [ + self::PAYPAL_PAYER_ID => __('Payer ID'), + self::PAYPAL_PAYER_EMAIL=> __('Payer Email'), + self::PAYPAL_PAYER_STATUS => __('Payer Status'), + self::PAYPAL_ADDRESS_ID => __('Payer Address ID'), + self::PAYPAL_ADDRESS_STATUS => __('Payer Address Status'), + self::PAYPAL_PROTECTION_ELIGIBILITY=> __('Merchant Protection Eligibility'), + self::PAYPAL_FRAUD_FILTERS => __('Triggered Fraud Filters'), + self::PAYPAL_CORRELATION_ID => __('Last Correlation ID'), + self::PAYPAL_AVS_CODE => __('Address Verification System Response'), + self::PAYPAL_CVV2_MATCH => __('CVV2 Check Result by PayPal'), + self::BUYER_TAX_ID => __('Buyer\'s Tax ID'), + self::BUYER_TAX_ID_TYPE => __('Buyer\'s Tax ID Type'), + self::CENTINEL_VPAS => __('PayPal/Centinel Visa Payer Authentication Service Result'), + self::CENTINEL_ECI => __('PayPal/Centinel Electronic Commerce Indicator') + ]; } - return ''; + return isset($this->_labelCodesCache[self::ITEM_LABELS][$key]) + ? $this->_labelCodesCache[self::ITEM_LABELS][$key] + : ''; } /** @@ -559,8 +604,12 @@ protected function _getLabel($key) */ public static function getCaseTypeLabel($key) { - $labels = array('chargeback' => __('Chargeback'), 'complaint' => __('Complaint'), 'dispute' => __('Dispute')); - $value = array_key_exists($key, $labels) && !empty($labels[$key]) ? $labels[$key] : ''; + $labels = [ + 'chargeback' => __('Chargeback'), + 'complaint' => __('Complaint'), + 'dispute' => __('Dispute') + ]; + $value = isset($labels[$key]) ? $labels[$key] : ''; return $value; } @@ -575,10 +624,10 @@ protected function _getValue($value, $key) { $label = ''; switch ($key) { - case 'paypal_avs_code': + case self::PAYPAL_AVS_CODE: $label = $this->_getAvsLabel($value); break; - case 'paypal_cvv2_match': + case self::PAYPAL_CVV2_MATCH: $label = $this->_getCvv2Label($value); break; case self::CENTINEL_VPAS: @@ -605,64 +654,42 @@ protected function _getValue($value, $key) */ protected function _getAvsLabel($value) { - switch ($value) { - // Visa, MasterCard, Discover and American Express - case 'A': - case 'YN': - return __('Matched Address only (no ZIP)'); - case 'B': + if (!isset($this->_labelCodesCache[self::PAYPAL_AVS_CODE])) { + $this->_labelCodesCache[self::PAYPAL_AVS_CODE] = [ + // Visa, MasterCard, Discover and American Express + 'A' => __('Matched Address only (no ZIP)'), // international "A" - return __('Matched Address only (no ZIP) International'); - case 'N': - return __('No Details matched'); - case 'C': + 'B' => __('Matched Address only (no ZIP) International'), + 'N' => __('No Details matched'), // international "N" - return __('No Details matched. International'); - case 'X': - return __('Exact Match. Address and nine-digit ZIP code'); - case 'D': + 'C' => __('No Details matched. International'), + 'X' => __('Exact Match. Address and nine-digit ZIP code'), // international "X" - return __('Exact Match. Address and Postal Code. International'); - case 'F': + 'D' => __('Exact Match. Address and Postal Code. International'), // UK-specific "X" - return __('Exact Match. Address and Postal Code. UK-specific'); - case 'E': - return __('N/A. Not allowed for MOTO (Internet/Phone) transactions'); - case 'G': - return __('N/A. Global Unavailable'); - case 'I': - return __('N/A. International Unavailable'); - case 'Z': - case 'NY': - return __('Matched five-digit ZIP only (no Address)'); - case 'P': + 'F' => __('Exact Match. Address and Postal Code. UK-specific'), + 'E' => __('N/A. Not allowed for MOTO (Internet/Phone) transactions'), + 'G' => __('N/A. Global Unavailable'), + 'I' => __('N/A. International Unavailable'), + 'Z' => __('Matched five-digit ZIP only (no Address)'), // international "Z" - case 'NY': - return __('Matched Postal Code only (no Address)'); - case 'R': - return __('N/A. Retry'); - case 'S': - return __('N/A. Service not Supported'); - case 'U': - return __('N/A. Unavailable'); - case 'W': - return __('Matched whole nine-didgit ZIP (no Address)'); - case 'Y': - return __('Yes. Matched Address and five-didgit ZIP'); + 'P' => __('Matched Postal Code only (no Address)'), + 'R' => __('N/A. Retry'), + 'S' => __('N/A. Service not Supported'), + 'U' => __('N/A. Unavailable'), + 'W' => __('Matched whole nine-didgit ZIP (no Address)'), + 'Y' => __('Yes. Matched Address and five-didgit ZIP'), // Maestro and Solo - case '0': - return __('All the address information matched'); - case '1': - return __('None of the address information matched'); - case '2': - return __('Part of the address information matched'); - case '3': - return __('N/A. The merchant did not provide AVS information'); - case '4': - return __('N/A. Address not checked, or acquirer had no response. Service not available'); - default: - return $value; + '0' => __('All the address information matched'), + '1' => __('None of the address information matched'), + '2' => __('Part of the address information matched'), + '3' => __('N/A. The merchant did not provide AVS information'), + '4' => __('N/A. Address not checked, or acquirer had no response. Service not available') + ]; } + return isset($this->_labelCodesCache[self::PAYPAL_AVS_CODE][$value]) + ? $this->_labelCodesCache[self::PAYPAL_AVS_CODE][$value] + : $value; } /** @@ -674,34 +701,26 @@ protected function _getAvsLabel($value) */ protected function _getCvv2Label($value) { - switch ($value) { - // Visa, MasterCard, Discover and American Express - case 'M': - return __('Matched (CVV2CSC)'); - case 'N': - return __('No match'); - case 'P': - return __('N/A. Not processed'); - case 'S': - return __('N/A. Service not supported'); - case 'U': - return __('N/A. Service not available'); - case 'X': - return __('N/A. No response'); + if (!isset($this->_labelCodesCache[self::PAYPAL_CVV2_MATCH])) { + $this->_labelCodesCache[self::PAYPAL_CVV2_MATCH] = [ + // Visa, MasterCard, Discover and American Express + 'M' => __('Matched (CVV2CSC)'), + 'N' => __('No match'), + 'P' => __('N/A. Not processed'), + 'S' => __('N/A. Service not supported'), + 'U' => __('N/A. Service not available'), + 'X' => __('N/A. No response'), // Maestro and Solo - case '0': - return __('Matched (CVV2)'); - case '1': - return __('No match'); - case '2': - return __('N/A. The merchant has not implemented CVV2 code handling'); - case '3': - return __('N/A. Merchant has indicated that CVV2 is not present on card'); - case '4': - return __('N/A. Service not available'); - default: - return $value; + '0' => __('Matched (CVV2)'), + '1' => __('No match'), + '2' => __('N/A. The merchant has not implemented CVV2 code handling'), + '3' => __('N/A. Merchant has indicated that CVV2 is not present on card'), + '4' => __('N/A. Service not available') + ]; } + return isset($this->_labelCodesCache[self::PAYPAL_CVV2_MATCH][$value]) + ? $this->_labelCodesCache[self::PAYPAL_CVV2_MATCH][$value] + : $value; } /** @@ -713,29 +732,27 @@ protected function _getCvv2Label($value) */ private function _getCentinelVpasLabel($value) { - switch ($value) { - case '2': - case 'D': - return __('Authenticated, Good Result'); - case '1': - return __('Authenticated, Bad Result'); - case '3': - case '6': - case '8': - case 'A': - case 'C': - return __('Attempted Authentication, Good Result'); - case '4': - case '7': - case '9': - return __('Attempted Authentication, Bad Result'); - case '': - case '0': - case 'B': - return __('No Liability Shift'); - default: - return $value; + if (!isset($this->_labelCodesCache[self::CENTINEL_VPAS])) { + $this->_labelCodesCache[self::CENTINEL_VPAS] = [ + '2' => __('Authenticated, Good Result'), + 'D' => __('Authenticated, Good Result'), + '1' => __('Authenticated, Bad Result'), + '3' => __('Attempted Authentication, Good Result'), + '6' => __('Attempted Authentication, Good Result'), + '8' => __('Attempted Authentication, Good Result'), + 'A' => __('Attempted Authentication, Good Result'), + 'C' => __('Attempted Authentication, Good Result'), + '4' => __('Attempted Authentication, Bad Result'), + '7' => __('Attempted Authentication, Bad Result'), + '9' => __('Attempted Authentication, Bad Result'), + '' => __('No Liability Shift'), + '0' => __('No Liability Shift'), + 'B' => __('No Liability Shift') + ]; } + return isset($this->_labelCodesCache[self::CENTINEL_VPAS][$value]) + ? $this->_labelCodesCache[self::CENTINEL_VPAS][$value] + : $value; } /** @@ -747,17 +764,18 @@ private function _getCentinelVpasLabel($value) */ private function _getCentinelEciLabel($value) { - switch ($value) { - case '01': - case '07': - return __('Merchant Liability'); - case '02': - case '05': - case '06': - return __('Issuer Liability'); - default: - return $value; + if (!isset($this->_labelCodesCache[self::CENTINEL_ECI])) { + $this->_labelCodesCache[self::CENTINEL_ECI] = [ + '01' => __('Merchant Liability'), + '07' => __('Merchant Liability'), + '02' => __('Issuer Liability'), + '05' => __('Issuer Liability'), + '06' => __('Issuer Liability') + ]; } + return isset($this->_labelCodesCache[self::CENTINEL_ECI][$value]) + ? $this->_labelCodesCache[self::CENTINEL_ECI][$value] + : $value; } /** @@ -768,15 +786,14 @@ private function _getCentinelEciLabel($value) */ protected function _getBuyerIdTypeValue($code) { - $value = ''; - switch ($code) { - case self::BUYER_TAX_ID_TYPE_CNPJ: - $value = __('CNPJ'); - break; - case self::BUYER_TAX_ID_TYPE_CPF: - $value = __('CPF'); - break; + if (!isset($this->_labelCodesCache[self::BUYER_TAX_ID_TYPE])) { + $this->_labelCodesCache[self::BUYER_TAX_ID_TYPE] = [ + self::BUYER_TAX_ID_TYPE_CNPJ => __('CNPJ'), + self::BUYER_TAX_ID_TYPE_CPF => __('CPF') + ]; } - return $value; + return isset($this->_labelCodesCache[self::BUYER_TAX_ID_TYPE][$code]) + ? $this->_labelCodesCache[self::BUYER_TAX_ID_TYPE][$code] + : ''; } } diff --git a/app/code/Magento/Paypal/Model/Ipn.php b/app/code/Magento/Paypal/Model/Ipn.php index a1fe5bf3b1a88..493bd9bdee3d3 100644 --- a/app/code/Magento/Paypal/Model/Ipn.php +++ b/app/code/Magento/Paypal/Model/Ipn.php @@ -107,7 +107,7 @@ protected function _getConfig() } /** @link https://cms.paypal.com/cgi-bin/marketingweb?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro */ // verify merchant email intended to receive notification - $merchantEmail = $this->_config->businessAccount; + $merchantEmail = $this->_config->getConfigValue('businessAccount'); if (!$merchantEmail) { return $this->_config; } diff --git a/app/code/Magento/Paypal/Model/Method/Agreement.php b/app/code/Magento/Paypal/Model/Method/Agreement.php index 843421a934579..2aa41c4c3ce14 100644 --- a/app/code/Magento/Paypal/Model/Method/Agreement.php +++ b/app/code/Magento/Paypal/Model/Method/Agreement.php @@ -139,7 +139,7 @@ class Agreement extends \Magento\Paypal\Model\Payment\Method\Billing\AbstractAgr * @param \Magento\Framework\Logger\AdapterFactory $logAdapterFactory * @param \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory + * @param \Magento\Paypal\Model\ProFactory $proFactory * @param \Magento\Framework\UrlInterface $urlBuilder * @param \Magento\Paypal\Model\CartFactory $cartFactory * @param array $data @@ -153,7 +153,7 @@ public function __construct( \Magento\Framework\Logger\AdapterFactory $logAdapterFactory, \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory, + \Magento\Paypal\Model\ProFactory $proFactory, \Magento\Framework\UrlInterface $urlBuilder, \Magento\Paypal\Model\CartFactory $cartFactory, array $data = array() @@ -173,7 +173,7 @@ public function __construct( if ($proInstance && $proInstance instanceof \Magento\Paypal\Model\Pro) { $this->_pro = $proInstance; } else { - $this->_pro = $proTypeFactory->create('Magento\Paypal\Model\Pro'); + $this->_pro = $proFactory->create(); } $this->_pro->setMethod($this->_code); } @@ -412,7 +412,7 @@ protected function _placeOrder(Payment $payment, $amount) $api = $this->_pro->getApi()->setReferenceId( $billingAgreement->getReferenceId() )->setPaymentAction( - $proConfig->paymentAction + $proConfig->getConfigValue('paymentAction') )->setAmount( $amount )->setCurrencyCode( @@ -422,7 +422,7 @@ protected function _placeOrder(Payment $payment, $amount) )->setPaypalCart( $cart )->setIsLineItemsEnabled( - $proConfig->lineItemsEnabled + $proConfig->getConfigValue('lineItemsEnabled') )->setInvNum( $order->getIncrementId() ); diff --git a/app/code/Magento/Paypal/Model/PayflowDirect.php b/app/code/Magento/Paypal/Model/PayflowDirect.php deleted file mode 100644 index 998f2bd5c0f26..0000000000000 --- a/app/code/Magento/Paypal/Model/PayflowDirect.php +++ /dev/null @@ -1,102 +0,0 @@ -_pro->getConfig()->cctypes; - } - - /** - * Merchant country limitation for 3d secure feature, rewrite for parent implementation - * - * @return bool - */ - public function getIsCentinelValidationEnabled() - { - if (!parent::getIsCentinelValidationEnabled()) { - return false; - } - // available only for US and UK merchants - if (in_array($this->_pro->getConfig()->getMerchantCountry(), array('US', 'GB'))) { - return true; - } - return false; - } - - /** - * Import direct payment results to payment - * - * @param \Magento\Paypal\Model\Api\Nvp $api - * @param \Magento\Sales\Model\Order\Payment $payment - * @return void - */ - protected function _importResultToPayment($api, $payment) - { - $payment->setTransactionId( - $api->getPaypalTransactionId() - )->setIsTransactionClosed( - 0 - )->setIsTransactionPending( - $api->getIsPaymentPending() - )->setTransactionAdditionalInfo( - \Magento\Paypal\Model\Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID, - $api->getTransactionId() - ); - $payment->setPreparedMessage(__('Payflow PNREF: #%1.', $api->getTransactionId())); - $this->_pro->importPaymentInfo($api, $payment); - } - - /** - * Format credit card expiration date based on month and year values - * Format: mmyy - * - * @param string|int $month - * @param string|int $year - * @return string - */ - protected function _getFormattedCcExpirationDate($month, $year) - { - return sprintf('%02d', $month) . sprintf('%02d', substr($year, -2, 2)); - } -} diff --git a/app/code/Magento/Paypal/Model/PayflowExpress.php b/app/code/Magento/Paypal/Model/PayflowExpress.php index 911897733bd4d..50d0c2081fbd6 100644 --- a/app/code/Magento/Paypal/Model/PayflowExpress.php +++ b/app/code/Magento/Paypal/Model/PayflowExpress.php @@ -21,36 +21,32 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + namespace Magento\Paypal\Model; +use Magento\Sales\Model\Order\Payment\Transaction; + class PayflowExpress extends \Magento\Paypal\Model\Express { /** * @var string */ - protected $_code = \Magento\Paypal\Model\Config::METHOD_WPP_PE_EXPRESS; + protected $_code = Config::METHOD_WPP_PE_EXPRESS; /** * @var string */ protected $_formBlockType = 'Magento\Paypal\Block\PayflowExpress\Form'; - /** - * Website Payments Pro instance type - * - * @var $_proType string - */ - protected $_proType = 'Magento\Paypal\Model\Payflow\Pro'; - /** * Express Checkout payment method instance * - * @var \Magento\Paypal\Model\Express + * @var Express */ protected $_ecInstance = null; /** - * @var \Magento\Paypal\Model\InfoFactory + * @var InfoFactory */ protected $_paypalInfoFactory; @@ -59,11 +55,11 @@ class PayflowExpress extends \Magento\Paypal\Model\Express * @param \Magento\Payment\Helper\Data $paymentData * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\Logger\AdapterFactory $logAdapterFactory - * @param \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory + * @param ProFactory $proFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\UrlInterface $urlBuilder - * @param \Magento\Paypal\Model\CartFactory $cartFactory - * @param \Magento\Paypal\Model\InfoFactory $paypalInfoFactory + * @param CartFactory $cartFactory + * @param InfoFactory $paypalInfoFactory * @param array $data */ public function __construct( @@ -71,11 +67,11 @@ public function __construct( \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\Logger\AdapterFactory $logAdapterFactory, - \Magento\Paypal\Model\Method\ProTypeFactory $proTypeFactory, + ProFactory $proFactory, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\UrlInterface $urlBuilder, - \Magento\Paypal\Model\CartFactory $cartFactory, - \Magento\Paypal\Model\InfoFactory $paypalInfoFactory, + CartFactory $cartFactory, + InfoFactory $paypalInfoFactory, array $data = array() ) { parent::__construct( @@ -83,7 +79,7 @@ public function __construct( $paymentData, $scopeConfig, $logAdapterFactory, - $proTypeFactory, + $proFactory, $storeManager, $urlBuilder, $cartFactory, @@ -105,7 +101,7 @@ public function isAvailable($quote = null) } if (!$this->_ecInstance) { $this->_ecInstance = $this->_paymentData->getMethodInstance( - \Magento\Paypal\Model\Config::METHOD_WPP_EXPRESS + Config::METHOD_WPP_EXPRESS ); } if ($quote && $this->_ecInstance) { @@ -117,7 +113,7 @@ public function isAvailable($quote = null) /** * Import payment info to payment * - * @param \Magento\Paypal\Model\Api\Nvp $api + * @param Api\Nvp $api * @param \Magento\Sales\Model\Order\Payment $payment * @return void */ @@ -128,12 +124,12 @@ protected function _importToPayment($api, $payment) )->setIsTransactionClosed( 0 )->setAdditionalInformation( - \Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT, + Express\Checkout::PAYMENT_INFO_TRANSPORT_REDIRECT, $api->getRedirectRequired() || $api->getRedirectRequested() )->setIsTransactionPending( $api->getIsPaymentPending() )->setTransactionAdditionalInfo( - \Magento\Paypal\Model\Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID, + Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID, $api->getTransactionId() ); $payment->setPreparedMessage(__('Payflow PNREF: #%1.', $api->getTransactionId())); @@ -151,4 +147,22 @@ public function getCheckoutRedirectUrl() { return $this->_urlBuilder->getUrl('paypal/payflowexpress/start'); } + + /** + * Check refund availability. + * The main factor is that the last capture transaction exists and has an Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID in + * additional information(needed to perform online refund. Requirement of the Payflow gateway) + * + * @return bool + */ + public function canRefund() + { + /** @var \Magento\Sales\Model\Order\Payment $payment */ + $payment = $this->getInfoInstance(); + // we need the last capture transaction was made + $captureTransaction = $payment->lookupTransaction('', Transaction::TYPE_CAPTURE); + return $captureTransaction && $captureTransaction->getAdditionalInformation( + Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID + ) && $this->_canRefund; + } } diff --git a/app/code/Magento/Paypal/Model/Standard.php b/app/code/Magento/Paypal/Model/Standard.php index a4e0c231f7704..db3685289c1ce 100644 --- a/app/code/Magento/Paypal/Model/Standard.php +++ b/app/code/Magento/Paypal/Model/Standard.php @@ -252,7 +252,7 @@ public function getStandardCheckoutFormFields() // add cart totals and line items $cart = $this->_cartFactory->create(array('salesModel' => $order)); - $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_config->lineItemsEnabled); + $api->setPaypalCart($cart)->setIsLineItemsEnabled($this->_config->getConfigValue('lineItemsEnabled')); $api->setCartSummary($this->_getAggregatedCartSummary()); $api->setLocale($api->getLocaleCode()); $result = $api->getStandardCheckoutRequest(); @@ -313,7 +313,7 @@ public function isAvailable($quote = null) */ public function getConfigData($field, $storeId = null) { - return $this->getConfig()->{$field}; + return $this->getConfig()->getConfigValue($field); } /** @@ -323,8 +323,8 @@ public function getConfigData($field, $storeId = null) */ private function _getAggregatedCartSummary() { - if ($this->_config->lineItemsSummary) { - return $this->_config->lineItemsSummary; + if ($this->_config->getConfigValue('lineItemsSummary')) { + return $this->_config->getConfigValue('lineItemsSummary'); } return $this->_storeManager->getStore($this->getStore())->getFrontendName(); } diff --git a/app/code/Magento/Paypal/etc/adminhtml/di.xml b/app/code/Magento/Paypal/etc/adminhtml/di.xml index 7a9dcd1d84ccc..34037115d3b55 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/di.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/di.xml @@ -51,4 +51,13 @@ adminhtml + + + + + + + + + diff --git a/app/code/Magento/Paypal/etc/adminhtml/system.xml b/app/code/Magento/Paypal/etc/adminhtml/system.xml index 1953c4fc7cad5..82bf0a09bf352 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/system.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/system.xml @@ -30,997 +30,1420 @@ Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Hint https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup - + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Location + + + If not specified, Default Country from General Config will be used + Magento\Paypal\Block\Adminhtml\System\Config\Field\Country + Magento\Paypal\Model\System\Config\Source\MerchantCountry + Magento\Paypal\Model\System\Config\Backend\MerchantCountry + paypal/general/merchant_country + - - - 1 - complex - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group - Choose a secure bundled payment solution for your business. - https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup - - - - - - - +
+
+ + + pp-method-general + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + Accept payments with a completely customizable checkout. + payment/paypal_direct/active + https://www.paypal.com/webapps/mpp/referral/website-payments-pro?partner_id=NB9WWHYEMVUMS + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + + + + + + + + - - + + + payment/paypal_direct/active + Magento\Backend\Model\Config\Source\Yesno + + + + paypal-enabler + 1 + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "Debit or Credit Card" per store views. + payment/paypal_direct/title + 1 + + + + payment/paypal_direct/sort_order + validate-number + 1 + + + + payment/paypal_direct/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + 1 + + + + Magento\Backend\Block\System\Config\Form\Field\Heading + 1 + + + + + http://www.paypal.com/amexupdate.]]> + + payment/paypal_direct/cctypes + Magento\Paypal\Model\Config::getWppCcTypesAsOptionArray + 1 + + + + config-advanced + + + payment/paypal_direct/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries + 1 + + + + payment/paypal_direct/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + + 1 + + 1 + + + + payment/paypal_direct/debug + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_direct/verify_peer + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_direct/line_items_enabled + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_direct/useccv + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + Magento\Backend\Block\System\Config\Form\Field\Heading + 1 + + + + payment/paypal_direct/centinel + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_direct/centinel_is_mode_strict + Severe Validation Removes Chargeback Liability on Merchant + Magento\Backend\Model\Config\Source\Yesno + + 1 + + 1 + + + + payment/paypal_direct/centinel_api_url + If empty, a default value will be used. Custom URL may be provided by CardinalCommerce agreement. + Magento\Backend\Model\Config\Source\Yesno + + 1 + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + + + + + + + + config-advanced + + + + + + + + + + - - - complex - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group - Process payments using your own internet merchant account. - https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content - - - - - paypal-enabler paypal-ec-pe + + + pp-method-general + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + Accept credit card and PayPal payments securely. + payment/paypal_standard/active + https://www.paypal.com/webapps/mpp/referral/website-payments-standard?partner_id=NB9WWHYEMVUMS + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + payment/paypal_standard/active + Magento\Backend\Model\Config\Source\Yesno + + + + paypal-enabler paypal-ec-conflicts + 1 + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "PayPal" per store views. + payment/paypal_standard/title + 1 + + + + payment/paypal_standard/sort_order + validate-number + 1 + + + + payment/paypal_standard/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + 1 + + + + config-advanced + + + payment/paypal_standard/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries + 1 + + + + payment/paypal_standard/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + + 1 + + 1 + + + + payment/paypal_standard/sandbox_flag + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_standard/line_items_enabled + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_standard/line_items_summary + Uses store frontend name by default. + + 0 + + 1 + + + + payment/paypal_standard/debug + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_standard/verify_peer + Magento\Backend\Model\Config\Source\Yesno + 1 - - - 1 - complex - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group - Add another payment method to your existing solution or as a stand-alone option. - Select a Payment Solution - https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content - - - - - - pp-method-general - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - https://www.paypal.com/webapps/mpp/referral/paypal-payments-advanced?partner_id=NB9WWHYEMVUMS - Accept payments with a PCI-compliant checkout that keeps customers on your site. - payment/payflow_advanced/active - - + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + pp-method-payflow + Connect your merchant account with a fully customizable gateway that lets customers pay without leaving your site. + payment/payflowpro/active + https://www.paypal.com/webapps/mpp/referral/paypal-payflow-pro?partner_id=NB9WWHYEMVUMS + 1 + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - - - payment/payflow_advanced/partner - 1 - - - - payment/payflow_advanced/vendor - 1 - - - - PayPal recommends that you set up an additional User on your account at manager.paypal.com - PayPal recommends you set up an additional User on your account at manager.paypal.com, instead of entering your admin username and password here. This will enhance your security and prevent service interruptions if you later change your password. If you do not want to set up an additional User, you can re-enter your Merchant Login here. - payment/payflow_advanced/user - 1 - - - - payment/payflow_advanced/pwd - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - - - payment/payflow_advanced/sandbox_flag - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/use_proxy - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/proxy_host - - 1 - - 1 - - - - payment/payflow_advanced/proxy_port - - 1 - - 1 - - - Magento\Paypal\Block\Adminhtml\System\Config\Payflowlink\Advanced - 1 - - - - - payment/payflow_advanced/active + + + payment/payflowpro/partner + 1 + + + + payment/payflowpro/user + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + + + payment/payflowpro/vendor + 1 + + + + payment/payflowpro/pwd + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + + + payment/payflowpro/sandbox_flag Magento\Backend\Model\Config\Source\Yesno - - - - paypal-enabler paypal-ec-pe paypal-payflow-advanced 1 - - payment/payflow_express/active - Magento\Paypal\Block\Adminhtml\System\Config\Field\Hidden + + + payment/payflowpro/use_proxy Magento\Backend\Model\Config\Source\Yesno - paypal-ec-payflow-enabler 1 - - - + + + + payment/payflowpro/proxy_host + + 1 + + 1 + + + + payment/payflowpro/proxy_port + + 1 + + 1 - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - It is recommended to set this value to "Debit or Credit Card" per store views. - payment/payflow_advanced/title + + + payment/payflowpro/active + Magento\Backend\Model\Config\Source\Yesno + + + + paypal-enabler paypal-ec-separate + 1 + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "Debit or Credit Card" per store views. + payment/payflowpro/title + 1 + + + + payment/payflowpro/sort_order + validate-number + 1 + + + + payment/payflowpro/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + 1 + + + + Magento\Backend\Block\System\Config\Form\Field\Heading + 1 + + + + + http://www.paypal.com/amexupdate.]]> + + payment/payflowpro/cctypes + Magento\Paypal\Model\Config::getPayflowproCcTypesAsOptionArray + 1 + + + + config-advanced + + + payment/payflowpro/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries 1 - - - payment/payflow_advanced/sort_order - validate-number + + + payment/payflowpro/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + + 1 + 1 - - - payment/payflow_advanced/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions + + + payment/payflowpro/debug + Magento\Backend\Model\Config\Source\Yesno 1 - - - config-advanced - - - payment/payflow_advanced/allowspecific - Magento\Payment\Model\Config\Source\Allspecificcountries - 1 - - - - payment/payflow_advanced/specificcountry - Magento\Paypal\Model\System\Config\Source\BuyerCountry - - 1 - - 1 - - - - payment/payflow_advanced/debug - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/verify_peer - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/csc_editable - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/csc_required - Magento\Backend\Model\Config\Source\Yesno - - 1 - - 1 - - - - payment/payflow_advanced/email_confirmation - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_advanced/url_method - Magento\Paypal\Model\System\Config\Source\UrlMethod - 1 - - - - - - - - - - - - - - - - - + + + payment/payflowpro/verify_peer + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/payflowpro/useccv + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + Magento\Backend\Block\System\Config\Form\Field\Heading + 1 + + + + payment/payflowpro/centinel + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/payflowpro/centinel_is_mode_strict + Severe validation removes chargeback liability on merchant. + Magento\Backend\Model\Config\Source\Yesno + + 1 + + 1 + + + + payment/payflowpro/centinel_api_url + A value is required for live mode. Refer to your CardinalCommerce agreement. + Magento\Backend\Model\Config\Source\Yesno + + 1 + + 1 + + + + + + + + + + + + + - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - - - - - - - pp-method-general - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - Accept payments with a completely customizable checkout. - payment/paypal_direct/active - https://www.paypal.com/webapps/mpp/referral/website-payments-pro?partner_id=NB9WWHYEMVUMS - - + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + pp-method-payflow + Connect your merchant account with a PCI-compliant gateway that lets customers pay without leaving your site. + payment/payflow_link/active + https://www.paypal.com/webapps/mpp/referral/paypal-payflow-link?partner_id=NB9WWHYEMVUMS + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - - - - - - - - - - - - payment/paypal_direct/active + + not-required + + 1 + + + + payment/payflow_link/partner + 1 + + + + payment/payflow_link/vendor + 1 + + + + If you do not have multiple users set up on your account, please re-enter your Vendor/Merchant Login here. + payment/payflow_link/user + 1 + + + + payment/payflow_link/pwd + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + + + payment/payflow_link/sandbox_flag + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/payflow_link/use_proxy Magento\Backend\Model\Config\Source\Yesno - - - - paypal-enabler + 1 + + + + payment/payflow_link/proxy_host + + 1 + + 1 + + + + payment/payflow_link/proxy_port + + 1 + + 1 + + + Magento\Paypal\Block\Adminhtml\System\Config\Payflowlink\Info 1 - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - It is recommended to set this value to "Debit or Credit Card" per store views. - payment/paypal_direct/title + + + payment/payflow_link/active + Magento\Backend\Model\Config\Source\Yesno + + + + paypal-enabler paypal-ec-pe paypal-payflowlink + 1 + + + + payment/payflow_express/active + Magento\Backend\Model\Config\Source\Yesno + paypal-ec-payflow-enabler + 1 + + + + + + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "Debit or Credit Card" per store views. + payment/payflow_link/title + 1 + + + + payment/payflow_link/sort_order + validate-number + 1 + + + + payment/payflow_link/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + 1 + + + + config-advanced + + + payment/payflow_link/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries 1 - - - payment/paypal_direct/sort_order - validate-number + + + payment/payflow_link/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + + 1 + 1 - - - payment/paypal_direct/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions + + + payment/payflow_link/debug + Magento\Backend\Model\Config\Source\Yesno 1 - - - Magento\Backend\Block\System\Config\Form\Field\Heading + + + payment/payflow_link/verify_peer + Magento\Backend\Model\Config\Source\Yesno 1 - - - - http://www.paypal.com/amexupdate.]]> - - payment/paypal_direct/cctypes - Magento\Paypal\Model\Config::getWppCcTypesAsOptionArray + + + payment/payflow_link/csc_editable + Magento\Backend\Model\Config\Source\Yesno 1 - - - config-advanced - - - payment/paypal_direct/allowspecific - Magento\Payment\Model\Config\Source\Allspecificcountries - 1 - - - - payment/paypal_direct/specificcountry - Magento\Paypal\Model\System\Config\Source\BuyerCountry - - 1 - - 1 - - - - payment/paypal_direct/debug - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_direct/verify_peer - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_direct/line_items_enabled - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_direct/useccv - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - Magento\Backend\Block\System\Config\Form\Field\Heading - 1 - - - - payment/paypal_direct/centinel - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_direct/centinel_is_mode_strict - Severe Validation Removes Chargeback Liability on Merchant - Magento\Backend\Model\Config\Source\Yesno - - 1 - - 1 - - - - payment/paypal_direct/centinel_api_url - If empty, a default value will be used. Custom URL may be provided by CardinalCommerce agreement. - Magento\Backend\Model\Config\Source\Yesno - - 1 - - 1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + payment/payflow_link/csc_required + Magento\Backend\Model\Config\Source\Yesno + + 1 + + 1 + + + + payment/payflow_link/email_confirmation + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/payflow_link/url_method + Magento\Paypal\Model\System\Config\Source\UrlMethod + 1 + + + + + + + + + + + + + + + + + - - + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + + + + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + pp-method-express + Add PayPal as an additional payment method to your checkout page. + payment/paypal_express/active + https://www.paypal.com/webapps/mpp/referral/paypal-express-checkout?partner_id=NB9WWHYEMVUMS + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - - - - - - - - config-advanced - - - - - - - - - - - + + + + Start accepting payments via PayPal!]]> + + Don't have a PayPal account? Simply enter your email address. + paypal/general/business_account + validate-email + 1 + + + + paypal/wpp/api_authentication + Magento\Paypal\Model\Config::getApiAuthenticationMethods + 1 + + + + paypal/wpp/api_username + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + + + paypal/wpp/api_password + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + + + paypal/wpp/api_signature + Magento\Backend\Model\Config\Backend\Encrypted + 1 + + 0 + + + + + paypal/wpp/api_cert + Magento\Paypal\Model\System\Config\Backend\Cert + 1 + + 1 + + + + Get Credentials from PayPal + + + + Sandbox Credentials + + + + Magento\Paypal\Block\Adminhtml\System\Config\ApiWizard + + + + paypal/wpp/sandbox_flag + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + paypal/wpp/use_proxy + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + paypal/wpp/proxy_host + 1 + + 1 + + + + + paypal/wpp/proxy_port + 1 + + 1 + + + + + payment/paypal_express/active + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + paypal-enabler paypal-ec-enabler + - - - pp-method-general - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - Accept credit card and PayPal payments securely. - payment/paypal_standard/active - https://www.paypal.com/webapps/mpp/referral/website-payments-standard?partner_id=NB9WWHYEMVUMS - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - payment/paypal_standard/active + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "Magento_Paypal" per store views. + payment/paypal_express/title + 1 + + + + payment/paypal_express/sort_order + validate-number + 1 + + + + payment/paypal_express/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions\Express + 1 + + + + payment/paypal_express/visible_on_cart + Also affects mini-shopping cart. + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_express/visible_on_product + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + Specifies what the Authorization Honor Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. + payment/paypal_express/authorization_honor_period + 1 + + Order + + + + + Specifies what the Order Valid Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. + payment/paypal_express/order_valid_period + 1 + + Order + + + + + The default number of child authorizations in your PayPal account is 1. To do multiple authorizations please contact PayPal to request an increase. + payment/paypal_express/child_authorization_number + 1 + + Order + + + + + config-advanced + + + payment/paypal_express/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries + 1 + + + + payment/paypal_express/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + 1 + + 1 + + + + + payment/paypal_express/debug Magento\Backend\Model\Config\Source\Yesno - - - - paypal-enabler paypal-ec-conflicts 1 - - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - It is recommended to set this value to "PayPal" per store views. - payment/paypal_standard/title + + + payment/paypal_express/verify_peer + Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/paypal_standard/sort_order - validate-number + + + payment/paypal_express/line_items_enabled + Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/paypal_standard/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions + + + payment/paypal_express/transfer_shipping_options + If this option is enabled, customer can change shipping address and shipping method on PayPal website. In live mode works via HTTPS protocol only. + Notice that PayPal can handle up to 10 shipping options. That is why Magento will transfer only first 10 cheapest shipping options if there are more than 10 available. + Magento\Backend\Model\Config\Source\Yesno 1 + + 1 + - - - config-advanced - + + + paypal/wpp/button_flavor + Magento\Paypal\Model\Config::getExpressCheckoutButtonFlavors + 1 + + + + Ability for buyer to purchase without PayPal account. + payment/paypal_express/solution_type + Magento\Paypal\Model\Config::getExpressCheckoutSolutionTypes + 1 + + + + This feature needs be enabled first for the merchant account through PayPal technical support. + payment/paypal_express/require_billing_address + Magento\Paypal\Model\System\Config\Source\RequireBillingAddress + 1 + + + + Whether to create a billing agreement, if there are no active billing agreements available. + + + + payment/paypal_express/allow_ba_signup + Magento\Paypal\Model\Config::getExpressCheckoutBASignupOptions + 1 + + + + + + + + + payment/paypal_billing_agreement/active + Magento\Backend\Model\Config\Source\Yesno + 1 + + + + payment/paypal_billing_agreement/title + 1 + + + + payment/paypal_billing_agreement/sort_order + validate-number + 1 + + + + payment/paypal_billing_agreement/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + 1 + + - payment/paypal_standard/allowspecific + payment/paypal_billing_agreement/allowspecific Magento\Payment\Model\Config\Source\Allspecificcountries 1 - + - payment/paypal_standard/specificcountry + payment/paypal_billing_agreement/specificcountry Magento\Paypal\Model\System\Config\Source\BuyerCountry + 1 1 - 1 - - - payment/paypal_standard/sandbox_flag + + + payment/paypal_billing_agreement/debug Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/paypal_standard/line_items_enabled + + + payment/paypal_billing_agreement/verify_peer Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/paypal_standard/line_items_summary - Uses store frontend name by default. - - 1 - - 1 - - - - payment/paypal_standard/debug + + + payment/paypal_billing_agreement/line_items_enabled Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/paypal_standard/verify_peer + + + payment/paypal_billing_agreement/allow_billing_agreement_wizard Magento\Backend\Model\Config\Source\Yesno 1 - - - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - pp-method-payflow - Connect your merchant account with a fully customizable gateway that lets customers pay without leaving your site. - payment/payflowpro/active - https://www.paypal.com/webapps/mpp/referral/paypal-payflow-pro?partner_id=NB9WWHYEMVUMS - 1 - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - payment/payflowpro/partner + + + + + Magento\Backend\Block\System\Config\Form\Field\Heading 1 - - - payment/payflowpro/user + + + paypal/fetch_reports/ftp_login Magento\Backend\Model\Config\Backend\Encrypted 1 - - - payment/payflowpro/vendor - 1 - - + - payment/payflowpro/pwd + paypal/fetch_reports/ftp_password Magento\Backend\Model\Config\Backend\Encrypted 1 - - - payment/payflowpro/sandbox_flag - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflowpro/use_proxy + + + paypal/fetch_reports/ftp_sandbox Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/payflowpro/proxy_host - - 1 - + + + By default it is "reports.paypal.com". + Use colon to specify port. For example: "test.example.com:5224". + paypal/fetch_reports/ftp_ip 1 - - - - payment/payflowpro/proxy_port - 1 + 0 - 1 - - - - payment/payflowpro/active - Magento\Backend\Model\Config\Source\Yesno - - - - paypal-enabler paypal-ec-separate - 1 - - - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - It is recommended to set this value to "Debit or Credit Card" per store views. - payment/payflowpro/title - 1 - - - - payment/payflowpro/sort_order - validate-number - 1 - - - - payment/payflowpro/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions - 1 - - - - Magento\Backend\Block\System\Config\Form\Field\Heading - 1 - - - - - http://www.paypal.com/amexupdate.]]> - - payment/payflowpro/cctypes - Magento\Paypal\Model\Config::getPayflowproCcTypesAsOptionArray - 1 - - - - config-advanced - - - payment/payflowpro/allowspecific - Magento\Payment\Model\Config\Source\Allspecificcountries + + + By default it is "/ppreports/outgoing". + paypal/fetch_reports/ftp_path 1 - - - - payment/payflowpro/specificcountry - Magento\Paypal\Model\System\Config\Source\BuyerCountry - 1 + 0 - 1 - - - - payment/payflowpro/debug - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflowpro/verify_peer - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflowpro/useccv - Magento\Backend\Model\Config\Source\Yesno - 1 - - + + Magento\Backend\Block\System\Config\Form\Field\Heading 1 - - - payment/payflowpro/centinel + + + paypal/fetch_reports/active Magento\Backend\Model\Config\Source\Yesno 1 - - - payment/payflowpro/centinel_is_mode_strict - Severe validation removes chargeback liability on merchant. - Magento\Backend\Model\Config\Source\Yesno - - 1 - + + + PayPal retains reports for 45 days. + paypal/fetch_reports/schedule + Magento\Paypal\Model\System\Config\Source\FetchingSchedule 1 - - - payment/payflowpro/centinel_api_url - A value is required for live mode. Refer to your CardinalCommerce agreement. - Magento\Backend\Model\Config\Source\Yesno - - 1 - + + + paypal/fetch_reports/time 1 - - - - - - - - - - - - - - - - - - 0 - - - - - - not-required - + + + - - - - - - - - - - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - payment/payflow_express/title - 1 - - - - payment/payflow_express/sort_order - validate-number - 1 - - - - payment/payflow_express/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions - 1 - - - - Also affects mini-shopping cart. - payment/payflow_express/visible_on_cart - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/payflow_express/visible_on_product - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - config-advanced - - - payment/payflow_express/allowspecific - Magento\Payment\Model\Config\Source\Allspecificcountries + + + Magento\Backend\Block\System\Config\Form\Field\Heading 1 - - - payment/payflow_express/specificcountry - Magento\Paypal\Model\System\Config\Source\BuyerCountry - - 1 - + + + paypal/style/page_style + + + 1 - - - payment/payflow_express/debug - Magento\Backend\Model\Config\Source\Yesno + + + paypal/style/paypal_hdrimg + + https is highly encouraged.]]> + 1 - - - payment/payflow_express/verify_peer - Magento\Backend\Model\Config\Source\Yesno + + + paypal/style/paypal_hdrbackcolor + + + 1 - - - payment/payflow_express/line_items_enabled - Magento\Backend\Model\Config\Source\Yesno + + + paypal/style/paypal_hdrbordercolor + 2-pixel perimeter around the header space. + 1 + + + + paypal/style/paypal_payflowcolor + + + 1 - - + + + + pp-method-general + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment + payment/hosted_pro/active + Accept payments with a PCI compliant checkout that keeps customers on your site. + 1 + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + + + + + + + + + + + + payment/hosted_pro/active + Magento\Backend\Model\Config\Source\Yesno + + + + paypal-enabler paypal-ec-separate + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + It is recommended to set this value to "PayPal" per store views. + payment/hosted_pro/title + + + + payment/hosted_pro/sort_order + validate-number + + + + payment/hosted_pro/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions + + + + payment/hosted_pro/display_ec + Magento\Backend\Model\Config\Source\Yesno + + + + config-advanced + + + payment/hosted_pro/allowspecific + Magento\Payment\Model\Config\Source\Allspecificcountries + + + + payment/hosted_pro/specificcountry + Magento\Paypal\Model\System\Config\Source\BuyerCountry + + 1 + + + + + payment/hosted_pro/debug + Magento\Backend\Model\Config\Source\Yesno + + + + payment/hosted_pro/verify_peer + Magento\Backend\Model\Config\Source\Yesno + + + + + + + + + + + + + + + + + +
+
+ + + 1 + complex + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group + Choose a secure bundled payment solution for your business. + https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup + + + + + + 1 + complex + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group + Add another payment method to your existing solution or as a stand-alone option. + https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content + + +
+
+ + + + pp-method-general Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - pp-method-payflow - Connect your merchant account with a PCI-compliant gateway that lets customers pay without leaving your site. - payment/payflow_link/active - https://www.paypal.com/webapps/mpp/referral/paypal-payflow-link?partner_id=NB9WWHYEMVUMS - + https://www.paypal.com/webapps/mpp/referral/paypal-payments-advanced?partner_id=NB9WWHYEMVUMS + Accept payments with a PCI-compliant checkout that keeps customers on your site. + payment/payflow_advanced/active + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - not-required + - 1 - + - payment/payflow_link/partner + payment/payflow_advanced/partner 1 - + - payment/payflow_link/vendor + payment/payflow_advanced/vendor 1 - + - If you do not have multiple users set up on your account, please re-enter your Vendor/Merchant Login here. - payment/payflow_link/user + PayPal recommends that you set up an additional User on your account at manager.paypal.com + PayPal recommends you set up an additional User on your account at manager.paypal.com, instead of entering your admin username and password here. This will enhance your security and prevent service interruptions if you later change your password. If you do not want to set up an additional User, you can re-enter your Merchant Login here. + payment/payflow_advanced/user 1 - + - payment/payflow_link/pwd + payment/payflow_advanced/pwd Magento\Backend\Model\Config\Backend\Encrypted 1 - + - payment/payflow_link/sandbox_flag + payment/payflow_advanced/sandbox_flag Magento\Backend\Model\Config\Source\Yesno 1 - + - payment/payflow_link/use_proxy + payment/payflow_advanced/use_proxy Magento\Backend\Model\Config\Source\Yesno 1 - + - payment/payflow_link/proxy_host + payment/payflow_advanced/proxy_host 1 1 - + - payment/payflow_link/proxy_port + payment/payflow_advanced/proxy_port 1 1 - - Magento\Paypal\Block\Adminhtml\System\Config\Payflowlink\Info + + Magento\Paypal\Block\Adminhtml\System\Config\Payflowlink\Advanced 1 - - - payment/payflow_link/active + + + payment/payflow_advanced/active Magento\Backend\Model\Config\Source\Yesno - + - paypal-enabler paypal-ec-pe paypal-payflowlink + paypal-enabler paypal-ec-pe paypal-payflow-advanced 1 - - - payment/payflow_express/active - Magento\Backend\Model\Config\Source\Yesno - paypal-ec-payflow-enabler - 1 + + Magento\Paypal\Block\Adminhtml\System\Config\Field\Hidden - + - - + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded It is recommended to set this value to "Debit or Credit Card" per store views. - payment/payflow_link/title + payment/payflow_advanced/title 1 - payment/payflow_link/sort_order + payment/payflow_advanced/sort_order validate-number 1 - payment/payflow_link/payment_action + payment/payflow_advanced/payment_action Magento\Paypal\Model\System\Config\Source\PaymentActions 1 - + config-advanced - + - payment/payflow_link/allowspecific + payment/payflow_advanced/allowspecific Magento\Payment\Model\Config\Source\Allspecificcountries 1 - + - payment/payflow_link/specificcountry + payment/payflow_advanced/specificcountry Magento\Paypal\Model\System\Config\Source\BuyerCountry 1 @@ -1029,25 +1452,25 @@ - payment/payflow_link/debug + payment/payflow_advanced/debug Magento\Backend\Model\Config\Source\Yesno 1 - payment/payflow_link/verify_peer + payment/payflow_advanced/verify_peer Magento\Backend\Model\Config\Source\Yesno 1 - payment/payflow_link/csc_editable + payment/payflow_advanced/csc_editable Magento\Backend\Model\Config\Source\Yesno 1 - payment/payflow_link/csc_required + payment/payflow_advanced/csc_required Magento\Backend\Model\Config\Source\Yesno 1 @@ -1056,495 +1479,368 @@ - payment/payflow_link/email_confirmation + payment/payflow_advanced/email_confirmation Magento\Backend\Model\Config\Source\Yesno 1 - payment/payflow_link/url_method + payment/payflow_advanced/url_method Magento\Paypal\Model\System\Config\Source\UrlMethod 1 - + - - - - - - - - - - + + + + + + + + + + - + - - + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - - - + + + + + + - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment - pp-method-express - Add PayPal as an additional payment method to your checkout page. - payment/paypal_express/active - https://www.paypal.com/webapps/mpp/referral/paypal-express-checkout?partner_id=NB9WWHYEMVUMS - + + + + + + + + + + + + + + + + + + + + + complex + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group + Process payments using your own internet merchant account. + https://merchant.paypal.com/cgi-bin/marketingweb?cmd=_render-content + + + + 0 + - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - - - - Start accepting payments via PayPal!]]> - - Don't have a PayPal account? Simply enter your email address. - paypal/general/business_account - validate-email - 1 - - - - paypal/wpp/api_authentication - Magento\Paypal\Model\Config::getApiAuthenticationMethods - 1 - - - - paypal/wpp/api_username - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - - - paypal/wpp/api_password - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - - - paypal/wpp/api_signature - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - 0 - - - - - paypal/wpp/api_cert - Magento\Paypal\Model\System\Config\Backend\Cert - 1 - - 1 - - - - Get Credentials from PayPal - - - - Sandbox Credentials - - - - Magento\Paypal\Block\Adminhtml\System\Config\ApiWizard - - - - paypal/wpp/sandbox_flag - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - paypal/wpp/use_proxy - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - paypal/wpp/proxy_host - 1 - - 1 - - - - - paypal/wpp/proxy_port + + paypal-enabler paypal-ec-pe + + + + + not-required + 1 - - 1 - - - - payment/paypal_express/active - Magento\Backend\Model\Config\Source\Yesno - 1 + + Magento\Paypal\Block\Adminhtml\System\Config\Field\Hidden - + - paypal-enabler paypal-ec-enabler - + + + + + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded - + - It is recommended to set this value to "Magento_Paypal" per store views. - payment/paypal_express/title + payment/payflow_express/title 1 - payment/paypal_express/sort_order + payment/payflow_express/sort_order validate-number 1 - payment/paypal_express/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions\Express + payment/payflow_express/payment_action + Magento\Paypal\Model\System\Config\Source\PaymentActions 1 - + - payment/paypal_express/visible_on_cart Also affects mini-shopping cart. + payment/payflow_express/visible_on_cart Magento\Backend\Model\Config\Source\Yesno 1 - + - payment/paypal_express/visible_on_product + payment/payflow_express/visible_on_product Magento\Backend\Model\Config\Source\Yesno 1 - - - Specifies what the Authorization Honor Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. - payment/paypal_express/authorization_honor_period - 1 - - Order - - - - - Specifies what the Order Valid Period is on the merchant’s PayPal account. It must mirror the setting in PayPal. - payment/paypal_express/order_valid_period - 1 - - Order - - - - - The default number of child authorizations in your PayPal account is 1. To do multiple authorizations please contact PayPal to request an increase. - payment/paypal_express/child_authorization_number - 1 - - Order - - - + config-advanced - payment/paypal_express/allowspecific + payment/payflow_express/allowspecific Magento\Payment\Model\Config\Source\Allspecificcountries 1 - payment/paypal_express/specificcountry + payment/payflow_express/specificcountry Magento\Paypal\Model\System\Config\Source\BuyerCountry - 1 1 + 1 - payment/paypal_express/debug + payment/payflow_express/debug Magento\Backend\Model\Config\Source\Yesno 1 - payment/paypal_express/verify_peer + payment/payflow_express/verify_peer Magento\Backend\Model\Config\Source\Yesno 1 - payment/paypal_express/line_items_enabled - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_express/transfer_shipping_options - If this option is enabled, customer can change shipping address and shipping method on PayPal website. In live mode works via HTTPS protocol only. - Notice that PayPal can handle up to 10 shipping options. That is why Magento will transfer only first 10 cheapest shipping options if there are more than 10 available. + payment/payflow_express/line_items_enabled Magento\Backend\Model\Config\Source\Yesno 1 - - 1 - - - - - paypal/wpp/button_flavor - Magento\Paypal\Model\Config::getExpressCheckoutButtonFlavors - 1 - - - - Ability for buyer to purchase without PayPal account. - payment/paypal_express/solution_type - Magento\Paypal\Model\Config::getExpressCheckoutSolutionTypes - 1 - - - - This feature needs be enabled first for the merchant account through PayPal technical support. - payment/paypal_express/require_billing_address - Magento\Paypal\Model\System\Config\Source\RequireBillingAddress - 1 - - - - Whether to create a billing agreement, if there are no active billing agreements available. - - - - payment/paypal_express/allow_ba_signup - Magento\Paypal\Model\Config::getExpressCheckoutBASignupOptions - 1 - + + + + + + + payment/payflow_express/active + + +
+
+ + + pp-general-uk + https://www.paypal-business.co.uk/accept-online-payments-with-paypal/index.htm + http://www.youtube.com/watch?v=mdPjvziH_rk&list=PLF18B1094ABCD7CE8&index=6&feature=plpp_video + Accept credit cards, debit cards and PayPal payments securely. + + + pp-general-uk + https://www.paypal-business.co.uk/process-online-payments-with-paypal/index.htm + http://www.youtube.com/watch?v=LBe-TW87eGI&list=PLF18B1094ABCD7CE8&index=1&feature=plpp_video + Accept payments with a completely customizable checkout page. + + + + pp-general-uk + https://cms.paypal.com/cms_content/GB/en_GB/files/developer/HostedSolution.pdf + 0 + + + + + + paypal-enabler + + + + + + - - - - - - payment/paypal_billing_agreement/active - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_billing_agreement/title - 1 - - - - payment/paypal_billing_agreement/sort_order - validate-number - 1 - - - - payment/paypal_billing_agreement/payment_action - Magento\Paypal\Model\System\Config\Source\PaymentActions - 1 - - - - payment/paypal_billing_agreement/allowspecific - Magento\Payment\Model\Config\Source\Allspecificcountries - 1 - - - - payment/paypal_billing_agreement/specificcountry - Magento\Paypal\Model\System\Config\Source\BuyerCountry - 1 - - 1 - - - - - payment/paypal_billing_agreement/debug - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_billing_agreement/verify_peer - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_billing_agreement/line_items_enabled - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - payment/paypal_billing_agreement/allow_billing_agreement_wizard - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - - - - Magento\Backend\Block\System\Config\Form\Field\Heading - 1 - - - - paypal/fetch_reports/ftp_login - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - - - paypal/fetch_reports/ftp_password - Magento\Backend\Model\Config\Backend\Encrypted - 1 - - - - paypal/fetch_reports/ftp_sandbox - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - By default it is "reports.paypal.com". - Use colon to specify port. For example: "test.example.com:5224". - paypal/fetch_reports/ftp_ip - 1 - - 0 - - - - - By default it is "/ppreports/outgoing". - paypal/fetch_reports/ftp_path - 1 - - 0 - - - - - Magento\Backend\Block\System\Config\Form\Field\Heading - 1 - - - - paypal/fetch_reports/active - Magento\Backend\Model\Config\Source\Yesno - 1 - - - - PayPal retains reports for 45 days. - paypal/fetch_reports/schedule - Magento\Paypal\Model\System\Config\Source\FetchingSchedule - 1 - - - - paypal/fetch_reports/time - 1 - + + + + + + + + + + - + - - - - Magento\Backend\Block\System\Config\Form\Field\Heading - 1 - - - - paypal/style/page_style - - - - 1 - - - - paypal/style/paypal_hdrimg - - https is highly encouraged.]]> - - 1 - - - - paypal/style/paypal_hdrbackcolor - - - - 1 - - - - paypal/style/paypal_hdrbordercolor - 2-pixel perimeter around the header space. - 1 - - - - paypal/style/paypal_payflowcolor - - - - 1 - + + + + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Expanded + + + + + + + + + + + config-advanced + + + + + + + + + + + + + + +
+
+ + + 1 + complex + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group + Add another payment method to your existing solution or as a stand-alone option. + https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup + + +
+
+ + + 1 + complex + Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group + Add another payment method to your existing solution or as a stand-alone option. + https://www.paypal-marketing.com/emarketing/partner/na/merchantlineup/home.page#mainTab=checkoutlineup&subTab=newlineup + + + +
+
+ + + + payment/payflow_express/active + + + + + +
+
+ + + + + + +
+
+ + + + + + + +
+
+ + + + + + + +
+
+ + + + + + + +
+
+ + + + +
+
+ + + + + +
+
+ + + + + +
diff --git a/app/code/Magento/Paypal/etc/config.xml b/app/code/Magento/Paypal/etc/config.xml index 95c0ec9730e0d..6202193ac0097 100644 --- a/app/code/Magento/Paypal/etc/config.xml +++ b/app/code/Magento/Paypal/etc/config.xml @@ -89,15 +89,6 @@ 1 Magento\Paypal\Model\PayflowExpress - - PayPal Direct Payment Payflow Edition - Authorization - VI,MC,AE - 1 - paypal - 1 - Magento\Paypal\Model\PayflowDirect - Magento\Paypal\Model\Payflowpro Payflow Pro diff --git a/app/code/Magento/Paypal/etc/di.xml b/app/code/Magento/Paypal/etc/di.xml index 902cae04b2a1a..e9488eaa55119 100644 --- a/app/code/Magento/Paypal/etc/di.xml +++ b/app/code/Magento/Paypal/etc/di.xml @@ -41,4 +41,14 @@ Magento\Paypal\Model\PayflowadvancedFactory + + + Magento\Paypal\Model\Payflow\Pro + + + + + Magento\Paypal\Model\Payflow\ProFactory + + diff --git a/app/code/Magento/Paypal/etc/payment.xml b/app/code/Magento/Paypal/etc/payment.xml index 8fc4bafa67008..ca6074525cba3 100644 --- a/app/code/Magento/Paypal/etc/payment.xml +++ b/app/code/Magento/Paypal/etc/payment.xml @@ -52,10 +52,6 @@ 1 1 - - 1 - 1 - 1 1 diff --git a/app/code/Magento/Paypal/view/adminhtml/templates/system/config/fieldset/store.phtml b/app/code/Magento/Paypal/view/adminhtml/templates/system/config/fieldset/store.phtml deleted file mode 100644 index 6f45512aeaaac..0000000000000 --- a/app/code/Magento/Paypal/view/adminhtml/templates/system/config/fieldset/store.phtml +++ /dev/null @@ -1,99 +0,0 @@ - - - diff --git a/app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php b/app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php index e90c97ed33bdc..a72226942f212 100644 --- a/app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php +++ b/app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php @@ -44,6 +44,36 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template */ protected $_store; + /** + * @var \Magento\Framework\Filter\Input\MaliciousCode + */ + protected $_maliciousCode; + + /** + * @param \Magento\Framework\View\Element\Template\Context $context + * @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode + * @param array $data + */ + public function __construct( + \Magento\Framework\View\Element\Template\Context $context, + \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode, + array $data = array() + ) { + $this->_maliciousCode = $maliciousCode; + parent::__construct($context, $data); + } + + /** + * Filter malicious code before insert content to email + * + * @param string|array $content + * @return string|array + */ + public function getFilteredContent($content) + { + return $this->_maliciousCode->filter($content); + } + /** * Set Store scope * diff --git a/app/code/Magento/ProductAlert/Block/Email/Stock.php b/app/code/Magento/ProductAlert/Block/Email/Stock.php index 6af99158c287f..f7bd8da4ba51f 100644 --- a/app/code/Magento/ProductAlert/Block/Email/Stock.php +++ b/app/code/Magento/ProductAlert/Block/Email/Stock.php @@ -43,15 +43,17 @@ class Stock extends \Magento\ProductAlert\Block\Email\AbstractEmail /** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Catalog\Helper\Image $imageHelper + * @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, + \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode, \Magento\Catalog\Helper\Image $imageHelper, array $data = array() ) { $this->_imageHelper = $imageHelper; - parent::__construct($context, $data); + parent::__construct($context, $maliciousCode, $data); } /** diff --git a/app/code/Magento/ProductAlert/view/frontend/templates/email/price.phtml b/app/code/Magento/ProductAlert/view/frontend/templates/email/price.phtml index 048411bd3e0e1..aa7fac0b397c4 100644 --- a/app/code/Magento/ProductAlert/view/frontend/templates/email/price.phtml +++ b/app/code/Magento/ProductAlert/view/frontend/templates/email/price.phtml @@ -41,7 +41,7 @@ escapeHtml($_product->getName()) ?>

- escapeHtml($_product->getShortDescription())): ?> + getFilteredContent($_product->getShortDescription())): ?>

getProductPriceHtml( diff --git a/app/code/Magento/ProductAlert/view/frontend/templates/email/stock.phtml b/app/code/Magento/ProductAlert/view/frontend/templates/email/stock.phtml index ae83ff32a6658..16c740ec320b3 100644 --- a/app/code/Magento/ProductAlert/view/frontend/templates/email/stock.phtml +++ b/app/code/Magento/ProductAlert/view/frontend/templates/email/stock.phtml @@ -40,7 +40,7 @@ escapeHtml($_product->getName()) ?>

- escapeHtml($_product->getShortDescription())): ?> + getFilteredContent($_product->getShortDescription())): ?>

getProductPriceHtml( diff --git a/app/code/Magento/RecurringPayment/sql/recurringpayment_setup/install-1.0.0.0.php b/app/code/Magento/RecurringPayment/sql/recurringpayment_setup/install-1.0.0.0.php index 83926d8912965..b89f2cae73a38 100644 --- a/app/code/Magento/RecurringPayment/sql/recurringpayment_setup/install-1.0.0.0.php +++ b/app/code/Magento/RecurringPayment/sql/recurringpayment_setup/install-1.0.0.0.php @@ -314,3 +314,4 @@ $this->getConnection()->createTable($table); $this->installEntities(); +$this->endSetup(); diff --git a/app/code/Magento/Review/Controller/Adminhtml/Product.php b/app/code/Magento/Review/Controller/Adminhtml/Product.php index 6bf8b0735e508..e2877ab095828 100644 --- a/app/code/Magento/Review/Controller/Adminhtml/Product.php +++ b/app/code/Magento/Review/Controller/Adminhtml/Product.php @@ -42,13 +42,35 @@ class Product extends \Magento\Backend\App\Action */ protected $_coreRegistry = null; + /** + * Review model factory + * + * @var \Magento\Review\Model\ReviewFactory + */ + protected $_reviewFactory; + + /** + * Rating model factory + * + * @var \Magento\Review\Model\RatingFactory + */ + protected $_ratingFactory; + /** * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Review\Model\ReviewFactory $reviewFactory + * @param \Magento\Review\Model\RatingFactory $ratingFactory */ - public function __construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry) - { + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Review\Model\ReviewFactory $reviewFactory, + \Magento\Review\Model\RatingFactory $ratingFactory + ) { $this->_coreRegistry = $coreRegistry; + $this->_reviewFactory = $reviewFactory; + $this->_ratingFactory = $ratingFactory; parent::__construct($context); } @@ -138,7 +160,7 @@ public function newAction() public function saveAction() { if (($data = $this->getRequest()->getPost()) && ($reviewId = $this->getRequest()->getParam('id'))) { - $review = $this->_objectManager->create('Magento\Review\Model\Review')->load($reviewId); + $review = $this->_reviewFactory->create()->load($reviewId); if (!$review->getId()) { $this->messageManager->addError(__('The review was removed by another user or does not exist.')); } else { @@ -153,8 +175,7 @@ public function saveAction() )->addOptionInfo()->load()->addRatingOptions(); foreach ($arrRatingId as $ratingId => $optionId) { if ($vote = $votes->getItemByColumnValue('rating_id', $ratingId)) { - $this->_objectManager->create( - 'Magento\Review\Model\Rating' + $this->_ratingFactory->create( )->setVoteId( $vote->getId() )->setReviewId( @@ -163,8 +184,7 @@ public function saveAction() $optionId ); } else { - $this->_objectManager->create( - 'Magento\Review\Model\Rating' + $this->_ratingFactory->create( )->setRatingId( $ratingId )->setReviewId( @@ -203,7 +223,7 @@ public function deleteAction() { $reviewId = $this->getRequest()->getParam('id', false); try { - $this->_objectManager->create('Magento\Review\Model\Review')->setId($reviewId)->aggregate()->delete(); + $this->_reviewFactory->create()->setId($reviewId)->aggregate()->delete(); $this->messageManager->addSuccess(__('The review has been deleted.')); if ($this->getRequest()->getParam('ret') == 'pending') { @@ -233,7 +253,7 @@ public function massDeleteAction() } else { try { foreach ($reviewsIds as $reviewId) { - $model = $this->_objectManager->create('Magento\Review\Model\Review')->load($reviewId); + $model = $this->_reviewFactory->create()->load($reviewId); $model->delete(); } $this->messageManager->addSuccess( @@ -261,7 +281,7 @@ public function massUpdateStatusAction() try { $status = $this->getRequest()->getParam('status'); foreach ($reviewsIds as $reviewId) { - $model = $this->_objectManager->create('Magento\Review\Model\Review')->load($reviewId); + $model = $this->_reviewFactory->create()->load($reviewId); $model->setStatusId($status)->save()->aggregate(); } $this->messageManager->addSuccess( @@ -293,7 +313,7 @@ public function massVisibleInAction() try { $stores = $this->getRequest()->getParam('stores'); foreach ($reviewsIds as $reviewId) { - $model = $this->_objectManager->create('Magento\Review\Model\Review')->load($reviewId); + $model = $this->_reviewFactory->create()->load($reviewId); $model->setSelectStores($stores); $model->save(); } @@ -361,30 +381,29 @@ public function postAction() $productId = $this->getRequest()->getParam('product_id', false); if ($data = $this->getRequest()->getPost()) { - if ($this->_objectManager->get('Magento\Store\Model\StoreManagerInterface')->hasSingleStore()) { + /** @var \Magento\Store\Model\StoreManagerInterface $storeManagerInterface */ + $storeManager = $this->_objectManager->get('Magento\Store\Model\StoreManagerInterface'); + if ($storeManager->hasSingleStore()) { $data['stores'] = array( - $this->_objectManager->get('Magento\Store\Model\StoreManager')->getStore(true)->getId() + $storeManager->getStore(true)->getId() ); } elseif (isset($data['select_stores'])) { $data['stores'] = $data['select_stores']; } - $review = $this->_objectManager->create('Magento\Review\Model\Review')->setData($data); - - $product = $this->_objectManager->create('Magento\Catalog\Model\Product')->load($productId); + $review = $this->_reviewFactory->create()->setData($data); try { $review->setEntityId(1) // product ->setEntityPkValue($productId) - ->setStoreId($product->getStoreId()) + ->setStoreId(\Magento\Store\Model\Store::DEFAULT_STORE_ID) ->setStatusId($data['status_id']) ->setCustomerId(null)//null is for administrator only ->save(); $arrRatingId = $this->getRequest()->getParam('ratings', array()); foreach ($arrRatingId as $ratingId => $optionId) { - $this->_objectManager->create( - 'Magento\Review\Model\Rating' + $this->_ratingFactory->create( )->setRatingId( $ratingId )->setReviewId( diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar.php index 65b0c1da6cc40..b005aacc65b63 100644 --- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar.php +++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Sidebar.php @@ -67,7 +67,7 @@ protected function _prepareLayout() */ public function canDisplay($child) { - if (method_exists($child, 'canDisplay')) { + if (method_exists($child, 'canDisplay') && is_callable([$child, 'canDisplay'])) { return $child->canDisplay(); } return true; diff --git a/app/code/Magento/Sales/Block/Order/Link.php b/app/code/Magento/Sales/Block/Order/Link.php index a048cf2fad9ad..9e4903979c261 100644 --- a/app/code/Magento/Sales/Block/Order/Link.php +++ b/app/code/Magento/Sales/Block/Order/Link.php @@ -74,10 +74,9 @@ public function getHref() */ protected function _toHtml() { - if ($this->hasKey() && method_exists( - $this->getOrder(), - 'has' . $this->getKey() - ) && !$this->getOrder()->{'has' . $this->getKey()}() + if ($this->hasKey() + && method_exists($this->getOrder(), 'has' . $this->getKey()) + && !$this->getOrder()->{'has' . $this->getKey()}() ) { return ''; } diff --git a/app/code/Magento/Sales/Block/Order/Totals.php b/app/code/Magento/Sales/Block/Order/Totals.php index 9b88f2b376426..fd661ba9d9d95 100644 --- a/app/code/Magento/Sales/Block/Order/Totals.php +++ b/app/code/Magento/Sales/Block/Order/Totals.php @@ -72,7 +72,7 @@ protected function _beforeToHtml() { $this->_initTotals(); foreach ($this->getLayout()->getChildBlocks($this->getNameInLayout()) as $child) { - if (method_exists($child, 'initTotals')) { + if (method_exists($child, 'initTotals') && is_callable([$child, 'initTotals'])) { $child->initTotals(); } } diff --git a/app/code/Magento/Sales/Helper/Quote/Item/Compare.php b/app/code/Magento/Sales/Helper/Quote/Item/Compare.php new file mode 100644 index 0000000000000..bb665aa5baf5d --- /dev/null +++ b/app/code/Magento/Sales/Helper/Quote/Item/Compare.php @@ -0,0 +1,89 @@ +getProductId() != $compared->getProductId()) { + return false; + } + $targetOptions = $this->getOptions($target); + $comparedOptions = $this->getOptions($compared); + + if (array_diff_key($targetOptions, $comparedOptions) != array_diff_key($comparedOptions, $targetOptions) + ) { + return false; + } + foreach ($targetOptions as $name => $value) { + if ($comparedOptions[$name] != $value) { + return false; + } + } + return true; + } + + /** + * Returns options adopted to compare + * + * @param Item $item + * @return array + */ + public function getOptions(Item $item) + { + $options = []; + foreach ($item->getOptions() as $option) { + $options[$option->getCode()] = $this->getOptionValues($option->getValue()); + } + return $options; + } +} diff --git a/app/code/Magento/Sales/Model/AdminOrder/Create.php b/app/code/Magento/Sales/Model/AdminOrder/Create.php index f285b0b142296..4ce2ec237a056 100644 --- a/app/code/Magento/Sales/Model/AdminOrder/Create.php +++ b/app/code/Magento/Sales/Model/AdminOrder/Create.php @@ -440,10 +440,8 @@ public function initFromOrder(\Magento\Sales\Model\Order $order) $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription()); $paymentData = $order->getPayment()->getData(); - if ('ccsave' !== $paymentData['method']) { - unset($paymentData['cc_type'], $paymentData['cc_last4']); - unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']); - } + unset($paymentData['cc_type'], $paymentData['cc_last4']); + unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']); $quote->getPayment()->addData($paymentData); $orderCouponCode = $order->getCouponCode(); diff --git a/app/code/Magento/Sales/Model/Payment/Method/Converter.php b/app/code/Magento/Sales/Model/Payment/Method/Converter.php deleted file mode 100644 index 7293a5da804f8..0000000000000 --- a/app/code/Magento/Sales/Model/Payment/Method/Converter.php +++ /dev/null @@ -1,106 +0,0 @@ - - */ -namespace Magento\Sales\Model\Payment\Method; - -class Converter -{ - /** - * List of fields that has to be encrypted - * Format: method_name => array(field1, field2, ... ) - * - * @var array - */ - protected $_encryptFields = array( - 'ccsave' => array('cc_owner' => true, 'cc_exp_year' => true, 'cc_exp_month' => true) - ); - - /** - * @var \Magento\Framework\Encryption\EncryptorInterface - */ - protected $_encryptor; - - /** - * @param \Magento\Framework\Encryption\EncryptorInterface $encryptor - */ - public function __construct(\Magento\Framework\Encryption\EncryptorInterface $encryptor) - { - $this->_encryptor = $encryptor; - } - - /** - * Check if specified field is encrypted - * - * @param \Magento\Framework\Model\AbstractModel $object - * @param string $filedName - * @return bool - */ - protected function _shouldBeEncrypted(\Magento\Framework\Model\AbstractModel $object, $filedName) - { - $method = $object->getData('method'); - return isset($this->_encryptFields[$method][$filedName]) && $this->_encryptFields[$method][$filedName]; - } - - /** - * Decode data - * - * @param \Magento\Framework\Model\AbstractModel $object - * @param string $filedName - * @return mixed - */ - public function decode(\Magento\Framework\Model\AbstractModel $object, $filedName) - { - $value = $object->getData($filedName); - - if ($this->_shouldBeEncrypted($object, $filedName)) { - $value = $this->_encryptor->decrypt($value); - } - - return $value; - } - - /** - * Encode data - * - * @param \Magento\Framework\Model\AbstractModel $object - * @param string $filedName - * @return mixed - */ - public function encode(\Magento\Framework\Model\AbstractModel $object, $filedName) - { - $value = $object->getData($filedName); - - if ($this->_shouldBeEncrypted($object, $filedName)) { - $value = $this->_encryptor->encrypt($value); - } - - return $value; - } -} diff --git a/app/code/Magento/Sales/Model/Quote/Item.php b/app/code/Magento/Sales/Model/Quote/Item.php index 4dea22c070c23..557efea73a522 100644 --- a/app/code/Magento/Sales/Model/Quote/Item.php +++ b/app/code/Magento/Sales/Model/Quote/Item.php @@ -197,13 +197,19 @@ class Item extends \Magento\Sales\Model\Quote\Item\AbstractItem */ protected $_itemOptionFactory; + /** + * @var \Magento\Sales\Helper\Quote\Item\Compare + */ + protected $_compareHelper; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Catalog\Model\ProductFactory $productFactory * @param \Magento\Sales\Model\Status\ListFactory $statusListFactory * @param \Magento\Framework\Locale\FormatInterface $localeFormat - * @param \Magento\Sales\Model\Quote\Item\OptionFactory $itemOptionFactory + * @param Item\OptionFactory $itemOptionFactory + * @param \Magento\Sales\Helper\Quote\Item\Compare $compareHelper * @param \Magento\Framework\Model\Resource\AbstractResource $resource * @param \Magento\Framework\Data\Collection\Db $resourceCollection * @param array $data @@ -217,6 +223,7 @@ public function __construct( \Magento\Sales\Model\Status\ListFactory $statusListFactory, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Sales\Model\Quote\Item\OptionFactory $itemOptionFactory, + \Magento\Sales\Helper\Quote\Item\Compare $compareHelper, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\Db $resourceCollection = null, array $data = array() @@ -224,6 +231,7 @@ public function __construct( $this->_errorInfos = $statusListFactory->create(); $this->_localeFormat = $localeFormat; $this->_itemOptionFactory = $itemOptionFactory; + $this->_compareHelper = $compareHelper; parent::__construct($context, $registry, $productFactory, $resource, $resourceCollection, $data); } @@ -504,46 +512,14 @@ public function compareOptions($options1, $options2) } /** - * Compare item + * Compare items * * @param \Magento\Sales\Model\Quote\Item $item * @return bool */ public function compare($item) { - if ($this->getProductId() != $item->getProductId()) { - return false; - } - foreach ($this->getOptions() as $option) { - if (in_array($option->getCode(), $this->_notRepresentOptions)) { - continue; - } - $itemOption = $item->getOptionByCode($option->getCode()); - if ($itemOption) { - $itemOptionValue = $itemOption->getValue(); - $optionValue = $option->getValue(); - - // dispose of some options params, that can cramp comparing of arrays - if (is_string($itemOptionValue) && is_string($optionValue)) { - $_itemOptionValue = @unserialize($itemOptionValue); - $_optionValue = @unserialize($optionValue); - if (is_array($_itemOptionValue) && is_array($_optionValue)) { - $itemOptionValue = $_itemOptionValue; - $optionValue = $_optionValue; - // looks like it does not break bundle selection qty - unset($itemOptionValue['qty'], $itemOptionValue['uenc']); - unset($optionValue['qty'], $optionValue['uenc']); - } - } - - if ($itemOptionValue != $optionValue) { - return false; - } - } else { - return false; - } - } - return true; + return $this->_compareHelper->compare($this, $item); } /** @@ -609,7 +585,7 @@ public function setOptions($options) /** * Get all item options * - * @return array + * @return \Magento\Sales\Model\Quote\Item\Option[] */ public function getOptions() { diff --git a/app/code/Magento/Sales/Model/Resource/AbstractResource.php b/app/code/Magento/Sales/Model/Resource/AbstractResource.php index ed229cee4cc2e..379b55361c53b 100644 --- a/app/code/Magento/Sales/Model/Resource/AbstractResource.php +++ b/app/code/Magento/Sales/Model/Resource/AbstractResource.php @@ -30,13 +30,6 @@ */ abstract class AbstractResource extends \Magento\Framework\Model\Resource\Db\AbstractDb { - /** - * Data converter object - * - * @var \Magento\Sales\Model\ConverterInterface - */ - protected $_converter = null; - /** * @var \Magento\Framework\Stdlib\DateTime */ @@ -68,64 +61,4 @@ protected function _prepareDataForSave(\Magento\Framework\Model\AbstractModel $o $data = parent::_prepareDataForSave($object); return $data; } - - /** - * Check if current model data should be converted - * - * @return bool - */ - protected function _shouldBeConverted() - { - return null !== $this->_converter; - } - - /** - * Perform actions before object save - * - * @param \Magento\Framework\Model\AbstractModel $object - * @return $this - */ - protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) - { - parent::_beforeSave($object); - - if (true == $this->_shouldBeConverted()) { - foreach ($object->getData() as $fieldName => $fieldValue) { - $object->setData($fieldName, $this->_converter->encode($object, $fieldName)); - } - } - return $this; - } - - /** - * Perform actions after object save - * - * @param \Magento\Framework\Model\AbstractModel $object - * @return $this - */ - protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) - { - if (true == $this->_shouldBeConverted()) { - foreach ($object->getData() as $fieldName => $fieldValue) { - $object->setData($fieldName, $this->_converter->decode($object, $fieldName)); - } - } - return parent::_afterSave($object); - } - - /** - * Perform actions after object load - * - * @param \Magento\Framework\Model\AbstractModel $object - * @return $this - */ - protected function _afterLoad(\Magento\Framework\Model\AbstractModel $object) - { - if (true == $this->_shouldBeConverted()) { - foreach ($object->getData() as $fieldName => $fieldValue) { - $object->setData($fieldName, $this->_converter->decode($object, $fieldName)); - } - } - return parent::_afterLoad($object); - } } diff --git a/app/code/Magento/Sales/Model/Resource/Order/Payment.php b/app/code/Magento/Sales/Model/Resource/Order/Payment.php index d87e40ca9eb12..b95ce67d42b74 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Payment.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Payment.php @@ -42,26 +42,18 @@ class Payment extends AbstractOrder */ protected $_eventPrefix = 'sales_order_payment_resource'; - /** - * @var \Magento\Sales\Model\Payment\Method\Converter - */ - protected $_paymentConverter; - /** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Framework\Stdlib\DateTime $dateTime * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Eav\Model\Entity\TypeFactory $eavEntityTypeFactory - * @param \Magento\Sales\Model\Payment\Method\Converter $paymentConverter */ public function __construct( \Magento\Framework\App\Resource $resource, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Eav\Model\Entity\TypeFactory $eavEntityTypeFactory, - \Magento\Sales\Model\Payment\Method\Converter $paymentConverter + \Magento\Eav\Model\Entity\TypeFactory $eavEntityTypeFactory ) { - $this->_paymentConverter = $paymentConverter; parent::__construct($resource, $dateTime, $eventManager, $eavEntityTypeFactory); } @@ -72,7 +64,6 @@ public function __construct( */ protected function _construct() { - $this->_converter = $this->_paymentConverter; $this->_init('sales_flat_order_payment', 'entity_id'); } } diff --git a/app/code/Magento/Sales/Model/Resource/Order/Payment/Collection.php b/app/code/Magento/Sales/Model/Resource/Order/Payment/Collection.php index 49d7984a31dba..1ed4e3da4b984 100644 --- a/app/code/Magento/Sales/Model/Resource/Order/Payment/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Order/Payment/Collection.php @@ -42,17 +42,11 @@ class Collection extends \Magento\Sales\Model\Resource\Order\Collection\Abstract */ protected $_eventObject = 'order_payment_collection'; - /** - * @var \Magento\Sales\Model\Payment\Method\Converter - */ - protected $_converter; - /** * @param \Magento\Core\Model\EntityFactory $entityFactory * @param \Magento\Framework\Logger $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Sales\Model\Payment\Method\Converter $converter * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ @@ -61,11 +55,9 @@ public function __construct( \Magento\Framework\Logger $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Sales\Model\Payment\Method\Converter $converter, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { - $this->_converter = $converter; parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } @@ -89,14 +81,6 @@ protected function _afterLoad() foreach ($this->_items as $item) { $this->getResource()->unserializeFields($item); } - - /** @var \Magento\Sales\Model\Order\Payment $item */ - foreach ($this->_items as $item) { - foreach ($item->getData() as $fieldName => $fieldValue) { - $item->setData($fieldName, $this->_converter->decode($item, $fieldName)); - } - } - return parent::_afterLoad(); } } diff --git a/app/code/Magento/Sales/Model/Resource/Quote/Payment.php b/app/code/Magento/Sales/Model/Resource/Quote/Payment.php index d36451baca400..22b0d7282e224 100644 --- a/app/code/Magento/Sales/Model/Resource/Quote/Payment.php +++ b/app/code/Magento/Sales/Model/Resource/Quote/Payment.php @@ -35,22 +35,14 @@ class Payment extends \Magento\Sales\Model\Resource\AbstractResource */ protected $_serializableFields = array('additional_information' => array(null, array())); - /** - * @var \Magento\Sales\Model\Payment\Method\Converter - */ - protected $_paymentConverter; - /** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Framework\Stdlib\DateTime $dateTime - * @param \Magento\Sales\Model\Payment\Method\Converter $paymentConverter */ public function __construct( \Magento\Framework\App\Resource $resource, - \Magento\Framework\Stdlib\DateTime $dateTime, - \Magento\Sales\Model\Payment\Method\Converter $paymentConverter + \Magento\Framework\Stdlib\DateTime $dateTime ) { - $this->_paymentConverter = $paymentConverter; parent::__construct($resource, $dateTime); } @@ -61,7 +53,6 @@ public function __construct( */ protected function _construct() { - $this->_converter = $this->_paymentConverter; $this->_init('sales_flat_quote_payment', 'payment_id'); } } diff --git a/app/code/Magento/Sales/Model/Resource/Quote/Payment/Collection.php b/app/code/Magento/Sales/Model/Resource/Quote/Payment/Collection.php index 0f8e74a47c435..2b4d468396ba0 100644 --- a/app/code/Magento/Sales/Model/Resource/Quote/Payment/Collection.php +++ b/app/code/Magento/Sales/Model/Resource/Quote/Payment/Collection.php @@ -28,17 +28,11 @@ */ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection { - /** - * @var \Magento\Sales\Model\Payment\Method\Converter - */ - protected $_converter; - /** * @param \Magento\Core\Model\EntityFactory $entityFactory * @param \Magento\Framework\Logger $logger * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Sales\Model\Payment\Method\Converter $converter * @param \Zend_Db_Adapter_Abstract $connection * @param \Magento\Framework\Model\Resource\Db\AbstractDb $resource */ @@ -47,12 +41,10 @@ public function __construct( \Magento\Framework\Logger $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Sales\Model\Payment\Method\Converter $converter, $connection = null, \Magento\Framework\Model\Resource\Db\AbstractDb $resource = null ) { parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); - $this->_converter = $converter; } /** @@ -86,14 +78,6 @@ protected function _afterLoad() foreach ($this->_items as $item) { $this->getResource()->unserializeFields($item); } - - /** @var \Magento\Sales\Model\Quote\Payment $item */ - foreach ($this->_items as $item) { - foreach ($item->getData() as $fieldName => $fieldValue) { - $item->setData($fieldName, $this->_converter->decode($item, $fieldName)); - } - } - return parent::_afterLoad(); } } diff --git a/app/code/Magento/Sales/data/sales_setup/data-upgrade-1.6.0.8-1.6.0.9.php b/app/code/Magento/Sales/data/sales_setup/data-upgrade-1.6.0.8-1.6.0.9.php deleted file mode 100644 index 42fbd4580f752..0000000000000 --- a/app/code/Magento/Sales/data/sales_setup/data-upgrade-1.6.0.8-1.6.0.9.php +++ /dev/null @@ -1,91 +0,0 @@ -startSetup(); -$itemsPerPage = 1000; -$currentPosition = 0; - -/** Update sales order payment */ -do { - $select = $installer->getConnection()->select()->from( - $installer->getTable('sales_flat_order_payment'), - array('entity_id', 'cc_owner', 'cc_exp_month', 'cc_exp_year', 'method') - )->where( - 'method = ?', - 'ccsave' - )->limit( - $itemsPerPage, - $currentPosition - ); - - $orders = $select->query()->fetchAll(); - $currentPosition += $itemsPerPage; - - foreach ($orders as $order) { - $installer->getConnection()->update( - $installer->getTable('sales_flat_order_payment'), - array( - 'cc_exp_month' => $installer->getEncryptor()->encrypt($order['cc_exp_month']), - 'cc_exp_year' => $installer->getEncryptor()->encrypt($order['cc_exp_year']), - 'cc_owner' => $installer->getEncryptor()->encrypt($order['cc_owner']) - ), - array('entity_id = ?' => $order['entity_id']) - ); - } -} while (count($orders) > 0); - -/** Update sales quote payment */ -$currentPosition = 0; -do { - $select = $installer->getConnection()->select()->from( - $installer->getTable('sales_flat_quote_payment'), - array('payment_id', 'cc_owner', 'cc_exp_month', 'cc_exp_year', 'method') - )->where( - 'method = ?', - 'ccsave' - )->limit( - $itemsPerPage, - $currentPosition - ); - - $quotes = $select->query()->fetchAll(); - $currentPosition += $itemsPerPage; - - foreach ($quotes as $quote) { - $installer->getConnection()->update( - $installer->getTable('sales_flat_quote_payment'), - array( - 'cc_exp_month' => $installer->getEncryptor()->encrypt($quote['cc_exp_month']), - 'cc_exp_year' => $installer->getEncryptor()->encrypt($quote['cc_exp_year']), - 'cc_owner' => $installer->getEncryptor()->encrypt($quote['cc_owner']) - ), - array('payment_id = ?' => $quote['payment_id']) - ); - } -} while (count($quotes) > 0); - -$installer->endSetup(); diff --git a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js index 7824557118969..5c41a0672a3d5 100644 --- a/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js +++ b/app/code/Magento/Sales/view/adminhtml/web/order/create/scripts.js @@ -938,22 +938,25 @@ AdminOrder.prototype = { } }, - loadAreaResponseHandler : function (response){ + loadAreaResponseHandler : function (response) { if (response.error) { alert(response.message); } - if(response.ajaxExpired && response.ajaxRedirect) { + if (response.ajaxExpired && response.ajaxRedirect) { setLocation(response.ajaxRedirect); } - if(!this.loadingAreas){ + if (!this.loadingAreas) { this.loadingAreas = []; } - if(typeof this.loadingAreas == 'string'){ + if (typeof this.loadingAreas == 'string') { this.loadingAreas = [this.loadingAreas]; } - if(this.loadingAreas.indexOf('message') == -1) { + if (this.loadingAreas.indexOf('message') == -1) { this.loadingAreas.push('message'); } + if (response.header) { + jQuery('.page-actions-inner').attr('data-title', response.header); + } for (var i = 0; i < this.loadingAreas.length; i++) { var id = this.loadingAreas[i]; @@ -968,7 +971,7 @@ AdminOrder.prototype = { } }, - prepareArea : function(area){ + prepareArea : function(area) { if (this.giftMessageDataChanged) { return area.without('giftmessage'); } diff --git a/app/code/Magento/SalesRule/Helper/Data.php b/app/code/Magento/SalesRule/Helper/Data.php deleted file mode 100644 index 9d0cc66847e2f..0000000000000 --- a/app/code/Magento/SalesRule/Helper/Data.php +++ /dev/null @@ -1,68 +0,0 @@ -setDiscountCalculationPrice($price); - $item->setBaseDiscountCalculationPrice($basePrice); - return $this; - } - - /** - * Add additional amounts to discount calculation prices - * - * @param AbstractItem $item - * @param float $basePrice - * @param float $price - * @return $this - */ - public function addItemDiscountPrices(AbstractItem $item, $basePrice, $price) - { - $discountPrice = $item->getDiscountCalculationPrice(); - $baseDiscountPrice = $item->getBaseDiscountCalculationPrice(); - - if ($discountPrice || $baseDiscountPrice || $basePrice || $price) { - $discountPrice = $discountPrice ? $discountPrice : $item->getCalculationPrice(); - $baseDiscountPrice = $baseDiscountPrice ? $baseDiscountPrice : $item->getBaseCalculationPrice(); - $this->setItemDiscountPrices($item, $baseDiscountPrice + $basePrice, $discountPrice + $price); - } - return $this; - } -} diff --git a/app/code/Magento/SalesRule/Model/Observer.php b/app/code/Magento/SalesRule/Model/Observer.php index e6c6a2a69b60d..9b0b1ceebf161 100644 --- a/app/code/Magento/SalesRule/Model/Observer.php +++ b/app/code/Magento/SalesRule/Model/Observer.php @@ -166,10 +166,9 @@ public function salesOrderAfterPlace($observer) /** * Refresh sales coupons report statistics for last day * - * @param Schedule $schedule * @return $this */ - public function aggregateSalesReportCouponsData($schedule) + public function aggregateSalesReportCouponsData() { $this->_localeResolver->emulate(0); $currentDate = $this->_localeDate->date(); diff --git a/app/code/Magento/Shipping/Model/Shipping.php b/app/code/Magento/Shipping/Model/Shipping.php index 467c80a0b34c2..21d3a7f0c1609 100644 --- a/app/code/Magento/Shipping/Model/Shipping.php +++ b/app/code/Magento/Shipping/Model/Shipping.php @@ -305,7 +305,7 @@ public function collectCarrierRates($carrierCode, $request) return $this; } // sort rates by price - if (method_exists($result, 'sortRatesByPrice')) { + if (method_exists($result, 'sortRatesByPrice') && is_callable([$result, 'sortRatesByPrice'])) { $result->sortRatesByPrice(); } $this->getResult()->append($result); diff --git a/app/code/Magento/Store/App/Response/Redirect.php b/app/code/Magento/Store/App/Response/Redirect.php index 6bca24ac9d720..615e1862bfbae 100644 --- a/app/code/Magento/Store/App/Response/Redirect.php +++ b/app/code/Magento/Store/App/Response/Redirect.php @@ -207,10 +207,19 @@ public function redirect(\Magento\Framework\App\ResponseInterface $response, $pa protected function _isUrlInternal($url) { if (strpos($url, 'http') !== false) { - $unsecure = strpos($url, $this->_storeManager->getStore()->getBaseUrl()) === 0; + $unsecure = strpos( + $url, + $this->_storeManager->getStore()->getBaseUrl( + \Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK, + false + ) + ) === 0; $secure = strpos( $url, - $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, true) + $this->_storeManager->getStore()->getBaseUrl( + \Magento\Framework\UrlInterface::URL_TYPE_DIRECT_LINK, + true + ) ) === 0; return $unsecure || $secure; } diff --git a/app/code/Magento/Tax/sql/tax_setup/install-1.6.0.0.php b/app/code/Magento/Tax/sql/tax_setup/install-1.6.0.0.php index 01c4fc7c0cc98..c7ea81fba3dd5 100644 --- a/app/code/Magento/Tax/sql/tax_setup/install-1.6.0.0.php +++ b/app/code/Magento/Tax/sql/tax_setup/install-1.6.0.0.php @@ -23,6 +23,7 @@ */ /** @var $installer \Magento\Tax\Model\Resource\Setup */ $installer = $this; +$installer->startSetup(); // /** * Create table 'tax/class' diff --git a/app/code/Magento/User/sql/user_setup/upgrade-1.6.1.3-1.6.1.4.php b/app/code/Magento/User/sql/user_setup/upgrade-1.6.1.3-1.6.1.4.php index c7b18636a6956..5f6bffb9e5465 100644 --- a/app/code/Magento/User/sql/user_setup/upgrade-1.6.1.3-1.6.1.4.php +++ b/app/code/Magento/User/sql/user_setup/upgrade-1.6.1.3-1.6.1.4.php @@ -39,3 +39,4 @@ 'comment' => 'Backend interface locale' ) ); +$installer->endSetup(); diff --git a/app/code/Magento/Weee/Helper/Data.php b/app/code/Magento/Weee/Helper/Data.php index 98002b4da5527..fd423abe59668 100644 --- a/app/code/Magento/Weee/Helper/Data.php +++ b/app/code/Magento/Weee/Helper/Data.php @@ -25,6 +25,7 @@ use Magento\Store\Model\Store; use Magento\Store\Model\Website; +use Magento\Sales\Model\Quote\Item\AbstractItem; /** * WEEE data helper @@ -440,4 +441,40 @@ public function getAmountInclTaxes($attributes) return (float) $amount; } + + /** + * Set store and base price which will be used during discount calculation to item object + * + * @param AbstractItem $item + * @param float $basePrice + * @param float $price + * @return $this + */ + public function setItemDiscountPrices(AbstractItem $item, $basePrice, $price) + { + $item->setDiscountCalculationPrice($price); + $item->setBaseDiscountCalculationPrice($basePrice); + return $this; + } + + /** + * Add additional amounts to discount calculation prices + * + * @param AbstractItem $item + * @param float $basePrice + * @param float $price + * @return $this + */ + public function addItemDiscountPrices(AbstractItem $item, $basePrice, $price) + { + $discountPrice = $item->getDiscountCalculationPrice(); + $baseDiscountPrice = $item->getBaseDiscountCalculationPrice(); + + if ($discountPrice || $baseDiscountPrice || $basePrice || $price) { + $discountPrice = $discountPrice ? $discountPrice : $item->getCalculationPrice(); + $baseDiscountPrice = $baseDiscountPrice ? $baseDiscountPrice : $item->getBaseCalculationPrice(); + $this->setItemDiscountPrices($item, $baseDiscountPrice + $basePrice, $discountPrice + $price); + } + return $this; + } } diff --git a/app/code/Magento/Weee/Model/Total/Quote/Weee.php b/app/code/Magento/Weee/Model/Total/Quote/Weee.php index 7b9155812a666..ab53d2cfdac71 100644 --- a/app/code/Magento/Weee/Model/Total/Quote/Weee.php +++ b/app/code/Magento/Weee/Model/Total/Quote/Weee.php @@ -77,27 +77,15 @@ public function collect(\Magento\Sales\Model\Quote\Address $address) if (!count($items)) { return $this; } - $address->setAppliedTaxesReset(true); $address->setAppliedTaxes(array()); - $this->_store = $address->getQuote()->getStore(); foreach ($items as $item) { - if ($item->getParentItemId()) { - continue; - } - $this->_resetItemData($item); - if ($item->getHasChildren() && $item->isChildrenCalculated()) { - foreach ($item->getChildren() as $child) { - $this->_resetItemData($child); - $this->_process($address, $child); - } + $this->_processItem($item, $address); + if ($item->isChildrenCalculated()) { $this->_recalculateParent($item); - } else { - $this->_process($address, $item); } } - if ($this->_isTaxAffected) { $address->unsSubtotalInclTax(); $address->unsBaseSubtotalInclTax(); @@ -107,18 +95,14 @@ public function collect(\Magento\Sales\Model\Quote\Address $address) } /** - * Calculate item fixed tax and prepare information for discount and recular taxation + * Calculate item fixed tax and prepare information for discount and regular taxation * * @param \Magento\Sales\Model\Quote\Address $address * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item - * @return void|$this + * @return array */ protected function _process(\Magento\Sales\Model\Quote\Address $address, $item) { - if (!$this->_weeeData->isEnabled($this->_store)) { - return $this; - } - $attributes = $this->_weeeData->getProductWeeeAttributes( $item->getProduct(), $address, @@ -126,27 +110,27 @@ protected function _process(\Magento\Sales\Model\Quote\Address $address, $item) $this->_store->getWebsiteId() ); - $applied = array(); - $productTaxes = array(); + $taxData['applied'] = array(); + $taxData['product_taxes'] = array(); - $totalValue = 0; - $baseTotalValue = 0; - $totalRowValue = 0; - $baseTotalRowValue = 0; + $valuesData['total'] = 0; + $valuesData['base_total'] = 0; + $valuesData['total_row'] = 0; + $valuesData['base_total_row'] = 0; foreach ($attributes as $key => $attribute) { - $baseValue = $attribute->getAmount(); - $value = $this->_store->convertPrice($baseValue); - $rowValue = $value * $item->getTotalQty(); - $baseRowValue = $baseValue * $item->getTotalQty(); - $title = $attribute->getName(); - - $totalValue += $value; - $baseTotalValue += $baseValue; - $totalRowValue += $rowValue; - $baseTotalRowValue += $baseRowValue; - - $productTaxes[] = array( + $baseValue = $attribute->getAmount(); + $value = $this->_store->convertPrice($baseValue); + $rowValue = $value * $item->getTotalQty(); + $baseRowValue = $baseValue * $item->getTotalQty(); + $title = $attribute->getName(); + + $valuesData['total'] += $value; + $valuesData['base_total'] += $baseValue; + $valuesData['total_row'] += $rowValue; + $valuesData['base_total_row'] += $baseRowValue; + + $taxData['product_taxes'][] = array( 'title' => $title, 'base_amount' => $baseValue, 'amount' => $value, @@ -161,54 +145,139 @@ protected function _process(\Magento\Sales\Model\Quote\Address $address, $item) 'base_row_amount_incl_tax' => $baseRowValue ); - $applied[] = array( - 'id' => $attribute->getCode(), - 'percent' => null, - 'hidden' => $this->_weeeData->includeInSubtotal($this->_store), - 'rates' => array(array( - 'base_real_amount'=> $baseRowValue, - 'base_amount' => $baseRowValue, - 'amount' => $rowValue, - 'code' => $attribute->getCode(), - 'title' => $title, - 'percent' => null, - 'position' => 1, - 'priority' => -1000 + $key, - )) + $taxData['applied'][] = array( + 'id' => $attribute->getCode(), + 'percent' => null, + 'hidden' => $this->_weeeData->includeInSubtotal($this->_store), + 'rates' => array( + array( + 'base_real_amount' => $baseRowValue, + 'base_amount' => $baseRowValue, + 'amount' => $rowValue, + 'code' => $attribute->getCode(), + 'title' => $title, + 'percent' => null, + 'position' => 1, + 'priority' => -1000 + $key + ) + ) ); } - $item->setWeeeTaxAppliedAmount($totalValue) - ->setBaseWeeeTaxAppliedAmount($baseTotalValue) - ->setWeeeTaxAppliedRowAmount($totalRowValue) - ->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValue); + return array('values' => $valuesData, 'tax' => $taxData, 'address' => $address, 'item' => $item); + } + + /** + * Prepare item data for processing. + * + * @param \Magento\Sales\Model\Quote\Address $address + * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item + * @return $this + */ + protected function _processItem($item, $address) + { + $this->_resetItemDataIfHasParent($item); + if ($item->getHasChildren() && $item->isChildrenCalculated()) { + foreach ($item->getChildren() as $child) { + $this->_resetItemData($child); + $this->_processDataWithWeeeData($address, $child); + } + } else { + $this->_processDataWithWeeeData($address, $item); + } + return $this; + } + + /** + * Process item if weee is enabled. + * + * @param \Magento\Sales\Model\Quote\Address $address + * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item + * @return $this + */ + protected function _processDataWithWeeeData ($address, $item) + { + if ($this->_weeeData->isEnabled($this->_store)) { + $processData = $this->_process($address, $item); + $this->_setTax($processData); + } + return $this; + } + + /** + * Reset item data if it have parent + * + * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item + * @return $this + */ + protected function _resetItemDataIfHasParent($item) + { + if (!$item->getParentItemId()) { + $this->_resetItemData($item); + } + return $this; + } + /** + * Set tax to item, process tax with total amount and discount settings + * + * @param array $processData + * @return $this + */ + protected function _setTax($processData) + { + $values = $processData['values']; + $tax = $processData['tax']; + $item = $processData['item']; + $address = $processData['address']; + + $this->_setAppliedTaxes($item, $values); $this->_processTaxSettings( $item, - $totalValue, - $baseTotalValue, - $totalRowValue, - $baseTotalRowValue + $values['total'], + $values['base_total'], + $values['total_row'], + $values['base_total_row'] )->_processTotalAmount( $address, - $totalRowValue, - $baseTotalRowValue + $values['total_row'], + $values['base_total_row'] )->_processDiscountSettings( $item, - $totalValue, - $baseTotalValue + $values['total'], + $values['base_total'] ); - $this->_weeeData->setApplied($item, array_merge($this->_weeeData->getApplied($item), $productTaxes)); - if ($applied) { + $this->_weeeData->setApplied($item, array_merge($this->_weeeData->getApplied($item), $tax['product_taxes'])); + if ($tax['applied']) { $this->_saveAppliedTaxes( $address, - $applied, + $tax['applied'], $item->getWeeeTaxAppliedAmount(), $item->getBaseWeeeTaxAppliedAmount(), null ); } + return $this; + } + + /** + * Set applied taxes to item data. + * + * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item + * @param array $values + * @return $this + */ + protected function _setAppliedTaxes($item, $values) + { + $taxAppliedData = array( + 'weee_tax_applied_amount' => $values['total'], + 'base_weee_tax_applied_amount' => $values['base_total'], + 'weee_tax_applied_row_amount' => $values['total_row'], + 'base_weee_tax_applied_row_amnt' => $values['base_total_row'], + ); + $item->addData($taxAppliedData); + return $this; } /** @@ -253,7 +322,7 @@ protected function _processTaxSettings($item, $value, $baseValue, $rowValue, $ba } /** - * Proces row amount based on FPT total amount configuration setting + * Process row amount based on FPT total amount configuration setting * * @param \Magento\Sales\Model\Quote\Address $address * @param float $rowValue @@ -277,7 +346,7 @@ protected function _processTotalAmount($address, $rowValue, $baseRowValue) * Recalculate parent item amounts based on children results * * @param \Magento\Sales\Model\Quote\Item\AbstractItem $item - * @return void + * @return null */ protected function _recalculateParent(\Magento\Sales\Model\Quote\Item\AbstractItem $item) { @@ -333,7 +402,6 @@ public function processConfigArray($config, $store) /** * No aggregated label for fixed product tax * - * TODO: fix * @return string */ public function getLabel() diff --git a/app/code/Magento/Weee/sql/weee_setup/install-1.6.0.0.php b/app/code/Magento/Weee/sql/weee_setup/install-1.6.0.0.php index 33362815bdbe6..58f89d2eda28c 100644 --- a/app/code/Magento/Weee/sql/weee_setup/install-1.6.0.0.php +++ b/app/code/Magento/Weee/sql/weee_setup/install-1.6.0.0.php @@ -24,6 +24,7 @@ /** @var $installer \Magento\Sales\Model\Resource\Setup */ $installer = $this; +$installer->startSetup(); /** * Create table 'weee_tax' */ diff --git a/app/design/frontend/Magento/blank/Magento_Theme/layout/default_head_blocks.xml b/app/design/frontend/Magento/blank/Magento_Theme/layout/default_head_blocks.xml index 8decbb3424573..e67563b85adc2 100644 --- a/app/design/frontend/Magento/blank/Magento_Theme/layout/default_head_blocks.xml +++ b/app/design/frontend/Magento/blank/Magento_Theme/layout/default_head_blocks.xml @@ -40,7 +40,7 @@ matchMedia.js - + js/responsive.js diff --git a/dev/tests/functional/lib/Mtf/App/State/State1.php b/dev/tests/functional/lib/Mtf/App/State/State1.php index cdd4dd9ea20ac..8184556d5a540 100644 --- a/dev/tests/functional/lib/Mtf/App/State/State1.php +++ b/dev/tests/functional/lib/Mtf/App/State/State1.php @@ -24,19 +24,38 @@ namespace Mtf\App\State; +use Magento\Core\Test\Fixture\Config; + /** * Class State1 * Example Application State class - * */ class State1 extends AbstractState { + /** + * Configuration fixture + * + * @var Config + */ + protected $config; + + /** + * @construct + * @param Config $config + */ + public function __construct(Config $config) + { + $this->config = $config; + } + /** * @inheritdoc */ public function apply() { parent::apply(); + $this->config->switchData('app_state1_configuration'); + $this->config->persist(); } /** diff --git a/dev/tests/functional/lib/Mtf/Client/Driver/Selenium/Element/DatepickerElement.php b/dev/tests/functional/lib/Mtf/Client/Driver/Selenium/Element/DatepickerElement.php index dfebc90bf0336..39b76ffce6e2b 100644 --- a/dev/tests/functional/lib/Mtf/Client/Driver/Selenium/Element/DatepickerElement.php +++ b/dev/tests/functional/lib/Mtf/Client/Driver/Selenium/Element/DatepickerElement.php @@ -39,14 +39,14 @@ class DatepickerElement extends Element * * @var string */ - protected $datePickerButton = './/following-sibling::img[contains(@class,"ui-datepicker-trigger")]'; + protected $datePickerButton = './../img[contains(@class,"ui-datepicker-trigger")]'; /** * DatePicker block * * @var string */ - protected $datePickerBlock = './/ancestor::body//*[contains(@id,"ui-datepicker-div")]'; + protected $datePickerBlock = './ancestor::body//*[@id="ui-datepicker-div"]'; /** * Field Month on the DatePicker diff --git a/dev/tests/functional/lib/Mtf/Util/Generate/testcase.xml b/dev/tests/functional/lib/Mtf/Util/Generate/testcase.xml index 2f47021158bc1..79bbd38c3dfe1 100644 --- a/dev/tests/functional/lib/Mtf/Util/Generate/testcase.xml +++ b/dev/tests/functional/lib/Mtf/Util/Generate/testcase.xml @@ -136,4 +136,34 @@ Verify created product. + + MTA-128 + MTA-128 + SuggestSearchingResult(SearchEntity)WithFucntionalTestsDesignedForAutomationTest + Cover Suggest Searching Result (SearchEntity) with fucntional tests designed for automation + Search + + Search Frontend (CS) + + + + + MTA-15 + MTA-15 + CreateDownloadableProductEntityTest + Test Creation for Create DownloadableProductEntity + Catalog + + Downloadable Product (CS) + + + Log in to Backend. + Navigate to Products > Catalog. + Start to create new Downloadable product. + Fill in data according to data set. + Fill Downloadable Information tab according to data set. + Save product. + Verify created product. + + diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/PageActions.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/PageActions.php index af74b013d2487..3c2da313a6956 100644 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/PageActions.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/System/Config/PageActions.php @@ -23,33 +23,25 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ + namespace Magento\Backend\Test\Block\System\Config; use Mtf\Client\Element\Locator; -use \Magento\Backend\Test\Block\PageActions as AbstractPageActions; +use Magento\Backend\Test\Block\FormPageActions as AbstractPageActions; +/** + * Class PageActions + * System config page action + */ class PageActions extends AbstractPageActions { /** - * Save button + * Scope CSS selector * * @var string */ - protected $saveButton = '#save'; - - /** - * @var string - */ protected $scopeSelector = '.actions.dropdown'; - /** - * Click "Save" button - */ - public function save() - { - $this->_rootElement->find($this->saveButton)->click(); - } - /** * Select store * diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php index fd68db66592c6..1a2bc9ce0feae 100644 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/FormTabs.php @@ -190,10 +190,9 @@ public function getData(FixtureInterface $fixture = null, Element $element = nul } else { $isHasData = ($fixture instanceof InjectableFixture) ? $fixture->hasData() : true; $tabsFields = $isHasData ? $this->getFieldsByTabs($fixture) : []; - foreach ($this->tabs as $tabName => $tab) { + foreach ($tabsFields as $tabName => $fields) { $this->openTab($tabName); - $tabFields = isset($tabsFields[$tabName]) ? $tabsFields[$tabName] : []; - $tabData = $this->getTabElement($tabName)->getDataFormTab($tabFields, $this->_rootElement); + $tabData = $this->getTabElement($tabName)->getDataFormTab($fields, $this->_rootElement); $data = array_merge($data, $tabData); } } @@ -289,7 +288,7 @@ private function getFixtureFieldsByTabsDeprecated(FixtureInterface $fixture) protected function getTabElement($tabName) { $tabClass = $this->tabs[$tabName]['class']; - /** @var $tabElement Tab */ + /** @var Tab $tabElement */ $tabElement = new $tabClass($this->_rootElement, $this->blockFactory, $this->mapper); if (!$tabElement instanceof Tab) { throw new \Exception('Wrong Tab Class.'); diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Grid.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Grid.php index ad48d1e9ff26f..7d9b5ba21680b 100644 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Block/Widget/Grid.php @@ -319,6 +319,7 @@ public function sortGridByField($field, $sort = "desc") $sortBlock = $this->_rootElement->find(sprintf($this->sortLink, $field, $sort)); if ($sortBlock->isVisible()) { $sortBlock->click(); + $this->getTemplateBlock()->waitLoader(); } } } diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Extractor.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Extractor.php new file mode 100644 index 0000000000000..9ccc06a5de2fd --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Handler/Extractor.php @@ -0,0 +1,87 @@ +url = $url; + $this->regExpPattern = $regExpPattern; + } + + /** + * Retrieves data from cURL response + * + * @throws \Exception + * @return array + */ + public function getData() + { + $url = $_ENV['app_backend_url'] . $this->url; + $curl = new BackendDecorator(new CurlTransport(), new Config); + $curl->addOption(CURLOPT_HEADER, 1); + $curl->write(CurlInterface::POST, $url, '1.0'); + $response = $curl->read(); + $curl->close(); + preg_match($this->regExpPattern, $response, $matches); + + if (count($matches) == 0) { + throw new \Exception('Matches array can\'t be empty.'); + } + return $matches; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.php new file mode 100644 index 0000000000000..bb02f962208af --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.php @@ -0,0 +1,80 @@ + [ + 'name' => 'pageActions', + 'class' => 'Magento\Backend\Test\Block\System\Config\PageActions', + 'locator' => '.page-main-actions', + 'strategy' => 'css selector', + ], + 'form' => [ + 'name' => 'form', + 'class' => 'Magento\Backend\Test\Block\System\Config\Form', + 'locator' => '#config-edit-form', + 'strategy' => 'css selector', + ], + 'messagesBlock' => [ + 'name' => 'messagesBlock', + 'class' => 'Magento\Core\Test\Block\Messages', + 'locator' => '#messages', + 'strategy' => 'css selector', + ], + ]; + + /** + * @return \Magento\Backend\Test\Block\System\Config\PageActions + */ + public function getPageActions() + { + return $this->getBlockInstance('pageActions'); + } + + /** + * @return \Magento\Backend\Test\Block\System\Config\Form + */ + public function getForm() + { + return $this->getBlockInstance('form'); + } + + /** + * @return \Magento\Core\Test\Block\Messages + */ + public function getMessagesBlock() + { + return $this->getBlockInstance('messagesBlock'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.xml b/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.xml new file mode 100644 index 0000000000000..ea51fba834096 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/SystemConfig.xml @@ -0,0 +1,45 @@ + + + + + pageActions + Magento\Backend\Test\Block\FormPageActions + .page-main-actions + css selector + + + form + Magento\Backend\Test\Block\System\Config\Form + #config-edit-form + css selector + + + messagesBlock + Magento\Core\Test\Block\Messages + #messages + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/Page/System/Config.php b/dev/tests/functional/tests/app/Magento/Backend/Test/Page/System/Config.php deleted file mode 100644 index e61502fe4aa06..0000000000000 --- a/dev/tests/functional/tests/app/Magento/Backend/Test/Page/System/Config.php +++ /dev/null @@ -1,102 +0,0 @@ -_url = $_ENV['app_backend_url'] . self::MCA; - } - - /** - * Retrieve form block - * - * @return \Magento\Backend\Test\Block\System\Config\Form - */ - public function getForm() - { - return Factory::getBlockFactory()->getMagentoBackendSystemConfigForm($this->_browser->find($this->form)); - } - - /** - * Retrieve page actions block - * - * @return \Magento\Backend\Test\Block\System\Config\PageActions - */ - public function getPageActions() - { - return Factory::getBlockFactory()->getMagentoBackendSystemConfigPageActions( - $this->_browser->find($this->pageActions) - ); - } - - /** - * Retrieve messages block - * - * @return Messages - */ - public function getMessagesBlock() - { - return Factory::getBlockFactory()->getMagentoCoreMessages($this->_browser->find($this->messages)); - } -} diff --git a/dev/tests/functional/tests/app/Magento/Backend/Test/etc/global/page.xml b/dev/tests/functional/tests/app/Magento/Backend/Test/etc/global/page.xml new file mode 100644 index 0000000000000..9085814b56243 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Backend/Test/etc/global/page.xml @@ -0,0 +1,32 @@ + + + + + admin/system_config + adminhtml + Magento\Backend\Test\Page\Adminhtml\SystemConfig + + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.php index ac327030fc2fd..c1694c281b905 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.php @@ -88,14 +88,14 @@ class Form extends FormTabs * * @var string */ - protected $advancedTabPanel = '[role="tablist"] [role="tabpanel"][aria-expanded="true"]:not("overflow")'; + protected $advancedTabPanel = './/*[role="tablist"]//ul[!contains(@style,"overflow")]'; /** - * Locator status of products + * CSS locator button status of the product * * @var string */ - protected $onlineSwitcher = '#product-online-switcher + [for="product-online-switcher"]'; + protected $onlineSwitcher = '#product-online-switcher%s + [for="product-online-switcher"]'; /** * Category fixture @@ -112,13 +112,25 @@ class Form extends FormTabs * @param Element $element * @return $this */ - public function fillProduct(FixtureInterface $fixture, CatalogCategoryEntity $category = null, Element $element = null) - { + public function fillProduct( + FixtureInterface $fixture, + CatalogCategoryEntity $category = null, + Element $element = null + ) { $this->category = $category; $this->fillCategory($fixture); - if ($fixture instanceof InjectableFixture && $fixture->getStatus() === 'Product offline') { - $this->_rootElement->find($this->onlineSwitcher)->click(); + + if ($fixture instanceof InjectableFixture) { + $status = $fixture->getStatus(); + if (($status === 'Product offline' + && $this->_rootElement->find(sprintf($this->onlineSwitcher, ':checked'))->isVisible()) + || ($status === 'Product online' + && $this->_rootElement->find(sprintf($this->onlineSwitcher, ':not(:checked)'))->isVisible()) + ) { + $this->_rootElement->find(sprintf($this->onlineSwitcher, ''))->click(); + } } + return parent::fill($fixture, $element); } @@ -152,7 +164,7 @@ protected function fillCategory(FixtureInterface $fixture) $categoryName = $this->category->getName(); } if (empty($categoryName) && !($fixture instanceof InjectableFixture)) { - $categoryName = $fixture->getCategoryName(); + $categoryName = $fixture->getCategoryName(); } if (empty($categoryName)) { return; @@ -268,11 +280,11 @@ public function openTab($tabName) $strategy = isset($this->tabs[$tabName]['strategy']) ? $this->tabs[$tabName]['strategy'] : Locator::SELECTOR_CSS; - $advancedTabList = $this->advancedTabList; $tab = $this->_rootElement->find($selector, $strategy); $advancedSettings = $this->_rootElement->find($this->advancedSettings); // Wait until all tabs will load + $advancedTabList = $this->advancedTabList; $this->_rootElement->waitUntil( function () use ($rootElement, $advancedTabList) { return $rootElement->find($advancedTabList)->isVisible(); @@ -287,12 +299,17 @@ function () use ($rootElement, $advancedTabList) { $tabPanel = $this->advancedTabPanel; $this->_rootElement->waitUntil( function () use ($rootElement, $tabPanel) { - return $rootElement->find($tabPanel)->isVisible(); + return $rootElement->find($tabPanel, Locator::SELECTOR_XPATH)->isVisible(); } ); // Wait until needed tab will appear $this->_rootElement->waitUntil( - function () use ($rootElement, $selector, $strategy) { + function () use ($rootElement, $selector, $strategy, $tabPanel) { + $this->_rootElement->waitUntil( + function () use ($rootElement, $tabPanel) { + return $rootElement->find($tabPanel, Locator::SELECTOR_XPATH)->isVisible(); + } + ); return $rootElement->find($selector, $strategy)->isVisible(); } ); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.xml index fc1169c2d07dc..b488bff8a9092 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Form.xml @@ -85,6 +85,13 @@ [name='product[stock_data][qty]'] + + [name='product[stock_data][use_config_min_qty]'] + checkbox + + + [name='product[stock_data][min_qty]'] + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php index 55376f2f69d16..316afd6e097f4 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php @@ -27,7 +27,7 @@ use Magento\Backend\Test\Block\Widget\Grid as ParentGrid; /** - * Class ProductGrid + * Class Grid * Backend catalog product grid */ class Grid extends ParentGrid @@ -35,24 +35,24 @@ class Grid extends ParentGrid /** * Initialize block elements */ - protected $filters = array( - 'name' => array( + protected $filters = [ + 'name' => [ 'selector' => '#productGrid_product_filter_name' - ), - 'sku' => array( + ], + 'sku' => [ 'selector' => '#productGrid_product_filter_sku' - ), - 'type' => array( + ], + 'type' => [ 'selector' => '#productGrid_product_filter_type', 'input' => 'select' - ), - 'price_from' => array( + ], + 'price_from' => [ 'selector' => '#productGrid_product_filter_price_from' - ), - 'price_to' => array( + ], + 'price_to' => [ 'selector' => '#productGrid_product_filter_price_to' - ) - ); + ] + ]; /** * Update attributes for selected items diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Toolbar.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Toolbar.php index f1e7ce1b27a75..8bbdb92f1e050 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Toolbar.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/Toolbar.php @@ -27,7 +27,7 @@ use Mtf\Block\Block; /** - * Class ProductPagination + * Class Toolbar * Toolbar the product list page */ class Toolbar extends Block diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php index f03aa6d5e63dc..eb37a68a232de 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php @@ -238,8 +238,9 @@ public function getProductSku() */ public function getProductPriceBlock() { - return Factory::getBlockFactory()->getMagentoCatalogProductPrice( - $this->_rootElement->find($this->priceBlockClass, Locator::SELECTOR_CLASS_NAME) + return $this->blockFactory->create( + 'Magento\Catalog\Test\Block\Product\Price', + ['element' => $this->_rootElement->find($this->priceBlockClass, Locator::SELECTOR_CLASS_NAME)] ); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Search.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Search.php index 24029a7351bbc..ec26a9203f0ea 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Search.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Search.php @@ -33,6 +33,20 @@ */ class Search extends Block { + /** + * Selector matches found - "Suggest Search" + * + * @var string + */ + protected $searchAutocomplete = './/div[@id="search_autocomplete"]//li[text()="%s"]'; + + /** + * Selector number of matches for a given row + * + * @var string + */ + protected $searchItemAmount = '/span[contains(@class,"amount") and text()="%d"]'; + /** * Search field * @@ -62,10 +76,21 @@ class Search extends Block */ public function search($keyword) { - $this->_rootElement->find($this->searchInput, Locator::SELECTOR_CSS)->setValue($keyword); + $this->fillSearch($keyword); $this->_rootElement->find($this->searchButton, Locator::SELECTOR_CSS)->click(); } + /** + * Fills the search field + * + * @param string $text + * @return void + */ + public function fillSearch($text) + { + $this->_rootElement->find($this->searchInput, Locator::SELECTOR_CSS)->setValue($text); + } + /** * Check that placeholder contains text * @@ -80,4 +105,23 @@ public function isPlaceholderContains($placeholderText) ); return $field->isVisible(); } + + /** + * Checking block visibility "Suggest Search" + * + * @param string $text + * @param int|null $amount + * @return bool + */ + public function isSuggestSearchVisible($text, $amount = null) + { + $searchAutocomplete = sprintf($this->searchAutocomplete, $text); + if ($amount !== null) { + $searchAutocomplete .= sprintf($this->searchItemAmount, $amount); + } + + $this->waitForElementVisible($searchAutocomplete, Locator::SELECTOR_XPATH); + return $this->_rootElement->find($searchAutocomplete, Locator::SELECTOR_XPATH) + ->isVisible(); + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonAbsent.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonAbsent.php index cfcff41e0c71d..6b2726761fd16 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonAbsent.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonAbsent.php @@ -72,7 +72,7 @@ class AssertAddToCartButtonAbsent extends AbstractConstraint protected $catalogProductView; /** - * Assert that "Add to cart" button is not display on page. + * Assert that "Add to cart" button is not display on page * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView @@ -127,7 +127,7 @@ protected function addToCardAbsentOnProduct() $this->catalogCategoryView->getListProductBlock()->openProductViewPage($this->product->getName()); \PHPUnit_Framework_Assert::assertFalse( $this->catalogProductView->getViewBlock()->checkAddToCardButton(), - "Button 'Add to Card' is present on Product page" + "Button 'Add to Card' is present on Product page." ); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonPresent.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonPresent.php index 2cca302e25137..f4ac24bc1c39d 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonPresent.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAddToCartButtonPresent.php @@ -72,7 +72,7 @@ class AssertAddToCartButtonPresent extends AbstractConstraint protected $catalogProductView; /** - * Assert that "Add to cart" button is present on page. + * Assert that "Add to cart" button is present on page * * @param CmsIndex $cmsIndex * @param CatalogCategoryView $catalogCategoryView @@ -109,7 +109,7 @@ protected function addToCardPresentOnCategory() ); \PHPUnit_Framework_Assert::assertTrue( $this->catalogCategoryView->getListProductBlock()->checkAddToCardButton(), - "Button 'Add to Card' is absent on Category page" + "Button 'Add to Card' is absent on Category page." ); } @@ -127,7 +127,7 @@ protected function addToCardPresentOnProduct() $this->catalogCategoryView->getListProductBlock()->openProductViewPage($this->product->getName()); \PHPUnit_Framework_Assert::assertTrue( $this->catalogProductView->getViewBlock()->checkAddToCardButton(), - "Button 'Add to Card' is absent on Product page" + "Button 'Add to Card' is absent on Product page." ); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCustomOptionsOnProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCustomOptionsOnProductPage.php index 49c2917a8fef1..95e1ef295df99 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCustomOptionsOnProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertCustomOptionsOnProductPage.php @@ -30,8 +30,6 @@ /** * Class AssertCustomOptionsOnProductPage - * - * @package Magento\Catalog\Test\Constraint */ class AssertCustomOptionsOnProductPage extends AbstractConstraint { @@ -63,47 +61,30 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt // Open product view page $catalogProductView->init($this->product); $catalogProductView->open(); + // Prepare data $customOptions = $catalogProductView->getCustomOptionsBlock()->getOptions(); - $compareOptions = $this->product->getCustomOptions(); - - $compareOptions = $this->prepareOptionArray($compareOptions); - ksort($compareOptions); - ksort($customOptions); - $noError = array_keys($compareOptions) === array_keys($customOptions); - - if ($noError) { - $noError = $this->compareOptions($customOptions, $compareOptions); + foreach ($customOptions as &$option) { + unset($option['value']); } + unset($option); + $compareOptions = $this->prepareOptionArray($this->product->getCustomOptions()); + $customOptions = $this->dataSortByKey($customOptions); + $compareOptions = $this->dataSortByKey($compareOptions); - \PHPUnit_Framework_Assert::assertTrue( - $noError, + \PHPUnit_Framework_Assert::assertEquals( + $customOptions, + $compareOptions, 'Incorrect display of custom product options on the product page.' ); } - /** - * Comparison of options - * - * @param array $options - * @param array $compareOptions - * @return bool - */ - protected function compareOptions(array $options, array $compareOptions) + protected function dataSortByKey(array $data) { - foreach ($options as $key => $option) { - sort($option['price']); - if (!isset($compareOptions[$key]['price'])) { - return false; - } - sort($compareOptions[$key]['price']); - if ($option['is_require'] !== $compareOptions[$key]['is_require'] - || $option['price'] !== $compareOptions[$key]['price'] - ) { - return false; - } + foreach ($data as &$item) { + ksort($item); } - - return true; + unset($item); + return $data; } /** @@ -116,12 +97,13 @@ protected function prepareOptionArray(array $options) { $result = []; $productPrice = $this->product->hasData('group_price') - ? $this->product->getPrice() - : $this->product->getGroupPrice()[0]['price']; + ? $this->product->getGroupPrice()[0]['price'] + : $this->product->getPrice(); $placeholder = ['Yes' => true, 'No' => false]; foreach ($options as $option) { $result[$option['title']]['is_require'] = $placeholder[$option['is_require']]; + $result[$option['title']]['title'] = $option['title']; $result[$option['title']]['price'] = []; foreach ($option['options'] as $optionValue) { if ($optionValue['price_type'] === 'Percent') { @@ -135,7 +117,7 @@ protected function prepareOptionArray(array $options) } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertGroupedPriceOnProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertGroupedPriceOnProductPage.php index f6b68f85742cd..0e364e2975f53 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertGroupedPriceOnProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertGroupedPriceOnProductPage.php @@ -53,8 +53,10 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt $catalogProductView->open(); $fields = $product->getData(); $groupPrice = $catalogProductView->getViewBlock()->getProductPrice(); - $groupPrice = empty($groupPrice['price_special_price']) ? null : $groupPrice['price_special_price']; - if (!empty($fields['group_price'])) { + $groupPrice = isset($groupPrice['price_special_price']) + ? $groupPrice['price_special_price'] + : null; + if (isset($fields['group_price'])) { foreach ($fields['group_price'] as $itemGroupPrice) { \PHPUnit_Framework_Assert::assertEquals( $itemGroupPrice['price'], @@ -66,7 +68,7 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductForm.php index d02f71f0fbbe7..414472c7caa75 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductForm.php @@ -86,7 +86,7 @@ public function processAssert( $errors = $this->compareArray($fixtureData, $formData); \PHPUnit_Framework_Assert::assertTrue( empty($errors), - "These data must be equal to each other:\n" . implode("\n - ", $errors) + "These data must be equal to each other:\n" . implode("\n", $errors) ); } @@ -115,7 +115,6 @@ function (&$item, $key, $formattingOptions) { }, $this->formattingOptions ); - unset($compareData['url_key']); return $compareData; } @@ -132,7 +131,7 @@ protected function compareArray(array $fixtureData, array $formData) $errors = []; $keysDiff = array_diff(array_keys($fixtureData), array_keys($formData)); if (!empty($keysDiff)) { - return ['fixture data do not correspond to form data in composition']; + return ['- fixture data do not correspond to form data in composition.']; } foreach ($fixtureData as $key => $value) { @@ -156,7 +155,7 @@ protected function compareArray(array $fixtureData, array $formData) } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCart.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCart.php index 9ea5b04180518..e72639796d61a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCart.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCart.php @@ -54,7 +54,7 @@ public function processAssert( FixtureInterface $product, CheckoutCart $checkoutCart ) { - //Add product to cart + // Add product to cart $catalogProductView->init($product); $catalogProductView->open(); $productOptions = $product->getCustomOptions(); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCategory.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCategory.php index 477d4a5195735..5dd30e4ca1c04 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCategory.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInCategory.php @@ -57,7 +57,7 @@ public function processAssert( FixtureInterface $product, CatalogCategoryEntity $category ) { - //Open category view page and check visible product + // Open category view page and check visible product $cmsIndex->open(); $cmsIndex->getTopmenu()->selectCategoryByName($category->getName()); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInGrid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInGrid.php index 0b069ffcaff42..7b1a718a69e5e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInGrid.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInGrid.php @@ -58,7 +58,7 @@ public function processAssert(FixtureInterface $product, CatalogProductIndex $pr } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInStock.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInStock.php index ebfff102de1dc..88af87b1409a5 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInStock.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductInStock.php @@ -65,7 +65,7 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductIsNotDisplayingOnFrontend.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductIsNotDisplayingOnFrontend.php index 7776d97ccdb2d..5efd08e691efe 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductIsNotDisplayingOnFrontend.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductIsNotDisplayingOnFrontend.php @@ -76,13 +76,13 @@ public function processAssert( if ($titleBlock->getTitle() !== self::NOT_FOUND_MESSAGE) { $errors[] = '- the headline on the page does not match, the text should be -> "' - . self::NOT_FOUND_MESSAGE . '"'; + . self::NOT_FOUND_MESSAGE . '".'; } $cmsIndex->open(); $cmsIndex->getSearchBlock()->search($product->getSku()); if ($catalogSearchResult->getListProductBlock()->isProductVisible($product->getName())) { - $errors[] = '- successful product search'; + $errors[] = '- successful product search.'; } $cmsIndex->open(); @@ -93,7 +93,7 @@ public function processAssert( } if ($isProductVisible) { - $errors[] = '- product found in this category'; + $errors[] = '- product found in this category.'; } \PHPUnit_Framework_Assert::assertTrue( @@ -104,7 +104,7 @@ public function processAssert( } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductOutOfStock.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductOutOfStock.php index bda4162dc0647..7d340ceddbce8 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductOutOfStock.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductOutOfStock.php @@ -46,7 +46,7 @@ class AssertProductOutOfStock extends AbstractConstraint const STOCK_AVAILABILITY = 'Out of stock'; /** - * Assert that Out of Stock status is displayed on product page + * Assert that Out of Stock status is displayed on product page * * @param CatalogProductView $catalogProductView * @param FixtureInterface $product @@ -64,7 +64,7 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php index 90d03847b8e8e..52f18eade7d15 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php @@ -143,7 +143,7 @@ protected function assertSpecialPrice(array $price) } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSearchableBySku.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSearchableBySku.php index 630fad6e5bfad..7316ea2c1e39b 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSearchableBySku.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSearchableBySku.php @@ -53,10 +53,10 @@ class AssertProductSearchableBySku extends AbstractConstraint * * @var string */ - protected $successfulMessage = 'Product successfully found by SKU'; + protected $successfulMessage = 'Product successfully found by SKU.'; /** - * Assert that product can be searched via Quick Search using searchable product attributes (Search by SKU). + * Assert that product can be searched via Quick Search using searchable product attributes (Search by SKU) * * @param CatalogsearchResult $catalogSearchResult * @param CmsIndex $cmsIndex @@ -73,8 +73,8 @@ public function processAssert( if ($product->getVisibility() === 'Catalog' || $product->getQuantityAndStockStatus() === 'Out of Stock') { $isVisible = !($catalogSearchResult->getListProductBlock()->isProductVisible($product->getName())); - $this->errorMessage = 'Product successfully found by SKU'; - $this->successfulMessage = 'The product has not been found by SKU'; + $this->errorMessage = 'Product successfully found by SKU.'; + $this->successfulMessage = 'The product has not been found by SKU.'; } else { $isVisible = $catalogSearchResult->getListProductBlock()->isProductVisible($product->getName()); } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSkuAutoGenerated.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSkuAutoGenerated.php index c8e30f4c41e48..f43094d78dcf3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSkuAutoGenerated.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductSkuAutoGenerated.php @@ -58,12 +58,12 @@ public function processAssert(FixtureInterface $product, CatalogProductIndex $pr } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ public function toString() { - return 'Sku successfully generated'; + return 'Sku successfully generated.'; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductVisibleInCategory.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductVisibleInCategory.php index de868e8d8a941..36268f5db5f3a 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductVisibleInCategory.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductVisibleInCategory.php @@ -82,8 +82,8 @@ public function processAssert( if ($product->getVisibility() === 'Search' || $product->getQuantityAndStockStatus() === 'Out of Stock') { $isProductVisible = !$isProductVisible; - $this->errorMessage = 'Product found in this category'; - $this->successfulMessage = 'Asserts that the product could not be found in this category'; + $this->errorMessage = 'Product found in this category.'; + $this->successfulMessage = 'Asserts that the product could not be found in this category.'; } \PHPUnit_Framework_Assert::assertTrue( @@ -93,7 +93,7 @@ public function processAssert( } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertSpecialPriceOnProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertSpecialPriceOnProductPage.php index 3bdec2b01e2bf..aa17ed49c67a0 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertSpecialPriceOnProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertSpecialPriceOnProductPage.php @@ -53,8 +53,10 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt $catalogProductView->open(); $fields = $product->getData(); $specialPrice = $catalogProductView->getViewBlock()->getProductPrice(); - $specialPrice = isset($specialPrice['price_special_price']) ? $specialPrice['price_special_price'] : null; - if (!empty($fields['special_price'])) { + $specialPrice = (isset($specialPrice['price_special_price'])) + ? $specialPrice['price_special_price'] + : null; + if (isset($fields['special_price'])) { \PHPUnit_Framework_Assert::assertEquals( $fields['special_price'], $specialPrice, @@ -64,12 +66,12 @@ public function processAssert(CatalogProductView $catalogProductView, FixtureInt } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ public function toString() { - return "Assert that displayed special price on product page equals passed from fixture"; + return "Assert that displayed special price on product page equals passed from fixture."; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertTierPriceOnProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertTierPriceOnProductPage.php index a7642631be0b9..221acb64db489 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertTierPriceOnProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertTierPriceOnProductPage.php @@ -92,12 +92,12 @@ protected function assertTierPrice(FixtureInterface $product, CatalogProductView } /** - * Returns a string representation of the object. + * Returns a string representation of the object * * @return string */ public function toString() { - return 'Tier price is displayed on the product page'; + return 'Tier price is displayed on the product page.'; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.php index 65bbb63233883..e4422708a4ecb 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple.php @@ -92,9 +92,11 @@ public function __construct( protected $defaultDataSet = [ 'name' => 'Test simple product %isolation%', 'sku' => 'test_simple_sku_%isolation%', + 'attribute_set_id' => 'Default', 'price' => ['value' => 100.00], 'weight' => 12.0000, - 'qty' => 10 + 'qty' => 10, + 'quantity_and_stock_status' => 'In Stock', ]; protected $category_ids = [ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomOptions.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomOptions.php index b1aec4809ba0c..3750cbc12c754 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomOptions.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/CustomOptions.php @@ -216,6 +216,62 @@ protected function getPreset($name) ] ] ] + ], + 'default' => [ + [ + 'title' => 'custom option drop down', + 'is_require' => 'Yes', + 'type' => 'Drop-down', + 'options' => [ + [ + 'title' => '10 percent', + 'price' => 10, + 'price_type' => 'Percent', + 'sku' => 'sku_drop_down_row_1' + ] + ] + ], + [ + 'title' => 'custom option drop down2', + 'is_require' => 'Yes', + 'type' => 'Drop-down', + 'options' => [ + [ + 'title' => '20 percent', + 'price' => 20, + 'price_type' => 'Percent', + 'sku' => 'sku_drop_down_row_2' + ] + ] + ] + ], + 'two_options' => [ + [ + 'title' => 'custom option drop down', + 'is_require' => 'Yes', + 'type' => 'Drop-down', + 'options' => [ + [ + 'title' => '10 percent', + 'price' => 10, + 'price_type' => 'Percent', + 'sku' => 'sku_drop_down_row_1' + ] + ] + ], + [ + 'title' => 'custom option drop down2', + 'is_require' => 'Yes', + 'type' => 'Drop-down', + 'options' => [ + [ + 'title' => '20 percent', + 'price' => 20, + 'price_type' => 'Percent', + 'sku' => 'sku_drop_down_row_2' + ] + ] + ] ] ]; if (!isset($presets[$name])) { diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php index 38d0010f5228d..0964f7e4330ed 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/CatalogProductSimple/GroupPriceOptions.php @@ -105,6 +105,13 @@ protected function getPreset($name) 'website' => 'All Websites [USD]', 'customer_group' => 'NOT LOGGED IN' ] + ], + 'default' => [ + [ + 'price' => 20, + 'website' => 'All Websites [USD]', + 'customer_group' => 'NOT LOGGED IN' + ] ] ]; if (!isset($presets[$name])) { diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index 7bcaacf689eb8..b01de33862679 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -38,11 +38,54 @@ */ class Curl extends AbstractCurl implements CatalogProductSimpleInterface { + /** + * Placeholder for data sent Curl + * + * @var array + */ + protected $placeholderData = [ + 'manage_stock' => [ + 'Yes' => 1, + 'No' => 0 + ], + 'is_virtual' => [ + 'Yes' => 1 + ], + 'inventory_manage_stock' => [ + 'Yes' => 1, + 'No' => 0 + ], + 'quantity_and_stock_status' => [ + 'In Stock' => 1, + 'Out of Stock' => 0 + ], + 'visibility' => [ + 'Not Visible Individually' => 1, + 'Catalog' => 2, + 'Search' => 3, + 'Catalog, Search' => 4 + ], + 'tax_class_id' => [ + 'None' => 0, + 'Taxable Goods' => 2 + ], + 'website_ids' => [ + 'Main Website' => 1 + ], + 'status' => [ + 'Product offline' => 2, + 'Product online' => 1 + ], + 'attribute_set_id' => [ + 'Default' => 4 + ] + ]; + /** * Post request for creating simple product * * @param FixtureInterface $fixture [optional] - * @return mixed|string + * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) @@ -52,6 +95,17 @@ public function persist(FixtureInterface $fixture = null) // @todo remove "if" when fixtures refactored if ($fixture instanceof InjectableFixture) { $fields = $fixture->getData(); + // Apply a placeholder for data + array_walk_recursive( + $fields, + function (&$item, $key, $placeholder) { + $item = isset($placeholder[$key][$item]) ? $placeholder[$key][$item] : $item; + }, + $this->placeholderData + ); + + $fields = $this->prepareStockData($fields); + if ($prefix) { $data[$prefix] = $fields; } else { @@ -79,6 +133,54 @@ public function persist(FixtureInterface $fixture = null) return ['id' => $id]; } + /** + * Preparation of stock data + * + * @param array $fields + * @return array + */ + protected function prepareStockData(array $fields) + { + $fields['stock_data']['manage_stock'] = 0; + + if (empty($fields['stock_data']['is_in_stock'])) { + $fields['stock_data']['is_in_stock'] = isset($fields['quantity_and_stock_status']) + ? $fields['quantity_and_stock_status'] + : (isset($fields['inventory_manage_stock']) ? $fields['inventory_manage_stock'] : null); + } + if (empty($fields['stock_data']['qty'])) { + $fields['stock_data']['qty'] = isset($fields['qty']) ? $fields['qty'] : null; + } + if (!empty($fields['stock_data']['qty']) || !empty($fields['stock_data']['is_in_stock'])) { + $fields['stock_data']['manage_stock'] = 1; + } + + $fields['quantity_and_stock_status'] = [ + 'qty' => $fields['stock_data']['qty'], + 'is_in_stock' => $fields['stock_data']['is_in_stock'] + ]; + + return $this->filter($fields); + } + + /** + * Remove items from a null + * + * @param array $data + * @return array + */ + protected function filter(array $data) + { + foreach ($data as $key => $value) { + if ($value === null) { + unset($data[$key]); + } elseif (is_array($data[$key])) { + $data[$key] = $this->filter($data[$key]); + } + } + return $data; + } + /** * Prepare POST data for creating product request * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.php index d0376a8e0f048..825424bcce1c4 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.php @@ -58,7 +58,7 @@ class CatalogCategoryView extends FrontendPage 'class' => 'Magento\Catalog\Test\Block\Product\ProductList\Toolbar', 'locator' => '.pages .items', 'strategy' => 'css selector', - ], + ] ]; /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.php index 0b047f6fae11b..8e0b3d43f38f9 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Product/CatalogProductView.php @@ -29,10 +29,14 @@ /** * Class CatalogProductView + * * Frontend product view page */ class CatalogProductView extends FrontendPage { + /** + * URL for catalog product grid + */ const MCA = 'catalog/product/view'; protected $_blocks = [ @@ -90,12 +94,6 @@ class CatalogProductView extends FrontendPage 'locator' => '#customer-reviews', 'strategy' => 'css selector', ], - 'downloadableLinksBlock' => [ - 'name' => 'downloadableLinksBlock', - 'class' => 'Magento\Downloadable\Test\Block\Catalog\Product\Links', - 'locator' => '[data-container-for=downloadable-links]', - 'strategy' => 'css selector', - ], 'mapBlock' => [ 'name' => 'mapBlock', 'class' => 'Magento\Catalog\Test\Block\Product\Price', @@ -105,15 +103,13 @@ class CatalogProductView extends FrontendPage 'titleBlock' => [ 'name' => 'titleBlock', 'class' => 'Magento\Theme\Test\Block\Html\Title', - 'locator' => '.page.title h1.title', + 'locator' => '.page.title', 'strategy' => 'css selector', ] ]; /** * Custom constructor - * - * @return void */ protected function _init() { @@ -132,6 +128,8 @@ public function init(FixtureInterface $fixture) } /** + * Get product view block + * * @return \Magento\Catalog\Test\Block\Product\View */ public function getViewBlock() @@ -140,6 +138,8 @@ public function getViewBlock() } /** + * Get product options block + * * @return \Magento\Catalog\Test\Block\Product\View\CustomOptions */ public function getCustomOptionsBlock() @@ -203,14 +203,6 @@ public function getCrosssellBlock() return $this->getBlockInstance('crosssellBlock'); } - /** - * @return \Magento\Downloadable\Test\Block\Catalog\Product\Links - */ - public function getDownloadableLinksBlock() - { - return $this->getBlockInstance('downloadableLinksBlock'); - } - /** * @return \Magento\Catalog\Test\Block\Product\Price */ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.php index 5e506ad74a314..a80d41a60332f 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.php @@ -72,13 +72,15 @@ public function __construct(array $defaultConfig = [], array $defaultData = []) 'category_ids' => ['presets' => 'default_subcategory'] ]; - $this->_data['product_without_category'] = [ - 'sku' => 'simple_product_without_category_%isolation%', - 'name' => 'Simple product without category %isolation%', + $this->_data['default'] = [ 'type_id' => 'simple', - 'attribute_set_id' => '4', - 'price' => ['value' => 100, 'preset' => '-'], - 'category_ids' => ['presets' => null] + 'attribute_set_id' => 'Default', + 'name' => 'Simple Product %isolation%', + 'sku' => 'sku_simple_product_%isolation%', + 'weight' => 1, + 'quantity_and_stock_status' => 'In Stock', + 'qty' => 25, + 'price' => ['value' => 560, 'preset' => '-'], ]; } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateProductSimpleEntityTest.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest.php similarity index 90% rename from dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateProductSimpleEntityTest.php rename to dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest.php index b69d1115890bd..4713711616341 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateProductSimpleEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest.php @@ -38,7 +38,7 @@ * * Precondition: * Category is created. - * Product is created. + * Product is created and assigned to created category. * * Steps: * 1. Login to backend. @@ -46,12 +46,12 @@ * 3. Select a product in the grid. * 4. Edit test value(s) according to dataset. * 5. Click "Save". - * 6. Perform asserts + * 6. Perform asserts. * * @group Products_(CS) * @ZephyrId MAGETWO-23544 */ -class UpdateProductSimpleEntityTest extends Injectable +class UpdateSimpleProductEntityTest extends Injectable { /** * Simple product fixture @@ -75,32 +75,41 @@ class UpdateProductSimpleEntityTest extends Injectable protected $editProductPage; /** - * Category fixture + * Prepare data * - * @var CatalogCategoryEntity + * @param CatalogCategoryEntity $category + * @return array */ - protected $category; + public function __prepare(CatalogCategoryEntity $category) + { + $category->persist(); + return [ + 'category' => $category + ]; + } /** * Injection data * * @param CatalogProductIndex $productGrid * @param CatalogProductEdit $editProductPage + * @param CatalogCategoryEntity $category * @param FixtureFactory $fixtureFactory * @return array */ public function __inject( CatalogProductIndex $productGrid, CatalogProductEdit $editProductPage, + CatalogCategoryEntity $category, FixtureFactory $fixtureFactory ) { $this->product = $fixtureFactory->createByCode( 'catalogProductSimple', [ - 'dataSet' => 'product_without_category', + 'dataSet' => 'default', 'data' => [ 'category_ids' => [ - 'category' => $this->category + 'category' => $category ] ] ] @@ -111,21 +120,6 @@ public function __inject( $this->editProductPage = $editProductPage; } - /** - * Prepare data - * - * @param CatalogCategoryEntity $category - * @return array - */ - public function __prepare(CatalogCategoryEntity $category) - { - $category->persist(); - $this->category = $category; - return [ - 'category' => $category - ]; - } - /** * Run update product simple entity test * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateProductSimpleEntityTest/testUpdate.csv b/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest/testUpdate.csv similarity index 100% rename from dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateProductSimpleEntityTest/testUpdate.csv rename to dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/UpdateSimpleProductEntityTest/testUpdate.csv diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/global/constraint.xml index 58b83ca973f79..a197598be462d 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/global/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/etc/global/constraint.xml @@ -56,7 +56,7 @@ - + @@ -74,7 +74,7 @@ - + @@ -141,7 +141,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Constraint/AssertSuggestSearchingResult.php b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Constraint/AssertSuggestSearchingResult.php new file mode 100644 index 0000000000000..b59049d3cd94b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Constraint/AssertSuggestSearchingResult.php @@ -0,0 +1,80 @@ +open(); + $searchBlock = $cmsIndex->getSearchBlock(); + + $queryText = $catalogSearch->getQueryText(); + $searchBlock->fillSearch($queryText); + + if ($amount = $catalogSearch->getNumResults()) { + $isVisible = $searchBlock->isSuggestSearchVisible($queryText, $amount); + } else { + $isVisible = $searchBlock->isSuggestSearchVisible($queryText); + } + + \PHPUnit_Framework_Assert::assertTrue( + $isVisible, + 'Block "Suggest Search" when searching was not found' + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Asserts window contains requested entity and quantity'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.php b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.php new file mode 100644 index 0000000000000..324f898ee20d7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.php @@ -0,0 +1,193 @@ + null, + 'is_active' => null, + 'updated_at' => null, + ]; + + protected $query_id = [ + 'attribute_code' => 'query_id', + 'backend_type' => 'int', + 'is_required' => '1', + 'default_value' => '', + 'input' => '', + ]; + + protected $query_text = [ + 'attribute_code' => 'query_text', + 'backend_type' => 'varchar', + 'is_required' => '', + 'default_value' => '', + 'input' => '', + 'source' => 'Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery\SearchData', + ]; + + protected $num_results = [ + 'attribute_code' => 'num_results', + 'backend_type' => 'int', + 'is_required' => '', + 'default_value' => '0', + 'input' => '', + ]; + + protected $popularity = [ + 'attribute_code' => 'popularity', + 'backend_type' => 'int', + 'is_required' => '', + 'default_value' => '0', + 'input' => '', + ]; + + protected $redirect = [ + 'attribute_code' => 'redirect', + 'backend_type' => 'varchar', + 'is_required' => '', + 'default_value' => '', + 'input' => '', + ]; + + protected $synonym_for = [ + 'attribute_code' => 'synonym_for', + 'backend_type' => 'varchar', + 'is_required' => '', + 'default_value' => '', + 'input' => '', + ]; + + protected $store_id = [ + 'attribute_code' => 'store_id', + 'backend_type' => 'smallint', + 'is_required' => '', + 'default_value' => '0', + 'input' => '', + ]; + + protected $display_in_terms = [ + 'attribute_code' => 'display_in_terms', + 'backend_type' => 'smallint', + 'is_required' => '', + 'default_value' => '1', + 'input' => '', + ]; + + protected $is_active = [ + 'attribute_code' => 'is_active', + 'backend_type' => 'smallint', + 'is_required' => '', + 'default_value' => '1', + 'input' => '', + ]; + + protected $is_processed = [ + 'attribute_code' => 'is_processed', + 'backend_type' => 'smallint', + 'is_required' => '', + 'default_value' => '0', + 'input' => '', + ]; + + protected $updated_at = [ + 'attribute_code' => 'updated_at', + 'backend_type' => 'timestamp', + 'is_required' => '', + 'default_value' => 'CURRENT_TIMESTAMP', + 'input' => '', + ]; + + public function getQueryId() + { + return $this->getData('query_id'); + } + + public function getQueryText() + { + return $this->getData('query_text'); + } + + public function getNumResults() + { + return $this->getData('num_results'); + } + + public function getPopularity() + { + return $this->getData('popularity'); + } + + public function getRedirect() + { + return $this->getData('redirect'); + } + + public function getSynonymFor() + { + return $this->getData('synonym_for'); + } + + public function getStoreId() + { + return $this->getData('store_id'); + } + + public function getDisplayInTerms() + { + return $this->getData('display_in_terms'); + } + + public function getIsActive() + { + return $this->getData('is_active'); + } + + public function getIsProcessed() + { + return $this->getData('is_processed'); + } + + public function getUpdatedAt() + { + return $this->getData('updated_at'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.xml b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.xml new file mode 100644 index 0000000000000..d4d8cbd51fec8 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery.xml @@ -0,0 +1,113 @@ + + + + Magento_CatalogSearch + flat + catalogsearch_query + Magento\CatalogSearch\Model\Resource\Query\Collection + + + query_id + int + 1 + + + + + query_text + varchar + + + + Magento\CatalogSearch\Test\Fixture\CatalogSearchQuery\SearchData + + + num_results + int + + 0 + + + + popularity + int + + 0 + + + + redirect + varchar + + + + + + synonym_for + varchar + + + + + + store_id + smallint + + 0 + + + + display_in_terms + smallint + + 1 + + + + is_active + smallint + + 1 + + + + is_processed + smallint + + 0 + + + + updated_at + timestamp + + CURRENT_TIMESTAMP + + + + Magento\CatalogSearch\Test\Repository\CatalogSearchQuery + Magento\CatalogSearch\Test\Handler\CatalogSearchQuery\CatalogSearchQueryInterface + diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/SearchData.php b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/SearchData.php new file mode 100644 index 0000000000000..3d1f9eedeca68 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/Fixture/CatalogSearchQuery/SearchData.php @@ -0,0 +1,92 @@ +params = $params; + $explodeValue = explode('::', $data['value']); + if (!empty($explodeValue) && count($explodeValue) > 1) { + /** @var FixtureInterface $fixture */ + $fixture = $fixtureFactory->createByCode($explodeValue[0]); + $fixture->persist(); + $this->data = $fixture->$explodeValue[1](); + } else { + $this->data = strval($data['value']); + } + } + + /** + * Persist custom selections products + * + * @return void + */ + public function persist() + { + // + } + + /** + * Return prepared data + * + * @param string|null $key + * @return string + */ + public function getData($key = null) + { + return $this->data; + } + + /** + * Return data set configuration settings + * + * @return array + */ + public function getDataConfig() + { + return $this->params; + } +} diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest.php b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest.php new file mode 100644 index 0000000000000..6ab76bc8d2eee --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest.php @@ -0,0 +1,63 @@ +open(); + $cmsIndex->getSearchBlock()->search($catalogSearch->getQueryText()); + } +} diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest/testSearch.csv b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest/testSearch.csv new file mode 100644 index 0000000000000..2843f836b276b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/TestCase/SuggestSearchingResultEntityTest/testSearch.csv @@ -0,0 +1,3 @@ +"catalogSearch/data/query_text/value";"catalogSearch/data/num_results";"constraint" +"catalogProductSimple::getName";"-";"assertSuggestSearchingResult" +"catalogProductSimple::getSku";"1";"assertSuggestSearchingResult" diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/constraint.xml new file mode 100644 index 0000000000000..123ca419303da --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/constraint.xml @@ -0,0 +1,34 @@ + + + + + high + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/fixture.xml b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/fixture.xml new file mode 100644 index 0000000000000..0ca4f481f402b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/CatalogSearch/Test/etc/global/fixture.xml @@ -0,0 +1,32 @@ + + + + + flat + catalogsearch_query + Magento\CatalogSearch\Model\Resource\Query\Collection + + diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerNotInGrid.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerNotInGrid.php new file mode 100644 index 0000000000000..e1cfd78cab5c3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerNotInGrid.php @@ -0,0 +1,72 @@ + $customer->getEmail() + ]; + + $customerIndexPage->open(); + \PHPUnit_Framework_Assert::assertFalse( + $customerIndexPage->getCustomerGridBlock()->isRowVisible($filter), + "Customer with email {$filter['email']} is present in Customer grid." + ); + } + + /** + * Success message if Customer not in grid + * + * @return string + */ + public function toString() + { + return 'Customer is absent in Customer grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerSuccessDeleteMessage.php b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerSuccessDeleteMessage.php new file mode 100644 index 0000000000000..977b903f0aa3e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/Constraint/AssertCustomerSuccessDeleteMessage.php @@ -0,0 +1,71 @@ +getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::DELETE_MESSAGE, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::DELETE_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Text success delete message is displayed + * + * @return string + */ + public function toString() + { + return 'Assert that success delete message is displayed.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest.php b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest.php new file mode 100644 index 0000000000000..02b14d07ae771 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest.php @@ -0,0 +1,93 @@ +customerIndexPage = $customerIndexPage; + $this->customerIndexEditPage = $customerIndexEditPage; + } + + /** + * Runs Delete Customer Backend Entity test + * + * @param CustomerInjectable $initialCustomer + * @return void + */ + public function testDeleteCustomerBackendEntity(CustomerInjectable $customer) + { + // Preconditions: + $customer->persist(); + + // Steps: + $filter = ['email' => $customer->getEmail()]; + $this->customerIndexPage->open(); + $this->customerIndexPage->getCustomerGridBlock()->searchAndOpen($filter); + $this->customerIndexEditPage->getPageActionsBlock()->delete(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest/testDeleteCustomerBackendEntity.csv b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest/testDeleteCustomerBackendEntity.csv new file mode 100644 index 0000000000000..20581464f19ca --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/TestCase/DeleteCustomerBackendEntityTest/testDeleteCustomerBackendEntity.csv @@ -0,0 +1,2 @@ +"customer/dataSet";"constraint" +"default";"assertCustomerSuccessDeleteMessage, assertCustomerNotInGrid" diff --git a/dev/tests/functional/tests/app/Magento/Customer/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/Customer/Test/etc/global/constraint.xml index 68b0d80fe8be6..7e62e8457fe49 100644 --- a/dev/tests/functional/tests/app/Magento/Customer/Test/etc/global/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/Customer/Test/etc/global/constraint.xml @@ -30,6 +30,12 @@ + + low + + + + low @@ -43,14 +49,13 @@ - + middle - - + - + middle @@ -59,15 +64,6 @@ - - middle - - - - - - - middle diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php index 5272ddc9cb88f..add2d50717a77 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable.php @@ -25,14 +25,13 @@ namespace Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab; use Mtf\Client\Element; -use Mtf\Factory\Factory; -use Mtf\Client\Driver\Selenium\Element as RootElement; use Magento\Backend\Test\Block\Widget\Tab; -use Magento\Bundle\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option; +use Mtf\Client\Element\Locator; /** * Class Downloadable * + * Product downloadable tab */ class Downloadable extends Tab { @@ -43,6 +42,54 @@ class Downloadable extends Tab */ protected $addNewRow = '[data-action=add-link]'; + /** + * Downloadable block + * + * @var string + */ + protected $downloadableBlock = '//dl[@id="tab_content_downloadableInfo"]'; + + /** + * Get Downloadable block + * + * @param string $type + * @param Element $element + * @return \Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Samples | + * \Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\Links + */ + public function getDownloadableBlock($type, Element $element = null) + { + $element = $element ? : $this->_rootElement; + return $this->blockFactory->create( + 'Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\\' . $type, + ['element' => $element->find($this->downloadableBlock, Locator::SELECTOR_XPATH)] + ); + } + + /** + * Get data to fields on downloadable tab + * + * @param array|null $fields + * @param Element|null $element + * @return array + */ + public function getDataFormTab($fields = null, Element $element = null) + { + $newFields = []; + if (isset($fields['downloadable_sample']['value'])) { + $newFields['downloadable_sample'] = $this->getDownloadableBlock('Samples')->getDataSamples( + $fields['downloadable_sample']['value'] + ); + } + if (isset($fields['downloadable_links']['value'])) { + $newFields['downloadable_links'] = $this->getDownloadableBlock('Links')->getDataLinks( + $fields['downloadable_links']['value'] + ); + } + + return $newFields; + } + /** * Fill downloadable information * @@ -52,13 +99,12 @@ class Downloadable extends Tab */ public function fillFormTab(array $fields, Element $element = null) { - if (isset($fields['downloadable'])) { - foreach ($fields['downloadable']['link'] as $index => $link) { - $element->find($this->addNewRow)->click(); - $linkRowBlock = Factory::getBlockFactory() - ->getMagentoDownloadableAdminhtmlCatalogProductEditTabDownloadableLinkRow($element); - $linkRowBlock->fill($index, $link); - } + if (isset($fields['downloadable_sample']['value'])) { + $this->getDownloadableBlock('Samples')->fillSamples($fields['downloadable_sample']['value']); + } + + if (isset($fields['downloadable_links']['value'])) { + $this->getDownloadableBlock('Links')->fillLinks($fields['downloadable_links']['value']); } return $this; diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.php index 8e493e267a6b4..d6cde4fe846bc 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.php @@ -23,40 +23,36 @@ */ namespace Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable; -use Mtf\Block\Block; -use Mtf\Client\Element\Locator; +use Mtf\Block\Form; -class LinkRow extends Block +/** + * Class LinkRow + * + * Form item links + */ +class LinkRow extends Form { /** - * Example: name="downloadable[link][1][price]" + * Fill item link * - * @var string + * @param array $fields + * @return void */ - protected $fieldSelectorTemplate = '[name="downloadable[link][%d][%s]"]'; + public function fillLinkRow(array $fields) + { + $mapping = $this->dataMapping($fields); + $this->_fill($mapping); + } /** - * @param int $rowIndex - * @param array $rowData + * Get data item link + * + * @param array $fields + * @return array */ - public function fill($rowIndex, $rowData) + public function getDataLinkRow(array $fields) { - foreach ([ - 'title', 'price', 'number_of_downloads', 'is_unlimited', - 'is_shareable', 'sample][type', 'sample][url', 'type', 'link_url', 'sort_order' - ] as $field) { - if (isset($rowData[$field]['value'])) { - $fieldSelector = sprintf($this->fieldSelectorTemplate, $rowIndex, $field); - /* @TODO replace with typified radio element */ - $type = isset($rowData[$field]['input']) ? $rowData[$field]['input'] : null; - if ($type == 'radio') { - $type = 'checkbox'; - $fieldSelector .= sprintf('[value=%s]', $rowData[$field]['value']); - $rowData[$field]['value'] = 'Yes'; - } - $this->_rootElement->find($fieldSelector, Locator::SELECTOR_CSS, $type) - ->setValue($rowData[$field]['value']); - } - } + $mapping = $this->dataMapping($fields); + return $this->_getData($mapping); } } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.xml new file mode 100644 index 0000000000000..0d9f64e628c1f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/LinkRow.xml @@ -0,0 +1,85 @@ + + + + + + <selector>[name$='[title]']</selector> + <strategy>css selector</strategy> + + + [name$='[price]'] + css selector + + + [name$='[number_of_downloads]'] + css selector + + + [name$='[is_unlimited]'] + css selector + checkbox + + + [name$='[is_shareable]'] + css selector + select + + + + [value='url'][name$='[sample][type]'] + css selector + checkbox + + + [value='file'][name$='[sample][type]'] + css selector + checkbox + + + [name$='[sample][url]'] + css selector + + + + [value='url'][name*='[type]']:not([name*='[sample]']) + css selector + checkbox + + + [value='file'][name*='[type]']:not([name*='[sample]']) + css selector + checkbox + + + [name$='[link_url]'] + css selector + + + [name$='[sort_order]'] + css selector + + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php new file mode 100644 index 0000000000000..cf65d7ffc3b47 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php @@ -0,0 +1,127 @@ +_rootElement; + return $this->blockFactory->create( + 'Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\LinkRow', + ['element' => $element->find(sprintf($this->rowBlock, ++$index), Locator::SELECTOR_XPATH)] + ); + } + + /** + * Fill links block + * + * @param array $fields + * @param Element $element + * @return void + */ + public function fillLinks(array $fields, Element $element = null) + { + $element = $element ? : $this->_rootElement; + if (!$element->find($this->title, Locator::SELECTOR_XPATH)->isVisible()) { + $element->find($this->showLinks, Locator::SELECTOR_XPATH)->click(); + } + $mapping = $this->dataMapping( + ['title' => $fields['title'], 'links_purchased_separately' => $fields['links_purchased_separately']] + ); + $this->_fill($mapping); + foreach ($fields['downloadable']['link'] as $index => $link) { + $element->find($this->addNewLinkRow, Locator::SELECTOR_XPATH)->click(); + $this->getRowBlock($index, $element)->fillLinkRow($link); + } + } + + /** + * Get data links block + * + * @param array|null $fields + * @param Element|null $element + * @return array + */ + public function getDataLinks(array $fields = null, Element $element = null) + { + $element = $element ? : $this->_rootElement; + if (!$element->find($this->title, Locator::SELECTOR_XPATH)->isVisible()) { + $element->find($this->showLinks, Locator::SELECTOR_XPATH)->click(); + } + $mapping = $this->dataMapping( + ['title' => $fields['title'], 'links_purchased_separately' => $fields['links_purchased_separately']] + ); + $newFields = $this->_getData($mapping); + foreach ($fields['downloadable']['link'] as $index => $link) { + $newFields['downloadable']['link'][$index] = $this->getRowBlock($index, $element) + ->getDataLinkRow($link); + } + return $newFields; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.xml new file mode 100644 index 0000000000000..64a6ef172a1e1 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.xml @@ -0,0 +1,38 @@ + + + + + + <selector>[name="product[links_title]"]</selector> + <strategy>css selector</strategy> + + + [name="product[links_purchased_separately]"] + css selector + select + + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.php new file mode 100644 index 0000000000000..4133fa8844586 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.php @@ -0,0 +1,57 @@ +dataMapping($fields); + $this->_fill($mapping); + } + + /** + * Get data item sample + * + * @param array $fields + * @return array + */ + public function getDataSampleRow(array $fields) + { + $mapping = $this->dataMapping($fields); + return $this->_getData($mapping); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.xml new file mode 100644 index 0000000000000..d417faa2a6336 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/SampleRow.xml @@ -0,0 +1,51 @@ + + + + + + <selector>[name$='[title]']</selector> + <strategy>css selector</strategy> + + + [value='file'][name$='[type]'] + css selector + checkbox + + + [value='url'][name$='[type]'] + css selector + checkbox + + + [name$='[sample_url]'] + css selector + + + [name$='[sort_order]'] + css selector + + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php new file mode 100644 index 0000000000000..2e11d2fdf678e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.php @@ -0,0 +1,123 @@ +_rootElement; + return $this->blockFactory->create( + 'Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Tab\Downloadable\SampleRow', + ['element' => $element->find(sprintf($this->rowBlock, ++$index), Locator::SELECTOR_XPATH)] + ); + } + + /** + * Fill samples block + * + * @param array|null $fields + * @param Element $element + * @return void + */ + public function fillSamples(array $fields = null, Element $element = null) + { + $element = $element ? : $this->_rootElement; + if (!$element->find($this->samplesTitle, Locator::SELECTOR_XPATH)->isVisible()) { + $element->find($this->showSample, Locator::SELECTOR_XPATH)->click(); + } + $mapping = $this->dataMapping(['title' => $fields['title']]); + $this->_fill($mapping); + foreach ($fields['downloadable']['sample'] as $index => $sample) { + $element->find($this->addNewSampleRow, Locator::SELECTOR_XPATH)->click(); + $this->getRowBlock($index, $element)->fillSampleRow($sample); + } + } + + /** + * Get data samples block + * + * @param array|null $fields + * @param Element|null $element + * @return array + */ + public function getDataSamples(array $fields = null, Element $element = null) + { + $element = $element ? : $this->_rootElement; + if (!$element->find($this->samplesTitle, Locator::SELECTOR_XPATH)->isVisible()) { + $element->find($this->showSample, Locator::SELECTOR_XPATH)->click(); + } + $mapping = $this->dataMapping(['title' => $fields['title']]); + $newFields = $this->_getData($mapping); + foreach ($fields['downloadable']['sample'] as $index => $sample) { + $newFields['downloadable']['sample'][$index] = $this->getRowBlock($index, $element) + ->getDataSampleRow($sample); + } + return $newFields; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.xml new file mode 100644 index 0000000000000..7e693a04c8d4e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Samples.xml @@ -0,0 +1,33 @@ + + + + + + <selector>[name="product[samples_title]"]</selector> + <strategy>css selector</strategy> + + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Backend/ProductForm.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Product/Form.xml similarity index 100% rename from dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Backend/ProductForm.xml rename to dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Adminhtml/Product/Form.xml diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View.php new file mode 100644 index 0000000000000..e00adf945ce1f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View.php @@ -0,0 +1,79 @@ +blockFactory->create( + 'Magento\Downloadable\Test\Block\Catalog\Product\View\Links', + [ + 'element' => $this->_rootElement->find($this->blockDownloadableLinks, Locator::SELECTOR_XPATH) + ] + ); + } + + /** + * Get downloadable samples block + * + * @return \Magento\Downloadable\Test\Block\Catalog\Product\View\Samples + */ + public function getDownloadableSamplesBlock() + { + return $this->blockFactory->create( + 'Magento\Downloadable\Test\Block\Catalog\Product\View\Samples', + [ + 'element' => $this->_rootElement->find($this->blockDownloadableSamples, Locator::SELECTOR_XPATH) + ] + ); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Links.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Links.php new file mode 100644 index 0000000000000..c0ca52627e921 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Links.php @@ -0,0 +1,128 @@ +linksListSelector, $index); + } + + /** + * Get title for links block + * + * @return string + */ + public function getTitleForLinkBlock() + { + return $this->_rootElement->find($this->titleForLink, Locator::SELECTOR_XPATH)->getText(); + } + + /** + * Get title for item link on data list + * + * @param int $index + * @return string + */ + public function getItemTitle($index) + { + return $this->_rootElement->find($this->formatIndex($index) . $this->titleForList, Locator::SELECTOR_XPATH) + ->getText(); + } + + /** + * Visible checkbox for item link on data list + * + * @param int $index + * @return bool + */ + public function isVisibleItemCheckbox($index) + { + return $this->_rootElement->find($this->formatIndex($index) . $this->separatelyForList, Locator::SELECTOR_XPATH) + ->isVisible(); + } + + /** + * Get price for item link on data list + * + * @param int $index + * @return string + */ + public function getItemPrice($index) + { + return $this->_rootElement->find($this->formatIndex($index) . $this->priceForList, Locator::SELECTOR_XPATH) + ->getText(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Samples.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Samples.php new file mode 100644 index 0000000000000..65ea689e839df --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Block/Catalog/Product/View/Samples.php @@ -0,0 +1,72 @@ +_rootElement->find($this->titleForSampleBlock, Locator::SELECTOR_XPATH)->getText(); + } + + /** + * Get title for item sample on data list + * + * @param int $index + * @return string + */ + public function getItemTitle($index) + { + $formatTitle = sprintf($this->titleForList, $index); + return $this->_rootElement->find($formatTitle, Locator::SELECTOR_XPATH)->getText(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableLinks.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableLinks.php new file mode 100644 index 0000000000000..4f77fa13534c3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableLinks.php @@ -0,0 +1,128 @@ +init($product); + $downloadableProductView->open(); + $linksBlock = $downloadableProductView->getDownloadableViewBlock()->getDownloadableLinksBlock(); + $fields = $product->getData(); + // Title for for Link block + \PHPUnit_Framework_Assert::assertEquals( + $linksBlock->getTitleForLinkBlock(), + $fields['downloadable_links']['title'], + 'Title for for Link block for downloadable product on front-end is not correct.' + ); + + $this->sortDownloadableArray($fields['downloadable_links']['downloadable']['link']); + + foreach ($fields['downloadable_links']['downloadable']['link'] as $index => $link) { + $index++; + // Titles for each links + // Links are displaying according to Sort Order + \PHPUnit_Framework_Assert::assertEquals( + $linksBlock->getItemTitle($index), + $link['title'], + 'Link item ' . $index . ' with title "' . $link['title'] . '" is not visible.' + ); + + // If Links can be Purchase Separately, check-nob is presented near each link + // If Links CANNOT be Purchase Separately, check-nob is not presented near each link + if ($fields['downloadable_links']['links_purchased_separately'] == "Yes") { + \PHPUnit_Framework_Assert::assertTrue( + $linksBlock->isVisibleItemCheckbox($index), + 'Item ' . $index . ' link block CANNOT be Purchase Separately.' + ); + // Price is equals passed according to fixture + $link['price'] = sprintf('$%1.2f', $link['price']); + \PHPUnit_Framework_Assert::assertEquals( + $linksBlock->getItemPrice($index), + $link['price'], + 'Link item ' . $index . ' price is not visible.' + ); + } elseif ($fields['downloadable_links']['links_purchased_separately'] == "No") { + \PHPUnit_Framework_Assert::assertFalse( + $linksBlock->isVisibleItemCheckbox($index), + 'Item ' . $index . ' link block can be Purchase Separately.' + ); + } + } + } + + /** + * Sort downloadable links array + * + * @param array $fields + * @return array + */ + protected function sortDownloadableArray(&$fields) + { + usort( + $fields, + function ($a, $b) { + if ($a['sort_order'] == $b['sort_order']) { + return 0; + } + return ($a['sort_order'] < $b['sort_order']) ? -1 : 1; + } + ); + } + + /** + * Text of Visible in downloadable assert for link block + * + * @return string + */ + public function toString() + { + return 'Link block for downloadable product on front-end is visible.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableProductForm.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableProductForm.php new file mode 100644 index 0000000000000..55fc50f6b2e9b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableProductForm.php @@ -0,0 +1,123 @@ + $product->getData('sku')]; + $productGrid->open()->getProductGrid()->searchAndOpen($filter); + + $fields = $this->prepareFixtureData($product); + $fields = $this->convertDownloadableArray($fields); + + $fieldsForm = $productPage->getForm()->getData($product); + \PHPUnit_Framework_Assert::assertEquals($fields, $fieldsForm, 'Form data not equals fixture data.'); + } + + /** + * Sort downloadable array + * + * @param array $fields + * @return array + */ + protected function sortDownloadableArray(&$fields) + { + usort( + $fields, + function ($a, $b) { + return $a['sort_order'] - $b['sort_order']; + } + ); + } + + /** + * Convert fixture array + * + * @param array $fields + * @return array + */ + protected function convertDownloadableArray(array $fields) + { + if (isset($fields['downloadable_links']['downloadable']['link'])) { + $this->sortDownloadableArray( + $fields['downloadable_links']['downloadable']['link'] + ); + } + if (isset($fields['downloadable_sample']['downloadable']['sample'])) { + $this->sortDownloadableArray( + $fields['downloadable_sample']['downloadable']['sample'] + ); + } + + foreach ($fields as $key => $value) { + if (is_array($value)) { + $fields[$key] = $this->convertDownloadableArray($value); + } else { + if ($key == "special_price") { + $fields[$key] = [$key => $fields[$key]]; + } + } + } + return $fields; + } + + /** + * Text of Visible in product form assert + * + * @return string + */ + public function toString() + { + return 'Form data equal the fixture data.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableSamplesData.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableSamplesData.php new file mode 100644 index 0000000000000..8beb8b74196c8 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Constraint/AssertDownloadableSamplesData.php @@ -0,0 +1,107 @@ +init($product); + $productView->open(); + $sampleBlock = $productView->getDownloadableViewBlock()->getDownloadableSamplesBlock(); + $fields = $product->getData(); + + // Title for for sample block + \PHPUnit_Framework_Assert::assertEquals( + $sampleBlock->getTitleForSampleBlock(), + $fields['downloadable_sample']['title'], + 'Title for for Samples block for downloadable product on front-end is not correct.' + ); + + $this->sortDownloadableArray($fields['downloadable_sample']['downloadable']['sample']); + + foreach ($fields['downloadable_sample']['downloadable']['sample'] as $index => $sample) { + // Titles for each sample + // Samples are displaying according to Sort Order + \PHPUnit_Framework_Assert::assertEquals( + $sampleBlock->getItemTitle(++$index), + $sample['title'], + 'Sample item ' . $index . ' with title "' . $sample['title'] . '" is not visible.' + ); + } + } + + /** + * Sort downloadable sample array + * + * @param array $fields + * @return array + */ + protected function sortDownloadableArray(&$fields) + { + usort( + $fields, + function ($a, $b) { + if ($a['sort_order'] == $b['sort_order']) { + return 0; + } + return ($a['sort_order'] < $b['sort_order']) ? -1 : 1; + } + ); + } + + /** + * Text of Visible in downloadable assert for sample block + * + * @return string + */ + public function toString() + { + return 'Sample block for downloadable product on front-end is visible.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.php new file mode 100644 index 0000000000000..1b9904168278a --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.php @@ -0,0 +1,939 @@ +data['url_key']) && isset($this->data['name'])) { + $this->data['url_key'] = trim(strtolower(preg_replace('#[^0-9a-z%]+#i', '-', $this->data['name'])), '-'); + } + + } + + protected $dataConfig = [ + 'create_url_params' => [ + 'type' => 'downloadable', + 'set' => '4', + ], + 'input_prefix' => 'product', + ]; + + protected $defaultDataSet = [ + 'name' => 'DownloadableProduct_%isolation%', + 'sku' => 'DownloadableProduct_%isolation%', + 'price' => '100', + 'tax_class' => 'Taxable Goods', + 'description' => 'This is description for downloadable product', + 'short_description' => 'This is short description for downloadable product', + 'quantity_and_stock_status_qty' => '1', + 'quantity_and_stock_status' => 'In Stock', + 'is_virtual' => 'Yes', + 'downloadable_links' => ['preset' => 'default'], + ]; + + protected $category_ids = [ + 'attribute_code' => 'category_ids', + 'backend_type' => 'static', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + 'fixture' => 'Magento\Catalog\Test\Fixture\CategoryIds' + ]; + + protected $cost = [ + 'attribute_code' => 'cost', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'price', + ]; + + protected $created_at = [ + 'attribute_code' => 'created_at', + 'backend_type' => 'static', + 'is_required' => '1', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $custom_design = [ + 'attribute_code' => 'custom_design', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'select', + ]; + + protected $custom_design_from = [ + 'attribute_code' => 'custom_design_from', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $custom_design_to = [ + 'attribute_code' => 'custom_design_to', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $custom_layout_update = [ + 'attribute_code' => 'custom_layout_update', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'textarea', + ]; + + protected $description = [ + 'attribute_code' => 'description', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => 'This is description for downloadable product', + 'input' => 'textarea', + 'group' => 'product-details' + ]; + + protected $gallery = [ + 'attribute_code' => 'gallery', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'gallery', + ]; + + protected $gift_message_available = [ + 'attribute_code' => 'gift_message_available', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'select', + ]; + + protected $group_price = [ + 'attribute_code' => 'group_price', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + 'group' => 'advanced-pricing', + 'fixture' => 'Magento\Catalog\Test\Fixture\CatalogProductSimple\GroupPriceOptions' + ]; + + protected $has_options = [ + 'attribute_code' => 'has_options', + 'backend_type' => 'static', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $image = [ + 'attribute_code' => 'image', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'media_image', + ]; + + protected $image_label = [ + 'attribute_code' => 'image_label', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $is_returnable = [ + 'attribute_code' => 'is_returnable', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '2', + 'input' => 'select', + ]; + + protected $links_exist = [ + 'attribute_code' => 'links_exist', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '0', + 'input' => '', + ]; + + protected $links_purchased_separately = [ + 'attribute_code' => 'links_purchased_separately', + 'backend_type' => 'int', + 'is_required' => '1', + 'default_value' => '', + 'input' => '', + ]; + + protected $links_title = [ + 'attribute_code' => 'links_title', + 'backend_type' => 'varchar', + 'is_required' => '1', + 'default_value' => '', + 'input' => '', + ]; + + protected $media_gallery = [ + 'attribute_code' => 'media_gallery', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'gallery', + ]; + + protected $meta_description = [ + 'attribute_code' => 'meta_description', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'textarea', + ]; + + protected $meta_keyword = [ + 'attribute_code' => 'meta_keyword', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'textarea', + ]; + + protected $meta_title = [ + 'attribute_code' => 'meta_title', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $minimal_price = [ + 'attribute_code' => 'minimal_price', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'price', + ]; + + protected $msrp = [ + 'attribute_code' => 'msrp', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'price', + ]; + + protected $msrp_display_actual_price_type = [ + 'attribute_code' => 'msrp_display_actual_price_type', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '4', + 'input' => 'select', + ]; + + protected $msrp_enabled = [ + 'attribute_code' => 'msrp_enabled', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '2', + 'input' => 'select', + ]; + + protected $name = [ + 'attribute_code' => 'name', + 'backend_type' => 'varchar', + 'is_required' => '1', + 'default_value' => '', + 'input' => 'text', + 'group' => 'product-details', + ]; + + protected $news_from_date = [ + 'attribute_code' => 'news_from_date', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $news_to_date = [ + 'attribute_code' => 'news_to_date', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $old_id = [ + 'attribute_code' => 'old_id', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $options_container = [ + 'attribute_code' => 'options_container', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => 'container2', + 'input' => 'select', + ]; + + protected $page_layout = [ + 'attribute_code' => 'page_layout', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'select', + ]; + + protected $price = [ + 'attribute_code' => 'price', + 'backend_type' => 'decimal', + 'is_required' => '1', + 'default_value' => '', + 'input' => 'price', + 'group' => 'product-details' + ]; + + protected $inventory_manage_stock = [ + 'attribute_code' => 'inventory_manage_stock', + 'input' => 'select', + 'group' => 'advanced-inventory', + ]; + + protected $stock_data_min_qty= [ + 'attribute_code' => 'stock_data_min_qty', + 'input' => 'text', + 'group' => 'advanced-inventory', + ]; + + protected $stock_data_use_config_min_qty = [ + 'attribute_code' => 'stock_data_use_config_min_qty', + 'input' => 'checkbox', + 'group' => 'advanced-inventory' + ]; + + protected $inventory_qty = [ + 'attribute_code' => 'inventory_qty', + 'input' => 'text', + 'group' => 'advanced-inventory', + ]; + + protected $quantity_and_stock_status = [ + 'attribute_code' => 'quantity_and_stock_status', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '1', + 'input' => 'select', + 'group' => 'product-details', + ]; + + protected $qty = [ + 'attribute_code' => 'qty', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '1', + 'input' => 'text', + 'group' => 'product-details', + ]; + + protected $related_tgtr_position_behavior = [ + 'attribute_code' => 'related_tgtr_position_behavior', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $related_tgtr_position_limit = [ + 'attribute_code' => 'related_tgtr_position_limit', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $required_options = [ + 'attribute_code' => 'required_options', + 'backend_type' => 'static', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $samples_title = [ + 'attribute_code' => 'samples_title', + 'backend_type' => 'varchar', + 'is_required' => '1', + 'default_value' => '', + 'input' => '', + ]; + + protected $short_description = [ + 'attribute_code' => 'short_description', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => 'This is short description for downloadable product', + 'input' => 'textarea', + 'group' => 'autosettings' + ]; + + protected $downloadable_links = [ + 'attribute_code' => 'downloadable_items', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => 'dafault', + 'input' => 'text', + 'group' => 'downloadable_information', + 'fixture' => 'Magento\Downloadable\Test\Fixture\CatalogProductDownloadable\Links' + + ]; + + protected $downloadable_sample = [ + 'attribute_code' => 'downloadable_sample', + 'backend_type' => 'text', + 'is_required' => '0', + 'default_value' => 'dafault', + 'input' => 'text', + 'group' => 'downloadable_information', + 'fixture' => 'Magento\Downloadable\Test\Fixture\CatalogProductDownloadable\Samples' + + ]; + + protected $sku = [ + 'attribute_code' => 'sku', + 'backend_type' => 'static', + 'is_required' => '1', + 'default_value' => '', + 'input' => 'text', + 'group' => 'product-details', + ]; + + protected $small_image = [ + 'attribute_code' => 'small_image', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'media_image', + ]; + + protected $small_image_label = [ + 'attribute_code' => 'small_image_label', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $special_from_date = [ + 'attribute_code' => 'special_from_date', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $special_price = [ + 'attribute_code' => 'special_price', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '10', + 'group' => 'advanced-pricing' + ]; + + protected $special_to_date = [ + 'attribute_code' => 'special_to_date', + 'backend_type' => 'datetime', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'date', + ]; + + protected $status = [ + 'attribute_code' => 'status', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '1', + 'input' => 'select', + ]; + + protected $tax_class_id = [ + 'attribute_code' => 'tax_class_id', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '2', + 'input' => 'select', + 'group' => 'product-details' + ]; + + protected $thumbnail = [ + 'attribute_code' => 'thumbnail', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'media_image', + ]; + + protected $thumbnail_label = [ + 'attribute_code' => 'thumbnail_label', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $tier_price = [ + 'attribute_code' => 'tier_price', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => 'default', + 'input' => 'text', + 'group' => 'advanced-pricing', + 'fixture' => 'Magento\Catalog\Test\Fixture\CatalogProductSimple\TierPriceOptions' + ]; + + protected $updated_at = [ + 'attribute_code' => 'updated_at', + 'backend_type' => 'static', + 'is_required' => '1', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $upsell_tgtr_position_behavior = [ + 'attribute_code' => 'upsell_tgtr_position_behavior', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $upsell_tgtr_position_limit = [ + 'attribute_code' => 'upsell_tgtr_position_limit', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $url_key = [ + 'attribute_code' => 'url_key', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + 'group' => 'autosettings' + ]; + + protected $url_path = [ + 'attribute_code' => 'url_path', + 'backend_type' => 'varchar', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'text', + ]; + + protected $visibility = [ + 'attribute_code' => 'visibility', + 'backend_type' => 'int', + 'is_required' => '0', + 'default_value' => '4', + 'input' => 'select', + ]; + + protected $weight = [ + 'attribute_code' => 'weight', + 'backend_type' => 'decimal', + 'is_required' => '0', + 'default_value' => '', + 'input' => 'weight', + ]; + + protected $custom_options = [ + 'attribute_code' => 'custom_options', + 'backend_type' => 'virtual', + 'is_required' => '0', + 'default_value' => 'default', + 'group' => 'customer-options', + 'fixture' => 'Magento\Catalog\Test\Fixture\CatalogProductSimple\CustomOptions', + ]; + + protected $id = [ + 'attribute_code' => 'id', + 'backend_type' => 'virtual', + ]; + + public function getCategoryIds() + { + return $this->getData('category_ids'); + } + + public function getCost() + { + return $this->getData('cost'); + } + + public function getCreatedAt() + { + return $this->getData('created_at'); + } + + public function getCustomDesign() + { + return $this->getData('custom_design'); + } + + public function getCustomDesignFrom() + { + return $this->getData('custom_design_from'); + } + + public function getCustomDesignTo() + { + return $this->getData('custom_design_to'); + } + + public function getCustomLayoutUpdate() + { + return $this->getData('custom_layout_update'); + } + + public function getDescription() + { + return $this->getData('description'); + } + + public function getGallery() + { + return $this->getData('gallery'); + } + + public function getGiftMessageAvailable() + { + return $this->getData('gift_message_available'); + } + + public function getGroupPrice() + { + return $this->getData('group_price'); + } + + public function getHasOptions() + { + return $this->getData('has_options'); + } + + public function getImage() + { + return $this->getData('image'); + } + + public function getImageLabel() + { + return $this->getData('image_label'); + } + + public function getIsReturnable() + { + return $this->getData('is_returnable'); + } + + public function getLinksExist() + { + return $this->getData('links_exist'); + } + + public function getLinksPurchasedSeparately() + { + return $this->getData('links_purchased_separately'); + } + + public function getLinksTitle() + { + return $this->getData('links_title'); + } + + public function getMediaGallery() + { + return $this->getData('media_gallery'); + } + + public function getMetaDescription() + { + return $this->getData('meta_description'); + } + + public function getMetaKeyword() + { + return $this->getData('meta_keyword'); + } + + public function getMetaTitle() + { + return $this->getData('meta_title'); + } + + public function getMinimalPrice() + { + return $this->getData('minimal_price'); + } + + public function getMsrp() + { + return $this->getData('msrp'); + } + + public function getMsrpDisplayActualPriceType() + { + return $this->getData('msrp_display_actual_price_type'); + } + + public function getMsrpEnabled() + { + return $this->getData('msrp_enabled'); + } + + public function getName() + { + return $this->getData('name'); + } + + public function getNewsFromDate() + { + return $this->getData('news_from_date'); + } + + public function getNewsToDate() + { + return $this->getData('news_to_date'); + } + + public function getOldId() + { + return $this->getData('old_id'); + } + + public function getOptionsContainer() + { + return $this->getData('options_container'); + } + + public function getPageLayout() + { + return $this->getData('page_layout'); + } + + public function getPrice() + { + return $this->getData('price'); + } + + public function getQuantityAndStockStatus() + { + return $this->getData('quantity_and_stock_status'); + } + + public function getRelatedTgtrPositionBehavior() + { + return $this->getData('related_tgtr_position_behavior'); + } + + public function getRelatedTgtrPositionLimit() + { + return $this->getData('related_tgtr_position_limit'); + } + + public function getRequiredOptions() + { + return $this->getData('required_options'); + } + + public function getSamplesTitle() + { + return $this->getData('samples_title'); + } + + public function getShortDescription() + { + return $this->getData('short_description'); + } + + public function getSku() + { + return $this->getData('sku'); + } + + public function getSmallImage() + { + return $this->getData('small_image'); + } + + public function getSmallImageLabel() + { + return $this->getData('small_image_label'); + } + + public function getSpecialFromDate() + { + return $this->getData('special_from_date'); + } + + public function getSpecialPrice() + { + return $this->getData('special_price'); + } + + public function getSpecialToDate() + { + return $this->getData('special_to_date'); + } + + public function getStatus() + { + return $this->getData('status'); + } + + public function getTaxClassId() + { + return $this->getData('tax_class_id'); + } + + public function getThumbnail() + { + return $this->getData('thumbnail'); + } + + public function getThumbnailLabel() + { + return $this->getData('thumbnail_label'); + } + + public function getTierPrice() + { + return $this->getData('tier_price'); + } + + public function getUpdatedAt() + { + return $this->getData('updated_at'); + } + + public function getUpsellTgtrPositionBehavior() + { + return $this->getData('upsell_tgtr_position_behavior'); + } + + public function getUpsellTgtrPositionLimit() + { + return $this->getData('upsell_tgtr_position_limit'); + } + + public function getUrlKey() + { + return $this->getData('url_key'); + } + + public function getUrlPath() + { + return $this->getData('url_path'); + } + + public function getVisibility() + { + return $this->getData('visibility'); + } + + public function getWeight() + { + return $this->getData('weight'); + } + + public function getId() + { + return $this->getData('id'); + } + + public function getCustomOptions() + { + return $this->getData('custom_options'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.xml new file mode 100644 index 0000000000000..bf08f36eef698 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable.xml @@ -0,0 +1,479 @@ + + + + Magento_Downloadable + eav + catalog_product + downloadable + Magento\Catalog\Model\Resource\Product\Collection + sku + + + category_ids + static + 0 + + text + + + cost + decimal + 0 + + price + + + created_at + static + 1 + + text + + + custom_design + varchar + 0 + + select + + + custom_design_from + datetime + 0 + + date + + + custom_design_to + datetime + 0 + + date + + + custom_layout_update + text + 0 + + textarea + + + description + text + 0 + + textarea + + + gallery + varchar + 0 + + gallery + + + gift_message_available + varchar + 0 + + select + + + group_price + decimal + 0 + + text + + + has_options + static + 0 + + text + + + image + varchar + 0 + + media_image + + + image_label + varchar + 0 + + text + + + is_returnable + varchar + 0 + 2 + select + + + links_exist + int + 0 + 0 + + + + links_purchased_separately + int + 1 + + + + + links_title + varchar + 1 + + + + + media_gallery + varchar + 0 + + gallery + + + meta_description + varchar + 0 + + textarea + + + meta_keyword + text + 0 + + textarea + + + meta_title + varchar + 0 + + text + + + minimal_price + decimal + 0 + + price + + + msrp + decimal + 0 + + price + + + msrp_display_actual_price_type + varchar + 0 + 4 + select + + + msrp_enabled + varchar + 0 + 2 + select + + + name + varchar + 1 + + text + + + news_from_date + datetime + 0 + + date + + + news_to_date + datetime + 0 + + date + + + old_id + int + 0 + + text + + + options_container + varchar + 0 + container2 + select + + + page_layout + varchar + 0 + + select + + + price + decimal + 1 + + price + + + quantity_and_stock_status][qty + int + 0 + 1 + select + + + related_tgtr_position_behavior + int + 0 + + text + + + related_tgtr_position_limit + int + 0 + + text + + + required_options + static + 0 + + text + + + samples_title + varchar + 1 + + + + + short_description + text + 0 + + textarea + + + sku + static + 1 + + text + + + small_image + varchar + 0 + + media_image + + + small_image_label + varchar + 0 + + text + + + special_from_date + datetime + 0 + + date + + + special_price + decimal + 0 + + + + special_to_date + datetime + 0 + + date + + + status + int + 0 + 1 + select + + + tax_class_id + int + 0 + 2 + select + + + thumbnail + varchar + 0 + + media_image + + + thumbnail_label + varchar + 0 + + text + + + tier_price + decimal + 0 + + text + + + updated_at + static + 1 + + text + + + upsell_tgtr_position_behavior + int + 0 + + text + + + upsell_tgtr_position_limit + int + 0 + + text + + + url_key + varchar + 0 + + text + + + url_path + varchar + 0 + + text + + + visibility + int + 0 + 4 + select + + + weight + decimal + 0 + + weight + + + id + virtual + + + inventory_manage_stock + select + + + quantity_and_stock_status + select + + + inventory_qty + text + + + stock_data_use_config_min_qty + checkbox + + + stock_data_min_qty + text + + + + + + + + + + + + + + + + downloadable + 4 + + product + + Magento\Downloadable\Test\Repository\CatalogProductDownloadable + + Magento\Downloadable\Test\Handler\CatalogProductDownloadable\CatalogProductDownloadableInterface + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Links.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Links.php new file mode 100644 index 0000000000000..0fdcb311173e0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Links.php @@ -0,0 +1,177 @@ +params = $params; + if (isset($data['preset'])) { + $this->data = $this->getPreset($data['preset']); + } + } + + /** + * Persist group price + * + * @return void + */ + public function persist() + { + // + } + + /** + * Return prepared data set + * + * @param string $key [optional] + * @return mixed + */ + public function getData($key = null) + { + return $this->data; + } + + /** + * Return data set configuration settings + * + * @return string + */ + public function getDataConfig() + { + return $this->params; + } + + /** + * Preset array for downloadable links + * + * @param string $name + * @return array|null + */ + protected function getPreset($name) + { + $presets = [ + 'default' => [ + 'title' => 'Links%isolation%', + 'links_purchased_separately' => 'Yes', + 'downloadable' => [ + 'link' => [ + [ + 'title' => 'link1%isolation%', + 'price' => 2.43, + 'number_of_downloads' => 2, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example.com', + 'is_shareable' => 'No', + 'sort_order' => 1 + ], + [ + 'title' => 'link2%isolation%', + 'price' => 3, + 'number_of_downloads' => 3, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example3.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example3.com', + 'is_shareable' => 'Yes', + 'sort_order' => 0 + ], + ] + ] + ], + 'with_three_links' => [ + 'title' => 'Links%isolation%', + 'links_purchased_separately' => 'Yes', + 'downloadable' => [ + 'link' => [ + [ + 'title' => 'link1%isolation%', + 'price' => 2.43, + 'number_of_downloads' => 2, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example.com', + 'is_shareable' => 'No', + 'sort_order' => 0 + ], + [ + 'title' => 'link2%isolation%', + 'price' => 3, + 'number_of_downloads' => 3, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example3.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example3.com', + 'is_shareable' => 'Yes', + 'sort_order' => 1 + ], + [ + 'title' => 'link3%isolation%', + 'price' => 5.43, + 'number_of_downloads' => 5, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example3.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example3.com', + 'is_shareable' => 'Yes', + 'sort_order' => 2 + ] + ] + ] + ] + ]; + if (!isset($presets[$name])) { + return null; + } + return $presets[$name]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Samples.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Samples.php new file mode 100644 index 0000000000000..cff42de45c750 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/CatalogProductDownloadable/Samples.php @@ -0,0 +1,140 @@ +params = $params; + if (isset($data['preset'])) { + $this->data = $this->getPreset($data['preset']); + } + } + + /** + * Persist group price + * + * @return void + */ + public function persist() + { + // + } + + /** + * Return prepared data set + * + * @param string $key [optional] + * @return mixed + */ + public function getData($key = null) + { + return $this->data; + } + + /** + * Return data set configuration settings + * + * @return string + */ + public function getDataConfig() + { + return $this->params; + } + + /** + * Preset array for downloadable samples + * + * @param string $name + * @return array|null + */ + protected function getPreset($name) + { + $presets = [ + 'default' => [ + 'title' => 'Samples%isolation%', + 'downloadable' => [ + 'sample' => [ + [ + 'title' => 'sample1%isolation%', + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example.com', + 'sort_order' => 0 + ], + [ + 'title' => 'sample2%isolation%', + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example2.com', + 'sort_order' => 1 + ] + ] + ] + ], + 'with_three_samples' => [ + 'title' => 'Samples%isolation%', + 'downloadable' => [ + 'sample' => [ + [ + 'title' => 'sample1%isolation%', + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example.com', + 'sort_order' => 0 + ], + [ + 'title' => 'sample2%isolation%', + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example2.com', + 'sort_order' => 1 + ], + [ + 'title' => 'sample3%isolation%', + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example3.com', + 'sort_order' => 2 + ] + ] + ] + ] + ]; + if (!isset($presets[$name])) { + return null; + } + return $presets[$name]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct.php index 0540fe6e0779d..2cf30517f9034 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct.php @@ -26,6 +26,10 @@ use Mtf\Factory\Factory; use Magento\Catalog\Test\Fixture\Product; +/** + * Class DownloadableProduct + * Fixture for Downloadable product + */ class DownloadableProduct extends Product { const GROUP = 'downloadable_information'; @@ -55,14 +59,7 @@ protected function _initData() 'price' => [ 'value' => '1', 'group' => static::GROUP_PRODUCT_DETAILS - ], - 'downloadable_link_purchase_type' => [ - 'value' => 'Yes', - 'input_value' => '1', - 'group' => static::GROUP, - 'input' => 'select', - 'input_name' => 'links_purchased_separately' - ], + ] ); $this->_data['fields'] = $data + $this->_data['fields']; diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksNotPurchasedSeparately.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksNotPurchasedSeparately.php index cf7c630a14f54..cdaebcff139fd 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksNotPurchasedSeparately.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksNotPurchasedSeparately.php @@ -26,10 +26,14 @@ use Mtf\Factory\Factory; use Magento\Downloadable\Test\Fixture\DownloadableProduct; +/** + * Class LinksNotPurchasedSeparately + * Init downloadable data not purchased separately + */ class LinksNotPurchasedSeparately extends LinksPurchasedSeparately { /** - * {inheritdoc} + * Init downloadable data */ protected function _initData() { diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksPurchasedSeparately.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksPurchasedSeparately.php index 1bc600cf159dd..b8b9ac44a1c2e 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksPurchasedSeparately.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Fixture/DownloadableProduct/LinksPurchasedSeparately.php @@ -26,10 +26,15 @@ use Mtf\Factory\Factory; use Magento\Downloadable\Test\Fixture\DownloadableProduct; +/** + * Class LinksPurchasedSeparately + * + * Init downloadable data purchased separately + */ class LinksPurchasedSeparately extends DownloadableProduct { /** - * {inheritdoc} + * Init downloadable data */ protected function _initData() { @@ -38,28 +43,30 @@ protected function _initData() $this->_data, [ 'fields' => [ - 'downloadable_link_purchase_type' => [ - 'value' => 'Yes', - 'input_value' => '1', - ], - 'downloadable' => [ - 'link' => [ - [ - 'title' => ['value' => 'row1'], - 'price' => ['value' => 2], - 'number_of_downloads' => ['value' => 2], - 'sample][type' => ['value' => 'url', 'input' => 'radio'], - 'sample][url' => ['value' => 'http://example.com'], - 'type' => ['value' => 'url', 'input' => 'radio'], - 'link_url' => ['value' => 'http://example.com'], - 'is_shareable' => [ // needed explicit default value for CURL handler - 'input' => 'select', - 'input_value' => static::LINK_IS_SHAREABLE_USE_CONFIG_VALUE, + 'downloadable_links' => [ + 'value' => [ + 'title' => 'Links%isolation%', + 'links_purchased_separately' => 'Yes', + 'downloadable' => [ + 'link' => [ + [ + 'title' => 'row1%isolation%', + 'price' => 2.43, + 'number_of_downloads' => 2, + 'sample' => [ + 'sample_type_url' => 'Yes', + 'sample_url' => 'http://example.com' + ], + 'file_type_url' => 'Yes', + 'file_link_url' => 'http://example.com', + 'is_shareable' => 'No', + 'sort_order' => 0 + ] ], ] ], 'group' => static::GROUP - ] + ], ] ] ); diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/Curl/CreateDownloadable.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/Curl/CreateDownloadable.php index d458fe081b53b..b7c2d936812db 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/Curl/CreateDownloadable.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Handler/Curl/CreateDownloadable.php @@ -78,6 +78,8 @@ protected function getValue($values) } /** + * Prepare downloadable data + * * @param string $key * @param string|array $value * @return array diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.php new file mode 100644 index 0000000000000..729bf7c8c47a1 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.php @@ -0,0 +1,61 @@ +_blocks['downloadableViewBlock'] = [ + 'name' => 'downloadableViewBlock', + 'class' => 'Magento\Downloadable\Test\Block\Catalog\Product\View', + 'locator' => '.product.info.main', + 'strategy' => 'css selector', + ]; + parent::_init(); + } + + /** + * @return \Magento\Downloadable\Test\Block\Catalog\Product\View + */ + public function getDownloadableViewBlock() + { + return $this->getBlockInstance('downloadableViewBlock'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.xml new file mode 100644 index 0000000000000..2f62dab457f35 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/Page/Product/CatalogProductView.xml @@ -0,0 +1,33 @@ + + + + + downloadableViewBlock + Magento\Downloadable\Test\Block\Catalog\Product\View + .product.info.main + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/Create/LinksPurchasedSeparatelyTest.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/Create/LinksPurchasedSeparatelyTest.php index 274e3a47850a2..a26211d4dd74c 100644 --- a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/Create/LinksPurchasedSeparatelyTest.php +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/Create/LinksPurchasedSeparatelyTest.php @@ -45,7 +45,6 @@ protected function setUp() $this->product = Factory::getFixtureFactory() ->getMagentoDownloadableDownloadableProductLinksPurchasedSeparately(); $this->product->switchData('downloadable'); - Factory::getApp()->magentoBackendLoginUser(); } @@ -57,15 +56,17 @@ protected function setUp() */ public function test() { - $createProductPage = Factory::getPageFactory()->getCatalogProductNew(); - $createProductPage->init($this->product); - $productForm = $createProductPage->getProductForm(); - + $createProductPage = Factory::getPageFactory()->getCatalogProductIndex(); $createProductPage->open(); - $productForm->fill($this->product); - $createProductPage->getFormAction()->save(); + $createProductPage->getProductBlock()->addProduct('downloadable'); + + $createProductPageNew = Factory::getPageFactory()->getCatalogProductNew(); + $productBlockForm = $createProductPageNew->getForm(); + + $productBlockForm->fillProduct($this->product); + $createProductPageNew->getFormAction()->save(); - $createProductPage->getMessagesBlock()->assertSuccessMessage(); + $createProductPageNew->getMessagesBlock()->assertSuccessMessage(); $cachePage = Factory::getPageFactory()->getAdminCache(); $cachePage->open(); @@ -99,7 +100,7 @@ protected function assertOnFrontend() $product = $this->product; $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); - $productPage = Factory::getPageFactory()->getCatalogProductView(); + $productPage = Factory::getPageFactory()->getDownloadableCatalogProductView(); $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getCategoryName()); @@ -108,18 +109,21 @@ protected function assertOnFrontend() $this->assertTrue($productListBlock->isProductVisible($product->getProductName())); $productListBlock->openProductViewPage($product->getProductName()); - $productViewBlock = $productPage->getViewBlock(); + $productViewBlock = $productPage->getDownloadableViewBlock(); $this->assertEquals($product->getProductName(), $productViewBlock->getProductName()); - $price = $productViewBlock->getProductPrice(); - $this->assertEquals(number_format($product->getProductPrice(), 2), $price['price_regular_price']); + $this->assertEquals( + sprintf('%1.2f', $product->getProductPrice()), + $productViewBlock->getProductPrice()['price_regular_price'] + ); - $productPage->getDownloadableLinksBlock() - ->check([['title' => $product->getData('fields/downloadable/link/0/title/value')]]); + $this->assertEquals( + $productPage->getDownloadableViewBlock()->getDownloadableLinksBlock()->getItemTitle(1), + $product->getData('fields/downloadable_links/value/downloadable/link/0/title') + ); - $price = $productViewBlock->getProductPrice(); $this->assertEquals( - number_format($product->getProductPrice() + $product->getData('fields/downloadable/link/0/price/value'), 2), - $price['price_regular_price'] + sprintf('$%1.2f', $product->getData('fields/downloadable_links/value/downloadable/link/0/price')), + $productPage->getDownloadableViewBlock()->getDownloadableLinksBlock()->getItemPrice(1) ); } } diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest.php b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest.php new file mode 100644 index 0000000000000..a63ccb7a77364 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest.php @@ -0,0 +1,116 @@ + Catalog. + * 3. Start to create new Downloadable product. + * 4. Fill in data according to data set. + * 5. Fill Downloadable Information tab according to data set. + * 6. Save product. + * 7. Verify created product. + * + * @group Downloadable_Product_(CS) + * @ZephyrId MAGETWO-23425 + */ +class CreateDownloadableProductEntityTest extends Injectable +{ + /** + * Fixture category + * + * @var CatalogCategoryEntity + */ + protected $category; + + /** + * Product page with a grid + * + * @var CatalogProductIndex + */ + protected $catalogProductIndex; + + /** + * New product page on backend + * + * @var CatalogProductNew + */ + protected $catalogProductNew; + + /** + * Persist category + * + * @param CatalogCategoryEntity $category + * @return array + */ + public function __prepare(CatalogCategoryEntity $category) + { + $category->persist(); + return [ + 'category' => $category + ]; + } + + /** + * Filling objects of the class + * + * @param CatalogCategoryEntity $category + * @param CatalogProductIndex $catalogProductIndexNewPage + * @param CatalogProductNew $catalogProductNewPage + */ + public function __inject( + CatalogCategoryEntity $category, + CatalogProductIndex $catalogProductIndexNewPage, + CatalogProductNew $catalogProductNewPage + ) { + $this->category = $category; + $this->catalogProductIndex = $catalogProductIndexNewPage; + $this->catalogProductNew = $catalogProductNewPage; + } + + /** + * Test create downloadable product + * + * @param CatalogProductDownloadable $product + * @param CatalogCategoryEntity $category + */ + public function testCreateDownloadableProduct(CatalogProductDownloadable $product, CatalogCategoryEntity $category) + { + $this->catalogProductIndex->open(); + $this->catalogProductIndex->getProductBlock()->addProduct('downloadable'); + $productBlockForm = $this->catalogProductNew->getForm(); + $productBlockForm->fillProduct($product, $category); + $this->catalogProductNew->getFormAction()->save(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest/testCreateDownloadableProduct.csv b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest/testCreateDownloadableProduct.csv new file mode 100644 index 0000000000000..bd7bc3f326ba6 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/TestCase/CreateDownloadableProductEntityTest/testCreateDownloadableProduct.csv @@ -0,0 +1,15 @@ +product/data/name;product/data/sku;product/data/price;product/data/tax_class;product/data/qty;product/data/quantity_and_stock_status;product/data/is_virtual;product/data/category;product/data/description;product/data/short_description;product/data/inventory_manage_stock;product/data/inventory_qty;product/data/stock_data_use_config_min_qty;product/data/stock_data_min_qty;product/data/downloadable_sample/preset;product/data/downloadable_links/preset;product/data/custom_options/preset;product/data/special_price;product/data/group_price/preset;product/data/tier_price/preset;constraint +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;100;Taxable Goods;1;In Stock;Yes;Default Category;-;-;-;-;-;-;-;default;-;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductVisibleInCategory, assertProductPage, assertProductInStock +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;1;Taxable Goods;10;In Stock;Yes;category %isolation%;-;-;-;-;-;-;default;default;-;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductVisibleInCategory, assertDownloadableSamplesData, assertDownloadableLinks +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;33;Taxable Goods;10;In Stock;Yes;category %isolation%;-;-;-;-;-;-;-;default;default;-;-;-;assertProductSaveMessage, assertDownloadableProductForm, assertCustomOptionsOnProductPage, assertProductVisibleInCategory, assertProductPage, assertDownloadableLinks +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;55;Taxable Goods;10;In Stock;Yes;-;-;-;-;-;-;-;with_three_samples;with_three_links;two_options;-;-;-;assertProductSaveMessage, assertCustomOptionsOnProductPage, assertProductInGrid, assertDownloadableProductForm, assertProductVisibleInCategory, assertProductPage, assertDownloadableLinks, assertProductInStock, assertProductSearchableBySku +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;100;Taxable Goods;50;Out of Stock;Yes;Default Category;-;-;-;-;-;-;-;default;-;-;-;-;assertProductSaveMessage, assertProductOutOfStock, assertProductInGrid, assertDownloadableProductForm +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;9999;Taxable Goods;-;-;Yes;Default Category;-;-;Yes;123;No;123;-;default;-;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductOutOfStock +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;98;None;5;In Stock;Yes;Default Category;This is description for downloadable product;-;-;-;-;-;-;default;-;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;57;Taxable Goods;10;In Stock;Yes;category %isolation%;-;This is short description for downloadable product;-;-;-;-;default;with_three_links;default;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage, assertCustomOptionsOnProductPage, assertDownloadableSamplesData, assertDownloadableLinks +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;65;Taxable Goods;11;In Stock;Yes;category %isolation%;This is description for downloadable product;This is short description for downloadable product;-;-;-;-;default;with_three_links;default;-;-;-;assertProductSaveMessage, assertProductPage, assertProductInGrid, assertDownloadableProductForm, assertCustomOptionsOnProductPage, assertDownloadableSamplesData, assertDownloadableLinks +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;65;Taxable Goods;11;In Stock;Yes;category %isolation%;-;-;-;-;-;-;default;with_three_links;default;-;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage, assertDownloadableLinks, assertCustomOptionsOnProductPage +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;100;Taxable Goods;-;-;Yes;Default Category;-;-;-;-;-;-;-;default;-;-;-;-;assertProductSaveMessage, assertDownloadableProductForm, assertProductVisibleInCategory, assertProductPage +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;10;Taxable Goods;10;In Stock;Yes;category %isolation%;-;-;-;-;-;-;-;-;-;5;-;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage, assertSpecialPriceOnProductPage +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;365;Taxable Goods;23;In Stock;Yes;category %isolation%;-;-;-;-;-;-;-;-;-;-;default;-;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage, assertGroupedPriceOnProductPage +DownloadableProduct_%isolation%;DownloadableProduct_%isolation%;250;Taxable Goods;65;In Stock;Yes;category %isolation%;-;-;-;-;-;-;-;-;-;-;-;default;assertProductSaveMessage, assertProductInGrid, assertDownloadableProductForm, assertProductPage, assertTierPriceOnProductPage \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/global/constraint.xml new file mode 100644 index 0000000000000..113ed007c2353 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Downloadable/Test/etc/global/constraint.xml @@ -0,0 +1,36 @@ + + + + + low + + + low + + + low + + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/Form.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/Form.php new file mode 100644 index 0000000000000..531eccf27ba35 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/Form.php @@ -0,0 +1,36 @@ + + + + + + + + checkbox + + + + + + select + + + select + + + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/FormPageActions.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/FormPageActions.php new file mode 100644 index 0000000000000..01f0c1fc60f83 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Block/Adminhtml/Rate/Edit/FormPageActions.php @@ -0,0 +1,41 @@ + [ + 'selector' => '#tax_rate_grid_filter_code', + ], + 'tax_country_id' => [ + 'selector' => '#tax_rate_grid_filter_tax_country_id', + 'input' => 'select', + ], + 'tax_postcode' => [ + 'selector' => '#tax_rate_grid_filter_tax_postcode', + ], + ]; +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateForm.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateForm.php new file mode 100644 index 0000000000000..0e7fa32068bfb --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateForm.php @@ -0,0 +1,130 @@ +getData(), $taxRate->getData()) + : $taxRate->getData(); + $data = $this->prepareData($data); + $filter = [ + 'code' => $data['code'], + ]; + + $taxRateIndexPage->open(); + $taxRateIndexPage->getTaxRateGrid()->searchAndOpen($filter); + $formData = $taxRateNewPage->getTaxRateForm()->getData($taxRate); + $dataDiff = $this->verifyForm($formData, $data); + \PHPUnit_Framework_Assert::assertTrue( + empty($dataDiff), + 'Tax Rate form was filled incorrectly.' + . "\nLog:\n" . implode(";\n", $dataDiff) + ); + } + + /** + * Preparing data for verification + * + * @param array $data + * @return array + */ + protected function prepareData(array $data) + { + if ($data['zip_is_range'] === 'Yes') { + unset($data['tax_postcode']); + } else { + unset($data['zip_from'], $data['zip_to']); + } + $data['rate'] = number_format($data['rate'], 4); + + return $data; + } + + /** + * Verifying that form is filled correctly + * + * @param array $formData + * @param array $fixtureData + * @return array $errorMessages + */ + protected function verifyForm(array $formData, array $fixtureData) + { + $errorMessages = []; + + foreach ($fixtureData as $key => $value) { + if ($key === 'id') { + continue; + } + if ($value !== $formData[$key]) { + $errorMessages[] = "Data in " . $key . " field not equal." + . "\nExpected: " . $value + . "\nActual: " . $formData[$key]; + } + } + + return $errorMessages; + } + + /** + * Text that form was filled correctly + * + * @return string + */ + public function toString() + { + return 'Tax Rate form was filled correctly.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateInGrid.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateInGrid.php new file mode 100644 index 0000000000000..c6314af8ad899 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateInGrid.php @@ -0,0 +1,83 @@ +getData() + : array_merge($initialTaxRate->getData(), $taxRate->getData()); + $filter = [ + 'code' => $data['code'], + 'tax_country_id' => $data['tax_country_id'], + ]; + $filter['tax_postcode'] = ($data['zip_is_range'] === 'No') + ? $data['tax_postcode'] + : $data['zip_from'] . '-' . $data['zip_to']; + + $taxRateIndexPage->open(); + \PHPUnit_Framework_Assert::assertTrue( + $taxRateIndexPage->getTaxRateGrid()->isRowVisible($filter), + 'Tax Rate \'' . $filter['code'] . '\' is absent in Tax Rate grid.' + ); + } + + /** + * Text of Tax Rate in grid assert + * + * @return string + */ + public function toString() + { + return 'Tax rate is present in grid.'; + } +} diff --git a/app/code/Magento/OfflinePayments/Model/Ccsave.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateIsInCorrectRange.php similarity index 70% rename from app/code/Magento/OfflinePayments/Model/Ccsave.php rename to dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateIsInCorrectRange.php index 2ba4606708d01..c940134113f1e 100644 --- a/app/code/Magento/OfflinePayments/Model/Ccsave.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateIsInCorrectRange.php @@ -21,27 +21,36 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\OfflinePayments\Model; -class Ccsave extends \Magento\Payment\Model\Method\Cc +namespace Magento\Tax\Test\Constraint; + +use Mtf\Constraint\AbstractConstraint; + +/** + * Class AssertTaxRateIsInCorrectRange + */ +class AssertTaxRateIsInCorrectRange extends AbstractConstraint { /** + * Constraint severeness + * * @var string */ - protected $_code = 'ccsave'; + protected $severeness = 'low'; /** - * @var bool + * @return void */ - protected $_canSaveCc = true; + public function processAssert() + { + // + } /** - * @var string - */ - protected $_formBlockType = 'Magento\OfflinePayments\Block\Form\Ccsave'; - - /** - * @var string + * @return string */ - protected $_infoBlockType = 'Magento\OfflinePayments\Block\Info\Ccsave'; + public function toString() + { + // + } } diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateSuccessSaveMessage.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateSuccessSaveMessage.php new file mode 100644 index 0000000000000..9826d5ab2fea1 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRateSuccessSaveMessage.php @@ -0,0 +1,71 @@ +getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_MESSAGE, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::SUCCESS_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Text of Created Tax Rate Success Message assert + * + * @return string + */ + public function toString() + { + return 'Tax rate success create message is present.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsApplied.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsApplied.php new file mode 100644 index 0000000000000..94f6c54145f4f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsApplied.php @@ -0,0 +1,125 @@ +open(); + $customerAccountLogin->open(); + $customerAccountLogin->getLoginBlock()->login($customer); + // Clearing shopping cart and adding product to shopping cart + $checkoutCart->open()->getCartBlock()->clearShoppingCart(); + $catalogProductView->init($productSimple); + $catalogProductView->open(); + $catalogProductView->getViewBlock()->clickAddToCart(); + // Estimate Shipping and Tax + $checkoutCart->getShippingBlock()->openEstimateShippingAndTax(); + $checkoutCart->getShippingBlock()->fill($address); + $checkoutCart->getShippingBlock()->clickGetQuote(); + $checkoutCart->getShippingBlock()->selectShippingMethod($shipping); + // Preparing data to compare + $taxRate = $taxRule->getDataFieldConfig('tax_rate')['source']->getFixture()[0]->getRate(); + $expectedGrandTotal = $productSimple->getPrice() + $taxRate + $shipping['price']; + $expectedGrandTotal = number_format($expectedGrandTotal, 2); + $actualGrandTotal = $checkoutCart->getTotalsBlock()->getGrandTotal(); + + if ($checkoutCart->getTotalsBlock()->isTaxVisible()) { + $expectedTax = number_format($taxRate, 2); + $actualTax = $checkoutCart->getTotalsBlock()->getTax(); + if ($expectedTax !== $actualTax) { + $errorMessages[] = 'Tax is not correct.' + . "\nExpected: " . $expectedTax + . "\nActual: " . $actualTax; + } + } + if ($expectedGrandTotal !== $actualGrandTotal) { + $errorMessages[] = 'Grand Total is not correct.' + . "\nExpected: " . $expectedGrandTotal + . "\nActual: " . $actualGrandTotal; + } + + \PHPUnit_Framework_Assert::assertTrue( + empty($errorMessages), + implode(";\n", $errorMessages) + ); + } + + /** + * Text of Tax Rule is applied on product in shopping cart. + * + * @return string + */ + public function toString() + { + return "Tax rule applied on product in shopping cart."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsNotApplied.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsNotApplied.php new file mode 100644 index 0000000000000..c80b20ad4fd76 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Constraint/AssertTaxRuleIsNotApplied.php @@ -0,0 +1,125 @@ +hasData('code')) ? $taxRule->getCode() : $initialTaxRule->getCode(); + } else { + $taxRuleCode = $taxRule->getCode(); + } + // Customer login + $customerAccountLogout->open(); + $customerAccountLogin->open(); + $customerAccountLogin->getLoginBlock()->login($customer); + // Clearing shopping cart and adding product to shopping cart + $checkoutCart->open()->getCartBlock()->clearShoppingCart(); + $catalogProductView->init($productSimple); + $catalogProductView->open(); + $catalogProductView->getViewBlock()->clickAddToCart(); + // Estimate Shipping and Tax + $checkoutCart->getShippingBlock()->openEstimateShippingAndTax(); + $checkoutCart->getShippingBlock()->fill($address); + $checkoutCart->getShippingBlock()->clickGetQuote(); + $checkoutCart->getShippingBlock()->selectShippingMethod($shipping); + // Preparing data to compare + $expectedGrandTotal = $productSimple->getPrice() + $shipping['price']; + $expectedGrandTotal = number_format($expectedGrandTotal, 2); + $actualGrandTotal = $checkoutCart->getTotalsBlock()->getGrandTotal(); + + if ($checkoutCart->getTotalsBlock()->isTaxVisible()) { + $errorMessages[] = 'Tax Rule \'' . $taxRuleCode . '\' present in shopping cart.'; + } + if ($expectedGrandTotal !== $actualGrandTotal) { + $errorMessages[] = 'Grand Total is not correct.' + . "\nExpected: " . $expectedGrandTotal + . "\nActual: " . $actualGrandTotal; + } + + \PHPUnit_Framework_Assert::assertTrue( + empty($errorMessages), + implode(";\n", $errorMessages) + ); + } + + /** + * Text of Tax Rule is not applied on product in shopping cart. + * + * @return string + */ + public function toString() + { + return "Tax rule was not applied on product in shopping cart."; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Fixture/TaxRate.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Fixture/TaxRate.php index a71e5f2953b55..7a25175cd950b 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/Fixture/TaxRate.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Fixture/TaxRate.php @@ -46,7 +46,7 @@ class TaxRate extends InjectableFixture 'rate' => '10', 'tax_country_id' => 'United States', 'tax_postcode' => '*', - 'tax_region_id' => '0', + 'tax_region_id' => 'California', ]; protected $tax_calculation_rate_id = [ diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.php new file mode 100644 index 0000000000000..9d7384ad5fa1b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.php @@ -0,0 +1,80 @@ + [ + 'name' => 'gridPageActions', + 'class' => 'Magento\Backend\Test\Block\GridPageActions', + 'locator' => '.page-main-actions', + 'strategy' => 'css selector', + ], + 'taxRateGrid' => [ + 'name' => 'taxRateGrid', + 'class' => 'Magento\Tax\Test\Block\Adminhtml\Rate\Grid', + 'locator' => '#tax_rate_grid', + 'strategy' => 'css selector', + ], + 'messagesBlock' => [ + 'name' => 'messagesBlock', + 'class' => 'Magento\Core\Test\Block\Messages', + 'locator' => '#messages', + 'strategy' => 'css selector', + ], + ]; + + /** + * @return \Magento\Backend\Test\Block\GridPageActions + */ + public function getGridPageActions() + { + return $this->getBlockInstance('gridPageActions'); + } + + /** + * @return \Magento\Tax\Test\Block\Adminhtml\Rate\Grid + */ + public function getTaxRateGrid() + { + return $this->getBlockInstance('taxRateGrid'); + } + + /** + * @return \Magento\Core\Test\Block\Messages + */ + public function getMessagesBlock() + { + return $this->getBlockInstance('messagesBlock'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.xml b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.xml new file mode 100644 index 0000000000000..6de779d910f0c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateIndex.xml @@ -0,0 +1,45 @@ + + + + + gridPageActions + Magento\Backend\Test\Block\GridPageActions + .page-main-actions + css selector + + + taxRateGrid + Magento\Tax\Test\Block\Adminhtml\Rate\Grid + #tax_rate_grid + css selector + + + messagesBlock + Magento\Core\Test\Block\Messages + #messages + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.php new file mode 100644 index 0000000000000..50e57e8bdc4a0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.php @@ -0,0 +1,80 @@ + [ + 'name' => 'formPageActions', + 'class' => 'Magento\Tax\Test\Block\Adminhtml\Rate\Edit\FormPageActions', + 'locator' => '.page-main-actions', + 'strategy' => 'css selector', + ], + 'taxRateForm' => [ + 'name' => 'taxRateForm', + 'class' => 'Magento\Tax\Test\Block\Adminhtml\Rate\Edit\Form', + 'locator' => '#rate-form', + 'strategy' => 'css selector', + ], + 'messagesBlock' => [ + 'name' => 'messagesBlock', + 'class' => 'Magento\Core\Test\Block\Messages', + 'locator' => '#messages', + 'strategy' => 'css selector', + ], + ]; + + /** + * @return \Magento\Tax\Test\Block\Adminhtml\Rate\Edit\FormPageActions + */ + public function getFormPageActions() + { + return $this->getBlockInstance('formPageActions'); + } + + /** + * @return \Magento\Tax\Test\Block\Adminhtml\Rate\Edit\Form + */ + public function getTaxRateForm() + { + return $this->getBlockInstance('taxRateForm'); + } + + /** + * @return \Magento\Core\Test\Block\Messages + */ + public function getMessagesBlock() + { + return $this->getBlockInstance('messagesBlock'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.xml b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.xml new file mode 100644 index 0000000000000..276f7f8a4d3c9 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Page/Adminhtml/TaxRateNew.xml @@ -0,0 +1,45 @@ + + + + + formPageActions + Magento\Tax\Test\Block\Adminhtml\Rate\Edit\FormPageActions + .page-main-actions + css selector + + + taxRateForm + Magento\Tax\Test\Block\Adminhtml\Rate\Edit\Form + #rate-form + css selector + + + messagesBlock + Magento\Core\Test\Block\Messages + #messages + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/Repository/TaxRate.php b/dev/tests/functional/tests/app/Magento/Tax/Test/Repository/TaxRate.php index 958373b4dc044..7f220dafe5cb0 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/Repository/TaxRate.php +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/Repository/TaxRate.php @@ -93,7 +93,7 @@ public function __construct(array $defaultConfig = [], array $defaultData = []) $this->_data['uk_full_tax_rate'] = [ 'code' => 'Tax Rate %isolation%', - 'rate' => '10', + 'rate' => '20', 'tax_country_id' => 'United Kingdom', 'tax_postcode' => '*', ]; @@ -114,5 +114,21 @@ public function __construct(array $defaultConfig = [], array $defaultData = []) 'tax_region_id' => 'California', 'rate' => '15.5' ]; + + $this->_data['withFixedZip'] = [ + 'code' => 'TaxIdentifier%isolation%', + 'tax_postcode' => '*', + 'tax_country_id' => 'United States', + 'tax_region_id' => 'Texas', + 'rate' => '20' + ]; + + $this->_data['us_ut_fixed_zip_rate_20'] = [ + 'code' => 'TaxIdentifier%isolation%', + 'tax_postcode' => '84001', + 'tax_country_id' => 'United States', + 'tax_region_id' => 'Utah', + 'rate' => '20' + ]; } } diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest.php b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest.php new file mode 100644 index 0000000000000..48b97c21b3ac3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest.php @@ -0,0 +1,105 @@ + Taxes -> Tax Zones and Rates. + * 3. Search tax rate in grid by given data. + * 4. Open this tax rate by clicking. + * 5. Edit test value(s) according to dataset. + * 6. Click 'Save Rate' button. + * 7. Perform asserts. + * + * @group Tax_(CS) + * @ZephyrId MAGETWO-23299 + */ +class UpdateTaxRateEntityTest extends Injectable +{ + /** + * Tax Rate grid page + * + * @var TaxRateIndex + */ + protected $taxRateIndex; + + /** + * Tax Rate new/edit page + * + * @var TaxRateNew + */ + protected $taxRateNew; + + /** + * Injection data + * + * @param TaxRateIndex $taxRateIndex + * @param TaxRateNew $taxRateNew + * @return void + */ + public function __inject( + TaxRateIndex $taxRateIndex, + TaxRateNew $taxRateNew + ) { + $this->taxRateIndex = $taxRateIndex; + $this->taxRateNew = $taxRateNew; + } + + /** + * Update Tax Rate Entity test + * + * @param TaxRate $initialTaxRate + * @param TaxRate $taxRate + * @return void + */ + public function testUpdateTaxRate( + TaxRate $initialTaxRate, + TaxRate $taxRate + ) { + // Precondition + $initialTaxRate->persist(); + + // Steps + $filter = [ + 'code' => $initialTaxRate->getCode(), + ]; + $this->taxRateIndex->open(); + $this->taxRateIndex->getTaxRateGrid()->searchAndOpen($filter); + $this->taxRateNew->getTaxRateForm()->fill($taxRate); + $this->taxRateNew->getFormPageActions()->save(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest/testUpdateTaxRate.csv b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest/testUpdateTaxRate.csv new file mode 100644 index 0000000000000..a2d457148db73 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRateEntityTest/testUpdateTaxRate.csv @@ -0,0 +1,7 @@ +"initialTaxRate/dataSet";"taxRate/data/code";"taxRate/data/zip_is_range";"taxRate/data/zip_from";"taxRate/data/zip_to";"taxRate/data/tax_postcode";"taxRate/data/tax_country_id";"taxRate/data/tax_region_id";"taxRate/data/rate";"constraint" +"default";"TaxIdentifier%isolation%";"No";"-";"-";"90001";"United States";"California";"100";"assertTaxRateSuccessSaveMessage, assertTaxRateInGrid, assertTaxRateForm" +"default";"TaxIdentifier%isolation%";"Yes";"90001";"96162";"-";"United States";"California";"15.05";"assertTaxRateSuccessSaveMessage, assertTaxRateInGrid, assertTaxRateForm" +"default";"TaxIdentifier%isolation%";"No";"-";"-";"*";"United Kingdom";"*";"777";"assertTaxRateIsInCorrectRange" +"withZipRange";"TaxIdentifier%isolation%";"No";"-";"-";"180";"Canada";"*";"25";"assertTaxRateSuccessSaveMessage, assertTaxRateInGrid, assertTaxRateForm" +"withZipRange";"TaxIdentifier%isolation%";"Yes";"0";"7800935";"-";"United Kingdom";"*";"0";"assertTaxRateIsInCorrectRange" +"withZipRange";"TaxIdentifier%isolation%";"No";"-";"-";"*";"France";"Val-d'Oise";"0.1";"assertTaxRateSuccessSaveMessage, assertTaxRateInGrid, assertTaxRateForm" \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest.php new file mode 100644 index 0000000000000..0f8e0b7b9bb46 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest.php @@ -0,0 +1,130 @@ + Tax Rules + * 3. Click Tax Rule from grid + * 4. Edit test value(s) according to dataset. + * 5. Click 'Save' button. + * 6. Perform all asserts. + * + * @group Tax_(CS) + * @ZephyrId MAGETWO-20996 + */ +class UpdateTaxRuleEntityTest extends Injectable +{ + /** + * Tax Rule grid page + * + * @var TaxRuleIndex + */ + protected $taxRuleIndexPage; + + /** + * Tax Rule new and edit page + * + * @var TaxRuleNew + */ + protected $taxRuleNewPage; + + /** + * Prepare data + * + * @param FixtureFactory $fixtureFactory + * @return array + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $productSimple = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => '100_dollar_product']); + $productSimple->persist(); + $customer = $fixtureFactory->createByCode('customerInjectable', ['dataSet' => 'default']); + $customer->persist(); + + return [ + 'productSimple' => $productSimple, + 'customer' => $customer, + ]; + } + + /** + * Injection data + * + * @param TaxRuleIndex $taxRuleIndexPage + * @param TaxRuleNew $taxRuleNewPage + * @return void + */ + public function __inject( + TaxRuleIndex $taxRuleIndexPage, + TaxRuleNew $taxRuleNewPage + ) { + $this->taxRuleIndexPage = $taxRuleIndexPage; + $this->taxRuleNewPage = $taxRuleNewPage; + } + + /** + * Update Tax Rule Entity test + * + * @param TaxRule $initialTaxRule + * @param TaxRule $taxRule + * @param AddressInjectable $address + * @param array $shipping + * @return void + */ + public function testUpdateTaxRule( + TaxRule $initialTaxRule, + TaxRule $taxRule, + AddressInjectable $address, + array $shipping + ) { + // Precondition + $initialTaxRule->persist(); + + // Steps + $filters = [ + 'code' => $initialTaxRule->getCode(), + ]; + $this->taxRuleIndexPage->open(); + $this->taxRuleIndexPage->getTaxRuleGrid()->searchAndOpen($filters); + $this->taxRuleNewPage->getTaxRuleForm()->fill($taxRule); + $this->taxRuleNewPage->getFormPageActions()->save(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest/testUpdateTaxRule.csv b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest/testUpdateTaxRule.csv new file mode 100644 index 0000000000000..b87c02bedf660 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/TestCase/UpdateTaxRuleEntityTest/testUpdateTaxRule.csv @@ -0,0 +1,5 @@ +"initialTaxRule/dataSet";"address/data/country_id";"address/data/region_id";"address/data/postcode";"shipping/carrier";"shipping/method";"shipping/price";"taxRule/data/code";"taxRule/data/tax_rate/dataSet/rate_0";"taxRule/data/tax_customer_class/dataSet/class_0";"taxRule/data/tax_product_class/dataSet/class_0";"taxRule/data/priority";"taxRule/data/position";"constraint" +"tax_rule_default";"-";"-";"-";"-";"-";"-";"New Tax Rule name%isolation%";"default";"customer_tax_class";"product_tax_class";"2";"2";"assertTaxRuleSuccessSaveMessage, assertTaxRuleInGrid, assertTaxRuleForm" +"tax_rule_with_custom_tax_classes";"-";"-";"-";"-";"-";"-";"-";"withZipRange";"Retail Customer";"Taxable Goods";"-";"-";"assertTaxRuleSuccessSaveMessage, assertTaxRuleInGrid, assertTaxRuleForm" +"tax_rule_with_custom_tax_classes";"United States";"Utah";84001;"Flat Rate";"Fixed";5;"-";"us_ut_fixed_zip_rate_20";"-";"-";"-";"-";"assertTaxRuleSuccessSaveMessage, assertTaxRuleInGrid, assertTaxRuleForm, assertTaxRuleIsApplied" +"tax_rule_with_custom_tax_classes";"United States";"Idaho";83201;"Flat Rate";"Fixed";5;"-";"withFixedZip";"-";"-";"-";"-";"assertTaxRuleSuccessSaveMessage, assertTaxRuleInGrid, assertTaxRuleForm, assertTaxRuleIsNotApplied" \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/constraint.xml index 54e405d8c0a07..fa9046b598b7a 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/constraint.xml @@ -45,4 +45,37 @@ + + high + + + + + + high + + + + + + + high + + + + + + + + low + + + + high + + + + high + + diff --git a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/page.xml b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/page.xml index ddde8e9355ca7..712eaffc63e03 100644 --- a/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/page.xml +++ b/dev/tests/functional/tests/app/Magento/Tax/Test/etc/global/page.xml @@ -34,4 +34,14 @@ adminhtml Magento\Tax\Test\Page\Adminhtml\TaxRuleNew + + tax/rate/index + adminhtml + Magento\Tax\Test\Page\Adminhtml\TaxRateIndex + + + tax/rate/add + adminhtml + Magento\Tax\Test\Page\Adminhtml\TaxRateNew + diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertPageByUrlRewriteIsNotFound.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertPageByUrlRewriteIsNotFound.php new file mode 100644 index 0000000000000..bf78bda113e33 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertPageByUrlRewriteIsNotFound.php @@ -0,0 +1,80 @@ +open($_ENV['app_frontend_url'] . $productRedirect->getRequestPath()); + \PHPUnit_Framework_Assert::assertEquals( + self::NOT_FOUND_MESSAGE, + $catalogProductView->getTitleBlock()->getTitle(), + 'Wrong page is displayed.' + ); + } + + /** + * Not found page is display + * + * @return string + */ + public function toString() + { + return 'Not found page is display.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteDeletedMessage.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteDeletedMessage.php new file mode 100644 index 0000000000000..287bf259b31fe --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteDeletedMessage.php @@ -0,0 +1,75 @@ +getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_DELETE_MESSAGE, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::SUCCESS_DELETE_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Url rewrite delete message is displayed + * + * @return string + */ + public function toString() + { + return 'Url rewrite delete message is displayed.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteNotInGrid.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteNotInGrid.php new file mode 100644 index 0000000000000..a47ff883bb89f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Constraint/AssertUrlRewriteNotInGrid.php @@ -0,0 +1,70 @@ +open(); + $filter = ['request_path' => $productRedirect->getRequestPath()]; + \PHPUnit_Framework_Assert::assertFalse( + $urlRewriteIndex->getUrlRedirectGrid()->isRowVisible($filter), + 'URL Redirect with request path \'' . $productRedirect->getRequestPath() . '\' is present in grid.' + ); + } + + /** + * URL rewrite category not present in grid + * + * @return string + */ + public function toString() + { + return 'URL Redirect is not present in grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.php index f62eab17ebcba..9f84c5b500c45 100644 --- a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.php +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.php @@ -31,6 +31,16 @@ */ class UrlRewrite extends InjectableFixture { + /** + * @var string + */ + protected $repositoryClass = 'Magento\UrlRewrite\Test\Repository\UrlRewrite'; + + /** + * @var string + */ + protected $handlerInterface = 'Magento\UrlRewrite\Test\Handler\UrlRewrite\UrlRewriteInterface'; + protected $defaultDataSet = [ 'store_id' => 'Default Store View', 'request_path' => 'test_request%isolation%', @@ -41,6 +51,11 @@ class UrlRewrite extends InjectableFixture 'backend_type' => 'virtual', ]; + protected $id_path = [ + 'attribute_code' => 'id_path', + 'backend_type' => 'virtual', + ]; + protected $store_id = [ 'attribute_code' => 'store_id', 'backend_type' => 'varchar', @@ -76,6 +91,11 @@ public function getId() return $this->getData('id'); } + public function getIdPath() + { + return $this->getData('id_path'); + } + public function getStoreId() { return $this->getData('store_id'); diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.xml b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.xml index 7f11744b1e789..3e28df6a0c1ce 100644 --- a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.xml +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Fixture/UrlRewrite.xml @@ -34,6 +34,10 @@ id virtual + + id_path + virtual + store_id varchar @@ -61,4 +65,6 @@ text + Magento\UrlRewrite\Test\Repository\UrlRewrite + Magento\UrlRewrite\Test\Handler\UrlRewrite diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php new file mode 100644 index 0000000000000..49368c86669ca --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/Curl.php @@ -0,0 +1,97 @@ + ['Default Store View' => 1], + 'options' => [ + 'Temporary (302)' => 'R', + 'Temporary (301)' => 'RP', + 'No' => '' + ] + ]; + + /** + * Url for save rewrite + * + * @var string + */ + protected $url = 'admin/urlrewrite/save/'; + + /** + * Post request for creating url rewrite + * + * @param FixtureInterface $fixture + * @throws \Exception + * @return mixed|void + */ + public function persist(FixtureInterface $fixture = null) + { + $url = $_ENV['app_backend_url'] . $this->url . $fixture->getData('id_path'); + $data = $this->prepareData($fixture->getData()); + $curl = new BackendDecorator(new CurlTransport(), new Config()); + $curl->write(CurlInterface::POST, $url, '1.0', array(), $data); + $response = $curl->read(); + + if (!strpos($response, 'data-ui-id="messages-message-success"')) { + throw new \Exception("Product creation by curl handler was not successful! Response: $response"); + } + $curl->close(); + } + + /** + * Prepare data + * + * @param array $data + * @return array + */ + protected function prepareData(array $data) + { + foreach ($data as $key => $value) { + if (isset($this->dataMapping[$key])) { + $data[$key] = $this->dataMapping[$key][$value]; + } + } + return $data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/UrlRewriteInterface.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/UrlRewriteInterface.php new file mode 100644 index 0000000000000..80dccd6f26f19 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/Handler/UrlRewrite/UrlRewriteInterface.php @@ -0,0 +1,35 @@ +_data['default'] = [ + 'request_path' => 'test-test-test%isolation%.html', + 'options' => 'No', + 'store_id' => 'Default Store View' + ]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest.php b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest.php new file mode 100644 index 0000000000000..f1a7b36911d1e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest.php @@ -0,0 +1,113 @@ + URL Redirects. + * 3. Click Redirect from grid. + * 4. Click 'Delete' button. + * 5. Perform asserts. + * + * @group URL_Rewrites_(PS) + * @ZephyrId MAGETWO-23287 + */ +class DeleteProductUrlRewritesEntityTest extends Injectable +{ + /** + * Url rewrite index page + * + * @var UrlrewriteIndex + */ + protected $urlRewriteIndex; + + /** + * Url rewrite edit page + * + * @var UrlrewriteEdit + */ + protected $urlRewriteEdit; + + /** + * Prepare dataSets and pages + * + * @param FixtureFactory $fixtureFactory + * @param UrlrewriteIndex $urlRewriteIndex + * @param UrlrewriteEdit $urlRewriteEdit + * @return array + */ + public function __inject( + FixtureFactory $fixtureFactory, + UrlrewriteIndex $urlRewriteIndex, + UrlrewriteEdit $urlRewriteEdit + ) { + /** @var CatalogProductSimple $product */ + $product = $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_without_category']); + $product->persist(); + + /** @var UrlRewrite $productRedirect */ + $productRedirect = $fixtureFactory->createByCode( + 'urlRewrite', + [ + 'dataSet' => 'default', + 'data' => ['id_path' => 'product/' . $product->getId()] + ] + ); + $productRedirect->persist(); + + $this->urlRewriteIndex = $urlRewriteIndex; + $this->urlRewriteEdit = $urlRewriteEdit; + return ['productRedirect' => $productRedirect]; + } + + /** + * Delete product url rewrites entity + * + * @param UrlRewrite $productRedirect + * @return void + */ + public function testDeleteProductUrlRewrites(UrlRewrite $productRedirect) + { + $this->urlRewriteIndex->open(); + $filter = ['request_path' => $productRedirect->getRequestPath()]; + $this->urlRewriteIndex->getUrlRedirectGrid()->searchAndOpen($filter); + $this->urlRewriteEdit->getPageMainActions()->delete(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest/testDeleteProductUrlRewrites.csv b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest/testDeleteProductUrlRewrites.csv new file mode 100644 index 0000000000000..a0af0ee845617 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/TestCase/DeleteProductUrlRewritesEntityTest/testDeleteProductUrlRewrites.csv @@ -0,0 +1,2 @@ +"constraint" +"assertUrlRewriteDeletedMessage, assertUrlRewriteNotInGrid, assertPageByUrlRewriteIsNotFound" diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/curl/di.xml b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/curl/di.xml new file mode 100644 index 0000000000000..6dcbbc44a53c7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/curl/di.xml @@ -0,0 +1,28 @@ + + + + + diff --git a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/global/constraint.xml index 2ca992fbdc011..a31770c301196 100644 --- a/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/global/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/UrlRewrite/Test/etc/global/constraint.xml @@ -37,4 +37,25 @@ low + + low + + + + + + low + + + + + + + low + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Form.php b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Form.php similarity index 74% rename from dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Form.php rename to dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Form.php index d5f27dd5da544..d503dbb373467 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Form.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Form.php @@ -22,17 +22,16 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\User\Test\Block\User\Edit; +namespace Magento\User\Test\Block\Adminhtml\User\Edit; -use Mtf\Fixture\FixtureInterface; use Mtf\Client\Element; use Mtf\Client\Element\Locator; use Magento\Backend\Test\Block\Widget\FormTabs; +use Magento\User\Test\Block\Adminhtml\User\Edit\Tab\Roles; /** * Class Form * Form for User Edit/Create page - * */ class Form extends FormTabs { @@ -45,9 +44,24 @@ class Form extends FormTabs /** * Open Role tab for User Edit page + * + * @return void */ public function openRoleTab() { $this->_rootElement->find($this->roleTab, Locator::SELECTOR_ID)->click(); } + + /** + * Get roles grid on user edit page + * + * @return Roles + */ + public function getRolesGrid() + { + return $this->blockFactory->create( + 'Magento\User\Test\Block\Adminhtml\User\Edit\Tab\Roles', + ['element' => $this->_rootElement->find('#permissionsUserRolesGrid')] + ); + } } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Tab/Roles.php b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Tab/Roles.php similarity index 82% rename from dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Tab/Roles.php rename to dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Tab/Roles.php index ccf627df72298..18bf72dc38ce2 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Block/User/Edit/Tab/Roles.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/User/Edit/Tab/Roles.php @@ -22,7 +22,7 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\User\Test\Block\User\Edit\Tab; +namespace Magento\User\Test\Block\Adminhtml\User\Edit\Tab; use Mtf\Client\Element; use Mtf\Factory\Factory; @@ -31,10 +31,23 @@ /** * Class Roles * Grid on Roles Tab page for User - * */ class Roles extends Grid { + /** + * Locator value for link in action column + * + * @var string + */ + protected $editLink = '.col-role_name'; + + /** + * An element locator which allows to select entities in grid + * + * @var string + */ + protected $selectItem = 'tbody tr'; + /** * Filters Name for Roles Grid * @@ -49,13 +62,4 @@ class Roles extends Grid 'selector' => '#permissionsUserRolesGrid_filter_role_name' ) ); - - /** - * Initialize grid elements - */ - protected function _init() - { - parent::_init(); - $this->selectItem = 'tbody tr'; - } } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/UserGrid.php b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/UserGrid.php new file mode 100644 index 0000000000000..ec9a46557561e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Block/Adminhtml/UserGrid.php @@ -0,0 +1,55 @@ + [ + 'selector' => '#permissionsUserGrid_filter_username' + ], + 'email' => [ + 'selector' => '#permissionsUserGrid_filter_email' + ] + ]; + + /** + * Locator value of td with username + * + * @var string + */ + protected $editLink = '[data-column="username"]'; +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Block/Backend/UserGrid.php b/dev/tests/functional/tests/app/Magento/User/Test/Block/Backend/UserGrid.php deleted file mode 100644 index 55b32da488552..0000000000000 --- a/dev/tests/functional/tests/app/Magento/User/Test/Block/Backend/UserGrid.php +++ /dev/null @@ -1,78 +0,0 @@ -Permissions -> All Users page - * - */ -class UserGrid extends Grid -{ - /** - * Link to click on Email cell for user - * - * @var string - */ - protected $editLink = 'td[data-column="email"]'; - - /** - * Filters Name for Permission User Grid - * - * @var array - */ - protected $filters = array( - 'id' => array( - 'selector' => '#permissionsUserGrid_filter_user_id' - ), - 'user_name' => array( - 'selector' => '#permissionsUserGrid_filter_username' - ), - 'first_name' => array( - 'selector' => '#permissionsUserGrid_filter_firstname' - ), - 'last_name' => array( - 'selector' => '#permissionsUserGrid_filter_lastname' - ), - 'email' => array( - 'selector' => '#permissionsUserGrid_filter_email' - ), - 'status' => array( - 'selector' => '#permissionsUserGrid_filter_is_active', - 'input' => 'select' - ) - ); - - /** - * Initialize grid elements - */ - protected function _init() - { - parent::_init(); - } -} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertImpossibleDeleteYourOwnAccount.php b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertImpossibleDeleteYourOwnAccount.php new file mode 100644 index 0000000000000..6ade229966bdb --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertImpossibleDeleteYourOwnAccount.php @@ -0,0 +1,71 @@ +getMessagesBlock()->getErrorMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::ERROR_MESSAGE, + $errorMessage, + 'Wrong error message is displayed.' + . "\nExpected: " . self::ERROR_MESSAGE + . "\nActual: " . $errorMessage + ); + } + + /** + * Returns message if equals to expected message. + * + * @return string + */ + public function toString() + { + return '"You cannot delete self-assigned roles." message on UserEdit page is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInGrid.php b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInGrid.php new file mode 100644 index 0000000000000..1b2c17f7fa576 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserInGrid.php @@ -0,0 +1,71 @@ + $adminUser->getUsername()]; + $userIndex->open(); + \PHPUnit_Framework_Assert::assertTrue( + $userIndex->getUserGrid()->isRowVisible($filter), + 'User with name \'' . $adminUser->getUsername() . '\' is absent in User grid.' + ); + } + + /** + * Returns success message if assert true. + * + * @return string + */ + public function toString() + { + return 'User is present in Users grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserNotInGrid.php b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserNotInGrid.php new file mode 100644 index 0000000000000..19056cdf4c199 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserNotInGrid.php @@ -0,0 +1,71 @@ + $adminUser->getUsername()]; + $userIndex->open(); + \PHPUnit_Framework_Assert::assertFalse( + $userIndex->getUserGrid()->isRowVisible($filter), + 'User with name \'' . $adminUser->getUsername() . '\' is present in Users grid.' + ); + } + + /** + * Returns message if user not in grid. + * + * @return string + */ + public function toString() + { + return 'User is absent in Users grid.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserSuccessDeleteMessage.php b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserSuccessDeleteMessage.php new file mode 100644 index 0000000000000..089d70b510b24 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Constraint/AssertUserSuccessDeleteMessage.php @@ -0,0 +1,71 @@ +getMessagesBlock()->getSuccessMessages(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_MESSAGE, + $successMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . self::SUCCESS_MESSAGE + . "\nActual: " . $successMessage + ); + } + + /** + * Returns message if success message equals to expected message. + * + * @return string + */ + public function toString() + { + return 'Success delete message on users page is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Fixture/AdminUserInjectable.php b/dev/tests/functional/tests/app/Magento/User/Test/Fixture/AdminUserInjectable.php index c45c17571bddf..0c6dd05ad1fea 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Fixture/AdminUserInjectable.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Fixture/AdminUserInjectable.php @@ -28,6 +28,7 @@ /** * Class AdminUserInjectable + * */ class AdminUserInjectable extends InjectableFixture { @@ -42,12 +43,12 @@ class AdminUserInjectable extends InjectableFixture protected $handlerInterface = 'Magento\User\Test\Handler\AdminUser\AdminUserInterface'; protected $defaultDataSet = [ - 'username' => 'customAdmin%isolation%', + 'username' => 'AdminUser%isolation%', 'firstname' => 'FirstName%isolation%', 'lastname' => 'LastName%isolation%', 'email' => 'email%isolation%@example.com', 'password' => '123123q', - 'password_confirmation' => '123123q', + 'password_confirmation' => '123123q' ]; protected $user_id = [ diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUser/Curl.php b/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUser/Curl.php index 33deba9d62617..13653bc9d2fea 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUser/Curl.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUser/Curl.php @@ -30,7 +30,7 @@ use Mtf\Util\Protocol\CurlTransport; use Mtf\Util\Protocol\CurlTransport\BackendDecorator; use Mtf\System\Config; -use Magento\Backend\Test\Handler\Pagination; +use Magento\Backend\Test\Handler\Extractor; /** * Class Curl @@ -65,8 +65,8 @@ public function persist(FixtureInterface $fixture = null) $url = 'admin/user/roleGrid/sort/user_id/dir/desc'; $regExpPattern = '/class=\"\scol\-id col\-user_id\W*>\W+(\d+)\W+<\/td>\W+\W+?' . $data['username'] . '/siu'; - $pagination = new Pagination($url, $regExpPattern); + $extractor = new Extractor($url, $regExpPattern); - return ['user_id' => $pagination->getId()]; + return ['user_id' => $extractor->getData()[1]]; } } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUserRole/Curl.php b/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUserRole/Curl.php index 4abace1c4c321..918d42c2c4b55 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUserRole/Curl.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Handler/AdminUserRole/Curl.php @@ -24,9 +24,7 @@ namespace Magento\User\Test\Handler\AdminUserRole; -use Magento\User\Test\Handler\AdminUserRole\AdminUserRoleInterface; -use Magento\Backend\Test\Handler\Pagination; -use Magento\User\Test\Page\Adminhtml\UserRoleIndex; +use Magento\Backend\Test\Handler\Extractor; use Mtf\Fixture\FixtureInterface; use Mtf\Handler\Curl as AbstractCurl; use Mtf\Util\Protocol\CurlInterface; @@ -70,8 +68,8 @@ public function persist(FixtureInterface $fixture = null) $regExpPattern = '/class=\"\scol\-id col\-role_id\W*>\W+(\d+)\W+<\/td>\W+\W+?' . $data['rolename'] . '/siu'; - $pagination = new Pagination($url, $regExpPattern); + $extractor = new Extractor($url, $regExpPattern); - return ['role_id' => $pagination->getId()]; + return ['role_id' => $extractor->getData()[1]]; } } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.php b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.php new file mode 100644 index 0000000000000..d12315a867ccf --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.php @@ -0,0 +1,80 @@ + [ + 'name' => 'pageActions', + 'class' => 'Magento\Backend\Test\Block\FormPageActions', + 'locator' => '.page-main-actions', + 'strategy' => 'css selector', + ], + 'messagesBlock' => [ + 'name' => 'messagesBlock', + 'class' => 'Magento\Core\Test\Block\Messages', + 'locator' => '#messages', + 'strategy' => 'css selector', + ], + 'userForm' => [ + 'name' => 'userForm', + 'class' => 'Magento\User\Test\Block\Adminhtml\User\Edit\Form', + 'locator' => '[id="page:main-container"]', + 'strategy' => 'css selector', + ], + ]; + + /** + * @return \Magento\Backend\Test\Block\FormPageActions + */ + public function getPageActions() + { + return $this->getBlockInstance('pageActions'); + } + + /** + * @return \Magento\Core\Test\Block\Messages + */ + public function getMessagesBlock() + { + return $this->getBlockInstance('messagesBlock'); + } + + /** + * @return \Magento\User\Test\Block\Adminhtml\User\Edit\Form + */ + public function getUserForm() + { + return $this->getBlockInstance('userForm'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.xml b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.xml new file mode 100644 index 0000000000000..c5235586183e0 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserEdit.xml @@ -0,0 +1,45 @@ + + + + + pageActions + Magento\Backend\Test\Block\FormPageActions + .page-main-actions + css selector + + + messagesBlock + Magento\Core\Test\Block\Messages + #messages + css selector + + + userForm + Magento\User\Test\Block\Adminhtml\User\Edit\Form + [id="page:main-container"] + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.php b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.php new file mode 100644 index 0000000000000..ba6103d709647 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.php @@ -0,0 +1,80 @@ + [ + 'name' => 'pageActions', + 'class' => 'Magento\Backend\Test\Block\GridPageActions', + 'locator' => '.page-main-actions', + 'strategy' => 'css selector', + ], + 'userGrid' => [ + 'name' => 'userGrid', + 'class' => 'Magento\User\Test\Block\Adminhtml\UserGrid', + 'locator' => '#permissionsUserGrid', + 'strategy' => 'css selector', + ], + 'messagesBlock' => [ + 'name' => 'messagesBlock', + 'class' => 'Magento\Core\Test\Block\Messages', + 'locator' => '#messages', + 'strategy' => 'css selector', + ], + ]; + + /** + * @return \Magento\Backend\Test\Block\GridPageActions + */ + public function getPageActions() + { + return $this->getBlockInstance('pageActions'); + } + + /** + * @return \Magento\User\Test\Block\Adminhtml\UserGrid + */ + public function getUserGrid() + { + return $this->getBlockInstance('userGrid'); + } + + /** + * @return \Magento\Core\Test\Block\Messages + */ + public function getMessagesBlock() + { + return $this->getBlockInstance('messagesBlock'); + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.xml b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.xml new file mode 100644 index 0000000000000..1783a653f4172 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/Page/Adminhtml/UserIndex.xml @@ -0,0 +1,45 @@ + + + + + pageActions + Magento\Backend\Test\Block\GridPageActions + .page-main-actions + css selector + + + userGrid + Magento\User\Test\Block\Adminhtml\UserGrid + #permissionsUserGrid + css selector + + + messagesBlock + Magento\Core\Test\Block\Messages + #messages + css selector + + diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserEdit.php b/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserEdit.php deleted file mode 100644 index fa736405c46db..0000000000000 --- a/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserEdit.php +++ /dev/null @@ -1,124 +0,0 @@ -_url = $_ENV['app_backend_url'] . self::MCA; - } - - /** - * Get form for admin user creation/edit - * - * @return \Magento\User\Test\Block\User\Edit\Form - */ - public function getEditFormBlock() - { - return Factory::getBlockFactory()->getMagentoUserUserEditForm( - $this->_browser->find($this->editFormBlock, Locator::SELECTOR_ID) - ); - } - - /** - * Get global messages block - * - * @return \Magento\Core\Test\Block\Messages - */ - public function getMessagesBlock() - { - return Factory::getBlockFactory()->getMagentoCoreMessages( - $this->_browser->find($this->messagesBlock) - ); - } - - /** - * Get Role grid - * - * @return \Magento\User\Test\Block\User\Edit\Tab\Roles - */ - public function getRoleGridBlock() - { - return Factory::getBlockFactory()->getMagentoUserUserEditTabRoles( - $this->_browser->find($this->roleGridBlock, Locator::SELECTOR_ID) - ); - } - - /** - * Get Grid page actions block - * - * @return \Magento\User\Test\Block\Backend\UserEditPageActions - */ - public function getPageActionsBlock() - { - return Factory::getBlockFactory()->getMagentoUserBackendUserEditPageActions( - $this->_browser->find($this->pageActionsBlock) - ); - } -} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserIndex.php b/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserIndex.php deleted file mode 100644 index 2ab29dd452b0d..0000000000000 --- a/dev/tests/functional/tests/app/Magento/User/Test/Page/Backend/UserIndex.php +++ /dev/null @@ -1,105 +0,0 @@ -Permissions -> All Users page - * - */ -class UserIndex extends Page -{ - /** - * URL part for admin user page - */ - const MCA = 'admin/user/'; - - /** - * Admin User Grid on backend - * - * @var string - */ - protected $userGridBlock = 'permissionsUserGrid'; - - /** - * Message Block on page - * - * @var string - */ - protected $messagesBlock = '#messages .messages'; - - /** - * Admin header Block - * - * @var string - */ - protected $adminPanelHeaderBlock = 'page-header'; - - /** - * Constructor - */ - protected function _init() - { - $this->_url = $_ENV['app_backend_url'] . self::MCA; - } - - /** - * Get User Grid block - * - * @return \Magento\User\Test\Block\Backend\UserGrid - */ - public function getUserGridBlock() - { - return Factory::getBlockFactory()->getMagentoUserBackendUserGrid( - $this->_browser->find($this->userGridBlock, Locator::SELECTOR_ID) - ); - } - - /** - * Get global messages block - * - * @return \Magento\Core\Test\Block\Messages - */ - public function getMessagesBlock() - { - return Factory::getBlockFactory()->getMagentoCoreMessages($this->_browser->find($this->messagesBlock)); - } - - /** - * Get Admin Panel Header Block - * - * @return \Magento\Backend\Test\Block\Page\Header - */ - public function getAdminPanelHeaderBlock() - { - return Factory::getBlockFactory()->getMagentoBackendPageHeader( - $this->_browser->find($this->adminPanelHeaderBlock, Locator::SELECTOR_CLASS_NAME) - ); - } -} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserInjectable.php b/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserInjectable.php index 7dd1a13099823..feeccc7cd5cfb 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserInjectable.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserInjectable.php @@ -28,36 +28,33 @@ /** * Class Admin User Repository - * */ class AdminUserInjectable extends AbstractRepository { - /* + /** * @constructor * @param array $defaultConfig * @param array $defaultData */ public function __construct(array $defaultConfig = [], array $defaultData = []) { - $this->_data['custom_admin'] = [ - 'username' => 'AdminUser%isolation%', + $this->_data['default'] = [ + 'username' => 'admin', 'firstname' => 'FirstName%isolation%', 'lastname' => 'LastName%isolation%', 'email' => 'email%isolation%@example.com', 'password' => '123123q', 'password_confirmation' => '123123q', - 'user_role' => 'user_role%isolation%' + 'user_id' => 1 ]; - $this->_data['default_admin'] = [ - 'username' => 'admin', + $this->_data['custom_admin'] = [ + 'username' => 'AdminUser%isolation%', 'firstname' => 'FirstName%isolation%', 'lastname' => 'LastName%isolation%', 'email' => 'email%isolation%@example.com', 'password' => '123123q', 'password_confirmation' => '123123q', - 'user_role' => 'Administrators', - 'user_id' => '1' ]; } } diff --git a/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserRole.php b/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserRole.php index c162f8898a877..c50b52232b9c7 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserRole.php +++ b/dev/tests/functional/tests/app/Magento/User/Test/Repository/AdminUserRole.php @@ -32,6 +32,7 @@ class AdminUserRole extends AbstractRepository { /** + * @constructor * @param array $defaultConfig * @param array $defaultData */ diff --git a/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest.php b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest.php new file mode 100644 index 0000000000000..97cc5a45aa7b8 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest.php @@ -0,0 +1,153 @@ +Permissions>All Users + * 3. Open admin user from precondition + * 4. Click "Delete User" button + * 5. Perform all assertions + * + * @group ACL_(MX) + * @ZephyrId MAGETWO-23416 + */ +class DeleteAdminUserEntityTest extends Injectable +{ + /** + * @var UserIndex + */ + protected $userIndex; + + /** + * @var UserEdit + */ + protected $userEdit; + + /** + * @var Dashboard + */ + protected $dashboard; + + /** + * @var AdminAuthLogin + */ + protected $adminAuthLogin; + + /** + * Preparing preconditions for test. + * + * @param FixtureFactory $fixtureFactory + * @return array + */ + public function __prepare(FixtureFactory $fixtureFactory) + { + $role = $fixtureFactory->createByCode('adminUserRole', ['dataSet' => 'default']); + $role->persist(); + $role_id = $role->getData('role_id'); + $adminUser = $fixtureFactory->createByCode( + 'adminUserInjectable', + [ + 'dataSet' => 'custom_admin', + 'data' => ['role_id' => $role_id] + ] + ); + $adminUser->persist(); + + return [ + 'adminUser' => $adminUser + ]; + } + + /** + * Preparing pages for each test iteration. + * + * @param UserIndex $userIndex + * @param UserEdit $userEdit + * @param Dashboard $dashboard + * @param AdminAuthLogin $adminAuthLogin + * @return array + */ + public function __inject( + UserIndex $userIndex, + UserEdit $userEdit, + Dashboard $dashboard, + AdminAuthLogin $adminAuthLogin + ) { + $this->userIndex = $userIndex; + $this->userEdit = $userEdit; + $this->dashboard = $dashboard; + $this->adminAuthLogin = $adminAuthLogin; + } + + /** + * Runs Delete User Entity test + * + * @param AdminUserInjectable $adminUser + * @param string $isDefaultUser + * @return void + */ + public function testDeleteAdminUserEntity( + AdminUserInjectable $adminUser, + $isDefaultUser + ) { + $filter = [ + 'username' => $adminUser->getUsername() + ]; + //Steps + if ($isDefaultUser == 0) { + $this->adminAuthLogin->open(); + $this->adminAuthLogin->getLoginBlock()->fill($adminUser); + $this->adminAuthLogin->getLoginBlock()->submit(); + } + $this->userIndex->open(); + $this->userIndex->getUserGrid()->searchAndOpen($filter); + $this->userEdit->getPageActions()->delete(); + } + + /** + * Logout Admin User from account + * + * return void + */ + public function tearDown() + { + $this->dashboard->getAdminPanelHeader()->logOut(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest/testDeleteAdminUserEntity.csv b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest/testDeleteAdminUserEntity.csv new file mode 100644 index 0000000000000..60040ccc535ca --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/User/Test/TestCase/DeleteAdminUserEntityTest/testDeleteAdminUserEntity.csv @@ -0,0 +1,3 @@ +"isDefaultUser";"constraint" +"0";"assertImpossibleDeleteYourOwnAccount, assertUserInGrid" +"1";"assertUserSuccessDeleteMessage, assertUserNotInGrid" diff --git a/dev/tests/functional/tests/app/Magento/User/Test/etc/curl/di.xml b/dev/tests/functional/tests/app/Magento/User/Test/etc/curl/di.xml index 2b731bc10bd55..60f06e7f1110f 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/etc/curl/di.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/etc/curl/di.xml @@ -23,7 +23,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ --> - - - - + + + + \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/constraint.xml b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/constraint.xml index d35518ac3c7f1..1107ec8a9371b 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/constraint.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/constraint.xml @@ -36,34 +36,59 @@ - - low - - - - + + low + + + + low - + low - + low + + + low + + + + low + + low + + + + + + low + + + + + + low + + + + diff --git a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/fixture.xml b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/fixture.xml index 529ab99fd95c9..097d3e5dd5e46 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/fixture.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/fixture.xml @@ -24,11 +24,6 @@ */ --> - - flat - admin_user - Magento\User\Model\Resource\User\Collection - flat admin_user diff --git a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/page.xml b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/page.xml index e5a2ec81677b2..a5b7baf8dbfff 100644 --- a/dev/tests/functional/tests/app/Magento/User/Test/etc/global/page.xml +++ b/dev/tests/functional/tests/app/Magento/User/Test/etc/global/page.xml @@ -34,8 +34,14 @@ adminhtml Magento\User\Test\Page\Adminhtml\UserRoleEditRole - - admin/auth/login - Magento\User\Test\Page\Adminhtml\AdminAuthLogin - + + admin/user + adminhtml + Magento\User\Test\Page\Adminhtml\UserIndex + + + admin/user/edit + adminhtml + Magento\User\Test\Page\Adminhtml\UserEdit + \ No newline at end of file diff --git a/dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/TestCaseProperties.php b/dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/TestCaseProperties.php index ec8d844915e94..2a31fbdf52605 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/TestCaseProperties.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Workaround/Cleanup/TestCaseProperties.php @@ -44,7 +44,7 @@ public function endTestSuite(\PHPUnit_Framework_TestSuite $suite) foreach ($properties as $property) { $property->setAccessible(true); $value = $property->getValue($test); - if (is_object($value) && method_exists($value, '__destruct')) { + if (is_object($value) && method_exists($value, '__destruct') && is_callable([$value, '__destruct'])) { $value->__destruct(); } $property->setValue($test, null); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php new file mode 100644 index 0000000000000..7f95890098d61 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php @@ -0,0 +1,95 @@ +source = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + 'Magento\Catalog\Model\Resource\Product\Indexer\Eav\Source' + ); + + /** @var \Magento\Catalog\Model\Resource\Product $productResource */ + $this->productResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( + 'Magento\Catalog\Model\Resource\Product' + ); + } + + /** + * Test reindex for configurable product with both disabled and enabled variations. + */ + public function testReindexEntitiesForConfigurableProduct() + { + /** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attr **/ + $attr = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Eav\Model\Config') + ->getAttribute('catalog_product', 'test_configurable'); + $attr->setIsFilterable(1)->save(); + + /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection $options **/ + $options = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + 'Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection' + ); + $options->setAttributeFilter($attr->getId())->load(); + $optionIds = $options->getAllIds(); + + $adapter = $this->productResource->getReadConnection(); + $select = $adapter->select()->from($this->productResource->getTable('catalog_product_index_eav')) + ->where('entity_id = ?', 1) + ->where('attribute_id = ?', $attr->getId()) + ->where('value IN (?)', $optionIds); + + $result = $adapter->fetchAll($select); + $this->assertCount(2, $result); + + /** @var \Magento\Catalog\Model\Product $product1 **/ + $product1 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Catalog\Model\Product'); + $product1 = $product1->load($optionIds[0] * 10); + $product1->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)->save(); + + /** @var \Magento\Catalog\Model\Product $product2 **/ + $product2 = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Catalog\Model\Product'); + $product2 = $product2->load($optionIds[1] * 10); + $product2->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)->save(); + + $result = $adapter->fetchAll($select); + $this->assertCount(0, $result); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_ccsave_payment.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_rollback.php similarity index 62% rename from dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_ccsave_payment.php rename to dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_rollback.php index 33a4ed1899068..6ffb72acf9bb1 100644 --- a/dev/tests/integration/testsuite/Magento/Checkout/_files/quote_with_ccsave_payment.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_rollback.php @@ -22,15 +22,18 @@ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -require 'quote_with_address.php'; -/** @var \Magento\Sales\Model\Quote $quote */ +/** @var \Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get('Magento\Framework\Registry'); -$quote->getShippingAddress()->setShippingMethod('flatrate_flatrate'); -$quote->getPayment()->setMethod('ccsave'); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); -$quote->collectTotals(); -$quote->save(); +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(1); +if ($product->getId()) { + $product->delete(); +} -$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); -$quoteService = $objectManager->create('Magento\Sales\Model\Service\Quote', array('quote' => $quote)); -$quoteService->getQuote()->getPayment()->setMethod('ccsave'); +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual_rollback.php new file mode 100644 index 0000000000000..a1bb99f463d4c --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_virtual_rollback.php @@ -0,0 +1,39 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(21); +if ($product->getId()) { + $product->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/products_crosssell_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_crosssell_rollback.php new file mode 100644 index 0000000000000..e0138c03c9b45 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_crosssell_rollback.php @@ -0,0 +1,46 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var $crossProduct \Magento\Catalog\Model\Product */ +$crossProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$crossProduct->load(1); +if ($crossProduct->getId()) { + $crossProduct->delete(); +} + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(2); +if ($product->getId()) { + $product->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/products_new_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_new_rollback.php new file mode 100644 index 0000000000000..d3afe5486389e --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_new_rollback.php @@ -0,0 +1,38 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(1); +if ($product->getId()) { + $product->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/products_related_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_related_rollback.php new file mode 100644 index 0000000000000..eb54578000682 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_related_rollback.php @@ -0,0 +1,46 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var $relatedProduct \Magento\Catalog\Model\Product */ +$relatedProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$relatedProduct->load(1); +if ($relatedProduct->getId()) { + $relatedProduct->delete(); +} + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(2); +if ($product->getId()) { + $product->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell.php new file mode 100644 index 0000000000000..31bad3794336d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell.php @@ -0,0 +1,72 @@ +create('Magento\Catalog\Model\Product'); +$product->setTypeId( + \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE +)->setId( + 1 +)->setAttributeSetId( + 4 +)->setName( + 'Simple Up Sell' +)->setSku( + 'simple' +)->setPrice( + 100 +)->setVisibility( + \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH +)->setStatus( + \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED +)->setWebsiteIds( + array(1) +)->setStockData( + array('qty' => 100, 'is_in_stock' => 1) +)->save(); + +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->setTypeId( + \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE +)->setId( + 2 +)->setAttributeSetId( + 4 +)->setName( + 'Simple Product With Up Sell' +)->setSku( + 'simple_with_upsell' +)->setPrice( + 10 +)->setVisibility( + \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH +)->setStatus( + \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED +)->setWebsiteIds( + array(1) +)->setStockData( + array('qty' => 100, 'is_in_stock' => 1) +)->setUpSellLinkData( + array(1 => array('position' => 1)) +)->save(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell_rollback.php new file mode 100644 index 0000000000000..f15594777e558 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/products_upsell_rollback.php @@ -0,0 +1,45 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var $upSellProduct \Magento\Catalog\Model\Product */ +$upSellProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$upSellProduct->load(1); +if ($upSellProduct->getId()) { + $upSellProduct->delete(); +} + +/** @var $product \Magento\Catalog\Model\Product */ +$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$product->load(2); +if ($product->getId()) { + $product->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/Centinel/CreateOrderTest.php b/dev/tests/integration/testsuite/Magento/Centinel/CreateOrderTest.php index 5b6f063d36b59..e32afba7425f2 100644 --- a/dev/tests/integration/testsuite/Magento/Centinel/CreateOrderTest.php +++ b/dev/tests/integration/testsuite/Magento/Centinel/CreateOrderTest.php @@ -28,6 +28,12 @@ */ class CreateOrderTest extends \Magento\Backend\Utility\Controller { + public function setUp() + { + parent::setUp(); + $this->markTestIncomplete('MAGETWO-24796: [TD] Fix integration test according to story MAGETWO-23885'); + } + /** * @magentoConfigFixture default_store payment/ccsave/centinel 1 * @magentoDataFixture Magento/Catalog/_files/product_simple.php diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index b0add5539b38b..5bd46f2824fc0 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -458,10 +458,10 @@ public function testGenerateSimpleProducts($productsData) /** * @param array $productsData - * @dataProvider generateSimpleProductsWithoutQtyDataProvider + * @dataProvider generateSimpleProductsWithPartialDataDataProvider * @magentoDbIsolation enabled */ - public function testGenerateSimpleProductsWithoutQty($productsData) + public function testGenerateSimpleProductsWithPartialData($productsData) { $this->_product->setNewVariationsAttributeSetId(4); $generatedProducts = $this->_model->generateSimpleProducts($this->_product, $productsData); @@ -472,6 +472,7 @@ public function testGenerateSimpleProductsWithoutQty($productsData) ); $product->load($productId); $this->assertEquals('0', $product->getStockItem()->getData('manage_stock')); + $this->assertEquals('1', $product->getStockItem()->getData('is_in_stock')); } } @@ -515,7 +516,7 @@ public static function generateSimpleProductsDataProvider() /** * @return array */ - public static function generateSimpleProductsWithoutQtyDataProvider() + public static function generateSimpleProductsWithPartialDataDataProvider() { return array( array( diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/Edit/FormTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/Edit/FormTest.php index c08088f6cc346..2c6cf5b1d62c2 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/Edit/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/Edit/FormTest.php @@ -106,10 +106,11 @@ public function testGetForm() */ public function testGetFormExistInCustomGroup() { + $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Service\V1\Data\FilterBuilder'); /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchCriteria */ $searchCriteria = Bootstrap::getObjectManager() ->create('Magento\Framework\Service\V1\Data\SearchCriteriaBuilder') - ->addFilter([(new FilterBuilder())->setField('code')->setValue('custom_group')->create()])->create(); + ->addFilter([$builder->setField('code')->setValue('custom_group')->create()])->create(); /** @var CustomerGroup $customerGroup */ $customerGroup = $this->customerGroupService->searchGroups($searchCriteria)->getItems()[0]; $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/EditTest.php b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/EditTest.php index 41f7651b6d263..0a44b35075f92 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/EditTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Group/EditTest.php @@ -97,10 +97,11 @@ public function testDeleteButtonNotExistInDefaultGroup() */ public function testDeleteButtonExistInCustomGroup() { + $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Service\V1\Data\FilterBuilder'); /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchCriteria */ $searchCriteria = Bootstrap::getObjectManager() ->create('Magento\Framework\Service\V1\Data\SearchCriteriaBuilder') - ->addFilter([(new FilterBuilder())->setField('code')->setValue('custom_group')->create()])->create(); + ->addFilter([$builder->setField('code')->setValue('custom_group')->create()])->create(); /** @var CustomerGroup $customerGroup */ $customerGroup = $this->customerGroupService->searchGroups($searchCriteria)->getItems()[0]; $this->getRequest()->setParam('id', $customerGroup->getId()); diff --git a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php index efc37113916b6..fd36e4dfd62dd 100755 --- a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php @@ -76,6 +76,7 @@ protected function setUp() $this->_customerDetailsBuilder = $this->_objectManager->create('Magento\Customer\Service\V1\Data\CustomerDetailsBuilder'); + $regionBuilder = $this->_objectManager->create('Magento\Customer\Service\V1\Data\RegionBuilder'); $this->_addressBuilder->setId(1) ->setCountryId('US') ->setCustomerId(1) @@ -83,7 +84,7 @@ protected function setUp() ->setDefaultShipping(true) ->setPostcode('75477') ->setRegion( - (new V1\Data\RegionBuilder())->setRegionCode('AL')->setRegion('Alabama')->setRegionId(1)->create() + $regionBuilder->setRegionCode('AL')->setRegion('Alabama')->setRegionId(1)->create() ) ->setStreet(['Green str, 67']) ->setTelephone('3468676') @@ -99,7 +100,7 @@ protected function setUp() ->setDefaultShipping(false) ->setPostcode('47676') ->setRegion( - (new V1\Data\RegionBuilder())->setRegionCode('AL')->setRegion('Alabama')->setRegionId(1)->create() + $regionBuilder->setRegionCode('AL')->setRegion('Alabama')->setRegionId(1)->create() ) ->setStreet(['Black str, 48']) ->setCity('CityX') @@ -1217,22 +1218,23 @@ public function testSearchCustomers($filters, $filterGroup, $expectedResult) public function searchCustomersDataProvider() { + $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Service\V1\Data\FilterBuilder'); return [ 'Customer with specific email' => [ - [(new FilterBuilder())->setField('email')->setValue('customer@search.example.com')->create()], + [$builder->setField('email')->setValue('customer@search.example.com')->create()], null, [1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname']] ], 'Customer with specific first name' => [ - [(new FilterBuilder())->setField('firstname')->setValue('Firstname2')->create()], + [$builder->setField('firstname')->setValue('Firstname2')->create()], null, [2 => ['email' => 'customer2@search.example.com', 'firstname' => 'Firstname2']] ], 'Customers with either email' => [ [], [ - (new FilterBuilder())->setField('firstname')->setValue('Firstname')->create(), - (new FilterBuilder())->setField('firstname')->setValue('Firstname2')->create() + $builder->setField('firstname')->setValue('Firstname')->create(), + $builder->setField('firstname')->setValue('Firstname2')->create() ], [ 1 => ['email' => 'customer@search.example.com', 'firstname' => 'Firstname'], @@ -1241,7 +1243,7 @@ public function searchCustomersDataProvider() ], 'Customers created since' => [ [ - (new FilterBuilder())->setField('created_at')->setValue('2011-02-28 15:52:26') + $builder->setField('created_at')->setValue('2011-02-28 15:52:26') ->setConditionType('gt')->create() ], [], @@ -1266,7 +1268,7 @@ public function testSearchCustomersOrder() ->create('Magento\Framework\Service\V1\Data\SearchCriteriaBuilder'); // Filter for 'firstname' like 'First' - $filterBuilder = new FilterBuilder(); + $filterBuilder = $this->_objectManager->create('\Magento\Framework\Service\V1\Data\FilterBuilder'); $firstnameFilter = $filterBuilder->setField('firstname') ->setConditionType('like') ->setValue('First%') diff --git a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php index ec65c59b472e1..767f5b0a12900 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php @@ -60,7 +60,8 @@ protected function setUp() $this->_addressBuilder = $this->_objectManager->create('Magento\Customer\Service\V1\Data\AddressBuilder'); $this->_customerBuilder = $this->_objectManager->create('Magento\Customer\Service\V1\Data\CustomerBuilder'); - $region = (new \Magento\Customer\Service\V1\Data\RegionBuilder()) + $builder = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\RegionBuilder'); + $region = $builder ->setRegionCode('AL') ->setRegion('Alabama') ->setRegionId(1) diff --git a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerGroupServiceTest.php b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerGroupServiceTest.php index 38b6d90703496..90053a700c367 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerGroupServiceTest.php +++ b/dev/tests/integration/testsuite/Magento/Customer/Service/V1/CustomerGroupServiceTest.php @@ -143,7 +143,8 @@ public function getGroupsDataProvider() public function testCreateGroup() { - $group = (new Data\CustomerGroupBuilder())->setId(null)->setCode('Test Group')->setTaxClassId(3)->create(); + $builder = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\CustomerGroupBuilder'); + $group = $builder->setId(null)->setCode('Test Group')->setTaxClassId(3)->create(); $groupId = $this->_groupService->saveGroup($group); $this->assertNotNull($groupId); @@ -155,7 +156,8 @@ public function testCreateGroup() public function testUpdateGroup() { - $group = (new Data\CustomerGroupBuilder())->setId(null)->setCode('New Group')->setTaxClassId(3)->create(); + $builder = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\CustomerGroupBuilder'); + $group = $builder->setId(null)->setCode('New Group')->setTaxClassId(3)->create(); $groupId = $this->_groupService->saveGroup($group); $this->assertNotNull($groupId); @@ -164,7 +166,7 @@ public function testUpdateGroup() $this->assertEquals($group->getCode(), $newGroup->getCode()); $this->assertEquals($group->getTaxClassId(), $newGroup->getTaxClassId()); - $updates = (new Data\CustomerGroupBuilder())->setId($groupId)->setCode('Updated Group')->setTaxClassId(3) + $updates = $builder->setId($groupId)->setCode('Updated Group')->setTaxClassId(3) ->create(); $newId = $this->_groupService->saveGroup($updates); $this->assertEquals($newId, $groupId); @@ -256,17 +258,18 @@ public function testSearchGroups($filters, $filterGroup, $expectedResult) public function searchGroupsDataProvider() { + $builder = Bootstrap::getObjectManager()->create('\Magento\Framework\Service\V1\Data\FilterBuilder'); return [ 'eq' => [ - [(new FilterBuilder())->setField(CustomerGroup::CODE)->setValue('General')->create()], + [$builder->setField(CustomerGroup::CODE)->setValue('General')->create()], null, [1 => [CustomerGroup::CODE => 'General', CustomerGroup::TAX_CLASS_ID => 3]] ], 'and' => [ [ - (new FilterBuilder())->setField(CustomerGroup::CODE)->setValue('General')->create(), - (new FilterBuilder())->setField(CustomerGroup::TAX_CLASS_ID)->setValue('3')->create(), - (new FilterBuilder())->setField(CustomerGroup::ID)->setValue('1')->create(), + $builder->setField(CustomerGroup::CODE)->setValue('General')->create(), + $builder->setField(CustomerGroup::TAX_CLASS_ID)->setValue('3')->create(), + $builder->setField(CustomerGroup::ID)->setValue('1')->create(), ], [], [1 => [CustomerGroup::CODE => 'General', CustomerGroup::TAX_CLASS_ID => 3]] @@ -274,8 +277,8 @@ public function searchGroupsDataProvider() 'or' => [ [], [ - (new FilterBuilder())->setField(CustomerGroup::CODE)->setValue('General')->create(), - (new FilterBuilder())->setField(CustomerGroup::CODE)->setValue('Wholesale')->create(), + $builder->setField(CustomerGroup::CODE)->setValue('General')->create(), + $builder->setField(CustomerGroup::CODE)->setValue('Wholesale')->create(), ], [ 1 => [CustomerGroup::CODE => 'General', CustomerGroup::TAX_CLASS_ID => 3], @@ -284,7 +287,7 @@ public function searchGroupsDataProvider() ], 'like' => [ [ - (new FilterBuilder())->setField(CustomerGroup::CODE)->setValue('er')->setConditionType('like') + $builder->setField(CustomerGroup::CODE)->setValue('er')->setConditionType('like') ->create() ], [], diff --git a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_group.php b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_group.php index a99badfc75386..2bbf2c1bed2fc 100644 --- a/dev/tests/integration/testsuite/Magento/Customer/_files/customer_group.php +++ b/dev/tests/integration/testsuite/Magento/Customer/_files/customer_group.php @@ -25,10 +25,11 @@ $customerGroupService = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( 'Magento\Customer\Service\V1\CustomerGroupService' ); -$customerGroupBuilder = (new Magento\Customer\Service\V1\Data\CustomerGroupBuilder())->setCode( - 'custom_group' -)->setTaxClassId( - 3 + +$builder = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + '\Magento\Customer\Service\V1\Data\CustomerGroupBuilder' ); +$customerGroupBuilder = $builder->setCode('custom_group')->setTaxClassId(3); + $customerGroup = new Magento\Customer\Service\V1\Data\CustomerGroup($customerGroupBuilder); $customerGroupService->saveGroup($customerGroup); diff --git a/dev/tests/integration/testsuite/Magento/DesignEditor/Model/Translate/_files/_inline_page_original.html b/dev/tests/integration/testsuite/Magento/DesignEditor/Model/Translate/_files/_inline_page_original.html index 7c275839c59e0..e242158b1386f 100644 --- a/dev/tests/integration/testsuite/Magento/DesignEditor/Model/Translate/_files/_inline_page_original.html +++ b/dev/tests/integration/testsuite/Magento/DesignEditor/Model/Translate/_files/_inline_page_original.html @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_DesignEditor - * @subpackage integration_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_rollback.php b/dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_rollback.php new file mode 100644 index 0000000000000..68994cbb42c94 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/GroupedProduct/_files/product_grouped_rollback.php @@ -0,0 +1,54 @@ +get('Magento\Framework\Registry'); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + + +/** @var $simpleProduct \Magento\Catalog\Model\Product */ +$simpleProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$simpleProduct->load(2); +if ($simpleProduct->getId()) { + $simpleProduct->delete(); +} + +/** @var $virtualProduct \Magento\Catalog\Model\Product */ +$virtualProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$virtualProduct->load(21); +if ($virtualProduct->getId()) { + $virtualProduct->delete(); +} + +/** @var $groupedProduct \Magento\Catalog\Model\Product */ +$groupedProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Catalog\Model\Product'); +$groupedProduct->load(9); +if ($groupedProduct->getId()) { + $groupedProduct->delete(); +} + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/product_with_custom_options.csv b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/product_with_custom_options.csv index d75112c11cbf9..f0dcc3da8b4fe 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/product_with_custom_options.csv +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/product_with_custom_options.csv @@ -1,4 +1,4 @@ -"sku","_store","_attribute_set","_type","_category","_root_category","_product_websites","color","cost","country_of_manufacture","created_at","custom_design","custom_design_from","custom_design_to","custom_layout_update","description","gallery","gift_message_available","has_options","image","image_label","manufacturer","media_gallery","meta_description","meta_keyword","meta_title","minimal_price","msrp","msrp_display_actual_price_type","msrp_enabled","name","news_from_date","news_to_date","options_container","page_layout","price","required_options","short_description","small_image","small_image_label","special_from_date","special_price","special_to_date","status","tax_class_id","thumbnail","thumbnail_label","updated_at","url_key","url_path","visibility","weight","qty","min_qty","use_config_min_qty","is_qty_decimal","backorders","use_config_backorders","min_sale_qty","use_config_min_sale_qty","max_sale_qty","use_config_max_sale_qty","is_in_stock","notify_stock_qty","use_config_notify_stock_qty","manage_stock","use_config_manage_stock","use_config_qty_increments","qty_increments","use_config_enable_qty_inc","enable_qty_increments","is_decimal_divided","_links_related_sku","_links_related_position","_links_crosssell_sku","_links_crosssell_position","_links_upsell_sku","_links_upsell_position","_associated_sku","_associated_default_qty","_associated_position","_tier_price_website","_tier_price_customer_group","_tier_price_qty","_tier_price_price","_group_price_website","_group_price_customer_group","_group_price_price","_media_attribute_id","_media_image","_media_label","_media_position","_media_is_disabled","_custom_option_store","_custom_option_type","_custom_option_title","_custom_option_is_required","_custom_option_price","_custom_option_sku","_custom_option_max_characters","_custom_option_sort_order","_custom_option_row_title","_custom_option_row_price","_custom_option_row_sku","_custom_option_row_sort" +"sku","_store","_attribute_set","_type","_category","_root_category","_product_websites","color","cost","country_of_manufacture","created_at","custom_design","custom_design_from","custom_design_to","custom_layout_update","description","gallery","gift_message_available","has_options","image","image_label","manufacturer","media_gallery","meta_description","meta_keyword","meta_title","minimal_price","msrp","msrp_display_actual_price_type","msrp_enabled","name","news_from_date","news_to_date","options_container","page_layout","price","required_options","short_description","small_image","small_image_label","special_from_date","special_price","special_to_date","status","tax_class_id","thumbnail","thumbnail_label","updated_at","url_key","url_path","visibility","weight","qty","min_qty","use_config_min_qty","is_qty_decimal","backorders","use_config_backorders","min_sale_qty","use_config_min_sale_qty","max_sale_qty","use_config_max_sale_qty","is_in_stock","notify_stock_qty","use_config_notify_stock_qty","manage_stock","use_config_manage_stock","use_config_qty_increments","qty_increments","use_config_enable_qty_inc","enable_qty_increments","is_decimal_divided","_related_sku","_related_position","_crosssell_sku","_crosssell_position","_upsell_sku","_upsell_position","_associated_sku","_associated_default_qty","_associated_position","_tier_price_website","_tier_price_customer_group","_tier_price_qty","_tier_price_price","_group_price_website","_group_price_customer_group","_group_price_price","_media_attribute_id","_media_image","_media_label","_media_position","_media_is_disabled","_custom_option_store","_custom_option_type","_custom_option_title","_custom_option_is_required","_custom_option_price","_custom_option_sku","_custom_option_max_characters","_custom_option_sort_order","_custom_option_row_title","_custom_option_row_price","_custom_option_row_sku","_custom_option_row_sort" "simple",,"Default","simple",,,"base",,,,,,,,,,,,1,,,,,,,,,,,,"New Product",,,"Block after Info Column",,"10.0000",1,,,,,,,1,,,,"2012-07-13 12:04:17","new-product","new-product.html",4,,"100.0000","0.0000",1,0,0,1,"1.0000",1,"0.0000",1,1,,1,0,1,1,"0.0000",1,0,0,,,,,,,,,,,,,,,,,,,,,,,"field","Test Field",1,"1.0000","1-text",100,0,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,default,,"Test Field",,,,,,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"date_time","Test Date and Time",1,"2.0000","2-date",,0,,,, diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/products_to_import_invalid_attribute_set.csv b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/products_to_import_invalid_attribute_set.csv index 8976e7f7f246e..3f852c2b90c60 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/products_to_import_invalid_attribute_set.csv +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Model/Import/Entity/_files/products_to_import_invalid_attribute_set.csv @@ -1,4 +1,4 @@ -sku,price,name,_type,_attribute_set,_links_upsell_sku,description +sku,price,name,_type,_attribute_set,_upsell_sku,description simple1,25,"Simple Product",simple,Default,,description simple2,NULL,"Simple Product2",invalid attribute set,Default,,HiThere simple3,58,"Simple Product 3",simple,Default,simple2,description diff --git a/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractTest.php b/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractTest.php index 419c47799ccb5..166f138ed9296 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/Form/AbstractTest.php @@ -67,10 +67,16 @@ public function testAddAttributesToForm() $formFactory = $objectManager->get('Magento\Framework\Data\FormFactory'); $form = $formFactory->create(); $fieldset = $form->addFieldset('test_fieldset', array()); - $dateAttribute = (new AttributeMetadataBuilder( - new OptionBuilder(), - new ValidationRuleBuilder() - ))->setAttributeCode( + $attributeBuilder = $objectManager->create( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + [ + 'optionBuilder' => $objectManager->create('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'), + 'validationRuleBuilder' => $objectManager->create( + '\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder' + ), + ] + ); + $dateAttribute = $attributeBuilder->setAttributeCode( 'date' )->setBackendType( 'datetime' diff --git a/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/FormTest.php b/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/FormTest.php index 1e4b6478cfea1..8b395149a37f8 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/FormTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Block/Adminhtml/Order/Create/FormTest.php @@ -107,6 +107,9 @@ public function testOrderDataJson() private function setUpMockAddress() { + $regionBuilder1 = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\RegionBuilder'); + $regionBuilder2 = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\RegionBuilder'); + /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder */ $addressBuilder = $this->_objectManager->create('Magento\Customer\Service\V1\Data\AddressBuilder'); /** @var \Magento\Customer\Service\V1\CustomerAddressServiceInterface $addressService */ @@ -126,7 +129,7 @@ private function setUpMockAddress() '75477' )->setRegion( new V1\Data\Region( - (new V1\Data\RegionBuilder())->populateWithArray( + $regionBuilder1->populateWithArray( array('region_code' => 'AL', 'region' => 'Alabama', 'region_id' => 1) ) ) @@ -156,7 +159,7 @@ private function setUpMockAddress() '47676' )->setRegion( new V1\Data\Region( - (new V1\Data\RegionBuilder())->populateWithArray( + $regionBuilder2->populateWithArray( array('region_code' => 'AL', 'region' => 'Alabama', 'region_id' => 1) ) ) diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index f34d88da2cb59..f9f373c06b995 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -138,33 +138,6 @@ public function testInitFromOrderCcInformationDeleted() $this->assertNull($payment->getCcLast4()); } - /** - * @magentoDataFixture Magento/Sales/_files/order_paid_with_saved_cc.php - */ - public function testInitFromOrderSavedCcInformationNotDeleted() - { - /** @var $objectManager \Magento\TestFramework\ObjectManager */ - $objectManager = Bootstrap::getObjectManager(); - - /** @var $order \Magento\Sales\Model\Order */ - $order = $objectManager->create('Magento\Sales\Model\Order'); - $order->loadByIncrementId('100000001'); - - $payment = $order->getPayment(); - $this->assertEquals('5', $payment->getCcExpMonth()); - $this->assertEquals('2016', $payment->getCcExpYear()); - $this->assertEquals('AE', $payment->getCcType()); - $this->assertEquals('0005', $payment->getCcLast4()); - - $objectManager->get('Magento\Framework\Registry')->unregister('rule_data'); - $payment = $this->_model->initFromOrder($order)->getQuote()->getPayment(); - - $this->assertEquals('5', $payment->getCcExpMonth()); - $this->assertEquals('2016', $payment->getCcExpYear()); - $this->assertEquals('AE', $payment->getCcType()); - $this->assertEquals('0005', $payment->getCcLast4()); - } - /** * @magentoAppIsolation enabled */ diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/Service/QuoteTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/Service/QuoteTest.php index d422d31701a7d..b6dc3f5470988 100755 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/Service/QuoteTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/Service/QuoteTest.php @@ -228,6 +228,7 @@ private function getSampleCustomerEntity() */ private function getSampleAddressEntity() { + $regionBuilder = Bootstrap::getObjectManager()->create('\Magento\Customer\Service\V1\Data\RegionBuilder'); $this->_customerAddressBuilder->setCountryId( 'US' )->setDefaultBilling( @@ -237,7 +238,7 @@ private function getSampleAddressEntity() )->setPostcode( '75477' )->setRegion( - (new RegionBuilder())->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL')->create() + $regionBuilder->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL')->create() )->setStreet( array('Green str, 67') )->setTelephone( @@ -260,7 +261,7 @@ private function getSampleAddressEntity() )->setPostcode( '47676' )->setRegion( - (new RegionBuilder())->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL')->create() + $regionBuilder->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL')->create() )->setStreet( array('Black str, 48') )->setCity( diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/order_paid_with_saved_cc.php b/dev/tests/integration/testsuite/Magento/Sales/_files/order_paid_with_saved_cc.php deleted file mode 100644 index 7bab4a6991f8e..0000000000000 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/order_paid_with_saved_cc.php +++ /dev/null @@ -1,64 +0,0 @@ -loadArea( - \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE -); - -$addressData = include __DIR__ . '/address_data.php'; - -$billingAddress = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - 'Magento\Sales\Model\Order\Address', - array('data' => $addressData) -); -$billingAddress->setAddressType('billing'); - -$shippingAddress = clone $billingAddress; -$shippingAddress->setId(null)->setAddressType('shipping'); - -$payment = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Sales\Model\Order\Payment'); -$payment->setMethod('ccsave')->setCcExpMonth('5')->setCcLast4('0005')->setCcType('AE')->setCcExpYear('2016'); - -$order = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\Sales\Model\Order'); -$order->setIncrementId( - '100000001' -)->setSubtotal( - 100 -)->setBaseSubtotal( - 100 -)->setCustomerIsGuest( - true -)->setBillingAddress( - $billingAddress -)->setShippingAddress( - $shippingAddress -)->setStoreId( - \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( - 'Magento\Store\Model\StoreManagerInterface' - )->getStore()->getId() -)->setPayment( - $payment -); - -$order->save(); diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php index be9f738483c99..30dca15ae9732 100644 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php +++ b/dev/tests/integration/testsuite/Magento/Tax/Model/Sales/Total/Quote/SetupUtil.php @@ -488,7 +488,7 @@ protected function createCustomerGroup($customerTaxClassId) { /** @var \Magento\Customer\Service\V1\CustomerGroupService $customerGroupService */ $customerGroupService = $this->objectManager->create('Magento\Customer\Service\V1\CustomerGroupService'); - $customerGroupBuilder = (new \Magento\Customer\Service\V1\Data\CustomerGroupBuilder()) + $customerGroupBuilder = $this->objectManager->create('\Magento\Customer\Service\V1\Data\CustomerGroupBuilder') ->setCode('custom_group') ->setTaxClassId($customerTaxClassId); $customerGroup = new \Magento\Customer\Service\V1\Data\CustomerGroup($customerGroupBuilder); diff --git a/dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/Type/CustomerTest.php b/dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/Type/CustomerTest.php index 6706fb04571d9..2c4621007df75 100644 --- a/dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/Type/CustomerTest.php +++ b/dev/tests/integration/testsuite/Magento/Tax/Model/TaxClass/Type/CustomerTest.php @@ -41,6 +41,7 @@ public function testIsAssignedToObjects() { /** @var $objectManager \Magento\TestFramework\ObjectManager */ $this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $builder = $this->_objectManager->create('\Magento\Customer\Service\V1\Data\CustomerGroupBuilder'); /* Create a tax class */ $model = $this->_objectManager->create('Magento\Tax\Model\ClassModel'); @@ -53,7 +54,7 @@ public function testIsAssignedToObjects() $model->setId($taxClassId); /** @var $customerGroupService \Magento\Customer\Service\V1\CustomerGroupServiceInterface */ $customerGroupService = $this->_objectManager->create('\Magento\Customer\Service\V1\CustomerGroupService'); - $group = (new CustomerGroupBuilder())->setId(null)->setCode(self::GROUP_CODE)->setTaxClassId($taxClassId) + $group = $builder->setId(null)->setCode(self::GROUP_CODE)->setTaxClassId($taxClassId) ->create(); $customerGroupService->saveGroup($group); diff --git a/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/design-abstraction_select.html b/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/design-abstraction_select.html index dd48203f1fa68..8349949dbe6bf 100644 --- a/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/design-abstraction_select.html +++ b/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/design-abstraction_select.html @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Widget - * @subpackage integration_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/page_types_select.html b/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/page_types_select.html index 503e3cfb2d896..bc52f9da0ece2 100644 --- a/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/page_types_select.html +++ b/dev/tests/integration/testsuite/Magento/Widget/Block/Adminhtml/Widget/Instance/Edit/Chooser/_files/page_types_select.html @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Widget - * @subpackage integration_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jmx b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jmx index 33a9e95f11a74..327c10bc179f6 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jmx +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jmx @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jtl b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jtl index 53fd0e6678c0e..91ed72017c4a4 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jtl +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario.jtl @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jmx b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jmx index 33a9e95f11a74..327c10bc179f6 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jmx +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jmx @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jtl b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jtl index 210427835de95..5d3f4c6ea18c9 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jtl +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_error.jtl @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jmx b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jmx index 33a9e95f11a74..327c10bc179f6 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jmx +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jmx @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jtl b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jtl index 5433d676347f0..b9420e16cf01d 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jtl +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_failure.jtl @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_without_report.jmx b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_without_report.jmx index 33a9e95f11a74..327c10bc179f6 100644 --- a/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_without_report.jmx +++ b/dev/tests/performance/framework/tests/unit/testsuite/Magento/Test/Performance/_files/scenario_without_report.jmx @@ -19,9 +19,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package performance_tests - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) */ diff --git a/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeSniffer.php b/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeSniffer.php index 8d2e932729d10..2650dfb0097fb 100644 --- a/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeSniffer.php +++ b/dev/tests/static/framework/Magento/TestFramework/CodingStandard/Tool/CodeSniffer.php @@ -120,7 +120,7 @@ function ($item) { $this->wrapper->checkRequirements(); $settings = $this->wrapper->getDefaults(); $settings['files'] = $whiteList; - $settings['standard'] = $this->rulesetDir; + $settings['standard'] = [$this->rulesetDir]; $settings['ignored'] = $blackList; $settings['extensions'] = $extensions; $settings['reportFile'] = $this->reportFile; diff --git a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/CodingStandard/Tool/CodeSnifferTest.php b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/CodingStandard/Tool/CodeSnifferTest.php index 2894dccb3f4a0..91ebc3b58dc8f 100644 --- a/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/CodingStandard/Tool/CodeSnifferTest.php +++ b/dev/tests/static/framework/tests/unit/testsuite/Magento/TestFramework/CodingStandard/Tool/CodeSnifferTest.php @@ -65,7 +65,7 @@ public function testRun() $expectedCliEmulation = array( 'files' => $whiteList, - 'standard' => self::RULE_SET, + 'standard' => [self::RULE_SET], 'ignored' => $blackList, 'extensions' => $extensions, 'reportFile' => self::REPORT_FILE, diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php index 57923ed71f614..f8bffc780f1b2 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php @@ -2517,6 +2517,13 @@ 'Magento\SalesArchive\Block\Adminhtml\Sales\Order\Grid\Button', 'Magento\SalesArchive\Block\Adminhtml\Sales\Order\Grid' ], + ['Magento\OfflinePayments\Block\Form\Ccsave'], + ['Magento\OfflinePayments\Block\Info\Ccsave'], + ['Magento\OfflinePayments\Model\Ccsave'], + ['Magento\Sales\Model\Payment\Method\Converter'], + ['Magento\Payment\Model\Config\Source\Allowedmethods'], + ['Magento\Paypal\Model\PayflowDirect'], + ['Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Store'], ['Magento\Framework\View\Url', 'Magento\Framework\View\Asset\Repository'], ['Magento\Less\File\Source\Base', 'Magento\Framework\View\File\Collector\Base'], ['Magento\Less\File\Source\Theme', 'Magento\Framework\View\File\Collector\ThemeModular'], @@ -2579,4 +2586,9 @@ ['Magento\Css\PreProcessor\Cache\CacheInterface'], ['Magento\Css\PreProcessor\Cache\CacheManager'], ['Magento\Framework\View\Design\FileResolution\Strategy\ViewInterface'], + [ + 'Magento\Bundle\Pricing\Price\BasePrice', + 'Magento\Catalog\Pricing\Price\BasePrice' + ], + ['\Magento\Bundle\Pricing\Price\BasePriceInterface'], ); diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php index 06439ab61e2ca..e3181c66e2a5f 100644 --- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php +++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php @@ -1696,6 +1696,12 @@ ['_isDataChanged', 'Magento\Catalog\Model\Product'], ['getVisibleOnFrontStates', 'Magento\Sales\Model\Order\Config', 'getVisibleOnFrontStatuses'], ['getInvisibleOnFrontStates', 'Magento\Sales\Model\Order\Config', 'getInvisibleOnFrontStatuses'], + ['_shouldBeConverted', 'Magento\Sales\Model\Resource\AbstractResource'], + ['_beforeSave', 'Magento\Sales\Model\Resource\AbstractResource'], + ['_afterSave', 'Magento\Sales\Model\Resource\AbstractResource'], + ['_afterLoad', 'Magento\Sales\Model\Resource\AbstractResource'], + ['getAllMethods', 'Magento\Payment\Model\Config'], + ['_getMethod', 'Magento\Payment\Model\Config'], ['getViewFileUrl', 'Magento\Framework\View\Url', 'Magento\Framework\View\Asset\Repository::getUrl'], ['getCssFiles', 'Magento\Core\Helper\Theme', 'Magento\Core\Helper\Theme::getCssAssets'], ['getGroupedCssFiles', 'Magento\Core\Helper\Theme'], diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt index def5917a24f6a..b3840585683fd 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt @@ -27,6 +27,7 @@ app/code/Magento/Catalog/Model/ProductOptions app/code/Magento/Catalog/Model/ProductTypes app/code/Magento/Catalog/Model/Plugin app/code/Magento/Catalog/Model/Observer/Reindex.php +app/code/Magento/Catalog/Service app/code/Magento/CatalogInventory/Block/Adminhtml/Form/Field/Stock.php app/code/Magento/Centinel/Model/State/Jcb.php app/code/Magento/Checkout/Block/Cart/Link.php @@ -64,6 +65,7 @@ app/code/Magento/Eav/Model/Cache/Type.php app/code/Magento/GiftMessage/Model/Plugin app/code/Magento/GoogleShopping/Block/SiteVerification.php app/code/Magento/GoogleShopping/Model/AttributeFactory.php +app/code/Magento/GroupedProduct/Service app/code/Magento/Eav/Model/Entity/Attribute/Config app/code/Magento/Eav/Model/Entity/Attribute/Config.php app/code/Magento/Email diff --git a/dev/tests/unit/framework/Magento/TestFramework/Helper/ObjectManager.php b/dev/tests/unit/framework/Magento/TestFramework/Helper/ObjectManager.php index 6d2c3a615a66b..36507e50baeeb 100644 --- a/dev/tests/unit/framework/Magento/TestFramework/Helper/ObjectManager.php +++ b/dev/tests/unit/framework/Magento/TestFramework/Helper/ObjectManager.php @@ -170,11 +170,46 @@ protected function _getMockWithoutConstructorCall($className) */ public function getObject($className, array $arguments = array()) { + if (is_subclass_of($className, '\Magento\Framework\Service\Data\AbstractObjectBuilder')) { + return $this->getBuilder($className, $arguments); + } $constructArguments = $this->getConstructArguments($className, $arguments); $reflectionClass = new \ReflectionClass($className); return $reflectionClass->newInstanceArgs($constructArguments); } + /** + * Get data object builder + * + * @param string $className + * @param array $arguments + * @return object + */ + protected function getBuilder($className, array $arguments) + { + $objectFactory = $this->_testObject->getMock('Magento\Framework\Service\Data\ObjectFactory', [], [], '', false); + + if (!isset($arguments['objectFactory'])) { + $arguments['objectFactory'] = $objectFactory; + } + + + $constructArguments = $this->getConstructArguments($className, $arguments); + $reflectionClass = new \ReflectionClass($className); + $builderObject = $reflectionClass->newInstanceArgs($constructArguments); + + $objectFactory->expects($this->_testObject->any()) + ->method('create') + ->will($this->_testObject->returnCallback( + function ($className, $arguments) { + $reflectionClass = new \ReflectionClass($className); + return $reflectionClass->newInstanceArgs($arguments); + } + )); + + return $builderObject; + } + /** * Retrieve list of arguments that used for new object instance creation * diff --git a/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/invalidSystemXmlArray.php b/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/invalidSystemXmlArray.php index a63ca7a436f5f..0dd4dc1228088 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/invalidSystemXmlArray.php +++ b/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/invalidSystemXmlArray.php @@ -45,8 +45,7 @@ '

' . '
', array( - "Element 'field': This element is not expected. Expected is one of ( label, class, tab, header_css, " . - "resource, group )." + "Element 'field': This element is not expected." ) ), 'group_id_not_unique' => array( @@ -165,14 +164,6 @@ '', array("Element 'options': Missing child element(s). Expected is ( option ).") ), - 'section_with_only_one_allowed_element' => array( - '
' . - '
', - array( - "Element 'section': Missing child element(s). Expected is one of ( label, class, tab, header_css, " . - "resource, group )." - ) - ), 'system_node_without_allowed_elements' => array( '', array("Element 'system': Missing child element(s). Expected is one of ( tab, section ).") diff --git a/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/valid_system.xml b/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/valid_system.xml index ecb0fbd2fd4c6..710be42b3cce6 100644 --- a/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/valid_system.xml +++ b/dev/tests/unit/testsuite/Magento/Backend/Model/Config/_files/valid_system.xml @@ -33,7 +33,6 @@ some_css 1 Some_Clone_Model - 1 Some_Source_Model diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/OptionTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/OptionTest.php index ee87e8a321ffd..8be08360ed1f3 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/OptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Block/Catalog/Product/View/Type/Bundle/OptionTest.php @@ -122,7 +122,7 @@ public function testRenderPriceString() ->disableOriginalConstructor() ->getMock(); - $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $amount = $this->getMock('Magento\Framework\Pricing\Amount\AmountInterface'); $priceRenderBlock = $this->getMockBuilder('Magento\Framework\Pricing\Render') diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Adjustment/CalculatorTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Adjustment/CalculatorTest.php index e7171e2b24438..5f7cbfb1931f4 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Adjustment/CalculatorTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Adjustment/CalculatorTest.php @@ -72,7 +72,7 @@ protected function setUp() ->setMethods(['getPriceInfo', 'getPriceType', '__wakeup']) ->disableOriginalConstructor() ->getMock(); - $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface', [], [], '', true); + $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $priceInfo->expects($this->any())->method('getPrice')->will($this->returnCallback(function ($type) { if (!isset($this->priceMocks[$type])) { throw new \PHPUnit_Framework_ExpectationFailedException('Unexpected type of price model'); diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BasePriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BasePriceTest.php deleted file mode 100644 index e74eb2e392014..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BasePriceTest.php +++ /dev/null @@ -1,123 +0,0 @@ -quantity = 1.5; - - $this->saleable = $this->getMockBuilder('Magento\Catalog\Model\Product') - ->disableOriginalConstructor() - ->getMock(); - - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); - - $this->saleable->expects($this->once()) - ->method('getPriceInfo') - ->will($this->returnValue($this->priceInfo)); - - $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->model = $objectHelper->getObject('Magento\Bundle\Pricing\Price\BasePrice', [ - 'saleableItem' => $this->saleable, - 'quantity' => $this->quantity - ]); - } - - /** - * @covers \Magento\Bundle\Pricing\Price\BasePrice::calculateBaseValue - * @covers \Magento\Bundle\Pricing\Price\BasePrice::getValue - */ - public function testGetValue() - { - $priceValues = [115, 90, 75]; - $tearPriceValue = 15; - $groupPriceValue = 10; - $specialPriceValue = 40; - $result = 45; - - $pricesIncludedInBase = []; - foreach ($priceValues as $priceValue) { - $price = $this->getMock('Magento\Catalog\Pricing\Price\RegularPrice', [], [], '', false); - $price->expects($this->atLeastOnce()) - ->method('getValue') - ->will($this->returnValue($priceValue)); - $pricesIncludedInBase[] = $price; - } - - $this->priceInfo->expects($this->once()) - ->method('getPrices') - ->will($this->returnValue($pricesIncludedInBase)); - - $tearPrice = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); - $tearPrice->expects($this->atLeastOnce()) - ->method('getValue') - ->will($this->returnValue($tearPriceValue)); - - $groupPrice = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); - $groupPrice->expects($this->atLeastOnce()) - ->method('getValue') - ->will($this->returnValue($groupPriceValue)); - - $specialPrice = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); - $specialPrice->expects($this->atLeastOnce()) - ->method('getValue') - ->will($this->returnValue($specialPriceValue)); - - $this->priceInfo->expects($this->any()) - ->method('getPrice') - ->will($this->returnValueMap([ - [CatalogPrice\TierPrice::PRICE_CODE, $this->quantity, $tearPrice], - [CatalogPrice\GroupPrice::PRICE_CODE, $this->quantity, $groupPrice], - [CatalogPrice\SpecialPrice::PRICE_CODE, $this->quantity, $specialPrice], - ])); - - $this->assertEquals($result, $this->model->getValue()); - $this->assertEquals($result, $this->model->getValue()); - } -} diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BundleSelectionPriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BundleSelectionPriceTest.php index 095891164fe08..eaa8ac14a49d0 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BundleSelectionPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/BundleSelectionPriceTest.php @@ -24,240 +24,240 @@ namespace Magento\Bundle\Pricing\Price; -use Magento\TestFramework\Helper\ObjectManager as ObjectManagerHelper; use Magento\Catalog\Pricing\Price as CatalogPrice; +use Magento\Catalog\Pricing\Price\RegularPrice; /** * Class BundleSelectionPriceTest * - * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class BundleSelectionPriceTest extends \PHPUnit_Framework_TestCase { - /** @var \Magento\Bundle\Pricing\Price\BundleSelectionPrice */ - protected $bundleSelectionPrice; - - /** @var ObjectManagerHelper */ - protected $objectManagerHelper; - - /** @var \Magento\Framework\Pricing\Object\SaleableInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $saleableInterfaceMock; - - /** @var float */ - protected $quantity = 1.; + /** + * @var \Magento\Bundle\Pricing\Price\BundleSelectionPrice + */ + protected $selectionPrice; - /** @var \Magento\Framework\Pricing\Adjustment\CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $calculatorInterfaceMock; + /** + * @var \Magento\Framework\Pricing\Adjustment\CalculatorInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $calculatorMock; - /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject + */ protected $productMock; - /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $managerInterfaceMock; + /** + * @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject + */ + protected $bundleMock; - /** @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $priceInfoMock; + /** + * @var \Magento\Framework\Event\Manager|\PHPUnit_Framework_MockObject_MockObject + */ + protected $eventManagerMock; - /** @var \Magento\Catalog\Pricing\Price\BasePrice|\PHPUnit_Framework_MockObject_MockObject */ - protected $basePriceMock; + /** + * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject + */ + protected $priceInfoMock; - /** @var \Magento\Catalog\Pricing\Price\FinalPrice|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Catalog\Pricing\Price\FinalPrice|\PHPUnit_Framework_MockObject_MockObject + */ protected $finalPriceMock; - /** @var \Magento\Catalog\Pricing\Price\RegularPrice|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Magento\Catalog\Pricing\Price\RegularPrice|\PHPUnit_Framework_MockObject_MockObject + */ protected $regularPriceMock; - /** @var float */ - protected $finalPriceValue; - - /** @var float */ - protected $regularPriceValue; + /** + * @var \Magento\Bundle\Pricing\Price\DiscountCalculator|\PHPUnit_Framework_MockObject_MockObject + */ + protected $discountCalculatorMock; - /** @var float */ - protected $expectedResult; + /** + * @var float + */ + protected $quantity; - protected function prepare() + /** + * Test setUp + */ + protected function setUp() { - $this->saleableInterfaceMock = $this->getMock( + $this->productMock = $this->getMock( 'Magento\Catalog\Model\Product', - [ - 'getPriceInfo', - 'getSelectionPriceType', - 'getSelectionPriceValue', - '__wakeup', - '__sleep' - ], + ['__wakeup', 'getPriceInfo', 'getSelectionPriceType', 'getSelectionPriceValue'], [], '', false ); - $this->calculatorInterfaceMock = $this->getMock('Magento\Framework\Pricing\Adjustment\CalculatorInterface'); - $this->productMock = $this->getMock( + + $this->bundleMock = $this->getMock( 'Magento\Catalog\Model\Product', - ['getPriceType', 'setFinalPrice', 'getQty', 'getData', 'getPriceInfo', '__wakeup', '__sleep'], + ['__wakeup', 'getPriceType', 'getPriceInfo', 'setFinalPrice', 'getData'], + [], + '', + false + ); + $this->calculatorMock = $this->getMock( + 'Magento\Framework\Pricing\Adjustment\CalculatorInterface', + [], [], '', false, + true, false ); - - $this->managerInterfaceMock = $this->getMock('Magento\Framework\Event\ManagerInterface'); - - $this->priceInfoMock = $this->getMock('\Magento\Framework\Pricing\PriceInfoInterface'); - $this->priceInfoMock->expects($this->atLeastOnce()) - ->method('getPrice') - ->will($this->returnCallback(array($this, 'getPriceCallback'))); - - $this->productMock->expects($this->atLeastOnce()) + $this->eventManagerMock = $this->getMock( + 'Magento\Framework\Event\Manager', + ['dispatch'], + [], + '', + false + ); + $this->priceInfoMock = $this->getMock( + 'Magento\Framework\Pricing\PriceInfo\Base', + ['getPrice'], + [], + '', + false + ); + $this->discountCalculatorMock = $this->getMock( + 'Magento\Bundle\Pricing\Price\DiscountCalculator', + [], + [], + '', + false + ); + $this->finalPriceMock = $this->getMock( + 'Magento\Catalog\Pricing\Price\FinalPrice', + [], + [], + '', + false + ); + $this->regularPriceMock = $this->getMock( + 'Magento\Catalog\Pricing\Price\RegularPrice', + [], + [], + '', + false + ); + $this->productMock->expects($this->once()) ->method('getPriceInfo') ->will($this->returnValue($this->priceInfoMock)); - $this->saleableInterfaceMock->expects($this->atLeastOnce()) - ->method('getPriceInfo') - ->will($this->returnValue($this->priceInfoMock)); + $this->quantity = 1; + $this->selectionPrice = new \Magento\Bundle\Pricing\Price\BundleSelectionPrice( + $this->productMock, + $this->quantity, + $this->calculatorMock, + $this->bundleMock, + $this->eventManagerMock, + $this->discountCalculatorMock + ); } /** - * @param string $priceType - * @return \PHPUnit_Framework_MockObject_MockObject + * test fro method getValue with dynamic productType */ - public function getPriceCallback($priceType) + public function testGetValueTypeDynamic() { - switch ($priceType) { - case CatalogPrice\BasePrice::PRICE_CODE: - $this->basePriceMock = $this->getMock('Magento\Bundle\Pricing\Price\BasePrice', [], [], '', false); - $this->basePriceMock->expects($this->once()) - ->method('calculateBaseValue') - ->with($this->expectedResult) - ->will($this->returnArgument(0)); - return $this->basePriceMock; - case CatalogPrice\FinalPrice::PRICE_CODE: - $this->finalPriceMock = $this->getMock( - 'Magento\Catalog\Pricing\Price\FinalPrice', - [], - [], - '', - false - ); - $this->finalPriceMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($this->finalPriceValue)); - return $this->finalPriceMock; - case CatalogPrice\RegularPrice::PRICE_CODE: - $this->regularPriceMock = $this->getMock( - 'Magento\Catalog\Pricing\Price\RegularPrice', - [], - [], - '', - false - ); - $this->regularPriceMock->expects($this->once()) - ->method('getValue') - ->will($this->returnValue($this->regularPriceValue)); - return $this->regularPriceMock; - default: - break; - } - $this->fail('Price mock was not found'); + $this->bundleMock->expects($this->once()) + ->method('getPriceType') + ->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_DYNAMIC)); + $this->priceInfoMock->expects($this->once()) + ->method('getPrice') + ->with($this->equalTo(FinalPrice::PRICE_CODE)) + ->will($this->returnValue($this->finalPriceMock)); + $this->finalPriceMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(100)); + $this->discountCalculatorMock->expects($this->once()) + ->method('calculateDiscount') + ->with( + $this->equalTo($this->bundleMock), + $this->equalTo(100) + ) + ->will($this->returnValue(70)); + $this->assertEquals(70, $this->selectionPrice->getValue()); + $this->assertEquals(70, $this->selectionPrice->getValue()); } /** - * @param string $bundlePriceType - * @param array $selectionData - * @param float $expectedResult - * @dataProvider getValueDataProvider + * test for method getValue with type Fixed and selectionPriceType not null */ - public function testGetValue($bundlePriceType, $selectionData, $expectedResult) + public function testGetValueTypeFixedWithSelectionPriceType() { - $this->prepare(); - $this->expectedResult = $expectedResult; - $this->productMock->expects($this->once()) + $this->bundleMock->expects($this->once()) ->method('getPriceType') - ->will($this->returnValue($bundlePriceType)); - - if (isset($selectionData['getSelectionPriceType'])) { - $this->saleableInterfaceMock->expects($this->once()) - ->method('getSelectionPriceType') - ->will($this->returnValue($selectionData['getSelectionPriceType'])); - if ($selectionData['getSelectionPriceType']) { - $this->regularPriceValue = $selectionData['regularPriceValue']; - $this->productMock->expects($this->once()) - ->method('setFinalPrice') - ->with($this->equalTo($selectionData['regularPriceValue'])) - ->will($this->returnSelf()); - $this->productMock->expects($this->once()) - ->method('getQty') - ->will($this->returnValue($selectionData['bundleQty'])); - - $this->productMock->expects($this->once()) - ->method('getData') - ->with($this->equalTo('final_price')) - ->will($this->returnValue($selectionData['finalPrice'])); - - $this->managerInterfaceMock->expects($this->once()) - ->method('dispatch') - ->with( - $this->equalTo('catalog_product_get_final_price'), - $this->equalTo(['product' => $this->productMock, 'qty' => $selectionData['bundleQty']]) - ) - ->will($this->returnSelf()); - } - $this->quantity = $selectionData['bundleQty']; - $this->saleableInterfaceMock->expects($this->once()) + ->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); + $this->bundleMock->expects($this->atLeastOnce()) + ->method('getPriceInfo') + ->will($this->returnValue($this->priceInfoMock)); + $this->priceInfoMock->expects($this->once()) + ->method('getPrice') + ->with($this->equalTo(RegularPrice::PRICE_CODE)) + ->will($this->returnValue($this->regularPriceMock)); + $this->regularPriceMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(100)); + $this->bundleMock->expects($this->once()) + ->method('setFinalPrice') + ->will($this->returnSelf()); + $this->eventManagerMock->expects($this->once()) + ->method('dispatch'); + $this->bundleMock->expects($this->exactly(2)) + ->method('getData') + ->will($this->returnValueMap( + [ + ['qty', null, 1], + ['final_price', null, 100], + ] + ) + ); + $this->productMock->expects($this->once()) + ->method('getSelectionPriceType') + ->will($this->returnValue(true)); + $this->productMock->expects($this->any()) ->method('getSelectionPriceValue') - ->will($this->returnValue($selectionData['selectionPriceValue'])); - } else { - $this->finalPriceValue = $expectedResult; - } - $this->objectManagerHelper = new ObjectManagerHelper($this); - $this->bundleSelectionPrice = $this->objectManagerHelper->getObject( - 'Magento\Bundle\Pricing\Price\BundleSelectionPrice', - [ - 'saleableItem' => $this->saleableInterfaceMock, - 'quantity' => $this->quantity, - 'calculator' => $this->calculatorInterfaceMock, - 'bundleProduct' => $this->productMock, - 'eventManager' => $this->managerInterfaceMock - ] - ); - - $this->assertSame($expectedResult, $this->bundleSelectionPrice->getValue()); - // test value caching - $this->assertSame($expectedResult, $this->bundleSelectionPrice->getValue()); + ->will($this->returnValue(100)); + $this->discountCalculatorMock->expects($this->once()) + ->method('calculateDiscount') + ->with( + $this->equalTo($this->bundleMock), + $this->equalTo(100) + ) + ->will($this->returnValue(70)); + $this->assertEquals(70, $this->selectionPrice->getValue()); } /** - * @return array + * test for method getValue with type Fixed and selectionPriceType is empty or zero */ - public function getValueDataProvider() + public function testGetValueTypeFixedWithoutSelectionPriceType() { - return [ - 'dynamic bundle' => [ - 'bundle type' => 0, - 'selection data' => [], - 'expected result' => 3.3 - ], - 'fixed bundle - percent price' => [ - 'bundle type' => 1, - 'selection data' => [ - 'getSelectionPriceType' => true, - 'regularPriceValue' => 4., - 'bundleQty' => 3., - 'finalPrice' => 100, - 'selectionPriceValue' => 10. - ], - 'expected result' => 10. - ], - 'fixed bundle - fixed price' => [ - 'bundle type' => 1, - 'selection data' => [ - 'getSelectionPriceType' => false, - 'bundleQty' => 2., - 'selectionPriceValue' => 10. - ], - 'expected result' => 20. - ], - ]; + $this->bundleMock->expects($this->once()) + ->method('getPriceType') + ->will($this->returnValue(\Magento\Bundle\Model\Product\Price::PRICE_TYPE_FIXED)); + $this->productMock->expects($this->once()) + ->method('getSelectionPriceType') + ->will($this->returnValue(false)); + $this->productMock->expects($this->any()) + ->method('getSelectionPriceValue') + ->will($this->returnValue(100)); + $this->discountCalculatorMock->expects($this->once()) + ->method('calculateDiscount') + ->with( + $this->equalTo($this->bundleMock), + $this->equalTo(100) + ) + ->will($this->returnValue(70)); + $this->assertEquals(70, $this->selectionPrice->getValue()); } } diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/DiscountCalculatorTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/DiscountCalculatorTest.php new file mode 100644 index 0000000000000..7f5c91f0cf83f --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/DiscountCalculatorTest.php @@ -0,0 +1,152 @@ +productMock = $this->getMock( + 'Magento\Catalog\Model\Product', + [], + [], + '', + false + ); + $this->priceInfoMock = $this->getMock( + 'Magento\Framework\Pricing\PriceInfo\Base', + ['getPrice', 'getPrices'], + [], + '', + false + ); + $this->finalPriceMock = $this->getMock( + 'Magento\Catalog\Pricing\Price\FinalPrice', + [], + [], + '', + false + ); + $this->priceMock = $this->getMockForAbstractClass('Magento\Bundle\Pricing\Price\DiscountProviderInterface'); + $this->calculator = new \Magento\Bundle\Pricing\Price\DiscountCalculator(); + } + + /** + * Returns price mock with specified % + * + * @param int $value + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function getPriceMock($value) + { + $price = clone $this->priceMock; + $price->expects($this->exactly(3)) + ->method('getDiscountPercent') + ->will($this->returnValue($value)); + return $price; + } + + /** + * test method calculateDiscount with default price amount + */ + public function testCalculateDiscountWithDefaultAmount() + { + $this->productMock->expects($this->exactly(2)) + ->method('getPriceInfo') + ->will($this->returnValue($this->priceInfoMock)); + $this->priceInfoMock->expects($this->once()) + ->method('getPrice') + ->with($this->equalTo(FinalPrice::PRICE_CODE)) + ->will($this->returnValue($this->finalPriceMock)); + $this->finalPriceMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue(100)); + $this->priceInfoMock->expects($this->once()) + ->method('getPrices') + ->will($this->returnValue( + [ + $this->getPriceMock(30), + $this->getPriceMock(20), + $this->getPriceMock(40), + ] + ) + ); + $this->assertEquals(20, $this->calculator->calculateDiscount($this->productMock)); + } + + /** + * test method calculateDiscount with custom price amount + */ + public function testCalculateDiscountWithCustomAmount() + { + $this->productMock->expects($this->once()) + ->method('getPriceInfo') + ->will($this->returnValue($this->priceInfoMock)); + $this->priceInfoMock->expects($this->once()) + ->method('getPrices') + ->will($this->returnValue( + [ + $this->getPriceMock(30), + $this->getPriceMock(20), + $this->getPriceMock(40), + ] + ) + ); + $this->assertEquals(10, $this->calculator->calculateDiscount($this->productMock, 50)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/FinalPriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/FinalPriceTest.php index f1e4daf947cca..6607d80eace01 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/FinalPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/FinalPriceTest.php @@ -46,10 +46,10 @@ class FinalPriceTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface|\PHPUnit_Framework_MockObject_MockObject */ protected $bundleCalculatorMock; - /** @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; - /** @var \Magento\Bundle\Pricing\Price\BasePrice|\PHPUnit_Framework_MockObject_MockObject */ + /** @var \Magento\Catalog\Pricing\Price\BasePrice|\PHPUnit_Framework_MockObject_MockObject */ protected $basePriceMock; /** @var BundleOptionPrice|\PHPUnit_Framework_MockObject_MockObject */ @@ -63,7 +63,7 @@ protected function prepareMock() $this->saleableInterfaceMock = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); $this->bundleCalculatorMock = $this->getMock('Magento\Bundle\Pricing\Adjustment\BundleCalculatorInterface'); - $this->basePriceMock = $this->getMock('Magento\Bundle\Pricing\Price\BasePrice', [], [], '', false); + $this->basePriceMock = $this->getMock('Magento\Catalog\Pricing\Price\BasePrice', [], [], '', false); $this->basePriceMock->expects($this->any()) ->method('getValue') ->will($this->returnValue($this->baseAmount)); @@ -72,13 +72,13 @@ protected function prepareMock() ->disableOriginalConstructor() ->getMock(); - $this->priceInfoMock = $this->getMock('\Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); + $this->priceInfoMock = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->priceInfoMock->expects($this->atLeastOnce()) ->method('getPrice') ->will($this->returnValueMap([ [\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE, $this->basePriceMock], - [BundleOptionPrice::PRICE_CODE, $this->quantity, $this->bundleOptionMock] + [BundleOptionPrice::PRICE_CODE, $this->bundleOptionMock] ])); $this->saleableInterfaceMock->expects($this->once()) @@ -96,19 +96,14 @@ protected function prepareMock() /** * @dataProvider getValueDataProvider */ - public function testGetValue($baseAmount, $discountValue, $result) + public function testGetValue($baseAmount, $optionsValue, $result) { $this->baseAmount = $baseAmount; - $optionsValue = rand(1, 10); $this->prepareMock(); $this->bundleOptionMock->expects($this->once()) ->method('getValue') ->will($this->returnValue($optionsValue)); - $this->basePriceMock->expects($this->once())->method('calculateBaseValue') - ->with($this->equalTo($optionsValue)) - ->will($this->returnValue($discountValue)); - $this->assertSame($result, $this->finalPrice->getValue()); } diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/GroupPriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/GroupPriceTest.php index 060baae3ed733..0ec45ccb35d24 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/GroupPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/GroupPriceTest.php @@ -36,7 +36,7 @@ class GroupPriceTest extends \PHPUnit_Framework_TestCase protected $saleable; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfo; @@ -47,25 +47,29 @@ public function setUp() ->disableOriginalConstructor() ->getMock(); - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->saleable->expects($this->once()) ->method('getPriceInfo') ->will($this->returnValue($this->priceInfo)); $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->model = $objectHelper->getObject('Magento\Bundle\Pricing\Price\GroupPrice', [ - 'saleableItem' => $this->saleable - ]); + $this->model = $objectHelper->getObject( + 'Magento\Bundle\Pricing\Price\GroupPrice', + [ + 'saleableItem' => $this->saleable + ] + ); } /** - * @param float $basePrice - * @param [] $storedGroupPrice - * @param float $value + * @param $regularPrice + * @param $storedGroupPrice + * @param $value + * @param $percent * @dataProvider getValueDataProvider */ - public function testGetValue($basePrice, $storedGroupPrice, $value) + public function testGetValue($regularPrice, $storedGroupPrice, $value, $percent) { $customerGroupId = 234; @@ -82,14 +86,14 @@ public function testGetValue($basePrice, $storedGroupPrice, $value) $price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); $this->priceInfo->expects($this->once()) ->method('getPrice') - ->with(\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE) + ->with(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE) ->will($this->returnValue($price)); $price->expects($this->once()) ->method('getValue') - ->will($this->returnValue($basePrice)); + ->will($this->returnValue($regularPrice)); } - $this->assertEquals($value, $this->model->getValue()); + $this->assertEquals($percent, $this->model->getDiscountPercent()); } /** @@ -98,9 +102,12 @@ public function testGetValue($basePrice, $storedGroupPrice, $value) public function getValueDataProvider() { return array( - ['basePrice' => 100, 'storedGroupPrice' => [['cust_group' => 234, 'website_price' => 40]], 'value' => 60], - ['basePrice' => 75, 'storedGroupPrice' => [['cust_group' => 234, 'website_price' => 40]], 'value' => 45], - ['basePrice' => 75, 'storedGroupPrice' => [], 'value' => false], + ['regularPrice' => 100, 'storedGroupPrice' + => [['cust_group' => 234, 'website_price' => 40]], 'value' => 60, 'percent' => 60], + ['regularPrice' => 75, 'storedGroupPrice' + => [['cust_group' => 234, 'website_price' => 40]], 'value' => 45, 'percent' => 60], + ['regularPrice' => 75, 'storedGroupPrice' + => [], 'value' => false, 'percent' => null], ); } } diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/SpecialPriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/SpecialPriceTest.php index dea2c4834422c..431296fa1d68c 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/SpecialPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/SpecialPriceTest.php @@ -36,7 +36,7 @@ class SpecialPriceTest extends \PHPUnit_Framework_TestCase protected $saleable; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfo; @@ -52,7 +52,7 @@ public function setUp() ->getMock(); $this->localeDate = $this->getMock('Magento\Framework\Stdlib\DateTime\TimezoneInterface'); - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->saleable->expects($this->once()) ->method('getPriceInfo') @@ -66,16 +66,17 @@ public function setUp() } /** - * @param float $basePrice - * @param float $specialPrice - * @param bool $isScopeDateInInterval - * @param float $value + * @param $regularPrice + * @param $specialPrice + * @param $isScopeDateInInterval + * @param $value + * @param $percent * @dataProvider getValueDataProvider */ - public function testGetValue($basePrice, $specialPrice, $isScopeDateInInterval, $value) + public function testGetValue($regularPrice, $specialPrice, $isScopeDateInInterval, $value, $percent) { $specialFromDate = 'some date from'; - $specialToDate = 'som date to'; + $specialToDate = 'some date to'; $this->saleable->expects($this->once()) ->method('getSpecialPrice') @@ -103,15 +104,18 @@ public function testGetValue($basePrice, $specialPrice, $isScopeDateInInterval, $price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); $this->priceInfo->expects($this->once()) ->method('getPrice') - ->with(\Magento\Catalog\Pricing\Price\BasePrice::PRICE_CODE) + ->with(\Magento\Catalog\Pricing\Price\RegularPrice::PRICE_CODE) ->will($this->returnValue($price)); $price->expects($this->once()) ->method('getValue') - ->will($this->returnValue($basePrice)); + ->will($this->returnValue($regularPrice)); } $this->assertEquals($value, $this->model->getValue()); + + //check that the second call will get data from cache the same as in first call $this->assertEquals($value, $this->model->getValue()); + $this->assertEquals($percent, $this->model->getDiscountPercent()); } /** @@ -120,9 +124,12 @@ public function testGetValue($basePrice, $specialPrice, $isScopeDateInInterval, public function getValueDataProvider() { return array( - ['basePrice' => 100, 'specialPrice' => 40, 'isScopeDateInInterval' => true, 'value' => 60], - ['basePrice' => 75, 'specialPrice' => 40, 'isScopeDateInInterval' => true, 'value' => 45], - ['basePrice' => 75, 'specialPrice' => 40, 'isScopeDateInInterval' => false, 'value' => false], + ['regularPrice' => 100, 'specialPrice' => 40, 'isScopeDateInInterval' => true, 'value' => 40, + 'percent' => 40], + ['regularPrice' => 75, 'specialPrice' => 40, 'isScopeDateInInterval' => true, 'value' => 30, + 'percent' => 40], + ['regularPrice' => 75, 'specialPrice' => 40, 'isScopeDateInInterval' => false, 'value' => false, + 'percent' => null], ); } } diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/TierPriceTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/TierPriceTest.php index 516dcc4679aa3..9d2aa9f67990d 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/TierPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Price/TierPriceTest.php @@ -54,7 +54,7 @@ class TierPriceTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->product = $this->getMockBuilder('Magento\Catalog\Model\Product') ->setMethods(['getPriceInfo', 'hasCustomerGroupId', 'getCustomerGroupId', 'getResource', '__wakeup']) diff --git a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Render/FinalPriceBoxTest.php b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Render/FinalPriceBoxTest.php index 1dc0eeea7b3d8..46ce50d346e96 100644 --- a/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Render/FinalPriceBoxTest.php +++ b/dev/tests/unit/testsuite/Magento/Bundle/Pricing/Render/FinalPriceBoxTest.php @@ -52,7 +52,7 @@ public function setUp() */ public function testShowRangePrice($value, $maxValue, $result) { - $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $optionPrice = $this->getMockBuilder('Magento\Bundle\Pricing\Price\BundleOptionPrice') ->disableOriginalConstructor() ->getMock(); diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/CategoryTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/CategoryTest.php index 110292007c8c6..650bf9efc75c0 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/CategoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/CategoryTest.php @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Catalog - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Options/AjaxTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Options/AjaxTest.php new file mode 100644 index 0000000000000..cf0d854600d46 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Block/Adminhtml/Product/Options/AjaxTest.php @@ -0,0 +1,138 @@ +context = $this->getMockBuilder('Magento\Backend\Block\Context') + ->setMethods(['getEventManager', 'getScopeConfig', 'getLayout', 'getRequest']) + ->disableOriginalConstructor() + ->getMock(); + $this->encoderInterface= $this->getMock('Magento\Framework\Json\EncoderInterface'); + $this->productFactory= $this->getMock('Magento\Catalog\Model\ProductFactory', ['create']); + $this->coreHelper= $this->getMock('Magento\Core\Helper\Data', [], [], '', false); + $this->registry= $this->getMock('Magento\Framework\Registry'); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + } + + /** + * Test protected `_toHtml` method via public `toHtml` method. + */ + public function testToHtml() + { + $eventManager= $this->getMockBuilder('Magento\Framework\Event\Manager') + ->disableOriginalConstructor() + ->setMethods(['dispatch']) + ->getMock(); + $eventManager->expects($this->once())->method('dispatch')->will($this->returnValue(true)); + + $scopeConfig= $this->getMockBuilder('\Magento\Framework\App\Config') + ->setMethods(['getValue']) + ->disableOriginalConstructor()->getMock(); + $scopeConfig->expects($this->once())->method('getValue')->withAnyParameters() + ->will($this->returnValue(false)); + + $product= $this->getMockBuilder('Magento\Catalog\Model\Product')->disableOriginalConstructor() + ->setMethods(['setStoreId', 'load', 'getId', '__wakeup', '__sleep']) + ->getMock(); + $product->expects($this->once())->method('setStoreId')->will($this->returnSelf()); + $product->expects($this->once())->method('load')->will($this->returnSelf()); + $product->expects($this->once())->method('getId')->will($this->returnValue(1)); + + $optionsBlock = $this->getMockBuilder('Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option') + ->setMethods(['setIgnoreCaching', 'setProduct', 'getOptionValues']) + ->disableOriginalConstructor() + ->getMock(); + $optionsBlock->expects($this->once())->method('setIgnoreCaching')->with(true)->will($this->returnSelf()); + $optionsBlock->expects($this->once())->method('setProduct')->with($product)->will($this->returnSelf()); + $optionsBlock->expects($this->once())->method('getOptionValues')->will($this->returnValue([])); + + $layout= $this->getMockBuilder('Magento\Framework\View\Layout\Element\Layout') + ->disableOriginalConstructor() + ->setMethods(['createBlock']) + ->getMock(); + $layout->expects($this->once())->method('createBlock') + ->with('Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option') + ->will($this->returnValue($optionsBlock)); + + $request= $this->getMockBuilder('Magento\Framework\App\Request\Http') + ->setMethods(['getParam']) + ->disableOriginalConstructor() + ->getMock(); + $request->expects($this->once())->method('getParam')->with('store') + ->will($this->returnValue(0)); + + $this->context->expects($this->once())->method('getEventManager') + ->will($this->returnValue($eventManager)); + $this->context->expects($this->once())->method('getScopeConfig') + ->will($this->returnValue($scopeConfig)); + $this->context->expects($this->once())->method('getLayout') + ->will($this->returnValue($layout)); + $this->context->expects($this->once())->method('getRequest') + ->will($this->returnValue($request)); + $this->registry->expects($this->once())->method('registry') + ->with('import_option_products') + ->will($this->returnValue([1])); + $this->productFactory->expects($this->once())->method('create')->will($this->returnValue($product)); + + $this->block = $this->objectManagerHelper->getObject( + 'Magento\Catalog\Block\Adminhtml\Product\Options\Ajax', + [ + 'context' => $this->context, + 'jsonEncoder' => $this->encoderInterface, + 'productFactory' => $this->productFactory, + 'coreData' => $this->coreHelper, + 'registry' => $this->registry + ] + ); + $this->block->toHtml(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Initialization/HelperTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Initialization/HelperTest.php index 8a18f4f0bbd6e..2faacb4ec0408 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -70,6 +70,11 @@ class HelperTest extends \PHPUnit_Framework_TestCase */ protected $helper; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $jsHelperMock; + protected function setUp() { $this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', array(), array(), '', false); @@ -86,7 +91,7 @@ protected function setUp() false ); $this->productLinksMock = $this->getMock( - 'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks', + 'Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks', array(), array(), '', @@ -128,11 +133,13 @@ protected function setUp() $this->returnValue($this->storeMock) ); + $this->jsHelperMock = $this->getMock('\Magento\Backend\Helper\Js', [], [], '', false); $this->helper = new Helper( $this->requestMock, $this->storeManagerMock, $this->stockFilterMock, - $this->productLinksMock + $this->productLinksMock, + $this->jsHelperMock ); } @@ -170,7 +177,7 @@ public function testInitialize() ); $this->requestMock->expects( - $this->at(2) + $this->at(3) )->method( 'getPost' )->with( diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php index 585f538638273..85d3f8bc32a72 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Controller/Adminhtml/ProductTest.php @@ -30,12 +30,52 @@ class ProductTest extends \PHPUnit_Framework_TestCase */ protected $_controller; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $context; + /** * @var \Magento\Catalog\Model\Indexer\Product\Price\Processor */ protected $_priceProcessor; public function setUp() + { + $this->initContext(); + $this->_priceProcessor = $this->getMockBuilder('Magento\Catalog\Model\Indexer\Product\Price\Processor') + ->disableOriginalConstructor()->getMock(); + + $productBuilder = $this->getMockBuilder('Magento\Catalog\Controller\Adminhtml\Product\Builder')->setMethods([ + 'build' + ])->disableOriginalConstructor()->getMock(); + + $product = $this->getMockBuilder('\Magento\Catalog\Model\Product')->disableOriginalConstructor() + ->setMethods(['getTypeId', 'getStoreId', '__sleep', '__wakeup'])->getMock(); + $product->expects($this->any())->method('getTypeId')->will($this->returnValue('simple')); + $product->expects($this->any())->method('getStoreId')->will($this->returnValue('1')); + $productBuilder->expects($this->any())->method('build')->will($this->returnValue($product)); + + $this->_controller = new \Magento\Catalog\Controller\Adminhtml\Product( + $this->context, + $this->getMock('Magento\Framework\Registry', array(), array(), '', false), + $this->getMock('Magento\Framework\Stdlib\DateTime\Filter\Date', array(), array(), '', false), + $this->getMockBuilder('Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper') + ->disableOriginalConstructor()->getMock(), + $this->getMockBuilder('Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter') + ->disableOriginalConstructor()->getMock(), + $this->getMock('Magento\Catalog\Model\Product\Copier', array(), array(), '', false), + $productBuilder, + $this->getMock('Magento\Catalog\Model\Product\Validator', array(), array(), '', false), + $this->getMock('Magento\Catalog\Model\Product\TypeTransitionManager', array(), array(), '', false), + $this->_priceProcessor + ); + } + + /** + * Init context object + */ + protected function initContext() { $productActionMock = $this->getMock('Magento\Catalog\Model\Product\Action', array(), array(), '', false); $objectManagerMock = $this->getMockForAbstractClass( @@ -48,76 +88,74 @@ public function setUp() array('get') ); $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($productActionMock)); - $this->_priceProcessor = $this->getMock( - 'Magento\Catalog\Model\Indexer\Product\Price\Processor', - array(), - array(), - '', - false - ); - $requestInterfaceMock = $this->getMock('Magento\Framework\App\RequestInterface', array(), array(), '', false); - $responseInterfaceMock = $this->getMock( - 'Magento\Framework\App\ResponseInterface', + + $block = $this->getMockBuilder('\Magento\Framework\View\Element\AbstractBlock') + ->disableOriginalConstructor()->getMockForAbstractClass(); + $layout = $this->getMockBuilder('Magento\Framework\View\Layout\Element\Layout') + ->setMethods(['getBlock'])->disableOriginalConstructor() + ->getMock(); + $layout->expects($this->any())->method('getBlock')->will($this->returnValue($block)); + $view = $this->getMockBuilder('Magento\Framework\App\View') + ->setMethods(['loadLayout', 'getLayout', 'renderLayout']) + ->disableOriginalConstructor()->getMock(); + $view->expects($this->any())->method('renderLayout')->will($this->returnSelf()); + $view->expects($this->any())->method('getLayout')->will($this->returnValue($layout)); + $view->expects($this->any())->method('loadLayout')->with(array( + 'popup', + 'catalog_product_new', + 'catalog_product_simple' + ))->will($this->returnSelf()); + + $eventManager = $this->getMockBuilder('Magento\Framework\Event\Manager') + ->setMethods(['dispatch'])->disableOriginalConstructor()->getMock(); + $eventManager->expects($this->any())->method('dispatch')->will($this->returnSelf()); + $title = $this->getMockBuilder('\Magento\Framework\App\Action\Title') + ->setMethods(['add'])->disableOriginalConstructor()->getMock(); + $title->expects($this->any())->method('add')->withAnyParameters()->will($this->returnSelf()); + $requestInterfaceMock = $this->getMockBuilder('Magento\Framework\App\Request\Http')->setMethods( + array('getParam', 'getFullActionName') + )->disableOriginalConstructor()->getMock(); + + $responseInterfaceMock = $this->getMockBuilder('Magento\Framework\App\ResponseInterface')->setMethods( array('setRedirect', 'sendResponse') - ); - $managerInterfaceMock = $this->getMock( - 'Magento\Framework\Message\ManagerInterface', - array(), - array(), - '', - false - ); + )->getMock(); + + $managerInterfaceMock = $this->getMock('Magento\Framework\Message\ManagerInterface'); $sessionMock = $this->getMock('Magento\Backend\Model\Session', array(), array(), '', false); $actionFlagMock = $this->getMock('Magento\Framework\App\ActionFlag', array(), array(), '', false); $helperDataMock = $this->getMock('Magento\Backend\Helper\Data', array(), array(), '', false); - $contextMock = $this->getMock( + $this->context = $this->getMock( 'Magento\Backend\App\Action\Context', array( 'getRequest', 'getResponse', 'getObjectManager', + 'getEventManager', 'getMessageManager', 'getSession', 'getActionFlag', - 'getHelper' + 'getHelper', + 'getTitle', + 'getView' ), array(), '', false ); - $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock)); - $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock)); - $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock)); - $contextMock->expects($this->any()) + + $this->context->expects($this->any())->method('getTitle')->will($this->returnValue($title)); + $this->context->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager)); + $this->context->expects($this->any())->method('getView')->will($this->returnValue($view)); + $this->context->expects($this->any())->method('getRequest')->will($this->returnValue($requestInterfaceMock)); + $this->context->expects($this->any())->method('getResponse')->will($this->returnValue($responseInterfaceMock)); + $this->context->expects($this->any())->method('getObjectManager')->will($this->returnValue($objectManagerMock)); + + $this->context->expects($this->any()) ->method('getMessageManager') ->will($this->returnValue($managerInterfaceMock)); - $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($sessionMock)); - $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); - $contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock)); - $this->_controller = new \Magento\Catalog\Controller\Adminhtml\Product( - $contextMock, - $this->getMock('Magento\Framework\Registry', array(), array(), '', false), - $this->getMock('Magento\Framework\Stdlib\DateTime\Filter\Date', array(), array(), '', false), - $this->getMock( - 'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper', - array(), - array(), - '', - false - ), - $this->getMock( - 'Magento\Catalog\Controller\Adminhtml\Product\Initialization\StockDataFilter', - array(), - array(), - '', - false - ), - $this->getMock('Magento\Catalog\Model\Product\Copier', array(), array(), '', false), - $this->getMock('Magento\Catalog\Controller\Adminhtml\Product\Builder', array(), array(), '', false), - $this->getMock('Magento\Catalog\Model\Product\Validator', array(), array(), '', false), - $this->getMock('Magento\Catalog\Model\Product\TypeTransitionManager', array(), array(), '', false), - $this->_priceProcessor - ); + $this->context->expects($this->any())->method('getSession')->will($this->returnValue($sessionMock)); + $this->context->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock)); + $this->context->expects($this->any())->method('getHelper')->will($this->returnValue($helperDataMock)); } public function testMassStatusAction() @@ -126,4 +164,18 @@ public function testMassStatusAction() $this->_controller->massStatusAction(); } + + /** + * Testing `newAction` method + */ + public function testNewAction() + { + $this->_controller->getRequest()->expects($this->at(0))->method('getParam') + ->with('set')->will($this->returnValue(true)); + $this->_controller->getRequest()->expects($this->at(1))->method('getParam') + ->with('popup')->will($this->returnValue(true)); + $this->_controller->getRequest()->expects($this->any())->method('getFullActionName') + ->will($this->returnValue('catalog_product_new')); + $this->_controller->newAction(); + } } diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/MediaTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/MediaTest.php index 50156d529fd18..821ab44fee3ac 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/MediaTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Backend/MediaTest.php @@ -28,48 +28,93 @@ class MediaTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Catalog\Model\Product\Attribute\Backend\Media */ - protected $_model; + protected $model; /** * @var \Magento\TestFramework\Helper\ObjectManager */ protected $_objectHelper; + /** + * @var \Magento\Framework\Object | \PHPUnit_Framework_MockObject_MockObject + */ + protected $dataObject; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $productFactory; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $resourceModel; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $mediaConfig; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $mediaDirectory; + protected function setUp() { $this->_objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', array(), array(), '', false); + $eventManager = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); - $fileStorageDb = $this->getMock('Magento\Core\Helper\File\Storage\Database', array(), array(), '', false); - $coreData = $this->getMock('Magento\Core\Helper\Data', array(), array(), '', false); - $resource = $this->getMock( + $fileStorageDb = $this->getMock('Magento\Core\Helper\File\Storage\Database', [], [], '', false); + $coreData = $this->getMock('Magento\Core\Helper\Data', [], [], '', false); + $this->resourceModel = $this->getMock( 'Magento\Catalog\Model\Resource\Product\Attribute\Backend\Media', - array('getMainTable', '__wakeup'), - array(), + [ + 'getMainTable', + '__wakeup', + 'insertGallery', + 'deleteGalleryValueInStore', + 'insertGalleryValueInStore', + 'deleteGallery' + ], + [], '', false ); - $resource->expects($this->any())->method('getMainTable')->will($this->returnValue('table')); + $this->resourceModel->expects($this->any())->method('getMainTable')->will($this->returnValue('table')); - $mediaConfig = $this->getMock('Magento\Catalog\Model\Product\Media\Config', array(), array(), '', false); - $directory = $this->getMockBuilder( - 'Magento\Framework\Filesystem\Directory\Write' - )->disableOriginalConstructor()->getMock(); + $this->mediaConfig = $this->getMock('Magento\Catalog\Model\Product\Media\Config', [], [], '', false); + $this->mediaDirectory = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Write') + ->disableOriginalConstructor() + ->getMock(); $filesystem = $this->getMockBuilder('Magento\Framework\App\Filesystem') ->disableOriginalConstructor() ->getMock(); - $filesystem->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directory)); - $this->_model = $this->_objectHelper->getObject( + $filesystem->expects($this->once())->method('getDirectoryWrite')->will( + $this->returnValue($this->mediaDirectory) + ); + + $this->productFactory = $this->getMockBuilder('Magento\Catalog\Model\Resource\ProductFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + + $this->model = $this->_objectHelper->getObject( 'Magento\Catalog\Model\Product\Attribute\Backend\Media', - array( + [ + 'productFactory' => $this->productFactory, 'eventManager' => $eventManager, 'fileStorageDb' => $fileStorageDb, 'coreData' => $coreData, - 'mediaConfig' => $mediaConfig, + 'mediaConfig' => $this->mediaConfig, 'filesystem' => $filesystem, - 'resourceProductAttribute' => $resource - ) + 'resourceProductAttribute' => $this->resourceModel + ] ); + $this->dataObject = $this->getMockBuilder('Magento\Framework\Object') + ->disableOriginalConstructor() + ->setMethods(['getIsDuplicate', 'isLockedAttribute']) + ->getMock(); } public function testGetAffectedFields() @@ -79,33 +124,139 @@ public function testGetAffectedFields() $attribute = $this->getMock( 'Magento\Eav\Model\Entity\Attribute\AbstractAttribute', - array('getBackendTable', 'isStatic', 'getAttributeId', 'getName', '__wakeup'), - array(), + ['getBackendTable', 'isStatic', 'getAttributeId', 'getName', '__wakeup'], + [], '', false ); $attribute->expects($this->any())->method('getName')->will($this->returnValue('image')); - $attribute->expects($this->any())->method('getAttributeId')->will($this->returnValue($attributeId)); - $attribute->expects($this->any())->method('isStatic')->will($this->returnValue(false)); - $attribute->expects($this->any())->method('getBackendTable')->will($this->returnValue('table')); - - $this->_model->setAttribute($attribute); + $this->model->setAttribute($attribute); $object = new \Magento\Framework\Object(); - $object->setImage(array('images' => array(array('value_id' => $valueId)))); + $object->setImage(['images' => [['value_id' => $valueId]]]); $object->setId(555); $this->assertEquals( - array( - 'table' => array( - array('value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()) - ) - ), - $this->_model->getAffectedFields($object) + [ + 'table' => [ + ['value_id' => $valueId, 'attribute_id' => $attributeId, 'entity_id' => $object->getId()] + ] + ], + $this->model->getAffectedFields($object) ); } + + public function testAfterSaveDuplicate() + { + $attributeCode = 'test_code'; + $attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute') + ->disableOriginalConstructor() + ->getMock(); + $attributeMock->expects($this->once()) + ->method('getAttributeCode') + ->will($this->returnValue($attributeCode)); + + $this->dataObject->expects($this->once()) + ->method('getIsDuplicate') + ->will($this->returnValue(true)); + $this->dataObject->setData($attributeCode, []); + + $this->model->setAttribute($attributeMock); + $this->assertNull($this->model->afterSave($this->dataObject)); + } + + public function testAfterSaveNoAttribute() + { + $attributeCode = 'test_code'; + $attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute') + ->disableOriginalConstructor() + ->getMock(); + $attributeMock->expects($this->once()) + ->method('getAttributeCode') + ->will($this->returnValue($attributeCode)); + + $this->dataObject->expects($this->once()) + ->method('getIsDuplicate') + ->will($this->returnValue(false)); + $this->dataObject->setData($attributeCode, []); + + $this->model->setAttribute($attributeMock); + $this->assertNull($this->model->afterSave($this->dataObject)); + } + + public function testAfterSaveDeleteFiles() + { + $storeId = 1; + $storeIds = ['store_1' => 1, 'store_2' => 2]; + $attributeCode = 'test_code'; + $toDelete = [1]; + $mediaPath = 'catalog/media'; + $filePathToRemove = $mediaPath . '/file/path'; + $attributeValue = [ + 'images' => [ + [ + 'removed' => true, + 'value_id' => 1, + 'file' => 'file/path' + ], + [ + 'removed' => false, + 'value_id' => 1, + 'file' => 'file/path2' + ] + ] + ]; + $assignedImages = [ + ['filepath' => 'path_to_image'] + ]; + + $attributeMock = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute') + ->disableOriginalConstructor() + ->getMock(); + $attributeMock->expects($this->once()) + ->method('getAttributeCode') + ->will($this->returnValue($attributeCode)); + + $this->dataObject->expects($this->once()) + ->method('getIsDuplicate') + ->will($this->returnValue(false)); + $this->dataObject->expects($this->once()) + ->method('isLockedAttribute') + ->will($this->returnValue(false)); + $this->dataObject->setData($attributeCode, $attributeValue); + $this->dataObject->setId(1); + $this->dataObject->setStoreId($storeId); + $this->dataObject->setStoreIds($storeIds); + + $productMock = $this->getMockBuilder('Magento\Catalog\Model\Product') + ->disableOriginalConstructor() + ->setMethods(['getAssignedImages', '__wakeup']) + ->getMock(); + $productMock->expects($this->any()) + ->method('getAssignedImages') + ->will($this->returnValue($assignedImages)); + + $this->productFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($productMock)); + + $this->resourceModel->expects($this->once()) + ->method('deleteGallery') + ->with($toDelete); + + $this->mediaConfig->expects($this->once()) + ->method('getBaseMediaPath') + ->will($this->returnValue($mediaPath)); + + $this->mediaDirectory->expects($this->once()) + ->method('delete') + ->with($filePathToRemove); + + $this->model->setAttribute($attributeMock); + $this->assertNull($this->model->afterSave($this->dataObject)); + } } diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Source/CountryofmanufactureTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Source/CountryofmanufactureTest.php new file mode 100644 index 0000000000000..40bba460bfc91 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Model/Product/Attribute/Source/CountryofmanufactureTest.php @@ -0,0 +1,95 @@ +storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface'); + $this->storeMock = $this->getMock('\Magento\Store\Model\Store', array(), array(), '', false); + $this->cacheConfig = $this->getMock('\Magento\Framework\App\Cache\Type\Config', array(), array(), '', false); + $this->objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + } + + /** + * Test for getAllOptions method + * + * @param $cachedDataSrl + * @param $cachedDataUnsrl + * + * @dataProvider testGetAllOptionsDataProvider + */ + public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl) + { + $this->storeMock->expects($this->once())->method('getCode')->will($this->returnValue('store_code')); + $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock)); + $this->cacheConfig->expects($this->once()) + ->method('load') + ->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code')) + ->will($this->returnValue($cachedDataSrl)); + + $countryOfManufacture = $this->objectManagerHelper->getObject( + 'Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture', + [ + 'storeManager' => $this->storeManagerMock, + 'configCacheType' => $this->cacheConfig, + ] + ); + $this->assertEquals($cachedDataUnsrl, $countryOfManufacture->getAllOptions()); + } + + /** + * Data provider for testGetAllOptions + * + * @return array + */ + public function testGetAllOptionsDataProvider() + { + return + [ + ['cachedDataSrl' => 'a:1:{s:3:"key";s:4:"data";}', 'cachedDataUnsrl' => ['key' => 'data']] + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php index b67afb1fb3b70..c66ff5fe315c2 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Model/ProductTest.php @@ -53,7 +53,12 @@ class ProductTest extends \PHPUnit_Framework_TestCase /** * @var Product\Type|\PHPUnit_Framework_MockObject_MockObject */ - protected $productTypeMock; + protected $productTypeInstanceMock; + + /** + * @var Product\Option|\PHPUnit_Framework_MockObject_MockObject + */ + protected $optionInstanceMock; /** * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject @@ -62,13 +67,7 @@ class ProductTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->categoryIndexerMock = $this->getMockForAbstractClass( - '\Magento\Indexer\Model\IndexerInterface', - array(), - '', - false, - false - ); + $this->categoryIndexerMock = $this->getMockForAbstractClass('\Magento\Indexer\Model\IndexerInterface'); $this->productFlatProcessor = $this->getMock( 'Magento\Catalog\Model\Indexer\Product\Flat\Processor', @@ -79,7 +78,7 @@ public function setUp() ); $this->_priceInfoMock = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); - $this->productTypeMock = $this->getMock('Magento\Catalog\Model\Product\Type', [], [], '', false); + $this->productTypeInstanceMock = $this->getMock('Magento\Catalog\Model\Product\Type', [], [], '', false); $this->productPriceProcessor = $this->getMock( 'Magento\Catalog\Model\Indexer\Product\Price\Processor', array(), @@ -93,16 +92,16 @@ public function setUp() ->method('getAreaCode') ->will($this->returnValue(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE)); - $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', array(), array(), '', false); + $eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface'); $actionValidatorMock = $this->getMock( - '\Magento\Framework\Model\ActionValidator\RemoveAction', - [], - [], - '', + '\Magento\Framework\Model\ActionValidator\RemoveAction', + [], + [], + '', false ); $actionValidatorMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true)); - $cacheInterfaceMock = $this->getMock('Magento\Framework\App\CacheInterface', array(), array(), '', false); + $cacheInterfaceMock = $this->getMock('Magento\Framework\App\CacheInterface'); $contextMock = $this->getMock( '\Magento\Framework\Model\Context', @@ -117,15 +116,20 @@ public function setUp() ->method('getActionValidator') ->will($this->returnValue($actionValidatorMock)); + $this->optionInstanceMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Option') + ->setMethods(['setProduct', 'saveOptions', '__wakeup', '__sleep']) + ->disableOriginalConstructor()->getMock(); + $this->objectManagerHelper = new ObjectManagerHelper($this); $this->model = $this->objectManagerHelper->getObject( 'Magento\Catalog\Model\Product', [ 'context' => $contextMock, - 'catalogProductType' => $this->productTypeMock, + 'catalogProductType' => $this->productTypeInstanceMock, 'categoryIndexer' => $this->categoryIndexerMock, 'productFlatIndexerProcessor' => $this->productFlatProcessor, 'productPriceIndexerProcessor' => $this->productPriceProcessor, + 'catalogProductOption' => $this->optionInstanceMock, 'data' => array('id' => 1) ] ); @@ -202,7 +206,7 @@ public function getIdentitiesProvider() */ public function testGetPriceInfo() { - $this->productTypeMock->expects($this->once()) + $this->productTypeInstanceMock->expects($this->once()) ->method('getPriceInfo') ->with($this->equalTo($this->model)) ->will($this->returnValue($this->_priceInfoMock)); @@ -214,7 +218,7 @@ public function testGetPriceInfo() */ public function testSetQty() { - $this->productTypeMock->expects($this->once()) + $this->productTypeInstanceMock->expects($this->once()) ->method('getPriceInfo') ->with($this->equalTo($this->model)) ->will($this->returnValue($this->_priceInfoMock)); @@ -227,7 +231,7 @@ public function testSetQty() */ public function testReloadPriceInfo() { - $this->productTypeMock->expects($this->exactly(2)) + $this->productTypeInstanceMock->expects($this->exactly(2)) ->method('getPriceInfo') ->with($this->equalTo($this->model)) ->will($this->returnValue($this->_priceInfoMock)); @@ -243,4 +247,44 @@ public function testGetQty() $this->model->setQty(1); $this->assertEquals(1, $this->model->getQty()); } + + /** + * Test for `save` method + */ + public function testSave() + { + $this->model->setIsDuplicate(false); + $this->configureSaveTest(); + $this->optionInstanceMock->expects($this->any())->method('setProduct')->will($this->returnSelf()); + $this->optionInstanceMock->expects($this->once())->method('saveOptions')->will($this->returnSelf()); + $this->model->save(); + } + + /** + * Test for `save` method for duplicated product + */ + public function testSaveAndDuplicate() + { + $this->model->setIsDuplicate(true); + $this->configureSaveTest(); + $this->model->save(); + } + + /** + * Configure environment for `testSave` and `testSaveAndDuplicate` methods + * @return array + */ + protected function configureSaveTest() + { + $productTypeMock = $this->getMockBuilder('Magento\Catalog\Model\Product\Type\Simple') + ->disableOriginalConstructor()->setMethods(['beforeSave', 'save'])->getMock(); + $productTypeMock->expects($this->once())->method('beforeSave')->will($this->returnSelf()); + $productTypeMock->expects($this->once())->method('save')->will($this->returnSelf()); + + $this->productTypeInstanceMock->expects($this->once())->method('factory')->with($this->model) + ->will($this->returnValue($productTypeMock)); + + $this->model->getResource()->expects($this->any())->method('addCommitCallback')->will($this->returnSelf()); + $this->model->getResource()->expects($this->any())->method('commit')->will($this->returnSelf()); + } } diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php new file mode 100644 index 0000000000000..bc4c977b81dc9 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Model/Resource/Product/Indexer/Eav/SourceTest.php @@ -0,0 +1,132 @@ +resource = $this->getMock( + 'Magento\Framework\App\Resource', + ['getConnection', 'getTableName'], + [], + '', + false + ); + $this->config = $this->getMock('Magento\Eav\Model\Config', [], [], '', false); + $this->managerInterface = $this->getMock('Magento\Framework\Event\ManagerInterface'); + $this->helper = $this->getMock('Magento\Catalog\Model\Resource\Helper', [], [], '', false); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->source = $this->objectManagerHelper->getObject( + 'Magento\Catalog\Model\Resource\Product\Indexer\Eav\Source', + [ + 'resource' => $this->resource, + 'eavConfig' => $this->config, + 'eventManager' => $this->managerInterface, + 'resourceHelper' => $this->helper + ] + ); + } + + /** + * Test `reindexEntity` method + */ + public function testReindexEntities() + { + $query = $this->getMockBuilder('PDO_Statement')->setMethods(['fetch'])->disableOriginalConstructor()->getMock(); + $query->expects($this->any())->method('fetch')->will($this->returnValue([])); + + $select = $this->getMockBuilder('\Magento\Framework\DB\Select')->setMethods([ + 'select', 'from', 'where', 'join', 'joinLeft', 'joinInner', + 'assemble', 'columns', 'insertFromSelect', 'query', 'deleteFromSelect' + ])->disableOriginalConstructor()->getMock(); + $select->expects($this->any())->method('from')->withAnyParameters()->will($this->returnSelf()); + $select->expects($this->any())->method('where')->will($this->returnSelf()); + $select->expects($this->any())->method('join')->will($this->returnSelf()); + $select->expects($this->any())->method('query')->will($this->returnValue($query)); + $select->expects($this->any())->method('columns')->will($this->returnSelf()); + $select->expects($this->any())->method('joinLeft')->will($this->returnSelf()); + $select->expects($this->any())->method('insertFromSelect')->will($this->returnSelf()); + $select->expects($this->any())->method('deleteFromSelect')->with('catalog_product_index_eav_tmp') + ->will($this->returnValue($query)); + $select->expects($this->once())->method('joinInner') + ->with( + array('d2' => 'catalog_product_entity_int'), + 'd.entity_id = d2.entity_id AND d2.attribute_id = 96 AND d2.value = 1 AND d.store_id = 0' + )->will($this->returnSelf()); + + $adapter = $this->getMockBuilder('Magento\Framework\DB\Adapter\Pdo\Mysql') + ->setMethods([ + 'select', 'delete', 'beginTransaction', 'getTransactionLevel', 'fetchCol', 'query', 'quoteInto', + 'describeTable', 'commit' + ])->disableOriginalConstructor()->getMock(); + $adapter->expects($this->any())->method('select')->will($this->returnValue($select)); + $adapter->expects($this->any())->method('getTransactionLevel')->will($this->returnValue(1)); + $adapter->expects($this->any())->method('fetchCol')->will($this->returnValue([1])); + $adapter->expects($this->any())->method('query')->will($this->returnValue($query)); + $adapter->expects($this->any())->method('describeTable')->will($this->returnValue([])); + $adapter->expects($this->any())->method('commit')->will($this->returnValue(null)); + + + $this->resource->expects($this->any())->method('getConnection')->with('core_write') + ->will($this->returnValue($adapter)); + $this->resource->expects($this->at(4))->method('getTableName')->with('catalog_product_index_eav_tmp') + ->will($this->returnArgument(0)); + $this->resource->expects($this->at(8))->method('getTableName')->with('catalog_product_entity_int') + ->will($this->returnArgument(0)); + + + $attribute = $this->getMockBuilder('Magento\Eav\Model\Entity\Attribute')->disableOriginalConstructor() + ->setMethods(['getId', '__sleep', '__wakeup', 'getBackend', 'getTable', 'isScopeGlobal'])->getMock(); + $attribute->expects($this->once())->method('getId')->will($this->returnValue(96)); + $attribute->expects($this->any())->method('getBackend')->will($this->returnSelf()); + $attribute->expects($this->any())->method('getTable')->will($this->returnValue('some_table')); + $attribute->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(true)); + $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($attribute)); + + $this->source->reindexEntities([1]); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/BasePriceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/BasePriceTest.php index b0f87ecaccd1a..8ea497367bef5 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/BasePriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/BasePriceTest.php @@ -34,7 +34,7 @@ class BasePriceTest extends \PHPUnit_Framework_TestCase protected $basePrice; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/ConfiguredPriceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/ConfiguredPriceTest.php index 8ad8599043886..3be40026abfe2 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/ConfiguredPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/ConfiguredPriceTest.php @@ -67,7 +67,7 @@ protected function setUp() $basePrice = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface', [], [], '', false); $basePrice->expects($this->any())->method('getValue')->will($this->returnValue($this->basePriceValue)); - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface', [], [], '', false); + $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->priceInfo->expects($this->any())->method('getPrice')->will($this->returnValue($basePrice)); $this->product = $this->getMockBuilder('Magento\Catalog\Model\Product') diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/GroupPriceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/GroupPriceTest.php index cc3ac4c83a844..36d889fbdeb1f 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/GroupPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/GroupPriceTest.php @@ -128,7 +128,7 @@ protected function prepareSaleableItem($groupPrice) ->will($this->returnValue($this->prepareSaleableItemResource())); $priceInfo = $this->getMockBuilder( - 'Magento\Framework\Pricing\PriceInfoInterface' + 'Magento\Framework\Pricing\PriceInfo\Base' )->disableOriginalConstructor()->getMockForAbstractClass(); $priceInfo->expects($this->any()) diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/TierPriceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/TierPriceTest.php index d578dd0a4498e..6dc86b8bd4a53 100644 --- a/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/TierPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Catalog/Pricing/Price/TierPriceTest.php @@ -73,7 +73,7 @@ class TierPriceTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface', [], [], '', false); + $this->priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $this->product = $this->getMock( 'Magento\Catalog\Model\Product', diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceTest.php new file mode 100644 index 0000000000000..d961bb8f27446 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/ReadServiceTest.php @@ -0,0 +1,73 @@ +groupListFactory = $this->getMock( + '\Magento\Eav\Model\Resource\Entity\Attribute\Group\CollectionFactory', + array('create'), + array(), + '', + false + ); + $groupBuilder = $helper->getObject('\Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $this->service = new ReadService($this->groupListFactory, $groupBuilder); + } + + public function testListGroups() + { + $groupList = $this->getMock( + '\Magento\Eav\Model\Resource\Entity\Attribute\Group\Collection', + array(), + array(), + '', + false + ); + $this->groupListFactory->expects($this->once())->method('create')->will($this->returnValue($groupList)); + $item1 = new \Magento\Framework\Object(array('id' => 1, 'attribute_group_name' => 'First')); + $item2 = new \Magento\Framework\Object(array('id' => 2, 'attribute_group_name' => 'Second')); + $groupList->expects($this->once())->method('getItems')->will($this->returnValue(array($item1, $item2))); + $result = $this->service->getList(1); + $this->assertCount(2, $result); + $this->assertInstanceOf('\Magento\Catalog\Service\V1\Data\Eav\AttributeGroup', $result[0]); + $this->assertInstanceOf('\Magento\Catalog\Service\V1\Data\Eav\AttributeGroup', $result[1]); + $this->assertEquals('First', $result[0]->getName()); + $this->assertEquals('Second', $result[1]->getName()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceTest.php new file mode 100644 index 0000000000000..9d8c7e507472e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeGroup/WriteServiceTest.php @@ -0,0 +1,163 @@ +objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + + $this->groupFactory = $this->getMock( + '\Magento\Catalog\Model\Product\Attribute\GroupFactory', + array('create'), + array(), + '', + false + ); + $this->group = $this->getMock( + '\Magento\Catalog\Model\Product\Attribute\Group', + array( + 'getId', 'setId', 'setAttributeGroupName', '__wakeUp', 'save', 'load', 'delete', 'hasSystemAttributes' + ), + array(), + '', + false + ); + $this->groupFactory->expects($this->any())->method('create')->will($this->returnValue($this->group)); + $this->groupBuilder = $this->objectHelper->getObject( + 'Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder' + ); + $this->service = new WriteService($this->groupFactory, $this->groupBuilder); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testCreateThrowsException() + { + $this->group->expects($this->once())->method('save')->will($this->throwException(new \Exception())); + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->create(1, $groupDataBuilder->create()); + } + + public function testCreateCreatesNewAttributeGroup() + { + $this->group->expects($this->once())->method('setAttributeGroupName')->with('testName'); + $this->group->expects($this->once())->method('save'); + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->create(1, $groupDataBuilder->create()); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testUpdateThrowsExceptionIfNoSuchEntityExists() + { + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->update(1, $groupDataBuilder->create()); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testUpdateThrowsExceptionIfEntityWasNotSaved() + { + $this->group->expects($this->once())->method('save')->will($this->throwException(new \Exception())); + $this->group->expects($this->once())->method('getId')->will($this->returnValue(1)); + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->update(1, $groupDataBuilder->create()); + } + + public function testUpdateSavesEntity() + { + $this->group->expects($this->once())->method('save'); + $this->group->expects($this->once())->method('getId')->will($this->returnValue(1)); + $this->group->expects($this->once())->method('setId')->with(null); + $this->group->expects($this->once())->method('setAttributeGroupName')->with('testName'); + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->update(1, $groupDataBuilder->create()); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testDeleteThrowsExceptionIfNoEntityExists() + { + $this->group->expects($this->once())->method('getId')->will($this->returnValue(null)); + $groupDataBuilder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeGroupBuilder'); + $groupDataBuilder->setName('testName'); + $this->service->delete(1, $groupDataBuilder->create()); + } + + /** + * @expectedException \Magento\Framework\Exception\StateException + */ + public function testDeleteThrowsStateExceptionIfTryToDeleteGroupWithSystemAttributes() + { + $this->group->expects($this->once())->method('hasSystemAttributes')->will($this->returnValue(true)); + $this->group->expects($this->never())->method('delete'); + $this->service->delete(1); + } + + public function testDeleteRemovesEntity() + { + $this->group->expects($this->once())->method('getId')->will($this->returnValue(1)); + $this->group->expects($this->once())->method('delete'); + $this->service->delete(1); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceTest.php new file mode 100644 index 0000000000000..f3e9b543bbdad --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/AttributeServiceTest.php @@ -0,0 +1,379 @@ +objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + + $attributeFactoryMock = $this->getMock( + '\Magento\Eav\Model\Entity\AttributeFactory', array('create'), array(), '', false + ); + $setFactoryMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\SetFactory', array('create'), array(), '', false + ); + $groupFactoryMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\GroupFactory', array('create'), array(), '', false + ); + $entityTypeFactoryMock = $this->getMock( + '\Magento\Eav\Model\ConfigFactory', array('create'), array(), '', false + ); + + $this->attributeMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute', + array( + 'getId', 'setId', 'setEntityTypeId', 'setAttributeSetId', 'load', + 'setAttributeGroupId', 'setSortOrder', 'loadEntityAttributeIdBySet', '__sleep', '__wakeup' + ), + array(), '', false + ); + $this->attributeGroupMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Group', array(), array(), '', false + ); + $this->attributeSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', array(), array(), '', false + ); + $this->entityTypeConfigMock = $this->getMock( + '\Magento\Eav\Model\Config', array('getEntityType', 'getEntityTypeCode', 'getId', '__sleep', '__wakeup'), + array(), '', false + ); + $this->attrResourceMock = $this->getMock( + '\Magento\Eav\Model\Resource\Entity\Attribute', array(), array(), '', false + ); + + $attributeFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->attributeMock)); + $setFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->attributeSetMock)); + $groupFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->attributeGroupMock)); + $entityTypeFactoryMock->expects($this->any()) + ->method('create')->will($this->returnValue($this->entityTypeConfigMock)); + + $this->service = new AttributeService( + $attributeFactoryMock, + $groupFactoryMock, + $setFactoryMock, + $entityTypeFactoryMock, + $this->attrResourceMock + ); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::__construct + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::addAttribute + */ + public function testAddAttribute() + { + $data = [ + 'attribute_id' => 1, + 'attribute_group_id' => 1, + 'sort_order' => 1 + ]; + $builder = $this->objectHelper->getObject('\Magento\Catalog\Service\V1\Data\Eav\AttributeSet\AttributeBuilder'); + $attributeDataObject = $builder->populateWithArray($data)->create(); + + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $objectMock->expects($this->any())->method('getData')->will($this->returnValue(1)); + + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->attributeGroupMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->attributeMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue(\Magento\Catalog\Model\Product::ENTITY)); + $this->entityTypeConfigMock->expects($this->once())->method('getId')->will($this->returnValue(4)); + + $this->attributeMock->expects($this->once())->method('setId')->with(1); + $this->attributeMock->expects($this->once())->method('setEntityTypeId')->with(4); + $this->attributeMock->expects($this->once())->method('setAttributeSetId')->with(1); + $this->attributeMock->expects($this->once())->method('setAttributeGroupId')->with(1); + $this->attributeMock->expects($this->once())->method('setSortOrder')->with(1); + $this->attributeMock->expects($this->once()) + ->method('loadEntityAttributeIdBySet')->will($this->returnValue($objectMock)); + $this->attrResourceMock->expects($this->once())->method('saveInSetIncluding')->with($this->attributeMock); + + $this->service->addAttribute(1, $attributeDataObject); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::addAttribute + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Attribute set does not exist + */ + public function testAddAttributeWithWrongAttributeSet() + { + $builder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeSet\AttributeBuilder'); + $attributeDataObject = $builder->populateWithArray([])->create(); + + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->service->addAttribute(1, $attributeDataObject); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::addAttribute + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Wrong attribute set id provided + */ + public function testAddAttributeWithAttributeSetOfOtherEntityType() + { + $builder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeSet\AttributeBuilder'); + $attributeDataObject = $builder->populateWithArray(['attribute_group'])->create(); + + $attributeSetMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $attributeSetMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($attributeSetMock)); + + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once())->method('getEntityTypeCode')->will($this->returnValue('0')); + + $this->service->addAttribute(1, $attributeDataObject); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::addAttribute + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Attribute group does not exist + */ + public function testAddAttributeWithWrongAttributeGroup() + { + $builder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeSet\AttributeBuilder'); + $attributeDataObject = $builder->populateWithArray(['attribute_group'])->create(); + + $attributeSetMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $attributeSetMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($attributeSetMock)); + + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + + $attributeGroupMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $this->attributeGroupMock->expects($this->once())->method('load') + ->will($this->returnValue($attributeGroupMock)); + + $this->service->addAttribute(1, $attributeDataObject); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\AttributeSet\AttributeService::addAttribute + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Attribute does not exist + */ + public function testAddAttributeWithWrongAttribute() + { + $builder = $this->objectHelper->getObject('Magento\Catalog\Service\V1\Data\Eav\AttributeSet\AttributeBuilder'); + $attributeDataObject = $builder->populateWithArray(['attribute_group'])->create(); + + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->attributeGroupMock->expects($this->once())->method('load') ->will($this->returnValue($objectMock)); + + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + + $attributeMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $this->attributeMock->expects($this->once())->method('load')->will($this->returnValue($attributeMock)); + + $this->service->addAttribute(1, $attributeDataObject); + } + + public function testSuccessfullyDeleteAttribute() + { + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $methods = array('__wakeup', 'setAttributeSetId', + 'loadEntityAttributeIdBySet', 'getEntityAttributeId', 'deleteEntity', 'getId', 'getIsUserDefined'); + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->with(1)->will($this->returnValue($objectMock)); + $attributeMock = + $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $methods, array(), '', false); + $this->attributeMock + ->expects($this->once())->method('load')->with(10)->will($this->returnValue($attributeMock)); + $attributeMock->expects($this->any())->method('getId')->will($this->returnValue(2)); + $attributeMock->expects($this->once())->method('setAttributeSetId')->with(1)->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('loadEntityAttributeIdBySet')->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('getEntityAttributeId')->will($this->returnValue(10)); + $attributeMock->expects($this->once())->method('getIsUserDefined')->will($this->returnValue(true)); + $attributeMock->expects($this->once())->method('deleteEntity'); + $this->assertEquals(true, $this->service->deleteAttribute(1, 10)); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with attributeSetId = 1 + */ + public function testDeleteAttributeFromNonExistingAttributeSet() + { + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(false)); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->attributeMock->expects($this->never())->method('load'); + + $this->service->deleteAttribute(1, 10); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with attributeId = 10 + */ + public function testDeleteNonExistingAttribute() + { + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $methods = array('__wakeup', 'setAttributeSetId', + 'loadEntityAttributeIdBySet', 'getEntityAttributeId', 'deleteEntity', 'getId'); + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->with(1)->will($this->returnValue($objectMock)); + $attributeMock = + $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $methods, array(), '', false); + $this->attributeMock->expects($this->once())->method('load')->with(10) + ->will($this->returnValue($attributeMock)); + $attributeMock->expects($this->any())->method('getId')->will($this->returnValue(false)); + $attributeMock->expects($this->never())->method('setAttributeSetId'); + $this->service->deleteAttribute(1, 10); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Requested attribute is not in requested attribute set. + */ + public function testDeleteAttributeNotInAttributeSet() + { + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $methods = array('__wakeup', 'setAttributeSetId', + 'loadEntityAttributeIdBySet', 'getEntityAttributeId', 'deleteEntity', 'getId'); + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->with(1)->will($this->returnValue($objectMock)); + $attributeMock = + $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $methods, array(), '', false); + $this->attributeMock->expects($this->once())->method('load')->with(10) + ->will($this->returnValue($attributeMock)); + $attributeMock->expects($this->any())->method('getId')->will($this->returnValue(2)); + $attributeMock->expects($this->once())->method('setAttributeSetId')->with(1)->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('loadEntityAttributeIdBySet')->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('getEntityAttributeId')->will($this->returnValue(false)); + $attributeMock->expects($this->never())->method('deleteEntity'); + $this->assertEquals(true, $this->service->deleteAttribute(1, 10)); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage Attribute with wrong attribute type is provided + */ + public function testDeleteAttributeHasNotCorrespondingType() + { + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue('some_type')); + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->will($this->returnValue($objectMock)); + $this->attributeMock->expects($this->never())->method('load'); + $this->assertEquals(true, $this->service->deleteAttribute(1, 10)); + } + + /** + * @expectedException \Magento\Framework\Exception\StateException + * @expectedExceptionMessage System attribute can not be deleted + */ + public function testDeleteSystemAttribute() + { + $entityCode = \Magento\Catalog\Model\Product::ENTITY; + $methods = array('__wakeup', 'setAttributeSetId', + 'loadEntityAttributeIdBySet', 'getEntityAttributeId', 'deleteEntity', 'getId', 'getIsUserDefined'); + $this->entityTypeConfigMock->expects($this->once())->method('getEntityType')->will($this->returnSelf()); + $this->entityTypeConfigMock->expects($this->once()) + ->method('getEntityTypeCode')->will($this->returnValue($entityCode)); + $objectMock = $this->getMock('\Magento\Framework\Object', array(), array(), '', false); + $objectMock->expects($this->any())->method('getId')->will($this->returnValue(1)); + $this->attributeSetMock->expects($this->once())->method('load')->with(1)->will($this->returnValue($objectMock)); + $attributeMock = + $this->getMock('Magento\Eav\Model\Entity\Attribute\AbstractAttribute', $methods, array(), '', false); + $this->attributeMock + ->expects($this->once())->method('load')->with(10)->will($this->returnValue($attributeMock)); + $attributeMock->expects($this->any())->method('getId')->will($this->returnValue(2)); + $attributeMock->expects($this->once())->method('setAttributeSetId')->with(1)->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('loadEntityAttributeIdBySet')->will($this->returnSelf()); + $attributeMock->expects($this->once())->method('getEntityAttributeId')->will($this->returnValue(10)); + $attributeMock->expects($this->once())->method('getIsUserDefined')->will($this->returnValue(false)); + $attributeMock->expects($this->never())->method('deleteEntity'); + $this->service->deleteAttribute(1, 10); + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceTest.php new file mode 100644 index 0000000000000..f1c32d7fbea80 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/ReadServiceTest.php @@ -0,0 +1,340 @@ +setFactoryMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\SetFactory', + array('create'), array(), '', false); + $this->collectionFactoryMock = $this->getMock( + '\Magento\Eav\Model\Resource\Entity\Attribute\Set\CollectionFactory', + array('create'), array(), '', false + ); + + $this->eavConfigMock = $this->getMock('\Magento\Eav\Model\Config', array(), array(), '', false); + $this->entityTypeMock = $this->getMock('\Magento\Eav\Model\Entity\Type', array(), array(), '', false); + $this->eavConfigMock->expects($this->any()) + ->method('getEntityType') + ->with(\Magento\Catalog\Model\Product::ENTITY) + ->will($this->returnValue($this->entityTypeMock)); + + $this->builderMock = $this->getMock('\Magento\Catalog\Service\V1\Data\Eav\AttributeSetBuilder', + array('create', 'setId', 'setName', 'setSortOrder'), array(), '', false); + + $this->attrCollectionMock = $this->getMock('\Magento\Eav\Model\Resource\Entity\Attribute\Collection', + array(), array(), '', false); + $this->attributeBuilderMock = $this->getMock('\Magento\Catalog\Service\V1\Data\Eav\AttributeBuilder', + array(), array(), '', false); + + $this->service = new ReadService( + $this->setFactoryMock, + $this->collectionFactoryMock, + $this->eavConfigMock, + $this->builderMock, + $this->attrCollectionMock, + $this->attributeBuilderMock + ); + } + + public function testGetList() + { + $attributeSetData = array('attribute_set_id' => 4, 'attribute_set_name' => 'Default', 'sort_order' => 2); + + $collectionMock = $this->getMock( + '\Magento\Eav\Model\Resource\Entity\Attribute\Set\Collection', array(), array(), '', false + ); + + $productEntityId = 4; + $this->entityTypeMock->expects($this->once())->method('getId')->will($this->returnValue($productEntityId)); + + $this->collectionFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($collectionMock)); + + $collectionMock->expects($this->once())->method('setEntityTypeFilter') + ->with($productEntityId) + ->will($this->returnSelf()); + + $collectionMock->expects($this->once())->method('load')->will($this->returnSelf()); + + $attributeSets = $resultSets = array(); + + //prepare getter checks + $setMock = $this->getMock('\Magento\Eav\Model\Resource\Entity\Attribute\Set', + array('getId', 'getAttributeSetName', 'getSortOrder', '__wakeup'), array(), '', false); + $setMock->expects($this->any())->method('getId') + ->will($this->returnValue($attributeSetData['attribute_set_id'])); + $setMock->expects($this->any())->method('getAttributeSetName') + ->will($this->returnValue($attributeSetData['attribute_set_name'])); + $setMock->expects($this->any())->method('getSortOrder') + ->will($this->returnValue($attributeSetData['sort_order'])); + $attributeSets[] = $setMock; + + //prepare setter checks + $this->builderMock->expects($this->once())->method('setId') + ->with($attributeSetData['attribute_set_id']); + $this->builderMock->expects($this->once())->method('setName') + ->with($attributeSetData['attribute_set_name']); + $this->builderMock->expects($this->once())->method('setSortOrder') + ->with($attributeSetData['sort_order']); + + $dataObjectMock = $this->getMock( + 'Magento\Catalog\Service\V1\Data\Eav\AttributeSet', array(), array(), '', false + ); + $this->builderMock->expects($this->once())->method('create')->will($this->returnValue($dataObjectMock)); + $resultSets[] = $dataObjectMock; + + $collectionMock->expects($this->any())->method('getIterator') + ->will($this->returnValue(new \ArrayIterator($attributeSets))); + + $this->assertEquals($resultSets, $this->service->getList()); + } + + public function testGetInfoReturnsAttributeSetIfIdIsValid() + { + $attributeSetData = array( + 'id' => 4, + 'name' => 'Default', + 'sort_order' => 2, + ); + $attributeSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('load', 'getId', 'getAttributeSetName', 'getSortOrder', '__wakeup', 'getEntityTypeId'), + array(), + '', + false + ); + $entityTypeId = 4; + $this->entityTypeMock->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId)); + + $this->setFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($attributeSetMock)); + $attributeSetMock->expects($this->any())->method('getId') + ->will($this->returnValue($attributeSetData['id'])); + $attributeSetMock->expects($this->any())->method('getAttributeSetName') + ->will($this->returnValue($attributeSetData['name'])); + $attributeSetMock->expects($this->any())->method('getSortOrder') + ->will($this->returnValue($attributeSetData['sort_order'])); + $attributeSetMock->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entityTypeId)); + $attributeSetMock->expects($this->once()) + ->method('load') + ->with($attributeSetData['id']) + ->will($this->returnSelf()); + $this->builderMock->expects($this->once()) + ->method('setId') + ->with($attributeSetData['id']) + ->will($this->returnSelf()); + $this->builderMock->expects($this->once()) + ->method('setName') + ->with($attributeSetData['name']) + ->will($this->returnSelf()); + $this->builderMock->expects($this->once()) + ->method('setSortOrder') + ->with($attributeSetData['sort_order']) + ->will($this->returnSelf()); + $dataObjectMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $this->builderMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($dataObjectMock)); + $this->assertEquals($dataObjectMock, $this->service->getInfo($attributeSetData['id'])); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with attributeSetId = 1 + */ + public function testGetInfoThrowsExceptionIfIdIsNotValid() + { + $attributeSetData = array( + 'id' => 1, + ); + $attributeSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('load', 'getId', 'getName', 'getSortOrder', '__wakeup'), + array(), + '', + false + ); + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($attributeSetMock)); + $attributeSetMock->expects($this->once()) + ->method('load') + ->with($attributeSetData['id']) + ->will($this->returnSelf()); + $this->builderMock->expects($this->never())->method('create'); + $this->service->getInfo($attributeSetData['id']); + } + + public function testGetAttributeListIfIdIsValid() + { + $attributeSetId = 4; + $attributeSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('load', 'getId', 'getAttributeSetName', 'getSortOrder', '__wakeup', 'getEntityTypeId'), + array(), + '', + false + ); + $entityTypeId = 4; + $this->entityTypeMock->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId)); + + $this->setFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($attributeSetMock)); + $attributeSetMock->expects($this->any())->method('getId') + ->will($this->returnValue($attributeSetId)); + $attributeSetMock->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entityTypeId)); + $attributeSetMock->expects($this->once()) + ->method('load') + ->with($attributeSetId) + ->will($this->returnSelf()); + + $this->attrCollectionMock->expects($this->once())->method('setAttributeSetFilter')->with($attributeSetId) + ->will($this->returnSelf()); + + $attributeData = array( + 'attribute_id' => 1, + 'attribute_code' => 'status', + 'frontend_label' => 'Status', + 'default_value' => '1', + 'is_required' => false, + 'is_user_defined' => false, + ); + + // Use magento object for simplicity + $this->attrCollectionMock->expects($this->once())->method('load')->will($this->returnValue( + array(new \Magento\Framework\Object($attributeData)) + )); + $this->attributeBuilderMock->expects($this->once()) + ->method('setId') + ->with($attributeData['attribute_id']) + ->will($this->returnSelf()); + $this->attributeBuilderMock->expects($this->once()) + ->method('setCode') + ->with($attributeData['attribute_code']) + ->will($this->returnSelf()); + $this->attributeBuilderMock->expects($this->once()) + ->method('setFrontendLabel') + ->with($attributeData['frontend_label']) + ->will($this->returnSelf()); + $this->attributeBuilderMock->expects($this->once()) + ->method('setDefaultValue') + ->with($attributeData['default_value']) + ->will($this->returnSelf()); + $this->attributeBuilderMock->expects($this->once()) + ->method('setIsRequired') + ->with($attributeData['is_required']) + ->will($this->returnSelf()); + $this->attributeBuilderMock->expects($this->once()) + ->method('setIsUserDefined') + ->with($attributeData['is_user_defined']) + ->will($this->returnSelf()); + + $dataObjectMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\Attribute', + array(), + array(), + '', + false + ); + $this->attributeBuilderMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($dataObjectMock)); + $this->assertContains($dataObjectMock, $this->service->getAttributeList($attributeSetId)); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with attributeSetId = 80085 + */ + public function testGetAttributeListThrowsExceptionIfIdIsNotValid() + { + $attributeSetId = 80085; + $attributeSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('load', 'getId', 'getName', 'getSortOrder', '__wakeup'), + array(), + '', + false + ); + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($attributeSetMock)); + $attributeSetMock->expects($this->once()) + ->method('load') + ->with($attributeSetId) + ->will($this->returnSelf()); + $this->attrCollectionMock->expects($this->never())->method('load'); + $this->attributeBuilderMock->expects($this->never())->method('create'); + $this->service->getAttributeList($attributeSetId); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceTest.php new file mode 100644 index 0000000000000..62f48a97cc1e3 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/AttributeSet/WriteServiceTest.php @@ -0,0 +1,379 @@ +setFactoryMock = $this->getMock('\Magento\Eav\Model\Entity\Attribute\SetFactory', + array('create'), array(), '', false); + $this->eavConfigMock = $this->getMock('\Magento\Eav\Model\Config', array(), array(), '', false); + $this->entityTypeMock = $this->getMock('\Magento\Eav\Model\Entity\Type', array(), array(), '', false); + $this->eavConfigMock->expects($this->any())->method('getEntityType') + ->with(\Magento\Catalog\Model\Product::ENTITY) + ->will($this->returnValue($this->entityTypeMock)); + $this->setMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array( + 'setData', 'getData', 'validate', 'save', 'getId', 'delete', 'setAttributeSetName', 'setSortOrder', + 'load', 'initFromSkeleton', '__wakeup', 'getEntityTypeId', + ), + array(), + '', + false + ); + $this->service = new WriteService( + $this->setFactoryMock, + $this->eavConfigMock + ); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testCreateWithExistingId() + { + $setDataMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $this->setFactoryMock->expects($this->any())->method('create')->will($this->returnValue($this->setMock)); + $setDataMock->expects($this->any())->method('getId')->will($this->returnValue($this->defaultSetId)); + + $this->service->create($setDataMock, $this->defaultSetId); + } + + /** + * @expectedException \Magento\Eav\Exception + */ + public function testCreateWithEmptyName() + { + $setDataMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $setDataMock->expects($this->any())->method('getId')->will($this->returnValue(null)); + $setDataMock->expects($this->any())->method('getName')->will($this->returnValue(null)); + $setDataMock->expects($this->any())->method('getSortOrder')->will($this->returnValue(20)); + + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $exception = new \Magento\Eav\Exception('empty name'); + $this->setMock->expects($this->once())->method('validate')->will($this->throwException($exception)); + $this->setMock->expects($this->never())->method('save'); + + $this->service->create($setDataMock, $this->defaultSetId); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testCreateWithNoSkeletonId() + { + $setDataMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $setDataMock->expects($this->any())->method('getId')->will($this->returnValue(null)); + $setDataMock->expects($this->any())->method('getName')->will($this->returnValue('cool attribute set')); + $setDataMock->expects($this->any())->method('getSortOrder')->will($this->returnValue(20)); + + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('validate')->will($this->returnValue(true)); + + $this->service->create($setDataMock, null); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testCreateWithAbsentSkeleton() + { + $absentId = 134523; + $setDataMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $setDataMock->expects($this->any())->method('getId')->will($this->returnValue(null)); + $setDataMock->expects($this->any())->method('getName')->will($this->returnValue('cool attribute set')); + $setDataMock->expects($this->any())->method('getSortOrder')->will($this->returnValue(20)); + + $this->setFactoryMock->expects($this->exactly(2))->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('validate')->will($this->returnValue(true)); + $skeletonSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('setData', 'validate', 'save', 'getId', 'getData', 'load', '__wakeup'), + array(), + '', + false + ); + $skeletonSetMock->expects($this->once())->method('getData')->will($this->returnValue(array())); + $this->setMock->expects($this->once())->method('load') + ->with($absentId) + ->will($this->returnValue($skeletonSetMock)); + + $this->service->create($setDataMock, $absentId); + } + + public function testCreatePositive() + { + $setId = 123321; + $setDataMock = $this->getMock( + '\Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), + array(), + '', + false + ); + $setDataMock->expects($this->any())->method('getId')->will($this->returnValue(null)); + $setDataMock->expects($this->any())->method('getName')->will($this->returnValue('cool attribute set')); + $setDataMock->expects($this->any())->method('getSortOrder')->will($this->returnValue(20)); + + $this->setFactoryMock->expects($this->exactly(2))->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('validate')->will($this->returnValue(true)); + $this->setMock->expects($this->exactly(2))->method('save'); + $this->setMock->expects($this->once())->method('getId')->will($this->returnValue($setId)); + $skeletonSetMock = $this->getMock( + '\Magento\Eav\Model\Entity\Attribute\Set', + array('setData', 'validate', 'save', 'getId', 'load', 'getData', '__wakeup'), + array(), + '', + false + ); + $this->setMock->expects($this->once())->method('load') + ->with($this->defaultSetId) + ->will($this->returnValue($skeletonSetMock)); + $skeletonSetMock->expects($this->once())->method('getData')->will($this->returnValue(array(1, 2, 3))); + $this->setMock->expects($this->once())->method('initFromSkeleton')->with($this->defaultSetId); + + $this->assertEquals($setId, $this->service->create($setDataMock, $this->defaultSetId)); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testRemoveInvalidId() + { + $this->setFactoryMock->expects($this->never())->method('create'); + $this->service->remove('absent id'); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testRemoveAbsentSet() + { + $id = 145678; + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('getData')->will($this->returnValue(null)); + $this->setMock->expects($this->never())->method('delete'); + $this->service->remove($id); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + */ + public function testRemoveWrongEntity() + { + $id = 14; + + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $typeMock = $this->getMock('\Magento\Eav\Model\Entity\Type', array('getId', '__wakeup'), array(), '', false); + $this->eavConfigMock->expects($this->any())->method('getEntityType')->will($this->returnValue($typeMock)); + $typeMock->expects($this->any())->method('getId')->will($this->returnValue(4)); + + $this->setMock->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('getData')->will($this->returnValue(array(5, 7, 9))); + $this->setMock->expects($this->any())->method('getEntityTypeId')->will($this->returnValue(1)); + $this->setMock->expects($this->never())->method('delete'); + $this->service->remove($id); + } + + public function testRemovePositive() + { + $id = 456; + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('getData')->will($this->returnValue(array(5, 6, 7))); + $this->setMock->expects($this->once())->method('delete'); + + $this->service->remove($id); + } + + public function testUpdate() + { + $data = array( + AttributeSet::ID => 4, + AttributeSet::NAME => 'Test Attribute Set', + AttributeSet::ORDER => 200, + ); + $attributeSetDataMock = $this->getMock('Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), array(), '', false); + $attributeSetDataMock->expects($this->any())->method('getId') + ->will($this->returnValue($data[AttributeSet::ID])); + $attributeSetDataMock->expects($this->any())->method('getName') + ->will($this->returnValue($data[AttributeSet::NAME])); + $attributeSetDataMock->expects($this->any())->method('getSortOrder') + ->will($this->returnValue($data[AttributeSet::ORDER])); + + $entityTypeId = 4; + $this->entityTypeMock->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId)); + + $this->setFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once()) + ->method('load') + ->with($data[AttributeSet::ID]) + ->will($this->returnSelf()); + $this->setMock->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entityTypeId)); + $this->setMock->expects($this->any())->method('getId') + ->will($this->returnValue($data[AttributeSet::ID])); + $this->setMock->expects($this->once())->method('setAttributeSetName')->with($data[AttributeSet::NAME]) + ->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('setSortOrder')->with($data[AttributeSet::ORDER]) + ->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('save') + ->will($this->returnSelf()); + $this->assertEquals($data[AttributeSet::ID], $this->service->update($attributeSetDataMock)); + } + + /** + * @expectedException \Magento\Framework\Exception\InputException + * @expectedExceptionMessage id is a required field. + */ + public function testUpdateThrowsExceptionIfAttributeSetIdIsNotSpecified() + { + $data = array( + AttributeSet::ID => null, + AttributeSet::NAME => 'Test Attribute Set', + AttributeSet::ORDER => 200, + ); + $attributeSetDataMock = $this->getMock('Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), array(), '', false); + $attributeSetDataMock->expects($this->any())->method('getId') + ->will($this->returnValue($data[AttributeSet::ID])); + $this->service->update($attributeSetDataMock); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage No such entity with id = 9999 + */ + public function testUpdateThrowsExceptionIfAttributeSetIdIsInvalid() + { + $entityTypeId = 4; + $data = array( + AttributeSet::ID => 9999, + AttributeSet::NAME => 'Test Attribute Set', + AttributeSet::ORDER => 200, + ); + $attributeSetDataMock = $this->getMock('Magento\Catalog\Service\V1\Data\Eav\AttributeSet', + array(), array(), '', false); + $attributeSetDataMock->expects($this->any())->method('getId') + ->will($this->returnValue($data[AttributeSet::ID])); + + $this->entityTypeMock->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId)); + + $this->setFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once()) + ->method('load') + ->with($data[AttributeSet::ID]) + ->will($this->returnSelf()); + $this->setMock->expects($this->any()) + ->method('getEntityTypeId') + ->will($this->returnValue($entityTypeId)); + $this->setMock->expects($this->any())->method('getId'); + $this->setMock->expects($this->never())->method('setAttributeSetName'); + $this->setMock->expects($this->never())->method('setSortOrder'); + $this->setMock->expects($this->never())->method('save'); + $this->service->update($attributeSetDataMock); + } + + /** + * @expectedException \Magento\Framework\Exception\StateException + * @expectedExceptionMessage Default attribute set can not be deleted + */ + public function testRemoveDefaultAttributeSet() + { + $id = 456; + $this->setFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->setMock)); + $this->setMock->expects($this->once())->method('load')->with($id)->will($this->returnSelf()); + $this->setMock->expects($this->once())->method('getData')->will($this->returnValue(array(5, 6, 7))); + $this->setMock->expects($this->never())->method('delete'); + $this->entityTypeMock + ->expects($this->once()) + ->method('getDefaultAttributeSetId') + ->will($this->returnValue($id)); + $this->service->remove($id); + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/CrosssellTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/CrosssellTest.php new file mode 100644 index 0000000000000..9afa36d6ab7d6 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/CrosssellTest.php @@ -0,0 +1,37 @@ +getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $expected = [$product]; + $product->expects($this->once())->method('getCrossSellProducts')->will($this->returnValue($expected)); + $model = new Crosssell(); + $this->assertEquals($expected, $model->getLinkedProducts($product)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/RelatedTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/RelatedTest.php new file mode 100644 index 0000000000000..df30fbdcbc6d8 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/RelatedTest.php @@ -0,0 +1,37 @@ +getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $expected = [$product]; + $product->expects($this->once())->method('getRelatedProducts')->will($this->returnValue($expected)); + $model = new Related(); + $this->assertEquals($expected, $model->getLinkedProducts($product)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/UpsellTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/UpsellTest.php new file mode 100644 index 0000000000000..691e93a337724 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/UpsellTest.php @@ -0,0 +1,37 @@ +getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $expected = [$product]; + $product->expects($this->once())->method('getUpSellProducts')->will($this->returnValue($expected)); + $model = new Upsell(); + $this->assertEquals($expected, $model->getLinkedProducts($product)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderTest.php new file mode 100644 index 0000000000000..60f651e36aa52 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/CollectionProviderTest.php @@ -0,0 +1,115 @@ +productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $this->converterPoolMock = $this->getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\ProductEntity\ConverterPool', + [], [], '', false + ); + $this->converterMock = $this->getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\ProductEntity\ConverterInterface' + ); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Collection provider is not registered + */ + public function testGetCollectionWithInvalidType() + { + $provider = new CollectionProvider($this->converterPoolMock); + $provider->getCollection($this->productMock, 'someType'); + } + + /** + * @covers \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider::getCollection + * @covers \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider::__construct + */ + public function testGetCollection() + { + $productA = $this->getMock('\Magento\Catalog\Model\Product', ['getId', '__wakeup'], [], '', false); + $productA->expects($this->once())->method('getId')->will($this->returnValue('resultA')); + $providerA = $this->getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProviderInterface' + ); + $providerA->expects($this->once()) + ->method('getLinkedProducts') + ->with($this->productMock) + ->will($this->returnValue([$productA])); + $resultA = ['resultA' => $productA]; + + $productB = $this->getMock('\Magento\Catalog\Model\Product', ['getId', '__wakeup'], [], '', false); + $productB->expects($this->once())->method('getId')->will($this->returnValue('resultB')); + $providerB = $this->getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProviderInterface' + ); + $providerB->expects($this->once()) + ->method('getLinkedProducts') + ->with($this->productMock) + ->will($this->returnValue([$productB])); + $resultB = ['resultB' => $productB]; + + $this->converterPoolMock + ->expects($this->any()) + ->method('getConverter') + ->will($this->returnValue($this->converterMock)); + + $this->converterMock + ->expects($this->any()) + ->method('convert') + ->will($this->returnArgument(0)); + + $provider = new CollectionProvider( + $this->converterPoolMock, + [ + 'typeA' => $providerA, + 'typeB' => $providerB + ] + ); + + $this->assertEquals($resultA, $provider->getCollection($this->productMock, 'typeA')); + $this->assertEquals($resultB, $provider->getCollection($this->productMock, 'typeB')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapper/CompositeTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapper/CompositeTest.php new file mode 100644 index 0000000000000..2b8176547111a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/DataMapper/CompositeTest.php @@ -0,0 +1,56 @@ +getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface' + ); + + $mapperTwo = $this->getMock( + '\Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface' + ); + + $model = new Composite([$mapperOne, $mapperTwo]); + $originData = ['some' => 'test', 'data' => '.']; + $firstModification = ['some' => 'test', 'data' => '.', 'first' => 'modification']; + $secondModification = ['some' => 'test', 'data' => '.', 'first' => 'modification', 'second' => 'modification']; + + $mapperOne->expects($this->once()) + ->method('map') + ->with($originData) + ->will($this->returnValue($firstModification)); + + $mapperTwo->expects($this->once()) + ->method('map') + ->with($firstModification) + ->will($this->returnValue($secondModification)); + + $this->assertEquals($secondModification, $model->map($originData)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterPoolTests.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterPoolTests.php new file mode 100644 index 0000000000000..71552cb330073 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterPoolTests.php @@ -0,0 +1,56 @@ + 'Simple Converter', + 'complex' => 'Complex Converter', + 'default' => 'Default Converter', + ); + + $this->model = new \Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\ProductEntity\ConverterPool( + $converters + ); + } + + public function testGetConverterExisting() + { + $this->assertEquals('Simple Converter', $this->model->getConverter('simple')); + } + + public function testGetConverterAbsent() + { + $this->assertEquals('Default Converter', $this->model->getConverter('absent')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverterTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverterTest.php new file mode 100644 index 0000000000000..0bd91bb6c9b74 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/Data/ProductLink/ProductEntity/DefaultConverterTest.php @@ -0,0 +1,68 @@ +product = $this->getMock( + '\Magento\Catalog\Model\Product', + ['getTypeId', 'getSku', 'getPosition', '__sleep', '__wakeup'], + [], + '', + false + ); + + $this->converter = new DefaultConverter(); + } + + public function testConvert() + { + $this->product->expects($this->once())->method('getTypeId')->will($this->returnValue('simple')); + $this->product->expects($this->once())->method('getSku')->will($this->returnValue('simple-sku')); + $this->product->expects($this->once())->method('getPosition')->will($this->returnValue(1)); + + $expected = [ + ProductLink::TYPE => 'simple', + ProductLink::SKU => 'simple-sku', + ProductLink::POSITION => 1 + ]; + + $this->assertEquals($expected, $this->converter->convert($this->product)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolverTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolverTest.php new file mode 100644 index 0000000000000..0af948e7a56a5 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/LinkTypeResolverTest.php @@ -0,0 +1,62 @@ +providerMock = $this->getMock('Magento\Catalog\Model\Product\LinkTypeProvider', [], [], '', false); + $this->model = new LinkTypeResolver($this->providerMock); + } + + public function testGetTypeIdByCode() + { + $linkTypes = ['crosssell' => 1, 'upsell' => 2, 'related' => 4]; + $this->providerMock->expects($this->once())->method('getLinkTypes')->will($this->returnValue($linkTypes)); + $this->assertEquals(4, $this->model->getTypeIdByCode('related')); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Unknown link type code is provided + */ + public function testGetTypeIdByCodeWithInvalidType() + { + $linkTypes = ['crosssell' => 1, 'upsell' => 2, 'related' => 4]; + $this->providerMock->expects($this->once())->method('getLinkTypes')->will($this->returnValue($linkTypes)); + $this->model->getTypeIdByCode('invalid_type'); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ProductLoaderTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ProductLoaderTest.php new file mode 100644 index 0000000000000..347e76b35babe --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ProductLoaderTest.php @@ -0,0 +1,84 @@ +factoryMock = $this->getMock('\Magento\Catalog\Model\ProductFactory', ['create'], [], '', false); + $this->productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $this->model = new ProductLoader($this->factoryMock); + } + + public function testLoad() + { + $this->factoryMock->expects($this->once())->method('create')->will($this->returnValue($this->productMock)); + $this->productMock->expects($this->once()) + ->method('getIdBySku') + ->with($this->productSku) + ->will($this->returnValue(1)); + + $this->productMock->expects($this->once())->method('load')->with(1); + $this->assertEquals($this->productMock, $this->model->load($this->productSku)); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage There is no product with provided SKU + */ + public function testLoadWithNonExistedProduct() + { + $this->factoryMock->expects($this->once())->method('create')->will($this->returnValue($this->productMock)); + $this->productMock->expects($this->once()) + ->method('getIdBySku') + ->with($this->productSku) + ->will($this->returnValue(null)); + + $this->productMock->expects($this->never())->method('load'); + + $this->assertEquals($this->productMock, $this->model->load($this->productSku)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ReadServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ReadServiceTest.php new file mode 100644 index 0000000000000..82e91616653eb --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/ReadServiceTest.php @@ -0,0 +1,229 @@ +providerMock = $this->getMock('Magento\Catalog\Model\Product\LinkTypeProvider', [], [], '', false); + $this->builderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\LinkTypeBuilder', + [], + [], + '', + false + ); + $this->productBuilderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLinkBuilder', + [], + [], + '', + false + ); + + $this->productLoaderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\ProductLoader', + [], + [], + '', + false + ); + + $this->collectionProviderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider', + [], + [], + '', + false + ); + + $this->linkFactoryMock = $this->getMock( + 'Magento\Catalog\Model\Product\LinkFactory', + ['create'], + [], + '', + false + ); + + $this->linkBuilderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\LinkAttributeBuilder', + [], + [], + '', + false + ); + + $this->linkResolverMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\LinkTypeResolver', + [], + [], + '', + false + ); + + $this->service = $helper->getObject( + 'Magento\Catalog\Service\V1\Product\Link\ReadService', + [ + 'linkTypeProvider' => $this->providerMock, + 'builder' => $this->builderMock, + 'productLoader' => $this->productLoaderMock, + 'productEntityBuilder' => $this->productBuilderMock, + 'entityCollectionProvider' => $this->collectionProviderMock, + 'linkFactory' => $this->linkFactoryMock, + 'linkAttributeBuilder' => $this->linkBuilderMock, + 'linkTypeResolver' => $this->linkResolverMock + + ] + ); + } + + public function testGetProductLinkTypes() + { + $types = ['typeOne' => 'codeOne', 'typeTwo' => 'codeTwo']; + + $this->providerMock->expects($this->once())->method('getLinkTypes')->will($this->returnValue($types)); + + $this->builderMock->expects($this->exactly(2)) + ->method('populateWithArray') + ->with( + $this->logicalOr( + $this->equalTo([LinkType::TYPE => 'typeOne', LinkType::CODE => 'codeOne']), + $this->equalTo([LinkType::TYPE => 'typeTwo', LinkType::CODE => 'codeTwo']) + ) + )->will($this->returnSelf()); + + $this->builderMock->expects($this->exactly(2)) + ->method('create') + ->will($this->returnSelf()); + + $this->assertCount(2, $this->service->getProductLinkTypes()); + } + + public function testGetLinkedProducts() + { + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $this->productLoaderMock + ->expects($this->once())->method('load') + ->with('product_sku') + ->will($this->returnValue($productMock)); + $itemMock = [ + ProductLink::TYPE => 'typeId', + ProductLink::SKU => 'sku', + ProductLink::POSITION => 0 + ]; + $this->collectionProviderMock + ->expects($this->once()) + ->method('getCollection') + ->with($productMock, 'productType') + ->will($this->returnValue(array($itemMock))); + + $this->productBuilderMock + ->expects($this->once()) + ->method('populateWithArray') + ->with($itemMock) + ->will($this->returnSelf()); + $this->productBuilderMock->expects($this->once())->method('create')->will($this->returnValue('Expected')); + $this->assertequals(array('Expected'), $this->service->getLinkedProducts('product_sku', 'productType')); + } + + public function testGetLinkedAttributes() + { + $linkMock = $this->getMock('Magento\Catalog\Model\Product\Link', array(), array(), '', false); + $attributeMock = [['code' => 'code_name', 'type' => 'type_name']]; + $this->linkResolverMock + ->expects($this->once()) + ->method('getTypeIdByCode') + ->with('productType') + ->will($this->returnValue('type_id')); + $this->linkFactoryMock + ->expects($this->once()) + ->method('create') + ->with(['data' => ['link_type_id' => 'type_id']]) + ->will($this->returnValue($linkMock)); + $data = [ + Data\LinkAttribute::CODE => 'code_name', + Data\LinkAttribute::TYPE => 'type_name' + ]; + $linkMock->expects($this->once())->method('getAttributes')->will($this->returnValue($attributeMock)); + $this->linkBuilderMock + ->expects($this->once()) + ->method('populateWithArray') + ->with($data) + ->will($this->returnSelf()); + $this->linkBuilderMock->expects($this->once())->method('create')->will($this->returnValue('Expected')); + $this->assertequals(array('Expected'), $this->service->getLinkAttributes('productType')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/WriteServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/WriteServiceTest.php new file mode 100644 index 0000000000000..2d5d764f104d4 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/Product/Link/WriteServiceTest.php @@ -0,0 +1,317 @@ +linkInitializerMock = $this->getMock( + 'Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks', + [], + [], + '', + false + ); + + $this->collectionProviderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\CollectionProvider', + [], + [], + '', + false + ); + + $this->productLoaderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\ProductLoader', + [], + [], + '', + false + ); + + $this->productResourceMock = $this->getMock( + 'Magento\Catalog\Model\Resource\Product', + [], + [], + '', + false + ); + + $this->dataMapperMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLink\DataMapperInterface', + [], + [], + '', + false + ); + $this->service = $helper->getObject('Magento\Catalog\Service\V1\Product\Link\WriteService', + [ + 'linkInitializer' => $this->linkInitializerMock, + 'entityCollectionProvider' => $this->collectionProviderMock, + 'productLoader' => $this->productLoaderMock, + 'productResource' => $this->productResourceMock, + 'dataMapper' => $this->dataMapperMock + ] + ); + } + + public function testSaveLinks() + { + $assignedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + + $this->productLoaderMock + ->expects($this->once()) + ->method('load') + ->with('product_sku') + ->will($this->returnValue($productMock)); + $assignedProductMock->expects($this->any())->method('getSku')->will($this->returnValue('assigned_sku')); + $this->productResourceMock + ->expects($this->once()) + ->method('getProductsIdsBySkus') + ->with(array('assigned_sku')) + ->will($this->returnValue(['assigned_sku' => 1])); + $this->dataMapperMock->expects($this->once())->method('map')->with([1 => ['product_id' => 1]]); + $productMock->expects($this->once())->method('save'); + $this->assertTrue($this->service->assign('product_sku', array($assignedProductMock), 'product_type')); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Product with SKU "assigned_sku" does not exist + */ + public function testSaveLinkWithNotExistingSku() + { + $assignedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + + $this->productLoaderMock + ->expects($this->once()) + ->method('load') + ->with('product_sku') + ->will($this->returnValue($productMock)); + $assignedProductMock->expects($this->any())->method('getSku')->will($this->returnValue('assigned_sku')); + $this->productResourceMock + ->expects($this->once()) + ->method('getProductsIdsBySkus') + ->with(array('assigned_sku')) + ->will($this->returnValue(['some_sku' => 1])); + $productMock->expects($this->never())->method('save'); + $this->service->assign('product_sku', array($assignedProductMock), 'product_type'); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + * @expectedExceptionMessage Invalid data provided for linked products + */ + public function testSaveLinkWithInvalidData() + { + $assignedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + + $this->productLoaderMock + ->expects($this->once()) + ->method('load') + ->with('product_sku') + ->will($this->returnValue($productMock)); + $assignedProductMock->expects($this->any())->method('getSku')->will($this->returnValue('assigned_sku')); + $this->productResourceMock + ->expects($this->once()) + ->method('getProductsIdsBySkus') + ->with(array('assigned_sku')) + ->will($this->returnValue(['assigned_sku' => 1])); + $this->dataMapperMock->expects($this->once())->method('map')->with([1 => ['product_id' => 1]]); + $productMock + ->expects($this->once()) + ->method('save') + ->will($this->throwException(new CouldNotSaveException('Invalid data provided for linked products'))); + $this->service->assign('product_sku', array($assignedProductMock), 'product_type'); + } + + public function testSuccessUpdate() + { + $linkedEntityMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLink', + [], + [], + '', + false + ); + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $linkedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $valueMap = [ + ['product_sku', $productMock], + ['linked_product_sku', $linkedProductMock] + ]; + $linkedEntityMock->expects($this->any())->method('getSku')->will($this->returnValue('linked_product_sku')); + $linkedProductMock->expects($this->exactly(3))->method('getId')->will($this->returnValue(10)); + $this->productLoaderMock + ->expects($this->any()) + ->method('load') + ->will($this->returnValueMap($valueMap)); + $this->collectionProviderMock + ->expects($this->once()) + ->method('getCollection') + ->with($productMock, 'product_type') + ->will($this->returnValue([10 => 1])); + $this->dataMapperMock + ->expects($this->once()) + ->method('map') + ->with([10 => ['product_id' => 10]]) + ->will($this->returnValue('mapped_value')); + $this->linkInitializerMock + ->expects($this->once()) + ->method('initializeLinks') + ->with($productMock, ['product_type' => 'mapped_value']); + $productMock->expects($this->once())->method('save'); + $this->assertTrue($this->service->update('product_sku', $linkedEntityMock, 'product_type')); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Product with SKU "linked_product_sku" is not linked to product with SKU product_sku + */ + public function testUpdateNotLinkedProduct() + { + $linkedEntityMock = $this->getMock( + 'Magento\Catalog\Service\V1\Product\Link\Data\ProductLink', + [], + [], + '', + false + ); + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $linkedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $valueMap = [ + ['product_sku', $productMock], + ['linked_product_sku', $linkedProductMock] + ]; + $linkedEntityMock->expects($this->exactly(2))->method('getSku')->will($this->returnValue('linked_product_sku')); + $linkedProductMock->expects($this->exactly(1))->method('getId')->will($this->returnValue(5)); + $this->productLoaderMock + ->expects($this->any()) + ->method('load') + ->will($this->returnValueMap($valueMap)); + $this->collectionProviderMock + ->expects($this->once()) + ->method('getCollection') + ->with($productMock, 'product_type') + ->will($this->returnValue([10 => 1])); + $productMock->expects($this->never())->method('save'); + $this->service->update('product_sku', $linkedEntityMock, 'product_type'); + } + + public function testSuccessRemove() + { + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $linkedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $valueMap = [ + ['product_sku', $productMock], + ['linked_product_sku', $linkedProductMock] + ]; + $linkedProductMock->expects($this->exactly(2))->method('getId')->will($this->returnValue(10)); + $this->productLoaderMock + ->expects($this->any()) + ->method('load') + ->will($this->returnValueMap($valueMap)); + $this->collectionProviderMock + ->expects($this->once()) + ->method('getCollection') + ->with($productMock, 'product_type') + ->will($this->returnValue([10 => 1])); + $this->dataMapperMock + ->expects($this->once()) + ->method('map') + ->with([]) + ->will($this->returnValue('mapped_value')); + $this->linkInitializerMock + ->expects($this->once()) + ->method('initializeLinks') + ->with($productMock, ['product_type' => 'mapped_value']); + $productMock->expects($this->once())->method('save'); + $this->assertTrue($this->service->remove('product_sku', 'linked_product_sku', 'product_type')); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + * @expectedExceptionMessage Product with SKU linked_product_sku is not linked to product with SKU product_sku + */ + public function testRemoveNotLinkedProduct() + { + $productMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $linkedProductMock = $this->getMock('Magento\Catalog\Model\Product', array(), array(), '', false); + $valueMap = [ + ['product_sku', $productMock], + ['linked_product_sku', $linkedProductMock] + ]; + $linkedProductMock->expects($this->exactly(1))->method('getId')->will($this->returnValue(5)); + $this->productLoaderMock + ->expects($this->any()) + ->method('load') + ->will($this->returnValueMap($valueMap)); + $this->collectionProviderMock + ->expects($this->once()) + ->method('getCollection') + ->with($productMock, 'product_type') + ->will($this->returnValue([10 => 1])); + $productMock->expects($this->never())->method('save'); + $this->service->remove('product_sku', 'linked_product_sku', 'product_type'); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/ProductTypeServiceTest.php b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/ProductTypeServiceTest.php new file mode 100644 index 0000000000000..7ce47be825566 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Catalog/Service/V1/ProductTypeServiceTest.php @@ -0,0 +1,92 @@ +typeConfigMock = $this->getMock('Magento\Catalog\Model\ProductTypes\ConfigInterface'); + $this->typeBuilderMock = $this->getMock( + 'Magento\Catalog\Service\V1\Data\ProductTypeBuilder', + array(), + array(), + '', + false + ); + $this->service = new ProductTypeService( + $this->typeConfigMock, + $this->typeBuilderMock + ); + } + + public function testGetProductTypes() + { + $simpleProductType = array( + 'name' => 'simple', + 'label' => 'Simple Product', + ); + $productTypeData = array( + 'simple' => $simpleProductType, + ); + $productTypeMock = $this->getMock( + 'Magento\Catalog\Service\V1\Data\ProductType', + array(), + array(), + '', + false + ); + $this->typeConfigMock->expects($this->any())->method('getAll')->will($this->returnValue($productTypeData)); + $this->typeBuilderMock->expects($this->once()) + ->method('setName') + ->with($simpleProductType['name']) + ->will($this->returnSelf()); + $this->typeBuilderMock->expects($this->once()) + ->method('setLabel') + ->with($simpleProductType['label']) + ->will($this->returnSelf()); + $this->typeBuilderMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($productTypeMock)); + + $productTypes = $this->service->getProductTypes(); + $this->assertCount(1, $productTypes); + $this->assertContains($productTypeMock, $productTypes); + } +} diff --git a/dev/tests/unit/testsuite/Magento/CatalogRule/Pricing/Price/CatalogRulePriceTest.php b/dev/tests/unit/testsuite/Magento/CatalogRule/Pricing/Price/CatalogRulePriceTest.php index ab93e29b48cfb..db097c1d1d55c 100644 --- a/dev/tests/unit/testsuite/Magento/CatalogRule/Pricing/Price/CatalogRulePriceTest.php +++ b/dev/tests/unit/testsuite/Magento/CatalogRule/Pricing/Price/CatalogRulePriceTest.php @@ -55,7 +55,7 @@ class CatalogRulePriceTest extends \PHPUnit_Framework_TestCase protected $customerSessionMock; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base | \PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php b/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php index 71043e2a78261..53f619bd3e200 100644 --- a/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php +++ b/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Model/Product/Type/ConfigurableTest.php @@ -35,6 +35,21 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase */ protected $_model; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_configurableAttributeFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_typeConfigurableFactory; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_attributeCollectionFactory; + /** * @var \Magento\TestFramework\Helper\ObjectManager */ @@ -52,9 +67,9 @@ protected function setUp() $coreRegistry = $this->getMock('Magento\Framework\Registry', array(), array(), '', false); $logger = $this->getMock('Magento\Framework\Logger', array(), array(), '', false); $productFactoryMock = $this->getMock('Magento\Catalog\Model\ProductFactory', array(), array(), '', false); - $confFactoryMock = $this->getMock( + $this->_typeConfigurableFactory = $this->getMock( 'Magento\ConfigurableProduct\Model\Resource\Product\Type\ConfigurableFactory', - array(), + ['create', 'saveProducts'], array(), '', false @@ -68,9 +83,9 @@ protected function setUp() '', false ); - $confAttrFactoryMock = $this->getMock( + $this->_configurableAttributeFactoryMock = $this->getMock( 'Magento\ConfigurableProduct\Model\Product\Type\Configurable\AttributeFactory', - array(), + array('create'), array(), '', false @@ -82,9 +97,9 @@ protected function setUp() '', false ); - $attrColFactory = $this->getMock( + $this->_attributeCollectionFactory = $this->getMock( 'Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Attribute\CollectionFactory', - array(), + array('create'), array(), '', false @@ -93,13 +108,13 @@ protected function setUp() 'Magento\ConfigurableProduct\Model\Product\Type\Configurable', array( 'productFactory' => $productFactoryMock, - 'typeConfigurableFactory' => $confFactoryMock, + 'typeConfigurableFactory' => $this->_typeConfigurableFactory, 'entityFactory' => $entityFactoryMock, 'attributeSetFactory' => $setFactoryMock, 'eavAttributeFactory' => $attributeFactoryMock, - 'configurableAttributeFactory' => $confAttrFactoryMock, + 'configurableAttributeFactory' => $this->_configurableAttributeFactoryMock, 'productCollectionFactory' => $productColFactory, - 'attributeCollectionFactory' => $attrColFactory, + 'attributeCollectionFactory' => $this->_attributeCollectionFactory, 'eventManager' => $eventManager, 'coreData' => $coreDataMock, 'fileStorageDb' => $fileStorageDbMock, @@ -114,4 +129,63 @@ public function testHasWeightTrue() { $this->assertTrue($this->_model->hasWeight(), 'This product has not weight, but it should'); } + + /** + * Test `Save` method + */ + public function testSave() + { + $attributeData = [1 => [ + 'id' => 1, + 'code' => 'someattr', + 'attribute_id' => 111, + 'position' => 0, + 'label' => 'Some Super Attribute', + 'values' => [] + ]]; + + $product = $this->getMockBuilder('\Magento\Catalog\Model\Product') + ->setMethods(['getIsDuplicate', 'dataHasChangedFor', 'getConfigurableAttributesData', 'getStoreId', + 'getId', 'getData', 'hasData', 'getAssociatedProductIds', '__wakeup', '__sleep' + ])->disableOriginalConstructor() + ->getMock(); + $product->expects($this->any())->method('dataHasChangedFor')->will($this->returnValue('false')); + $product->expects($this->any())->method('getConfigurableAttributesData') + ->will($this->returnValue($attributeData)); + $product->expects($this->once())->method('getIsDuplicate')->will($this->returnValue(true)); + $product->expects($this->any())->method('getStoreId')->will($this->returnValue(1)); + $product->expects($this->any())->method('getId')->will($this->returnValue(1)); + $product->expects($this->any())->method('getAssociatedProductIds')->will($this->returnValue([2])); + $product->expects($this->any())->method('hasData')->with('_cache_instance_used_product_attribute_ids') + ->will($this->returnValue(true)); + $product->expects($this->any())->method('getData')->with('_cache_instance_used_product_attribute_ids') + ->will($this->returnValue([1])); + + $attribute = $this->getMockBuilder('\Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute') + ->disableOriginalConstructor() + ->setMethods(['addData', 'setStoreId', 'setProductId', 'save', '__wakeup', '__sleep']) + ->getMock(); + $expectedAttributeData = $attributeData[1]; + unset($expectedAttributeData['id']); + $attribute->expects($this->once())->method('addData')->with($expectedAttributeData)->will($this->returnSelf()); + $attribute->expects($this->once())->method('setStoreId')->with(1)->will($this->returnSelf()); + $attribute->expects($this->once())->method('setProductId')->with(1)->will($this->returnSelf()); + $attribute->expects($this->once())->method('save')->will($this->returnSelf()); + + $this->_configurableAttributeFactoryMock->expects($this->any())->method('create') + ->will($this->returnValue($attribute)); + + $attributeCollection = $this->getMockBuilder( + '\Magento\ConfigurableProduct\Model\Resource\Product\Type\Configurable\Attribute\Collection' + )->setMethods(['setProductFilter', 'addFieldToFilter', 'walk'])->disableOriginalConstructor() + ->getMock(); + $this->_attributeCollectionFactory->expects($this->any())->method('create') + ->will($this->returnValue($attributeCollection)); + + $this->_typeConfigurableFactory->expects($this->once())->method('create')->will($this->returnSelf()); + $this->_typeConfigurableFactory->expects($this->once())->method('saveProducts')->withAnyParameters() + ->will($this->returnSelf()); + + $this->_model->save($product); + } } diff --git a/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Pricing/Price/AttributePriceTest.php b/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Pricing/Price/AttributePriceTest.php index ce0c9bc305a00..8e7f8fa222fb2 100644 --- a/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Pricing/Price/AttributePriceTest.php +++ b/dev/tests/unit/testsuite/Magento/ConfigurableProduct/Pricing/Price/AttributePriceTest.php @@ -50,7 +50,7 @@ class AttributePriceTest extends \PHPUnit_Framework_TestCase protected $calculatorMock; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/Core/Model/View/DesignTest.php b/dev/tests/unit/testsuite/Magento/Core/Model/View/DesignTest.php index 1f08bd9f014e9..df8df8bf3cb45 100644 --- a/dev/tests/unit/testsuite/Magento/Core/Model/View/DesignTest.php +++ b/dev/tests/unit/testsuite/Magento/Core/Model/View/DesignTest.php @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Core - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php b/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php new file mode 100644 index 0000000000000..53222f9505e0a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Renderer/Attribute/SendemailTest.php @@ -0,0 +1,83 @@ +contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context') + ->setMethods(['getStoreManager']) + ->disableOriginalConstructor() + ->getMock(); + $this->objectManagerHelper = new ObjectManagerHelper($this); + } + + public function testIsSingleStoreMode() + { + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', ['isSingleStoreMode'], [], '', false); + $storeManagerMock->expects($this->any()) + ->method('isSingleStoreMode') + ->will($this->returnValue(true)); + $this->contextMock->expects($this->any()) + ->method('getStoreManager') + ->will($this->returnValue($storeManagerMock)); + + $this->block = $this->objectManagerHelper->getObject( + 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail', + [ + 'context' => $this->contextMock + ] + ); + + $this->assertTrue($this->block->isSingleStoreMode()); + } + + public function testGetFormHtmlId() + { + $formMock = $this->getMock('Magento\Framework\Data\Form', ['getHtmlIdPrefix'], [], '', false); + $formMock->expects($this->once())->method('getHtmlIdPrefix')->will($this->returnValue('account_form')); + $this->block = $this->objectManagerHelper->getObject( + 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail', + [ + 'context' => $this->contextMock, + 'data' => ['form' => $formMock] + ] + ); + + $this->assertEquals('account_form', $this->block->getFormHtmlId()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php b/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php new file mode 100644 index 0000000000000..cd77186b769a4 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/AccountTest.php @@ -0,0 +1,234 @@ +objectManagerHelper = new ObjectManagerHelper($this); + $this->contextMock = $this->getMockBuilder('Magento\Backend\Block\Template\Context') + ->setMethods( + ['getBackendSession', 'getLayout', 'getStoreManager', 'getUrlBuilder'] + )->disableOriginalConstructor() + ->getMock(); + $this->registryMock = $this->getMock('Magento\Framework\Registry'); + $this->formFactoryMock = $this->getMock('Magento\Framework\Data\FormFactory', [], [], '', false); + $this->encoderInterfaceMock = $this->getMock('Magento\Framework\Json\EncoderInterface'); + $this->customerFormFactoryMock = $this->getMockBuilder('Magento\Customer\Model\Metadata\FormFactory') + ->disableOriginalConstructor() + ->getMock(); + $this->storeMock = $this->getMock('Magento\Store\Model\System\Store', [], [], '', false); + $this->customerHelperMock = $this->getMockBuilder('Magento\Customer\Helper\Data') + ->setMethods(['getNamePrefixOptions', 'getNameSuffixOptions']) + ->disableOriginalConstructor()->getMock(); + $this->customerAccountServiceInterfaceMock = $this->getMock( + 'Magento\Customer\Service\V1\CustomerAccountServiceInterface' + ); + $this->customerMetadataServiceInterfaceMock = $this->getMock( + 'Magento\Customer\Service\V1\CustomerMetadataServiceInterface' + ); + $this->customerBuilderMock = $this->getMockBuilder('Magento\Customer\Service\V1\Data\CustomerBuilder') + ->setMethods(['populateWithArray', 'create']) + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * @param $customerData + * @param $isSingleStoreMode + * @param $canModifyCustomer + */ + private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer) + { + $backendSessionMock = $this->getMock('\Magento\Backend\Model\Session', ['getCustomerData'], [], '', false); + $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([])); + + $layoutMock = $this->getMock('\Magento\Framework\View\Layout\Element\Layout', ['createBlock'], [], '', false); + $layoutMock->expects($this->at(0))->method('createBlock') + ->with('Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group') + ->will($this->returnValue( + $this->objectManagerHelper->getObject('\Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Group') + )); + $layoutMock->expects($this->at(1))->method('createBlock') + ->with('Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element') + ->will($this->returnValue( + $this->objectManagerHelper->getObject( + 'Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element' + ) + )); + if (empty($customerData['id'])) { + $layoutMock->expects($this->at(2))->method('createBlock') + ->with('Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail') + ->will($this->returnValue($this->objectManagerHelper->getObject( + 'Magento\Customer\Block\Adminhtml\Edit\Renderer\Attribute\Sendemail' + )) + ); + } + + $urlBuilderMock = $this->getMock('\Magento\Backend\Model\Url', ['getBaseUrl'], [], '', false); + $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl')); + + $storeManagerMock = $this->getMock('Magento\Store\Model\StoreManager', [], [], '', false); + $storeManagerMock->expects($this->any())->method('isSingleStoreMode') + ->will($this->returnValue($isSingleStoreMode)); + + $customerObject = $this->getMockBuilder('\Magento\Customer\Service\V1\Data\Customer') + ->setMethods(['__toArray', 'getId']) + ->disableOriginalConstructor() + ->getMock(); + $customerObject->expects($this->any())->method('__toArray')->will($this->returnValue($customerData)); + if (!empty($customerData['id'])) { + $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id'])); + } + + $fieldset = $this->getMockBuilder('\Magento\Framework\Data\Form\Element\Fieldset') + ->setMethods(['getForm', 'addField', 'removeField']) + ->disableOriginalConstructor() + ->getMock(); + $accountForm = $this->getMockBuilder('Magento\Framework\Data\Form') + ->setMethods(['create', 'addFieldset', 'getElement', 'setValues']) + ->disableOriginalConstructor() + ->getMock(); + + $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset') + ->will($this->returnValue($fieldset)); + $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm)); + $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm)); + $formElement = $this->getMockBuilder('\Magento\Framework\Data\Form\Element\Select') + ->setMethods(['setRenderer', 'addClass', 'setDisabled']) + ->disableOriginalConstructor()->getMock(); + + $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null)); + $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null)); + $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null)); + $accountForm->expects($this->any())->method('getElement')->withAnyParameters() + ->will($this->returnValue($formElement)); + + $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement)); + + $customerForm = $this->getMock('\Magento\Customer\Model\Metadata\Form', ['getAttributes'], [], '', false); + $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([])); + + $this->contextMock->expects($this->any())->method('getBackendSession') + ->will($this->returnValue($backendSessionMock)); + $this->contextMock->expects($this->any())->method('getLayout') + ->will($this->returnValue($layoutMock)); + $this->contextMock->expects($this->any())->method('getUrlBuilder') + ->will($this->returnValue($urlBuilderMock)); + $this->contextMock->expects($this->any())->method('getStoreManager') + ->will($this->returnValue($storeManagerMock)); + $this->customerBuilderMock->expects($this->any())->method('populateWithArray') + ->will($this->returnValue($this->customerBuilderMock)); + $this->customerBuilderMock->expects($this->any())->method('create') + ->will($this->returnValue($customerObject)); + $this->customerHelperMock->expects($this->any())->method('getNamePrefixOptions') + ->will($this->returnValue(['Pref1', 'Pref2'])); + $this->customerHelperMock->expects($this->any())->method('getNameSuffixOptions') + ->will($this->returnValue(['Suf1', 'Suf2'])); + $this->formFactoryMock->expects($this->any())->method('create') + ->will($this->returnValue($accountForm)); + $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer') + ->will($this->returnValue($customerForm)); + $this->customerAccountServiceInterfaceMock->expects($this->any())->method('canModify')->withAnyParameters() + ->will($this->returnValue($canModifyCustomer)); + $this->customerAccountServiceInterfaceMock->expects($this->any())->method('getConfirmationStatus') + ->withAnyParameters() + ->will($this->returnValue(CustomerAccountServiceInterface::ACCOUNT_CONFIRMED)); + } + + /** + * @dataProvider getInitFormData + */ + public function testInitForm($customerData, $isSingleStoreMode, $canModifyCustomer) + { + $this->_setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer); + $this->objectManagerHelper->getObject( + 'Magento\Customer\Block\Adminhtml\Edit\Tab\Account', + [ + 'context' => $this->contextMock, + 'registry' => $this->registryMock, + 'formFactory' => $this->formFactoryMock, + 'jsonEncoder' => $this->encoderInterfaceMock, + 'customerFormFactory' => $this->customerFormFactoryMock, + 'systemStore' => $this->storeMock, + 'customerHelper' => $this->customerHelperMock, + 'customerAccountService' => $this->customerAccountServiceInterfaceMock, + 'customerMetadataService' => $this->customerMetadataServiceInterfaceMock, + 'customerBuilder' => $this->customerBuilderMock + ] + )->initForm(); + } + + /** + * Data provider for method testInitForm + * @return array + */ + public function getInitFormData() + { + return array( + array([], true, true), + array(['id' => 1], true, true), + array([], false, false), + array(['id' => 1], false, false), + ); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Customer/Block/Widget/GenderTest.php b/dev/tests/unit/testsuite/Magento/Customer/Block/Widget/GenderTest.php index 8c3e22c239356..7e0535a694526 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Block/Widget/GenderTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Block/Widget/GenderTest.php @@ -173,10 +173,12 @@ public function testIsRequiredWithException() */ public function testGetCustomer() { - $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - /** @var $customerBuilder \Magento\Customer\Service\V1\Data\CustomerBuilder' */ - $customerBuilder = $objectManager->getObject('\Magento\Customer\Service\V1\Data\CustomerBuilder'); - $customerData = $customerBuilder->setFirstname('John')->setLastname('Doe')->create(); + $data = [ + 'firstname' => 'John', 'lastname' => 'Doe' + ]; + $builder = $this->getMock('\Magento\Customer\Service\V1\Data\CustomerBuilder', [], [], '', false); + $builder->expects($this->any())->method('getData')->will($this->returnValue($data)); + $customerData = new \Magento\Customer\Service\V1\Data\Customer($builder); $this->_customerSession->expects($this->once())->method('getCustomerId')->will($this->returnValue(1)); $this->_customerAccountService->expects( diff --git a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php index 17fa5328a81e4..cc50faf149738 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/IndexTest.php @@ -422,10 +422,16 @@ public function testResetPasswordActionSendEmail() $this->returnValue($customerId) ); - $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - /** @var $customerBuilder \Magento\Customer\Service\V1\Data\CustomerBuilder' */ - $customerBuilder = $objectManager->getObject('\Magento\Customer\Service\V1\Data\CustomerBuilder'); - $customer = $customerBuilder->setId($customerId)->setEmail($email)->setWebsiteId($websiteId)->create(); + + $customerBuilder = $this->getMock('\Magento\Customer\Service\V1\Data\CustomerBuilder', [], [], '', false); + $data = [ + 'id' => $customerId, + 'email' => $email, + 'website_id' => $websiteId + ]; + $customerBuilder->expects($this->once())->method('getData')->will($this->returnValue($data)); + + $customer = new \Magento\Customer\Service\V1\Data\Customer($customerBuilder); $this->_acctServiceMock->expects( $this->once() diff --git a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/MultiselectTest.php b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/MultiselectTest.php index 3eeb87e4086d8..fe2ae2f9c00e6 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/MultiselectTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/MultiselectTest.php @@ -204,6 +204,8 @@ public function outputValueJsonDataProvider() */ protected function runOutputValueTest($value, $expected, $format) { + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->attributeMetadataMock->expects( $this->any() )->method( @@ -211,8 +213,10 @@ protected function runOutputValueTest($value, $expected, $format) )->will( $this->returnValue( array( - (new OptionBuilder())->setValue('14')->setLabel('fourteen')->create(), - (new OptionBuilder())->setValue('some key')->setLabel('some string')->create() + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setValue('14')->setLabel('fourteen')->create(), + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setValue('some key')->setLabel('some string')->create() ) ) ); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/SelectTest.php b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/SelectTest.php index 141741e53238c..25b072d916a1a 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/SelectTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/SelectTest.php @@ -113,6 +113,7 @@ public function validateValueRequiredDataProvider() */ public function testOutputValue($value, $expected) { + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $this->attributeMetadataMock->expects( $this->any() )->method( @@ -120,9 +121,12 @@ public function testOutputValue($value, $expected) )->will( $this->returnValue( array( - (new OptionBuilder())->setValue('14')->setLabel('fourteen')->create(), - (new OptionBuilder())->setValue('some key')->setLabel('some string')->create(), - (new OptionBuilder())->setValue('true')->setLabel('True')->create() + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setValue('14')->setLabel('fourteen')->create(), + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setValue('some key')->setLabel('some string')->create(), + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setValue('true')->setLabel('True')->create() ) ) ); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/TextTest.php b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/TextTest.php index 5c3b8b85ae444..b1c90ff6c5c43 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/TextTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Model/Metadata/Form/TextTest.php @@ -124,12 +124,15 @@ public function validateValueRequiredDataProvider() */ public function testValidateValueLength($value, $expected) { + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $validationRules = array( 'min_text_length' => new ValidationRule( - (new ValidationRuleBuilder())->populateWithArray(array('name' => 'min_text_length', 'value' => 4)) + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder') + ->populateWithArray(array('name' => 'min_text_length', 'value' => 4)) ), 'max_text_length' => new ValidationRule( - (new ValidationRuleBuilder())->populateWithArray(array('name' => 'max_text_length', 'value' => 8)) + $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder') + ->populateWithArray(array('name' => 'max_text_length', 'value' => 8)) ) ); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php b/dev/tests/unit/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php index 194e2986bd28c..701739639b2f3 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Model/Resource/Group/Grid/ServiceCollectionTest.php @@ -52,7 +52,7 @@ class ServiceCollectionTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->filterBuilder = new \Magento\Framework\Service\V1\Data\FilterBuilder(); + $this->filterBuilder = $this->objectManager->getObject('\Magento\Framework\Service\V1\Data\FilterBuilder'); $filterGroupBuilder = $this->objectManager ->getObject('Magento\Framework\Service\V1\Data\Search\FilterGroupBuilder'); /** @var \Magento\Framework\Service\V1\Data\SearchCriteriaBuilder $searchBuilder */ @@ -62,7 +62,8 @@ public function setUp() ); $this->groupServiceMock = $this->getMockBuilder('\Magento\Customer\Service\V1\CustomerGroupServiceInterface') ->getMock(); - $this->searchResults = (new \Magento\Customer\Service\V1\Data\SearchResultsBuilder())->create(); + $this->searchResults = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\SearchResultsBuilder')->create(); $this->serviceCollection = $this->objectManager ->getObject( diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php index fa3934ef73b5f..7caf2cbc47538 100755 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAccountServiceTest.php @@ -1560,7 +1560,7 @@ public function testSearchCustomersEmpty() ); $customerService = $this->_createService(); - $filterBuilder = new FilterBuilder(); + $filterBuilder = $this->_objectManager->getObject('\Magento\Framework\Service\V1\Data\FilterBuilder'); $filter = $filterBuilder->setField('email')->setValue('customer@search.example.com')->create(); $this->_searchBuilder->addFilter([$filter]); @@ -1630,7 +1630,7 @@ public function testSearchCustomers() ); $customerService = $this->_createService(); - $filterBuilder = new FilterBuilder(); + $filterBuilder = $this->_objectManager->getObject('\Magento\Framework\Service\V1\Data\FilterBuilder'); $filter = $filterBuilder->setField('email')->setValue(self::EMAIL)->create(); $this->_searchBuilder->addFilter([$filter]); @@ -1963,7 +1963,8 @@ private function _createService() 'customerFactory' => $this->_customerFactoryMock, 'storeManager' => $this->_storeManagerMock, 'converter' => $this->_converter, - 'searchResultsBuilder' => new Data\SearchResultsBuilder, + 'searchResultsBuilder' => $this->_objectManager + ->getObject('\Magento\Customer\Service\V1\Data\SearchResultsBuilder'), 'customerBuilder' => $this->_customerBuilder, 'customerDetailsBuilder' => $this->_customerDetailsBuilder, 'customerAddressService' => $this->_customerAddressServiceMock, diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php index fd2485efb6ca3..ab041c6ab0b63 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerAddressServiceTest.php @@ -129,6 +129,11 @@ class CustomerAddressServiceTest extends \PHPUnit_Framework_TestCase */ private $_validator; + /** + * @var \Magento\TestFramework\Helper\ObjectManager + */ + protected $objectManagerHelper; + public function setUp() { $this->_customerFactoryMock = $this->getMockBuilder( @@ -227,8 +232,8 @@ public function setUp() '\Magento\Customer\Model\Metadata\Validator' )->disableOriginalConstructor()->getMock(); - $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $regionBuilder = $objectManagerHelper->getObject('Magento\Customer\Service\V1\Data\RegionBuilder'); + $this->objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + $regionBuilder = $this->objectManagerHelper->getObject('Magento\Customer\Service\V1\Data\RegionBuilder'); $metadataService = $this->getMockForAbstractClass( 'Magento\Customer\Service\V1\CustomerMetadataServiceInterface', @@ -253,12 +258,12 @@ public function setUp() $this->returnValue(array()) ); - $this->_addressBuilder = $objectManagerHelper->getObject( + $this->_addressBuilder = $this->objectManagerHelper->getObject( 'Magento\Customer\Service\V1\Data\AddressBuilder', array('regionBuilder' => $regionBuilder, 'metadataService' => $metadataService) ); - $customerBuilder = $objectManagerHelper->getObject( + $customerBuilder = $this->objectManagerHelper->getObject( 'Magento\Customer\Service\V1\Data\CustomerBuilder', ['metadataService' => $metadataService] ); @@ -483,12 +488,14 @@ public function testSaveAddresses() $customerService = $this->_createService(); + $this->_addressBuilder->setFirstname( 'John' )->setLastname( self::LASTNAME )->setRegion( - (new Data\RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( @@ -538,7 +545,8 @@ public function testSaveAddressesChanges() )->setLastname( self::LASTNAME )->setRegion( - (new RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( @@ -608,7 +616,8 @@ public function testSaveAddressesIdSetButNotAlreadyExisting() )->setLastname( self::LASTNAME )->setRegion( - (new Data\RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( @@ -651,7 +660,8 @@ public function testSaveAddressesCustomerIdNotExist() )->setLastname( self::LASTNAME )->setRegion( - (new RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( @@ -732,7 +742,8 @@ public function testSaveAddressesWithValidatorException() )->setLastname( self::LASTNAME )->setRegion( - (new Data\RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( @@ -772,7 +783,8 @@ public function testValidateAddressesValid() )->setLastname( self::LASTNAME )->setRegion( - (new Data\RegionBuilder())->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(self::REGION_ID)->setRegion(self::REGION)->create() )->setStreet( array(self::STREET) )->setTelephone( diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerMetadataServiceTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerMetadataServiceTest.php index 402b86858ee7e..f17609b64b959 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerMetadataServiceTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/CustomerMetadataServiceTest.php @@ -58,6 +58,11 @@ class CustomerMetadataServiceTest extends \PHPUnit_Framework_TestCase /** @var array */ private $_validateRules = array(); + /** + * @var \Magento\TestFramework\Helper\ObjectManager + */ + private $objectManager; + public function setUp() { $this->_eavConfigMock = $this->getMockBuilder( @@ -103,6 +108,8 @@ public function setUp() 'getFrontend' => $frontendMock ) ); + + $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); } public function testGetAttributeMetadata() @@ -138,12 +145,13 @@ public function testGetAttributeMetadata() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -177,12 +185,13 @@ public function testGetAttributeMetadataWithoutAttributeMetadata() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -232,12 +241,13 @@ public function testGetAttributeMetadataWithoutOptions() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -275,12 +285,13 @@ public function testGetAttributeMetadataWithoutSource() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -310,12 +321,13 @@ public function testGetCustomerAttributeMetadataWithoutAttributeMetadata() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -349,12 +361,13 @@ public function testGetAddressAttributeMetadataWithoutAttributeMetadata() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( @@ -397,12 +410,13 @@ public function testGetAllAttributeSetMetadataWithoutAttributeMetadata() '\Magento\Store\Model\StoreManager' )->disableOriginalConstructor()->getMock(); - $optionBuilder = new \Magento\Customer\Service\V1\Data\Eav\OptionBuilder(); - $validationRuleBuilder = new \Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder(); + $optionBuilder = $this->objectManager->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder'); + $validationRuleBuilder = $this->objectManager + ->getObject('\Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder'); - $attributeMetadataBuilder = new \Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder + $attributeMetadataBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] ); $service = new CustomerMetadataService( diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressConverterTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressConverterTest.php index e19e605ae9859..fcbabe9023404 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressConverterTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressConverterTest.php @@ -121,7 +121,7 @@ public function testToFlatArrayCustomAttributes() 'Magento\Customer\Service\V1\Data\AddressBuilder', [ 'valueBuilder' => $valueBuilder, - 'regionBuilder' => new RegionBuilder(), + 'regionBuilder' => $this->_objectManager->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder'), 'metadataService' => $this->_customerMetadataService ] ); @@ -136,7 +136,8 @@ public function testToFlatArrayCustomAttributes() */ protected function _sampleAddressDataObject() { - $regionBuilder = (new RegionBuilder())->setRegion('Texas')->setRegionId(1)->setRegionCode('TX'); + $regionBuilder = $this->_objectManager->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegion('Texas')->setRegionId(1)->setRegionCode('TX'); $valueBuilder = $this->_objectManager->getObject('Magento\Framework\Service\Data\Eav\AttributeValueBuilder'); /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressData */ $addressData = $this->_objectManager->getObject( diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressTest.php index 1ddfe1eb67daf..5caf847a8ed79 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/AddressTest.php @@ -104,8 +104,8 @@ class AddressTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $regionBuilder = $objectManagerHelper->getObject('Magento\Customer\Service\V1\Data\RegionBuilder'); + $this->objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + $regionBuilder = $this->objectManagerHelper->getObject('Magento\Customer\Service\V1\Data\RegionBuilder'); /** @var \Magento\Customer\Service\V1\CustomerMetadataService $customerMetadataService */ $this->_customerMetadataService = $this->getMockBuilder( 'Magento\Customer\Service\V1\CustomerMetadataService' @@ -124,9 +124,9 @@ protected function setUp() ) ) ); - $this->_valueBuilder = $objectManagerHelper + $this->_valueBuilder = $this->objectManagerHelper ->getObject('Magento\Framework\Service\Data\Eav\AttributeValueBuilder'); - $this->_addressBuilder = $objectManagerHelper->getObject( + $this->_addressBuilder = $this->objectManagerHelper->getObject( 'Magento\Customer\Service\V1\Data\AddressBuilder', [ 'valueBuilder' => $this->_valueBuilder, @@ -156,7 +156,8 @@ public function testCopyAndModify() 'getStreet' => $this->_expectedValues['street'], 'getCity' => $this->_expectedValues['city'], 'getCountryId' => $this->_expectedValues['country_id'], - 'getRegion' => (new RegionBuilder())->setRegionId(0)->setRegion('Texas')->create(), + 'getRegion' => $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionId(0)->setRegion('Texas')->create(), 'getPostcode' => $this->_expectedValues['postcode'], 'getTelephone' => $this->_expectedValues['telephone'] ) @@ -225,7 +226,7 @@ private function _fillMinimumRequiredFields(AddressBuilder $addressBuilder) $addressBuilder->setCity($this->_expectedValues['city']); $addressBuilder->setCountryId($this->_expectedValues['country_id']); $addressBuilder->setRegion( - (new RegionBuilder())->setRegionId( + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder')->setRegionId( $this->_expectedValues['region']['region_id'] )->setRegion( $this->_expectedValues['region']['region'] @@ -264,7 +265,7 @@ private function _assertMinimumRequiredFields(Address $address) $this->assertEquals($this->_expectedValues['city'], $address->getCity()); $this->assertEquals($this->_expectedValues['country_id'], $address->getCountryId()); $this->assertEquals( - (new RegionBuilder())->setRegionId( + $this->objectManagerHelper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder')->setRegionId( $this->_expectedValues['region']['region_id'] )->setRegion( $this->_expectedValues['region']['region'] diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerBuilderTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerBuilderTest.php index dcd27dadff0b1..a6ba8c2372586 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerBuilderTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerBuilderTest.php @@ -166,7 +166,7 @@ public function testPopulateException() 'Magento\Customer\Service\V1\Data\AddressBuilder', [ 'valueBuilder' => $this->_valueBuilder, - 'regionBuilder' => new RegionBuilder(), + 'regionBuilder' => $this->_objectManager->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder'), 'metadataService' => $this->_customerMetadataService ] )->create(); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerDetailsBuilderTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerDetailsBuilderTest.php index 8093aaf4df266..0b5c66166b5cd 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerDetailsBuilderTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/CustomerDetailsBuilderTest.php @@ -53,6 +53,11 @@ class CustomerDetailsBuilderTest extends \PHPUnit_Framework_TestCase */ protected $_addressMock; + /** + * @var \Magento\TestFramework\Helper\ObjectManager + */ + private $objectManager; + protected function setUp() { $this->_customerBuilderMock = $this->getMockBuilder( @@ -67,12 +72,17 @@ protected function setUp() $this->_addressMock = $this->getMockBuilder( '\Magento\Customer\Service\V1\Data\Address' )->disableOriginalConstructor()->getMock(); + + $this->objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); } public function testConstructor() { $this->_customerBuilderMock->expects($this->once())->method('create')->will($this->returnValue('customer')); - $customerDetailsBuilder = new CustomerDetailsBuilder($this->_customerBuilderMock, $this->_addressBuilderMock); + $customerDetailsBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\CustomerDetailsBuilder', + ['customerBuilder' => $this->_customerBuilderMock, 'addressBuilder' => $this->_addressBuilderMock] + ); $customerDetails = $customerDetailsBuilder->create(); $this->assertEquals('customer', $customerDetails->getCustomer()); $this->assertEquals(null, $customerDetails->getAddresses()); @@ -81,7 +91,10 @@ public function testConstructor() public function testSetCustomer() { $this->_customerBuilderMock->expects($this->never())->method('create')->will($this->returnValue('customer')); - $customerDetailsBuilder = new CustomerDetailsBuilder($this->_customerBuilderMock, $this->_addressBuilderMock); + $customerDetailsBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\CustomerDetailsBuilder', + ['customerBuilder' => $this->_customerBuilderMock, 'addressBuilder' => $this->_addressBuilderMock] + ); $customerDetails = $customerDetailsBuilder->setCustomer($this->_customerMock)->create(); $this->assertEquals($this->_customerMock, $customerDetails->getCustomer()); $this->assertEquals(null, $customerDetails->getAddresses()); @@ -90,7 +103,10 @@ public function testSetCustomer() public function testSetAddresses() { $this->_customerBuilderMock->expects($this->once())->method('create')->will($this->returnValue('customer')); - $customerDetailsBuilder = new CustomerDetailsBuilder($this->_customerBuilderMock, $this->_addressBuilderMock); + $customerDetailsBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\CustomerDetailsBuilder', + ['customerBuilder' => $this->_customerBuilderMock, 'addressBuilder' => $this->_addressBuilderMock] + ); $customerDetails = $customerDetailsBuilder->setAddresses( array($this->_addressMock, $this->_addressMock) )->create(); @@ -106,7 +122,6 @@ public function testSetAddresses() */ public function testPopulateWithArray($data, $expectedCustomerStr, $expectedAddressesStr) { - $expectedCustomer = $expectedCustomerStr == 'customerMock' ? $this->_customerMock : $expectedCustomerStr; $expectedAddresses = null; if (isset($expectedAddressesStr)) { @@ -145,7 +160,10 @@ public function testPopulateWithArray($data, $expectedCustomerStr, $expectedAddr $this->returnValue($this->_addressMock) ); - $customerDetailsBuilder = new CustomerDetailsBuilder($this->_customerBuilderMock, $this->_addressBuilderMock); + $customerDetailsBuilder = $this->objectManager->getObject( + '\Magento\Customer\Service\V1\Data\CustomerDetailsBuilder', + ['customerBuilder' => $this->_customerBuilderMock, 'addressBuilder' => $this->_addressBuilderMock] + ); $customerDetails = $customerDetailsBuilder->populateWithArray($data)->create(); $this->assertEquals($expectedCustomer, $customerDetails->getCustomer()); $this->assertEquals($expectedAddresses, $customerDetails->getAddresses()); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataTest.php index 44ea1b6fdf115..716325cba1e06 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/AttributeMetadataTest.php @@ -51,10 +51,10 @@ public function testConstructorAndGetters() 'Magento\Customer\Service\V1\Data\Eav\ValidationRuleBuilder' ); - $attributeMetadataBuilder = (new AttributeMetadataBuilder( - $optionBuilder, - $validationRuleBuilder - ))->populateWithArray( + $attributeMetadataBuilder = $objectManager->getObject( + '\Magento\Customer\Service\V1\Data\Eav\AttributeMetadataBuilder', + ['optionBuilder' => $optionBuilder, 'validationRuleBuilder' => $validationRuleBuilder] + )->populateWithArray( array( 'attribute_code' => self::ATTRIBUTE_CODE, 'frontend_input' => self::FRONTEND_INPUT, diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/OptionTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/OptionTest.php index 5f895fe827285..44dd81e8af8fb 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/OptionTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/Eav/OptionTest.php @@ -34,7 +34,9 @@ class OptionTest extends \PHPUnit_Framework_TestCase public function testConstructorAndGetters() { - $optionBuilder = (new OptionBuilder())->setLabel(self::LABEL)->setValue(self::VALUE); + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); + $optionBuilder = $helper->getObject('\Magento\Customer\Service\V1\Data\Eav\OptionBuilder') + ->setLabel(self::LABEL)->setValue(self::VALUE); $option = new Option($optionBuilder); $this->assertSame(self::LABEL, $option->getLabel()); $this->assertSame(self::VALUE, $option->getValue()); diff --git a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/RegionTest.php b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/RegionTest.php index 977d480c0e1b6..ccfeffd627cfd 100644 --- a/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/RegionTest.php +++ b/dev/tests/unit/testsuite/Magento/Customer/Service/V1/Data/RegionTest.php @@ -32,7 +32,10 @@ class RegionTest extends \PHPUnit_Framework_TestCase { public function testRegion() { - $region = new Region((new RegionBuilder())->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL')); + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); + $region = new Region($helper->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegion('Alabama')->setRegionId(1)->setRegionCode('AL') + ); $this->assertEquals(1, $region->getRegionId()); $this->assertEquals('AL', $region->getRegionCode()); diff --git a/dev/tests/unit/testsuite/Magento/Downloadable/Block/Catalog/Product/LinksTest.php b/dev/tests/unit/testsuite/Magento/Downloadable/Block/Catalog/Product/LinksTest.php index 5aee86121e173..345e4b87e8f9b 100644 --- a/dev/tests/unit/testsuite/Magento/Downloadable/Block/Catalog/Product/LinksTest.php +++ b/dev/tests/unit/testsuite/Magento/Downloadable/Block/Catalog/Product/LinksTest.php @@ -43,7 +43,7 @@ class LinksTest extends \PHPUnit_Framework_TestCase protected $productMock; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/Action/ActionTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/Action/ActionTest.php new file mode 100644 index 0000000000000..b9cc26b0518ac --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/App/Action/ActionTest.php @@ -0,0 +1,212 @@ + 'value']; + + protected function setUp() + { + $this->_eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface', [], [], '', false); + $this->_actionFlagMock = $this->getMock('Magento\Framework\App\ActionFlag', [], [], '', false); + $this->_redirectMock = $this->getMock('Magento\Framework\App\Response\RedirectInterface', [], [], '', false); + $this->_requestMock = $this->getMock( + 'Magento\Framework\App\RequestInterface', + [ + 'getFullActionName', + 'getRouteName', + 'isDispatched', + 'initForward', + 'setParams', + 'setControllerName', + 'setDispatched', + 'getModuleName', + 'setModuleName', + 'getActionName', + 'setActionName', + 'getParam' + ], + [], + '', + false + ); + $this->_responseMock = $this->getMock('Magento\Framework\App\ResponseInterface', [], [], '', false); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->action = $this->objectManagerHelper->getObject( + 'Magento\Framework\App\Action\ActionFake', + [ + 'request' => $this->_requestMock, + 'response' => $this->_responseMock, + 'eventManager' => $this->_eventManagerMock, + 'redirect' => $this->_redirectMock, + 'actionFlag' => $this->_actionFlagMock, + ] + ); + \Magento\Framework\Profiler::disable(); + } + + public function testDispatchPostDispatch() + { + $this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will( + $this->returnValue(self::FULL_ACTION_NAME) + ); + $this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will( + $this->returnValue(self::ROUTE_NAME) + ); + $expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock]; + $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with( + 'controller_action_predispatch', + $expectedEventParameters + ); + $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with( + 'controller_action_predispatch_' . self::ROUTE_NAME, + $expectedEventParameters + ); + $this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with( + 'controller_action_predispatch_' . self::FULL_ACTION_NAME, + $expectedEventParameters + ); + + $this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true)); + $this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will( + $this->returnValue(false) + ); + + $this->_requestMock->expects($this->once())->method('getActionName')->will( + $this->returnValue(self::ACTION_NAME) + ); + + // _forward expectations + $this->_requestMock->expects($this->once())->method('initForward'); + $this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams); + $this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME); + $this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME); + $this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME); + $this->_requestMock->expects($this->once())->method('setDispatched')->with(false); + + // _redirect expectations + $this->_redirectMock->expects($this->once())->method('redirect')->with( + $this->_responseMock, + self::FULL_ACTION_NAME, + self::$actionParams + ); + + $this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will( + $this->returnValue(false) + ); + + $this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with( + 'controller_action_postdispatch_' . self::FULL_ACTION_NAME, + $expectedEventParameters + ); + $this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with( + 'controller_action_postdispatch_' . self::ROUTE_NAME, + $expectedEventParameters + ); + $this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with( + 'controller_action_postdispatch', + $expectedEventParameters + ); + + $this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock)); + } +} + +class ActionFake extends Action +{ + /** + * Fake action to check a method call from a parent + */ + public function someactionAction() + { + $this->_forward( + ActionTest::ACTION_NAME, + ActionTest::CONTROLLER_NAME, + ActionTest::MODULE_NAME, + ActionTest::$actionParams); + $this->_redirect(ActionTest::FULL_ACTION_NAME, ActionTest::$actionParams); + return; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/Cache/TypeListTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/Cache/TypeListTest.php new file mode 100644 index 0000000000000..491fbcf55a439 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/App/Cache/TypeListTest.php @@ -0,0 +1,198 @@ +_typesArray = [ + self::TYPE_KEY => [ + 'label' => 'Type Label', + 'description' => 'Type Description' + ] + ]; + $this->_config = $this->getMock( + 'Magento\Framework\Cache\ConfigInterface', + ['getTypes', 'getType'], + [], + '', + false + ); + $this->_config->expects($this->any())->method('getTypes')->will($this->returnValue($this->_typesArray)); + + $cacheState = $this->getMock( + 'Magento\Framework\App\Cache\StateInterface', + ['isEnabled', 'setEnabled', 'persist'], + [], + '', + false + ); + $cacheState->expects($this->any())->method('isEnabled')->will($this->returnValue(self::IS_CACHE_ENABLED)); + $cacheBlockMock = $this->getMock(self::CACHE_TYPE, [], [], '', false); + $factory = $this->getMock('Magento\Framework\App\Cache\InstanceFactory', ['get'], [], '', false); + $factory->expects($this->any())->method('get')->with(self::CACHE_TYPE)->will( + $this->returnValue($cacheBlockMock) + ); + $this->_cache = $this->getMock( + 'Magento\Framework\App\CacheInterface', + ['load', 'getFrontend', 'save', 'remove', 'clean'], + [], + '', + false + ); + + $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->_typeList = $objectHelper->getObject( + 'Magento\Framework\App\Cache\TypeList', + [ + 'config' => $this->_config, + 'cacheState' => $cacheState, + 'factory' => $factory, + 'cache' => $this->_cache + ] + ); + } + + public function testGetTypes() + { + $expectation = [ + self::TYPE_KEY => $this->_getPreparedType() + ]; + $this->assertEquals($expectation, $this->_typeList->getTypes()); + } + + public function testGetInvalidated() + { + $expectation = [self::TYPE_KEY => $this->_getPreparedType()]; + $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will( + $this->returnValue(serialize($this->_typesArray)) + ); + $this->assertEquals($expectation, $this->_typeList->getInvalidated()); + } + + public function testInvalidate() + { + // there are no invalidated types + $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will( + $this->returnValue([]) + ); + $expectedInvalidated = [ + self::TYPE_KEY => 1 + ]; + $this->_cache->expects($this->once())->method('save')->with( + serialize($expectedInvalidated), + TypeList::INVALIDATED_TYPES + ); + $this->_typeList->invalidate(self::TYPE_KEY); + } + + public function testInvalidateList() + { + $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will( + $this->returnValue([]) + ); + $expectedInvalidated = [ + self::TYPE_KEY => 1 + ]; + $this->_cache->expects($this->once())->method('save')->with( + serialize($expectedInvalidated), + TypeList::INVALIDATED_TYPES + ); + $this->_typeList->invalidate([self::TYPE_KEY]); + } + + public function testCleanType() + { + $this->_cache->expects($this->once())->method('load')->with(TypeList::INVALIDATED_TYPES)->will( + $this->returnValue(serialize($this->_typesArray)) + ); + $this->_config->expects($this->once())->method('getType')->with(self::TYPE_KEY)->will( + $this->returnValue(['instance' => self::CACHE_TYPE]) + ); + unset($this->_typesArray[self::TYPE_KEY]); + $this->_cache->expects($this->once())->method('save')->with( + serialize($this->_typesArray), + TypeList::INVALIDATED_TYPES + ); + $this->_typeList->cleanType(self::TYPE_KEY); + } + + /** + * Returns prepared type + * + * @return \Magento\Framework\Object + */ + private function _getPreparedType() + { + return new \Magento\Framework\Object( + [ + 'id' => self::TYPE_KEY, + 'cache_type' => $this->_typesArray[self::TYPE_KEY]['label'], + 'description' => $this->_typesArray[self::TYPE_KEY]['description'], + 'tags' => '', + 'status' => self::IS_CACHE_ENABLED + ] + ); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/App/Config/Initial/ReaderTest.php b/dev/tests/unit/testsuite/Magento/Framework/App/Config/Initial/ReaderTest.php index d9d0df301e93b..50752518f7715 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/App/Config/Initial/ReaderTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/App/Config/Initial/ReaderTest.php @@ -92,17 +92,6 @@ public function testReadNoFiles() $this->at(0) )->method( 'get' - )->with( - 'config.xml', - 'primary' - )->will( - $this->returnValue(array()) - ); - - $this->_fileResolverMock->expects( - $this->at(1) - )->method( - 'get' )->with( 'config.xml', 'global' @@ -128,17 +117,6 @@ public function testReadValidConfig() $this->at(0) )->method( 'get' - )->with( - 'config.xml', - 'primary' - )->will( - $this->returnValue(array()) - ); - - $this->_fileResolverMock->expects( - $this->at(1) - )->method( - 'get' )->with( 'config.xml', 'global' diff --git a/dev/tests/unit/testsuite/Magento/Framework/ArchiveTest.php b/dev/tests/unit/testsuite/Magento/Framework/ArchiveTest.php new file mode 100644 index 0000000000000..b45838ec36160 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/ArchiveTest.php @@ -0,0 +1,219 @@ +archive = new Archive(); + $this->sourceFilePath = __DIR__ . '/_files/Archive/source.txt'; + $this->destinationDir = __DIR__ . '/_files/Archive/archives/'; + } + + protected function tearDown() + { + if (!empty($this->packed) && file_exists($this->packed)) { + unlink($this->packed); + $this->packed = null; + } + if (!empty($this->unpacked) && file_exists($this->unpacked)) { + unlink($this->unpacked); + $this->unpacked = null; + } + } + + /** + * @dataProvider isArchiveProvider + * @param string $file + * @param bool $isArchive + */ + public function testIsArchive($file, $isArchive) + { + $this->assertEquals($isArchive, $this->archive->isArchive($file)); + } + + public function isArchiveProvider() + { + return [ + ['archive.tar', true], + ['archive.gz', true], + ['archive.gzip', true], + ['archive.tgz', true], + ['archive.tgzip', true], + ['archive.bz', true], + ['archive.bzip', true], + ['archive.bzip2', true], + ['archive.bz2', true], + ['archive.tbz', true], + ['archive.tbzip', true], + ['archive.tbz2', true], + ['archive.tbzip2', true], + ['archive.txt', false], + ['archive.php', false], + ['archive.phtml', false], + ['archive.js', false], + ['archive.log', false], + ]; + } + + /** + * @dataProvider isTarProvider + * @param string $file + * @param bool $isArchive + */ + public function testIsTar($file, $isArchive) + { + $this->assertEquals($isArchive, $this->archive->isTar($file)); + } + + public function isTarProvider() + { + return [ + ['archive.tar', true], + ['archive.gz', false], + ['archive.gzip', false], + ['archive.tgz', false], + ['archive.tgzip', false], + ['archive.bz', false], + ['archive.bzip', false], + ['archive.bzip2', false], + ['archive.bz2', false], + ['archive.tbz', false], + ['archive.tbzip', false], + ['archive.tbz2', false], + ['archive.tbzip2', false], + ['archive.txt', false], + ['archive.php', false], + ['archive.phtml', false], + ['archive.js', false], + ['archive.log', false], + ]; + } + + /** + * @dataProvider destinationProvider + * @param string $destinationFile + */ + public function testPackUnpackGzBz($destinationFile) + { + $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile); + + $this->assertFileExists($this->packed); + $this->assertEquals($this->destinationDir . $destinationFile, $this->packed); + + $this->unpacked = $this->archive->unpack($this->packed, $this->destinationDir); + + $this->assertFileExists($this->unpacked); + $this->assertStringStartsWith($this->destinationDir, $this->unpacked); + } + + public function destinationProvider() + { + return [ + ['archive.gz', false], + ['archive.gzip', false], + ['archive.bz', false], + ['archive.bzip', false], + ['archive.bzip2', false], + ['archive.bz2', false] + ]; + } + + /** + * @dataProvider tarProvider + * @param string $destinationFile + */ + public function testPackUnpackTar($destinationFile) + { + $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile); + + $this->assertFileExists($this->packed); + $this->assertEquals($this->destinationDir . $destinationFile, $this->packed); + + $unpacked = $this->archive->unpack($this->packed, $this->destinationDir); + + $this->unpacked = $unpacked . pathinfo($this->sourceFilePath, PATHINFO_BASENAME); + + $this->assertFileExists($this->unpacked); + $this->assertStringStartsWith($this->destinationDir, $this->unpacked); + } + + /** + * @dataProvider tarProvider + * @param string $destinationFile + */ + public function testExtract($destinationFile) + { + $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile); + + $this->assertFileExists($this->packed); + $this->assertEquals($this->destinationDir . $destinationFile, $this->packed); + + $filename = pathinfo($this->sourceFilePath, PATHINFO_BASENAME); + $this->unpacked = $this->archive->extract($filename, $this->packed, $this->destinationDir); + + $this->assertFileExists($this->unpacked); + $this->assertStringStartsWith($this->destinationDir, $this->unpacked); + } + + public function tarProvider() + { + return [ + ['archive.tar', true], + ['archive.tgz', false], + ['archive.tgzip', false], + ['archive.tbz', false], + ['archive.tbzip', false], + ['archive.tbz2', false], + ['archive.tbzip2', false] + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Backup/MediaTest.php b/dev/tests/unit/testsuite/Magento/Framework/Backup/MediaTest.php index a9cc92909c773..442cc1e875da5 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Backup/MediaTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Backup/MediaTest.php @@ -23,8 +23,6 @@ */ namespace Magento\Framework\Backup; -require_once __DIR__ . '/_files/Gz.php'; -require_once __DIR__ . '/_files/Tar.php'; require_once __DIR__ . '/_files/Fs.php'; require_once __DIR__ . '/_files/Helper.php'; require_once __DIR__ . '/_files/io.php'; @@ -90,18 +88,26 @@ public function testAction($action) $model = new \Magento\Framework\Backup\Media($this->_filesystemMock, $this->_backupFactoryMock); $model->setRootDir($rootDir); + $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); $this->assertTrue($model->{$action}()); - $paths = $model->getIgnorePaths(); - $path1 = str_replace('\\', '/', $paths[0]); - $path2 = str_replace('\\', '/', $paths[1]); + $ignorePaths = $model->getIgnorePaths(); + $rootDir = str_replace('\\', '/', $rootDir); - $this->assertEquals($rootDir . '/code', $path1); - $this->assertEquals($rootDir . '/var/log', $path2); + foreach ($ignorePaths as &$path) { + if (strpos($path, '~tmp-') || strpos($path, '_media')) { + unlink($path); + } + $path = str_replace('\\', '/', $path); + } + + $this->assertTrue(in_array($rootDir, $ignorePaths)); + $this->assertTrue(in_array($rootDir . '/code', $ignorePaths)); + $this->assertTrue(in_array($rootDir . '/var/log', $ignorePaths)); } /** diff --git a/dev/tests/unit/testsuite/Magento/Framework/Backup/NomediaTest.php b/dev/tests/unit/testsuite/Magento/Framework/Backup/NomediaTest.php index 1525d0ca2e001..6ba27c2e09ddd 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Backup/NomediaTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Backup/NomediaTest.php @@ -23,8 +23,6 @@ */ namespace Magento\Framework\Backup; -require_once __DIR__ . '/_files/Gz.php'; -require_once __DIR__ . '/_files/Tar.php'; require_once __DIR__ . '/_files/Fs.php'; require_once __DIR__ . '/_files/Helper.php'; require_once __DIR__ . '/_files/io.php'; @@ -90,10 +88,11 @@ public function testAction($action) $model = new \Magento\Framework\Backup\Nomedia($this->_filesystemMock, $this->_backupFactoryMock); $model->setRootDir($rootDir); + $model->setBackupsDir($rootDir); $model->{$action}(); $this->assertTrue($model->getIsSuccess()); - $this->assertEquals(array($rootDir . '/media', $rootDir . '/pub/media'), $model->getIgnorePaths()); + $this->assertEquals(array($rootDir, $rootDir . '/media', $rootDir . '/pub/media'), $model->getIgnorePaths()); } /** diff --git a/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/data/.gitignore b/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/data/.gitignore new file mode 100644 index 0000000000000..22e83649f7d52 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/Backup/_files/data/.gitignore @@ -0,0 +1 @@ +/* \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Magento/Framework/Code/ValidatorTest.php b/dev/tests/unit/testsuite/Magento/Framework/Code/ValidatorTest.php index e283eb92a783c..78fecfe607a03 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Code/ValidatorTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Code/ValidatorTest.php @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Code - * @subpackage unit_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/dev/tests/unit/testsuite/Magento/Framework/DB/Adapter/Pdo/MysqlTest.php b/dev/tests/unit/testsuite/Magento/Framework/DB/Adapter/Pdo/MysqlTest.php index fd8544aaec17c..2294b08e31a4c 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/DB/Adapter/Pdo/MysqlTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/DB/Adapter/Pdo/MysqlTest.php @@ -67,7 +67,16 @@ protected function setUp() $this->_adapter = $this->getMock( 'Magento\Framework\DB\Adapter\Pdo\Mysql', - array('_connect', '_beginTransaction', '_commit', '_rollBack', 'query', '_debugWriteToFile', 'fetchRow'), + array( + 'getCreateTable', + '_connect', + '_beginTransaction', + '_commit', + '_rollBack', + 'query', + '_debugWriteToFile', + 'fetchRow' + ), array( 'dbname' => 'not_exists', 'username' => 'not_valid', @@ -529,4 +538,88 @@ public function addColumnDataProvider() ) ); } + + /** + * @dataProvider getForeignKeysProvider + * @param string $tableName + * @param string $schemaName + * @param string $constraint + * @param array $expected + */ + public function testGetForeignKeys($tableName, $schemaName, $constraint, $expected) + { + $constraint = ",\n" . $constraint; + $this->_adapter->expects($this->once()) + ->method('getCreateTable') + ->will($this->returnValue($constraint)); + $this->assertEquals($expected, $this->_adapter->getForeignKeys($tableName, $schemaName)); + } + + public function getForeignKeysProvider() + { + return [ + [ + 'table1', + 'schema1', + 'CONSTRAINT `FK_SALES_FLAT_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID` FOREIGN KEY ' + . '(`customer_id`) REFERENCES `customer_entity` (`entity_id`) ON DELETE SET NULL ON UPDATE CASCADE', + [ + 'FK_SALES_FLAT_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID' => [ + 'FK_NAME' => 'FK_SALES_FLAT_ORDER_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID', + 'SCHEMA_NAME' => 'schema1', + 'TABLE_NAME' => 'table1', + 'COLUMN_NAME' => 'customer_id', + 'REF_SHEMA_NAME' => '', + 'REF_TABLE_NAME' => 'customer_entity', + 'REF_COLUMN_NAME' => 'entity_id', + 'ON_DELETE' => 'SET NULL', + 'ON_UPDATE' => 'CASCADE' + ] + ] + ], + [ + 'table1', + 'schema1', + 'CONSTRAINT `FK_SALES_FLAT_ORDER_STORE_ID_STORE_STORE_ID` FOREIGN KEY (`store_id`) ' + . 'REFERENCES `store` (`store_id`) ON DELETE SET NULL ON UPDATE CASCADE', + [ + 'FK_SALES_FLAT_ORDER_STORE_ID_STORE_STORE_ID' => [ + 'FK_NAME' => 'FK_SALES_FLAT_ORDER_STORE_ID_STORE_STORE_ID', + 'SCHEMA_NAME' => 'schema1', + 'TABLE_NAME' => 'table1', + 'COLUMN_NAME' => 'store_id', + 'REF_SHEMA_NAME' => '', + 'REF_TABLE_NAME' => 'store', + 'REF_COLUMN_NAME' => 'store_id', + 'ON_DELETE' => 'SET NULL', + 'ON_UPDATE' => 'CASCADE' + ] + ] + ], + [ + 'table1', + 'schema1', + '`entity_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT \'Entity Id\'', + [] + ], + [ + 'table1', + 'schema1', + 'CONSTRAINT `refdata_ibfk_1` FOREIGN KEY (`refcol`) REFERENCES `test_ref`.`usefuldata` (`col`)', + [ + 'REFDATA_IBFK_1' => [ + 'FK_NAME' => 'refdata_ibfk_1', + 'SCHEMA_NAME' => 'schema1', + 'TABLE_NAME' => 'table1', + 'COLUMN_NAME' => 'refcol', + 'REF_SHEMA_NAME' => 'test_ref', + 'REF_TABLE_NAME' => 'usefuldata', + 'REF_COLUMN_NAME' => 'col', + 'ON_DELETE' => '', + 'ON_UPDATE' => '' + ] + ] + ], + ]; + } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/EscaperTest.php b/dev/tests/unit/testsuite/Magento/Framework/EscaperTest.php index e5ceeb33edb50..ae928e68db32b 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/EscaperTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/EscaperTest.php @@ -42,9 +42,9 @@ protected function setUp() * @covers \Magento\Framework\Escaper::escapeHtml * @dataProvider escapeHtmlDataProvider */ - public function testEscapeHtml($data, $expected) + public function testEscapeHtml($data, $expected, $allowedTags = null) { - $actual = $this->_escaper->escapeHtml($data); + $actual = $this->_escaper->escapeHtml($data, $allowedTags); $this->assertEquals($expected, $actual); } @@ -53,17 +53,24 @@ public function testEscapeHtml($data, $expected) */ public function escapeHtmlDataProvider() { - return array( - 'array data' => array( - 'data' => array('one', 'three'), - 'expected' => array('one', '<two>three</two>') - ), - 'string data conversion' => array( + return [ + 'array data' => [ + 'data' => ['one', 'three'], + 'expected' => ['one', '<two>three</two>'], + null + ], + 'string data conversion' => [ 'data' => 'three', - 'expected' => '<two>three</two>' - ), - 'string data no conversion' => array('data' => 'one', 'expected' => 'one') - ); + 'expected' => '<two>three</two>', + null + ], + 'string data no conversion' => ['data' => 'one', 'expected' => 'one'], + 'string data with allowed tags' => [ + 'data' => 'some text in tags', + 'expected' => 'some text in tags', + 'allowedTags' => ['span', 'b'] + ] + ]; } /** @@ -82,8 +89,8 @@ public function testEscapeUrl() */ public function testEscapeJsQuote() { - $data = array("Don't do that.", 'lost_key' => "Can't do that."); - $expected = array("Don\\'t do that.", "Can\\'t do that."); + $data = ["Don't do that.", 'lost_key' => "Can't do that."]; + $expected = ["Don\\'t do that.", "Can\\'t do that."]; $this->assertEquals($expected, $this->_escaper->escapeJsQuote($data)); $this->assertEquals($expected[0], $this->_escaper->escapeJsQuote($data[0])); } @@ -94,10 +101,10 @@ public function testEscapeJsQuote() public function testEscapeQuote() { $data = "Text with 'single' and \"double\" quotes"; - $expected = array( + $expected = [ "Text with 'single' and "double" quotes", "Text with \\'single\\' and \\"double\\" quotes" - ); + ]; $this->assertEquals($expected[0], $this->_escaper->escapeQuote($data)); $this->assertEquals($expected[1], $this->_escaper->escapeQuote($data, true)); } diff --git a/dev/tests/unit/testsuite/Magento/Framework/EventTest.php b/dev/tests/unit/testsuite/Magento/Framework/EventTest.php new file mode 100644 index 0000000000000..b58facf4211e3 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/EventTest.php @@ -0,0 +1,114 @@ + 'ObserverName', + 'block' => 'testBlockName' + ]; + $this->event = new Event($data); + $this->observers = new Collection(); + $this->observer = new Observer($data); + $this->observers->addObserver($this->observer); + } + + protected function tearDown() + { + unset($this->event); + } + + public function testGetObservers() + { + $this->event->addObserver($this->observer); + $expected = $this->observers; + $result = $this->event->getObservers(); + $this->assertEquals($expected, $result); + } + + public function testAddObservers() + { + $data = ['name' => 'Add New Observer']; + $observer = new Observer($data); + $this->event->addObserver($observer); + $actual = $this->event->getObservers()->getObserverByName($data['name']); + $this->assertSame($observer, $actual); + } + + public function testRemoveObserverByName() + { + $data = [ + 'name' => 'ObserverName', + ]; + $this->event->addObserver($this->observer); + $expected = 'Magento\Framework\Event\Observer\Collection'; + $actual = $this->event->getObservers()->removeObserverByName($data['name']); + $this->assertInstanceOf($expected, $actual); + } + + public function testDispatch() + { + $this->assertInstanceOf('Magento\Framework\Event', $this->event->dispatch()); + } + + public function testGetName() + { + $data = 'ObserverName'; + $this->assertEquals($data, $this->event->getName()); + $this->event = new Event(); + $this->assertNull($this->event->getName()); + } + + public function testGetBlock() + { + $block = 'testBlockName'; + $this->assertEquals($block, $this->event->getBlock()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/FlagTest.php b/dev/tests/unit/testsuite/Magento/Framework/FlagTest.php new file mode 100644 index 0000000000000..b05138a5148d6 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/FlagTest.php @@ -0,0 +1,153 @@ + 'synchronize']; + $this->createInstance($data); + } + + protected function createInstance(array $data = []) + { + $eventManager = $this->getMock('Magento\Framework\Event\Manager', ['dispatch'], [], '', false, false); + $context = $this->getMock('Magento\Framework\Model\Context', [], [], '', false, false); + $context->expects($this->once()) + ->method('getEventDispatcher') + ->will($this->returnValue($eventManager)); + $registry = $this->getMock('Magento\Framework\Registry', [], [], '', false, false); + + $adapter = $this->getMock('Magento\Framework\DB\Adapter\Adapter', ['beginTransaction'], [], '', false, false); + $adapter->expects($this->any()) + ->method('beginTransaction') + ->will($this->returnSelf()); + $appResource = $this->getMock( + 'Magento\Framework\App\Resource', + ['beginTransaction', 'getConnection'], + [], + '', + false, + false + ); + $appResource->expects($this->any()) + ->method('getConnection') + ->will($this->returnValue($adapter)); + + $resource = $this->getMockBuilder('Magento\Framework\Flag\Resource') + ->setMethods(['__wakeup', 'load', 'save', 'addCommitCallback', 'commit', 'rollBack']) + ->setConstructorArgs(['resource' => $appResource]) + ->getMockForAbstractClass(); + $resource->expects($this->any()) + ->method('addCommitCallback') + ->will($this->returnSelf()); + + $resourceCollection = $this->getMock('Magento\Framework\Data\Collection\Db', [], [], '', false, false); + + + $this->flag = new \Magento\Framework\Flag( + $context, + $registry, + $resource, + $resourceCollection, + $data + ); + } + + public function tearDown() + { + unset($this->flag); + } + + public function testConstruct() + { + $flagCode = 'synchronize'; + $this->createInstance(); + $this->flag->setFlagCode('synchronize'); + $this->assertEquals($flagCode, $this->flag->getFlagCode()); + } + + public function testGetFlagData() + { + $result = $this->flag->getFlagData(); + $this->assertNull($result); + $flagData = serialize('data'); + $this->flag->setData('flag_data', $flagData); + $result = $this->flag->getFlagData(); + $this->assertEquals(unserialize($flagData), $result); + } + + public function testSetFlagData() + { + $flagData = 'data'; + $this->flag->setFlagData($flagData); + $result = unserialize($this->flag->getData('flag_data')); + $this->assertEquals($flagData, $result); + } + + public function testLoadSelf() + { + $this->assertInstanceOf('Magento\Framework\Flag', $this->flag->loadSelf()); + } + + /** + * @expectedException \Magento\Framework\Model\Exception + * @expectedExceptionMessage Please define flag code. + */ + public function testLoadSelfException() + { + $this->createInstance(); + $this->flag->loadSelf(); + } + + public function testBeforeSave() + { + $this->flag->setData('block', 'blockNmae'); + $result = $this->flag->save(); + $this->assertSame($this->flag, $result); + $this->assertEquals('synchronize', $this->flag->getFlagCode()); + } + + /** + * @expectedException \Magento\Framework\Model\Exception + * @expectedExceptionMessage Please define flag code. + */ + public function testBeforeSaveException() + { + $this->createInstance(); + $this->flag->setData('block', 'blockNmae'); + $this->flag->save(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Less/PreProcessor/Instruction/ImportTest.php b/dev/tests/unit/testsuite/Magento/Framework/Less/PreProcessor/Instruction/ImportTest.php index be53920108c6f..0b26541517859 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Less/PreProcessor/Instruction/ImportTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Less/PreProcessor/Instruction/ImportTest.php @@ -124,7 +124,7 @@ public function testProcessNoImport() } /** - * @covers resetRelatedFiles + * @covers \Magento\Framework\Less\PreProcessor\Instruction\Import::resetRelatedFiles */ public function testGetRelatedFiles() { diff --git a/dev/tests/unit/testsuite/Magento/Framework/LoggerTest.php b/dev/tests/unit/testsuite/Magento/Framework/LoggerTest.php index ec47ad4793690..76509bb84a0ed 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/LoggerTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/LoggerTest.php @@ -30,39 +30,34 @@ class LoggerTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\Framework\Logger|\PHPUnit_Framework_MockObject_MockObject */ - protected $_model = null; + protected $model = null; /** * @var \ReflectionProperty */ - protected $_loggersProperty = null; + protected $loggersProperty = null; /** * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $_filesystemMock; + protected $filesystemMock; /** * @var Write | \PHPUnit_Framework_MockObject_MockObject */ - protected $_directory; + protected $directory; protected function setUp() { $logDir = TESTS_TEMP_DIR . '/var/log'; - $this->_filesystemMock = $this->getMock('Magento\Framework\App\Filesystem', array(), array(), '', false); - $this->_directory = $this->getMock('Magento\Framework\Filesystem\Directory\Write', array(), array(), '', false); - $this->_filesystemMock->expects( - $this->any() - )->method( - 'getDirectoryWrite' - )->with( - \Magento\Framework\App\Filesystem::LOG_DIR - )->will( - $this->returnValue($this->_directory) - ); - $this->_directory->expects($this->any())->method('create')->will($this->returnValue(true)); - $this->_directory->expects($this->any())->method('getAbsolutePath')->will( + $this->filesystemMock = $this->getMock('Magento\Framework\App\Filesystem', [], [], '', false); + $this->directory = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); + $this->filesystemMock->expects($this->any()) + ->method('getDirectoryWrite') + ->with(\Magento\Framework\App\Filesystem::LOG_DIR) + ->will($this->returnValue($this->directory)); + $this->directory->expects($this->any())->method('create')->will($this->returnValue(true)); + $this->directory->expects($this->any())->method('getAbsolutePath')->will( $this->returnCallback( function ($path) use ($logDir) { $path = ltrim($path, '\/'); @@ -75,9 +70,9 @@ function ($path) use ($logDir) { mkdir($logDir, 0777, true); } - $this->_model = new \Magento\Framework\Logger($this->_filesystemMock); - $this->_loggersProperty = new \ReflectionProperty($this->_model, '_loggers'); - $this->_loggersProperty->setAccessible(true); + $this->model = new \Magento\Framework\Logger($this->filesystemMock); + $this->loggersProperty = new \ReflectionProperty($this->model, '_loggers'); + $this->loggersProperty->setAccessible(true); } /** @@ -87,11 +82,11 @@ function ($path) use ($logDir) { */ public function testAddStreamLog($key, $fileOrWrapper) { - $this->assertFalse($this->_model->hasLog($key)); - $this->_model->addStreamLog($key, $fileOrWrapper); - $this->assertTrue($this->_model->hasLog($key)); + $this->assertFalse($this->model->hasLog($key)); + $this->model->addStreamLog($key, $fileOrWrapper); + $this->assertTrue($this->model->hasLog($key)); - $loggers = $this->_loggersProperty->getValue($this->_model); + $loggers = $this->loggersProperty->getValue($this->model); $this->assertArrayHasKey($key, $loggers); $zendLog = $loggers[$key]; $this->assertInstanceOf('Zend_Log', $zendLog); @@ -115,7 +110,7 @@ public function testAddStreamLog($key, $fileOrWrapper) */ public function addStreamLogDataProvider() { - return array(array('test', 'php://output'), array('test', 'custom_file.log'), array('test', '')); + return [['test', 'php://output'], ['test', 'custom_file.log'], ['test', '']]; } /** @@ -124,8 +119,8 @@ public function addStreamLogDataProvider() public function testAddLogWithSpecificKey() { $key = uniqid(); - $this->_model->addStreamLog($key); - $this->assertTrue($this->_model->hasLog($key)); + $this->model->addStreamLog($key); + $this->assertTrue($this->model->hasLog($key)); } public function testLog() @@ -136,33 +131,39 @@ public function testLog() $this->expectOutputRegex( '/' . 'DEBUG \(7\).+?' . $messageTwo . '.+?' . 'CRIT \(2\).+?' . $messageThree . '/s' ); - $this->_model->addStreamLog('test', 'php://output'); - $this->_model->log($messageOne); - $this->_model->log($messageTwo, \Zend_Log::DEBUG, 'test'); - $this->_model->log($messageThree, \Zend_Log::CRIT, 'test'); + $this->model->addStreamLog('test', 'php://output'); + $this->model->log($messageOne); + $this->model->log($messageTwo, \Zend_Log::DEBUG, 'test'); + $this->model->log($messageThree, \Zend_Log::CRIT, 'test'); } public function testLogComplex() { $this->expectOutputRegex('/Array\s\(\s+\[0\] => 1\s\).+stdClass Object/s'); - $this->_model->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM, 'php://output'); - $this->_model->log(array(1)); - $this->_model->log(new \StdClass()); + $this->model->addStreamLog(\Magento\Framework\Logger::LOGGER_SYSTEM, 'php://output'); + $this->model->log([1]); + $this->model->log(new \StdClass()); + $this->model->log('key'); + } + + public function testLogNoKey() + { + $key = 'key'; + $this->model->log($key); + $this->assertFalse($this->model->hasLog($key)); } public function testLogDebug() { $message = uniqid(); /** @var $model \Magento\Framework\Logger|\PHPUnit_Framework_MockObject_MockObject */ - $model = $this->getMock('Magento\Framework\Logger', array('log'), array(), '', false); + $model = $this->getMock('Magento\Framework\Logger', ['log'], [], '', false); $model->expects($this->at(0)) ->method('log') ->with($message, \Zend_Log::DEBUG, \Magento\Framework\Logger::LOGGER_SYSTEM); - $model->expects( - $this->at(1) - )->method( - 'log' - )->with( + $model->expects($this->at(1)) + ->method('log') + ->with( $message, \Zend_Log::DEBUG, \Magento\Framework\Logger::LOGGER_EXCEPTION @@ -176,16 +177,33 @@ public function testLogException() $exception = new \Exception(); $expected = "\n{$exception}"; /** @var $model \Magento\Framework\Logger|\PHPUnit_Framework_MockObject_MockObject */ - $model = $this->getMock('Magento\Framework\Logger', array('log'), array(), '', false); - $model->expects( - $this->at(0) - )->method( - 'log' - )->with( + $model = $this->getMock('Magento\Framework\Logger', ['log'], [], '', false); + $model->expects($this->at(0)) + ->method('log') + ->with( $expected, \Zend_Log::ERR, \Magento\Framework\Logger::LOGGER_EXCEPTION ); $model->logException($exception); } -} + + public function testUnsetLoggers() + { + $key = 'test'; + $fileOrWrapper = 'custom_file.log'; + $this->model->addStreamLog($key, $fileOrWrapper); + $this->assertTrue($this->model->hasLog($key)); + $this->model->unsetLoggers(); + $this->assertFalse($this->model->hasLog($key)); + } + + public function testLogFile() + { + $message = ['Wrong file name', 'Avoid using special chars']; + $filename = 'custom_file.log'; + $this->model->logFile($message, \Zend_Log::DEBUG); + $this->model->logFile($message, \Zend_Log::DEBUG, $filename); + $this->assertTrue($this->model->hasLog($filename)); + } +} \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php index 11276b58df633..0192c410993ea 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Adjustment/CalculatorTest.php @@ -108,9 +108,8 @@ public function testGetAmount() $adjustments = [$taxAdjustmentMock, $weeeAdjustmentMock]; - $priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfoInterface') + $priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfo\Base') ->disableOriginalConstructor() - //->setMethods(['getPriceInfo']) ->getMock(); $priceInfoMock->expects($this->any()) ->method('getAdjustments') @@ -177,9 +176,8 @@ public function testGetAmountExclude() $adjustments = [$taxAdjustmentMock, $weeeAdjustmentMock]; - $priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfoInterface') + $priceInfoMock = $this->getMockBuilder('\Magento\Framework\Pricing\PriceInfo\Base') ->disableOriginalConstructor() - //->setMethods(['getPriceInfo']) ->getMock(); $priceInfoMock->expects($this->any()) ->method('getAdjustments') diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php index d478d29d4a905..35134d134f995 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Price/AbstractPriceTest.php @@ -35,7 +35,7 @@ class AbstractPriceTest extends \PHPUnit_Framework_TestCase protected $price; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface |\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base |\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php index 093a30d2985b0..b0fc60ad4dfde 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/PriceInfo/FactoryTest.php @@ -56,7 +56,7 @@ class FactoryTest extends \PHPUnit_Framework_TestCase protected $saleableItemMock; /** - * @var \Magento\Framework\Pricing\PriceInfoInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\Pricing\PriceInfo\Base|\PHPUnit_Framework_MockObject_MockObject */ protected $priceInfoMock; diff --git a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php index 10a5827952828..4a8f5212a1058 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Pricing/Render/PriceBoxTest.php @@ -155,7 +155,7 @@ public function testGetPriceType() $price = $this->getMock('Magento\Framework\Pricing\Price\PriceInterface'); - $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfoInterface'); + $priceInfo = $this->getMock('Magento\Framework\Pricing\PriceInfo\Base', [], [], '', false); $priceInfo->expects($this->once()) ->method('getPrice') ->with($priceCode) diff --git a/dev/tests/unit/testsuite/Magento/Framework/RegistryTest.php b/dev/tests/unit/testsuite/Magento/Framework/RegistryTest.php new file mode 100644 index 0000000000000..d47897a3a4f74 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/RegistryTest.php @@ -0,0 +1,92 @@ +registry = new Registry(); + $this->data = [ + 'key' => 'customer', + 'value' => '\Magento\Customer\Model\Customer' + ]; + $this->registry->register($this->data['key'], $this->data['value']); + } + + public function tearDown() + { + unset($this->registry); + } + + public function testRegistry() + { + $this->assertEquals($this->data['value'], $this->registry->registry($this->data['key'])); + $this->assertNull($this->registry->registry($this->data['value'])); + } + + public function testRegister() + { + $key = 'email'; + $value = 'test@magento.com'; + $this->registry->register($key, $value); + $this->assertEquals($value, $this->registry->registry($key)); + $key = 'name'; + $graceful = true; + $this->registry->register($key, $value, $graceful); + } + + /** + * @expectedException \RuntimeException + */ + public function testRegisterKeyExists() + { + $this->registry->register($this->data['key'], $this->data['value']); + } + + public function testUnregister() + { + $key = 'csv_adapter'; + $valueObj = $this->getMock('\Magento\ImportExport\Model\Export\Adapter\Csv', [], [], '', false, false); + $this->registry->register($key, $valueObj); + $this->assertEquals($valueObj, $this->registry->registry($key)); + $this->registry->unregister($key); + $this->assertNull($this->registry->registry($key)); + $this->registry->unregister($this->data['key']); + $this->assertNull($this->registry->registry($this->data['key'])); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/Service/Data/Eav/AttributeValueTest.php b/dev/tests/unit/testsuite/Magento/Framework/Service/Data/Eav/AttributeValueTest.php index 4d6a55d515962..9534bf01a7318 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Service/Data/Eav/AttributeValueTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Service/Data/Eav/AttributeValueTest.php @@ -31,7 +31,8 @@ class AttributeValueTest extends \PHPUnit_Framework_TestCase public function testConstructorAndGetters() { - $attributeBuilder = (new AttributeValueBuilder()) + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); + $attributeBuilder = $helper->getObject('\Magento\Framework\Service\Data\Eav\AttributeValueBuilder') ->setAttributeCode(self::ATTRIBUTE_CODE) ->setValue(self::VALUE); $attribute = new AttributeValue($attributeBuilder); diff --git a/dev/tests/unit/testsuite/Magento/Framework/Service/DataObjectConverterTest.php b/dev/tests/unit/testsuite/Magento/Framework/Service/DataObjectConverterTest.php index 0f94cc8a69383..da12eefa256cd 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/Service/DataObjectConverterTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/Service/DataObjectConverterTest.php @@ -25,7 +25,6 @@ namespace Magento\Framework\Service; use Magento\Customer\Service\V1\Data\Customer; -use Magento\Customer\Service\V1\Data\RegionBuilder; /** * Class implements tests for DataObjectConverterTest class. @@ -164,8 +163,11 @@ private function getCustomerDetails() ->setDefaultShipping(true) ->setPostcode('75477') ->setRegion( - (new RegionBuilder())->setRegionCode(self::REGION_CODE)->setRegion(self::REGION) - ->setRegionId(self::REGION_ID)->create() + $objectManager->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionCode(self::REGION_CODE) + ->setRegion(self::REGION) + ->setRegionId(self::REGION_ID) + ->create() ) ->setStreet($street1) ->setTelephone('3468676') @@ -181,8 +183,11 @@ private function getCustomerDetails() ->setDefaultShipping(false) ->setPostcode('47676') ->setRegion( - (new RegionBuilder())->setRegionCode(self::REGION_CODE)->setRegion(self::REGION) - ->setRegionId(self::REGION_ID)->create() + $objectManager->getObject('\Magento\Customer\Service\V1\Data\RegionBuilder') + ->setRegionCode(self::REGION_CODE) + ->setRegion(self::REGION) + ->setRegionId(self::REGION_ID) + ->create() ) ->setStreet($street2) ->setCity('CityX') diff --git a/dev/tests/unit/testsuite/Magento/Framework/TranslateTest.php b/dev/tests/unit/testsuite/Magento/Framework/TranslateTest.php index cc5ddf0d7c0ea..56ffb6e2186ba 100644 --- a/dev/tests/unit/testsuite/Magento/Framework/TranslateTest.php +++ b/dev/tests/unit/testsuite/Magento/Framework/TranslateTest.php @@ -27,7 +27,6 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - * */ class TranslateTest extends \PHPUnit_Framework_TestCase { @@ -90,7 +89,9 @@ public function setUp() $this->_appState = $this->getMock('\Magento\Framework\App\State', [], [], '', false); $this->_request = $this->getMock('\Magento\Framework\App\RequestInterface', [], [], '', false); $this->_csvParser = $this->getMock('\Magento\Framework\File\Csv', [], [], '', false); - + $this->_config->expects($this->once()) + ->method('getHierarchy') + ->will($this->returnValue(['en_US' => ['en_GB']])); $this->_directory = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false); $filesystem = $this->getMock('\Magento\Framework\App\Filesystem', [], [], '', false); $filesystem->expects($this->once())->method('getDirectoryRead')->will($this->returnValue($this->_directory)); @@ -117,10 +118,11 @@ public function setUp() * @param bool $forceReload * @param array $cachedData * @dataProvider dataProviderForTestLoadData + * @SuppressWarnings(PHPMD.NPathComplexity) */ public function testLoadData($area, $forceReload, $cachedData) { - $this->_expectsSetConfig(); + $this->_expectsSetConfig('themeId'); $this->_cache->expects($this->exactly($forceReload ? 0 : 1)) ->method('load') @@ -137,21 +139,28 @@ public function testLoadData($area, $forceReload, $cachedData) // _loadModuleTranslation() $modules = [['name' => 'module']]; $this->_moduleList->expects($this->once())->method('getModules')->will($this->returnValue($modules)); - $moduleData = ['module original' => 'module translated']; + $moduleData = [ + 'module original' => 'module translated', + 'module original2' => 'module original2' + ]; $this->_modulesReader->expects($this->any())->method('getModuleDir')->will($this->returnValue('/app/module')); - $this->_csvParser->expects(new MethodInvokedAtIndex(0)) + $themeData = ['theme original' => 'theme translated']; + $this->_csvParser->expects($this->any()) ->method('getDataPairs') - ->with('/app/module/en_US.csv') - ->will($this->returnValue($moduleData)); + ->will( + $this->returnValueMap( + [ + ['/app/module/en_US.csv', 0, 1, $moduleData], + ['/app/module/en_GB.csv', 0, 1, $moduleData], + ['/theme.csv', 0, 1, $themeData], + ] + ) + ); // _loadThemeTranslation() - $themeData = ['theme original' => 'theme translated']; - $this->_viewFileSystem->expects($this->once())->method('getLocaleFileName') + $this->_viewFileSystem->expects($this->any()) + ->method('getLocaleFileName') ->will($this->returnValue('/theme.csv')); - $this->_csvParser->expects(new MethodInvokedAtIndex(1)) - ->method('getDataPairs') - ->with('/theme.csv') - ->will($this->returnValue($themeData)); // _loadDbTranslation() $dbData = ['db original' => 'db translated']; @@ -162,7 +171,12 @@ public function testLoadData($area, $forceReload, $cachedData) $this->_translate->loadData($area, $forceReload); - $expected = $moduleData + $themeData + $dbData; + $condition = ($area == 'adminhtml' && !$forceReload) ? true : false; + $expected = [ + 'module original' => 'module translated', + ($condition ? 'themethemeId::' : '') . 'theme original' => 'theme translated', + ($condition ? 'adminCode::' : '') . 'db original' => 'db translated' + ]; $this->assertEquals($expected, $this->_translate->getData()); } @@ -175,19 +189,33 @@ public function dataProviderForTestLoadData() ['frontend', true, false], ['frontend', false, $cachedData], [null, true, false], - [null, false, $cachedData] + [null, false, $cachedData], + ['adminhtml', false, false] ]; } - public function testGetData() + /** + * @param $data + * @param $result + * @dataProvider dataProviderForTestGetData + */ + public function testGetData($data, $result) { - $data = array('original 1' => 'translated 1', 'original 2' => 'translated 2'); $this->_cache->expects($this->once()) ->method('load') ->will($this->returnValue(serialize($data))); - $this->_expectsSetConfig(); + $this->_expectsSetConfig('themeId'); $this->_translate->loadData('frontend'); - $this->assertEquals($data, $this->_translate->getData()); + $this->assertEquals($result, $this->_translate->getData()); + } + + public function dataProviderForTestGetData() + { + $data = ['original 1' => 'translated 1', 'original 2' => 'translated 2']; + return [ + [$data, $data], + [null, []] + ]; } public function testGetLocale() @@ -222,15 +250,35 @@ public function testGetTheme() $this->assertEquals('themeTheme Title', $this->_translate->getTheme()); } + public function testLoadDataNoTheme() + { + $forceReload = true; + $this->_expectsSetConfig(null, null); + $this->_moduleList->expects($this->once())->method('getModules')->will($this->returnValue([])); + $this->_appState->expects($this->once())->method('getAreaCode')->will($this->returnValue('frontend')); + $this->_resource->expects($this->any())->method('getTranslationArray')->will($this->returnValue([])); + $this->assertEquals($this->_translate, $this->_translate->loadData(null, $forceReload)); + } + /** * Declare calls expectation for setConfig() method */ - protected function _expectsSetConfig() + protected function _expectsSetConfig($themeId, $localeCode = 'en_US') { - $this->_locale->expects($this->any())->method('getLocaleCode')->will($this->returnValue('en_US')); + $this->_locale->expects($this->any())->method('getLocaleCode')->will($this->returnValue($localeCode)); $scope = new \Magento\Framework\Object(); - $this->_scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($scope)); - $designTheme = new \Magento\Framework\Object(['id' => 'themeId']); + $scopeAdmin = new \Magento\Framework\Object(['code' => 'adminCode', 'id' => 1]); + $this->_scopeResolver->expects($this->any()) + ->method('getScope') + ->will( + $this->returnValueMap( + [ + [null, $scope], + ['admin', $scopeAdmin] + ] + ) + ); + $designTheme = new \Magento\Framework\Object(['id' => $themeId]); $this->_viewDesign->expects($this->any())->method('getDesignTheme')->will($this->returnValue($designTheme)); } } diff --git a/dev/tests/unit/testsuite/Magento/Framework/UtilTest.php b/dev/tests/unit/testsuite/Magento/Framework/UtilTest.php new file mode 100644 index 0000000000000..a13ebbe1cade4 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/UtilTest.php @@ -0,0 +1,36 @@ +assertEquals($version, $util->getTrimmedPhpVersion()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/archives/.gitignore b/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/archives/.gitignore new file mode 100644 index 0000000000000..22e83649f7d52 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/archives/.gitignore @@ -0,0 +1 @@ +/* \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/source.txt b/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/source.txt new file mode 100644 index 0000000000000..1d3a06547c706 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Framework/_files/Archive/source.txt @@ -0,0 +1 @@ +source \ No newline at end of file diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php similarity index 53% rename from dev/tests/unit/testsuite/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php rename to dev/tests/unit/testsuite/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php index 22cdac721d778..a08f93f209c30 100644 --- a/dev/tests/unit/testsuite/Magento/GroupedProduct/Controller/Adminhtml/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php +++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Model/Product/Initialization/Helper/ProductLinks/Plugin/GroupedTest.php @@ -22,20 +22,17 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\GroupedProduct\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks\Plugin; +namespace Magento\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin; + +use Magento\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin\Grouped; class GroupedTest extends \PHPUnit_Framework_TestCase { /** - * @var \Magento\GroupedProduct\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks\Plugin\Grouped + * @var \Magento\GroupedProduct\Model\Product\Initialization\Helper\ProductLinks\Plugin\Grouped */ protected $model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $requestMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -48,7 +45,6 @@ class GroupedTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->requestMock = $this->getMock('Magento\Framework\App\Request\Http', array(), array(), '', false); $this->productMock = $this->getMock( 'Magento\Catalog\Model\Product', array('getGroupedReadonly', 'setGroupedLinkData', '__wakeup'), @@ -57,71 +53,33 @@ protected function setUp() false ); $this->subjectMock = $this->getMock( - 'Magento\Catalog\Controller\Adminhtml\Product\Initialization\Helper\ProductLinks', + 'Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks', array(), array(), '', false ); - $this->model = new Grouped($this->requestMock); + $this->model = new Grouped(); } - public function testAfterInitializeLinksRequestDoesNotHaveGrouped() + public function testBeforeInitializeLinksRequestDoesNotHaveGrouped() { - $this->requestMock->expects( - $this->once() - )->method( - 'getPost' - )->with( - 'links' - )->will( - $this->returnValue(array()) - ); $this->productMock->expects($this->never())->method('getGroupedReadonly'); $this->productMock->expects($this->never())->method('setGroupedLinkData'); - $this->assertEquals( - $this->productMock, - $this->model->afterInitializeLinks($this->subjectMock, $this->productMock) - ); + $this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, array()); } - public function testAfterInitializeLinksRequestHasGrouped() + public function testBeforeInitializeLinksRequestHasGrouped() { - $this->requestMock->expects( - $this->once() - )->method( - 'getPost' - )->with( - 'links' - )->will( - $this->returnValue(array('grouped' => 'value')) - ); - $this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(false)); $this->productMock->expects($this->once())->method('setGroupedLinkData')->with(array('value')); - $this->assertEquals( - $this->productMock, - $this->model->afterInitializeLinks($this->subjectMock, $this->productMock) - ); + $this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, array('associated' => 'value')); } - public function testAfterInitializeLinksProductIsReadonly() + public function testBeforeInitializeLinksProductIsReadonly() { - $this->requestMock->expects( - $this->once() - )->method( - 'getPost' - )->with( - 'links' - )->will( - $this->returnValue(array('grouped' => 'value')) - ); - $this->productMock->expects($this->once())->method('getGroupedReadonly')->will($this->returnValue(true)); $this->productMock->expects($this->never())->method('setGroupedLinkData'); - $this->assertEquals( - $this->productMock, - $this->model->afterInitializeLinks($this->subjectMock, $this->productMock) - ); + $this->model->beforeInitializeLinks($this->subjectMock, $this->productMock, array('associated' => 'value')); } } diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/GroupedTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/GroupedTest.php new file mode 100644 index 0000000000000..b52e70fa6b805 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/CollectionProvider/GroupedTest.php @@ -0,0 +1,44 @@ +getMock('\Magento\GroupedProduct\Model\Product\Type\Grouped', [], [], '', false); + $product = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $expected = [$product]; + + $product->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstance)); + $typeInstance->expects($this->once()) + ->method('getAssociatedProducts') + ->with($product) + ->will($this->returnValue($expected)); + + $model = new Grouped(); + $this->assertEquals($expected, $model->getLinkedProducts($product)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProductTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProductTest.php new file mode 100644 index 0000000000000..56084e6ba9962 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/DataMapper/GroupedProductTest.php @@ -0,0 +1,51 @@ + 'item1', + 'custom_attributes' => ['qty' => ['value' => 5]] + ], + [ + 'name' => 'item2' + ] + ]; + + $model = new GroupedProduct(); + $mappedData = $model->map($data); + + $this->assertEquals(5, $mappedData[0]['qty']); + $this->assertFalse(isset($mappedData[1]['qty'])); + } +} diff --git a/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterTest.php b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterTest.php new file mode 100644 index 0000000000000..534ee3b490693 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/GroupedProduct/Service/V1/Product/Link/Data/ProductLink/ProductEntity/ConverterTest.php @@ -0,0 +1,60 @@ +getMock( + '\Magento\Catalog\Model\Product', + ['getTypeId', 'getPosition', 'getSku', 'getQty', '__wakeup', '__sleep'], + [], '', false + ); + + $expected = [ + ProductLink::TYPE => 1, + ProductLink::SKU => 3, + ProductLink::POSITION => 4, + ProductLink::CUSTOM_ATTRIBUTES_KEY => [ + [AttributeValue::ATTRIBUTE_CODE => 'qty',AttributeValue::VALUE => 5] + ] + ]; + + $productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(1)); + $productMock->expects($this->once())->method('getSku')->will($this->returnValue(3)); + $productMock->expects($this->once())->method('getPosition')->will($this->returnValue(4)); + $productMock->expects($this->once())->method('getQty')->will($this->returnValue(5)); + + $model = new Converter(); + $this->assertEquals($expected, $model->convert($productMock)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/ImportExport/Model/Import/Entity/Product/_files/product_with_custom_options.csv b/dev/tests/unit/testsuite/Magento/ImportExport/Model/Import/Entity/Product/_files/product_with_custom_options.csv index 8920106716fad..6dd31ced170f4 100644 --- a/dev/tests/unit/testsuite/Magento/ImportExport/Model/Import/Entity/Product/_files/product_with_custom_options.csv +++ b/dev/tests/unit/testsuite/Magento/ImportExport/Model/Import/Entity/Product/_files/product_with_custom_options.csv @@ -1,4 +1,4 @@ -sku,_store,_attribute_set,_type,_category,_root_category,_product_websites,color,cost,country_of_manufacture,created_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,description,enable_googlecheckout,gallery,gift_message_available,gift_wrapping_available,gift_wrapping_price,has_options,image,image_label,is_returnable,manufacturer,media_gallery,meta_description,meta_keyword,meta_title,minimal_price,msrp,msrp_display_actual_price_type,msrp_enabled,name,news_from_date,news_to_date,options_container,page_layout,price,related_tgtr_position_behavior,related_tgtr_position_limit,required_options,short_description,small_image,small_image_label,special_from_date,special_price,special_to_date,status,tax_class_id,thumbnail,thumbnail_label,updated_at,upsell_tgtr_position_behavior,upsell_tgtr_position_limit,url_key,url_path,visibility,weight,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,_links_related_sku,_links_related_position,_links_crosssell_sku,_links_crosssell_position,_links_upsell_sku,_links_upsell_position,_associated_sku,_associated_default_qty,_associated_position,_tier_price_website,_tier_price_customer_group,_tier_price_qty,_tier_price_price,_group_price_website,_group_price_customer_group,_group_price_price,_media_attribute_id,_media_image,_media_label,_media_position,_media_is_disabled,_custom_option_store,_custom_option_type,_custom_option_title,_custom_option_is_required,_custom_option_price,_custom_option_sku,_custom_option_max_characters,_custom_option_sort_order,_custom_option_row_title,_custom_option_row_price,_custom_option_row_sku,_custom_option_row_sort +sku,_store,_attribute_set,_type,_category,_root_category,_product_websites,color,cost,country_of_manufacture,created_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,description,enable_googlecheckout,gallery,gift_message_available,gift_wrapping_available,gift_wrapping_price,has_options,image,image_label,is_returnable,manufacturer,media_gallery,meta_description,meta_keyword,meta_title,minimal_price,msrp,msrp_display_actual_price_type,msrp_enabled,name,news_from_date,news_to_date,options_container,page_layout,price,related_tgtr_position_behavior,related_tgtr_position_limit,required_options,short_description,small_image,small_image_label,special_from_date,special_price,special_to_date,status,tax_class_id,thumbnail,thumbnail_label,updated_at,upsell_tgtr_position_behavior,upsell_tgtr_position_limit,url_key,url_path,visibility,weight,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,_related_sku,_related_position,_crosssell_sku,_crosssell_position,_upsell_sku,_upsell_position,_associated_sku,_associated_default_qty,_associated_position,_tier_price_website,_tier_price_customer_group,_tier_price_qty,_tier_price_price,_group_price_website,_group_price_customer_group,_group_price_price,_media_attribute_id,_media_image,_media_label,_media_position,_media_is_disabled,_custom_option_store,_custom_option_type,_custom_option_title,_custom_option_is_required,_custom_option_price,_custom_option_sku,_custom_option_max_characters,_custom_option_sort_order,_custom_option_row_title,_custom_option_row_price,_custom_option_row_sku,_custom_option_row_sort simple,,Default,simple,,,base,,,,,,,,,,1,,,,,1,,,"Use config",,,,,,,,,,"New Product",,,"Block after Info Column",,10.0000,,,1,,,,,,,1,,,,"2012-07-13 12:04:17",,,new-product,new-product.html,4,,100.0000,0.0000,1,0,0,1,1.0000,1,0.0000,1,1,,1,0,1,1,0.0000,1,0,0,,,,,,,,,,,,,,,,,,,,,,,field,"Test Field Title",1,,1-text,100,0,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,date_time,"Test Date and Time Title",1,2.0000,2-date,,0,,,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,drop_down,"Test Select",1,,,,0,"Option 1",3.0000,3-1-select,0 @@ -6,4 +6,4 @@ simple,,Default,simple,,,base,,,,,,,,,,1,,,,,1,,,"Use config",,,,,,,,,,"New Prod ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,default,,,,,,,,"Option 2",,, ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,radio,"Test Radio",1,,,,0,"Option 1",3.0000,4-1-radio,0 ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"Option 2",3.0000,4-2-radio,0 -,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,default,,,,,,,,"Option 2",,, \ No newline at end of file +,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,default,,,,,,,,"Option 2",,, diff --git a/dev/tests/unit/testsuite/Magento/Ogone/Model/ApiTest.php b/dev/tests/unit/testsuite/Magento/Ogone/Model/ApiTest.php index 57aed72cb162b..50edbe9aa7c8c 100644 --- a/dev/tests/unit/testsuite/Magento/Ogone/Model/ApiTest.php +++ b/dev/tests/unit/testsuite/Magento/Ogone/Model/ApiTest.php @@ -25,11 +25,6 @@ class ApiTest extends \PHPUnit_Framework_TestCase { - protected function setUp() - { - $this->markTestSkipped('Api tests were skipped'); - } - /** * Test protected method, which converts Magento internal charset (UTF-8) to the one, understandable * by Ogone (ISO-8859-1), and then encodes html entities diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseCheckoutTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseCheckoutTest.php new file mode 100644 index 0000000000000..afbfea37e1411 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseCheckoutTest.php @@ -0,0 +1,64 @@ +_model = new CanUseCheckout(); + } + + /** + * @dataProvider paymentMethodDataProvider + * @param bool $expectation + */ + public function testIsApplicable($expectation) + { + $quote = $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $paymentMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMethod->expects($this->once())->method('canUseCheckout')->will( + $this->returnValue($expectation) + ); + $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quote)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[true], [false]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCountryTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCountryTest.php new file mode 100644 index 0000000000000..b20ca5525d010 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCountryTest.php @@ -0,0 +1,78 @@ +_model = new CanUseForCountry(); + } + + /** + * @dataProvider paymentMethodDataProvider + * @param bool $expectation + */ + public function testIsApplicable($expectation) + { + $quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $billingAddressMock = $this->getMockBuilder( + 'Magento\Sales\Model\Quote\Address' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $billingAddressMock->expects($this->once())->method('getCountry')->will( + $this->returnValue(self::EXPECTED_COUNTRY_ID) + ); + $quoteMock->expects($this->once())->method('getBillingAddress')->will($this->returnValue($billingAddressMock)); + + $paymentMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMethod->expects($this->once())->method('canUseForCountry')->with( + self::EXPECTED_COUNTRY_ID + )->will($this->returnValue($expectation)); + + $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quoteMock)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[true], [false]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCurrencyTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCurrencyTest.php new file mode 100644 index 0000000000000..32dba3395d027 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseForCurrencyTest.php @@ -0,0 +1,78 @@ +_model = new CanUseForCurrency(); + } + + /** + * @dataProvider paymentMethodDataProvider + * @param bool $expectation + */ + public function testIsApplicable($expectation) + { + $paymentMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMethod->expects($this->once())->method('canUseForCurrency')->with( + self::EXPECTED_CURRENCY_CODE + )->will($this->returnValue($expectation)); + + $quoteMock = $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $store = $this->getMockBuilder( + 'Magento\Store\Model\Store' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $store->expects($this->once())->method('getBaseCurrencyCode')->will( + $this->returnValue(self::EXPECTED_CURRENCY_CODE) + ); + $quoteMock->expects($this->once())->method('getStore')->will($this->returnValue($store)); + + $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quoteMock)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[true], [false]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseInternalTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseInternalTest.php new file mode 100644 index 0000000000000..b85d22cc9f564 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CanUseInternalTest.php @@ -0,0 +1,64 @@ +_model = new CanUseInternal(); + } + + /** + * @dataProvider paymentMethodDataProvider + * @param bool $expectation + */ + public function testIsApplicable($expectation) + { + $quote = $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $paymentMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMethod->expects($this->once())->method('canUseInternal')->will( + $this->returnValue($expectation) + ); + $this->assertEquals($expectation, $this->_model->isApplicable($paymentMethod, $quote)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[true], [false]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CompositeTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CompositeTest.php new file mode 100644 index 0000000000000..d71afc522af14 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/CompositeTest.php @@ -0,0 +1,59 @@ +getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + [] + )->getMock(); + $paymentMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + + $specification = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\SpecificationInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $specification->expects($this->once())->method('isApplicable')->with($paymentMethod, $quote)->will( + $this->returnValue($expectation) + ); + $model = new Composite([$specification]); + $this->assertEquals($expectation, $model->isApplicable($paymentMethod, $quote)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[true], [false]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/SpecificationFactoryTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/SpecificationFactoryTest.php new file mode 100644 index 0000000000000..396fddf512f0c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/SpecificationFactoryTest.php @@ -0,0 +1,63 @@ +_compositeFactory = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\CompositeFactory' + )->disableOriginalConstructor()->setMethods(['create'])->getMock(); + } + + public function testCreate() + { + $specification = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\SpecificationInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $specificationMapping = [self::SPECIFICATION_KEY => $specification]; + + $expectedComposite = $this->getMockBuilder( + 'Magento\Payment\Model\Checks\Composite' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $modelFactory = new SpecificationFactory($this->_compositeFactory, $specificationMapping); + $this->_compositeFactory->expects($this->once())->method('create')->with( + ['list' => $specificationMapping] + )->will($this->returnValue($expectedComposite)); + + $this->assertEquals($expectedComposite, $modelFactory->create([self::SPECIFICATION_KEY])); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/TotalMinMaxTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/TotalMinMaxTest.php new file mode 100644 index 0000000000000..63db8c3add812 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/TotalMinMaxTest.php @@ -0,0 +1,72 @@ +getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMethod->expects($this->at(0))->method('getConfigData')->with( + TotalMinMax::MIN_ORDER_TOTAL + )->will($this->returnValue(self::PAYMENT_MIN_TOTAL)); + $paymentMethod->expects($this->at(1))->method('getConfigData')->with( + TotalMinMax::MAX_ORDER_TOTAL + )->will($this->returnValue(self::PAYMENT_MAX_TOTAL)); + + $quote = $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + ['getBaseGrandTotal', '__wakeup'] + )->getMock(); + $quote->expects($this->once())->method('getBaseGrandTotal')->will($this->returnValue($baseGrandTotal)); + + $model = new TotalMinMax(); + $this->assertEquals($expectation, $model->isApplicable($paymentMethod, $quote)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [[1, false], [6, false], [3, true]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/ZeroTotalTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/ZeroTotalTest.php new file mode 100644 index 0000000000000..85be6b35962c8 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Checks/ZeroTotalTest.php @@ -0,0 +1,67 @@ +getMockBuilder( + 'Magento\Payment\Model\Checks\PaymentMethodChecksInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + if (!$total) { + $paymentMethod->expects($this->once())->method('getCode')->will($this->returnValue($code)); + } + + $quote= $this->getMockBuilder('Magento\Sales\Model\Quote')->disableOriginalConstructor()->setMethods( + ['getBaseSubtotal', 'getShippingAddress', '__wakeup'] + )->getMock(); + $shippingAddress = $this->getMockBuilder( + 'Magento\Sales\Model\Quote\Address' + )->disableOriginalConstructor()->setMethods(['getBaseShippingAmount', '__wakeup'])->getMock(); + $shippingAddress->expects($this->once())->method('getBaseShippingAmount')->will( + $this->returnValue($total) + ); + $quote->expects($this->once())->method('getBaseSubtotal')->will($this->returnValue($total)); + $quote->expects($this->once())->method('getShippingAddress')->will($this->returnValue($shippingAddress)); + + $model = new ZeroTotal(); + $this->assertEquals($expectation, $model->isApplicable($paymentMethod, $quote)); + } + + /** + * @return array + */ + public function paymentMethodDataProvider() + { + return [['not_free', 0, false], ['free', 1, true]]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Config/SchemaLocatorTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/SchemaLocatorTest.php new file mode 100644 index 0000000000000..4d12d5afedbba --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/SchemaLocatorTest.php @@ -0,0 +1,62 @@ +getMockBuilder( + 'Magento\Framework\Module\Dir\Reader' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $moduleReader->expects($this->exactly(2))->method('getModuleDir')->with('etc', 'Magento_Payment')->will( + $this->returnValue(self::MODULE_DIR_PATH) + ); + $this->model = new SchemaLocator($moduleReader); + } + + public function testGetSchema() + { + $this->assertEquals( + self::MODULE_DIR_PATH . '/' . SchemaLocator::MERGED_CONFIG_SCHEMA, + $this->model->getSchema() + ); + } + + public function testGetPerFileSchema() + { + $this->assertEquals( + self::MODULE_DIR_PATH . '/' . SchemaLocator::PER_FILE_VALIDATION_SCHEMA, + $this->model->getPerFileSchema() + ); + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllmethodsTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllmethodsTest.php new file mode 100644 index 0000000000000..1af7ce84a2533 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllmethodsTest.php @@ -0,0 +1,58 @@ +_paymentData = $this->getMockBuilder( + 'Magento\Payment\Helper\Data' + )->disableOriginalConstructor()->setMethods([])->getMock(); + + $this->_model = new Allmethods($this->_paymentData); + } + + public function testToOptionArray() + { + $expectedArray = ['key' => 'value']; + $this->_paymentData->expects($this->once())->method('getPaymentMethodList')->with( + true, true, true + )->will($this->returnValue($expectedArray)); + $this->assertEquals($expectedArray, $this->_model->toOptionArray()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllspecificcountriesTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllspecificcountriesTest.php new file mode 100644 index 0000000000000..cc03ffacc7e5d --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/AllspecificcountriesTest.php @@ -0,0 +1,38 @@ + 0, 'label' => __('All Allowed Countries')], + ['value' => 1, 'label' => __('Specific Countries')] + ]; + $model = new Allspecificcountries(); + $this->assertEquals($expectedArray, $model->toOptionArray()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/CctypeTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/CctypeTest.php new file mode 100644 index 0000000000000..8582c0c631910 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Config/Source/CctypeTest.php @@ -0,0 +1,59 @@ +_paymentConfig = $this->getMockBuilder( + 'Magento\Payment\Model\Config' + )->disableOriginalConstructor()->setMethods([])->getMock(); + + $this->_model = new Cctype($this->_paymentConfig); + } + + public function testToOptionArray() + { + $cctypesArray = ['code' => 'name']; + $expectedArray = [ + ['value' => 'code', 'label' => 'name'] + ]; + $this->_paymentConfig->expects($this->once())->method('getCcTypes')->will($this->returnValue($cctypesArray)); + $this->assertEquals($expectedArray, $this->_model->toOptionArray()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/ConfigTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/ConfigTest.php new file mode 100644 index 0000000000000..ccfc8c105c0db --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/ConfigTest.php @@ -0,0 +1,204 @@ + ['active' => 0], + 'active_method_no_model' => ['active' => 1], + 'active_method' => ['active' => 1, 'model' => 'model_name'] + ]; + + /** + * List of test month + * + * @var array + */ + protected $monthList = [ + 1 => 'Marsabruary', + 11 => 'Venusly' + ]; + + /** + * Expected months list + * + * @var array + */ + protected $expectedMonthList = [ + 1 => '01 - Marsabruary', + 11 => '11 - Venusly' + ]; + + /** + * Current year value in ISO + */ + const CURRENT_YEAR = '2250'; + + protected function setUp() + { + $this->scopeConfig = $this->getMock( + 'Magento\Framework\App\Config\ScopeConfigInterface', + [], + [], + '', + false + ); + $this->paymentMethodFactory = $this->getMock('Magento\Payment\Model\Method\Factory', [], [], '', false); + $this->localeLists = $this->getMock('Magento\Framework\Locale\ListsInterface', [], [], '', false); + $this->dataStorage = $this->getMock('Magento\Framework\Config\DataInterface', [], [], '', false); + $this->date = $this->getMock('Magento\Framework\Stdlib\DateTime\DateTime', [], [], '', false); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->config = $this->objectManagerHelper->getObject( + 'Magento\Payment\Model\Config', + [ + 'scopeConfig' => $this->scopeConfig, + 'paymentMethodFactory' => $this->paymentMethodFactory, + 'localeLists' => $this->localeLists, + 'dataStorage' => $this->dataStorage, + 'date' => $this->date + ] + ); + } + + /** + * @param bool $isActive + * @dataProvider getActiveMethodsDataProvider + */ + public function testGetActiveMethods($isActive) + { + $abstractMethod = $this->getMockBuilder( + 'Magento\Payment\Model\Method\AbstractMethod' + )->disableOriginalConstructor()->setMethods(['setId', 'setStore', 'getConfigData'])->getMock(); + $this->scopeConfig->expects($this->once())->method('getValue')->with( + 'payment', ScopeInterface::SCOPE_STORE, null + )->will($this->returnValue($this->paymentMethodsList)); + $this->paymentMethodFactory->expects($this->once())->method('create')->with( + $this->paymentMethodsList['active_method']['model'] + )->will($this->returnValue($abstractMethod)); + $abstractMethod->expects($this->any())->method('setId')->with('active_method')->will( + $this->returnValue($abstractMethod) + ); + $abstractMethod->expects($this->any())->method('setStore')->with(null); + $abstractMethod->expects($this->any()) + ->method('getConfigData') + ->with('active', $this->isNull()) + ->will($this->returnValue($isActive)); + $this->assertEquals($isActive ? ['active_method' => $abstractMethod] : [], $this->config->getActiveMethods()); + } + + public function getActiveMethodsDataProvider() + { + return [[true], [false]]; + } + + public function testGetCcTypes() + { + $expected = []; + $this->dataStorage->expects($this->once())->method('get')->with('credit_cards')->will( + $this->returnValue($expected) + ); + $this->assertEquals($expected, $this->config->getCcTypes()); + } + + public function testGetMethodsInfo() + { + $expected = []; + $this->dataStorage->expects($this->once())->method('get')->with('methods')->will( + $this->returnValue($expected) + ); + $this->assertEquals($expected, $this->config->getMethodsInfo()); + } + + public function testGetGroups() + { + $expected = []; + $this->dataStorage->expects($this->once())->method('get')->with('groups')->will( + $this->returnValue($expected) + ); + $this->assertEquals($expected, $this->config->getGroups()); + } + + public function testGetMonths() + { + $this->localeLists->expects($this->once())->method('getTranslationList')->with('month')->will( + $this->returnValue($this->monthList) + ); + $this->assertEquals($this->expectedMonthList, $this->config->getMonths()); + } + + public function testGetYears() + { + $this->date->expects($this->once())->method('date')->with('Y')->will($this->returnValue(self::CURRENT_YEAR)); + $this->assertEquals($this->_getPreparedYearsList(), $this->config->getYears()); + } + + /** + * Generates expected years list + * + * @return array + */ + private function _getPreparedYearsList() + { + $expectedYearsList = []; + for ($index = 0; $index <= Config::YEARS_RANGE; $index++) { + $year = (int)self::CURRENT_YEAR + $index; + $expectedYearsList[$year] = $year; + } + return $expectedYearsList; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/InfoTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/InfoTest.php new file mode 100644 index 0000000000000..1b68e24970933 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/InfoTest.php @@ -0,0 +1,242 @@ +contextMock = $this->getMock('Magento\Framework\Model\Context', [], [], '', false); + $this->registryMock = $this->getMock('Magento\Framework\Registry'); + $this->paymentHelperMock = $this->getMock('Magento\Payment\Helper\Data', [], [], '', false); + $this->encryptorInterfaceMock = $this->getMock( + 'Magento\Framework\Encryption\EncryptorInterface', + [], + [], + '', + false + ); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->info = $this->objectManagerHelper->getObject( + 'Magento\Payment\Model\Info', + [ + 'context' => $this->contextMock, + 'registry' => $this->registryMock, + 'paymentData' => $this->paymentHelperMock, + 'encryptor' => $this->encryptorInterfaceMock + ] + ); + } + + /** + * @dataProvider ccKeysDataProvider + * @param string $keyCc + * @param string $keyCcEnc + */ + public function testGetDataCcNumber($keyCc, $keyCcEnc) + { + // no data was set + $this->assertNull($this->info->getData($keyCc)); + + // we set encrypted data + $this->info->setData($keyCcEnc, $keyCcEnc); + $this->encryptorInterfaceMock->expects($this->once())->method('decrypt')->with($keyCcEnc)->will( + $this->returnValue($keyCc) + ); + $this->assertEquals($keyCc, $this->info->getData($keyCc)); + } + + /** + * Returns array of Cc keys which needs prepare logic + * + * @return array + */ + public function ccKeysDataProvider() + { + return [ + ['cc_number', 'cc_number_enc'], + ['cc_cid', 'cc_cid_enc'] + ]; + } + + /** + * @expectedException \Magento\Framework\Model\Exception + */ + public function testGetMethodInstanceException() + { + $this->info->getMethodInstance(); + } + + public function testGetMethodInstanceSubstitution() + { + $code = 'unreal_method'; + $this->info->setData('method', $code); + + $methodInstance = $this->getMockBuilder( + 'Magento\Payment\Model\MethodInterface')->disableOriginalConstructor()->setMethods( + ['setInfoInstance', 'getCode', 'getFormBlockType', 'getTitle'] + )->getMock(); + $this->paymentHelperMock->expects($this->at(0))->method('getMethodInstance')->with($code)->will( + $this->returnValue(null) + ); + $this->paymentHelperMock->expects($this->at(1))->method('getMethodInstance')->with( + Method\Substitution::CODE + )->will($this->returnValue($methodInstance)); + + $methodInstance->expects($this->once())->method('setInfoInstance')->with($this->info); + $this->assertSame($methodInstance, $this->info->getMethodInstance()); + } + + public function testGetMethodInstanceRequestedMethod() + { + $code = 'unreal_method'; + $this->info->setData('method', $code); + + $methodInstance = $this->getMockBuilder( + 'Magento\Payment\Model\MethodInterface')->disableOriginalConstructor()->setMethods( + ['setInfoInstance', 'getCode', 'getFormBlockType', 'getTitle'] + )->getMock(); + $this->paymentHelperMock->expects($this->once())->method('getMethodInstance')->with($code)->will( + $this->returnValue($methodInstance) + ); + + $methodInstance->expects($this->once())->method('setInfoInstance')->with($this->info); + $this->assertSame($methodInstance, $this->info->getMethodInstance()); + + // as the method is already stored at Info, check that it's not initialized again + $this->assertSame($methodInstance, $this->info->getMethodInstance()); + } + + public function testEncrypt() + { + $data = 'data'; + $encryptedData = 'd1a2t3a4'; + + $this->encryptorInterfaceMock->expects($this->once())->method('encrypt')->with($data)->will( + $this->returnValue($encryptedData) + ); + $this->assertEquals($encryptedData, $this->info->encrypt($data)); + } + + public function testDecrypt() + { + $data = 'data'; + $encryptedData = 'd1a2t3a4'; + + $this->encryptorInterfaceMock->expects($this->once())->method('decrypt')->with($encryptedData)->will( + $this->returnValue($data) + ); + $this->assertEquals($data, $this->info->decrypt($encryptedData)); + } + + /** + * @expectedException \Magento\Framework\Model\Exception + */ + public function testSetAdditionalInformationException() + { + $this->info->setAdditionalInformation('object', new \StdClass); + } + + /** + * @dataProvider additionalInformationDataProvider + * @param mixed $key + * @param mixed $value + */ + public function testSetAdditionalInformationMultipleTypes($key, $value = null) + { + $this->info->setAdditionalInformation($key, $value); + $this->assertEquals($value ? [$key => $value] : $key, $this->info->getAdditionalInformation()); + } + + /** + * Prepared data for testSetAdditionalInformationMultipleTypes + * + * @return array + */ + public function additionalInformationDataProvider() + { + return [ + [['key1' => 'data1', 'key2' => 'data2'], null], + ['key', 'data'] + ]; + } + + public function testGetAdditionalInformationByKey() + { + $key = 'key'; + $value = 'value'; + $this->info->setAdditionalInformation($key, $value); + $this->assertEquals($value, $this->info->getAdditionalInformation($key)); + } + + public function testUnsAdditionalInformation() + { + // set array to additional + $data = ['key1' => 'data1', 'key2' => 'data2']; + $this->info->setAdditionalInformation($data); + + // unset by key + $this->assertEquals( + ['key2' => 'data2'], + $this->info->unsAdditionalInformation('key1')->getAdditionalInformation() + ); + + // unset all + $this->assertEmpty($this->info->unsAdditionalInformation()->getAdditionalInformation()); + } + + public function testHasAdditionalInformation() + { + $this->assertFalse($this->info->hasAdditionalInformation()); + + $data = ['key1' => 'data1', 'key2' => 'data2']; + $this->info->setAdditionalInformation($data); + $this->assertFalse($this->info->hasAdditionalInformation('key3')); + + $this->assertTrue($this->info->hasAdditionalInformation('key2')); + $this->assertTrue($this->info->hasAdditionalInformation()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/ObserverTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/ObserverTest.php new file mode 100644 index 0000000000000..31688bf3fe407 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/ObserverTest.php @@ -0,0 +1,277 @@ +orderConfigMock = $this->getMock('Magento\Sales\Model\Order\Config', [], [], '', false); + $this->paymentConfigMock = $this->getMock('Magento\Payment\Model\Config', [], [], '', false); + $this->coreResourceConfigMock = $this->getMock('Magento\Core\Model\Resource\Config', [], [], '', false); + + $this->objectManagerHelper = new ObjectManagerHelper($this); + $this->observer = $this->objectManagerHelper->getObject( + 'Magento\Payment\Model\Observer', + [ + 'salesOrderConfig' => $this->orderConfigMock, + 'paymentConfig' => $this->paymentConfigMock, + 'resourceConfig' => $this->coreResourceConfigMock + ] + ); + + $this->observerMock = $this->getMockBuilder( + 'Magento\Framework\Event\Observer' + )->disableOriginalConstructor()->setMethods([])->getMock(); + } + + public function testSalesOrderBeforeSaveMethodNotFree() + { + $this->_prepareEventMockWithMethods(['getOrder']); + $neverInvokedMethods = ['canUnhold', 'isCanceled', 'getState', 'hasForcedCanCreditMemo']; + $order = $this->_getPreparedOrderMethod( + 'not_free', + $neverInvokedMethods + ); + $this->_prepareNeverInvokedOrderMethods($order, $neverInvokedMethods); + $this->eventMock->expects($this->once())->method('getOrder')->will( + $this->returnValue($order) + ); + + $this->observer->salesOrderBeforeSave($this->observerMock); + } + + public function testSalesOrderBeforeSaveCantUnhold() + { + $this->_prepareEventMockWithMethods(['getOrder']); + $neverInvokedMethods = ['isCanceled', 'getState', 'hasForcedCanCreditMemo']; + $order = $this->_getPreparedOrderMethod('free', ['canUnhold'] + $neverInvokedMethods); + $this->_prepareNeverInvokedOrderMethods($order, $neverInvokedMethods); + $this->eventMock->expects($this->once())->method('getOrder')->will( + $this->returnValue($order) + ); + $order->expects($this->once())->method('canUnhold')->will($this->returnValue(true)); + $this->observer->salesOrderBeforeSave($this->observerMock); + } + + public function testSalesOrderBeforeSaveIsCanceled() + { + // check first canceled state + $this->_prepareEventMockWithMethods(['getOrder']); + $neverInvokedMethods = ['getState', 'hasForcedCanCreditMemo']; + $order = $this->_getPreparedOrderMethod('free', ['canUnhold', 'isCanceled'] + $neverInvokedMethods); + $this->_prepareNeverInvokedOrderMethods($order, $neverInvokedMethods); + $this->eventMock->expects($this->once())->method('getOrder')->will( + $this->returnValue($order) + ); + $order->expects($this->once())->method('canUnhold')->will($this->returnValue(false)); + + $order->expects($this->once())->method('isCanceled')->will($this->returnValue(true)); + + $this->observer->salesOrderBeforeSave($this->observerMock); + } + + public function testSalesOrderBeforeSaveIsClosed() + { + // check closed state at second + $this->_prepareEventMockWithMethods(['getOrder']); + $neverInvokedMethods = ['hasForcedCanCreditMemo']; + $order = $this->_getPreparedOrderMethod('free', ['canUnhold', 'isCanceled', 'getState'] + $neverInvokedMethods); + $this->_prepareNeverInvokedOrderMethods($order, $neverInvokedMethods); + $this->eventMock->expects($this->once())->method('getOrder')->will( + $this->returnValue($order) + ); + $order->expects($this->once())->method('canUnhold')->will($this->returnValue(false)); + + $order->expects($this->once())->method('isCanceled')->will($this->returnValue(false)); + $order->expects($this->once())->method('getState')->will( + $this->returnValue(\Magento\Sales\Model\Order::STATE_CLOSED) + ); + $this->observer->salesOrderBeforeSave($this->observerMock); + } + + public function testSalesOrderBeforeSaveSetForced() + { + // check closed state at second + $this->_prepareEventMockWithMethods(['getOrder']); + $order = $this->_getPreparedOrderMethod( + 'free', + ['canUnhold', 'isCanceled', 'getState', 'setForcedCanCreditmemo', 'hasForcedCanCreditmemo'] + ); + $this->eventMock->expects($this->once())->method('getOrder')->will( + $this->returnValue($order) + ); + $order->expects($this->once())->method('canUnhold')->will($this->returnValue(false)); + + $order->expects($this->once())->method('isCanceled')->will($this->returnValue(false)); + $order->expects($this->once())->method('getState')->will( + $this->returnValue('not_closed_state') + ); + $order->expects($this->once())->method('hasForcedCanCreditmemo')->will($this->returnValue(false)); + $order->expects($this->once())->method('setForcedCanCreditmemo')->will($this->returnValue(true)); + + $this->observer->salesOrderBeforeSave($this->observerMock); + } + + public function testUpdateOrderStatusForPaymentMethodsNotNewState() + { + $this->_prepareEventMockWithMethods(['getState']); + $this->eventMock->expects($this->once())->method('getState')->will($this->returnValue('NotNewState')); + $this->observer->updateOrderStatusForPaymentMethods($this->observerMock); + } + + public function testUpdateOrderStatusForPaymentMethodsNewState() + { + $this->_prepareEventMockWithMethods(['getState', 'getStatus']); + $this->eventMock->expects($this->once())->method('getState')->will( + $this->returnValue(\Magento\Sales\Model\Order::STATE_NEW) + ); + $this->eventMock->expects($this->once())->method('getStatus')->will( + $this->returnValue(self::ORDER_STATUS) + ); + + $defaultStatus = 'defaultStatus'; + $this->orderConfigMock->expects($this->once())->method('getStateDefaultStatus')->with( + \Magento\Sales\Model\Order::STATE_NEW + )->will($this->returnValue($defaultStatus)); + + $this->paymentConfigMock->expects($this->once())->method('getActiveMethods')->will( + $this->returnValue($this->_getPreparedActiveMethods()) + ); + + $this->coreResourceConfigMock->expects($this->once())->method('saveConfig')->with( + 'payment/' . self::METHOD_CODE . '/order_status', + $defaultStatus, + 'default', + 0 + ); + $this->observer->updateOrderStatusForPaymentMethods($this->observerMock); + } + + /** + * Prepares EventMock with set of methods + * + * @param $methodsList + */ + private function _prepareEventMockWithMethods($methodsList) + { + $this->eventMock = $this->getMockBuilder( + 'Magento\Framework\Event' + )->disableOriginalConstructor()->setMethods($methodsList)->getMock(); + $this->observerMock->expects($this->any())->method('getEvent')->will($this->returnValue($this->eventMock)); + } + + /** + * Prepares Order with MethodInterface + * + * @param string $methodCode + * @param array $orderMethods + * @return \PHPUnit_Framework_MockObject_MockObject + */ + private function _getPreparedOrderMethod($methodCode, $orderMethods = []) + { + $order = $this->getMockBuilder('Magento\Sales\Model\Order')->disableOriginalConstructor()->setMethods( + array_merge(['__wakeup', 'getPayment'], $orderMethods) + )->getMock(); + $paymentMock = $this->getMockBuilder( + 'Magento\Sales\Model\Order\Payment' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $order->expects($this->once())->method('getPayment')->will($this->returnValue($paymentMock)); + $methodInstance = $this->getMockBuilder( + 'Magento\Payment\Model\MethodInterface' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $paymentMock->expects($this->once())->method('getMethodInstance')->will($this->returnValue($methodInstance)); + $methodInstance->expects($this->once())->method('getCode')->will($this->returnValue($methodCode)); + return $order; + } + + /** + * Return mocked data of getActiveMethods + * + * @return array + */ + private function _getPreparedActiveMethods() + { + $mockedMethods = ['getCode', 'getFormBlockType', 'getTitle', 'getConfigData']; + $method1 = $this->getMockBuilder( + 'Magento\Payment\Model\MethodInterface' + )->disableOriginalConstructor()->setMethods($mockedMethods)->getMock(); + $method1->expects($this->once())->method('getConfigData')->with('order_status')->will( + $this->returnValue(self::ORDER_STATUS) + ); + $method1->expects($this->once())->method('getCode')->will( + $this->returnValue(self::METHOD_CODE) + ); + + $method2 = $this->getMockBuilder( + 'Magento\Payment\Model\MethodInterface' + )->disableOriginalConstructor()->setMethods($mockedMethods)->getMock(); + $method2->expects($this->once())->method('getConfigData')->with('order_status')->will( + $this->returnValue('not_a_status') + ); + + return [$method1, $method2]; + } + + /** + * Sets never expectation for order methods listed in $method + * + * @param \PHPUnit_Framework_MockObject_MockObject $order + * @param array $methods + */ + private function _prepareNeverInvokedOrderMethods(\PHPUnit_Framework_MockObject_MockObject $order, $methods = []) + { + foreach ($methods as $method) { + $order->expects($this->never())->method($method); + } + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Source/CctypeTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Source/CctypeTest.php new file mode 100644 index 0000000000000..82fafc7357bd2 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Source/CctypeTest.php @@ -0,0 +1,96 @@ + 'name']; + + /** + * Expected cctype array after toOptionArray call + * + * @var array + */ + protected $_expectedToOptionsArray = [['value' => 'allowed_cc_type', 'label' => 'name']]; + + public function setUp() + { + $this->_paymentConfig = $this->getMockBuilder( + 'Magento\Payment\Model\Config' + )->disableOriginalConstructor()->setMethods([])->getMock(); + + $this->_model = new Cctype($this->_paymentConfig); + } + + public function testSetAndGetAllowedTypes() + { + $model = $this->_model->setAllowedTypes($this->_allowedTypes); + $this->assertEquals($this->_allowedTypes, $model->getAllowedTypes()); + } + + public function testToOptionArrayEmptyAllowed() + { + $this->_preparePaymentConfig(); + $this->assertEquals($this->_expectedToOptionsArray, $this->_model->toOptionArray()); + } + + public function testToOptionArrayNotEmptyAllowed() + { + $this->_preparePaymentConfig(); + $this->_model->setAllowedTypes($this->_allowedTypes); + $this->assertEquals($this->_expectedToOptionsArray, $this->_model->toOptionArray()); + } + + private function _preparePaymentConfig() + { + $this->_paymentConfig->expects($this->once())->method('getCcTypes')->will( + $this->returnValue($this->_cctypesArray) + ); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Payment/Model/Source/InvoiceTest.php b/dev/tests/unit/testsuite/Magento/Payment/Model/Source/InvoiceTest.php new file mode 100644 index 0000000000000..ff7c47fe5ca00 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Payment/Model/Source/InvoiceTest.php @@ -0,0 +1,51 @@ +_model = new Invoice(); + } + + public function testToOptionArray() + { + $expectedResult = array( + array( + 'value' => \Magento\Payment\Model\Method\AbstractMethod::ACTION_AUTHORIZE_CAPTURE, + 'label' => __('Yes') + ), + array('value' => '', 'label' => __('No')) + ); + + $this->assertEquals($expectedResult, $this->_model->toOptionArray()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/Store/SwitcherPluginTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/Store/SwitcherPluginTest.php new file mode 100644 index 0000000000000..3e37385c2279e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/Store/SwitcherPluginTest.php @@ -0,0 +1,65 @@ +_model = new SwitcherPlugin(); + } + + /** + * @param null|string $countryParam + * @param array $getUrlParams + * @dataProvider aroundGetUrlDataProvider + */ + public function testAroundGetUrl($countryParam, $getUrlParams) + { + $subjectRequest = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface'); + $subjectRequest->expects($this->once()) + ->method('getParam') + ->with(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY) + ->will($this->returnValue($countryParam)); + $subject = $this->getMock('Magento\Backend\Block\Store\Switcher', ['getRequest'], [], '', false); + $subject->expects($this->any())->method('getRequest')->will($this->returnValue($subjectRequest)); + $getUrl = function ($route, $params) { + return [$route, $params]; + }; + $this->assertEquals(['', $getUrlParams], $this->_model->aroundGetUrl($subject, $getUrl, '', [])); + } + + public function aroundGetUrlDataProvider() + { + return [ + ['any value', [\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY => null]], + [null, []] + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Field/CountryTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Field/CountryTest.php new file mode 100644 index 0000000000000..401be38904deb --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Field/CountryTest.php @@ -0,0 +1,147 @@ +_element = $this->getMockForAbstractClass( + 'Magento\Framework\Data\Form\Element\AbstractElement', + [], + '', + false, + true, + true, + ['getHtmlId', 'getElementHtml', 'getName'] + ); + $this->_element->expects($this->any()) + ->method('getHtmlId') + ->will($this->returnValue('html id')); + $this->_element->expects($this->any()) + ->method('getElementHtml') + ->will($this->returnValue('element html')); + $this->_element->expects($this->any()) + ->method('getName') + ->will($this->returnValue('name')); + $this->_request = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface'); + $this->_jsHelper = $this->getMock('Magento\Framework\View\Helper\Js', [], [], '', false); + $this->_url = $this->getMock('Magento\Backend\Model\Url', [], [], '', false); + $this->_model = $helper->getObject( + 'Magento\Paypal\Block\Adminhtml\System\Config\Field\Country', + ['request' => $this->_request, 'jsHelper' => $this->_jsHelper, 'url' => $this->_url] + ); + } + + /** + * @param null|string $requestCountry + * @param null|string $requestDefaultCountry + * @param bool $canUseDefault + * @param bool $inherit + * @dataProvider renderDataProvider + */ + public function testRender($requestCountry, $requestDefaultCountry, $canUseDefault, $inherit) + { + $this->_request->expects($this->any()) + ->method('getParam') + ->will($this->returnCallback(function ($param) use ($requestCountry, $requestDefaultCountry) { + if ($param == \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY) { + return $requestCountry; + } + if ($param == Country::REQUEST_PARAM_DEFAULT_COUNTRY) { + return $requestDefaultCountry; + } + return $param; + })); + $this->_element->setInherit($inherit); + $this->_element->setCanUseDefaultValue($canUseDefault); + $constraints = [ + new \PHPUnit_Framework_Constraint_StringContains('document.observe("dom:loaded", function() {'), + new \PHPUnit_Framework_Constraint_StringContains( + '$("' . $this->_element->getHtmlId() . '").observe("change", function () {' + ) + ]; + if ($canUseDefault && ($requestCountry == 'US') && $requestDefaultCountry) { + $constraints[] = new \PHPUnit_Framework_Constraint_StringContains( + '$("' . $this->_element->getHtmlId() . '_inherit").observe("click", function () {' + ); + } + $this->_jsHelper->expects($this->once()) + ->method('getScript') + ->with(new \PHPUnit_Framework_Constraint_And($constraints)); + $this->_url->expects($this->once()) + ->method('getUrl') + ->with( + '*/*/*', + [ + 'section' => 'section', + 'website' => 'website', + 'store' => 'store', + \Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY => '__country__' + ] + ); + $this->_model->render($this->_element); + } + + public function renderDataProvider() + { + return [ + [null, null, false, false], + [null, null, true, true], + [null, null, true, false], + ['IT', null, true, false], + ['IT', null, true, true], + ['IT', 'GB', true, false], + ['US', 'GB', true, true], + ['US', 'GB', true, false], + ['US', null, true, false], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/GroupTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/GroupTest.php new file mode 100644 index 0000000000000..61c40926e1e1e --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/GroupTest.php @@ -0,0 +1,121 @@ +_group = $this->getMock('Magento\Backend\Model\Config\Structure\Element\Group', [], [], '', false); + $this->_element = $this->getMockForAbstractClass( + 'Magento\Framework\Data\Form\Element\AbstractElement', + [], + '', + false, + true, + true, + ['getHtmlId', 'getElementHtml', 'getName', 'getElements', 'getId'] + ); + $this->_element->expects($this->any()) + ->method('getHtmlId') + ->will($this->returnValue('html id')); + $this->_element->expects($this->any()) + ->method('getElementHtml') + ->will($this->returnValue('element html')); + $this->_element->expects($this->any()) + ->method('getName') + ->will($this->returnValue('name')); + $this->_element->expects($this->any()) + ->method('getElements') + ->will($this->returnValue([])); + $this->_element->expects($this->any()) + ->method('getId') + ->will($this->returnValue('id')); + $this->_user = $this->getMock('Magento\User\Model\User', [], [], '', false); + $this->_authSession = $this->getMock('Magento\Backend\Model\Auth\Session', [], [], '', false); + $this->_authSession->expects($this->any()) + ->method('__call') + ->with('getUser') + ->will($this->returnValue($this->_user)); + $this->_model = $helper->getObject( + 'Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Group', + ['authSession' => $this->_authSession] + ); + $this->_model->setGroup($this->_group); + } + + /** + * @param mixed $expanded + * @param int $expected + * @dataProvider isCollapseStateDataProvider + */ + public function testIsCollapseState($expanded, $expected) + { + $this->_user->setExtra(['configState' => []]); + $this->_element->setGroup(isset($expanded) ? ['expanded' => $expanded] : []); + $html = $this->_model->render($this->_element); + $this->assertContains( + '', + $html + ); + } + + public function isCollapseStateDataProvider() + { + return [ + [null, 0], + [false, 0], + ['', 0], + [1, 1], + ['1', 1], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/PaymentTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/PaymentTest.php new file mode 100644 index 0000000000000..50f5dd6439985 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Block/Adminhtml/System/Config/Fieldset/PaymentTest.php @@ -0,0 +1,144 @@ +_group = $this->getMock('Magento\Backend\Model\Config\Structure\Element\Group', [], [], '', false); + $this->_element = $this->getMockForAbstractClass( + 'Magento\Framework\Data\Form\Element\AbstractElement', + [], + '', + false, + true, + true, + ['getHtmlId', 'getElementHtml', 'getName', 'getElements', 'getId'] + ); + $this->_element->expects($this->any()) + ->method('getHtmlId') + ->will($this->returnValue('html id')); + $this->_element->expects($this->any()) + ->method('getElementHtml') + ->will($this->returnValue('element html')); + $this->_element->expects($this->any()) + ->method('getName') + ->will($this->returnValue('name')); + $this->_element->expects($this->any()) + ->method('getElements') + ->will($this->returnValue([])); + $this->_element->expects($this->any()) + ->method('getId') + ->will($this->returnValue('id')); + $this->_backendConfig = $this->getMock('Magento\Backend\Model\Config', [], [], '', false); + $this->_model = $helper->getObject( + 'Magento\Paypal\Block\Adminhtml\System\Config\Fieldset\Payment', + ['backendConfig' => $this->_backendConfig] + ); + $this->_model->setGroup($this->_group); + } + + /** + * @dataProvider isPaymentEnabledDataProvider + */ + public function testIsPaymentEnabled($groupConfig, $expected) + { + $this->_element->setGroup($groupConfig); + $this->_backendConfig->expects($this->any()) + ->method('getConfigDataValue') + ->will($this->returnValueMap( + [[self::CONFIG_PATH_ACTIVE, null, null, '1'], [self::CONFIG_PATH_NOT_ACTIVE, null, null, '0']] + )); + $html = $this->_model->render($this->_element); + $this->assertContains($expected, $html); + } + + public function isPaymentEnabledDataProvider() + { + return [ + [[], ' class="section-config with-button">'], + [['fieldset_css' => 'any-css'], ' class="section-config any-css with-button">'], + [['activity_path' => self::CONFIG_PATH_ACTIVE], ' class="section-config with-button enabled">'], + [['activity_path' => self::CONFIG_PATH_NOT_ACTIVE], ' class="section-config with-button">'], + [['activity_path' => [self::CONFIG_PATH_ACTIVE]], ' class="section-config with-button enabled">'], + [['activity_path' => [self::CONFIG_PATH_NOT_ACTIVE]], ' class="section-config with-button">'], + [ + ['activity_path' => [self::CONFIG_PATH_ACTIVE, self::CONFIG_PATH_NOT_ACTIVE]], + ' class="section-config with-button enabled">' + ], + [ + ['activity_path' => self::CONFIG_PATH_ACTIVE, 'fieldset_css' => 'any-css'], + ' class="section-config any-css with-button enabled">' + ], + [ + ['activity_path' => self::CONFIG_PATH_NOT_ACTIVE, 'fieldset_css' => 'any-css'], + ' class="section-config any-css with-button">' + ], + [ + ['activity_path' => [self::CONFIG_PATH_ACTIVE], 'fieldset_css' => 'any-css'], + ' class="section-config any-css with-button enabled">' + ], + [ + ['activity_path' => [self::CONFIG_PATH_NOT_ACTIVE], 'fieldset_css' => 'any-css'], + ' class="section-config any-css with-button">' + ], + [ + [ + 'activity_path' => [self::CONFIG_PATH_ACTIVE, self::CONFIG_PATH_NOT_ACTIVE], + 'fieldset_css' => 'any-css' + ], + ' class="section-config any-css with-button enabled">' + ], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Helper/BackendTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Helper/BackendTest.php new file mode 100644 index 0000000000000..92e487637b75a --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Helper/BackendTest.php @@ -0,0 +1,150 @@ +_request = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface'); + $this->_coreHelper = $this->getMock('Magento\Core\Helper\Data', [], [], '', false); + $this->_backendConfig = $this->getMock('Magento\Backend\Model\Config', [], [], '', false); + + $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->_helper = $objectManager->getObject( + 'Magento\Paypal\Helper\Backend', + [ + 'httpRequest' => $this->_request, + 'coreHelper' => $this->_coreHelper, + 'backendConfig' => $this->_backendConfig + ] + ); + } + + public function testGetConfigurationCountryCodeFromRequest() + { + $this->_configurationCountryCodePrepareRequest('US'); + $this->_configurationCountryCodeAssertResult('US'); + } + + /** + * @param string|null $request + * @dataProvider getConfigurationCountryCodeFromConfigDataProvider + */ + public function testGetConfigurationCountryCodeFromConfig($request) + { + $this->_configurationCountryCodePrepareRequest($request); + $this->_configurationCountryCodePrepareConfig('GB'); + $this->_configurationCountryCodeAssertResult('GB'); + } + + public function getConfigurationCountryCodeFromConfigDataProvider() + { + return [ + [null], + ['not country code'], + ]; + } + + /** + * @param string|null $request + * @param string|null|false $config + * @param string|null $default + * @dataProvider getConfigurationCountryCodeFromDefaultDataProvider + */ + public function testGetConfigurationCountryCodeFromDefault($request, $config, $default) + { + $this->_configurationCountryCodePrepareRequest($request); + $this->_configurationCountryCodePrepareConfig($config); + $this->_coreHelper->expects($this->once()) + ->method('getDefaultCountry') + ->will($this->returnValue($default)); + $this->_configurationCountryCodeAssertResult($default); + } + + public function getConfigurationCountryCodeFromDefaultDataProvider() + { + return [ + [null, false, 'DE'], + ['not country code', false, 'DE'], + ['not country code', '', 'any final result'] + ]; + } + + /** + * Prepare request for test + * + * @param string|null $request + */ + private function _configurationCountryCodePrepareRequest($request) + { + $this->_request->expects($this->once()) + ->method('getParam') + ->with(\Magento\Paypal\Model\Config\StructurePlugin::REQUEST_PARAM_COUNTRY) + ->will($this->returnValue($request)); + } + + /** + * Prepare backend config for test + * + * @param string|null|false $config + */ + private function _configurationCountryCodePrepareConfig($config) + { + $this->_backendConfig->expects($this->once()) + ->method('getConfigDataValue') + ->with(\Magento\Paypal\Block\Adminhtml\System\Config\Field\Country::FIELD_CONFIG_PATH) + ->will($this->returnValue($config)); + } + + /** + * Assert result of getConfigurationCountryCode method + * + * @param string $expected + */ + private function _configurationCountryCodeAssertResult($expected) + { + $this->assertEquals($expected, $this->_helper->getConfigurationCountryCode()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/Structure/Element/FieldPluginTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/Structure/Element/FieldPluginTest.php new file mode 100644 index 0000000000000..e77bb080da7c0 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/Structure/Element/FieldPluginTest.php @@ -0,0 +1,100 @@ +request = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface'); + $this->subject = $this->getMock('Magento\Backend\Model\Config\Structure\Element\Field', [], [], '', false); + + $helper = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->model = $helper->getObject( + 'Magento\Paypal\Model\Config\Structure\Element\FieldPlugin', + ['request' => $this->request] + ); + } + + public function testAroundGetConfigPathHasResult() + { + $someResult = 'some result'; + $callback = function () use ($someResult) { + return $someResult; + }; + $this->assertEquals($someResult, $this->model->aroundGetConfigPath($this->subject, $callback)); + } + + public function testAroundGetConfigPathNonPaymentSection() + { + $callback = function () { + return null; + }; + $this->request->expects($this->once()) + ->method('getParam') + ->with('section') + ->will($this->returnValue('non-payment')); + $this->assertNull($this->model->aroundGetConfigPath($this->subject, $callback)); + } + + /** + * @param string $subjectPath + * @param string $expectedConfigPath + * @dataProvider aroundGetConfigPathDataProvider + */ + public function testAroundGetConfigPath($subjectPath, $expectedConfigPath) + { + $callback = function () { + return null; + }; + $this->request->expects($this->once()) + ->method('getParam') + ->with('section') + ->will($this->returnValue('payment')); + $this->subject->expects($this->once()) + ->method('getPath') + ->will($this->returnValue($subjectPath)); + $this->assertEquals($expectedConfigPath, $this->model->aroundGetConfigPath($this->subject, $callback)); + } + + public function aroundGetConfigPathDataProvider() + { + return [ + ['payment_us/group/field', 'payment/group/field'], + ['payment_other/group/field', 'payment/group/field'], + ['payment_us', 'payment_us'], + ['payment_wrong_country/group/field', 'payment_wrong_country/group/field'], + ]; + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/StructurePluginTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/StructurePluginTest.php new file mode 100644 index 0000000000000..413ae0e44934b --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/Config/StructurePluginTest.php @@ -0,0 +1,222 @@ +_scopeDefiner = $this->getMock('Magento\Backend\Model\Config\ScopeDefiner', [], [], '', false); + $this->_helper = $this->getMock('Magento\Paypal\Helper\Backend', [], [], '', false); + + $objectManagerHelper = new ObjectManagerHelper($this); + $this->_model = $objectManagerHelper->getObject( + 'Magento\Paypal\Model\Config\StructurePlugin', + ['scopeDefiner' => $this->_scopeDefiner, 'helper' => $this->_helper] + ); + } + + public function testGetPaypalConfigCountriesWithOther() + { + $countries = StructurePlugin::getPaypalConfigCountries(true); + $this->assertContains('payment_us', $countries); + $this->assertContains('payment_other', $countries); + } + + public function testGetPaypalConfigCountries() + { + $countries = StructurePlugin::getPaypalConfigCountries(false); + $this->assertContains('payment_us', $countries); + $this->assertNotContains('payment_other', $countries); + } + + /** + * @param array $pathParts + * @param bool $returnResult + * @dataProvider aroundGetElementByPathPartsNonPaymentDataProvider + */ + public function testAroundGetElementByPathPartsNonPayment($pathParts, $returnResult) + { + $result = $returnResult + ? $this->getMockForAbstractClass('Magento\Backend\Model\Config\Structure\ElementInterface') + : null; + $this->_aroundGetElementByPathPartsAssertResult( + $result, + $this->_getElementByPathPartsCallback($pathParts, $result), + $pathParts + ); + } + + public function aroundGetElementByPathPartsNonPaymentDataProvider() + { + return [ + [['non-payment', 'group1', 'group2', 'field'], true], + [['non-payment'], true], + [['non-payment', 'group1', 'group2', 'field'], false], + [['non-payment'], false], + ]; + } + + /** + * @param array $pathParts + * @param string $countryCode + * @param array $expectedPathParts + * @dataProvider aroundGetElementByPathPartsDataProvider + */ + public function testAroundGetElementByPathPartsNoResult($pathParts, $countryCode, $expectedPathParts) + { + $this->_getElementByPathPartsPrepareHelper($countryCode); + $this->_aroundGetElementByPathPartsAssertResult( + null, + $this->_getElementByPathPartsCallback($expectedPathParts, null), + $pathParts + ); + } + + /** + * @param array $pathParts + * @param string $countryCode + * @param array $expectedPathParts + * @dataProvider aroundGetElementByPathPartsDataProvider + */ + public function testAroundGetElementByPathParts($pathParts, $countryCode, $expectedPathParts) + { + $this->_getElementByPathPartsPrepareHelper($countryCode); + $result = $this->getMockForAbstractClass('Magento\Backend\Model\Config\Structure\ElementInterface'); + $this->_aroundGetElementByPathPartsAssertResult( + $result, + $this->_getElementByPathPartsCallback($expectedPathParts, $result), + $pathParts + ); + } + + public function aroundGetElementByPathPartsDataProvider() + { + return [ + [ + ['payment', 'group1', 'group2', 'field'], + 'any', + ['payment_other', 'group1', 'group2', 'field'] + ], + [ + ['payment', 'group1', 'group2', 'field'], + 'DE', + ['payment_de', 'group1', 'group2', 'field'] + ], + ]; + } + + /** + * @param array $pathParts + * @param string $countryCode + * @param array $expectedPathParts + * @dataProvider aroundGetSectionByPathPartsDataProvider + */ + public function testAroundGetSectionByPathParts($pathParts, $countryCode, $expectedPathParts) + { + $this->_getElementByPathPartsPrepareHelper($countryCode); + $result = $this->getMock('Magento\Backend\Model\Config\Structure\Element\Section', [], [], '', false); + $self = $this; + $getElementByPathParts = function ($pathParts) use ($self, $expectedPathParts, $result) { + $self->assertEquals($expectedPathParts, $pathParts); + $scope = 'any scope'; + $self->_scopeDefiner->expects($self->once()) + ->method('getScope') + ->will($self->returnValue($scope)); + $result->expects($self->once()) + ->method('getData') + ->will($self->returnValue([])); + $result->expects($self->once()) + ->method('setData') + ->with(['showInDefault' => true, 'showInWebsite' => true, 'showInStore' => true], $scope) + ->will($self->returnSelf()); + return $result; + }; + $this->_aroundGetElementByPathPartsAssertResult($result, $getElementByPathParts, $pathParts); + } + + public function aroundGetSectionByPathPartsDataProvider() + { + return [ + [['payment'], 'GB', ['payment_gb']], + [['payment'], 'any', ['payment_other']], + ]; + } + + /** + * Assert result of aroundGetElementByPathParts method + * + * @param \PHPUnit_Framework_MockObject_MockObject|null $result + * @param \Closure $getElementByPathParts + * @param array $pathParts + */ + private function _aroundGetElementByPathPartsAssertResult($result, $getElementByPathParts, $pathParts) + { + $this->assertEquals($result, $this->_model->aroundGetElementByPathParts( + $this->getMock('Magento\Backend\Model\Config\Structure', [], [], '', false), + $getElementByPathParts, + $pathParts + )); + } + + /** + * Get callback for aroundGetElementByPathParts method + * + * @param array $expectedPathParts + * @param \PHPUnit_Framework_MockObject_MockObject|null $result + * @return \Closure + */ + private function _getElementByPathPartsCallback($expectedPathParts, $result) + { + $self = $this; + return function ($pathParts) use ($self, $expectedPathParts, $result) { + $self->assertEquals($expectedPathParts, $pathParts); + return $result; + }; + } + + /** + * Prepare helper for test + * + * @param string $countryCode + */ + private function _getElementByPathPartsPrepareHelper($countryCode) + { + $this->_helper->expects($this->once()) + ->method('getConfigurationCountryCode') + ->will($this->returnValue($countryCode)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/ConfigTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/ConfigTest.php new file mode 100644 index 0000000000000..e64f6667d711c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/ConfigTest.php @@ -0,0 +1,76 @@ +_model = $helper->getObject('Magento\Paypal\Model\Config'); + } + + public function testGetCountryMethods() + { + $this->assertNotContains('payflow_direct', $this->_model->getCountryMethods('GB')); + $this->assertContains(Config::METHOD_WPP_PE_EXPRESS, $this->_model->getCountryMethods('CA')); + $this->assertNotContains(Config::METHOD_WPP_PE_EXPRESS, $this->_model->getCountryMethods('GB')); + $this->assertContains(Config::METHOD_WPP_PE_EXPRESS, $this->_model->getCountryMethods('CA')); + $this->assertContains(Config::METHOD_WPP_EXPRESS, $this->_model->getCountryMethods('DE')); + $this->assertContains(Config::METHOD_BILLING_AGREEMENT, $this->_model->getCountryMethods('DE')); + } + + public function testGetBuildNotationCode() + { + $this->_model->setMethod('payflow_direct'); + $this->assertEquals('Magento_Cart_WPP_some-country', $this->_model->getBuildNotationCode('some-country')); + } + + public function testIsMethodActive() + { + $this->assertFalse($this->_model->isMethodActive('payflow_direct')); + } + + public function testIsMethodAvailable() + { + $this->assertFalse($this->_model->isMethodAvailable('payflow_direct')); + } + + public function testIsCreditCardMethod() + { + $this->assertFalse($this->_model->getIsCreditCardMethod('payflow_direct')); + } + + public function testGetSpecificConfigPath() + { + $this->_model->setMethod('payflow_direct'); + $this->assertNull($this->_model->getConfigValue('useccv')); + $this->assertNull($this->_model->getConfigValue('vendor')); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/InfoTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/InfoTest.php new file mode 100644 index 0000000000000..1b32051c8e100 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/InfoTest.php @@ -0,0 +1,278 @@ +objectManagerHelper = new ObjectManagerHelper($this); + $this->info = $this->objectManagerHelper->getObject( + 'Magento\Paypal\Model\Info' + ); + } + + /** + * @dataProvider additionalInfoDataProvider + * @param array $additionalInfo + * @param array $expectation + */ + public function testGetPaymentInfo($additionalInfo, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($additionalInfo); + $this->assertEquals($expectation, $this->info->getPaymentInfo($paymentInfo)); + } + + /** + * @dataProvider additionalInfoDataProvider + * @param array $additionalInfo + * @param array $expectation + */ + public function testGetPaymentInfoLabelValues($additionalInfo, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($additionalInfo); + $this->assertEquals( + $this->_prepareLabelValuesExpectation($expectation), + $this->info->getPaymentInfo($paymentInfo, true) + ); + } + + /** + * @dataProvider additionalInfoPublicDataProvider + * @param array $additionalInfo + * @param array $expectation + */ + public function testGetPublicPaymentInfo($additionalInfo, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($additionalInfo); + $this->assertEquals( + $this->_prepareLabelValuesExpectation($expectation), + $this->info->getPublicPaymentInfo($paymentInfo, true) + ); + } + + /** + * @dataProvider additionalInfoPublicDataProvider + * @param array $additionalInfo + * @param array $expectation + */ + public function testGetPublicPaymentInfoLabelValues($additionalInfo, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($additionalInfo); + $this->assertEquals($expectation, $this->info->getPublicPaymentInfo($paymentInfo)); + } + + /** + * @dataProvider importToPaymentDataProvider + * @param array $mapping + * @param array $expectation + */ + public function testImportToPayment($mapping, $expectation) + { + // we create $from object, based on mapping + $from = new \Magento\Framework\Object($mapping); + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $this->info->importToPayment($from, $paymentInfo); + $this->assertEquals($expectation, $paymentInfo->getAdditionalInformation()); + } + + /** + * @dataProvider importToPaymentDataProvider + * @param array $mapping + * @param array $expectation + */ + public function testExportFromPayment($mapping, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($expectation); + + // we create $to empty object + $to = new \Magento\Framework\Object(); + $this->info->exportFromPayment($paymentInfo, $to); + $this->assertEquals($mapping, $to->getData()); + } + + /** + * @dataProvider importToPaymentDataProvider + * @param array $mapping + * @param array $expectation + */ + public function testExportFromPaymentCustomMapping($mapping, $expectation) + { + /** @var \Magento\Payment\Model\Info $paymentInfo */ + $paymentInfo = $this->objectManagerHelper->getObject('Magento\Payment\Model\Info'); + $paymentInfo->setAdditionalInformation($expectation); + + // we create $to empty object + $to = new \Magento\Framework\Object(); + $this->info->exportFromPayment($paymentInfo, $to, array_flip($mapping)); + $this->assertEquals($mapping, $to->getData()); + } + + /** + * Converts expectation result from ['key' => ['label' => 'Label', 'value' => 'Value']] to ['Label' => 'Value'] + * + * @param $expectation + * @return array + */ + private function _prepareLabelValuesExpectation($expectation) + { + $labelValueExpectation = []; + foreach ($expectation as $data) { + $labelValueExpectation[$data['label']] = $data['value']; + } + return $labelValueExpectation; + } + + /** + * List of Labels + * + * @return array + */ + public function additionalInfoDataProvider() + { + return include __DIR__ . '/_files/additional_info_data.php'; + } + + /** + *List of public labels + * + * @return array + */ + public function additionalInfoPublicDataProvider() + { + return [ + [ + [ + Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE_CNPJ + ], + [ + Info::PAYPAL_PAYER_EMAIL => [ + 'label' => 'Payer Email', + 'value' => Info::PAYPAL_PAYER_EMAIL, + ], + Info::BUYER_TAX_ID => [ + 'label' => 'Buyer\'s Tax ID', + 'value' => Info::BUYER_TAX_ID, + ], + Info::BUYER_TAX_ID_TYPE => [ + 'label' => 'Buyer\'s Tax ID Type', + 'value' => 'CNPJ', + ] + ] + ], + [ + [ + Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE + ], + [ + Info::PAYPAL_PAYER_EMAIL => [ + 'label' => 'Payer Email', + 'value' => Info::PAYPAL_PAYER_EMAIL, + ], + Info::BUYER_TAX_ID => [ + 'label' => 'Buyer\'s Tax ID', + 'value' => Info::BUYER_TAX_ID, + ] + ] + ] + ]; + } + + /** + * Mapping and expectation + * + * @return array + */ + public function importToPaymentDataProvider() + { + return [ + [ + [ + Info::PAYER_ID => Info::PAYPAL_PAYER_ID, + Info::PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::PAYER_STATUS => Info::PAYPAL_PAYER_STATUS, + Info::ADDRESS_ID => Info::PAYPAL_ADDRESS_ID, + Info::ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS, + Info::PROTECTION_EL => Info::PAYPAL_PROTECTION_ELIGIBILITY, + Info::FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS, + Info::CORRELATION_ID => Info::PAYPAL_CORRELATION_ID, + Info::AVS_CODE => Info::PAYPAL_AVS_CODE, + Info::CVV2_MATCH => Info::PAYPAL_CVV2_MATCH, + Info::CENTINEL_VPAS => Info::CENTINEL_VPAS, + Info::CENTINEL_ECI => Info::CENTINEL_ECI, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE, + Info::PAYMENT_STATUS => Info::PAYMENT_STATUS_GLOBAL, + Info::PENDING_REASON => Info::PENDING_REASON_GLOBAL, + Info::IS_FRAUD => Info::IS_FRAUD_GLOBAL + ], + [ + Info::PAYPAL_PAYER_ID => Info::PAYPAL_PAYER_ID, + Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::PAYPAL_PAYER_STATUS => Info::PAYPAL_PAYER_STATUS, + Info::PAYPAL_ADDRESS_ID => Info::PAYPAL_ADDRESS_ID, + Info::PAYPAL_ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS, + Info::PAYPAL_PROTECTION_ELIGIBILITY => Info::PAYPAL_PROTECTION_ELIGIBILITY, + Info::PAYPAL_FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS, + Info::PAYPAL_CORRELATION_ID => Info::PAYPAL_CORRELATION_ID, + Info::PAYPAL_AVS_CODE => Info::PAYPAL_AVS_CODE, + Info::PAYPAL_CVV2_MATCH => Info::PAYPAL_CVV2_MATCH, + Info::CENTINEL_VPAS => Info::CENTINEL_VPAS, + Info::CENTINEL_ECI => Info::CENTINEL_ECI, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE, + Info::PAYMENT_STATUS_GLOBAL => Info::PAYMENT_STATUS_GLOBAL, + Info::PENDING_REASON_GLOBAL => Info::PENDING_REASON_GLOBAL, + Info::IS_FRAUD_GLOBAL => Info::IS_FRAUD_GLOBAL + ] + ] + ]; + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php index a987d9765da3b..3945c6e4e91f5 100644 --- a/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/IpnTest.php @@ -29,91 +29,125 @@ class IpnTest extends \PHPUnit_Framework_TestCase { - const REQUEST_MC_GROSS = 38.12; - /** * @var \Magento\Paypal\Model\Ipn */ protected $_ipn; - protected function setUp() - { - $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->_ipn = $objectHelper->getObject('Magento\Paypal\Model\Ipn'); - } + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_orderMock; /** - * Prepare order property for ipn model - * - * @param \Magento\Paypal\Model\Ipn|\PHPUnit_Framework_MockObject_MockObject $ipn - * @return \PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject */ - protected function _prepareIpnOrderProperty($ipn) + protected $_paypalInfo; + + protected function setUp() { - // Create payment and order mocks - $payment = $this->getMockBuilder('Magento\Sales\Model\Order\Payment')->disableOriginalConstructor()->getMock(); - $order = $this->getMockBuilder('Magento\Sales\Model\Order')->disableOriginalConstructor()->getMock(); - $order->expects($this->any())->method('getPayment')->will($this->returnValue($payment)); + $methods = [ + 'create', + 'loadByIncrementId', + 'canFetchPaymentReviewUpdate', + 'getId', + 'getPayment', + 'getMethod', + 'getStoreId', + 'registerPaymentReviewAction', + 'getAdditionalInformation', + 'getEmailSent', + 'save' + ]; + $this->_orderMock = $this->getMock('Magento\Sales\Model\OrderFactory', $methods, [], '', false); + $this->_orderMock->expects($this->any())->method('create')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('loadByIncrementId')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('getId')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('getMethod')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('getStoreId')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('getEmailSent')->will($this->returnValue(true)); - // Set order to ipn - $orderProperty = new \ReflectionProperty('Magento\Paypal\Model\Ipn', '_order'); - $orderProperty->setAccessible(true); - $orderProperty->setValue($ipn, $order); + $configFactory = $this->getMock( + 'Magento\Paypal\Model\ConfigFactory', + ['create', 'isMethodActive', 'isMethodAvailable', 'getConfigValue', 'getPaypalUrl'], + [], + '', + false + ); + $configFactory->expects($this->any())->method('create')->will($this->returnSelf()); + $configFactory->expects($this->any())->method('isMethodActive')->will($this->returnValue(true)); + $configFactory->expects($this->any())->method('isMethodAvailable')->will($this->returnValue(true)); + $configFactory->expects($this->any())->method('getConfigValue')->will($this->returnValue(null)); + $configFactory->expects($this->any())->method('getPaypalUrl')->will($this->returnValue('http://paypal_url')); - return $order; + $curlFactory = $this->getMock( + 'Magento\Framework\HTTP\Adapter\CurlFactory', + ['create', 'setConfig', 'write', 'read'], + [], + '', + false + ); + $curlFactory->expects($this->any())->method('create')->will($this->returnSelf()); + $curlFactory->expects($this->any())->method('setConfig')->will($this->returnSelf()); + $curlFactory->expects($this->any())->method('write')->will($this->returnSelf()); + $curlFactory->expects($this->any())->method('read')->will($this->returnValue( + ' + VERIFIED' + )); + $this->_paypalInfo = $this->getMock( + 'Magento\Paypal\Model\Info', + ['importToPayment', 'getMethod', 'getAdditionalInformation'], + [], + '', + false + ); + $this->_paypalInfo->expects($this->any())->method('getMethod')->will($this->returnValue('some_method')); + $objectHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->_ipn = $objectHelper->getObject('Magento\Paypal\Model\Ipn', + [ + 'configFactory' => $configFactory, + 'logAdapterFactory' => $this->getMock('Magento\Framework\Logger\AdapterFactory', [], [], '', false), + 'curlFactory' => $curlFactory, + 'orderFactory' => $this->_orderMock, + 'paypalInfo' => $this->_paypalInfo, + 'data' => ['payment_status' => 'Pending', 'pending_reason' => 'authorization'] + ] + ); } public function testLegacyRegisterPaymentAuthorization() { - $order = $this->_prepareIpnOrderProperty($this->_ipn); - $order->expects($this->once())->method('canFetchPaymentReviewUpdate')->will($this->returnValue(false)); - $payment = $order->getPayment(); - $payment->expects( - $this->once() - )->method( - 'registerAuthorizationNotification' - )->with( - $this->equalTo(self::REQUEST_MC_GROSS) + $this->_orderMock->expects($this->any())->method('canFetchPaymentReviewUpdate')->will( + $this->returnValue(false) ); - $payment->expects($this->any())->method('__call')->will($this->returnSelf()); - - // Create info mock - $info = $this->getMock('Magento\Paypal\Model\Info'); - $info->expects($this->once())->method('importToPayment'); - - // Set request to ipn - $requestProperty = new \ReflectionProperty('Magento\Paypal\Model\Ipn', '_ipnRequest'); - $requestProperty->setAccessible(true); - $requestProperty->setValue($this->_ipn, array('mc_gross' => self::REQUEST_MC_GROSS)); - - // Set info to ipn - $infoProperty = new \ReflectionProperty('Magento\Paypal\Model\Ipn', '_paypalInfo'); - $infoProperty->setAccessible(true); - $infoProperty->setValue($this->_ipn, $info); + $methods = [ + 'setPreparedMessage', + '__wakeup', + 'setTransactionId', + 'setParentTransactionId', + 'setIsTransactionClosed', + 'registerAuthorizationNotification' + ]; + $payment = $this->getMock('Magento\Sales\Model\Order\Payment', $methods, [], '', false); + $payment->expects($this->any())->method('setPreparedMessage')->will($this->returnSelf()); + $payment->expects($this->any())->method('setTransactionId')->will($this->returnSelf()); + $payment->expects($this->any())->method('setParentTransactionId')->will($this->returnSelf()); + $payment->expects($this->any())->method('setIsTransactionClosed')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('getPayment')->will($this->returnValue($payment)); + $this->_orderMock->expects($this->any())->method('getAdditionalInformation')->will($this->returnValue(array())); - $testMethod = new \ReflectionMethod('Magento\Paypal\Model\Ipn', '_registerPaymentAuthorization'); - $testMethod->setAccessible(true); - $this->markTestIncomplete( - 'MAGETWO-23755: "Fatal error: Using $this when not in object context" is observed under PHPUnit4' - ); - $testMethod->invoke($this->_ipn); + $this->_paypalInfo->expects($this->once())->method('importToPayment'); + $this->_ipn->processIpnRequest(); } public function testPaymentReviewRegisterPaymentAuthorization() { - $order = $this->_prepareIpnOrderProperty($this->_ipn); - $order->expects($this->once())->method('canFetchPaymentReviewUpdate')->will($this->returnValue(true)); - $order->getPayment()->expects( - $this->once() - )->method( - 'registerPaymentReviewAction' - )->with( - $this->equalTo(\Magento\Sales\Model\Order\Payment::REVIEW_ACTION_UPDATE), - $this->equalTo(true) - ); - - $testMethod = new \ReflectionMethod('Magento\Paypal\Model\Ipn', '_registerPaymentAuthorization'); - $testMethod->setAccessible(true); - $testMethod->invoke($this->_ipn); + $this->_orderMock->expects($this->any())->method('getPayment')->will($this->returnSelf()); + $this->_orderMock->expects($this->any())->method('canFetchPaymentReviewUpdate')->will($this->returnValue(true)); + $this->_orderMock->expects($this->once())->method('registerPaymentReviewAction')->with( + 'update', + true + )->will($this->returnSelf()); + $this->_ipn->processIpnRequest(); } } diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/Method/AgreementTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/Method/AgreementTest.php index 657470e930af7..f92d1e643f16b 100644 --- a/dev/tests/unit/testsuite/Magento/Paypal/Model/Method/AgreementTest.php +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/Method/AgreementTest.php @@ -47,7 +47,7 @@ protected function setUp() $paypalConfigMock = $this->getMockBuilder( '\Magento\Paypal\Model\Config' )->disableOriginalConstructor()->setMethods( - array('__get') + array('getConfigValue') )->getMock(); $this->_apiNvpMock = $this->getMockBuilder( '\Magento\Paypal\Model\Api\Nvp' diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/PayflowExpressTest.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/PayflowExpressTest.php new file mode 100644 index 0000000000000..9ddcf127db8a4 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/PayflowExpressTest.php @@ -0,0 +1,117 @@ +getMockBuilder( + 'Magento\Paypal\Model\ProFactory' + )->disableOriginalConstructor()->setMethods(['create'])->getMock(); + $paypalPro = $this->getMockBuilder( + 'Magento\Paypal\Model\Pro' + )->disableOriginalConstructor()->setMethods([])->getMock(); + + $proFactory->expects($this->once())->method('create')->will($this->returnValue($paypalPro)); + + $this->_model = $objectManager->getObject('Magento\Paypal\Model\PayflowExpress', ['proFactory' => $proFactory]); + } + + public function testCanRefundCaptureNotExist() + { + $paymentInfo = $this->_getPreparedPaymentInfo(); + + $paymentInfo->expects($this->once())->method('lookupTransaction')->with('', Transaction::TYPE_CAPTURE)->will( + $this->returnValue(false) + ); + $this->assertFalse($this->_model->canRefund()); + } + + public function testCanRefundCaptureExistNoAdditionalInfo() + { + $paymentInfo = $this->_getPreparedPaymentInfo(); + $captureTransaction = $this->_getCaptureTransaction(); + $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with( + Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID + )->will($this->returnValue(null)); + $paymentInfo->expects($this->once())->method('lookupTransaction')->with('', Transaction::TYPE_CAPTURE)->will( + $this->returnValue($captureTransaction) + ); + $this->assertFalse($this->_model->canRefund()); + } + + public function testCanRefundCaptureExistValid() + { + $paymentInfo = $this->_getPreparedPaymentInfo(); + $captureTransaction = $this->_getCaptureTransaction(); + $captureTransaction->expects($this->once())->method('getAdditionalInformation')->with( + Payflow\Pro::TRANSPORT_PAYFLOW_TXN_ID + )->will($this->returnValue(self::TRANSPORT_PAYFLOW_TXN_ID)); + $paymentInfo->expects($this->once())->method('lookupTransaction')->with('', Transaction::TYPE_CAPTURE)->will( + $this->returnValue($captureTransaction) + ); + $this->assertTrue($this->_model->canRefund()); + } + + /** + * Prepares payment info mock and adds it to the model + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function _getPreparedPaymentInfo() + { + $paymentInfo = $this->getMockBuilder( + 'Magento\Sales\Model\Order\Payment' + )->disableOriginalConstructor()->setMethods([])->getMock(); + $this->_model->setData('info_instance', $paymentInfo); + return $paymentInfo; + } + + /** + * Prepares capture transaction + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function _getCaptureTransaction() + { + return $this->getMockBuilder( + 'Magento\Sales\Model\Order\Payment\Transaction' + )->disableOriginalConstructor()->setMethods([])->getMock(); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Paypal/Model/_files/additional_info_data.php b/dev/tests/unit/testsuite/Magento/Paypal/Model/_files/additional_info_data.php new file mode 100644 index 0000000000000..bcab4fedbdb3c --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Paypal/Model/_files/additional_info_data.php @@ -0,0 +1,183 @@ + Info::PAYPAL_PAYER_ID, + Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::PAYPAL_PAYER_STATUS => Info::PAYPAL_PAYER_STATUS, + Info::PAYPAL_ADDRESS_ID => Info::PAYPAL_ADDRESS_ID, + Info::PAYPAL_ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS, + Info::PAYPAL_PROTECTION_ELIGIBILITY => Info::PAYPAL_PROTECTION_ELIGIBILITY, + Info::PAYPAL_FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS, + Info::PAYPAL_CORRELATION_ID => Info::PAYPAL_CORRELATION_ID, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::PAYPAL_AVS_CODE => 'A', + Info::PAYPAL_CVV2_MATCH => 'M', + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE_CNPJ, + Info::CENTINEL_VPAS => '2', + Info::CENTINEL_ECI => '01' + ], + [ + Info::PAYPAL_PAYER_ID => [ + 'label' => 'Payer ID', + 'value' => Info::PAYPAL_PAYER_ID, + ], + Info::PAYPAL_PAYER_EMAIL => [ + 'label' => 'Payer Email', + 'value' => Info::PAYPAL_PAYER_EMAIL, + ], + Info::PAYPAL_PAYER_STATUS => [ + 'label' => 'Payer Status', + 'value' => Info::PAYPAL_PAYER_STATUS, + ], + Info::PAYPAL_ADDRESS_ID => [ + 'label' => 'Payer Address ID', + 'value' => Info::PAYPAL_ADDRESS_ID, + ], + Info::PAYPAL_ADDRESS_STATUS => [ + 'label' => 'Payer Address Status', + 'value' => Info::PAYPAL_ADDRESS_STATUS, + ], + Info::PAYPAL_PROTECTION_ELIGIBILITY => [ + 'label' => 'Merchant Protection Eligibility', + 'value' => Info::PAYPAL_PROTECTION_ELIGIBILITY, + ], + Info::PAYPAL_FRAUD_FILTERS => [ + 'label' => 'Triggered Fraud Filters', + 'value' => Info::PAYPAL_FRAUD_FILTERS, + ], + Info::PAYPAL_CORRELATION_ID => [ + 'label' => 'Last Correlation ID', + 'value' => Info::PAYPAL_CORRELATION_ID, + ], + Info::PAYPAL_AVS_CODE => [ + 'label' => 'Address Verification System Response', + 'value' => '#A: Matched Address only (no ZIP)', + ], + Info::PAYPAL_CVV2_MATCH => [ + 'label' => 'CVV2 Check Result by PayPal', + 'value' => '#M: Matched (CVV2CSC)', + ], + Info::CENTINEL_VPAS => [ + 'label' => 'PayPal/Centinel Visa Payer Authentication Service Result', + 'value' => '#2: Authenticated, Good Result', + ], + Info::CENTINEL_ECI => [ + 'label' => 'PayPal/Centinel Electronic Commerce Indicator', + 'value' => '#01: Merchant Liability', + ], + Info::BUYER_TAX_ID => [ + 'label' => 'Buyer\'s Tax ID', + 'value' => Info::BUYER_TAX_ID, + ], + Info::BUYER_TAX_ID_TYPE => [ + 'label' => 'Buyer\'s Tax ID Type', + 'value' => 'CNPJ', + ], + 'last_trans_id' => [ + 'label' => 'Last Transaction ID', + 'value' => NULL + ] + ] + ], + [ + [ + Info::PAYPAL_PAYER_ID => Info::PAYPAL_PAYER_ID, + Info::PAYPAL_PAYER_EMAIL => Info::PAYPAL_PAYER_EMAIL, + Info::PAYPAL_PAYER_STATUS => Info::PAYPAL_PAYER_STATUS, + Info::PAYPAL_ADDRESS_ID => Info::PAYPAL_ADDRESS_ID, + Info::PAYPAL_ADDRESS_STATUS => Info::PAYPAL_ADDRESS_STATUS, + Info::PAYPAL_PROTECTION_ELIGIBILITY => Info::PAYPAL_PROTECTION_ELIGIBILITY, + Info::PAYPAL_FRAUD_FILTERS => Info::PAYPAL_FRAUD_FILTERS, + Info::PAYPAL_CORRELATION_ID => Info::PAYPAL_CORRELATION_ID, + Info::BUYER_TAX_ID => Info::BUYER_TAX_ID, + Info::PAYPAL_AVS_CODE => Info::PAYPAL_AVS_CODE, + Info::PAYPAL_CVV2_MATCH => Info::PAYPAL_CVV2_MATCH, + Info::BUYER_TAX_ID_TYPE => Info::BUYER_TAX_ID_TYPE, + Info::CENTINEL_VPAS => Info::CENTINEL_VPAS, + Info::CENTINEL_ECI => Info::CENTINEL_ECI + ], + [ + Info::PAYPAL_PAYER_ID => [ + 'label' => 'Payer ID', + 'value' => Info::PAYPAL_PAYER_ID, + ], + Info::PAYPAL_PAYER_EMAIL => [ + 'label' => 'Payer Email', + 'value' => Info::PAYPAL_PAYER_EMAIL, + ], + Info::PAYPAL_PAYER_STATUS => [ + 'label' => 'Payer Status', + 'value' => Info::PAYPAL_PAYER_STATUS, + ], + Info::PAYPAL_ADDRESS_ID => [ + 'label' => 'Payer Address ID', + 'value' => Info::PAYPAL_ADDRESS_ID, + ], + Info::PAYPAL_ADDRESS_STATUS => [ + 'label' => 'Payer Address Status', + 'value' => Info::PAYPAL_ADDRESS_STATUS, + ], + Info::PAYPAL_PROTECTION_ELIGIBILITY => [ + 'label' => 'Merchant Protection Eligibility', + 'value' => Info::PAYPAL_PROTECTION_ELIGIBILITY, + ], + Info::PAYPAL_FRAUD_FILTERS => [ + 'label' => 'Triggered Fraud Filters', + 'value' => Info::PAYPAL_FRAUD_FILTERS, + ], + Info::PAYPAL_CORRELATION_ID => [ + 'label' => 'Last Correlation ID', + 'value' => Info::PAYPAL_CORRELATION_ID, + ], + Info::PAYPAL_AVS_CODE => [ + 'label' => 'Address Verification System Response', + 'value' => '#paypal_avs_code', + ], + Info::PAYPAL_CVV2_MATCH => [ + 'label' => 'CVV2 Check Result by PayPal', + 'value' => '#paypal_cvv2_match', + ], + Info::CENTINEL_VPAS => [ + 'label' => 'PayPal/Centinel Visa Payer Authentication Service Result', + 'value' => '#centinel_vpas_result', + ], + Info::CENTINEL_ECI => [ + 'label' => 'PayPal/Centinel Electronic Commerce Indicator', + 'value' => '#centinel_eci_result', + ], + Info::BUYER_TAX_ID => [ + 'label' => 'Buyer\'s Tax ID', + 'value' => Info::BUYER_TAX_ID, + ], + 'last_trans_id' => [ + 'label' => 'Last Transaction ID', + 'value' => NULL + ] + ] + ] +]; diff --git a/dev/tests/unit/testsuite/Magento/ProductAlert/Block/Email/StockTest.php b/dev/tests/unit/testsuite/Magento/ProductAlert/Block/Email/StockTest.php new file mode 100644 index 0000000000000..d9bf2a9714d08 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/ProductAlert/Block/Email/StockTest.php @@ -0,0 +1,76 @@ +_filter = $this->getMock( + '\Magento\Framework\Filter\Input\MaliciousCode', + array('filter'), + array(), + '', + false + ); + $this->_block = $objectManager->getObject( + 'Magento\ProductAlert\Block\Email\Stock', + array('maliciousCode' => $this->_filter) + ); + } + + /** + * @dataProvider testGetFilteredContentDataProvider + * @param $contentToFilter + * @param $contentFiltered + */ + public function testGetFilteredContent($contentToFilter, $contentFiltered) + { + $this->_filter->expects($this->once())->method('filter')->with($contentToFilter) + ->will($this->returnValue($contentFiltered)); + $this->assertEquals($contentFiltered, $this->_block->getFilteredContent($contentToFilter)); + } + + public function testGetFilteredContentDataProvider() + { + return array( + 'normal desc' => array('Howdy!', 'Howdy!'), + 'malicious desc 1' => array('Howdy!', 'Howdy!'), + ); + } +} diff --git a/dev/tests/unit/testsuite/Magento/RequireJs/Block/Html/Head/ConfigTest.php b/dev/tests/unit/testsuite/Magento/RequireJs/Block/Html/Head/ConfigTest.php index 695281ee650e0..93c3c4a4d6203 100644 --- a/dev/tests/unit/testsuite/Magento/RequireJs/Block/Html/Head/ConfigTest.php +++ b/dev/tests/unit/testsuite/Magento/RequireJs/Block/Html/Head/ConfigTest.php @@ -18,9 +18,6 @@ * versions in the future. If you wish to customize Magento for your * needs please refer to http://www.magentocommerce.com for more information. * - * @category Magento - * @package Magento_Review - * @subpackage integration_tests * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ diff --git a/dev/tests/unit/testsuite/Magento/Review/Controller/Adminhtml/ProductTest.php b/dev/tests/unit/testsuite/Magento/Review/Controller/Adminhtml/ProductTest.php new file mode 100644 index 0000000000000..cc5e0baa021f6 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Review/Controller/Adminhtml/ProductTest.php @@ -0,0 +1,235 @@ +_prepareMockObjects(); + + $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + + $this->_model = $objectManagerHelper->getObject( + 'Magento\Review\Controller\Adminhtml\Product', + [ + 'coreRegistry' => $this->_registryMock, + 'reviewFactory' => $this->_reviewFactoryMock, + 'ratingFactory' => $this->_ratingFactoryMock, + 'request' => $this->_requestMock, + 'response' => $this->_responseMock, + 'objectManager' => $this->_objectManagerMock, + 'messageManager' => $this->_messageManagerMock, + 'helper' => $this->_helperMock + ] + ); + + } + + /** + * Get mock objects for SetUp() + */ + protected function _prepareMockObjects() + { + $requestMethods = array( + 'getPost', + 'getModuleName', + 'setModuleName', + 'getActionName', + 'setActionName', + 'getParam' + ); + $this->_registryMock = $this->getMock('Magento\Framework\Registry', array(), array(), '', false); + $this->_requestMock = $this->getMock( + '\Magento\Framework\App\RequestInterface', $requestMethods + ); + $this->_responseMock = $this->getMock( + '\Magento\Framework\App\ResponseInterface', array('setRedirect', 'sendResponse') + ); + $this->_objectManagerMock = $this->getMock( + '\Magento\Framework\ObjectManager', array('get', 'create', 'configure'), array(), '', false + ); + $this->_messageManagerMock = $this->getMock('\Magento\Framework\Message\Manager', array(), array(), '', false); + $this->_storeManagerInterfaceMock = $this->getMockForAbstractClass('Magento\Store\Model\StoreManagerInterface'); + $this->_storeModelMock = $this->getMock( + 'Magento\Store\Model\Store', array('__wakeup', 'getId'), array(), '', false + ); + $this->_reviewModelMock = $this->getMock( + 'Magento\Review\Model\Review', + array('__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate'), + array(), + '', + false + ); + + $this->_reviewFactoryMock = $this->getMock( + 'Magento\Review\Model\ReviewFactory', + array('create'), + array(), + '', + false + ); + + $this->_ratingModelMock = $this->getMock( + 'Magento\Review\Model\Rating', + array('__wakeup', 'setRatingId', 'setReviewId', 'addOptionVote'), + array(), + '', + false); + + $this->_ratingFactoryMock = $this->getMock( + 'Magento\Review\Model\RatingFactory', + array('create'), + array(), + '', + false + ); + + $this->_helperMock = $this->getMock('\Magento\Backend\Helper\Data', array(), array(), '', false); + } + + /** + * Check postAction method and assert that review model storeId equals null. + */ + public function testPostAction() + { + $this->_requestMock->expects($this->at(0))->method('getParam') + ->will($this->returnValue(1)); + $this->_requestMock->expects($this->at(2))->method('getParam') + ->will($this->returnValue(array('1' => '1'))); + $this->_requestMock->expects($this->once())->method('getPost') + ->will($this->returnValue(array('status_id' => 1))); + $this->_objectManagerMock->expects($this->at(0))->method('get') + ->with('Magento\Store\Model\StoreManagerInterface') + ->will($this->returnValue($this->_storeManagerInterfaceMock)); + $this->_reviewFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($this->_reviewModelMock)); + $this->_ratingFactoryMock->expects($this->once())->method('create') + ->will($this->returnValue($this->_ratingModelMock)); + $this->_storeManagerInterfaceMock->expects($this->once())->method('hasSingleStore') + ->will($this->returnValue(true)); + $this->_storeManagerInterfaceMock->expects($this->once())->method('getStore') + ->will($this->returnValue($this->_storeModelMock)); + $this->_storeModelMock->expects($this->once())->method('getId') + ->will($this->returnValue(1)); + $this->_reviewModelMock->expects($this->once())->method('save') + ->will($this->returnValue($this->_reviewModelMock)); + $this->_reviewModelMock->expects($this->once())->method('getId') + ->will($this->returnValue(1)); + $this->_reviewModelMock->expects($this->once())->method('aggregate') + ->will($this->returnValue($this->_reviewModelMock)); + $this->_ratingModelMock->expects($this->once())->method('setRatingId') + ->will($this->returnSelf()); + $this->_ratingModelMock->expects($this->once())->method('setReviewId') + ->will($this->returnSelf()); + $this->_ratingModelMock->expects($this->once())->method('addOptionVote') + ->will($this->returnSelf()); + $this->_helperMock->expects($this->once())->method('geturl') + ->will($this->returnValue('url')); + + $this->_model->postAction(); + } + +} diff --git a/dev/tests/unit/testsuite/Magento/Sales/Helper/Quote/Item/CompareTest.php b/dev/tests/unit/testsuite/Magento/Sales/Helper/Quote/Item/CompareTest.php new file mode 100644 index 0000000000000..bb29521c1a6be --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Sales/Helper/Quote/Item/CompareTest.php @@ -0,0 +1,206 @@ +itemMock = $this->getMock( + 'Magento\Sales\Model\Quote\Item', + ['__wakeup', 'getProductId', 'getOptions'], + [], + '', + false + ); + $this->comparedMock = $this->getMock( + 'Magento\Sales\Model\Quote\Item', + ['__wakeup', 'getProductId', 'getOptions'], + [], + '', + false + ); + $this->optionMock = $this->getMock( + 'Magento\Sales\Model\Quote\Item\Option', + ['__wakeup', 'getCode', 'getValue'], + [], + '', + false + ); + + $this->helper = new \Magento\Sales\Helper\Quote\Item\Compare(); + } + + /** + * @param string $code + * @param mixed $value + * @return \PHPUnit_Framework_MockObject_MockObject + */ + protected function getOptionMock($code, $value) + { + $optionMock = clone $this->optionMock; + $optionMock->expects($this->once()) + ->method('getCode') + ->will($this->returnValue($code)); + $optionMock->expects($this->once()) + ->method('getValue') + ->will($this->returnValue($value)); + return $optionMock; + } + + /** + * test compare two different products + */ + public function testCompareDifferentProduct() + { + $this->itemMock->expects($this->once()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->itemMock->expects($this->once()) + ->method('getProductId') + ->will($this->returnValue(2)); + + $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock)); + } + + /** + * test compare two items with different options + */ + public function testCompareProductWithDifferentOptions() + { + $this->itemMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->comparedMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + + $this->itemMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([ + $this->getOptionMock('option-1', 1), + $this->getOptionMock('option-2', 'option-value'), + $this->getOptionMock('option-3', serialize([ + 'value' => 'value-1', + 'qty' => 2 + ]) + )] + )); + $this->comparedMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([ + $this->getOptionMock('option-4', 1), + $this->getOptionMock('option-2', 'option-value'), + $this->getOptionMock('option-3', serialize([ + 'value' => 'value-1', + 'qty' => 2 + ])) + ]) + ); + $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock)); + } + + /** + * test compare two items first with options and second without options + */ + public function testCompareItemWithComparedWithoutOption() + { + $this->itemMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->comparedMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->itemMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([ + $this->getOptionMock('option-1', 1), + $this->getOptionMock('option-2', 'option-value'), + $this->getOptionMock('option-3', serialize([ + 'value' => 'value-1', + 'qty' => 2 + ]) + )] + )); + $this->comparedMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([])); + $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock)); + } + + /** + * test compare two items first without options and second with options + */ + public function testCompareItemWithoutOptionWithCompared() + { + $this->itemMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->comparedMock->expects($this->any()) + ->method('getProductId') + ->will($this->returnValue(1)); + $this->comparedMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([ + $this->getOptionMock('option-1', 1), + $this->getOptionMock('option-2', 'option-value'), + $this->getOptionMock('option-3', serialize([ + 'value' => 'value-1', + 'qty' => 2 + ]) + )] + )); + $this->itemMock->expects($this->any()) + ->method('getOptions') + ->will($this->returnValue([])); + $this->assertFalse($this->helper->compare($this->itemMock, $this->comparedMock)); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/ConfigTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/ConfigTest.php new file mode 100644 index 0000000000000..8b98432146cc5 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/ConfigTest.php @@ -0,0 +1,108 @@ +configDataMock = $this->getMockBuilder('Magento\Sales\Model\Config\Data') + ->disableOriginalConstructor() + ->getMock(); + $this->stateMock = $this->getMockBuilder('Magento\Framework\App\State') + ->disableOriginalConstructor() + ->getMock(); + $this->model = new \Magento\Sales\Model\Config($this->configDataMock, $this->stateMock); + } + + public function testInstanceOf() + { + $model = new \Magento\Sales\Model\Config($this->configDataMock, $this->stateMock); + $this->assertInstanceOf('Magento\Sales\Model\Config', $model); + } + + public function testGetTotalsRenderer() + { + $areaCode = 'frontend'; + $section = 'config'; + $group = 'sales'; + $code = 'payment'; + $path = $section . '/' . $group . '/' . $code . '/' . 'renderers' . '/' . $areaCode; + $expected = ['test data']; + + $this->stateMock->expects($this->once()) + ->method('getAreaCode') + ->will($this->returnValue($areaCode)); + $this->configDataMock->expects($this->once()) + ->method('get') + ->with($this->equalTo($path)) + ->will($this->returnValue($expected)); + + $result = $this->model->getTotalsRenderer($section, $group, $code); + $this->assertEquals($expected, $result); + } + + public function testGetGroupTotals() + { + $section = 'config'; + $group = 'payment'; + $expected = ['test data']; + $path = $section . '/' . $group; + + $this->configDataMock->expects($this->once()) + ->method('get') + ->with($this->equalTo($path)) + ->will($this->returnValue($expected)); + + $result = $this->model->getGroupTotals($section, $group); + $this->assertEquals($expected, $result); + } + + public function testGetAvailableProductTypes() + { + $productTypes = ['simple']; + + $this->configDataMock->expects($this->once()) + ->method('get') + ->with($this->equalTo('order/available_product_types')) + ->will($this->returnValue($productTypes)); + $result = $this->model->getAvailableProductTypes(); + $this->assertEquals($productTypes, $result); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/DownloadTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/DownloadTest.php new file mode 100644 index 0000000000000..13a3e8e474c71 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/DownloadTest.php @@ -0,0 +1,247 @@ +writeDirectoryMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Write') + ->disableOriginalConstructor() + ->getMock(); + $this->filesystemMock = $this->getMockBuilder('Magento\Framework\App\Filesystem') + ->disableOriginalConstructor() + ->getMock(); + $this->filesystemMock->expects($this->any()) + ->method('getDirectoryWrite') + ->with(\Magento\Framework\App\Filesystem::ROOT_DIR) + ->will($this->returnValue($this->writeDirectoryMock)); + + $this->storageMock = $this->getMockBuilder('Magento\Core\Helper\File\Storage\Database') + ->disableOriginalConstructor() + ->getMock(); + $this->storageFactoryMock = $this->getMockBuilder('Magento\Core\Model\File\Storage\DatabaseFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->httpFileFactoryMock = $this->getMockBuilder('Magento\Framework\App\Response\Http\FileFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->model = new \Magento\Sales\Model\Download( + $this->filesystemMock, + $this->storageMock, + $this->storageFactoryMock, + $this->httpFileFactoryMock + ); + } + + public function testInstanceOf() + { + $model = new \Magento\Sales\Model\Download( + $this->filesystemMock, + $this->storageMock, + $this->storageFactoryMock, + $this->httpFileFactoryMock + ); + $this->assertInstanceOf('Magento\Sales\Model\Download', $model); + } + + /** + * @expectedException \Exception + */ + public function testDownloadFileException() + { + $info = ['order_path' => 'test/path', 'quote_path' => 'test/path2', 'title' => 'test title']; + $isFile = true; + $isReadable = false; + + $this->writeDirectoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->will($this->returnArgument(0)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue($isFile)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isReadable') + ->will($this->returnValue($isReadable)); + + $this->storageFactoryMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(false)); + + $this->model->downloadFile($info); + } + + /** + * @expectedException \Exception + */ + public function testDownloadFileNoStorage() + { + $info = ['order_path' => 'test/path', 'quote_path' => 'test/path2', 'title' => 'test title']; + $isFile = true; + $isReadable = false; + + $this->writeDirectoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->will($this->returnArgument(0)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue($isFile)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isReadable') + ->will($this->returnValue($isReadable)); + + $this->storageMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(true)); + $this->storageMock->expects($this->any()) + ->method('getMediaRelativePath') + ->will($this->returnArgument(0)); + + $storageDatabaseMock = $this->getMockBuilder('Magento\Core\Model\File\Storage\Database') + ->disableOriginalConstructor() + ->getMock(); + $storageDatabaseMock->expects($this->at(0)) + ->method('loadByFilename') + ->with($this->equalTo($info['order_path'])) + ->will($this->returnSelf()); + $storageDatabaseMock->expects($this->at(2)) + ->method('loadByFilename') + ->with($this->equalTo($info['quote_path'])) + ->will($this->returnSelf()); + + $storageDatabaseMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue(false)); + + $this->storageFactoryMock->expects($this->any()) + ->method('create') + ->will($this->returnValue($storageDatabaseMock)); + + $this->model->downloadFile($info); + } + + public function testDownloadFile() + { + $info = ['order_path' => 'test/path', 'quote_path' => 'test/path2', 'title' => 'test title']; + $isFile = true; + $isReadable = false; + + $writeMock = $this->getMockBuilder('Magento\Framework\Filesystem\File\Write') + ->disableOriginalConstructor() + ->getMock(); + $writeMock->expects($this->any()) + ->method('lock'); + $writeMock->expects($this->any()) + ->method('write'); + $writeMock->expects($this->any()) + ->method('unlock'); + $writeMock->expects($this->any()) + ->method('close'); + + $this->writeDirectoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->will($this->returnArgument(0)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isFile') + ->will($this->returnValue($isFile)); + $this->writeDirectoryMock->expects($this->any()) + ->method('isReadable') + ->will($this->returnValue($isReadable)); + $this->writeDirectoryMock->expects($this->any()) + ->method('openFile') + ->will($this->returnValue($writeMock)); + $this->writeDirectoryMock->expects($this->once()) + ->method('getRelativePath') + ->with($info['order_path']) + ->will($this->returnArgument(0)); + + $this->storageMock->expects($this->any()) + ->method('checkDbUsage') + ->will($this->returnValue(true)); + $this->storageMock->expects($this->any()) + ->method('getMediaRelativePath') + ->will($this->returnArgument(0)); + + $storageDatabaseMock = $this->getMockBuilder('Magento\Core\Model\File\Storage\Database') + ->disableOriginalConstructor() + ->setMethods(['loadByFilename', 'getId', '__wakeup']) + ->getMock(); + $storageDatabaseMock->expects($this->any()) + ->method('loadByFilename') + ->will($this->returnSelf()); + + $storageDatabaseMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue(true)); + + $this->storageFactoryMock->expects($this->any()) + ->method('create') + ->will($this->returnValue($storageDatabaseMock)); + + $this->httpFileFactoryMock->expects($this->once()) + ->method('create') + ->with( + $info['title'], + ['value' => $info['order_path'], 'type' => 'filename'], + \Magento\Framework\App\Filesystem::ROOT_DIR, + 'application/octet-stream', + null + ); + + $result = $this->model->downloadFile($info); + $this->assertNull($result); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Payment/Method/ConverterTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Payment/Method/ConverterTest.php deleted file mode 100644 index 260c572b90c18..0000000000000 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Payment/Method/ConverterTest.php +++ /dev/null @@ -1,173 +0,0 @@ -getMock('Magento\Framework\Encryption\EncryptorInterface'); - $encryptor->expects($this->any()) - ->method('encrypt') - ->with(self::INPUT_VALUE) - ->will($this->returnValue(self::ENCRYPTED_VALUE)); - $encryptor->expects($this->any()) - ->method('decrypt') - ->with(self::INPUT_VALUE) - ->will($this->returnValue(self::DECRYPTED_VALUE)); - - $this->converter = new Converter($encryptor); - } - - /** - * Create mock AbstractModel object - * - * @param string $method - * @param string $fieldName - * @return \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Model\AbstractModel - */ - private function mockModelObject($method, $fieldName) - { - $modelMock = $this->getMockBuilder('Magento\Framework\Model\AbstractModel') - ->setMethods(['__wakeup', 'getData']) - ->disableOriginalConstructor() - ->getMockForAbstractClass(); - - //map arguments to return values, including optional parameters - $valueMap = [ - ['method', null, $method], - [$fieldName, null, self::INPUT_VALUE], - ]; - $modelMock->expects($this->any()) - ->method('getData') - ->will($this->returnValueMap($valueMap)); - - return $modelMock; - } - - /** - * Test positive calls to decode(), value should be decrypted - * - * @param string $method - * @param string $fieldName - * @dataProvider positiveDataProvider - */ - public function testDecodePositive($method, $fieldName) - { - $modelMock = $this->mockModelObject($method, $fieldName); - - $returnValue = $this->converter->decode($modelMock, $fieldName); - $this->assertEquals(self::DECRYPTED_VALUE, $returnValue); - } - - /** - * Test the positive calls to encode(), return value should encrypted - * - * @param string $method - * @param string $fieldName - * @dataProvider positiveDataProvider - */ - public function testEncodePositive($method, $fieldName) - { - $modelMock = $this->mockModelObject($method, $fieldName); - - $returnValue = $this->converter->encode($modelMock, $fieldName); - $this->assertEquals(self::ENCRYPTED_VALUE, $returnValue); - } - - /** - * Positive dataProvider - * - * @see \Magento\Sales\Model\Payment\Method\Converter::$_encryptFields - * @return array - */ - public function positiveDataProvider() - { - $data = [ - 'owner' => ['ccsave', 'cc_owner'], - 'exp_year' => ['ccsave', 'cc_exp_year'], - 'exp_month' => ['ccsave', 'cc_exp_month'], - ]; - - return $data; - } - - /** - * Test the negative calls to decode(), value should be original value, not decrypted - * - * @param string $method - * @param string $fieldName - * @dataProvider negativeDataProvider - */ - public function testDecodeNegative($method, $fieldName) - { - $modelMock = $this->mockModelObject($method, $fieldName); - - $returnValue = $this->converter->decode($modelMock, $fieldName); - $this->assertEquals(self::INPUT_VALUE, $returnValue); - } - - /** - * Test the negative calls to encode(), return value should be original value, not encrypted - * - * @param string $method - * @param string $fieldName - * @dataProvider negativeDataProvider - */ - public function testEncodeNegative($method, $fieldName) - { - $modelMock = $this->mockModelObject($method, $fieldName); - - $returnValue = $this->converter->encode($modelMock, $fieldName); - $this->assertEquals(self::INPUT_VALUE, $returnValue); - } - - /** - * Negative dataProvider - * - * @return array - */ - public function negativeDataProvider() - { - $data = [ - 'incorrect_method_name' => ['ccsave_incorrect', 'cc_owner'], - 'incorrect_field_name' => ['ccsave', 'cc_exp_year_incorrect'], - ]; - return $data; - } -} diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php index c9e41f6ce4b4c..e4d2d5311fa05 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/Quote/ItemTest.php @@ -60,6 +60,11 @@ class ItemTest extends \PHPUnit_Framework_TestCase */ private $objectManagerHelper; + /** + * @var \Magento\Sales\Helper\Quote\Item\Compare|\PHPUnit_Framework_MockObject_MockObject + */ + protected $compareHelper; + const PRODUCT_ID = 1; const PRODUCT_TYPE = 'simple'; const PRODUCT_SKU = '12345'; @@ -109,6 +114,14 @@ protected function setUp() ->setMethods(['create']) ->getMock(); + $this->compareHelper = $this->getMock( + 'Magento\Sales\Helper\Quote\Item\Compare', + [], + [], + '', + false + ); + $this->model = $this->objectManagerHelper->getObject( '\Magento\Sales\Model\Quote\Item', [ @@ -116,6 +129,7 @@ protected function setUp() 'context' => $this->modelContext, 'statusListFactory' => $statusListFactory, 'itemOptionFactory' => $this->itemOptionFactory, + 'compareHelper' => $this->compareHelper ] ); } @@ -612,6 +626,24 @@ public function testRepresentProductTrue() $this->assertTrue($this->model->representProduct($productMock)); } + /** + * test compare + */ + public function testCompare() + { + $itemMock = $this->getMock('Magento\Sales\Model\Quote\Item', + [], + [], + '', + false + ); + $this->compareHelper->expects($this->once()) + ->method('compare') + ->with($this->equalTo($this->model), $this->equalTo($itemMock)) + ->will($this->returnValue(true)); + $this->assertTrue($this->model->compare($itemMock)); + } + public function testCompareOptionsEqual() { $optionCode1 = 1234; diff --git a/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php b/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php index f46fa01e52141..06e38508367f2 100644 --- a/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php +++ b/dev/tests/unit/testsuite/Magento/Sales/Model/QuoteTest.php @@ -47,19 +47,39 @@ class QuoteTest extends \PHPUnit_Framework_TestCase protected $quoteAddressCollectionMock; /** - * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject */ protected $storeManagerMock; /** - * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $storeMock; + protected $resourceMock; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \PHPUnit_Framework_MockObject_MockObject */ - protected $scopeConfigMock; + protected $contextMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $customerFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $addressConverterMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $eventManagerMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $customerGroupServiceMock; /** * @var \Magento\Sales\Model\Quote @@ -75,11 +95,24 @@ protected function setUp() '', false ); - $this->quoteAddressMock = $this->getMock('Magento\Sales\Model\Quote\Address', array(), array(), '', false); - $methods = array('isDeleted', 'setQuoteFilter', 'getIterator', 'validateMinimumAmount'); + $this->quoteAddressMock = $this->getMock( + 'Magento\Sales\Model\Quote\Address', + [ + 'isDeleted', + 'getCollection', + 'getId', + 'getCustomerAddressId', + '__wakeup', + 'getAddressType', + 'getDeleteImmediately' + ], + [], + '', + false + ); $this->quoteAddressCollectionMock = $this->getMock( 'Magento\Sales\Model\Resource\Quote\Address\Collection', - $methods, + array(), array(), '', false @@ -100,18 +133,49 @@ protected function setUp() $this->returnValue($this->quoteAddressCollectionMock) ); - $this->storeManagerMock = $this->getMock('Magento\Store\Model\StoreManagerInterface'); + $this->eventManagerMock = $this->getMockBuilder('Magento\Framework\Event\Manager') + ->disableOriginalConstructor() + ->getMock(); + + $this->storeManagerMock = $this->getMockBuilder('Magento\Store\Model\StoreManager') + ->disableOriginalConstructor() + ->getMock(); + $this->resourceMock = $this->getMockBuilder('Magento\Sales\Model\Resource\Quote') + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock = $this->getMockBuilder('Magento\Framework\Model\Context') + ->disableOriginalConstructor() + ->getMock(); + $this->customerFactoryMock = $this->getMockBuilder('Magento\Customer\Model\CustomerFactory') + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->addressConverterMock = $this->getMockBuilder('Magento\Customer\Model\Address\Converter') + ->disableOriginalConstructor() + ->getMock(); + $this->customerGroupServiceMock = $this->getMockBuilder('Magento\Customer\Service\V1\CustomerGroupService') + ->disableOriginalConstructor() + ->getMock(); + $this->contextMock->expects($this->any()) + ->method('getEventDispatcher') + ->will($this->returnValue($this->eventManagerMock)); - $this->storeMock = $this->getMock('Magento\Store\Model\Store', array(), array(), '', false); - $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); - $this->scopeConfigMock = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); - $this->quote = (new ObjectManager( + + $this->quote = ( + new ObjectManager( $this - ))->getObject( + ) + )->getObject( 'Magento\Sales\Model\Quote', - array('quoteAddressFactory' => $this->quoteAddressFactoryMock, - 'storeManager' => $this->storeManagerMock, - 'scopeConfig' => $this->scopeConfigMock) + [ + 'quoteAddressFactory' => $this->quoteAddressFactoryMock, + 'storeManager' => $this->storeManagerMock, + 'resource' => $this->resourceMock, + 'context' => $this->contextMock, + 'customerFactory' => $this->customerFactoryMock, + 'addressConverter' => $this->addressConverterMock, + 'customerGroupService' => $this->customerGroupServiceMock + ] ); } @@ -201,25 +265,416 @@ protected function getAddressMock($type) return $shippingAddressMock; } - public function testValidateMinimumAmount() + public function testGetStoreIdNoId() { + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $storeMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue(null)); + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->will($this->returnValue($storeMock)); - $this->storeMock->expects($this->any())->method('getId')->will($this->returnValue(false)); - $valueMap = array( - array('sales/minimum_order/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, false, true), - array('sales/minimum_order/multi_address', - \Magento\Store\Model\ScopeInterface::SCOPE_STORE, false, true) - ); - $this->scopeConfigMock->expects($this->any())->method('isSetFlag')->will($this->returnValueMap($valueMap)); - $this->scopeConfigMock->expects($this->once()) - ->method('getValue') - ->with('sales/minimum_order/amount', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, false) - ->will($this->returnValue(150)); - $this->quoteAddressCollectionMock - ->expects($this->any()) + $result = $this->quote->getStoreId(); + $this->assertNull($result); + } + + public function testGetStoreId() + { + $storeId = 1; + + $result = $this->quote->setStoreId($storeId)->getStoreId(); + $this->assertEquals($storeId, $result); + } + + public function testGetStore() + { + $storeId = 1; + + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->will($this->returnValue($storeMock)); + + $this->quote->setStoreId($storeId); + $result = $this->quote->getStore(); + $this->assertInstanceOf('Magento\Store\Model\Store', $result); + } + + public function testSetStore() + { + $storeId = 1; + + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $storeMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($storeId)); + + $result = $this->quote->setStore($storeMock); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); + } + + public function testGetSharedWebsiteStoreIds() + { + $sharedIds = null; + $storeIds = [1, 2, 3]; + + $websiteMock = $this->getMockBuilder('Magento\Store\Model\Website') + ->disableOriginalConstructor() + ->getMock(); + $websiteMock->expects($this->once()) + ->method('getStoreIds') + ->will($this->returnValue($storeIds)); + + $this->quote->setData('shared_store_ids', $sharedIds); + $this->quote->setWebsite($websiteMock); + $result = $this->quote->getSharedStoreIds(); + $this->assertEquals($storeIds, $result); + } + + public function testGetSharedStoreIds() + { + $sharedIds = null; + $storeIds = [1, 2, 3]; + $storeId = 1; + + $websiteMock = $this->getMockBuilder('Magento\Store\Model\Website') + ->disableOriginalConstructor() + ->getMock(); + $websiteMock->expects($this->once()) + ->method('getStoreIds') + ->will($this->returnValue($storeIds)); + + $storeMock = $this->getMockBuilder('Magento\Store\Model\Store') + ->disableOriginalConstructor() + ->getMock(); + $storeMock->expects($this->once()) + ->method('getWebsite') + ->will($this->returnValue($websiteMock)); + + $this->storeManagerMock->expects($this->once()) + ->method('getStore') + ->with($storeId) + ->will($this->returnValue($storeMock)); + + $this->quote->setData('shared_store_ids', $sharedIds); + $this->quote->setStoreId($storeId); + $result = $this->quote->getSharedStoreIds(); + $this->assertEquals($storeIds, $result); + } + + public function testLoadActive() + { + $quoteId = 1; + + $this->resourceMock->expects($this->once()) + ->method('loadActive') + ->with($this->quote, $quoteId); + + $this->eventManagerMock->expects($this->any()) + ->method('dispatch'); + + $result = $this->quote->loadActive($quoteId); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); + } + + public function testloadByIdWithoutStore() + { + $quoteId = 1; + + $this->resourceMock->expects($this->once()) + ->method('loadByIdWithoutStore') + ->with($this->quote, $quoteId); + + $this->eventManagerMock->expects($this->any()) + ->method('dispatch'); + + $result = $this->quote->loadByIdWithoutStore($quoteId); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); + } + + public function testSetCustomerAddressData() + { + $customerId = 1; + + $addressItemMock = $this->getMockBuilder('Magento\Customer\Service\V1\Data\Address') + ->disableOriginalConstructor() + ->getMock(); + $addresses = [$addressItemMock]; + + $addressModelMock = $this->getMockBuilder('Magento\Customer\Model\Address') + ->disableOriginalConstructor() + ->getMock(); + + $this->addressConverterMock->expects($this->once()) + ->method('createAddressModel') + ->with($addressItemMock) + ->will($this->returnValue($addressModelMock)); + + $addressCollectionMock = $this->getMockBuilder('Magento\Customer\Model\Resource\Address\Collection') + ->disableOriginalConstructor() + ->getMock(); + $addressCollectionMock->expects($this->once()) + ->method('removeAllItems'); + + $customerMock = $this->getMockBuilder('Magento\Customer\Model\Customer') + ->disableOriginalConstructor() + ->getMock(); + $customerMock->expects($this->once()) + ->method('load') + ->with($customerId); + $customerMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue(false)); + $customerMock->expects($this->once()) + ->method('getAddressesCollection') + ->will($this->returnValue($addressCollectionMock)); + $customerMock->expects($this->once()) + ->method('addAddress') + ->with($addressModelMock); + + $this->customerFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($customerMock)); + $this->quote->setCustomerId($customerId); + + $result = $this->quote->setCustomerAddressData($addresses); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); + } + + public function testGetCustomerTaxClassId() + { + $groupId = 1; + $taxClassId = 1; + + $customerGroupMock = $this->getMockBuilder('Magento\Customer\Service\V1\Data\CustomerGroup') + ->disableOriginalConstructor() + ->getMock(); + $customerGroupMock->expects($this->once()) + ->method('getTaxClassId') + ->will($this->returnValue($taxClassId)); + + $this->customerGroupServiceMock->expects($this->once()) + ->method('getGroup') + ->with($groupId) + ->will($this->returnValue($customerGroupMock)); + + $this->quote->setData('customer_group_id', $groupId); + $result = $this->quote->getCustomerTaxClassId(); + $this->assertEquals($taxClassId, $result); + } + + public function testGetAllAddresses() + { + $id = 1; + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('setQuoteFilter') + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->once()) + ->method('isDeleted') + ->will($this->returnValue(false)); + + $iterator = new \ArrayIterator([$this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + $result = $this->quote->getAllAddresses(); + $this->assertEquals([$this->quoteAddressMock], $result); + } + + /** + * @dataProvider dataProviderGetAddress + */ + public function testGetAddressById($addressId, $expected) + { + $id = 1; + $this->quoteAddressCollectionMock->expects($this->once()) ->method('setQuoteFilter') - ->will($this->returnValue(array($this->quoteAddressCollectionMock))); - $this->quoteAddressCollectionMock->expects($this->never())->method('validateMinimumAmount'); - $this->assertEquals(true, $this->quote->validateMinimumAmount(true)); + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($id)); + + $iterator = new \ArrayIterator([$this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + $result = $this->quote->getAddressById($addressId); + + $this->assertEquals((bool)$expected, (bool)$result); + } + + public static function dataProviderGetAddress() + { + return [ + [1, true], + [2, false] + ]; + } + + /** + * @param $isDeleted + * @param $customerAddressId + * @param $expected + * + * @dataProvider dataProviderGetAddressByCustomer + */ + public function testGetAddressByCustomerAddressId($isDeleted, $customerAddressId, $expected) + { + $id = 1; + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('setQuoteFilter') + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->once()) + ->method('isDeleted') + ->will($this->returnValue($isDeleted)); + $this->quoteAddressMock->expects($this->once()) + ->method('getCustomerAddressId') + ->will($this->returnValue($customerAddressId)); + + $iterator = new \ArrayIterator([$this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + $result = $this->quote->getAddressByCustomerAddressId($id); + + $this->assertEquals((bool)$expected, (bool)$result); + } + + public static function dataProviderGetAddressByCustomer() + { + return [ + [false, 1, true], + [false, 2, false] + ]; + } + + /** + * @param $isDeleted + * @param $addressType + * @param $customerAddressId + * @param $expected + * + * @dataProvider dataProviderShippingAddress + */ + public function testGetShippingAddressByCustomerAddressId($isDeleted, $addressType, $customerAddressId, $expected) + { + $id = 1; + + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('setQuoteFilter') + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->once()) + ->method('isDeleted') + ->will($this->returnValue($isDeleted)); + $this->quoteAddressMock->expects($this->once()) + ->method('getCustomerAddressId') + ->will($this->returnValue($customerAddressId)); + $this->quoteAddressMock->expects($this->once()) + ->method('getAddressType') + ->will($this->returnValue($addressType)); + + $iterator = new \ArrayIterator([$this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + + $result = $this->quote->getShippingAddressByCustomerAddressId($id); + $this->assertEquals($expected, (bool)$result); + } + + public static function dataProviderShippingAddress() + { + return [ + [false, \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING, 1, true], + [false, \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING, 2, false], + ]; + } + + public function testRemoveAddress() + { + $id = 1; + + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('setQuoteFilter') + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->once()) + ->method('isDeleted') + ->with(true); + $this->quoteAddressMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($id)); + + $iterator = new \ArrayIterator([$this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + + $result = $this->quote->removeAddress($id); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); + } + + public function testRemoveAllAddresses() + { + $id = 1; + + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('setQuoteFilter') + ->with($id) + ->will($this->returnSelf()); + + $this->quoteAddressMock->expects($this->any()) + ->method('getAddressType') + ->will($this->returnValue(\Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING)); + $this->quoteAddressMock->expects($this->any()) + ->method('isDeleted') + ->will($this->returnValue(false)); + $this->quoteAddressMock->expects($this->once()) + ->method('getId') + ->will($this->returnValue($id)); + $this->quoteAddressMock->expects($this->once()) + ->method('getDeleteImmediately') + ->will($this->returnValue(true)); + + $iterator = new \ArrayIterator([$id => $this->quoteAddressMock]); + $this->quoteAddressCollectionMock->expects($this->any()) + ->method('getIterator') + ->will($this->returnValue($iterator)); + $this->quoteAddressCollectionMock->expects($this->once()) + ->method('removeItemByKey') + ->with($id) + ->will($this->returnValue($iterator)); + + $this->quote->setId($id); + + $result = $this->quote->removeAllAddresses(); + $this->assertInstanceOf('Magento\Sales\Model\Quote', $result); } } diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Helper/CouponTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Helper/CouponTest.php new file mode 100644 index 0000000000000..4b643ae1f3ade --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Helper/CouponTest.php @@ -0,0 +1,168 @@ +scopeConfig = $this->getMock('Magento\Framework\App\Config', [], [], '', false); + $this->context = $this->getMock('Magento\Framework\App\Helper\Context', [], [], '', false); + $this->couponParameters = [ + 'separator' => $this->separator, + 'charset' => [ + 'format' => 'abc' + ] + ]; + + $this->helper = $objectManager->getObject( + 'Magento\SalesRule\Helper\Coupon', + [ + 'context' => $this->context, + 'scopeConfig' => $this->scopeConfig, + 'couponParameters' => $this->couponParameters + ] + ); + } + + public function testGetFormatsList() + { + $helper = $this->helper; + $this->assertArrayHasKey( + $helper::COUPON_FORMAT_ALPHABETICAL, + $helper->getFormatsList(), + 'The returned list should contain COUPON_FORMAT_ALPHABETICAL constant value as a key' + ); + $this->assertArrayHasKey( + $helper::COUPON_FORMAT_ALPHANUMERIC, + $helper->getFormatsList(), + 'The returned list should contain COUPON_FORMAT_ALPHANUMERIC constant value as a key' + ); + $this->assertArrayHasKey( + $helper::COUPON_FORMAT_NUMERIC, + $helper->getFormatsList(), + 'The returned list should contain COUPON_FORMAT_NUMERIC constant value as a key' + ); + } + + public function testGetDefaultLength() + { + $helper = $this->helper; + $defaultLength = 100; + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with($helper::XML_PATH_SALES_RULE_COUPON_LENGTH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->will($this->returnValue($defaultLength)); + + $this->assertEquals($defaultLength, $helper->getDefaultLength()); + } + + public function testGetDefaultFormat() + { + $helper = $this->helper; + $defaultFormat = 'format'; + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with($helper::XML_PATH_SALES_RULE_COUPON_FORMAT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->will($this->returnValue($defaultFormat)); + + $this->assertEquals($defaultFormat, $helper->getDefaultFormat()); + } + + public function testGetDefaultPrefix() + { + $helper = $this->helper; + $defaultPrefix = 'prefix'; + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with($helper::XML_PATH_SALES_RULE_COUPON_PREFIX, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->will($this->returnValue($defaultPrefix)); + + $this->assertEquals($defaultPrefix, $helper->getDefaultPrefix()); + } + + public function testGetDefaultSuffix() + { + $helper = $this->helper; + $defaultSuffix = 'suffix'; + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with($helper::XML_PATH_SALES_RULE_COUPON_SUFFIX, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->will($this->returnValue($defaultSuffix)); + + $this->assertEquals($defaultSuffix, $helper->getDefaultSuffix()); + } + + public function testGetDefaultDashInterval() + { + $helper = $this->helper; + $defaultDashInterval = 4; + $this->scopeConfig->expects($this->once()) + ->method('getValue') + ->with($helper::XML_PATH_SALES_RULE_COUPON_DASH_INTERVAL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE) + ->will($this->returnValue($defaultDashInterval)); + + $this->assertEquals($defaultDashInterval, $helper->getDefaultDashInterval()); + } + + public function testGetCharset() + { + $format = 'format'; + $expected = ['a', 'b', 'c']; + + $this->assertEquals($expected, $this->helper->getCharset($format)); + } + + public function testGetSeparator() + { + $this->assertEquals($this->separator, $this->helper->getCodeSeparator()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/ObserverTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/ObserverTest.php index eb612c34ed11c..a1aa9bac796c4 100644 --- a/dev/tests/unit/testsuite/Magento/SalesRule/Model/ObserverTest.php +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/ObserverTest.php @@ -28,61 +28,487 @@ class ObserverTest extends \PHPUnit_Framework_TestCase /** * @var \Magento\SalesRule\Model\Observer|\PHPUnit_Framework_MockObject_MockObject */ - protected $_model; + protected $model; /** * @var \Magento\SalesRule\Model\Coupon|\PHPUnit_Framework_MockObject_MockObject */ - protected $_couponMock; + protected $couponMock; + + /** + * @var \Magento\SalesRule\Model\RuleFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $ruleFactory; + + /** + * @var + */ + protected $ruleCustomerFactory; + + /** + * @var \Magento\Framework\Locale\Resolver|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeResolver; + + /** + * @var \Magento\SalesRule\Model\Resource\Coupon\Usage|\PHPUnit_Framework_MockObject_MockObject + */ + protected $couponUsage; + + /** + * @var \Magento\Framework\Stdlib\DateTime\Timezone|\PHPUnit_Framework_MockObject_MockObject + */ + protected $localeDate; + + /** + * @var \Magento\SalesRule\Model\Resource\Report\Rule|\PHPUnit_Framework_MockObject_MockObject + */ + protected $reportRule; + + /** + * @var \Magento\SalesRule\Model\Resource\Rule\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $collectionFactory; + + /** + * @var \Magento\Framework\Message\Manager|\PHPUnit_Framework_MockObject_MockObject + */ + protected $messageManager; protected function setUp() { $helper = new \Magento\TestFramework\Helper\ObjectManager($this); - $this->_couponMock = $this->getMock( + $this->initMocks(); + + $this->model = $helper->getObject( + 'Magento\SalesRule\Model\Observer', + [ + 'coupon' => $this->couponMock, + 'ruleFactory' => $this->ruleFactory, + 'ruleCustomerFactory' => $this->ruleCustomerFactory, + 'localeResolver' => $this->localeResolver, + 'couponUsage' => $this->couponUsage, + 'localeDate' => $this->localeDate, + 'reportRule' => $this->reportRule, + 'collectionFactory' => $this->collectionFactory, + 'messageManager' => $this->messageManager + ] + ); + } + + protected function initMocks() + { + $this->couponMock = $this->getMock( '\Magento\SalesRule\Model\Coupon', - array('__wakeup', 'save', 'load'), - array(), + [ + '__wakeup', + 'save', + 'load', + 'getId', + 'setTimesUsed', + 'getTimesUsed', + 'getRuleId', + 'loadByCode', + 'updateCustomerCouponTimesUsed' + ], + [], + '', + false + ); + $this->ruleFactory = $this->getMock('Magento\SalesRule\Model\RuleFactory', ['create'], [], '', false); + $this->ruleCustomerFactory = $this->getMock( + 'Magento\SalesRule\Model\Rule\CustomerFactory', + ['create'], + [], + '', + false + ); + $this->localeResolver = $this->getMock('Magento\Framework\Locale\Resolver', [], [], '', false); + $this->couponUsage = $this->getMock('Magento\SalesRule\Model\Resource\Coupon\Usage', [], [], '', false); + $this->localeDate = $this->getMock('Magento\Framework\Stdlib\DateTime\Timezone', ['date'], [], '', false); + $this->reportRule = $this->getMock('Magento\SalesRule\Model\Resource\Report\Rule', [], [], '', false); + $this->collectionFactory = $this->getMock( + 'Magento\SalesRule\Model\Resource\Rule\CollectionFactory', + ['create'], + [], + '', + false + ); + $this->messageManager = $this->getMock( + 'Magento\Framework\Message\Manager', + ['addWarning'], + [], '', false ); - $this->_model = $helper->getObject('Magento\SalesRule\Model\Observer', array('coupon' => $this->_couponMock)); } /** - * @covers \Magento\SalesRule\Model\Observer::salesOrderAfterPlace + * @param \\PHPUnit_Framework_MockObject_MockObject $observer + * @return \PHPUnit_Framework_MockObject_MockObject $order */ - public function testSalesOrderAfterPlaceWithoutDiscount() + protected function initOrderFromEvent($observer) { - $event = new \Magento\Framework\Event(); - $observer = new \Magento\Framework\Event\Observer(array('event' => $event)); - /** @var $mockOrder \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject */ - $mockOrder = $this->getMock( + $event = $this->getMock('Magento\Framework\Event', ['getOrder'], [], '', false); + $order = $this->getMock( 'Magento\Sales\Model\Order', - array('__wakeup', 'getDiscountAmount'), - array(), + ['getAppliedRuleIds', 'getCustomerId', 'getDiscountAmount', 'getCouponCode', '__wakeup'], + [], '', false ); - $event->setData('order', $mockOrder); - $mockOrder->expects($this->once())->method('getDiscountAmount')->will($this->returnValue(0)); - $this->assertInstanceOf('Magento\SalesRule\Model\Observer', $this->_model->salesOrderAfterPlace($observer)); + + $observer->expects($this->any()) + ->method('getEvent') + ->will($this->returnValue($event)); + $event->expects($this->any()) + ->method('getOrder') + ->will($this->returnValue($order)); + + return $order; + } + + public function testSalesOrderAfterPlaceWithoutOrder() + { + $observer = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false); + $this->initOrderFromEvent($observer); + + $this->assertEquals($this->model, $this->model->salesOrderAfterPlace($observer)); + } + + public function testSalesOrderAfterPlaceWithoutRuleId() + { + $observer = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false); + $order = $this->initOrderFromEvent($observer); + $discountAmount = 10; + $order->expects($this->once()) + ->method('getDiscountAmount') + ->will($this->returnValue($discountAmount)); + + $this->ruleFactory->expects($this->never()) + ->method('create'); + $this->assertEquals($this->model, $this->model->salesOrderAfterPlace($observer)); } /** - * @covers \Magento\SalesRule\Model\Observer::salesOrderAfterPlace + * @param int|bool $ruleCustomerId + * @dataProvider salesOrderAfterPlaceDataProvider */ - public function testSalesOrderAfterPlaceWithDiscount() + public function testSalesOrderAfterPlace($ruleCustomerId) + { + $observer = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false); + $rule = $this->getMock('Magento\SalesRule\Model\Rule', [], [], '', false); + $ruleCustomer = $this->getMock( + 'Magento\SalesRule\Model\Rule\Customer', + [ + 'setCustomerId', + 'loadByCustomerRule', + 'getId', + 'setTimesUsed', + 'setRuleId', + 'save', + '__wakeup' + ], + [], + '', + false + ); + $order = $this->initOrderFromEvent($observer); + $ruleId = 1; + $couponId = 1; + $customerId = 1; + $discountAmount = 10; + + $order->expects($this->once()) + ->method('getAppliedRuleIds') + ->will($this->returnValue($ruleId)); + $order->expects($this->once()) + ->method('getDiscountAmount') + ->will($this->returnValue($discountAmount)); + $order->expects($this->once()) + ->method('getCustomerId') + ->will($this->returnValue($customerId)); + $this->ruleFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($rule)); + $rule->expects($this->once()) + ->method('getId') + ->will($this->returnValue($ruleId)); + $this->ruleCustomerFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($ruleCustomer)); + $ruleCustomer->expects($this->once()) + ->method('getId') + ->will($this->returnValue($ruleCustomerId)); + $ruleCustomer->expects($this->any()) + ->method('setCustomerId') + ->will($this->returnSelf()); + $ruleCustomer->expects($this->any()) + ->method('setRuleId') + ->will($this->returnSelf()); + $this->couponMock->expects($this->any()) + ->method('getId') + ->will($this->returnValue($couponId)); + + $this->couponUsage->expects($this->once()) + ->method('updateCustomerCouponTimesUsed') + ->with($customerId, $couponId); + + $this->assertEquals($this->model, $this->model->salesOrderAfterPlace($observer)); + } + + public function salesOrderAfterPlaceDataProvider() + { + return [ + 'With customer rule id' => [1], + 'Without customer rule id' => [null] + ]; + } + + public function testAggregateSalesReportCouponsData() + { + $dateMock = $this->getMock('Magento\Framework\Stdlib\DateTime\DateInterface', [], [], '', false); + $this->localeResolver->expects($this->once()) + ->method('emulate') + ->with(0); + $this->localeDate->expects($this->once()) + ->method('date') + ->will($this->returnValue($dateMock)); + $dateMock->expects($this->once()) + ->method('subHour') + ->with(25) + ->will($this->returnSelf()); + $this->reportRule->expects($this->once()) + ->method('aggregate') + ->with($dateMock); + $this->localeResolver->expects($this->once()) + ->method('revert'); + + $this->assertEquals($this->model, $this->model->aggregateSalesReportCouponsData()); + } + + protected function checkSalesRuleAvailability($attributeCode) + { + $collection = $this->getMock( + 'Magento\SalesRule\Model\Resource\Rule\Collection', + ['addAttributeInConditionFilter', '__wakeup'], + [], + '', + false + ); + $rule = $this->getMock( + 'Magento\SalesRule\Model\Rule', + ['setIsActive', 'getConditions', 'getActions', 'save', '__wakeup'], + [], + '', + false + ); + $combine = $this->getMock( + 'Magento\Rule\Model\Condition\Combine', + ['getConditions', 'setConditions', '__wakeup'], + [], + '', + false + ); + $combineProduct = $this->getMock( + 'Magento\SalesRule\Model\Rule\Condition\Product', + ['getAttribute', 'setConditions', '__wakeup'], + [], + '', + false + ); + + + $this->collectionFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($collection)); + $collection->expects($this->once()) + ->method('addAttributeInConditionFilter') + ->with($attributeCode) + ->will($this->returnValue([$rule])); + $rule->expects($this->once()) + ->method('setIsActive') + ->with(0); + $rule->expects($this->once()) + ->method('getConditions') + ->will($this->returnValue($combine)); + $rule->expects($this->once()) + ->method('getActions') + ->will($this->returnValue($combine)); + $combine->expects($this->at(0)) + ->method('getConditions') + ->will($this->returnValue([$combine])); + $combine->expects($this->at(1)) + ->method('getConditions') + ->will($this->returnValue([$combineProduct])); + $combine->expects($this->at(4)) + ->method('getConditions') + ->will($this->returnValue([])); + + $combineProduct->expects($this->once()) + ->method('getAttribute') + ->will($this->returnValue($attributeCode)); + $combine->expects($this->any()) + ->method('setConditions') + ->will( + $this->returnValueMap( + [ + [[], null], + [[$combine], null], + [[], null], + ] + ) + ); + + $this->messageManager->expects($this->once()) + ->method('addWarning') + ->with(sprintf('1 Shopping Cart Price Rules based on "%s" attribute have been disabled.', $attributeCode)); + } + + public function testCatalogAttributeSaveAfter() + { + $attributeCode = 'attributeCode'; + $observer = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false); + $event = $this->getMock('Magento\Framework\Event', ['getAttribute', '__wakeup'], [], '', false); + $attribute = $this->getMock( + 'Magento\Catalog\Model\Resource\Eav\Attribute', + ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup'], + [], + '', + false + ); + + $observer->expects($this->once()) + ->method('getEvent') + ->will($this->returnValue($event)); + $event->expects($this->any()) + ->method('getAttribute') + ->will($this->returnValue($attribute)); + $attribute->expects($this->any()) + ->method('dataHasChangedFor') + ->with('is_used_for_promo_rules') + ->will($this->returnValue(true)); + $attribute->expects($this->any()) + ->method('getIsUsedForPromoRules') + ->will($this->returnValue(false)); + $attribute->expects($this->any()) + ->method('getAttributeCode') + ->will($this->returnValue($attributeCode)); + $this->checkSalesRuleAvailability($attributeCode); + + $this->assertEquals($this->model, $this->model->catalogAttributeSaveAfter($observer)); + } + + public function testCatalogAttributeDeleteAfter() { - $event = new \Magento\Framework\Event(); - $observer = new \Magento\Framework\Event\Observer(array('event' => $event)); - /** @var $mockOrder \Magento\Sales\Model\Order|\PHPUnit_Framework_MockObject_MockObject */ - $mockOrder = $this->getMock('Magento\Sales\Model\Order', array('__wakeup'), array(), '', false); - $event->setData('order', $mockOrder); - $mockOrder->addData(array('discount_amount' => -10, 'applied_rule_ids' => '', 'coupon_code' => 'some_code')); - $this->_couponMock->expects($this->once())->method('load')->with('some_code', 'code'); - $this->_couponMock->expects($this->once())->method('save'); - $this->_couponMock->addData(array('id' => 'some_code', 'times_used' => 1)); - $this->assertInstanceOf('Magento\SalesRule\Model\Observer', $this->_model->salesOrderAfterPlace($observer)); - $this->assertEquals(2, $this->_couponMock->getTimesUsed()); + $attributeCode = 'attributeCode'; + $observer = $this->getMock('Magento\Framework\Event\Observer', [], [], '', false); + $event = $this->getMock('Magento\Framework\Event', ['getAttribute', '__wakeup'], [], '', false); + $attribute = $this->getMock( + 'Magento\Catalog\Model\Resource\Eav\Attribute', + ['dataHasChangedFor', 'getIsUsedForPromoRules', 'getAttributeCode', '__wakeup'], + [], + '', + false + ); + + $observer->expects($this->once()) + ->method('getEvent') + ->will($this->returnValue($event)); + $event->expects($this->any()) + ->method('getAttribute') + ->will($this->returnValue($attribute)); + $attribute->expects($this->any()) + ->method('getIsUsedForPromoRules') + ->will($this->returnValue(true)); + $attribute->expects($this->any()) + ->method('getAttributeCode') + ->will($this->returnValue($attributeCode)); + $this->checkSalesRuleAvailability($attributeCode); + + $this->assertEquals($this->model, $this->model->catalogAttributeDeleteAfter($observer)); + } + + public function testAddSalesRuleNameToOrderWithoutCouponCode() + { + $observer = $this->getMock('Magento\Framework\Event\Observer', ['getOrder'], [], '', false); + $order = $this->getMock( + 'Magento\Sales\Model\Order', + ['setCouponRuleName', 'getCouponCode', '__wakeup'], + [], + '', + false + ); + + $observer->expects($this->any()) + ->method('getOrder') + ->will($this->returnValue($order)); + + $this->couponMock->expects($this->never()) + ->method('loadByCode'); + + $this->assertEquals($this->model, $this->model->addSalesRuleNameToOrder($observer)); + } + + public function testAddSalesRuleNameToOrderWithoutRule() + { + $observer = $this->getMock('Magento\Framework\Event\Observer', ['getOrder'], [], '', false); + $order = $this->getMock( + 'Magento\Sales\Model\Order', + ['setCouponRuleName', 'getCouponCode', '__wakeup'], + [], + '', + false + ); + $couponCode = 'coupon code'; + + $observer->expects($this->any()) + ->method('getOrder') + ->will($this->returnValue($order)); + + $order->expects($this->once()) + ->method('getCouponCode') + ->will($this->returnValue($couponCode)); + $this->ruleFactory->expects($this->never()) + ->method('create'); + + $this->assertEquals($this->model, $this->model->addSalesRuleNameToOrder($observer)); + } + + public function testAddSalesRuleNameToOrder() + { + $observer = $this->getMock('Magento\Framework\Event\Observer', ['getOrder'], [], '', false); + $rule = $this->getMock('Magento\SalesRule\Model\Rule', ['load', 'getName', '__wakeup'], [], '', false); + $order = $this->getMock( + 'Magento\Sales\Model\Order', + ['setCouponRuleName', 'getCouponCode', '__wakeup'], + [], + '', + false + ); + $couponCode = 'coupon code'; + $ruleId = 1; + + $observer->expects($this->any()) + ->method('getOrder') + ->will($this->returnValue($order)); + + $order->expects($this->once()) + ->method('getCouponCode') + ->will($this->returnValue($couponCode)); + $this->couponMock->expects($this->once()) + ->method('getRuleId') + ->will($this->returnValue($ruleId)); + $this->ruleFactory->expects($this->once()) + ->method('create') + ->will($this->returnValue($rule)); + $rule->expects($this->once()) + ->method('load') + ->with($ruleId) + ->will($this->returnSelf()); + $order->expects($this->once()) + ->method('setCouponRuleName'); + + $this->assertEquals($this->model, $this->model->addSalesRuleNameToOrder($observer)); } } diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/Plugin/QuoteConfigProductAttributesTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Plugin/QuoteConfigProductAttributesTest.php new file mode 100644 index 0000000000000..610ca756b8d39 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/Plugin/QuoteConfigProductAttributesTest.php @@ -0,0 +1,70 @@ +ruleResource = $this->getMock('Magento\SalesRule\Model\Resource\Rule', [], [], '', false); + + $this->plugin = $objectManager->getObject( + 'Magento\SalesRule\Model\Plugin\QuoteConfigProductAttributes', + [ + 'ruleResource' => $this->ruleResource + ] + ); + } + + public function testAfterGetProductAttributes() + { + $subject = $this->getMock('Magento\Sales\Model\Quote\Config', [], [], '', false); + $attributeCode = 'code of the attribute'; + $expected = [0 => $attributeCode]; + + $this->ruleResource->expects($this->once()) + ->method('getActiveAttributes') + ->will( + $this->returnValue( + [ + ['attribute_code' => $attributeCode, 'enabled' => true] + ] + ) + ); + + $this->assertEquals($expected, $this->plugin->afterGetProductAttributes($subject, [])); + } +} diff --git a/dev/tests/unit/testsuite/Magento/SalesRule/Model/System/Config/Source/Coupon/FormatTest.php b/dev/tests/unit/testsuite/Magento/SalesRule/Model/System/Config/Source/Coupon/FormatTest.php new file mode 100644 index 0000000000000..b6175448ec126 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/SalesRule/Model/System/Config/Source/Coupon/FormatTest.php @@ -0,0 +1,75 @@ +salesRuleCoupon = $this->getMock( + 'Magento\SalesRule\Helper\Coupon', + [], + [], + '', + false + ); + + $this->model = $objectManager->getObject( + 'Magento\SalesRule\Model\System\Config\Source\Coupon\Format', + [ + 'salesRuleCoupon' => $this->salesRuleCoupon + ] + ); + } + + + public function testToOptionArray() + { + $formatTitle = 'format Title'; + $expected = [ + [ + 'label' => $formatTitle, + 'value' => 0 + ] + ]; + $this->salesRuleCoupon->expects($this->once()) + ->method('getFormatsList') + ->will($this->returnValue([$formatTitle])); + + $this->assertEquals($expected, $this->model->toOptionArray()); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Store/App/Response/RedirectTest.php b/dev/tests/unit/testsuite/Magento/Store/App/Response/RedirectTest.php new file mode 100644 index 0000000000000..42d91bb87bbcf --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Store/App/Response/RedirectTest.php @@ -0,0 +1,133 @@ +_requestMock = $this->getMock( + 'Magento\Framework\App\RequestInterface', + array( + 'getServer', + 'getModuleName', + 'setModuleName', + 'getActionName', + 'setActionName', + 'getParam' + ) + ); + $this->_storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface'); + $this->_urlCoderMock = $this->getMock( + '\Magento\Framework\Encryption\UrlCoder', + array(), + array(), + '', + false + ); + $this->_sessionMock = $this->getMock('\Magento\Framework\Session\SessionManagerInterface'); + $this->_sidResolverMock = $this->getMock('\Magento\Framework\Session\SidResolverInterface'); + $this->_urlBuilderMock = $this->getMock('\Magento\Framework\UrlInterface'); + + $this->_model = new \Magento\Store\App\Response\Redirect( + $this->_requestMock, + $this->_storeManagerMock, + $this->_urlCoderMock, + $this->_sessionMock, + $this->_sidResolverMock, + $this->_urlBuilderMock + ); + } + + /** + * @dataProvider urlAddresses + * @param string $baseUrl + * @param string $successUrl + */ + public function testSuccessUrl($baseUrl, $successUrl) + { + $testStoreMock = $this->getMock('\Magento\Store\Model\Store', array(), array(), '', false); + $testStoreMock->expects($this->any())->method('getBaseUrl')->will($this->returnValue($baseUrl)); + $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue(null)); + $this->_storeManagerMock->expects($this->any())->method('getStore') + ->will($this->returnValue($testStoreMock)); + $this->assertEquals($baseUrl, $this->_model->success($successUrl)); + } + + /** + * DataProvider with the test urls + * + * @return array + */ + public function urlAddresses() + { + return array( + array( + 'http://externalurl.com/', + 'http://internalurl.com/' + ), + array( + 'http://internalurl.com/', + 'http://internalurl.com/' + ) + ); + } +} diff --git a/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/DataFromArrayTest.php b/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/DataFromArrayTest.php index 6659cf50cf81c..40c3256c7fafd 100644 --- a/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/DataFromArrayTest.php +++ b/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/DataFromArrayTest.php @@ -35,7 +35,7 @@ class DataFromArrayTest extends \PHPUnit_Framework_TestCase public function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); - $objectFactory = new \Magento\Webapi\Service\Entity\WebapiObjectManager(); + $objectFactory = new \Magento\Webapi\Service\Entity\WebapiObjectManager($objectManager); $typeProcessor = $objectManager->getObject('Magento\Webapi\Model\Config\ClassReflector\TypeProcessor'); $this->serializer = new ServiceArgsSerializer($typeProcessor, $objectFactory); } diff --git a/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/WebapiObjectManager.php b/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/WebapiObjectManager.php index a15c6d1748911..b395f8c83c58a 100644 --- a/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/WebapiObjectManager.php +++ b/dev/tests/unit/testsuite/Magento/Webapi/Service/Entity/WebapiObjectManager.php @@ -30,6 +30,19 @@ class WebapiObjectManager implements \Magento\Framework\ObjectManager */ private $configuration; + /** + * @var \Magento\TestFramework\Helper\ObjectManager + */ + protected $factory; + + /** + * @param \Magento\TestFramework\Helper\ObjectManager $factory + */ + public function __construct(\Magento\TestFramework\Helper\ObjectManager $factory) + { + $this->factory = $factory; + } + /** * Create new object instance * @@ -39,7 +52,7 @@ class WebapiObjectManager implements \Magento\Framework\ObjectManager */ public function create($type, array $arguments = array()) { - return new $type($arguments); + return $this->factory->getObject($type, $arguments); } /** @@ -50,7 +63,7 @@ public function create($type, array $arguments = array()) */ public function get($type) { - return new $type(); + return $this->factory->getObject($type); } /** diff --git a/dev/tests/unit/testsuite/Magento/Weee/Helper/DataTest.php b/dev/tests/unit/testsuite/Magento/Weee/Helper/DataTest.php index ef372460155b4..da35a3dd5a47f 100644 --- a/dev/tests/unit/testsuite/Magento/Weee/Helper/DataTest.php +++ b/dev/tests/unit/testsuite/Magento/Weee/Helper/DataTest.php @@ -35,6 +35,11 @@ class DataTest extends \PHPUnit_Framework_TestCase */ protected $_helperData; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_abstractItem; + protected function setUp() { $this->_product = $this->getMock('Magento\Catalog\Model\Product', [], [], '', false); @@ -42,6 +47,25 @@ protected function setUp() $scopeConfig->expects($this->any())->method('getValue')->will($this->returnValue(true)); $weeeTax = $this->getMock('Magento\Weee\Model\Tax', [], [], '', false); $weeeTax->expects($this->any())->method('getWeeeAmount')->will($this->returnValue('11.26')); + $this->_abstractItem = $this->getMock( + '\Magento\Sales\Model\Quote\Item\AbstractItem', + array( + '__wakeup', + 'setDiscountCalculationPrice', + 'setBaseDiscountCalculationPrice', + 'getDiscountCalculationPrice', + 'getBaseDiscountCalculationPrice', + 'getCalculationPrice', + 'getBaseCalculationPrice', + 'setItemDiscountPrices', + 'getQuote', + 'getAddress', + 'getOptionByCode' + ), + array(), + '', + false + ); $arguments = array( 'scopeConfig' => $scopeConfig, 'weeeTax' => $weeeTax @@ -54,4 +78,58 @@ public function testGetAmount() { $this->assertEquals('11.26', $this->_helperData->getAmount($this->_product)); } + + /** + * @covers \Magento\Weee\Helper\Data::addItemDiscountPrices + * @covers \Magento\Weee\Helper\Data::setItemDiscountPrices + * + * @param string $getDiscountPrice + * @param string $basePrice + * @param string $price + * @param string $baseDiscountCalculationPrice + * @param string $callPriceCalculation + * + * @dataProvider addItemDiscountPricesDataProvider + */ + public function testAddItemDiscountPrices( + $getDiscountPrice, $basePrice, $price, $baseDiscountCalculationPrice, $callPriceCalculation + ) { + $this->_abstractItem->expects($this->once())->method('getDiscountCalculationPrice') + ->will($this->returnValue($getDiscountPrice)); + $this->_abstractItem->expects($this->once())->method('getBaseDiscountCalculationPrice') + ->will($this->returnValue($getDiscountPrice)); + $this->_abstractItem->expects($this->exactly($callPriceCalculation))->method('getCalculationPrice') + ->will($this->returnValue($price)); + $this->_abstractItem->expects($this->exactly($callPriceCalculation))->method('getBaseCalculationPrice') + ->will($this->returnValue($price)); + $this->_abstractItem->expects($this->once())->method('setDiscountCalculationPrice') + ->with($basePrice); + $this->_abstractItem->expects($this->once())->method('setBaseDiscountCalculationPrice') + ->with($baseDiscountCalculationPrice); + + $this->assertEquals( + $this->_helperData, $this->_helperData->addItemDiscountPrices($this->_abstractItem, $basePrice, $price) + ); + } + + public function addItemDiscountPricesDataProvider() + { + return array( + array( + 'discount_price' => null, + 'base_price' => '2', + 'price' => '1', + 'base_calculation_price' => '3', + 'call_price_calculation' => 1 + ), + array( + 'discount_price' => '1', + 'base_price' => '2', + 'price' => '1', + 'base_calculation_price' => '3', + 'call_price_calculation' => 0 + ) + ); + } + } diff --git a/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php new file mode 100644 index 0000000000000..9a9790902c512 --- /dev/null +++ b/dev/tests/unit/testsuite/Magento/Weee/Model/Total/Quote/WeeeTest.php @@ -0,0 +1,433 @@ +_initializeMockObjects(); + $this->_prepareStaticMockExpects(); + $objectManagerHelper = new \Magento\TestFramework\Helper\ObjectManager($this); + $this->_model = $objectManagerHelper->getObject( + '\Magento\Weee\Model\Total\Quote\Weee', + array( + 'weeeData' => $this->_weeeDataMock, + 'taxConfig' => $this->_configMock + ) + ); + } + + /** + * Initialize mock objects + */ + protected function _initializeMockObjects() + { + $quoteItemMethods = [ + '__wakeup', + 'getProduct', + 'setWeeeTaxAppliedAmount', + 'setBaseWeeeTaxAppliedAmount', + 'setWeeeTaxAppliedRowAmount', + 'setBaseWeeeTaxAppliedRowAmnt', + 'getHasChildren', + 'getChildren', + 'isChildrenCalculated', + 'getTotalQty', + 'getQuote' + ]; + + $this->_storeManagerInterfaceMock = $this->getMock( + 'Magento\Store\Model\StoreManagerInterface', [], [], '', false + ); + $this->_weeeTaxMock = $this->getMock( + '\Magento\Weee\Model\Tax', ['__wakeup', 'getProductWeeeAttributes'], [], '', false + ); + $this->_taxHelperMock = $this->getMock('\Magento\Tax\Helper\Data', [], [], '', false); + $this->_registryMock = $this->getMock('\Magento\Framework\Registry', [], [], '', false); + $this->_scopeConfigInterfaceMock = $this->getMock( + '\Magento\Framework\App\Config\ScopeConfigInterface', ['isSetFlag', 'getValue'], [], '', false + ); + $this->_weeeDataMock = $this->getMock('\Magento\Weee\Helper\Data', array(), array(), '', false); + $this->_configMock = $this->getMock('\Magento\Tax\Model\Config', ['priceIncludesTax'], [], '', false); + $this->_objectMock = $this->getMock('\Magento\Framework\Object', [], [], '', false); + $this->_storeMock = $this->getMock('\Magento\Store\Model\Store', ['__wakeup', 'convertPrice'], [], '', false); + $this->_quoteItemMock = $this->getMock('Magento\Sales\Model\Quote\Item', $quoteItemMethods, [], '', false); + $this->_productModelMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); + $this->_quoteModelMock = $this->getMock('\Magento\Sales\Model\Quote', + ['__wakeup', 'getBillingAddress', 'getStore'], [], '', false); + $this->_addressMock = $this->getMock('\Magento\Sales\Model\Quote\Address', [ + '__wakeup', + 'unsSubtotalInclTax', + 'unsBaseSubtotalInclTax', + 'getAllItems', + 'getQuote', + 'getAllNonNominalItems', + 'getPrice' + ], [], '', false); + } + + /** + * Prepare expects for mocked objects + */ + protected function _prepareStaticMockExpects() + { + $this->_addressMock->expects($this->any())->method('getQuote') + ->will($this->returnValue($this->_quoteModelMock)); + $this->_addressMock->expects($this->any())->method('getAllItems') + ->will($this->returnValue($this->_quoteModelMock)); + $this->_quoteModelMock->expects($this->any())->method('getStore') + ->will($this->returnValue($this->_storeMock)); + $this->_quoteModelMock->expects($this->any())->method('getBillingAddress') + ->will($this->returnValue($this->_addressMock)); + $this->_quoteModelMock->expects($this->any())->method('getPrice') + ->will($this->returnValue(1)); + $this->_quoteItemMock->expects($this->any())->method('getProduct') + ->will($this->returnValue($this->_productModelMock)); + $this->_quoteItemMock->expects($this->any())->method('getTotalQty') + ->will($this->returnValue(1)); + $this->_quoteItemMock->expects($this->any())->method('getQuote') + ->will($this->returnValue($this->_quoteModelMock)); + $this->_scopeConfigInterfaceMock->expects($this->any())->method('isSetFlag') + ->will($this->returnValue(true)); + $this->_weeeTaxMock->expects($this->any())->method('getProductWeeeAttributes') + ->will($this->returnValue(array($this->_objectMock))); + $this->_weeeDataMock->expects($this->any())->method('getProductWeeeAttributes') + ->will($this->returnValue(array($this->_objectMock))); + $this->_weeeDataMock->expects($this->any())->method('getApplied') + ->will($this->returnValue(array())); + $this->_storeMock->expects($this->any())->method('convertPrice') + ->will($this->returnValue(1)); + } + + /** + * Collect items and apply discount to weee + */ + public function testCollectWithAddItemDiscountPrices() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items without applying discount to weee + */ + public function testCollectWithoutAddItemDiscountPrices() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->never())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items without address item + */ + public function testCollectWithoutAddressItem() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array())); + $this->_addressMock->expects($this->never())->method('setAppliedTaxesReset'); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items with child + */ + public function testCollectWithChildItem() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_quoteItemMock->expects($this->once())->method('isChildrenCalculated') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items with price that includes tax + * + * @param array + */ + public function testCollectPriceIncludesTax() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_addressMock->expects($this->once())->method('getAllNonNominalItems'); + $this->_addressMock->expects($this->once())->method('getAllNonNominalItems'); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_configMock->expects($this->once())->method('priceIncludesTax') + ->will($this->returnValue(false)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items with price that does not include tax + * + * @param array + */ + public function testCollectPriceNotIncludesTax() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_configMock->expects($this->once())->method('priceIncludesTax') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect taxable items + */ + public function testCollectTaxable() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_addressMock->expects($this->once())->method('unsSubtotalInclTax'); + $this->_addressMock->expects($this->once())->method('unsBaseSubtotalInclTax'); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_configMock->expects($this->once())->method('priceIncludesTax') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect does not taxable items + */ + public function testCollectDataStoreDisabled() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_addressMock->expects($this->never())->method('unsSubtotalInclTax'); + $this->_addressMock->expects($this->never())->method('unsBaseSubtotalInclTax'); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->any())->method('includeInSubtotal') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->once(0))->method('isEnabled') + ->will($this->returnValue(false)); + $this->_configMock->expects($this->never())->method('priceIncludesTax') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect items and apply discount to weee + */ + public function testCollectWithChildren() + { + $childQuoteItemMock = $this->getMock('Magento\Sales\Model\Quote\Item', [], [], '', false); + + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_quoteItemMock->expects($this->any())->method('getHasChildren') + ->will($this->returnValue(true)); + $this->_quoteItemMock->expects($this->any())->method('isChildrenCalculated') + ->will($this->returnValue(true)); + $this->_quoteItemMock->expects($this->any())->method('getChildren') + ->will($this->returnValue(array($childQuoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + public function testCollectWeeeIncludeInSubtotal() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(array($this->_quoteItemMock))); + $this->_weeeDataMock->expects($this->any())->method('isDiscounted') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('isTaxable') + ->will($this->returnValue(false)); + $this->_weeeDataMock->expects($this->once())->method('addItemDiscountPrices'); + $this->_weeeDataMock->expects($this->any())->method('isEnabled') + ->will($this->returnValue(true)); + $this->_weeeDataMock->expects($this->any())->method('includeInSubtotal') + ->will($this->returnValue(true)); + $this->_model->collect($this->_addressMock); + } + + /** + * Collect empty items + */ + public function testCollectWithoutItems() + { + $this->_addressMock->expects($this->any())->method('getAllNonNominalItems') + ->will($this->returnValue(null)); + $this->assertEquals($this->_model, $this->_model->collect($this->_addressMock)); + } + + /** + * Fetch method test + */ + public function testFetch() + { + $this->assertEquals($this->_model, $this->_model->fetch($this->_addressMock)); + } + + /** + * Process configuration array + */ + public function testProcessConfigArray() + { + $this->assertEquals( + $this->_configMock, $this->_model->processConfigArray($this->_configMock, $this->_storeMock) + ); + } + + /** + * Get label + */ + public function testGetLabel() + { + $this->assertEquals('', $this->_model->getLabel()); + } +} diff --git a/downloader/lib/Magento/Framework/Connect/Converter.php b/downloader/lib/Magento/Framework/Connect/Converter.php index 0f51b1da174d1..6f8c31842047b 100644 --- a/downloader/lib/Magento/Framework/Connect/Converter.php +++ b/downloader/lib/Magento/Framework/Connect/Converter.php @@ -191,19 +191,27 @@ public function convertPackageObject($pearObject) throw new \Exception("Invalid 'getterArgs' for '{$field}', should be array"); } - if ($useGetter && !method_exists($pearObject, $rules['getter'])) { + if ($useGetter + && (!method_exists($pearObject, $rules['getter']) + || !is_callable([$pearObject, $rules['getter']]) + ) + ) { $mName = get_class($pearObject) . "::" . $rules['getter']; throw new \Exception('No getter method exists: ' . $mName); } - if ($useSetter && !method_exists($mageObject, $rules['setter'])) { + if ($useSetter + && (!method_exists($mageObject, $rules['setter']) + || !is_callable([$mageObject, $rules['setter']]) + ) + ) { $mName = get_class($mageObject) . "::" . $rules['setter']; throw new \Exception('No setter method exists: ' . $mName); } $useConverter = !empty($rules['converter']); - if ($useConverter && false === method_exists($this, $rules['converter'])) { + if ($useConverter && !method_exists($this, $rules['converter'])) { $mName = get_class($this) . "::" . $rules['converter']; throw new \Exception('No converter method exists: ' . $mName); } diff --git a/downloader/lib/Magento/Framework/Connect/Package.php b/downloader/lib/Magento/Framework/Connect/Package.php index 3681ff8969f91..7a25caadcf9b1 100644 --- a/downloader/lib/Magento/Framework/Connect/Package.php +++ b/downloader/lib/Magento/Framework/Connect/Package.php @@ -1223,7 +1223,7 @@ public function validate() /** * Check for method availability, validator */ - if (!method_exists($v, $validatorMethod)) { + if (!method_exists($v, $validatorMethod) || !is_callable([$v, $validatorMethod])) { throw new \Magento\Framework\Exception("Invalid method specified for Validator : {$validatorMethod}"); } diff --git a/lib/internal/Magento/Framework/App/Config/Initial/Reader.php b/lib/internal/Magento/Framework/App/Config/Initial/Reader.php index 25b90165cb4fa..e63c724365e78 100644 --- a/lib/internal/Magento/Framework/App/Config/Initial/Reader.php +++ b/lib/internal/Magento/Framework/App/Config/Initial/Reader.php @@ -60,7 +60,7 @@ class Reader * * @var array */ - protected $_scopePriorityScheme = array('primary', 'global'); + protected $_scopePriorityScheme = array('global'); /** * Path to corresponding XSD file with validation rules for config diff --git a/lib/internal/Magento/Framework/AppInterface.php b/lib/internal/Magento/Framework/AppInterface.php index b025f1a1a3659..12909ce6089ab 100644 --- a/lib/internal/Magento/Framework/AppInterface.php +++ b/lib/internal/Magento/Framework/AppInterface.php @@ -35,7 +35,7 @@ interface AppInterface /** * Magento version */ - const VERSION = '2.0.0.0-dev80'; + const VERSION = '2.0.0.0-dev81'; /** * Launch application diff --git a/lib/internal/Magento/Framework/Archive.php b/lib/internal/Magento/Framework/Archive.php index 68bc94b69beef..1a113687884fe 100644 --- a/lib/internal/Magento/Framework/Archive.php +++ b/lib/internal/Magento/Framework/Archive.php @@ -80,11 +80,8 @@ class Archive */ protected function _getArchiver($extension) { - if (array_key_exists(strtolower($extension), $this->_formats)) { - $format = $this->_formats[$extension]; - } else { - $format = self::DEFAULT_ARCHIVER; - } + $extension = strtolower($extension); + $format = isset($this->_formats[$extension]) ? $this->_formats[$extension] : self::DEFAULT_ARCHIVER; $class = '\\Magento\Framework\Archive\\' . ucfirst($format); $this->_archiver = new $class(); return $this->_archiver; @@ -99,15 +96,10 @@ protected function _getArchiver($extension) protected function _getArchivers($source) { $ext = pathinfo($source, PATHINFO_EXTENSION); - if (!isset($this->_formats[$ext])) { - return array(); - } - $format = $this->_formats[$ext]; - if ($format) { - $archivers = explode('.', $format); - return $archivers; + if (!empty($this->_formats[$ext])) { + return explode('.', $this->_formats[$ext]); } - return array(); + return []; } /** diff --git a/lib/internal/Magento/Framework/Connect/Command.php b/lib/internal/Magento/Framework/Connect/Command.php index b94780cc912ba..a5dd20c163be5 100644 --- a/lib/internal/Magento/Framework/Connect/Command.php +++ b/lib/internal/Magento/Framework/Connect/Command.php @@ -142,7 +142,7 @@ public function run($command, $options, $params) $data = $this->getCommandInfo($command); $method = $data['function']; if (!method_exists($this, $method)) { - throw new \Exception("{$method} does't exist in class " . $this->_class); + throw new \Exception("{$method} can not be executed in class " . $this->_class); } return $this->{$method}($command, $options, $params); } diff --git a/lib/internal/Magento/Framework/Connect/Converter.php b/lib/internal/Magento/Framework/Connect/Converter.php index 63fcc3778821f..a843ab1c467ad 100644 --- a/lib/internal/Magento/Framework/Connect/Converter.php +++ b/lib/internal/Magento/Framework/Connect/Converter.php @@ -196,19 +196,27 @@ public function convertPackageObject($pearObject) throw new \Exception("Invalid 'getterArgs' for '{$field}', should be array"); } - if ($useGetter && !method_exists($pearObject, $rules['getter'])) { + if ($useGetter + && (!method_exists($pearObject, $rules['getter']) + || !is_callable([$pearObject, $rules['getter']]) + ) + ) { $mName = get_class($pearObject) . "::" . $rules['getter']; throw new \Exception('No getter method exists: ' . $mName); } - if ($useSetter && !method_exists($mageObject, $rules['setter'])) { + if ($useSetter + && (!method_exists($mageObject, $rules['setter']) + || !is_callable([$mageObject, $rules['setter']]) + ) + ) { $mName = get_class($mageObject) . "::" . $rules['setter']; throw new \Exception('No setter method exists: ' . $mName); } $useConverter = !empty($rules['converter']); - if ($useConverter && false === method_exists($this, $rules['converter'])) { + if ($useConverter && !method_exists($this, $rules['converter'])) { $mName = get_class($this) . "::" . $rules['converter']; throw new \Exception('No converter method exists: ' . $mName); } diff --git a/lib/internal/Magento/Framework/Connect/Package.php b/lib/internal/Magento/Framework/Connect/Package.php index 599c3c6ff5c7d..9ced857a64ed1 100644 --- a/lib/internal/Magento/Framework/Connect/Package.php +++ b/lib/internal/Magento/Framework/Connect/Package.php @@ -1397,7 +1397,7 @@ public function validate() /** * Check for method availability, validator */ - if (!method_exists($v, $validatorMethod)) { + if (!method_exists($v, $validatorMethod) || !is_callable([$v, $validatorMethod])) { throw new \Magento\Framework\Exception("Invalid method specified for Validator : {$validatorMethod}"); } diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php index e56566387e714..49385b44bfb3b 100644 --- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php +++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php @@ -1141,7 +1141,7 @@ public function getForeignKeys($tableName, $schemaName = null) // collect CONSTRAINT $regExp = '#,\s+CONSTRAINT `([^`]*)` FOREIGN KEY \(`([^`]*)`\) ' - . 'REFERENCES (`[^`]*\.)?`([^`]*)` \(`([^`]*)`\)' + . 'REFERENCES (`([^`]*)`\.)?`([^`]*)` \(`([^`]*)`\)' . '( ON DELETE (RESTRICT|CASCADE|SET NULL|NO ACTION))?' . '( ON UPDATE (RESTRICT|CASCADE|SET NULL|NO ACTION))?#'; $matches = array(); @@ -1152,11 +1152,11 @@ public function getForeignKeys($tableName, $schemaName = null) 'SCHEMA_NAME' => $schemaName, 'TABLE_NAME' => $tableName, 'COLUMN_NAME' => $match[2], - 'REF_SHEMA_NAME' => isset($match[3]) ? $match[3] : $schemaName, - 'REF_TABLE_NAME' => $match[4], - 'REF_COLUMN_NAME' => $match[5], - 'ON_DELETE' => isset($match[6]) ? $match[7] : '', - 'ON_UPDATE' => isset($match[8]) ? $match[9] : '' + 'REF_SHEMA_NAME' => isset($match[4]) ? $match[4] : $schemaName, + 'REF_TABLE_NAME' => $match[5], + 'REF_COLUMN_NAME' => $match[6], + 'ON_DELETE' => isset($match[7]) ? $match[8] : '', + 'ON_UPDATE' => isset($match[9]) ? $match[10] : '' ); } diff --git a/lib/internal/Magento/Framework/Event/Invoker/InvokerDefault.php b/lib/internal/Magento/Framework/Event/Invoker/InvokerDefault.php index 5709c05df784a..721736e899df1 100644 --- a/lib/internal/Magento/Framework/Event/Invoker/InvokerDefault.php +++ b/lib/internal/Magento/Framework/Event/Invoker/InvokerDefault.php @@ -87,7 +87,7 @@ public function dispatch(array $configuration, Observer $observer) */ protected function _callObserverMethod($object, $method, $observer) { - if (method_exists($object, $method)) { + if (method_exists($object, $method) && is_callable([$object, $method])) { $object->{$method}($observer); } elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) { throw new \LogicException('Method "' . $method . '" is not defined in "' . get_class($object) . '"'); diff --git a/lib/internal/Magento/Framework/Exception/CouldNotSaveException.php b/lib/internal/Magento/Framework/Exception/CouldNotSaveException.php new file mode 100644 index 0000000000000..120db878b4c03 --- /dev/null +++ b/lib/internal/Magento/Framework/Exception/CouldNotSaveException.php @@ -0,0 +1,30 @@ +_validateCallbacks as $params) { - if (is_object($params['object']) && method_exists($params['object'], $params['method'])) { + if (is_object($params['object']) + && method_exists($params['object'], $params['method']) + && is_callable([$params['object'], $params['method']]) + ) { $params['object']->{$params['method']}($this->_file['tmp_name']); } } diff --git a/lib/internal/Magento/Framework/Filter/Template.php b/lib/internal/Magento/Framework/Filter/Template.php index 867c0d4965152..e22208d53c72b 100644 --- a/lib/internal/Magento/Framework/Filter/Template.php +++ b/lib/internal/Magento/Framework/Filter/Template.php @@ -119,9 +119,9 @@ public function filter($value) { // "depend" and "if" operands should be first foreach (array( - self::CONSTRUCTION_DEPEND_PATTERN => 'dependDirective', - self::CONSTRUCTION_IF_PATTERN => 'ifDirective' - ) as $pattern => $directive) { + self::CONSTRUCTION_DEPEND_PATTERN => 'dependDirective', + self::CONSTRUCTION_IF_PATTERN => 'ifDirective' + ) as $pattern => $directive) { if (preg_match_all($pattern, $value, $constructions, PREG_SET_ORDER)) { foreach ($constructions as $construction) { $callback = array($this, $directive); @@ -269,7 +269,7 @@ protected function _getVariable($value, $default = '{no_value_defined}') $stackVars[$i]['variable'] =& $this->_templateVars[$stackVars[$i]['name']]; } elseif (isset( $stackVars[$i - 1]['variable'] - ) && $stackVars[$i - 1]['variable'] instanceof \Magento\Framework\Object + ) && $stackVars[$i - 1]['variable'] instanceof \Magento\Framework\Object ) { // If object calling methods or getting properties if ($stackVars[$i]['type'] == 'property') { diff --git a/lib/internal/Magento/Framework/Gdata/Gshopping/Content.php b/lib/internal/Magento/Framework/Gdata/Gshopping/Content.php index f3c58c488d7ad..128e594f7d5f4 100644 --- a/lib/internal/Magento/Framework/Gdata/Gshopping/Content.php +++ b/lib/internal/Magento/Framework/Gdata/Gshopping/Content.php @@ -278,7 +278,7 @@ public function setDebug($flag) */ public function setLogAdapter($instance, $method) { - if (method_exists($instance, $method)) { + if (method_exists($instance, $method) && is_callable([$instance, $method])) { $this->_logAdapter = $instance; $this->_logAdapterLogAction = $method; } diff --git a/lib/internal/Magento/Framework/Model/AbstractModel.php b/lib/internal/Magento/Framework/Model/AbstractModel.php index 59880c84189d0..ccf03d36baca7 100644 --- a/lib/internal/Magento/Framework/Model/AbstractModel.php +++ b/lib/internal/Magento/Framework/Model/AbstractModel.php @@ -164,7 +164,9 @@ public function __construct( $this->_logger = $context->getLogger(); $this->_actionValidator = $context->getActionValidator(); - if (method_exists($this->_resource, 'getIdFieldName') || $this->_resource instanceof \Magento\Framework\Object) { + if (method_exists($this->_resource, 'getIdFieldName') + || $this->_resource instanceof \Magento\Framework\Object + ) { $this->_idFieldName = $this->_getResource()->getIdFieldName(); } diff --git a/lib/internal/Magento/Framework/ObjectManager/Factory/Factory.php b/lib/internal/Magento/Framework/ObjectManager/Factory/Factory.php index 86ac4db6d3de7..7077e7ae27af7 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Factory/Factory.php +++ b/lib/internal/Magento/Framework/ObjectManager/Factory/Factory.php @@ -164,7 +164,7 @@ protected function parseArray(&$array) ? $this->globalArguments[$item['argument']] : null; } else { - $this->parseArray($item); + $this->parseArray($array[$key]); } } } diff --git a/lib/internal/Magento/Framework/Registry.php b/lib/internal/Magento/Framework/Registry.php index f4d59f11ea211..275dbf8778f30 100644 --- a/lib/internal/Magento/Framework/Registry.php +++ b/lib/internal/Magento/Framework/Registry.php @@ -78,7 +78,10 @@ public function register($key, $value, $graceful = false) public function unregister($key) { if (isset($this->_registry[$key])) { - if (is_object($this->_registry[$key]) && method_exists($this->_registry[$key], '__destruct')) { + if (is_object($this->_registry[$key]) + && method_exists($this->_registry[$key], '__destruct') + && is_callable([$this->_registry[$key], '__destruct']) + ) { $this->_registry[$key]->__destruct(); } unset($this->_registry[$key]); diff --git a/lib/internal/Magento/Framework/Service/Data/AbstractObject.php b/lib/internal/Magento/Framework/Service/Data/AbstractObject.php index c4d534d29c531..efa021b882fe9 100644 --- a/lib/internal/Magento/Framework/Service/Data/AbstractObject.php +++ b/lib/internal/Magento/Framework/Service/Data/AbstractObject.php @@ -63,13 +63,16 @@ protected function _get($key) public function __toArray() { $data = $this->_data; + $hasToArray = function ($model) { + return is_object($model) && method_exists($model, '__toArray') && is_callable([$model, '__toArray']); + }; foreach ($data as $key => $value) { - if (is_object($value) && method_exists($value, '__toArray')) { + if ($hasToArray($value)) { $data[$key] = $value->__toArray(); } elseif (is_array($value)) { - foreach ($value as $nestedArrayKey => $nestedArrayValue) { - if (is_object($nestedArrayValue) && method_exists($nestedArrayValue, '__toArray')) { - $value[$nestedArrayKey] = $nestedArrayValue->__toArray(); + foreach ($value as $nestedKey => $nestedValue) { + if ($hasToArray($nestedValue)) { + $value[$nestedKey] = $nestedValue->__toArray(); } } $data[$key] = $value; diff --git a/lib/internal/Magento/Framework/Service/Data/AbstractObjectBuilder.php b/lib/internal/Magento/Framework/Service/Data/AbstractObjectBuilder.php index 86c5ddf0b863f..81bbd1c075b8a 100644 --- a/lib/internal/Magento/Framework/Service/Data/AbstractObjectBuilder.php +++ b/lib/internal/Magento/Framework/Service/Data/AbstractObjectBuilder.php @@ -34,11 +34,17 @@ abstract class AbstractObjectBuilder protected $_data; /** - * Initialize internal storage + * @var ObjectFactory */ - public function __construct() + protected $objectFactory; + + /** + * @param ObjectFactory $objectFactory + */ + public function __construct(ObjectFactory $objectFactory) { $this->_data = array(); + $this->objectFactory = $objectFactory; } /** @@ -152,7 +158,7 @@ public function mergeDataObjectWithArray(AbstractObject $dataObject, array $data public function create() { $dataObjectType = $this->_getDataObjectType(); - $dataObject = new $dataObjectType($this); + $dataObject = $this->objectFactory->create($dataObjectType, ['builder' => $this]); $this->_data = array(); return $dataObject; } diff --git a/lib/internal/Magento/Framework/Service/Data/Eav/AbstractObjectBuilder.php b/lib/internal/Magento/Framework/Service/Data/Eav/AbstractObjectBuilder.php index e121f6c5d25e5..234117461e9cb 100644 --- a/lib/internal/Magento/Framework/Service/Data/Eav/AbstractObjectBuilder.php +++ b/lib/internal/Magento/Framework/Service/Data/Eav/AbstractObjectBuilder.php @@ -34,12 +34,15 @@ abstract class AbstractObjectBuilder extends \Magento\Framework\Service\Data\Abs protected $_valueBuilder; /** + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory * @param AttributeValueBuilder $valueBuilder */ - public function __construct(AttributeValueBuilder $valueBuilder) - { + public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, + AttributeValueBuilder $valueBuilder + ) { $this->_valueBuilder = $valueBuilder; - parent::__construct(); + parent::__construct($objectFactory); } /** diff --git a/app/code/Magento/Paypal/Model/Method/ProTypeFactory.php b/lib/internal/Magento/Framework/Service/Data/ObjectFactory.php similarity index 70% rename from app/code/Magento/Paypal/Model/Method/ProTypeFactory.php rename to lib/internal/Magento/Framework/Service/Data/ObjectFactory.php index 9fbfcb72e2619..a758b69201a94 100644 --- a/app/code/Magento/Paypal/Model/Method/ProTypeFactory.php +++ b/lib/internal/Magento/Framework/Service/Data/ObjectFactory.php @@ -21,39 +21,33 @@ * @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ -namespace Magento\Paypal\Model\Method; -/** - * Factory class for payment method model - */ -class ProTypeFactory +namespace Magento\Framework\Service\Data; + +class ObjectFactory { /** - * Object Manager instance - * * @var \Magento\Framework\ObjectManager */ - protected $_objectManager = null; + protected $objectManager; /** - * Factory constructor - * * @param \Magento\Framework\ObjectManager $objectManager */ public function __construct(\Magento\Framework\ObjectManager $objectManager) { - $this->_objectManager = $objectManager; + $this->objectManager = $objectManager; } /** - * Create class instance with specified parameters + * Create data object * * @param string $className - * @param array $data - * @return \Magento\Framework\Object + * @param array $arguments + * @return AbstractObject */ - public function create($className, array $data = array()) + public function create($className, array $arguments) { - return $this->_objectManager->create($className, $data); + return $this->objectManager->create($className, $arguments); } } diff --git a/lib/internal/Magento/Framework/Service/V1/Data/Search/FilterGroupBuilder.php b/lib/internal/Magento/Framework/Service/V1/Data/Search/FilterGroupBuilder.php index aaf1bfcabb760..1dbe072de9755 100644 --- a/lib/internal/Magento/Framework/Service/V1/Data/Search/FilterGroupBuilder.php +++ b/lib/internal/Magento/Framework/Service/V1/Data/Search/FilterGroupBuilder.php @@ -38,13 +38,14 @@ class FilterGroupBuilder extends AbstractObjectBuilder protected $_filterBuilder; /** - * Constructor - * + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory * @param FilterBuilder $filterBuilder */ - public function __construct(FilterBuilder $filterBuilder) - { - parent::__construct(); + public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, + FilterBuilder $filterBuilder + ) { + parent::__construct($objectFactory); $this->_filterBuilder = $filterBuilder; } diff --git a/lib/internal/Magento/Framework/Service/V1/Data/SearchCriteriaBuilder.php b/lib/internal/Magento/Framework/Service/V1/Data/SearchCriteriaBuilder.php index a938584c8929c..9e56257d09e9e 100644 --- a/lib/internal/Magento/Framework/Service/V1/Data/SearchCriteriaBuilder.php +++ b/lib/internal/Magento/Framework/Service/V1/Data/SearchCriteriaBuilder.php @@ -38,13 +38,14 @@ class SearchCriteriaBuilder extends AbstractObjectBuilder protected $_filterGroupBuilder; /** - * Constructor - * + * @param \Magento\Framework\Service\Data\ObjectFactory $objectFactory * @param FilterGroupBuilder $filterGroupBuilder */ - public function __construct(FilterGroupBuilder $filterGroupBuilder) - { - parent::__construct(); + public function __construct( + \Magento\Framework\Service\Data\ObjectFactory $objectFactory, + FilterGroupBuilder $filterGroupBuilder + ) { + parent::__construct($objectFactory); $this->_filterGroupBuilder = $filterGroupBuilder; }