From 2a36edbb2c03124881c5e2bb320b14ba58e7b1ed Mon Sep 17 00:00:00 2001 From: Patrick Blom Date: Fri, 10 Apr 2020 22:08:36 +0200 Subject: [PATCH] finalize tests, update readme and changelog --- CHANGELOG.md | 4 +- README.md | 52 ++++++++++++++++++++++--- Tests/Unit/Core/EmailTest.php | 73 +++++++++++++++++++++++++++++++---- composer.json | 3 +- config.inc.TEST.php.dist | 11 ++++++ 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 config.inc.TEST.php.dist diff --git a/CHANGELOG.md b/CHANGELOG.md index 4396b58..99cb67e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -## [v1.0.0] - 2020-04-02 +## [v1.0.0] - 2020-04-10 ### Added -- Initial module commit +- Initial module release diff --git a/README.md b/README.md index 2de23c6..b044a0d 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,19 @@ admin order mail. ![Image alt="preview of the module"](module-preview.png) -### Compatability +### Compatibility -* This module is OXID eShop 6.2 only +* The module is OXID eShop 6.2 and higher only +* The module was build and will work on the OXID eShop Community Edition +* The module should work on OXID eShop Professional Edition and OXID eShop Enterprise Edition +* The module was tested on the OXID eShop Community Edition +* The module wat **not tested** on OXID eShop Professional Edition and OXID eShop Enterprise Edition + + +### Requirements + +* OXID eShop 6.2 Community Edition (or higher) +* PHP 7.1 (or higher) ### Module installation via composer @@ -36,9 +46,39 @@ admin order mail. * `vendor/bin/oe-eshop-unified_namespace_generator` * `vendor/bin/oe-eshop-db_views_regenerate` -## Usage +### Usage -- After the installation you will find a new mail address field called `Additional e-mail addresses for orders` under: - - `Master Settings -> Core Settings -> Main (right side)` -- The additional mail addresses must be separated by a semicolon (;) +* After the installation and activation you will find a new mail address field called `Additional e-mail addresses for orders` under: + * `Master Settings -> Core Settings -> Main (right side)` +* The additional mail addresses must be separated by a semicolon (;) +* Only valid mail addresses will be added as carbon copy +* If no address is provided, no carbon copy entry will be set +### Testing + +#### !Attention! +The testing process should only be done in a development environment or CI pipeline. + +#### Preparing +* Install the module as described +* Prepare the [OXID Testing Library](https://github.com/OXID-eSales/testing_library) likes described in their repository +or use the [oxvm_eshop](https://github.com/OXID-eSales/oxvm_eshop) / [docker-eshop-sdk](https://github.com/OXID-eSales/docker-eshop-sdk) +* Add `pb/MultiOrderMailReceiver` to the partial module paths in your test_config.yml (e.g: `partial_module_paths: 'pb/MultiOrderMailReceiver'`) +* Copy the `config.inc.TEST.php.dist` to your shop root and rename it to `config.inc.TEST.php` +* Adjust the settings in the `config.inc.TEST.php` to your needs (test database name, error reporting, etc) +* Modify your `config.inc.php` and ensure that the `config.inc.TEST.php` will be loaded during the tests +```php + // bottom of config.inc.php + if (defined('OXID_PHP_UNIT')) { + include "config.inc.TEST.php"; + } +``` + +#### Run tests +* Navigate to the shop root +* Run the test using the following command: `php vendor/bin/runtests /source/modules/pb/MultiOrderMailReceiver/Tests` +* Run the coverage using the following command: `php vendor/bin/runtests-coverage /source/modules/pb/MultiOrderMailReceiver/Tests` + + +### License +The module is released under GPL-3.0. For a full overview check the [LICENSE](LICENSE) file. diff --git a/Tests/Unit/Core/EmailTest.php b/Tests/Unit/Core/EmailTest.php index 0a68013..db398dc 100644 --- a/Tests/Unit/Core/EmailTest.php +++ b/Tests/Unit/Core/EmailTest.php @@ -2,7 +2,11 @@ namespace PaBlo\MultiOrderMailReceiver\Test\Unit\Core; +use OxidEsales\Eshop\Application\Model\Order; use OxidEsales\Eshop\Application\Model\Shop; +use OxidEsales\Eshop\Core\Field; +use OxidEsales\Eshop\Core\Price; +use OxidEsales\Eshop\Application\Model\User; use OxidEsales\TestingLibrary\UnitTestCase; use PaBlo\MultiOrderMailReceiver\Core\Email; @@ -29,7 +33,7 @@ public function setUp() parent::setUp(); $this->SUT = $this->getMockBuilder(Email::class) - ->setMethods(['__call', 'send', 'getRenderer']) + ->setMethods(['__call', '_sendMail']) ->getMock(); } @@ -83,7 +87,6 @@ public function testSetCarbonCopy_withValidData(): void $this->assertSame('Max Muster', $carbonCopies[0][1]); } - /** * @covers \PaBlo\MultiOrderMailReceiver\Core\Email::setCarbonCopy * @covers \PaBlo\MultiOrderMailReceiver\Core\Email::idnToAscii @@ -124,7 +127,6 @@ public function testSetCarbonCopyActive_willSetInternalStateTrue(): void $this->assertTrue($internalState); } - /** * @covers \PaBlo\MultiOrderMailReceiver\Core\Email::getCarbonCopyActiveState */ @@ -176,7 +178,7 @@ public function testSetFrom_willAddCarbonCopyEntries(): void { // add demo carbon copies /** @var Shop $shop */ - $shop = $this->getConfig()->getActiveShop(); + $shop = $this->getConfig()->getActiveShop(); $shop->oxshops__pbowneremailreceiver->rawValue = 'foo@bar.com;NOEMAILADDRESS;bar@baz.de'; $shop->save(); @@ -190,12 +192,67 @@ public function testSetFrom_willAddCarbonCopyEntries(): void $this->assertTrue($result); $carbonCopies = $this->SUT->getCarbonCopy(); + $this->assertNotEmpty($carbonCopies); $this->assertCount(2, $carbonCopies); - $this->assertSame('foo@bar.com',$carbonCopies[0][0]); - $this->assertSame('bar@baz.de',$carbonCopies[1][0]); - $this->assertSame('order',$carbonCopies[0][1]); - $this->assertSame('order',$carbonCopies[1][1]); + $this->assertSame('foo@bar.com', $carbonCopies[0][0]); + $this->assertSame('bar@baz.de', $carbonCopies[1][0]); + $this->assertSame('order', $carbonCopies[0][1]); + $this->assertSame('order', $carbonCopies[1][1]); + + } + + /** + * @covers \PaBlo\MultiOrderMailReceiver\Core\Email::sendOrderEmailToOwner + */ + public function testSendOrderEMailToOwner_willSetCarbonCopyActive(): void + { + $internalState = $this->getProtectedClassProperty($this->SUT, '_blCarbonCopyActiveState'); + $this->assertFalse($internalState); + $payment = oxNew('oxPayment'); + $payment->oxpayments__oxdesc = new Field("testPaymentDesc"); + + $basket = oxNew('oxBasket'); + $basket->setCost('oxpayment', new Price(0)); + $basket->setCost('oxdelivery', new Price(6626)); + + $user = oxNew(User::class); + $user->setId('_testUserId'); + $user->oxuser__oxactive = new Field('1', Field::T_RAW); + $user->oxuser__oxusername = new Field('info@patrick-blom.de', Field::T_RAW); + $user->oxuser__oxcustnr = new Field('998', Field::T_RAW); + $user->oxuser__oxfname = new Field('Patrick', Field::T_RAW); + $user->oxuser__oxlname = new Field('Blom', Field::T_RAW); + $user->oxuser__oxpassword = new Field('ox_BBpaRCslUU8u', Field::T_RAW); //pass = admin + $user->oxuser__oxregister = new Field(date("Y-m-d H:i:s"), Field::T_RAW); + + $order = $this->getMockBuilder(Order::class) + ->setMethods(['getOrderUser', 'getBasket', 'getPayment', 'getDelSet']) + ->getMock(); + $order->oxorder__oxbillcompany = new Field(''); + $order->oxorder__oxbillfname = new Field(''); + $order->oxorder__oxbilllname = new Field(''); + $order->oxorder__oxbilladdinfo = new Field(''); + $order->oxorder__oxbillstreet = new Field(''); + $order->oxorder__oxbillcity = new Field(''); + $order->oxorder__oxbillcountry = new Field(''); + $order->oxorder__oxdeltype = new Field('oxidstandard'); + + $order->expects($this->any())->method('getOrderUser')->willReturn($user); + $order->expects($this->any())->method('getBasket')->willReturn($basket); + $order->expects($this->any())->method('getPayment')->willReturn($payment); + + $delSet = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySet::class); + $delSet->load($order->oxorder__oxdeltype->value); + $order->expects($this->any())->method('getDelSet')->willReturn($delSet); + + $this->SUT->expects($this->once())->method('_sendMail')->willReturn(true); + + $blRet = $this->SUT->sendOrderEmailToOwner($order); + $this->assertTrue($blRet); + + $internalState = $this->getProtectedClassProperty($this->SUT, '_blCarbonCopyActiveState'); + $this->assertTrue($internalState); } } diff --git a/composer.json b/composer.json index 4bc70d4..3d4675c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "extra": { "oxideshop": { "blacklist-filter": [ - "documentation/**/*.*" + "documentation/**/*.*", + "config.inc.TEST.php.dist" ], "target-directory": "pb/MultiOrderMailReceiver" } diff --git a/config.inc.TEST.php.dist b/config.inc.TEST.php.dist new file mode 100644 index 0000000..fa12c07 --- /dev/null +++ b/config.inc.TEST.php.dist @@ -0,0 +1,11 @@ +dbName = 'oxid_test'; // database name +$this->sShopDir = __DIR__; +$this->sCompileDir = $this->sShopDir . '/tmp'; + +$this->iUtfMode = 0; + +$this->iDebug = 1; + +$this->blSkipViewUsage = true;