mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
successfully test state-balance/ajaxGetBalance
This commit is contained in:
parent
b900afed29
commit
88d8a547cf
@ -158,6 +158,7 @@ class AppController extends Controller
|
||||
|
||||
if ($session_id != 0) {
|
||||
$userStored = $session->read('StateUser');
|
||||
|
||||
|
||||
$transactionPendings = $session->read('Transaction.pending');
|
||||
$transactionExecutings = $session->read('Transaction.executing');
|
||||
|
||||
@ -21,7 +21,7 @@ class StateBalancesController extends AppController
|
||||
{
|
||||
parent::initialize();
|
||||
//$this->Auth->allow(['add', 'edit']);
|
||||
$this->Auth->allow(['overview', 'overviewGdt']);
|
||||
$this->Auth->allow(['overview', 'overviewGdt', 'ajaxGetBalance']);
|
||||
$this->loadComponent('JsonRequestClient');
|
||||
}
|
||||
/**
|
||||
@ -189,7 +189,8 @@ class StateBalancesController extends AppController
|
||||
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
|
||||
}
|
||||
$user = $session->read('StateUser');
|
||||
return $this->returnJson(['state' => 'success', 'balance' => $session->read('StateUser.balance')]);
|
||||
//var_dump($user);
|
||||
return $this->returnJson(['state' => 'success', 'balance' => $user['balance']]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Controller\ElopageBuysController;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* App\Controller\ElopageBuysController Test Case
|
||||
*
|
||||
* @uses \App\Controller\ElopageBuysController
|
||||
*/
|
||||
class ElopageBuysControllerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'app.ElopageBuys',
|
||||
'app.ElopageUsers',
|
||||
'app.AffiliatePrograms',
|
||||
'app.Publishers',
|
||||
'app.Orders',
|
||||
'app.Products',
|
||||
];
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testView()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdd()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Controller\JsonRequestHandlerController;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
@ -70,14 +69,14 @@ class JsonRequestHandlerControllerTest extends TestCase
|
||||
|
||||
public function testNotSetTransaction()
|
||||
{
|
||||
$this->postAndParse(
|
||||
$this->postAndParse(
|
||||
['method' => 'putTransaction'],
|
||||
['state' => 'error', 'msg' => 'parameter error']
|
||||
);
|
||||
}
|
||||
public function testNotSetMethod()
|
||||
{
|
||||
$this->postAndParse(
|
||||
$this->postAndParse(
|
||||
['transaction' => $this->transactions['validCreation']],
|
||||
['state' => 'error', 'msg' => 'parameter error']
|
||||
);
|
||||
@ -86,7 +85,7 @@ class JsonRequestHandlerControllerTest extends TestCase
|
||||
public function testUnknownMethod()
|
||||
{
|
||||
//$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']);
|
||||
$this->postAndParse(
|
||||
$this->postAndParse(
|
||||
['method' => 'foobar', 'transaction' => $this->transactions['validCreation']],
|
||||
['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar']
|
||||
);
|
||||
@ -160,9 +159,14 @@ class JsonRequestHandlerControllerTest extends TestCase
|
||||
|
||||
private function postAndParse($params, $expected)
|
||||
{
|
||||
|
||||
//$this->enableCsrfToken();
|
||||
//$this->enableSecurityToken();
|
||||
|
||||
$token = 'my-csrf-token';
|
||||
$this->cookie('csrfToken', $token);
|
||||
|
||||
$this->configRequest([
|
||||
'headers' => ['Accept' => 'application/json']
|
||||
'headers' => ['Accept' => 'application/json', 'X-CSRF-Token' => $token]
|
||||
]);
|
||||
|
||||
$this->disableErrorHandlerMiddleware();
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Controller\StateBalancesController;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
@ -67,7 +66,21 @@ class StateBalancesControllerTest extends TestCase
|
||||
*/
|
||||
public function testAjaxGetBalance()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
$session_id = rand();
|
||||
$balance = rand();
|
||||
$this->session([
|
||||
'session_id' => $session_id,
|
||||
'Transaction' => ['pending' => 0, 'executing' => 0],
|
||||
'StateUser' => [
|
||||
'id' => 2, // 1 don't work, I don't know why
|
||||
'email_checked' => 1,
|
||||
'balance' => $balance
|
||||
]
|
||||
]);
|
||||
//echo "balance: $balance";
|
||||
$this->getAndParse('/state-balances/ajaxGetBalance/' . $session_id,
|
||||
['state' => 'success', 'balance' => $balance]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,4 +152,27 @@ class StateBalancesControllerTest extends TestCase
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
|
||||
private function getAndParse($path, $expected)
|
||||
{
|
||||
$this->configRequest([
|
||||
'headers' => ['Accept' => 'application/json']
|
||||
]);
|
||||
|
||||
$this->disableErrorHandlerMiddleware();
|
||||
$this->get($path);
|
||||
|
||||
// Check that the response was a 200
|
||||
$this->assertResponseOk();
|
||||
|
||||
$responseBodyString = (string)$this->_response->getBody();
|
||||
$json = json_decode($responseBodyString);
|
||||
$this->assertNotFalse($json);
|
||||
|
||||
if(is_array($expected)) {
|
||||
$expected = json_encode($expected);
|
||||
}
|
||||
$this->assertEquals($expected, $responseBodyString);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Controller\UsersController;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* App\Controller\UsersController Test Case
|
||||
*
|
||||
* @uses \App\Controller\UsersController
|
||||
*/
|
||||
class UsersControllerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'app.Users',
|
||||
'app.EmailOptIn',
|
||||
'app.UserBackups',
|
||||
'app.UserRoles',
|
||||
];
|
||||
|
||||
/**
|
||||
* Test index method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test view method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testView()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test add method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAdd()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test edit method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test delete method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Model\Table;
|
||||
|
||||
use App\Model\Table\ElopageBuysTable;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* App\Model\Table\ElopageBuysTable Test Case
|
||||
*/
|
||||
class ElopageBuysTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \App\Model\Table\ElopageBuysTable
|
||||
*/
|
||||
public $ElopageBuys;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'app.ElopageBuys',
|
||||
'app.ElopageUsers',
|
||||
'app.AffiliatePrograms',
|
||||
'app.Publishers',
|
||||
'app.Orders',
|
||||
'app.Products',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$config = TableRegistry::getTableLocator()->exists('ElopageBuys') ? [] : ['className' => ElopageBuysTable::class];
|
||||
$this->ElopageBuys = TableRegistry::getTableLocator()->get('ElopageBuys', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->ElopageBuys);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initialize method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitialize()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildRules()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test defaultConnectionName method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultConnectionName()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
namespace App\Test\TestCase\Model\Table;
|
||||
|
||||
use App\Model\Table\UsersTable;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* App\Model\Table\UsersTable Test Case
|
||||
*/
|
||||
class UsersTableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var \App\Model\Table\UsersTable
|
||||
*/
|
||||
public $Users;
|
||||
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'app.Users',
|
||||
'app.EmailOptIn',
|
||||
'app.UserBackups',
|
||||
'app.UserRoles',
|
||||
];
|
||||
|
||||
/**
|
||||
* setUp method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$config = TableRegistry::getTableLocator()->exists('Users') ? [] : ['className' => UsersTable::class];
|
||||
$this->Users = TableRegistry::getTableLocator()->get('Users', $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDown method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
unset($this->Users);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test initialize method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInitialize()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validationDefault method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testValidationDefault()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test buildRules method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBuildRules()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test defaultConnectionName method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultConnectionName()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
}
|
||||
}
|
||||
4
tests/testApi.sh
Executable file
4
tests/testApi.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
cd ..
|
||||
sudo -u www-data ./vendor/bin/phpunit --testdox tests/TestCase/Controller/StateBalancesControllerTest
|
||||
cd tests
|
||||
Loading…
x
Reference in New Issue
Block a user