Remove unwanted files

This commit is contained in:
Abhishek Kumar
2023-04-12 17:43:57 +05:30
parent 90f317b54b
commit 7078aebef0
5 changed files with 1 additions and 866 deletions

View File

@@ -1,418 +0,0 @@
GitHub contributors:
--------------------------------
- (d)oekia
- 123monsite-regis
- 1RV34
- Adonis Karavokyros
- Adrien
- Adrien Astier
- Agence CINS
- Aleksander Palyan
- Alessandro Corbelli
- Alex Even
- Alexander Grosul
- Alexander Otchenashev
- Alexandra Even
- AlexEven
- Alexey Svistunov
- alexey-svistunov
- alexsimple
- Alfakom-MK
- Alfonso Jimenez
- Alphacom IT Solutions - Macedonia
- amatosg
- anat
- Anatole
- Andrew
- Antonino Di Bella
- antoniofr
- AntonLejon
- Arnaud Lemercier
- axi
- Axome
- Balestrino
- bellini13
- Benjamin PONGY
- bercik999
- Bersam Karbasion
- BigZ
- BluTiGeS
- Bruno Desprez
- Bruno Leveque
- bumbu
- Burhan
- Caleydon Media
- cam.lafit
- Captain FLAM
- Captain-FLAM
- ccauw
- cedricfontaine
- cedricgeffroy
- Chen.Zhidong
- Chris
- Chris Gurk
- ChristopheBoucaut
- CINS
- cippest
- Claire Meuriot
- cmouleyre
- codvir
- Comkwatt
- Conner Burnett
- Corentin Delcourt
- Cosmin Hutanu
- Cedric Mouleyre
- damien
- Damien Metzger
- Damien PIQUET
- DamienMetzger
- Damon Skelhorn
- Dan Hlavenka
- danidomen
- Daniel
- Daniele Giachino
- danoosh
- Danoosh Mir
- David Gasperoni
- David Sivocha
- David-Julian BUCH
- Davy Rolink
- Denver Prophit Jr.
- Desbouche Christophe
- DevNet
- Dh42
- Dimitrios Karvounaris
- Dinis Lage
- djbuch
- djfm
- dlage
- doekia
- DOEO
- Dragan Skrbic
- Dream me up
- dreammeup
- DrySs
- DrySs'
- dSevere
- Dustin
- Dvir Julius
- Dvir-Julius
- edamart
- Edouard Gaulue
- el-tenkova
- elationbase
- eleazar
- Elitius
- Emilien Puget
- emilien-puget
- emily-d
- Eolia
- Eric Le Lay
- Eric Rouvier
- erickturcios
- Etienne Samson
- Fabio Chelly
- fchellypresta
- Felipe Uribe
- fetis
- fird
- flashmaestro
- Florian Kwakkenbos
- fram
- Francois Gaillard
- Francois-Marie de Jouvencel
- François Gaillard
- Frederic BENOIST
- Gabriel Schwardy
- Gaelle ITZKOVITZ
- Gamesh
- ggedamed
- Giant Leap Lab
- Gordon Coubrough
- gr4devel
- Granger Kevin
- Gregory Roussac
- gRoussac
- Gregoire Belorgey
- gskema
- Guillaume DELOINCE
- Guillaume Lafarge
- Guillaume Leseur
- Gytis
- Gytis SkÄ—ma
- Ha!*!*y
- ha99y
- hadjedjvincent
- harelguy
- hiousi
- htrex
- indesign47
- iNem0o
- ironwo0d
- ITBpro.com
- Ivan
- ivancasasempere
- J. Danse
- janisVincent
- Javsmile
- JEAN
- jeanbe
- jeckyl
- Jeroen Dewaele
- Jerome Nadaud
- jeromenadaud
- jessylenne
- Joan
- Joan Juvanteny
- joce
- Joe Siwiak
- joemartin247
- Joep Hendrix
- Jonadabe
- Jonathan Danse
- Jonathan SAHM
- Jorge Vargas
- joseantgv
- jtogrul
- Julien
- Julien Bouchez
- Julien Bourdeau
- Julien Deniau
- Julien Martin
- julienbourdeau
- julvernois
- Jachym Tousek
- Kamil Szymański
- Kelly Karnetsky
- kermes
- Kevin Granger
- Kijam Lopez
- kiropowered
- kpodemski
- Krystian Podemski
- Kevin Dunglas
- Ladel
- ldecoker
- Lesley Paone
- LOIC ROSSET ltd
- luc
- Luc Vandesype
- Luca T.
- Lucas CERDAN
- LucasC
- Lyo Nick
- LyoNick
- Leo
- M-Mommsen
- Madef
- Madman
- Mainmich
- makk1ntosh
- manuelbcd
- marcinsz101
- Marco Cervellin
- Marcos
- matiasiglesias
- Mats Rynge
- Matteo
- MatthieuB
- MaX3315
- Maxence
- Maxime
- Maxime Biloe
- Maxime Vasse
- mchelh
- mchojnacki
- mdomenjoud
- Michael Hjulskov
- Michel Courtade
- Mickael Desgranges
- Mikael Blotin
- Mikko Hellsing
- Milow
- Mingsong Hu
- minic studio
- misthero
- moncef102
- montes
- mplh
- MustangZhong
- natrim
- neemzy
- nezenmoins
- Nicolas Sorosac
- Niklas Ekman
- Niko Wicaksono
- Nils-Helge Garli Hegvik
- NinjaOfWeb
- Nino Uzelac
- nodexpl
- nturato
- oleacorner
- Otto Nascarella
- Pan P
- Pan P.
- Pan Ploenes
- Panagiotis Tigas
- panesarsandeep
- Patanock
- Patrick Mettraux
- Pavel Novitsky
- pbirnzain
- Pedro J. Parra
- Per Lejontand
- Peter Schaeffer
- peterept
- Petyuska
- PhpMadman
- Pierre
- Piotr Kaczor
- Piotr Moćko
- Presta Module
- PrestaEdit
- PrestaLab
- prestamodule
- PrestanceDesign
- prestarocket
- Prestaspirit
- Priyank Bolia
- Profileo
- Pronux
- proydsl
- pxls
- quadrateam
- Quentin Leonetti
- Quentin Montant
- Quentin MONTANT - KIWIK
- Quetzacoalt91
- Racochejl
- Rafael Cunha
- Raphael Malie
- raulgundin
- rGaillard
- Rhys
- Richard LT
- Rimas Kudelis
- robert
- Roland Schütz
- romainberger
- runningz
- Remi Gaillard
- s-duval
- Sacha
- Sacha FROMENT
- sadlyblue
- sagaradonis
- Sam Sanchez
- Samir Shah
- Samy Rabih
- Sarah Lorenzini
- Seb
- SebSept
- Seynaeve
- sfroment42
- shaffe-fr
- Shagshag
- Shipow
- Shudrum
- sidhujag
- sjousse
- sLorenzini
- smartdatasoft
- snamor
- soufyan
- soware
- Staging
- Stanislav Yordanov
- Stefano Kowalke
- Stephan Obadia
- Steven "SDF" Sulley
- Steven Sulley
- Studio Kiwik
- Sumh
- svensson_david
- Sylvain Gougouzian
- Sylvain WITMEYER
- Sebastien
- Sebastien Bareyre
- Sebastien Bocahu
- Sebastien Monterisi
- Tanguy JACQUET
- tchauviere
- Thibaud Chauviere
- thoma202
- Thomas
- Thomas Blanc
- Thomas N
- Thomas Nabord
- thomas-aw
- Threef
- timsit
- tmackay
- TMMeilleur
- Tom Panier
- Tomasz Slominski
- Tomas Votruba
- tucoinfo
- Tung Dao
- unlocomqx
- Valerii Savchenko
- vAugagneur
- Vincent Augagneur
- Vincent Schoener
- Vincent Terenti
- vinvin27
- vinzter
- vitekj
- Wayann
- web-plus
- webbax
- Wojciech Grzebieniowski
- Xavier
- Xavier Borderie
- Xavier Gouley
- Xavier POITAU
- xitromedia
- xKnut
- yanngarras
- Yoozio
- zimmi1
- ZiZuu.com
- Zollner Robert
SVN contributors:
--------------------------------
- aFolletete
- aKorczak
- aNiassy
- bLeveque
- bMancone
- dMetzger
- dSevere
- fBrignoli
- Francois Gaillard
- fSerny
- gBrunier
- gCharmes
- gPoulain
- hAitmansour
- jBreux
- jmCollin
- jObregon
- lBrieu
- lCherifi
- lLefevre
- mBertholino
- mDeflotte
- mMarinetti
- nPellicari
- rGaillard
- rMalie
- rMontagne
- sLorenzini
- sThiebaut
- tDidierjean
- vAugagneur
- vChabot
- vKham
- vSchoener

View File

@@ -26,7 +26,7 @@
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', getcwd());
}
require_once(_PS_ADMIN_DIR_.'/../images.inc.php');
function bindDatepicker($id, $time)
{
if ($time) {

View File

@@ -1,276 +0,0 @@
# Making PrestaShop Unit Testable
*An adventure in dependency breaking - guidelines and proposals*
We have tasked ourselves with an interesting challenge:
to make one of the core business functions in PrestaShop unit testable. The function we chose, `Cart::getOrderTotal`, performs price computations in the shopping cart - it's the one that tells your customers how much they're going to pay. That's kind of useful.
We chose to focus on this function because it is large and complex enough to demonstrate a number of different techniques.
This post shows our progress and leads to a proposal for a new software architecture for PrestaShop. The new architecture is intended to be lightweight and safe.
## Where we Started From
*The issues with `Cart::getOrderTotal`*
`Cart::getOrderTotal` is a ~300 lines long instance method. It makes it hard to reason about.
You cannot instantiate a `Cart` object to test the `getOrderTotal` method because the constructor indirectly accesses the database.
To make things even more interesting, the method makes static calls to methods on at least three different classes: `Configuration`, `Address`, `Product`.
A large number of execution paths are conditioned on the value of different global variables that `getOrderTotal` accesses implicitly.
## Our Goal
We set out to write a **meaningful** unit test on `Cart::getOrderTotal`.
Before we dive into the changes we had to make, here is a preview of the end result - one of the unit tests we were able to write:
```php
public function test_getOrderTotal_Round_Line_When_No_Tax()
{
$this->setRoundType(Order::ROUND_LINE);
// Add 3 products each with (pre-tax) price 10.125
$this->productPriceCalculator->addFakeProduct(new FakeProduct(3, 10.125));
// Add 1 product with (pre-tax) price 10.125
$this->productPriceCalculator->addFakeProduct(new FakeProduct(1, 10.125));
$orderTotal = $this->cart->getOrderTotal(false, Cart::ONLY_PRODUCTS, $this->productPriceCalculator->getProducts());
$this->assertEquals(40.51, $orderTotal);
}
```
This test simulates adding 4 products to the cart and checks that `getOrderTotal` produces the expected total before tax.
The test does not make any access to the database.
## The Techniques we Used and When to Use Them
In this chapter we try to put a name on different techniques we have used and extract guidelines about the cases in which we believe they are appropriate.
### Application Singleton Injection
This technique is one of the least intrusive. The problem it tries to solve is: there is a static access to an application singleton deeply nested in some code that we do not care about for the purpose of our test.
In our case the `Db` class was accessed indirectly upon instantiation of a `Cart` object though a sequence of calls leading to a static access to `Group` that performs actions that have nothing to do with the computation of the total of the Cart.
We could have gone deep into the call stack and broken the dependency to the database there, directly in `Group`.
But it might have been dangerous: we would have had to change code that we did not intend to test.
So to keep things simple and not lose focus on `getOrderTotal` we just mocked the whole `Db` instance, injecting it into the application singleton with an ad-hoc static method that was added to `Db`:
```php
public function setupDatabaseMock()
{
$this->database = Phake::mock('Db');
Db::setInstanceForTesting($this->database);
}
```
And `setInstanceForTesting` is straightforward:
```php
class Db
{
/*
...
*/
/**
* @param $test_db Db
* Unit testing purpose only
*/
public static function setInstanceForTesting($test_db)
{
self::$instance[0] = $test_db;
}
/*
...
*/
}
```
Note the *ForTesting* suffix: it warns developers not to use this in production code. This is only a test helper.
The exact same technique is used to inject a fake context into the `Context` application singleton.
The boilerplate code for this is factored out into the [`UnitTestCase::setup`](tests/TestCase/UnitTestCase.php) method so that the next tests are easier to write.
Great, now we can instantiate a `Cart` object (`new` it)!
### ServiceLocator Based Injection
This technique solves the same type of issues as the Application Singleton Injection does. It breaks dependencies. The primary difference is that we use it in the code that we are working on. Not deep into the dependency chain.
The goal is to make the previously hidden dependency very visible and to have full control over the component.
Ideally, when we discover a hidden dependency in the code under test, we should find a way to make the dependency trickle down from the top layers of the application right into the code under test.
This is not always possible (when no predictable execution path leads to the code under test for instance), so a temporary solution is is to use a ServiceLocator.
It looks like this:
```php
public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)
{
// Dependencies
$address_factory = Adapter_ServiceLocator::get('Adapter_AddressFactory');
$price_calculator = Adapter_ServiceLocator::get('Adapter_ProductPriceCalculator');
$configuration = Adapter_ServiceLocator::get('Core_Business_Configuration');
// Code...
}
```
On the unit test side, setting up the mocked objects follow this pattern:
```php
$this->container = new Core_Foundation_IoC_Container;
Adapter_ServiceLocator::setServiceContainerInstance($this->container);
$addressFactory = Phake::mock('Adapter_AddressFactory');
$address = new Address;
$address->id = 1;
Phake::when($addressFactory)->findOrCreate()->thenReturn($address);
$this->container->bind('Adapter_AddressFactory', $addressFactory);
```
What's happening here is:
1. We create a Dependency Injection Container instance specifically for our tests
2. We tell the ServiceLocator to fetch dependencies from our container
3. We mock our dependency (`Adapter_AddressFactory` here)
4. We bind the mocked dependency to the ServiceContainer instance
5. In the code under test, the ServiceLocator only talks with our test container and pulls the dependencies we crafted from there
#### But what's this whole `Adapter_*` thing about?
The classes in the `Adapter_` namespace (in the `Adapter` directory) make a bridge between the legacy code (the thing we're trying to write tests on) and the cleaner code (the new things we're going to write, which will *have tests from the start*).
Code from the non-legacy part should only call legacy code through an adapter. Adapters should eventually disappear and be replaced with new, non-legacy code.
Code in an adapter might:
- wrap calls to code in the legacy part
- call new, non-legacy code
As a first step, an Adapter can just use the same code as the legacy part it replaces.
For instance our `Adapter_AddressFactory` class:
```php
<?php
class Adapter_AddressFactory
{
public function findOrCreate($id_address = null, $with_geoloc = false)
{
return call_user_func_array(array('Address', 'initialize'), func_get_args());
}
public function addressExists($id_address)
{
return Address::addressExists($id_address);
}
}
```
It just forwards the calls to existing legacy code.
We replaced a line in `Cart` from:
```php
$address = Address::initialize($id_address, true);
```
to:
```php
$address = $address_factory->findOrCreate($id_address, true);
```
But the same exact code as before is called, which is as safe as can be.
#### Next Steps
Now that our dependencies are safely exposed we have a solid starting point for further work:
if `Adapter_AddressFactory::findOrCreate` does strange things we're not comfortable with, and if we have strong unit tests on the code that uses the adapter, then we can start delegating work from `Adapter_AddressFactory` to non-legacy code instead of using the copy-pasted logic from the legacy code.
# A Proposal for a New Software Architecture
Code falls into one of the following 3 categories
```
PrestaShop/
|-- Core/
| |-- Foundation/
| └-- Business/
|-- Adapter/
└-- *Legacy*/
```
Where `Legacy` is not itself a directory but represents any file or directory in the current file tree that is not in `Core` or `Adapter`.
The purpose of each directory and the interactions between code in the 3 categories are described in the sections below.
## Core
`Core` is for code **covered by unit tests**.
No new class may be added to the `Core` directory if it doesn't have unit tests.
**No global access** to variables (or even constants!) is allowed inside the `Core` directory. This also means, no `ServiceLocator` here.
Dependencies of below-top-level components should be injected by an application layer that is higher up in the layer hierarchy.
The handling of a typical HTTP request might look something like this:
- `index.php`
- loads the system configuration...
- creates a dependency injection container...
- binds general purpose services like the database to the dependency injection container...
- `new`s a `Dispatcher`, passing the container to it
- the `Dispatcher` creates the `Controller` it needs, passing the dependency injection container to it
- the `Controller`
- gets the dependencies it needs from the dependency injection container...
- delegates its work to services (services that it gets from the container or `new`s)...
- sends the response!
As a general rule, in she schema above, the `Controller` is the last application layer which has access to the dependency injection container.
Inside the `Core` directory, `Business` is for business logic (e.g. how do I compute the tax for a product?), while `Foundation` is reserved for general purpose logic (e.g. dependency injection, database interaction). In theory it should be possible to extract any components in `Foundation` to their own composer packages so that other projects could use them.
**Code inside `Core` is not allowed to call code inside `Legacy`**.
## Adapter
`Adapter` is a layer between `Core` and `Legacy`.
Inside `Adapter`, code may call any code from either `Core`, `Adapter` or `Legacy`.
The `Adapter` file hierarchy should eventually go away, so developers are encouraged to use `Core` code as much as possible when writing adapters.
Adapters should be used when we want to break a dependency in the code under test and when breaking the dependency cleanly is too risky.
The life cycle of an adapter is roughly as follows:
- **Debugging / Refactoring Stage**
1. Create `Adapter_SomeService` to break a static dependency to `SomeService` in the code you're working on
- Adapter should be minimal at first - [it might just forward a call to some legacy function](https://github.com/djfm/PrestaShop/commit/42db57be45c299259a28a247db6c62267d3fb671).
2. Use `Adapter_ServiceLocator::get('Adapter_SomeService')` in the code under test to retrieve an instance of the service we depend on
3. Write tests, refactor...
- **Architecture Improvement Stage**: With time and experience, the precise responsibilities of `Adapter_SomeService` have been clearly identified and tested
1. Write a new `Core_SomeService` class inside the `Core` file hierarchy, test it thoroughly
2. Delegate work from `Adapter_SomeService` to `Core_SomeService`, keeping the `Adapter_ServiceLocator::get('Adapter_SomeService')` calls in the code where proper dependency injection is still too hard to do. Propagate the `Core_SomeService` dependency in a better way where possible.
- **Adapter Removal**: At some point, if enough code has been cleaned up, the `Adapter_SomeService` might not be needed any more
1. Remove all calls to `Adapter_ServiceLocator::get('Adapter_SomeService')` and replace them with proper dependency injection
2. Delete `Adapter_SomeService`.
3. Profit!
## Legacy
`Legacy` code is any code that is not inside `Core` or `Adapter`.
Our goal is to gradually move the code from `Legacy` towards `Core`.
As an intermediate step, code in `Legacy` is expected to make heavy use of the `Adapter_ServiceLocator` to break dependencies.

View File

@@ -1127,7 +1127,6 @@ class WebserviceSpecificManagementImagesCore implements WebserviceSpecificManage
throw new WebserviceException(sprintf('The image size is too large (maximum allowed is %d KB)', ($this->imgMaxUploadSize / 1000)), array(72, 400));
}
require_once(_PS_CORE_DIR_.'/images.inc.php');
if ($error = ImageManager::validateUpload($file)) {
throw new WebserviceException('Image upload error : '.$error, array(76, 400));
}

View File

@@ -1,170 +0,0 @@
<?php
/*
* 2007-2017 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2017 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @deprecated 1.5.0
*/
function cacheImage($image, $cacheImage, $size, $imageType = 'jpg', $disableCache = false)
{
Tools::displayAsDeprecated();
return ImageManager::thumbnail($image, $cacheImage, $size, $imageType, $disableCache);
}
/**
* @deprecated 1.5.0
*/
function checkImage($file, $maxFileSize = 0)
{
Tools::displayAsDeprecated();
return ImageManager::validateUpload($file, $maxFileSize);
}
/**
* @deprecated 1.5.0
*/
function checkImageUploadError($file)
{
return ImageManager::getErrorFromCode($file['error']);
}
/**
* @deprecated 1.5.0
*/
function isPicture($file, $types = null)
{
Tools::displayAsDeprecated();
return ImageManager::isRealImage($file['tmp_name'], $file['type'], $types);
}
/**
* @deprecated 1.5.0
*/
function checkIco($file, $maxFileSize = 0)
{
Tools::displayAsDeprecated();
return ImageManager::validateIconUpload($file, $maxFileSize);
}
/**
* @deprecated 1.5.0
*/
function imageResize($sourceFile, $destFile, $destWidth = null, $destHeight = null, $fileType = 'jpg')
{
Tools::displayAsDeprecated();
return ImageManager::resize($sourceFile, $destFile, $destWidth, $destHeight, $fileType);
}
/**
* @deprecated 1.5.0
*/
function imageCut($srcFile, $destFile, $destWidth = null, $destHeight = null, $fileType = 'jpg', $destX = 0, $destY = 0)
{
Tools::displayAsDeprecated();
if (isset($srcFile['tmp_name'])) {
return ImageManager::cut($srcFile['tmp_name'], $destFile, $destWidth, $destHeight, $fileType, $destX, $destY);
}
return false;
}
/**
* @deprecated 1.5.0
*/
function createSrcImage($type, $filename)
{
Tools::displayAsDeprecated();
return ImageManager::create($type, $filename);
}
/**
* @deprecated 1.5.0
*/
function createDestImage($width, $height)
{
Tools::displayAsDeprecated();
return ImageManager::createWhiteImage($width, $height);
}
/**
* @deprecated 1.5.0
*/
function returnDestImage($type, $ressource, $filename)
{
Tools::displayAsDeprecated();
return ImageManager::write($type, $ressource, $filename);
}
/**
* @deprecated 1.5.0
*/
function deleteImage($id_item, $id_image = null)
{
Tools::displayAsDeprecated();
// Category
if (!$id_image) {
$path = _PS_CAT_IMG_DIR_;
$table = 'category';
if (file_exists(_PS_TMP_IMG_DIR_.$table.'_'.$id_item.'.jpg')) {
unlink(_PS_TMP_IMG_DIR_.$table.'_'.$id_item.'.jpg');
}
if (!$id_image and file_exists($path.$id_item.'.jpg')) {
unlink($path.$id_item.'.jpg');
}
/* Auto-generated images */
$imagesTypes = ImageType::getImagesTypes();
foreach ($imagesTypes as $k => $imagesType) {
if (file_exists($path.$id_item.'-'.$imagesType['name'].'.jpg')) {
unlink($path.$id_item.'-'.$imagesType['name'].'.jpg');
}
}
} else {
// Product
$path = _PS_PROD_IMG_DIR_;
$table = 'product';
$image = new Image($id_image);
$image->id_product = $id_item;
if (file_exists($path.$image->getExistingImgPath().'.jpg')) {
unlink($path.$image->getExistingImgPath().'.jpg');
}
/* Auto-generated images */
$imagesTypes = ImageType::getImagesTypes();
foreach ($imagesTypes as $k => $imagesType) {
if (file_exists($path.$image->getExistingImgPath().'-'.$imagesType['name'].'.jpg')) {
unlink($path.$image->getExistingImgPath().'-'.$imagesType['name'].'.jpg');
}
}
}
/* BO "mini" image */
if (file_exists(_PS_TMP_IMG_DIR_.$table.'_mini_'.$id_item.'.jpg')) {
unlink(_PS_TMP_IMG_DIR_.$table.'_mini_'.$id_item.'.jpg');
}
return true;
}