first commit
This commit is contained in:
19
modules/gamification/tests/autoload.php
Normal file
19
modules/gamification/tests/autoload.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
// ========== Mocks ===========
|
||||
require_once __DIR__ . '/mocks/ObjectModel.php';
|
||||
|
||||
// ======== Classes ===========
|
||||
require_once __DIR__ . '/../classes/Advice.php';
|
||||
require_once __DIR__ . '/../classes/Badge.php';
|
||||
require_once __DIR__ . '/../classes/GamificationTools.php';
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
define('_PS_VERSION_', 'TEST_VERSION');
|
||||
}
|
||||
|
||||
if (!defined('__PS_BASE_URI__')) {
|
||||
define('__PS_BASE_URI__', '__PS_BASE_URI__');
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CallToGamificationServerTest extends TestCase
|
||||
{
|
||||
public function testContentIsGzipped()
|
||||
{
|
||||
$workingCallUrl = 'https://gamification.prestashop.com/json/data_EN_IDR_ID.json';
|
||||
|
||||
$response = GamificationTools::retrieveJsonApiFile($workingCallUrl, true);
|
||||
$this->assertContains('content-encoding: gzip', $response);
|
||||
}
|
||||
}
|
||||
20
modules/gamification/tests/mocks/ObjectModel.php
Normal file
20
modules/gamification/tests/mocks/ObjectModel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
class ObjectModel
|
||||
{
|
||||
const TYPE_INT = 1;
|
||||
|
||||
const TYPE_BOOL = 2;
|
||||
|
||||
const TYPE_STRING = 3;
|
||||
|
||||
const TYPE_FLOAT = 4;
|
||||
|
||||
const TYPE_DATE = 5;
|
||||
|
||||
const TYPE_HTML = 6;
|
||||
|
||||
const TYPE_NOTHING = 7;
|
||||
|
||||
const TYPE_SQL = 8;
|
||||
}
|
||||
28
modules/gamification/tests/phpstan.sh
Normal file
28
modules/gamification/tests/phpstan.sh
Normal file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
PS_VERSION=$1
|
||||
|
||||
set -e
|
||||
|
||||
# Docker images prestashop/prestashop may be used, even if the shop remains uninstalled
|
||||
echo "Pull PrestaShop files (Tag ${PS_VERSION})"
|
||||
|
||||
docker rm -f temp-ps || true
|
||||
docker volume rm -f ps-volume || true
|
||||
|
||||
docker run -tid --rm -v ps-volume:/var/www/html --name temp-ps prestashop/prestashop:$PS_VERSION
|
||||
|
||||
# Clear previous instance of the module in the PrestaShop volume
|
||||
echo "Clear previous module"
|
||||
|
||||
docker exec -t temp-ps rm -rf /var/www/html/modules/gamification
|
||||
|
||||
# Run a container for PHPStan, having access to the module content and PrestaShop sources.
|
||||
# This tool is outside the composer.json because of the compatibility with PHP 5.6
|
||||
echo "Run PHPStan using phpstan-${PS_VERSION}.neon file"
|
||||
|
||||
docker run --rm --volumes-from temp-ps \
|
||||
-v $PWD:/var/www/html/modules/gamification \
|
||||
-e _PS_ROOT_DIR_=/var/www/html \
|
||||
--workdir=/var/www/html/modules/gamification phpstan/phpstan:0.12 \
|
||||
analyse \
|
||||
--configuration=/var/www/html/modules/gamification/tests/phpstan/phpstan-$PS_VERSION.neon
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.1.2.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.1.2.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.2.5.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.2.5.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.3.4.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.3.4.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.4.4.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.4.4.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.5.1.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.5.1.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.6.9.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.6.9.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-1.7.7.3.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-1.7.7.3.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
15
modules/gamification/tests/phpstan/phpstan-latest.neon
Normal file
15
modules/gamification/tests/phpstan/phpstan-latest.neon
Normal file
@@ -0,0 +1,15 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/tests/phpstan/phpstan.neon
|
||||
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
- '#Access to an undefined property Cookie::\$id_employee.#'
|
||||
- '#Call to private method add\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method delete\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method hydrate\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method update\(\) of parent class ObjectModel.#'
|
||||
- '#Call to private method save\(\) of parent class ObjectModel.#'
|
||||
- '#Class Advice does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Badge does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Class Condition does not have a constructor and must be instantiated without any parameters.#'
|
||||
- '#Constant _PS_CREATION_DATE_ not found.#'
|
||||
16
modules/gamification/tests/phpstan/phpstan.neon
Normal file
16
modules/gamification/tests/phpstan/phpstan.neon
Normal file
@@ -0,0 +1,16 @@
|
||||
includes:
|
||||
- %currentWorkingDirectory%/vendor/prestashop/php-dev-tools/phpstan/ps-module-extension.neon
|
||||
|
||||
parameters:
|
||||
paths:
|
||||
# From PHPStan 0.12, paths to check are relative to the neon file
|
||||
- ../../gamification.php
|
||||
- ../../sql_install.php
|
||||
- ../../classes/
|
||||
- ../../controllers/
|
||||
- ../../data/
|
||||
- ../../tests/
|
||||
- ../../translations/
|
||||
- ../../upgrade/
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
level: 5
|
||||
58
modules/gamification/tests/unit/AdviceTest.php
Normal file
58
modules/gamification/tests/unit/AdviceTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AdviceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var array the list of expected properties of Advice model
|
||||
*/
|
||||
const ADVICE_PROPERTIES = [
|
||||
'table',
|
||||
'primary',
|
||||
'multilang',
|
||||
'fields',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array the list of fields of Advice model
|
||||
*/
|
||||
const ADVICE_FIELDS = [
|
||||
'id_ps_advice',
|
||||
'id_tab',
|
||||
'selector',
|
||||
'location',
|
||||
'validated',
|
||||
'start_day',
|
||||
'stop_day',
|
||||
'weight',
|
||||
'html',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Advice
|
||||
*/
|
||||
private $advice;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->advice = new Advice();
|
||||
}
|
||||
|
||||
public function testAdviceDefinitionIsValid()
|
||||
{
|
||||
$definition = Advice::$definition;
|
||||
|
||||
$this->assertInternalType('array', $definition);
|
||||
|
||||
foreach (self::ADVICE_PROPERTIES as $property) {
|
||||
$this->assertArrayHasKey($property, $definition);
|
||||
}
|
||||
|
||||
$fieldsProperty = $definition['fields'];
|
||||
|
||||
foreach (self::ADVICE_FIELDS as $field) {
|
||||
$this->assertArrayHasKey($field, $fieldsProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
modules/gamification/tests/unit/BadgeTest.php
Normal file
21
modules/gamification/tests/unit/BadgeTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BadgeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var Badge
|
||||
*/
|
||||
private $badge;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->badge = new Badge();
|
||||
}
|
||||
|
||||
public function testImgUrl()
|
||||
{
|
||||
$this->assertStringStartsWith(__PS_BASE_URI__, $this->badge->getBadgeImgUrl());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user