Testing a file upload to a form in a Behat feature file - symfony

I am quite new to writing Behat test suites and I am currently trying to flesh out my existing feature file with an added test to test an uploaded file.
This is what I have come up with so far.
Scenario: Submitting a valid asset form and uploading a file
When I submit a asset form with values:
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Then the form should be valid
And the entity form entity should have the following values
| name | type | position | active | file |
| St Andrews Release | image | 1 | 1 | /web/images/product/icon/default.jpg |
Failed asserting that null matches expected '/web/images/product/icon/default.jpg'.
And the entity form entity should be persisted correctly
This is the method handling the scenario:
/**
* #When I submit a asset form with values:
*/
public function iSubmitAssetFormWithValues(TableNode $table)
{
$data = $table->getColumnsHash()[0];
$this->form = $this->submitTheForm('crmpicco.asset.type', $this->entity, $data);
}
The submitTheForm method returns a Symfony\Component\Form\FormInterface.
Am I along the right lines? I am currently getting an error:
Failed asserting that null matches expected
'/web/images/product/swatch/default.jpg'.

I suggest you to create a dedicated folder structure for files which will be used in behat tests right in your application root because tests and the files used in tests must be consistent for all developers. I sometimes see people writing tests to upload files that exist on their local desktop:) My desktop and your desktop would be different hence reason the test would fail.
Structure
football #your application name/root
build
dummy
document
hello.doc
world.xls
image
test.jpg
behat.yml
Apart from other common setting, you must define file_path.
....
....
default:
extensions:
Behat\MinkExtension\Extension:
files_path: %behat.paths.base%/build/dummy/
....
....
Example Gherkin scenario
Feature: I can upload a file which is stored in my generic "dummy" folder
Scenario: I can upload image
Given I am on "/"
When I attach the file "image/test.jpg" to "league_flag"
And I press "Submit"
Then I should see "Succeeded."

Related

Sbt in project plugin, how to structure them?

We do have a custom plugin as a single file in our project folder:
acme-project
|- ...
|- project
| |- CustomPlugin.scala
object CustomPlugin extends AutoPlugin {
// ...
That was simple and easy until that plugin started to grow...
In the first step, we added more classes/objects to the same source file. However, it continues to grow and I would like to add more structure via packages.
acme-project
|- ...
|- project
| |- CustomPlugin.scala
| |- SupportingClass.scala
| |- acme
| | |- plugin
| | | |- PackagedClass.scala
My CustomPlugin seems to be able to use the SupportingClass from the folder, whenever this class declare another package. However, I cannot use the PackagedClass :
[error] /~/acme-project/project/CustomPlugin.scala:1:8: not found: object acme
[error] import mega.plugin.PackagedClass
[error]             ^
I tried to add one src/main/scala folder but have the same kind of import errors.
So, I would like to know if there are ways to create large/structured plugins inside a project without making a complete one?
I would like to keep the simplicity of this format where I do not have to publish my plugin. Having it inside a dedicated module would be ok.
Thanks
One way to do this is to restructure your plugin as its own sbt project, then load it as a module dependency in your project's plugins.sbt.
Move the code to its own directory. This can be anywhere you like, e.g.:
acme-project/project/my-custom-plugin/
acme-project/my-custom-plugin/
some-other-path/my-custom-plugin/
Write a my-custom-plugin/build.sbt with at least these settings:
enablePlugins(SbtPlugin)
sbtPlugin := true
scalaVersion := "2.12.16"
name := "my-custom-plugin"
Add it to your project as a module dependency in acme-project/project/plugins.sbt:
// For acme-project/project/my-custom-plugin/
val myCustomPlugin =
project in file("my-custom-plugin")
// For acme-project/my-custom-plugin/
val myCustomPlugin =
ProjectRef(file("../../my-custom-plugin"), "my-custom-plugin")
// For some-other-path/my-custom-plugin/
val myCustomPlugin =
ProjectRef(file("/path/to/my-custom-plugin", "my-custom-plugin")
dependsOn(myCustomPlugin)
You only need one of those val myCustomPlugin = lines, depending on where you put your my-custom-plugin/ directory.

Is it possible to add properties to multiple files after they have been uploaded to artifactory?

As the title says. Due to a lack of understanding about how best to query files in artifactory I now have a situation where I have a few hundred files I need to add the same properties to.
Can this be done in bulk?
the folder structure looks like this:
repository
|
|- main folder
|
|- type
|
|- language1
|
|-sub-folder1
|-sub-folder2
|-file1
|-file2
...
...
...
Each sub-folder can have around 5 files, each language folder can have many sub-folders.
Sure it is.
You have two main options.
The first one is to use the Set Item Properties REST API on the relevant folder with the "recursiveProperties=1".
The second option, which I believe is better, will be to use the JFrog CLI to set properties on existing artifacts. This options will provide you with the ability to define a more complex logic on setting the properties.

SourceForge file releases

I would like to automate updating from SourceForge. This was working for a while
http://sourceforge.net/projects/msys2/rss?path=/Base/x86_64
However I realized that the RSS feed has a max of 100 items. So if the chosen
path was last updated before that then it will not be on RSS, and will return
500 Internal Server Error
§ File Releases
So can I access a SourceForge file list with another "API"? I would prefer to
not have to scrape the page like an animal.
This is a workaround, but PowerShell can easily parse HTML
$base = Invoke-WebRequest 'http://sourceforge.net/projects/msys2/files/Base/x86_64'
Example, get latest file
$base.Links | ? class -eq name | select -fir 1 -exp href
Get latest file matching tar
$base.Links | ? href -match tar | select -fir 1 -exp href

The relationship between namespace and actual files layer

OK, just as the title asked, I currently worked on a asp.net website, I found out that all the aspx and ascx files actually stay in one namespace, however there are different directory hierarchy between them. See below example.
Mainsite
| Dialogs
| | Help.ascx
| | Price.aspx
| Includes
| | QuickLink.acsx
| Members
| Orders
| Login.aspx
| Default.aspx
Like above example, all aspx ans ascx files belong to namespace Order, however Login.aspx and Price.aspx are in different directory. I mean by default when you create a aspx file in certain directory, the default namespace will inherit the directory information.
The thing is that I found at a frequently happened bug, is in Default.aspx there is ajax call to Dialogs/Price.aspx, then the error message can not find Dialogs/Dialogs/Price.aspx, it is weird.

URL Routing for CMS

I am developing a CMS that stores user content in a database table like this:
----------------------------------------
PageId | PageTitle(Unique) | Content
----------------------------------------
1 | PageOne | ...
2 | PageTwo | ...
3 | PageThree | ...
4 | PageFour | ...
Now I have an aspx page "SitePageFactory.aspx" at root that serves dynamic content when a querystring is passed to it, suppose /SitePageFactory.aspx?pgid=1 is passed then it serves the content for PageOne.
The concept above is working fine.
Now I want to put a step further by adding dynamic routes to this application and modify /SitePageFactory.aspx?pgid=1 to /PageOne.aspx but unable to do it at root level.
NOTE: Currently I am able to perform routing like /SitePageFactory/PageOne.aspx but I want the results at the root level.
Thanks.
You can use ASP.NET Routing to accomplish this.
Routing let's you map an url like: www.mysite.com/pages/pageone to an aspx page. The different parts in your url can be mapped to route parameters that you can access in your aspx.
Here is the MSDN documentation for routing.
You can add the folowing route:
routes.MapRoute("ViewPage",
"<PageName>",
new { controller = "Page", action = "ViewPage" }
This will map the url www.yourdomain/ to the Page controllers ViewPage method.

Resources