[phpunit] user/create/params tests
This commit is contained in:
parent
fe6386d6fb
commit
676ecc5720
|
@ -187,6 +187,11 @@
|
|||
}
|
||||
|
||||
|
||||
public function args(){
|
||||
return $this->arguments;
|
||||
}
|
||||
|
||||
|
||||
public function setHttpCode(){
|
||||
http_response_code( $this->error == Err::Success ? 200 : 417 );
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
<testsuites>
|
||||
|
||||
<testsuite name="user">
|
||||
<file>./tests/user/create.php</file>
|
||||
<testsuite name="user_create">
|
||||
<directory suffix='.php'>tests/user/create/</directory>
|
||||
</testsuite>
|
||||
|
||||
</testsuites>
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use \PHPUnit\Framework\TestCase;
|
||||
|
||||
use \api\core\Request;
|
||||
use \error\core\Err;
|
||||
use \orm\core\Table;
|
||||
use \orm\core\Rows;
|
||||
|
||||
class create extends TestCase{
|
||||
class already extends TestCase{
|
||||
|
||||
private static $created;
|
||||
|
||||
/*
|
||||
* @before
|
||||
* @beforeClass
|
||||
*/
|
||||
public function setUp(){
|
||||
$_SERVER['REQUEST_METHOD'] = 'POST';
|
||||
|
@ -125,8 +125,10 @@
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* @depends testCreateAlready
|
||||
* @afterClass
|
||||
*/
|
||||
public function testRemoveCreated(){
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
<?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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,153 @@
|
|||
<?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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
use \PHPUnit\Framework\TestCase;
|
||||
|
||||
use \api\core\Request;
|
||||
use \error\core\Err;
|
||||
use \orm\core\Table;
|
||||
use \orm\core\Rows;
|
||||
|
||||
class lastname 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 testParamLastnameMin(){
|
||||
|
||||
$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' => 'aaa',
|
||||
'lastname' => $value,
|
||||
'mail' => ''
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamLastnameMinError(){
|
||||
|
||||
$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' => 'aaa',
|
||||
'lastname' => $value,
|
||||
'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 testParamLastnameMax(){
|
||||
|
||||
$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' => 'aaa',
|
||||
'lastname' => $value,
|
||||
'mail' => ''
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamLastnameMaxError(){
|
||||
|
||||
$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' => 'aaa',
|
||||
'lastname' => $value,
|
||||
'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 testParamLastnameCharsetError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => '1.3-5a*',
|
||||
'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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,398 @@
|
|||
<?php
|
||||
use \PHPUnit\Framework\TestCase;
|
||||
|
||||
use \api\core\Request;
|
||||
use \error\core\Err;
|
||||
use \orm\core\Table;
|
||||
use \orm\core\Rows;
|
||||
|
||||
class mail 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 testParamMail(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a.b-c@domain-c.d.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***************
|
||||
**** Root ****
|
||||
****************/
|
||||
|
||||
|
||||
public function testParamMailRootMin(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.cd'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailRootMinError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.c'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailRootMax(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.cdef'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailRootMaxError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.cdefg'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailRootCharsetError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.c9d'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***************
|
||||
**** Domain ****
|
||||
****************/
|
||||
|
||||
|
||||
public function testParamMailDomain(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b_c.d-e.f-g.h.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testParamMailDomainMin(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailDomainMinError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testParamMailDomainMax(){
|
||||
|
||||
$domain = '1234567890123456789012345678901234567890abcde';
|
||||
$mail = "a@{$domain}.fr";
|
||||
$this->assertEquals(strlen($mail), 50);
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => $mail
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailDomainMaxError(){
|
||||
|
||||
$domain = '1234567890123456789012345678901234567890abcdef';
|
||||
$mail = "a@{$domain}.fr";
|
||||
$this->assertGreaterThan(50, strlen($mail));
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => $mail
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailDomainCharsetError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@b-c0*d.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************
|
||||
**** Identifier ****
|
||||
********************/
|
||||
|
||||
|
||||
public function testParamMailIdentifier(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'ab-cd.ef-09.xx_3-2@x.yz'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testParamMailIdentifierMin(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a@x.yz'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailIdentifierMinError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => '@a.com'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function testParamMailIdentifierMax(){
|
||||
|
||||
$identifier = '1234567890123456789012345678901234567890abcde';
|
||||
$mail = "{$identifier}@a.fr";
|
||||
$this->assertEquals(strlen($mail), 50);
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => $mail
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::Success);
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailIdentifierMaxError(){
|
||||
|
||||
$identifier = '1_3-5.7890123456789012345678901234567890abcdef';
|
||||
$mail = "{$identifier}@a.fr";
|
||||
$this->assertGreaterThan(50, strlen($mail));
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => $mail
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
public function testParamMailIdentifierCharsetError(){
|
||||
|
||||
/* (1) Création requête */
|
||||
$req = new Request('userDefault/create', [
|
||||
'code' => '01-10-01-10',
|
||||
'username' => 'a',
|
||||
'firstname' => 'aaa',
|
||||
'lastname' => 'aaa',
|
||||
'mail' => 'a_b-c0*d@x.yz'
|
||||
]);
|
||||
|
||||
/* (2) Gestion erreur */
|
||||
$this->assertEquals($req->error->get(), Err::WrongParam);
|
||||
$this->assertEquals(count($req->error->args()), 2);
|
||||
$this->assertEquals($req->error->args()[0], 'mail');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,160 @@
|
|||
<?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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue