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

153 lines
4.6 KiB
PHP

<?php
use \PHPUnit\Framework\TestCase;
use \api\core\Request;
use \error\core\Err;
use \orm\core\Table;
use \orm\core\Rows;
class firstname 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 testParamFirstnameMin(){
$value = 'aaa';
$this->assertEquals(strlen($value), 3);
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10',
'username' => 'a',
'firstname' => $value,
'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], 'lastname');
}
public function testParamFirstnameMinError(){
$value = 'aa';
$this->assertLessThan(3, strlen($value));
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10',
'username' => 'a',
'firstname' => $value,
'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 testParamFirstnameMax(){
$value = '1.3-56789012345678901234567 ab';
$this->assertEquals(strlen($value), 30);
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10',
'username' => 'a',
'firstname' => $value,
'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], 'lastname');
}
public function testParamFirstnameMaxError(){
$value = '1.3-56789012345678901234567 ab0';
$this->assertGreaterThan(30, strlen($value));
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10',
'username' => 'a',
'firstname' => $value,
'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 testParamFirstnameCharsetError(){
/* (1) Création requête */
$req = new Request('userDefault/create', [
'code' => '01-10-01-10',
'username' => 'a',
'firstname' => '1.3-5a*',
'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');
}
}
?>