diff --git a/.travis.yml b/.travis.yml index eaeda5f52..3b985469d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ script: - sed -i 's/opensourcepos.tar.gz/opensourcepos.$version.tgz/g' package.json - npm ci && npm install -g gulp && npm run build - docker build . --target ospos -t ospos + - docker build . --target ospos_test -t ospos_test + - docker run --rm ospos_test /app/vendor/bin/phpunit --testdox - docker build app/Database/ -t "jekkos/opensourcepos:sql-$TAG" env: global: diff --git a/Dockerfile b/Dockerfile index 4846cd46e..376b0834d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN composer install -d/app #RUN sed -i 's/backupGlobals="true"/backupGlobals="false"/g' /app/tests/phpunit.xml WORKDIR /app/tests -CMD ["/app/vendor/phpunit/phpunit/phpunit"] +CMD ["/app/vendor/phpunit/phpunit/phpunit", "/app/test/helpers"] FROM ospos AS ospos_dev diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 3cce20b59..db61d5dc9 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -466,7 +466,9 @@ class Sales extends Secure_Controller */ public function getDeletePayment(string $payment_id): void { - $this->sale_lib->delete_payment(base64_decode($payment_id)); + helper('url'); + + $this->sale_lib->delete_payment(base64url_decode($payment_id)); $this->_reload(); // TODO: Hungarian notation } diff --git a/app/Helpers/url_helper.php b/app/Helpers/url_helper.php new file mode 100644 index 000000000..d0249b2f2 --- /dev/null +++ b/app/Helpers/url_helper.php @@ -0,0 +1,31 @@ +' . esc($success) . ''; } + +helper('url'); ?>
@@ -478,7 +480,7 @@ if (isset($success)) { $payment) { ?> - ') ?> + ') ?> diff --git a/composer.json b/composer.json index 308197e4f..c8f52e0e4 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "matrix": "https://matrix.to/#/#opensourcepos_Lobby:gitter.im" }, "require": { + "ext-intl": "*", "php": "^8.1", "codeigniter4/framework": "4.6.0", "dompdf/dompdf": "^2.0.3", diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 939be156f..4ff0e18fe 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -1,5 +1,3 @@ -version: '2.2' - include: - docker/docker-mysql.yml @@ -18,6 +16,6 @@ services: - MYSQL_DATABASE=ospos - MYSQL_USERNAME=admin - MYSQL_PASSWORD=pointofsale - command: [ "/bin/wait-for-it.sh", "mysql:3306", "--", "/app/vendor/bin/phpunit", "/app/app/tests" ] + command: [ "/bin/wait-for-it.sh", "mysql:3306", "--", "/app/vendor/bin/phpunit", "/app/tests" ] ports: - "80:80" diff --git a/package-lock.json b/package-lock.json index 80d886572..da62b2d92 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@opensourcepos/opensourcepos", - "version": "3.4.0", + "version": "3.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@opensourcepos/opensourcepos", - "version": "3.4.0", + "version": "3.4.1", "license": "MIT", "dependencies": { "bootstrap": "^3.4.1", diff --git a/tests/giftcard_numbering.js b/tests/giftcard_numbering.js deleted file mode 100644 index e76c3256b..000000000 --- a/tests/giftcard_numbering.js +++ /dev/null @@ -1,22 +0,0 @@ -var assert = require("assert"); // Node.js core module -var ospos = require("./ospos"); - -describe("giftcard numbering test", function () { - this.timeout(25000); - - it("should be able to login", function (done) { - return ospos.login(this.browser, done); - }); - - it.skip("issue #65: giftcard numbering should add properly", function (done) { - return this.browser.get(ospos.url("/index.php/giftcards")).elementByCssSelector(".modal-dlg").click() - .elementByName("value", 10000).type("100").elementById('giftcard_number').clear().type("10") - .elementById("submit").click().elementByXPath("//table/tbody/tr[td/text()='10']", 2000).text().then(function (value) { - assert.ok(value, "giftcard failed to be added properly!"); - }).elementByCssSelector(".modal-dlg").click().elementByName("value", 4000).type("100").elementById("submit").click() - .elementByXPath("//table/tbody/tr[td/text()='11']").text().then(function (value) { - assert.equal(value, "11", "giftcard number not incrementing properly!!"); - }).then(done, done); - }); - -}); diff --git a/tests/helpers/UrlHelperTest.php b/tests/helpers/UrlHelperTest.php new file mode 100644 index 000000000..d49bc279c --- /dev/null +++ b/tests/helpers/UrlHelperTest.php @@ -0,0 +1,25 @@ +assertMatchesRegularExpression('/^[A-Za-z0-9\-_]+$/', $encoded); + + // Assert that decoding the encoded string returns the original data + $decoded = base64url_decode($encoded); + $this->assertEquals($data, $decoded); + } + } diff --git a/tests/index.html b/tests/index.html deleted file mode 100644 index b702fbc39..000000000 --- a/tests/index.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - 403 Forbidden - - - -

Directory access is forbidden.

- - - diff --git a/tests/make_sale_receiving.js b/tests/make_sale_receiving.js deleted file mode 100644 index 9567dfebf..000000000 --- a/tests/make_sale_receiving.js +++ /dev/null @@ -1,43 +0,0 @@ -var assert = require('assert'); -var ospos = require('./ospos'); -require('wd'); - -describe("create item and make sale", function () { - this.timeout(25000); - - var def_timeout = 3000; - - var item = { name: "anItem", category: "aCategory", cost_price: 10, unit_price: 20 }; - - it("should be able to add item", function (done) { - return ospos.create_item(this.browser, item).then(done, done); - }); - - it("should be able to make sale", function (done) { - return this.browser.get(ospos.url("/index.php/sales")) - .elementById("item", def_timeout).clear().type("1\uE007") - .elementByName("quantity", def_timeout).clear().type("2").elementByName("discount", def_timeout).type(item.cost_price).elementByCssSelector(".glyphicon.glyphicon-refresh").click() - .elementById("add_payment_button", def_timeout).click().elementByCssSelector("tbody#payment_contents tr td:last-child", def_timeout).text().then(function (value) { - assert.equal(value, "$43.56", "price " + value + " in sale register is not correct!!"); - }).elementById("finish_sale_button", def_timeout).click().elementByCssSelector("#receipt_items tbody tr:nth-child(8) td:last-child", def_timeout).text().then(function (value) { - assert.equal(value, "$43.56", "price " + value + " on sale receipt is not correct!!"); - }).elementByCssSelector("#receipt_items tbody tr:nth-child(10) td:last-child", def_timeout).text().then(function (value) { - assert.equal(value, "-$43.56", "payment amount " + value + " on sale receipt is not correct!!") - }).then(done, done); - }); - - - it("should be able to make receiving", function (done) { - return this.browser.get(ospos.url("/index.php/receivings")) - .elementById("item", def_timeout).clear().type("1\uE007") - .elementByName("quantity", def_timeout).clear().type("2").elementByCssSelector("a[title='Update']").click() - .elementByCssSelector("td:nth-last-child(2)").text().then(function (value) { - assert.equal(value, "$20.00", "price " + value + " in receiving register is not correct!!"); - }).elementById("finish_receiving_button").click().elementByCssSelector("#receipt_items tbody tr:nth-last-child(2) td:nth-child(2) div.total-value").text().then(function (value) { - assert.equal(value, "$20.00", "price " + value + " on receiving receipt is not correct!!"); - }) - .then(done, done); - }); - - -}); diff --git a/tests/ospos.js b/tests/ospos.js deleted file mode 100644 index 26ea741d0..000000000 --- a/tests/ospos.js +++ /dev/null @@ -1,47 +0,0 @@ -var assert = require('assert'); - -var ospos = function () { - - var server = "http://localhost"; - - return { - - url: function (suffix) { - return server + suffix; - } - , - login: function (browser, done) { - return browser.get(this.url("/index.php")) - .elementByName('username').type("admin").getValue() - .then(function (value) { - assert.equal(value, "admin"); - }) - .elementByName('password').type("pointofsale").getValue() - .then(function (value) { - assert.ok(value, "pointofsale"); - }) - .elementByName('loginButton').click() - .elementById('home_module_list').then(function (value) { - assert.ok(value, "Login failed!!") - }) - .then(done, done); - - }, - - create_item: function (browser, item) { - return browser.get(this.url("/index.php/items")).elementByCssSelector("button[title*='New Item']", 5000).click() - .elementById('cost_price', 2000).clear().type(item.cost_price) - .elementById("unit_price", 2000).type(item.unit_price) - .elementById('tax_name_1', 2000).type('VAT').elementById("tax_percent_name_1", 2000).type("21") - .elementById("name", 10000).type(item.name) - .elementById("category", 2000).clear().type(item.category) - .elementById('receiving_quantity', 2000).type(item.receiving_quantity || 1) - .elementById("quantity_1", 2000).type("1").elementById("reorder_level", 2000).type("0").elementById("submit", 2000).click() - .elementByXPath("//table/tbody/tr[td/text()='anItem']", 5000).text().then(function (value) { - assert.equal(value, "1 - anItem aCategory - $10.00 $20.00 1 21.00%"); - }); - } - } -}; - -module.exports = ospos(); diff --git a/tests/phpunit.xml b/tests/phpunit.xml index ccde244d8..7c20c1a2d 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,26 +1,15 @@ - + stopOnFailure = "false"> helpers - - libraries - - - models - diff --git a/tests/receiving_quantity.js b/tests/receiving_quantity.js deleted file mode 100644 index c00883645..000000000 --- a/tests/receiving_quantity.js +++ /dev/null @@ -1,32 +0,0 @@ -var assert = require('assert'); -var ospos = require('./ospos'); - -describe("test receiving quantity", function () { - - var def_timeout = 10000; - - var item = { - name: "recvQty", - category: "aCategory", - cost_price: 10, - unit_price: 20, - receiving_quantity: 2 - }; - - it("should be able to create item with receiving quantity", function (done) { - return ospos.create_item(this.browser, item).then(done, done); - }); - - it("should be able to receive quantities with multiplier", function (done) { - this.browser.get(ospos.url('/index.php/receivings')).elementById("item").clear().type(item.name) - .elementByCssSelector(".ui-autocomplete .ui-menu-item", def_timeout).click() - .elementByName("quantity") - .elementByCssSelector("#cart_contents tr td:nth-child(5)").text().then(function (value) { - assert(value, "x " + item.receiving_quantity, "receiving quantity " + item.receiving_quantity + " is not displayed correctly in receivings module!"); - }).elementById("finish_receiving_button", def_timeout).submit() - .elementByCssSelector("#receipt_items tr:nth-child(2) td:nth-last-child(2)", def_timeout).text().then(function (value) { - assert(value, "1 x " + item.receiving_quantity, "receiving quantity " + item.receiving_quantity + " is not displayed correctly on receipt!!"); - }).then(done, done); - }); - -}); diff --git a/tests/sanity_check.js b/tests/sanity_check.js deleted file mode 100644 index 9adfc7357..000000000 --- a/tests/sanity_check.js +++ /dev/null @@ -1,11 +0,0 @@ -var assert = require("assert"); // Node.js core module -var wd = require('wd'); - -describe('A Mocha test run by grunt-mocha-webdriver', function () { - it('has a browser injected into it', function () { - assert.ok(this.browser); - }); - it('has wd injected into it for customizing', function () { - assert.notEqual(this.wd, undefined); - }); -});