Skip to content

Commit 4c888f7

Browse files
committed
Added functional tests for DefaultController main action
1 parent d0c46e5 commit 4c888f7

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: fpapadopou
5+
* Date: 4/20/15
6+
* Time: 12:07 PM
7+
*/
8+
9+
namespace Codebender\BuilderBundle\Tests\Controller;
10+
11+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
12+
use Symfony\Bundle\FrameworkBundle\Client;
13+
14+
class DefaultControllerFunctionalTest extends WebTestCase
15+
{
16+
public function testStatusAction() {
17+
$client = static::createClient();
18+
19+
$client->request('GET', '/status');
20+
21+
$this->assertEquals($client->getResponse()->getContent(), '{"success":true,"status":"OK"}');
22+
}
23+
24+
public function testHandleRequestGet() {
25+
$client = static::createClient();
26+
27+
/*
28+
* Using the same auth key and version like the ones in the dist parameter file
29+
*/
30+
$client->request('GET', '/authKey/v1');
31+
32+
$this->assertEquals($client->getResponse()->getStatusCode(), 405);
33+
}
34+
35+
public function testHandleRequestCompile() {
36+
$client = static::createClient();
37+
38+
$client
39+
->request(
40+
'POST',
41+
'authenticationekey/version',
42+
$parameters = array(),
43+
$files = array(),
44+
$server = array(),
45+
$content = '{"type":"compiler","data":{"files":[{"filename":"project.ino","content":"void setup(){\n\n}\nvoid loop(){\n\n}\n"}],"format":"binary","version":"105","build":{"mcu":"atmega328p","f_cpu":"16000000L","core":"arduino","variant":"standard"}}}',
46+
$changeHistory = true);
47+
48+
$response = json_decode($client->getResponse()->getContent(), true);
49+
$this->assertArrayHasKey('success', $response);
50+
$this->assertEquals($response['success'], true);
51+
$this->assertArrayHasKey('time', $response);
52+
}
53+
54+
public function testHandleRequestLibraryFetching() {
55+
$client = static::createClient();
56+
57+
$client
58+
->request(
59+
'POST',
60+
'authenticationekey/version',
61+
$parameters = array(),
62+
$files = array(),
63+
$server = array(),
64+
$content = '{"type":"library","data":{"type":"fetch","library":"Ethernet"}}',
65+
$changeHistory = true);
66+
67+
$response = json_decode($client->getResponse()->getContent(), true);
68+
$this->assertArrayHasKey('success', $response);
69+
$this->assertEquals($response['success'], true);
70+
$this->assertArrayHasKey('message', $response);
71+
$this->assertEquals($response['message'], 'Library found');
72+
}
73+
74+
public function testHandleRequestLibraryKeywords() {
75+
$client = static::createClient();
76+
77+
$client
78+
->request(
79+
'POST',
80+
'authenticationekey/version',
81+
$parameters = array(),
82+
$files = array(),
83+
$server = array(),
84+
$content = '{"type":"library","data":{"type":"getKeywords","library":"Ethernet"}}',
85+
$changeHistory = true);
86+
87+
$response = json_decode($client->getResponse()->getContent(), true);
88+
89+
$this->assertArrayHasKey('success', $response);
90+
$this->assertEquals($response['success'], true);
91+
$this->assertArrayHasKey('keywords', $response);
92+
$this->assertTrue(is_array($response['keywords']));
93+
}
94+
}

0 commit comments

Comments
 (0)