forked from FriendsOfPHP/Sismo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appTest.php
135 lines (101 loc) · 4.77 KB
/
appTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*
* This file is part of the Sismo utility.
*
* (c) Fabien Potencier <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
use Silex\WebTestCase;
use Sismo\Project;
use Symfony\Component\HttpKernel\Util\Filesystem;
class AppTest extends WebTestCase
{
protected $baseDir;
public function createApp()
{
$app = require __DIR__.'/../src/bootstrap.php';
$this->baseDir = sys_get_temp_dir().'/sismo';
$fs = new Filesystem();
$fs->mkdir($this->baseDir);
$fs->mkdir($this->baseDir.'/config');
$app['data.path'] = $this->baseDir.'/db';
$app['config.file'] = $this->baseDir.'/config.php';
@unlink($this->app['db.path']);
file_put_contents($app['config.file'], '<?php return array();');
require __DIR__.'/../src/app.php';
return $app;
}
public function tearDown()
{
parent::tearDown();
$fs = new Filesystem();
$fs->remove($this->baseDir);
}
public function testGetProjectsEmpty()
{
$crawler = $this->createClient()->request('GET', '/');
$this->assertEquals(1, count($crawler->filter('p:contains("No project yet.")')));
}
public function testPages()
{
$sismo = $this->app['sismo'];
$storage = $this->app['storage'];
$sismo->addProject(new Project('Twig'));
$sismo->addProject($project1 = new Project('Silex1'));
$commit = $storage->initCommit($project1, '7d78d5', 'fabien', new \DateTime(), 'foo');
$storage->updateProject($project1);
$sismo->addProject($project2 = new Project('Silex2'));
$commit = $storage->initCommit($project2, '7d78d5', 'fabien', new \DateTime(), 'foo');
$commit->setStatusCode('success');
$storage->updateCommit($commit);
$storage->updateProject($project2);
$sismo->addProject($project3 = new Project('Silex3'));
$commit = $storage->initCommit($project3, '7d78d5', 'fabien', new \DateTime(), 'foo');
$commit->setStatusCode('failed');
$storage->updateCommit($commit);
$storage->updateProject($project3);
// projects page
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$this->assertEquals(array('Twig', 'Silex1', 'Silex2', 'Silex3'), $crawler->filter('ul#projects li a')->each(function ($node) { return trim($node->nodeValue); }));
$this->assertEquals(array('not built yet', 'building', 'succeeded', 'failed'), $crawler->filter('ul#projects li div')->each(function ($node) { return trim($node->nodeValue); }));
$this->assertEquals(array('no_build', 'building', 'success', 'failed'), $crawler->filter('ul#projects li')->extract('class'));
$links = $crawler->filter('ul#projects li a')->links();
// project page
$crawler = $client->click($links[0]);
$this->assertEquals(1, count($crawler->filter('p:contains("Never built yet.")')));
$crawler = $client->click($links[1]);
$this->assertEquals('#7d78d5 building', trim($crawler->filter('div.commit')->text()));
$crawler = $client->click($links[2]);
$this->assertEquals('#7d78d5 succeeded', trim($crawler->filter('div.commit')->text()));
$crawler = $client->click($links[3]);
$this->assertEquals('#7d78d5 failed', trim($crawler->filter('div.commit')->text()));
// sha page
$crawler = $client->request('GET', '/silex2/7d78d5');
$this->assertEquals('#7d78d5 succeeded', trim($crawler->filter('div.commit')->text()));
// cc tray
$crawler = $client->request('GET', '/dashboard/cctray.xml');
$this->assertEquals(4, count($crawler->filter('Project')));
$this->assertEquals(array('Unknown', 'Unknown', 'Success', 'Failure'), $crawler->filter('Project')->extract('lastBuildStatus'));
$this->assertEquals(array('Sleeping', 'Building', 'Sleeping', 'Sleeping'), $crawler->filter('Project')->extract('activity'));
}
public function testGetNonExistentProject()
{
$crawler = $this->createClient()->request('GET', '/foobar');
$this->assertEquals('Project "foobar" not found.', $crawler->filter('p')->text());
}
public function testGetNonExistentProjectOnShaPage()
{
$crawler = $this->createClient()->request('GET', '/foo/bar');
$this->assertEquals('Project "foo" not found.', $crawler->filter('p')->text());
}
public function testGetNonExistentSha()
{
$sismo = $this->app['sismo'];
$sismo->addProject(new Project('Twig'));
$crawler = $this->createClient()->request('GET', '/twig/bar');
$this->assertEquals('Commit "bar" for project "twig" not found.', $crawler->filter('p')->text());
}
}