From 90678fe42aa01bf4c3646834902cd013dfa6085b Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 13 May 2020 13:04:28 +0000 Subject: [PATCH] adding missing files to git --- src/Controller/ElopageWebhookController.php | 51 +++++ tests/Fixture/ElopageBuysFixture.php | 64 ++++++ tests/Fixture/UsersFixture.php | 61 ++++++ .../Controller/ElopageBuysControllerTest.php | 80 ++++++++ .../JsonRequestHandlerControllerTest.php | 183 ++++++++++++++++++ ...actionJsonRequestHandlerControllerTest.php | 174 +++++++++++++++++ .../Controller/UsersControllerTest.php | 78 ++++++++ .../Model/Table/AdminErrorsTableTest.php | 83 ++++++++ .../Model/Table/ElopageBuysTableTest.php | 97 ++++++++++ .../Model/Table/StateErrorsTableTest.php | 84 ++++++++ .../Model/Table/StateUsersTableTest.php | 97 ++++++++++ tests/TestCase/Model/Table/UsersTableTest.php | 95 +++++++++ .../Transactions/TransactionCreationTest.php | 113 +++++++++++ 13 files changed, 1260 insertions(+) create mode 100644 src/Controller/ElopageWebhookController.php create mode 100644 tests/Fixture/ElopageBuysFixture.php create mode 100644 tests/Fixture/UsersFixture.php create mode 100644 tests/TestCase/Controller/ElopageBuysControllerTest.php create mode 100644 tests/TestCase/Controller/JsonRequestHandlerControllerTest.php create mode 100644 tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php create mode 100644 tests/TestCase/Controller/UsersControllerTest.php create mode 100644 tests/TestCase/Model/Table/AdminErrorsTableTest.php create mode 100644 tests/TestCase/Model/Table/ElopageBuysTableTest.php create mode 100644 tests/TestCase/Model/Table/StateErrorsTableTest.php create mode 100644 tests/TestCase/Model/Table/StateUsersTableTest.php create mode 100644 tests/TestCase/Model/Table/UsersTableTest.php create mode 100644 tests/TestCase/Model/Transactions/TransactionCreationTest.php diff --git a/src/Controller/ElopageWebhookController.php b/src/Controller/ElopageWebhookController.php new file mode 100644 index 000000000..4e806fa69 --- /dev/null +++ b/src/Controller/ElopageWebhookController.php @@ -0,0 +1,51 @@ +Auth->allow(['put']); + + } + + public function put() + { + $this->autoRender = false; + $data = $this->request->getData(); + $response = $this->response->withType('text/plain'); + + $dataString = http_build_query($data); + //$this->recursiveArrayToString($data, $dataString); + // %5B => [ + // %5D => ] + $dataString = preg_replace(['/\%5B/', '/\%5D/'], ['[', ']'], $dataString); + //var_dump($dataString); + + //2020-02-27T13:52:32+01:00 + $dateString = date('c'); + $fh = fopen('/etc/grd_login/php_elopage_requests.txt', 'a'); + if($fh === FALSE) { + return $response->withStringBody('400 ERROR'); + } + fwrite($fh, $dateString); + fwrite($fh, "\n"); + fwrite($fh, $dataString); + fwrite($fh, "\n"); + fclose($fh); + + + return $response->withStringBody('200 OK'); + + } +} diff --git a/tests/Fixture/ElopageBuysFixture.php b/tests/Fixture/ElopageBuysFixture.php new file mode 100644 index 000000000..20be0f4e3 --- /dev/null +++ b/tests/Fixture/ElopageBuysFixture.php @@ -0,0 +1,64 @@ + ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'elopage_user_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'affiliate_program_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'publisher_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'order_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'product_id' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'product_price' => ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'payer_email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'publisher_email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'payed' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'success_date' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null], + 'event' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8mb4_general_ci', 'comment' => '', 'precision' => null, 'fixed' => null], + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], + ], + '_options' => [ + 'engine' => 'InnoDB', + 'collation' => 'utf8_bin' + ], + ]; + // @codingStandardsIgnoreEnd + /** + * Init method + * + * @return void + */ + public function init() + { + $this->records = [ + [ + 'id' => 1, + 'elopage_user_id' => 1, + 'affiliate_program_id' => 1, + 'publisher_id' => 1, + 'order_id' => 1, + 'product_id' => 1, + 'product_price' => 1, + 'payer_email' => 'Lorem ipsum dolor sit amet', + 'publisher_email' => 'Lorem ipsum dolor sit amet', + 'payed' => 1, + 'success_date' => '2020-02-13 09:49:46', + 'event' => 'Lorem ipsum dolor sit amet', + ], + ]; + parent::init(); + } +} diff --git a/tests/Fixture/UsersFixture.php b/tests/Fixture/UsersFixture.php new file mode 100644 index 000000000..fc1a9e620 --- /dev/null +++ b/tests/Fixture/UsersFixture.php @@ -0,0 +1,61 @@ + ['type' => 'integer', 'length' => 11, 'unsigned' => false, 'null' => false, 'default' => null, 'comment' => '', 'autoIncrement' => true, 'precision' => null], + 'email' => ['type' => 'string', 'length' => 255, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'first_name' => ['type' => 'string', 'length' => 150, 'null' => false, 'default' => null, 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'last_name' => ['type' => 'string', 'length' => 255, 'null' => true, 'default' => '', 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + 'password' => ['type' => 'biginteger', 'length' => 25, 'unsigned' => true, 'null' => false, 'default' => null, 'comment' => '', 'precision' => null, 'autoIncrement' => null], + 'pubkey' => ['type' => 'binary', 'length' => 32, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], + 'privkey' => ['type' => 'binary', 'length' => 80, 'null' => true, 'default' => null, 'comment' => '', 'precision' => null], + 'created' => ['type' => 'datetime', 'length' => null, 'null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '', 'precision' => null], + 'email_checked' => ['type' => 'boolean', 'length' => null, 'null' => false, 'default' => '0', 'comment' => '', 'precision' => null], + 'language' => ['type' => 'string', 'length' => 4, 'null' => false, 'default' => 'de', 'collate' => 'utf8_bin', 'comment' => '', 'precision' => null, 'fixed' => null], + '_constraints' => [ + 'primary' => ['type' => 'primary', 'columns' => ['id'], 'length' => []], + 'email' => ['type' => 'unique', 'columns' => ['email'], 'length' => []], + ], + '_options' => [ + 'engine' => 'InnoDB', + 'collation' => 'utf8_general_ci' + ], + ]; + // @codingStandardsIgnoreEnd + /** + * Init method + * + * @return void + */ + public function init() + { + $this->records = [ + [ + 'id' => 1, + 'email' => 'Lorem ipsum dolor sit amet', + 'first_name' => 'Lorem ipsum dolor sit amet', + 'last_name' => 'Lorem ipsum dolor sit amet', + 'password' => 1, + 'pubkey' => 'Lorem ipsum dolor sit amet', + 'privkey' => 'Lorem ipsum dolor sit amet', + 'created' => '2020-02-13 10:54:19', + 'email_checked' => 1, + 'language' => 'Lo', + ], + ]; + parent::init(); + } +} diff --git a/tests/TestCase/Controller/ElopageBuysControllerTest.php b/tests/TestCase/Controller/ElopageBuysControllerTest.php new file mode 100644 index 000000000..38783976e --- /dev/null +++ b/tests/TestCase/Controller/ElopageBuysControllerTest.php @@ -0,0 +1,80 @@ +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.'); + } +} diff --git a/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php b/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php new file mode 100644 index 000000000..d51062563 --- /dev/null +++ b/tests/TestCase/Controller/JsonRequestHandlerControllerTest.php @@ -0,0 +1,183 @@ + 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQJ8wF12eZo3hcMAlAKKJ9WLT-zuSkNmGh7D98UEqH4KoIysnCkXqEya9EBZl9o11_nJ8xmm_nOevuVjR-GfLMQ8qSQoOSGFsbG8gV2VsdCAxMjMSBgiZm4ruBUovCicKIJSuE1uTzZ8zdStOVcQZA6P6oTp1u5C_1BHqHUoaXnEfEKDakwEQtYntlgo', + 'validCreation900' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQNVZ8Ae3Zbg3G0wZ840fzKan6N4KtTcSe0KYi17kQwFmsl18oFxXv8_s6j1xXFrIKjy1_1Olq0a7xYLErDMkjwYqORIGCNb5iu4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgNHKCBC1ie2WCg', + 'validCreation1200' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQEEey5QMAdldoOTP_jTETHgOQriGsixEY0cziQeRfT_J5YtbI_A6AizEYD-JcxmRmXzv1xjjTgsV39Y32ta2CQkqORIGCIeGi-4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgOy4CxC1ie2WCg', + 'notBase64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3', + 'validTransfer' => 'GmYKZAoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0SQDddHyKzAX3LBV0PuDiPc6lxkUipss5tyuLRpMtFJQnT30tsbYIkA1FXimjMKOoiuLswf4OLLV3bAIYehW-b9AgqYQoFSGFsbG8SBgiJlaPvBUJQCiYKIIGQvaWF7l8dn799BugeaewY4TN2EEz_VLdFfrfT73ENEICfSRImCiDtdleSLxhUgEbMW9DpqIwsykFj3-z_enKEOuGnXrmW8xCAn0k', + 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==', + 'creationValid' => 'GmYKZAogLtKKHPXhFtg2FUBrxXcVIiHC93SlZW9moOdUD3V21xsSQHpXYAGiVmSfhjB3o7OPx0ZJuPXrDk5eu1_AOhQBODU3KpUqBRA9yMX54S_mvGijGubCNRcMLcm7wiYbyAG-3AkqSwoQZWluIE1vbmF0c2dlaGFsdBIGCKqs5vEFSi8KJwoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0QgNrECRDKyd3uAQ' + ]; + + /*public function setUp() { + parent::setUp(); + } +*/ + public function testWrongMethod() + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + $this->get('/JsonRequestHandler'); + $this->assertResponseOk(); + + $expected = json_encode(['state' => 'error', 'msg' => 'no post']); + $this->assertEquals($expected, (string)$this->_response->getBody()); + } + + public function testInvalidJson() + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + $this->post('/JsonRequestHandler', '{This isn\'t valid json}'); + $this->assertResponseOk(); + + $expected = json_encode(['state' => 'error', 'msg' => 'parameter error']); + $this->assertEquals($expected, (string)$this->_response->getBody()); + } + + public function testNotSetTransaction() + { + $this->postAndParse( + ['method' => 'putTransaction'], + ['state' => 'error', 'msg' => 'parameter error'] + ); + } + public function testNotSetMethod() + { + $this->postAndParse( + ['transaction' => $this->transactions['validCreation']], + ['state' => 'error', 'msg' => 'parameter error'] + ); + } + + public function testUnknownMethod() + { + //$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']); + $this->postAndParse( + ['method' => 'foobar', 'transaction' => $this->transactions['validCreation']], + ['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar'] + ); + + } + + public function testInvalidEncodedTransaction() { + //"msg":"error parsing transaction","details":[{"Transaction":"base64 decode error"}] + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['notBase64']], + ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ + ['Transaction' => 'invalid base64 string'] + ]] + ); + } + + public function testInvalidTransaction() { + + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => base64_encode('Hallo Miau Welt')], + ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ + ['Transaction' => 'Error occurred during parsing: Unexpected wire type.'] + ]] + ); + } + + public function testToLargeCreationSum() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation900']], + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + ); + } + + public function testToLargeCreation() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation1200']], + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + ); + } + + public function testValidTransfer() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validTransfer']], + ['state' => 'success'] + ); + } + + /*public function testMissingPreviousTransaction() + { + + }*/ + + public function testValidTransaction() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation']], + ['state' => 'success'] + ); + } + + public function testValidCreation() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['creationValid']], + ['state' => 'success'] + ); + } + + private function postAndParse($params, $expected) + { + + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + + $this->disableErrorHandlerMiddleware(); + $this->post('/JsonRequestHandler', json_encode($params)); + + // 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); + } +} diff --git a/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php b/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php new file mode 100644 index 000000000..7ad28760c --- /dev/null +++ b/tests/TestCase/Controller/TransactionJsonRequestHandlerControllerTest.php @@ -0,0 +1,174 @@ + 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQJ8wF12eZo3hcMAlAKKJ9WLT-zuSkNmGh7D98UEqH4KoIysnCkXqEya9EBZl9o11_nJ8xmm_nOevuVjR-GfLMQ8qSQoOSGFsbG8gV2VsdCAxMjMSBgiZm4ruBUovCicKIJSuE1uTzZ8zdStOVcQZA6P6oTp1u5C_1BHqHUoaXnEfEKDakwEQtYntlgo', + 'validCreation900' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQNVZ8Ae3Zbg3G0wZ840fzKan6N4KtTcSe0KYi17kQwFmsl18oFxXv8_s6j1xXFrIKjy1_1Olq0a7xYLErDMkjwYqORIGCNb5iu4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgNHKCBC1ie2WCg', + 'validCreation1200' => 'GmYKZAogYbkjwhjLY6ZKjGLzhgEhKDuVd_N00KMVkLoCzcKRKZkSQEEey5QMAdldoOTP_jTETHgOQriGsixEY0cziQeRfT_J5YtbI_A6AizEYD-JcxmRmXzv1xjjTgsV39Y32ta2CQkqORIGCIeGi-4FSi8KJwoglK4TW5PNnzN1K05VxBkDo_qhOnW7kL_UEeodShpecR8QgOy4CxC1ie2WCg', + 'notBase64' => 'CgpIYWxsbyBXZW-0EgYIyfSG7gV_LwonCiCboKikqwjZfes9xuqgthFH3', + 'validTransfer' => 'GmYKZAoggZC9pYXuXx2fv30G6B5p7BjhM3YQTP9Ut0V-t9PvcQ0SQDddHyKzAX3LBV0PuDiPc6lxkUipss5tyuLRpMtFJQnT30tsbYIkA1FXimjMKOoiuLswf4OLLV3bAIYehW-b9AgqYQoFSGFsbG8SBgiJlaPvBUJQCiYKIIGQvaWF7l8dn799BugeaewY4TN2EEz_VLdFfrfT73ENEICfSRImCiDtdleSLxhUgEbMW9DpqIwsykFj3-z_enKEOuGnXrmW8xCAn0k', + 'errornusTransfer' => 'ClxGcm9oZXMgTmV1ZXMgSmFociB1bmQgREFOS0UsIGRhc3MgZHUgZGljaCBzbyBlaW5zZXR6dCBmw7xyIEdyYWRpZG8hIEhlcnpsaWNoZSBHcsO8w59lIFRlcmVzYRIGCPjjgvEFQlAKJgogUQwFYeVlGlfWDrkXNN7rHwejoCDJKt+YkYJfbJVyj3EQwIQ9EiYKIPXIRnUhVJ/zCs5+y/VaTBjTIoYizJNwS+JC//xsbQrHEMCEPQ==' + ]; + + /*public function setUp() { + parent::setUp(); + } +*/ + public function testWrongMethod() + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + $this->get('/TransactionJsonRequestHandler'); + $this->assertResponseOk(); + + $expected = json_encode(['state' => 'error', 'msg' => 'no post']); + $this->assertEquals($expected, (string)$this->_response->getBody()); + } + + public function testInvalidJson() + { + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + $this->post('/TransactionJsonRequestHandler', '{This isn\'t valid json}'); + $this->assertResponseOk(); + + $expected = json_encode(['state' => 'error', 'msg' => 'parameter error']); + $this->assertEquals($expected, (string)$this->_response->getBody()); + } + + public function testNotSetTransaction() + { + $this->postAndParse( + ['method' => 'putTransaction'], + ['state' => 'error', 'msg' => 'parameter error'] + ); + } + public function testNotSetMethod() + { + $this->postAndParse( + ['transaction' => $this->transactions['validCreation']], + ['state' => 'error', 'msg' => 'parameter error'] + ); + } + + public function testUnknownMethod() + { + //$this->post('/TransactionJsonRequestHandler', ['method' => 'putTransaction', 'transaction' => 'CgpIYWxsbyBXZWx0EgYIyfSG7gVKLwonCiCboKikqwjZfes9xuqgthFH3/cHHaWchkUhWiGhQjB23xCg2pMBELWJ7ZYK']); + $this->postAndParse( + ['method' => 'foobar', 'transaction' => $this->transactions['validCreation']], + ['state' => 'error', 'msg' => 'unknown method', 'details' => 'foobar'] + ); + + } + + public function testInvalidEncodedTransaction() { + //"msg":"error parsing transaction","details":[{"Transaction":"base64 decode error"}] + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['notBase64']], + ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ + ['Transaction' => 'invalid base64 string'] + ]] + ); + } + + public function testInvalidTransaction() { + + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => base64_encode('Hallo Miau Welt')], + ['state' => 'error', 'msg' => 'error parsing transaction', 'details' => [ + ['Transaction' => 'Error occurred during parsing: Unexpected wire type.'] + ]] + ); + } + + public function testToLargeCreationSum() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation900']], + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + ); + } + + public function testToLargeCreation() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation1200']], + '{"state":"error","msg":"error validate transaction","details":[{"TransactionCreation::validate":"Creation more than 1000 gr per Month not allowed"}]}' + ); + } + + public function testValidTransfer() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validTransfer']], + ['state' => 'success'] + ); + } + + /*public function testMissingPreviousTransaction() + { + + }*/ + + public function testValidTransaction() + { + $this->postAndParse( + ['method' => 'putTransaction', 'transaction' => $this->transactions['validCreation']], + ['state' => 'success'] + ); + } + + private function postAndParse($params, $expected) + { + + $this->configRequest([ + 'headers' => ['Accept' => 'application/json'] + ]); + + $this->disableErrorHandlerMiddleware(); + $this->post('/TransactionJsonRequestHandler', json_encode($params)); + + // 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); + } +} diff --git a/tests/TestCase/Controller/UsersControllerTest.php b/tests/TestCase/Controller/UsersControllerTest.php new file mode 100644 index 000000000..db9f98307 --- /dev/null +++ b/tests/TestCase/Controller/UsersControllerTest.php @@ -0,0 +1,78 @@ +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.'); + } +} diff --git a/tests/TestCase/Model/Table/AdminErrorsTableTest.php b/tests/TestCase/Model/Table/AdminErrorsTableTest.php new file mode 100644 index 000000000..09d7a35fb --- /dev/null +++ b/tests/TestCase/Model/Table/AdminErrorsTableTest.php @@ -0,0 +1,83 @@ +exists('AdminErrors') ? [] : ['className' => AdminErrorsTable::class]; + $this->AdminErrors = TableRegistry::getTableLocator()->get('AdminErrors', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->AdminErrors); + + 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.'); + } +} diff --git a/tests/TestCase/Model/Table/ElopageBuysTableTest.php b/tests/TestCase/Model/Table/ElopageBuysTableTest.php new file mode 100644 index 000000000..35aecc813 --- /dev/null +++ b/tests/TestCase/Model/Table/ElopageBuysTableTest.php @@ -0,0 +1,97 @@ +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.'); + } +} diff --git a/tests/TestCase/Model/Table/StateErrorsTableTest.php b/tests/TestCase/Model/Table/StateErrorsTableTest.php new file mode 100644 index 000000000..21cbe6128 --- /dev/null +++ b/tests/TestCase/Model/Table/StateErrorsTableTest.php @@ -0,0 +1,84 @@ +exists('StateErrors') ? [] : ['className' => StateErrorsTable::class]; + $this->StateErrors = TableRegistry::getTableLocator()->get('StateErrors', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->StateErrors); + + 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.'); + } +} diff --git a/tests/TestCase/Model/Table/StateUsersTableTest.php b/tests/TestCase/Model/Table/StateUsersTableTest.php new file mode 100644 index 000000000..49deb1166 --- /dev/null +++ b/tests/TestCase/Model/Table/StateUsersTableTest.php @@ -0,0 +1,97 @@ +exists('StateUsers') ? [] : ['className' => StateUsersTable::class]; + $this->StateUsersTable = TableRegistry::getTableLocator()->get('StateUsers', $config); + } + + /** + * tearDown method + * + * @return void + */ + public function tearDown() + { + unset($this->StateUsersTable); + + 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 getReceiverProposal method + * + * @return void + */ + public function testGetReceiverProposal() + { + $this->markTestIncomplete('Not implemented yet.'); + } +} diff --git a/tests/TestCase/Model/Table/UsersTableTest.php b/tests/TestCase/Model/Table/UsersTableTest.php new file mode 100644 index 000000000..7b730de54 --- /dev/null +++ b/tests/TestCase/Model/Table/UsersTableTest.php @@ -0,0 +1,95 @@ +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.'); + } +} diff --git a/tests/TestCase/Model/Transactions/TransactionCreationTest.php b/tests/TestCase/Model/Transactions/TransactionCreationTest.php new file mode 100644 index 000000000..60a6307ed --- /dev/null +++ b/tests/TestCase/Model/Transactions/TransactionCreationTest.php @@ -0,0 +1,113 @@ + 97, + "b" => 98, + "c" => 99, + "d" => 100, + "aa" => 12513, + "ab" => 12514, + "@" => 64, + ".d" => 5988, + "gmx" => 1701624, + "@gmx" => 135919352, + "@gmx.de" => 3742152099, + "***REMOVED***" => 2928827813, + "***REMOVED***" => 1899591683, + "***REMOVED***" => 2089074830, + "maximilian.muster@gradido.net" => 793144931, + "coin-info5@gradido.net" => 1829129963, + "coin-info6@gradido.net" => 1830178539, + "coin-info8@gradido.net" => 1832275691, + "coin-info9@gradido.net" => 1833324267, + "coin-info10@gradido.net" => 3877298078, + "coin-info11@gradido.net" => 3878346654, + "coin-info12@gradido.net" => 3879395230, + "***REMOVED***" => 2089074830, + "***REMOVED***" => 3996757473, + "***REMOVED***" => 3788634614, + "***REMOVED***" => 807797884, + "***REMOVED***" => 1640973721, + "***REMOVED***" => 2025729173, + "***REMOVED***" => 1961122507, + "***REMOVED***" => 362466358, + "***REMOVED***" => 3796728871, + "***REMOVED***" => 807797884, + "***REMOVED***" => 3794905967, + "***REMOVED***" => 3077694284, + "***REMOVED***" => 3246159770, + "***REMOVED***" => 3123402690, + "testneu-11-12-3@gradido.net" => 4092403827, + "***REMOVED***" => 3151414199, + "***REMOVED***" => 3526188273, + "***REMOVED***" => 966804823, + "***REMOVED***" => 1309273258, + "***REMOVED***" => 995978784, + "***REMOVED***" => 310113324, + "***REMOVED***" => 1309273258, + "***REMOVED***" => 530108573, + "***REMOVED***" => 1734855679, + "***REMOVED***" => 767779182, + "***REMOVED***" => 2247491519, + "***REMOVED***" => 3248626267, + "***REMOVED***" => 3516649930, + "***REMOVED***" => 231214190, + "***REMOVED***" => 4247461928, + "***REMOVED***" => 324829839, + "***REMOVED***" => 3046147747, + "***REMOVED***" => 3207307415, + "***REMOVED***" => 728893500, + "***REMOVED***" => 3905254663, + "***REMOVED***" => 3207307415, + "***REMOVED***" => 1155733239, + "***REMOVED***" => 2013046423, + "***REMOVED***" => 4033835283, + "***REMOVED***" => 1945541625, + "***REMOVED***" => 2310715309, + "***REMOVED***" => 1221362064, + "***REMOVED***" => 4161339877 + ]; + foreach($pairs as $email => $cpp_hash) { + $php_hash = TransactionCreation::DRMakeStringHash($email); + // assertEquals(mixed $expected, mixed $actual[, string $message = '']) + if($php_hash != $cpp_hash) { + $this->assertEquals($cpp_hash, $php_hash, "hashes for $email don't match"); + } + } + } + + +}