Files
FOSSBilling/tests/modules/Profile/Api/AdminTest.php
T
Belle Aerni b9c35a1747 Replace Box_Session and improve session handling (#1332)
* Replace Box_Session and improve session handling

* Improve weights, capitalize class name correctly

* Make the tests pass, update the SQL structure

* Tweak to the fingerprint class, fix more tests

* Regenerate session IDs when logging in

* Improve readability

* Update ServiceTest.php

* Tweak weights and added Huntr badge to the readme

* Improve readability, add PHPDocs, and updated weight

* Update SECURITY.md
2023-06-19 04:14:29 -07:00

134 lines
4.3 KiB
PHP

<?php
namespace Box\Tests\Mod\Profile\Api;
class AdminTest extends \BBTestCase
{
public function testGet()
{
$service = new \Box\Mod\Profile\Service();
$model = new \Model_Admin();
$model->loadBean(new \DummyBean());
$model->id = 1;
$model->role = 'admin';
$model->admin_group_id = 1;
$model->email = 'admin@fossbilling.org';
$model->name = 'Admin';
$model->signature = 'Sincerely';
$model->status = 'active';
$model->created_at = '2014-01-01';
$model->updated_at = '2014-01-01';
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setIdentity($model);
$adminApi->setService($service);
$result = $adminApi->get();
$expected = array(
'id' => $model->id,
'role' => $model->role,
'admin_group_id' => $model->admin_group_id,
'email' => $model->email,
'name' => $model->name,
'signature' => $model->signature,
'status' => $model->status,
'api_token' => null,
'created_at' => $model->created_at,
'updated_at' => $model->updated_at,
);
$this->assertEquals($expected, $result);
}
public function testLogout()
{
$sessionMock = $this->getMockBuilder('\FOSSBilling\Session')
->disableOriginalConstructor()
->getMock();
$di = new \Pimple\Container();
$di['session'] = $sessionMock;
$di['logger'] = new \Box_Log();
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setDi($di);
$result = $adminApi->logout();
$this->assertTrue($result);
}
public function testUpdate()
{
$model = new \Model_Admin();
$serviceMock = $this->getMockBuilder('\Box\Mod\Profile\Service')
->getMock();
$serviceMock->expects($this->once())
->method('updateAdmin')
->will($this->returnValue(true));
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setIdentity($model);
$adminApi->setService($serviceMock);
$result = $adminApi->update(array('name'=>'Root'));
$this->assertTrue($result);
}
public function testGenerateApiKey()
{
$model = new \Model_Admin();
$serviceMock = $this->getMockBuilder('\Box\Mod\Profile\Service')
->getMock();
$serviceMock->expects($this->once())
->method('generateNewApiKey')
->will($this->returnValue(true));
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setIdentity($model);
$adminApi->setService($serviceMock);
$result = $adminApi->generate_api_key(array());
$this->assertTrue($result);
}
public function testChangePasswordExceptions()
{
$di = new \Pimple\Container();
$di['validator'] = new \FOSSBilling\Validate();
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setDi($di);
$this->expectException(\Box_Exception::class);
$adminApi->change_password(array());
$this->fail('password should be passed');
$this->expectException(\Exception::class);
$adminApi->change_password(array('password'=>'new_pass'));
$this->fail('password confirmation should be passed');
}
public function testChangePassword()
{
$di = new \Pimple\Container();
$di['validator'] = new \FOSSBilling\Validate();
$di['password'] = new \Box_Password();
$model = new \Model_Admin();
$model->loadBean(new \DummyBean());
$model->pass = $di['password']->hashIt('oldpw');
$serviceMock = $this->getMockBuilder('\Box\Mod\Profile\Service')
->getMock();
$serviceMock->expects($this->once())
->method('changeAdminPassword')
->will($this->returnValue(true));
$adminApi = new \Box\Mod\Profile\Api\Admin();
$adminApi->setDi($di);
$adminApi->setIdentity($model);
$adminApi->setService($serviceMock);
$result = $adminApi->change_password(array('current_password'=>'oldpw','new_password'=>'84asasd221AS', 'confirm_password'=>'84asasd221AS'));
$this->assertTrue($result);
}
}