Skip to content

Commit

Permalink
Merge pull request #173 from magento-api/Bug-Fixes
Browse files Browse the repository at this point in the history
[API] Bug fixes
  • Loading branch information
Tulika,Eugene(etulika) committed Mar 20, 2015
2 parents 892718b + 6a26a69 commit 3a802e2
Show file tree
Hide file tree
Showing 15 changed files with 150 additions and 38 deletions.
6 changes: 0 additions & 6 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@

</IfModule>

############################################
## By default allow all access

Order allow,deny
Allow from all

###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version

Expand Down
6 changes: 0 additions & 6 deletions .htaccess.sample
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,6 @@

</IfModule>

############################################
## By default allow all access

Order allow,deny
Allow from all

###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
namespace Magento\CatalogUrlRewrite\Model\Category\Plugin\Category;

use Magento\Catalog\Model\Category;
use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider;
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
Expand Down Expand Up @@ -41,15 +41,20 @@ public function __construct(
/**
* Remove product urls from storage
*
* @param Category $category
* @param \Magento\Catalog\Model\Resource\Category $subject
* @param callable $proceed
* @param CategoryInterface $category
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(Category $category, \Closure $proceed)
{
public function aroundDelete(
\Magento\Catalog\Model\Resource\Category $subject,
\Closure $proceed,
CategoryInterface $category
) {
$categoryIds = $this->childrenCategoriesProvider->getChildrenIds($category, true);
$categoryIds[] = $category->getId();
$result = $proceed();
$result = $proceed($category);
foreach ($categoryIds as $categoryId) {
$this->deleteRewritesForCategory($categoryId);
}
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/CatalogUrlRewrite/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
<type name="Magento\Store\Model\Resource\Group">
<plugin name="group_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Store\Group"/>
</type>
<type name="Magento\Catalog\Model\Category">
<plugin name="category_delete_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Remove"/>
</type>
<type name="Magento\CatalogImportExport\Model\Import\Product">
<plugin name="import_save_plugin" type="Magento\CatalogUrlRewrite\Model\Product\Plugin\Import"/>
</type>
<type name="Magento\Catalog\Model\Resource\Category">
<plugin name="category_move_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Move"/>
<plugin name="category_delete_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Remove"/>
</type>
<type name="Magento\UrlRewrite\Model\StorageInterface">
<plugin name="storage_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Storage"/>
Expand Down
4 changes: 4 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<argument name="urlFinder" xsi:type="object">Magento\CatalogUrlRewrite\Model\Storage\DbStorage</argument>
</arguments>
</type>
<type name="Magento\Catalog\Model\Resource\Category">
<plugin name="category_move_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Move"/>
<plugin name="category_delete_plugin" type="Magento\CatalogUrlRewrite\Model\Category\Plugin\Category\Remove"/>
</type>
</config>
15 changes: 15 additions & 0 deletions app/code/Magento/CatalogUrlRewrite/etc/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Event/etc/events.xsd">
<event name="catalog_category_prepare_save">
<observer name="category_save_rewrites_history_setter" instance="Magento\CatalogUrlRewrite\Observer\CategorySaveRewritesHistorySetter" method="invoke"/>
</event>
<event name="catalog_category_save_after">
<observer name="process_url_rewrite_saving" instance="Magento\CatalogUrlRewrite\Model\Category\Observer" method="processUrlRewriteSaving"/>
</event>
</config>
10 changes: 10 additions & 0 deletions app/code/Magento/Config/Model/Config/Backend/Image/Logo.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,14 @@ protected function _addWhetherScopeInfo()
{
return true;
}

/**
* Getter for allowed extensions of uploaded files.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['jpg', 'jpeg', 'gif', 'png', 'svg'];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Config\Test\Unit\Model\Config\Backend\Image;

class LogoTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Config\Model\Config\Backend\Image\Logo
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $uploaderFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $uploaderMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $requestDataMock;

public function setUp()
{
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->uploaderFactoryMock = $this->getMockBuilder('\Magento\MediaStorage\Model\File\UploaderFactory')
->setMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->uploaderMock = $this->getMockBuilder('\Magento\MediaStorage\Model\File\Uploader')
->setMethods(['setAllowedExtensions', 'save'])
->disableOriginalConstructor()
->getMock();
$this->uploaderFactoryMock
->expects($this->once())
->method('create')
->will($this->returnValue($this->uploaderMock));
$this->requestDataMock = $this
->getMockBuilder('\Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface')
->setMethods(['getTmpName'])
->getMockForAbstractClass();
$mediaDirectoryMock = $this->getMockBuilder('\Magento\Framework\Filesystem\Directory\WriteInterface')
->disableOriginalConstructor()
->getMockForAbstractClass();
$filesystemMock = $this->getMockBuilder('\Magento\Framework\Filesystem')
->disableOriginalConstructor()
->setMethods(['getDirectoryWrite'])
->getMock();
$filesystemMock->expects($this->once())
->method('getDirectoryWrite')
->will($this->returnValue($mediaDirectoryMock));
$this->model = $helper->getObject(
'Magento\Config\Model\Config\Backend\Image\Logo',
[
'uploaderFactory' => $this->uploaderFactoryMock,
'requestData' => $this->requestDataMock,
'filesystem' => $filesystemMock,
]
);
}

public function testBeforeSave()
{
$this->requestDataMock->expects($this->once())
->method('getTmpName')
->will($this->returnValue('/tmp/val'));
$this->uploaderMock->expects($this->once())
->method('setAllowedExtensions')
->with($this->equalTo(['jpg', 'jpeg', 'gif', 'png', 'svg']));
$this->model->beforeSave();
}
}
6 changes: 0 additions & 6 deletions app/code/Magento/Customer/etc/webapi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,6 @@
<resource ref="anonymous"/>
</resources>
</route>
<route url="/V1/customers/:customerId/password" method="PUT">
<service class="Magento\Customer\Api\AccountManagementInterface" method="resetPassword"/>
<resources>
<resource ref="Magento_Customer::manage"/>
</resources>
</route>
<route url="/V1/customers/:customerId/confirm" method="GET">
<service class="Magento\Customer\Api\AccountManagementInterface" method="getConfirmationStatus"/>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/view/email/shipment_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"var order.shipping_address.format('html')":"Shipping Address",
"var order.shipping_description":"Shipping Description",
"layout handle=\"sales_email_order_shipment_items\" shipment=$shipment order=$order":"Shipment Items Grid",
"block type='Magento\Framework\View\Element\Template' area='frontend' template='email/shipment/track.phtml' shipment=$shipment order=$order":"Shipment Track Details",
"block type='Magento\\Framework\\View\\Element\\Template' area='frontend' template='email/shipment/track.phtml' shipment=$shipment order=$order":"Shipment Track Details",
"var comment":"Shipment Comment"}
@-->
<!--@styles
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sales/view/email/shipment_new_guest.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"var order.shipping_address.format('html')":"Shipping Address",
"var order.shipping_description":"Shipping Description",
"layout handle=\"sales_email_order_shipment_items\" shipment=$shipment order=$order":"Shipment Items Grid",
"block type='Magento\Framework\View\Element\Template' area='frontend' template='email/shipment/track.phtml' shipment=$shipment order=$order":"Shipment Track Details",
"block type='Magento\\Framework\\View\\Element\\Template' area='frontend' template='email/shipment/track.phtml' shipment=$shipment order=$order":"Shipment Track Details",
"var comment":"Shipment Comment"}
@-->
<!--@styles
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Theme/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<label>Header</label>
<field id="logo_src" translate="label" type="image" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Logo Image</label>
<comment>Allowed file types:PNG, GIF, JPG, JPEG.</comment>
<comment>Allowed file types:PNG, GIF, JPG, JPEG, SVG.</comment>
<backend_model>Magento\Config\Model\Config\Backend\Image\Logo</backend_model>
<base_url type="media" scope_info="1">logo</base_url>
</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;

class CategoryRepositoryTest extends WebapiAbstract
{
Expand Down Expand Up @@ -98,14 +100,35 @@ public function testCreate($category)
{
$category = $this->createCategory($category);
$this->assertGreaterThan(0, $category['id']);
// delete category to clean up auto-generated url rewrites
$this->deleteCategory($category['id']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/category.php
*/
public function testDelete()
{
/** @var \Magento\UrlRewrite\Model\Storage\DbStorage $storage */
$storage = Bootstrap::getObjectManager()->get('Magento\UrlRewrite\Model\Storage\DbStorage');
$categoryId = $this->modelId;
$data = [
UrlRewrite::ENTITY_ID => $categoryId,
UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE
];
/** @var \Magento\UrlRewrite\Service\V1\Data\UrlRewrite $urlRewrite*/
$urlRewrite = $storage->findOneByData($data);

// Assert that a url rewrite is auto-generated for the category created from the data fixture
$this->assertEquals(1, $urlRewrite->getIsAutogenerated());
$this->assertEquals($categoryId, $urlRewrite->getEntityId());
$this->assertEquals(CategoryUrlRewriteGenerator::ENTITY_TYPE, $urlRewrite->getEntityType());
$this->assertEquals('category-1.html', $urlRewrite->getRequestPath());

// Assert deleting category is successful
$this->assertTrue($this->deleteCategory($this->modelId));
// After the category is deleted, assert that the associated url rewrite is also auto-deleted
$this->assertNull($storage->findOneByData($data));
}

public function testDeleteNoSuchEntityException()
Expand Down Expand Up @@ -156,6 +179,8 @@ public function testUpdate()
$category = $model->load($categoryId);
$this->assertEquals("Update Category Test", $category->getName());
$this->assertEquals("Update Category Description Test", $category->getDescription());
// delete category to clean up auto-generated url rewrites
$this->deleteCategory($categoryId);
}

protected function getSimpleCategoryData($categoryData = [])
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/Magento/Framework/Filesystem/Directory/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ protected function setPath($path)
* E.g.: /var/www/application/file.txt
*
* @param string $path
* @param string $schema
* @param string $scheme
* @return string
*/
public function getAbsolutePath($path = null, $schema = null)
public function getAbsolutePath($path = null, $scheme = null)
{
return $this->driver->getAbsolutePath($this->path, $path, $schema);
return $this->driver->getAbsolutePath($this->path, $path, $scheme);
}

/**
Expand Down
6 changes: 0 additions & 6 deletions pub/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@

</IfModule>

############################################
## By default allow all access

Order allow,deny
Allow from all

###########################################
## Deny access to release notes to prevent disclosure of the installed Magento version

Expand Down

0 comments on commit 3a802e2

Please sign in to comment.