Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
BulkTest.php
1 <?php
2 /**
3  * Created by JetBrains PhpStorm.
4  * User: Andrey
5  * Date: 5/22/13
6  * Time: 11:26 AM
7  * To change this template use File | Settings | File Templates.
8  */
9 
10 class BulkTest extends CDbTestCase{
11 
12  public $fixtures = array(
13 
14  );
15 
16  public $bulkController;
17 
18  public static function setUpBeforeClass(){
19 
20  Yii::app()->getModule('bulk')->setImport(array('bulk.controllers.*'));
21  }
22 
23  public function setUp(){
24 
25  $this->bulkController = new BulkController('test');
26 
27  ob_start();
28  $this->bulkController->actionClear('all');
29 
30  $bufferClearResults = ob_get_contents();
31  ob_end_clean();
32 
33  preg_match("/Clear complete/", $bufferClearResults, $match);
34  $this->assertNotEmpty($match, "Clear failed");
35  }
36 
37  public function testBulkUsers(){
38 
39  $_GET['GenerationForm'] = array(
40  'usersQty'=> "5",
41  'likesQty'=> "",
42  'likesContentId'=>"",
43  'commentsQty'=>"",
44  'commentsForEach'=>"0",
45  'commentsContentId'=>""
46  );
47  ob_start();
48 
49  $this->bulkController->actionGenerate();
50 
51  $bufferAddUsersResults = ob_get_contents();
52  ob_end_clean();
53 
54  preg_match("/Generation complete/s", $bufferAddUsersResults, $match);
55  $this->assertNotEmpty($match, "Users were not added");
56 
57  $usersQty = User::model()->count('is_bulk = :is_bulk', array(':is_bulk' => true));
58  $this->assertEquals($usersQty, 5, "Incorrect count of the bulk users");
59 
60  preg_match("/Users: (?P<count>\d+)/s", $bufferAddUsersResults, $match);
61  $this->assertNotEmpty($match, "Users addition failed");
62 
63  $this->bulkComments();
64 
65  $this->bulkLikes();
66  }
67 
68  public function bulkComments(){
69 
70  $_GET['GenerationForm'] = array(
71  'usersQty'=> "",
72  'likesQty'=> "",
73  'likesContentId'=>"",
74  'commentsQty'=>"5",
75  'commentsForEach'=>"0",
76  'commentsContentId'=>""
77  );
78  ob_start();
79 
80  $this->bulkController->actionGenerate();
81 
82  $bufferAddCommentsResults = ob_get_contents();
83  ob_end_clean();
84 
85  preg_match("/Generation complete/s", $bufferAddCommentsResults, $match);
86  $this->assertNotEmpty($match, "Comments were not added");
87 
88  $commentsQty = Yii::app()->db->createCommand()
89  ->select('count(*)')
90  ->from(Comment::model()->tableName())
91  ->join(User::model()->tableName() . ' as u', 'u.id = user_id')
92  ->where('is_bulk = :is_bulk', array(':is_bulk' => true))
93  ->queryScalar();
94 
95  $this->assertEquals($commentsQty, 5, "Incorrect count of the bulk comments");
96 
97  preg_match("/Comments: (?P<count>\d+)/s", $bufferAddCommentsResults, $match);
98  $this->assertNotEmpty($match, "Comments addition failed");
99  }
100 
101  public function bulkLikes(){
102 
103  $_GET['GenerationForm'] = array(
104  'usersQty'=> "",
105  'likesQty'=> "5",
106  'likesContentId'=>"",
107  'commentsQty'=>"",
108  'commentsForEach'=>"0",
109  'commentsContentId'=>""
110  );
111  ob_start();
112 
113  $this->bulkController->actionGenerate();
114 
115  $bufferAddLikesResults = ob_get_contents();
116  ob_end_clean();
117 
118  preg_match("/Generation complete/s", $bufferAddLikesResults, $match);
119  $this->assertNotEmpty($match, "Likes were not added");
120 
121  $likesQty = Yii::app()->db->createCommand()
122  ->select('count(*)')
123  ->from(Like::model()->tableName())
124  ->join(User::model()->tableName() . ' as u', 'u.id = user_id')
125  ->where('is_bulk = :is_bulk', array(':is_bulk' => true))
126  ->queryScalar();
127 
128  $this->assertEquals($likesQty, 5, "Incorrect count of the bulk likes");
129 
130  preg_match("/Likes: (?P<count>\d+)/s", $bufferAddLikesResults, $match);
131  $this->assertNotEmpty($match, "Likes addition failed");
132 
133  if(count($match)){
134  $this->assertEquals($match['count'], 5, "Incorrect count of the inserts is shown");
135  }
136  }
137 }