Merge branch 'dev_1.x_frontend' into dev_1.x_frontend_620

This commit is contained in:
Daniel Seifert 2019-08-14 23:53:59 +02:00
commit 4bd06dde16
6 changed files with 247 additions and 17 deletions

View File

@ -18,7 +18,6 @@ namespace D3\Totp\Application\Model;
use BaconQrCode\Renderer\Image\Svg;
use BaconQrCode\Renderer\RendererInterface;
use BaconQrCode\Writer;
use D3\ModCfg\Application\Model\d3database;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use Doctrine\DBAL\DBALException;
use OTPHP\TOTP;
@ -53,23 +52,15 @@ class d3totp extends BaseModel
/**
* @param $userId
* @throws DBALException
* @throws DatabaseConnectionException
*/
public function loadByUserId($userId)
{
$this->userId = $userId;
//$oQB = d3database::getInstance()->getQueryBuilder();
$oDb = $this->d3GetDb();
if ($oDb->getOne("SHOW TABLES LIKE '".$this->tableName."'")) {
$query = "SELECT oxid FROM ".$this->getViewName().' WHERE oxuserid = '.$oDb->quote($userId).' LIMIT 1';
/*$oQB->select('oxid')
->from($this->getViewName())
->where("oxuserid = " . $oQB->createNamedParameter($userId))
->setMaxResults(1);
*/
//$this->load($oDb->getOne($oQB->getSQL(), $oQB->getParameters()));
$this->load($oDb->getOne($query));
}
}
@ -301,4 +292,4 @@ class d3totp extends BaseModel
return $blDelete;
}
}
}

View File

@ -34,8 +34,6 @@ class d3_totp_user extends d3_totp_user_parent
/**
* @return d3totp
* @throws DatabaseConnectionException
* @throws DBALException
*/
public function d3getTotp()
{

View File

@ -28,6 +28,7 @@ use OxidEsales\Eshop\Core\Exception\SystemComponentException;
class Events
{
/**
* @codeCoverageIgnore
* @throws d3ShopCompatibilityAdapterException
* @throws DBALException
* @throws DatabaseConnectionException
@ -42,6 +43,9 @@ class Events
}
}
/**
* @codeCoverageIgnore
*/
public static function onDeactivate()
{
}

View File

@ -18,6 +18,7 @@ namespace D3\Totp\Setup;
use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Install\d3install_updatebase;
use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\ConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
@ -257,7 +258,16 @@ class Installation extends d3install_updatebase
{
$query = "SELECT 1 FROM " . getViewName('oxseo') . " WHERE oxstdurl = 'index.php?cl=d3_account_totp'";
return !DatabaseProvider::getDb()->getOne($query);
return !$this->d3GetDb()->getOne($query);
}
/**
* @return DatabaseInterface
* @throws DatabaseConnectionException
*/
public function d3GetDb()
{
return DatabaseProvider::getDb();
}
/**

View File

@ -19,15 +19,12 @@ namespace D3\Totp\tests\unit\Application\Model;
use BaconQrCode\Renderer\Image\Svg;
use BaconQrCode\Writer;
use D3\Totp\Application\Model\d3backupcode;
use D3\Totp\Application\Model\d3backupcodelist;
use D3\Totp\Application\Model\d3totp;
use D3\Totp\Application\Model\Exceptions\d3totp_wrongOtpException;
use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OTPHP\TOTP;
use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit_Framework_MockObject_MockObject;
@ -105,9 +102,11 @@ class d3totpTest extends d3TotpUnitTestCase
{
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array(
'getOne'
'getOne',
'quote'
), array(), '', false);
$oDbMock->expects($this->exactly(2))->method('getOne')->willReturnOnConsecutiveCalls(true, true);
$oDbMock->method('quote')->willReturn(true);
/** @var d3totp|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(d3totp::class, array(

View File

@ -0,0 +1,228 @@
<?php
/**
* This Software is the property of Data Development and is protected
* by copyright law - it is NOT Freeware.
*
* Any unauthorized use of this software without a valid license
* is a violation of the license agreement and will be prosecuted by
* civil and criminal law.
*
* http://www.shopmodule.com
*
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
* @link http://www.oxidmodule.com
*/
namespace D3\Totp\tests\unit\Setup;
use D3\Totp\Setup\Installation;
use D3\Totp\tests\unit\d3TotpUnitTestCase;
use OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database;
use PHPUnit_Framework_MockObject_MockObject;
use ReflectionException;
class InstallationTest extends d3TotpUnitTestCase
{
/** @var Installation */
protected $_oModel;
/**
* setup basic requirements
*/
public function setUp()
{
parent::setUp();
$this->_oModel = oxNew(Installation::class);
}
public function tearDown()
{
parent::tearDown();
unset($this->_oModel);
}
/**
* @test
* @throws ReflectionException
*/
public function doesTotpTableNotExistCallCheckMethod()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'_checkTableNotExist',
));
$oModelMock->expects($this->once())->method('_checkTableNotExist')->with('d3totp')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertSame(
'testReturn',
$this->callMethod($this->_oModel, 'doesTotpTableNotExist')
);
}
/**
* @test
* @throws ReflectionException
*/
public function addTotpTableNotExistingTable()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'doesTotpTableNotExist',
'_addTable2',
));
$oModelMock->method('doesTotpTableNotExist')->willReturn(true);
$oModelMock->expects($this->once())->method('_addTable2')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertSame(
'testReturn',
$this->callMethod($this->_oModel, 'addTotpTable')
);
}
/**
* @test
* @throws ReflectionException
*/
public function addTotpTableExistingTable()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'doesTotpTableNotExist',
'_addTable2',
));
$oModelMock->method('doesTotpTableNotExist')->willReturn(false);
$oModelMock->expects($this->never())->method('_addTable2')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertFalse(
$this->callMethod($this->_oModel, 'addTotpTable')
);
}
/**
* @test
* @throws ReflectionException
*/
public function doesTotpBCTableNotExistCallCheckMethod()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'_checkTableNotExist',
));
$oModelMock->expects($this->once())->method('_checkTableNotExist')->with('d3totp_backupcodes')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertSame(
'testReturn',
$this->callMethod($this->_oModel, 'doesTotpBCTableNotExist')
);
}
/**
* @test
* @throws ReflectionException
*/
public function addTotpBCTableNotExistingTable()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'doesTotpBCTableNotExist',
'_addTable2',
));
$oModelMock->method('doesTotpBCTableNotExist')->willReturn(true);
$oModelMock->expects($this->once())->method('_addTable2')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertSame(
'testReturn',
$this->callMethod($this->_oModel, 'addTotpBCTable')
);
}
/**
* @test
* @throws ReflectionException
*/
public function addTotpBCTableExistingTable()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'doesTotpBCTableNotExist',
'_addTable2',
));
$oModelMock->method('doesTotpBCTableNotExist')->willReturn(false);
$oModelMock->expects($this->never())->method('_addTable2')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertFalse(
$this->callMethod($this->_oModel, 'addTotpBCTable')
);
}
/**
* @test
* @throws ReflectionException
*/
public function d3GetDbReturnsRightInstance()
{
$this->assertInstanceOf(
Database::class,
$this->callMethod($this->_oModel, 'd3GetDb')
);
}
/**
* @test
* @throws ReflectionException
*/
public function checkSEONotExistsPass()
{
/** @var Database|PHPUnit_Framework_MockObject_MockObject $oDbMock */
$oDbMock = $this->getMock(Database::class, array(
'getOne'
), array(), '', false);
$oDbMock->expects($this->once())->method('getOne')->willReturn(true);
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'd3GetDb'
));
$oModelMock->method('d3GetDb')->willReturn($oDbMock);
$this->_oModel = $oModelMock;
$this->assertFalse($this->callMethod($this->_oModel, 'checkSEONotExists'));
}
/**
* @test
* @throws ReflectionException
*/
public function addSEOPass()
{
/** @var Installation|PHPUnit_Framework_MockObject_MockObject $oModelMock */
$oModelMock = $this->getMock(Installation::class, array(
'_executeMultipleQueries'
));
$oModelMock->expects($this->once())->method('_executeMultipleQueries')->willReturn('testReturn');
$this->_oModel = $oModelMock;
$this->assertSame(
'testReturn',
$this->callMethod($this->_oModel, 'addSEO')
);
}
}