-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathPostsPage.php
64 lines (53 loc) · 1.44 KB
/
PostsPage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
class PostsPage
{
// include url of current page
static $url = '/posts';
public static function route($param = '')
{
return static::$url.$param;
}
static $formFields = ['title' => '#title', 'body' => 'Body:'];
/**
* @var FunctionalTester;
*/
protected $tester;
public function __construct(FunctionalTester $I)
{
$this->tester = $I;
}
public static function of(FunctionalTester $I)
{
return new static($I);
}
public function createPost($fields = array())
{
$I = $this->tester;
$I->amOnPage(self::$url);
$I->click('Add new post');
$this->fillFormFields($fields);
$I->click('Submit');
return $this;
}
public function editPost($id, $fields = array())
{
$I = $this->tester;
$I->amOnPage(self::route("/$id/edit"));
$I->see('Edit Post', 'h1');
$this->fillFormFields($fields);
$I->click('Update');
}
public function deletePost($id)
{
$I = $this->tester;
$I->amOnPage($I->amOnPage(self::route("/$id")));
$I->click('Delete');
}
protected function fillFormFields($data)
{
foreach ($data as $field => $value) {
if (!isset(self::$formFields[$field])) throw new \Exception("Form field $field does not exist");
$this->tester->fillField(self::$formFields[$field], $value);
}
}
}