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

398 lines
12 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 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');
}
}
?>