Initial commit
59
tests/functionnal/casperjs/conf/local.js
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
var system = require('system');
|
||||
|
||||
// Thalie Base URL
|
||||
var thelia2_base_url = '';
|
||||
|
||||
if (casper.cli.has('thelia2_base_url')){
|
||||
thelia2_base_url = casper.cli.get('thelia2_base_url');
|
||||
casper.test.comment('CasperJS will use Thelia on : '+ thelia2_base_url);
|
||||
} else if (system.env.thelia2_base_url){
|
||||
thelia2_base_url = system.env.thelia2_base_url;
|
||||
casper.test.comment('CasperJS will use Thelia (ENV) on : '+ thelia2_base_url);
|
||||
} else {
|
||||
thelia2_base_url = 'http://dev.thelia.net/index_dev.php/';
|
||||
casper.test.comment('CasperJS will use fallback URL for tests : '+ thelia2_base_url);
|
||||
casper.test.comment('If you want to use custom URL just set the environment variable `thelia2_base_url`');
|
||||
}
|
||||
|
||||
// Administrator account
|
||||
var administrator = {
|
||||
login: "thelia2",
|
||||
password: "thelia2"
|
||||
};
|
||||
|
||||
// Default
|
||||
var thelia2_store_name = "Thelia V2";
|
||||
|
||||
var screenshot_enabled = true;
|
||||
if (casper.cli.has('thelia2_screenshot_disabled')) {
|
||||
screenshot_enabled = false;
|
||||
}
|
||||
|
||||
// Screenshot Dir
|
||||
var screenshot_dir = 'tests/functionnal/casperjs/screenshot/';
|
||||
if (casper.cli.has('thelia2_screenshot_path')){
|
||||
screenshot_dir = casper.cli.get('thelia2_screenshot_path');
|
||||
}
|
||||
casper.test.comment('Screenshots will be saved under : '+ screenshot_dir);
|
||||
|
||||
|
||||
// Default Viewport size
|
||||
casper.options.viewportSize = {width: 1024, height: 768};
|
||||
casper.test.comment('Viewport size: '+ casper.options.viewportSize.width + 'x' + casper.options.viewportSize.height);
|
||||
|
||||
// Default timeout in ms
|
||||
var thelia_default_timeout = 15000;
|
||||
// for the waitFor method
|
||||
casper.options.waitTimeout = thelia_default_timeout;
|
||||
casper.options.logLevel = "info";
|
||||
|
||||
casper.test.comment('Default timeout: '+ thelia_default_timeout + ' ms');
|
||||
|
||||
// Email created during front/20_register.js test
|
||||
var thelia_customer = {
|
||||
"email": null,
|
||||
"password": "thelia"
|
||||
};
|
||||
|
||||
casper.test.done();
|
||||
164
tests/functionnal/casperjs/exe/back/10_pages.js
Normal file
@@ -0,0 +1,164 @@
|
||||
/**
|
||||
* Created by julien on 16/10/14.
|
||||
*/
|
||||
var x = require('casper').selectXPath;
|
||||
var errors = [], resourceErrors = [];
|
||||
|
||||
casper.test.begin('Back Office - Pages', 100, function suite(test) {
|
||||
|
||||
var pages = [
|
||||
{"url": "admin", "title": "Back-office home"},
|
||||
{"url": "admin/home", "title": "Back-office home"},
|
||||
{"url": "admin/catalog", "title": "Categories"},
|
||||
{"url": "admin/customers", "title": "Customer"},
|
||||
{"url": "admin/orders", "title": "Orders"},
|
||||
{"url": "admin/categories", "title": "Categories"},
|
||||
{"url": "admin/products", "title": "Categories"},
|
||||
{"url": "admin/folders", "title": "Folders"},
|
||||
{"url": "admin/coupon", "title": "Coupons"},
|
||||
{"url": "admin/configuration", "title": "Configuration"},
|
||||
{"url": "admin/configuration/variables", "title": "Thelia System Variables"},
|
||||
{"url": "admin/configuration/store", "title": "Store"},
|
||||
{"url": "admin/configuration/system-logs", "title": "System Logs"},
|
||||
{"url": "admin/configuration/messages", "title": "Thelia Mailing Templates"},
|
||||
{"url": "admin/configuration/currencies", "title": "Currencies"},
|
||||
{"url": "admin/configuration/templates", "title": "Thelia Product Templates"},
|
||||
{"url": "admin/configuration/attributes", "title": "Thelia Product Attributes"},
|
||||
{"url": "admin/configuration/shipping_zones", "title": "Thelia Shipping zones"},
|
||||
{"url": "admin/configuration/countries", "title": "Countries"},
|
||||
{"url": "admin/configuration/profiles", "title": "Administration profiles"},
|
||||
{"url": "admin/configuration/administrators", "title": "Back-office users"},
|
||||
{"url": "admin/configuration/mailingSystem", "title": "Thelia Mailing System"},
|
||||
{"url": "admin/configuration/adminLogs", "title": "Administration logs"},
|
||||
{"url": "admin/configuration/features", "title": "Thelia Product Features"},
|
||||
{"url": "admin/configuration/advanced", "title": "Advanced configuration"},
|
||||
{"url": "admin/modules", "title": "Modules"},
|
||||
{"url": "admin/hooks", "title": "Hooks"},
|
||||
{"url": "admin/module-hooks", "title": "Modules attachments"},
|
||||
{"url": "admin/configuration/taxes_rules", "title": "Taxes rules"},
|
||||
{"url": "admin/configuration/languages", "title": "Thelia Languages"},
|
||||
{"url": "admin/configuration/translations", "title": "Translation"},
|
||||
{"url": "admin/brand", "title": "Brands"},
|
||||
{"url": "admin/export", "title": "Exports"},
|
||||
{"url": "admin/import", "title": "Imports"},
|
||||
{"url": "admin/sales", "title": "Sales management"},
|
||||
{"url": "admin/logout", "title": "Welcome"}
|
||||
];
|
||||
|
||||
casper.on('page.error', function(msg, trace) {
|
||||
this.echo("Error: " + msg, "ERROR");
|
||||
|
||||
errors.push(msg);
|
||||
});
|
||||
|
||||
casper.on('resource.error', function(resourceError) {
|
||||
|
||||
var message = [
|
||||
"Failed to load resource :", resourceError.url,
|
||||
"-", resourceError.errorCode,
|
||||
":", resourceError.errorString
|
||||
].join(' ');
|
||||
|
||||
this.echo(message, "ERROR");
|
||||
|
||||
resourceErrors.push(message);
|
||||
});
|
||||
|
||||
casper.start(thelia2_base_url + 'admin/login', function() {
|
||||
|
||||
test.comment('Login to back Office');
|
||||
|
||||
// trick too update the number of planned tests : 100 - 2 - (2x number of urls) !!
|
||||
test.skip(98 - (pages.length * 2));
|
||||
|
||||
|
||||
test.assertTitle("Welcome - Thelia Back Office");
|
||||
test.assertExists('body.login-page', "This is the login page");
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + "login.png");
|
||||
}
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#username').value = username;
|
||||
document.querySelector('#password').value = password;
|
||||
}, administrator.login, administrator.password);
|
||||
|
||||
this.click('body.login-page button[type="submit"]');
|
||||
|
||||
this.echo('Waiting...');
|
||||
});
|
||||
|
||||
casper.then(function(){
|
||||
|
||||
this.echo('Done');
|
||||
this.echo('Processing ' + pages.length + ' URLs');
|
||||
|
||||
casper.eachThen(pages, function(response) {
|
||||
|
||||
var page = response.data;
|
||||
|
||||
this.echo('Loading page : ' + page.url);
|
||||
casper.thenOpen(thelia2_base_url + page.url);
|
||||
|
||||
casper.waitForSelector("footer.footer",
|
||||
function success() {
|
||||
var pageTitle = this.getTitle().replace(" - Thelia Back Office", "");
|
||||
var imageName = page.url + ".png";
|
||||
|
||||
test.assertExists(
|
||||
"footer.footer",
|
||||
"Page " + page.url + " [" + pageTitle + "] loaded"
|
||||
);
|
||||
test.assertEquals(
|
||||
pageTitle,
|
||||
page.title,
|
||||
"The page title is correct : " + pageTitle
|
||||
);
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + imageName);
|
||||
}
|
||||
},
|
||||
function fail() {
|
||||
// try to catch exception
|
||||
if (this.exists('span.exception_title')) {
|
||||
var exceptionTitle = this.fetchText('span.exception_title');
|
||||
var exceptionMessage = this.fetchText('span.exception_message');
|
||||
|
||||
this.echo(
|
||||
"Exception title : " + exceptionTitle + " " + exceptionMessage,
|
||||
"ERROR"
|
||||
);
|
||||
}
|
||||
|
||||
test.assertExists(
|
||||
"footer.footer",
|
||||
"Page " + page.url + " can't be loaded !"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
|
||||
if (errors.length > 0) {
|
||||
this.echo(errors.length + ' JavaScript errors found', "WARNING");
|
||||
} else {
|
||||
this.echo('No Javascript errors found', "INFO");
|
||||
}
|
||||
|
||||
if (resourceErrors.length > 0) {
|
||||
this.echo(resourceErrors.length + ' Resources errors found', "WARNING");
|
||||
} else {
|
||||
this.echo('No resources errors found', "INFO");
|
||||
}
|
||||
|
||||
casper.exit();
|
||||
});
|
||||
|
||||
});
|
||||
17
tests/functionnal/casperjs/exe/front/10_home.js
Normal file
@@ -0,0 +1,17 @@
|
||||
casper.test.comment('== Front Homepage ==');
|
||||
|
||||
casper.test.begin('Front Homepage', 2, function suite(test) {
|
||||
|
||||
casper.start(thelia2_base_url, function() {
|
||||
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
|
||||
test.assertExists('form#form-search', "main search form is found");
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/10_home.png');
|
||||
}
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
139
tests/functionnal/casperjs/exe/front/20_register.js
Normal file
@@ -0,0 +1,139 @@
|
||||
casper.test.comment('== Register ==');
|
||||
|
||||
casper.test.begin('Register', 15, function suite(test) {
|
||||
|
||||
var newEmail = '';
|
||||
|
||||
casper.start(thelia2_base_url + "register", function() {
|
||||
test.assertTitle("Register - " + thelia2_store_name, "title is the one expected");
|
||||
test.assertExists('form#form-register', "register form is found");
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/20_register.png');
|
||||
}
|
||||
|
||||
casper.test.comment('== Register blank account');
|
||||
|
||||
this.fill('form#form-register', {
|
||||
'thelia_customer_create[title]': '',
|
||||
'thelia_customer_create[firstname]': '',
|
||||
'thelia_customer_create[lastname]': '',
|
||||
'thelia_customer_create[email]': '',
|
||||
'thelia_customer_create[phone]': '',
|
||||
'thelia_customer_create[cellphone]': '',
|
||||
'thelia_customer_create[company]': '',
|
||||
'thelia_customer_create[address1]': '',
|
||||
'thelia_customer_create[address2]': '',
|
||||
'thelia_customer_create[zipcode]': '',
|
||||
'thelia_customer_create[city]': '',
|
||||
'thelia_customer_create[country]': '',
|
||||
'thelia_customer_create[password]': '',
|
||||
'thelia_customer_create[password_confirm]': '',
|
||||
'thelia_customer_create[newsletter]': ''
|
||||
}, true);
|
||||
|
||||
});
|
||||
|
||||
|
||||
casper.then(function() {
|
||||
|
||||
casper.test.comment('== Register thelia account');
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/20_register-ko.png');
|
||||
}
|
||||
|
||||
test.assertExists('.group-title.has-error', 'title can not be empty');
|
||||
test.assertExists('.group-firstname.has-error', 'firstname can not be empty');
|
||||
test.assertExists('.group-lastname.has-error', 'lastname can not be empty');
|
||||
test.assertExists('.group-email.has-error', 'email can not be empty');
|
||||
test.assertExists('.group-address1.has-error', 'address1 can not be empty');
|
||||
test.assertExists('.group-zip.has-error', 'zipcode can not be empty');
|
||||
test.assertExists('.group-city.has-error', 'city can not be empty');
|
||||
test.assertExists('.group-password.has-error', 'password can not be empty');
|
||||
test.assertExists('.group-password_confirm.has-error', 'password confirm can not be empty');
|
||||
|
||||
this.fill('form#form-register', {
|
||||
'thelia_customer_create[title]': '1',
|
||||
'thelia_customer_create[firstname]': 'thelia',
|
||||
'thelia_customer_create[lastname]': 'thelia',
|
||||
'thelia_customer_create[email]': 'test@thelia.net',
|
||||
'thelia_customer_create[email_confirm]': 'test@thelia.net',
|
||||
'thelia_customer_create[phone]': '',
|
||||
'thelia_customer_create[cellphone]': '',
|
||||
'thelia_customer_create[company]': 'OpenStudio',
|
||||
'thelia_customer_create[address1]': '4 rue Rochon',
|
||||
'thelia_customer_create[address2]': '',
|
||||
'thelia_customer_create[zipcode]': '63000',
|
||||
'thelia_customer_create[city]': 'Clermont-Ferrand',
|
||||
'thelia_customer_create[country]': '64',
|
||||
'thelia_customer_create[password]': 'thelia',
|
||||
'thelia_customer_create[password_confirm]': 'thelia',
|
||||
'thelia_customer_create[newsletter]': ''
|
||||
}, false);
|
||||
|
||||
this.click('form#form-register button[type="submit"]');
|
||||
|
||||
});
|
||||
|
||||
casper.waitForSelector(
|
||||
'.group-email .help-block',
|
||||
function(){
|
||||
test.assertSelectorHasText('.group-email .help-block', 'This email already exists.');
|
||||
|
||||
// generate a new email and save it
|
||||
// we're going to use this new account later
|
||||
newEmail = Math.random().toString(36).substr(2,7) + '@thelia.net';
|
||||
thelia_customer.email = newEmail;
|
||||
|
||||
this.fill('form#form-register', {
|
||||
'thelia_customer_create[email]': newEmail,
|
||||
'thelia_customer_create[email_confirm]': newEmail,
|
||||
'thelia_customer_create[password]': 'thelia',
|
||||
'thelia_customer_create[password_confirm]': 'thelia'
|
||||
}, false);
|
||||
|
||||
this.click('form#form-register button[type="submit"]');
|
||||
|
||||
},
|
||||
function(){
|
||||
this.die("Selector '.group-email .help-block' not found. It should contain 'This email already exists'");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'.navbar-customer a.account',
|
||||
function() {
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/20_register-ok.png');
|
||||
}
|
||||
test.assertSelectorHasText('.navbar-customer a.account', 'My Account');
|
||||
test.assertExists('a.logout', 'Logout button exists');
|
||||
|
||||
casper.test.comment('== Logout');
|
||||
|
||||
this.click('a.logout');
|
||||
},
|
||||
function(){
|
||||
this.die("'My account' button not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'a.login',
|
||||
function() {
|
||||
test.assertExists('a.login', 'Login button exists');
|
||||
},
|
||||
function() {
|
||||
this.die('Login button doesn\'t exist');
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
102
tests/functionnal/casperjs/exe/front/30_login.js
Normal file
@@ -0,0 +1,102 @@
|
||||
casper.test.comment('== Login ==');
|
||||
|
||||
casper.test.begin('Login', 5, function suite(test) {
|
||||
|
||||
casper.start(thelia2_base_url + "login", function() {
|
||||
test.assertTitle("Login - " + thelia2_store_name, "title is the one expected");
|
||||
test.assertExists('form#form-login', "login form is found");
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/30_login.png');
|
||||
}
|
||||
casper.test.comment('== Login with a bad account');
|
||||
|
||||
this.fill('form#form-login', {
|
||||
'thelia_customer_login[account]': "1"
|
||||
}, false);
|
||||
|
||||
});
|
||||
|
||||
casper.then(function(){
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#email').value = username;
|
||||
document.querySelector('#password').disabled = false;
|
||||
document.querySelector('#password').value = password;
|
||||
}, 'chuck-norris@thelia.net', 'thelia');
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/30_login-ko-0.png');
|
||||
}
|
||||
|
||||
this.click('form#form-login button[type="submit"]');
|
||||
|
||||
});
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-login .alert-danger',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/30_login-ko.png');
|
||||
}
|
||||
|
||||
test.assertSelectorHasText('form#form-login .alert-danger', 'Wrong email or password. Please try again');
|
||||
|
||||
casper.test.comment('== Login with a good account');
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#email').value = username;
|
||||
document.querySelector('#password').disabled = false;
|
||||
document.querySelector('#password').value = password;
|
||||
document.querySelector('#remerber_me').checked = false;
|
||||
}, 'test@thelia.net', 'azerty');
|
||||
|
||||
this.click('form#form-login button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("Selector 'form#form-login .alert-danger' not found. It should contain the message 'Wrong email or password. Please try again'");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
|
||||
casper.waitForSelector(
|
||||
'a.logout',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/30_login-ok.png');
|
||||
}
|
||||
test.assertExists('a.logout', 'Logout button exists');
|
||||
|
||||
casper.test.comment('== Logout');
|
||||
|
||||
this.click('a.logout');
|
||||
},
|
||||
function(){
|
||||
this.die("Logout button not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'a.login',
|
||||
function() {
|
||||
test.assertExists('a.login', 'Login button exists');
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#email-mini').value = username;
|
||||
document.querySelector('#password-mini').value = password;
|
||||
}, thelia_customer.email, thelia_customer.password);
|
||||
this.click('form#form-login-mini button[type="submit"]');
|
||||
},
|
||||
function() {
|
||||
this.die('Login button not found');
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
76
tests/functionnal/casperjs/exe/front/40_cart.js
Normal file
@@ -0,0 +1,76 @@
|
||||
casper.test.comment('== Cart ==');
|
||||
|
||||
casper.test.begin('Cart', 5, function suite(test) {
|
||||
|
||||
var productUrl = '';
|
||||
|
||||
casper.start(thelia2_base_url, function() {
|
||||
|
||||
var productsUrl = this.getElementsAttribute('a.product-info', 'href');
|
||||
productUrl = productsUrl[Math.floor(Math.random() * productsUrl.length)];
|
||||
|
||||
this.echo("product : " + productUrl);
|
||||
|
||||
this.thenOpen(productUrl, function() {
|
||||
this.echo(this.getTitle());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
casper.waitForSelector(
|
||||
"#pse-submit",
|
||||
function(){
|
||||
test.assertExists("#pse-submit", "Add to cart button exists");
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/40_product.png');
|
||||
}
|
||||
this.echo("Submit add to cart");
|
||||
|
||||
var isDisabled = this.evaluate(function() {
|
||||
return document.querySelector("#pse-submit").hasAttribute('disabled');
|
||||
});
|
||||
|
||||
if (isDisabled) {
|
||||
this.skipTest("This product doesn't have any quantity")
|
||||
}
|
||||
this.click("#pse-submit");
|
||||
},
|
||||
function(){
|
||||
this.die("Add to cart button not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'.bootbox h3.text-center',
|
||||
function() {
|
||||
//this.echo(this.getHTML());
|
||||
test.assertSelectorHasText('.bootbox h3.text-center', 'The product has been added to your cart');
|
||||
if (screenshot_enabled) {
|
||||
this.captureSelector(screenshot_dir + 'front/40_added-to-cart.png', '.bootbox');
|
||||
}
|
||||
},
|
||||
function(){
|
||||
this.die("'The product has been added to your cart' pop-in not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.thenOpen(thelia2_base_url + "cart", function() {
|
||||
this.echo(this.getTitle());
|
||||
test.assertExists("#cart .table-cart", "Cart table exists");
|
||||
test.assertElementCount("#cart .table-cart tbody tr h3.name a", 1, "Cart contains 1 product")
|
||||
|
||||
var link = this.getElementInfo('#cart .table-cart tbody tr h3.name a');
|
||||
test.assertTruthy( link.attributes.href == productUrl, "This is the right product in cart");
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/40_cart.png');
|
||||
}
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
54
tests/functionnal/casperjs/exe/front/50-order-process.js
Normal file
@@ -0,0 +1,54 @@
|
||||
casper.test.comment('== Order process ==');
|
||||
|
||||
casper.test.begin('Order process', 4, function suite(test) {
|
||||
|
||||
casper.start(thelia2_base_url + "order/delivery", function goToDelivery() {
|
||||
|
||||
casper.waitForSelector(
|
||||
'#delivery-module-list-block .radio',
|
||||
function then() {
|
||||
casper.test.comment('== Page loaded : ' + this.getCurrentUrl());
|
||||
test.assertTitle("Billing and delivery - Cart - " + thelia2_store_name, "title is the one expected for url : " + this.getCurrentUrl());
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/50_delivery_list.png');
|
||||
}
|
||||
|
||||
test.assertEval(function () {
|
||||
return __utils__.findAll("#form-cart-delivery table.table-address tr").length >= 1;
|
||||
}, "We expect at least one delivery address");
|
||||
|
||||
this.click('form#form-cart-delivery button[type="submit"]');
|
||||
},
|
||||
function timeout() {
|
||||
test.assertElementCount("table.table-cart-mini tbody tr", 1, "cart contain 1 product");
|
||||
if (this.getCurrentUrl() == thelia2_base_url + "order/invoice") {
|
||||
test.info("with a virtual product, the delivery page is skipped");
|
||||
test.skip(1);
|
||||
} else {
|
||||
this.die("impossible to load delivery methods");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
casper.waitForSelector(
|
||||
'.footer-container',
|
||||
function(){
|
||||
test.assertTitle("My order - Cart - " + thelia2_store_name, "title is the one expected for url : " + this.getCurrentUrl());
|
||||
|
||||
test.assertElementCount("table.table-cart tbody tr", 1, "cart contain 1 product");
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/50_delivery_order.png');
|
||||
}
|
||||
},
|
||||
function(){
|
||||
this.die("The 'title' tag didn't change");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
});
|
||||
249
tests/functionnal/casperjs/exe/front/60-newsletter.js
Normal file
@@ -0,0 +1,249 @@
|
||||
casper.test.comment('== Newsletter ==');
|
||||
|
||||
casper.test.begin('Newsletter', 12, function suite(test) {
|
||||
|
||||
var newEmail = '';
|
||||
|
||||
casper.start(thelia2_base_url + "newsletter", function() {
|
||||
if (this.exists('.navbar-customer .logout')) {
|
||||
this.click('.navbar-customer .logout');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
casper.thenOpen(thelia2_base_url + "newsletter", function(){
|
||||
test.assertTitle("Newsletter - Thelia V2", "title is the one expected");
|
||||
});
|
||||
|
||||
casper.waitForSelector(
|
||||
'.navbar-customer .register',
|
||||
function() {
|
||||
test.assertExists('.navbar-customer .register', 'user is disconnected');
|
||||
|
||||
test.assertExists('form#form-newsletter', "newsletter form is found");
|
||||
|
||||
casper.test.comment("== User isn't connected");
|
||||
|
||||
test.assertExists('form#form-newsletter #firstname_newsletter', 'firstname field is displayed');
|
||||
test.assertExists('form#form-newsletter #lastname_newsletter', 'lastname field is displayed');
|
||||
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter.png');
|
||||
}
|
||||
|
||||
casper.test.comment('== Newsletter blank submission');
|
||||
|
||||
this.fill('form#form-newsletter', {
|
||||
'thelia_newsletter[email]': '',
|
||||
'thelia_newsletter[firstname]': 'Thelia',
|
||||
'thelia_newsletter[lastname]': 'Thelia'
|
||||
}, true);
|
||||
},
|
||||
function(){
|
||||
this.die("Select '.navbar-customer .register' not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
|
||||
casper.waitForSelector(
|
||||
'#email_newsletter',
|
||||
function(){
|
||||
casper.evaluate(function(email) {
|
||||
document.querySelector('#email_newsletter').value = email;
|
||||
}, '');
|
||||
|
||||
this.click('form#form-newsletter button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("'email' field in newsletter form not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter .group-email.has-error',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter-ko-0.png');
|
||||
}
|
||||
test.assertExists('form#form-newsletter .group-email.has-error', 'email can not be empty');
|
||||
},function(){
|
||||
this.die("Can't find newsletter form error");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter',
|
||||
function(){
|
||||
casper.test.comment('== Test submission');
|
||||
|
||||
this.fill('form#form-newsletter', {
|
||||
'thelia_newsletter[email]': 'test@thelia.net',
|
||||
'thelia_newsletter[firstname]': 'Thelia',
|
||||
'thelia_newsletter[lastname]': 'Thelia'
|
||||
}, true);
|
||||
|
||||
casper.evaluate(function(email) {
|
||||
document.querySelector('#email_newsletter').value = email;
|
||||
}, 'test@thelia.net');
|
||||
|
||||
this.click('form#form-newsletter button[type="submit"]');
|
||||
},
|
||||
function() {
|
||||
this.die("Newsletter form not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter',
|
||||
function(){
|
||||
casper.test.comment('== Existing email on submission');
|
||||
|
||||
this.fill('form#form-newsletter', {
|
||||
'thelia_newsletter[email]': 'test@thelia.net',
|
||||
'thelia_newsletter[firstname]': 'Thelia',
|
||||
'thelia_newsletter[lastname]': 'Thelia'
|
||||
}, true);
|
||||
|
||||
casper.evaluate(function(email) {
|
||||
document.querySelector('#email_newsletter').value = email;
|
||||
}, 'test@thelia.net');
|
||||
|
||||
this.click('form#form-newsletter button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter .group-email.has-error',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter-ko-0.png');
|
||||
}
|
||||
test.assertExists('form#form-newsletter .group-email.has-error', 'email already exist');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form error message not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter',
|
||||
function(){
|
||||
casper.test.comment('== Great email on submission');
|
||||
|
||||
newEmail = Math.random().toString(36).substr(2,7) + '@thelia.net';
|
||||
|
||||
this.fill('form#form-newsletter', {
|
||||
'thelia_newsletter[email]': newEmail,
|
||||
'thelia_newsletter[firstname]': 'Thelia',
|
||||
'thelia_newsletter[lastname]': 'Thelia'
|
||||
}, true);
|
||||
|
||||
casper.evaluate(function(email) {
|
||||
document.querySelector('#email_newsletter').value = email;
|
||||
}, newEmail);
|
||||
|
||||
this.click('form#form-newsletter button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter .group-email.has-success',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter-ok-0.png');
|
||||
}
|
||||
test.assertExists('form#form-newsletter .group-email.has-success', 'subscription with success');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form success message not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'#email-mini',
|
||||
function(){
|
||||
casper.test.comment('== Login user');
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#email-mini').value = username;
|
||||
document.querySelector('#password-mini').value = password;
|
||||
}, 'test@thelia.net', 'azerty');
|
||||
|
||||
this.click('form#form-login-mini button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form 'email-mini' field not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'a.logout',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter-ok-1.png');
|
||||
}
|
||||
test.assertExists('a.logout', 'Logout button exists');
|
||||
test.assertDoesntExist('form#form-newsletter #firstname_newsletter', "firstname field doesn't exist");
|
||||
test.assertDoesntExist('form#form-newsletter #lastname_newsletter', "lastname field doesn't exist");
|
||||
},
|
||||
function(){
|
||||
this.die("Logout button not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter',
|
||||
function(){
|
||||
casper.test.comment('== Subscribe again');
|
||||
|
||||
this.fill('form#form-newsletter', {
|
||||
'thelia_newsletter[email]': 'test@thelia.net'
|
||||
}, true);
|
||||
|
||||
casper.evaluate(function(email) {
|
||||
document.querySelector('#email_newsletter').value = email;
|
||||
}, 'test@thelia.net');
|
||||
|
||||
this.click('form#form-newsletter button[type="submit"]');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.waitForSelector(
|
||||
'form#form-newsletter .group-email.has-error',
|
||||
function(){
|
||||
if (screenshot_enabled) {
|
||||
this.capture(screenshot_dir + 'front/60_newsletter-ko-1.png');
|
||||
}
|
||||
test.assertExists('form#form-newsletter .group-email.has-error', 'this user is already registered');
|
||||
},
|
||||
function(){
|
||||
this.die("Newsletter form error message not found");
|
||||
},
|
||||
thelia_default_timeout
|
||||
);
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
141
tests/functionnal/casperjs/exe/hook/10_position.js
Normal file
@@ -0,0 +1,141 @@
|
||||
var xp = require('casper').selectXPath;
|
||||
|
||||
casper.test.comment('== Hook - changing position ==');
|
||||
|
||||
casper.test.begin('Front Homepage', 12, function suite(test) {
|
||||
|
||||
|
||||
|
||||
var modules = {
|
||||
newProducts: {
|
||||
// block id in FO
|
||||
id: "products-new",
|
||||
// title in BO
|
||||
title: "Block New Products"
|
||||
},
|
||||
promoProducts: {
|
||||
id: "products-offer",
|
||||
title: "Block Promo Products"
|
||||
}
|
||||
};
|
||||
|
||||
var modulePromoProductId = null;
|
||||
|
||||
// Try to login
|
||||
casper.start(thelia2_base_url + 'admin/login', function() {
|
||||
|
||||
test.comment('Login to back Office');
|
||||
|
||||
test.assertTitle("Welcome - Thelia Back Office");
|
||||
test.assertExists('div.loginpage', "This is the login page");
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#username').value = username;
|
||||
document.querySelector('#password').value = password;
|
||||
}, administrator.login, administrator.password);
|
||||
|
||||
this.click('div.loginpage button[type="submit"]');
|
||||
});
|
||||
|
||||
casper.waitForSelector('body .homepage', function(){
|
||||
|
||||
test.assertTitle("Back-office home - Thelia Back Office", "This is the dashboard");
|
||||
|
||||
});
|
||||
|
||||
// Get current order
|
||||
casper.thenOpen(thelia2_base_url, function() {
|
||||
|
||||
var order = [], i;
|
||||
|
||||
test.comment('Get current order on home page');
|
||||
|
||||
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
|
||||
|
||||
homeModules = this.getElementsInfo('#content > section');
|
||||
for (i=0 ; i<homeModules.length ; i++){
|
||||
order.push(homeModules[i].attributes['id'])
|
||||
}
|
||||
|
||||
test.assertTruthy(
|
||||
homeModules.length == 2,
|
||||
"2 modules on home page : " + order.join(", ")
|
||||
);
|
||||
|
||||
test.assertTruthy(
|
||||
order.join() == [modules.newProducts.id, modules.promoProducts.id].join(),
|
||||
"The order of the module on the home page is good : " + order.join(', ')
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
// Change Order
|
||||
casper.thenOpen(thelia2_base_url + 'admin/module-hooks', function() {
|
||||
|
||||
test.comment('Change order');
|
||||
|
||||
test.assertTitle("Hooks position - Thelia Back Office", "This is the page to manage modules hooks");
|
||||
|
||||
var linePromoProducts = null;
|
||||
|
||||
linePromoProducts = this.getElementInfo(
|
||||
xp('//tr[@class="hook-module"]/td[normalize-space(.)="' + modules.promoProducts.title + '"]/..')
|
||||
);
|
||||
|
||||
test.assertTruthy(linePromoProducts != null, "The module Promo Product exist");
|
||||
|
||||
modulePromoProductId = linePromoProducts.attributes['data-module-id'];
|
||||
|
||||
// trigger position change
|
||||
this.click('tr[data-module-id="' + modulePromoProductId + '"] a.u-position-up');
|
||||
|
||||
casper.waitFor(
|
||||
function(){
|
||||
var linePromoProductPosition = this.getElementInfo(
|
||||
'tr[data-module-id="' + modulePromoProductId + '"] .moduleHookPositionChange'
|
||||
);
|
||||
return linePromoProductPosition.text == "1";
|
||||
},
|
||||
function(){
|
||||
test.comment('Position for hooks position has changed');
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
// Get new order
|
||||
// Get current order
|
||||
casper.thenOpen(thelia2_base_url, function() {
|
||||
|
||||
test.comment('Get new order on home page');
|
||||
|
||||
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
|
||||
|
||||
homeModules = this.getElementsInfo('#content > section');
|
||||
test.assertTruthy(
|
||||
homeModules.length == 2,
|
||||
"2 modules on home page"
|
||||
);
|
||||
|
||||
order = [
|
||||
homeModules[0].attributes['id'],
|
||||
homeModules[1].attributes['id']
|
||||
];
|
||||
|
||||
test.assertTruthy(
|
||||
order.join() == [modules.promoProducts.id, modules.newProducts.id].join(),
|
||||
"The order of the module on the home page has change : " + order.join(', ')
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
casper.thenOpen(thelia2_base_url + 'admin/logout', function() {
|
||||
test.comment('logout');
|
||||
test.assertTitle("Welcome - Thelia Back Office");
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
221
tests/functionnal/casperjs/exe/hook/20_activation.js
Normal file
@@ -0,0 +1,221 @@
|
||||
var xp = require('casper').selectXPath;
|
||||
|
||||
casper.test.comment('== Hook - changing position ==');
|
||||
|
||||
casper.test.begin('Front Homepage', 22, function suite(test) {
|
||||
|
||||
var modules = {
|
||||
newProducts: {
|
||||
// block id in FO
|
||||
id: "products-new",
|
||||
// title in BO
|
||||
title: "Block New Products"
|
||||
},
|
||||
promoProducts: {
|
||||
id: "products-offer",
|
||||
title: "Block Promo Products"
|
||||
},
|
||||
blockCurrency: {
|
||||
id: 'nav-currency',
|
||||
title: 'Block Currency'
|
||||
}
|
||||
};
|
||||
|
||||
// Try to login
|
||||
casper.start(thelia2_base_url + 'admin/login', function() {
|
||||
|
||||
test.comment('Login to back Office');
|
||||
|
||||
test.assertTitle("Welcome - Thelia Back Office");
|
||||
test.assertExists('div.loginpage', "This is the login page");
|
||||
|
||||
casper.evaluate(function(username, password) {
|
||||
document.querySelector('#username').value = username;
|
||||
document.querySelector('#password').value = password;
|
||||
}, administrator.login, administrator.password);
|
||||
|
||||
this.click('div.loginpage button[type="submit"]');
|
||||
});
|
||||
|
||||
casper.waitForSelector('body .homepage', function(){
|
||||
|
||||
test.assertTitle("Back-office home - Thelia Back Office", "This is the dashboard");
|
||||
|
||||
});
|
||||
|
||||
// be sure to have the good configuration
|
||||
|
||||
casper.thenOpen(thelia2_base_url, function() {
|
||||
|
||||
test.comment('Get current configuration on home page');
|
||||
|
||||
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
|
||||
|
||||
// 2 modules in hook home.body
|
||||
test.assertElementCount(
|
||||
'#content > section',
|
||||
2,
|
||||
"2 modules on home page (hook: home.body)"
|
||||
);
|
||||
|
||||
// module currency exists
|
||||
test.assertExists(
|
||||
".nav-secondary .navbar-currency",
|
||||
"Module Currency selector exists"
|
||||
);
|
||||
|
||||
// module currency exists
|
||||
test.assertExists(
|
||||
".nav-secondary .navbar-currency",
|
||||
"Module Currency selector exists"
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
// deactivation of module hook
|
||||
|
||||
casper.thenOpen(thelia2_base_url + 'admin/module-hooks', function() {
|
||||
|
||||
test.comment('deactivate module hook for Promo products');
|
||||
|
||||
test.assertTitle("Hooks position - Thelia Back Office", "This is the page to manage modules hooks");
|
||||
|
||||
var moduleHookTag = null,
|
||||
hookId = null;
|
||||
|
||||
moduleHookTag = this.getElementInfo(
|
||||
xp('//tr[@class="hook-module"]/td[normalize-space(.)="' + modules.promoProducts.title + '"]/..')
|
||||
);
|
||||
|
||||
test.assertTruthy(moduleHookTag != null, "The module Promo Product exist");
|
||||
|
||||
hookId = moduleHookTag.attributes['data-module-id'];
|
||||
|
||||
// test if activated
|
||||
test.assertExist(
|
||||
'tr[data-module-id="' + hookId + '"] .switch-on',
|
||||
'module hook for Promo products is activated'
|
||||
);
|
||||
// trigger toggle activation
|
||||
this.click('tr[data-module-id="' + hookId + '"] div.module-hook-activation .switch-left');
|
||||
|
||||
test.comment('waiting...');
|
||||
|
||||
casper.waitForSelector('tr[data-module-id="' + hookId + '"] .switch-off', function(){
|
||||
test.comment('Status for hook position has changed');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// deactivation of module Block Currency
|
||||
|
||||
casper.thenOpen(thelia2_base_url + 'admin/modules', function() {
|
||||
|
||||
var moduleIdTag = null,
|
||||
moduleId = null;
|
||||
|
||||
test.comment('deactivate module Block Currency');
|
||||
|
||||
test.assertTitle("Modules - Thelia Back Office", "This is the page to manage modules hooks");
|
||||
|
||||
moduleIdTag = this.getElementInfo(
|
||||
xp('//tr/td[normalize-space(.)="' + modules.blockCurrency.title + '"]/../td[1]')
|
||||
);
|
||||
|
||||
test.assertTruthy(moduleIdTag != null, "The module Block Currency exists");
|
||||
|
||||
moduleId = moduleIdTag.text;
|
||||
|
||||
// test if activated
|
||||
test.assertExist(
|
||||
'.make-switch[data-id="' + moduleId + '"] .switch-on',
|
||||
'module Block Currency is activated'
|
||||
);
|
||||
|
||||
// trigger toggle activation
|
||||
this.click('.make-switch[data-id="' + moduleId + '"] .switch-left');
|
||||
|
||||
test.comment('waiting...');
|
||||
|
||||
casper.waitForSelector('.make-switch[data-id="' + moduleId + '"] .switch-off', function(){
|
||||
test.comment('Status for module has changed');
|
||||
});
|
||||
});
|
||||
|
||||
// deactivation of hook main.navbar-primary
|
||||
|
||||
casper.thenOpen(thelia2_base_url + 'admin/hooks', function() {
|
||||
|
||||
test.comment('deactivate hook main.navbar-primary');
|
||||
|
||||
test.assertTitle("Hooks - Thelia Back Office", "This is the page to manage modules hooks");
|
||||
|
||||
var hookTag = null,
|
||||
hookId = null;
|
||||
|
||||
hookTag = this.getElementInfo(
|
||||
xp('//tr/td/a[normalize-space(.)="main.navbar-primary"]/../../td[1]')
|
||||
);
|
||||
|
||||
test.assertTruthy(hookTag != null, "The hook main.navbar-primary exists");
|
||||
|
||||
hookId = hookTag.text;
|
||||
|
||||
// test if activated
|
||||
test.assertExist(
|
||||
'.make-switch[data-id="' + hookId + '"] .switch-on',
|
||||
'hook main.navbar-primary is activated'
|
||||
);
|
||||
// trigger toggle activation
|
||||
this.click('.make-switch[data-id="' + hookId + '"] .switch-left');
|
||||
|
||||
test.comment('waiting...');
|
||||
|
||||
casper.waitForSelector('.make-switch[data-id="' + hookId + '"] .switch-off', function(){
|
||||
test.comment('Status for hook has changed');
|
||||
});
|
||||
});
|
||||
|
||||
// Test the new home page
|
||||
casper.thenOpen(thelia2_base_url, function() {
|
||||
|
||||
test.comment('Get new configuration on home page');
|
||||
|
||||
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
|
||||
|
||||
// 1 module in hook home.body
|
||||
test.assertElementCount(
|
||||
'#content > section',
|
||||
1,
|
||||
"1 module on home page"
|
||||
);
|
||||
|
||||
test.assertDoesntExist(
|
||||
modules.promoProducts.id,
|
||||
"The module on the home page is ok"
|
||||
);
|
||||
|
||||
// module currency should not exist
|
||||
test.assertDoesntExist(
|
||||
".nav-secondary .navbar-currency",
|
||||
"Module Currency selector doesn't exist"
|
||||
);
|
||||
|
||||
// module currency exists
|
||||
test.assertDoesntExist(
|
||||
"header.container .nav-main",
|
||||
"Main navigation doesn't exists"
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
casper.thenOpen(thelia2_base_url + 'admin/logout', function() {
|
||||
test.comment('logout');
|
||||
test.assertTitle("Welcome - Thelia Back Office", "This is the good title. url: " + this.getCurrentUrl());
|
||||
});
|
||||
|
||||
casper.run(function() {
|
||||
test.done();
|
||||
});
|
||||
|
||||
});
|
||||
184
tests/phpunit/Thelia/Tests/Action/AddressTest.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Action\Address;
|
||||
use Thelia\Core\Event\Address\AddressCreateOrUpdateEvent;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* test address eventListener
|
||||
*
|
||||
* Class AddressTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AddressTest extends BaseAction
|
||||
{
|
||||
public function testCreatedAddress()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
|
||||
$AddressCreateOrUpdateEvent = new AddressCreateOrUpdateEvent(
|
||||
"test address",
|
||||
1,
|
||||
"Thelia",
|
||||
"Thelia",
|
||||
"5 rue rochon",
|
||||
"",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$AddressCreateOrUpdateEvent->setCustomer($customer);
|
||||
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->create($AddressCreateOrUpdateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAddress = $AddressCreateOrUpdateEvent->getAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $createdAddress);
|
||||
$this->assertFalse($createdAddress->isNew());
|
||||
$this->assertSame($customer, $createdAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLabel(), $createdAddress->getLabel());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getTitle(), $createdAddress->getTitleId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getFirstname(), $createdAddress->getFirstname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getLastname(), $createdAddress->getLastname());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress1(), $createdAddress->getAddress1());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress2(), $createdAddress->getAddress2());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getAddress3(), $createdAddress->getAddress3());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getZipcode(), $createdAddress->getZipcode());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCity(), $createdAddress->getCity());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCountry(), $createdAddress->getCountryId());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getPhone(), $createdAddress->getPhone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCellphone(), $createdAddress->getCellphone());
|
||||
$this->assertEquals($AddressCreateOrUpdateEvent->getCompany(), $createdAddress->getCompany());
|
||||
}
|
||||
|
||||
public function testUpdatedAddress()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
$address = $customer->getAddresses()->getFirst();
|
||||
|
||||
$addressEvent = new AddressCreateOrUpdateEvent(
|
||||
"",
|
||||
1,
|
||||
"Thelia modif",
|
||||
"Thelia modif",
|
||||
"cour des étoiles",
|
||||
"rue des miracles",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
""
|
||||
);
|
||||
$addressEvent->setAddress($address);
|
||||
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->update($addressEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAddress = $addressEvent->getAddress();
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $updatedAddress);
|
||||
$this->assertFalse($updatedAddress->isNew());
|
||||
$this->assertSame($customer, $updatedAddress->getCustomer());
|
||||
|
||||
$this->assertEquals($address->getLabel(), $updatedAddress->getLabel());
|
||||
$this->assertEquals($addressEvent->getTitle(), $updatedAddress->getTitleId());
|
||||
$this->assertEquals($addressEvent->getFirstname(), $updatedAddress->getFirstname());
|
||||
$this->assertEquals($addressEvent->getLastname(), $updatedAddress->getLastname());
|
||||
$this->assertEquals($addressEvent->getAddress1(), $updatedAddress->getAddress1());
|
||||
$this->assertEquals($addressEvent->getAddress2(), $updatedAddress->getAddress2());
|
||||
$this->assertEquals($addressEvent->getAddress3(), $updatedAddress->getAddress3());
|
||||
$this->assertEquals($addressEvent->getZipcode(), $updatedAddress->getZipcode());
|
||||
$this->assertEquals($addressEvent->getCity(), $updatedAddress->getCity());
|
||||
$this->assertEquals($addressEvent->getCountry(), $updatedAddress->getCountryId());
|
||||
$this->assertEquals($addressEvent->getPhone(), $updatedAddress->getPhone());
|
||||
$this->assertEquals($addressEvent->getCellphone(), $updatedAddress->getCellphone());
|
||||
$this->assertEquals($addressEvent->getCompany(), $updatedAddress->getCompany());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bug found in Thelia 2.0.2
|
||||
*/
|
||||
public function testUpdateDefaultAddress()
|
||||
{
|
||||
/**
|
||||
* Disable propel cache in order to get a new instance of the
|
||||
* active record in $updatedAddress
|
||||
*/
|
||||
Propel::disableInstancePooling();
|
||||
|
||||
/**
|
||||
* Get a customer and it's default address
|
||||
*/
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
$defaultAddress = $customer->getDefaultAddress();
|
||||
$addressId = $defaultAddress->getId();
|
||||
|
||||
/**
|
||||
* Try to update the address, and set the isDefault argument,
|
||||
* that should keep this address as the default one.
|
||||
*/
|
||||
$addressEvent = new AddressCreateOrUpdateEvent(
|
||||
"",
|
||||
1,
|
||||
"Thelia modif",
|
||||
"Thelia modif",
|
||||
"cour des étoiles",
|
||||
"rue des miracles",
|
||||
"",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
"0102030405",
|
||||
"",
|
||||
"",
|
||||
1
|
||||
);
|
||||
|
||||
$addressEvent->setAddress($defaultAddress);
|
||||
|
||||
/**
|
||||
* Do the update
|
||||
*/
|
||||
$actionAddress = new Address();
|
||||
$actionAddress->update($addressEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAddress = AddressQuery::create()
|
||||
->findPk($addressId);
|
||||
|
||||
/**
|
||||
* This address should still be the default address
|
||||
*/
|
||||
$this->assertEquals(
|
||||
1,
|
||||
$updatedAddress->getIsDefault()
|
||||
);
|
||||
|
||||
/**
|
||||
* Renable it after
|
||||
*/
|
||||
Propel::enableInstancePooling();
|
||||
}
|
||||
}
|
||||
178
tests/phpunit/Thelia/Tests/Action/AdministratorTest.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Administrator;
|
||||
use Thelia\Core\Event\Administrator\AdministratorEvent;
|
||||
use Thelia\Core\Event\Administrator\AdministratorUpdatePasswordEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\AdminQuery;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Tools\TokenProvider;
|
||||
|
||||
/**
|
||||
* Class AdministratorTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AdministratorTest extends BaseAction
|
||||
{
|
||||
protected $mailerFactory;
|
||||
protected $tokenProvider;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$this->mailerFactory = $this->getMockBuilder("Thelia\\Mailer\\MailerFactory")
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($request);
|
||||
|
||||
$translator = new Translator(new Container());
|
||||
|
||||
$this->tokenProvider = new TokenProvider($requestStack, $translator, 'test');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$login = 'thelia'.uniqid();
|
||||
$locale = LangQuery::create()->findOne()->getLocale();
|
||||
$adminEvent = new AdministratorEvent();
|
||||
$adminEvent
|
||||
->setFirstname('thelia')
|
||||
->setLastname('thelia')
|
||||
->setLogin($login)
|
||||
->setPassword('azerty')
|
||||
->setLocale($locale)
|
||||
->setEmail(uniqid().'@example.com')
|
||||
;
|
||||
|
||||
$admin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$admin->create($adminEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $createdAdmin);
|
||||
$this->assertFalse($createdAdmin->isNew());
|
||||
|
||||
$this->assertEquals($adminEvent->getFirstname(), $createdAdmin->getFirstname());
|
||||
$this->assertEquals($adminEvent->getLastname(), $createdAdmin->getLastname());
|
||||
$this->assertEquals($adminEvent->getLogin(), $createdAdmin->getLogin());
|
||||
$this->assertEquals($adminEvent->getLocale(), $createdAdmin->getLocale());
|
||||
$this->assertEquals($adminEvent->getProfile(), $createdAdmin->getProfileId());
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $createdAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$login = 'thelia'.uniqid();
|
||||
$locale = LangQuery::create()->findOne()->getLocale();
|
||||
$adminEvent = new AdministratorEvent();
|
||||
$adminEvent
|
||||
->setId($admin->getId())
|
||||
->setFirstname('thelia_update')
|
||||
->setLastname('thelia_update')
|
||||
->setLogin($login)
|
||||
->setPassword('azertyuiop')
|
||||
->setLocale($locale)
|
||||
->setEmail(uniqid().'@example.com')
|
||||
->setDispatcher($this->getMockEventDispatcher())
|
||||
;
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->update($adminEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertFalse($updatedAdmin->isNew());
|
||||
|
||||
$this->assertEquals($adminEvent->getFirstname(), $updatedAdmin->getFirstname());
|
||||
$this->assertEquals($adminEvent->getLastname(), $updatedAdmin->getLastname());
|
||||
$this->assertEquals($adminEvent->getLogin(), $updatedAdmin->getLogin());
|
||||
$this->assertEquals($adminEvent->getLocale(), $updatedAdmin->getLocale());
|
||||
$this->assertEquals($adminEvent->getProfile(), $updatedAdmin->getProfileId());
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$adminEvent = new AdministratorEvent();
|
||||
|
||||
$adminEvent
|
||||
->setId($admin->getId())
|
||||
;
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->delete($adminEvent);
|
||||
|
||||
$deletedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $deletedAdmin);
|
||||
$this->assertTrue($deletedAdmin->isDeleted());
|
||||
}
|
||||
|
||||
public function testUpdatePassword()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
|
||||
$adminEvent = new AdministratorUpdatePasswordEvent($admin);
|
||||
$adminEvent
|
||||
->setPassword('toto');
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
|
||||
$actionAdmin->updatePassword($adminEvent);
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdmin();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
|
||||
}
|
||||
|
||||
public function testRenewPassword()
|
||||
{
|
||||
$admin = AdminQuery::create()->findOne();
|
||||
$admin->setPasswordRenewToken(null)->setEmail('no_reply@thelia.net')->save();
|
||||
|
||||
$adminEvent = new AdministratorEvent($admin);
|
||||
|
||||
$actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
|
||||
$actionAdmin->createPassword($adminEvent);
|
||||
|
||||
$updatedAdmin = $adminEvent->getAdministrator();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Admin", $updatedAdmin);
|
||||
$this->assertNotEmpty($admin->getPasswordRenewToken());
|
||||
}
|
||||
}
|
||||
142
tests/phpunit/Thelia/Tests/Action/AreaTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Area;
|
||||
use Thelia\Core\Event\Area\AreaAddCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaCreateEvent;
|
||||
use Thelia\Core\Event\Area\AreaDeleteEvent;
|
||||
use Thelia\Core\Event\Area\AreaRemoveCountryEvent;
|
||||
use Thelia\Core\Event\Area\AreaUpdatePostageEvent;
|
||||
use Thelia\Model\Area as AreaModel;
|
||||
use Thelia\Model\CountryAreaQuery;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
/**
|
||||
* Class AreaTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AreaTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new AreaCreateEvent();
|
||||
$event
|
||||
->setAreaName('foo');
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $createdArea);
|
||||
$this->assertFalse($createdArea->isNew());
|
||||
$this->assertTrue($event->hasArea());
|
||||
|
||||
$this->assertEquals('foo', $createdArea->getName());
|
||||
|
||||
return $createdArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testCreate
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testUpdatePostage(AreaModel $area)
|
||||
{
|
||||
$event = new AreaUpdatePostageEvent($area->getId());
|
||||
$event
|
||||
->setPostage(20);
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->updatePostage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertEquals(20, $updatedArea->getPostage());
|
||||
|
||||
return $updatedArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testUpdatePostage
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testAddCountry(AreaModel $area)
|
||||
{
|
||||
$country = CountryQuery::create()->findOne();
|
||||
|
||||
$event = new AreaAddCountryEvent($area->getId(), [ $country->getId() ]);
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->addCountry($event);
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$updatedCountry = CountryAreaQuery::create()->findOneByAreaId($updatedArea->getId());
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertEquals($country->getId(), $updatedCountry->getCountryId());
|
||||
|
||||
return $updatedArea;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testAddCountry
|
||||
* @return AreaModel
|
||||
*/
|
||||
public function testRemoveCountry(AreaModel $area)
|
||||
{
|
||||
$country = CountryQuery::create()->filterByArea($area)->find()->getFirst();
|
||||
|
||||
$event = new AreaRemoveCountryEvent($area->getId(), $country->getId());
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->removeCountry($event);
|
||||
|
||||
$updatedCountry = CountryAreaQuery::create()
|
||||
->filterByCountryId($country->getId())
|
||||
->filterByStateId(null)
|
||||
->filterByAreaId($area->getId())
|
||||
->findOne();
|
||||
|
||||
$updatedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $updatedArea);
|
||||
$this->assertNull($updatedCountry);
|
||||
|
||||
return $event->getArea();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AreaModel $area
|
||||
* @depends testRemoveCountry
|
||||
*/
|
||||
public function testDelete(AreaModel $area)
|
||||
{
|
||||
$event = new AreaDeleteEvent($area->getId());
|
||||
|
||||
$areaAction = new Area();
|
||||
$areaAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedArea = $event->getArea();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Area', $deletedArea);
|
||||
$this->assertTrue($deletedArea->isDeleted());
|
||||
}
|
||||
}
|
||||
105
tests/phpunit/Thelia/Tests/Action/AttributeAvTest.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\AttributeAv;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvCreateEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeAvUpdateEvent;
|
||||
use Thelia\Model\AttributeQuery;
|
||||
use Thelia\Model\AttributeAv as AttributeAvModel;
|
||||
|
||||
/**
|
||||
* Class AttributeAvTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AttributeAvTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$attribute = AttributeQuery::create()->findOne();
|
||||
|
||||
$event = new AttributeAvCreateEvent();
|
||||
|
||||
$event
|
||||
->setAttributeId($attribute->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('foo');
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$attributeAvCreated = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $attributeAvCreated);
|
||||
|
||||
$this->assertEquals('en_US', $attributeAvCreated->getLocale());
|
||||
$this->assertEquals('foo', $attributeAvCreated->getTitle());
|
||||
$this->assertNull($attributeAvCreated->getDescription());
|
||||
$this->assertNull($attributeAvCreated->getPostscriptum());
|
||||
$this->assertNull($attributeAvCreated->getChapo());
|
||||
$this->assertEquals($attribute, $attributeAvCreated->getAttribute());
|
||||
|
||||
return $attributeAvCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeAvModel $attributeAv
|
||||
* @depends testCreate
|
||||
* @return AttributeAvModel
|
||||
*/
|
||||
public function testUpdate(AttributeAvModel $attributeAv)
|
||||
{
|
||||
$event = new AttributeAvUpdateEvent($attributeAv->getId());
|
||||
|
||||
$event
|
||||
->setLocale($attributeAv->getLocale())
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum')
|
||||
;
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAttributeAv = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $updatedAttributeAv);
|
||||
|
||||
$this->assertEquals('bar', $updatedAttributeAv->getTitle());
|
||||
$this->assertEquals('bar description', $updatedAttributeAv->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedAttributeAv->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedAttributeAv->getPostscriptum());
|
||||
|
||||
return $updatedAttributeAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeAvModel $attributeAv
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(AttributeAvModel $attributeAv)
|
||||
{
|
||||
$event = new AttributeAvDeleteEvent($attributeAv->getId());
|
||||
|
||||
$action = new AttributeAv();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedAttributeAv = $event->getAttributeAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\AttributeAv', $deletedAttributeAv);
|
||||
$this->assertTrue($deletedAttributeAv->isDeleted());
|
||||
}
|
||||
}
|
||||
95
tests/phpunit/Thelia/Tests/Action/AttributeTest.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Attribute;
|
||||
use Thelia\Core\Event\Attribute\AttributeDeleteEvent;
|
||||
use Thelia\Core\Event\Attribute\AttributeUpdateEvent;
|
||||
use Thelia\Model\Attribute as AttributeModel;
|
||||
use Thelia\Core\Event\Attribute\AttributeCreateEvent;
|
||||
|
||||
/**
|
||||
* Class AttributeTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class AttributeTest extends BaseAction
|
||||
{
|
||||
public function testCreateSimple()
|
||||
{
|
||||
$event = new AttributeCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('foo');
|
||||
|
||||
$action = new Attribute($this->getMockEventDispatcher());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $createdAttribute);
|
||||
$this->assertEquals($createdAttribute->getLocale(), 'en_US');
|
||||
$this->assertEquals($createdAttribute->getTitle(), 'foo');
|
||||
|
||||
return $createdAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeModel $attribute
|
||||
* @depends testCreateSimple
|
||||
* @return AttributeModel
|
||||
*/
|
||||
public function testUpdate(AttributeModel $attribute)
|
||||
{
|
||||
$event = new AttributeUpdateEvent($attribute->getId());
|
||||
|
||||
$event
|
||||
->setLocale($attribute->getLocale())
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum');
|
||||
|
||||
$action = new Attribute();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $updatedAttribute);
|
||||
$this->assertEquals('en_US', $updatedAttribute->getLocale());
|
||||
$this->assertEquals('bar', $updatedAttribute->getTitle());
|
||||
$this->assertEquals('bar description', $updatedAttribute->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedAttribute->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedAttribute->getPostscriptum());
|
||||
|
||||
return $updatedAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AttributeModel $attribute
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(AttributeModel $attribute)
|
||||
{
|
||||
$event = new AttributeDeleteEvent($attribute->getId());
|
||||
|
||||
$action = new Attribute();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedAttribute = $event->getAttribute();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Attribute', $deletedAttribute);
|
||||
$this->assertTrue($deletedAttribute->isDeleted());
|
||||
}
|
||||
}
|
||||
50
tests/phpunit/Thelia/Tests/Action/BaseAction.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Core\Template\ParserInterface;
|
||||
|
||||
/**
|
||||
* Class BaseAction
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class BaseAction extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ParserInterface
|
||||
*/
|
||||
protected function getMockParserInterface()
|
||||
{
|
||||
return $this->createMock("Thelia\\Core\\Template\\ParserInterface");
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->set("event_dispatcher", $this->getMockEventDispatcher());
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
251
tests/phpunit/Thelia/Tests/Action/BrandTest.php
Normal file
@@ -0,0 +1,251 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Brand;
|
||||
use Thelia\Core\Event\Brand\BrandCreateEvent;
|
||||
use Thelia\Core\Event\Brand\BrandDeleteEvent;
|
||||
use Thelia\Core\Event\Brand\BrandToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Brand\BrandUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\BrandQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class BrandTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class BrandTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
public function getUpdateEvent(&$brand)
|
||||
{
|
||||
if (!$brand instanceof \Thelia\Model\Brand) {
|
||||
$brand = $this->getRandomBrand();
|
||||
}
|
||||
|
||||
$event = new BrandUpdateEvent($brand->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($brand->getLocale())
|
||||
->setTitle($brand->getTitle())
|
||||
->setChapo($brand->getChapo())
|
||||
->setDescription($brand->getDescription())
|
||||
->setPostscriptum($brand->getPostscriptum())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BrandUpdateEvent $event
|
||||
* @return Brand
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$brandAction = new Brand();
|
||||
$brandAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getBrand();
|
||||
}
|
||||
|
||||
public function testCreateBrand()
|
||||
{
|
||||
$event = new BrandCreateEvent();
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create brand')
|
||||
;
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $createdBrand);
|
||||
$this->assertEquals(1, $createdBrand->getVisible());
|
||||
$this->assertEquals('test create brand', $createdBrand->getTitle());
|
||||
}
|
||||
|
||||
public function testUpdateBrand()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$event = new BrandUpdateEvent($brand->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update brand title')
|
||||
->setChapo('test update brand short description')
|
||||
->setDescription('test update brand description')
|
||||
->setPostscriptum('test update brand postscriptum')
|
||||
;
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $updatedBrand);
|
||||
$this->assertEquals(1, $updatedBrand->getVisible());
|
||||
$this->assertEquals('test update brand title', $updatedBrand->getTitle());
|
||||
$this->assertEquals('test update brand short description', $updatedBrand->getChapo());
|
||||
$this->assertEquals('test update brand description', $updatedBrand->getDescription());
|
||||
$this->assertEquals('test update brand postscriptum', $updatedBrand->getPostscriptum());
|
||||
}
|
||||
|
||||
public function testDeleteBrand()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$event = new BrandDeleteEvent($brand->getId());
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $deletedBrand);
|
||||
$this->assertTrue($deletedBrand->isDeleted());
|
||||
}
|
||||
|
||||
public function testBrandToggleVisibility()
|
||||
{
|
||||
$brand = $this->getRandomBrand();
|
||||
|
||||
$visibility = $brand->getVisible();
|
||||
|
||||
$event = new BrandToggleVisibilityEvent($brand);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = $event->getBrand();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Brand', $updatedBrand);
|
||||
$this->assertEquals(!$visibility, $updatedBrand->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$newPosition = $brand->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedBrand->getPosition(), sprintf("new position is %d, new position expected is %d for brand %d", $newPosition, $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$newPosition = $brand->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_DOWN);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedBrand->getPosition(), sprintf("new position is %d, new position expected is %d for brand %d", $newPosition, $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$this->resetBrandPosition();
|
||||
|
||||
$brand = BrandQuery::create()
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent($brand->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
|
||||
|
||||
$brandAction = new Brand();
|
||||
$brandAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedBrand = BrandQuery::create()->findPk($brand->getId());
|
||||
|
||||
$this->assertEquals(1, $updatedBrand->getPosition(), sprintf("new position is 1, new position expected is %d for brand %d", $updatedBrand->getPosition(), $updatedBrand->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorder brand to have proper position
|
||||
*/
|
||||
protected function resetBrandPosition()
|
||||
{
|
||||
$brands = BrandQuery::create()->find();
|
||||
$counter = 1;
|
||||
|
||||
/** @var \Thelia\Model\Brand $brand */
|
||||
foreach ($brands as $brand) {
|
||||
$brand->setPosition($counter);
|
||||
$brand->save();
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Brand
|
||||
*/
|
||||
protected function getRandomBrand()
|
||||
{
|
||||
$brand = BrandQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $brand) {
|
||||
$this->fail('use fixtures before launching test, there is no brand in database');
|
||||
}
|
||||
|
||||
return $brand;
|
||||
}
|
||||
}
|
||||
68
tests/phpunit/Thelia/Tests/Action/CacheTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Action\Cache;
|
||||
use Thelia\Core\Event\Cache\CacheEvent;
|
||||
|
||||
/**
|
||||
* Class CacheTest
|
||||
* @package Thelia\Tests\Action\assets
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
* @author Gilles Bourgeat <gilles.bourgeat@gmail.com>
|
||||
*/
|
||||
class CacheTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $dir;
|
||||
protected $dir2;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->dir = __DIR__ . '/test';
|
||||
$this->dir2 = __DIR__ . '/test2';
|
||||
|
||||
$fs = new Filesystem();
|
||||
$fs->mkdir($this->dir);
|
||||
$fs->mkdir($this->dir2);
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
{
|
||||
$event = new CacheEvent($this->dir, false);
|
||||
|
||||
$adapter = new ArrayAdapter();
|
||||
$action = new Cache($adapter);
|
||||
$action->cacheClear($event);
|
||||
|
||||
$fs = new Filesystem();
|
||||
$this->assertFalse($fs->exists($this->dir));
|
||||
}
|
||||
|
||||
public function testKernelTerminateCacheClear()
|
||||
{
|
||||
$event = new CacheEvent($this->dir2);
|
||||
|
||||
$adapter = new ArrayAdapter();
|
||||
$action = new Cache($adapter);
|
||||
$action->cacheClear($event);
|
||||
|
||||
$fs = new Filesystem();
|
||||
$this->assertTrue($fs->exists($this->dir2));
|
||||
|
||||
$action->onTerminate();
|
||||
|
||||
$this->assertFalse($fs->exists($this->dir2));
|
||||
}
|
||||
}
|
||||
189
tests/phpunit/Thelia/Tests/Action/CategoryTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Category;
|
||||
use Thelia\Core\Event\Category\CategoryCreateEvent;
|
||||
use Thelia\Core\Event\Category\CategoryDeleteEvent;
|
||||
use Thelia\Core\Event\Category\CategoryToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Category\CategoryUpdateEvent;
|
||||
use Thelia\Core\Event\Template\TemplateDeleteEvent;
|
||||
use Thelia\Model\Category as CategoryModel;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\Template;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class CategoryTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CategoryTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Category
|
||||
*/
|
||||
protected function getRandomCategory()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $category) {
|
||||
$this->fail('use fixtures before launching test, there is no category in database');
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CategoryCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setParent(0)
|
||||
->setTitle('foo')
|
||||
->setVisible(1);
|
||||
|
||||
$action = new Category();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $createdCategory);
|
||||
|
||||
$this->assertFalse($createdCategory->isNew());
|
||||
|
||||
$this->assertEquals('en_US', $createdCategory->getLocale());
|
||||
$this->assertEquals('foo', $createdCategory->getTitle());
|
||||
$this->assertEquals(1, $createdCategory->getVisible());
|
||||
$this->assertEquals(0, $createdCategory->getParent());
|
||||
$this->assertNull($createdCategory->getDescription());
|
||||
$this->assertNull($createdCategory->getChapo());
|
||||
$this->assertNull($createdCategory->getPostscriptum());
|
||||
|
||||
return $createdCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryModel $category
|
||||
* @depends testCreate
|
||||
* @return CategoryModel
|
||||
*/
|
||||
public function testUpdate(CategoryModel $category)
|
||||
{
|
||||
$template = new Template();
|
||||
$template->setName('A sample template')->save();
|
||||
|
||||
$event = new CategoryUpdateEvent($category->getId());
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('bar')
|
||||
->setDescription('bar description')
|
||||
->setChapo('bar chapo')
|
||||
->setPostscriptum('bar postscriptum')
|
||||
->setVisible(0)
|
||||
->setParent(0)
|
||||
->setDefaultTemplateId($template->getId())
|
||||
;
|
||||
|
||||
$action = new Category();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $updatedCategory);
|
||||
|
||||
$this->assertEquals('en_US', $updatedCategory->getLocale());
|
||||
$this->assertEquals('bar', $updatedCategory->getTitle());
|
||||
$this->assertEquals('bar description', $updatedCategory->getDescription());
|
||||
$this->assertEquals('bar chapo', $updatedCategory->getChapo());
|
||||
$this->assertEquals('bar postscriptum', $updatedCategory->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedCategory->getVisible());
|
||||
$this->assertEquals($template->getId(), $updatedCategory->getDefaultTemplateId());
|
||||
$this->assertEquals(0, $updatedCategory->getParent());
|
||||
|
||||
return [ $updatedCategory, $template ];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $argArray
|
||||
* @depends testUpdate
|
||||
* @return CategoryModel
|
||||
*/
|
||||
public function testRemoveTemplate($argArray)
|
||||
{
|
||||
/** @var CategoryModel $category */
|
||||
$category = $argArray[0];
|
||||
|
||||
/** @var Template $template */
|
||||
$template = $argArray[1];
|
||||
|
||||
$event = new TemplateDeleteEvent($template->getId());
|
||||
|
||||
$action = new \Thelia\Action\Template();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Template', $event->getTemplate());
|
||||
|
||||
$theCat = CategoryQuery::create()->findPk($category->getId());
|
||||
|
||||
$this->assertNull($theCat->getDefaultTemplateId());
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CategoryModel $category
|
||||
* @depends testRemoveTemplate
|
||||
*/
|
||||
public function testDelete(CategoryModel $category)
|
||||
{
|
||||
$event = new CategoryDeleteEvent($category->getId());
|
||||
|
||||
$action = new Category();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $deletedCategory);
|
||||
$this->assertTrue($deletedCategory->isDeleted());
|
||||
}
|
||||
|
||||
public function testToggleVisibility()
|
||||
{
|
||||
$category = $this->getRandomCategory();
|
||||
$expectedVisibility = !$category->getVisible();
|
||||
|
||||
$event = new CategoryToggleVisibilityEvent($category);
|
||||
|
||||
$action = new Category();
|
||||
$action->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCategory = $event->getCategory();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Category', $updatedCategory);
|
||||
$this->assertEquals($expectedVisibility, $updatedCategory->getVisible());
|
||||
}
|
||||
}
|
||||
152
tests/phpunit/Thelia/Tests/Action/ConfigTest.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Config;
|
||||
use Thelia\Core\Event\Config\ConfigCreateEvent;
|
||||
use Thelia\Core\Event\Config\ConfigDeleteEvent;
|
||||
use Thelia\Core\Event\Config\ConfigUpdateEvent;
|
||||
use Thelia\Model\Config as ConfigModel;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ConfigTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ConfigQuery::create()
|
||||
->filterByName('foo')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ConfigCreateEvent();
|
||||
|
||||
$event
|
||||
->setEventName('foo')
|
||||
->setValue('bar')
|
||||
->setLocale('en_US')
|
||||
->setTitle('test config foo bar')
|
||||
->setHidden(true)
|
||||
->setSecured(true)
|
||||
;
|
||||
|
||||
$action = new Config();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $createdConfig);
|
||||
|
||||
$this->assertFalse($createdConfig->isNew());
|
||||
|
||||
$this->assertEquals('foo', $createdConfig->getName());
|
||||
$this->assertEquals('bar', $createdConfig->getValue());
|
||||
$this->assertEquals('en_US', $createdConfig->getLocale());
|
||||
$this->assertEquals('test config foo bar', $createdConfig->getTitle());
|
||||
$this->assertEquals(1, $createdConfig->getHidden());
|
||||
$this->assertEquals(1, $createdConfig->getSecured());
|
||||
|
||||
return $createdConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testCreate
|
||||
* @return ConfigModel
|
||||
*/
|
||||
public function testSetValue(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigUpdateEvent($config->getId());
|
||||
$event
|
||||
->setValue('baz');
|
||||
|
||||
$action = new Config();
|
||||
$action->setValue($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $updatedConfig);
|
||||
|
||||
$this->assertEquals($config->getName(), $updatedConfig->getName());
|
||||
$this->assertEquals('baz', $updatedConfig->getValue());
|
||||
$this->assertEquals($config->getLocale(), $updatedConfig->getLocale());
|
||||
$this->assertEquals($config->getTitle(), $updatedConfig->getTitle());
|
||||
$this->assertEquals($config->getHidden(), $updatedConfig->getHidden());
|
||||
$this->assertEquals($config->getSecured(), $updatedConfig->getSecured());
|
||||
|
||||
return $updatedConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testSetValue
|
||||
* @return ConfigModel
|
||||
*/
|
||||
public function testModify(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigUpdateEvent($config->getId());
|
||||
$event
|
||||
->setEventName('foo')
|
||||
->setValue('update baz')
|
||||
->setLocale('en_US')
|
||||
->setTitle('config title')
|
||||
->setDescription('config description')
|
||||
->setChapo('config chapo')
|
||||
->setPostscriptum('config postscriptum')
|
||||
->setHidden(0)
|
||||
->setSecured(0)
|
||||
;
|
||||
|
||||
$action = new Config();
|
||||
$action->modify($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $updatedConfig);
|
||||
|
||||
$this->assertEquals('foo', $updatedConfig->getName());
|
||||
$this->assertEquals('update baz', $updatedConfig->getValue());
|
||||
$this->assertEquals('en_US', $updatedConfig->getLocale());
|
||||
$this->assertEquals('config title', $updatedConfig->getTitle());
|
||||
$this->assertEquals('config description', $updatedConfig->getDescription());
|
||||
$this->assertEquals('config chapo', $updatedConfig->getChapo());
|
||||
$this->assertEquals('config postscriptum', $updatedConfig->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedConfig->getHidden());
|
||||
$this->assertEquals(0, $updatedConfig->getSecured());
|
||||
|
||||
return $updatedConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ConfigModel $config
|
||||
* @depends testModify
|
||||
*/
|
||||
public function testDelete(ConfigModel $config)
|
||||
{
|
||||
$event = new ConfigDeleteEvent($config->getId());
|
||||
|
||||
$action = new Config();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedConfig = $event->getConfig();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Config', $deletedConfig);
|
||||
$this->assertTrue($deletedConfig->isDeleted());
|
||||
}
|
||||
}
|
||||
373
tests/phpunit/Thelia/Tests/Action/ContentTest.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Propel\Runtime\Collection\Collection;
|
||||
use Thelia\Action\Content;
|
||||
use Thelia\Core\Event\Content\ContentAddFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentCreateEvent;
|
||||
use Thelia\Core\Event\Content\ContentDeleteEvent;
|
||||
use Thelia\Core\Event\Content\ContentRemoveFolderEvent;
|
||||
use Thelia\Core\Event\Content\ContentToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Content\ContentUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\ContentFolder;
|
||||
use Thelia\Model\ContentFolderQuery;
|
||||
use Thelia\Model\ContentQuery;
|
||||
use Thelia\Model\Folder;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Content as ContentModel;
|
||||
|
||||
/**
|
||||
* Class ContentTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ContentTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use I18nTestTrait;
|
||||
|
||||
protected static $folderForPositionTest = null;
|
||||
|
||||
public function getUpdateEvent(&$content)
|
||||
{
|
||||
if (!$content instanceof ContentModel) {
|
||||
$content = $this->getRandomContent();
|
||||
}
|
||||
|
||||
$event = new ContentUpdateEvent($content->getId());
|
||||
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($content->getLocale())
|
||||
->setTitle($content->getTitle())
|
||||
->setChapo($content->getChapo())
|
||||
->setDescription($content->getDescription())
|
||||
->setPostscriptum($content->getPostscriptum())
|
||||
->setDefaultFolder($content->getDefaultFolderId())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContentUpdateEvent$event
|
||||
* @return ContentModel
|
||||
* @throws \Exception
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$contentAction = new Content();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getContent();
|
||||
}
|
||||
|
||||
public function testCreateContent()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new ContentCreateEvent();
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create content')
|
||||
->setDefaultFolder($folder->getId())
|
||||
;
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $createdContent);
|
||||
$this->assertEquals(1, $createdContent->getVisible());
|
||||
$this->assertEquals('test create content', $createdContent->getTitle());
|
||||
$this->assertEquals($folder->getId(), $createdContent->getDefaultFolderId());
|
||||
}
|
||||
|
||||
public function testUpdateContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new ContentUpdateEvent($content->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update content title')
|
||||
->setChapo('test update content short description')
|
||||
->setDescription('test update content description')
|
||||
->setPostscriptum('test update content postscriptum')
|
||||
->setDefaultFolder($folder->getId())
|
||||
;
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $updatedContent);
|
||||
$this->assertEquals(1, $updatedContent->getVisible());
|
||||
$this->assertEquals('test update content title', $updatedContent->getTitle());
|
||||
$this->assertEquals('test update content short description', $updatedContent->getChapo());
|
||||
$this->assertEquals('test update content description', $updatedContent->getDescription());
|
||||
$this->assertEquals('test update content postscriptum', $updatedContent->getPostscriptum());
|
||||
$this->assertEquals($folder->getId(), $updatedContent->getDefaultFolderId());
|
||||
}
|
||||
|
||||
public function testDeleteContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
$event = new ContentDeleteEvent($content->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $deletedContent);
|
||||
$this->assertTrue($deletedContent->isDeleted());
|
||||
}
|
||||
|
||||
public function testContentToggleVisibility()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
$visibility = $content->getVisible();
|
||||
|
||||
$event = new ContentToggleVisibilityEvent($content);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = $event->getContent();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Content', $updatedContent);
|
||||
$this->assertEquals(!$visibility, $updatedContent->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(2, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$newPosition = $contentFolderQuery->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_UP,
|
||||
null,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
|
||||
$this->assertEquals($newPosition, $updatedContent->getPosition(), sprintf("new position is %d, new position expected is %d for content %d", $newPosition, $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$newPosition = $contentFolderQuery->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_DOWN,
|
||||
null,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
;
|
||||
|
||||
$this->assertEquals($newPosition, $updatedContent->getPosition(), sprintf("new position is %d, new position expected is %d for content %d", $newPosition, $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$contentFolderQuery = ContentFolderQuery::create()
|
||||
->filterByFolder($this->getFolderForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $contentFolderQuery) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent(
|
||||
$contentFolderQuery->getContentId(),
|
||||
UpdatePositionEvent::POSITION_ABSOLUTE,
|
||||
1,
|
||||
$contentFolderQuery->getFolderId()
|
||||
);
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedContent = ContentFolderQuery::create()
|
||||
->filterByFolderId($contentFolderQuery->getFolderId())
|
||||
->filterByContentId($contentFolderQuery->getContentId())
|
||||
->findOne();
|
||||
;
|
||||
|
||||
$this->assertEquals(1, $updatedContent->getPosition(), sprintf("new position is 1, new position expected is %d for content %d", $updatedContent->getPosition(), $updatedContent->getContentId()));
|
||||
}
|
||||
|
||||
public function testAddFolderToContent()
|
||||
{
|
||||
$content = $this->getRandomContent();
|
||||
|
||||
do {
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$test = ContentFolderQuery::create()
|
||||
->filterByContent($content)
|
||||
->filterByFolder($folder);
|
||||
} while ($test->count() > 0);
|
||||
|
||||
$event = new ContentAddFolderEvent($content, $folder->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->addFolder($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$testAddFolder = ContentFolderQuery::create()
|
||||
->filterByContent($content)
|
||||
->filterByFolder($folder)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$this->assertNotNull($testAddFolder);
|
||||
$this->assertEquals($content->getId(), $testAddFolder->getContentId(), 'check if content id are equals');
|
||||
$this->assertEquals($folder->getId(), $testAddFolder->getFolderId(), 'check if folder id are equals');
|
||||
|
||||
return $testAddFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContentFolder $association
|
||||
* @depends testAddFolderToContent
|
||||
*/
|
||||
public function testRemoveFolder(ContentFolder $association)
|
||||
{
|
||||
$event = new ContentRemoveFolderEvent($association->getContent(), $association->getFolder()->getId());
|
||||
|
||||
$contentAction = new Content();
|
||||
$contentAction->removeFolder($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$testAssociation = ContentFolderQuery::create()
|
||||
->filterByContent($association->getContent())
|
||||
->filterByFolder($association->getFolder())
|
||||
->findOne();
|
||||
|
||||
$this->assertNull($testAssociation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Content
|
||||
*/
|
||||
protected function getRandomContent()
|
||||
{
|
||||
$content = ContentQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $content) {
|
||||
$this->fail('use fixtures before launching test, there is no content in database');
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a folder and its contents to be used in Position tests
|
||||
*
|
||||
* @return Folder the parent folder
|
||||
*/
|
||||
protected function getFolderForPositionTest()
|
||||
{
|
||||
if (null === self::$folderForPositionTest) {
|
||||
$folder = new Folder();
|
||||
|
||||
$folder->setParent(0);
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$content = new ContentModel();
|
||||
|
||||
$content->setVisible(1);
|
||||
|
||||
$content->addFolder($folder);
|
||||
|
||||
$this->setI18n($content);
|
||||
|
||||
$content->save();
|
||||
}
|
||||
|
||||
self::$folderForPositionTest = $folder;
|
||||
}
|
||||
|
||||
return self::$folderForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
protected function getRandomFolder()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
return $folder;
|
||||
}
|
||||
}
|
||||
138
tests/phpunit/Thelia/Tests/Action/CountryTest.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Country;
|
||||
use Thelia\Core\Event\Country\CountryCreateEvent;
|
||||
use Thelia\Core\Event\Country\CountryDeleteEvent;
|
||||
use Thelia\Core\Event\Country\CountryToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Country\CountryUpdateEvent;
|
||||
use Thelia\Model\Country as CountryModel;
|
||||
use Thelia\Model\CountryQuery;
|
||||
|
||||
/**
|
||||
* Class CountryTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CountryTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CountryCreateEvent();
|
||||
|
||||
$event
|
||||
->setIsocode('001')
|
||||
->setIsoAlpha2('AA')
|
||||
->setIsoAlpha3('AAA')
|
||||
->setVisible(1)
|
||||
->setHasStates(0)
|
||||
->setLocale('en_US')
|
||||
->setTitle('Test')
|
||||
;
|
||||
|
||||
$action = new Country();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $createdCountry);
|
||||
$this->assertFalse($createdCountry->isNew());
|
||||
|
||||
$this->assertEquals('001', $createdCountry->getIsocode());
|
||||
$this->assertEquals('AA', $createdCountry->getIsoalpha2());
|
||||
$this->assertEquals('AAA', $createdCountry->getIsoalpha3());
|
||||
$this->assertEquals(1, $createdCountry->getVisible());
|
||||
$this->assertEquals(0, $createdCountry->getHasStates());
|
||||
$this->assertEquals('AAA', $createdCountry->getIsoalpha3());
|
||||
$this->assertEquals('en_US', $createdCountry->getLocale());
|
||||
$this->assertEquals('Test', $createdCountry->getTitle());
|
||||
|
||||
return $createdCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CountryModel $country
|
||||
* @depends testCreate
|
||||
* @return CountryModel
|
||||
*/
|
||||
public function testUpdate(CountryModel $country)
|
||||
{
|
||||
$event = new CountryUpdateEvent($country->getId());
|
||||
|
||||
$event
|
||||
->setIsocode('002')
|
||||
->setIsoAlpha2('BB')
|
||||
->setIsoAlpha3('BBB')
|
||||
->setVisible(1)
|
||||
->setHasStates(0)
|
||||
->setLocale('en_US')
|
||||
->setTitle('Test')
|
||||
;
|
||||
|
||||
$action = new Country();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $updatedCountry);
|
||||
|
||||
$this->assertEquals('002', $updatedCountry->getIsocode());
|
||||
$this->assertEquals('BB', $updatedCountry->getIsoalpha2());
|
||||
$this->assertEquals('BBB', $updatedCountry->getIsoalpha3());
|
||||
$this->assertEquals(1, $updatedCountry->getVisible());
|
||||
$this->assertEquals(0, $updatedCountry->getHasStates());
|
||||
$this->assertEquals('en_US', $updatedCountry->getLocale());
|
||||
$this->assertEquals('Test', $updatedCountry->getTitle());
|
||||
|
||||
return $updatedCountry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CountryModel $country
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(CountryModel $country)
|
||||
{
|
||||
$event = new CountryDeleteEvent($country->getId());
|
||||
|
||||
$action = new Country();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $deletedCountry);
|
||||
$this->assertTrue($deletedCountry->isDeleted());
|
||||
}
|
||||
|
||||
public function testToggleDefault()
|
||||
{
|
||||
/** @var CountryModel $country */
|
||||
$country = CountryQuery::create()
|
||||
->filterByByDefault(0)
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
$event = new CountryToggleDefaultEvent($country->getId());
|
||||
|
||||
$action = new Country($this->getMockEventDispatcher());
|
||||
$action->toggleDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCountry = $event->getCountry();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Country', $updatedCountry);
|
||||
$this->assertEquals(1, $updatedCountry->getByDefault());
|
||||
|
||||
$this->assertEquals(1, CountryQuery::create()->filterByByDefault(1)->count());
|
||||
}
|
||||
}
|
||||
195
tests/phpunit/Thelia/Tests/Action/CurrencyTest.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Action\Currency;
|
||||
use Thelia\Core\Event\Currency\CurrencyDeleteEvent;
|
||||
use Thelia\Core\Event\Currency\CurrencyUpdateEvent;
|
||||
use Thelia\CurrencyConverter\CurrencyConverter;
|
||||
use Thelia\CurrencyConverter\Provider\ECBProvider;
|
||||
use Thelia\Model\Currency as CurrencyModel;
|
||||
use Thelia\Core\Event\Currency\CurrencyCreateEvent;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class CurrencyTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CurrencyTest extends ContainerAwareTestCase
|
||||
{
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new CurrencyCreateEvent();
|
||||
|
||||
$event
|
||||
->setCurrencyName('test')
|
||||
->setCode('AZE')
|
||||
->setRate('1.35')
|
||||
->setLocale('en_US')
|
||||
->setSymbol('ù')
|
||||
->setFormat('%n %c')
|
||||
;
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $createdCurrency);
|
||||
$this->assertFalse($createdCurrency->isNew());
|
||||
|
||||
$this->assertEquals('test', $createdCurrency->getName());
|
||||
$this->assertEquals('AZE', $createdCurrency->getCode());
|
||||
$this->assertEquals('1.35', $createdCurrency->getRate());
|
||||
$this->assertEquals('en_US', $createdCurrency->getLocale());
|
||||
$this->assertEquals('ù', $createdCurrency->getSymbol());
|
||||
$this->assertEquals('%n %c', $createdCurrency->getFormat());
|
||||
|
||||
return $createdCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testCreate
|
||||
* @return CurrencyModel
|
||||
*/
|
||||
public function testUpdate(CurrencyModel $currency)
|
||||
{
|
||||
$event = new CurrencyUpdateEvent($currency->getId());
|
||||
|
||||
$event
|
||||
->setCurrencyName('test update')
|
||||
->setCode('AZER')
|
||||
->setRate('2.35')
|
||||
->setLocale('en_US')
|
||||
->setSymbol('ù')
|
||||
->setFormat('%n %c')
|
||||
;
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency);
|
||||
$this->assertEquals('test update', $updatedCurrency->getName());
|
||||
$this->assertEquals('AZER', $updatedCurrency->getCode());
|
||||
$this->assertEquals('2.35', $updatedCurrency->getRate());
|
||||
$this->assertEquals('en_US', $updatedCurrency->getLocale());
|
||||
$this->assertEquals('ù', $updatedCurrency->getSymbol());
|
||||
$this->assertEquals('%n %c', $updatedCurrency->getFormat());
|
||||
|
||||
return $updatedCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testUpdate
|
||||
* @return CurrencyModel
|
||||
*/
|
||||
public function testSetDefault(CurrencyModel $currency)
|
||||
{
|
||||
$event = new CurrencyUpdateEvent($currency->getId());
|
||||
$event
|
||||
->setIsDefault(1);
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->setDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $updatedCurrency);
|
||||
|
||||
$this->assertEquals(1, $updatedCurrency->getByDefault());
|
||||
$this->assertEquals(1, CurrencyQuery::create()->filterByByDefault(true)->count());
|
||||
|
||||
return $updatedCurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CurrencyModel $currency
|
||||
* @depends testSetDefault
|
||||
*/
|
||||
public function testDelete(CurrencyModel $currency)
|
||||
{
|
||||
$currency->setByDefault(0)
|
||||
->save();
|
||||
|
||||
$event = new CurrencyDeleteEvent($currency->getId());
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedCurrency = $event->getCurrency();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Currency', $deletedCurrency);
|
||||
|
||||
$this->assertTrue($deletedCurrency->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage It is not allowed to delete the default currency
|
||||
*/
|
||||
public function testDeleteDefault()
|
||||
{
|
||||
CurrencyQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->limit(1)
|
||||
->update(array('ByDefault' => true));
|
||||
|
||||
$currency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
|
||||
$event = new CurrencyDeleteEvent($currency->getId());
|
||||
|
||||
$action = new Currency($this->getCurrencyConverter());
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
CurrencyQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->limit(1)
|
||||
->update(array('ByDefault' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
// TODO: Implement buildContainer() method.
|
||||
}
|
||||
|
||||
protected function getCurrencyConverter()
|
||||
{
|
||||
$ecbProvider = new ECBProvider();
|
||||
$currencyConverter = new CurrencyConverter($ecbProvider);
|
||||
|
||||
return $currencyConverter;
|
||||
}
|
||||
}
|
||||
187
tests/phpunit/Thelia/Tests/Action/CustomerTest.php
Normal file
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Customer;
|
||||
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CustomerTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @var SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $customerAction;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
CustomerQuery::create()
|
||||
->filterByRef('testRef')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$this->request = new Request();
|
||||
$this->request->setSession($session);
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
$requestStack->push($this->request);
|
||||
|
||||
$this->securityContext = new SecurityContext($requestStack);
|
||||
|
||||
$this->customerAction = new Customer(
|
||||
$this->securityContext,
|
||||
new MailerFactory($this->getMockEventDispatcher(), $this->getMockParserInterface()),
|
||||
$requestStack
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreatedCustomer()
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
1,
|
||||
"thelia",
|
||||
"thelia",
|
||||
"street address 1",
|
||||
"street address 2",
|
||||
"street address 3",
|
||||
"0102030405",
|
||||
"0607080910",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
sprintf("%s@thelia.fr", uniqid()),
|
||||
uniqid(),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company',
|
||||
null
|
||||
);
|
||||
|
||||
/** @var Customer $customerAction */
|
||||
$customerAction = $this->customerAction;
|
||||
|
||||
$customerAction->create($customerCreateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$customerCreated = $customerCreateEvent->getCustomer();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
|
||||
$this->assertFalse($customerCreated->isNew());
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $addressCreated);
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
|
||||
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
|
||||
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
|
||||
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
|
||||
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
|
||||
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
|
||||
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
|
||||
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
|
||||
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
|
||||
}
|
||||
|
||||
public function testCreatedCustomerWithSpecifiedRef()
|
||||
{
|
||||
$customerCreateEvent = new CustomerCreateOrUpdateEvent(
|
||||
1,
|
||||
"thelia",
|
||||
"thelia",
|
||||
"street address 1",
|
||||
"street address 2",
|
||||
"street address 3",
|
||||
"0102030405",
|
||||
"0607080910",
|
||||
"63000",
|
||||
"clermont-ferrand",
|
||||
64,
|
||||
sprintf("%s@thelia.fr", uniqid()),
|
||||
uniqid(),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
'My super company',
|
||||
'testRef'
|
||||
);
|
||||
|
||||
/** @var Customer $customerAction */
|
||||
$customerAction = $this->customerAction;
|
||||
|
||||
$customerAction->create($customerCreateEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$customerCreated = $customerCreateEvent->getCustomer();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Customer", $customerCreated, "new customer created must be an instance of Thelia\Model\Customer");
|
||||
$this->assertFalse($customerCreated->isNew());
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $customerCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $customerCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $customerCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getEmail(), $customerCreated->getEmail());
|
||||
$this->assertEquals($customerCreateEvent->getReseller(), $customerCreated->getReseller());
|
||||
$this->assertEquals($customerCreateEvent->getSponsor(), $customerCreated->getSponsor());
|
||||
$this->assertEquals($customerCreateEvent->getDiscount(), $customerCreated->getDiscount());
|
||||
$this->assertEquals($customerCreateEvent->getRef(), $customerCreated->getRef());
|
||||
|
||||
$addressCreated = $customerCreated->getDefaultAddress();
|
||||
|
||||
$this->assertInstanceOf("Thelia\Model\Address", $addressCreated);
|
||||
|
||||
$this->assertEquals($customerCreateEvent->getFirstname(), $addressCreated->getFirstname());
|
||||
$this->assertEquals($customerCreateEvent->getLastname(), $addressCreated->getLastname());
|
||||
$this->assertEquals($customerCreateEvent->getTitle(), $addressCreated->getTitleId());
|
||||
$this->assertEquals($customerCreateEvent->getAddress1(), $addressCreated->getAddress1());
|
||||
$this->assertEquals($customerCreateEvent->getAddress2(), $addressCreated->getAddress2());
|
||||
$this->assertEquals($customerCreateEvent->getAddress3(), $addressCreated->getAddress3());
|
||||
$this->assertEquals($customerCreateEvent->getZipcode(), $addressCreated->getZipcode());
|
||||
$this->assertEquals($customerCreateEvent->getCity(), $addressCreated->getCity());
|
||||
$this->assertEquals($customerCreateEvent->getCountry(), $addressCreated->getCountryId());
|
||||
$this->assertEquals($customerCreateEvent->getPhone(), $addressCreated->getPhone());
|
||||
$this->assertEquals($customerCreateEvent->getCellphone(), $addressCreated->getCellphone());
|
||||
$this->assertEquals($customerCreateEvent->getCompany(), $addressCreated->getCompany());
|
||||
}
|
||||
}
|
||||
280
tests/phpunit/Thelia/Tests/Action/DocumentTest.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Document;
|
||||
use Thelia\Core\Event\Document\DocumentEvent;
|
||||
use Thelia\Files\FileManager;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class DocumentTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\DocumentTest
|
||||
*/
|
||||
class DocumentTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $cache_dir_from_web_root;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $session;
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$dispatcher = $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
$container->set("thelia.file_manager", $this->getFileManager());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getFileManager()
|
||||
{
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
return $fileManager;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
$this->request = new Request();
|
||||
|
||||
$this->request->setSession($this->session);
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('document_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$this->cache_dir_from_web_root = $config->getValue();
|
||||
|
||||
$config->setValue(__DIR__ . "/assets/documents/cache");
|
||||
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$dir = THELIA_WEB_DIR . "/cache/tests";
|
||||
if ($dh = @opendir($dir)) {
|
||||
while ($file = readdir($dh)) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink(sprintf("%s/%s", $dir, $file));
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// restore cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('document_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Documentevent is empty, mandatory parameters not specified.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessEmptyDocumentEvent()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a non-existent file
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessNonExistentDocument()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a file outside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessDocumentOutsideValidPath()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.pdf");
|
||||
$event->setCacheSubdirectory("../../../");
|
||||
|
||||
$document->processDocument($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessDocumentCopy()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/documents/sources/test-document-1.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName(Document::CONFIG_DELIVERY_MODE)->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('copy')->save();
|
||||
}
|
||||
|
||||
$document->processDocument($event);
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('document_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-document-1.txt");
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> link !
|
||||
*/
|
||||
public function testProcessDocumentSymlink()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/documents/sources/test-document-2.txt");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName(Document::CONFIG_DELIVERY_MODE)->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('symlink')->save();
|
||||
}
|
||||
|
||||
$document->processDocument($event);
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('document_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-document-2.txt");
|
||||
}
|
||||
|
||||
public function testClearTestsCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('tests');
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
|
||||
public function testClearWholeCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to clear directory ouside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testClearUnallowedPathCache()
|
||||
{
|
||||
$event = new DocumentEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('../../../..');
|
||||
|
||||
$document = new Document($this->getFileManager());
|
||||
|
||||
$document->clearCache($event);
|
||||
}
|
||||
}
|
||||
119
tests/phpunit/Thelia/Tests/Action/FeatureAvTest.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\FeatureAv;
|
||||
use Thelia\Core\Event\Feature\FeatureAvCreateEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureAvUpdateEvent;
|
||||
use Thelia\Model\FeatureAv as FeatureAvModel;
|
||||
use Thelia\Model\FeatureQuery;
|
||||
|
||||
/**
|
||||
* Class FeatureAvTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FeatureAvTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @return \Thelia\Model\Feature
|
||||
*/
|
||||
protected function getRandomFeature()
|
||||
{
|
||||
$feature = FeatureQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $feature) {
|
||||
$this->fail('use fixtures before launching test, there is no feature in database');
|
||||
}
|
||||
|
||||
return $feature;
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$feature = $this->getRandomFeature();
|
||||
|
||||
$event = new FeatureAvCreateEvent();
|
||||
$event
|
||||
->setFeatureId($feature->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('test');
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $createdFeatureAv);
|
||||
|
||||
$this->assertFalse($createdFeatureAv->isNew());
|
||||
|
||||
$this->assertEquals('en_US', $createdFeatureAv->getLocale());
|
||||
$this->assertEquals('test', $createdFeatureAv->getTitle());
|
||||
$this->assertEquals($feature->getId(), $createdFeatureAv->getFeatureId());
|
||||
|
||||
return $createdFeatureAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureAvModel $featureAv
|
||||
* @depends testCreate
|
||||
* @return FeatureAvModel
|
||||
*/
|
||||
public function testUpdate(FeatureAvModel $featureAv)
|
||||
{
|
||||
$event = new FeatureAvUpdateEvent($featureAv->getId());
|
||||
$event
|
||||
->setLocale('en_uS')
|
||||
->setTitle('test update')
|
||||
->setDescription('test description')
|
||||
->setChapo('test chapo')
|
||||
->setPostscriptum('test postscriptum');
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $updatedFeatureAv);
|
||||
|
||||
$this->assertEquals('en_US', $updatedFeatureAv->getLocale());
|
||||
$this->assertEquals('test update', $updatedFeatureAv->getTitle());
|
||||
$this->assertEquals('test chapo', $updatedFeatureAv->getChapo());
|
||||
$this->assertEquals('test description', $updatedFeatureAv->getDescription());
|
||||
$this->assertEquals('test postscriptum', $updatedFeatureAv->getPostscriptum());
|
||||
|
||||
return $updatedFeatureAv;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureAvModel $featureAv
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(FeatureAvModel $featureAv)
|
||||
{
|
||||
$event = new FeatureAvDeleteEvent($featureAv->getId());
|
||||
|
||||
$action = new FeatureAv();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFeatureAv = $event->getFeatureAv();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\FeatureAv', $deletedFeatureAv);
|
||||
|
||||
$this->assertTrue($deletedFeatureAv->isDeleted());
|
||||
}
|
||||
}
|
||||
99
tests/phpunit/Thelia/Tests/Action/FeatureTest.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Feature;
|
||||
use Thelia\Core\Event\Feature\FeatureDeleteEvent;
|
||||
use Thelia\Core\Event\Feature\FeatureUpdateEvent;
|
||||
use Thelia\Model\Feature as FeatureModel;
|
||||
use Thelia\Core\Event\Feature\FeatureCreateEvent;
|
||||
|
||||
/**
|
||||
* Class FeatureTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FeatureTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new FeatureCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test feature');
|
||||
|
||||
$action = new Feature();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $createdFeature);
|
||||
|
||||
$this->assertFalse($createdFeature->isNew());
|
||||
|
||||
$this->assertEquals("en_US", $createdFeature->getLocale());
|
||||
$this->assertEquals("test feature", $createdFeature->getTitle());
|
||||
|
||||
return $createdFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureModel $feature
|
||||
* @depends testCreate
|
||||
* @return FeatureModel
|
||||
*/
|
||||
public function testUpdate(FeatureModel $feature)
|
||||
{
|
||||
$event = new FeatureUpdateEvent($feature->getId());
|
||||
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update')
|
||||
->setChapo('test chapo')
|
||||
->setDescription('test description')
|
||||
->setPostscriptum('test postscriptum');
|
||||
|
||||
$action = new Feature();
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $updatedFeature);
|
||||
|
||||
$this->assertEquals('test update', $updatedFeature->getTitle());
|
||||
$this->assertEquals('test chapo', $updatedFeature->getChapo());
|
||||
$this->assertEquals('test description', $updatedFeature->getDescription());
|
||||
$this->assertEquals('test postscriptum', $updatedFeature->getPostscriptum());
|
||||
$this->assertEquals('en_US', $updatedFeature->getLocale());
|
||||
|
||||
return $updatedFeature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FeatureModel $feature
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(FeatureModel $feature)
|
||||
{
|
||||
$event = new FeatureDeleteEvent($feature->getId());
|
||||
|
||||
$action = new Feature();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFeature = $event->getFeature();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Feature', $deletedFeature);
|
||||
|
||||
$this->assertTrue($deletedFeature->isDeleted());
|
||||
}
|
||||
}
|
||||
319
tests/phpunit/Thelia/Tests/Action/FolderTest.php
Normal file
@@ -0,0 +1,319 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Action\Folder;
|
||||
use Thelia\Core\Event\Folder\FolderCreateEvent;
|
||||
use Thelia\Core\Event\Folder\FolderDeleteEvent;
|
||||
use Thelia\Core\Event\Folder\FolderToggleVisibilityEvent;
|
||||
use Thelia\Core\Event\Folder\FolderUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Core\Event\UpdateSeoEvent;
|
||||
use Thelia\Model\FolderQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Folder as FolderModel;
|
||||
|
||||
/**
|
||||
* Class FolderTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class FolderTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
use RewrittenUrlTestTrait;
|
||||
use I18nTestTrait;
|
||||
|
||||
/** @var int folder id used in position tests */
|
||||
protected static $folderIdForPositionTest = null;
|
||||
|
||||
public function getUpdateEvent(&$folder)
|
||||
{
|
||||
if (!$folder instanceof FolderModel) {
|
||||
$folder = $this->getRandomFolder();
|
||||
}
|
||||
|
||||
$event = new FolderUpdateEvent($folder->getId());
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setLocale($folder->getLocale())
|
||||
->setTitle($folder->getTitle())
|
||||
->setChapo($folder->getChapo())
|
||||
->setDescription($folder->getDescription())
|
||||
->setPostscriptum($folder->getPostscriptum())
|
||||
->setParent($folder->getParent())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function getUpdateSeoEvent(&$folder)
|
||||
{
|
||||
if (!$folder instanceof FolderModel) {
|
||||
$folder = $this->getRandomFolder();
|
||||
}
|
||||
|
||||
$event = new UpdateSeoEvent($folder->getId());
|
||||
$event
|
||||
->setLocale($folder->getLocale())
|
||||
->setMetaTitle($folder->getMetaTitle())
|
||||
->setMetaDescription($folder->getMetaDescription())
|
||||
->setMetaKeywords($folder->getMetaKeywords());
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public function processUpdateSeoAction($event)
|
||||
{
|
||||
$contentAction = new Folder();
|
||||
|
||||
return $contentAction->updateSeo($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FolderUpdateEvent $event
|
||||
* @return FolderModel
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$contentAction = new Folder();
|
||||
$contentAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getFolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder creation
|
||||
* @covers Thelia\Action\Folder::create
|
||||
*/
|
||||
public function testCreateFolder()
|
||||
{
|
||||
$event = new FolderCreateEvent();
|
||||
$event
|
||||
->setParent(0)
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('folder creation test');
|
||||
|
||||
$folderAction = new Folder();
|
||||
|
||||
$folderAction->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$folder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $folder);
|
||||
$this->assertEquals('folder creation test', $folder->getTitle());
|
||||
$this->assertEquals(1, $folder->getVisible());
|
||||
$this->assertEquals(0, $folder->getParent());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\Folder::update
|
||||
*/
|
||||
public function testUpdateFolder()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$visible = !$folder->getVisible();
|
||||
$event = new FolderUpdateEvent($folder->getId());
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update folder')
|
||||
->setVisible($visible)
|
||||
->setChapo('test folder update chapo')
|
||||
->setDescription('update folder description')
|
||||
->setPostscriptum('update folder postscriptum')
|
||||
->setParent(0)
|
||||
;
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $updatedFolder);
|
||||
$this->assertEquals('test update folder', $updatedFolder->getTitle());
|
||||
$this->assertEquals('test folder update chapo', $updatedFolder->getChapo());
|
||||
$this->assertEquals('update folder description', $updatedFolder->getDescription());
|
||||
$this->assertEquals('update folder postscriptum', $updatedFolder->getPostscriptum());
|
||||
$this->assertEquals(0, $updatedFolder->getParent());
|
||||
$this->assertEquals($visible, $updatedFolder->getVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder removal
|
||||
* @covers Thelia\Action\Folder::delete
|
||||
*/
|
||||
public function testDeleteFolder()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
|
||||
$event = new FolderDeleteEvent($folder->getId());
|
||||
$folderAction = new Folder();
|
||||
$folderAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $deletedFolder);
|
||||
$this->assertTrue($deletedFolder->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* test folder toggle visibility
|
||||
* @covers Thelia\Action\Folder::toggleVisibility
|
||||
*/
|
||||
public function testToggleVisibility()
|
||||
{
|
||||
$folder = $this->getRandomFolder();
|
||||
$visible = $folder->getVisible();
|
||||
|
||||
$event = new FolderToggleVisibilityEvent($folder);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->toggleVisibility($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = $event->getFolder();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Folder', $updatedFolder);
|
||||
$this->assertEquals(!$visible, $updatedFolder->getVisible());
|
||||
}
|
||||
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $folder->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedFolder->getPosition(), sprintf("new position is %d, new position expected is %d for folder %d", $newPosition, $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionDown()
|
||||
{
|
||||
$nextFolder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(2)
|
||||
->findOne();
|
||||
|
||||
if (null === $nextFolder) {
|
||||
$this->fail('use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$folder = FolderQuery::create()
|
||||
->filterByPosition(1)
|
||||
->filterByParent($nextFolder->getParent())
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $folder->getPosition()+1;
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_DOWN);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $updatedFolder->getPosition(), sprintf("new position is %d, new position expected is %d for folder %d", $newPosition, $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
public function testUpdatePositionWithSpecificPosition()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->filterByParent($this->getFolderIdForPositionTest())
|
||||
->filterByPosition(1, Criteria::GREATER_THAN)
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
$event = new UpdatePositionEvent($folder->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, 1);
|
||||
|
||||
$folderAction = new Folder();
|
||||
$folderAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedFolder = FolderQuery::create()->findPk($folder->getId());
|
||||
|
||||
$this->assertEquals(1, $updatedFolder->getPosition(), sprintf("new position is 1, new position expected is %d for folder %d", $updatedFolder->getPosition(), $updatedFolder->getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* generates a folder and its sub folders to be used in Position tests
|
||||
*
|
||||
* @return int the parent folder id
|
||||
*/
|
||||
protected function getFolderIdForPositionTest()
|
||||
{
|
||||
if (null === self::$folderIdForPositionTest) {
|
||||
$folder = new FolderModel();
|
||||
|
||||
$folder->setParent(0);
|
||||
$folder->setVisible(1);
|
||||
$folder->setPosition(1);
|
||||
|
||||
$this->setI18n($folder);
|
||||
|
||||
$folder->save();
|
||||
|
||||
for ($i = 0; $i < 4; $i++) {
|
||||
$subFolder = new FolderModel();
|
||||
|
||||
$subFolder->setParent($folder->getId());
|
||||
$subFolder->setVisible(1);
|
||||
$subFolder->setPosition($i + 1);
|
||||
|
||||
$this->setI18n($subFolder);
|
||||
|
||||
$subFolder->save();
|
||||
}
|
||||
|
||||
self::$folderIdForPositionTest = $folder->getId();
|
||||
}
|
||||
|
||||
return self::$folderIdForPositionTest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Folder
|
||||
*/
|
||||
protected function getRandomFolder()
|
||||
{
|
||||
$folder = FolderQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $folder) {
|
||||
$this->fail('use fixtures before launching test, there is no folder in database');
|
||||
}
|
||||
|
||||
return $folder;
|
||||
}
|
||||
}
|
||||
224
tests/phpunit/Thelia/Tests/Action/HookTest.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Hook;
|
||||
use Thelia\Core\Event\Hook\HookCreateAllEvent;
|
||||
use Thelia\Core\Event\Hook\HookDeactivationEvent;
|
||||
use Thelia\Core\Event\Hook\HookDeleteEvent;
|
||||
use Thelia\Core\Event\Hook\HookToggleActivationEvent;
|
||||
use Thelia\Core\Event\Hook\HookUpdateEvent;
|
||||
use Thelia\Model\Hook as HookModel;
|
||||
use Thelia\Core\Event\Hook\HookCreateEvent;
|
||||
use Thelia\Core\Template\TemplateDefinition;
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class HookTest extends BaseAction
|
||||
{
|
||||
/** @var Hook $action */
|
||||
protected $action;
|
||||
|
||||
protected $locale;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->locale = LangQuery::create()->findOne()->getLocale();
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->action = new Hook($stubContainer, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new HookCreateEvent();
|
||||
$event
|
||||
->setCode('test.hook-' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test");
|
||||
|
||||
$this->action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\Hook', $createdHook);
|
||||
$this->assertFalse($createdHook->isNew());
|
||||
$this->assertTrue($event->hasHook());
|
||||
|
||||
$this->assertEquals($event->getCode(), $createdHook->getCode());
|
||||
$this->assertEquals($event->getType(), $createdHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $createdHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $createdHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $createdHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $createdHook->getTitle());
|
||||
|
||||
return $createdHook;
|
||||
}
|
||||
|
||||
public function createAll(HookCreateAllEvent $event)
|
||||
{
|
||||
$event = new HookCreateAllEvent();
|
||||
$event
|
||||
->setCode('test.hook-' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test")
|
||||
->setDescription("Hook Description")
|
||||
->setChapo("Hook Chapo")
|
||||
->setBlock(false)
|
||||
->setByModule(false);
|
||||
|
||||
$this->action->createAll($event);
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\Hook', $createdHook);
|
||||
$this->assertFalse($createdHook->isNew());
|
||||
$this->assertTrue($event->hasHook());
|
||||
|
||||
$this->assertEquals($event->getCode(), $createdHook->getCode());
|
||||
$this->assertEquals($event->getType(), $createdHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $createdHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $createdHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $createdHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $createdHook->getTitle());
|
||||
$this->assertEquals($event->getDescription(), $createdHook->getDescription());
|
||||
$this->assertEquals($event->getChapo(), $createdHook->getChapo());
|
||||
$this->assertEquals($event->getBlock(), $createdHook->getBlock());
|
||||
$this->assertEquals($event->getByModule(), $createdHook->getByModule());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testCreate
|
||||
* @expectedException \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function testCreateDuplicate(HookModel $hook)
|
||||
{
|
||||
$event = new HookCreateEvent();
|
||||
$event
|
||||
->setCode($hook->getCode())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(true)
|
||||
->setNative(true)
|
||||
->setTitle("Hook Test");
|
||||
|
||||
$this->action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdHook = $event->getHook();
|
||||
|
||||
$this->assertNull($createdHook);
|
||||
$this->assertFalse($event->hasHook());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testCreate
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testDeactivation(HookModel $hook)
|
||||
{
|
||||
$event = new HookDeactivationEvent($hook->getId());
|
||||
|
||||
$this->action->deactivation($event);
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertFalse($updatedHook->getActivate());
|
||||
|
||||
return $hook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testDeactivation
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testToggleActivation(HookModel $hook)
|
||||
{
|
||||
$event = new HookToggleActivationEvent($hook->getId());
|
||||
|
||||
$this->action->toggleActivation($event, null, $this->getMockEventDispatcher());
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertTrue($updatedHook->getActivate());
|
||||
|
||||
return $hook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testToggleActivation
|
||||
* @return HookModel
|
||||
*/
|
||||
public function testUpdate(HookModel $hook)
|
||||
{
|
||||
$event = new HookUpdateEvent($hook->getId());
|
||||
|
||||
$event
|
||||
->setCode('test.hook.' . uniqid())
|
||||
->setType(TemplateDefinition::FRONT_OFFICE)
|
||||
->setLocale($this->locale)
|
||||
->setActive(false)
|
||||
->setNative(false)
|
||||
->setTitle("Updated Hook Test")
|
||||
->setDescription("Updated Hook Description")
|
||||
->setChapo("Updated Hook Chapo")
|
||||
->setBlock(false)
|
||||
->setByModule(false);
|
||||
|
||||
$this->action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedHook = $event->getHook();
|
||||
|
||||
$this->assertEquals($event->getCode(), $updatedHook->getCode());
|
||||
$this->assertEquals($event->getType(), $updatedHook->getType());
|
||||
$this->assertEquals($event->getLocale(), $updatedHook->getLocale());
|
||||
$this->assertEquals($event->getActive(), $updatedHook->getActivate());
|
||||
$this->assertEquals($event->getNative(), $updatedHook->getNative());
|
||||
$this->assertEquals($event->getTitle(), $updatedHook->getTitle());
|
||||
$this->assertEquals($event->getDescription(), $updatedHook->getDescription());
|
||||
$this->assertEquals($event->getChapo(), $updatedHook->getChapo());
|
||||
$this->assertEquals($event->getBlock(), $updatedHook->getBlock());
|
||||
$this->assertEquals($event->getByModule(), $updatedHook->getByModule());
|
||||
|
||||
return $updatedHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param HookModel $hook
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(HookModel $hook)
|
||||
{
|
||||
$event = new HookDeleteEvent($hook->getId());
|
||||
|
||||
$this->action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedHook = $event->getHook();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Hook', $deletedHook);
|
||||
$this->assertTrue($deletedHook->isDeleted());
|
||||
}
|
||||
}
|
||||
53
tests/phpunit/Thelia/Tests/Action/I18nTestTrait.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Model\LangQuery;
|
||||
|
||||
/**
|
||||
* Class I18NTestTrait
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
trait I18nTestTrait
|
||||
{
|
||||
/** @var array list of available locale */
|
||||
protected static $localeList = null;
|
||||
|
||||
/**
|
||||
* populate a list of field for each locale for an object
|
||||
*
|
||||
* @param mixed $object the object to populate
|
||||
* @param array $fields list of field to populate
|
||||
* @param array $localeList list of locale to use populate the object
|
||||
*/
|
||||
protected function setI18n(&$object, $fields = array("Title"), $localeList = null)
|
||||
{
|
||||
if (null === $localeList) {
|
||||
if (null === self::$localeList) {
|
||||
self::$localeList = LangQuery::create()
|
||||
->select("Locale")
|
||||
->find()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$localeList = self::$localeList;
|
||||
}
|
||||
|
||||
foreach ($localeList as $locale) {
|
||||
foreach ($fields as $name) {
|
||||
$object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
396
tests/phpunit/Thelia/Tests/Action/ImageTest.php
Executable file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Action\Image;
|
||||
use Thelia\Core\Event\Image\ImageEvent;
|
||||
use Thelia\Files\FileManager;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
|
||||
/**
|
||||
* Class ImageTest
|
||||
*
|
||||
* @package Thelia\Tests\Action\ImageTest
|
||||
*/
|
||||
class ImageTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
protected $cache_dir_from_web_root;
|
||||
|
||||
protected $request;
|
||||
|
||||
protected $session;
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->set("event_dispatcher", $this->getDispatcher());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->session);
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getFileManager()
|
||||
{
|
||||
$fileManager = new FileManager([
|
||||
"document.product" => "Thelia\\Model\\ProductDocument",
|
||||
"image.product" => "Thelia\\Model\\ProductImage",
|
||||
"document.category" => "Thelia\\Model\\CategoryDocument",
|
||||
"image.category" => "Thelia\\Model\\CategoryImage",
|
||||
"document.content" => "Thelia\\Model\\ContentDocument",
|
||||
"image.content" => "Thelia\\Model\\ContentImage",
|
||||
"document.folder" => "Thelia\\Model\\FolderDocument",
|
||||
"image.folder" => "Thelia\\Model\\FolderImage",
|
||||
"document.brand" => "Thelia\\Model\\BrandDocument",
|
||||
"image.brand" => "Thelia\\Model\\BrandImage",
|
||||
]);
|
||||
|
||||
return $fileManager;
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->session = new Session(new MockArraySessionStorage());
|
||||
$this->request = new Request();
|
||||
|
||||
$this->request->setSession($this->session);
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$this->cache_dir_from_web_root = $config->getValue();
|
||||
|
||||
$config->setValue(__DIR__ . "/assets/images/cache");
|
||||
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$dir = THELIA_WEB_DIR . "/cache/tests";
|
||||
if ($dh = @opendir($dir)) {
|
||||
while ($file = readdir($dh)) {
|
||||
if ($file == '.' || $file == '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
unlink(sprintf("%s/%s", $dir, $file));
|
||||
}
|
||||
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// restore cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('image_cache_dir_from_web_root')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($this->cache_dir_from_web_root)->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Imageevent is empty, mandatory parameters not specified.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessEmptyImageEvent()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a non-existent file
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessNonExistentImage()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Try to process a file outside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testProcessImageOutsideValidPath()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$event->setCacheFilepath("blablabla.png");
|
||||
$event->setCacheSubdirectory("../../../");
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessImageWithoutAnyTransformationsCopy()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-1.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('copy')->save();
|
||||
}
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-image-1.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* No operation done on source file -> copie !
|
||||
*/
|
||||
public function testProcessImageWithoutAnyTransformationsSymlink()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-9.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
// mock cache configuration.
|
||||
$config = ConfigQuery::create()->filterByName('original_image_delivery_mode')->findOne();
|
||||
|
||||
if ($config != null) {
|
||||
$oldval = $config->getValue();
|
||||
$config->setValue('symlink')->save();
|
||||
}
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
if ($config != null) {
|
||||
$config->setValue($oldval)->save();
|
||||
}
|
||||
|
||||
$imgdir = ConfigQuery::read('image_cache_dir_from_web_root');
|
||||
|
||||
$this->assertFileExists(THELIA_WEB_DIR . "/$imgdir/tests/test-image-9.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with bands width > height
|
||||
*/
|
||||
public function testProcessImageResizeHorizWithBands()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-2.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with bands height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertWithBands()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-3.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_BORDERS);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply all transformations
|
||||
*/
|
||||
public function testProcessImageWithTransformations()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-4.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setEffects(array("grayscale", "vertical_flip", "horizontal_flip", 'colorize:#00ff00', 'gamma: 0.2'));
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop width > height
|
||||
*/
|
||||
public function testProcessImageResizeHorizWithCrop()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-5.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(180);
|
||||
$event->setHeight(100);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertWithCrop()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-6.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setBackgroundColor('#ff0000');
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(150);
|
||||
$event->setResizeMode(Image::EXACT_RATIO_WITH_CROP);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image keeping image ration
|
||||
*/
|
||||
public function testProcessImageResizeHorizKeepRatio()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-7.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resize image with crop height > width
|
||||
*/
|
||||
public function testProcessImageResizeVertKeepRatio()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-8.png");
|
||||
$event->setCacheSubdirectory("tests");
|
||||
|
||||
$event->setWidth(100);
|
||||
$event->setHeight(100);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->processImage($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public function testClearTestsCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('tests');
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
|
||||
public function testClearWholeCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to clear directory ouside of the cache
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testClearUnallowedPathCache()
|
||||
{
|
||||
$event = new ImageEvent($this->request);
|
||||
|
||||
$event->setCacheSubdirectory('../../../..');
|
||||
|
||||
$image = new Image($this->getFileManager());
|
||||
|
||||
$image->clearCache($event);
|
||||
}
|
||||
}
|
||||
231
tests/phpunit/Thelia/Tests/Action/LangTest.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Lang;
|
||||
use Thelia\Core\Event\Lang\LangDeleteEvent;
|
||||
use Thelia\Core\Event\Lang\LangToggleDefaultEvent;
|
||||
use Thelia\Core\Event\Lang\LangUpdateEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Template\TheliaTemplateHelper;
|
||||
use Thelia\Model\LangQuery;
|
||||
use Thelia\Model\Lang as LangModel;
|
||||
use Thelia\Core\Event\Lang\LangCreateEvent;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class LangTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class LangTest extends ContainerAwareTestCase
|
||||
{
|
||||
protected static $defaultId;
|
||||
|
||||
protected $requestStack;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$lang = LangQuery::create()
|
||||
->filterByByDefault(1)
|
||||
->findOne();
|
||||
|
||||
self::$defaultId = $lang->getId();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
$this->requestStack = new RequestStack();
|
||||
$this->requestStack->push($request);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new LangCreateEvent();
|
||||
|
||||
$event
|
||||
->setLocale('te_TE')
|
||||
->setTitle('test')
|
||||
->setCode('TES')
|
||||
->setDateFormat('Y-m-d')
|
||||
->setTimeFormat('H:i:s')
|
||||
->setDecimalSeparator(".")
|
||||
->setThousandsSeparator(" ")
|
||||
->setDecimals("2")
|
||||
;
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $createdLang);
|
||||
|
||||
$this->assertFalse($createdLang->isNew());
|
||||
|
||||
$this->assertEquals('te_TE', $createdLang->getLocale());
|
||||
$this->assertEquals('test', $createdLang->getTitle());
|
||||
$this->assertEquals('TES', $createdLang->getCode());
|
||||
$this->assertEquals('Y-m-d H:i:s', $createdLang->getDatetimeFormat());
|
||||
$this->assertEquals('Y-m-d', $createdLang->getDateFormat());
|
||||
$this->assertEquals('H:i:s', $createdLang->getTimeFormat());
|
||||
$this->assertEquals('.', $createdLang->getDecimalSeparator());
|
||||
$this->assertEquals(' ', $createdLang->getThousandsSeparator());
|
||||
$this->assertEquals('2', $createdLang->getDecimals());
|
||||
|
||||
return $createdLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testCreate
|
||||
* @return LangModel
|
||||
*/
|
||||
public function testUpdate(LangModel $lang)
|
||||
{
|
||||
$event = new LangUpdateEvent($lang->getId());
|
||||
|
||||
$event
|
||||
->setLocale('te_TE')
|
||||
->setTitle('test update')
|
||||
->setCode('TEST')
|
||||
->setDateFormat('d-m-Y')
|
||||
->setTimeFormat('H-i-s')
|
||||
->setDecimalSeparator(",")
|
||||
->setThousandsSeparator(".")
|
||||
->setDecimals("1")
|
||||
;
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
|
||||
$this->assertEquals('te_TE', $updatedLang->getLocale());
|
||||
$this->assertEquals('TEST', $updatedLang->getCode());
|
||||
$this->assertEquals('test update', $updatedLang->getTitle());
|
||||
$this->assertEquals('d-m-Y', $updatedLang->getDateFormat());
|
||||
$this->assertEquals('H-i-s', $updatedLang->getTimeFormat());
|
||||
$this->assertEquals(',', $updatedLang->getDecimalSeparator());
|
||||
$this->assertEquals('.', $updatedLang->getThousandsSeparator());
|
||||
$this->assertEquals('1', $updatedLang->getDecimals());
|
||||
$this->assertEquals('d-m-Y H-i-s', $updatedLang->getDatetimeFormat());
|
||||
|
||||
// set a specific date/time format
|
||||
$event->setDateTimeFormat('d/m/Y H:i:s');
|
||||
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
$this->assertEquals('d/m/Y H:i:s', $updatedLang->getDatetimeFormat());
|
||||
|
||||
return $updatedLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testUpdate
|
||||
* @return LangModel
|
||||
*/
|
||||
public function testToggleDefault(LangModel $lang)
|
||||
{
|
||||
$event = new LangToggleDefaultEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->toggleDefault($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $updatedLang);
|
||||
|
||||
$this->assertEquals('1', $updatedLang->getByDefault());
|
||||
|
||||
$this->assertEquals('1', LangQuery::create()->filterByByDefault(1)->count());
|
||||
|
||||
return $updatedLang;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LangModel $lang
|
||||
* @depends testToggleDefault
|
||||
*/
|
||||
public function testDelete(LangModel $lang)
|
||||
{
|
||||
$lang->setByDefault(0)
|
||||
->save();
|
||||
|
||||
self::tearDownAfterClass();
|
||||
|
||||
$event = new LangDeleteEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedLang = $event->getLang();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Lang', $deletedLang);
|
||||
|
||||
$this->assertTrue($deletedLang->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage It is not allowed to delete the default language
|
||||
*/
|
||||
public function testDeleteDefault()
|
||||
{
|
||||
$lang = LangQuery::create()->findOneByByDefault(1);
|
||||
|
||||
$event = new LangDeleteEvent($lang->getId());
|
||||
|
||||
$action = new Lang(new TheliaTemplateHelper(), $this->requestStack);
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
LangQuery::create()
|
||||
->filterById(self::$defaultId)
|
||||
->update(array('ByDefault' => true));
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
@unlink(THELIA_TEMPLATE_DIR . "backOffice/default/assets/img/flags/TEST.png");
|
||||
@unlink(THELIA_TEMPLATE_DIR . "backOffice/default/assets/img/flags/TES.png");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
// TODO: Implement buildContainer() method.
|
||||
}
|
||||
}
|
||||
121
tests/phpunit/Thelia/Tests/Action/MessageTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Message;
|
||||
use Thelia\Core\Event\Message\MessageDeleteEvent;
|
||||
use Thelia\Core\Event\Message\MessageUpdateEvent;
|
||||
use Thelia\Model\Message as MessageModel;
|
||||
use Thelia\Core\Event\Message\MessageCreateEvent;
|
||||
use Thelia\Model\MessageQuery;
|
||||
|
||||
/**
|
||||
* Class MessageTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class MessageTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$lang = MessageQuery::create()
|
||||
->filterByName('test')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new MessageCreateEvent();
|
||||
$event
|
||||
->setMessageName('test')
|
||||
->setLocale('en_US')
|
||||
->setTitle('test title')
|
||||
->setSecured(0)
|
||||
;
|
||||
|
||||
$action = new Message();
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $createdMessage);
|
||||
$this->assertFalse($createdMessage->isNew());
|
||||
|
||||
$this->assertEquals('test', $createdMessage->getName());
|
||||
$this->assertEquals('en_US', $createdMessage->getLocale());
|
||||
$this->assertEquals('test title', $createdMessage->getTitle());
|
||||
$this->assertEquals(0, $createdMessage->getSecured());
|
||||
|
||||
return $createdMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageModel $message
|
||||
* @depends testCreate
|
||||
* @return MessageModel
|
||||
*/
|
||||
public function testModify(MessageModel $message)
|
||||
{
|
||||
$event = new MessageUpdateEvent($message->getId());
|
||||
|
||||
$event
|
||||
->setMessageName('test')
|
||||
->setLocale('en_us')
|
||||
->setTitle('test update title')
|
||||
->setSubject('test subject')
|
||||
->setHtmlMessage('my html message')
|
||||
->setTextMessage('my text message')
|
||||
->setHtmlLayoutFileName(null)
|
||||
->setHtmlTemplateFileName(null)
|
||||
->setTextLayoutFileName(null)
|
||||
->setTextTemplateFileName(null)
|
||||
;
|
||||
|
||||
$action = new Message();
|
||||
$action->modify($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $updatedMessage);
|
||||
|
||||
$this->assertEquals('test', $updatedMessage->getName());
|
||||
$this->assertEquals('en_US', $updatedMessage->getLocale());
|
||||
$this->assertEquals('test update title', $updatedMessage->getTitle());
|
||||
$this->assertEquals('test subject', $updatedMessage->getSubject());
|
||||
$this->assertEquals('my html message', $updatedMessage->getHtmlMessage());
|
||||
$this->assertEquals('my text message', $updatedMessage->getTextMessage());
|
||||
$this->assertNull($updatedMessage->getHtmlLayoutFileName());
|
||||
$this->assertNull($updatedMessage->getHtmlTemplateFileName());
|
||||
$this->assertNull($updatedMessage->getTextLayoutFileName());
|
||||
$this->assertNull($updatedMessage->getTextTemplateFileName());
|
||||
|
||||
return $updatedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MessageModel $message
|
||||
* @depends testModify
|
||||
*/
|
||||
public function testDelete(MessageModel $message)
|
||||
{
|
||||
$event = new MessageDeleteEvent($message->getId());
|
||||
|
||||
$action = new Message();
|
||||
$action->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedMessage = $event->getMessage();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Message', $deletedMessage);
|
||||
$this->assertTrue($deletedMessage->isDeleted());
|
||||
}
|
||||
}
|
||||
189
tests/phpunit/Thelia/Tests/Action/MetaDataTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Core\Event\MetaData\MetaDataDeleteEvent;
|
||||
use Thelia\Model\MetaDataQuery;
|
||||
use Thelia\Model\Product;
|
||||
use Thelia\Action\MetaData;
|
||||
use Thelia\Core\Event\MetaData\MetaDataCreateOrUpdateEvent;
|
||||
use Thelia\Model\ProductQuery;
|
||||
|
||||
/**
|
||||
* Class MetaDataTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class MetaDataTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$boom = MetaDataQuery::create()
|
||||
->deleteAll();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
// get a product
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
// simple
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey('test')
|
||||
->setElementKey(get_class($product))
|
||||
->setElementId($product->getId())
|
||||
->setValue('test');
|
||||
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$created = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $created);
|
||||
|
||||
$this->assertFalse($created->isNew());
|
||||
|
||||
$this->assertEquals('test', $created->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $created->getElementKey());
|
||||
$this->assertEquals($product->getId(), $created->getElementId());
|
||||
$this->assertEquals('test', $created->getValue());
|
||||
$this->assertEquals(false, $created->getIsSerialized());
|
||||
|
||||
// complex
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey('test2')
|
||||
->setElementKey(get_class($product))
|
||||
->setElementId($product->getId())
|
||||
->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$created = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $created);
|
||||
|
||||
$this->assertFalse($created->isNew());
|
||||
|
||||
$this->assertEquals('test2', $created->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $created->getElementKey());
|
||||
$this->assertEquals($product->getId(), $created->getElementId());
|
||||
$this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $created->getValue());
|
||||
$this->assertEquals(true, $created->getIsSerialized());
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testCreate
|
||||
* @return Product
|
||||
*/
|
||||
public function testRead(Product $product)
|
||||
{
|
||||
$metaDatas = MetaDataQuery::create()
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->find();
|
||||
|
||||
$this->assertEquals($metaDatas->count(), 2);
|
||||
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
$this->assertEquals('test', $metaData->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $metaData->getElementKey());
|
||||
$this->assertEquals($product->getId(), $metaData->getElementId());
|
||||
$this->assertEquals('test', $metaData->getValue());
|
||||
|
||||
$this->assertEquals(false, $metaData->getIsSerialized());
|
||||
|
||||
$datas = MetaDataQuery::getAllVal(get_class($product), $product->getId());
|
||||
$this->assertEquals(count($datas), 2);
|
||||
$this->assertEquals($datas['test'], 'test');
|
||||
$this->assertEquals($datas['test2'], array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testRead
|
||||
* @return Product
|
||||
*/
|
||||
public function testUpdate(Product $product)
|
||||
{
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
|
||||
$event = new MetaDataCreateOrUpdateEvent();
|
||||
$event
|
||||
->setMetaKey($metaData->getMetaKey())
|
||||
->setElementKey($metaData->getElementKey())
|
||||
->setElementId($metaData->getElementId())
|
||||
->setValue(array("fr_FR" => "bonjour", "en_US" => "Hello"));
|
||||
|
||||
$action = new MetaData();
|
||||
$action->createOrUpdate($event);
|
||||
|
||||
$updated = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $updated);
|
||||
|
||||
$this->assertFalse($updated->isNew());
|
||||
|
||||
$this->assertEquals('test', $updated->getMetaKey());
|
||||
$this->assertEquals(get_class($product), $updated->getElementKey());
|
||||
$this->assertEquals($product->getId(), $updated->getElementId());
|
||||
$this->assertEquals(array("fr_FR" => "bonjour", "en_US" => "Hello"), $updated->getValue());
|
||||
$this->assertEquals(true, $updated->getIsSerialized());
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Product $product
|
||||
* @depends testUpdate
|
||||
* @return Product
|
||||
*/
|
||||
public function testDelete(Product $product)
|
||||
{
|
||||
$metaData = MetaDataQuery::create()
|
||||
->filterByMetaKey('test')
|
||||
->filterByElementKey(get_class($product))
|
||||
->filterByElementId($product->getId())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($metaData);
|
||||
|
||||
$event = new MetaDataDeleteEvent('test', get_class($product), $product->getId());
|
||||
|
||||
$action = new MetaData();
|
||||
$action->delete($event);
|
||||
|
||||
$deleted = $event->getMetaData();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\MetaData', $deleted);
|
||||
$this->assertTrue($deleted->isDeleted());
|
||||
}
|
||||
}
|
||||
137
tests/phpunit/Thelia/Tests/Action/ModuleHookTest.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\ModuleHook;
|
||||
use Thelia\Core\Event\Hook\ModuleHookCreateEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookDeleteEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookToggleActivationEvent;
|
||||
use Thelia\Core\Event\Hook\ModuleHookUpdateEvent;
|
||||
use Thelia\Model\Hook as HookModel;
|
||||
use Thelia\Model\Module as ModuleModel;
|
||||
use Thelia\Model\ModuleHook as ModuleHookModel;
|
||||
use Thelia\Model\HookQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
|
||||
/**
|
||||
* Class HookTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ModuleHookTest extends BaseAction
|
||||
{
|
||||
/** @var ModuleHook $action */
|
||||
protected $action;
|
||||
|
||||
/** @var ModuleModel */
|
||||
protected $module;
|
||||
|
||||
/** @var HookModel */
|
||||
protected $hook;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->action = new ModuleHook($stubContainer, $this->getMockEventDispatcher());
|
||||
|
||||
$this->module = ModuleQuery::create()->findOneByActivate(1);
|
||||
|
||||
$this->hook = HookQuery::create()->findOneByActivate(true);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ModuleHookCreateEvent();
|
||||
$event
|
||||
->setHookId($this->hook->getId())
|
||||
->setModuleId($this->module->getId());
|
||||
|
||||
$this->action->createModuleHook($event);
|
||||
|
||||
$createdModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertInstanceOf('\Thelia\Model\ModuleHook', $createdModuleHook);
|
||||
$this->assertFalse($createdModuleHook->isNew());
|
||||
$this->assertTrue($event->hasModuleHook());
|
||||
|
||||
$this->assertEquals($event->getHookId(), $createdModuleHook->getHookId());
|
||||
$this->assertEquals($event->getModuleId(), $createdModuleHook->getModuleId());
|
||||
|
||||
return $createdModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testCreate
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testToggleActivation(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$activated = $moduleHook->getActive();
|
||||
|
||||
$event = new ModuleHookToggleActivationEvent($moduleHook);
|
||||
|
||||
$this->action->toggleModuleHookActivation($event, null, $this->getMockEventDispatcher());
|
||||
$updatedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertEquals(!$activated, $updatedModuleHook->getActive());
|
||||
|
||||
return $updatedModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testToggleActivation
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testUpdate(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$event = new ModuleHookUpdateEvent($moduleHook);
|
||||
|
||||
$event
|
||||
->setHookId($moduleHook->getHookId())
|
||||
->setClassname($moduleHook->getClassname())
|
||||
->setMethod($moduleHook->getMethod())
|
||||
->setActive(true);
|
||||
|
||||
$this->action->updateModuleHook($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertEquals($event->getHookId(), $updatedModuleHook->getHookId());
|
||||
$this->assertEquals($event->getClassname(), $updatedModuleHook->getClassname());
|
||||
$this->assertEquals($event->getMethod(), $updatedModuleHook->getMethod());
|
||||
$this->assertEquals($event->getActive(), $updatedModuleHook->getActive());
|
||||
|
||||
return $updatedModuleHook;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ModuleHookModel $moduleHook
|
||||
* @depends testUpdate
|
||||
* @return ModuleHookModel
|
||||
*/
|
||||
public function testDelete(ModuleHookModel $moduleHook)
|
||||
{
|
||||
$event = new ModuleHookDeleteEvent($moduleHook->getId());
|
||||
|
||||
$this->action->deleteModuleHook($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedModuleHook = $event->getModuleHook();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\ModuleHook', $deletedModuleHook);
|
||||
$this->assertTrue($deletedModuleHook->isDeleted());
|
||||
}
|
||||
}
|
||||
118
tests/phpunit/Thelia/Tests/Action/NewsletterTest.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Newsletter;
|
||||
use Thelia\Model\Newsletter as NewsletterModel;
|
||||
use Thelia\Core\Event\Newsletter\NewsletterEvent;
|
||||
use Thelia\Model\NewsletterQuery;
|
||||
|
||||
/**
|
||||
* Class NewsletterTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class NewsletterTest extends BaseAction
|
||||
{
|
||||
protected $mailerFactory;
|
||||
protected $dispatcher;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mailerFactory = $this->getMockBuilder("Thelia\\Mailer\\MailerFactory")
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$this->dispatcher = $this->getMockEventDispatcher();
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
NewsletterQuery::create()
|
||||
->filterByEmail('test@foo.com')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testSubscribe()
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event
|
||||
->setFirstname("foo")
|
||||
->setLastname("bar")
|
||||
;
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->subscribe($event);
|
||||
|
||||
$subscribedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $subscribedNewsletter);
|
||||
$this->assertFalse($subscribedNewsletter->isNew());
|
||||
|
||||
$this->assertEquals('test@foo.com', $subscribedNewsletter->getEmail());
|
||||
$this->assertEquals('en_US', $subscribedNewsletter->getLocale());
|
||||
$this->assertEquals('foo', $subscribedNewsletter->getFirstname());
|
||||
$this->assertEquals('bar', $subscribedNewsletter->getLastname());
|
||||
|
||||
return $subscribedNewsletter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewsletterModel $newsletter
|
||||
* @depends testSubscribe
|
||||
* @return NewsletterModel
|
||||
*/
|
||||
public function testUpdate(NewsletterModel $newsletter)
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event
|
||||
->setId($newsletter->getId())
|
||||
->setFirstname("foo update")
|
||||
->setLastname("bar update")
|
||||
;
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->update($event);
|
||||
|
||||
$updatedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $updatedNewsletter);
|
||||
|
||||
$this->assertEquals('test@foo.com', $updatedNewsletter->getEmail());
|
||||
$this->assertEquals('en_US', $updatedNewsletter->getLocale());
|
||||
$this->assertEquals('foo update', $updatedNewsletter->getFirstname());
|
||||
$this->assertEquals('bar update', $updatedNewsletter->getLastname());
|
||||
|
||||
return $updatedNewsletter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param NewsletterModel $newsletter
|
||||
* @depends testUpdate
|
||||
* @param NewsletterModel $newsletter
|
||||
*/
|
||||
public function testUnsubscribe(NewsletterModel $newsletter)
|
||||
{
|
||||
$event = new NewsletterEvent('test@foo.com', 'en_US');
|
||||
$event->setId($newsletter->getId());
|
||||
|
||||
$action = new Newsletter($this->mailerFactory, $this->dispatcher);
|
||||
$action->unsubscribe($event);
|
||||
|
||||
$deletedNewsletter = $event->getNewsletter();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Newsletter', $deletedNewsletter);
|
||||
$this->assertEquals(1, NewsletterQuery::create()->filterByEmail('test@foo.com')->filterByUnsubscribed(true)->count());
|
||||
}
|
||||
}
|
||||
226
tests/phpunit/Thelia/Tests/Action/OrderStatusTest.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Action\OrderStatus as OrderStatusAction;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusCreateEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusDeleteEvent;
|
||||
use Thelia\Core\Event\OrderStatus\OrderStatusUpdateEvent;
|
||||
use Thelia\Core\Event\UpdatePositionEvent;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\OrderStatus as OrderStatusModel;
|
||||
|
||||
/**
|
||||
* Class OrderStatusTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Gilles Bourgeat <gbourgeat@openstudio.fr>
|
||||
*/
|
||||
class OrderStatusTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
/**
|
||||
* @param OrderStatusModel $orderStatus
|
||||
* @return OrderStatusUpdateEvent
|
||||
*/
|
||||
public function getUpdateEvent(OrderStatusModel $orderStatus)
|
||||
{
|
||||
$event = new OrderStatusUpdateEvent($orderStatus->getId());
|
||||
$event
|
||||
->setLocale($orderStatus->getLocale())
|
||||
->setTitle($orderStatus->getTitle())
|
||||
->setChapo($orderStatus->getChapo())
|
||||
->setDescription($orderStatus->getDescription())
|
||||
->setPostscriptum($orderStatus->getPostscriptum())
|
||||
->setColor($orderStatus->getColor())
|
||||
->setCode($orderStatus->getCode())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param OrderStatusUpdateEvent $event
|
||||
* @return OrderStatusModel
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
return $event->getOrderStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status creation
|
||||
* @covers Thelia\Action\OrderStatus::create
|
||||
*/
|
||||
public function testCreateOrderStatus()
|
||||
{
|
||||
OrderStatusQuery::create()->filterByCode(['order_status_test', 'order_status_test2'], Criteria::IN)->delete();
|
||||
|
||||
$code = 'order_status_test';
|
||||
|
||||
$event = new OrderStatusCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('order status creation test')
|
||||
->setCode($code);
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
$orderStatusAction->create($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('order status creation test', $orderStatus->getTitle());
|
||||
$this->assertEquals($code, $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\OrderStatus::update
|
||||
*/
|
||||
public function testUpdateOrderStatusProtected()
|
||||
{
|
||||
if (null !== $find = OrderStatusQuery::create()->findOneByCode('paid_force_update')) {
|
||||
$find->setCode('paid')->save();
|
||||
}
|
||||
|
||||
if (null === OrderStatusQuery::create()->findOneByCode('paid')) {
|
||||
$this->fail('It\'s not possible to run the tests, because the order status "paid" not found');
|
||||
}
|
||||
|
||||
$event = $this->getUpdateEvent(OrderStatusQuery::create()->findOneByCode('paid'));
|
||||
|
||||
$event->setDescription('test');
|
||||
$event->setCode('paid_force_update');
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('test', $orderStatus->getDescription());
|
||||
$this->assertEquals('paid', $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test update creation
|
||||
* @covers Thelia\Action\OrderStatus::update
|
||||
* @depends testCreateOrderStatus
|
||||
*/
|
||||
public function testUpdateOrderStatusNotProtected()
|
||||
{
|
||||
$event = $this->getUpdateEvent(OrderStatusQuery::create()->findOneByCode('order_status_test'));
|
||||
|
||||
$event->setDescription('test');
|
||||
$event->setCode('order_status_test2');
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->update($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertEquals('test', $orderStatus->getDescription());
|
||||
$this->assertEquals('order_status_test2', $orderStatus->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusNotProtected
|
||||
*/
|
||||
public function testDeleteOrderStatus()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('order_status_test2');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->delete($event);
|
||||
|
||||
$orderStatus = $event->getOrderStatus();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\OrderStatus', $orderStatus);
|
||||
$this->assertTrue($orderStatus->isDeleted());
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusProtected
|
||||
*/
|
||||
public function testDeleteOrderStatusProtected()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('paid');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
try {
|
||||
$orderStatusAction->delete($event);
|
||||
$this->fail("A protected order status has been removed");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status removal
|
||||
* @covers Thelia\Action\OrderStatus::delete
|
||||
* @depends testUpdateOrderStatusNotProtected
|
||||
*/
|
||||
public function testDeleteOrderStatusWithOrders()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()->findOneByCode('paid');
|
||||
|
||||
$event = new OrderStatusDeleteEvent($orderStatus->getId());
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
|
||||
try {
|
||||
$orderStatusAction->delete($event);
|
||||
$this->fail("A protected order status with orders has been removed");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test order status update position
|
||||
* @covers Thelia\Action\OrderStatus::updatePosition
|
||||
*/
|
||||
public function testUpdatePositionUp()
|
||||
{
|
||||
$orderStatus = OrderStatusQuery::create()
|
||||
->filterByPosition(2)
|
||||
->findOne();
|
||||
|
||||
if (null === $orderStatus) {
|
||||
$this->fail('Use fixtures before launching test, there is not enough folder in database');
|
||||
}
|
||||
|
||||
$newPosition = $orderStatus->getPosition()-1;
|
||||
|
||||
$event = new UpdatePositionEvent($orderStatus->getId(), UpdatePositionEvent::POSITION_UP);
|
||||
|
||||
$orderStatusAction = new OrderStatusAction();
|
||||
$orderStatusAction->updatePosition($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$orderStatusUpdated = OrderStatusQuery::create()->findOneById($orderStatus->getId());
|
||||
|
||||
$this->assertEquals($newPosition, $orderStatusUpdated->getPosition(), sprintf("new position is %d, new position expected is %d for order status %d", $newPosition, $orderStatusUpdated->getPosition(), $orderStatusUpdated->getCode()));
|
||||
}
|
||||
}
|
||||
772
tests/phpunit/Thelia/Tests/Action/OrderTest.php
Normal file
@@ -0,0 +1,772 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Action\Order;
|
||||
use Thelia\Core\Event\Order\OrderAddressEvent;
|
||||
use Thelia\Core\Event\Order\OrderEvent;
|
||||
use Thelia\Core\Event\Order\OrderManualEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Mailer\MailerFactory;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Cart;
|
||||
use Thelia\Model\CartItem;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Customer as CustomerModel;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\Order as OrderModel;
|
||||
use Thelia\Model\OrderAddressQuery;
|
||||
use Thelia\Model\OrderProductQuery;
|
||||
use Thelia\Model\OrderQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
use Thelia\Model\OrderStatusQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElements;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class OrderTest extends BaseAction
|
||||
{
|
||||
/**
|
||||
* @var EventDispatcherInterface $realDispatcher
|
||||
*/
|
||||
protected $realDispatcher;
|
||||
|
||||
/**
|
||||
* @var ContainerBuilder $container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var Order $orderAction
|
||||
*/
|
||||
protected $orderAction;
|
||||
|
||||
/**
|
||||
* @var \Thelia\Core\Event\Order\OrderEvent $orderEvent
|
||||
*/
|
||||
protected $orderEvent;
|
||||
|
||||
/**
|
||||
* @var CustomerModel $customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @var Cart $customer
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* @var CartItem[]
|
||||
*/
|
||||
protected $cartItems;
|
||||
|
||||
/**
|
||||
* @var SecurityContext
|
||||
*/
|
||||
protected $securityContext;
|
||||
|
||||
/** @var RequestStack */
|
||||
protected $requestStack;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
$this->container = new ContainerBuilder();
|
||||
|
||||
$this->container->set("event_dispatcher", $this->getMockEventDispatcher());
|
||||
$this->container->set('request', $request);
|
||||
|
||||
$this->requestStack = new RequestStack();
|
||||
$this->requestStack->push($request);
|
||||
$this->container->set('request_stack', $this->requestStack);
|
||||
|
||||
$this->securityContext = new SecurityContext($this->requestStack);
|
||||
|
||||
$this->orderEvent = new OrderEvent(new OrderModel());
|
||||
|
||||
$mailerFactory = new MailerFactory(
|
||||
$this->getMockEventDispatcher(),
|
||||
$this->getMockParserInterface()
|
||||
);
|
||||
|
||||
$this->orderAction = new Order(
|
||||
$this->requestStack,
|
||||
$mailerFactory,
|
||||
$this->securityContext
|
||||
);
|
||||
|
||||
$this->realDispatcher = new EventDispatcher();
|
||||
$this->realDispatcher->addSubscriber($this->orderAction);
|
||||
|
||||
/* load customer */
|
||||
$this->customer = $this->loadCustomer();
|
||||
if (null === $this->customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* fill cart */
|
||||
$this->cart = $this->fillCart();
|
||||
}
|
||||
|
||||
public function loadCustomer()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
if (null === $customer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->securityContext->setCustomerUser($customer);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function fillCart()
|
||||
{
|
||||
$currency = CurrencyQuery::create()->findOne();
|
||||
|
||||
//create a fake cart in database;
|
||||
$cart = new Cart();
|
||||
$cart->setToken(uniqid("createorder", true))
|
||||
->setCustomer($this->customer)
|
||||
->setCurrency($currency)
|
||||
->save();
|
||||
|
||||
/* add 3 items */
|
||||
$productList = array();
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->filterByProduct(
|
||||
ProductQuery::create()
|
||||
->filterByVisible(1)
|
||||
->filterById($productList, Criteria::NOT_IN)
|
||||
->find()
|
||||
)
|
||||
->filterByQuantity(5, Criteria::GREATER_EQUAL)
|
||||
->joinProductPrice('pp', Criteria::INNER_JOIN)
|
||||
->addJoinCondition('pp', 'currency_id = ?', $currency->getId(), null, \PDO::PARAM_INT)
|
||||
->withColumn('`pp`.price', 'price_PRICE')
|
||||
->withColumn('`pp`.promo_price', 'price_PROMO_PRICE')
|
||||
->findOne();
|
||||
|
||||
$productList[] = $pse->getProductId();
|
||||
|
||||
$cartItem = new CartItem();
|
||||
$cartItem
|
||||
->setCart($cart)
|
||||
->setProduct($pse->getProduct())
|
||||
->setProductSaleElements($pse)
|
||||
->setQuantity($i + 1)
|
||||
->setPrice($pse->getPrice())
|
||||
->setPromoPrice($pse->getPromoPrice())
|
||||
->setPromo($pse->getPromo())
|
||||
->setPriceEndOfLife(time() + 60 * 60 * 24 * 30)
|
||||
->save();
|
||||
$this->cartItems[] = $cartItem;
|
||||
}
|
||||
|
||||
$this->requestStack->getCurrentRequest()->getSession()->set("thelia.cart_id", $cart->getId());
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public function testSetDeliveryAddress()
|
||||
{
|
||||
//$validAddressId = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$this->orderEvent->setDeliveryAddress(321);
|
||||
|
||||
$this->orderAction->setDeliveryAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
321,
|
||||
$this->orderEvent->getOrder()->getChoosenDeliveryAddress()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetinvoiceAddress()
|
||||
{
|
||||
$this->orderEvent->setInvoiceAddress(654);
|
||||
|
||||
$this->orderAction->setInvoiceAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
654,
|
||||
$this->orderEvent->getOrder()->getChoosenInvoiceAddress()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetDeliveryModule()
|
||||
{
|
||||
$this->orderEvent->setDeliveryModule(123);
|
||||
|
||||
$this->orderAction->setDeliveryModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
123,
|
||||
$this->orderEvent->getOrder()->getDeliveryModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetPaymentModule()
|
||||
{
|
||||
$this->orderEvent->setPaymentModule(456);
|
||||
|
||||
$this->orderAction->setPaymentModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
456,
|
||||
$this->orderEvent->getOrder()->getPaymentModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
$validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$deliveryModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::DELIVERY_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $deliveryModule) {
|
||||
throw new \Exception('No Delivery Module fixture found');
|
||||
}
|
||||
|
||||
$paymentModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::PAYMENT_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if (null === $paymentModule) {
|
||||
throw new \Exception('No Payment Module fixture found');
|
||||
}
|
||||
|
||||
$this->orderEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
|
||||
$this->orderEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
|
||||
$this->orderEvent->getOrder()->setDeliveryModuleId($deliveryModule->getId());
|
||||
$this->orderEvent->getOrder()->setPostage(20);
|
||||
$this->orderEvent->getOrder()->setPaymentModuleId($paymentModule->getId());
|
||||
|
||||
/* memorize current stocks */
|
||||
$itemsStock = array();
|
||||
foreach ($this->cartItems as $index => $cartItem) {
|
||||
$itemsStock[$index] = $cartItem->getProductSaleElements()->getQuantity();
|
||||
}
|
||||
|
||||
$this->orderAction->create($this->orderEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $this->orderEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
$manageStock = $placedOrder->isStockManagedOnOrderCreation($this->getMockEventDispatcher());
|
||||
|
||||
/* check customer */
|
||||
$this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not match');
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
|
||||
|
||||
/* check currency */
|
||||
$this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not match');
|
||||
$this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not match');
|
||||
|
||||
/* check delivery module */
|
||||
$this->assertEquals(20, $placedOrder->getPostage(), 'postage does not match');
|
||||
$this->assertEquals($deliveryModule->getId(), $placedOrder->getDeliveryModuleId(), 'delivery module does not match');
|
||||
|
||||
/* check payment module */
|
||||
$this->assertEquals($paymentModule->getId(), $placedOrder->getPaymentModuleId(), 'payment module does not match');
|
||||
|
||||
/* check status */
|
||||
$this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match');
|
||||
|
||||
/* check lang */
|
||||
$this->assertEquals($this->requestStack->getCurrentRequest()->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match');
|
||||
|
||||
/* check ordered product */
|
||||
foreach ($this->cartItems as $index => $cartItem) {
|
||||
$orderProduct = OrderProductQuery::create()
|
||||
->filterByOrderId($placedOrder->getId())
|
||||
->filterByProductRef($cartItem->getProduct()->getRef())
|
||||
->filterByProductSaleElementsRef($cartItem->getProductSaleElements()->getRef())
|
||||
->filterByQuantity($cartItem->getQuantity())
|
||||
->filterByPrice($cartItem->getPrice(), Criteria::LIKE)
|
||||
->filterByPromoPrice($cartItem->getPromoPrice(), Criteria::LIKE)
|
||||
->filterByWasNew($cartItem->getProductSaleElements()->getNewness())
|
||||
->filterByWasInPromo($cartItem->getPromo())
|
||||
->filterByWeight($cartItem->getProductSaleElements()->getWeight())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($orderProduct);
|
||||
|
||||
/* check attribute combinations */
|
||||
$this->assertEquals(
|
||||
$cartItem->getProductSaleElements()->getAttributeCombinations()->count(),
|
||||
$orderProduct->getOrderProductAttributeCombinations()->count()
|
||||
);
|
||||
|
||||
if ($manageStock) {
|
||||
if ($orderProduct->getVirtual()) {
|
||||
/* check same stock*/
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index],
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
} else {
|
||||
/* check stock decrease */
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index] - $orderProduct->getQuantity(),
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
/* check same stock*/
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index],
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* check tax */
|
||||
$orderProductTaxList = $orderProduct->getOrderProductTaxes();
|
||||
foreach ($cartItem->getProduct()->getTaxRule()->getTaxDetail($cartItem->getProduct(), $validDeliveryAddress->getCountry(), $cartItem->getPrice(), $cartItem->getPromoPrice()) as $index => $tax) {
|
||||
$orderProductTax = $orderProductTaxList[$index];
|
||||
$this->assertEquals($tax->getAmount(), $orderProductTax->getAmount());
|
||||
$this->assertEquals($tax->getPromoAmount(), $orderProductTax->getPromoAmount());
|
||||
}
|
||||
}
|
||||
|
||||
return $placedOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
* @param OrderModel $order
|
||||
* @return OrderModel
|
||||
*/
|
||||
public function testCreateManual(OrderModel $order)
|
||||
{
|
||||
$orderCopy = $order->copy();
|
||||
|
||||
$validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
$validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$orderManuelEvent = new OrderManualEvent(
|
||||
$orderCopy,
|
||||
$this->cart->getCurrency(),
|
||||
$this->requestStack->getCurrentRequest()->getSession()->getLang(),
|
||||
$this->cart,
|
||||
$this->customer
|
||||
);
|
||||
|
||||
$orderManuelEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
|
||||
$orderManuelEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
|
||||
|
||||
$deliveryModuleId = $orderCopy->getDeliveryModuleId();
|
||||
$paymentModuleId = $orderCopy->getPaymentModuleId();
|
||||
|
||||
$this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $orderManuelEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check customer */
|
||||
$this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not match');
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
|
||||
|
||||
/* check currency */
|
||||
$this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not match');
|
||||
$this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not match');
|
||||
|
||||
/* check delivery module */
|
||||
$this->assertEquals(20, $placedOrder->getPostage(), 'postage does not match');
|
||||
$this->assertEquals($deliveryModuleId, $placedOrder->getDeliveryModuleId(), 'delivery module does not match');
|
||||
|
||||
/* check payment module */
|
||||
$this->assertEquals($paymentModuleId, $placedOrder->getPaymentModuleId(), 'payment module does not match');
|
||||
|
||||
/* check status */
|
||||
$this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match');
|
||||
|
||||
/* check lang */
|
||||
$this->assertEquals($this->requestStack->getCurrentRequest()->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match');
|
||||
|
||||
|
||||
// without address duplication
|
||||
$copyOrder = $order->copy();
|
||||
|
||||
$orderManuelEvent
|
||||
->setOrder($copyOrder)
|
||||
->setUseOrderDefinedAddresses(true);
|
||||
|
||||
$validDeliveryAddressId = $orderCopy->getDeliveryOrderAddressId();
|
||||
$validInvoiceAddressId = $orderCopy->getInvoiceOrderAddressId();
|
||||
|
||||
$this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
|
||||
|
||||
$placedOrder = $orderManuelEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddressId, $deliveryOrderAddress->getId(), 'delivery address title does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddressId, $invoiceOrderAddress->getId(), 'invoice address title does not match');
|
||||
|
||||
return $placedOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function testUpdateStatus(OrderModel $order)
|
||||
{
|
||||
// Set Status to "not paid"
|
||||
$newStatusId = OrderStatusQuery::getNotPaidStatus()->getId();
|
||||
$this->orderEvent->setStatus($newStatusId);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->realDispatcher);
|
||||
|
||||
$this->assertEquals($newStatusId, $this->orderEvent->getOrder()->getStatusId());
|
||||
$this->assertEquals($newStatusId, OrderQuery::create()->findPk($order->getId())->getStatusId());
|
||||
|
||||
$orderProductList = $order->getOrderProducts();
|
||||
|
||||
$orderProductList[0]->setQuantity(2)->save();
|
||||
|
||||
/** @var ProductSaleElements $testProductSaleElement */
|
||||
$testProductSaleElement = ProductSaleElementsQuery::create()->findPk($orderProductList[0]->getProductSaleElementsId());
|
||||
$testProductSaleElement->setQuantity(100)->save();
|
||||
|
||||
// Set status to paid
|
||||
$newStatusId = OrderStatusQuery::getPaidStatus()->getId();
|
||||
$this->orderEvent->setStatus($newStatusId);
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->realDispatcher);
|
||||
|
||||
$this->assertEquals($newStatusId, $this->orderEvent->getOrder()->getStatusId());
|
||||
$this->assertEquals($newStatusId, OrderQuery::create()->findPk($order->getId())->getStatusId());
|
||||
|
||||
// The stock should have been decreased
|
||||
$testProductSaleElement->reload();
|
||||
$this->assertEquals(98, $testProductSaleElement->getQuantity());
|
||||
|
||||
// Set status to canceled
|
||||
$newStatusId = OrderStatusQuery::getCancelledStatus()->getId();
|
||||
$this->orderEvent->setStatus($newStatusId);
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->realDispatcher);
|
||||
|
||||
$this->assertEquals($newStatusId, $this->orderEvent->getOrder()->getStatusId());
|
||||
$this->assertEquals($newStatusId, OrderQuery::create()->findPk($order->getId())->getStatusId());
|
||||
|
||||
// The stock should have been updated
|
||||
$testProductSaleElement->reload();
|
||||
$this->assertEquals(100, $testProductSaleElement->getQuantity());
|
||||
|
||||
// Set status to sent
|
||||
$newStatusId = OrderStatusQuery::getSentStatus()->getId();
|
||||
$this->orderEvent->setStatus($newStatusId);
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->realDispatcher);
|
||||
|
||||
$this->assertEquals($newStatusId, $this->orderEvent->getOrder()->getStatusId());
|
||||
$this->assertEquals($newStatusId, OrderQuery::create()->findPk($order->getId())->getStatusId());
|
||||
|
||||
// The stock should have been updated
|
||||
$testProductSaleElement->reload();
|
||||
$this->assertEquals(98, $testProductSaleElement->getQuantity());
|
||||
|
||||
// Set status to not paid
|
||||
$newStatusId = OrderStatusQuery::getNotPaidStatus()->getId();
|
||||
$this->orderEvent->setStatus($newStatusId);
|
||||
$this->orderAction->updateStatus($this->orderEvent, null, $this->realDispatcher);
|
||||
|
||||
$this->assertEquals($newStatusId, $this->orderEvent->getOrder()->getStatusId());
|
||||
$this->assertEquals($newStatusId, OrderQuery::create()->findPk($order->getId())->getStatusId());
|
||||
|
||||
// The stock should have been updated
|
||||
$testProductSaleElement->reload();
|
||||
$this->assertEquals(100, $testProductSaleElement->getQuantity());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusPaidWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setPaid();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isPaid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusNotPaidWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setNotPaid();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_NOT_PAID)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isNotPaid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusProcessedWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setProcessing();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PROCESSING)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isProcessing()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusSentWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setSent();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_SENT)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isSent()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testModelUpdateStatusCanceledWithHelpers(OrderModel $order)
|
||||
{
|
||||
$order->setCancelled();
|
||||
|
||||
$this->assertEquals(
|
||||
$order->getStatusId(),
|
||||
OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_CANCELED)->getId()
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$order->isCancelled()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateTransactionRef(OrderModel $order)
|
||||
{
|
||||
$transactionRef = uniqid('TRANSREF');
|
||||
$this->orderEvent->setTransactionRef($transactionRef);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateTransactionRef($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
$transactionRef,
|
||||
$this->orderEvent->getOrder()->getTransactionRef()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$transactionRef,
|
||||
OrderQuery::create()->findPk($order->getId())->getTransactionRef()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateDeliveryRef(OrderModel $order)
|
||||
{
|
||||
$deliveryRef = uniqid('DELREF');
|
||||
$this->orderEvent->setDeliveryRef($deliveryRef);
|
||||
$this->orderEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateDeliveryRef($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
$deliveryRef,
|
||||
$this->orderEvent->getOrder()->getDeliveryRef()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$deliveryRef,
|
||||
OrderQuery::create()->findPk($order->getId())->getDeliveryRef()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*
|
||||
* @param OrderModel $order
|
||||
*/
|
||||
public function testUpdateAddress(OrderModel $order)
|
||||
{
|
||||
$orderAddress = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId());
|
||||
$title = $orderAddress->getCustomerTitleId() == 3 ? 1 : 3;
|
||||
$country = $orderAddress->getCountryId() == 64 ? 1 : 64;
|
||||
$orderAddressEvent = new OrderAddressEvent(
|
||||
$title, 'B', 'C', 'D', 'E', 'F', 'G', 'H', $country, 'J', 'K', '0102030405'
|
||||
);
|
||||
$orderAddressEvent->setOrderAddress($orderAddress);
|
||||
$orderAddressEvent->setOrder($order);
|
||||
|
||||
$this->orderAction->updateAddress($orderAddressEvent);
|
||||
|
||||
$newOrderAddress = OrderAddressQuery::create()->findPk($orderAddress->getId());
|
||||
|
||||
$this->assertEquals($title, $orderAddressEvent->getOrderAddress()->getCustomerTitleId());
|
||||
$this->assertEquals('B', $orderAddressEvent->getOrderAddress()->getFirstname());
|
||||
$this->assertEquals('C', $orderAddressEvent->getOrderAddress()->getLastname());
|
||||
$this->assertEquals('D', $orderAddressEvent->getOrderAddress()->getAddress1());
|
||||
$this->assertEquals('E', $orderAddressEvent->getOrderAddress()->getAddress2());
|
||||
$this->assertEquals('F', $orderAddressEvent->getOrderAddress()->getAddress3());
|
||||
$this->assertEquals('G', $orderAddressEvent->getOrderAddress()->getZipcode());
|
||||
$this->assertEquals('H', $orderAddressEvent->getOrderAddress()->getCity());
|
||||
$this->assertEquals($country, $orderAddressEvent->getOrderAddress()->getCountryId());
|
||||
$this->assertEquals('J', $orderAddressEvent->getOrderAddress()->getPhone());
|
||||
$this->assertEquals('0102030405', $orderAddressEvent->getOrderAddress()->getCellphone());
|
||||
$this->assertEquals('K', $orderAddressEvent->getOrderAddress()->getCompany());
|
||||
|
||||
$this->assertEquals($title, $newOrderAddress->getCustomerTitleId());
|
||||
$this->assertEquals('B', $newOrderAddress->getFirstname());
|
||||
$this->assertEquals('C', $newOrderAddress->getLastname());
|
||||
$this->assertEquals('D', $newOrderAddress->getAddress1());
|
||||
$this->assertEquals('E', $newOrderAddress->getAddress2());
|
||||
$this->assertEquals('F', $newOrderAddress->getAddress3());
|
||||
$this->assertEquals('G', $newOrderAddress->getZipcode());
|
||||
$this->assertEquals('H', $newOrderAddress->getCity());
|
||||
$this->assertEquals($country, $newOrderAddress->getCountryId());
|
||||
$this->assertEquals('J', $newOrderAddress->getPhone());
|
||||
$this->assertEquals('K', $newOrderAddress->getCompany());
|
||||
}
|
||||
}
|
||||
36
tests/phpunit/Thelia/Tests/Action/PdfTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Pdf;
|
||||
use Thelia\Core\Event\PdfEvent;
|
||||
|
||||
/**
|
||||
* Class PdfTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class PdfTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testGeneratePdf()
|
||||
{
|
||||
$event = new PdfEvent("test content");
|
||||
|
||||
$action = new Pdf();
|
||||
$action->generatePdf($event);
|
||||
|
||||
$generatedPdf = $event->getPdf();
|
||||
|
||||
$this->assertNotNull($generatedPdf);
|
||||
}
|
||||
}
|
||||
1142
tests/phpunit/Thelia/Tests/Action/ProductTest.php
Normal file
134
tests/phpunit/Thelia/Tests/Action/ProfileTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Profile;
|
||||
use Thelia\Core\Security\AccessManager;
|
||||
use Thelia\Model\Profile as ProfileModel;
|
||||
use Thelia\Core\Event\Profile\ProfileEvent;
|
||||
use Thelia\Model\ProfileQuery;
|
||||
|
||||
/**
|
||||
* Class ProfileTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ProfileTest extends BaseAction
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
ProfileQuery::create()
|
||||
->filterByCode('Test')
|
||||
->delete();
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setCode("Test")
|
||||
->setLocale('en_US')
|
||||
->setTitle('test profile')
|
||||
->setChapo('test chapo')
|
||||
->setDescription('test description')
|
||||
->setPostscriptum('test postscriptum');
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->create($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$createdProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $createdProfile);
|
||||
$this->assertFalse($createdProfile->isNew());
|
||||
|
||||
$this->assertEquals('Test', $createdProfile->getCode());
|
||||
$this->assertEquals('en_US', $createdProfile->getLocale());
|
||||
$this->assertEquals('test profile', $createdProfile->getTitle());
|
||||
$this->assertEquals('test chapo', $createdProfile->getChapo());
|
||||
$this->assertEquals('test description', $createdProfile->getDescription());
|
||||
$this->assertEquals('test postscriptum', $createdProfile->getPostscriptum());
|
||||
|
||||
return $createdProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProfileModel $profile
|
||||
* @depends testCreate
|
||||
* @return ProfileModel
|
||||
*/
|
||||
public function testUpdate(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update title')
|
||||
->setChapo('test update chapo')
|
||||
->setDescription('test update description')
|
||||
->setPostscriptum('test update postscriptum');
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$this->assertEquals($profile->getCode(), $updatedProfile->getCode());
|
||||
$this->assertEquals('en_US', $updatedProfile->getLocale());
|
||||
$this->assertEquals('test update title', $updatedProfile->getTitle());
|
||||
$this->assertEquals('test update chapo', $updatedProfile->getChapo());
|
||||
$this->assertEquals('test update description', $updatedProfile->getDescription());
|
||||
$this->assertEquals('test update postscriptum', $updatedProfile->getPostscriptum());
|
||||
|
||||
return $updatedProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ProfileModel $profile
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testUpdateResourceAccess(ProfileModel $profile)
|
||||
{
|
||||
$event = new ProfileEvent();
|
||||
$event
|
||||
->setId($profile->getId())
|
||||
->setResourceAccess(array(
|
||||
'admin.address' => array(AccessManager::CREATE)
|
||||
))
|
||||
;
|
||||
|
||||
$action = new Profile($this->getMockEventDispatcher());
|
||||
$action->updateResourceAccess($event);
|
||||
|
||||
$updatedProfile = $event->getProfile();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Profile', $updatedProfile);
|
||||
|
||||
$resources = $updatedProfile->getResources();
|
||||
|
||||
$this->assertEquals(1, count($resources));
|
||||
|
||||
$resource = $resources->getFirst();
|
||||
$this->assertEquals('admin.address', $resource->getCode());
|
||||
|
||||
$profileResource = $updatedProfile->getProfileResources()->getFirst();
|
||||
$accessManager = new AccessManager($profileResource->getAccess());
|
||||
|
||||
$this->assertTrue($accessManager->can(AccessManager::CREATE));
|
||||
}
|
||||
}
|
||||
113
tests/phpunit/Thelia/Tests/Action/RewrittenUrlTestTrait.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Thelia\Exception\UrlRewritingException;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\RewritingUrlQuery;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
use Thelia\Rewriting\RewritingResolver;
|
||||
|
||||
/**
|
||||
* Class RewrittenUrlTestTrait
|
||||
* @package Thelia\Tests\Action
|
||||
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
* @method EventDispatcherInterface getMockEventDispatcher()
|
||||
*/
|
||||
trait RewrittenUrlTestTrait
|
||||
{
|
||||
abstract public function getUpdateEvent(&$object);
|
||||
abstract public function getUpdateSeoEvent(&$object);
|
||||
abstract public function processUpdateAction($event);
|
||||
abstract public function processUpdateSeoAction($event);
|
||||
|
||||
/**
|
||||
* @expectedException \Thelia\Form\Exception\FormValidationException
|
||||
* @expectedExceptionCode 100
|
||||
*/
|
||||
public function testUpdateExistingUrl()
|
||||
{
|
||||
$object = null;
|
||||
$event = $this->getUpdateSeoEvent($object);
|
||||
|
||||
/* get an existing url */
|
||||
$existingUrl = RewritingUrlQuery::create()
|
||||
->filterByViewId($object->getId(), Criteria::NOT_EQUAL)
|
||||
->filterByRedirected(null)
|
||||
->filterByView(ConfigQuery::getObsoleteRewrittenUrlView(), Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
if (null === $existingUrl) {
|
||||
$this->fail('use fixtures before launching test, there is not enough rewritten url');
|
||||
}
|
||||
|
||||
$event->setUrl($existingUrl->getUrl());
|
||||
|
||||
$this->processUpdateSeoAction($event);
|
||||
}
|
||||
|
||||
public function testUpdateUrl()
|
||||
{
|
||||
$object = null;
|
||||
$event = $this->getUpdateSeoEvent($object);
|
||||
|
||||
$currentUrl = $object->getRewrittenUrl($object->getLocale());
|
||||
|
||||
/* get a brand new URL */
|
||||
$exist = true;
|
||||
while (true === $exist) {
|
||||
$newUrl = md5(rand(1, 999999)) . ".html";
|
||||
try {
|
||||
new RewritingResolver($newUrl);
|
||||
} catch (UrlRewritingException $e) {
|
||||
if ($e->getCode() === UrlRewritingException::URL_NOT_FOUND) {
|
||||
/* It's all good if URL is not found */
|
||||
$exist = false;
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$event->setUrl($newUrl);
|
||||
|
||||
$updatedObject = $this->processUpdateSeoAction($event);
|
||||
|
||||
/* new URL is updated */
|
||||
$this->assertEquals($newUrl, $updatedObject->getRewrittenUrl($object->getLocale()));
|
||||
|
||||
/* old url must be redirected to the new one */
|
||||
$newUrlEntry = RewritingUrlQuery::create()->findOneByUrl($newUrl);
|
||||
$oldUrlEntry = RewritingUrlQuery::create()->findOneByUrl($currentUrl);
|
||||
|
||||
$this->assertEquals($oldUrlEntry->getRedirected(), $newUrlEntry->getId());
|
||||
|
||||
/* we can reassign old Url to another object */
|
||||
$aRandomProduct = ProductQuery::create()
|
||||
->filterById($object->getId(), Criteria::NOT_EQUAL)
|
||||
->findOne();
|
||||
|
||||
$failReassign = true;
|
||||
try {
|
||||
$aRandomProduct->setRewrittenUrl($aRandomProduct->getLocale(), $currentUrl);
|
||||
$failReassign = false;
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
$this->assertFalse($failReassign);
|
||||
}
|
||||
}
|
||||
230
tests/phpunit/Thelia/Tests/Action/SaleTest.php
Normal file
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\Sale;
|
||||
use Thelia\Core\Event\Sale\SaleClearStatusEvent;
|
||||
use Thelia\Core\Event\Sale\SaleCreateEvent;
|
||||
use Thelia\Core\Event\Sale\SaleDeleteEvent;
|
||||
use Thelia\Core\Event\Sale\SaleToggleActivityEvent;
|
||||
use Thelia\Core\Event\Sale\SaleUpdateEvent;
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\SaleQuery;
|
||||
use Thelia\Tests\TestCaseWithURLToolSetup;
|
||||
use Thelia\Model\Sale as SaleModel;
|
||||
|
||||
/**
|
||||
* Class SaleTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class SaleTest extends TestCaseWithURLToolSetup
|
||||
{
|
||||
public function getUpdateEvent(&$sale)
|
||||
{
|
||||
if (!$sale instanceof SaleModel) {
|
||||
$sale = $this->getRandomSale();
|
||||
}
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setActive(1)
|
||||
->setLocale($sale->getLocale())
|
||||
->setTitle($sale->getTitle())
|
||||
->setChapo($sale->getChapo())
|
||||
->setDescription($sale->getDescription())
|
||||
->setPostscriptum($sale->getPostscriptum())
|
||||
;
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SaleUpdateEvent $event
|
||||
* @return SaleModel
|
||||
* @throws \Exception
|
||||
* @throws \Propel\Runtime\Exception\PropelException
|
||||
*/
|
||||
public function processUpdateAction($event)
|
||||
{
|
||||
$saleAction = new Sale();
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
return $event->getSale();
|
||||
}
|
||||
|
||||
public function testCreateSale()
|
||||
{
|
||||
$event = new SaleCreateEvent();
|
||||
$event
|
||||
->setLocale('en_US')
|
||||
->setTitle('test create sale')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->create($event);
|
||||
|
||||
$createdSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $createdSale);
|
||||
$this->assertEquals('test create sale', $createdSale->getTitle());
|
||||
$this->assertEquals('test create sale label', $createdSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testUpdateSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$date = new \DateTime();
|
||||
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setStartDate($date->setTimestamp(strtotime("today - 1 month")))
|
||||
->setEndDate($date->setTimestamp(strtotime("today + 1 month")))
|
||||
->setActive(1)
|
||||
->setDisplayInitialPrice(1)
|
||||
->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)
|
||||
->setPriceOffsets([ CurrencyQuery::create()->findOne()->getId() => 10 ])
|
||||
->setProducts([$product->getId()])
|
||||
->setProductAttributes([])
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update sale title')
|
||||
->setChapo('test update sale short description')
|
||||
->setDescription('test update sale description')
|
||||
->setPostscriptum('test update sale postscriptum')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale();
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(1, $updatedSale->getActive());
|
||||
$this->assertEquals('test update sale title', $updatedSale->getTitle());
|
||||
$this->assertEquals('test update sale short description', $updatedSale->getChapo());
|
||||
$this->assertEquals('test update sale description', $updatedSale->getDescription());
|
||||
$this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum());
|
||||
$this->assertEquals('test create sale label', $updatedSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testUpdatePseSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$date = new \DateTime();
|
||||
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$attrAv = AttributeAvQuery::create()->findOne();
|
||||
|
||||
$event = new SaleUpdateEvent($sale->getId());
|
||||
$event
|
||||
->setStartDate($date->setTimestamp(strtotime("today - 1 month")))
|
||||
->setEndDate($date->setTimestamp(strtotime("today + 1 month")))
|
||||
->setActive(1)
|
||||
->setDisplayInitialPrice(1)
|
||||
->setPriceOffsetType(SaleModel::OFFSET_TYPE_AMOUNT)
|
||||
->setPriceOffsets([ CurrencyQuery::create()->findOne()->getId() => 10 ])
|
||||
->setProducts([$product->getId()])
|
||||
->setProductAttributes([$product->getId() => [ $attrAv->getId()] ])
|
||||
->setLocale('en_US')
|
||||
->setTitle('test update sale title')
|
||||
->setChapo('test update sale short description')
|
||||
->setDescription('test update sale description')
|
||||
->setPostscriptum('test update sale postscriptum')
|
||||
->setSaleLabel('test create sale label')
|
||||
;
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->update($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(1, $updatedSale->getActive());
|
||||
$this->assertEquals('test update sale title', $updatedSale->getTitle());
|
||||
$this->assertEquals('test update sale short description', $updatedSale->getChapo());
|
||||
$this->assertEquals('test update sale description', $updatedSale->getDescription());
|
||||
$this->assertEquals('test update sale postscriptum', $updatedSale->getPostscriptum());
|
||||
$this->assertEquals('test create sale label', $updatedSale->getSaleLabel());
|
||||
}
|
||||
|
||||
public function testDeleteSale()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$event = new SaleDeleteEvent($sale->getId());
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->delete($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$deletedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $deletedSale);
|
||||
$this->assertTrue($deletedSale->isDeleted());
|
||||
}
|
||||
|
||||
public function testSaleToggleVisibility()
|
||||
{
|
||||
$sale = $this->getRandomSale();
|
||||
|
||||
$visibility = $sale->getActive();
|
||||
|
||||
$event = new SaleToggleActivityEvent($sale);
|
||||
|
||||
$saleAction = new Sale($this->getMockEventDispatcher());
|
||||
$saleAction->toggleActivity($event, null, $this->getMockEventDispatcher());
|
||||
|
||||
$updatedSale = $event->getSale();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\Sale', $updatedSale);
|
||||
$this->assertEquals(!$visibility, $updatedSale->getActive());
|
||||
}
|
||||
|
||||
public function testClearAllSales()
|
||||
{
|
||||
// Store current promo statuses
|
||||
$promoList = ProductSaleElementsQuery::create()->filterByPromo(true)->select('Id')->find()->toArray();
|
||||
|
||||
$event = new SaleClearStatusEvent();
|
||||
|
||||
$saleAction = new Sale();
|
||||
$saleAction->clearStatus($event);
|
||||
|
||||
// Restore promo status
|
||||
ProductSaleElementsQuery::create()->filterById($promoList)->update(['Promo' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Sale
|
||||
*/
|
||||
protected function getRandomSale()
|
||||
{
|
||||
$sale = SaleQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $sale) {
|
||||
$this->fail('use fixtures before launching test, there is no sale in database');
|
||||
}
|
||||
|
||||
return $sale;
|
||||
}
|
||||
}
|
||||
110
tests/phpunit/Thelia/Tests/Action/StateTest.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Action;
|
||||
|
||||
use Thelia\Action\State;
|
||||
use Thelia\Core\Event\State\StateCreateEvent;
|
||||
use Thelia\Core\Event\State\StateDeleteEvent;
|
||||
use Thelia\Core\Event\State\StateUpdateEvent;
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\State as StateModel;
|
||||
|
||||
/**
|
||||
* Class StateTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Julien Chanséaume <julien@thelia.net>
|
||||
*/
|
||||
class StateTest extends BaseAction
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$country = CountryQuery::create()
|
||||
->filterByHasStates(1)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
$event = new StateCreateEvent();
|
||||
|
||||
$event
|
||||
->setVisible(1)
|
||||
->setCountry($country->getId())
|
||||
->setIsocode('AA')
|
||||
->setLocale('en_US')
|
||||
->setTitle('State1')
|
||||
;
|
||||
|
||||
$action = new State();
|
||||
$action->create($event);
|
||||
|
||||
$createdState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $createdState);
|
||||
$this->assertFalse($createdState->isNew());
|
||||
|
||||
$this->assertEquals($country->getId(), $createdState->getCountryId());
|
||||
$this->assertEquals('AA', $createdState->getIsocode());
|
||||
$this->assertEquals('en_US', $createdState->getLocale());
|
||||
$this->assertEquals('State1', $createdState->getTitle());
|
||||
|
||||
return $createdState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StateModel $state
|
||||
* @depends testCreate
|
||||
* @return StateModel
|
||||
*/
|
||||
public function testUpdate(StateModel $state)
|
||||
{
|
||||
$event = new StateUpdateEvent($state->getId());
|
||||
|
||||
$event
|
||||
->setIsocode('BB')
|
||||
->setVisible(0)
|
||||
->setCountry($state->getCountryId())
|
||||
->setLocale('en_US')
|
||||
->setTitle('State2')
|
||||
;
|
||||
|
||||
$action = new State();
|
||||
$action->update($event);
|
||||
|
||||
$updatedState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $updatedState);
|
||||
|
||||
$this->assertEquals('BB', $updatedState->getIsocode());
|
||||
$this->assertEquals(0, $updatedState->getVisible());
|
||||
$this->assertEquals('en_US', $updatedState->getLocale());
|
||||
$this->assertEquals('State2', $updatedState->getTitle());
|
||||
|
||||
return $updatedState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param StateModel $state
|
||||
* @depends testUpdate
|
||||
*/
|
||||
public function testDelete(StateModel $state)
|
||||
{
|
||||
$event = new StateDeleteEvent($state->getId());
|
||||
|
||||
$action = new State();
|
||||
$action->delete($event);
|
||||
|
||||
$deletedState = $event->getState();
|
||||
|
||||
$this->assertInstanceOf('Thelia\Model\State', $deletedState);
|
||||
$this->assertTrue($deletedState->isDeleted());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
This is a text document.
|
||||
@@ -0,0 +1 @@
|
||||
This is a text document.
|
||||
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-1.png
Executable file
|
After Width: | Height: | Size: 13 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-2.png
Executable file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-3.png
Executable file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-4.png
Executable file
|
After Width: | Height: | Size: 8.9 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-5.png
Executable file
|
After Width: | Height: | Size: 17 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-6.png
Executable file
|
After Width: | Height: | Size: 15 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-7.png
Executable file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-8.png
Executable file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
tests/phpunit/Thelia/Tests/Action/assets/images/sources/test-image-9.png
Executable file
|
After Width: | Height: | Size: 11 KiB |
42
tests/phpunit/Thelia/Tests/Api/ApiSendJsonTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ApiSendJsonTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ApiSendJsonTest extends ApiTestCase
|
||||
{
|
||||
public function testSendNotValidJson()
|
||||
{
|
||||
$data = "this is not a valid json";
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?sign='.$this->getSignParameter($data),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$data
|
||||
);
|
||||
|
||||
$this->assertEquals(400, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
104
tests/phpunit/Thelia/Tests/Api/AttributeAvControllerTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class AttributeAvControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class AttributeAvControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$attributeAvCount = AttributeAvQuery::create()->count();
|
||||
if ($attributeAvCount > 10) {
|
||||
$attributeAvCount = 10;
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($attributeAvCount, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testListWithTranslation()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$attributeAvCount = AttributeAvQuery::create()->count();
|
||||
if ($attributeAvCount > 10) {
|
||||
$attributeAvCount = 10;
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($attributeAvCount, $content, "10 results must be return by default");
|
||||
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals(1, $firstResult['IS_TRANSLATED'], 'content must be translated');
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testGetActionWithWrongId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/attribute-avs/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
}
|
||||
}
|
||||
159
tests/phpunit/Thelia/Tests/Api/BrandControllerTest.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Brand;
|
||||
use Thelia\Model\BrandQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class BrandControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class BrandControllerTest extends ApiTestCase
|
||||
{
|
||||
protected $created = false;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
if (!$this->created) {
|
||||
if (BrandQuery::create()->count() === 0) {
|
||||
$brand = new Brand();
|
||||
|
||||
$brand
|
||||
->getTranslation()
|
||||
->setTitle("Foo")
|
||||
->setChapo("Bar")
|
||||
->setDescription("Baz")
|
||||
;
|
||||
|
||||
$brand
|
||||
->getTranslation("fr_FR")
|
||||
->setTitle("orange")
|
||||
->setChapo("banana")
|
||||
->setDescription("apple")
|
||||
;
|
||||
|
||||
$brand->save();
|
||||
}
|
||||
|
||||
$this->created = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$brand = $this->getBrand();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands/'.$brand->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$brand = $this->getBrand("fr_FR");
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/brands/'.$brand->getId().'?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
protected function getBrand($locale = 'en_US')
|
||||
{
|
||||
$brand = BrandQuery::create()
|
||||
->joinBrandI18n("brand_i18n_join", Criteria::INNER_JOIN)
|
||||
->addJoinCondition('brand_i18n_join', "locale = ?", $locale, null, \PDO::PARAM_STR)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $brand) {
|
||||
$this->markTestSkipped(
|
||||
sprintf(
|
||||
"You must have at least one brand with an i18n that has the '%s' locale",
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $brand;
|
||||
}
|
||||
}
|
||||
243
tests/phpunit/Thelia/Tests/Api/CategoryControllerTest.php
Normal file
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Thelia\Model\Category;
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CategoryControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CategoryControllerTest extends ApiTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (CategoryQuery::create()->count() === 0) {
|
||||
$category = new Category();
|
||||
|
||||
$category->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testListWithTranslation()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, "10 results must be return by default");
|
||||
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals(1, $firstResult['IS_TRANSLATED'], 'content must be translated');
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = $this->getCategory();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories/'.$category->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, "10 results must be return by default");
|
||||
}
|
||||
|
||||
public function testGetActionWithWrongId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/categories/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Response must be 200 on category list action');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$category = [
|
||||
'title' => 'test en',
|
||||
'locale' => 'en_US',
|
||||
'visible' => 0,
|
||||
'parent' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($category);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/categories?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
$this->assertEquals(0, $content[0]['VISIBLE']);
|
||||
}
|
||||
|
||||
public function testCreateFr()
|
||||
{
|
||||
$category = [
|
||||
'title' => 'test fr',
|
||||
'locale' => 'fr_FR',
|
||||
'visible' => 1,
|
||||
'parent' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($category);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/categories?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('fr_FR', $content[0]['LOCALE']);
|
||||
}
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->orderById(Criteria::DESC)
|
||||
->findOne();
|
||||
|
||||
$content = [
|
||||
'id' => $category->getId(),
|
||||
'title' => 'foo',
|
||||
'parent' => 0,
|
||||
'locale' => 'en_US',
|
||||
'visible' => 1,
|
||||
'chapo' => 'category chapo',
|
||||
'description' => 'category description',
|
||||
'postscriptum' => 'category postscriptum'
|
||||
];
|
||||
$requestContent = json_encode($content);
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/categories?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'HTTP status code must be 204');
|
||||
|
||||
$results = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertEquals(1, $results[0]["VISIBLE"]);
|
||||
}
|
||||
|
||||
public function testDeleteAction()
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->orderById(Criteria::DESC)
|
||||
->findOne();
|
||||
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/categories/'.$category->getId().'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'HTTP status code muse be 204');
|
||||
}
|
||||
|
||||
protected function getCategory($locale = 'en_US')
|
||||
{
|
||||
$category = CategoryQuery::create()
|
||||
->joinCategoryI18n("category_i18n_join", Criteria::INNER_JOIN)
|
||||
->addJoinCondition('category_i18n_join', "locale = ?", $locale, null, \PDO::PARAM_STR)
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $category) {
|
||||
$this->markTestSkipped(
|
||||
sprintf(
|
||||
"You must have at least one category with an i18n that has the '%s' locale",
|
||||
$locale
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/CountryControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CountryControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class CountryControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/countries/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/CurrencyControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CurrencyControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class CurrencyControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/currencies/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
390
tests/phpunit/Thelia/Tests/Api/CustomerControllerTest.php
Normal file
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class CustomerControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
* @author Baptiste Cabarrou <bcabarrou@openstudio.fr>
|
||||
*/
|
||||
class CustomerControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithDefaultParameters()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithOrderError()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?order=foo&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers?limit=1&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
protected function customerKeyTest($customer)
|
||||
{
|
||||
$this->assertArrayHasKey('ID', $customer, 'customer entity must contains Id key');
|
||||
$this->assertArrayHasKey('REF', $customer, 'customer entity must contains Ref key');
|
||||
$this->assertArrayHasKey('TITLE', $customer, 'customer entity must contains TitleId key');
|
||||
$this->assertArrayHasKey('FIRSTNAME', $customer, 'customer entity must contains Firstname key');
|
||||
$this->assertArrayHasKey('LASTNAME', $customer, 'customer entity must contains Lastname key');
|
||||
$this->assertArrayHasKey('EMAIL', $customer, 'customer entity must contains Email key');
|
||||
$this->assertArrayHasKey('RESELLER', $customer, 'customer entity must contains Reseller key');
|
||||
$this->assertArrayHasKey('SPONSOR', $customer, 'customer entity must contains Sponsor key');
|
||||
$this->assertArrayHasKey('DISCOUNT', $customer, 'customer entity must contains Discount key');
|
||||
$this->assertArrayHasKey('CREATE_DATE', $customer, 'customer entity must contains CreatedAt key');
|
||||
$this->assertArrayHasKey('UPDATE_DATE', $customer, 'customer entity must contains UpdatedAt key');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers/1?&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content);
|
||||
|
||||
$this->customerKeyTest($content[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::getAction
|
||||
*/
|
||||
public function testGetActionWithUnexistingCustomer()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/customers/'.PHP_INT_MAX.'?&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$user = [
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'password' => 'azerty',
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode());
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
return $content[0]['ID'];
|
||||
}
|
||||
|
||||
public function testCreateWithExistingEmail()
|
||||
{
|
||||
$customer = CustomerQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
|
||||
$user = [
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => $customer->getEmail(),
|
||||
'password' => 'azerty',
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreate
|
||||
*/
|
||||
public function testDelete($customerId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/customers/'.$customerId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), "the response code must be 204");
|
||||
}
|
||||
|
||||
public function testDeleteWithExistingOrders()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/customers/1?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(403, $client->getResponse()->getStatusCode(), "the response code must be 403 because the customer already have orders");
|
||||
}
|
||||
|
||||
public function testUpdateCustomer()
|
||||
{
|
||||
$user = [
|
||||
'id' => 1,
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testUpdateCustomerWithUnexistingCustomer()
|
||||
{
|
||||
$user = [
|
||||
'id' => PHP_INT_MAX,
|
||||
'title' => 1,
|
||||
'firstname' => 'Thelia',
|
||||
'lastname' => 'Thelia',
|
||||
'address1' => 'street address 1',
|
||||
'city' => 'Clermont-Ferrand',
|
||||
'zipcode' => 63100,
|
||||
'country' => 64,
|
||||
'email' => sprintf("%s@thelia.fr", uniqid()),
|
||||
'lang_id' => 1
|
||||
];
|
||||
|
||||
$requestContent = json_encode($user);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/customers?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLogin()
|
||||
{
|
||||
$logins = [
|
||||
'email' => CustomerQuery::create()->findPk(1)->getEmail(),
|
||||
'password' => 'azerty'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLoginWithUnexistingEmail()
|
||||
{
|
||||
$logins = [
|
||||
'email' => 'test@exemple.com',
|
||||
'password' => 'azerty'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\CustomerController::checkLoginAction
|
||||
*/
|
||||
public function testCheckLoginWithWrongPassword()
|
||||
{
|
||||
$logins = [
|
||||
'email' => CustomerQuery::create()->findPk(1)->getEmail(),
|
||||
'password' => 'notthis'
|
||||
];
|
||||
|
||||
$requestContent = json_encode($logins);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/customers/checkLogin?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
36
tests/phpunit/Thelia/Tests/Api/IndexControllerTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class IndexControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class IndexControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testIndexAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$crawler = $client->request(
|
||||
'GET',
|
||||
'/api'
|
||||
);
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('OK', $response->getContent());
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/LangControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class LangControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class LangControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/languages/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
276
tests/phpunit/Thelia/Tests/Api/ProductControllerTest.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\CategoryQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Model\TemplateQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ProductControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(10, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products?limit=2&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(2, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
$taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
|
||||
$product = [
|
||||
'ref' => uniqid('testCreateProduct'),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product create from api',
|
||||
'description' => 'product description from api',
|
||||
'default_category' => $category->getId(),
|
||||
'visible' => 1,
|
||||
'price' => '10',
|
||||
'currency' => $defaultCurrency->getId(),
|
||||
'tax_rule' => $taxRule->getId(),
|
||||
'weight' => 10,
|
||||
'brand_id' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($product);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
|
||||
return $content['0']['ID'];
|
||||
}
|
||||
|
||||
public function testCreateWithOptionalParametersAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$category = CategoryQuery::create()->addAscendingOrderByColumn('RAND()')->findOne();
|
||||
$defaultCurrency = CurrencyQuery::create()->findOneByByDefault(1);
|
||||
$taxRule = TaxRuleQuery::create()->findOneByIsDefault(1);
|
||||
$templateId = $category->getDefaultTemplateId();
|
||||
|
||||
if (null === $templateId) {
|
||||
$templateId = TemplateQuery::create()->addAscendingOrderByColumn('RAND()')->findOne()->getId();
|
||||
}
|
||||
|
||||
$product = [
|
||||
'ref' => uniqid('testCreateProduct'),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product create from api',
|
||||
'description' => 'product description from api',
|
||||
'default_category' => $category->getId(),
|
||||
'visible' => 1,
|
||||
'price' => '10',
|
||||
'currency' => $defaultCurrency->getId(),
|
||||
'tax_rule' => $taxRule->getId(),
|
||||
'weight' => 10,
|
||||
'brand_id' => 0,
|
||||
'quantity' => 10,
|
||||
'template_id' => $templateId
|
||||
];
|
||||
|
||||
$requestContent = json_encode($product);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('en_US', $content[0]['LOCALE']);
|
||||
|
||||
$this->assertEquals(10, $content[0]['QUANTITY']);
|
||||
$this->assertEquals($templateId, $content[0]['TEMPLATE']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($productId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = ProductQuery::create()->findPk($productId);
|
||||
|
||||
$productData = [
|
||||
'ref' => $product->getRef(),
|
||||
'locale' => 'en_US',
|
||||
'title' => 'product updated from api',
|
||||
'default_category' => $product->getDefaultCategoryId(),
|
||||
'visible' => 1,
|
||||
'description' => 'product description updated from api',
|
||||
'chapo' => 'product chapo updated from api',
|
||||
'postscriptum' => 'product postscriptum',
|
||||
'brand_id' => 0
|
||||
];
|
||||
|
||||
$requestContent = json_encode($productData);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/'.$productId.'?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
|
||||
return $productId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $productId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testDeleteAction($productId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/'.$productId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
}
|
||||
318
tests/phpunit/Thelia/Tests/Api/ProductImageControllerTest.php
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Propel\Runtime\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductImageControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductImageControllerTest extends ApiTestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel.png'
|
||||
);
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel2.png'
|
||||
);
|
||||
|
||||
$fs->copy(
|
||||
__DIR__ . '/fixtures/base.png',
|
||||
__DIR__ . '/fixtures/visuel3.png'
|
||||
);
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1/images?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertGreaterThan(0, count($content), 'must contain at least 1 image');
|
||||
}
|
||||
|
||||
public function testListActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.PHP_INT_MAX.'/images?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = ProductQuery::create()->joinProductImage()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("This test can't be run as there is no product that has an image");
|
||||
}
|
||||
|
||||
$productImage = $product->getProductImages()->get(0);
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/'.$product->getId().'/images/'.$productImage->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'image get action must retrieve 1 image');
|
||||
}
|
||||
|
||||
public function testGetActionWithNonExistingImage()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/products/1/images/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateImageAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel.png',
|
||||
'visuel.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$image2 = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel2.png',
|
||||
'visuel2.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products/1/images?&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image,
|
||||
'image2' => $image2
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$last = array_pop($content);
|
||||
|
||||
return $last['ID'];
|
||||
}
|
||||
|
||||
public function testCreateImageActionWithWrongMimeType()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/fail.pdf',
|
||||
'fail.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/products/1/images?&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateImageAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$image = new UploadedFile(
|
||||
__DIR__ . '/fixtures/visuel3.png',
|
||||
'visuel3.png',
|
||||
'image/png'
|
||||
);
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[
|
||||
'image1' => $image
|
||||
],
|
||||
$servers
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateImageDataAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "My Image",
|
||||
"chapo" => "My Super Image"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Mon image",
|
||||
"chapo" => "Ma super image"
|
||||
]
|
||||
)
|
||||
];
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$content = json_encode($data);
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?lang=en_US&no-cache=yes&sign='.$this->getSignParameter($content),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$content
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 201');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals("My Image", $content[0]["TITLE"]);
|
||||
$this->assertEquals("My Super Image", $content[0]["CHAPO"]);
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testCreateImageAction
|
||||
*/
|
||||
public function testUpdateFailsOnPutNothing($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.$imageId.'?no-cache=yes&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(500, $client->getResponse()->getStatusCode(), 'Http status code must be 500');
|
||||
|
||||
return $imageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $imageId
|
||||
* @depends testUpdateImageAction
|
||||
*/
|
||||
public function testDeleteImageAction($imageId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/products/1/images/'.$imageId.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testUpdateImageFailWithBadId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/products/1/images/'.PHP_INT_MAX.'?no-cache=yes&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\AttributeAvQuery;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\Map\AttributeAvTableMap;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class ProductSaleElementsControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductSaleElementsControllerTest extends ApiTestCase
|
||||
{
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/product/'.$product->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$productPse = $product->getProductSaleElementss()->count();
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(
|
||||
$productPse > 10 ? 10 : $productPse,
|
||||
$content,
|
||||
'without parameters, the api must return 10 results, or the number of PSE of the product'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::listAction
|
||||
*/
|
||||
public function testListActionWithLimit()
|
||||
{
|
||||
$client = static::createClient();
|
||||
$product = $this->getProduct();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/product/'.$product->getId().'?limit=1&sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'with the limit parameter at 1, the api must return 1 result');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pse = ProductSaleElementsQuery::create()->findOne();
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped(
|
||||
sprintf("You can't run this test without any product sale elements")
|
||||
);
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/'.$pse->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'without parameters, the api must return 10 results');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Thelia\Controller\Api\ProductController::getAction
|
||||
*/
|
||||
public function testGetActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/pse/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
$currency = $this->getCurrency();
|
||||
$taxRule = $this->getTaxRule();
|
||||
|
||||
$attributeAvs = AttributeAvQuery::create()
|
||||
->limit(2)
|
||||
->select(AttributeAvTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.99",
|
||||
"reference" => "foo",
|
||||
"attribute_av" => $attributeAvs,
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/pse?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
// Find the item we've juste created in the result list
|
||||
$pse = null;
|
||||
|
||||
if (count($content) > 1) {
|
||||
foreach ($content as $item) {
|
||||
if ($item['REF'] == 'foo') {
|
||||
$pse = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} elseif (count($content) == 1) {
|
||||
$pse = $content[0];
|
||||
}
|
||||
|
||||
$this->assertNotNull($pse);
|
||||
|
||||
$this->assertEquals('3.99', $pse['PRICE']);
|
||||
|
||||
return $content['0']['ID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pseId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($pseId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pseData = [
|
||||
"pse" => [
|
||||
[
|
||||
"id" => $pseId,
|
||||
"price" => "3.33",
|
||||
"sale_price" => "2.11",
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($pseData);
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/pse/'.$pseId.'?&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(201, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
|
||||
$data = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertEquals('3.33', $data["0"]["PRICE"]);
|
||||
$this->assertEquals('2.11', $data["0"]["PROMO_PRICE"]);
|
||||
$this->assertEquals('foo', $data["0"]["REF"]);
|
||||
|
||||
return $pseId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $pseId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testDeleteAction($pseId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$pse = ProductSaleElementsQuery::create()->findPk($pseId);
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped(
|
||||
sprintf("You can't run this test without any product sale elements")
|
||||
);
|
||||
}
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/pse/'.$pse->getId().'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode(), 'Http status code must be 204');
|
||||
}
|
||||
|
||||
public function testCreateMultiplePSEInOneShot()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$product = $this->getProduct();
|
||||
$currency = $this->getCurrency();
|
||||
$taxRule = $this->getTaxRule();
|
||||
|
||||
$attributeAvs = AttributeAvQuery::create()
|
||||
->limit(2)
|
||||
->select(AttributeAvTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray();
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.12",
|
||||
"reference" => "foo",
|
||||
"quantity" => 1,
|
||||
"attribute_av" => $attributeAvs,
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
],
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "3.33",
|
||||
"reference" => "bar",
|
||||
"quantity" => 10,
|
||||
"attribute_av" => [$attributeAvs[0]],
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
],
|
||||
[
|
||||
"product_id" => $product->getId(),
|
||||
"tax_rule_id" => $taxRule->getId(),
|
||||
"currency_id" => $currency->getId(),
|
||||
"price" => "12.09",
|
||||
"reference" => "baz",
|
||||
"quantity" => 100,
|
||||
"attribute_av" => [$attributeAvs[1]],
|
||||
"onsale" => true,
|
||||
"isnew" => true,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/pse?order=quantity&sign=' . $this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(3, $content);
|
||||
$this->assertEquals('3.12', $content[0]['PRICE']);
|
||||
$this->assertEquals('3.33', $content[1]['PRICE']);
|
||||
$this->assertEquals('12.09', $content[2]['PRICE']);
|
||||
|
||||
$ids = array();
|
||||
|
||||
foreach ($content as $entry) {
|
||||
$ids[] = $entry["ID"];
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ids
|
||||
* @depends testCreateMultiplePSEInOneShot
|
||||
*/
|
||||
public function testUpdateMultiplePSEInOneShot($ids)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"pse" => [
|
||||
[
|
||||
"id" => $ids[0],
|
||||
"price" => "3.50",
|
||||
],
|
||||
[
|
||||
"id" => $ids[1],
|
||||
"price" => "2.54",
|
||||
],
|
||||
[
|
||||
"id" => $ids[2],
|
||||
"price" => "9.60",
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/pse?order=quantity&sign=' . $this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
201,
|
||||
$client->getResponse()->getStatusCode(),
|
||||
sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
)
|
||||
);
|
||||
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(3, $content);
|
||||
$this->assertEquals('3.50', $content[0]['PRICE']);
|
||||
$this->assertEquals('2.54', $content[1]['PRICE']);
|
||||
$this->assertEquals('9.60', $content[2]['PRICE']);
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNonExistingProduct()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/pse/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(""),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
/**
|
||||
* Not tests
|
||||
*/
|
||||
|
||||
protected function getProduct()
|
||||
{
|
||||
$product = ProductQuery::create()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one product to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
protected function getTaxRule()
|
||||
{
|
||||
$product = TaxRuleQuery::create()->findOne();
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one tax rule to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
protected function getCurrency()
|
||||
{
|
||||
$product = CurrencyQuery::create()->findOneByCode("EUR");
|
||||
|
||||
if (null === $product) {
|
||||
$this->markTestSkipped("You must have at least one currency to run this test");
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
}
|
||||
103
tests/phpunit/Thelia/Tests/Api/TaxControllerTest.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TaxControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class TaxControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/taxes/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
}
|
||||
307
tests/phpunit/Thelia/Tests/Api/TaxRuleControllerTest.php
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\CountryQuery;
|
||||
use Thelia\Model\Map\CountryTableMap;
|
||||
use Thelia\Model\Map\TaxTableMap;
|
||||
use Thelia\Model\TaxQuery;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TaxRuleControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class TaxRuleControllerTest extends ApiTestCase
|
||||
{
|
||||
protected static $defaultId;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$taxRule = TaxRuleQuery::create()
|
||||
->filterByIsDefault(1)
|
||||
->findOne();
|
||||
|
||||
self::$defaultId = $taxRule->getId();
|
||||
}
|
||||
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertGreaterThan(0, count($content), 'The request must return at least one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/tax-rules/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
|
||||
$this->assertCount(1, $content, 'The request must return one result');
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testCreateTaxRule()
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$taxes = TaxQuery::create()
|
||||
->limit(2)
|
||||
->select(TaxTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$countries = CountryQuery::create()
|
||||
->limit(2)
|
||||
->select(CountryTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"country" => $countries,
|
||||
"tax" => $taxes,
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "Test tax rule",
|
||||
"description" => "foo",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Test règle de taxe",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/tax-rules?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
$content = json_decode($response->getContent(), true)[0];
|
||||
|
||||
$this->assertEquals("Test tax rule", $content["TITLE"]);
|
||||
$this->assertEquals(0, $content["IS_DEFAULT"]);
|
||||
|
||||
return $content["ID"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $taxRuleId
|
||||
* @depends testCreateTaxRule
|
||||
*/
|
||||
public function testUpdateTaxRule($taxRuleId)
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$data = [
|
||||
"id" => $taxRuleId,
|
||||
"default" => true,
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"description" => "bar",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"description" => "baz",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/tax-rules?lang=fr_FR&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode());
|
||||
|
||||
$content = json_decode($response->getContent(), true)[0];
|
||||
|
||||
$this->assertEquals("Test règle de taxe", $content["TITLE"]);
|
||||
$this->assertEquals("baz", $content["DESCRIPTION"]);
|
||||
$this->assertEquals(1, $content["IS_DEFAULT"]);
|
||||
|
||||
return $content["ID"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $taxRuleId
|
||||
* @depends testCreateTaxRule
|
||||
*/
|
||||
public function testDeleteTaxRule($taxRuleId)
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/tax-rules/'.$taxRuleId.'?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$servers
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(204, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCreateTaxRuleWithInvalidData()
|
||||
{
|
||||
$this->markTestSkipped('Must be revisited. Tax Rules do not work like this.');
|
||||
|
||||
$countries = CountryQuery::create()
|
||||
->limit(2)
|
||||
->select(CountryTableMap::COL_ID)
|
||||
->find()
|
||||
->toArray()
|
||||
;
|
||||
|
||||
$data = [
|
||||
"country" => $countries,
|
||||
"tax" => array(),
|
||||
"i18n" => array(
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"title" => "Test tax rule",
|
||||
"description" => "foo",
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"title" => "Test règle de taxe",
|
||||
]
|
||||
)
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$client = static::createClient();
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/tax-rules?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
TaxRuleQuery::create()
|
||||
->filterById(self::$defaultId)
|
||||
->update(array('IsDefault' => true));
|
||||
}
|
||||
}
|
||||
374
tests/phpunit/Thelia/Tests/Api/TitleControllerTest.php
Normal file
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Api;
|
||||
|
||||
use Thelia\Model\CustomerTitleQuery;
|
||||
use Thelia\Tests\ApiTestCase;
|
||||
|
||||
/**
|
||||
* Class TitleControllerTest
|
||||
* @package Thelia\Tests\Api
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class TitleControllerTest extends ApiTestCase
|
||||
{
|
||||
public function testListAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$maxCount = CustomerTitleQuery::create()->count();
|
||||
|
||||
if ($maxCount > 10) {
|
||||
$maxCount = 10;
|
||||
}
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($maxCount, $content, sprintf('reponse must contains %d results', $maxCount));
|
||||
}
|
||||
|
||||
public function testListActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$maxCount = CustomerTitleQuery::create()->count();
|
||||
|
||||
if ($maxCount > 10) {
|
||||
$maxCount = 10;
|
||||
}
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount($maxCount, $content, sprintf('reponse must contains %d results', $maxCount));
|
||||
|
||||
$firstResult = $content[0];
|
||||
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/1?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'response must contains only 1 result');
|
||||
}
|
||||
|
||||
public function testGetActionWithLocale()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/1?lang=fr_FR&sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $client->getResponse()->getStatusCode(), 'Http status code must be 200');
|
||||
$content = json_decode($client->getResponse()->getContent(), true);
|
||||
$this->assertCount(1, $content, 'response must contains only 1 result');
|
||||
$firstResult = $content[0];
|
||||
$this->assertEquals('fr_FR', $firstResult['LOCALE'], 'the returned locale must be fr_FR');
|
||||
}
|
||||
|
||||
public function testGetActionWithUnexistingId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'GET',
|
||||
'/api/title/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode(), 'Http status code must be 404');
|
||||
}
|
||||
|
||||
public function testCreateAction()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"short" => "Mr"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"short" => "M.",
|
||||
"long" => "Monsieur"
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/title?lang=en_US&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
$content = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals('Mr', $content[0]['SHORT']);
|
||||
$this->assertEquals('', $content[0]['LONG']);
|
||||
|
||||
return $content[0]['ID'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testCreateAction
|
||||
*/
|
||||
public function testUpdateAction($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"long" => "Mister"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => $titleId,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?lang=en_US&no-cache=yes&sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(201, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 201. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
$content = json_decode($response->getContent(), true);
|
||||
|
||||
$this->assertEquals('Mr', $content[0]['SHORT']);
|
||||
$this->assertEquals('Mister', $content[0]['LONG']);
|
||||
$this->assertEquals(1, $content[0]['DEFAULT']);
|
||||
|
||||
return $titleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testUpdateAction
|
||||
*/
|
||||
public function testUpdateActionWithFormError($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"short" => "This sentence is really too long for a short"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => $titleId,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 500. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
|
||||
return $titleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $titleId
|
||||
* @depends testUpdateActionWithFormError
|
||||
*/
|
||||
public function testDeleteAction($titleId)
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/title/'.$titleId.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(204, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
|
||||
public function testCreateActionWithNotCompleteForm()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"short" => "Mr"
|
||||
],
|
||||
[
|
||||
"locale" => "fr_FR",
|
||||
"short" => "Mr",
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'POST',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(500, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 500. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
}
|
||||
|
||||
public function testUpdateActionWithNotExistingTitleId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$data = [
|
||||
"i18n" => [
|
||||
[
|
||||
"locale" => "en_US",
|
||||
"long" => "Mister"
|
||||
],
|
||||
],
|
||||
"default" => true,
|
||||
"title_id" => PHP_INT_MAX,
|
||||
];
|
||||
|
||||
$requestContent = json_encode($data);
|
||||
|
||||
$servers = $this->getServerParameters();
|
||||
$servers['CONTENT_TYPE'] = 'application/json';
|
||||
|
||||
$client->request(
|
||||
'PUT',
|
||||
'/api/title?sign='.$this->getSignParameter($requestContent),
|
||||
[],
|
||||
[],
|
||||
$servers,
|
||||
$requestContent
|
||||
);
|
||||
|
||||
$response = $client->getResponse();
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode(), sprintf(
|
||||
'Http status code must be 404. Error: %s',
|
||||
$client->getResponse()->getContent()
|
||||
));
|
||||
}
|
||||
|
||||
public function testDeleteActionWithNotExistingTitleId()
|
||||
{
|
||||
$client = static::createClient();
|
||||
|
||||
$client->request(
|
||||
'DELETE',
|
||||
'/api/title/'.PHP_INT_MAX.'?sign='.$this->getSignParameter(''),
|
||||
[],
|
||||
[],
|
||||
$this->getServerParameters()
|
||||
);
|
||||
|
||||
$this->assertEquals(404, $client->getResponse()->getStatusCode());
|
||||
}
|
||||
}
|
||||
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/base.png
Normal file
|
After Width: | Height: | Size: 76 KiB |
BIN
tests/phpunit/Thelia/Tests/Api/fixtures/fail.pdf
Normal file
43
tests/phpunit/Thelia/Tests/ApiTestCase.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests;
|
||||
|
||||
use Thelia\Model\ApiQuery;
|
||||
|
||||
/**
|
||||
* Class ApiTestCase
|
||||
* @package Thelia\Tests
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ApiTestCase extends WebTestCase
|
||||
{
|
||||
const API_KEY = "79E95BD784CADA0C9A578282E";
|
||||
|
||||
protected function getServerParameters()
|
||||
{
|
||||
return [
|
||||
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
||||
'HTTP_AUTHORIZATION' => 'Token '.self::API_KEY
|
||||
];
|
||||
}
|
||||
|
||||
protected function getSignParameter($content)
|
||||
{
|
||||
$api = ApiQuery::create()
|
||||
->findOneByApiKey(self::API_KEY);
|
||||
|
||||
$secureKey = pack('H*', $api->getSecureKey());
|
||||
|
||||
return hash_hmac('sha1', $content, $secureKey);
|
||||
}
|
||||
}
|
||||
35
tests/phpunit/Thelia/Tests/Command/BaseCommandTest.php
Executable file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
/**
|
||||
* base class for testing command line command
|
||||
*
|
||||
* Class BaseCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
abstract class BaseCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return KernelInterface
|
||||
*/
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->createMock("Symfony\Component\HttpKernel\KernelInterface");
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
}
|
||||
123
tests/phpunit/Thelia/Tests/Command/CacheClearTest.php
Executable file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Cache;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Command\CacheClear;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* test the cache:clear command
|
||||
*
|
||||
* Class CacheClearTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class CacheClearTest extends ContainerAwareTestCase
|
||||
{
|
||||
public $cache_dir;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->cache_dir = THELIA_CACHE_DIR . 'test_cache';
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$fs->mkdir($this->cache_dir);
|
||||
$fs->mkdir(THELIA_WEB_DIR . "/assets");
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->exists($this->cache_dir)) {
|
||||
$fs->chmod($this->cache_dir, 0700);
|
||||
$fs->remove($this->cache_dir);
|
||||
}
|
||||
}
|
||||
|
||||
public function testCacheClear()
|
||||
{
|
||||
// Fails on windows - do not execute this test on windows
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$this->markTestSkipped('Fails on windows');
|
||||
}
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$cacheClear = new CacheClear();
|
||||
$cacheClear->setContainer($this->getContainer());
|
||||
|
||||
$application->add($cacheClear);
|
||||
|
||||
$command = $application->find("cache:clear");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
));
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$this->assertFalse($fs->exists($this->cache_dir));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testCacheClearWithoutWritePermission()
|
||||
{
|
||||
// Fails on windows - mock this test on windows
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
$this->markTestSkipped('Fails on windows');
|
||||
}
|
||||
|
||||
$fs = new Filesystem();
|
||||
$fs->chmod($this->cache_dir, 0100);
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$cacheClear = new CacheClear();
|
||||
$cacheClear->setContainer($this->getContainer());
|
||||
|
||||
$application->add($cacheClear);
|
||||
|
||||
$command = $application->find("cache:clear");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Cache(new ArrayAdapter()));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter("kernel.cache_dir", $this->cache_dir);
|
||||
}
|
||||
}
|
||||
281
tests/phpunit/Thelia/Tests/Command/ConfigCommandTest.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Thelia\Command\ConfigCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\Config;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
/**
|
||||
* Class ConfigCommandTest
|
||||
* @package Command
|
||||
* @author Julien Chanséaume <jchanseaume@openstudio.fr>
|
||||
*/
|
||||
class ConfigCommandTest extends BaseCommandTest
|
||||
{
|
||||
/** @var ConfigCommand */
|
||||
protected $command;
|
||||
|
||||
/** @var CommandTester */
|
||||
protected $commandTester;
|
||||
|
||||
const PREFIX_NAME = "config_command_test_";
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
if (null === $this->commandTester) {
|
||||
$application = new Application($this->getKernel());
|
||||
$configCommand = new ConfigCommand();
|
||||
|
||||
$application->add($configCommand);
|
||||
|
||||
$this->command = $application->find("thelia:config");
|
||||
$this->commandTester = new CommandTester($this->command);
|
||||
}
|
||||
}
|
||||
|
||||
public function testArguments()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$commands = $this->getFakeCommands();
|
||||
|
||||
foreach ($commands as $command) {
|
||||
$arguments = array_merge(
|
||||
$command['args'],
|
||||
["command" => $this->command->getName()]
|
||||
);
|
||||
|
||||
$tester->execute($arguments);
|
||||
|
||||
$this->assertStringContains(
|
||||
$tester->getDisplay(),
|
||||
$command["out"],
|
||||
"Should display : " . $command["out"]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testList()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "list"
|
||||
]);
|
||||
|
||||
$out = $tester->getDisplay();
|
||||
|
||||
$vars = ConfigQuery::create()->find();
|
||||
|
||||
/** @var Config $var */
|
||||
foreach ($vars as $var) {
|
||||
$this->assertStringContains(
|
||||
$out,
|
||||
$var->getName(),
|
||||
"Should display : " . $var->getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetSetDelete()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$varName = $this->getRandomVariableName();
|
||||
|
||||
// Get
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "get",
|
||||
"name" => $varName
|
||||
]);
|
||||
|
||||
$expected = sprintf("Unknown variable '%s'", $varName);
|
||||
|
||||
$this->assertStringContains(
|
||||
$tester->getDisplay(),
|
||||
$expected,
|
||||
"Should display : " . $expected
|
||||
);
|
||||
|
||||
// Set
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "0"
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "0");
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "Thelia"
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "Thelia");
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "Thelia",
|
||||
"--secured" => true,
|
||||
"--visible" => true,
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "Thelia", 1, 0);
|
||||
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "set",
|
||||
"name" => $varName,
|
||||
"value" => "THELIA",
|
||||
"--visible" => true
|
||||
]);
|
||||
|
||||
$this->assertVariableEqual($varName, "THELIA", 0, 0);
|
||||
|
||||
// DELETE
|
||||
$tester->execute([
|
||||
"command" => $this->command->getName(),
|
||||
"COMMAND" => "delete",
|
||||
"name" => $varName
|
||||
]);
|
||||
|
||||
$this->assertNull(
|
||||
ConfigQuery::read($varName),
|
||||
sprintf("Variable '%s' should not exist", $varName)
|
||||
);
|
||||
}
|
||||
|
||||
public static function clearTest()
|
||||
{
|
||||
ConfigQuery::create()
|
||||
->filterByName(self::PREFIX_NAME . '%', Criteria::LIKE)
|
||||
->delete();
|
||||
}
|
||||
|
||||
protected function getRandomVariableName()
|
||||
{
|
||||
return sprintf(
|
||||
"%s%s",
|
||||
self::PREFIX_NAME,
|
||||
substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyz"), 0, 10)
|
||||
);
|
||||
}
|
||||
|
||||
protected function assertVariableEqual($name, $value, $secured = 0, $hidden = 1)
|
||||
{
|
||||
$var = ConfigQuery::create()->findOneByName($name);
|
||||
|
||||
$this->assertNotNull($var, sprintf("Variable '%s' should exist", $name));
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getName(),
|
||||
$name,
|
||||
sprintf("Variable '%s' should have name '%s' :/", $var->getName(), $name)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getValue(),
|
||||
$value,
|
||||
sprintf(
|
||||
"Variable '%s' should have value '%s' ('%s' found)",
|
||||
$name,
|
||||
$value,
|
||||
$var->getValue()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getSecured(),
|
||||
$secured,
|
||||
sprintf("Variable '%s' should be %s secured", $name, $secured === 1 ? '' : 'NOT')
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$var->getHidden(),
|
||||
$hidden,
|
||||
sprintf("Variable '%s' should be %s hidden", $name, $hidden === 1 ? '' : 'NOT')
|
||||
);
|
||||
}
|
||||
|
||||
protected function assertStringContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false !== strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function assertStringNotContains($data, $needle, $message = "")
|
||||
{
|
||||
$this->assertTrue((false === strpos($data, $needle)), $message);
|
||||
}
|
||||
|
||||
protected function getFakeCommands()
|
||||
{
|
||||
$commands = [
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'hello',
|
||||
],
|
||||
'out' => "Unknown argument 'COMMAND'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'get',
|
||||
],
|
||||
'out' => "Need argument 'name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'get',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Unknown variable 'unknown_var_name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'delete',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Unknown variable 'unknown_var_name'"
|
||||
],
|
||||
[
|
||||
"args" => [
|
||||
'COMMAND' => 'set',
|
||||
'name' => 'unknown_var_name',
|
||||
],
|
||||
'out' => "Need argument 'name' and 'value'"
|
||||
]
|
||||
];
|
||||
|
||||
return $commands;
|
||||
}
|
||||
}
|
||||
106
tests/phpunit/Thelia/Tests/Command/ModuleActivateCommandTest.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Module;
|
||||
use Thelia\Command\ModuleActivateCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ModuleActivateCommandTest
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class ModuleActivateCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
public function testModuleActivateCommand()
|
||||
{
|
||||
$module = ModuleQuery::create()->findOne();
|
||||
|
||||
if (null !== $module) {
|
||||
$prev_activation_status = $module->getActivate();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$module->setActivate(BaseModule::IS_NOT_ACTIVATED);
|
||||
$module->save();
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => $module->getCode(),
|
||||
));
|
||||
|
||||
$activated = ModuleQuery::create()->findPk($module->getId())->getActivate();
|
||||
|
||||
// Restore activation status
|
||||
$module->setActivate($prev_activation_status)->save();
|
||||
|
||||
$this->assertEquals(BaseModule::IS_ACTIVATED, $activated);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
|
||||
*/
|
||||
public function testModuleActivateCommandUnknownModule()
|
||||
{
|
||||
$testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
|
||||
|
||||
if (null == $testedModule) {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => "letshopethismoduledoesnotexists",
|
||||
));
|
||||
|
||||
$out = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Module($container, $eventDispatcher));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter('kernel.cache_dir', THELIA_CACHE_DIR . 'dev');
|
||||
}
|
||||
}
|
||||
106
tests/phpunit/Thelia/Tests/Command/ModuleDeactivateCommandTest.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Module;
|
||||
use Thelia\Command\ModuleDeactivateCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ModuleDeactivateCommandTest
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Nicolas Villa <nicolas@libre-shop.com>
|
||||
*/
|
||||
class ModuleDeactivateCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
public function testModuleDeactivateCommand()
|
||||
{
|
||||
$module = ModuleQuery::create()->findOne();
|
||||
|
||||
if (null !== $module) {
|
||||
$prev_activation_status = $module->getActivate();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$module->setActivate(BaseModule::IS_ACTIVATED);
|
||||
$module->save();
|
||||
|
||||
$moduleDeactivate = new ModuleDeactivateCommand();
|
||||
$moduleDeactivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleDeactivate);
|
||||
|
||||
$command = $application->find("module:deactivate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => $module->getCode(),
|
||||
));
|
||||
|
||||
$deactivated = ModuleQuery::create()->findPk($module->getId())->getActivate();
|
||||
|
||||
// Restore activation status
|
||||
$module->setActivate($prev_activation_status)->save();
|
||||
|
||||
$this->assertEquals(BaseModule::IS_NOT_ACTIVATED, $deactivated);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
|
||||
*/
|
||||
public function testModuleDeactivateCommandUnknownModule()
|
||||
{
|
||||
$testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
|
||||
|
||||
if (null == $testedModule) {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleDeactivate = new ModuleDeactivateCommand();
|
||||
$moduleDeactivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleDeactivate);
|
||||
|
||||
$command = $application->find("module:deactivate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => "letshopethismoduledoesnotexists",
|
||||
));
|
||||
|
||||
$out = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Module($container, $this->getMockEventDispatcher()));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
|
||||
$container->setParameter('kernel.cache_dir', THELIA_CACHE_DIR . 'dev');
|
||||
}
|
||||
}
|
||||
131
tests/phpunit/Thelia/Tests/Command/ModuleGenerateCommandTest.php
Executable file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Command\ModuleGenerateCommand;
|
||||
|
||||
/**
|
||||
* test the module:generate command
|
||||
*
|
||||
* Class ModuleGenerateCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class ModuleGenerateCommandTest extends BaseCommandTest
|
||||
{
|
||||
/** @var Command */
|
||||
protected $command;
|
||||
|
||||
/** @var CommandTester */
|
||||
protected $commandTester;
|
||||
|
||||
public static function clearTest()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
|
||||
if ($fs->exists(THELIA_MODULE_DIR . "Test")) {
|
||||
$fs->remove(THELIA_MODULE_DIR . "Test");
|
||||
}
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
self::clearTest();
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleGenerator = new ModuleGenerateCommand();
|
||||
|
||||
$application->add($moduleGenerator);
|
||||
|
||||
$this->command = $application->find("module:generate");
|
||||
$this->commandTester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
public function testGenerateModule()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test"
|
||||
));
|
||||
|
||||
$fs = new Filesystem();
|
||||
|
||||
$this->assertTrue($fs->exists(THELIA_MODULE_DIR . "Test"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGenerateModule
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGenerateDuplicateModule()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test"
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGenerateModule
|
||||
*/
|
||||
public function testGenerateDuplicateModuleWithForceOption()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
// remove the config.xml
|
||||
$fs = new Filesystem();
|
||||
$configFile = THELIA_MODULE_DIR . "Test" .
|
||||
DIRECTORY_SEPARATOR . "Config" .
|
||||
DIRECTORY_SEPARATOR . "config.xml"
|
||||
;
|
||||
$fs->remove($configFile);
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "test",
|
||||
"--force" => ""
|
||||
));
|
||||
|
||||
$this->assertTrue($fs->exists($configFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testGenerateWithReservedKeyWord()
|
||||
{
|
||||
$tester = $this->commandTester;
|
||||
|
||||
$tester->execute(array(
|
||||
"command" => $this->command->getName(),
|
||||
"name" => "thelia"
|
||||
));
|
||||
}
|
||||
}
|
||||
107
tests/phpunit/Thelia/Tests/Command/ModuleRefreshCommandTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
use Thelia\Command\ModuleRefreshCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\ModuleManagement;
|
||||
|
||||
/**
|
||||
* Class ModuleRefreshCommandTest
|
||||
* Test refresh modules list command
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*
|
||||
* Date: 2014-06-06
|
||||
* Time: 17:29
|
||||
*/
|
||||
class ModuleRefreshCommandTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Test ModuleRefreshCommand
|
||||
*/
|
||||
public function testModuleRefreshCommand()
|
||||
{
|
||||
$moduleManagement = new ModuleManagement($this->getContainer());
|
||||
$moduleManagement->updateModules($this->getContainer());
|
||||
|
||||
$module = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
|
||||
|
||||
if ($module !== null) {
|
||||
$module->delete();
|
||||
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$moduleRefresh = new ModuleRefreshCommand;
|
||||
$moduleRefresh->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleRefresh);
|
||||
|
||||
$command = $application->find('module:refresh');
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute([
|
||||
'command' => $command->getName()
|
||||
]);
|
||||
|
||||
$expected = $module;
|
||||
$actual = ModuleQuery::create()->filterByType(1)->orderByPosition(Criteria::DESC)->findOne();
|
||||
|
||||
$this->assertEquals($expected->getCode(), $actual->getCode(), 'Last standard module code must be same after deleting this one and calling module:refresh');
|
||||
$this->assertEquals($expected->getType(), $actual->getType(), 'Last standard module type must be same after deleting this one and calling module:refresh');
|
||||
$this->assertEquals($expected->getFullNamespace(), $actual->getFullNamespace(), 'Last standard module namespace must be same after deleting this one and calling module:refresh');
|
||||
|
||||
// Restore activation status
|
||||
$actual
|
||||
->setActivate($expected->getActivate())
|
||||
->save();
|
||||
} else {
|
||||
$this->markTestIncomplete(
|
||||
'This test cannot be complete without at least one standard module.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get HttpKernel mock
|
||||
*
|
||||
* @return Kernel Not really a Kernel but the mocked one
|
||||
*/
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->createMock('Symfony\\Component\\HttpKernel\\KernelInterface');
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get new ContainerBuilder
|
||||
*
|
||||
* @return ContainerBuilder
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder;
|
||||
|
||||
$container->set('event_dispatcher', new EventDispatcher());
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Command;
|
||||
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Thelia\Action\Sale;
|
||||
use Thelia\Command\SaleCheckActivationCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\SaleQuery;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class SaleCheckActivationCommandTest
|
||||
* @package Thelia\Tests\Command
|
||||
* @author manuel raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class SaleCheckActivationCommandTest extends ContainerAwareTestCase
|
||||
{
|
||||
protected static $deactivated;
|
||||
|
||||
protected static $activated;
|
||||
|
||||
/**
|
||||
* in this method two sales are created. The first must be activated and the second one must be deactivated
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
/** @var \Thelia\Model\Sale $sale */
|
||||
$sale = SaleQuery::create()
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
if (null === $sale) {
|
||||
throw new \RuntimeException('use fixtures before launching test, there is no sale in database');
|
||||
}
|
||||
|
||||
$startDate = new \DateTime("@".strtotime("today - 1 month"));
|
||||
$endDate = new \DateTime("@".strtotime("today + 1 month"));
|
||||
|
||||
$sale->setStartDate($startDate)
|
||||
->setEndDate($endDate)
|
||||
->setActive(false)
|
||||
->save();
|
||||
|
||||
self::$deactivated = $sale->getId();
|
||||
|
||||
/** @var \Thelia\Model\Sale $otherSale */
|
||||
$otherSale = SaleQuery::create()
|
||||
->filterById($sale->getId(), Criteria::NOT_IN)
|
||||
->addAscendingOrderByColumn('RAND()')
|
||||
->findOne();
|
||||
|
||||
$startDate = new \DateTime("@".strtotime("today - 1 month"));
|
||||
$endDate = new \DateTime("@".strtotime("today - 1 day"));
|
||||
|
||||
$otherSale
|
||||
->setStartDate($startDate)
|
||||
->setEndDate($endDate)
|
||||
->setActive(true)
|
||||
->save();
|
||||
|
||||
|
||||
self::$activated = $otherSale->getId();
|
||||
}
|
||||
|
||||
public function testCommand()
|
||||
{
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$checkCommand = new SaleCheckActivationCommand();
|
||||
$checkCommand->setContainer($this->getContainer());
|
||||
|
||||
$application->add($checkCommand);
|
||||
|
||||
$command = $application->find("sale:check-activation");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute([
|
||||
"command" => $command->getName(),
|
||||
"--env" => "test"
|
||||
]);
|
||||
|
||||
$deactivatedSale = SaleQuery::create()->findPk(self::$deactivated);
|
||||
|
||||
$this->assertTrue($deactivatedSale->getActive(), "the sale must be actived now");
|
||||
|
||||
$activatedSale = SaleQuery::create()->findPk(self::$activated);
|
||||
|
||||
$this->assertFalse($activatedSale->getActive(), "the sale must be deactived now");
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$eventDispatcher = new EventDispatcher();
|
||||
$eventDispatcher->addSubscriber(new Sale($eventDispatcher));
|
||||
|
||||
$container->set("event_dispatcher", $eventDispatcher);
|
||||
}
|
||||
}
|
||||
170
tests/phpunit/Thelia/Tests/Condition/ConditionCollectionTest.php
Normal file
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmount;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Unit Test ConditionCollection Class
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24.
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ConditionCollection
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function testGetConditions()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $condition1;
|
||||
|
||||
$expected = $condition1;
|
||||
$actual = $collection[0];
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$this->assertFalse($collection->count() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Condition\ConditionCollection::count
|
||||
*/
|
||||
public function testIsEmpty()
|
||||
{
|
||||
$collection = new ConditionCollection();
|
||||
$this->assertTrue($collection->count() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Condition\ConditionCollection::__toString
|
||||
*/
|
||||
public function test__toString()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators1 = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values1 = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators1, $values1);
|
||||
|
||||
$condition2 = new MatchForTotalAmount($stubFacade);
|
||||
$operators2 = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values2 = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 600,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition2->setValidatorsFromForm($operators2, $values2);
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $condition1;
|
||||
$collection[] = $condition2;
|
||||
|
||||
$expected = '[{"conditionServiceId":"thelia.condition.match_for_total_amount","operators":{"price":">","currency":"=="},"values":{"price":400,"currency":"EUR"}},{"conditionServiceId":"thelia.condition.match_for_total_amount","operators":{"price":"<","currency":"=="},"values":{"price":600,"currency":"EUR"}}]';
|
||||
$actual = $collection->__toString();
|
||||
;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
}
|
||||
193
tests/phpunit/Thelia/Tests/Condition/ConditionEvaluatorTest.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Condition;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\ConditionCollection;
|
||||
|
||||
/**
|
||||
* Unit Test ConditionEvaluator Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Test variable comparison
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
|
||||
*/
|
||||
public function testVariableOpComparisonSuccess()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = true;
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test variable comparison
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
|
||||
*/
|
||||
public function testVariableOpComparisonFail()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = false;
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test variable comparison
|
||||
*
|
||||
* @expectedException \Exception
|
||||
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
|
||||
*/
|
||||
public function testVariableOpComparisonException()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = true;
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test condition collection matching
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionEvaluator::isMatching
|
||||
*/
|
||||
public function testIsMatchingTrue()
|
||||
{
|
||||
$stubConditionTrue1 = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubConditionTrue1->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubConditionTrue2 = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubConditionTrue2->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $stubConditionTrue1;
|
||||
$collection[] = $stubConditionTrue2;
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$actual = $conditionEvaluator->isMatching($collection);
|
||||
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test condition collection matching
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionEvaluator::isMatching
|
||||
*/
|
||||
public function testIsMatchingFalse()
|
||||
{
|
||||
$stubConditionTrue = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubConditionTrue->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubConditionFalse = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubConditionFalse->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $stubConditionTrue;
|
||||
$collection[] = $stubConditionFalse;
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$actual = $conditionEvaluator->isMatching($collection);
|
||||
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
439
tests/phpunit/Thelia/Tests/Condition/ConditionFactoryTest.php
Normal file
@@ -0,0 +1,439 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Condition;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\Implementation\MatchForEveryone;
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmount;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Condition\ConditionCollection;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Unit Test ConditionFactory Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the Rules serialization module
|
||||
*/
|
||||
public function testBuild()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmount($stubFacade)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 40.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
$ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
|
||||
|
||||
$expected = $condition1;
|
||||
$actual = $ruleManager1;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
$this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId());
|
||||
$this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the Rules serialization module
|
||||
*/
|
||||
public function testBuildFail()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmount($stubFacade)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValueMap(array('unset.service', false)));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 40.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
$conditionManager1 = $conditionFactory->build('unset.service', $operators, $values);
|
||||
|
||||
$expected = false;
|
||||
$actual = $conditionManager1;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the Rules serialization module
|
||||
*/
|
||||
public function testRuleSerialisation()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmount($stubFacade)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 40.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$condition2 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions[] = $condition1;
|
||||
$conditions[] = $condition2;
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
||||
$unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
|
||||
|
||||
$expected = (string) $conditions;
|
||||
$actual = (string) $unserializedConditions;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputs()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 40.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions[] = $condition1;
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = $condition1->getValidators();
|
||||
$actual = $conditionFactory->getInputsFromServiceId('thelia.condition.match_for_x_articles');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputsFalse()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 40.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions[] = $condition1;
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = false;
|
||||
$actual = $conditionFactory->getInputsFromServiceId('thelia.condition.unknown');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test condition serialization if collection is empty
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionFactory::serializeConditionCollection
|
||||
*/
|
||||
public function testSerializeConditionCollectionEmpty()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForEveryone($stubFacade)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$conditionNone = new MatchForEveryone($stubFacade);
|
||||
$expectedCollection = new ConditionCollection();
|
||||
$expectedCollection[] = $conditionNone;
|
||||
|
||||
$expected = $conditionFactory->serializeConditionCollection($expectedCollection);
|
||||
$actual = $conditionFactory->serializeConditionCollection($conditions);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Category;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class CartContainsCategoriesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
$category1 = new Category();
|
||||
$category1->setId(10);
|
||||
|
||||
$category2 = new Category();
|
||||
$category2->setId(20);
|
||||
|
||||
$category3 = new Category();
|
||||
$category3->setId(30);
|
||||
|
||||
$product1 = new Product();
|
||||
$product1->addCategory($category1)->addCategory($category2);
|
||||
|
||||
$product2 = new Product();
|
||||
$product2->addCategory($category3);
|
||||
|
||||
$cartItem1Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartItem1Stub
|
||||
->expects($this->any())
|
||||
->method('getProduct')
|
||||
->will($this->returnValue($product1))
|
||||
;
|
||||
|
||||
$cartItem1Stub
|
||||
->expects($this->any())
|
||||
->method('getQuantity')
|
||||
->will($this->returnValue(1))
|
||||
;
|
||||
|
||||
$cartItem2Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartItem2Stub
|
||||
->expects($this->any())
|
||||
->method('getProduct')
|
||||
->will($this->returnValue($product2));
|
||||
|
||||
$cartItem2Stub
|
||||
->expects($this->any())
|
||||
->method('getQuantity')
|
||||
->will($this->returnValue(2))
|
||||
;
|
||||
|
||||
$cartStub = $this->getMockBuilder('\Thelia\Model\Cart')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartStub
|
||||
->expects($this->any())
|
||||
->method('getCartItems')
|
||||
->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCart')
|
||||
->will($this->returnValue($cartStub));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array()
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array()
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array(10, 20)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsCategories::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsCategories($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
CartContainsCategories::CATEGORIES_LIST => array(
|
||||
'availableOperators' => array(
|
||||
'in' => 'Price',
|
||||
'out' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => 'in'
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'categories' => 'in'
|
||||
),
|
||||
'setValues' => array(
|
||||
'categories' => array(50, 60)
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Category;
|
||||
use Thelia\Model\Product;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class CartContainsProductsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
$category1 = new Category();
|
||||
$category1->setId(10);
|
||||
|
||||
$category2 = new Category();
|
||||
$category2->setId(20);
|
||||
|
||||
$category3 = new Category();
|
||||
$category3->setId(30);
|
||||
|
||||
$product1 = new Product();
|
||||
$product1->setId(10)->addCategory($category1)->addCategory($category2);
|
||||
|
||||
$product2 = new Product();
|
||||
$product2->setId(20)->addCategory($category3);
|
||||
|
||||
$cartItem1Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartItem1Stub
|
||||
->expects($this->any())
|
||||
->method('getProduct')
|
||||
->will($this->returnValue($product1))
|
||||
;
|
||||
|
||||
$cartItem1Stub
|
||||
->expects($this->any())
|
||||
->method('getQuantity')
|
||||
->will($this->returnValue(1))
|
||||
;
|
||||
|
||||
$cartItem2Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartItem2Stub
|
||||
->expects($this->any())
|
||||
->method('getProduct')
|
||||
->will($this->returnValue($product2));
|
||||
|
||||
$cartItem2Stub
|
||||
->expects($this->any())
|
||||
->method('getQuantity')
|
||||
->will($this->returnValue(2))
|
||||
;
|
||||
|
||||
$cartStub = $this->getMockBuilder('\Thelia\Model\Cart')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$cartStub
|
||||
->expects($this->any())
|
||||
->method('getCartItems')
|
||||
->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCart')
|
||||
->will($this->returnValue($cartStub));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array()
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array()
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array(10, 20)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\CartContainsProducts::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new CartContainsProducts($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
CartContainsProducts::PRODUCTS_LIST => array(
|
||||
'availableOperators' => array(
|
||||
'in' => 'Price',
|
||||
'out' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => 'in'
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'products' => 'in'
|
||||
),
|
||||
'setValues' => array(
|
||||
'products' => array(50, 60)
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class ForSomeCustomersTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$customer = new Customer();
|
||||
$customer->setId(10);
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCustomer')
|
||||
->will($this->returnValue($customer));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array()
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array()
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array(10, 20)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ForSomeCustomers::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new ForSomeCustomers($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
ForSomeCustomers::CUSTOMERS_LIST => array(
|
||||
'availableOperators' => array(
|
||||
'in' => 'Price',
|
||||
'out' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => 'in'
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'customers' => 'in'
|
||||
),
|
||||
'setValues' => array(
|
||||
'customers' => array(50, 60)
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Address;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class MatchBillingCountriesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$address = new Address();
|
||||
$address->setCountryId(10);
|
||||
|
||||
$stubCustomer = $this->getMockBuilder('\Thelia\Model\Customer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubCustomer->expects($this->any())
|
||||
->method('getDefaultAddress')
|
||||
->will($this->returnValue($address));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCustomer')
|
||||
->will($this->returnValue($stubCustomer));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array()
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array()
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array(10, 20)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchBillingCountries::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchBillingCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
MatchBillingCountries::COUNTRIES_LIST => array(
|
||||
'availableOperators' => array(
|
||||
'in' => 'Price',
|
||||
'out' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => 'in'
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'countries' => 'in'
|
||||
),
|
||||
'setValues' => array(
|
||||
'countries' => array(50, 60)
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Address;
|
||||
use Thelia\Model\Customer;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class MatchDeliveryCountriesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$address = new Address();
|
||||
$address->setCountryId(10);
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCustomer')
|
||||
->will($this->returnValue(new Customer()));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getDeliveryAddress')
|
||||
->will($this->returnValue($address));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array()
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array()
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array(10, 20)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchDeliveryCountries($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
MatchDeliveryCountries::COUNTRIES_LIST => array(
|
||||
'availableOperators' => array(
|
||||
'in' => 'Price',
|
||||
'out' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => 'in'
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'countries' => 'in'
|
||||
),
|
||||
'setValues' => array(
|
||||
'countries' => array(50, 60)
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
/**
|
||||
* Unit Test MatchForEveryone Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForEveryoneTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var FacadeInterface $stubTheliaAdapter */
|
||||
protected $stubTheliaAdapter = null;
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
$currency1 = new Currency();
|
||||
$currency1->setCode('EUR');
|
||||
$currency2 = new Currency();
|
||||
$currency2->setCode('USD');
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue(array($currency1, $currency2)));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::setValidators
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInputOperator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForEveryone($stubFacade);
|
||||
$operators = array();
|
||||
$values = array();
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if condition is always matching
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::isMatching
|
||||
*
|
||||
*/
|
||||
public function testIsMatching()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForEveryone($stubFacade);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual = $isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Everybody can use it (no condition)');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForEveryone($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Everybody can use it (no condition)';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Will return always true');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForEveryone($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Will return always true';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::generateInputs
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryone::setValidatorsFromForm
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForEveryone($stubFacade);
|
||||
$actual1 = $condition1->setValidatorsFromForm(array(), array());
|
||||
$expected1 = $condition1;
|
||||
$actual2 = $condition1->getValidators();
|
||||
|
||||
$validators = array();
|
||||
$validators['inputs'] = array();
|
||||
$validators['setOperators'] = array();
|
||||
$validators['setValues'] = array();
|
||||
$expected2 = $validators;
|
||||
|
||||
$this->assertEquals($expected1, $actual1);
|
||||
$this->assertEquals($expected2, $actual2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,946 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionCollection;
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\Implementation\MatchForTotalAmount;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Unit Test MatchForTotalAmount Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var FacadeInterface $stubTheliaAdapter */
|
||||
protected $stubTheliaAdapter = null;
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalTaxPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currency1 = new Currency();
|
||||
$currency1->setCode('EUR');
|
||||
$currency2 = new Currency();
|
||||
$currency2->setCode('USD');
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue(array($currency1, $currency2)));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::IN,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => '400',
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator2()
|
||||
{
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => '400',
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 'X',
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue2()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'FLA');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionInferior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionInferior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionInferiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionInferiorEquals2()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionInferiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(401, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test equals operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionEqual()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test equals operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionEqual()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionSuperiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(401, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionSuperiorEquals2()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionSuperiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionSuperior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(401, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionSuperior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check currency is checked
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingConditionCurrency()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check currency is checked
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingConditionCurrency()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateAdapterStub(400.00, 'EUR');
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'USD');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check unknown currency
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ConditionAbstract::isCurrencyValid
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testUnknownCurrencyCode()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'UNK');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $condition1;
|
||||
|
||||
$serialized = $conditionFactory->serializeConditionCollection($collection);
|
||||
$conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invalid currency
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ConditionAbstract::isPriceValid
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testInvalidCurrencyValue()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 'notfloat',
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $condition1;
|
||||
|
||||
$serialized = $conditionFactory->serializeConditionCollection($collection);
|
||||
$conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invalid currency
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\ConditionAbstract::isPriceValid
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testPriceAsZero()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 0.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
$collection[] = $condition1;
|
||||
|
||||
$serialized = $conditionFactory->serializeConditionCollection($collection);
|
||||
$conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
$currency1 = new Currency();
|
||||
$currency1->setCode('EUR');
|
||||
$currency2 = new Currency();
|
||||
$currency2->setCode('USD');
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue(array($currency1, $currency2)));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Cart total amount');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Cart total amount';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'If cart total amount is <strong>%operator%</strong> %amount% %currency%');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'If cart total amount is <strong>%operator%</strong> %amount% %currency%';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForTotalAmount($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
|
||||
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmount::CART_TOTAL => 400.00,
|
||||
MatchForTotalAmount::CART_CURRENCY => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
MatchForTotalAmount::CART_TOTAL => array(
|
||||
'availableOperators' => array(
|
||||
'<' => 'Price',
|
||||
'<=' => 'Price',
|
||||
'==' => 'Price',
|
||||
'>=' => 'Price',
|
||||
'>' => 'Price'
|
||||
),
|
||||
'availableValues' => '',
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
),
|
||||
MatchForTotalAmount::CART_CURRENCY => array(
|
||||
'availableOperators' => array('==' => 'Price'),
|
||||
'availableValues' => array(
|
||||
'EUR' => '€',
|
||||
'USD' => '$',
|
||||
'GBP' => '£',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => Operators::EQUAL
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'price' => '==',
|
||||
'currency' => '=='
|
||||
),
|
||||
'setValues' => array(
|
||||
'price' => 400,
|
||||
'currency' => 'EUR'
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,716 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
|
||||
/**
|
||||
* Unit Test MatchForXArticles Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 5
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 'X'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 5
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4,
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL,
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 5,
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals2()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 3
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test equals operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test equals operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleEqual()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 5
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals2()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 3
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperiorEquals()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 5
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 3
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test superior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperior()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'If cart products quantity is <strong>superior to</strong> 4');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'If cart products quantity is <strong>superior to</strong> 4';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticles::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new MatchForXArticles($stubFacade);
|
||||
$operators = array(
|
||||
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticles::CART_QUANTITY => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
MatchForXArticles::CART_QUANTITY => array(
|
||||
'availableOperators' => array(
|
||||
'<' => 'Price',
|
||||
'<=' => 'Price',
|
||||
'==' => 'Price',
|
||||
'>=' => 'Price',
|
||||
'>' => 'Price'
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => ''
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'quantity' => '>'
|
||||
),
|
||||
'setValues' => array(
|
||||
'quantity' => 4
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\FacadeInterface;
|
||||
use Thelia\Model\Address;
|
||||
use Thelia\Model\Lang;
|
||||
|
||||
/**
|
||||
* @package Coupon
|
||||
* @author Franck Allimant <franck@cqfdev.fr>
|
||||
*/
|
||||
class StartDateTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public $startDate;
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->startDate = time() - 2000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
* @param string $i18nOutput Output from each translation
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||
{
|
||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$address = new Address();
|
||||
$address->setCountryId(10);
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getDeliveryAddress')
|
||||
->will($this->returnValue($address));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnValue($i18nOutput));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
|
||||
$lang = new Lang();
|
||||
$lang->setDateFormat("d/m/Y");
|
||||
|
||||
$stubSession = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Session\Session')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubSession->expects($this->any())
|
||||
->method('getLang')
|
||||
->will($this->returnValue($lang));
|
||||
|
||||
$stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubRequest->expects($this->any())
|
||||
->method('getSession')
|
||||
->will($this->returnValue($stubSession));
|
||||
|
||||
$stubFacade->expects($this->any())
|
||||
->method('getRequest')
|
||||
->will($this->returnValue($stubRequest));
|
||||
|
||||
return $stubFacade;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
StartDate::START_DATE => 'petite licorne'
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => $this->startDate
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
$operators = array(
|
||||
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => 'petit poney'
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
$operators = array(
|
||||
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => $this->startDate
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatching()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => time() + 2000
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$stubFacade = $this->generateFacadeStub();
|
||||
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => $this->startDate
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check getName i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::getName
|
||||
*
|
||||
*/
|
||||
public function testGetName()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$actual = $condition1->getName();
|
||||
$expected = 'Number of articles in cart';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check tooltip i18n
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::getToolTip
|
||||
*
|
||||
*/
|
||||
public function testGetToolTip()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$actual = $condition1->getToolTip();
|
||||
$expected = 'Sample coupon condition';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check validator
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\StartDate::generateInputs
|
||||
*
|
||||
*/
|
||||
public function testGetValidator()
|
||||
{
|
||||
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
|
||||
|
||||
/** @var FacadeInterface $stubFacade */
|
||||
$condition1 = new StartDate($stubFacade);
|
||||
|
||||
$operators = array(
|
||||
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
StartDate::START_DATE => $this->startDate
|
||||
);
|
||||
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$actual = $condition1->getValidators();
|
||||
|
||||
$validators = array(
|
||||
'inputs' => array(
|
||||
StartDate::START_DATE => array(
|
||||
'availableOperators' => array(
|
||||
'>=' => 'Price',
|
||||
),
|
||||
'value' => '',
|
||||
'selectedOperator' => '>='
|
||||
)
|
||||
),
|
||||
'setOperators' => array(
|
||||
'start_date' => '>='
|
||||
),
|
||||
'setValues' => array(
|
||||
'start_date' => $this->startDate
|
||||
)
|
||||
);
|
||||
$expected = $validators;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
}
|
||||
96
tests/phpunit/Thelia/Tests/Condition/OperatorsTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Unit Test Operators Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
public function testOperatorI18n()
|
||||
{
|
||||
/** @var Translator $stubTranslator */
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubTranslator->expects($this->any())
|
||||
->method('trans')
|
||||
->will($this->returnCallback((array($this, 'callbackI18n'))));
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR);
|
||||
$expected = 'Less than';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL);
|
||||
$expected = 'Less than or equals';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::EQUAL);
|
||||
$expected = 'Equal to';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL);
|
||||
$expected = 'Greater than or equals';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR);
|
||||
$expected = 'Greater than';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT);
|
||||
$expected = 'Not equal to';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::IN);
|
||||
$expected = 'In';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
|
||||
$expected = 'Not in';
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = Operators::getI18n($stubTranslator, 'unexpected operator');
|
||||
$expected = 'unexpected operator';
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
public function callbackI18n()
|
||||
{
|
||||
$args = func_get_args();
|
||||
|
||||
return $args[0];
|
||||
}
|
||||
}
|
||||
280
tests/phpunit/Thelia/Tests/Config/RoutesConfigTest.php
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Config;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Routing\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Core\Controller\ControllerResolver;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\Template\ParserContext;
|
||||
use Thelia\Core\Template\TheliaTemplateHelper;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
use TheliaSmarty\Template\SmartyParser;
|
||||
|
||||
/**
|
||||
* Check the core and front routing files.
|
||||
*
|
||||
* @author Baptiste Cabarrou <bcabarrou@openstudio.fr>
|
||||
*/
|
||||
class RoutesConfigTest extends ContainerAwareTestCase
|
||||
{
|
||||
/**
|
||||
* Path to the routing files XSD.
|
||||
* @var string
|
||||
*/
|
||||
protected static $routingXSDPath;
|
||||
|
||||
/**
|
||||
* Path to the core (admin + api) routing files.
|
||||
* @var string
|
||||
*/
|
||||
protected static $routingFilesPathCore;
|
||||
|
||||
/**
|
||||
* Path to the front routing files.
|
||||
* @var string
|
||||
*/
|
||||
protected static $routingFilesPathFront;
|
||||
|
||||
/**
|
||||
* Routing files paths => [routing files names].
|
||||
* @var array
|
||||
*/
|
||||
protected static $routingFiles;
|
||||
|
||||
/**
|
||||
* Routing files paths => file locator for that path.
|
||||
* @var FileLocatorInterface[]
|
||||
*/
|
||||
protected $routerFileLocators;
|
||||
|
||||
/**
|
||||
* Routing files paths => file loader for that path.
|
||||
* @var LoaderInterface[]
|
||||
*/
|
||||
protected $routerFileLoaders;
|
||||
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
}
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
self::$routingXSDPath
|
||||
= THELIA_VENDOR
|
||||
. DS . 'symfony'
|
||||
. DS . 'routing'
|
||||
. DS . 'Loader'
|
||||
. DS . XmlFileLoader::SCHEME_PATH;
|
||||
|
||||
// core files
|
||||
self::$routingFilesPathCore
|
||||
= THELIA_LIB
|
||||
. DS . 'Config'
|
||||
. DS . 'Resources'
|
||||
. DS . 'routing';
|
||||
|
||||
self::$routingFiles[self::$routingFilesPathCore] = [
|
||||
'admin.xml',
|
||||
'api.xml',
|
||||
];
|
||||
|
||||
// front files
|
||||
self::$routingFilesPathFront
|
||||
= THELIA_MODULE_DIR
|
||||
. DS . 'Front'
|
||||
. DS . 'Config';
|
||||
|
||||
self::$routingFiles[self::$routingFilesPathFront] = [
|
||||
'front.xml'
|
||||
];
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
foreach (static::$routingFiles as $filePath => $fileNames) {
|
||||
$this->routerFileLocators[$filePath] = new FileLocator($filePath);
|
||||
$this->routerFileLoaders[$filePath] = new XmlFileLoader($this->routerFileLocators[$filePath]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that there are no duplicate route ids.
|
||||
*/
|
||||
public function testNoDuplicateIds()
|
||||
{
|
||||
$existingIds = [];
|
||||
|
||||
foreach (static::$routingFiles as $filePath => $fileNames) {
|
||||
$routerFileLocator = $this->routerFileLocators[$filePath];
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
$xml = XmlUtils::loadFile(
|
||||
$routerFileLocator->locate($fileName),
|
||||
static::$routingXSDPath
|
||||
);
|
||||
|
||||
foreach ($xml->documentElement->childNodes as $node) {
|
||||
if (!$node instanceof \DOMElement) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($node->localName != 'route') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$id = $node->getAttribute('id');
|
||||
|
||||
$this->assertFalse(in_array($id, $existingIds), "Duplicate route id '$id'.");
|
||||
|
||||
$existingIds[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that there are no obvious duplicate route methods + paths.
|
||||
* Will not catch all duplicates, but should catch most of the common errors.
|
||||
* Can catch some routes that looks like they are conflicting but are not due to disjoint arguments requirements.
|
||||
*/
|
||||
public function testNoDuplicatePaths()
|
||||
{
|
||||
// a map of existing paths => [existing methods for this path]
|
||||
$existingPaths = [];
|
||||
|
||||
foreach (static::$routingFiles as $filePath => $fileNames) {
|
||||
$routerFileLoader = $this->routerFileLoaders[$filePath];
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
$router = new Router($routerFileLoader, $fileName);
|
||||
|
||||
/** @var Route $route */
|
||||
foreach ($router->getRouteCollection() as $route) {
|
||||
$routeMethods = $route->getMethods();
|
||||
if (empty($routeMethods)) {
|
||||
$routeMethods = ['*'];
|
||||
}
|
||||
|
||||
// check for path collision, then method collision
|
||||
$pathsCollide = in_array($route->getPath(), array_keys($existingPaths));
|
||||
|
||||
if ($pathsCollide) {
|
||||
$methodsIntersection = array_intersect($routeMethods, $existingPaths[$route->getPath()]);
|
||||
} else {
|
||||
$methodsIntersection = [];
|
||||
}
|
||||
|
||||
$methodsCollide = !empty($methodsIntersection);
|
||||
|
||||
$this->assertFalse(
|
||||
$pathsCollide && $methodsCollide,
|
||||
"Potentially duplicate route path '"
|
||||
. implode('|', $methodsIntersection)
|
||||
. " "
|
||||
. $route->getPath()
|
||||
. "'."
|
||||
);
|
||||
|
||||
if ($pathsCollide) {
|
||||
$existingPaths[$route->getPath()]
|
||||
= array_merge($existingPaths[$route->getPath()], $routeMethods);
|
||||
} else {
|
||||
$existingPaths[$route->getPath()] = $routeMethods;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that controller methods for the routes are callable.
|
||||
*/
|
||||
public function testTargetControllerMethodsAreCallable()
|
||||
{
|
||||
$controllerResolver = new ControllerResolver($this->getContainer());
|
||||
|
||||
foreach (static::$routingFiles as $filePath => $fileNames) {
|
||||
$routerFileLoader = $this->routerFileLoaders[$filePath];
|
||||
|
||||
foreach ($fileNames as $fileName) {
|
||||
$router = new Router($routerFileLoader, $fileName);
|
||||
|
||||
/** @var Route $route */
|
||||
foreach ($router->getRouteCollection() as $route) {
|
||||
// prepare a dummy request to the controller so that we can check it using the ControllerResolver
|
||||
$request = new Request();
|
||||
$request->attributes->set('_controller', $route->getDefault('_controller'));
|
||||
|
||||
// will throw an exception if the controller method is not callable
|
||||
$controllerResolver->getController($request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that views for the front routes exists.
|
||||
*/
|
||||
public function testTargetFrontViewsExists()
|
||||
{
|
||||
/** @var RequestStack $requestStack */
|
||||
$requestStack = $this->getContainer()->get('request_stack');
|
||||
|
||||
/** @var EventDispatcherInterface $eventDispatcher */
|
||||
$eventDispatcher = $this->getContainer()->get('event_dispatcher');
|
||||
|
||||
// we are not going to do any actual rendering, so a mock ParserContext should be enough
|
||||
/** @var ParserContext $parserContext */
|
||||
$parserContext = $this
|
||||
->getMockBuilder('Thelia\Core\Template\ParserContext')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$templateHelper = new TheliaTemplateHelper();
|
||||
|
||||
$parser = new SmartyParser(
|
||||
$requestStack,
|
||||
$eventDispatcher,
|
||||
$parserContext,
|
||||
$templateHelper
|
||||
);
|
||||
$parser->setTemplateDefinition($templateHelper->getActiveFrontTemplate());
|
||||
|
||||
$frontRouterFileLoader = $this->routerFileLoaders[static::$routingFilesPathFront];
|
||||
|
||||
foreach (static::$routingFiles[static::$routingFilesPathFront] as $fileName) {
|
||||
$router = new Router($frontRouterFileLoader, $fileName);
|
||||
|
||||
/** @var Route $route */
|
||||
foreach ($router->getRouteCollection() as $route) {
|
||||
if (null === $view = $route->getDefault('_view')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->assertTrue(
|
||||
$parser->templateExists($view . '.html'),
|
||||
"Front view '$view' does not exist."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
128
tests/phpunit/Thelia/Tests/ContainerAwareTestCase.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\PropelInitService;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Log\Tlog;
|
||||
|
||||
/**
|
||||
* Class ContainerAwareTestCase
|
||||
* @package Thelia\Tests
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
abstract class ContainerAwareTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $import;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
/** @var Session */
|
||||
protected $session;
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->set("thelia.translator", new Translator(new Container()));
|
||||
|
||||
$dispatcher = $this->getMockEventDispatcher();
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
|
||||
$propelInitService = $this->getMockPropelInitService();
|
||||
|
||||
$container->set('thelia.propel.init', $propelInitService);
|
||||
|
||||
$request = new Request();
|
||||
$request->setSession($this->getSession());
|
||||
|
||||
$container->set("request", $request);
|
||||
|
||||
$requestStack = new RequestStack();
|
||||
|
||||
$requestStack->push($request);
|
||||
|
||||
$container->set("request_stack", $requestStack);
|
||||
|
||||
$container->set("kernel", $this->getKernel());
|
||||
|
||||
new Translator($container);
|
||||
$container->set("thelia.securitycontext", new SecurityContext($requestStack));
|
||||
|
||||
$this->buildContainer($container);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
public function getSession()
|
||||
{
|
||||
return new Session(new MockArraySessionStorage());
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
Tlog::getNewInstance();
|
||||
|
||||
$this->session = $this->getSession();
|
||||
$this->container = $this->getContainer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
abstract protected function buildContainer(ContainerBuilder $container);
|
||||
|
||||
/**
|
||||
* @return EventDispatcherInterface
|
||||
*/
|
||||
protected function getMockEventDispatcher()
|
||||
{
|
||||
return $this->createMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PropelInitService
|
||||
*/
|
||||
protected function getMockPropelInitService()
|
||||
{
|
||||
return $this->createMock(PropelInitService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return KernelInterface
|
||||
*/
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->createMock("\Thelia\Core\Thelia");
|
||||
|
||||
// Stub propel initialization service
|
||||
$kernel
|
||||
->expects($this->any())
|
||||
->method('initializePropelService')
|
||||
;
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
}
|
||||
40
tests/phpunit/Thelia/Tests/Controller/ControllerTestBase.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Thelia\Controller\BaseController;
|
||||
use Thelia\Tests\ContainerAwareTestCase;
|
||||
|
||||
/**
|
||||
* Class ControllerTestBase
|
||||
* @package Thelia\Tests\ImportExport\Import
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
abstract class ControllerTestBase extends ContainerAwareTestCase
|
||||
{
|
||||
/** @var BaseController */
|
||||
protected $controller;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->controller = $this->getController();
|
||||
$this->controller->setContainer($this->container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Controller\BaseController The controller you want to test
|
||||
*/
|
||||
abstract protected function getController();
|
||||
}
|
||||
100
tests/phpunit/Thelia/Tests/Controller/DefaultControllerTest.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Controller\Front\DefaultController;
|
||||
|
||||
/**
|
||||
* Class DefaultControllerTest
|
||||
* @package Thelia\Tests\Controller
|
||||
* @author Manuel Raynaud <manu@raynaud.io>
|
||||
*/
|
||||
class DefaultControllerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testNoAction()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request();
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), "index");
|
||||
}
|
||||
|
||||
public function testNoActionWithGetParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(array(
|
||||
"view" => "foo"
|
||||
));
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithPostParam()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttribute()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'foo');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndQuery()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array("view" => "bar"),
|
||||
array(),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
|
||||
public function testNoActionWithAttributeAndRequest()
|
||||
{
|
||||
$defaultController = new DefaultController();
|
||||
$request = new Request(
|
||||
array(),
|
||||
array("view" => "bar"),
|
||||
array("_view" => "foo")
|
||||
);
|
||||
|
||||
$defaultController->noAction($request);
|
||||
|
||||
$this->assertEquals($request->attributes->get('_view'), 'bar');
|
||||
}
|
||||
}
|
||||
146
tests/phpunit/Thelia/Tests/Controller/ProductControllerTest.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Tests\Controller;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Controller\Admin\ProductController;
|
||||
use Thelia\Model\ProductDocumentQuery;
|
||||
use Thelia\Model\ProductImageQuery;
|
||||
use Thelia\Model\ProductSaleElementsProductDocumentQuery;
|
||||
use Thelia\Model\ProductSaleElementsProductImageQuery;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
|
||||
/**
|
||||
* Class ProductControllerTest
|
||||
* @package Thelia\Tests\Controller
|
||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||
*/
|
||||
class ProductControllerTest extends ControllerTestBase
|
||||
{
|
||||
/**
|
||||
* Use this method to build the container with the services that you need.
|
||||
*/
|
||||
protected function buildContainer(ContainerBuilder $container)
|
||||
{
|
||||
$parser = $this->getMockBuilder("Thelia\\Core\\Template\\ParserInterface")
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
|
||||
$container->set("thelia.parser", $parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Thelia\Controller\BaseController The controller you want to test
|
||||
*/
|
||||
protected function getController()
|
||||
{
|
||||
$controller = new ProductController();
|
||||
|
||||
return $controller;
|
||||
}
|
||||
|
||||
public function testAssociatePSEImage()
|
||||
{
|
||||
/**
|
||||
* Get a product sale elements which has a related product image
|
||||
*/
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->useProductQuery()
|
||||
->joinProductImage()
|
||||
->endUse()
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this image and check if they are associated
|
||||
*/
|
||||
$productImage = ProductImageQuery::create()
|
||||
->findOneByProductId($pse->getProductId())
|
||||
;
|
||||
|
||||
$association = ProductSaleElementsProductImageQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductImageId($productImage->getId())
|
||||
;
|
||||
|
||||
$isAssociated = $association !== null;
|
||||
|
||||
$this->controller
|
||||
->getAssociationResponseData(
|
||||
$pse->getId(),
|
||||
"image",
|
||||
$productImage->getId()
|
||||
);
|
||||
|
||||
$newAssociation = ProductSaleElementsProductImageQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductImageId($productImage->getId())
|
||||
;
|
||||
|
||||
$isNowAssociated = $newAssociation !== null;
|
||||
|
||||
$this->assertFalse($isAssociated === $isNowAssociated);
|
||||
}
|
||||
|
||||
public function testAssociatePSEDocument()
|
||||
{
|
||||
/**
|
||||
* Get a product sale elements which has a related product image
|
||||
*/
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->useProductQuery()
|
||||
->joinProductDocument()
|
||||
->endUse()
|
||||
->findOne()
|
||||
;
|
||||
|
||||
if (null === $pse) {
|
||||
$this->markTestSkipped("You must have at least one product_sale_elements which has a product_image related to it's product");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this image and check if they are associated
|
||||
*/
|
||||
$productDocument = ProductDocumentQuery::create()
|
||||
->findOneByProductId($pse->getProductId())
|
||||
;
|
||||
|
||||
$association = ProductSaleElementsProductDocumentQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductDocumentId($productDocument->getId())
|
||||
;
|
||||
|
||||
$isAssociated = $association !== null;
|
||||
|
||||
$this->controller
|
||||
->getAssociationResponseData(
|
||||
$pse->getId(),
|
||||
"document",
|
||||
$productDocument->getId()
|
||||
);
|
||||
|
||||
$newAssociation = ProductSaleElementsProductDocumentQuery::create()
|
||||
->filterByProductSaleElements($pse)
|
||||
->findOneByProductDocumentId($productDocument->getId())
|
||||
;
|
||||
|
||||
$isNowAssociated = $newAssociation !== null;
|
||||
|
||||
$this->assertFalse($isAssociated === $isNowAssociated);
|
||||
}
|
||||
}
|
||||
294
tests/phpunit/Thelia/Tests/Core/Archiver/ArchiverManagerTest.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Tests\Core\Archiver;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Core\Archiver\ArchiverManager as SUT;
|
||||
|
||||
/**
|
||||
* Class ArchiverManagerTest
|
||||
* @author Jérôme Billiras <jbilliras@openstudio.fr>
|
||||
*/
|
||||
class ArchiverManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Thelia\Core\Archiver\ArchiverManager
|
||||
*/
|
||||
protected $sut;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $stubArchiver;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->sut = new SUT;
|
||||
$this->stubArchiver = $this->createMock('Thelia\\Core\\Archiver\\ArchiverInterface');
|
||||
|
||||
new Translator(new Container);
|
||||
}
|
||||
|
||||
public function testGetArchivers()
|
||||
{
|
||||
$archivers = $this->sut->getArchivers();
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$archivers = $this->sut->getArchivers(true);
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$archivers = $this->sut->getArchivers(false);
|
||||
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
}
|
||||
|
||||
public function testAddArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'add'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertEquals(
|
||||
'Thelia\\Core\\Archiver\\ArchiverInterface',
|
||||
$reflectedParameters[0]->getClass()->getName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3', 'archiver1'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount($i, $archivers);
|
||||
}
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
}
|
||||
|
||||
public function testSetArchiversArgs()
|
||||
{
|
||||
$reflectedParameters = (new \ReflectionMethod($this->sut, 'setArchivers'))->getParameters();
|
||||
|
||||
$this->assertCount(1, $reflectedParameters);
|
||||
$this->assertFalse($reflectedParameters[0]->allowsNull());
|
||||
$this->assertFalse($reflectedParameters[0]->isOptional());
|
||||
$this->assertTrue($reflectedParameters[0]->isArray());
|
||||
}
|
||||
|
||||
public function testSetArchivers()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3', 'archiver4', 'archiver5'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertTrue($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
$this->assertFalse($this->sut->has('archiver5'));
|
||||
|
||||
$this->sut->setArchivers([$this->stubArchiver, $this->stubArchiver]);
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(2, $archivers);
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertTrue($this->sut->has('archiver4'));
|
||||
$this->assertTrue($this->sut->has('archiver5'));
|
||||
|
||||
$this->setExpectedException('Exception');
|
||||
|
||||
$this->sut->setArchivers(['notAnArchiverInterface']);
|
||||
}
|
||||
|
||||
public function testReset()
|
||||
{
|
||||
$this->sut->reset();
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(3, $archivers);
|
||||
|
||||
$this->sut->reset();
|
||||
|
||||
$archivers = $this->sut->getArchivers();
|
||||
$this->assertInternalType('array', $archivers);
|
||||
$this->assertCount(0, $archivers);
|
||||
}
|
||||
|
||||
public function testHas()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('archiver1'))
|
||||
;
|
||||
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has(-1));
|
||||
$this->assertFalse($this->sut->has(0));
|
||||
$this->assertFalse($this->sut->has(1));
|
||||
$this->assertFalse($this->sut->has(null));
|
||||
$this->assertFalse($this->sut->has(true));
|
||||
$this->assertFalse($this->sut->has(false));
|
||||
}
|
||||
|
||||
public function testHasThrowException()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->returnValue('archiver1'))
|
||||
;
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1', true));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->has('archiver2', true);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver3'))
|
||||
;
|
||||
$this->stubArchiver->expects($this->any())->method('isAvailable')->will($this->returnValue(true));
|
||||
|
||||
$unavailableMock = $this->createMock('Thelia\\Core\\Archiver\\ArchiverInterface');
|
||||
$unavailableMock->expects($this->any())->method('getId')->will($this->returnValue('archiver2'));
|
||||
$unavailableMock->expects($this->any())->method('isAvailable')->will($this->returnValue(false));
|
||||
|
||||
$this->sut->add($this->stubArchiver);
|
||||
$this->sut->add($this->stubArchiver);
|
||||
$this->sut->add($unavailableMock);
|
||||
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2'));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3'));
|
||||
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1', true));
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2', true));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3', true));
|
||||
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver1', false));
|
||||
$this->assertInstanceOf('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver2', false));
|
||||
$this->isNull('Thelia\\Core\\Archiver\\ArchiverInterface', $this->sut->get('archiver3', false));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->get('archiver4');
|
||||
}
|
||||
|
||||
public function testRemove()
|
||||
{
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->stubArchiver
|
||||
->expects($this->any())
|
||||
->method('getId')
|
||||
->will($this->onConsecutiveCalls('archiver1', 'archiver2', 'archiver3'))
|
||||
;
|
||||
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$this->sut->add($this->stubArchiver);
|
||||
}
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertTrue($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->sut->remove('archiver2');
|
||||
|
||||
$this->assertTrue($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertTrue($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->sut->remove('archiver1');
|
||||
$this->sut->remove('archiver3');
|
||||
|
||||
$this->assertFalse($this->sut->has('archiver1'));
|
||||
$this->assertFalse($this->sut->has('archiver2'));
|
||||
$this->assertFalse($this->sut->has('archiver3'));
|
||||
$this->assertFalse($this->sut->has('archiver4'));
|
||||
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
|
||||
$this->sut->remove('archiver4');
|
||||
}
|
||||
}
|
||||