Working : Fix : Image Management + Document Management

This commit is contained in:
gmorel
2013-09-24 18:41:28 +02:00
parent 71888e68aa
commit 7f3367f590
15 changed files with 372 additions and 179 deletions

View File

@@ -25,7 +25,6 @@ namespace Thelia\Action;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\File\File;
use Thelia\Core\Event\DocumentCreateOrUpdateEvent; use Thelia\Core\Event\DocumentCreateOrUpdateEvent;
use Thelia\Core\Event\DocumentDeleteEvent; use Thelia\Core\Event\DocumentDeleteEvent;
use Thelia\Core\Event\DocumentEvent; use Thelia\Core\Event\DocumentEvent;
@@ -163,6 +162,7 @@ class Document extends BaseCachedFile implements EventSubscriberInterface
$model = $event->getModelDocument(); $model = $event->getModelDocument();
$nbModifiedLines = $model->save(); $nbModifiedLines = $model->save();
$event->setModelDocument($model); $event->setModelDocument($model);
if (!$nbModifiedLines) { 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); $fileManager = new FileManager($this->container);
// Copy and save file // Copy and save file
if ($event->getUploadedFile()) { if ($event->getUploadedFile()) {

View File

@@ -181,9 +181,8 @@ class FileController extends BaseAdminController
return new Response('', 404); return new Response('', 404);
} }
$defaultTitle = $parentModel->getTitle();
$documentModel->setParentId($parentId); $documentModel->setParentId($parentId);
$documentModel->setTitle($defaultTitle); $documentModel->setTitle($fileBeingUploaded->getClientOriginalName());
$documentCreateOrUpdateEvent = new DocumentCreateOrUpdateEvent( $documentCreateOrUpdateEvent = new DocumentCreateOrUpdateEvent(
$parentType, $parentType,
@@ -292,12 +291,13 @@ class FileController extends BaseAdminController
try { try {
$fileManager = new FileManager($this->container); $fileManager = new FileManager($this->container);
$image = $fileManager->getImageModelQuery($parentType)->findPk($imageId); $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( return $this->render('image-edit', array(
'imageId' => $imageId, 'imageId' => $imageId,
'imageType' => $parentType, 'imageType' => $parentType,
'redirectUrl' => $redirectUrl 'redirectUrl' => $redirectUrl,
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_IMAGES)
)); ));
} catch (\Exception $e) { } catch (\Exception $e) {
$this->pageNotFound(); $this->pageNotFound();
@@ -320,12 +320,13 @@ class FileController extends BaseAdminController
try { try {
$fileManager = new FileManager($this->container); $fileManager = new FileManager($this->container);
$document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId); $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( return $this->render('document-edit', array(
'documentId' => $documentId, 'documentId' => $documentId,
'documentType' => $parentType, 'documentType' => $parentType,
'redirectUrl' => $redirectUrl 'redirectUrl' => $redirectUrl,
'formId' => $fileManager->getFormId($parentType, FileManager::FILE_TYPE_DOCUMENTS)
)); ));
} catch (\Exception $e) { } catch (\Exception $e) {
$this->pageNotFound(); $this->pageNotFound();
@@ -399,9 +400,13 @@ class FileController extends BaseAdminController
->setGeneralError($message); ->setGeneralError($message);
} }
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $image->getParentId(), FileManager::FILE_TYPE_IMAGES);
return $this->render('image-edit', array( return $this->render('image-edit', array(
'imageId' => $imageId, '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) public function updateDocumentAction($documentId, $parentType)
{ {
if (null !== $response = $this->checkAuth('admin.image.update')) { if (null !== $response = $this->checkAuth('admin.document.update')) {
return $response; return $response;
} }
$message = false; $message = false;
$fileManager = new FileManager($this->container); $fileManager = new FileManager($this->container);
$documentModification = $fileManager->getImageForm($parentType, $this->getRequest()); $documentModification = $fileManager->getDocumentForm($parentType, $this->getRequest());
try { try {
$document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId); $document = $fileManager->getDocumentModelQuery($parentType)->findPk($documentId);
@@ -433,8 +438,8 @@ class FileController extends BaseAdminController
$form = $this->validateForm($documentModification); $form = $this->validateForm($documentModification);
$event = $this->createImageEventInstance($parentType, $document, $form->getData()); $event = $this->createDocumentEventInstance($parentType, $document, $form->getData());
$event->setOldModelImage($oldDocument); $event->setOldModelDocument($oldDocument);
$files = $this->getRequest()->files; $files = $this->getRequest()->files;
$fileForm = $files->get($documentModification->getName()); $fileForm = $files->get($documentModification->getName());
@@ -444,7 +449,7 @@ class FileController extends BaseAdminController
$this->dispatch(TheliaEvents::DOCUMENT_UPDATE, $event); $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())); $this->adminLogAppend(sprintf('Document with Ref %s (ID %d) modified', $documentUpdated->getTitle(), $documentUpdated->getId()));
@@ -472,9 +477,13 @@ class FileController extends BaseAdminController
->setGeneralError($message); ->setGeneralError($message);
} }
$redirectUrl = $fileManager->getRedirectionUrl($parentType, $document->getParentId(), FileManager::FILE_TYPE_DOCUMENTS);
return $this->render('document-edit', array( return $this->render('document-edit', array(
'documentId' => $documentId, '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 CategoryDocument|ProductDocument|ContentDocument|FolderDocument $model Document model
* @param array $data Post data * @param array $data Post data
* *
* @return ImageCreateOrUpdateEvent * @return DocumentCreateOrUpdateEvent
*/ */
protected function createDocumentEventInstance($parentType, $model, $data) protected function createDocumentEventInstance($parentType, $model, $data)
{ {

View File

@@ -56,7 +56,7 @@ class DocumentDeleteEvent extends ActionEvent
*/ */
public function __construct($documentToDelete, $documentType) public function __construct($documentToDelete, $documentType)
{ {
$this->imageToDelete = $documentToDelete; $this->documentToDelete = $documentToDelete;
$this->documentType = $documentType; $this->documentType = $documentType;
} }
@@ -93,7 +93,7 @@ class DocumentDeleteEvent extends ActionEvent
*/ */
public function setDocumentToDelete($documentToDelete) public function setDocumentToDelete($documentToDelete)
{ {
$this->imageToDelete = $documentToDelete; $this->documentToDelete = $documentToDelete;
return $this; return $this;
} }

View File

@@ -443,6 +443,48 @@ class FileManager
return $model; 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 * Get image parent model from type
* *
@@ -577,24 +619,30 @@ class FileManager
/** /**
* Deduce image redirecting URL from parent type * 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 int $parentId Parent id
* @param string $fileType File type ex : self::FILE_TYPE_DOCUMENTS
*
* @return string * @return string
*/ */
public function getRedirectionUrl($parentType, $parentId) public function getRedirectionUrl($parentType, $parentId, $fileType)
{ {
if (!in_array($fileType, self::$availableFileType)) {
return false;
}
switch ($parentType) { switch ($parentType) {
case self::TYPE_PRODUCT: case self::TYPE_PRODUCT:
$uri = '/admin/products/update?product_id=' . $parentId . '&current_tab=images'; $uri = '/admin/products/update?product_id=' . $parentId . '&current_tab=' . $fileType;
break; break;
case self::TYPE_CATEGORY: case self::TYPE_CATEGORY:
$uri = '/admin/categories/update?category_id=' . $parentId . '&current_tab=images'; $uri = '/admin/categories/update?category_id=' . $parentId . '&current_tab=' . $fileType;
break; break;
case self::TYPE_CONTENT: case self::TYPE_CONTENT:
$uri = '/admin/content/update/' . $parentId . '&current_tab=images'; $uri = '/admin/content/update/' . $parentId . '?current_tab=' . $fileType;
break; break;
case self::TYPE_FOLDER: case self::TYPE_FOLDER:
$uri = '/admin/folders/update/' . $parentId . '&current_tab=images'; $uri = '/admin/folders/update/' . $parentId . '?current_tab=' . $fileType;
break; break;
default: default:
$uri = false; $uri = false;

View File

@@ -8,6 +8,8 @@ $(function($){
// Remove image on click // Remove image on click
$.documentUploadManager.initDocumentDropZone = function() { $.documentUploadManager.initDocumentDropZone = function() {
$.documentUploadManager.onClickDeleteDocument();
var documentDropzone = new Dropzone("#documents-dropzone", { var documentDropzone = new Dropzone("#documents-dropzone", {
dictDefaultMessage : $('.btn-browse').html(), dictDefaultMessage : $('.btn-browse').html(),
uploadMultiple: false, uploadMultiple: false,
@@ -95,5 +97,4 @@ $(function($){
return false; return false;
}); });
}; };
$.documentUploadManager.onClickDeleteDocument();
}); });

View File

@@ -8,6 +8,8 @@ $(function($){
// Remove image on click // Remove image on click
$.imageUploadManager.initImageDropZone = function() { $.imageUploadManager.initImageDropZone = function() {
$.imageUploadManager.onClickDeleteImage();
var imageDropzone = new Dropzone("#images-dropzone", { var imageDropzone = new Dropzone("#images-dropzone", {
dictDefaultMessage : $('.btn-browse').html(), dictDefaultMessage : $('.btn-browse').html(),
uploadMultiple: false, uploadMultiple: false,
@@ -96,5 +98,4 @@ $(function($){
return false; return false;
}); });
}; };
$.imageUploadManager.onClickDeleteImage();
}); });

View File

@@ -250,6 +250,7 @@
</div> </div>
<div class="tab-pane fade" id="documents"> <div class="tab-pane fade" id="documents">
{include file='includes/document-upload-form.html' documentType='content' parentId=$content_id}
</div> </div>
<div class="tab-pane fade" id="modules"> <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'} {javascripts file='assets/js/image-upload.js'}
<script src="{$asset_url}"></script> <script src="{$asset_url}"></script>
{/javascripts} {/javascripts}
{javascripts file='assets/js/document-upload.js'}
<script src="{$asset_url}"></script>
{/javascripts}
<script> <script>
$(function() { $(function() {
$.imageUploadManager.initImageDropZone(); $.imageUploadManager.initImageDropZone();
$.documentUploadManager.initDocumentDropZone();
$('.use_default_rewriten_url').click(function(ev) { $('.use_default_rewriten_url').click(function(ev) {
alert("Not functionnal"); alert("Not functionnal");

View File

@@ -26,16 +26,16 @@
<div class="form-container"> <div class="form-container">
<div class="col-md-12"> <div class="col-md-12">
{form name="$formId"}
{form name="thelia.admin.category.document.modification"}
<form method="POST" action="{url path="/admin/document/type/{$documentType}/{$ID}/update"}" enctype="multipart/form-data" class="clearfix"> <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="row inner-toolbar clearfix">
<div class="col-md-6 inner-actions pull-right"> <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> <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>
</div> </div>
{form_hidden_fields form=$form} {form_hidden_fields form=$form}
{form_field form=$form field='success_url'} {form_field form=$form field='success_url'}
@@ -94,7 +94,14 @@
</div> </div>
{/form_field} {/form_field}
</div> </div>
</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>
{/form} {/form}
@@ -111,6 +118,11 @@
{elseloop rel="document_edit"} {elseloop rel="document_edit"}
<div class="row"> <div class="row">
<div class="col-md-12"> <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"> <div class="alert alert-error">
{intl l="Sorry, document ID=$documentId was not found."} {intl l="Sorry, document ID=$documentId was not found."}
</div> </div>

View File

@@ -27,15 +27,16 @@
<div class="form-container"> <div class="form-container">
<div class="col-md-12"> <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"> <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="row inner-toolbar clearfix">
<div class="col-md-6 inner-actions pull-right"> <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> <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>
</div> </div>
{form_hidden_fields form=$form} {form_hidden_fields form=$form}
{form_field form=$form field='success_url'} {form_field form=$form field='success_url'}
@@ -50,7 +51,11 @@
<div class="col-md-6"> <div class="col-md-6">
<div class="form-group"> <div class="form-group">
<label class="control-label">{intl l="Preview"} : </label> <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>
</div> </div>
@@ -93,7 +98,15 @@
</div> </div>
{/form_field} {/form_field}
</div> </div>
</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>
{/form} {/form}
@@ -110,6 +123,11 @@
{elseloop rel="image_edit"} {elseloop rel="image_edit"}
<div class="row"> <div class="row">
<div class="col-md-12"> <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"> <div class="alert alert-error">
{intl l="Sorry, image ID=$imageId was not found."} {intl l="Sorry, image ID=$imageId was not found."}
</div> </div>

View File

@@ -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"} {loop type="image" name="image" source="{$imageType}" order="manual-reverse" source_id="{$parentId}" width="200" height="100" resize_mode="borders"}
<tr> <tr>
<td> <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>
<td> <td>
<div class="btn-group"> <div class="btn-group">

View File

@@ -70,7 +70,13 @@
{intl l="Images"} {intl l="Images"}
</a> </a>
</li> </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> <li><a href="#modules" data-toggle="tab">{intl l="Modules"}</a></li>
</ul> </ul>
@@ -122,6 +128,9 @@
{javascripts file='assets/js/image-upload.js'} {javascripts file='assets/js/image-upload.js'}
<script src="{$asset_url}"></script> <script src="{$asset_url}"></script>
{/javascripts} {/javascripts}
{javascripts file='assets/js/document-upload.js'}
<script src="{$asset_url}"></script>
{/javascripts}
{javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'} {javascripts file='assets/js/bootstrap-editable/bootstrap-editable.js'}
<script src="{$asset_url}"></script> <script src="{$asset_url}"></script>
{/javascripts} {/javascripts}

View File

@@ -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 findMyId = /([0-9]+)$/;
//var currentId; //var currentId;

View File

@@ -12,145 +12,145 @@
casper.test.comment('Testing coupons'); casper.test.comment('Testing coupons');
////LIST ////LIST
// @todo implement ////@todo implement
//
////CREATE //////CREATE
casper.start(thelia2_login_coupon_create_url, function() { //casper.start(thelia2_login_coupon_create_url, function() {
this.test.assertHttpStatus(200); // this.test.assertHttpStatus(200);
this.test.comment('Now on : ' + this.getCurrentUrl()); // this.test.comment('Now on : ' + this.getCurrentUrl());
this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png'); // this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png');
this.test.comment('COUPON - CREATE EMPTY'); // this.test.comment('COUPON - CREATE EMPTY');
//
// Click on is unlimited button // // Click on is unlimited button
this.click("form #is-unlimited"); // this.click("form #is-unlimited");
this.sendKeys('input#max-usage', '-2'); // this.sendKeys('input#max-usage', '-2');
//
// cleaning expiration date default value // // cleaning expiration date default value
this.evaluate(function() { // this.evaluate(function() {
$("#expiration-date").val('').change(); // $("#expiration-date").val('').change();
return true; // return true;
}); // });
//
this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png'); // this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png');
this.click("form .control-group .btn.btn-default.btn-primary"); // this.click("form .control-group .btn.btn-default.btn-primary");
//
}); //});
//
casper.wait(1000, function() { //casper.wait(1000, function() {
this.echo("\nWaiting...."); // this.echo("\nWaiting....");
}); //});
//
// Test Coupon creation if no input //// Test Coupon creation if no input
casper.then(function(){ //casper.then(function(){
this.test.assertHttpStatus(200); // this.test.assertHttpStatus(200);
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-empty-coupon.png'); // 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 #code', 'Error on code input found');
this.test.assertExists('.has-error #title', 'Error on title 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 #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 #max-usage', 'Error on max usage input found');
this.test.assertExists('.has-error #description', 'Error on description 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 #effect', 'Error on effect input found');
this.test.assertExists('.has-error #amount', 'Error on amount 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'); // this.test.assertExists('.has-error #short-description', 'Error on short-description input found');
}); //});
//
// Test Coupon creation if good input //// Test Coupon creation if good input
casper.then(function(){ //casper.then(function(){
//
this.sendKeys('input#code', 'XMAS10'); // this.sendKeys('input#code', 'XMAS10');
this.sendKeys('input#title', 'christmas'); // this.sendKeys('input#title', 'christmas');
this.click("form #is-enabled"); // this.click("form #is-enabled");
this.click("form #is-available-on-special-offers"); // this.click("form #is-available-on-special-offers");
this.click("form #is-cumulative"); // this.click("form #is-cumulative");
this.click("form #is-removing-postage"); // this.click("form #is-removing-postage");
//
this.evaluate(function() { // this.evaluate(function() {
$("#expiration-date").val('2013-11-14').change(); // $("#expiration-date").val('2013-11-14').change();
return true; // return true;
}); // });
//
// Click on is unlimited button // // Click on is unlimited button
this.click("form #is-unlimited"); // this.click("form #is-unlimited");
this.sendKeys('input#max-usage', '40'); // this.sendKeys('input#max-usage', '40');
//
this.evaluate(function() { // this.evaluate(function() {
$('#effect').val('thelia.coupon.type.remove_x_amount').change(); // $('#effect').val('thelia.coupon.type.remove_x_amount').change();
return true; // return true;
}); // });
//
this.test.assertSelectorHasText( // this.test.assertSelectorHasText(
'#effectToolTip', // '#effectToolTip',
this.evaluate(function () { // this.evaluate(function () {
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description'); // return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
}), // }),
'Tooltip found' // 'Tooltip found'
); // );
this.sendKeys('input#amount', '42.12'); // 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('#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.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.capture('tests/functionnal/casperjs/screenshot/coupons/coupon-created-ready-to-be-saved.png');
this.click("#save-coupon-btn"); // this.click("#save-coupon-btn");
}); //});
//
casper.wait(2000, function() { //casper.wait(2000, function() {
this.echo("\nWaiting...."); // this.echo("\nWaiting....");
}); //});
//
// Test Coupon creation if good input is well saved //// Test Coupon creation if good input is well saved
casper.then(function(){ //casper.then(function(){
this.test.assertHttpStatus(302); // this.test.assertHttpStatus(302);
this.test.comment('Now on : ' + this.getCurrentUrl()); // this.test.comment('Now on : ' + this.getCurrentUrl());
this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-coupon.png'); // 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[code]', 'XMAS10', 'Code found');
this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found'); // this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found');
//
this.test.assert(this.evaluate(function () { // this.test.assert(this.evaluate(function () {
return document.getElementById('is-enabled').checked; // return document.getElementById('is-enabled').checked;
}), 'Checkbox is enabled checked'); // }), 'Checkbox is enabled checked');
this.test.assert(this.evaluate(function () { // this.test.assert(this.evaluate(function () {
return document.getElementById('is-available-on-special-offers').checked; // return document.getElementById('is-available-on-special-offers').checked;
}), 'Checkbox is available on special offers checked'); // }), 'Checkbox is available on special offers checked');
this.test.assert(this.evaluate(function () { // this.test.assert(this.evaluate(function () {
return document.getElementById('is-cumulative').checked; // return document.getElementById('is-cumulative').checked;
}), 'Checkbox is cumulative checked'); // }), 'Checkbox is cumulative checked');
this.test.assert(this.evaluate(function () { // this.test.assert(this.evaluate(function () {
return document.getElementById('is-removing-postage').checked; // return document.getElementById('is-removing-postage').checked;
}), 'Checkbox is cumulative checked'); // }), 'Checkbox is cumulative checked');
//
this.test.assertField('thelia_coupon_creation[expirationDate]', '2013-11-14', 'Expiration date found'); // 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.assertField('thelia_coupon_creation[maxUsage]', '40', 'Max usage found');
this.test.assert(this.evaluate(function () { // this.test.assert(this.evaluate(function () {
return !document.getElementById('is-unlimited').checked; // return !document.getElementById('is-unlimited').checked;
}), 'Checkbox is unlimited not checked'); // }), 'Checkbox is unlimited not checked');
//
this.test.assert( // this.test.assert(
this.evaluate(function () { // this.evaluate(function () {
return $("#effect").val(); // return $("#effect").val();
}), // }),
'thelia.coupon.type.remove_x_amount', // 'thelia.coupon.type.remove_x_amount',
'Effect found' // 'Effect found'
); // );
this.test.assertSelectorHasText( // this.test.assertSelectorHasText(
'#effectToolTip', // '#effectToolTip',
this.evaluate(function () { // this.evaluate(function () {
return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description'); // return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description');
}), // }),
'Tooltip found' // 'Tooltip found'
); // );
this.test.assertField('thelia_coupon_creation[amount]', '42.12', 'Amount 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[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'); // 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 //////EDIT CHECK
// @todo implement //// @todo implement
//
////DELETE //////DELETE
// @todo implement //// @todo implement
//RUN //RUN
casper.run(function() { casper.run(function() {

View File

@@ -9,7 +9,7 @@
//// verbose:true //// verbose:true
////}); ////});
// //
//casper.test.comment('Testing coupons rules'); casper.test.comment('Testing coupons rules');
// //
////UPDATE COUPON RULE ////UPDATE COUPON RULE
//casper.start(thelia2_login_coupon_update_url, function() { //casper.start(thelia2_login_coupon_update_url, function() {
@@ -306,7 +306,7 @@
// test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)'); // test.assertDoesntExist('tbody#constraint-list tr:nth-child(2)');
//}); //});
// //
////RUN //RUN
//casper.run(function() { casper.run(function() {
// this.test.done(); this.test.done();
//}); });

View 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();
});