Skip to content

Instantly share code, notes, and snippets.

@benglass
Created November 12, 2014 18:09
Show Gist options
  • Save benglass/6eb6fe3f2b093785e936 to your computer and use it in GitHub Desktop.
Save benglass/6eb6fe3f2b093785e936 to your computer and use it in GitHub Desktop.
<?php
class MyTest
{
public function testSomething()
{
$crawler = $this->request('/foo');
$form = $this->findFormByButtonText('Save');
$data = array(
'name' => 'Foo'
);
$this->fillForm($form, $data);
// do something else like maybe add a file
$this->submitForm($form);
}
public function findFormByButtonText($crawler, $buttonText)
{
$form = $button->form();
$name = // find the form name from first input/select/textarea
return new Form($form->getNode(), $form->getUri(), $form->getMethod(), $name);
}
protected function findFormBySelector($crawler, $cssSelector)
{
// example maybe use a css selector
}
}
class Form extends Form
{
protected $crawler;
protected $namePrefix;
public function __construct(\DomElement $node, $currentUri, $method, $namePrefix = '')
{
$this->namePrefix = $namePrefix;
parent::__construct($node, $currentUri, $method);
}
public function getNamePrefix()
{
return $this->getNamePrefix();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment