160 lines
4.8 KiB
PHP
160 lines
4.8 KiB
PHP
<?php
|
|
use \PHPUnit\Framework\TestCase;
|
|
|
|
use \api\core\Request;
|
|
use \error\core\Err;
|
|
use \orm\core\Table;
|
|
use \orm\core\Rows;
|
|
|
|
class create 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 testParamUsername(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-10',
|
|
'username' => 'a.b-c.d-e10',
|
|
'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], 'firstname');
|
|
|
|
}
|
|
|
|
|
|
public function testParamUsernameMin(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-10',
|
|
'username' => 'a',
|
|
'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], 'firstname');
|
|
|
|
}
|
|
|
|
public function testParamUsernameMinError(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-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 testParamUsernameMax(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-10',
|
|
'username' => '123456789012345678901234567890',
|
|
'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], 'firstname');
|
|
|
|
}
|
|
|
|
public function testParamUsernameMaxError(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-10',
|
|
'username' => '123456789012345678901234567890x',
|
|
'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 testParamUsernameCharsetError(){
|
|
|
|
/* (1) Création requête */
|
|
$req = new Request('userDefault/create', [
|
|
'code' => '01-10-01-10',
|
|
'username' => '12345678901234567890123456789 ',
|
|
'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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|