Working : Fix : Image Management + Document Management
This commit is contained in:
@@ -25,7 +25,6 @@ namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\DocumentDeleteEvent;
|
||||
use Thelia\Core\Event\DocumentEvent;
|
||||
@@ -163,6 +162,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
$model = $event->getModelDocument();
|
||||
|
||||
$nbModifiedLines = $model->save();
|
||||
|
||||
$event->setModelDocument($model);
|
||||
|
||||
if (!$nbModifiedLines) {
|
||||
@@ -202,6 +202,10 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
|
||||
)
|
||||
);
|
||||
|
||||
if (null !== $event->getUploadedFile()) {
|
||||
$event->getModelDocument()->setTitle($event->getUploadedFile()->getClientOriginalName());
|
||||
}
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
// Copy and save file
|
||||
if ($event->getUploadedFile()) {
|
||||
|
||||
@@ -181,9 +181,8 @@ class FileController extends BaseAdminController
|
||||
return new Response('', 404);
|
||||
}
|
||||
|
||||
$defaultTitle = $parentModel->getTitle();
|
||||
$documentModel->setParentId($parentId);
|
||||
$documentModel->setTitle($defaultTitle);
|
||||
$documentModel->setTitle($fileBeingUploaded->getClientOriginalName());
|
||||
|
||||
$documentCreateOrUpdateEvent = new DocumentCreateOrUpdateEvent(
|
||||
$parentType,
|
||||
@@ -292,12 +291,13 @@ class FileController extends BaseAdminController
|
||||
try {
|
||||
$fileManager = new FileManager($this->container);
|
||||
$image = $fileManager->getImageModelQuery($parentType)->findPk($imageId);
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId());
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId(), FileManager::FILE_TYPE_IMAGES);
|
||||
|
||||
return $this->render('image-edit', array(
|
||||
'imageId' => $imageId,
|
||||
'imageType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_IMAGES)
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->pageNotFound();
|
||||
@@ -320,12 +320,13 @@ class FileController extends BaseAdminController
|
||||
try {
|
||||
$fileManager = new FileManager($this->container);
|
||||
$document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId);
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $document->getParentId());
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $document->getParentId(), FileManager::FILE_TYPE_DOCUMENTS);
|
||||
|
||||
return $this->render('document-edit', array(
|
||||
'documentId' => $documentId,
|
||||
'documentType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_DOCUMENTS)
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
$this->pageNotFound();
|
||||
@@ -399,9 +400,13 @@ class FileController extends BaseAdminController
|
||||
->setGeneralError($message);
|
||||
}
|
||||
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId(), FileManager::FILE_TYPE_IMAGES);
|
||||
|
||||
return $this->render('image-edit', array(
|
||||
'imageId' => $imageId,
|
||||
'imageType' => $parentType
|
||||
'imageType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_IMAGES)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -415,14 +420,14 @@ class FileController extends BaseAdminController
|
||||
*/
|
||||
public function updateDocumentAction($documentId, $parentType)
|
||||
{
|
||||
if (null !== $response = $this->checkAuth('admin.image.update')) {
|
||||
if (null !== $response = $this->checkAuth('admin.document.update')) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$message = false;
|
||||
|
||||
$fileManager = new FileManager($this->container);
|
||||
$documentModification = $fileManager->getImageForm($parentType, $this->getRequest());
|
||||
$documentModification = $fileManager->getDocumentForm($parentType, $this->getRequest());
|
||||
|
||||
try {
|
||||
$document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId);
|
||||
@@ -433,8 +438,8 @@ class FileController extends BaseAdminController
|
||||
|
||||
$form = $this->validateForm($documentModification);
|
||||
|
||||
$event = $this->createImageEventInstance($parentType, $document, $form->getData());
|
||||
$event->setOldModelImage($oldDocument);
|
||||
$event = $this->createDocumentEventInstance($parentType, $document, $form->getData());
|
||||
$event->setOldModelDocument($oldDocument);
|
||||
|
||||
$files = $this->getRequest()->files;
|
||||
$fileForm = $files->get($documentModification->getName());
|
||||
@@ -444,7 +449,7 @@ class FileController extends BaseAdminController
|
||||
|
||||
$this->dispatch(TheliaEvents::DOCUMENT_UPDATE, $event);
|
||||
|
||||
$documentUpdated = $event->getModelImage();
|
||||
$documentUpdated = $event->getModelDocument();
|
||||
|
||||
$this->adminLogAppend(sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId()));
|
||||
|
||||
@@ -472,9 +477,13 @@ class FileController extends BaseAdminController
|
||||
->setGeneralError($message);
|
||||
}
|
||||
|
||||
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $document->getParentId(), FileManager::FILE_TYPE_DOCUMENTS);
|
||||
|
||||
return $this->render('document-edit', array(
|
||||
'documentId' => $documentId,
|
||||
'documentType' => $parentType
|
||||
'documentType' => $parentType,
|
||||
'redirectUrl' => $redirectUrl,
|
||||
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_DOCUMENTS)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -640,7 +649,7 @@ class FileController extends BaseAdminController
|
||||
* @param CategoryDocument|ProductDocument|ContentDocument|FolderDocument $model Document model
|
||||
* @param array $data Post data
|
||||
*
|
||||
* @return ImageCreateOrUpdateEvent
|
||||
* @return DocumentCreateOrUpdateEvent
|
||||
*/
|
||||
protected function createDocumentEventInstance($parentType, $model, $data)
|
||||
{
|
||||
|
||||
@@ -56,7 +56,7 @@ class DocumentDeleteEvent extends ActionEvent
|
||||
*/
|
||||
public function __construct($documentToDelete, $documentType)
|
||||
{
|
||||
$this->imageToDelete = $documentToDelete;
|
||||
$this->documentToDelete = $documentToDelete;
|
||||
$this->documentType = $documentType;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ class DocumentDeleteEvent extends ActionEvent
|
||||
*/
|
||||
public function setDocumentToDelete($documentToDelete)
|
||||
{
|
||||
$this->imageToDelete = $documentToDelete;
|
||||
$this->documentToDelete = $documentToDelete;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -443,6 +443,48 @@ class FileManager
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get form service id from type
|
||||
*
|
||||
* @param string $parentType
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @todo refactor make all documents using propel inheritance and factorise image behaviour into one single clean action
|
||||
*/
|
||||
public function getFormId($parentType, $fileType)
|
||||
{
|
||||
switch ($fileType) {
|
||||
case self::FILE_TYPE_IMAGES:
|
||||
$type = 'image';
|
||||
break;
|
||||
case self::FILE_TYPE_DOCUMENTS:
|
||||
$type = 'document';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($parentType) {
|
||||
case self::TYPE_PRODUCT:
|
||||
$formId = 'thelia.admin.product.' . $type . '.modification';
|
||||
break;
|
||||
case self::TYPE_CATEGORY:
|
||||
$formId = 'thelia.admin.category.' . $type . '.modification';
|
||||
break;
|
||||
case self::TYPE_CONTENT:
|
||||
$formId = 'thelia.admin.content.' . $type . '.modification';
|
||||
break;
|
||||
case self::TYPE_FOLDER:
|
||||
$formId = 'thelia.admin.folder.' . $type . '.modification';
|
||||
break;
|
||||
default:
|
||||
$formId = false;
|
||||
}
|
||||
|
||||
return $formId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image parent model from type
|
||||
*
|
||||
@@ -577,24 +619,30 @@ class FileManager
|
||||
/**
|
||||
* Deduce image redirecting URL from parent type
|
||||
*
|
||||
* @param string $parentType Parent type
|
||||
* @param string $parentType Parent type ex : self::TYPE_PRODUCT
|
||||
* @param int $parentId Parent id
|
||||
* @param string $fileType File type ex : self::FILE_TYPE_DOCUMENTS
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRedirectionUrl($parentType, $parentId)
|
||||
public function getRedirectionUrl($parentType, $parentId, $fileType)
|
||||
{
|
||||
if (!in_array($fileType, self::$availableFileType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($parentType) {
|
||||
case self::TYPE_PRODUCT:
|
||||
$uri = '/admin/products/update?product_id=' . $parentId . '¤t_tab=images';
|
||||
$uri = '/admin/products/update?product_id=' . $parentId . '¤t_tab=' . $fileType;
|
||||
break;
|
||||
case self::TYPE_CATEGORY:
|
||||
$uri = '/admin/categories/update?category_id=' . $parentId . '¤t_tab=images';
|
||||
$uri = '/admin/categories/update?category_id=' . $parentId . '¤t_tab=' . $fileType;
|
||||
break;
|
||||
case self::TYPE_CONTENT:
|
||||
$uri = '/admin/content/update/' . $parentId . '¤t_tab=images';
|
||||
$uri = '/admin/content/update/' . $parentId . '?current_tab=' . $fileType;
|
||||
break;
|
||||
case self::TYPE_FOLDER:
|
||||
$uri = '/admin/folders/update/' . $parentId . '¤t_tab=images';
|
||||
$uri = '/admin/folders/update/' . $parentId . '?current_tab=' . $fileType;
|
||||
break;
|
||||
default:
|
||||
$uri = false;
|
||||
|
||||
@@ -8,6 +8,8 @@ $(function($){
|
||||
|
||||
// Remove image on click
|
||||
$.documentUploadManager.initDocumentDropZone = function() {
|
||||
$.documentUploadManager.onClickDeleteDocument();
|
||||
|
||||
var documentDropzone = new Dropzone("#documents-dropzone", {
|
||||
dictDefaultMessage : $('.btn-browse').html(),
|
||||
uploadMultiple: false,
|
||||
@@ -95,5 +97,4 @@ $(function($){
|
||||
return false;
|
||||
});
|
||||
};
|
||||
$.documentUploadManager.onClickDeleteDocument();
|
||||
});
|
||||
|
||||
@@ -8,6 +8,8 @@ $(function($){
|
||||
|
||||
// Remove image on click
|
||||
$.imageUploadManager.initImageDropZone = function() {
|
||||
$.imageUploadManager.onClickDeleteImage();
|
||||
|
||||
var imageDropzone = new Dropzone("#images-dropzone", {
|
||||
dictDefaultMessage : $('.btn-browse').html(),
|
||||
uploadMultiple: false,
|
||||
@@ -96,5 +98,4 @@ $(function($){
|
||||
return false;
|
||||
});
|
||||
};
|
||||
$.imageUploadManager.onClickDeleteImage();
|
||||
});
|
||||
|
||||
@@ -250,6 +250,7 @@
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="documents">
|
||||
{include file='includes/document-upload-form.html' documentType='content' parentId=$content_id}
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="modules">
|
||||
@@ -293,10 +294,14 @@ form_content = {$smarty.capture.delete_content_dialog nofilter}
|
||||
{javascripts file='assets/js/image-upload.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
{javascripts file='assets/js/document-upload.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
<script>
|
||||
$(function() {
|
||||
$.imageUploadManager.initImageDropZone();
|
||||
$.documentUploadManager.initDocumentDropZone();
|
||||
|
||||
$('.use_default_rewriten_url').click(function(ev) {
|
||||
alert("Not functionnal");
|
||||
|
||||
@@ -26,16 +26,16 @@
|
||||
|
||||
<div class="form-container">
|
||||
<div class="col-md-12">
|
||||
|
||||
{form name="thelia.admin.category.document.modification"}
|
||||
{form name="$formId"}
|
||||
<form method="POST" action="{url path="/admin/document/type/{$documentType}/{$ID}/update"}" enctype="multipart/form-data" class="clearfix">
|
||||
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
<button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Close'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{form_field form=$form field='success_url'}
|
||||
@@ -95,6 +95,13 @@
|
||||
{/form_field}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
<button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{/form}
|
||||
|
||||
@@ -111,6 +118,11 @@
|
||||
{elseloop rel="document_edit"}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-error">
|
||||
{intl l="Sorry, document ID=$documentId was not found."}
|
||||
</div>
|
||||
|
||||
@@ -27,15 +27,16 @@
|
||||
<div class="form-container">
|
||||
<div class="col-md-12">
|
||||
|
||||
{form name="thelia.admin.category.image.modification"}
|
||||
{form name="$formId"}
|
||||
<form method="POST" action="{url path="/admin/image/type/{$imageType}/{$ID}/update"}" enctype="multipart/form-data" class="clearfix">
|
||||
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
<button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Close'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{form_hidden_fields form=$form}
|
||||
|
||||
{form_field form=$form field='success_url'}
|
||||
@@ -50,7 +51,11 @@
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<label class="control-label">{intl l="Preview"} : </label>
|
||||
<p><img src="{$IMAGE_URL}" alt="{$TITLE}" class="img-thumbnail"></p>
|
||||
<p>
|
||||
<a href="{$ORIGINAL_IMAGE_URL}" alt="{$TITLE}" target="_blank">
|
||||
<img src="{$IMAGE_URL}" alt="{$TITLE}" class="img-thumbnail">
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -94,6 +99,14 @@
|
||||
{/form_field}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
<button type="submit" name="save_mode" value="stay" class="btn btn-default btn-primary" title="{intl l='Save'}">{intl l='Save'} <span class="glyphicon glyphicon-ok"></span></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{/form}
|
||||
|
||||
@@ -110,6 +123,11 @@
|
||||
{elseloop rel="image_edit"}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="row inner-toolbar clearfix">
|
||||
<div class="col-md-6 inner-actions pull-right">
|
||||
<a href="{url path="{$redirectUrl}"}" class="btn btn-default btn-info">{intl l='Back'} <span class="glyphicon glyphicon-remove"></span></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-error">
|
||||
{intl l="Sorry, image ID=$imageId was not found."}
|
||||
</div>
|
||||
|
||||
@@ -13,7 +13,9 @@ Parameters:
|
||||
{loop type="image" name="image" source="{$imageType}" order="manual-reverse" source_id="{$parentId}" width="200" height="100" resize_mode="borders"}
|
||||
<tr>
|
||||
<td>
|
||||
<img src="{$IMAGE_URL}" alt="{$TITLE}" class="img-thumbnail">
|
||||
<a href="{url path="/admin/image/type/$imageType/$ID/update"}" alt="{intl l='Update this image'}">
|
||||
<img src="{$IMAGE_URL}" alt="{$TITLE}" class="img-thumbnail">
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group">
|
||||
|
||||
@@ -70,7 +70,13 @@
|
||||
{intl l="Images"}
|
||||
</a>
|
||||
</li>
|
||||
<li><a href="#documents" data-toggle="tab">{intl l="Documents"}</a></li>
|
||||
<li>
|
||||
<a href="#documents"
|
||||
data-toggle="tab"
|
||||
data-href="{url path="/admin/document/type/product/{$product_id}/form-ajax"}"
|
||||
data-callback="$.documentUploadManager.initDocumentDropZone">
|
||||
{intl l="Documents"}
|
||||
</a>
|
||||
<li><a href="#modules" data-toggle="tab">{intl l="Modules"}</a></li>
|
||||
</ul>
|
||||
|
||||
@@ -122,6 +128,9 @@
|
||||
{javascripts file='assets/js/image-upload.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
{javascripts file='assets/js/document-upload.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
{javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'}
|
||||
<script src="{$asset_url}"></script>
|
||||
{/javascripts}
|
||||
|
||||
@@ -9,6 +9,13 @@ var thelia2_login_coupon_update_url = thelia2_base_url + 'admin/coupon/update/1'
|
||||
|
||||
|
||||
|
||||
var thelia2_category_image_list_url = thelia2_base_url + 'admin/categories/update?category_id=1';
|
||||
var thelia2_product_image_list_url = thelia2_base_url + 'admin/products/update?product_id=1';
|
||||
var thelia2_folder_image_list_url = thelia2_base_url + 'admin/folders/update/1';
|
||||
var thelia2_content_image_list_url = thelia2_base_url + 'admin/content/update/1';
|
||||
|
||||
|
||||
|
||||
//var findMyId = /([0-9]+)$/;
|
||||
//var currentId;
|
||||
|
||||
|
||||
@@ -12,145 +12,145 @@
|
||||
casper.test.comment('Testing coupons');
|
||||
|
||||
////LIST
|
||||
// @todo implement
|
||||
|
||||
////CREATE
|
||||
casper.start(thelia2_login_coupon_create_url, function() {
|
||||
this.test.assertHttpStatus(200);
|
||||
this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png');
|
||||
this.test.comment('COUPON - CREATE EMPTY');
|
||||
|
||||
// Click on is unlimited button
|
||||
this.click("form #is-unlimited");
|
||||
this.sendKeys('input#max-usage', '-2');
|
||||
|
||||
// cleaning expiration date default value
|
||||
this.evaluate(function() {
|
||||
$("#expiration-date").val('').change();
|
||||
return true;
|
||||
});
|
||||
|
||||
this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png');
|
||||
this.click("form .control-group .btn.btn-default.btn-primary");
|
||||
|
||||
});
|
||||
|
||||
casper.wait(1000, function() {
|
||||
this.echo("\nWaiting....");
|
||||
});
|
||||
|
||||
// Test Coupon creation if no input
|
||||
casper.then(function(){
|
||||
this.test.assertHttpStatus(200);
|
||||
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-empty-coupon.png');
|
||||
this.test.assertExists('.has-error #code', 'Error on code input found');
|
||||
this.test.assertExists('.has-error #title', 'Error on title input found');
|
||||
|
||||
this.test.assertExists('.has-error #expiration-date', 'Error on expiration date input found');
|
||||
this.test.assertExists('.has-error #max-usage', 'Error on max usage input found');
|
||||
this.test.assertExists('.has-error #description', 'Error on description input found');
|
||||
this.test.assertExists('.has-error #effect', 'Error on effect input found');
|
||||
this.test.assertExists('.has-error #amount', 'Error on amount input found');
|
||||
this.test.assertExists('.has-error #short-description', 'Error on short-description input found');
|
||||
});
|
||||
|
||||
// Test Coupon creation if good input
|
||||
casper.then(function(){
|
||||
|
||||
this.sendKeys('input#code', 'XMAS10');
|
||||
this.sendKeys('input#title', 'christmas');
|
||||
this.click("form #is-enabled");
|
||||
this.click("form #is-available-on-special-offers");
|
||||
this.click("form #is-cumulative");
|
||||
this.click("form #is-removing-postage");
|
||||
|
||||
this.evaluate(function() {
|
||||
$("#expiration-date").val('2013-11-14').change();
|
||||
return true;
|
||||
});
|
||||
|
||||
// Click on is unlimited button
|
||||
this.click("form #is-unlimited");
|
||||
this.sendKeys('input#max-usage', '40');
|
||||
|
||||
this.evaluate(function() {
|
||||
$('#effect').val('thelia.coupon.type.remove_x_amount').change();
|
||||
return true;
|
||||
});
|
||||
|
||||
this.test.assertSelectorHasText(
|
||||
'#effectToolTip',
|
||||
this.evaluate(function () {
|
||||
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
|
||||
}),
|
||||
'Tooltip found'
|
||||
);
|
||||
this.sendKeys('input#amount', '42.12');
|
||||
this.sendKeys('#short-description', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.');
|
||||
this.sendKeys('#description', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.');
|
||||
|
||||
this.capture('tests/functionnal/casperjs/screenshot/coupons/coupon-created-ready-to-be-saved.png');
|
||||
this.click("#save-coupon-btn");
|
||||
});
|
||||
|
||||
casper.wait(2000, function() {
|
||||
this.echo("\nWaiting....");
|
||||
});
|
||||
|
||||
// Test Coupon creation if good input is well saved
|
||||
casper.then(function(){
|
||||
this.test.assertHttpStatus(302);
|
||||
this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-coupon.png');
|
||||
this.test.assertField('thelia_coupon_creation[code]', 'XMAS10', 'Code found');
|
||||
this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found');
|
||||
|
||||
this.test.assert(this.evaluate(function () {
|
||||
return document.getElementById('is-enabled').checked;
|
||||
}), 'Checkbox is enabled checked');
|
||||
this.test.assert(this.evaluate(function () {
|
||||
return document.getElementById('is-available-on-special-offers').checked;
|
||||
}), 'Checkbox is available on special offers checked');
|
||||
this.test.assert(this.evaluate(function () {
|
||||
return document.getElementById('is-cumulative').checked;
|
||||
}), 'Checkbox is cumulative checked');
|
||||
this.test.assert(this.evaluate(function () {
|
||||
return document.getElementById('is-removing-postage').checked;
|
||||
}), 'Checkbox is cumulative checked');
|
||||
|
||||
this.test.assertField('thelia_coupon_creation[expirationDate]', '2013-11-14', 'Expiration date found');
|
||||
this.test.assertField('thelia_coupon_creation[maxUsage]', '40', 'Max usage found');
|
||||
this.test.assert(this.evaluate(function () {
|
||||
return !document.getElementById('is-unlimited').checked;
|
||||
}), 'Checkbox is unlimited not checked');
|
||||
|
||||
this.test.assert(
|
||||
this.evaluate(function () {
|
||||
return $("#effect").val();
|
||||
}),
|
||||
'thelia.coupon.type.remove_x_amount',
|
||||
'Effect found'
|
||||
);
|
||||
this.test.assertSelectorHasText(
|
||||
'#effectToolTip',
|
||||
this.evaluate(function () {
|
||||
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
|
||||
}),
|
||||
'Tooltip found'
|
||||
);
|
||||
this.test.assertField('thelia_coupon_creation[amount]', '42.12', 'Amount found');
|
||||
|
||||
this.test.assertField('thelia_coupon_creation[shortDescription]', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.', 'Short description found');
|
||||
this.test.assertField('thelia_coupon_creation[description]', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.', 'Description found');
|
||||
|
||||
|
||||
});
|
||||
////EDIT CHECK
|
||||
// @todo implement
|
||||
|
||||
////DELETE
|
||||
// @todo implement
|
||||
////@todo implement
|
||||
//
|
||||
//////CREATE
|
||||
//casper.start(thelia2_login_coupon_create_url, function() {
|
||||
// this.test.assertHttpStatus(200);
|
||||
// this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
// this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png');
|
||||
// this.test.comment('COUPON - CREATE EMPTY');
|
||||
//
|
||||
// // Click on is unlimited button
|
||||
// this.click("form #is-unlimited");
|
||||
// this.sendKeys('input#max-usage', '-2');
|
||||
//
|
||||
// // cleaning expiration date default value
|
||||
// this.evaluate(function() {
|
||||
// $("#expiration-date").val('').change();
|
||||
// return true;
|
||||
// });
|
||||
//
|
||||
// this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png');
|
||||
// this.click("form .control-group .btn.btn-default.btn-primary");
|
||||
//
|
||||
//});
|
||||
//
|
||||
//casper.wait(1000, function() {
|
||||
// this.echo("\nWaiting....");
|
||||
//});
|
||||
//
|
||||
//// Test Coupon creation if no input
|
||||
//casper.then(function(){
|
||||
// this.test.assertHttpStatus(200);
|
||||
// this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-empty-coupon.png');
|
||||
// this.test.assertExists('.has-error #code', 'Error on code input found');
|
||||
// this.test.assertExists('.has-error #title', 'Error on title input found');
|
||||
//
|
||||
// this.test.assertExists('.has-error #expiration-date', 'Error on expiration date input found');
|
||||
// this.test.assertExists('.has-error #max-usage', 'Error on max usage input found');
|
||||
// this.test.assertExists('.has-error #description', 'Error on description input found');
|
||||
// this.test.assertExists('.has-error #effect', 'Error on effect input found');
|
||||
// this.test.assertExists('.has-error #amount', 'Error on amount input found');
|
||||
// this.test.assertExists('.has-error #short-description', 'Error on short-description input found');
|
||||
//});
|
||||
//
|
||||
//// Test Coupon creation if good input
|
||||
//casper.then(function(){
|
||||
//
|
||||
// this.sendKeys('input#code', 'XMAS10');
|
||||
// this.sendKeys('input#title', 'christmas');
|
||||
// this.click("form #is-enabled");
|
||||
// this.click("form #is-available-on-special-offers");
|
||||
// this.click("form #is-cumulative");
|
||||
// this.click("form #is-removing-postage");
|
||||
//
|
||||
// this.evaluate(function() {
|
||||
// $("#expiration-date").val('2013-11-14').change();
|
||||
// return true;
|
||||
// });
|
||||
//
|
||||
// // Click on is unlimited button
|
||||
// this.click("form #is-unlimited");
|
||||
// this.sendKeys('input#max-usage', '40');
|
||||
//
|
||||
// this.evaluate(function() {
|
||||
// $('#effect').val('thelia.coupon.type.remove_x_amount').change();
|
||||
// return true;
|
||||
// });
|
||||
//
|
||||
// this.test.assertSelectorHasText(
|
||||
// '#effectToolTip',
|
||||
// this.evaluate(function () {
|
||||
// return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
|
||||
// }),
|
||||
// 'Tooltip found'
|
||||
// );
|
||||
// this.sendKeys('input#amount', '42.12');
|
||||
// this.sendKeys('#short-description', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.');
|
||||
// this.sendKeys('#description', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.');
|
||||
//
|
||||
// this.capture('tests/functionnal/casperjs/screenshot/coupons/coupon-created-ready-to-be-saved.png');
|
||||
// this.click("#save-coupon-btn");
|
||||
//});
|
||||
//
|
||||
//casper.wait(2000, function() {
|
||||
// this.echo("\nWaiting....");
|
||||
//});
|
||||
//
|
||||
//// Test Coupon creation if good input is well saved
|
||||
//casper.then(function(){
|
||||
// this.test.assertHttpStatus(302);
|
||||
// this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
// this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-coupon.png');
|
||||
// this.test.assertField('thelia_coupon_creation[code]', 'XMAS10', 'Code found');
|
||||
// this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found');
|
||||
//
|
||||
// this.test.assert(this.evaluate(function () {
|
||||
// return document.getElementById('is-enabled').checked;
|
||||
// }), 'Checkbox is enabled checked');
|
||||
// this.test.assert(this.evaluate(function () {
|
||||
// return document.getElementById('is-available-on-special-offers').checked;
|
||||
// }), 'Checkbox is available on special offers checked');
|
||||
// this.test.assert(this.evaluate(function () {
|
||||
// return document.getElementById('is-cumulative').checked;
|
||||
// }), 'Checkbox is cumulative checked');
|
||||
// this.test.assert(this.evaluate(function () {
|
||||
// return document.getElementById('is-removing-postage').checked;
|
||||
// }), 'Checkbox is cumulative checked');
|
||||
//
|
||||
// this.test.assertField('thelia_coupon_creation[expirationDate]', '2013-11-14', 'Expiration date found');
|
||||
// this.test.assertField('thelia_coupon_creation[maxUsage]', '40', 'Max usage found');
|
||||
// this.test.assert(this.evaluate(function () {
|
||||
// return !document.getElementById('is-unlimited').checked;
|
||||
// }), 'Checkbox is unlimited not checked');
|
||||
//
|
||||
// this.test.assert(
|
||||
// this.evaluate(function () {
|
||||
// return $("#effect").val();
|
||||
// }),
|
||||
// 'thelia.coupon.type.remove_x_amount',
|
||||
// 'Effect found'
|
||||
// );
|
||||
// this.test.assertSelectorHasText(
|
||||
// '#effectToolTip',
|
||||
// this.evaluate(function () {
|
||||
// return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
|
||||
// }),
|
||||
// 'Tooltip found'
|
||||
// );
|
||||
// this.test.assertField('thelia_coupon_creation[amount]', '42.12', 'Amount found');
|
||||
//
|
||||
// this.test.assertField('thelia_coupon_creation[shortDescription]', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.', 'Short description found');
|
||||
// this.test.assertField('thelia_coupon_creation[description]', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.', 'Description found');
|
||||
//
|
||||
//
|
||||
//});
|
||||
//////EDIT CHECK
|
||||
//// @todo implement
|
||||
//
|
||||
//////DELETE
|
||||
//// @todo implement
|
||||
|
||||
//RUN
|
||||
casper.run(function() {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//// verbose:true
|
||||
////});
|
||||
//
|
||||
//casper.test.comment('Testing coupons rules');
|
||||
casper.test.comment('Testing coupons rules');
|
||||
//
|
||||
////UPDATE COUPON RULE
|
||||
//casper.start(thelia2_login_coupon_update_url, function() {
|
||||
@@ -306,7 +306,7 @@
|
||||
// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)');
|
||||
//});
|
||||
//
|
||||
////RUN
|
||||
//casper.run(function() {
|
||||
// this.test.done();
|
||||
//});
|
||||
//RUN
|
||||
casper.run(function() {
|
||||
this.test.done();
|
||||
});
|
||||
77
tests/functionnal/casperjs/exe/40_images_management.js
Normal file
77
tests/functionnal/casperjs/exe/40_images_management.js
Normal file
@@ -0,0 +1,77 @@
|
||||
//
|
||||
//var casper = require('casper').create({
|
||||
// viewportSize:{
|
||||
// width:1024, height:768
|
||||
// },
|
||||
// pageSettings:{
|
||||
// userAgent:'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11'
|
||||
// },
|
||||
// verbose:true
|
||||
//});
|
||||
|
||||
casper.test.comment('Testing Image Management');
|
||||
|
||||
// Image list
|
||||
// @todo implement
|
||||
////CREATE
|
||||
casper.start(thelia2_category_image_list_url, function() {
|
||||
this.test.assertHttpStatus(200);
|
||||
this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
this.capture('tests/functionnal/casperjs/screenshot/category/images/init.png');
|
||||
this.test.comment('CATEGORY : IMAGES - CREATE');
|
||||
|
||||
// Click on is unlimited button
|
||||
this.clickLabel('Images', 'a');
|
||||
|
||||
});
|
||||
|
||||
casper.wait(1000, function() {
|
||||
this.echo("\nWaiting....");
|
||||
});
|
||||
|
||||
// Test Coupon creation if no input
|
||||
casper.then(function(){
|
||||
this.capture('tests/functionnal/casperjs/screenshot/category/images/init-tab-image.png');
|
||||
this.test.assertExists('.existing-image tr:nth-child(1)', 'First image found');
|
||||
|
||||
this.click('.existing-image tr:nth-child(1) .image-update-btn');
|
||||
|
||||
});
|
||||
|
||||
casper.wait(1000, function() {
|
||||
this.echo("\nWaiting....");
|
||||
|
||||
});
|
||||
|
||||
// Test Coupon creation if no input
|
||||
casper.then(function(){
|
||||
this.test.assertHttpStatus(200);
|
||||
this.test.comment('Now on : ' + this.getCurrentUrl());
|
||||
this.capture('tests/functionnal/casperjs/screenshot/category/images/read-image.png');
|
||||
});
|
||||
|
||||
// Image add 1
|
||||
// @todo implement
|
||||
|
||||
// Image add 4
|
||||
// @todo implement
|
||||
|
||||
// Image read
|
||||
// @todo implement
|
||||
|
||||
// Image update
|
||||
// @todo implement
|
||||
|
||||
// Image delete
|
||||
// @todo implement
|
||||
|
||||
// Image links
|
||||
// @todo implement
|
||||
|
||||
// Image i18n
|
||||
// @todo implement
|
||||
|
||||
//RUN
|
||||
casper.run(function() {
|
||||
this.test.done();
|
||||
});
|
||||
Reference in New Issue
Block a user