File tree 8 files changed +178
-0
lines changed
8 files changed +178
-0
lines changed Original file line number Diff line number Diff line change
1
+ /vendor
2
+ composer.lock
3
+
Original file line number Diff line number Diff line change 13
13
"php" : " >=5.4.0" ,
14
14
"illuminate/support" : " ~5.0"
15
15
},
16
+ "require-dev" : {
17
+ "phpunit/phpunit" : " 3.7.*" ,
18
+ "mockery/mockery" : " 0.9.*" ,
19
+ "satooshi/php-coveralls" : " dev-master"
20
+ },
16
21
"autoload" : {
17
22
"psr-4" : {
18
23
"Laraplus\\ Form\\ " : " src/"
19
24
}
25
+ },
26
+ "autoload-dev" : {
27
+ "classmap" : [
28
+ " tests/TestCase.php"
29
+ ]
20
30
}
21
31
}
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <phpunit backupGlobals =" false"
3
+ backupStaticAttributes =" false"
4
+ bootstrap =" vendor/autoload.php"
5
+ colors =" true"
6
+ convertErrorsToExceptions =" true"
7
+ convertNoticesToExceptions =" true"
8
+ convertWarningsToExceptions =" true"
9
+ processIsolation =" false"
10
+ stopOnFailure =" false"
11
+ syntaxCheck =" false"
12
+ >
13
+ <testsuites >
14
+ <testsuite name =" Package Test Suite" >
15
+ <directory suffix =" .php" >./tests/</directory >
16
+ </testsuite >
17
+ </testsuites >
18
+ </phpunit >
Original file line number Diff line number Diff line change 4
4
use Laraplus \Form \Fields \Open ;
5
5
use Laraplus \Form \Fields \Text ;
6
6
use Laraplus \Form \Fields \Close ;
7
+ use Laraplus \Form \Fields \Group ;
7
8
use Laraplus \Form \Fields \Select ;
8
9
use Laraplus \Form \Fields \Submit ;
9
10
use Laraplus \Form \Fields \Password ;
Original file line number Diff line number Diff line change 1
1
<?php namespace Laraplus \Form ;
2
2
3
+ use Closure ;
3
4
use Exception ;
4
5
use ArrayAccess ;
5
6
use Laraplus \Form \Fields \Open ;
@@ -118,6 +119,23 @@ public function style($style = null)
118
119
return $ this ;
119
120
}
120
121
122
+
123
+ /**
124
+ * @param $name
125
+ * @param Closure $builder
126
+ * @return $this
127
+ */
128
+ public function group ($ name , Closure $ builder )
129
+ {
130
+ $ instance = new self ($ this ->presenter , $ this ->dataStore , $ this ->config );
131
+
132
+ $ builder ($ instance );
133
+
134
+ $ this ->elements [$ name ?: 'element- ' . count ($ this ->elements )] = $ instance ;
135
+
136
+ return $ this ;
137
+ }
138
+
121
139
/**
122
140
* @param string $style
123
141
* @return string
Original file line number Diff line number Diff line change
1
+ <?php namespace Laraplus \Form \Presenters ;
2
+
3
+ use Laraplus \Form \Fields \Base \Button ;
4
+ use Laraplus \Form \Fields \Open ;
5
+
6
+ class RawPresenter extends BasePresenter
7
+ {
8
+ /**
9
+ * @param Open $open
10
+ * @return string
11
+ */
12
+ public function renderOpeningTag (Open $ open )
13
+ {
14
+ return '<form ' . $ this ->renderAttributes ($ open ->attributes ) . '> ' ;
15
+ }
16
+
17
+ /**
18
+ * @param Button $button
19
+ * @return string
20
+ */
21
+ public function renderButton (Button $ button )
22
+ {
23
+ return '<button ' . $ this ->renderAttributes ($ button ->attributes ) . '> ' . $ button ->text . '</button> ' ;
24
+ }
25
+
26
+ /**
27
+ * @return string
28
+ */
29
+ public function renderLabel ()
30
+ {
31
+ return '<label for=" ' . $ this ->attributes ['id ' ] . '"> ' . $ this ->label . '</label> ' ;
32
+ }
33
+
34
+ /**
35
+ * @return string
36
+ */
37
+ public function renderField ()
38
+ {
39
+ return $ this ->element ->render ();
40
+ }
41
+
42
+ /**
43
+ * @return string
44
+ */
45
+ public function renderError ()
46
+ {
47
+ return '<strong> ' . $ this ->error . '</strong> ' ;
48
+ }
49
+
50
+ /**
51
+ * @return string
52
+ */
53
+ public function renderAll ()
54
+ {
55
+ return '<div> ' . $ this ->renderLabel () . $ this ->renderField () . $ this ->renderError () . '</div> ' ;
56
+ }
57
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ class TestBasicForm extends TestCase
4
+ {
5
+ public function testEmptyFormWithNoToken ()
6
+ {
7
+ $ expect = '<form method="GET" action="/"></form> ' ;
8
+
9
+ $ this ->form ->open ('test ' );
10
+ $ this ->form ->close ()->noToken ();
11
+
12
+ $ this ->assertEquals ($ expect , $ this ->clean ($ this ->form ));
13
+ }
14
+
15
+ public function testEmptyFormWithToken ()
16
+ {
17
+ $ expect = '<form method="GET" action="/"><input type="hidden" name="_token" value="secret_token" /></form> ' ;
18
+
19
+ $ this ->form ->open ('test ' );
20
+ $ this ->form ->close ();
21
+
22
+ $ this ->assertEquals ($ expect , $ this ->clean ($ this ->form ));
23
+ }
24
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Laraplus \Form \Contracts \ConfigProvider ;
4
+ use Laraplus \Form \Form ;
5
+ use Laraplus \Form \Contracts \DataStore ;
6
+ use Laraplus \Form \Presenters \RawPresenter ;
7
+
8
+ class TestCase extends PHPUnit_Framework_TestCase
9
+ {
10
+ protected $ form ;
11
+
12
+ public function setUp ()
13
+ {
14
+ $ presenter = new RawPresenter ();
15
+ $ dataStore = $ this ->emptyDataStore ();
16
+ $ configProvider = $ this ->emptyConfigProvider ();
17
+
18
+ $ this ->form = new Form ($ presenter , $ dataStore , $ configProvider );
19
+ }
20
+
21
+ protected function emptyDataStore ()
22
+ {
23
+ $ dataStore = Mockery::mock (DataStore::class);
24
+ $ dataStore ->shouldReceive ('getUrl ' )->andReturn ('/ ' );
25
+ $ dataStore ->shouldReceive ('getToken ' )->andReturn ('secret_token ' );
26
+
27
+ return $ dataStore ;
28
+ }
29
+
30
+ protected function emptyConfigProvider ()
31
+ {
32
+ $ config = Mockery::mock (ConfigProvider::class);
33
+ $ config ->shouldReceive ('get ' )->andReturn (null );
34
+
35
+ return $ config ;
36
+ }
37
+
38
+ protected function clean ($ string )
39
+ {
40
+ return str_replace ("\n" , '' , $ string );
41
+ }
42
+
43
+ public function tearDown ()
44
+ {
45
+ Mockery::close ();
46
+ }
47
+ }
You can’t perform that action at this time.
0 commit comments