prepare functional test integration

This commit is contained in:
David Große 2020-01-10 11:23:31 +01:00
parent 3ca5c99f27
commit 11081654bb
4 changed files with 173 additions and 0 deletions

1
bin/codecept Symbolic link
View File

@ -0,0 +1 @@
../vendor/bin/codecept

59
bin/test.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
PROGRESS_REPORTER="--ext Codeception\\ProgressReporter\\ProgressReporter"
while getopts ":c" arg; do
case $arg in
# c)lassic reporter
c) PROGRESS_REPORTER="";;
esac
done
printf "### start preparation ###\n"
WORKPATH=$(dirname ${0})
printf ">> workpath is %s\n" ${WORKPATH}
LOG_DIR="${WORKPATH}/../storage/logs/tests"
printf ">> log-dir is %s\n" ${LOG_DIR}
printf ">> create and truncate log dir\n"
mkdir -p ${LOG_DIR}
rm -rf ${LOG_DIR}/*
printf ">> truncate and migrate database\n"
php artisan migrate:fresh --env=testing --quiet
printf "### finish preparation ###\n"
printf "### start tests ###\n"
SUCCESS=1
execSuite() {
${WORKPATH}/../vendor/bin/codecept run ${1} \
${PROGRESS_REPORTER} \
--xml report_${1}.xml ${CODECEPT_OPTIONS} | tee ${LOG_DIR}/tests_${1}.log
if [[ ${PIPESTATUS[0]} -ne 0 ]]
then
SUCCESS=0
fi
}
execSuite unit
execSuite functional
if [[ ${?} -ne 0 ]]
then
SUCCESS=0
fi
printf "### finish tests ###\n"
if [[ ${SUCCESS} -eq 1 ]]
then
printf ">> all tests are \e[01;32mgreen\e[0m\n"
exit 0
else
printf ">> at least one test is \e[01;31mred\e[0m\n"
exit 1
fi

View File

@ -19,6 +19,7 @@
"ext-tokenizer": "*",
"astrotomic/laravel-translatable": "^11.0.0",
"barryvdh/laravel-dompdf": "0.8.3",
"codeception/codeception-progress-reporter": "^1.0",
"doctrine/dbal": "2.9.2",
"fideloper/proxy": "^4.0",
"flynsarmy/db-blade-compiler": "*",

View File

@ -0,0 +1,112 @@
<?php
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
class CustomerCest
{
public function _before(FunctionalTester $I)
{
}
public function updateCustomerProfile(FunctionalTester $I)
{
$customer = $I->loginAsCustomer();
$I->amOnPage('/');
$I->click('Profile');
$I->click('Edit');
$I->selectOption('gender', 'Other');
$I->click('Update Profile');
$I->dontSeeInSource('The old password does not match.');
$I->seeInSource('Profile updated successfully.');
$I->seeRecord(Customer::class, [
'id' => $customer->id,
'gender' => 'Other',
]);
}
public function updateCustomerAddress(FunctionalTester $I)
{
$faker = Faker\Factory::create();
$formCssSelector = '.account-layout > form:nth-child(2)';
$customer = $I->loginAsCustomer();
$I->amOnPage('/');
$I->click('Profile');
$I->click('Address');
$I->click('Add Address');
$fields = [
'company_name' => $faker->company,
'address1[]' => $faker->streetAddress,
'country' => $faker->countryCode,
'state' => $faker->state,
'city' => $faker->city,
'postcode' => $faker->postcode,
'phone' => $faker->phoneNumber,
];
foreach ($fields as $key => $value) {
// the following fields are being rendered via javascript so we ignore them:
if (! in_array($key, [
'country',
'state',
])) {
$selector = 'input[name="' . $key . '"]';
$I->fillField($selector, $value);
}
}
$I->wantTo('Ensure that the company_name field is being displayed');
$I->seeElement('.account-table-content > div:nth-child(2) > input:nth-child(2)');
// we need to use this css selector to hit the correct <form>. There is another one at the
// page header (search)
$I->submitForm($formCssSelector, $fields);
$I->seeInSource('Address have been successfully added.');
$I->seeRecord(CustomerAddress::class, [
'company_name' => $fields['company'],
'address1' => $fields['address1'],
'country' => $fields['country'],
'state' => $fields['state'],
'city' => $fields['city'],
'phone' => $fields['phone'],
'postcode' => $fields['postcode'],
]);
$I->wantTo('Update the created customer address again');
$I->click('Edit');
$oldcompany = $fields['company_name'];
$fields['company_name'] = $faker->company;
$I->submitForm($formCssSelector, $fields);
$I->seeInSource('Address updated successfully.');
$I->dontSeeRecord(CustomerAddress::class, [
'company_name' => $oldcompany,
]);
$I->seeRecord(CustomerAddress::class, [
'company_name' => $fields['company_name'],
'postcode' => $fields['postcode'],
]);
}
}