mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 20:27:07 +09:00
* Update rector config to include tests * Run Rector against the tests * Delete test-results * Update .gitignore * Correctly set the PHP min to 8.1, split the configs * Corrected PHPDoc * Deleted tests we can't really get to pass PHPunit is hard-coded to fail when a class has a return type of `never`, which is the correct return type of our redirect function (and rightfully so). No way to disable the exception as far as we can tell
191 lines
5.8 KiB
PHP
191 lines
5.8 KiB
PHP
<?php
|
|
#[\PHPUnit\Framework\Attributes\Group('Core')]
|
|
class Api_Guest_ClientTest extends BBDbApiTestCase
|
|
{
|
|
protected $_initialSeedFile = 'initial.xml';
|
|
|
|
public function testCreate()
|
|
{
|
|
$this->api_admin->extension_config_save(array(
|
|
'ext' => 'mod_client',
|
|
'required' => array(),
|
|
));
|
|
|
|
$e = random_int(5, 56666).'@gmail.com';
|
|
$pass = 'testA1sssss';
|
|
|
|
$data = array(
|
|
'aid' => '2',
|
|
'email' => $e,
|
|
'first_name' => 'John',
|
|
'last_name' => 'Doe',
|
|
'address_1' => 'Palo Alto',
|
|
'country' => 'USA',
|
|
'company_vat' => 'LS-2qwddwqdsd12',
|
|
'city' => 'California',
|
|
'tel_cc' => '211',
|
|
'phone' => '11212156485451',
|
|
'password' => $pass,
|
|
'password_confirm' => $pass,
|
|
);
|
|
$id = $this->api_guest->client_create($data);
|
|
$this->assertIsInt($id);
|
|
$client = $this->di['db']->load('Client', $id);
|
|
|
|
$this->assertNotEquals($data['password'], $client->pass);
|
|
$this->assertTrue($this->di['password']->verify($data['password'], $client->pass));
|
|
}
|
|
|
|
/**
|
|
* @expectedException \FOSSBilling\Exception
|
|
*/
|
|
public function testRequiredFields()
|
|
{
|
|
$this->api_admin->extension_config_save(array(
|
|
'ext' => 'mod_client',
|
|
'required' => array(
|
|
'last_name'
|
|
),
|
|
));
|
|
|
|
$pass = 'testA222sssww';
|
|
$data = array(
|
|
'email' => 'test@example.com',
|
|
'first_name' => 'John',
|
|
'password' => $pass,
|
|
'password_confirm' => $pass,
|
|
);
|
|
$id = $this->api_guest->client_create($data);
|
|
}
|
|
|
|
public function testPasswordReset()
|
|
{
|
|
$data = array(
|
|
'email' => 'client@fossbilling.org',
|
|
);
|
|
$bool = $this->api_guest->client_reset_password($data);
|
|
$this->assertTrue($bool);
|
|
|
|
$data = array(
|
|
'hash' => 'hash',
|
|
);
|
|
$bool = $this->api_guest->client_confirm_reset($data);
|
|
$this->assertTrue($bool);
|
|
}
|
|
|
|
public function testVat()
|
|
{
|
|
$data = array(
|
|
'country' => 'GB',
|
|
'vat' => 'GB999 9999 73',
|
|
);
|
|
$bool = $this->api_guest->client_is_vat($data);
|
|
//$this->assertTrue($bool);
|
|
}
|
|
|
|
public function testClientLogin()
|
|
{
|
|
$data = array(
|
|
'email' => 'client@fossbilling.org',
|
|
'password' => 'demo',
|
|
);
|
|
$array = $this->api_guest->client_login($data);
|
|
$this->assertIsArray($array);
|
|
$this->assertTrue(is_numeric($this->session->get('client_id')), 'Client id is not integer');
|
|
|
|
$bool = $this->api_client->client_logout($data);
|
|
$this->assertNull($this->session->get('client_id'));
|
|
|
|
$this->assertTrue($bool);
|
|
$this->assertNull($this->session->get('admin'));
|
|
}
|
|
|
|
public function testRequired()
|
|
{
|
|
$array = $this->api_guest->client_required();
|
|
$this->assertIsArray($array);
|
|
}
|
|
|
|
public function testCreateWithCustom()
|
|
{
|
|
$this->api_admin->extension_config_save(array(
|
|
'ext' => 'mod_client',
|
|
'required' => array(
|
|
'last_name'
|
|
),
|
|
'custom_fields' => array(
|
|
'custom_5' => array(
|
|
'active' => true,
|
|
'required' => true,
|
|
'title' => 'Your username'
|
|
)
|
|
)
|
|
));
|
|
|
|
|
|
$e = random_int(5, 56666) . '@gmail.com';
|
|
$pass = 'testA1sssss';
|
|
|
|
$data = array(
|
|
'aid' => '2',
|
|
'email' => $e,
|
|
'first_name' => 'John',
|
|
'last_name' => 'Doe',
|
|
'address_1' => 'Palo Alto',
|
|
'country' => 'USA',
|
|
'company_vat' => 'LS-2qwddwqdsd12',
|
|
'city' => 'California',
|
|
'tel_cc' => '211',
|
|
'phone' => '11212156485451',
|
|
'password' => $pass,
|
|
'password_confirm' => $pass,
|
|
'custom_5' => 'JohnUsername'
|
|
|
|
);
|
|
$id = $this->api_guest->client_create($data);
|
|
$this->assertIsInt($id);
|
|
$client = $this->di['db']->load('Client', $id);
|
|
|
|
$this->assertEquals($data['custom_5'], $client->custom_5);
|
|
}
|
|
|
|
/**
|
|
* @expectedException \FOSSBilling\Exception
|
|
*/
|
|
public function testCreateWithCustomRequiredException()
|
|
{
|
|
$this->api_admin->extension_config_save(array(
|
|
'ext' => 'mod_client',
|
|
'required' => array(
|
|
'last_name'
|
|
),
|
|
'custom_fields' => array(
|
|
'custom_5' => array(
|
|
'active' => true,
|
|
'required' => true,
|
|
'title' => 'Your username'
|
|
)
|
|
)
|
|
));
|
|
|
|
$e = random_int(5, 56666) . '@gmail.com';
|
|
$pass = 'testA1sssss';
|
|
|
|
$data = array(
|
|
'aid' => '2',
|
|
'email' => $e,
|
|
'first_name' => 'John',
|
|
'last_name' => 'Doe',
|
|
'address_1' => 'Palo Alto',
|
|
'country' => 'USA',
|
|
'company_vat' => 'LS-2qwddwqdsd12',
|
|
'city' => 'California',
|
|
'tel_cc' => '211',
|
|
'phone' => '11212156485451',
|
|
'password' => $pass,
|
|
'password_confirm' => $pass,
|
|
|
|
);
|
|
$id = $this->api_guest->client_create($data);
|
|
}
|
|
} |