Skip to content

Commit

Permalink
finalize tests, update readme and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-blom committed Apr 10, 2020
1 parent f54cdfc commit 2a36edb
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 17 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 46 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 <absolute path to shop root>/source/modules/pb/MultiOrderMailReceiver/Tests`
* Run the coverage using the following command: `php vendor/bin/runtests-coverage <absolute path to shop root>/source/modules/pb/MultiOrderMailReceiver/Tests`


### License
The module is released under GPL-3.0. For a full overview check the [LICENSE](LICENSE) file.
73 changes: 65 additions & 8 deletions Tests/Unit/Core/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -29,7 +33,7 @@ public function setUp()
parent::setUp();

$this->SUT = $this->getMockBuilder(Email::class)
->setMethods(['__call', 'send', 'getRenderer'])
->setMethods(['__call', '_sendMail'])
->getMock();
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -124,7 +127,6 @@ public function testSetCarbonCopyActive_willSetInternalStateTrue(): void
$this->assertTrue($internalState);
}


/**
* @covers \PaBlo\MultiOrderMailReceiver\Core\Email::getCarbonCopyActiveState
*/
Expand Down Expand Up @@ -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 = '[email protected];NOEMAILADDRESS;[email protected]';
$shop->save();

Expand All @@ -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('[email protected]',$carbonCopies[0][0]);
$this->assertSame('[email protected]',$carbonCopies[1][0]);
$this->assertSame('order',$carbonCopies[0][1]);
$this->assertSame('order',$carbonCopies[1][1]);
$this->assertSame('[email protected]', $carbonCopies[0][0]);
$this->assertSame('[email protected]', $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('[email protected]', 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);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"extra": {
"oxideshop": {
"blacklist-filter": [
"documentation/**/*.*"
"documentation/**/*.*",
"config.inc.TEST.php.dist"
],
"target-directory": "pb/MultiOrderMailReceiver"
}
Expand Down
11 changes: 11 additions & 0 deletions config.inc.TEST.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED & ~E_WARNING & ~E_NOTICE);
$this->dbName = 'oxid_test'; // database name
$this->sShopDir = __DIR__;
$this->sCompileDir = $this->sShopDir . '/tmp';

$this->iUtfMode = 0;

$this->iDebug = 1;

$this->blSkipViewUsage = true;

0 comments on commit 2a36edb

Please sign in to comment.