@@ -17,100 +17,100 @@ public function call_checkHeaders($files, $personallib)
17
17
18
18
class DefaultControllerUnitTest extends \PHPUnit_Framework_TestCase
19
19
{
20
- public function testCompilelibrariesAction_Success ()
21
- {
22
- $ controller = $ this ->getMock ("Codebender\ApiBundle\Controller\DefaultController " , array ("get " , "getRequest " , "checkHeaders " ));
23
-
24
- $ request = $ this ->getMockBuilder ("Symfony\Component\HttpFoundation\Request " )
25
- ->disableOriginalConstructor ()
26
- ->setMethods (array ('getContent ' ))
27
- ->getMock ();
28
-
29
- $ container = $ this ->getMockBuilder ("Symfony\Component\DependencyInjection\ContainerInterface " )
30
- ->disableOriginalConstructor ()
31
- ->setMethods (array ('getParameter ' ))
32
- ->getMockForAbstractClass ();
33
-
34
- $ handler = $ this ->getMockBuilder ("Codebender\ApiBundle\Handler\DefaultHandler " )
35
- ->disableOriginalConstructor ()
36
- ->setMethods (array ("get " , "post_raw_data " ))
37
- ->getMock ();
38
-
39
- $ controller ->setContainer ($ container );
40
-
41
- $ container ->expects ($ this ->at (0 ))->method ('getParameter ' )->with ($ this ->equalTo ('auth_key ' ))->will ($ this ->returnValue ('auth1sandip ' ));
42
- $ container ->expects ($ this ->at (1 ))->method ('getParameter ' )->with ($ this ->equalTo ('version ' ))->will ($ this ->returnValue ('v1 ' ));
43
-
44
- $ controller ->expects ($ this ->once ())->method ('getRequest ' )->will ($ this ->returnValue ($ request ));
45
- $ request ->expects ($ this ->once ())->method ('getContent ' )->will ($ this ->returnValue ('{"files":[{"filename":"project.ino","content":"#include <header.h> #include \"header2.h\" "}],"format":"binary","version":"105","build":{"mcu":"atmega328p","f_cpu":"16000000L","core":"arduino","variant":"standard"},"libraries":[{"0":" header.h"}]} ' ));
46
-
47
- $ controller ->expects ($ this ->once ())->method ('get ' )->with ($ this ->equalTo ('codebender_api.handler ' ))->will ($ this ->returnValue ($ handler ));
48
- $ container ->expects ($ this ->at (2 ))->method ('getParameter ' )->with ($ this ->equalTo ('library ' ))->will ($ this ->returnValue ('http://library/url ' ));
49
- $ container ->expects ($ this ->at (3 ))->method ('getParameter ' )->with ($ this ->equalTo ('compiler ' ))->will ($ this ->returnValue ('http://compiler/url ' ));
50
-
51
- $ controller ->expects ($ this ->once ())->method ('checkHeaders ' )->with (array (0 =>array ('filename ' =>'project.ino ' ,'content ' =>'#include <header.h> #include "header2.h" ' )), array (0 =>array (0 =>'header.h ' )))->will ($ this ->returnValue (array ('libraries ' => array ('header ' =>array (0 =>array ("filename " =>"header.h " ,"content " =>"" ))), 'foundFiles ' => array (), 'notFoundHeaders ' => array ())));
52
-
53
- $ handler ->expects ($ this ->once ())->method ('post_raw_data ' )->with ($ this ->equalTo ('http://compiler/url ' ), $ this ->equalTo ('{"files":[{"filename":"project.ino","content":"#include <header.h> #include \"header2.h\" "}],"format":"binary","version":"105","build":{"mcu":"atmega328p","f_cpu":"16000000L","core":"arduino","variant":"standard"},"libraries":{"header":[{"filename":"header.h","content":""}]}} ' ))->will ($ this ->returnValue ('{"success":true} ' ));
54
-
55
- $ response = $ controller ->compilelibrariesAction ('auth1sandip ' , 'v1 ' );
56
-
57
- $ this ->assertEquals ($ response ->getContent (), '{"success":true,"library":{"header":[{"filename":"header.h","content":""}]},"foundFiles":[],"notFoundHeaders":[],"compileResponse":"{\"success\":true}"} ' );
58
- }
59
-
60
- public function testCompilelibrariesAction_unAuthrize ()
61
- {
62
- $ controller = $ this ->getMock ("Codebender\ApiBundle\Controller\DefaultController " , array ("get " , "getRequest " , "checkHeaders " ));
63
-
64
- $ request = $ this ->getMockBuilder ("Symfony\Component\HttpFoundation\Request " )
65
- ->disableOriginalConstructor ()
66
- ->setMethods (array ('getContent ' ))
67
- ->getMock ();
68
-
69
- $ container = $ this ->getMockBuilder ("Symfony\Component\DependencyInjection\ContainerInterface " )
70
- ->disableOriginalConstructor ()
71
- ->setMethods (array ('getParameter ' ))
72
- ->getMockForAbstractClass ();
73
-
74
- $ controller ->setContainer ($ container );
75
-
76
- $ container ->expects ($ this ->at (0 ))->method ('getParameter ' )->with ($ this ->equalTo ('auth_key ' ))->will ($ this ->returnValue ('auth1 ' ));
77
-
78
- $ response = $ controller ->compilelibrariesAction ('auth1sandip ' , 'v1 ' );
79
-
80
- $ this ->assertEquals ($ response ->getContent (), '{"success":false,"step":0,"message":"Invalid authorization key."} ' );
81
- }
82
-
83
- public function testCheckHeaders_success ()
84
- {
85
- $ controller = $ this ->getMock ("Codebender\ApiBundle\Tests\Controller\ProtectedDefaultControllerTester " , array ("get " , "getRequest " ));
86
-
87
- $ handler = $ this ->getMockBuilder ("Codebender\ApiBundle\Handler\DefaultHandler " )
88
- ->disableOriginalConstructor ()
89
- ->setMethods (array ("get " , "read_libraries " ))
90
- ->getMock ();
91
-
92
- $ container = $ this ->getMockBuilder ("Symfony\Component\DependencyInjection\ContainerInterface " )
93
- ->disableOriginalConstructor ()
94
- ->setMethods (array ('getParameter ' ))
95
- ->getMockForAbstractClass ();
96
-
97
- $ request = $ this ->getMockBuilder ("Symfony\Component\HttpFoundation\Request " )
98
- ->disableOriginalConstructor ()
99
- ->getMock ();
100
-
101
- $ controller ->setContainer ($ container );
102
-
103
- $ controller ->expects ($ this ->once ())->method ('get ' )->with ($ this ->equalTo ('codebender_api.handler ' ))->will ($ this ->returnValue ($ handler ));
104
- $ handler ->expects ($ this ->once ())->method ('read_libraries ' )->with ($ this ->equalTo (array (array ('filename ' => 'header.h ' , 'content ' => '' ), array ('filename ' => 'project.ino ' , 'content ' => '' ))))->will ($ this ->returnValue (array ('header ' )));
105
-
106
- $ container ->expects ($ this ->once ())->method ('getParameter ' )->with ($ this ->equalTo ('library ' ))->will ($ this ->returnValue ('http://library/url ' ));
107
-
108
- $ handler ->expects ($ this ->once ())->method ('get ' )->with ($ this ->equalTo ('http://library/url/fetch?library=header ' ))->will ($ this ->returnValue ('{"success":true,"message":"Library found","files":[{"filename":"header.h","content":""}]} ' ));
109
-
110
- $ response = $ controller ->call_checkHeaders (array (array ('filename ' => 'header.h ' , 'content ' => '' ), array ('filename ' => 'project.ino ' , 'content ' => '' )), array ());
111
-
112
- $ this ->assertEquals ($ response , array ('libraries ' => array ('header ' =>array (0 =>array ('filename ' =>'header.h ' , 'content ' =>'' ))), 'foundFiles ' => array (0 =>'header.h ' ), 'notFoundHeaders ' => array ()));
113
- }
20
+ // public function testCompileWebsiteAction_Success ()
21
+ // {
22
+ // $controller = $this->getMock("Codebender\ApiBundle\Controller\DefaultController", array("get", "getRequest", "checkHeaders"));
23
+ //
24
+ // $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")
25
+ // ->disableOriginalConstructor()
26
+ // ->setMethods(array('getContent'))
27
+ // ->getMock();
28
+ //
29
+ // $container = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")
30
+ // ->disableOriginalConstructor()
31
+ // ->setMethods(array('getParameter'))
32
+ // ->getMockForAbstractClass();
33
+ //
34
+ // $handler = $this->getMockBuilder("Codebender\ApiBundle\Handler\DefaultHandler")
35
+ // ->disableOriginalConstructor()
36
+ // ->setMethods(array("get", "post_raw_data"))
37
+ // ->getMock();
38
+ //
39
+ // $controller->setContainer($container);
40
+ //
41
+ // $container->expects($this->at(0))->method('getParameter')->with($this->equalTo('auth_key'))->will($this->returnValue('myAuthKey '));
42
+ // $container->expects($this->at(1))->method('getParameter')->with($this->equalTo('version'))->will($this->returnValue('v1'));
43
+ //
44
+ // $controller->expects($this->once())->method('getRequest')->will($this->returnValue($request));
45
+ // $request->expects($this->once())->method('getContent')->will($this->returnValue('{"files":[{"filename":"project.ino","content":"#include <header.h> #include \"header2.h\" "}],"format":"binary","version":"105","build":{"mcu":"atmega328p","f_cpu":"16000000L","core":"arduino","variant":"standard"},"libraries":[{"0":{"1_cb_personal_lib_UTFT":{0:{"filename":" header.h","content":"#define MYDEF"},1:{"filename":"file.cpp","content":"#include \"header.h\""}}} }]}' ));
46
+ //
47
+ // $controller->expects($this->once())->method('get')->with($this->equalTo('codebender_api.handler'))->will($this->returnValue($handler));
48
+ //// $container->expects($this->at(2))->method('getParameter')->with($this->equalTo('library'))->will($this->returnValue('http://library/url'));
49
+ // $container->expects($this->at(3))->method('getParameter')->with($this->equalTo('compiler'))->will($this->returnValue('http://compiler/url'));
50
+ //
51
+ // $controller->expects($this->once())->method('checkHeaders')->with(array(0=>array('filename'=>'project.ino','content'=>'#include <header.h> #include "header2.h" ')), array(0=>array(0=>'header.h')))->will($this->returnValue(array('libraries' => array('header'=>array(0=>array("filename"=>"header.h","content"=>""))), 'foundFiles' => array(), 'notFoundHeaders' => array())));
52
+ //
53
+ // $handler->expects($this->once())->method('post_raw_data')->with($this->equalTo('http://compiler/url'), $this->equalTo('{"files":[{"filename":"project.ino","content":"#include <header.h> #include \"header2.h\" "}],"format":"binary","version":"105","build":{"mcu":"atmega328p","f_cpu":"16000000L","core":"arduino","variant":"standard"},"libraries":{"header":[{"filename":"header.h","content":""}]}}'))->will($this->returnValue('{"success":true}'));
54
+ //
55
+ // $response = $controller->compileWebsiteAction ('auth1sandip', 'v1');
56
+ //
57
+ // $this->assertEquals($response->getContent(), '{"success":true,"library":{"header":[{"filename":"header.h","content":""}]},"foundFiles":[],"notFoundHeaders":[],"compileResponse":"{\"success\":true}"}');
58
+ // }
59
+ //
60
+ // public function testCompileWebsiteAction_unAuthorize ()
61
+ // {
62
+ // $controller = $this->getMock("Codebender\ApiBundle\Controller\DefaultController", array("get", "getRequest", "checkHeaders"));
63
+ //
64
+ // $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")
65
+ // ->disableOriginalConstructor()
66
+ // ->setMethods(array('getContent'))
67
+ // ->getMock();
68
+ //
69
+ // $container = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")
70
+ // ->disableOriginalConstructor()
71
+ // ->setMethods(array('getParameter'))
72
+ // ->getMockForAbstractClass();
73
+ //
74
+ // $controller->setContainer($container);
75
+ //
76
+ // $container->expects($this->at(0))->method('getParameter')->with($this->equalTo('auth_key'))->will($this->returnValue('auth1'));
77
+ //
78
+ // $response = $controller->compilelibrariesAction('auth1sandip', 'v1');
79
+ //
80
+ // $this->assertEquals($response->getContent(), '{"success":false,"step":0,"message":"Invalid authorization key."}');
81
+ // }
82
+ //
83
+ // public function testCheckHeaders_success()
84
+ // {
85
+ // $controller = $this->getMock("Codebender\ApiBundle\Tests\Controller\ProtectedDefaultControllerTester", array("get", "getRequest"));
86
+ //
87
+ // $handler = $this->getMockBuilder("Codebender\ApiBundle\Handler\DefaultHandler")
88
+ // ->disableOriginalConstructor()
89
+ // ->setMethods(array("get", "read_libraries"))
90
+ // ->getMock();
91
+ //
92
+ // $container = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")
93
+ // ->disableOriginalConstructor()
94
+ // ->setMethods(array('getParameter'))
95
+ // ->getMockForAbstractClass();
96
+ //
97
+ // $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")
98
+ // ->disableOriginalConstructor()
99
+ // ->getMock();
100
+ //
101
+ // $controller->setContainer($container);
102
+ //
103
+ // $controller->expects($this->once())->method('get')->with($this->equalTo('codebender_api.handler'))->will($this->returnValue($handler));
104
+ // $handler->expects($this->once())->method('read_libraries')->with($this->equalTo(array(array('filename' => 'header.h', 'content' => ''), array('filename' => 'project.ino', 'content' => ''))))->will($this->returnValue(array('header')));
105
+ //
106
+ // $container->expects($this->once())->method('getParameter')->with($this->equalTo('library'))->will($this->returnValue('http://library/url'));
107
+ //
108
+ // $handler->expects($this->once())->method('get')->with($this->equalTo('http://library/url/fetch?library=header'))->will($this->returnValue('{"success":true,"message":"Library found","files":[{"filename":"header.h","content":""}]}'));
109
+ //
110
+ // $response = $controller->call_checkHeaders(array(array('filename' => 'header.h', 'content' => ''), array('filename' => 'project.ino', 'content' => '')), array());
111
+ //
112
+ // $this->assertEquals($response, array('libraries' => array('header'=>array(0=>array('filename'=>'header.h', 'content'=>''))), 'foundFiles' => array(0=>'header.h'), 'notFoundHeaders' => array()));
113
+ // }
114
114
115
115
116
116
}
0 commit comments