-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ebizmarts/develop
Version 3.0.12
- Loading branch information
Showing
12 changed files
with
266 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* Ebizmarts_Mandrill Magento JS component | ||
* | ||
* @category Ebizmarts | ||
* @package Ebizmarts_Mandrill | ||
* @author Ebizmarts Team <info@ebizmarts.com> | ||
* @copyright Ebizmarts (http://ebizmarts.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
namespace Ebizmarts\Mandrill\Model\Plugin; | ||
|
||
class TransportInterfaceFactory | ||
{ | ||
/** | ||
* Mandrill Transport Factory | ||
* | ||
* @var \Ebizmarts\Mandrill\Model\TransportFactory | ||
*/ | ||
protected $mandrillTransportFactory; | ||
|
||
/** | ||
* Mandrill Helper class | ||
* | ||
* @var \Ebizmarts\Mandrill\Helper\Data | ||
*/ | ||
protected $mandrillHelper; | ||
|
||
/** | ||
* TransportBuilder constructor. | ||
* @param \Ebizmarts\Mandrill\Helper\Data $mandrillHelper | ||
* @param \Ebizmarts\Mandrill\Model\TransportFactory $mandrillTransportFactory | ||
*/ | ||
public function __construct( | ||
\Ebizmarts\Mandrill\Helper\Data $mandrillHelper, | ||
\Ebizmarts\Mandrill\Model\TransportFactory $mandrillTransportFactory | ||
) { | ||
$this->mandrillHelper = $mandrillHelper; | ||
$this->mandrillTransportFactory = $mandrillTransportFactory; | ||
} | ||
|
||
/** | ||
* Replace mail transport with Mandrill if needed | ||
* | ||
* @param \Magento\Framework\Mail\TransportInterfaceFactory $subject | ||
* @param \Closure $proceed | ||
* @param array $data | ||
* | ||
* @return \Magento\Framework\Mail\TransportInterface | ||
*/ | ||
public function aroundCreate( | ||
\Magento\Framework\Mail\TransportInterfaceFactory $subject, | ||
\Closure $proceed, | ||
array $data = [] | ||
) { | ||
if ($this->isMandrillEnabled() === false) { | ||
/** @var \Magento\Framework\Mail\TransportInterface $transport */ | ||
return $proceed($data); | ||
} else { | ||
return $this->mandrillTransportFactory->create($data); | ||
} | ||
} | ||
|
||
/** | ||
* Get status of Mandrill | ||
* | ||
* @return bool | ||
*/ | ||
private function isMandrillEnabled() | ||
{ | ||
return $this->mandrillHelper->isMandrillEnabled(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\Mandrill\Test\Integration; | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
use Magento\Framework\Module\ModuleList; | ||
use Magento\TestFramework\ObjectManager; | ||
|
||
class ModuleConfigTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
const MODULE_NAME = 'Ebizmarts_Mandrill'; | ||
|
||
/** | ||
* @var $objectManager ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
protected function setUp() | ||
{ | ||
/** @var ObjectManager objectManager */ | ||
$this->objectManager = ObjectManager::getInstance(); | ||
} | ||
|
||
public function testTheModuleIsRegistered() | ||
{ | ||
$registrar = new ComponentRegistrar(); | ||
$this->assertArrayHasKey(self::MODULE_NAME, $registrar->getPaths(ComponentRegistrar::MODULE)); | ||
} | ||
|
||
public function testTheModuleIsConfiguredInTheTestEnvironment() | ||
{ | ||
/** @var $moduleList ModuleList */ | ||
$moduleList = $this->objectManager->create(ModuleList::class); | ||
$this->assertTrue($moduleList->has(self::MODULE_NAME)); | ||
} | ||
|
||
public function testTheModuleIsConfiguredInTheRealEnvironment() | ||
{ | ||
// The tests by default point to the wrong config directory for this test. | ||
$directoryList = $this->objectManager->create( | ||
\Magento\Framework\App\Filesystem\DirectoryList::class, | ||
['root' => BP] | ||
); | ||
$deploymentConfigReader = $this->objectManager->create( | ||
\Magento\Framework\App\DeploymentConfig\Reader::class, | ||
['dirList' => $directoryList] | ||
); | ||
$deploymentConfig = $this->objectManager->create( | ||
\Magento\Framework\App\DeploymentConfig::class, | ||
['reader' => $deploymentConfigReader] | ||
); | ||
|
||
/** @var $moduleList ModuleList */ | ||
$moduleList = $this->objectManager->create( | ||
ModuleList::class, | ||
['config' => $deploymentConfig] | ||
); | ||
$this->assertTrue($moduleList->has(self::MODULE_NAME)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\Mandrill\Test\Unit\Model\Plugin; | ||
|
||
class TransportInterfaceFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Main TransportInterfaceFactory test class | ||
* | ||
* @var \Ebizmarts\Mandrill\Model\Plugin\TransportInterfaceFactory | ||
*/ | ||
protected $factoryClass; | ||
|
||
/** | ||
* Returned Mandrill transport model | ||
* | ||
* @var \Ebizmarts\Mandrill\Model\Transport | ||
*/ | ||
protected $mandrillTransportMock; | ||
|
||
/** | ||
* Constructor message data | ||
* | ||
* @var array | ||
*/ | ||
protected $data; | ||
|
||
public function setUp() | ||
{ | ||
$mailMessageMock = $this->getMockBuilder(\Magento\Framework\Mail\Message::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->data = [ | ||
'message' => $mailMessageMock | ||
]; | ||
|
||
$mandrillHelperMock = $this->getMockBuilder(\Ebizmarts\Mandrill\Helper\Data::class) | ||
->setMethods(['isMandrillEnabled']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$mandrillHelperMock->expects($this->at(0))->method('isMandrillEnabled')->will($this->returnValue(false)); | ||
$mandrillHelperMock->expects($this->at(1))->method('isMandrillEnabled')->will($this->returnValue(true)); | ||
|
||
$mandrillTransportFactoryMock = $this->getMockBuilder(\Ebizmarts\Mandrill\Model\TransportFactory::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->mandrillTransportMock = $this->getMockBuilder(\Ebizmarts\Mandrill\Model\Transport::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$mandrillTransportFactoryMock->expects($this->once())->method('create') | ||
->with($this->equalTo($this->data))->willReturn($this->mandrillTransportMock); | ||
|
||
$this->factoryClass = new \Ebizmarts\Mandrill\Model\Plugin\TransportInterfaceFactory($mandrillHelperMock, $mandrillTransportFactoryMock); | ||
} | ||
|
||
public function testAroundCreate() | ||
{ | ||
$transportFactoryMock = $this->getMockBuilder(\Magento\Framework\Mail\TransportInterfaceFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$transportInterfaceMock = $this->getMockBuilder(\Magento\Framework\Mail\TrasportInterface::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$closure = function ($data) use ($transportInterfaceMock) { | ||
$this->assertSame($this->data, $data); | ||
return $transportInterfaceMock; | ||
}; | ||
|
||
$this->assertEquals( | ||
$transportInterfaceMock, | ||
$this->factoryClass->aroundCreate($transportFactoryMock, $closure, $this->data) | ||
); | ||
|
||
$this->assertEquals( | ||
$this->mandrillTransportMock, | ||
$this->factoryClass->aroundCreate($transportFactoryMock, $closure, $this->data) | ||
); | ||
} | ||
} |
Oops, something went wrong.