12 public $fixtures = array(
22 public static function setUpBeforeClass(){
24 Yii::app()->getModule(
'apalines');
29 $this->CCRunner =
new CConsoleCommandRunner();
30 $this->sourcePath = Yii::getPathOfAlias(
'unit.apalines.content.source');
31 $this->workPath = Yii::getPathOfAlias(
'unit.apalines.content.work');
32 $this->contentPath = Yii::getPathOfAlias(
'unit.apalines.content');
33 if (!file_exists($this->workPath)) {
34 mkdir($this->workPath);
35 chmod($this->workPath, 0777);
37 $this->clearTestRecords();
40 public function clearTestRecords(){
55 foreach ($news as $docid) {
60 foreach ($mmNews as $docid) {
61 $mmFiles =
ApalinesMM::model()->find(
'docid = :docid', array(
':docid' => $docid));
69 public function testNewsWithImage(){
71 $this->moveToWork(
'NewsWithImage');
74 $newsDocId =
'49210316212944776';
75 $mmDocId =
'49210316212948366';
78 $this->assertNotEmpty($newsLine);
80 $newsMM =
ApalinesMM::model()->find(
'docid = :docid', array(
':docid' => $mmDocId));
81 $this->assertNotEmpty($newsMM);
83 $this->assertEquals($newsMM->related_maindoc_id, $newsLine->id);
85 $mmFiles =
ApalinesFile::model()->findAll(
'parent_id = :parent_id', array(
':parent_id' => $newsMM->id));
87 $this->assertEquals($newsMM->type, ApalinesMM::IMAGE);
89 $this->assertEquals(count($mmFiles), 2);
95 public function testNewsWithVideo(){
97 $this->moveToWork(
'NewsWithVideo');
100 $newsDocId =
'4913044392';
101 $mmDocId =
'4913044328';
104 $this->assertNotEmpty($newsLine);
106 $newsMM =
ApalinesMM::model()->find(
'docid = :docid', array(
':docid' => $mmDocId));
107 $this->assertNotEmpty($newsMM);
109 $this->assertEquals($newsMM->related_maindoc_id, $newsLine->id);
111 $mmFiles =
ApalinesFile::model()->findAll(
'parent_id = :parent_id', array(
':parent_id' => $newsMM->id));
113 $this->assertEquals($newsMM->type, ApalinesMM::VIDEO);
115 $this->assertEquals(count($mmFiles), 2);
121 public function testNewsWithoutMM(){
123 $this->moveToWork(
'NewsWithoutMM');
126 $newsDocId =
'49210316212959430';
129 $this->assertNotEmpty($newsLine);
134 public function testNewsWithBgNews(){
136 $this->moveToWork(
'NewsWithBgNews');
139 $newsDocId =
'49210316213015736';
140 $bgNews =
'49210316213019836';
143 $this->assertNotEmpty($newsLine);
146 $this->assertNotEmpty($bgNewsLine);
148 $this->assertEquals($newsLine->background_news, 1);
150 $this->assertEquals($newsLine->id, $bgNewsLine->related_maindoc_id);
153 $bgNewsLine->delete();
156 public function testNewsWithoutBgNews(){
158 $this->moveToWork(
'NewsWithoutBgNews');
161 $newsDocId =
'49210316212958320';
164 $this->assertNotEmpty($newsLine);
166 $this->assertEquals($newsLine->background_news, 0);
172 public function testNewsUpdate(){
174 $this->moveToWork(
'NewsUpdate/insert');
177 $newsDocId =
'49210316213005018';
180 $this->assertNotEmpty($newsLine);
182 $this->assertEquals($newsLine->title,
'Initial title of the news line');
184 $this->moveToWork(
'NewsUpdate/update');
187 $updNewsLine =
ApalinesNews::model()->find(
'docid = :docid', array(
':docid' => $newsDocId));
188 $this->assertNotEmpty($updNewsLine);
190 $this->assertEquals($updNewsLine->title,
'Updated title of the news line');
192 $this->assertEquals($updNewsLine->id, $newsLine->id);
194 $updNewsLine->delete();
197 public function testDeleteNews(){
199 $this->moveToWork(
'NewsDelete/insert');
202 $newsDocId =
'49210316213020304';
205 $this->assertNotEmpty($newsLine);
207 $this->moveToWork(
'NewsDelete/delete');
210 $newsLine =
ApalinesNews::model()->find(
'docid = :docid AND deleted <> 1', array(
':docid' => $newsDocId));
212 $this->assertEmpty($newsLine);
215 private function moveToWork($sourceFolder){
217 $dir = $this->workPath;
220 $sourcePath = $this->sourcePath . DIRECTORY_SEPARATOR .$sourceFolder;
221 if (is_dir($sourcePath)) {
222 if ($dh = opendir($sourcePath)) {
223 while (($file = readdir($dh)) !==
false){
224 $filePath = $sourcePath. DIRECTORY_SEPARATOR . $file;
225 if(!is_file($filePath)){
228 copy($filePath, $this->workPath. DIRECTORY_SEPARATOR . $file);
234 private function processApa($clear = 0){
236 $commandName =
'processApa';
238 $shell->actionIndex(
'unit_test', $clear);
241 private function setupIncron(){
243 $commandName =
'processApa';
245 $shell->actionSetup();
249 static function rrmdir($dir) {
251 $objects = scandir($dir);
252 foreach ($objects as $object) {
253 if ($object !=
"." && $object !=
"..") {
254 if (filetype($dir.
"/".$object) ==
"dir") self::rrmdir($dir.
"/".$object);
else unlink($dir.
"/".$object);