keksAccount/tests/Controller/AdminControllerTest.php

112 lines
3.7 KiB
PHP

<?php
use Laravel\Lumen\Testing\DatabaseMigrations;
use Laravel\Lumen\Testing\DatabaseTransactions;
class AdminControllerTest extends TestCase
{
public function testlistAllAppsWithoutUser()
{
$this->get("/api/v1/admin/app");
$this->assertEquals(401, $this->response->getStatusCode());
$this->seeJson(["data" => [], "success" => false, "msg" => "You need to login"]);
}
public function testlistAllAppsUserButNoAdmin()
{
$user = new \App\Models\User();
$this->actingAs($user);
$this->get("/api/v1/admin/app");
$this->assertEquals(403, $this->response->getStatusCode());
$this->seeJson(["data" => [], "success" => false, "msg" => "You don't have the permission for this call"]);
}
public function testlistAllAppsUser()
{
$user = new \App\Models\User();
$user->admin = true;
$app = new \App\Data\Entity\App();
$app->name = "FooBar";
$app->access_api = true;
$appRepositoryMock = Mockery::mock(\App\Data\Repository\AppRepository::class);
$appRepositoryMock->shouldReceive("getAllApps")->once()->andReturn(collect([$app]));
$this->app->instance(\App\Data\Repository\AppRepository::class, $appRepositoryMock);
$this->actingAs($user);
$this->get("/api/v1/admin/app");
$this->assertEquals(200, $this->response->getStatusCode());
$this->seeJson(array(
'data' =>
array (
0 =>
array(
'id' => 0,
'name' => 'FooBar',
'description' => NULL,
'directUrl' => NULL,
'url' => NULL,
'iconURL' => NULL,
'properties' =>
array(
'testingWarning' => false,
'untrustedWarning' => false,
'showOnWebpage' => false,
'stopAutoRedirect' => false,
'hideInAppList' => false,
'userCantRemoveApp' => false,
),
'access' =>
array(
'oAuth' => false,
'api' => true,
'update_apps' => false,
'update_profile' => false,
'update_access' => false,
'read_access' => false,
'read_apps' => false,
'read_profile' => false,
),
),
),
'success' => true,
'msg' => NULL,
));
}
public function testUpdateAppPropertiesWithoutUser()
{
$this->put("/api/v1/admin/app/1/properties");
$this->assertEquals(401, $this->response->getStatusCode());
$this->seeJson(["data" => [], "success" => false, "msg" => "You need to login"]);
}
public function testUpdateAppPropertiesUserButNoAdmin()
{
$user = new \App\Models\User();
$this->actingAs($user);
$this->put("/api/v1/admin/app/1/properties");
$this->assertEquals(403, $this->response->getStatusCode());
$this->seeJson(["data" => [], "success" => false, "msg" => "You don't have the permission for this call"]);
}
public function testUpdateAppProperties() {
$this->assertTrue(true);
}
}