-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathCourseTester.php
More file actions
109 lines (101 loc) · 4.4 KB
/
CourseTester.php
File metadata and controls
109 lines (101 loc) · 4.4 KB
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
<?php
namespace tests\app\models;
use app\libraries\FileUtils;
use app\libraries\Utils;
use app\models\Course;
use tests\BaseUnitTest;
class CourseTester extends BaseUnitTest {
public function testCourse() {
$details = [
'term' => 's18',
'term_name' => 'Spring 2018',
'course' => 'csci1000',
'user_group' => 1
];
$course = new Course($this->createMockCore(), $details);
$this->assertEquals('s18', $course->getTerm());
$this->assertEquals('Spring 2018', $course->getLongTerm());
$this->assertEquals('csci1000', $course->getTitle());
$this->assertEquals('CSCI1000', $course->getCapitalizedTitle());
$this->assertEquals('', $course->getDisplayName());
$this->assertEquals('Spring 2018', $course->getTermName());
$array = [
'term' => 's18',
'term_name' => 'Spring 2018',
'title' => 'csci1000',
'display_name' => '',
'user_group' => 1,
'modified' => false,
'registration_section' => null
];
$this->assertEquals($array, $course->toArray());
}
public function testLoadDisplayName() {
$temp_dir = FileUtils::joinPaths(sys_get_temp_dir(), Utils::generateRandomString());
$config_path = FileUtils::joinPaths($temp_dir, 'courses', 's18', 'csci1000', 'config');
FileUtils::createDir($config_path, true);
$config = [
'course_details' => [
'course_name' => 'Test Course',
]
];
FileUtils::writeJsonFile(FileUtils::joinPaths($config_path, 'config.json'), $config);
$details = ['term' => 's18', 'term_name' => 'Spring 2018', 'course' => 'csci1000'];
try {
$course = new Course($this->createMockCore(['tmp_path' => $temp_dir]), $details);
$this->assertTrue($course->loadDisplayName());
$this->assertEquals('Test Course', $course->getDisplayName());
$array = [
'term' => 's18',
'term_name' => 'Spring 2018',
'title' => 'csci1000',
'display_name' => 'Test Course',
'user_group' => 3,
'modified' => false,
'registration_section' => null
];
$this->assertEquals($array, $course->toArray());
}
finally {
FileUtils::recursiveRmdir($temp_dir);
}
}
public function testInvalidPath() {
$details = ['term' => 's18', 'term_name' => 'Spring 2018', 'course' => 'csci1000'];
$course = new Course($this->createMockCore(['tmp_path' => '/invalid/path']), $details);
$this->assertFalse($course->loadDisplayName());
$this->assertEquals('', $course->getDisplayName());
}
public function testMissingSection() {
$temp_dir = FileUtils::joinPaths(sys_get_temp_dir(), Utils::generateRandomString());
$config_path = FileUtils::joinPaths($temp_dir, 'courses', 's18', 'csci1000', 'config');
FileUtils::createDir($config_path, true);
$config = [];
FileUtils::writeJsonFile(FileUtils::joinPaths($config_path, 'config.json'), $config);
$details = ['term' => 's18', 'term_name' => 'Spring 2018', 'course' => 'csci1000'];
try {
$course = new Course($this->createMockCore(['tmp_path' => $temp_dir]), $details);
$this->assertFalse($course->loadDisplayName());
$this->assertEquals('', $course->getDisplayName());
}
finally {
FileUtils::recursiveRmdir($temp_dir);
}
}
public function testMissingSetting() {
$temp_dir = FileUtils::joinPaths(sys_get_temp_dir(), Utils::generateRandomString());
$config_path = FileUtils::joinPaths($temp_dir, 'courses', 's18', 'csci1000', 'config');
FileUtils::createDir($config_path, true);
$config = ['course_details' => []];
FileUtils::writeJsonFile(FileUtils::joinPaths($config_path, 'config.json'), $config);
$details = ['term' => 's18', 'term_name' => 'Spring 2018', 'course' => 'csci1000'];
try {
$course = new Course($this->createMockCore(['tmp_path' => $temp_dir]), $details);
$this->assertFalse($course->loadDisplayName());
$this->assertEquals('', $course->getDisplayName());
}
finally {
FileUtils::recursiveRmdir($temp_dir);
}
}
}