How to easily test file upload in Yii models? - yii

I have a model that has a ImageARBehavior attached, and I would like to test it with Unit tests.
Currently, because the file is required I am not even able to save the model because of validation errors... (which I can pass using no validation but that is not the point...)

It seems to me, for this cases, is to use a Mock object. Although, of course is not the best option

Related

How to configure karate-config to only run block of code if certain conditions are met

I am completely new to Karate and had a question regarding the karate-config.js file.
I understand it is the first to run as "config" for all the scripts- sort of global settings.
What I have written are a few test cases that require different "setup" steps that cannot be done in the Background (what I understand runs after karate-config.js) for each test scenario.
I have two Feature files with scenarios in them. One of the feature file requires this setup from the karate-config.js. The other Feature file doesn't. Right now the setup is running for both Feature files when I only want it to run for the first one.
I was thinking I could tag each Feature file with a unique tag and use an If statement in karate-config.js to only run if this tag is present. However, that likely won't work since the Feature files don't get accessed until after karate-config.js is traversed right?
Is there a way to get this done?
Sorry if the description is long.
I think you are overcomplicating things. If something is not to be used in all features, please don't put it in karate-config.js.
Just go with the strategy of having 2 re-usable features and call them in the Background where needed. This is what is done in normal programming languages, and Karate in that regard is no different.
You seem to be trying to save one line of code being repeated in multiple files. My advice: don't.

Asp.Net Core validation without jQuery

Is there any mode to use Asp.Net Core client side validation without jquery + jquery validation + jq unobtrusive validation?
I mean it's 2017, every browser can handle lots of HTML5 input validators without JavaScript.
I created a library that is compatible with the original validation library but is much smaller and does not require jQuery. You can use it as a drop-in replacement if you want to reduce payload size of your assets:
https://github.com/kraaden/unobtrusive-validation
I don't know of any package that turns TagHelper for input fields into html5 element tags. You could probably quite easily make one. Check out the source code of the tag helpers: https://github.com/aspnet/AspNetCore/blob/master/src/Mvc/Mvc.TagHelpers/src/InputTagHelper.cs
Advise
Best approach would be to make sure you receive a json error object when validation fails and process this in javascript to show errrors (maybe show which fields fail). make a generic function you can use for any form.
Later manually fine tune/add additional tags/validation if needed in frontend. but that shouldn't be part of your MVP (minimal viable product).
old answer
Depends on what kind of validation you are looking for.
jQuery validation in combination with data annotations is the easiest one and the default one. Although html 5 can tackle quite some extensive tests. it can't handle any indepth stuff like properties being dependent on eachother.
Another option is to use the Popular FluentValidation. Validate only serverside but use Ajax and a small client side framework to show the errors
The last option would be to use Html5 input validations. This can only be partly achieved by default using dotnet types or some annotations: http://www.davepaquette.com/archive/2015/05/13/mvc6-input-tag-helper-deep-dive.aspx. You'd have to extend the taghelpers yourself if you'd want to add more in depth html 5 attribute support.
Too bad you can't use the same frontend and serverside code (like nodejs could) but for big projects i'd advise you to take option 2. it might not sound very snappy but dotnet is generally pretty fast and if you use FluentValidation in combination with Ajax Api calls no one will notice validation actually serverside. In the end i found data annotations always lack proper possibilities to test properties dependent on each other and it gets very hacky very fast. The only downside of this option is that you split the validation from the input-model and thus not always the validation is directly visible for external developers.

Projecting an instance from a A4Solution

I'm trying to make a new UI to visualize my Alloy instances. I've got an A4Solution and have been successful in extracting atoms, relations, checking atom signatures BUT I can't seem to understand how to project the instance on some sig.
I've noticed that I can try to use the edu.mit.csail.sdg.alloy4viz.AlloyInstance, I've got options to project there, but that'd imply in starting over, from a different angle.
Would that be the way to go? I'd prefer to extract that from the A4Solution object.
Thanks
You might want to look at the edu.mit.csail.sdg.alloy4viz.StaticProjector class and its project methods---that's how the Alloy Visualizer implements projections. If your visualization uses the edu.mit.csail.sdg.alloy4viz.AlloyModel class, you should be able to reuse the existing code in StaticProjector; from your post it seems, however, that you'd prefer not use any of the alloy4viz classes, in which case it should not be too difficult to understand how StaticProjector works and reapply the same ideas to your project. Or you could convert an A4Solution object to an AlloyInstance[1] and build your visualizer around the alloy4viz classes, which, in my opinion, would be a good way to go about your project.
[1] something like:
a4sol.writeXML("instance.xml")
AlloyInstance inst = StaticInstanceReader.parseInstance(new File("instance.xml"));

Tool or eclipse base plugin available for generate test cases for SalesForce platform related Apex classes

Can any one please tell me is there any kind of tools or eclipse base plugins available for generate relevant test cases for SalesForce platform related Apex classes. It seems with code coverage they are not expecting out come like we expect with JUnit, they want to cover whether, test cases are going through the flows of the source classes (like code go through).
Please don't get this post in wrong, I don't want anyone is going to write test cases for my codes :). I have post this question due to nature of SalesForce expecting that code coverage should be. Thanks.
Although Salesforce requires a certain percentage of code coverage for your test cases, you really need to be writing cases that check the results to ensure that the code behaves as designed.
So, even if there was a tool that could generate code to get 100% coverage of your test class, it wouldn't be able to test the results of those method calls, leaving you with a false sense of having "tested code".
I've found that breaking up long methods into separate, sometimes static, methods makes it easier to do unit testing. You can test each individual method, and not worry so much about tweaking parameters to a single method so that it covers all execution paths.
it's now possible to generate test classes automatically for your class/trigger/batch. You can install "Test Class Generator" app from AppExchange and see it working.
This would really help you generating test class and saves lot of your development time.

Dynamic Magento Grid built with database query

This is my first time asking a question here so, be nice;p .. I'm working with Magento (and Zend Framework) for the first time and I'm trying to build a custom grid that will populate based off of a manually written query. I'm trying to extend the Mage_Core_Model_Mysql4_Collection_Abstract to allow a query to be loaded into it and then parse the select fields in the extended Grid class to make it dynamic... Is this even possible or am I beating a dead horse? I've been at it for a week now and I'm not getting anywhere. The problem seems to be that inside the __Model_mysql4_Collection class has to be initialized with a resource model using _init() in the constuct
As a learning exercise use the module creator to make an admin grid page and see how that is done. Or even modify it's output to get what you need.
There will be a grid container block, a grid block (with _prepareCollection and _prepareColumns methods), a model, a resource model (representing a single record) and a collection resource model (representing several records).
Providing your own _init methods shouldn't be any sort of problem. Perhaps you'd like to post your config.xml and code so far as a pastebin or something.