Skip to content

Commit 2a36edb

Browse files
committed
finalize tests, update readme and changelog
1 parent f54cdfc commit 2a36edb

5 files changed

Lines changed: 126 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [v1.0.0] - 2020-04-02
7+
## [v1.0.0] - 2020-04-10
88

99
### Added
10-
- Initial module commit
10+
- Initial module release

README.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,19 @@ admin order mail.
1212

1313
![Image alt="preview of the module"](module-preview.png)
1414

15-
### Compatability
15+
### Compatibility
1616

17-
* This module is OXID eShop 6.2 only
17+
* The module is OXID eShop 6.2 and higher only
18+
* The module was build and will work on the OXID eShop Community Edition
19+
* The module should work on OXID eShop Professional Edition and OXID eShop Enterprise Edition
20+
* The module was tested on the OXID eShop Community Edition
21+
* The module wat **not tested** on OXID eShop Professional Edition and OXID eShop Enterprise Edition
22+
23+
24+
### Requirements
25+
26+
* OXID eShop 6.2 Community Edition (or higher)
27+
* PHP 7.1 (or higher)
1828

1929
### Module installation via composer
2030

@@ -36,9 +46,39 @@ admin order mail.
3646
* `vendor/bin/oe-eshop-unified_namespace_generator`
3747
* `vendor/bin/oe-eshop-db_views_regenerate`
3848

39-
## Usage
49+
### Usage
4050

41-
- After the installation you will find a new mail address field called `Additional e-mail addresses for orders` under:
42-
- `Master Settings -> Core Settings -> Main (right side)`
43-
- The additional mail addresses must be separated by a semicolon (;)
51+
* After the installation and activation you will find a new mail address field called `Additional e-mail addresses for orders` under:
52+
* `Master Settings -> Core Settings -> Main (right side)`
53+
* The additional mail addresses must be separated by a semicolon (;)
54+
* Only valid mail addresses will be added as carbon copy
55+
* If no address is provided, no carbon copy entry will be set
4456

57+
### Testing
58+
59+
#### !Attention!
60+
The testing process should only be done in a development environment or CI pipeline.
61+
62+
#### Preparing
63+
* Install the module as described
64+
* Prepare the [OXID Testing Library](https://github.com/OXID-eSales/testing_library) likes described in their repository
65+
or use the [oxvm_eshop](https://github.com/OXID-eSales/oxvm_eshop) / [docker-eshop-sdk](https://github.com/OXID-eSales/docker-eshop-sdk)
66+
* Add `pb/MultiOrderMailReceiver` to the partial module paths in your test_config.yml (e.g: `partial_module_paths: 'pb/MultiOrderMailReceiver'`)
67+
* Copy the `config.inc.TEST.php.dist` to your shop root and rename it to `config.inc.TEST.php`
68+
* Adjust the settings in the `config.inc.TEST.php` to your needs (test database name, error reporting, etc)
69+
* Modify your `config.inc.php` and ensure that the `config.inc.TEST.php` will be loaded during the tests
70+
```php
71+
// bottom of config.inc.php
72+
if (defined('OXID_PHP_UNIT')) {
73+
include "config.inc.TEST.php";
74+
}
75+
```
76+
77+
#### Run tests
78+
* Navigate to the shop root
79+
* Run the test using the following command: `php vendor/bin/runtests <absolute path to shop root>/source/modules/pb/MultiOrderMailReceiver/Tests`
80+
* Run the coverage using the following command: `php vendor/bin/runtests-coverage <absolute path to shop root>/source/modules/pb/MultiOrderMailReceiver/Tests`
81+
82+
83+
### License
84+
The module is released under GPL-3.0. For a full overview check the [LICENSE](LICENSE) file.

Tests/Unit/Core/EmailTest.php

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
namespace PaBlo\MultiOrderMailReceiver\Test\Unit\Core;
44

5+
use OxidEsales\Eshop\Application\Model\Order;
56
use OxidEsales\Eshop\Application\Model\Shop;
7+
use OxidEsales\Eshop\Core\Field;
8+
use OxidEsales\Eshop\Core\Price;
9+
use OxidEsales\Eshop\Application\Model\User;
610
use OxidEsales\TestingLibrary\UnitTestCase;
711
use PaBlo\MultiOrderMailReceiver\Core\Email;
812

@@ -29,7 +33,7 @@ public function setUp()
2933
parent::setUp();
3034

3135
$this->SUT = $this->getMockBuilder(Email::class)
32-
->setMethods(['__call', 'send', 'getRenderer'])
36+
->setMethods(['__call', '_sendMail'])
3337
->getMock();
3438
}
3539

@@ -83,7 +87,6 @@ public function testSetCarbonCopy_withValidData(): void
8387
$this->assertSame('Max Muster', $carbonCopies[0][1]);
8488
}
8589

86-
8790
/**
8891
* @covers \PaBlo\MultiOrderMailReceiver\Core\Email::setCarbonCopy
8992
* @covers \PaBlo\MultiOrderMailReceiver\Core\Email::idnToAscii
@@ -124,7 +127,6 @@ public function testSetCarbonCopyActive_willSetInternalStateTrue(): void
124127
$this->assertTrue($internalState);
125128
}
126129

127-
128130
/**
129131
* @covers \PaBlo\MultiOrderMailReceiver\Core\Email::getCarbonCopyActiveState
130132
*/
@@ -176,7 +178,7 @@ public function testSetFrom_willAddCarbonCopyEntries(): void
176178
{
177179
// add demo carbon copies
178180
/** @var Shop $shop */
179-
$shop = $this->getConfig()->getActiveShop();
181+
$shop = $this->getConfig()->getActiveShop();
180182
$shop->oxshops__pbowneremailreceiver->rawValue = '[email protected];NOEMAILADDRESS;[email protected]';
181183
$shop->save();
182184

@@ -190,12 +192,67 @@ public function testSetFrom_willAddCarbonCopyEntries(): void
190192
$this->assertTrue($result);
191193

192194
$carbonCopies = $this->SUT->getCarbonCopy();
195+
193196
$this->assertNotEmpty($carbonCopies);
194197
$this->assertCount(2, $carbonCopies);
195-
$this->assertSame('[email protected]',$carbonCopies[0][0]);
196-
$this->assertSame('[email protected]',$carbonCopies[1][0]);
197-
$this->assertSame('order',$carbonCopies[0][1]);
198-
$this->assertSame('order',$carbonCopies[1][1]);
198+
$this->assertSame('[email protected]', $carbonCopies[0][0]);
199+
$this->assertSame('[email protected]', $carbonCopies[1][0]);
200+
$this->assertSame('order', $carbonCopies[0][1]);
201+
$this->assertSame('order', $carbonCopies[1][1]);
202+
203+
}
204+
205+
/**
206+
* @covers \PaBlo\MultiOrderMailReceiver\Core\Email::sendOrderEmailToOwner
207+
*/
208+
public function testSendOrderEMailToOwner_willSetCarbonCopyActive(): void
209+
{
210+
$internalState = $this->getProtectedClassProperty($this->SUT, '_blCarbonCopyActiveState');
211+
$this->assertFalse($internalState);
199212

213+
$payment = oxNew('oxPayment');
214+
$payment->oxpayments__oxdesc = new Field("testPaymentDesc");
215+
216+
$basket = oxNew('oxBasket');
217+
$basket->setCost('oxpayment', new Price(0));
218+
$basket->setCost('oxdelivery', new Price(6626));
219+
220+
$user = oxNew(User::class);
221+
$user->setId('_testUserId');
222+
$user->oxuser__oxactive = new Field('1', Field::T_RAW);
223+
$user->oxuser__oxusername = new Field('[email protected]', Field::T_RAW);
224+
$user->oxuser__oxcustnr = new Field('998', Field::T_RAW);
225+
$user->oxuser__oxfname = new Field('Patrick', Field::T_RAW);
226+
$user->oxuser__oxlname = new Field('Blom', Field::T_RAW);
227+
$user->oxuser__oxpassword = new Field('ox_BBpaRCslUU8u', Field::T_RAW); //pass = admin
228+
$user->oxuser__oxregister = new Field(date("Y-m-d H:i:s"), Field::T_RAW);
229+
230+
$order = $this->getMockBuilder(Order::class)
231+
->setMethods(['getOrderUser', 'getBasket', 'getPayment', 'getDelSet'])
232+
->getMock();
233+
$order->oxorder__oxbillcompany = new Field('');
234+
$order->oxorder__oxbillfname = new Field('');
235+
$order->oxorder__oxbilllname = new Field('');
236+
$order->oxorder__oxbilladdinfo = new Field('');
237+
$order->oxorder__oxbillstreet = new Field('');
238+
$order->oxorder__oxbillcity = new Field('');
239+
$order->oxorder__oxbillcountry = new Field('');
240+
$order->oxorder__oxdeltype = new Field('oxidstandard');
241+
242+
$order->expects($this->any())->method('getOrderUser')->willReturn($user);
243+
$order->expects($this->any())->method('getBasket')->willReturn($basket);
244+
$order->expects($this->any())->method('getPayment')->willReturn($payment);
245+
246+
$delSet = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySet::class);
247+
$delSet->load($order->oxorder__oxdeltype->value);
248+
$order->expects($this->any())->method('getDelSet')->willReturn($delSet);
249+
250+
$this->SUT->expects($this->once())->method('_sendMail')->willReturn(true);
251+
252+
$blRet = $this->SUT->sendOrderEmailToOwner($order);
253+
$this->assertTrue($blRet);
254+
255+
$internalState = $this->getProtectedClassProperty($this->SUT, '_blCarbonCopyActiveState');
256+
$this->assertTrue($internalState);
200257
}
201258
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"extra": {
1212
"oxideshop": {
1313
"blacklist-filter": [
14-
"documentation/**/*.*"
14+
"documentation/**/*.*",
15+
"config.inc.TEST.php.dist"
1516
],
1617
"target-directory": "pb/MultiOrderMailReceiver"
1718
}

config.inc.TEST.php.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING & ~E_NOTICE);
3+
$this->dbName = 'oxid_test'; // database name
4+
$this->sShopDir = __DIR__;
5+
$this->sCompileDir = $this->sShopDir . '/tmp';
6+
7+
$this->iUtfMode = 0;
8+
9+
$this->iDebug = 1;
10+
11+
$this->blSkipViewUsage = true;

0 commit comments

Comments
 (0)