Skip to content

Commit 11d8bd3

Browse files
committed
fix tests
1 parent f59fc73 commit 11d8bd3

File tree

8 files changed

+52
-19
lines changed

8 files changed

+52
-19
lines changed

src/Goteo/Application/EventListener/SessionListener.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ public function onRequest(GetResponseEvent $event) {
6666
// reduce host: ca.goteo.org => goteo.org
6767
$host = implode('.', $parts);
6868
}
69-
ini_set('session.cookie_domain', ".$host");
69+
if(!Session::getSession()->isStarted()) {
70+
ini_set('session.cookie_domain', ".$host");
71+
}
7072
}
7173
Session::start('goteo-' . Config::get('env'), Config::get('session.time'));
7274

src/Goteo/Model/User/UserRoles.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function getRoleNames() {
121121
*/
122122
public function save(&$errors = []) {
123123
$values = [':user_id' => $this->user->id];
124-
$inserts = '';
124+
$inserts = [];
125125
$i = 0;
126126
foreach($this as $role => $permissions) {
127127
if($role !== 'user') {

tests/Goteo/Application/RoleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testAddPermissions() {
9898
$this->assertInternalType('array', $permissions);
9999
$this->assertArrayHasKey('perm-test1', $permissions);
100100
$this->assertArrayHasKey('perm-test2', $permissions);
101-
$this->assertContains('testmodel', $permissions['perm-test2']);
101+
$this->assertContains('user_testmodel', $permissions['perm-test2']['relational'], print_r($permissions['perm-test2'], 1));
102102

103103
}
104104

tests/Goteo/Model/Blog/Post/CommentTest.php

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
namespace Goteo\Model\Blog\Post\Tests;
55

66
use Goteo\Model\Blog\Post\Comment;
7+
use Goteo\Model\Blog\Post;
78

89
class CommentTest extends \PHPUnit_Framework_TestCase {
9-
private static $data = array('text' => 'Test comment', 'post' => 1, 'user' => 'test');
10+
private static $data = array('text' => 'Test comment');
11+
private static $post_data = array('title' => 'Test post', 'text' => 'test text',
12+
'blog' => 1,
13+
'date' => '2015-01-01',
14+
'allow' => 1,
15+
'publish' => 1);
1016

1117
public function testInstance() {
1218
\Goteo\Core\DB::cache(false);
@@ -26,10 +32,23 @@ public function testValidate($ob) {
2632
$this->assertFalse($ob->save());
2733
}
2834

29-
public function testCreate() {
30-
$ob = new Comment(self::$data);
35+
public function testCreatePost() {
36+
$errors = [];
37+
$ob = new Post(self::$post_data);
3138
$this->assertTrue($ob->validate($errors));
32-
$this->assertTrue($ob->save());
39+
$this->assertTrue($ob->save($errors), print_r($errors, 1));
40+
return $ob;
41+
}
42+
/**
43+
* @depends testCreatePost
44+
*/
45+
public function testCreate($post) {
46+
$errors = [];
47+
self::$data['post'] = $post->id;
48+
self::$data['user'] = get_test_user()->id;
49+
$ob = new Comment(self::$data);
50+
$this->assertTrue($ob->validate($errors), print_r($errors, 1));
51+
$this->assertTrue($ob->save($errors), print_r($errors, 1));
3352
$ob = Comment::get($ob->id);
3453
$this->assertInstanceOf('\Goteo\Model\Blog\Post\Comment', $ob);
3554

@@ -53,4 +72,13 @@ public function testNonExisting($ob) {
5372
$this->assertFalse($ob);
5473
$this->assertFalse(Comment::delete($ob->id));
5574
}
75+
76+
77+
/**
78+
* Some cleanup
79+
*/
80+
static function tearDownAfterClass() {
81+
Post::query('delete from `post` where id = ?', self::$data['post']);
82+
delete_test_user();
83+
}
5684
}

tests/Goteo/Model/LogTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use Goteo\TestCase;
77
use Goteo\Model\Log;
8+
use Goteo\Application\Session;
89

910
class LogTest extends TestCase {
1011
private static $data = ['scope' => 'test', 'target_type' => 'user', 'text' => 'Log test text'];
@@ -59,6 +60,7 @@ public function testNonExisting($ob) {
5960
* @depends testDelete
6061
*/
6162
public function testAppend($ob) {
63+
Session::setUser(get_test_user());
6264
try {
6365
Log::append();
6466
} catch(\Exception $e) {
@@ -73,8 +75,8 @@ public function testAppend($ob) {
7375
* Some cleanup
7476
*/
7577
static function tearDownAfterClass() {
76-
delete_test_node();
77-
delete_test_project();
7878
delete_test_user();
79+
delete_test_project();
80+
delete_test_node();
7981
}
8082
}

tests/Goteo/Model/MatcherTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public function testAddUsers($ob) {
121121
//Creates users first
122122
foreach(self::$user_data as $i => $user) {
123123
if(!($uob = User::get($user['userid']))) {
124-
echo "\nCreating user [{$user[userid]}]";
124+
echo "\nCreating user [{$user['userid']}]";
125125
$uob = new User($user);
126126
$this->assertTrue($uob->save($errors, ['active']), print_r($errors, 1));
127127
}
128128

129129
$this->assertInstanceOf('\Goteo\Model\User', $uob, print_r($errors, 1));
130130

131131
self::$user_data[$i]['ob'] = $uob;
132-
echo "\nSetting user's pool [{$user[userid]}]";
132+
echo "\nSetting user's pool [{$user['userid']}]";
133133
Matcher::query("REPLACE invest (`user`, amount, status, method, invested, charged, pool) VALUES (:user, :amount, :status, 'dummy', NOW(), NOW(), 1)", [':user' => $user['userid'], ':amount' => $user['pool'], ':status' => Invest::STATUS_TO_POOL]);
134134
Matcher::query("REPLACE user_pool (`user`, amount) VALUES (:user, :amount)", [':user' => $user['userid'], ':amount' => $user['pool']]);
135135
$this->assertEquals($user['pool'], $uob->getPool()->amount);
@@ -302,11 +302,11 @@ public function testNonExisting($ob) {
302302

303303
public function testCleanUsers() {
304304
foreach(self::$user_data as $user) {
305-
echo "\nDeleting user [{$user[userid]}]";
305+
echo "\nDeleting user [{$user['userid']}]";
306306
Matcher::query("DELETE FROM user_pool WHERE `user` = ?", $user['userid']);
307307
Matcher::query("DELETE FROM invest WHERE `user` = ?", $user['userid']);
308308
$user['ob']->dbDelete();
309-
$this->assertEquals(0, Matcher::query("SELECT COUNT(*) FROM `user` WHERE id = ?", $user['userid'])->fetchColumn(), "Unable to delete user [{$user[userid]}]. Please delete id manually");
309+
$this->assertEquals(0, Matcher::query("SELECT COUNT(*) FROM `user` WHERE id = ?", $user['userid'])->fetchColumn(), "Unable to delete user [{$user['userid']}]. Please delete id manually");
310310
}
311311
}
312312

tests/Goteo/Model/User/UserRolesTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function testAddRoles($roles) {
6060
*/
6161
public function testRoleNames($roles) {
6262
$this->assertInternalType('array', $roles->getRoleNames());
63-
$this->assertContains('user', $roles->getRoleNames());
64-
$this->assertContains('admin', $roles->getRoleNames());
63+
$this->assertArrayHasKey('user', $roles->getRoleNames(), print_r($roles->getRoleNames(), 1));
64+
$this->assertArrayHasKey('admin', $roles->getRoleNames());
6565
}
6666

6767
/**
@@ -88,6 +88,7 @@ public function testRemoveRoles($roles) {
8888
* @depends testRemoveRoles
8989
*/
9090
public function testPersistence($roles) {
91+
$errors = [];
9192
$this->assertInstanceOf('Goteo\Model\User\UserRoles', $roles->addRole('admin'));
9293
$this->assertTrue($roles->save($errors), print_r($errors, true));
9394
return $roles;

tests/Goteo/Util/MatcherProcessor/DuplicateInvestMatcherProcessorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testAddUsers($matcher) {
4747
//Creates users first
4848
foreach(self::$user_data as $i => $user) {
4949
if(!($uob = User::get($user['userid']))) {
50-
echo "\nCreating user [{$user[userid]}]";
50+
echo "\nCreating user [{$user['userid']}]";
5151
$uob = new User($user);
5252
$this->assertTrue($uob->save($errors, ['active']), print_r($errors, 1));
5353
}
@@ -57,7 +57,7 @@ public function testAddUsers($matcher) {
5757
self::$user_data[$i]['ob'] = $uob;
5858
if(isset($user['pool'])) {
5959

60-
echo "\nSetting user's pool [{$user[userid]}]";
60+
echo "\nSetting user's pool [{$user['userid']}]";
6161
Matcher::query("REPLACE invest (`user`, amount, status, method, invested, charged, pool) VALUES (:user, :amount, :status, 'dummy', NOW(), NOW(), 1)", [':user' => $user['userid'], ':amount' => $user['pool'], ':status' => Invest::STATUS_TO_POOL]);
6262

6363
Matcher::query("REPLACE user_pool (`user`, amount) VALUES (:user, :amount)", [':user' => $user['userid'], ':amount' => $user['pool']]);
@@ -251,11 +251,11 @@ public function testDelete($matcher) {
251251
}
252252
public function testCleanUsers() {
253253
foreach(self::$user_data as $user) {
254-
echo "\nDeleting user [{$user[userid]}]";
254+
echo "\nDeleting user [{$user['userid']}]";
255255
Matcher::query("DELETE FROM invest WHERE `user` = ?", $user['userid']);
256256
Matcher::query("DELETE FROM user_pool WHERE `user` = ?", $user['userid']);
257257
$user['ob']->dbDelete();
258-
$this->assertEquals(0, Matcher::query("SELECT COUNT(*) FROM `user` WHERE id = ?", $user['userid'])->fetchColumn(), "Unable to delete user [{$user[userid]}]. Please delete id manually");
258+
$this->assertEquals(0, Matcher::query("SELECT COUNT(*) FROM `user` WHERE id = ?", $user['userid'])->fetchColumn(), "Unable to delete user [{$user['userid']}]. Please delete id manually");
259259
}
260260
}
261261

0 commit comments

Comments
 (0)