DotmailerCouponCodeGeneratorTest.php 1.66 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
<?php

namespace Dotdigitalgroup\Email\Test\Unit\Model\SalesRule;

use Dotdigitalgroup\Email\Model\SalesRule\DotmailerCouponCodeGenerator;
use Magento\SalesRule\Helper\Coupon;
use PHPUnit\Framework\TestCase;

class DotmailerCouponCodeGeneratorTest extends TestCase
{
    /**
     * @var Coupon|\PHPUnit_Framework_MockObject_MockObject
     */
    private $couponHelperMock;

    /**
     * @var DotmailerCouponCodeGenerator
     */
    private $model;

    /**
     * Prepare data
     */
    protected function setUp()
    {
        $this->couponHelperMock = $this->getMockBuilder(Coupon::class)
                                       ->disableOriginalConstructor()
                                       ->getMock();

        $this->model = new DotmailerCouponCodeGenerator($this->couponHelperMock);
    }

    public function testCouponCodeDelimiterRetrievedFromCouponHelper()
    {
        $expectedSeparator = "^";
        $this->couponHelperMock->expects($this->once())
                               ->method('getCodeSeparator')
                               ->willReturn($expectedSeparator);

        $actualSeparator = $this->model->getDelimiter();

        $this->assertEquals($expectedSeparator, $actualSeparator);
    }

    public function testCouponFormatCorrect()
    {
        $delimiter = "$";
        $this->couponHelperMock->method('getCodeSeparator')
                               ->willReturn($delimiter);
        $this->couponHelperMock->method('getCharset')
                               ->willReturn(['1','2','3','A','S','D']);

        $couponCode = $this->model->generateCode();

        $this->assertStringMatchesFormat('DOT-%c%c%c$%c%c%c$%c%c%c', $couponCode);
    }
}