SMMP/phpunit/tests/user/create/param/code.php

108 lines
3.0 KiB
PHP
Raw Permalink Normal View History

2017-05-13 09:21:41 +00:00
<?php
use \PHPUnit\Framework\TestCase;
use \api\core\Request;
use \error\core\Err;
use \orm\core\Table;
use \orm\core\Rows;
class code extends TestCase{
/*
* @beforeClass
*/
public function setUp(){
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['SERVER_NAME'] = 'localhost';
$adminReq = Table::get('admin')
->select('id_warehouse')
->select('token')
->fetch();
$_SERVER['PHP_AUTH_DIGEST'] = $adminReq[0]['token'];
$warehouseReq = Table::get('warehouse')
->whereId($adminReq[0]['id_warehouse'])
->select('token')
->fetch();
$_SERVER['PHP_AUTH_DIGEST'] = $warehouseReq[0]['token'].$_SERVER['PHP_AUTH_DIGEST'];
}
/* API manifest
*
* FIELD TYPE
* --------- -------
* code rfid
* username varchar(1,30,alphanumeric)
* firstname varchar(3,30,letters)
* lastname varchar(3,30,letters)
* mail mail
*
* Note: letters is alphanumeric + ' '
*
*/
public function testParamCode(){
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '09-AB-CD-EF',
'username' => '',
'firstname' => '',
'lastname' => '',
'mail' => ''
]);
/* (2) Gestion erreur */
$this->assertEquals($req->error->get(), Err::WrongParam);
$this->assertEquals(count($req->error->args()), 2);
$this->assertEquals($req->error->args()[0], 'username');
}
public function testParamCodeAlternative(){
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10-10-10',
'username' => '',
'firstname' => '',
'lastname' => '',
'mail' => ''
]);
/* (2) Gestion erreur */
$this->assertEquals($req->error->get(), Err::WrongParam);
$this->assertEquals(count($req->error->args()), 2);
$this->assertEquals($req->error->args()[0], 'username');
}
public function testParamCodeCharsetError(){
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-1G',
'username' => '',
'firstname' => '',
'lastname' => '',
'mail' => ''
]);
/* (2) Gestion erreur */
$this->assertEquals($req->error->get(), Err::WrongParam);
$this->assertEquals(count($req->error->args()), 2);
$this->assertEquals($req->error->args()[0], 'code');
}
}
?>